adding shared preferences to ShareEpisodeDialog

This commit is contained in:
Gerardo Vázquez 2020-06-26 16:38:08 -05:00
parent 8d6fab6ead
commit b36078b8f1
5 changed files with 34 additions and 3 deletions

View File

@ -391,7 +391,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
break;
case R.id.share_item:
if (feedItem != null) {
new ShareDialog(this, feedItem).show(((AppCompatActivity) this).getSupportFragmentManager(), "ShareEpisodeDialog");
new ShareDialog(this, feedItem)
.show(((AppCompatActivity) this).getSupportFragmentManager(), "ShareEpisodeDialog");
}
break;
default:

View File

@ -3,7 +3,9 @@ package de.danoeh.antennapod.dialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
@ -15,6 +17,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.ShareUtils;
public class ShareDialog extends DialogFragment {
@ -27,10 +30,12 @@ public class ShareDialog extends DialogFragment {
private RadioButton radioEpisodeWebsite;
private RadioButton radioMediaFile;
private Switch switchStartAt;
private SharedPreferences prefs;
public ShareDialog(Context ctx, FeedItem item) {
this.ctx = ctx;
this.item = item;
prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
}
@NonNull
@ -55,15 +60,23 @@ public class ShareDialog extends DialogFragment {
if (radioEpisodeWebsite.isChecked()) {
if (switchStartAt.isChecked()) {
ShareUtils.shareFeedItemLink(ctx, item, true);
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_START_AT, true).apply();
} else {
ShareUtils.shareFeedItemLink(ctx, item);
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_START_AT, false).apply();
}
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_WEBSITE, true).apply();
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_MEDIA, false).apply();
} else {
if (switchStartAt.isChecked()) {
ShareUtils.shareFeedItemDownloadLink(ctx, item, true);
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_START_AT, true).apply();
} else {
ShareUtils.shareFeedItemDownloadLink(ctx, item);
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_START_AT, false).apply();
}
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_MEDIA, true).apply();
prefs.edit().putBoolean(UserPreferences.PREF_SHARE_EPISODE_WEBSITE, false).apply();
}
}
})
@ -87,5 +100,16 @@ public class ShareDialog extends DialogFragment {
radioMediaFile.setVisibility(View.GONE);
radioEpisodeWebsite.setChecked(true);
}
if (radioEpisodeWebsite.getVisibility() == View.VISIBLE && radioMediaFile.getVisibility() == View.VISIBLE) {
boolean radioEpisodeWebsiteIsChecked = prefs.getBoolean(UserPreferences.PREF_SHARE_EPISODE_WEBSITE, false);
radioEpisodeWebsite.setChecked(radioEpisodeWebsiteIsChecked);
boolean radioMediaIsChecked = prefs.getBoolean(UserPreferences.PREF_SHARE_EPISODE_MEDIA, false);
radioMediaFile.setChecked(radioMediaIsChecked);
}
boolean switchIsChecked = prefs.getBoolean(UserPreferences.PREF_SHARE_EPISODE_START_AT, false);
switchStartAt.setChecked(switchIsChecked);
}
}

View File

@ -236,7 +236,8 @@ public class FeedItemMenuHandler {
IntentUtils.openInBrowser(context, FeedItemUtil.getLinkWithFallback(selectedItem));
break;
case R.id.share_item:
new ShareDialog(context, selectedItem).show(((AppCompatActivity) context).getSupportFragmentManager(), "ShareEpisodeDialog");
new ShareDialog(context, selectedItem)
.show(((AppCompatActivity) context).getSupportFragmentManager(), "ShareEpisodeDialog");
break;
default:
Log.d(TAG, "Unknown menuItemId: " + menuItemId);

View File

@ -112,6 +112,11 @@ public class UserPreferences {
public static final String PREF_IMAGE_CACHE_SIZE = "prefImageCacheSize";
public static final String PREF_DELETE_REMOVES_FROM_QUEUE = "prefDeleteRemovesFromQueue";
// Dialogs
public static final String PREF_SHARE_EPISODE_WEBSITE = "prefShareEpisodeWebsite";
public static final String PREF_SHARE_EPISODE_MEDIA = "prefShareEpisodeMedia";
public static final String PREF_SHARE_EPISODE_START_AT = "prefShareEpisodeStartAt";
// Mediaplayer
public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer";
public static final String PREF_MEDIA_PLAYER_EXOPLAYER = "exoplayer";

View File

@ -765,7 +765,7 @@
<string name="rating_later_label">Remind me later</string>
<string name="rating_now_label">Sure, let\'s do this!</string>
<!-- Share epidose dialog -->
<!-- Share episode dialog -->
<string name="share_episode_label">Share…</string>
<string name="share_dialog_include_label">Include:</string>
<string name="share_start_at_timer_dialog_label">Start at (timer)</string>