Commit 1216bf06 authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'release/1.0.11'

parents 9f0d7c53 1a0e9810
......@@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 182
versionName '1.0.10'
versionCode 183
versionName '1.0.11'
}
compileOptions {
......
......@@ -394,14 +394,7 @@ public abstract class AbstractChat extends BaseEntity {
openChat();
if (!incoming)
notify = false;
if (notify && !notifyAboutMessage())
notify = false;
boolean showTicker = notify;
if (visible && showTicker) {
notify = false;
if (!ChatManager.getInstance().isNotifyVisible(account, user))
showTicker = false;
}
MessageItem messageItem = new MessageItem(this, record ? null
: NO_RECORD_TAG, resource, text, action, timestamp,
delayTimestamp, incoming, read, send, false, incoming,
......@@ -412,9 +405,17 @@ public abstract class AbstractChat extends BaseEntity {
if (save)
requestToWriteMessage(messageItem, resource, text, action,
timestamp, delayTimestamp, incoming, read, send);
if (showTicker)
NotificationManager.getInstance().onMessageNotification(
messageItem, notify);
if (notify && notifyAboutMessage()) {
if (visible) {
if (ChatManager.getInstance().isNotifyVisible(account, user)) {
NotificationManager.getInstance().onCurrentChatMessageNotification(messageItem);
}
} else {
NotificationManager.getInstance().onMessageNotification(messageItem);
}
}
MessageManager.getInstance().onChatChanged(account, user, incoming);
return messageItem;
}
......
......@@ -2,8 +2,6 @@ package com.xabber.android.data.notification;
import android.app.PendingIntent;
import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.text.Spannable;
import android.text.SpannableString;
......@@ -11,14 +9,13 @@ import android.text.style.StyleSpan;
import com.xabber.android.R;
import com.xabber.android.data.Application;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.message.MessageItem;
import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.ChatViewer;
import com.xabber.android.ui.ContactList;
import com.xabber.android.ui.helper.AccountPainter;
import com.xabber.android.utils.StringUtils;
......@@ -26,10 +23,10 @@ import java.util.List;
public class MessageNotificationCreator {
private static int UNIQUE_REQUEST_CODE = 0;
private final Application application;
private final AccountPainter accountPainter;
private List<MessageNotification> messageNotifications;
private NotificationCompat.Builder notificationBuilder;
public MessageNotificationCreator() {
application = Application.getInstance();
......@@ -56,7 +53,7 @@ public class MessageNotificationCreator {
boolean showText = ChatManager.getInstance().isShowText(message.getAccount(), message.getUser());
notificationBuilder = new NotificationCompat.Builder(application);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application);
notificationBuilder.setContentTitle(getTitle(message, messageCount));
notificationBuilder.setContentText(getText(message, showText));
notificationBuilder.setSubText(message.getAccount());
......@@ -75,7 +72,7 @@ public class MessageNotificationCreator {
notificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
addEffects(messageItem);
NotificationManager.addEffects(notificationBuilder, messageItem);
return notificationBuilder.build();
}
......@@ -199,24 +196,12 @@ public class MessageNotificationCreator {
}
private PendingIntent getIntent(MessageNotification message) {
Intent chatIntent
= ChatViewer.createClearTopIntent(application, message.getAccount(), message.getUser());
Intent backIntent = ContactList.createIntent(application);
backIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(application, 0, chatIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent intent = ChatViewer.createClearTopIntent(application, message.getAccount(), message.getUser());
return PendingIntent.getActivities(application, UNIQUE_REQUEST_CODE++,
new Intent[]{backIntent, intent}, PendingIntent.FLAG_ONE_SHOT);
}
private void addEffects(MessageItem messageItem) {
if (messageItem == null) {
return;
}
if (messageItem.getChat().getFirstNotification() || !SettingsManager.eventsFirstOnly()) {
Uri sound = PhraseManager.getInstance().getSound(messageItem.getChat().getAccount(),
messageItem.getChat().getUser(), messageItem.getText());
boolean makeVibration = ChatManager.getInstance().isMakeVibro(messageItem.getChat().getAccount(),
messageItem.getChat().getUser());
NotificationManager.getInstance().setNotificationDefaults(notificationBuilder,
makeVibration, sound, AudioManager.STREAM_NOTIFICATION);
}
}
}
......@@ -19,6 +19,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Handler;
import android.os.Vibrator;
......@@ -40,6 +41,8 @@ import com.xabber.android.data.account.OnAccountRemovedListener;
import com.xabber.android.data.connection.ConnectionState;
import com.xabber.android.data.message.MessageItem;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.ClearNotifications;
import com.xabber.android.ui.ContactList;
......@@ -64,6 +67,7 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
public static final int PERSISTENT_NOTIFICATION_ID = 1;
public static final int MESSAGE_NOTIFICATION_ID = 2;
public static final int CURRENT_CHAT_MESSAGE_NOTIFICATION_ID = 3;
private static final int BASE_NOTIFICATION_PROVIDER_ID = 0x10;
private static final long VIBRATION_DURATION = 500;
......@@ -153,6 +157,21 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
return instance;
}
public static void addEffects(NotificationCompat.Builder notificationBuilder, MessageItem messageItem) {
if (messageItem == null) {
return;
}
if (messageItem.getChat().getFirstNotification() || !SettingsManager.eventsFirstOnly()) {
Uri sound = PhraseManager.getInstance().getSound(messageItem.getChat().getAccount(),
messageItem.getChat().getUser(), messageItem.getText());
boolean makeVibration = ChatManager.getInstance().isMakeVibro(messageItem.getChat().getAccount(),
messageItem.getChat().getUser());
NotificationManager.getInstance().setNotificationDefaults(notificationBuilder,
makeVibration, sound, AudioManager.STREAM_NOTIFICATION);
}
}
private void initPersistentNotification() {
persistentNotificationBuilder.setContentTitle(application.getString(R.string.application_title_full));
persistentNotificationBuilder.setDeleteIntent(clearNotifications);
......@@ -417,8 +436,6 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
return connectionState;
}
private void notify(int id, Notification notification) {
LogManager.i(this, "Notification: " + id
+ ", ticker: " + notification.tickerText
......@@ -441,43 +458,42 @@ public class NotificationManager implements OnInitializedListener, OnAccountChan
return null;
}
/**
* Shows ticker with the message and updates message notification.
*
* @param messageItem
* @param addNotification Whether notification should be stored.
*/
public void onMessageNotification(MessageItem messageItem, boolean addNotification) {
if (addNotification) {
MessageNotification messageNotification = getMessageNotification(
messageItem.getChat().getAccount(), messageItem.getChat().getUser());
if (messageNotification == null) {
messageNotification = new MessageNotification(
messageItem.getChat().getAccount(), messageItem.getChat().getUser(), null, null, 0);
} else {
messageNotifications.remove(messageNotification);
}
messageNotification.addMessage(messageItem.getText());
messageNotifications.add(messageNotification);
final String account = messageNotification.getAccount();
final String user = messageNotification.getUser();
final String text = messageNotification.getText();
final Date timestamp = messageNotification.getTimestamp();
final int count = messageNotification.getCount();
if (AccountManager.getInstance().getArchiveMode(account) != ArchiveMode.dontStore) {
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
NotificationTable.getInstance().write(account, user, text, timestamp, count);
}
});
}
public void onMessageNotification(MessageItem messageItem) {
MessageNotification messageNotification = getMessageNotification(
messageItem.getChat().getAccount(), messageItem.getChat().getUser());
if (messageNotification == null) {
messageNotification = new MessageNotification(
messageItem.getChat().getAccount(), messageItem.getChat().getUser(), null, null, 0);
} else {
messageNotifications.remove(messageNotification);
}
messageNotification.addMessage(messageItem.getText());
messageNotifications.add(messageNotification);
final String account = messageNotification.getAccount();
final String user = messageNotification.getUser();
final String text = messageNotification.getText();
final Date timestamp = messageNotification.getTimestamp();
final int count = messageNotification.getCount();
if (AccountManager.getInstance().getArchiveMode(account) != ArchiveMode.dontStore) {
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
NotificationTable.getInstance().write(account, user, text, timestamp, count);
}
});
}
updateMessageNotification(messageItem);
}
public void onCurrentChatMessageNotification(MessageItem messageItem) {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application);
addEffects(notificationBuilder, messageItem);
notify(CURRENT_CHAT_MESSAGE_NOTIFICATION_ID, notificationBuilder.build());
}
/**
* Updates message notification.
*/
......
......@@ -15,6 +15,7 @@ import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
......@@ -131,6 +132,8 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
}
});
setHasOptionsMenu(true);
AccountPainter accountPainter = new AccountPainter(getActivity());
toolbar.setBackgroundColor(accountPainter.getAccountMainColor(account));
......@@ -326,6 +329,23 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
updateChat();
}
/**
* This method used for hardware menu button
*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.chat, menu);
setUpOptionsMenu(menu);
}
/**
* This method used for hardware menu button
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return onMenuItemClick(item);
}
private void setUpOptionsMenu(Menu menu) {
AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
......
......@@ -848,7 +848,7 @@ public class XMPPConnection extends Connection {
throw new IllegalStateException();
context.init(kms, new TrustManager[]{new XMPPTrustManager(
KeyStoreManager.getOrCreateKeyStore(config),
getHost(), config.getCertificateListener(),
getServiceName(), config.getCertificateListener(),
chainCheck, domainCheck, allowSelfSigned)}, SECURE_RANDOM);
}
Socket plain = socket;
......
......@@ -55,7 +55,7 @@
android:singleLine="true"
android:text="Some Name"
android:textColor="@color/green_700"
android:textSize="18sp" />
android:textSize="16sp" />
<TextView
android:id="@+id/account_jid"
......@@ -79,6 +79,7 @@
android:gravity="top"
android:singleLine="true"
android:text="Online"
android:textColor="?android:attr/textColorSecondary" />
android:textColor="?android:attr/textColorSecondary"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment