Fixes some issues + 2

This commit is contained in:
tom79 2017-08-25 12:45:42 +02:00
parent 1289379582
commit ec760849ed
5 changed files with 88 additions and 63 deletions

View File

@ -224,13 +224,16 @@ public class MainActivity extends AppCompatActivity
case 0:
item = navigationView.getMenu().findItem(R.id.nav_home);
fragmentTag = "HOME_TIMELINE";
if( homeFragment != null)
homeFragment.refreshData();
updateHomeCounter(0);
break;
case 1:
fragmentTag = "NOTIFICATIONS";
item = navigationView.getMenu().findItem(R.id.nav_notification);
updateNotifCounter(0);
notificationsFragment.refreshData();
if( notificationsFragment != null)
notificationsFragment.refreshData();
break;
case 2:
fragmentTag = "LOCAL_TIMELINE";
@ -1006,7 +1009,7 @@ public class MainActivity extends AppCompatActivity
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(120)) {
if (last_refresh_date == null || (new Date().getTime() - last_refresh_date.getTime()) >= TimeUnit.SECONDS.toMillis(10)) {
if( notificationsFragment != null && notificationsFragment.isAdded()){
notificationsFragment.update();
@ -1018,7 +1021,7 @@ public class MainActivity extends AppCompatActivity
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(120)) {
if (last_refresh_date == null || (new Date().getTime() - last_refresh_date.getTime()) >= TimeUnit.SECONDS.toMillis(10)) {
if( homeFragment != null && homeFragment.isAdded()){
homeFragment.update();

View File

@ -180,6 +180,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
@Override
public void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId, boolean refreshData) {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
@ -197,17 +198,26 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
editor.apply();
String bubble_max_id = sharedpreferences.getString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, null);
List<Notification> notifications = apiResponse.getNotifications();
max_id = apiResponse.getMax_id();
if( refreshData || !displayNotificationsFragment.getUserVisibleHint()) {
if( !displayNotificationsFragment.getUserVisibleHint() && bubble_max_id != null){
int countData = 0;
for(Notification nt : notifications){
if( nt.getId().trim().equals(bubble_max_id.trim()) )
if( refreshData ) {
manageNotifications(notifications, max_id);
if( apiResponse.getSince_id() != null) {
editor.putString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, apiResponse.getSince_id());
editor.apply();
}
}else {
int countData = 0;
if( bubble_max_id != null) {
for (Notification nt : notifications) {
if (nt.getId().trim().equals(bubble_max_id.trim()))
break;
countData++;
}
}
if( !displayNotificationsFragment.getUserVisibleHint() ){
((MainActivity)context).updateNotifCounter(countData);
max_id = null;
firstLoad = true;
@ -215,23 +225,23 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
for(Notification tmpNotification: notifications){
this.notificationsTmp.add(tmpNotification);
}
}else{
manageNotifications(notifications, max_id);
}
if( apiResponse.getSince_id() != null) {
editor.putString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, apiResponse.getSince_id());
editor.apply();
}
}else {
if( notifications != null && notifications.size() > 0) {
max_id = null;
firstLoad = true;
notificationsTmp = new ArrayList<>();
for(Notification tmpNotification: notifications){
this.notificationsTmp.add(tmpNotification);
if( apiResponse.getSince_id() != null) {
editor.putString(Helper.LAST_MAX_ID_BUBBLE_NOTIF + userId, apiResponse.getSince_id());
editor.apply();
}
}else {
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_data.setVisibility(View.VISIBLE);
}
}
new_data.setVisibility(View.VISIBLE);
}
}
@ -265,7 +275,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
if( currentAccount != null && firstLoad){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getId(), notifications.get(0).getId());
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getId(), max_id);
editor.apply();
}
}
@ -279,12 +289,12 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
public void update(){
if( context != null){
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, null, null, null, !displayNotificationsFragment.getUserVisibleHint(), DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, null, null, null, false, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
public void refreshData(){
if(context != null && this.notificationsTmp != null){
if(context != null && this.notificationsTmp != null && this.notificationsTmp.size() > 0){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isOnWifi = Helper.isOnWIFI(context);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);

View File

@ -280,39 +280,49 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
editor.apply();
String bubble_max_id = sharedpreferences.getString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, null);
if( refreshData || !displayStatusFragment.getUserVisibleHint()) {
if( refreshData ) {
max_id = apiResponse.getMax_id();
if( !displayStatusFragment.getUserVisibleHint() && bubble_max_id != null){
int countData = 0;
for(Status st : statuses){
if( st.getId().trim().equals(bubble_max_id.trim()) )
break;
countData++;
}
((MainActivity)context).updateHomeCounter(countData);
max_id = null;
firstLoad = true;
statusesTmp = new ArrayList<>();
for(Status tmpStatus: statuses){
this.statusesTmp.add(tmpStatus);
}
}else {
manageStatus(statuses, max_id);
}
manageStatus(statuses, max_id);
if( apiResponse.getSince_id() != null) {
editor.putString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, apiResponse.getSince_id());
editor.apply();
}
}else {
if( statuses != null && statuses.size() > 0) {
max_id = null;
firstLoad = true;
statusesTmp = new ArrayList<>();
for(Status tmpStatus: statuses){
this.statusesTmp.add(tmpStatus);
int countData = 0;
if( bubble_max_id != null) {
for (Status st : statuses) {
if (st.getId().trim().equals(bubble_max_id.trim()))
break;
countData++;
}
}
new_data.setVisibility(View.VISIBLE);
if( !displayStatusFragment.getUserVisibleHint()){
((MainActivity)context).updateHomeCounter(countData);
if( countData > 0){
max_id = null;
firstLoad = true;
statusesTmp = new ArrayList<>();
for(Status tmpStatus: statuses){
this.statusesTmp.add(tmpStatus);
}
}
if( apiResponse.getSince_id() != null) {
editor.putString(Helper.LAST_MAX_ID_BUBBLE_HOME + userId, apiResponse.getSince_id());
editor.apply();
}
}else {
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_data.setVisibility(View.VISIBLE);
}
}
}
}else {
max_id = apiResponse.getMax_id();
@ -351,7 +361,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
if( currentAccount != null && firstLoad){
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + currentAccount.getId(), statuses.get(0).getId());
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + currentAccount.getId(), max_id);
editor.apply();
}
}
@ -389,12 +399,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
public void update() {
if( context != null) {
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, !displayStatusFragment.getUserVisibleHint(), DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, false, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
public void refreshData(){
if(context != null && this.statusesTmp != null){
if(context != null && this.statusesTmp != null && this.statusesTmp.size() > 0){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isOnWifi = Helper.isOnWIFI(context);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);

View File

@ -154,10 +154,11 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
intent.putExtra(PREF_KEY_ID, userId);
long notif_id = Long.parseLong(userId);
final int notificationId = ((notif_id + 2) > 2147483647) ? (int) (2147483647 - notif_id - 2) : (int) (notif_id + 2);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, apiResponse.getMax_id());
editor.apply();
if( apiResponse.getMax_id() != null) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, apiResponse.getMax_id());
editor.apply();
}
if( notificationUrl != null){
ImageLoader imageLoaderNoty = ImageLoader.getInstance();

View File

@ -257,10 +257,11 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
}
}
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, apiResponse.getMax_id());
editor.apply();
if(apiResponse.getMax_id() != null) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, apiResponse.getMax_id());
editor.apply();
}
}