updates for share dialog and implementing new instance pattern
This commit is contained in:
parent
0cb17304e7
commit
df19ca2741
|
@ -4,10 +4,8 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -43,7 +41,7 @@ import static de.test.antennapod.NthMatcher.first;
|
|||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
|
||||
/**
|
||||
* User interface tests for queue fragment.
|
||||
* User interface tests for share dialog.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ShareDialogTest {
|
||||
|
|
|
@ -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(getSupportFragmentManager(), "ShareEpisodeDialog");
|
||||
ShareDialog shareDialog = ShareDialog.newInstance(feedItem);
|
||||
shareDialog.show(getSupportFragmentManager(), "ShareEpisodeDialog");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -5,12 +5,10 @@ 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.CheckBox;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -18,34 +16,46 @@ 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 {
|
||||
|
||||
private static final String ARGUMENT_FEED_ITEM = "feedItem";
|
||||
|
||||
private static final String TAG = "ShareDialog";
|
||||
private final Context ctx;
|
||||
private Context ctx;
|
||||
private FeedItem item;
|
||||
|
||||
private static final String PREF_SHARE_EPISODE_WEBSITE = "prefShareEpisodeWebsite";
|
||||
private static final String PREF_SHARE_EPISODE_MEDIA = "prefShareEpisodeMedia";
|
||||
private static final String PREF_SHARE_DIALOG_OPTION = "prefShareDialogOption";
|
||||
private static final String PREF_SHARE_EPISODE_START_AT = "prefShareEpisodeStartAt";
|
||||
|
||||
private RadioGroup radioGroup;
|
||||
private RadioButton radioEpisodeWebsite;
|
||||
private RadioButton radioMediaFile;
|
||||
private Switch switchStartAt;
|
||||
private CheckBox checkBoxStartAt;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
public ShareDialog(Context ctx, FeedItem item) {
|
||||
this.ctx = ctx;
|
||||
this.item = item;
|
||||
prefs = ctx.getSharedPreferences("SHARE_DIALOG_PREFS", Context.MODE_PRIVATE);
|
||||
public ShareDialog() {
|
||||
// Empty constructor required for DialogFragment
|
||||
}
|
||||
|
||||
public static ShareDialog newInstance(FeedItem item) {
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putSerializable(ARGUMENT_FEED_ITEM, item);
|
||||
ShareDialog dialog = new ShareDialog();
|
||||
dialog.setArguments(arguments);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
if (getArguments() != null) {
|
||||
ctx = getActivity();
|
||||
item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
|
||||
prefs = getActivity().getSharedPreferences("ShareDialog", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
View content = View.inflate(ctx, R.layout.share_episode_dialog, null);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||
builder.setTitle(R.string.share_label);
|
||||
|
@ -54,34 +64,30 @@ public class ShareDialog extends DialogFragment {
|
|||
radioGroup = content.findViewById(R.id.share_dialog_radio_group);
|
||||
radioEpisodeWebsite = content.findViewById(R.id.share_episode_website_radio);
|
||||
radioMediaFile = content.findViewById(R.id.share_media_file_radio);
|
||||
switchStartAt = content.findViewById(R.id.share_start_at_timer_dialog);
|
||||
checkBoxStartAt = content.findViewById(R.id.share_start_at_timer_dialog);
|
||||
|
||||
setupOptions();
|
||||
|
||||
builder
|
||||
.setPositiveButton(R.string.share_label, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (radioEpisodeWebsite.isChecked()) {
|
||||
ShareUtils.shareFeedItemLink(ctx, item, switchStartAt.isChecked());
|
||||
prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, switchStartAt.isChecked()).apply();
|
||||
builder.setPositiveButton(R.string.share_label, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
boolean includePlaybackPosition = checkBoxStartAt.isChecked();
|
||||
if (radioEpisodeWebsite.isChecked()) {
|
||||
ShareUtils.shareFeedItemLink(ctx, item, includePlaybackPosition);
|
||||
prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, "website").apply();
|
||||
} else {
|
||||
ShareUtils.shareFeedItemDownloadLink(ctx, item, includePlaybackPosition);
|
||||
prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, "media").apply();
|
||||
}
|
||||
prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, includePlaybackPosition).apply();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel_label, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
prefs.edit().putBoolean(PREF_SHARE_EPISODE_WEBSITE, true).apply();
|
||||
prefs.edit().putBoolean(PREF_SHARE_EPISODE_MEDIA, false).apply();
|
||||
} else {
|
||||
ShareUtils.shareFeedItemLink(ctx, item, switchStartAt.isChecked());
|
||||
prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, switchStartAt.isChecked()).apply();
|
||||
|
||||
prefs.edit().putBoolean(PREF_SHARE_EPISODE_WEBSITE, false).apply();
|
||||
prefs.edit().putBoolean(PREF_SHARE_EPISODE_MEDIA, true).apply();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel_label, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
@ -99,19 +105,17 @@ public class ShareDialog extends DialogFragment {
|
|||
}
|
||||
|
||||
if (radioEpisodeWebsite.getVisibility() == View.VISIBLE && radioMediaFile.getVisibility() == View.VISIBLE) {
|
||||
boolean radioEpisodeWebsiteIsChecked = prefs.getBoolean(PREF_SHARE_EPISODE_WEBSITE, false);
|
||||
radioEpisodeWebsite.setChecked(radioEpisodeWebsiteIsChecked);
|
||||
|
||||
boolean radioMediaIsChecked = prefs.getBoolean(PREF_SHARE_EPISODE_MEDIA, false);
|
||||
radioMediaFile.setChecked(radioMediaIsChecked);
|
||||
|
||||
if (!radioEpisodeWebsiteIsChecked && !radioMediaIsChecked) {
|
||||
radioGroup.clearCheck();
|
||||
String option = prefs.getString(PREF_SHARE_DIALOG_OPTION, "website");
|
||||
if (option.equals("website")) {
|
||||
radioEpisodeWebsite.setChecked(true);
|
||||
radioMediaFile.setChecked(false);
|
||||
} else {
|
||||
radioEpisodeWebsite.setChecked(false);
|
||||
radioMediaFile.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
boolean switchIsChecked = prefs.getBoolean(PREF_SHARE_EPISODE_START_AT, false);
|
||||
switchStartAt.setChecked(switchIsChecked);
|
||||
checkBoxStartAt.setChecked(switchIsChecked);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.view.MenuItem;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
|
@ -236,8 +235,8 @@ public class FeedItemMenuHandler {
|
|||
IntentUtils.openInBrowser(context, FeedItemUtil.getLinkWithFallback(selectedItem));
|
||||
break;
|
||||
case R.id.share_item:
|
||||
new ShareDialog(context, selectedItem)
|
||||
.show((fragment.getActivity().getSupportFragmentManager()), "ShareEpisodeDialog");
|
||||
ShareDialog shareDialog = ShareDialog.newInstance(selectedItem);
|
||||
shareDialog.show((fragment.getActivity().getSupportFragmentManager()), "ShareEpisodeDialog");
|
||||
break;
|
||||
default:
|
||||
Log.d(TAG, "Unknown menuItemId: " + menuItemId);
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<RadioButton android:id="@+id/share_episode_website_radio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_dialog_episode_website_label"
|
||||
android:checked="true"
|
||||
/>
|
||||
<RadioButton android:id="@+id/share_media_file_radio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_dialog_media_file_label"
|
||||
/>
|
||||
|
@ -31,7 +31,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:text="@string/share_dialog_include_label"/>
|
||||
|
||||
<Switch
|
||||
<CheckBox
|
||||
android:id="@+id/share_start_at_timer_dialog"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
android:id="@+id/share_item"
|
||||
android:menuCategory="container"
|
||||
custom:showAsAction="never"
|
||||
android:title="@string/share_label">
|
||||
android:title="@string/share_label_with_ellipses">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/share_link_item"
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.text.TextUtils;
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -24,7 +25,7 @@ import de.danoeh.antennapod.core.util.ShownotesProvider;
|
|||
*
|
||||
* @author daniel
|
||||
*/
|
||||
public class FeedItem extends FeedComponent implements ShownotesProvider, ImageResource {
|
||||
public class FeedItem extends FeedComponent implements ShownotesProvider, ImageResource, Serializable {
|
||||
|
||||
/** tag that indicates this item is in the queue */
|
||||
public static final String TAG_QUEUE = "Queue";
|
||||
|
|
|
@ -137,6 +137,7 @@
|
|||
<string name="rename_feed_label">Rename podcast</string>
|
||||
<string name="remove_feed_label">Remove podcast</string>
|
||||
<string name="share_label">Share</string>
|
||||
<string name="share_label_with_ellipses">Share…</string>
|
||||
<string name="share_link_label">Share Episode URL</string>
|
||||
<string name="share_link_with_position_label">Share Episode URL with Position</string>
|
||||
<string name="share_file_label">Share File</string>
|
||||
|
|
Loading…
Reference in New Issue