diff --git a/app/src/main/java/org/schabi/newpipe/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/ErrorActivity.java index 4e4095be2..a0875c773 100644 --- a/app/src/main/java/org/schabi/newpipe/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ErrorActivity.java @@ -1,9 +1,12 @@ -package org.schabi.newpipe; +package org.schabi.newpipe; + import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.net.MailTo; +import android.net.Uri; import android.os.Build; import android.preference.PreferenceManager; import android.support.design.widget.Snackbar; @@ -11,16 +14,43 @@ import android.support.v4.app.NavUtils; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.os.Handler; +import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import org.apache.commons.lang.exception.ExceptionUtils; +import org.json.JSONArray; +import org.json.JSONObject; +import java.net.URI; import java.util.List; import java.util.Vector; +/** + * Created by Christian Schabesberger on 24.10.15. + * + * Copyright (C) Christian Schabesberger 2016 + * ErrorActivity.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + public class ErrorActivity extends AppCompatActivity { public static class ErrorInfo { @@ -44,6 +74,8 @@ public class ErrorActivity extends AppCompatActivity { public static final int REQUESTED_STREAM = 1; public static final String SEARCHED_STRING = "Searched"; public static final String REQUESTED_STREAM_STRING = "Requested Stream"; + public static final String ERROR_EMAIL_ADDRESS = "dummy@dummy.org"; + public static final String ERROR_EMAIL_SUBJECT="Exception in NewPipe " + BuildConfig.VERSION_NAME; private List errorList; private ErrorInfo errorInfo; @@ -51,6 +83,7 @@ public class ErrorActivity extends AppCompatActivity { // views private TextView errorView; + private EditText userCommentBox; public static void reportError(final Context context, final List el, final Class returnAcitivty, View rootView, final ErrorInfo errorInfo) { @@ -113,6 +146,8 @@ public class ErrorActivity extends AppCompatActivity { returnActivity = ac.returnActivity; errorInfo = ac.errorInfo; + Button reportButton = (Button) findViewById(R.id.errorReportButton); + userCommentBox = (EditText) findViewById(R.id.errorCommentBox); errorView = (TextView) findViewById(R.id.errorView); errorView.setText(formErrorText(errorList)); @@ -120,14 +155,43 @@ public class ErrorActivity extends AppCompatActivity { //importand add gurumeditaion addGuruMeditaion(); buildInfo(errorInfo); + + reportButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + Intent intent = new Intent(Intent.ACTION_SENDTO); + intent.setData(Uri.parse("mailto:" + ERROR_EMAIL_ADDRESS)) + .putExtra(Intent.EXTRA_SUBJECT, ERROR_EMAIL_SUBJECT) + .putExtra(Intent.EXTRA_TEXT, buildJson()); + + startActivity(Intent.createChooser(intent, "Send Email")); + } + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.error_menu, menu); + return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); - if (id == android.R.id.home) { - goToReturnActivity(); - return true; + switch(id) { + case android.R.id.home: + goToReturnActivity(); + break; + case R.id.menu_item_share_error: { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_SEND); + intent.putExtra(Intent.EXTRA_TEXT, buildJson()); + intent.setType("text/plain"); + startActivity(Intent.createChooser(intent, getString(R.string.share_dialog_title))); + } + break; } return false; } @@ -165,35 +229,65 @@ public class ErrorActivity extends AppCompatActivity { infoLabelView.setText(getString(R.string.info_labels).replace("\\n", "\n")); - String whatString = ""; - switch (info.userAction) { - case REQUESTED_STREAM: - whatString = REQUESTED_STREAM_STRING; - break; - case SEARCHED: - whatString = SEARCHED_STRING; - break; - default: - whatString = "Your description is in another castle."; - } - - String contentLang = PreferenceManager.getDefaultSharedPreferences(this) - .getString(this.getString(R.string.search_language_key), "none"); - - String osBase = Build.VERSION.SDK_INT >= 23 ? Build.VERSION.BASE_OS : "Android"; - String osString = (osBase.isEmpty() ? "Android" : osBase) - + " " + Build.VERSION.RELEASE; - - text += whatString + text += getUserActionString(info.userAction) + "\n" + info.request - + "\n" + contentLang + + "\n" + getContentLangString() + "\n" + info.serviceName + "\n" + BuildConfig.VERSION_NAME - + "\n" + osString; + + "\n" + getOsString(); infoView.setText(text); } + private String buildJson() { + JSONObject errorObject = new JSONObject(); + + try { + errorObject.put("user_action", getUserActionString(errorInfo.userAction)) + .put("request", errorInfo.request) + .put("content_language", getContentLangString()) + .put("service", errorInfo.serviceName) + .put("version", BuildConfig.VERSION_NAME) + .put("os", getOsString()); + + JSONArray exceptionArray = new JSONArray(); + for(Exception e : errorList) { + exceptionArray.put(ExceptionUtils.getStackTrace(e)); + } + + errorObject.put("exceptions", exceptionArray); + errorObject.put("user_comment", userCommentBox.getText().toString()); + + return errorObject.toString(3); + } catch (Exception e) { + Log.e(TAG, "Error while erroring: Could not build json"); + e.printStackTrace(); + } + + return ""; + } + + private String getUserActionString(int userAction) { + switch (userAction) { + case REQUESTED_STREAM: return REQUESTED_STREAM_STRING; + case SEARCHED: return SEARCHED_STRING; + default: return "Your description is in another castle."; + } + } + + private String getContentLangString() { + return PreferenceManager.getDefaultSharedPreferences(this) + .getString(this.getString(R.string.search_language_key), "none"); + } + + private String getOsString() { + String osBase = Build.VERSION.SDK_INT >= 23 ? Build.VERSION.BASE_OS : "Android"; + return System.getProperty("os.name") + + " " + (osBase.isEmpty() ? "Android" : osBase) + + " " + Build.VERSION.RELEASE + + " - " + Integer.toString(Build.VERSION.SDK_INT); + } + private void addGuruMeditaion() { //just an easter egg TextView sorryView = (TextView) findViewById(R.id.errorSorryView); diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 0bac36948..5c016f31f 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -330,8 +330,6 @@ public class YoutubeStreamExtractor implements StreamExtractor { @Override public String getUploader() throws ParsingException { - throw new ParsingException("blabla"); - /* try { if (playerArgs == null) { return videoInfoPage.get("author"); @@ -347,7 +345,6 @@ public class YoutubeStreamExtractor implements StreamExtractor { } catch (Exception e) { throw new ParsingException("failed permanently to load uploader name.", e); } - */ } @Override diff --git a/app/src/main/res/layout/activity_error.xml b/app/src/main/res/layout/activity_error.xml index 0b6fedb5a..68f61eeb3 100644 --- a/app/src/main/res/layout/activity_error.xml +++ b/app/src/main/res/layout/activity_error.xml @@ -46,15 +46,14 @@ + + + +