Changes methods in fragment and mainactivity
This commit is contained in:
parent
d43feffca8
commit
d222ab3ff2
|
@ -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
|
||||
|
|
|
@ -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<Void, Void, Void> {
|
|||
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<Void, Void, Void> {
|
|||
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<Void, Void, Void> {
|
|||
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<Void, Void, Void> {
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Void, Void, Void>
|
|||
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<Void, Void, Void>
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ public class Notification implements Parcelable {
|
|||
status = in.readParcelable(Status.class.getClassLoader());
|
||||
}
|
||||
|
||||
public Notification(){};
|
||||
|
||||
public static final Creator<Notification> CREATOR = new Creator<Notification>() {
|
||||
@Override
|
||||
public Notification createFromParcel(Parcel in) {
|
||||
|
|
|
@ -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<Notification> 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<Notification> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Status> 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<Status> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -58,11 +58,6 @@
|
|||
android:text="@string/set_auto_store_toot"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/set_bubble_counter"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/set_bubble_counter"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/set_preview_reply"
|
||||
|
|
|
@ -58,11 +58,6 @@
|
|||
android:text="@string/set_auto_store_toot"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/set_bubble_counter"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/set_bubble_counter"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/set_preview_reply"
|
||||
|
|
|
@ -131,6 +131,7 @@ public class MainActivity extends AppCompatActivity
|
|||
private DisplayNotificationsFragment notificationsFragment;
|
||||
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
|
||||
private BroadcastReceiver receive_data;
|
||||
private int newNotif, newHome;
|
||||
|
||||
public MainActivity() {
|
||||
}
|
||||
|
@ -139,31 +140,33 @@ public class MainActivity extends AppCompatActivity
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
||||
|
||||
newNotif = 0;
|
||||
newHome = 0;
|
||||
receive_data = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Bundle b = getIntent().getExtras();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean bubbles = sharedpreferences.getBoolean(Helper.SET_BUBBLE_COUNTER, true);
|
||||
StreamingUserAsyncTask.EventStreaming eventStreaming = (StreamingUserAsyncTask.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||
if( eventStreaming == StreamingUserAsyncTask.EventStreaming.NOTIFICATION){
|
||||
Notification notification = b.getParcelable("data");
|
||||
if( notificationsFragment.getUserVisibleHint() == true){
|
||||
|
||||
if(notificationsFragment.getUserVisibleHint()){
|
||||
notificationsFragment.updateData(notification);
|
||||
}else{
|
||||
|
||||
newNotif++;
|
||||
updateNotifCounter();
|
||||
}
|
||||
}else if(eventStreaming == StreamingUserAsyncTask.EventStreaming.UPDATE){
|
||||
Status status = b.getParcelable("data");
|
||||
if( notificationsFragment.getUserVisibleHint() == true){
|
||||
|
||||
if(homeFragment.getUserVisibleHint()){
|
||||
homeFragment.updateData(status);
|
||||
}else{
|
||||
|
||||
newHome++;
|
||||
updateHomeCounter();
|
||||
}
|
||||
}else if(eventStreaming == StreamingUserAsyncTask.EventStreaming.DELETE){
|
||||
String id = b.getString("id");
|
||||
if( notificationsFragment.getUserVisibleHint() == true){
|
||||
if(notificationsFragment.getUserVisibleHint()){
|
||||
|
||||
}else{
|
||||
|
||||
|
@ -251,7 +254,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) {
|
||||
|
@ -274,16 +276,14 @@ public class MainActivity extends AppCompatActivity
|
|||
case 0:
|
||||
item = navigationView.getMenu().findItem(R.id.nav_home);
|
||||
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);
|
||||
if( bubbles && notificationsFragment != null)
|
||||
notificationsFragment.refreshData();
|
||||
newNotif = 0;
|
||||
updateNotifCounter();
|
||||
break;
|
||||
case 2:
|
||||
fragmentTag = "LOCAL_TIMELINE";
|
||||
|
@ -1105,40 +1105,8 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void refreshData(){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
|
||||
if( account != null){
|
||||
String last_refresh = sharedpreferences.getString(Helper.LAST_BUBBLE_REFRESH_NOTIF + account.getId(), null);
|
||||
Date 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( 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
|
||||
|
|
Loading…
Reference in New Issue