Skip to content

Commit

Permalink
feat: setting for downloader package name
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 22, 2022
1 parent 6f5596f commit 8b09228
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
public enum SettingsEnum {
//Download Settings
// TODO: DOWNLOAD_PATH("revanced_download_path", Environment.getExternalStorageDirectory().getPath() + "/Download", ReturnType.STRING),
DOWNLOAD_BUTTON_SHOWN("revanced_downloads", true, ReturnType.BOOLEAN),
DOWNLOADS_BUTTON_SHOWN("revanced_downloads", true, ReturnType.BOOLEAN),
DOWNLOADS_PACKAGE_NAME("revanced_downloads_package_name", "org.schabi.newpipe" /* NewPipe */, ReturnType.STRING),

//Video Settings
OLD_STYLE_QUALITY_SETTINGS("revanced_use_old_style_quality_settings", true, ReturnType.BOOLEAN),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.revanced.integrations.videoplayer;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -48,20 +47,19 @@ public static void initializeDownloadButton(Object obj) {
LogHelper.debug(DownloadButton.class, "Download button clicked");

final var context = view.getContext();
final var powerTubePackageName = "ussr.razar.youtube_dl";
var downloaderPackageName = SettingsEnum.DOWNLOADS_PACKAGE_NAME.getString();

boolean packageEnabled = false;
try {
assert context != null;
packageEnabled = context.getPackageManager().getApplicationInfo(powerTubePackageName, 0).enabled;
packageEnabled = context.getPackageManager().getApplicationInfo(downloaderPackageName, 0).enabled;
} catch (PackageManager.NameNotFoundException error) {
LogHelper.debug(DownloadButton.class, "PowerTube could not be found: " + error);
LogHelper.debug(DownloadButton.class, "Downloader could not be found: " + error);
}

// If the package is not installed, show the toast
if (!packageEnabled) {
Toast.makeText(context, StringRef.str("powertube_not_installed_warning"), Toast.LENGTH_SHORT).show();
Toast.makeText(context, StringRef.str("powertube_not_installed_notice"), Toast.LENGTH_LONG).show();
Toast.makeText(context, downloaderPackageName + " " + StringRef.str("downloader_not_installed_warning"), Toast.LENGTH_LONG).show();
return;
}

Expand All @@ -71,7 +69,7 @@ public static void initializeDownloadButton(Object obj) {

Intent intent = new Intent("android.intent.action.SEND");
intent.setType("text/plain");
intent.setPackage(powerTubePackageName);
intent.setPackage(downloaderPackageName);
intent.putExtra("android.intent.extra.TEXT", content);
context.startActivity(intent);

Expand Down Expand Up @@ -129,7 +127,7 @@ public static void refreshShouldBeShown() {
}

private static boolean shouldBeShown() {
if (!SettingsEnum.DOWNLOAD_BUTTON_SHOWN.getBoolean()) {
if (!SettingsEnum.DOWNLOADS_BUTTON_SHOWN.getBoolean()) {
return false;
}

Expand Down

0 comments on commit 8b09228

Please sign in to comment.