Compare commits

...

3 Commits

Author SHA1 Message Date
rafalense
b58bfd8d72 Reset BuildVars values 2015-03-11 17:02:47 +01:00
rafalense
afc67309a8 Merge pull request #1 from PioneerAxon/master
Smart notifications for group chat
2015-03-06 07:46:53 +01:00
PioneerAxon
acf3a8608b Smart notifications for group chat 2015-03-05 02:01:11 +05:30
8 changed files with 341 additions and 31 deletions

View File

@ -3399,7 +3399,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (dialog != null) { if (dialog != null) {
dialog.notify_settings.mute_until = 0; dialog.notify_settings.mute_until = 0;
} }
editor.remove("notify2_" + dialog_id); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (preferences.getInt("notify2_" + dialog_id, 0) != 4) {
editor.remove("notify2_" + dialog_id);
}
MessagesStorage.getInstance().setDialogFlags(dialog_id, 0); MessagesStorage.getInstance().setDialogFlags(dialog_id, 0);
} }

View File

@ -43,7 +43,9 @@ import org.telegram.ui.PopupNotificationActivity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
public class NotificationsController { public class NotificationsController {
@ -353,6 +355,31 @@ public class NotificationsController {
notifyDisabled = true; notifyDisabled = true;
} }
boolean use_smart_notify = preferences.getBoolean("smart_notify_" + dialog_id, false);
Long smart_notify_timeframe = preferences.getLong("smart_notify_timeframe_" + dialog_id, 1);
int smart_notify_max_count = preferences.getInt("smart_notify_max_count_" + dialog_id, 1);
if (chat_id != 0 && use_smart_notify)
{
if (chat.sound_timestamps == null)
chat.sound_timestamps = new LinkedList<>();
boolean shouldAdd = true;
Date firstNotification = chat.sound_timestamps.peek();
Date currentDate = new Date();
if (firstNotification != null) {
if (currentDate.getTime() - firstNotification.getTime() < smart_notify_timeframe * 1000 && chat.sound_timestamps.size () >= smart_notify_max_count) {
shouldAdd = false;
}
}
if (!shouldAdd) {
notifyDisabled = true;
}
else {
if (chat.sound_timestamps.size() >= smart_notify_max_count)
chat.sound_timestamps.poll();
chat.sound_timestamps.add(currentDate);
}
}
String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath(); String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
if (!notifyDisabled) { if (!notifyDisabled) {
inAppSounds = preferences.getBoolean("EnableInAppSounds", true); inAppSounds = preferences.getBoolean("EnableInAppSounds", true);

View File

@ -10,10 +10,10 @@ package org.telegram.messenger;
public class BuildVars { public class BuildVars {
public static boolean DEBUG_VERSION = false; public static boolean DEBUG_VERSION = false;
public static int APP_ID = 16623; //obtaion your own APP_ID at https://core.telegram.org/api/obtaining_api_id public static int APP_ID = 0; //obtain your own APP_ID at https://core.telegram.org/api/obtaining_api_id
public static String APP_HASH = "8c9dbfe58437d1739540f5d53c72ae4b"; //obtain your own APP_HASH at https://core.telegram.org/api/obtaining_api_id public static String APP_HASH = ""; //obtain your own APP_HASH at https://core.telegram.org/api/obtaining_api_id
public static String HOCKEY_APP_HASH = "21098765432109876543210987654321";//"a5b5c4f551dadedc9918d9766a22ca7c"; public static String HOCKEY_APP_HASH = "your-hockeyapp-api-key-here";
public static String GCM_SENDER_ID = "326898382893"; public static String GCM_SENDER_ID = "760348033672";
public static String SEND_LOGS_EMAIL = "androiddeveloperplus@gmail.com"; public static String SEND_LOGS_EMAIL = "email@gmail.com";
public static String BING_SEARCH_KEY = "dKYt6BjhkmFnJABZI/nWs++mx7owYEKZLcdA3DTOO1s"; //obtain your own KEY at https://www.bing.com/dev/en-us/dev-center public static String BING_SEARCH_KEY = ""; //obtain your own KEY at https://www.bing.com/dev/en-us/dev-center
} }

View File

@ -9,7 +9,10 @@
package org.telegram.messenger; package org.telegram.messenger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.Locale; import java.util.Locale;
import java.util.Queue;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class TLRPC { public class TLRPC {
@ -5857,6 +5860,7 @@ public class TLRPC {
public boolean checked_in; public boolean checked_in;
public int version; public int version;
public boolean left; public boolean left;
public java.util.Queue<java.util.Date> sound_timestamps = null;
} }
public static class TL_chatForbidden extends Chat { public static class TL_chatForbidden extends Chat {

View File

@ -276,6 +276,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
return false; return false;
} }
} }
if (chatId > 0){
if (currentChat.sound_timestamps != null)
currentChat.sound_timestamps.clear();
}
if (chatId > 0) { if (chatId > 0) {
dialog_id = -chatId; dialog_id = -chatId;
} else { } else {

View File

@ -24,8 +24,12 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.NumberPicker;
import android.widget.Spinner;
import android.widget.Toast;
import org.telegram.android.AndroidUtilities; import org.telegram.android.AndroidUtilities;
import org.telegram.android.MessagesController; import org.telegram.android.MessagesController;
@ -55,6 +59,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
private int settingsVibrateRow; private int settingsVibrateRow;
private int settingsSoundRow; private int settingsSoundRow;
private int settingsPriorityRow; private int settingsPriorityRow;
private int settingsSmartNotifyRow;
private int settingsLedRow; private int settingsLedRow;
private int rowCount = 0; private int rowCount = 0;
@ -73,6 +78,12 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
} else { } else {
settingsPriorityRow = -1; settingsPriorityRow = -1;
} }
if (dialog_id < 0) {
settingsSmartNotifyRow = rowCount++;
}
else {
settingsSmartNotifyRow = -1;
}
settingsLedRow = rowCount++; settingsLedRow = rowCount++;
NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated); NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated);
return super.onFragmentCreate(); return super.onFragmentCreate();
@ -155,31 +166,67 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
} }
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setItems(new CharSequence[] { if (dialog_id < 0) {
LocaleController.getString("Default", R.string.Default), builder.setItems(new CharSequence[]{
LocaleController.getString("Enabled", R.string.Enabled), LocaleController.getString("Default", R.string.Default),
LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled) LocaleController.getString("Enabled", R.string.Enabled),
}, new DialogInterface.OnClickListener() { LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled),
@Override LocaleController.getString("Smart Notification", R.string.SmartNotification)
public void onClick(DialogInterface d, int which) { }, new DialogInterface.OnClickListener() {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); @Override
SharedPreferences.Editor editor = preferences.edit(); public void onClick(DialogInterface dialog, int which) {
editor.putInt("notify2_" + dialog_id, which); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0); SharedPreferences.Editor editor = preferences.edit();
editor.commit(); if (which == 3) {
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id); which = 4; //Leave space for "Mute group for D duration"
if (dialog != null) { editor.putBoolean("smart_notify_" + dialog_id, true);
dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); } else {
if (which == 2) { editor.putBoolean("smart_notify_" + dialog_id, false);
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
} }
editor.putInt("notify2_" + dialog_id, which);
MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
editor.commit();
TLRPC.TL_dialog tl_dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (tl_dialog != null) {
tl_dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
if (which == 2) {
tl_dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
}
if (listView != null) {
listView.invalidateViews();
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
} }
if (listView != null) { });
listView.invalidateViews(); }
else {
builder.setItems(new CharSequence[]{
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("Enabled", R.string.Enabled),
LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled),
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("notify2_" + dialog_id, which);
MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
editor.commit();
TLRPC.TL_dialog tl_dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (tl_dialog != null) {
tl_dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
if (which == 2) {
tl_dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
}
if (listView != null) {
listView.invalidateViews();
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
} }
NotificationsController.updateServerNotificationsSettings(dialog_id); });
} }
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder); showAlertDialog(builder);
} else if (i == settingsSoundRow) { } else if (i == settingsSoundRow) {
@ -290,6 +337,70 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder); showAlertDialog(builder);
} else if (i == settingsSmartNotifyRow) {
if (getParentActivity() == null) {
return;
}
LayoutInflater li = (LayoutInflater)getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_smart_notify, null, false);
String[] timeUnits = {
LocaleController.getString("Seconds", R.string.TimeUnitSeconds),
LocaleController.getString("Minutes", R.string.TimeUnitMinutes),
LocaleController.getString("Hours", R.string.TimeUnitHours),
LocaleController.getString("Days", R.string.TimeUnitDays)
};
final Spinner timeframeUnitSpinner = (Spinner) view.findViewById(R.id.timeframeunitSpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (li.getContext(), android.R.layout.simple_spinner_item, timeUnits);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
timeframeUnitSpinner.setAdapter(adapter);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
final NumberPicker maxcountNumberPicker = (NumberPicker) view.findViewById(R.id.maxcountNumberPicker);
maxcountNumberPicker.setMinValue(1);
maxcountNumberPicker.setMaxValue(10);
maxcountNumberPicker.setValue(preferences.getInt ("smart_notify_max_count_" + dialog_id, 1));
final NumberPicker timeframeNumberPicker = (NumberPicker) view.findViewById(R.id.timeframeNumberPicker);
timeframeNumberPicker.setMinValue(1);
timeframeNumberPicker.setMaxValue(100);
long timeframe = preferences.getLong("smart_notify_timeframe_" + dialog_id, 1);
long multiplier = (timeframe % 86400L == 0L) ? 86400L : ((timeframe % 3600L == 0L) ? 3600L : ((timeframe % 60L == 0L) ? 60L : 1L));
timeframe = timeframe / multiplier;
timeframeUnitSpinner.setSelection((multiplier == 1L) ? 0 : ((multiplier == 60L) ? 1 : (multiplier == 3600L) ? 2 : 3));
timeframeNumberPicker.setValue((int)timeframe);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("Smart Notification", R.string.SmartNotification));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
int unit = timeframeUnitSpinner.getSelectedItemPosition();
long multiplier = (unit == 0) ? 1L : ((unit == 1) ? 60L : ((unit == 2) ? 3600L : 86400L));
editor.putInt("smart_notify_max_count_" + dialog_id, maxcountNumberPicker.getValue());
editor.putLong("smart_notify_timeframe_" + dialog_id, timeframeNumberPicker.getValue() * multiplier);
editor.commit();
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("smart_notify_max_count_" + dialog_id, 1);
editor.putLong("smart_notify_timeframe_" + dialog_id, 1);
editor.commit();
listView.invalidateViews();
}
});
showAlertDialog(builder);
} }
} }
}); });
@ -355,11 +466,18 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
@Override @Override
public boolean areAllItemsEnabled() { public boolean areAllItemsEnabled() {
return true; return false;
} }
@Override @Override
public boolean isEnabled(int i) { public boolean isEnabled(int i) {
if (i < 0)
return false;
if (i == settingsSmartNotifyRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (!preferences.getBoolean("smart_notify_" + dialog_id, false))
return false;
}
return true; return true;
} }
@ -435,6 +553,8 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
} else { } else {
textCell.setTextAndValue(LocaleController.getString("Notifications", R.string.Notifications), LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled), true); textCell.setTextAndValue(LocaleController.getString("Notifications", R.string.Notifications), LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled), true);
} }
} else if (value == 4) {
textCell.setTextAndValue(LocaleController.getString("Notifications", R.string.Notifications), LocaleController.getString("Smart Notification", R.string.SmartNotification), true);
} }
} else if (i == settingsSoundRow) { } else if (i == settingsSoundRow) {
String value = preferences.getString("sound_" + dialog_id, LocaleController.getString("Default", R.string.Default)); String value = preferences.getString("sound_" + dialog_id, LocaleController.getString("Default", R.string.Default));
@ -453,6 +573,33 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
} else if (value == 3) { } else if (value == 3) {
textCell.setTextAndValue(LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority), LocaleController.getString("SettingsDefault", R.string.SettingsDefault), true); textCell.setTextAndValue(LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority), LocaleController.getString("SettingsDefault", R.string.SettingsDefault), true);
} }
} else if (i == settingsSmartNotifyRow) {
String value = LocaleController.getString("Disabled", R.string.Disabled);
if (preferences.getBoolean("smart_notify_" + dialog_id, false)) {
long timeframe = preferences.getLong("smart_notify_timeframe_" + dialog_id, 1);
long multiplier = (timeframe % 86400L == 0L) ? 86400L : ((timeframe % 3600L == 0L) ? 3600L : ((timeframe % 60L == 0L) ? 60L : 1L));
timeframe = timeframe / multiplier;
String[] timeUnits = {
LocaleController.getString("Seconds", R.string.TimeUnitSeconds),
LocaleController.getString("Minutes", R.string.TimeUnitMinutes),
LocaleController.getString("Hours", R.string.TimeUnitHours),
LocaleController.getString("Days", R.string.TimeUnitDays)
};
value = LocaleController.getString("Sound at most", R.string.settings_smart_notify_begin);
value += " ";
value += preferences.getInt("smart_notify_max_count_" + dialog_id, 1);
value += " ";
value += LocaleController.getString("time(s)", R.string.settings_smart_notify_mid1);
value += " ";
value += LocaleController.getString("within", R.string.settings_smart_notify_mid2);
value += " ";
value += timeframe;
value += " ";
value += timeUnits [((multiplier == 1L)? 0: (multiplier == 60L)? 1 : (multiplier == 3600L)? 2 : 3)];
value += " ";
value += LocaleController.getString(".", R.string.settings_smart_notify_end);
}
textCell.setTextAndValue(LocaleController.getString("Smart Notification", R.string.SmartNotification), value, true);
} }
} else if (type == 1) { } else if (type == 1) {
if (view == null) { if (view == null) {

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:weightSum="1"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_smart_notify_begin"
android:id="@+id/beginTextView"
android:layout_gravity="center"
android:autoText="false"
android:enabled="true"
android:focusable="false"
android:inputType="none"
android:singleLine="true"
android:textStyle="normal"
android:visibility="visible"
android:gravity="center"
android:layout_margin="5dp" />
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/maxcountNumberPicker"
android:clickable="true"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_smart_notify_mid1"
android:id="@+id/midTextView1"
android:layout_gravity="center"
android:autoText="false"
android:enabled="true"
android:focusable="false"
android:inputType="none"
android:singleLine="true"
android:textStyle="normal"
android:visibility="visible"
android:editable="true"
android:gravity="center"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:weightSum="1"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_smart_notify_mid2"
android:id="@+id/midTextView2"
android:layout_gravity="center"
android:autoText="false"
android:enabled="true"
android:focusable="false"
android:inputType="none"
android:singleLine="true"
android:textStyle="normal"
android:visibility="visible"
android:editable="true"
android:gravity="center"
android:layout_margin="5dp" />
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timeframeNumberPicker"
android:gravity="center" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timeframeunitSpinner"
android:spinnerMode="dropdown"
android:clickable="true"
android:gravity="center"
android:layout_gravity="center"
android:dropDownWidth="fill_parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_smart_notify_end"
android:id="@+id/endTextView"
android:layout_gravity="center"
android:autoText="false"
android:enabled="true"
android:focusable="false"
android:inputType="none"
android:singleLine="true"
android:textStyle="normal"
android:visibility="visible"
android:gravity="center"
android:layout_margin="5dp" />
</LinearLayout>
</LinearLayout>

View File

@ -266,6 +266,15 @@
<string name="ImportContacts">Import Contacts</string> <string name="ImportContacts">Import Contacts</string>
<string name="SortFirstName">First name</string> <string name="SortFirstName">First name</string>
<string name="SortLastName">Last name</string> <string name="SortLastName">Last name</string>
<string name="SmartNotification">Smart Notification</string>
<string name="TimeUnitSeconds">Seconds</string>
<string name="TimeUnitMinutes">Minutes</string>
<string name="TimeUnitHours">Hours</string>
<string name="TimeUnitDays">Days</string>
<string name="settings_smart_notify_begin">Sound at most</string>
<string name="settings_smart_notify_mid1">times</string>
<string name="settings_smart_notify_mid2">within</string>
<string name="settings_smart_notify_end">period.</string>
<string name="LedColor">LED Color</string> <string name="LedColor">LED Color</string>
<string name="PopupNotification">Popup Notifications</string> <string name="PopupNotification">Popup Notifications</string>
<string name="NoPopup">No popup</string> <string name="NoPopup">No popup</string>