From d222ab3ff2743973084abfc101ac487eb6806f71 Mon Sep 17 00:00:00 2001 From: tom79 Date: Mon, 28 Aug 2017 15:30:15 +0200 Subject: [PATCH] Changes methods in fragment and mainactivity --- .../activities/MainActivity.java | 26 ++-- .../asynctasks/RetrieveFeedsAsyncTask.java | 27 ---- .../RetrieveNotificationsAsyncTask.java | 23 ---- .../client/Entities/Notification.java | 2 + .../DisplayNotificationsFragment.java | 107 +++------------ .../fragments/DisplayStatusFragment.java | 124 ++---------------- .../mastodon/fragments/SettingsFragment.java | 13 -- .../gouv/etalab/mastodon/helper/Helper.java | 5 - .../res/layout-sw600dp/fragment_settings.xml | 5 - app/src/main/res/layout/fragment_settings.xml | 5 - .../activities/MainActivity.java | 76 ++++------- 11 files changed, 66 insertions(+), 347 deletions(-) diff --git a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 470b2d400..f7bb0cfd6 100644 --- a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -120,15 +120,17 @@ public class MainActivity extends AppCompatActivity private DisplayStatusFragment homeFragment; private DisplayNotificationsFragment notificationsFragment; private BroadcastReceiver receive_data; - + private int newNotif, newHome; public MainActivity() { } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA)); + newNotif = 0; + newHome = 0; + final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); @@ -205,7 +207,6 @@ public class MainActivity extends AppCompatActivity (getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); - final boolean bubbles = sharedpreferences.getBoolean(Helper.SET_BUBBLE_COUNTER, true); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { @@ -230,12 +231,14 @@ public class MainActivity extends AppCompatActivity fragmentTag = "HOME_TIMELINE"; if( bubbles && homeFragment != null) homeFragment.refreshData(); - updateHomeCounter(0); + newHome = 0; + updateHomeCounter(); break; case 1: fragmentTag = "NOTIFICATIONS"; item = navigationView.getMenu().findItem(R.id.nav_notification); - updateNotifCounter(0); + newNotif = 0; + updateNotifCounter(); if( bubbles && notificationsFragment != null) notificationsFragment.refreshData(); break; @@ -1043,7 +1046,7 @@ public class MainActivity extends AppCompatActivity } } - public void updateHomeCounter(int newHomeCount){ + public void updateHomeCounter(){ if( tabLayout.getTabAt(0) == null ) return; //noinspection ConstantConditions @@ -1051,8 +1054,8 @@ public class MainActivity extends AppCompatActivity if( tabHome == null) return; TextView tabCounterHome = (TextView) tabHome.findViewById(R.id.tab_counter); - tabCounterHome.setText(String.valueOf(newHomeCount)); - if( newHomeCount > 0){ + tabCounterHome.setText(String.valueOf(newHome)); + if( newHome > 0){ //New data are available //The fragment is not displayed, so the counter is displayed if( tabLayout.getSelectedTabPosition() != 0) @@ -1064,8 +1067,7 @@ public class MainActivity extends AppCompatActivity } } - - public void updateNotifCounter(int newNotifCount){ + public void updateNotifCounter(){ if(tabLayout.getTabAt(1) == null) return; //noinspection ConstantConditions @@ -1073,8 +1075,8 @@ public class MainActivity extends AppCompatActivity if( tabNotif == null) return; TextView tabCounterNotif = (TextView) tabNotif.findViewById(R.id.tab_counter); - tabCounterNotif.setText(String.valueOf(newNotifCount)); - if( newNotifCount > 0){ + tabCounterNotif.setText(String.valueOf(newNotif)); + if( newNotif > 0){ if( tabLayout.getSelectedTabPosition() != 1) tabCounterNotif.setVisibility(View.VISIBLE); else diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index 4c913630e..8763a5587 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -15,14 +15,9 @@ package fr.gouv.etalab.mastodon.asynctasks; import android.content.Context; -import android.content.SharedPreferences; import android.os.AsyncTask; - -import java.util.Date; - import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; -import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; @@ -61,8 +56,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { this.max_id = max_id; this.listener = onRetrieveFeedsInterface; this.refreshData = true; - updateTimeRefresh(); - } public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, OnRetrieveFeedsInterface onRetrieveFeedsInterface){ @@ -73,7 +66,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { this.targetedID = targetedID; this.showMediaOnly = showMediaOnly; this.refreshData = true; - updateTimeRefresh(); } public RetrieveFeedsAsyncTask(Context context, Type action, String tag, String targetedID, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){ this.context = context; @@ -83,17 +75,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { this.targetedID = targetedID; this.tag = tag; this.refreshData = true; - updateTimeRefresh(); } - public RetrieveFeedsAsyncTask(Context context, Type action, String max_id, boolean refreshData, OnRetrieveFeedsInterface onRetrieveFeedsInterface){ - this.context = context; - this.action = action; - this.max_id = max_id; - this.listener = onRetrieveFeedsInterface; - this.refreshData = refreshData; - updateTimeRefresh(); - } @Override protected Void doInBackground(Void... params) { @@ -134,14 +117,4 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { protected void onPostExecute(Void result) { listener.onRetrieveFeeds(apiResponse, refreshData); } - - private void updateTimeRefresh(){ - if( action == Type.HOME) { - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedpreferences.edit(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - editor.putString(Helper.LAST_BUBBLE_REFRESH_HOME + userId, Helper.dateToString(context, new Date())); - editor.apply(); - } - } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java index e59bb8417..6b7a8b7c6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveNotificationsAsyncTask.java @@ -15,14 +15,9 @@ package fr.gouv.etalab.mastodon.asynctasks; import android.content.Context; -import android.content.SharedPreferences; import android.os.AsyncTask; - -import java.util.Date; - import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; -import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveNotificationsInterface; @@ -51,20 +46,8 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask this.userId = userId; this.token = token; this.refreshData = true; - updateTimeRefresh(); } - public RetrieveNotificationsAsyncTask(Context context, String instance, String token, String max_id, String acct, String userId, boolean refreshData, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){ - this.context = context; - this.max_id = max_id; - this.listener = onRetrieveNotificationsInterface; - this.acct = acct; - this.instance = instance; - this.userId = userId; - this.token = token; - this.refreshData = refreshData; - updateTimeRefresh(); - } @Override protected Void doInBackground(Void... params) { @@ -82,10 +65,4 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask listener.onRetrieveNotifications(apiResponse, acct, userId, refreshData); } - private void updateTimeRefresh(){ - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_BUBBLE_REFRESH_NOTIF+ userId,Helper.dateToString(context, new Date())); - editor.apply(); - } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Notification.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Notification.java index 384ede022..c415088dc 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Notification.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Notification.java @@ -39,6 +39,8 @@ public class Notification implements Parcelable { status = in.readParcelable(Status.class.getClassLoader()); } + public Notification(){}; + public static final Creator CREATOR = new Creator() { @Override public Notification createFromParcel(Parcel in) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java index 6823f340b..d276e9b48 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java @@ -37,6 +37,7 @@ import java.util.List; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; @@ -145,13 +146,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve for(Notification notification: notificationsTmp){ notifications.add(notification); } - //The user clicked on the banner to refresh values so, the pointer is changed - if( notificationsTmp.size() > 0 ) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - editor.putString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, notificationsTmp.get(0).getId()); - editor.apply(); - } notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications); lv_notifications.setAdapter(notificationsListAdapter); if( notificationsTmp.size() > 0 && textviewNoAction.getVisibility() == View.VISIBLE) @@ -205,64 +199,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve return; } SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_BUBBLE_REFRESH_NOTIF+ userId,Helper.dateToString(context, new Date())); - editor.apply(); - String bubble_max_id = sharedpreferences.getString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, null); List notifications = apiResponse.getNotifications(); since_id = apiResponse.getSince_id(); max_id = apiResponse.getMax_id(); //The initial call comes from a classic tab refresh - if( refreshData ) { - manageNotifications(notifications, max_id, since_id); - //The current tab is displayed, so user is supposed to have seen the notifications - if( since_id != null && displayNotificationsFragment.getUserVisibleHint() && firstLoad) { - editor.putString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, since_id); - editor.apply(); - }else if(!displayNotificationsFragment.getUserVisibleHint()){ - //The refresh was done automatically, but the fragment was not displayed in viewpager - //So the bubble counter will be displayed - int countData = 0; - //Retrieves new notification count - if( bubble_max_id != null) { - for (Notification nt : notifications) { - if (nt.getId().trim().equals(bubble_max_id.trim())) - break; - countData++; - } - } - ((MainActivity)context).updateNotifCounter(countData); - } - }else { //Here, new values have been retrieved on the onResume call (forced mode) - int countData = 0; - if( bubble_max_id != null) { - for (Notification nt : notifications) { - if (nt.getId().trim().equals(bubble_max_id.trim())) - break; - countData++; - } - } - if( notifications != null && notifications.size() > 0 && countData > 0) { - max_id = null; - firstLoad = true; - notificationsTmp = new ArrayList<>(); - for (Notification tmpNotification : notifications) { - this.notificationsTmp.add(tmpNotification); - } - //New notifications will be counted - //The fragment is not displayed, so the bubble counter should be shown - if (!displayNotificationsFragment.getUserVisibleHint()) { - ((MainActivity) context).updateNotifCounter(countData); - } else { //The current fragment is visible, but for avoiding to populate with new values - // a message will be displayed at the bottom requiring a click to display these new values - new_data.setVisibility(View.VISIBLE); - } - } - } - } - - private void manageNotifications(List notifications, String max_id, String since_id){ flag_loading = (max_id == null ); - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); if( !swiped && firstLoad && (notifications == null || notifications.size() == 0)) textviewNoAction.setVisibility(View.VISIBLE); else @@ -284,11 +225,10 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve //Store last notification id to avoid to notify for those that have been already seen if( notifications != null && notifications.size() > 0) { //acct is null as userId when used in Fragment, data need to be retrieved via shared preferences and db - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); Account currentAccount = new AccountDAO(context, db).getAccountByID(userId); if( currentAccount != null && firstLoad && since_id != null){ - SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getId(), since_id); editor.apply(); } @@ -296,40 +236,23 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve firstLoad = false; } + public void scrollToTop(){ if( lv_notifications != null) lv_notifications.setAdapter(notificationsListAdapter); } - public void update(){ - if( context != null){ - asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, null, null, null, false, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + public void updateData(Notification notification){ + if( notificationsTmp != null && notificationsTmp.size() > 0){ + notificationsTmp.add(0,notification); + }else { + notificationsTmp = new ArrayList<>(); + for(Notification notificationTmp: this.notifications){ + notificationsTmp.add(notificationTmp); + } + notificationsTmp.add(0,notification); } - } - - public void refreshData(){ - - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - - if(context != null && this.notificationsTmp != null && this.notificationsTmp.size() > 0){ - boolean isOnWifi = Helper.isOnWIFI(context); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - notifications = new ArrayList<>(); - for(Notification notification: this.notificationsTmp){ - notifications.add(notification); - } - if( textviewNoAction.getVisibility() == View.VISIBLE) - textviewNoAction.setVisibility(View.GONE); - notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications); - lv_notifications.setAdapter(notificationsListAdapter); - this.notificationsTmp = new ArrayList<>(); - } - if( since_id != null){ - //The user clicked on the tab to refresh values so, the pointer is changed - SharedPreferences.Editor editor = sharedpreferences.edit(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - editor.putString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, since_id); - editor.apply(); - } - } + new_data.setVisibility(View.VISIBLE); + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 3aa2e1e6b..f3df16cab 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -229,13 +229,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn for(Status status: statusesTmp){ statuses.add(status); } - //The user clicked on the banner to refresh values so, the pointer is changed - if( statusesTmp.size() > 0 ) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - editor.putString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, statusesTmp.get(0).getId()); - editor.apply(); - } if( statusesTmp.size() > 0 && textviewNoAction.getVisibility() == View.VISIBLE) textviewNoAction.setVisibility(View.GONE); statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses); @@ -271,11 +264,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn for(Status status: statusesTmp){ statuses.add(status); } - //The user clicked on the tab to refresh values so, the pointer is changed - SharedPreferences.Editor editor = sharedpreferences.edit(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - editor.putString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, statusesTmp.get(0).getId()); - editor.apply(); statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses); lv_status.setAdapter(statusListAdapter); statusesTmp = new ArrayList<>(); @@ -315,72 +303,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn List statuses = apiResponse.getStatuses(); since_id = apiResponse.getSince_id(); max_id = apiResponse.getMax_id(); - //Special case for home timeline - if( type == RetrieveFeedsAsyncTask.Type.HOME){ - //Retrieves some values - SharedPreferences.Editor editor = sharedpreferences.edit(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - String bubble_max_id = sharedpreferences.getString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, null); - //The initial call comes from a classic tab refresh - if( refreshData ) { - - manageStatus(statuses, max_id, since_id); - //The current tab is displayed, so user is supposed to have seen status - if( since_id != null && displayStatusFragment.getUserVisibleHint() && firstLoad) { - editor.putString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, since_id); - editor.apply(); - }else if(!displayStatusFragment.getUserVisibleHint()){ - //Current fragment was loaded but not displayed to the user. - //So the bubble counter will be displayed - int countData = 0; - //Retrieves new status count - if( bubble_max_id != null) { - for (Status st : statuses) { - if (st.getId().trim().equals(bubble_max_id.trim())) - break; - countData++; - } - } - ((MainActivity)context).updateHomeCounter(countData); - } - }else { //Here, new values have been retrieved on the onResume call (forced mode) - int countData = 0; - if( bubble_max_id != null) { - for (Status st : statuses) { - if (st.getId().trim().equals(bubble_max_id.trim())) - break; - countData++; - } - } - - if( statuses != null && statuses.size() > 0 && countData > 0) { - max_id = null; - firstLoad = true; - statusesTmp = new ArrayList<>(); - for (Status tmpStatus : statuses) { - this.statusesTmp.add(tmpStatus); - } - //New status will be counted - //The fragment is not displayed, so the bubble counter should be shown - if (!displayStatusFragment.getUserVisibleHint()) { - ((MainActivity) context).updateHomeCounter(countData); - } else { - //The current fragment is visible, but for avoiding to populate with new values - //Values are put in temp and the banned is displayed - new_data.setVisibility(View.VISIBLE); - } - } - } - }else { - manageStatus(statuses, max_id, since_id); - } - - - - } - - private void manageStatus(List statuses, String max_id, String since_id){ flag_loading = (max_id == null ); if( !swiped && firstLoad && (statuses == null || statuses.size() == 0)) textviewNoAction.setVisibility(View.VISIBLE); @@ -401,7 +324,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn //Store last toot id for home timeline to avoid to notify for those that have been already seen if(statuses != null && statuses.size() > 0 && type == RetrieveFeedsAsyncTask.Type.HOME ){ - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); //acct is null when used in Fragment, data need to be retrieved via shared preferences and db String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); @@ -416,7 +338,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn //Retrieves replies if(statuses != null && statuses.size() > 0 && type == RetrieveFeedsAsyncTask.Type.HOME ) { - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true); //Retrieves attached replies to a toot if (showPreview) { @@ -425,6 +346,19 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } } + public void updateData(Status status){ + if( statusesTmp != null && statusesTmp.size() > 0){ + statusesTmp.add(0,status); + }else { + statusesTmp = new ArrayList<>(); + for(Status statusTmp: this.statuses){ + statusesTmp.add(statusTmp); + } + statusesTmp.add(0,status); + } + new_data.setVisibility(View.VISIBLE); + } + public void scrollToTop(){ if( lv_status != null) lv_status.setAdapter(statusListAdapter); @@ -444,36 +378,4 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } statusListAdapter.notifyDataSetChanged(); } - public void update() { - if( context != null) { - asyncTask = new RetrieveFeedsAsyncTask(context, type, null, false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - - public void refreshData(){ - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - if(context != null && this.statusesTmp != null && this.statusesTmp.size() > 0){ - - boolean isOnWifi = Helper.isOnWIFI(context); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); - - statuses = new ArrayList<>(); - for(Status status: statusesTmp){ - statuses.add(status); - } - if( textviewNoAction.getVisibility() == View.VISIBLE) - textviewNoAction.setVisibility(View.GONE); - statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses); - lv_status.setAdapter(statusListAdapter); - statusesTmp = new ArrayList<>(); - } - if( since_id != null){ - //The user clicked on the tab to refresh values so, the pointer is changed - SharedPreferences.Editor editor = sharedpreferences.edit(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - editor.putString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, since_id); - editor.apply(); - } - } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index 2783602f9..5907cb623 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -94,19 +94,6 @@ public class SettingsFragment extends Fragment { } }); - boolean bubble_counter = sharedpreferences.getBoolean(Helper.SET_BUBBLE_COUNTER, true); - - final CheckBox set_bubble_counter = (CheckBox) rootView.findViewById(R.id.set_bubble_counter); - set_bubble_counter.setChecked(bubble_counter); - set_bubble_counter.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putBoolean(Helper.SET_BUBBLE_COUNTER, set_bubble_counter.isChecked()); - editor.apply(); - } - }); - boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true); final CheckBox set_show_error_messages = (CheckBox) rootView.findViewById(R.id.set_show_error_messages); set_show_error_messages.setChecked(show_error_messages); 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 3419b1cdd..a5f171903 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 @@ -178,10 +178,6 @@ public class Helper { public static final String SHOW_BATTERY_SAVER_MESSAGE = "show_battery_saver_message"; public static final String LAST_NOTIFICATION_MAX_ID = "last_notification_max_id"; public static final String LAST_HOMETIMELINE_MAX_ID = "last_hometimeline_max_id"; - public static final String LAST_BUBBLE_REFRESH_NOTIF = "last_bubble_refresh_notif"; - public static final String LAST_BUBBLE_REFRESH_HOME = "last_bubble_refresh_home"; - public static final String LAST_MAX_ID_BUBBLE_NOTIF = "last_max_id_bubble_notif"; - public static final String LAST_MAX_ID_BUBBLE_HOME = "last_max_id_bubble_home"; public static final String CLIP_BOARD = "clipboard"; //Notifications public static final int NOTIFICATION_INTENT = 1; @@ -205,7 +201,6 @@ public class Helper { public static final String SET_ICON_SIZE = "set_icon_size"; public static final String SET_PREVIEW_REPLIES = "set_preview_replies"; public static final String SET_PREVIEW_REPLIES_PP = "set_preview_replies_pp"; - public static final String SET_BUBBLE_COUNTER = "set_bubble_counter"; public static final String SET_TRANSLATOR = "set_translator"; public static final int ATTACHMENT_ALWAYS = 1; diff --git a/app/src/main/res/layout-sw600dp/fragment_settings.xml b/app/src/main/res/layout-sw600dp/fragment_settings.xml index 73c3fd3d0..9e104537d 100644 --- a/app/src/main/res/layout-sw600dp/fragment_settings.xml +++ b/app/src/main/res/layout-sw600dp/fragment_settings.xml @@ -58,11 +58,6 @@ android:text="@string/set_auto_store_toot" android:layout_height="wrap_content" /> - - = TimeUnit.SECONDS.toMillis(60)) { - - if( notificationsFragment != null ){ - notificationsFragment.update(); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_BUBBLE_REFRESH_NOTIF+ account.getId(),Helper.dateToString(getApplicationContext(), new Date())); - editor.apply(); - } - } - - last_refresh = sharedpreferences.getString(Helper.LAST_BUBBLE_REFRESH_HOME + account.getId(), null); - last_refresh_date = Helper.stringToDate(getApplicationContext(), last_refresh); - - if (last_refresh_date == null || (new Date().getTime() - last_refresh_date.getTime()) >= TimeUnit.SECONDS.toMillis(60)) { - if( homeFragment != null ){ - homeFragment.update(); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_BUBBLE_REFRESH_HOME+ account.getId(),Helper.dateToString(getApplicationContext(), new Date())); - editor.apply(); - } - } - } - } - - public void updateHomeCounter(int newHomeCount){ + public void updateHomeCounter(){ if( tabLayout.getTabAt(0) == null ) return; //noinspection ConstantConditions @@ -1146,8 +1114,8 @@ public class MainActivity extends AppCompatActivity if( tabHome == null) return; TextView tabCounterHome = (TextView) tabHome.findViewById(R.id.tab_counter); - tabCounterHome.setText(String.valueOf(newHomeCount)); - if( newHomeCount > 0){ + tabCounterHome.setText(String.valueOf(newHome)); + if( newHome > 0){ //New data are available //The fragment is not displayed, so the counter is displayed if( tabLayout.getSelectedTabPosition() != 0) @@ -1159,7 +1127,7 @@ public class MainActivity extends AppCompatActivity } } - public void updateNotifCounter(int newNotifCount){ + public void updateNotifCounter(){ if(tabLayout.getTabAt(1) == null) return; //noinspection ConstantConditions @@ -1167,8 +1135,8 @@ public class MainActivity extends AppCompatActivity if( tabNotif == null) return; TextView tabCounterNotif = (TextView) tabNotif.findViewById(R.id.tab_counter); - tabCounterNotif.setText(String.valueOf(newNotifCount)); - if( newNotifCount > 0){ + tabCounterNotif.setText(String.valueOf(newNotif)); + if( newNotif > 0){ if( tabLayout.getSelectedTabPosition() != 1) tabCounterNotif.setVisibility(View.VISIBLE); else