diff options
Diffstat (limited to '')
6 files changed, 68 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; diff --git a/app/src/main/res/menu/crash_reports_fragment.xml b/app/src/main/res/menu/crash_reports_fragment.xml new file mode 100644 index 00000000..67bc62b5 --- /dev/null +++ b/app/src/main/res/menu/crash_reports_fragment.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <item + android:id="@+id/action_delete_logs_crash_reports_fragment" + android:orderInCategory="1" + android:title="@string/action_delete_logs" + android:icon="@drawable/ic_delete_24dp" + app:showAsAction="ifRoom" /> +</menu>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 496b787f..3fe9b283 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,6 +82,7 @@ <string name="action_share_link">Share Link</string> <string name="action_copy_link">Copy Link</string> <string name="action_add_to_post_filter">Add to Post Filter</string> + <string name="action_delete_logs">Delete Logs</string> <string name="parse_json_response_error">Error occurred when parsing the JSON response</string> <string name="retrieve_token_error">Error Retrieving the token</string> @@ -1094,4 +1095,6 @@ <string name="suggest_title">Suggest Title</string> <string name="suggest_title_failed">Failed to suggest a title</string> + <string name="crash_reports_deleted">Crash reports are deleted</string> + </resources> |