Improves unread toots/notifications
This commit is contained in:
parent
f930023578
commit
22e10925fd
|
@ -37,6 +37,7 @@ import android.support.v4.view.ViewPager;
|
|||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.support.design.widget.NavigationView;
|
||||
|
@ -141,11 +142,15 @@ public class MainActivity extends AppCompatActivity
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
Bundle b = intent.getExtras();
|
||||
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
||||
|
||||
Log.v(Helper.TAG,"eventStreaming= " + eventStreaming);
|
||||
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
||||
Notification notification = b.getParcelable("data");
|
||||
Log.v(Helper.TAG,"notificationsFragment= " + notificationsFragment);
|
||||
if(notificationsFragment != null){
|
||||
Log.v(Helper.TAG,"getUserVisibleHint= " + notificationsFragment.getUserVisibleHint());
|
||||
Log.v(Helper.TAG,"isActivityVisible= " + isActivityVisible());
|
||||
if(notificationsFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
|
||||
notificationsFragment.updateData(notification);
|
||||
}else{
|
||||
notificationsFragment.refresh(notification);
|
||||
|
@ -153,7 +158,10 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
||||
Status status = b.getParcelable("data");
|
||||
Log.v(Helper.TAG,"homeFragment= " + homeFragment);
|
||||
if( homeFragment != null){
|
||||
Log.v(Helper.TAG,"getUserVisibleHint= " + homeFragment.getUserVisibleHint());
|
||||
Log.v(Helper.TAG,"isActivityVisible= " + isActivityVisible());
|
||||
if(homeFragment.getUserVisibleHint() && isActivityVisible()){
|
||||
homeFragment.updateData(status);
|
||||
}else{
|
||||
|
@ -281,7 +289,6 @@ public class MainActivity extends AppCompatActivity
|
|||
if (homeFragment != null && Helper.getUnreadToots(getApplicationContext(), null) > 0) {
|
||||
homeFragment.refresh(null);
|
||||
}
|
||||
Helper.clearUnreadToots(getApplicationContext(), null);
|
||||
updateHomeCounter();
|
||||
}else if( tab.getPosition() == 1) {
|
||||
|
||||
|
@ -290,7 +297,6 @@ public class MainActivity extends AppCompatActivity
|
|||
if (notificationsFragment != null && Helper.getUnreadNotifications(getApplicationContext(), null) > 0) {
|
||||
notificationsFragment.refresh(null);
|
||||
}
|
||||
Helper.clearUnreadNotifications(getApplicationContext(), null);
|
||||
updateNotifCounter();
|
||||
}else if( tab.getPosition() == 2 && display_local) {
|
||||
|
||||
|
@ -338,9 +344,15 @@ public class MainActivity extends AppCompatActivity
|
|||
Fragment fragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, tab.getPosition());
|
||||
switch (tab.getPosition()){
|
||||
case 0:
|
||||
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||
if( displayStatusFragment != null )
|
||||
displayStatusFragment.scrollToTop();
|
||||
Helper.clearUnreadToots(getApplicationContext(), null);
|
||||
updateHomeCounter();
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||
displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||
if( displayStatusFragment != null )
|
||||
displayStatusFragment.scrollToTop();
|
||||
break;
|
||||
|
@ -348,6 +360,8 @@ public class MainActivity extends AppCompatActivity
|
|||
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
||||
if( displayNotificationsFragment != null )
|
||||
displayNotificationsFragment.scrollToTop();
|
||||
Helper.clearUnreadNotifications(getApplicationContext(), null);
|
||||
updateNotifCounter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.os.AsyncTask;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -227,7 +228,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
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(), since_id);
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getId(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
@ -255,9 +256,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
}
|
||||
|
||||
public void refresh(Notification notification){
|
||||
|
||||
Log.v(Helper.TAG,"notification: " + notification);
|
||||
if( notification != null){
|
||||
Log.v(Helper.TAG,"notificationsTmp: " + notificationsTmp);
|
||||
if( notificationsTmp != null && notificationsTmp.size() > 0){
|
||||
Log.v(Helper.TAG,"size: " + notificationsTmp.size());
|
||||
notificationsTmp.add(0,notification);
|
||||
}else {
|
||||
notificationsTmp = new ArrayList<>();
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -330,7 +331,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
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(), since_id);
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + currentAccount.getId(), statuses.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
@ -360,8 +361,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
}
|
||||
|
||||
public void refresh(Status status){
|
||||
Log.v(Helper.TAG,"status: " + status);
|
||||
if( status != null){
|
||||
Log.v(Helper.TAG,"statusesTmp: " + statusesTmp);
|
||||
if( statusesTmp != null && statusesTmp.size() > 0){
|
||||
Log.v(Helper.TAG,"size: " + statusesTmp.size());
|
||||
statusesTmp.add(0,status);
|
||||
}else {
|
||||
statusesTmp = new ArrayList<>();
|
||||
|
|
|
@ -1638,10 +1638,10 @@ public class Helper {
|
|||
if( userId == null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
return sharedpreferences.getInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
|
||||
return sharedpreferences.getInt(Helper.SET_UNREAD_TOOTS + userId, 0);
|
||||
}else {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
return sharedpreferences.getInt(Helper.SET_UNREAD_NOTIFICATIONS + userId, 0);
|
||||
return sharedpreferences.getInt(Helper.SET_UNREAD_TOOTS + userId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,24 +127,17 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveHomeTimelineService(APIResponse apiResponse, String acct, String userId) {
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
public void onRetrieveHomeTimelineService(APIResponse apiResponse, String acct, final String userId) {
|
||||
final List<Status> statuses = apiResponse.getStatuses();
|
||||
if( apiResponse.getError() != null || statuses == null || statuses.size() == 0)
|
||||
return;
|
||||
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
final String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
if( max_id == null){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, apiResponse.getSince_id());
|
||||
editor.apply();
|
||||
return;
|
||||
}
|
||||
|
||||
//No previous notifications in cache, so no notification will be sent
|
||||
String message;
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, apiResponse.getSince_id());
|
||||
editor.apply();
|
||||
|
||||
for(Status status: statuses){
|
||||
//The notification associated to max_id is discarded as it is supposed to have already been sent
|
||||
//Also, if the toot comes from the owner, we will avoid to warn him/her...
|
||||
|
@ -189,11 +182,17 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
||||
notify_user(getContext(), intent, notificationId, loadedImage, finalTitle, finalMessage);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){
|
||||
notify_user(getContext(), intent, notificationId, BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo), finalTitle, finalMessage);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
|
||||
editor.apply();
|
||||
}});
|
||||
|
||||
}
|
||||
|
|
|
@ -133,8 +133,8 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId, boolean refreshData) {
|
||||
List<Notification> notifications = apiResponse.getNotifications();
|
||||
public void onRetrieveNotifications(APIResponse apiResponse, String acct, final String userId, boolean refreshData) {
|
||||
final List<Notification> notifications = apiResponse.getNotifications();
|
||||
if( apiResponse.getError() != null || notifications == null || notifications.size() == 0)
|
||||
return;
|
||||
Bitmap icon_notification = null;
|
||||
|
@ -144,12 +144,7 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
||||
final String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||
if( max_id == null){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, apiResponse.getSince_id());
|
||||
editor.apply();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//No previous notifications in cache, so no notification will be sent
|
||||
int newFollows = 0;
|
||||
|
@ -217,9 +212,7 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
default:
|
||||
}
|
||||
}
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, apiResponse.getSince_id());
|
||||
editor.apply();
|
||||
|
||||
int allNotifCount = newFollows + newAdds + newAsks + newMentions + newShare;
|
||||
if( allNotifCount > 0){
|
||||
//Some others notification
|
||||
|
@ -254,14 +247,22 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
||||
if( max_id != null)
|
||||
if( max_id != null) {
|
||||
notify_user(getContext(), intent, notificationId, loadedImage, finalTitle, message);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){
|
||||
if( max_id != null)
|
||||
if( max_id != null) {
|
||||
notify_user(getContext(), intent, notificationId, BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo), finalTitle, message);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import android.os.SystemClock;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||
|
|
Loading…
Reference in New Issue