diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java
index 407ceb596..8b3f783fc 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java
@@ -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;
+ }
+ }
}
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java
index 098995f91..d4f3abd05 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsNotificationsFragment.java
@@ -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);
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java
index aafda0942..21b40cec1 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java
@@ -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();
diff --git a/app/src/main/res/layout/fragment_settings_notifications.xml b/app/src/main/res/layout/fragment_settings_notifications.xml
index 0772b7fcd..2363efabd 100644
--- a/app/src/main/res/layout/fragment_settings_notifications.xml
+++ b/app/src/main/res/layout/fragment_settings_notifications.xml
@@ -25,6 +25,7 @@
android:layout_height="match_parent">
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:text="@string/set_notify"/>
+
+ android:orientation="vertical">
+
+
+
-
+
-
-
+ android:text="@string/set_notif_follow_add"
+ android:layout_height="wrap_content" />
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+ android:layout_gravity="center_vertical"
+ android:orientation="horizontal">
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 2d45d66d6..69666e21a 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -307,6 +307,7 @@
Bestätigungsdialog vor dem favorisieren
Erweiterte Einstellungen
Nur bei WLAN benachrichtigen
+ Benachrichtigen?
Leise Benachrichtigungen
Nachtmodus
NSFW Anzeige Dauer (Sekunden, 0 bedeutet aus)
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index c02954cd2..a3ec2ed30 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -296,6 +296,7 @@
Confirmer avant d\'ajouter aux favoris
Options avancées
Notifier en WIFI seulement
+ Notifier ?
Utiliser le vibreur
Mode nuit
Délai d\'affichage NSFW (en secondes, 0 signifie aucun délai)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f156ee086..6ef38baab 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -302,6 +302,7 @@
Show confirmation dialog before adding to favourites
Advanced settings
Notify in WIFI only
+ Notify?
Silent Notifications
Night mode
NSFW view timeout (seconds, 0 means off)