Silent notifications + Displays profile of the original toot owner when shared.

Prepares notifications service for new toots in home timeline.
This commit is contained in:
tom79 2017-05-20 10:14:10 +02:00
parent 529cef7777
commit 4c3b64e744
6 changed files with 66 additions and 9 deletions

View File

@ -331,8 +331,7 @@ public class API {
limit = 40; limit = 40;
params.put("limit",String.valueOf(limit)); params.put("limit",String.valueOf(limit));
statuses = new ArrayList<>(); statuses = new ArrayList<>();
get("/timelines/home", params, new JsonHttpResponseHandler() {
get(String.format("/accounts/%s/statuses",userId), params, new JsonHttpResponseHandler() {
@Override @Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 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) { 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); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT); client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);

View File

@ -332,7 +332,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(context, ShowAccountActivity.class); Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle(); 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); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);
} }
@ -406,7 +409,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
String url = attachment.getPreview_url(); String url = attachment.getPreview_url();
if( url == null || url.trim().equals("")) if( url == null || url.trim().equals(""))
url = attachment.getUrl(); url = attachment.getUrl();
if( url.trim().equals("https://mastodon.etalab.gouv.fr/files/small/missing.png")) if( url.trim().contains("missing.png"))
continue; continue;
imageLoader.displayImage(url, imageView, options); imageLoader.displayImage(url, imageView, options);
imageView.setOnClickListener(new View.OnClickListener() { imageView.setOnClickListener(new View.OnClickListener() {

View File

@ -51,6 +51,8 @@ public class SettingsNotificationsFragment extends Fragment {
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true); boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
boolean notif_wifi = sharedpreferences.getBoolean(Helper.SET_WIFI_ONLY, false); 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 = (CheckBox) rootView.findViewById(R.id.set_notif_follow);
final CheckBox set_notif_follow_add = (CheckBox) rootView.findViewById(R.id.set_notif_follow_add); 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_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_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_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 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.setChecked(notif_follow);
set_notif_follow_add.setChecked(notif_add); 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_mention.setChecked(notif_mention);
set_notif_follow_share.setChecked(notif_share); set_notif_follow_share.setChecked(notif_share);
set_share_validation.setChecked(notif_validation); set_share_validation.setChecked(notif_validation);
set_notif_hometimeline.setChecked(notif_hometimeline);
switchCompatWIFI.setChecked(notif_wifi); 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() { set_notif_follow.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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; return rootView;
} }

View File

@ -99,6 +99,7 @@ public class Helper {
public static final String SET_NOTIF_SHARE = "set_notif_follow_share"; 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_NOTIF_VALIDATION = "set_share_validation";
public static final String SET_WIFI_ONLY = "set_wifi_only"; 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"; public static final String SET_NOTIF_SILENT = "set_notif_silent";
//End points //End points

View File

@ -69,7 +69,20 @@
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<!-- END NOTIFICATIONS SETTINGS --> <!-- END NOTIFICATIONS SETTINGS -->
<!-- NOTIFICATION CONTENT NEW -->
<TextView
android:text="@string/set_title_news"
android:background="@drawable/shape_border_bottom_settings"
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" />
<!-- MORE OPTIONS SETTINGS --> <!-- MORE OPTIONS SETTINGS -->
<TextView <TextView
android:text="@string/settings_title_more_options" android:text="@string/settings_title_more_options"
@ -105,7 +118,25 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> />
</LinearLayout> </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> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -183,6 +183,8 @@
<string name="set_wifi_only">Notifier en WIFI seulement</string> <string name="set_wifi_only">Notifier en WIFI seulement</string>
<string name="set_notif_silent">Utiliser le vibreur</string> <string name="set_notif_silent">Utiliser le vibreur</string>
<string name="set_title_news">Actualités</string>
<string name="set_notification_news">Notifier lors de nouveaux pouets sur le fil local</string>
<string name="action_follow">Suivre</string> <string name="action_follow">Suivre</string>
<string name="action_unfollow">Se désabonner</string> <string name="action_unfollow">Se désabonner</string>