Fixes notifications issues (filter no longer shared between push & displayed)
This commit is contained in:
parent
7394b4e93b
commit
14f30faa11
|
@ -241,10 +241,10 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
||||||
final MenuItem itemFollow = menu.findItem(R.id.action_follow);
|
final MenuItem itemFollow = menu.findItem(R.id.action_follow);
|
||||||
final MenuItem itemMention = menu.findItem(R.id.action_mention);
|
final MenuItem itemMention = menu.findItem(R.id.action_mention);
|
||||||
final MenuItem itemBoost = menu.findItem(R.id.action_boost);
|
final MenuItem itemBoost = menu.findItem(R.id.action_boost);
|
||||||
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, true);
|
||||||
notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD_FILTER, true);
|
||||||
notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION_FILTER, true);
|
||||||
notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE_FILTER, true);
|
||||||
itemFavourite.setChecked(notif_add);
|
itemFavourite.setChecked(notif_add);
|
||||||
itemFollow.setChecked(notif_follow);
|
itemFollow.setChecked(notif_follow);
|
||||||
itemMention.setChecked(notif_mention);
|
itemMention.setChecked(notif_mention);
|
||||||
|
@ -275,28 +275,28 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
||||||
case R.id.action_favorite:
|
case R.id.action_favorite:
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
notif_add = !notif_add;
|
notif_add = !notif_add;
|
||||||
editor.putBoolean(Helper.SET_NOTIF_ADD, notif_add);
|
editor.putBoolean(Helper.SET_NOTIF_ADD_FILTER, notif_add);
|
||||||
itemFavourite.setChecked(notif_add);
|
itemFavourite.setChecked(notif_add);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
break;
|
break;
|
||||||
case R.id.action_follow:
|
case R.id.action_follow:
|
||||||
editor = sharedpreferences.edit();
|
editor = sharedpreferences.edit();
|
||||||
notif_follow = !notif_follow;
|
notif_follow = !notif_follow;
|
||||||
editor.putBoolean(Helper.SET_NOTIF_FOLLOW, notif_follow);
|
editor.putBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, notif_follow);
|
||||||
itemFollow.setChecked(notif_follow);
|
itemFollow.setChecked(notif_follow);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
break;
|
break;
|
||||||
case R.id.action_mention:
|
case R.id.action_mention:
|
||||||
editor = sharedpreferences.edit();
|
editor = sharedpreferences.edit();
|
||||||
notif_mention = !notif_mention;
|
notif_mention = !notif_mention;
|
||||||
editor.putBoolean(Helper.SET_NOTIF_MENTION, notif_mention);
|
editor.putBoolean(Helper.SET_NOTIF_MENTION_FILTER, notif_mention);
|
||||||
itemMention.setChecked(notif_mention);
|
itemMention.setChecked(notif_mention);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
break;
|
break;
|
||||||
case R.id.action_boost:
|
case R.id.action_boost:
|
||||||
editor = sharedpreferences.edit();
|
editor = sharedpreferences.edit();
|
||||||
notif_share = !notif_share;
|
notif_share = !notif_share;
|
||||||
editor.putBoolean(Helper.SET_NOTIF_SHARE, notif_share);
|
editor.putBoolean(Helper.SET_NOTIF_SHARE_FILTER, notif_share);
|
||||||
itemBoost.setChecked(notif_share);
|
itemBoost.setChecked(notif_share);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
|
||||||
API api = new API(this.contextReference.get());
|
API api = new API(this.contextReference.get());
|
||||||
List<Notification> tempNotifications;
|
List<Notification> tempNotifications;
|
||||||
while (loopInc < 10){
|
while (loopInc < 10){
|
||||||
APIResponse apiResponse = api.getNotificationsSince(since_id, 40);
|
APIResponse apiResponse = api.getNotificationsSince(since_id, 40, false);
|
||||||
String max_id = apiResponse.getMax_id();
|
String max_id = apiResponse.getMax_id();
|
||||||
since_id = apiResponse.getSince_id();
|
since_id = apiResponse.getSince_id();
|
||||||
tempNotifications = apiResponse.getNotifications();
|
tempNotifications = apiResponse.getNotifications();
|
||||||
|
|
|
@ -40,8 +40,9 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
||||||
private String token;
|
private String token;
|
||||||
private boolean refreshData;
|
private boolean refreshData;
|
||||||
private WeakReference<Context> contextReference;
|
private WeakReference<Context> contextReference;
|
||||||
|
private boolean display;
|
||||||
|
|
||||||
public RetrieveNotificationsAsyncTask(Context context, String instance, String token, String max_id, String acct, String userId, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
|
public RetrieveNotificationsAsyncTask(Context context, boolean display, String instance, String token, String max_id, String acct, String userId, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
|
||||||
this.contextReference = new WeakReference<>(context);
|
this.contextReference = new WeakReference<>(context);
|
||||||
this.max_id = max_id;
|
this.max_id = max_id;
|
||||||
this.listener = onRetrieveNotificationsInterface;
|
this.listener = onRetrieveNotificationsInterface;
|
||||||
|
@ -50,6 +51,7 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.refreshData = true;
|
this.refreshData = true;
|
||||||
|
this.display = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,9 +60,9 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
||||||
|
|
||||||
API api = new API(this.contextReference.get(), instance, token);
|
API api = new API(this.contextReference.get(), instance, token);
|
||||||
if( acct == null)
|
if( acct == null)
|
||||||
apiResponse = api.getNotifications(max_id);
|
apiResponse = api.getNotifications(max_id, display);
|
||||||
else
|
else
|
||||||
apiResponse = api.getNotificationsSince(max_id);
|
apiResponse = api.getNotificationsSince(max_id, display);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1187,8 +1187,8 @@ public class API {
|
||||||
* @param since_id String since max
|
* @param since_id String since max
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse getNotificationsSince(String since_id){
|
public APIResponse getNotificationsSince(String since_id, boolean display){
|
||||||
return getNotifications(null, since_id, notificationPerPage);
|
return getNotifications(null, since_id, notificationPerPage, display);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1196,8 +1196,8 @@ public class API {
|
||||||
* @param since_id String since max
|
* @param since_id String since max
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse getNotificationsSince(String since_id, int notificationPerPage){
|
public APIResponse getNotificationsSince(String since_id, int notificationPerPage, boolean display){
|
||||||
return getNotifications(null, since_id, notificationPerPage);
|
return getNotifications(null, since_id, notificationPerPage, display);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1205,8 +1205,8 @@ public class API {
|
||||||
* @param max_id String id max
|
* @param max_id String id max
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
public APIResponse getNotifications(String max_id){
|
public APIResponse getNotifications(String max_id, boolean display){
|
||||||
return getNotifications(max_id, null, notificationPerPage);
|
return getNotifications(max_id, null, notificationPerPage, display);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrieves notifications for the authenticated account *synchronously*
|
* Retrieves notifications for the authenticated account *synchronously*
|
||||||
|
@ -1215,7 +1215,7 @@ public class API {
|
||||||
* @param limit int limit - max value 40
|
* @param limit int limit - max value 40
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
*/
|
*/
|
||||||
private APIResponse getNotifications(String max_id, String since_id, int limit){
|
private APIResponse getNotifications(String max_id, String since_id, int limit, boolean display){
|
||||||
|
|
||||||
RequestParams params = new RequestParams();
|
RequestParams params = new RequestParams();
|
||||||
if( max_id != null )
|
if( max_id != null )
|
||||||
|
@ -1227,10 +1227,18 @@ public class API {
|
||||||
params.put("limit",String.valueOf(limit));
|
params.put("limit",String.valueOf(limit));
|
||||||
|
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
boolean notif_follow, notif_add, notif_mention, notif_share;
|
||||||
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
if( !display) {
|
||||||
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
||||||
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
||||||
|
notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||||
|
notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
||||||
|
}else {
|
||||||
|
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, true);
|
||||||
|
notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD_FILTER, true);
|
||||||
|
notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION_FILTER, true);
|
||||||
|
notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE_FILTER, true);
|
||||||
|
}
|
||||||
if( !notif_follow )
|
if( !notif_follow )
|
||||||
params.add("exclude_types[]", "follow");
|
params.add("exclude_types[]", "follow");
|
||||||
if( !notif_add )
|
if( !notif_add )
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||||
if (!flag_loading) {
|
if (!flag_loading) {
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
nextElementLoader.setVisibility(View.VISIBLE);
|
nextElementLoader.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -125,14 +125,14 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
MainActivity.countNewNotifications = 0;
|
MainActivity.countNewNotifications = 0;
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
|
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
|
||||||
R.color.mastodonC2,
|
R.color.mastodonC2,
|
||||||
R.color.mastodonC3);
|
R.color.mastodonC3);
|
||||||
|
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
|
@ -251,7 +251,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = true;
|
swiped = true;
|
||||||
MainActivity.countNewNotifications = 0;
|
MainActivity.countNewNotifications = 0;
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,11 @@ public class Helper {
|
||||||
public static final String SET_NOTIF_ASK = "set_notif_follow_ask";
|
public static final String SET_NOTIF_ASK = "set_notif_follow_ask";
|
||||||
public static final String SET_NOTIF_MENTION = "set_notif_follow_mention";
|
public static final String SET_NOTIF_MENTION = "set_notif_follow_mention";
|
||||||
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_FOLLOW_FILTER = "set_notif_follow_filter";
|
||||||
|
public static final String SET_NOTIF_ADD_FILTER = "set_notif_follow_add_filter";
|
||||||
|
public static final String SET_NOTIF_MENTION_FILTER = "set_notif_follow_mention_filter";
|
||||||
|
public static final String SET_NOTIF_SHARE_FILTER = "set_notif_follow_share_filter";
|
||||||
|
|
||||||
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_NOTIF_VALIDATION_FAV = "set_share_validation_fav";
|
public static final String SET_NOTIF_VALIDATION_FAV = "set_share_validation_fav";
|
||||||
public static final String SET_WIFI_ONLY = "set_wifi_only";
|
public static final String SET_WIFI_ONLY = "set_wifi_only";
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
||||||
//Retrieve users in db that owner has.
|
//Retrieve users in db that owner has.
|
||||||
for (Account account: accounts) {
|
for (Account account: accounts) {
|
||||||
String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null);
|
String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null);
|
||||||
new RetrieveNotificationsAsyncTask(getContext(), account.getInstance(), account.getToken(), max_id, account.getAcct(), account.getId(), NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new RetrieveNotificationsAsyncTask(getContext(), false, account.getInstance(), account.getToken(), max_id, account.getAcct(), account.getId(), NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue