made error handling work a bit
This commit is contained in:
parent
27a2dee3bd
commit
64c423902a
|
@ -42,4 +42,5 @@ dependencies {
|
|||
compile 'de.hdodenhof:circleimageview:2.0.0'
|
||||
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
|
||||
compile 'com.github.nirhart:parallaxscroll:1.0'
|
||||
compile 'org.apache.directory.studio:org.apache.commons.lang:2.6'
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name=".ExitActivity"
|
||||
android:label="@string/general_error"
|
||||
android:theme="@android:style/Theme.NoDisplay" />
|
||||
<activity android:name=".errorhandling.ErrorActivity"></activity>
|
||||
</application>
|
||||
|
|
|
@ -22,10 +22,12 @@ package org.schabi.newpipe;
|
|||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Singleton:
|
||||
* Used to send data between certain Activity/Services within the same process.
|
||||
* This can be considered as hack inside the Android universe. **/
|
||||
* This can be considered as an ugly hack inside the Android universe. **/
|
||||
public class ActivityCommunicator {
|
||||
|
||||
private static ActivityCommunicator activityCommunicator = null;
|
||||
|
@ -39,4 +41,8 @@ public class ActivityCommunicator {
|
|||
|
||||
// Thumbnail send from VideoItemDetailFragment to BackgroundPlayer
|
||||
public volatile Bitmap backgroundPlayerThumbnail;
|
||||
|
||||
// Sent from any activity to ErrorActivity.
|
||||
public volatile List<Exception> errorList;
|
||||
public volatile Class returnActivity;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.schabi.newpipe.errorhandling.ErrorActivity;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.ParsingException;
|
||||
import org.schabi.newpipe.extractor.ServiceList;
|
||||
|
@ -166,10 +167,23 @@ public class VideoItemDetailFragment extends Fragment {
|
|||
});
|
||||
e.printStackTrace();
|
||||
} catch (ParsingException e) {
|
||||
postNewErrorToast(h, e.getMessage());
|
||||
ErrorActivity.reportError(h, getActivity(), e, 0, VideoItemListActivity.class);
|
||||
h.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
e.printStackTrace();
|
||||
} catch(Exception e) {
|
||||
postNewErrorToast(h, R.string.general_error);
|
||||
ErrorActivity.reportError(h, getActivity(), e,
|
||||
R.string.general_error, VideoItemListActivity.class);
|
||||
h.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if(videoInfo != null &&
|
||||
|
@ -178,6 +192,9 @@ public class VideoItemDetailFragment extends Fragment {
|
|||
for(Exception e : videoInfo.errors) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//todo: do not call directly ask the user if it should be reported
|
||||
ErrorActivity.reportError(h, getActivity(),
|
||||
videoInfo.errors, 0, VideoItemDetailActivity.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,12 +241,6 @@ public class VideoItemListActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
|
||||
|
||||
|
||||
/* this is for debuging only if this is still pressent in master branch kill the programmer */
|
||||
startActivity(new Intent(this, ErrorActivity.class));
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,15 +1,125 @@
|
|||
package org.schabi.newpipe.errorhandling;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.schabi.newpipe.ActivityCommunicator;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.VideoItemListActivity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class ErrorActivity extends AppCompatActivity {
|
||||
|
||||
private List<Exception> errorList;
|
||||
private Class returnActivity;
|
||||
|
||||
// views
|
||||
private TextView errorView;
|
||||
|
||||
public static void reportError(Context context, List<Exception> el, int message, Class returnAcitivty) {
|
||||
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
||||
ac.errorList = el;
|
||||
ac.returnActivity = returnAcitivty;
|
||||
Intent intent = new Intent(context, ErrorActivity.class);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void reportError(Context context, Exception e, int message, Class returnAcitivty) {
|
||||
List<Exception> el = new Vector<>();
|
||||
el.add(e);
|
||||
reportError(context, el, message, returnAcitivty);
|
||||
}
|
||||
|
||||
// async call
|
||||
public static void reportError(Handler handler, final Context context,
|
||||
final Exception e, final int message, final Class returnAcitivty) {
|
||||
List<Exception> el = new Vector<>();
|
||||
el.add(e);
|
||||
reportError(handler, context, el, message, returnAcitivty);
|
||||
}
|
||||
|
||||
// async call
|
||||
public static void reportError(Handler handler, final Context context,
|
||||
final List<Exception> el, final int message, final Class returnAcitivty) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reportError(context, el, message, returnAcitivty);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_error);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
||||
errorList = ac.errorList;
|
||||
returnActivity = ac.returnActivity;
|
||||
|
||||
errorView = (TextView) findViewById(R.id.errorView);
|
||||
errorView.setText(formErrorText(errorList));
|
||||
|
||||
//importand add gurumeditaion
|
||||
addGuruMeditaion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if (id == android.R.id.home) {
|
||||
goToReturnActivity();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String formErrorText(List<Exception> el) {
|
||||
String text = "";
|
||||
for(Exception e : el) {
|
||||
text += "-------------------------------------\n"
|
||||
+ ExceptionUtils.getStackTrace(e);
|
||||
}
|
||||
text += "-------------------------------------";
|
||||
return text;
|
||||
}
|
||||
|
||||
private void goToReturnActivity() {
|
||||
Intent intent;
|
||||
if(returnActivity != null &&
|
||||
returnActivity.isAssignableFrom(Activity.class)) {
|
||||
intent = new Intent(this, returnActivity);
|
||||
} else {
|
||||
intent = new Intent(this, VideoItemListActivity.class);
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
NavUtils.navigateUpTo(this, intent);
|
||||
}
|
||||
|
||||
private void addGuruMeditaion() {
|
||||
//just an easter egg
|
||||
TextView sorryView = (TextView) findViewById(R.id.errorSorryView);
|
||||
String text = sorryView.getText().toString();
|
||||
text += "\n" + getString(R.string.guru_meditation);
|
||||
sorryView.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
goToReturnActivity();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:gravity="center"
|
||||
android:text="@string/sorry_string"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
@ -44,35 +45,7 @@
|
|||
android:id="@+id/errorView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:typeface="monospace"
|
||||
android:text="asdkfjasdhfjshgfgnigregirenigneigheuigeorigjweogijhegiohegojiegoergjeogheoghweoghiehgohewgoiwehogihewrghieogh
|
||||

asdfgeogirejgoeirjgoregjogijegoiwejg
|
||||

wergjergljegoiejgoeigjogjeogjegohgeoigheognmgnbnorneog
|
||||

ergoegremgekgnonhotnhotrnhkhnh
|
||||

safs
|
||||

f
|
||||

s
|
||||

f
|
||||

f
|
||||

f
|
||||

safasf
|
||||

sageoigohntrh
|
||||

trhoijrhoirnhohintrionbobirnionb
|
||||

boitrnobinobnroni
|
||||

sadfsfagfkjgnsfdljhenvgoenvjibnoenpeoignweguihregpiorhnpoithtvhiohöio höio ho fvgegh gsfdsfd
|
||||

sfdaiohsfdiousfdahoiuhsfdaoiusfd oifdhoifdho fvigh fvuigupi refsfdasklsdfhsalkjfhsalkfjsa
|
||||

salgkjsfdgkjreog ehpio vpo hfgoeiwrhpwreo ibbuhwfgeubuh l jhjkb
|
||||
|
||||

ssfda
|
||||

sfda
|
||||

sfda
|
||||

sfda
|
||||


|
||||

sagrejgorigjeoigjgkofdjgölkfdjgsdökgjklgjoe
|
||||

sfdafgs
|
||||

dfg
|
||||

sd
|
||||

fg"/>
|
||||
android:typeface="monospace"/>
|
||||
</HorizontalScrollView>
|
||||
|
||||
<Button
|
||||
|
|
|
@ -89,7 +89,8 @@
|
|||
<string name="could_not_setup_download_menu">Could not setup download menu.</string>
|
||||
<string name="live_streams_not_supported">This is a LIVE STREAM. These are not yet supported.</string>
|
||||
<!-- error activity -->
|
||||
<string name="sorry_string">Sorry that shouldn#t have happened.</string>
|
||||
<string name="sorry_string">Sorry that should not happen.</string>
|
||||
<string name="guru_meditation" translatable="false">Guru Meditation.</string>
|
||||
<string name="error_report_button_text">Report error via mail</string>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue