From 92ab575b150ab49ca85e0ac994558142e49c9e68 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 5 Apr 2024 19:20:27 +0200 Subject: Delete core module (#7060) --- ui/common/build.gradle | 2 + .../antennapod/ui/common/ConfirmationDialog.java | 54 +++++++++++++++++ .../danoeh/antennapod/ui/common/IntentUtils.java | 67 ++++++++++++++++++++++ .../src/main/res/drawable/bg_blue_gradient.xml | 10 ++++ ui/common/src/main/res/drawable/bg_circle.xml | 6 ++ ui/common/src/main/res/drawable/bg_drawer_item.xml | 20 +++++++ ui/common/src/main/res/drawable/bg_gradient.xml | 10 ++++ ui/common/src/main/res/drawable/bg_pill.xml | 7 +++ .../src/main/res/drawable/bg_rounded_corners.xml | 6 ++ ui/common/website-languages.txt | 7 +++ 10 files changed, 189 insertions(+) create mode 100644 ui/common/src/main/java/de/danoeh/antennapod/ui/common/ConfirmationDialog.java create mode 100644 ui/common/src/main/java/de/danoeh/antennapod/ui/common/IntentUtils.java create mode 100644 ui/common/src/main/res/drawable/bg_blue_gradient.xml create mode 100644 ui/common/src/main/res/drawable/bg_circle.xml create mode 100644 ui/common/src/main/res/drawable/bg_drawer_item.xml create mode 100644 ui/common/src/main/res/drawable/bg_gradient.xml create mode 100644 ui/common/src/main/res/drawable/bg_pill.xml create mode 100644 ui/common/src/main/res/drawable/bg_rounded_corners.xml create mode 100644 ui/common/website-languages.txt (limited to 'ui/common') diff --git a/ui/common/build.gradle b/ui/common/build.gradle index 1325761d3..f2916593a 100644 --- a/ui/common/build.gradle +++ b/ui/common/build.gradle @@ -16,6 +16,8 @@ dependencies { implementation "androidx.viewpager2:viewpager2:$viewPager2Version" implementation "com.google.android.material:material:$googleMaterialVersion" implementation "androidx.core:core-splashscreen:1.0.0" + implementation "org.apache.commons:commons-lang3:$commonslangVersion" + implementation "commons-io:commons-io:$commonsioVersion" testImplementation "junit:junit:$junitVersion" } diff --git a/ui/common/src/main/java/de/danoeh/antennapod/ui/common/ConfirmationDialog.java b/ui/common/src/main/java/de/danoeh/antennapod/ui/common/ConfirmationDialog.java new file mode 100644 index 000000000..8acedc7d3 --- /dev/null +++ b/ui/common/src/main/java/de/danoeh/antennapod/ui/common/ConfirmationDialog.java @@ -0,0 +1,54 @@ +package de.danoeh.antennapod.ui.common; + +import android.content.Context; +import android.content.DialogInterface; +import androidx.appcompat.app.AlertDialog; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import android.util.Log; + +/** + * Creates an AlertDialog which asks the user to confirm something. Other + * classes can handle events like confirmation or cancellation. + */ +public abstract class ConfirmationDialog { + + private static final String TAG = ConfirmationDialog.class.getSimpleName(); + + private final Context context; + private final int titleId; + private final String message; + + private int positiveText; + + public ConfirmationDialog(Context context, int titleId, int messageId) { + this(context, titleId, context.getString(messageId)); + } + + public ConfirmationDialog(Context context, int titleId, String message) { + this.context = context; + this.titleId = titleId; + this.message = message; + } + + private void onCancelButtonPressed(DialogInterface dialog) { + Log.d(TAG, "Dialog was cancelled"); + dialog.dismiss(); + } + + public void setPositiveText(int id) { + this.positiveText = id; + } + + public abstract void onConfirmButtonPressed(DialogInterface dialog); + + public final AlertDialog createNewDialog() { + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context); + builder.setTitle(titleId); + builder.setMessage(message); + builder.setPositiveButton(positiveText != 0 ? positiveText : R.string.confirm_label, + (dialog, which) -> onConfirmButtonPressed(dialog)); + builder.setNegativeButton(R.string.cancel_label, (dialog, which) -> onCancelButtonPressed(dialog)); + builder.setOnCancelListener(ConfirmationDialog.this::onCancelButtonPressed); + return builder.create(); + } +} diff --git a/ui/common/src/main/java/de/danoeh/antennapod/ui/common/IntentUtils.java b/ui/common/src/main/java/de/danoeh/antennapod/ui/common/IntentUtils.java new file mode 100644 index 000000000..26c703e7b --- /dev/null +++ b/ui/common/src/main/java/de/danoeh/antennapod/ui/common/IntentUtils.java @@ -0,0 +1,67 @@ +package de.danoeh.antennapod.ui.common; + +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.net.Uri; +import android.util.Log; +import android.widget.Toast; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ArrayUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Locale; + +public class IntentUtils { + private static final String TAG = "IntentUtils"; + + private IntentUtils(){} + + /* + * Checks if there is at least one exported activity that can be performed for the intent + */ + public static boolean isCallable(final Context context, final Intent intent) { + List list = context.getPackageManager().queryIntentActivities(intent, + PackageManager.MATCH_DEFAULT_ONLY); + for(ResolveInfo info : list) { + if(info.activityInfo.exported) { + return true; + } + } + return false; + } + + public static void sendLocalBroadcast(Context context, String action) { + context.sendBroadcast(new Intent(action).setPackage(context.getPackageName())); + } + + public static void openInBrowser(Context context, String url) { + try { + Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(myIntent); + } catch (ActivityNotFoundException e) { + Toast.makeText(context, R.string.pref_no_browser_found, Toast.LENGTH_LONG).show(); + Log.e(TAG, Log.getStackTraceString(e)); + } + } + + public static String getLocalizedWebsiteLink(Context context) { + try (InputStream is = context.getAssets().open("website-languages.txt")) { + String[] languages = IOUtils.toString(is, StandardCharsets.UTF_8.name()).split("\n"); + String deviceLanguage = Locale.getDefault().getLanguage(); + if (ArrayUtils.contains(languages, deviceLanguage) && !"en".equals(deviceLanguage)) { + return "https://antennapod.org/" + deviceLanguage; + } else { + return "https://antennapod.org"; + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/ui/common/src/main/res/drawable/bg_blue_gradient.xml b/ui/common/src/main/res/drawable/bg_blue_gradient.xml new file mode 100644 index 000000000..8ae045b6d --- /dev/null +++ b/ui/common/src/main/res/drawable/bg_blue_gradient.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/ui/common/src/main/res/drawable/bg_circle.xml b/ui/common/src/main/res/drawable/bg_circle.xml new file mode 100644 index 000000000..0957db5e4 --- /dev/null +++ b/ui/common/src/main/res/drawable/bg_circle.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/common/src/main/res/drawable/bg_drawer_item.xml b/ui/common/src/main/res/drawable/bg_drawer_item.xml new file mode 100644 index 000000000..40727bf50 --- /dev/null +++ b/ui/common/src/main/res/drawable/bg_drawer_item.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/ui/common/src/main/res/drawable/bg_gradient.xml b/ui/common/src/main/res/drawable/bg_gradient.xml new file mode 100644 index 000000000..5022240b3 --- /dev/null +++ b/ui/common/src/main/res/drawable/bg_gradient.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/ui/common/src/main/res/drawable/bg_pill.xml b/ui/common/src/main/res/drawable/bg_pill.xml new file mode 100644 index 000000000..f5865ccff --- /dev/null +++ b/ui/common/src/main/res/drawable/bg_pill.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/ui/common/src/main/res/drawable/bg_rounded_corners.xml b/ui/common/src/main/res/drawable/bg_rounded_corners.xml new file mode 100644 index 000000000..11b7710c4 --- /dev/null +++ b/ui/common/src/main/res/drawable/bg_rounded_corners.xml @@ -0,0 +1,6 @@ + + + + diff --git a/ui/common/website-languages.txt b/ui/common/website-languages.txt new file mode 100644 index 000000000..64361314b --- /dev/null +++ b/ui/common/website-languages.txt @@ -0,0 +1,7 @@ +en +fr +nl +it +da +de +es -- cgit v1.2.3