add custom error report function

This commit is contained in:
Christian Schabesberger 2016-03-11 14:56:41 +01:00
parent c6ccc2b20d
commit d43365f6e6
4 changed files with 39 additions and 9 deletions

View File

@ -78,10 +78,12 @@ public class ErrorActivity extends AppCompatActivity {
public static final int REQUESTED_STREAM = 1; public static final int REQUESTED_STREAM = 1;
public static final int GET_SUGGESTIONS = 2; public static final int GET_SUGGESTIONS = 2;
public static final int SOMETHING_ELSE = 3; public static final int SOMETHING_ELSE = 3;
public static final int USER_REPORT = 4;
public static final String SEARCHED_STRING = "searched"; public static final String SEARCHED_STRING = "searched";
public static final String REQUESTED_STREAM_STRING = "requested stream"; public static final String REQUESTED_STREAM_STRING = "requested stream";
public static final String GET_SUGGESTIONS_STRING = "get suggestions"; public static final String GET_SUGGESTIONS_STRING = "get suggestions";
public static final String SOMETHING_ELSE_STRING = "something"; public static final String SOMETHING_ELSE_STRING = "something";
public static final String USER_REPORT_STRING = "user report";
public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org"; public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org";
public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME; public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME;
@ -129,16 +131,23 @@ public class ErrorActivity extends AppCompatActivity {
public static void reportError(final Context context, final Exception e, public static void reportError(final Context context, final Exception e,
final Class returnAcitivty, View rootView, final ErrorInfo errorInfo) { final Class returnAcitivty, View rootView, final ErrorInfo errorInfo) {
List<Exception> el = new Vector<>(); List<Exception> el = null;
if(e != null) {
el = new Vector<>();
el.add(e); el.add(e);
}
reportError(context, el, returnAcitivty, rootView, errorInfo); reportError(context, el, returnAcitivty, rootView, errorInfo);
} }
// async call // async call
public static void reportError(Handler handler, final Context context, final Exception e, public static void reportError(Handler handler, final Context context, final Exception e,
final Class returnAcitivty, final View rootView, final ErrorInfo errorInfo) { final Class returnAcitivty, final View rootView, final ErrorInfo errorInfo) {
List<Exception> el = new Vector<>();
List<Exception> el = null;
if(e != null) {
el = new Vector<>();
el.add(e); el.add(e);
}
reportError(handler, context, el, returnAcitivty, rootView, errorInfo); reportError(handler, context, el, returnAcitivty, rootView, errorInfo);
} }
@ -230,10 +239,12 @@ public class ErrorActivity extends AppCompatActivity {
private String formErrorText(List<Exception> el) { private String formErrorText(List<Exception> el) {
String text = ""; String text = "";
if(el != null) {
for (Exception e : el) { for (Exception e : el) {
text += "-------------------------------------\n" text += "-------------------------------------\n"
+ ExceptionUtils.getStackTrace(e); + ExceptionUtils.getStackTrace(e);
} }
}
text += "-------------------------------------"; text += "-------------------------------------";
return text; return text;
} }
@ -286,9 +297,11 @@ public class ErrorActivity extends AppCompatActivity {
.put("ip_range", globIpRange); .put("ip_range", globIpRange);
JSONArray exceptionArray = new JSONArray(); JSONArray exceptionArray = new JSONArray();
if(errorList != null) {
for (Exception e : errorList) { for (Exception e : errorList) {
exceptionArray.put(ExceptionUtils.getStackTrace(e)); exceptionArray.put(ExceptionUtils.getStackTrace(e));
} }
}
errorObject.put("exceptions", exceptionArray); errorObject.put("exceptions", exceptionArray);
errorObject.put("user_comment", userCommentBox.getText().toString()); errorObject.put("user_comment", userCommentBox.getText().toString());
@ -312,6 +325,8 @@ public class ErrorActivity extends AppCompatActivity {
return GET_SUGGESTIONS_STRING; return GET_SUGGESTIONS_STRING;
case SOMETHING_ELSE: case SOMETHING_ELSE:
return SOMETHING_ELSE_STRING; return SOMETHING_ELSE_STRING;
case USER_REPORT:
return USER_REPORT_STRING;
default: default:
return "Your description is in another castle."; return "Your description is in another castle.";
} }

View File

@ -24,6 +24,7 @@ import org.schabi.newpipe.extractor.StreamingService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector;
/** /**
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
@ -346,6 +347,14 @@ public class VideoItemListActivity extends AppCompatActivity
startActivity(intent); startActivity(intent);
return true; return true;
} }
case R.id.action_report_error: {
ErrorActivity.reportError(VideoItemListActivity.this, new Vector<Exception>(),
null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.USER_REPORT,
ServiceList.getNameOfService(currentStreamingServiceId),
"user_report", R.string.user_report));
return true;
}
default: default:
return videoFragment.onOptionsItemSelected(item) || return videoFragment.onOptionsItemSelected(item) ||
super.onOptionsItemSelected(item); super.onOptionsItemSelected(item);

View File

@ -10,4 +10,8 @@
<item android:id="@+id/action_settings" <item android:id="@+id/action_settings"
app:showAsAction="never" app:showAsAction="never"
android:title="@string/settings"/> android:title="@string/settings"/>
<item android:id="@+id/action_report_error"
app:showAsAction="never"
android:title="@string/report_error" />
</menu> </menu>

View File

@ -113,6 +113,8 @@
<string name="detail_dislikes_img_view_description">Dislikes</string> <string name="detail_dislikes_img_view_description">Dislikes</string>
<string name="use_tor_title">Use Tor</string> <string name="use_tor_title">Use Tor</string>
<string name="use_tor_summary">(Experimental) Force download traffic through Tor for increased privacy (streaming videos not yet supported).</string> <string name="use_tor_summary">(Experimental) Force download traffic through Tor for increased privacy (streaming videos not yet supported).</string>
<string name="report_error">Report an Error</string>
<string name="user_report">User report</string>
<string name="err_dir_create">Cannot create download directory \'%1$s\'</string> <string name="err_dir_create">Cannot create download directory \'%1$s\'</string>
<string name="info_dir_created">Created download directory \'%1$s\'</string> <string name="info_dir_created">Created download directory \'%1$s\'</string>