diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-04-02 09:35:07 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-04-02 09:35:07 +0000 |
commit | b54e9aabb1b869b98c351705c06a1f91d5f0563a (patch) | |
tree | 60c88bf56742ea49524311c2c1511b7932e00fc6 /app/src/main/java/ml | |
parent | 2d0aa76d3458800a7eeda357f85f38f11bcc0542 (diff) | |
download | infinity-for-reddit-b54e9aabb1b869b98c351705c06a1f91d5f0563a.tar infinity-for-reddit-b54e9aabb1b869b98c351705c06a1f91d5f0563a.tar.gz infinity-for-reddit-b54e9aabb1b869b98c351705c06a1f91d5f0563a.tar.bz2 infinity-for-reddit-b54e9aabb1b869b98c351705c06a1f91d5f0563a.tar.lz infinity-for-reddit-b54e9aabb1b869b98c351705c06a1f91d5f0563a.tar.xz infinity-for-reddit-b54e9aabb1b869b98c351705c06a1f91d5f0563a.tar.zst infinity-for-reddit-b54e9aabb1b869b98c351705c06a1f91d5f0563a.zip |
New option: delete crash reports in CrashReportsFragment.
Diffstat (limited to 'app/src/main/java/ml')
4 files changed, 55 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 4af5a6c7..8ac039ea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -73,6 +73,7 @@ import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.services.DownloadRedditVideoService; import ml.docilealligator.infinityforreddit.services.SubmitPostService; import ml.docilealligator.infinityforreddit.settings.AdvancedPreferenceFragment; +import ml.docilealligator.infinityforreddit.settings.CrashReportsFragment; import ml.docilealligator.infinityforreddit.settings.CustomizeBottomAppBarFragment; import ml.docilealligator.infinityforreddit.settings.CustomizeMainPageTabsFragment; import ml.docilealligator.infinityforreddit.settings.DownloadLocationPreferenceFragment; @@ -257,4 +258,6 @@ public interface AppComponent { void inject(SuicidePreventionActivity suicidePreventionActivity); void inject(WebViewActivity webViewActivity); + + void inject(CrashReportsFragment crashReportsFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java index 2eb2de1d..21f49973 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -95,7 +95,6 @@ public class LoginActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); - int llll = 0 / 0; setImmersiveModeNotApplicable(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 91b82fdf..5f41dc1d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -5,7 +5,6 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -270,7 +269,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } mGlide = Glide.with(this); - Resources resources = getResources(); mLocale = getResources().getConfiguration().locale; mLinearLayoutManager = new LinearLayoutManager(activity); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java index 6fee1427..350addf8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java @@ -1,29 +1,38 @@ package ml.docilealligator.infinityforreddit.settings; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.appcompat.view.menu.MenuItemImpl; +import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.crazylegend.crashyreporter.CrashyReporter; +import javax.inject.Inject; + +import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.adapters.CrashReportsRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -/** - * A simple {@link Fragment} subclass. - * Use the {@link CrashReportsFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class CrashReportsFragment extends Fragment { + @Inject + CustomThemeWrapper mCustomThemeWrapper; private Activity activity; public CrashReportsFragment() { @@ -36,6 +45,10 @@ public class CrashReportsFragment extends Fragment { // Inflate the layout for this fragment RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_crash_reports, container, false); + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + setHasOptionsMenu(true); + recyclerView.setLayoutManager(new LinearLayoutManager(activity)); recyclerView.setAdapter(new CrashReportsRecyclerViewAdapter(CrashyReporter.INSTANCE.getLogsAsStrings())); @@ -43,6 +56,40 @@ public class CrashReportsFragment extends Fragment { } @Override + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { + inflater.inflate(R.menu.crash_reports_fragment, menu); + applyMenuItemTheme(menu); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == R.id.action_delete_logs_crash_reports_fragment) { + CrashyReporter.INSTANCE.purgeLogs(); + Toast.makeText(activity, R.string.crash_reports_deleted, Toast.LENGTH_SHORT).show(); + return true; + } + return false; + } + + @SuppressLint("RestrictedApi") + protected boolean applyMenuItemTheme(Menu menu) { + if (mCustomThemeWrapper != null) { + int size = Math.min(menu.size(), 2); + for (int i = 0; i < size; i++) { + MenuItem item = menu.getItem(i); + if (((MenuItemImpl) item).requestsActionButton()) { + Drawable drawable = item.getIcon(); + if (drawable != null) { + DrawableCompat.setTint(drawable, mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor()); + item.setIcon(drawable); + } + } + } + } + return true; + } + + @Override public void onAttach(@NonNull Context context) { super.onAttach(context); activity = (Activity) context; |