From 4c3b64e744e0321bf25ea764eaebf3cbb660b18f Mon Sep 17 00:00:00 2001 From: tom79 Date: Sat, 20 May 2017 10:14:10 +0200 Subject: [PATCH] Silent notifications + Displays profile of the original toot owner when shared. Prepares notifications service for new toots in home timeline. --- .../fr/gouv/etalab/mastodon/client/API.java | 5 ++- .../mastodon/drawers/StatusListAdapter.java | 7 ++-- .../SettingsNotificationsFragment.java | 25 +++++++++++-- .../gouv/etalab/mastodon/helper/Helper.java | 1 + .../fragment_settings_notifications.xml | 35 +++++++++++++++++-- app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 66 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index c49e7e1a9..7960929d2 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -331,8 +331,7 @@ public class API { limit = 40; params.put("limit",String.valueOf(limit)); statuses = new ArrayList<>(); - - get(String.format("/accounts/%s/statuses",userId), params, new JsonHttpResponseHandler() { + get("/timelines/home", params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { @@ -1162,7 +1161,7 @@ public class API { private void get(String action, RequestParams params, AsyncHttpResponseHandler responseHandler) { - client.setTimeout(5000); + client.setTimeout(10000); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT); 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 91341fab8..a9003785d 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 @@ -332,7 +332,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf public void onClick(View v) { Intent intent = new Intent(context, ShowAccountActivity.class); Bundle b = new Bundle(); - b.putString("accountId", status.getAccount().getId()); + if( status.getReblog() == null) + b.putString("accountId", status.getAccount().getId()); + else + b.putString("accountId", status.getReblog().getAccount().getId()); intent.putExtras(b); context.startActivity(intent); } @@ -406,7 +409,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf String url = attachment.getPreview_url(); if( url == null || url.trim().equals("")) url = attachment.getUrl(); - if( url.trim().equals("https://mastodon.etalab.gouv.fr/files/small/missing.png")) + if( url.trim().contains("missing.png")) continue; imageLoader.displayImage(url, imageView, options); imageView.setOnClickListener(new View.OnClickListener() { 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 9d44598cf..c46601da2 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 @@ -51,6 +51,8 @@ public class SettingsNotificationsFragment extends Fragment { boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true); boolean notif_wifi = sharedpreferences.getBoolean(Helper.SET_WIFI_ONLY, false); + boolean notif_silent = sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT, false); + boolean notif_hometimeline = sharedpreferences.getBoolean(Helper.SET_NOTIF_HOMETIMELINE, true); final CheckBox set_notif_follow = (CheckBox) rootView.findViewById(R.id.set_notif_follow); final CheckBox set_notif_follow_add = (CheckBox) rootView.findViewById(R.id.set_notif_follow_add); @@ -58,7 +60,9 @@ public class SettingsNotificationsFragment extends Fragment { final CheckBox set_notif_follow_mention = (CheckBox) rootView.findViewById(R.id.set_notif_follow_mention); final CheckBox set_notif_follow_share = (CheckBox) rootView.findViewById(R.id.set_notif_follow_share); final CheckBox set_share_validation = (CheckBox) rootView.findViewById(R.id.set_share_validation); + final CheckBox set_notif_hometimeline = (CheckBox) rootView.findViewById(R.id.set_notif_hometimeline); final SwitchCompat switchCompatWIFI = (SwitchCompat) rootView.findViewById(R.id.set_wifi_only); + final SwitchCompat switchCompatSilent = (SwitchCompat) rootView.findViewById(R.id.set_silence); set_notif_follow.setChecked(notif_follow); set_notif_follow_add.setChecked(notif_add); @@ -66,9 +70,18 @@ public class SettingsNotificationsFragment extends Fragment { set_notif_follow_mention.setChecked(notif_mention); set_notif_follow_share.setChecked(notif_share); set_share_validation.setChecked(notif_validation); + set_notif_hometimeline.setChecked(notif_hometimeline); switchCompatWIFI.setChecked(notif_wifi); + switchCompatSilent.setChecked(notif_silent); - + set_notif_hometimeline.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_NOTIF_HOMETIMELINE, set_notif_hometimeline.isChecked()); + editor.apply(); + } + }); set_notif_follow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -128,7 +141,15 @@ public class SettingsNotificationsFragment extends Fragment { } }); - + switchCompatSilent.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_NOTIF_SILENT, isChecked); + editor.apply(); + } + }); return rootView; } 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 32bdc16e5..c3ad89c7f 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 @@ -99,6 +99,7 @@ public class Helper { public static final String SET_NOTIF_SHARE = "set_notif_follow_share"; public static final String SET_NOTIF_VALIDATION = "set_share_validation"; public static final String SET_WIFI_ONLY = "set_wifi_only"; + public static final String SET_NOTIF_HOMETIMELINE = "set_notif_hometimeline"; public static final String SET_NOTIF_SILENT = "set_notif_silent"; //End points diff --git a/app/src/main/res/layout/fragment_settings_notifications.xml b/app/src/main/res/layout/fragment_settings_notifications.xml index fdadadddd..4872e10e3 100644 --- a/app/src/main/res/layout/fragment_settings_notifications.xml +++ b/app/src/main/res/layout/fragment_settings_notifications.xml @@ -69,7 +69,20 @@ android:layout_height="wrap_content" /> - + + + + - + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b2980938..0cf981ee3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -183,6 +183,8 @@ Notifier en WIFI seulement Utiliser le vibreur + Actualités + Notifier lors de nouveaux pouets sur le fil local Suivre Se désabonner