From 4066da03b86d335b57f33b4a2ae6a16950145a2e Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 27 Aug 2021 07:50:22 +0200 Subject: [PATCH] Added debug field to messages list --- .../eu/faircode/email/FragmentMessages.java | 30 ++++++++++++++++++- app/src/main/res/layout/fragment_messages.xml | 13 ++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 1ccd3f05e8..15c0a0c06c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -64,6 +64,7 @@ import android.net.NetworkRequest; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Debug; import android.os.Parcel; import android.os.Parcelable; import android.print.PrintAttributes; @@ -261,6 +262,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private ImageButton ibSeen; private ImageButton ibUnflagged; private ImageButton ibSnoozed; + private TextView tvDebug; private TextViewAutoCompleteAction etSearch; private BottomNavigationView bottom_navigation; private ContentLoadingProgressBar pbWait; @@ -491,6 +493,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. ibUp = view.findViewById(R.id.ibUp); ibOutbox = view.findViewById(R.id.ibOutbox); tvOutboxCount = view.findViewById(R.id.tvOutboxCount); + tvDebug = view.findViewById(R.id.tvDebug); ibSeen = view.findViewById(R.id.ibSeen); ibUnflagged = view.findViewById(R.id.ibUnflagged); ibSnoozed = view.findViewById(R.id.ibSnoozed); @@ -820,6 +823,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }); + tvDebug.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.i("Manual GC"); + Runtime.getRuntime().runFinalization(); + Runtime.getRuntime().gc(); + updateDebugInfo(); + } + }); + ibSeen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -847,7 +860,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }); - etSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { @@ -1210,6 +1222,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. sbThread.setVisibility(View.GONE); ibDown.setVisibility(View.GONE); ibUp.setVisibility(View.GONE); + tvDebug.setText(null); + tvDebug.setVisibility( + BuildConfig.DEBUG && viewType != AdapterMessage.ViewType.THREAD + ? View.VISIBLE : View.GONE); ibSeen.setVisibility(View.GONE); ibUnflagged.setVisibility(View.GONE); ibSnoozed.setVisibility(View.GONE); @@ -5114,6 +5130,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. tvNoEmail.setVisibility(none ? View.VISIBLE : View.GONE); tvNoEmailHint.setVisibility(none && filtered ? View.VISIBLE : View.GONE); + if (BuildConfig.DEBUG) + updateDebugInfo(); + Log.i("List state reason=" + reason + " tasks=" + tasks + " loading=" + loading + " items=" + items + " initialized=" + initialized + @@ -5121,6 +5140,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. " no=" + (tvNoEmail.getVisibility() == View.VISIBLE)); } + private void updateDebugInfo() { + Runtime rt = Runtime.getRuntime(); + long hused = rt.totalMemory() - rt.freeMemory(); + long hmax = rt.maxMemory(); + long nheap = Debug.getNativeHeapAllocatedSize(); + int perc = Math.round(hused * 100f / hmax); + tvDebug.setText(perc + "% " + (nheap / (1024 * 1024)) + "M"); + } + private boolean handleThreadActions( @NonNull PagedList messages, ArrayList targets, List removed) { diff --git a/app/src/main/res/layout/fragment_messages.xml b/app/src/main/res/layout/fragment_messages.xml index a29347847f..93e5589d1f 100644 --- a/app/src/main/res/layout/fragment_messages.xml +++ b/app/src/main/res/layout/fragment_messages.xml @@ -258,6 +258,19 @@ app:layout_constraintEnd_toEndOf="@+id/ibOutbox" app:layout_constraintTop_toTopOf="@+id/ibOutbox" /> + +