Fixed log auto scroll

This commit is contained in:
M66B 2022-07-06 22:01:33 +02:00
parent 1837cf9dea
commit feab958d41
2 changed files with 14 additions and 7 deletions

View File

@ -106,7 +106,8 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
public void set(@NonNull List<EntityLog> logs,
Long account, Long folder, Long message,
@NonNull List<EntityLog.Type> types) {
@NonNull List<EntityLog.Type> types,
Runnable callback) {
Log.i("Set logs=" + logs.size());
this.all = logs;
@ -162,6 +163,8 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
try {
diff.dispatchUpdatesTo(AdapterLog.this);
if (callback != null)
callback.run();
} catch (Throwable ex) {
Log.e(ex);
}
@ -175,7 +178,7 @@ public class AdapterLog extends RecyclerView.Adapter<AdapterLog.ViewHolder> {
}
public void setTypes(@NonNull List<EntityLog.Type> types) {
set(all, account, folder, message, types);
set(all, account, folder, message, types, null);
}
private static class DiffCallback extends DiffUtil.Callback {

View File

@ -125,9 +125,13 @@ public class FragmentLogs extends FragmentBase {
if (logs == null)
logs = new ArrayList<>();
adapter.set(logs, account, folder, message, getTypes());
adapter.set(logs, account, folder, message, getTypes(), new Runnable() {
@Override
public void run() {
if (autoScroll)
rvLog.scrollToPosition(0);
}
});
pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE);
@ -173,7 +177,7 @@ public class FragmentLogs extends FragmentBase {
} else if (itemId == R.id.menu_auto_scroll) {
boolean enabled = !item.isChecked();
item.setChecked(enabled);
onMenuAutoScoll(enabled);
onMenuAutoScroll(enabled);
return true;
} else if (itemId == R.id.menu_show) {
onMenuShow();
@ -189,7 +193,7 @@ public class FragmentLogs extends FragmentBase {
prefs.edit().putBoolean("main_log", enabled).apply();
}
private void onMenuAutoScoll(boolean enabled) {
private void onMenuAutoScroll(boolean enabled) {
autoScroll = enabled;
}