From 318b11da01ad843ad63d82b4ac87eb1eaa84b9dc Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 8 Jul 2020 12:32:49 +0800 Subject: View crash reports in Settings -> About -> Crash Reports. --- .../infinityforreddit/Message/ComposeMessage.java | 3 -- .../Settings/CrashReportsFragment.java | 54 ++++++++++++++++++++++ .../Settings/CrashReportsRecyclerViewAdapter.java | 46 ++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsFragment.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsRecyclerViewAdapter.java (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java index 019e1207..ff40ccc8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java @@ -1,7 +1,5 @@ package ml.docilealligator.infinityforreddit.Message; -import android.util.Log; - import androidx.annotation.NonNull; import java.util.HashMap; @@ -41,7 +39,6 @@ public class ComposeMessage { composeMessageListener.composeMessageFailed(errorMessage); } }); - Log.i("asfsdaf", "s " + response.body()); } else { composeMessageListener.composeMessageFailed(response.message()); } 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..04bdc0e9 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsFragment.java @@ -0,0 +1,54 @@ +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 butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; + +public class CrashReportsFragment extends Fragment { + + @BindView(R.id.recycler_view_crash_reports_fragment) + RecyclerView recyclerView; + private Activity activity; + private CrashReportsRecyclerViewAdapter adapter; + private LinearLayoutManager linearLayoutManager; + + public CrashReportsFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View rootView = inflater.inflate(R.layout.fragment_crash_reports, container, false); + + ButterKnife.bind(this, rootView); + + adapter = new CrashReportsRecyclerViewAdapter(CrashyReporter.INSTANCE.getLogsAsStrings()); + linearLayoutManager = new LinearLayoutManager(activity); + recyclerView.setLayoutManager(linearLayoutManager); + recyclerView.setAdapter(adapter); + + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + this.activity = (Activity) context; + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsRecyclerViewAdapter.java new file mode 100644 index 00000000..47629585 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsRecyclerViewAdapter.java @@ -0,0 +1,46 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +import ml.docilealligator.infinityforreddit.R; + +class CrashReportsRecyclerViewAdapter extends RecyclerView.Adapter { + private List crashReports; + + public CrashReportsRecyclerViewAdapter(List crashReports) { + this.crashReports = crashReports; + } + + @NonNull + @Override + public CrashReportViewHolder 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 CrashReportViewHolder holder, int position) { + holder.crashReportTextView.setText(crashReports.get(holder.getAdapterPosition())); + } + + @Override + public int getItemCount() { + return crashReports == null ? 0 : crashReports.size(); + } + + class CrashReportViewHolder extends RecyclerView.ViewHolder { + TextView crashReportTextView; + + public CrashReportViewHolder(@NonNull View itemView) { + super(itemView); + crashReportTextView = (TextView) itemView; + } + } +} -- cgit v1.2.3