add button to export logs to GitHub issue (#1180)

This commit is contained in:
Patrick Demers 2022-11-02 07:16:23 -05:00 committed by GitHub
parent 9703a46f5f
commit f85959cd89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View File

@ -2,7 +2,10 @@ package ml.docilealligator.infinityforreddit.settings;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -20,10 +23,16 @@ import androidx.recyclerview.widget.RecyclerView;
import com.crazylegend.crashyreporter.CrashyReporter; import com.crazylegend.crashyreporter.CrashyReporter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import ml.docilealligator.infinityforreddit.BuildConfig;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.SettingsActivity; import ml.docilealligator.infinityforreddit.activities.SettingsActivity;
import ml.docilealligator.infinityforreddit.adapters.CrashReportsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.adapters.CrashReportsRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
@ -68,10 +77,40 @@ public class CrashReportsFragment extends Fragment {
CrashyReporter.INSTANCE.purgeLogs(); CrashyReporter.INSTANCE.purgeLogs();
Toast.makeText(activity, R.string.crash_reports_deleted, Toast.LENGTH_SHORT).show(); Toast.makeText(activity, R.string.crash_reports_deleted, Toast.LENGTH_SHORT).show();
return true; return true;
} else if (item.getItemId() == R.id.action_export_logs_crash_reports_fragment) {
return createGithubIssueWithLogs();
} }
return false; return false;
} }
/**
* Fetch the logs from CrashyReporter and open browser to create GitHub issue page.
* Issue will have logs, device model, app version, and Android version prefilled.
* @return if successful
*/
private boolean createGithubIssueWithLogs() {
Intent intent = new Intent(getContext(), LinkResolverActivity.class);
String logs, model, appVersion, androidVersion;
try {
List<String> logLines = CrashyReporter.INSTANCE.getLogsAsStrings();
if (logLines == null) {
return false;
}
logs = String.join("\n", logLines);
// limit size to 6800 characters to avoid `414 URI Too Long`
logs = URLEncoder.encode("```\n" + (logs.length() > 0 ? logs.substring(0, Math.min(6800, logs.length())) : "No logs found.") + "\n```", "UTF-8");
model = URLEncoder.encode(Build.MANUFACTURER + " " + Build.MODEL, "UTF-8");
appVersion = URLEncoder.encode(BuildConfig.VERSION_NAME, "UTF-8");
androidVersion = URLEncoder.encode(Build.VERSION.RELEASE, "UTF-8");
} catch (UnsupportedEncodingException e) {
return false;
}
Uri githubIssueUri = Uri.parse(String.format("https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/new?labels=possible-bug&device=%s&version=%s&android_version=%s&logs=%s&&template=BUG_REPORT.yml", model, appVersion, androidVersion, logs));
intent.setData(githubIssueUri);
startActivity(intent);
return true;
}
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
protected boolean applyMenuItemTheme(Menu menu) { protected boolean applyMenuItemTheme(Menu menu) {
if (mCustomThemeWrapper != null) { if (mCustomThemeWrapper != null) {

View File

@ -7,4 +7,10 @@
android:title="@string/action_delete_logs" android:title="@string/action_delete_logs"
android:icon="@drawable/ic_delete_24dp" android:icon="@drawable/ic_delete_24dp"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/action_export_logs_crash_reports_fragment"
android:orderInCategory="2"
android:title="@string/action_create_github_issue"
android:icon="@drawable/ic_open_link_24dp"
app:showAsAction="ifRoom" />
</menu> </menu>

View File

@ -90,6 +90,7 @@
<string name="action_open_external_browser">Open in browser</string> <string name="action_open_external_browser">Open in browser</string>
<string name="action_add_to_post_filter">Add to Post Filter</string> <string name="action_add_to_post_filter">Add to Post Filter</string>
<string name="action_delete_logs">Delete Logs</string> <string name="action_delete_logs">Delete Logs</string>
<string name="action_create_github_issue">Create GitHub Issue</string>
<string name="action_share_rpan_link">Share RPAN Link</string> <string name="action_share_rpan_link">Share RPAN Link</string>
<string name="action_share_post_link">Share Post Link</string> <string name="action_share_post_link">Share Post Link</string>
<string name="action_go_to_wiki">Go to Wiki</string> <string name="action_go_to_wiki">Go to Wiki</string>