Smooth scroll only when log items <= 1000
This commit is contained in:
parent
2d85cd5482
commit
43dbd73134
|
|
@ -6,6 +6,7 @@ import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
@ -53,6 +54,7 @@ public class LogsActivity extends BaseActivity {
|
||||||
private LogsAdapter adapter;
|
private LogsAdapter adapter;
|
||||||
private final Handler handler = new Handler();
|
private final Handler handler = new Handler();
|
||||||
private ActivityLogsBinding binding;
|
private ActivityLogsBinding binding;
|
||||||
|
private LinearLayoutManagerFix layoutManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
|
@ -82,7 +84,8 @@ public class LogsActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
adapter = new LogsAdapter();
|
adapter = new LogsAdapter();
|
||||||
binding.recyclerView.setAdapter(adapter);
|
binding.recyclerView.setAdapter(adapter);
|
||||||
binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this));
|
layoutManager = new LinearLayoutManagerFix(this);
|
||||||
|
binding.recyclerView.setLayoutManager(layoutManager);
|
||||||
if (App.getPreferences().getBoolean("disable_verbose_log", false)) {
|
if (App.getPreferences().getBoolean("disable_verbose_log", false)) {
|
||||||
binding.slidingTabs.setVisibility(View.GONE);
|
binding.slidingTabs.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
@ -121,9 +124,19 @@ public class LogsActivity extends BaseActivity {
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
if (itemId == R.id.menu_scroll_top) {
|
if (itemId == R.id.menu_scroll_top) {
|
||||||
scrollTop();
|
Log.e("Test", adapter.getItemCount() + "");
|
||||||
|
if (layoutManager.findFirstVisibleItemPosition() > 1000) {
|
||||||
|
binding.recyclerView.scrollToPosition(0);
|
||||||
|
} else {
|
||||||
|
binding.recyclerView.smoothScrollToPosition(0);
|
||||||
|
}
|
||||||
|
binding.recyclerView.smoothScrollToPosition(0);
|
||||||
} else if (itemId == R.id.menu_scroll_down) {
|
} else if (itemId == R.id.menu_scroll_down) {
|
||||||
scrollDown();
|
if (adapter.getItemCount() - layoutManager.findLastVisibleItemPosition() > 1000) {
|
||||||
|
binding.recyclerView.scrollToPosition(adapter.getItemCount() - 1);
|
||||||
|
} else {
|
||||||
|
binding.recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);
|
||||||
|
}
|
||||||
} else if (itemId == R.id.menu_refresh) {
|
} else if (itemId == R.id.menu_refresh) {
|
||||||
reloadErrorLog();
|
reloadErrorLog();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -144,14 +157,6 @@ public class LogsActivity extends BaseActivity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollTop() {
|
|
||||||
binding.recyclerView.smoothScrollToPosition(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scrollDown() {
|
|
||||||
binding.recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reloadErrorLog() {
|
private void reloadErrorLog() {
|
||||||
new LogsReader().execute(allLog ? fileAllLog : fileErrorLog);
|
new LogsReader().execute(allLog ? fileAllLog : fileErrorLog);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue