Start splitting notification Fragment

This commit is contained in:
stom79 2019-02-03 12:07:43 +01:00
parent 8165f53e1c
commit 7e01c841e1
13 changed files with 337 additions and 56 deletions

View File

@ -134,6 +134,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplayPeertubeNotificationsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
import fr.gouv.etalab.mastodon.fragments.SettingsFragment;
import fr.gouv.etalab.mastodon.fragments.SettingsPeertubeFragment;
import fr.gouv.etalab.mastodon.fragments.TabLayoutNotificationsFragment;
import fr.gouv.etalab.mastodon.fragments.TabLayoutScheduleFragment;
import fr.gouv.etalab.mastodon.fragments.TabLayoutSettingsFragment;
import fr.gouv.etalab.mastodon.fragments.WhoToFollowFragment;
@ -703,11 +704,8 @@ public abstract class BaseMainActivity extends BaseActivity
displayStatusFragment.scrollToTop();
displayStatusFragment.updateLastReadToot();
} else if( tab.getPosition() == 1) {
DisplayNotificationsFragment notificationsFragment = ((DisplayNotificationsFragment) fragment);
countNewNotifications = 0;
updateNotifCounter();
notificationsFragment.scrollToTop();
}else if (tab.getPosition() > 1) {
if (typePosition.containsKey(tab.getPosition()))
updateTimeLine(typePosition.get(tab.getPosition()), 0);
@ -761,8 +759,6 @@ public abstract class BaseMainActivity extends BaseActivity
displayStatusFragment.scrollToTop();
break;
case 1:
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
displayNotificationsFragment.scrollToTop();
break;
}
}
@ -2486,8 +2482,8 @@ public abstract class BaseMainActivity extends BaseActivity
homeFragment.setArguments(bundle);
return homeFragment;
} else if (position == 1) {
notificationsFragment = new DisplayNotificationsFragment();
return notificationsFragment;
TabLayoutNotificationsFragment tabLayoutNotificationsFragment = new TabLayoutNotificationsFragment();
return tabLayoutNotificationsFragment;
} else {
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", typePosition.get(position));
@ -2589,7 +2585,7 @@ public abstract class BaseMainActivity extends BaseActivity
if (position == 0) {
homeFragment = (DisplayStatusFragment) createdFragment;
} else if (position == 1) {
notificationsFragment = (DisplayNotificationsFragment) createdFragment;
tabLayoutNotificationsFragment = (TabLayoutNotificationsFragment) createdFragment;
} else {
if (display_local && position == tabPosition.get("local"))
localFragment = (DisplayStatusFragment) createdFragment;

View File

@ -24,6 +24,7 @@ import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Notification;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingNotificationsInterface;
@ -39,18 +40,20 @@ public class RetrieveMissingNotificationsAsyncTask extends AsyncTask<Void, Void,
private OnRetrieveMissingNotificationsInterface listener;
private WeakReference<Context> contextReference;
private List<Notification> notifications;
private DisplayNotificationsFragment.Type type;
public RetrieveMissingNotificationsAsyncTask(Context context, String since_id, OnRetrieveMissingNotificationsInterface onRetrieveMissingNotifications){
public RetrieveMissingNotificationsAsyncTask(Context context, DisplayNotificationsFragment.Type type, String since_id, OnRetrieveMissingNotificationsInterface onRetrieveMissingNotifications){
this.contextReference = new WeakReference<>(context);
this.since_id = since_id;
this.listener = onRetrieveMissingNotifications;
this.type = type;
}
@Override
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
APIResponse apiResponse = api.getNotificationsSince(since_id, 40, false);
APIResponse apiResponse = api.getNotificationsSince(type, since_id, 40, false);
since_id = apiResponse.getSince_id();
notifications = apiResponse.getNotifications();
if( notifications != null && notifications.size() > 0) {

View File

@ -26,6 +26,7 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.GNUAPI;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveNotificationsInterface;
@ -46,14 +47,16 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
private boolean refreshData;
private WeakReference<Context> contextReference;
private boolean display;
private DisplayNotificationsFragment.Type type;
public RetrieveNotificationsAsyncTask(Context context, boolean display, Account account, String max_id, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
public RetrieveNotificationsAsyncTask(Context context, DisplayNotificationsFragment.Type type, boolean display, Account account, String max_id, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
this.contextReference = new WeakReference<>(context);
this.max_id = max_id;
this.listener = onRetrieveNotificationsInterface;
this.account = account;
this.refreshData = true;
this.display = display;
this.type = type;
}
@ -64,27 +67,27 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
API api;
if (account == null) {
api = new API(this.contextReference.get());
apiResponse = api.getNotifications(max_id, display);
apiResponse = api.getNotifications(type, max_id, display);
} else {
if (this.contextReference.get() == null) {
apiResponse.setError(new Error());
return null;
}
api = new API(this.contextReference.get(), account.getInstance(), account.getToken());
apiResponse = api.getNotificationsSince(max_id, display);
apiResponse = api.getNotificationsSince(type, max_id, display);
}
}else{
GNUAPI gnuapi;
if (account == null) {
gnuapi = new GNUAPI(this.contextReference.get());
apiResponse = gnuapi.getNotifications(max_id, display);
apiResponse = gnuapi.getNotifications(type, max_id, display);
} else {
if (this.contextReference.get() == null) {
apiResponse.setError(new Error());
return null;
}
gnuapi = new GNUAPI(this.contextReference.get(), account.getInstance(), account.getToken());
apiResponse = gnuapi.getNotificationsSince(max_id, display);
apiResponse = gnuapi.getNotificationsSince(type, max_id, display);
}
}
return null;

View File

@ -63,6 +63,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Schedule;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.StoredStatus;
import fr.gouv.etalab.mastodon.client.Entities.Tag;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -2043,8 +2044,8 @@ public class API {
* @param since_id String since max
* @return APIResponse
*/
public APIResponse getNotificationsSince(String since_id, boolean display){
return getNotifications(null, since_id, notificationPerPage, display);
public APIResponse getNotificationsSince(DisplayNotificationsFragment.Type type, String since_id, boolean display){
return getNotifications(type, null, since_id, notificationPerPage, display);
}
/**
@ -2053,8 +2054,8 @@ public class API {
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getNotificationsSince(String since_id, int notificationPerPage, boolean display){
return getNotifications(null, since_id, notificationPerPage, display);
public APIResponse getNotificationsSince(DisplayNotificationsFragment.Type type, String since_id, int notificationPerPage, boolean display){
return getNotifications(type, null, since_id, notificationPerPage, display);
}
/**
@ -2062,8 +2063,8 @@ public class API {
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getNotifications(String max_id, boolean display){
return getNotifications(max_id, null, notificationPerPage, display);
public APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, boolean display){
return getNotifications(type, max_id, null, notificationPerPage, display);
}
@ -2074,7 +2075,7 @@ public class API {
* @param limit int limit - max value 40
* @return APIResponse
*/
private APIResponse getNotifications(String max_id, String since_id, int limit, boolean display){
private APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, String since_id, int limit, boolean display){
HashMap<String, String> params = new HashMap<>();
if( max_id != null )
@ -2087,33 +2088,59 @@ public class API {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean notif_follow, notif_add, notif_mention, notif_share;
if( display) {
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);
}else{
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, 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);
}
StringBuilder parameters = new StringBuilder();
if( type == DisplayNotificationsFragment.Type.ALL){
if( display) {
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);
}else{
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, 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);
}
if( !notif_follow )
if( !notif_follow )
parameters.append("exclude_types[]=").append("follow").append("&");
if( !notif_add )
parameters.append("exclude_types[]=").append("favourite").append("&");
if( !notif_share )
parameters.append("exclude_types[]=").append("reblog").append("&");
if( !notif_mention )
parameters.append("exclude_types[]=").append("mention").append("&");
if( parameters.length() > 0) {
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
params.put("exclude_types[]", parameters.toString());
}
}else if(type == DisplayNotificationsFragment.Type.MENTION){
parameters.append("exclude_types[]=").append("follow").append("&");
parameters.append("exclude_types[]=").append("favourite").append("&");
parameters.append("exclude_types[]=").append("reblog").append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
params.put("exclude_types[]", parameters.toString());
}else if(type == DisplayNotificationsFragment.Type.FAVORITE){
parameters.append("exclude_types[]=").append("follow").append("&");
if( !notif_add )
parameters.append("exclude_types[]=").append("favourite").append("&");
if( !notif_share )
parameters.append("exclude_types[]=").append("reblog").append("&");
if( !notif_mention )
parameters.append("exclude_types[]=").append("mention").append("&");
if( parameters.length() > 0) {
parameters.append("exclude_types[]=").append("reblog").append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
params.put("exclude_types[]", parameters.toString());
}else if(type == DisplayNotificationsFragment.Type.BOOST){
parameters.append("exclude_types[]=").append("follow").append("&");
parameters.append("exclude_types[]=").append("mention").append("&");
parameters.append("exclude_types[]=").append("favourite").append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
params.put("exclude_types[]", parameters.toString());
}else if(type == DisplayNotificationsFragment.Type.FOLLOW){
parameters.append("exclude_types[]=").append("reblog").append("&");
parameters.append("exclude_types[]=").append("mention").append("&");
parameters.append("exclude_types[]=").append("favourite").append("&");
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
params.put("exclude_types[]", parameters.toString());
}
List<Notification> notifications = new ArrayList<>();
try {

View File

@ -50,6 +50,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Notification;
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -1460,8 +1461,8 @@ public class GNUAPI {
* @param since_id String since max
* @return APIResponse
*/
public APIResponse getNotificationsSince(String since_id, boolean display){
return getNotifications(null, since_id, notificationPerPage, display);
public APIResponse getNotificationsSince(DisplayNotificationsFragment.Type type, String since_id, boolean display){
return getNotifications(type, null, since_id, notificationPerPage, display);
}
/**
@ -1470,8 +1471,8 @@ public class GNUAPI {
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getNotificationsSince(String since_id, int notificationPerPage, boolean display){
return getNotifications(null, since_id, notificationPerPage, display);
public APIResponse getNotificationsSince(DisplayNotificationsFragment.Type type, String since_id, int notificationPerPage, boolean display){
return getNotifications(type, null, since_id, notificationPerPage, display);
}
/**
@ -1479,8 +1480,8 @@ public class GNUAPI {
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getNotifications(String max_id, boolean display){
return getNotifications(max_id, null, notificationPerPage, display);
public APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, boolean display){
return getNotifications(type, max_id, null, notificationPerPage, display);
}
@ -1491,7 +1492,7 @@ public class GNUAPI {
* @param limit int limit - max value 40
* @return APIResponse
*/
private APIResponse getNotifications(String max_id, String since_id, int limit, boolean display){
private APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, String since_id, int limit, boolean display){
HashMap<String, String> params = new HashMap<>();
if( max_id != null )

View File

@ -84,6 +84,16 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
public DisplayNotificationsFragment(){
}
public enum Type{
ALL,
MENTION,
FAVORITE,
BOOST,
FOLLOW
}
Type type;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -96,7 +106,10 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
swiped = false;
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
Bundle bundle = this.getArguments();
if (bundle != null) {
type = (Type) bundle.get("type");
}
lv_notifications = rootView.findViewById(R.id.lv_notifications);
mainLoader = rootView.findViewById(R.id.loader);
@ -122,7 +135,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if (!flag_loading) {
flag_loading = true;
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveNotificationsAsyncTask(context, type,true, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
@ -184,7 +197,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
if( notifications != null && notifications.size() > 0 )
sinceId = notifications.get(0).getId();
if( context != null)
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, sinceId, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, type, sinceId, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -210,13 +223,13 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
break;
}
if( context != null)
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveNotificationsAsyncTask(context, type,true, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if( context != null)
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveNotificationsAsyncTask(context, type,true, null, max_id, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}, 500);
return rootView;
@ -316,7 +329,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
* @param sinceId String
*/
public void retrieveMissingNotifications(String sinceId){
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, sinceId, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, type, sinceId, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
@ -348,7 +361,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
flag_loading = true;
swiped = true;
MainActivity.countNewNotifications = 0;
asyncTask = new RetrieveNotificationsAsyncTask(context, true, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveNotificationsAsyncTask(context, type,true, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

View File

@ -0,0 +1,200 @@
package fr.gouv.etalab.mastodon.fragments;
/* Copyright 2017 Thomas Schneider
*
* This file is a part of Mastalab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.helper.Helper;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
/**
* Created by Thomas on 03/02/2019.
* Tablayout for notifications
*/
public class TabLayoutNotificationsFragment extends Fragment {
private Context context;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
context = getContext();
View inflatedView = inflater.inflate(R.layout.tablayout_settings, container, false);
TabLayout tabLayout = inflatedView.findViewById(R.id.tabLayout);
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.all)));
TabLayout.Tab tabMention = tabLayout.newTab();
TabLayout.Tab tabFav = tabLayout.newTab();
TabLayout.Tab tabBoost = tabLayout.newTab();
TabLayout.Tab tabFollow = tabLayout.newTab();
tabMention.setCustomView(R.layout.tab_badge);
tabFav.setCustomView(R.layout.tab_badge);
tabBoost.setCustomView(R.layout.tab_badge);
tabFollow.setCustomView(R.layout.tab_badge);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
ImageView iconMention = tabMention.getCustomView().findViewById(R.id.tab_icon);
iconMention.setImageResource(R.drawable.ic_mention_notif_tab);
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
ImageView iconFav = tabMention.getCustomView().findViewById(R.id.tab_icon);
iconFav.setImageResource(R.drawable.ic_star_notif_tab);
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
ImageView iconBoost = tabMention.getCustomView().findViewById(R.id.tab_icon);
iconBoost.setImageResource(R.drawable.ic_repeat_notif_tab);
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
ImageView iconFollow = tabMention.getCustomView().findViewById(R.id.tab_icon);
iconFollow.setImageResource(R.drawable.ic_follow_notif_tab);
if (theme == THEME_BLACK)
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.dark_icon), PorterDuff.Mode.SRC_IN);
else
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.mastodonC4), PorterDuff.Mode.SRC_IN);
if (theme == THEME_LIGHT) {
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
iconFollow.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
} else {
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
iconFollow.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
}
final ViewPager viewPager = inflatedView.findViewById(R.id.viewpager);
viewPager.setAdapter(new PagerAdapter
(getChildFragmentManager(), tabLayout.getTabCount()));
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
return inflatedView;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
}
/**
* Page Adapter for settings
*/
private class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
private PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
@Override
public Fragment getItem(int position) {
DisplayNotificationsFragment displayNotificationsFragment = new DisplayNotificationsFragment();
DisplayNotificationsFragment.Type type = null;
switch (position) {
case 0:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
type = DisplayNotificationsFragment.Type.ALL;
else
type = DisplayNotificationsFragment.Type.MENTION;
break;
case 1:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
type = DisplayNotificationsFragment.Type.MENTION;
else
type = DisplayNotificationsFragment.Type.FAVORITE;
break;
case 2:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
type = DisplayNotificationsFragment.Type.FAVORITE;
else
type = DisplayNotificationsFragment.Type.BOOST;
break;
case 3:
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
type = DisplayNotificationsFragment.Type.BOOST;
else
type = DisplayNotificationsFragment.Type.FOLLOW;
break;
case 4:
type = DisplayNotificationsFragment.Type.FOLLOW;
break;
default:
break;
}
Bundle bundle = new Bundle();
bundle.putSerializable("type", type);
displayNotificationsFragment.setArguments(bundle);
return displayNotificationsFragment;
}
@Override
public int getCount() {
return mNumOfTabs;
}
}
}

View File

@ -47,6 +47,7 @@ import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Notification;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -133,7 +134,7 @@ public class NotificationsSyncJob extends Job {
for (Account account: accounts) {
if( account.getSocial() == null || account.getSocial().equals("MASTODON")|| account.getSocial().equals("PLEROMA")) {
API api = new API(getContext(), account.getInstance(), account.getToken());
APIResponse apiResponse = api.getNotificationsSince(null, false);
APIResponse apiResponse = api.getNotificationsSince(DisplayNotificationsFragment.Type.ALL, null, false);
onRetrieveNotifications(apiResponse, account);
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M20,2H4c-1.1,0 -2,0.9 -2,2v18l4,-4h14c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>

View File

@ -868,6 +868,7 @@
<string name="action_markdown">Markdown</string>
<string name="action_logout_account">Logout account</string>
<string name="set_optimize_loading">Optimize loading time</string>
<string name="all">All</string>
<!-- end languages -->