add send via mail/share feature
This commit is contained in:
parent
7caf7be97e
commit
369d9204d9
|
@ -1,9 +1,12 @@
|
||||||
package org.schabi.newpipe;
|
|
||||||
|
|
||||||
|
|
||||||
|
package org.schabi.newpipe;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.MailTo;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
|
@ -11,16 +14,43 @@ import android.support.v4.app.NavUtils;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
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.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Christian Schabesberger on 24.10.15.
|
||||||
|
*
|
||||||
|
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
public class ErrorActivity extends AppCompatActivity {
|
public class ErrorActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static class ErrorInfo {
|
public static class ErrorInfo {
|
||||||
|
@ -44,6 +74,8 @@ public class ErrorActivity extends AppCompatActivity {
|
||||||
public static final int REQUESTED_STREAM = 1;
|
public static final int REQUESTED_STREAM = 1;
|
||||||
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 ERROR_EMAIL_ADDRESS = "dummy@dummy.org";
|
||||||
|
public static final String ERROR_EMAIL_SUBJECT="Exception in NewPipe " + BuildConfig.VERSION_NAME;
|
||||||
|
|
||||||
private List<Exception> errorList;
|
private List<Exception> errorList;
|
||||||
private ErrorInfo errorInfo;
|
private ErrorInfo errorInfo;
|
||||||
|
@ -51,6 +83,7 @@ public class ErrorActivity extends AppCompatActivity {
|
||||||
|
|
||||||
// views
|
// views
|
||||||
private TextView errorView;
|
private TextView errorView;
|
||||||
|
private EditText userCommentBox;
|
||||||
|
|
||||||
public static void reportError(final Context context, final List<Exception> el,
|
public static void reportError(final Context context, final List<Exception> el,
|
||||||
final Class returnAcitivty, View rootView, final ErrorInfo errorInfo) {
|
final Class returnAcitivty, View rootView, final ErrorInfo errorInfo) {
|
||||||
|
@ -113,6 +146,8 @@ public class ErrorActivity extends AppCompatActivity {
|
||||||
returnActivity = ac.returnActivity;
|
returnActivity = ac.returnActivity;
|
||||||
errorInfo = ac.errorInfo;
|
errorInfo = ac.errorInfo;
|
||||||
|
|
||||||
|
Button reportButton = (Button) findViewById(R.id.errorReportButton);
|
||||||
|
userCommentBox = (EditText) findViewById(R.id.errorCommentBox);
|
||||||
errorView = (TextView) findViewById(R.id.errorView);
|
errorView = (TextView) findViewById(R.id.errorView);
|
||||||
|
|
||||||
errorView.setText(formErrorText(errorList));
|
errorView.setText(formErrorText(errorList));
|
||||||
|
@ -120,14 +155,43 @@ public class ErrorActivity extends AppCompatActivity {
|
||||||
//importand add gurumeditaion
|
//importand add gurumeditaion
|
||||||
addGuruMeditaion();
|
addGuruMeditaion();
|
||||||
buildInfo(errorInfo);
|
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
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
if (id == android.R.id.home) {
|
switch(id) {
|
||||||
|
case android.R.id.home:
|
||||||
goToReturnActivity();
|
goToReturnActivity();
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -165,35 +229,65 @@ public class ErrorActivity extends AppCompatActivity {
|
||||||
|
|
||||||
infoLabelView.setText(getString(R.string.info_labels).replace("\\n", "\n"));
|
infoLabelView.setText(getString(R.string.info_labels).replace("\\n", "\n"));
|
||||||
|
|
||||||
String whatString = "";
|
text += getUserActionString(info.userAction)
|
||||||
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
|
|
||||||
+ "\n" + info.request
|
+ "\n" + info.request
|
||||||
+ "\n" + contentLang
|
+ "\n" + getContentLangString()
|
||||||
+ "\n" + info.serviceName
|
+ "\n" + info.serviceName
|
||||||
+ "\n" + BuildConfig.VERSION_NAME
|
+ "\n" + BuildConfig.VERSION_NAME
|
||||||
+ "\n" + osString;
|
+ "\n" + getOsString();
|
||||||
|
|
||||||
infoView.setText(text);
|
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() {
|
private void addGuruMeditaion() {
|
||||||
//just an easter egg
|
//just an easter egg
|
||||||
TextView sorryView = (TextView) findViewById(R.id.errorSorryView);
|
TextView sorryView = (TextView) findViewById(R.id.errorSorryView);
|
||||||
|
|
|
@ -330,8 +330,6 @@ public class YoutubeStreamExtractor implements StreamExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUploader() throws ParsingException {
|
public String getUploader() throws ParsingException {
|
||||||
throw new ParsingException("blabla");
|
|
||||||
/*
|
|
||||||
try {
|
try {
|
||||||
if (playerArgs == null) {
|
if (playerArgs == null) {
|
||||||
return videoInfoPage.get("author");
|
return videoInfoPage.get("author");
|
||||||
|
@ -347,7 +345,6 @@ public class YoutubeStreamExtractor implements StreamExtractor {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ParsingException("failed permanently to load uploader name.", e);
|
throw new ParsingException("failed permanently to load uploader name.", e);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,15 +46,14 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/errorInfoLabelsView"
|
android:id="@+id/errorInfoLabelsView"
|
||||||
android:layout_weight="1"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="200dp"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:text="@string/info_labels"/>
|
android:text="@string/info_labels"/>
|
||||||
|
|
||||||
<HorizontalScrollView
|
<HorizontalScrollView
|
||||||
android:layout_weight="1"
|
android:paddingLeft="16dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -86,6 +85,19 @@
|
||||||
android:typeface="monospace"/>
|
android:typeface="monospace"/>
|
||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/errorYourComment"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:text="@string/your_comment"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/errorCommentBox"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/errorReportButton"
|
android:id="@+id/errorReportButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item android:id="@+id/menu_item_share_error"
|
||||||
|
android:title="@string/share"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
android:icon="@drawable/ic_share_black"/>
|
||||||
|
</menu>
|
|
@ -99,7 +99,7 @@
|
||||||
<string name="info_labels">What:\\nRequest:\\nContent Lang:\\nService:\\nVersion:\\nOS version:</string>
|
<string name="info_labels">What:\\nRequest:\\nContent Lang:\\nService:\\nVersion:\\nOS version:</string>
|
||||||
<string name="info_searched_lbl">Searched for:</string>
|
<string name="info_searched_lbl">Searched for:</string>
|
||||||
<string name="info_requested_stream_lbl">Requested stream:</string>
|
<string name="info_requested_stream_lbl">Requested stream:</string>
|
||||||
<string name="your_commend">Your commend:</string>
|
<string name="your_comment">Your comment (in English):</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Content descriptions (for better accessibility) -->
|
<!-- Content descriptions (for better accessibility) -->
|
||||||
|
|
Loading…
Reference in New Issue