Improved scroll to top

pull/178/head
M66B 5 years ago
parent eed8d3fb34
commit 57092f01f0

@ -130,6 +130,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
static final String ACTION_EDIT_ANSWER = BuildConfig.APPLICATION_ID + ".EDIT_ANSWER";
static final String ACTION_EDIT_RULES = BuildConfig.APPLICATION_ID + ".EDIT_RULES";
static final String ACTION_EDIT_RULE = BuildConfig.APPLICATION_ID + ".EDIT_RULE";
static final String ACTION_NEW_MESSAGE = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE";
private static final int UPDATE_TIMEOUT = 15 * 1000; // milliseconds
private static final long EXIT_DELAY = 2500L; // milliseconds
@ -616,6 +617,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
iff.addAction(ACTION_EDIT_ANSWER);
iff.addAction(ACTION_EDIT_RULES);
iff.addAction(ACTION_EDIT_RULE);
iff.addAction(ACTION_NEW_MESSAGE);
lbm.registerReceiver(receiver, iff);
checkUpdate(false);
@ -1153,6 +1155,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
onEditRules(intent);
else if (ACTION_EDIT_RULE.equals(action))
onEditRule(intent);
else if (ACTION_NEW_MESSAGE.equals(action))
onNewMessage(intent);
}
}
};
@ -1257,6 +1261,25 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
fragmentTransaction.commit();
}
private List<Long> updatedFolders = new ArrayList<>();
boolean isFolderUpdated(long folder) {
boolean value = updatedFolders.contains(folder);
if (value)
updatedFolders.remove(folder);
return value;
}
private void onNewMessage(Intent intent) {
long folder = intent.getLongExtra("folder", -1);
boolean unified = intent.getBooleanExtra("unified", false);
if (!updatedFolders.contains(folder))
updatedFolders.add(folder);
if (unified && !updatedFolders.contains(-1L))
updatedFolders.add(-1L);
}
private class UpdateInfo {
String tag_name; // version
String html_url;

@ -2377,7 +2377,7 @@ class Core {
// Prepare scroll to top
if (!message.ui_seen && message.received > account.created) {
Intent report = new Intent(FragmentMessages.ACTION_NEW_MESSAGE);
Intent report = new Intent(ActivityView.ACTION_NEW_MESSAGE);
report.putExtra("folder", folder.id);
report.putExtra("unified", folder.unified);

@ -327,7 +327,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
static final String ACTION_NEW_MESSAGE = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE";
private static final long REVIEW_ASK_DELAY = 21 * 24 * 3600 * 1000L; // milliseconds
private static final long REVIEW_LATER_DELAY = 3 * 24 * 3600 * 1000L; // milliseconds
@ -1266,10 +1265,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
pgpService.bindToService();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
IntentFilter iff = new IntentFilter();
iff.addAction(SimpleTask.ACTION_TASK_COUNT);
iff.addAction(ACTION_NEW_MESSAGE);
lbm.registerReceiver(creceiver, iff);
IntentFilter iff = new IntentFilter(SimpleTask.ACTION_TASK_COUNT);
lbm.registerReceiver(treceiver, iff);
return view;
}
@ -1277,7 +1274,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
public void onDestroyView() {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.unregisterReceiver(creceiver);
lbm.unregisterReceiver(treceiver);
if (pgpService != null && pgpService.isBound()) {
Log.i("PGP unbinding");
@ -3168,7 +3165,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_STORE_RAW);
iff.addAction(ACTION_DECRYPT);
iff.addAction(ACTION_NEW_MESSAGE);
lbm.registerReceiver(receiver, iff);
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
@ -3974,9 +3970,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (messages == null)
return;
if (viewType == AdapterMessage.ViewType.THREAD)
if (viewType == AdapterMessage.ViewType.THREAD) {
if (handleThreadActions(messages))
return;
} else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean autoscroll = prefs.getBoolean("autoscroll", true);
if (autoscroll) {
ActivityView activity = (ActivityView) getActivity();
if (activity != null &&
activity.isFolderUpdated(viewType == AdapterMessage.ViewType.UNIFIED ? -1L : folder))
adapter.gotoTop();
}
}
Log.i("Submit messages=" + messages.size());
adapter.submitList(messages);
@ -4788,20 +4794,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return super.onCreateAnimation(transit, enter, nextAnim);
}
private BroadcastReceiver creceiver = new BroadcastReceiver() {
private BroadcastReceiver treceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (!SimpleTask.ACTION_TASK_COUNT.equals(action)) {
Log.i("Received " + intent);
Log.logExtras(intent);
}
if (SimpleTask.ACTION_TASK_COUNT.equals(action))
onTaskCount(intent);
else if (ACTION_NEW_MESSAGE.equals(action))
onNewMessage(intent);
onTaskCount(intent);
}
};
@ -4822,19 +4818,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
updateListState("Tasks", intent.getIntExtra("count", 0), adapter.getItemCount());
}
private void onNewMessage(Intent intent) {
long fid = intent.getLongExtra("folder", -1);
boolean unified = intent.getBooleanExtra("unified", false);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean autoscroll = prefs.getBoolean("autoscroll", true);
if (autoscroll &&
((viewType == AdapterMessage.ViewType.UNIFIED && unified) ||
(viewType == AdapterMessage.ViewType.FOLDER && folder == fid)))
adapter.gotoTop();
}
private void onStoreRaw(Intent intent) {
message = intent.getLongExtra("id", -1);
String subject = intent.getStringExtra("subject");

Loading…
Cancel
Save