New option: delete crash reports in CrashReportsFragment.

This commit is contained in:
Alex Ning 2021-04-02 17:35:07 +08:00
parent 2d0aa76d34
commit b54e9aabb1
6 changed files with 68 additions and 8 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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);

View File

@ -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,12 +45,50 @@ 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()));
return recyclerView;
}
@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);

View File

@ -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>

View File

@ -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>