Skip to content

Commit 81f740d

Browse files
committed
Replace ErrorActivity with ErrorUtil
1 parent 1d2642f commit 81f740d

29 files changed

Lines changed: 91 additions & 101 deletions

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import org.acra.config.ACRAConfigurationException;
1717
import org.acra.config.CoreConfiguration;
1818
import org.acra.config.CoreConfigurationBuilder;
19-
import org.schabi.newpipe.error.ErrorActivity;
2019
import org.schabi.newpipe.error.ErrorInfo;
20+
import org.schabi.newpipe.error.ErrorUtil;
2121
import org.schabi.newpipe.error.ReCaptchaActivity;
2222
import org.schabi.newpipe.error.UserAction;
2323
import org.schabi.newpipe.extractor.NewPipe;
@@ -217,7 +217,7 @@ protected void initACRA() {
217217
ACRA.init(this, acraConfig);
218218
} catch (final ACRAConfigurationException exception) {
219219
exception.printStackTrace();
220-
ErrorActivity.reportError(this, new ErrorInfo(exception,
220+
ErrorUtil.openActivity(this, new ErrorInfo(exception,
221221
UserAction.SOMETHING_ELSE, "Could not initialize ACRA crash report"));
222222
}
223223
}

app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import com.grack.nanojson.JsonParser;
2222
import com.grack.nanojson.JsonParserException;
2323

24-
import org.schabi.newpipe.error.ErrorActivity;
2524
import org.schabi.newpipe.error.ErrorInfo;
25+
import org.schabi.newpipe.error.ErrorUtil;
2626
import org.schabi.newpipe.error.UserAction;
2727
import org.schabi.newpipe.extractor.downloader.Response;
2828
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
@@ -64,7 +64,7 @@ private static String getCertificateSHA1Fingerprint(@NonNull final Application a
6464
signatures = PackageInfoCompat.getSignatures(application.getPackageManager(),
6565
application.getPackageName());
6666
} catch (final PackageManager.NameNotFoundException e) {
67-
ErrorActivity.reportError(application, new ErrorInfo(e,
67+
ErrorUtil.createNotification(application, new ErrorInfo(e,
6868
UserAction.CHECK_FOR_NEW_APP_VERSION, "Could not find package info"));
6969
return "";
7070
}
@@ -79,7 +79,7 @@ private static String getCertificateSHA1Fingerprint(@NonNull final Application a
7979
final CertificateFactory cf = CertificateFactory.getInstance("X509");
8080
c = (X509Certificate) cf.generateCertificate(input);
8181
} catch (final CertificateException e) {
82-
ErrorActivity.reportError(application, new ErrorInfo(e,
82+
ErrorUtil.createNotification(application, new ErrorInfo(e,
8383
UserAction.CHECK_FOR_NEW_APP_VERSION, "Certificate error"));
8484
return "";
8585
}
@@ -89,7 +89,7 @@ private static String getCertificateSHA1Fingerprint(@NonNull final Application a
8989
final byte[] publicKey = md.digest(c.getEncoded());
9090
return byte2HexFormatted(publicKey);
9191
} catch (NoSuchAlgorithmException | CertificateEncodingException e) {
92-
ErrorActivity.reportError(application, new ErrorInfo(e,
92+
ErrorUtil.createNotification(application, new ErrorInfo(e,
9393
UserAction.CHECK_FOR_NEW_APP_VERSION, "Could not retrieve SHA1 key"));
9494
return "";
9595
}

app/src/main/java/org/schabi/newpipe/MainActivity.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import org.schabi.newpipe.databinding.DrawerLayoutBinding;
6464
import org.schabi.newpipe.databinding.InstanceSpinnerLayoutBinding;
6565
import org.schabi.newpipe.databinding.ToolbarLayoutBinding;
66-
import org.schabi.newpipe.error.ErrorActivity;
66+
import org.schabi.newpipe.error.ErrorUtil;
6767
import org.schabi.newpipe.extractor.NewPipe;
6868
import org.schabi.newpipe.extractor.StreamingService;
6969
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -157,7 +157,7 @@ protected void onCreate(final Bundle savedInstanceState) {
157157
try {
158158
setupDrawer();
159159
} catch (final Exception e) {
160-
ErrorActivity.reportUiErrorInSnackbar(this, "Setting up drawer", e);
160+
ErrorUtil.showUiErrorSnackbar(this, "Setting up drawer", e);
161161
}
162162

163163
if (DeviceUtils.isTv(this)) {
@@ -214,7 +214,7 @@ public void onDrawerClosed(final View drawerView) {
214214
/**
215215
* Builds the drawer menu for the current service.
216216
*
217-
* @throws ExtractionException
217+
* @throws ExtractionException if the service didn't provide available kiosks
218218
*/
219219
private void addDrawerMenuForCurrentService() throws ExtractionException {
220220
//Tabs
@@ -266,7 +266,7 @@ private boolean drawerItemSelected(final MenuItem item) {
266266
try {
267267
tabSelected(item);
268268
} catch (final Exception e) {
269-
ErrorActivity.reportUiErrorInSnackbar(this, "Selecting main page tab", e);
269+
ErrorUtil.showUiErrorSnackbar(this, "Selecting main page tab", e);
270270
}
271271
break;
272272
case R.id.menu_options_about_group:
@@ -372,7 +372,7 @@ private void toggleServices() {
372372
try {
373373
addDrawerMenuForCurrentService();
374374
} catch (final Exception e) {
375-
ErrorActivity.reportUiErrorInSnackbar(this, "Showing main page tabs", e);
375+
ErrorUtil.showUiErrorSnackbar(this, "Showing main page tabs", e);
376376
}
377377
}
378378
}
@@ -475,7 +475,7 @@ protected void onResume() {
475475
drawerHeaderBinding.drawerHeaderActionButton.setContentDescription(
476476
getString(R.string.drawer_header_description) + selectedServiceName);
477477
} catch (final Exception e) {
478-
ErrorActivity.reportUiErrorInSnackbar(this, "Setting up service toggle", e);
478+
ErrorUtil.showUiErrorSnackbar(this, "Setting up service toggle", e);
479479
}
480480

481481
final SharedPreferences sharedPreferences
@@ -785,7 +785,7 @@ private void handleIntent(final Intent intent) {
785785
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
786786
}
787787
} catch (final Exception e) {
788-
ErrorActivity.reportUiErrorInSnackbar(this, "Handling intent", e);
788+
ErrorUtil.showUiErrorSnackbar(this, "Handling intent", e);
789789
}
790790
}
791791

app/src/main/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import org.schabi.newpipe.databinding.ListRadioIconItemBinding;
3838
import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding;
3939
import org.schabi.newpipe.download.DownloadDialog;
40-
import org.schabi.newpipe.error.ErrorActivity;
4140
import org.schabi.newpipe.error.ErrorInfo;
41+
import org.schabi.newpipe.error.ErrorUtil;
4242
import org.schabi.newpipe.error.ReCaptchaActivity;
4343
import org.schabi.newpipe.error.UserAction;
4444
import org.schabi.newpipe.extractor.Info;
@@ -231,7 +231,7 @@ private static void handleError(final Context context, final ErrorInfo errorInfo
231231
} else if (errorInfo.getThrowable() instanceof ContentNotSupportedException) {
232232
Toast.makeText(context, R.string.content_not_supported, Toast.LENGTH_LONG).show();
233233
} else {
234-
ErrorActivity.reportError(context, errorInfo);
234+
ErrorUtil.createNotification(context, errorInfo);
235235
}
236236

237237
if (context instanceof RouterActivity) {

app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
import org.schabi.newpipe.MainActivity;
4242
import org.schabi.newpipe.R;
4343
import org.schabi.newpipe.databinding.DownloadDialogBinding;
44-
import org.schabi.newpipe.error.ErrorActivity;
4544
import org.schabi.newpipe.error.ErrorInfo;
45+
import org.schabi.newpipe.error.ErrorUtil;
4646
import org.schabi.newpipe.error.UserAction;
4747
import org.schabi.newpipe.extractor.MediaFormat;
4848
import org.schabi.newpipe.extractor.NewPipe;
@@ -402,7 +402,7 @@ private void fetchStreamsSize() {
402402
== R.id.video_button) {
403403
setupVideoSpinner();
404404
}
405-
}, throwable -> ErrorActivity.reportErrorInSnackbar(context,
405+
}, throwable -> ErrorUtil.showSnackbar(context,
406406
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
407407
"Downloading video stream size",
408408
currentInfo.getServiceId()))));
@@ -412,7 +412,7 @@ private void fetchStreamsSize() {
412412
== R.id.audio_button) {
413413
setupAudioSpinner();
414414
}
415-
}, throwable -> ErrorActivity.reportErrorInSnackbar(context,
415+
}, throwable -> ErrorUtil.showSnackbar(context,
416416
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
417417
"Downloading audio stream size",
418418
currentInfo.getServiceId()))));
@@ -422,7 +422,7 @@ private void fetchStreamsSize() {
422422
== R.id.subtitle_button) {
423423
setupSubtitleSpinner();
424424
}
425-
}, throwable -> ErrorActivity.reportErrorInSnackbar(context,
425+
}, throwable -> ErrorUtil.showSnackbar(context,
426426
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
427427
"Downloading subtitle stream size",
428428
currentInfo.getServiceId()))));
@@ -799,7 +799,7 @@ private void checkSelectedDownload(final StoredDirectoryHelper mainStorage,
799799
mainStorage.getTag());
800800
}
801801
} catch (final Exception e) {
802-
ErrorActivity.reportErrorInSnackbar(this,
802+
ErrorUtil.createNotification(requireContext(),
803803
new ErrorInfo(e, UserAction.DOWNLOAD_FAILED, "Getting storage"));
804804
return;
805805
}

app/src/main/java/org/schabi/newpipe/error/AcraReportSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class AcraReportSender implements ReportSender {
3333

3434
@Override
3535
public void send(@NonNull final Context context, @NonNull final CrashReportData report) {
36-
ErrorActivity.reportError(context, new ErrorInfo(
36+
ErrorUtil.openActivity(context, new ErrorInfo(
3737
new String[]{report.getString(ReportField.STACK_TRACE)},
3838
UserAction.UI_ERROR,
3939
ErrorInfo.SERVICE_NONE,

app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
5353
*/
5454

55-
class ErrorActivity extends AppCompatActivity {
55+
public class ErrorActivity extends AppCompatActivity {
5656
// LOG TAGS
5757
public static final String TAG = ErrorActivity.class.toString();
5858
// BUNDLE TAGS

app/src/main/java/org/schabi/newpipe/error/ErrorPanelHelper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ErrorPanelHelper(
118118
showAndSetErrorButtonAction(
119119
R.string.error_snackbar_action
120120
) {
121-
ErrorActivity.reportError(context, errorInfo)
121+
ErrorUtil.openActivity(context, errorInfo)
122122
}
123123

124124
errorTextView.setText(getExceptionDescription(errorInfo.throwable))
@@ -178,7 +178,7 @@ class ErrorPanelHelper(
178178
val DEBUG: Boolean = MainActivity.DEBUG
179179

180180
@StringRes
181-
public fun getExceptionDescription(throwable: Throwable?): Int {
181+
fun getExceptionDescription(throwable: Throwable?): Int {
182182
return when (throwable) {
183183
is AgeRestrictedContentException -> R.string.restricted_video_no_stream
184184
is GeographicRestrictionException -> R.string.georestricted_content

app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.schabi.newpipe.R
1414

1515
class ErrorUtil {
1616
companion object {
17-
private const val ERROR_REPORT_NOTIFICATION_ID = 5340681;
17+
private const val ERROR_REPORT_NOTIFICATION_ID = 5340681
1818

1919
/**
2020
* Reports a new error by starting a new activity.
@@ -62,35 +62,35 @@ class ErrorUtil {
6262
@JvmStatic
6363
fun createNotification(context: Context, errorInfo: ErrorInfo) {
6464
val notificationManager =
65-
ContextCompat.getSystemService(context, NotificationManager::class.java)
65+
ContextCompat.getSystemService(context, NotificationManager::class.java)
6666
if (notificationManager == null) {
6767
// this should never happen, but just in case open error activity
6868
openActivity(context, errorInfo)
6969
}
7070

7171
val notificationBuilder: NotificationCompat.Builder =
72-
NotificationCompat.Builder(context,
73-
context.getString(R.string.error_report_channel_id))
74-
.setSmallIcon(R.drawable.ic_bug_report)
75-
.setContentTitle(context.getString(R.string.error_report_title))
76-
.setContentText(context.getString(errorInfo.messageStringId))
72+
NotificationCompat.Builder(
73+
context,
74+
context.getString(R.string.error_report_channel_id)
75+
)
76+
.setSmallIcon(R.drawable.ic_bug_report)
77+
.setContentTitle(context.getString(R.string.error_report_title))
78+
.setContentText(context.getString(errorInfo.messageStringId))
7779

7880
notificationManager!!.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
7981
}
8082

81-
8283
private fun showSnackbar(context: Context, rootView: View?, errorInfo: ErrorInfo) {
8384
if (rootView == null) {
8485
// fallback to showing a notification if no root view is available
8586
createNotification(context, errorInfo)
86-
8787
} else {
8888
Snackbar.make(rootView, R.string.error_snackbar_message, Snackbar.LENGTH_LONG)
89-
.setActionTextColor(Color.YELLOW)
90-
.setAction(context.getString(R.string.error_snackbar_action).uppercase()) {
91-
openActivity(context, errorInfo)
92-
}.show()
89+
.setActionTextColor(Color.YELLOW)
90+
.setAction(context.getString(R.string.error_snackbar_action).uppercase()) {
91+
openActivity(context, errorInfo)
92+
}.show()
9393
}
9494
}
9595
}
96-
}
96+
}

app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
import androidx.annotation.NonNull;
99
import androidx.annotation.Nullable;
10+
import androidx.fragment.app.Fragment;
1011

1112
import org.schabi.newpipe.BaseFragment;
1213
import org.schabi.newpipe.R;
13-
import org.schabi.newpipe.error.ErrorActivity;
1414
import org.schabi.newpipe.error.ErrorInfo;
1515
import org.schabi.newpipe.error.ErrorPanelHelper;
16+
import org.schabi.newpipe.error.ErrorUtil;
1617
import org.schabi.newpipe.util.InfoCache;
1718

1819
import java.util.concurrent.atomic.AtomicBoolean;
@@ -198,16 +199,15 @@ public final boolean isErrorPanelVisible() {
198199
}
199200

200201
/**
201-
* Show a SnackBar and only call
202-
* {@link ErrorActivity#reportErrorInSnackbar(androidx.fragment.app.Fragment, ErrorInfo)}
203-
* IF we a find a valid view (otherwise the error screen appears).
202+
* Directly calls {@link ErrorUtil#showSnackbar(Fragment, ErrorInfo)}, that shows a snackbar if
203+
* a valid view can be found, otherwise creates an error report notification.
204204
*
205205
* @param errorInfo The error information
206206
*/
207207
public void showSnackBarError(final ErrorInfo errorInfo) {
208208
if (DEBUG) {
209209
Log.d(TAG, "showSnackBarError() called with: errorInfo = [" + errorInfo + "]");
210210
}
211-
ErrorActivity.reportErrorInSnackbar(this, errorInfo);
211+
ErrorUtil.showSnackbar(this, errorInfo);
212212
}
213213
}

0 commit comments

Comments
 (0)