Convert share dialog to bottom sheet

This commit is contained in:
ByteHamster 2022-05-07 11:10:00 +02:00
parent 77ced35dff
commit 02197e31b3
3 changed files with 39 additions and 39 deletions

View File

@ -3,7 +3,14 @@ package de.test.antennapod.dialogs;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.test.antennapod.EspressoTestUtils;
import de.test.antennapod.ui.UITestUtils;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Before;
@ -11,19 +18,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.test.antennapod.EspressoTestUtils;
import de.test.antennapod.ui.UITestUtils;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static androidx.test.espresso.matcher.ViewMatchers.hasMinimumChildCount;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
@ -45,7 +41,6 @@ public class ShareDialogTest {
@Rule
public IntentsTestRule<MainActivity> activityRule = new IntentsTestRule<>(MainActivity.class, false, false);
private UITestUtils uiTestUtils;
protected Context context;
@Before
@ -54,7 +49,7 @@ public class ShareDialogTest {
EspressoTestUtils.clearPreferences();
EspressoTestUtils.clearDatabase();
EspressoTestUtils.setLastNavFragment(EpisodesFragment.TAG);
uiTestUtils = new UITestUtils(context);
UITestUtils uiTestUtils = new UITestUtils(context);
uiTestUtils.setup();
uiTestUtils.addLocalFeedData(true);
@ -73,15 +68,9 @@ public class ShareDialogTest {
}
@Test
public void testShareDialogDisplayed() throws InterruptedException {
public void testShareDialogDisplayed() {
onView(withText(R.string.share_label)).perform(click());
onView(allOf(isDisplayed(), withText(R.string.share_label)));
}
@Test
public void testShareDialogCancelButton() {
onView(withText(R.string.share_label)).perform(scrollTo()).perform(click());
onView(withText(R.string.cancel_label)).check(matches(isDisplayed())).perform(scrollTo()).perform(click());
}
}

View File

@ -1,21 +1,19 @@
package de.danoeh.antennapod.dialog;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import de.danoeh.antennapod.R;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.databinding.ShareEpisodeDialogBinding;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.core.util.ShareUtils;
public class ShareDialog extends DialogFragment {
public class ShareDialog extends BottomSheetDialogFragment {
private static final String ARGUMENT_FEED_ITEM = "feedItem";
private static final String PREF_NAME = "ShareDialog";
private static final String PREF_SHARE_EPISODE_START_AT = "prefShareEpisodeStartAt";
@ -39,25 +37,23 @@ public class ShareDialog extends DialogFragment {
return dialog;
}
@NonNull
@Nullable
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
if (getArguments() != null) {
ctx = getActivity();
item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}
viewBinding = ShareEpisodeDialogBinding.inflate(getLayoutInflater());
viewBinding = ShareEpisodeDialogBinding.inflate(inflater);
viewBinding.shareDialogRadioGroup.setOnCheckedChangeListener((group, checkedId) ->
viewBinding.sharePositionCheckbox.setEnabled(checkedId == viewBinding.shareSocialRadio.getId()));
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(R.string.share_label);
builder.setView(viewBinding.getRoot());
setupOptions();
builder.setPositiveButton(R.string.share_label, (dialog, id) -> {
viewBinding.shareButton.setOnClickListener((v) -> {
boolean includePlaybackPosition = viewBinding.sharePositionCheckbox.isChecked();
int position;
if (viewBinding.shareSocialRadio.isChecked()) {
@ -76,9 +72,9 @@ public class ShareDialog extends DialogFragment {
.putBoolean(PREF_SHARE_EPISODE_START_AT, includePlaybackPosition)
.putInt(PREF_SHARE_EPISODE_TYPE, position)
.apply();
}).setNegativeButton(R.string.cancel_label, (dialog, id) -> dialog.dismiss());
return builder.create();
dismiss();
});
return viewBinding.getRoot();
}
private void setupOptions() {

View File

@ -7,6 +7,13 @@
android:gravity="center"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/share_label"
android:layout_marginBottom="8dp"
style="@style/AntennaPod.TextView.Heading" />
<RadioGroup
android:id="@+id/share_dialog_radio_group"
android:layout_width="match_parent"
@ -38,7 +45,7 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="8dp"
android:background="?android:attr/listDivider" />
android:background="?attr/background_elevated" />
<CheckBox
android:id="@+id/share_position_checkbox"
@ -46,4 +53,12 @@
android:layout_height="wrap_content"
android:text="@string/share_playback_position_dialog_label" />
<Button
android:id="@+id/shareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/share_label"
style="@style/Widget.MaterialComponents.Button.TextButton" />
</LinearLayout>