Adds in settings the possibility to disable all notifications

Fixes an issue with counter and FP when filtering notifications
This commit is contained in:
tom79 2017-10-01 11:49:37 +02:00
parent e036c600e5
commit 65d4a10821
7 changed files with 208 additions and 142 deletions

View File

@ -195,10 +195,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
//Update the id of the last notification retrieved
MainActivity.lastNotificationId = notifications.get(0).getId();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId());
editor.apply();
lastReadNotifications = notifications.get(0).getId();
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId());
}
notificationsListAdapter.notifyDataSetChanged();
}
@ -225,11 +222,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
return;
//Store last notification id to avoid to notify for those that have been already seen
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
if (visible && notifications != null && notifications.size() > 0) {
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId());
editor.apply();
lastReadNotifications = notifications.get(0).getId();
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId());
}
}
@ -239,11 +233,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
//Store last toot id for home timeline to avoid to notify for those that have been already seen
//Store last notification id to avoid to notify for those that have been already seen
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
if (notifications != null && notifications.size() > 0) {
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId());
editor.apply();
lastReadNotifications = notifications.get(0).getId();
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId());
}
}
@ -297,4 +288,20 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
}catch (Exception ignored){}
}
}
/**
* Records the id of the notification only if its greater than the previous one.
* @param sharedPreferences SharedPreferences
* @param userId String current logged user
* @param notificationId String current notification id to check
*/
private void updateNotificationLastId(SharedPreferences sharedPreferences, String userId, String notificationId){
String lastNotif = sharedPreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
if( lastNotif != null && notificationId != null && Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notificationId);
editor.apply();
lastReadNotifications = notificationId;
}
}
}

View File

@ -32,6 +32,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
@ -69,6 +70,30 @@ public class SettingsNotificationsFragment extends Fragment {
}else {
style = R.style.Dialog;
}
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
final SwitchCompat switchCompatNotify = (SwitchCompat) rootView.findViewById(R.id.set_notify);
switchCompatNotify.setChecked(notify);
final LinearLayout notification_settings = (LinearLayout) rootView.findViewById(R.id.notification_settings);
if( notify)
notification_settings.setVisibility(View.VISIBLE);
else
notification_settings.setVisibility(View.GONE);
switchCompatNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Save the state here
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_NOTIFY, isChecked);
editor.apply();
if( isChecked)
notification_settings.setVisibility(View.VISIBLE);
else
notification_settings.setVisibility(View.GONE);
}
});
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
boolean notif_ask = sharedpreferences.getBoolean(Helper.SET_NOTIF_ASK, true);

View File

