From 2d0aa76d3458800a7eeda357f85f38f11bcc0542 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 2 Apr 2021 15:21:15 +0800 Subject: New option: Crash Reports. --- app/src/main/AndroidManifest.xml | 10 +++++ .../activities/LoginActivity.java | 1 + .../adapters/CrashReportsRecyclerViewAdapter.java | 45 +++++++++++++++++++ .../settings/CrashReportsFragment.java | 50 ++++++++++++++++++++++ app/src/main/res/layout/fragment_crash_reports.xml | 6 +++ app/src/main/res/layout/item_crash_report.xml | 8 ++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/advanced_preferences.xml | 4 ++ 8 files changed, 125 insertions(+) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CrashReportsRecyclerViewAdapter.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java create mode 100644 app/src/main/res/layout/fragment_crash_reports.xml create mode 100644 app/src/main/res/layout/item_crash_report.xml (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ce7ec3e3..f3b262b7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -409,6 +409,16 @@ android:resource="@xml/file_paths" /> + + + + { + private List crashReports; + + public CrashReportsRecyclerViewAdapter(List crashReports) { + this.crashReports = crashReports; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new CrashReportViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_crash_report, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + ((CrashReportViewHolder) holder).crashReportTextView.setText(crashReports.get(position)); + } + + @Override + public int getItemCount() { + return crashReports == null ? 0 : crashReports.size(); + } + + private class CrashReportViewHolder extends RecyclerView.ViewHolder { + TextView crashReportTextView; + public CrashReportViewHolder(@NonNull View itemView) { + super(itemView); + crashReportTextView = (TextView) itemView; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java new file mode 100644 index 00000000..6fee1427 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java @@ -0,0 +1,50 @@ +package ml.docilealligator.infinityforreddit.settings; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.crazylegend.crashyreporter.CrashyReporter; + +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.adapters.CrashReportsRecyclerViewAdapter; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link CrashReportsFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class CrashReportsFragment extends Fragment { + + private Activity activity; + + public CrashReportsFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_crash_reports, container, false); + + recyclerView.setLayoutManager(new LinearLayoutManager(activity)); + recyclerView.setAdapter(new CrashReportsRecyclerViewAdapter(CrashyReporter.INSTANCE.getLogsAsStrings())); + + return recyclerView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (Activity) context; + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_crash_reports.xml b/app/src/main/res/layout/fragment_crash_reports.xml new file mode 100644 index 00000000..bc87d22c --- /dev/null +++ b/app/src/main/res/layout/fragment_crash_reports.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_crash_report.xml b/app/src/main/res/layout/item_crash_report.xml new file mode 100644 index 00000000..8b5051ce --- /dev/null +++ b/app/src/main/res/layout/item_crash_report.xml @@ -0,0 +1,8 @@ + + \ 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 f2c97761..496b787f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -556,6 +556,7 @@ Hide Favorite Subreddits Section Hide Subscribed Subreddits Section Default Search Result Tab + Crash Reports Cannot get the link diff --git a/app/src/main/res/xml/advanced_preferences.xml b/app/src/main/res/xml/advanced_preferences.xml index 0ddef34d..3bc0ce77 100644 --- a/app/src/main/res/xml/advanced_preferences.xml +++ b/app/src/main/res/xml/advanced_preferences.xml @@ -46,4 +46,8 @@ app:key="restore_settings" app:title="@string/settings_restore_settings_title" /> + + \ No newline at end of file -- cgit v1.2.3