From 182087e5822929e4ed99234978add62656fb0e48 Mon Sep 17 00:00:00 2001 From: tom79 Date: Tue, 1 Aug 2017 15:44:26 +0200 Subject: [PATCH] Warns about notifications --- .../mastodon/activities/MainActivity.java | 40 +++++++++- .../mastodon/drawers/StatusListAdapter.java | 10 ++- .../gouv/etalab/mastodon/helper/Helper.java | 1 + .../main/res/layout/popup_quick_settings.xml | 80 +++++++++++++++++++ app/src/main/res/values-fr/strings.xml | 10 +++ app/src/main/res/values/strings.xml | 9 +++ 6 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/layout/popup_quick_settings.xml diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java index 98d439c22..82cdc1a7c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java @@ -29,6 +29,8 @@ import android.support.v4.app.FragmentManager; import android.support.v4.view.ViewPager; import android.support.v7.app.AlertDialog; import android.support.v7.widget.SearchView; +import android.support.v7.widget.SwitchCompat; +import android.view.LayoutInflater; import android.view.View; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -112,7 +114,7 @@ public class MainActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); if( theme == Helper.THEME_LIGHT){ @@ -335,6 +337,42 @@ public class MainActivity extends AppCompatActivity navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0); toolbarTitle.setText(R.string.home_menu); } + + boolean popupShown = sharedpreferences.getBoolean(Helper.SET_POPUP_PUSH, false); + if(!popupShown){ + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this); + LayoutInflater inflater = getLayoutInflater(); + View dialogView = inflater.inflate(R.layout.popup_quick_settings, null); + dialogBuilder.setView(dialogView); + + final SwitchCompat set_push_hometimeline = (SwitchCompat) dialogView.findViewById(R.id.set_push_hometimeline); + final SwitchCompat set_push_notification = (SwitchCompat) dialogView.findViewById(R.id.set_push_notification); + boolean notif_hometimeline = sharedpreferences.getBoolean(Helper.SET_NOTIF_HOMETIMELINE, true); + 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); + boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); + boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); + boolean notifif_notifications = !( !notif_follow && !notif_add && !notif_ask && !notif_mention && !notif_share); + set_push_hometimeline.setChecked(notif_hometimeline); + set_push_notification.setChecked(notifif_notifications); + + dialogBuilder.setTitle(R.string.settings_popup_title); + dialogBuilder.setCancelable(false); + dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_NOTIF_FOLLOW, set_push_notification.isChecked()); + editor.putBoolean(Helper.SET_NOTIF_ADD, set_push_notification.isChecked()); + editor.putBoolean(Helper.SET_NOTIF_ASK, set_push_notification.isChecked()); + editor.putBoolean(Helper.SET_NOTIF_MENTION, set_push_notification.isChecked()); + editor.putBoolean(Helper.SET_NOTIF_SHARE, set_push_notification.isChecked()); + editor.putBoolean(Helper.SET_NOTIF_HOMETIMELINE, set_push_hometimeline.isChecked()); + editor.putBoolean(Helper.SET_POPUP_PUSH, true); + editor.apply(); + } + }).show(); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index f29227a64..297a70749 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -310,7 +310,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf public void onClick(View v) { Intent intent = new Intent(context, ShowConversationActivity.class); Bundle b = new Bundle(); - b.putString("statusId", status.getId()); + if( status.getReblog() == null) + b.putString("statusId", status.getId()); + else + b.putString("statusId", status.getReblog().getId()); intent.putExtras(b); context.startActivity(intent); } @@ -320,7 +323,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf public void onClick(View v) { Intent intent = new Intent(context, ShowConversationActivity.class); Bundle b = new Bundle(); - b.putString("statusId", status.getId()); + if( status.getReblog() == null) + b.putString("statusId", status.getId()); + else + b.putString("statusId", status.getReblog().getId()); intent.putExtras(b); context.startActivity(intent); } 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 71c23b2da..2ec22507f 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 @@ -181,6 +181,7 @@ public class Helper { public static final String SET_TIME_FROM = "set_time_from"; public static final String SET_TIME_TO = "set_time_to"; public static final String SET_AUTO_STORE = "set_auto_store"; + public static final String SET_POPUP_PUSH = "set_popup_push"; public static final int ATTACHMENT_ALWAYS = 1; public static final int ATTACHMENT_WIFI = 2; public static final int ATTACHMENT_ASK = 3; diff --git a/app/src/main/res/layout/popup_quick_settings.xml b/app/src/main/res/layout/popup_quick_settings.xml new file mode 100644 index 000000000..cda459b22 --- /dev/null +++ b/app/src/main/res/layout/popup_quick_settings.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 7360accb4..32026663a 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -48,6 +48,7 @@ Suivant Précédent Ouvrir avec + Valider Accueil Fil public local @@ -302,6 +303,15 @@ Recherche + + Notifications push + + Veuillez confirmer les notifications que vous souhaitez recevoir. + Vous pourrez les activer ou les désactiver plus tard dans les paramètres (onglet Notifications). + + Pour les pouets non lus sur la page d\'accueil + Pour les notifications non lues ? + Nettoyage du cache Il y a %1$s de données en cache.\n\nSouhaitez-vous les supprimer ? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6e8fe587..fddaa5928 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,6 +51,7 @@ Next Previous Open with + Validate Home Local timeline @@ -307,6 +308,14 @@ Search + + Push notifications + + Please, confirm push notifications that you want to receive. + You can enable or disable these notifications later in settings (Notifications tab). + + For unread toots in home time-line? + For unread notifications? Clear cache There are %1$s data in cache.\n\nWould you like to delete them?