Fixes some behaviors
This commit is contained in:
parent
c1fd4b1d59
commit
c6305baa7c
|
@ -41,6 +41,7 @@ import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -344,10 +345,10 @@ public class MainActivity extends AppCompatActivity
|
||||||
switch (tab.getPosition()){
|
switch (tab.getPosition()){
|
||||||
case 0:
|
case 0:
|
||||||
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||||
if( displayStatusFragment != null )
|
|
||||||
displayStatusFragment.scrollToTop();
|
|
||||||
countNewStatus = 0;
|
countNewStatus = 0;
|
||||||
updateHomeCounter();
|
updateHomeCounter();
|
||||||
|
if( displayStatusFragment != null )
|
||||||
|
displayStatusFragment.scrollToTop();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -357,10 +358,10 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
||||||
if( displayNotificationsFragment != null )
|
|
||||||
displayNotificationsFragment.scrollToTop();
|
|
||||||
countNewNotifications = 0;
|
countNewNotifications = 0;
|
||||||
updateNotifCounter();
|
updateNotifCounter();
|
||||||
|
if( displayNotificationsFragment != null )
|
||||||
|
displayNotificationsFragment.scrollToTop();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1158,6 +1159,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
if( tabHome == null)
|
if( tabHome == null)
|
||||||
return;
|
return;
|
||||||
TextView tabCounterHome = (TextView) tabHome.findViewById(R.id.tab_counter);
|
TextView tabCounterHome = (TextView) tabHome.findViewById(R.id.tab_counter);
|
||||||
|
tabCounterHome.setText(String.valueOf(countNewStatus));
|
||||||
if( countNewStatus> 0){
|
if( countNewStatus> 0){
|
||||||
//New data are available
|
//New data are available
|
||||||
//The fragment is not displayed, so the counter is displayed
|
//The fragment is not displayed, so the counter is displayed
|
||||||
|
@ -1175,6 +1177,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
if( tabNotif == null)
|
if( tabNotif == null)
|
||||||
return;
|
return;
|
||||||
TextView tabCounterNotif = (TextView) tabNotif.findViewById(R.id.tab_counter);
|
TextView tabCounterNotif = (TextView) tabNotif.findViewById(R.id.tab_counter);
|
||||||
|
tabCounterNotif.setText(String.valueOf(countNewNotifications));
|
||||||
if( countNewNotifications > 0){
|
if( countNewNotifications > 0){
|
||||||
tabCounterNotif.setVisibility(View.VISIBLE);
|
tabCounterNotif.setVisibility(View.VISIBLE);
|
||||||
}else {
|
}else {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -62,8 +63,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
private SwipeRefreshLayout swipeRefreshLayout;
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
private boolean swiped;
|
private boolean swiped;
|
||||||
private ListView lv_notifications;
|
private ListView lv_notifications;
|
||||||
private String userId;
|
|
||||||
private String lastReadNotifications;
|
private String lastReadNotifications;
|
||||||
|
private String userId;
|
||||||
|
|
||||||
public DisplayNotificationsFragment(){
|
public DisplayNotificationsFragment(){
|
||||||
}
|
}
|
||||||
|
@ -175,10 +176,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
swiped = false;
|
swiped = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
List<Notification> notifications = apiResponse.getNotifications();
|
|
||||||
String since_id = apiResponse.getSince_id();
|
|
||||||
max_id = apiResponse.getMax_id();
|
max_id = apiResponse.getMax_id();
|
||||||
|
List<Notification> notifications = apiResponse.getNotifications();
|
||||||
//The initial call comes from a classic tab refresh
|
//The initial call comes from a classic tab refresh
|
||||||
flag_loading = (max_id == null );
|
flag_loading = (max_id == null );
|
||||||
if( !swiped && firstLoad && (notifications == null || notifications.size() == 0))
|
if( !swiped && firstLoad && (notifications == null || notifications.size() == 0))
|
||||||
|
@ -192,30 +191,35 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
lv_notifications.setAdapter(notificationsListAdapter);
|
lv_notifications.setAdapter(notificationsListAdapter);
|
||||||
swiped = false;
|
swiped = false;
|
||||||
}
|
}
|
||||||
|
if( firstLoad)
|
||||||
|
MainActivity.countNewNotifications = 0;
|
||||||
if( notifications != null && notifications.size() > 0) {
|
if( notifications != null && notifications.size() > 0) {
|
||||||
for(Notification tmpNotification: notifications){
|
for(Notification tmpNotification: notifications){
|
||||||
if( Long.parseLong(tmpNotification.getId()) > Long.parseLong(lastReadNotifications))
|
if( Long.parseLong(tmpNotification.getId()) > Long.parseLong(lastReadNotifications))
|
||||||
MainActivity.countNewNotifications++;
|
MainActivity.countNewNotifications++;
|
||||||
this.notifications.add(tmpNotification);
|
this.notifications.add(tmpNotification);
|
||||||
}
|
}
|
||||||
((MainActivity)context).updateNotifCounter();
|
|
||||||
notificationsListAdapter.notifyDataSetChanged();
|
notificationsListAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
if( firstLoad )
|
||||||
|
((MainActivity)context).updateNotifCounter();
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
//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
|
|
||||||
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){
|
|
||||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getId(), notifications.get(0).getId());
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMenuVisibility(final boolean visible) {
|
||||||
|
super.setMenuVisibility(visible);
|
||||||
|
if( context == null)
|
||||||
|
return;
|
||||||
|
//Store last notification id to avoid to notify for those that have been already seen
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
if (visible && notifications != null && notifications.size() > 0) {
|
||||||
|
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + this.userId, notifications.get(0).getId());
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void scrollToTop(){
|
public void scrollToTop(){
|
||||||
if( lv_notifications != null)
|
if( lv_notifications != null)
|
||||||
|
@ -231,10 +235,6 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notification.getId());
|
|
||||||
editor.apply();
|
|
||||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications);
|
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications);
|
||||||
lv_notifications.setAdapter(notificationsListAdapter);
|
lv_notifications.setAdapter(notificationsListAdapter);
|
||||||
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
||||||
|
|
|
@ -38,12 +38,9 @@ import java.util.List;
|
||||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRepliesAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRepliesAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
|
||||||
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|
||||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||||
|
@ -261,7 +258,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<Status> statuses = apiResponse.getStatuses();
|
List<Status> statuses = apiResponse.getStatuses();
|
||||||
String since_id = apiResponse.getSince_id();
|
|
||||||
max_id = apiResponse.getMax_id();
|
max_id = apiResponse.getMax_id();
|
||||||
|
|
||||||
flag_loading = (max_id == null );
|
flag_loading = (max_id == null );
|
||||||
|
@ -274,6 +270,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
lv_status.setAdapter(statusListAdapter);
|
lv_status.setAdapter(statusListAdapter);
|
||||||
swiped = false;
|
swiped = false;
|
||||||
}
|
}
|
||||||
|
if( firstLoad)
|
||||||
|
MainActivity.countNewStatus = 0;
|
||||||
if( statuses != null && statuses.size() > 0) {
|
if( statuses != null && statuses.size() > 0) {
|
||||||
for(Status tmpStatus: statuses){
|
for(Status tmpStatus: statuses){
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME && firstLoad && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadStatus)){
|
if( type == RetrieveFeedsAsyncTask.Type.HOME && firstLoad && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadStatus)){
|
||||||
|
@ -285,22 +283,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
this.statuses.add(tmpStatus);
|
this.statuses.add(tmpStatus);
|
||||||
}
|
}
|
||||||
statusListAdapter.notifyDataSetChanged();
|
statusListAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
if( firstLoad)
|
||||||
((MainActivity)context).updateHomeCounter();
|
((MainActivity)context).updateHomeCounter();
|
||||||
}
|
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
|
||||||
//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 ){
|
|
||||||
//acct is null when used in Fragment, data need to be retrieved via shared preferences and db
|
|
||||||
|
|
||||||
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_HOMETIMELINE_MAX_ID + currentAccount.getId(), statuses.get(0).getId());
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
|
|
||||||
//Retrieves replies
|
//Retrieves replies
|
||||||
|
@ -323,10 +309,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
||||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, status.getId());
|
|
||||||
editor.apply();
|
|
||||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
||||||
lv_status.setAdapter(statusListAdapter);
|
lv_status.setAdapter(statusListAdapter);
|
||||||
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
if (textviewNoAction.getVisibility() == View.VISIBLE)
|
||||||
|
@ -335,6 +317,21 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMenuVisibility(final boolean visible) {
|
||||||
|
super.setMenuVisibility(visible);
|
||||||
|
if( context == null)
|
||||||
|
return;
|
||||||
|
//Store last toot id for home timeline to avoid to notify for those that have been already seen
|
||||||
|
if (visible && statuses != null && statuses.size() > 0) {
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void scrollToTop(){
|
public void scrollToTop(){
|
||||||
if( lv_status != null)
|
if( lv_status != null)
|
||||||
lv_status.setAdapter(statusListAdapter);
|
lv_status.setAdapter(statusListAdapter);
|
||||||
|
|
Loading…
Reference in New Issue