diff options
author | ByteHamster <info@bytehamster.com> | 2020-10-25 17:31:47 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-10-25 17:31:47 +0100 |
commit | c8a2f20000032228226149500767ba903752e0a5 (patch) | |
tree | 0c56db9a3d01f6ce916d26d84a7ae9ca0ec5b60d /app/src/main/java/de/danoeh/antennapod/dialog | |
parent | 28ebbedbdf34b72b31c536a118bcf5108b3ea7e5 (diff) | |
parent | 3e4e6381bd39a40b210e5b6ab054e3adee371330 (diff) | |
download | AntennaPod-c8a2f20000032228226149500767ba903752e0a5.zip |
Merge branch 'develop' into add-local-feeds
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/dialog')
6 files changed, 94 insertions, 156 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/FeedFilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/FeedFilterDialog.java deleted file mode 100644 index 3b0e2d04b..000000000 --- a/app/src/main/java/de/danoeh/antennapod/dialog/FeedFilterDialog.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.danoeh.antennapod.dialog; - -import android.content.Context; - -import androidx.appcompat.app.AlertDialog; - -import org.greenrobot.eventbus.EventBus; - -import java.util.Arrays; -import java.util.List; - -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; -import de.danoeh.antennapod.core.preferences.UserPreferences; - -public class FeedFilterDialog { - public static void showDialog(Context context) { - AlertDialog.Builder dialog = new AlertDialog.Builder(context); - dialog.setTitle(context.getString(R.string.pref_filter_feed_title)); - dialog.setNegativeButton(android.R.string.cancel, (d, listener) -> d.dismiss()); - - int selected = UserPreferences.getFeedFilter(); - List<String> entryValues = - Arrays.asList(context.getResources().getStringArray(R.array.nav_drawer_feed_filter_values)); - final int selectedIndex = entryValues.indexOf("" + selected); - - String[] items = context.getResources().getStringArray(R.array.nav_drawer_feed_filter_options); - dialog.setSingleChoiceItems(items, selectedIndex, (d, which) -> { - if (selectedIndex != which) { - UserPreferences.setFeedFilter(entryValues.get(which)); - //Update subscriptions - EventBus.getDefault().post(new UnreadItemsUpdateEvent()); - } - d.dismiss(); - }); - dialog.show(); - } -} diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java index e45533826..98f6cc117 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.dialog; import android.app.Dialog; import android.os.Bundle; import android.os.Handler; +import android.os.Looper; import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -94,7 +95,7 @@ public class PlaybackControlsDialog extends DialogFragment { barRightVolume.setEnabled(false); } - final CheckBox skipSilence = (CheckBox) dialog.findViewById(R.id.skipSilence); + final CheckBox skipSilence = dialog.findViewById(R.id.skipSilence); skipSilence.setChecked(UserPreferences.isSkipSilence()); if (!UserPreferences.useExoplayer()) { skipSilence.setEnabled(false); @@ -159,7 +160,7 @@ public class PlaybackControlsDialog extends DialogFragment { butAudioTracks.setText(audioTracks.get(selectedAudioTrack)); butAudioTracks.setOnClickListener(v -> { controller.setAudioTrack((selectedAudioTrack + 1) % audioTracks.size()); - new Handler().postDelayed(this::setupAudioTracks, 500); + new Handler(Looper.getMainLooper()).postDelayed(this::setupAudioTracks, 500); }); } } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java deleted file mode 100644 index 7cb274708..000000000 --- a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java +++ /dev/null @@ -1,113 +0,0 @@ -package de.danoeh.antennapod.dialog; - -import android.app.Dialog; -import android.content.Context; -import android.content.SharedPreferences; -import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; -import android.util.Log; - -import java.lang.ref.WeakReference; -import java.util.concurrent.TimeUnit; - -import androidx.appcompat.app.AlertDialog; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.util.IntentUtils; - -public class RatingDialog { - - private RatingDialog(){} - - private static final String TAG = RatingDialog.class.getSimpleName(); - private static final int AFTER_DAYS = 7; - - private static WeakReference<Context> mContext; - private static SharedPreferences mPreferences; - private static Dialog mDialog; - - private static final String PREFS_NAME = "RatingPrefs"; - private static final String KEY_RATED = "KEY_WAS_RATED"; - private static final String KEY_FIRST_START_DATE = "KEY_FIRST_HIT_DATE"; - - public static void init(Context context) { - mContext = new WeakReference<>(context); - mPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - - long firstDate = mPreferences.getLong(KEY_FIRST_START_DATE, 0); - if (firstDate == 0) { - resetStartDate(); - } - } - - public static void check() { - if (mDialog != null && mDialog.isShowing()) { - return; - } - if (shouldShow()) { - try { - mDialog = createDialog(); - if (mDialog != null) { - mDialog.show(); - } - } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); - } - } - } - - private static void rateNow() { - Context context = mContext.get(); - if (context == null) { - return; - } - IntentUtils.openInBrowser(context, "https://play.google.com/store/apps/details?id=de.danoeh.antennapod"); - saveRated(); - } - - private static boolean rated() { - return mPreferences.getBoolean(KEY_RATED, false); - } - - @VisibleForTesting - public static void saveRated() { - mPreferences - .edit() - .putBoolean(KEY_RATED, true) - .apply(); - } - - private static void resetStartDate() { - mPreferences - .edit() - .putLong(KEY_FIRST_START_DATE, System.currentTimeMillis()) - .apply(); - } - - private static boolean shouldShow() { - if (rated()) { - return false; - } - - long now = System.currentTimeMillis(); - long firstDate = mPreferences.getLong(KEY_FIRST_START_DATE, now); - long diff = now - firstDate; - long diffDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); - return diffDays >= AFTER_DAYS; - } - - @Nullable - private static AlertDialog createDialog() { - Context context = mContext.get(); - if (context == null) { - return null; - } - return new AlertDialog.Builder(context) - .setTitle(R.string.rating_title) - .setMessage(R.string.rating_message) - .setPositiveButton(R.string.rating_now_label, (dialog, which) -> rateNow()) - .setNegativeButton(R.string.rating_never_label, (dialog, which) -> saveRated()) - .setNeutralButton(R.string.rating_later_label, (dialog, which) -> resetStartDate()) - .setOnCancelListener(dialog1 -> resetStartDate()) - .create(); - } -} diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index a9c54e879..274c3b7bd 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.dialog; +import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; @@ -137,6 +138,7 @@ public class SleepTimerDialog extends DialogFragment { if (controller != null) { controller.setSleepTimer(time); } + closeKeyboard(content); } catch (NumberFormatException e) { e.printStackTrace(); Snackbar.make(content, R.string.time_dialog_invalid_input, Snackbar.LENGTH_LONG).show(); @@ -153,4 +155,9 @@ public class SleepTimerDialog extends DialogFragment { timeDisplay.setVisibility(controller.sleepTimerActive() ? View.VISIBLE : View.GONE); time.setText(Converter.getDurationStringLong((int) controller.getSleepTimerTimeLeft())); } + + private void closeKeyboard(View content) { + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(content.getWindowToken(), 0); + } } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java new file mode 100644 index 000000000..a8915480c --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java @@ -0,0 +1,82 @@ +package de.danoeh.antennapod.dialog; + +import android.content.Context; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.RadioButton; + +import androidx.appcompat.app.AlertDialog; + +import org.greenrobot.eventbus.EventBus; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent; +import de.danoeh.antennapod.core.feed.SubscriptionsFilter; +import de.danoeh.antennapod.core.feed.SubscriptionsFilterGroup; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.view.RecursiveRadioGroup; + +public class SubscriptionsFilterDialog { + public static void showDialog(Context context) { + SubscriptionsFilter subscriptionsFilter = UserPreferences.getSubscriptionsFilter(); + final Set<String> filterValues = new HashSet<>(Arrays.asList(subscriptionsFilter.getValues())); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(context.getString(R.string.pref_filter_feed_title)); + + LayoutInflater inflater = LayoutInflater.from(context); + LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.filter_dialog, null, false); + builder.setView(layout); + + for (SubscriptionsFilterGroup item : SubscriptionsFilterGroup.values()) { + RecursiveRadioGroup row = (RecursiveRadioGroup) inflater.inflate(R.layout.filter_dialog_row, null); + RadioButton filter1 = row.findViewById(R.id.filter_dialog_radioButton1); + RadioButton filter2 = row.findViewById(R.id.filter_dialog_radioButton2); + filter1.setText(item.values[0].displayName); + filter1.setTag(item.values[0].filterId); + if (item.values.length == 2) { + filter2.setText(item.values[1].displayName); + filter2.setTag(item.values[1].filterId); + } else { + filter2.setVisibility(View.GONE); + } + layout.addView(row); + } + + for (String filterId : filterValues) { + if (!TextUtils.isEmpty(filterId)) { + ((RadioButton) layout.findViewWithTag(filterId)).setChecked(true); + } + } + + builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { + filterValues.clear(); + for (int i = 0; i < layout.getChildCount(); i++) { + if (!(layout.getChildAt(i) instanceof RecursiveRadioGroup)) { + continue; + } + RecursiveRadioGroup group = (RecursiveRadioGroup) layout.getChildAt(i); + if (group.getCheckedButton() != null) { + String tag = (String) group.getCheckedButton().getTag(); + if (tag != null) { // Clear buttons use no tag + filterValues.add((String) group.getCheckedButton().getTag()); + } + } + } + updateFilter(filterValues); + }); + builder.setNegativeButton(R.string.cancel_label, null); + builder.show(); + } + + private static void updateFilter(Set<String> filterValues) { + SubscriptionsFilter subscriptionsFilter = new SubscriptionsFilter(filterValues.toArray(new String[0])); + UserPreferences.setSubscriptionsFilter(subscriptionsFilter); + EventBus.getDefault().post(new UnreadItemsUpdateEvent()); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java index ef8ed335d..1fc7a77b2 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java @@ -45,9 +45,8 @@ public class VariableSpeedDialog extends DialogFragment { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.no_playback_plugin_title); builder.setMessage(R.string.no_playback_plugin_or_sonic_msg); - builder.setPositiveButton(R.string.enable_sonic, (dialog, which) -> { - UserPreferences.enableSonic(); - }); + builder.setPositiveButton(R.string.enable_sonic, (dialog, which) -> + UserPreferences.enableSonic()); builder.setNeutralButton(R.string.close_label, null); builder.show(); } |