Make 'Reset notifications and sounds' work.

This commit is contained in:
B. Petersen
2016-12-21 23:04:52 +01:00
parent cce4e31b0f
commit 2dfacc4858
6 changed files with 36 additions and 104 deletions
@@ -2500,7 +2500,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
try {
Vibrator v = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(50);
//NotificationsController.getInstance().playRecordSound();
//NotificationsController.getInstance().playRecordSound(); -- was also disabled in Telegram; playing a sound while recording may result in a feedback
} catch (Exception e) {
FileLog.e("messenger", e);
}
@@ -35,7 +35,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
private String uploadingAvatar = null;
public boolean enableJoined = true;
public int fontSize = AndroidUtilities.dp(16);
public int ratingDecay;
@@ -75,7 +74,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
enableJoined = preferences.getBoolean("EnableContactJoined", true);
preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
secretWebpagePreview = preferences.getInt("secretWebpage2", 2);
@@ -386,7 +386,11 @@ public class NotificationsController {
MrChat mrChat = MrMailbox.getChat(chat_id);
boolean isGroupChat = mrChat.getType()==MrChat.MR_CHAT_GROUP;
int popup = preferences.getInt(isGroupChat ? "popupGroup" : "popupAll", 0);
boolean value = !( (!preferences.getBoolean("EnableAll", true) || isGroupChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
if( value ) {
}
/* old func:
public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast)
@@ -433,19 +437,12 @@ public class NotificationsController {
Boolean value = settingsCache.get(dialog_id);
boolean isChat = (int) dialog_id < 0;
popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
if (value == null) {
int notifyOverride = getNotifyOverride(preferences, dialog_id);
value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true) || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0);
settingsCache.put(dialog_id, value);
}
if (popup != 0 && messageObject.messageOwner.to_id.channel_id != 0) {
popup = 0;
}
if (value) {
if (popup != 0) {
popupArray.add(0, messageObject);
}
delayedPushMessages.add(messageObject);
pushMessages.add(0, messageObject);
pushMessagesDict.put(mid, messageObject);
@@ -459,23 +456,7 @@ public class NotificationsController {
notifyCheck = isLast;
}
if (!popupArray.isEmpty() && oldCount != popupArray.size() && !AndroidUtilities.needShowPasscode(false)) {
final int popupFinal = popup;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
popupMessages = popupArray;
if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) {
MessageObject messageObject = messageObjects.get(0);
if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
Intent popupIntent = new Intent(ApplicationLoader.applicationContext, PopupNotificationActivity.class);
popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
ApplicationLoader.applicationContext.startActivity(popupIntent);
}
}
}
});
}
}
});
*/
@@ -1061,43 +1042,6 @@ public class NotificationsController {
}
}
/*public void playRecordSound() {
try {
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
return;
}
notificationsQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
if (soundPool == null) {
soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
if (status == 0) {
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
}
}
});
}
if (soundRecord == 0 && !soundRecordLoaded) {
soundRecordLoaded = true;
soundRecord = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_record, 1);
}
if (soundRecord != 0) {
soundPool.play(soundRecord, 1.0f, 1.0f, 1, 0, 1.0f);
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
});
} catch (Exception e) {
FileLog.e("messenger", e);
}
}*/
private void playInChatSound() {
if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
return;
@@ -18,6 +18,7 @@ import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Gravity;
import android.view.View;
@@ -26,8 +27,11 @@ import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.NotificationsController;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.ApplicationLoader;
@@ -48,7 +52,6 @@ import com.b44t.ui.Components.LayoutHelper;
public class NotificationsSettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private ListView listView;
private boolean reseting = false;
private int notificationsServiceRow;
private int notificationsServiceConnectionRow;
@@ -78,8 +81,6 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
private int otherSectionRow;
private int badgeNumberRow;
private int repeatRow;
private int resetSectionRow2;
private int resetSectionRow;
private int resetNotificationsRow;
private int rowCount = 0;
@@ -132,8 +133,6 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
notificationsServiceConnectionRow = rowCount++;
badgeNumberRow = rowCount++;
repeatRow = rowCount++;
resetSectionRow2 = rowCount++;
resetSectionRow = rowCount++;
resetNotificationsRow = rowCount++;
NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated);
@@ -240,34 +239,25 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
FileLog.e("messenger", e);
}
} else if (i == resetNotificationsRow) {
if (reseting) {
return;
}
reseting = true;
/*TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings();
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.formatString("AskResetNotifications", R.string.AskResetNotifications));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().enableJoined = true;
reseting = false;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
if (getParentActivity() != null) {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("ResetNotificationsText", R.string.ResetNotificationsText), Toast.LENGTH_SHORT);
toast.show();
}
}
});
public void onClick(DialogInterface dialogInterface, int i) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});*/
});
showDialog(builder.create());
} else if (i == inappSoundRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
@@ -550,9 +540,9 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
@Override
public boolean isEnabled(int i) {
return !(i == messageSectionRow || i == groupSectionRow || i == inappSectionRow ||
i == otherSectionRow || i == resetSectionRow ||
i == otherSectionRow ||
i == groupSectionRow2 ||
i == inappSectionRow2 || i == otherSectionRow2 || i == resetSectionRow2);
i == inappSectionRow2 || i == otherSectionRow2 );
}
@Override
@@ -590,8 +580,6 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
((HeaderCell) view).setText(LocaleController.getString("InAppNotifications", R.string.InAppNotifications));
} else if (i == otherSectionRow) {
((HeaderCell) view).setText(LocaleController.getString("NotificationsOther", R.string.NotificationsOther));
} else if (i == resetSectionRow) {
((HeaderCell) view).setText(LocaleController.getString("Reset", R.string.Reset));
}
} if (type == TYPE_CHECK_CELL) {
if (view == null) {
@@ -648,7 +636,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
textCell.setTextAndValue(LocaleController.getString("Sound", R.string.Sound), value, true);
} else if (i == resetNotificationsRow) {
textCell.setMultilineDetail(true);
textCell.setTextAndValue(LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications), LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom), false);
textCell.setTextAndValue(LocaleController.getString("Reset", R.string.Reset), LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications), false);
} else if (i == messageVibrateRow || i == groupVibrateRow) {
textCell.setMultilineDetail(false);
int value = 0;
@@ -679,7 +667,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
} else {
value = LocaleController.formatPluralString("Hours", minutes / 60);
}
textCell.setTextAndValue(LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications), value, false);
textCell.setTextAndValue(LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications), value, true);
} else if (i == messagePriorityRow || i == groupPriorityRow) {
textCell.setMultilineDetail(false);
int value = 0;
@@ -720,7 +708,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
@Override
public int getItemViewType(int i) {
if (i == messageSectionRow || i == groupSectionRow || i == inappSectionRow ||
i == otherSectionRow || i == resetSectionRow) {
i == otherSectionRow ) {
return TYPE_HEADER;
} else if (i == messageAlertRow || i == messagePreviewRow || i == groupAlertRow ||
i == groupPreviewRow || i == inappSoundRow || i == inappVibrateRow ||
@@ -731,7 +719,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
} else if (i == messageLedRow || i == groupLedRow) {
return TYPE_COLOR_CELL;
} else if ( i == groupSectionRow2 ||
i == inappSectionRow2 || i == otherSectionRow2 || i == resetSectionRow2) {
i == inappSectionRow2 || i == otherSectionRow2 ) {
return TYPE_SHADOW;
} else {
return TYPE_TEXT_DETAIL;
@@ -660,4 +660,5 @@
<string name="InviteText">Ich verwende nun auch den Delta Chat Messenger - %1$s - und bin dort unter %2$s erreichbar.</string>
<string name="AdvancedSettings">Fortgeschrittene Einstellungen</string>
<string name="CannotConnect"></string>
<string name="AskResetNotifications">Alle Benachrichtigungseinstellungen und Töne dieser Seite, der Kontakte und der Gruppen zurücksetzen?</string>
</resources>
@@ -660,4 +660,5 @@
<string name="InviteMenuEntry">Send invitations</string>
<string name="InviteText">I\'m using Delta Chat messenger now - %1$s - you can text me at %2$s</string>
<string name="AdvancedSettings">Advanced settings</string>
<string name="AskResetNotifications" >Reset all notification settings and sounds of this page and of your contacts and groups?</string>
</resources>