diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-05-07 21:53:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-07 21:53:33 +0200 |
commit | 4f82be769875cd4cfb245d2c9ff7d56d44b59c80 (patch) | |
tree | c58e8fa876ff9e3cc32417d59c06c66a67d8259f /app | |
parent | fb3f8949a3896d0ecdc2ff9a47c837f14081de76 (diff) | |
parent | 02197e31b3822d2420a654c03058a62d3b5820db (diff) | |
download | AntennaPod-4f82be769875cd4cfb245d2c9ff7d56d44b59c80.zip |
Merge pull request #5873 from ByteHamster/share-sheet
Convert share dialog to bottom sheet
Diffstat (limited to 'app')
3 files changed, 38 insertions, 38 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/dialogs/ShareDialogTest.java b/app/src/androidTest/java/de/test/antennapod/dialogs/ShareDialogTest.java index 29cea18dc..3c32407a5 100644 --- a/app/src/androidTest/java/de/test/antennapod/dialogs/ShareDialogTest.java +++ b/app/src/androidTest/java/de/test/antennapod/dialogs/ShareDialogTest.java @@ -3,27 +3,23 @@ package de.test.antennapod.dialogs; import android.content.Context; import android.content.Intent; import android.view.View; - -import org.hamcrest.Matcher; -import org.hamcrest.Matchers; -import org.junit.Before; -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 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; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; 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()); - } - } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java index dbd4cdb59..79a2d0005 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java @@ -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() { diff --git a/app/src/main/res/layout/share_episode_dialog.xml b/app/src/main/res/layout/share_episode_dialog.xml index f03899671..9d0a2f38d 100644 --- a/app/src/main/res/layout/share_episode_dialog.xml +++ b/app/src/main/res/layout/share_episode_dialog.xml @@ -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> |