@ -223,6 +223,7 @@ public class Helper {
public static final int TRANS_NONE = 2;
public static final String SET_TRANS_FORCED = "set_trans_forced";
public static final String SET_NOTIFY = "set_notify";
public static final String SET_NOTIF_FOLLOW = "set_notif_follow";
public static final String SET_NOTIF_ADD = "set_notif_follow_add";
public static final String SET_NOTIF_ASK = "set_notif_follow_ask";
@ -1443,6 +1444,9 @@ public class Helper {
*/
public static boolean canNotify(Context context){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
if( !notify)
return false;
String dateIni = sharedpreferences.getString(Helper.SET_TIME_FROM, "07:00");
String dateEnd = sharedpreferences.getString(Helper.SET_TIME_TO, "22:00");
Calendar now = Calendar.getInstance();

View File

@ -25,6 +25,7 @@
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -33,108 +34,6 @@
android:orientation="vertical"
tools:ignore="UselessParent">
<!-- NOTIFICATIONS SETTINGS -->
<TextView
android:text="@string/settings_title_notifications"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- Toots per page -->
<CheckBox
android:id="@+id/set_notif_follow"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_add"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow_add"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_ask"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow_ask"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_mention"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow_mention"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_share"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow_share"
android:layout_height="wrap_content" />
<!-- END NOTIFICATIONS SETTINGS -->
<!-- NOTIFICATION CONTENT NEW -->
<TextView
android:text="@string/set_title_news"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- New hometimeline content -->
<CheckBox
android:id="@+id/set_notif_hometimeline"
android:layout_width="wrap_content"
android:text="@string/set_notification_news"
android:layout_height="wrap_content" />
<TextView
android:text="@string/settings_title_hour"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
style="?attr/shapeBorder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:orientation="horizontal">
<TextView
android:text="@string/settings_time_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:focusableInTouchMode="false"
android:id="@+id/settings_time_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:text="@string/settings_time_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:focusableInTouchMode="false"
android:id="@+id/settings_time_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- MORE OPTIONS SETTINGS -->
<TextView
android:text="@string/settings_title_more_options"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -144,9 +43,9 @@
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_wifi_only"/>
android:text="@string/set_notify"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/set_wifi_only"
android:id="@+id/set_notify"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_margin="10dp"
@ -154,43 +53,171 @@
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/notification_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
android:orientation="vertical">
<!-- NOTIFICATIONS SETTINGS -->
<TextView
android:layout_gravity="center_vertical"
android:text="@string/settings_title_notifications"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- Toots per page -->
<CheckBox
android:id="@+id/set_notif_follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_notif_silent"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/set_silence"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_margin="10dp"
android:text="@string/set_notif_follow"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
android:text="@string/set_notif_follow_add"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_ask"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow_ask"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_mention"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow_mention"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_notif_follow_share"
android:layout_width="wrap_content"
android:text="@string/set_notif_follow_share"
android:layout_height="wrap_content" />
<!-- END NOTIFICATIONS SETTINGS -->
<!-- NOTIFICATION CONTENT NEW -->
<TextView
android:text="@string/set_title_news"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- New hometimeline content -->
<CheckBox
android:id="@+id/set_notif_hometimeline"
android:layout_width="wrap_content"
android:text="@string/set_notification_news"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/set_led_colour_label"
android:layout_width="wrap_content"
android:text="@string/settings_title_hour"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
style="?attr/shapeBorder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:text="@string/set_led_colour"/>
<Spinner
android:id="@+id/led_colour_spinner"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:orientation="horizontal">
<TextView
android:text="@string/settings_time_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:focusableInTouchMode="false"
android:id="@+id/settings_time_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:text="@string/settings_time_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:focusableInTouchMode="false"
android:id="@+id/settings_time_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- MORE OPTIONS SETTINGS -->
<TextView
android:text="@string/settings_title_more_options"
style="?attr/shapeBorder"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/led_colours"/>
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_wifi_only"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/set_wifi_only"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_notif_silent"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/set_silence"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/set_led_colour_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:text="@string/set_led_colour"/>
<Spinner
android:id="@+id/led_colour_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/led_colours"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -307,6 +307,7 @@
<string name="set_share_validation_fav">Bestätigungsdialog vor dem favorisieren</string>
<string name="settings_title_more_options">Erweiterte Einstellungen</string>
<string name="set_wifi_only">Nur bei WLAN benachrichtigen</string>
<string name="set_notify">Benachrichtigen?</string>
<string name="set_notif_silent">Leise Benachrichtigungen</string>
<string name="set_night_mode">Nachtmodus</string>
<string name="set_nsfw_timeout">NSFW Anzeige Dauer (Sekunden, 0 bedeutet aus)</string>

View File

@ -296,6 +296,7 @@
<string name="set_share_validation_fav">Confirmer avant d\'ajouter aux favoris</string>
<string name="settings_title_more_options">Options avancées</string>
<string name="set_wifi_only">Notifier en WIFI seulement</string>
<string name="set_notify">Notifier ?</string>
<string name="set_notif_silent">Utiliser le vibreur</string>
<string name="set_night_mode">Mode nuit</string>
<string name="set_nsfw_timeout">Délai d\'affichage NSFW (en secondes, 0 signifie aucun délai)</string>

View File

@ -302,6 +302,7 @@
<string name="set_share_validation_fav">Show confirmation dialog before adding to favourites</string>
<string name="settings_title_more_options">Advanced settings</string>
<string name="set_wifi_only">Notify in WIFI only</string>
<string name="set_notify">Notify?</string>
<string name="set_notif_silent">Silent Notifications</string>
<string name="set_night_mode">Night mode</string>
<string name="set_nsfw_timeout">NSFW view timeout (seconds, 0 means off)</string>