summaryrefslogtreecommitdiff
path: root/ui/common
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-04-05 19:20:27 +0200
committerGitHub <noreply@github.com>2024-04-05 19:20:27 +0200
commit92ab575b150ab49ca85e0ac994558142e49c9e68 (patch)
tree422dcd76895a4ba06ed02723ff61351435c0fe49 /ui/common
parent2143ab135182434911d4554a8ef08115eaa0d2d0 (diff)
downloadAntennaPod-92ab575b150ab49ca85e0ac994558142e49c9e68.zip
Delete core module (#7060)
Diffstat (limited to 'ui/common')
-rw-r--r--ui/common/build.gradle2
-rw-r--r--ui/common/src/main/java/de/danoeh/antennapod/ui/common/ConfirmationDialog.java54
-rw-r--r--ui/common/src/main/java/de/danoeh/antennapod/ui/common/IntentUtils.java67
-rw-r--r--ui/common/src/main/res/drawable/bg_blue_gradient.xml10
-rw-r--r--ui/common/src/main/res/drawable/bg_circle.xml6
-rw-r--r--ui/common/src/main/res/drawable/bg_drawer_item.xml20
-rw-r--r--ui/common/src/main/res/drawable/bg_gradient.xml10
-rw-r--r--ui/common/src/main/res/drawable/bg_pill.xml7
-rw-r--r--ui/common/src/main/res/drawable/bg_rounded_corners.xml6
-rw-r--r--ui/common/website-languages.txt7
10 files changed, 189 insertions, 0 deletions
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<ResolveInfo> 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
+ <gradient
+ android:angle="90"
+ android:endColor="@color/gradient_025"
+ android:startColor="@color/gradient_075"
+ android:type="linear" />
+ <corners
+ android:radius="0dp"/>
+</shape>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+ <solid android:color="?attr/colorPrimary" />
+ <corners android:radius="30dp" />
+ <size android:width="60dp" android:height="60dp"/>
+</shape>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?attr/colorSurfaceVariant">
+ <item android:id="@android:id/mask">
+ <shape android:shape="rectangle">
+ <solid android:color="@color/black"/>
+ <corners android:radius="32dp"/>
+ </shape>
+ </item>
+ <item>
+ <selector>
+ <item android:state_selected="true">
+ <shape android:shape="rectangle">
+ <solid android:color="?attr/colorSurfaceVariant"/>
+ <corners android:radius="32dp"/>
+ </shape>
+ </item>
+ <item android:drawable="@android:color/transparent" />
+ </selector>
+ </item>
+</ripple>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
+ <gradient
+ android:angle="90"
+ android:endColor="#00ffffff"
+ android:startColor="#ffffffff"
+ android:type="linear" />
+ <corners
+ android:radius="0dp"/>
+</shape> \ 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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+ <stroke
+ android:width="1dp"
+ android:color="?attr/colorPrimary" />
+ <corners android:radius="20dp" />
+</shape> \ 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <corners android:radius="8dp" />
+</shape>
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