mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-09 23:47:56 +01:00
Work around Android's AlertDialog pushing out buttons when content gets large (#6282)
This commit is contained in:
parent
98107419e0
commit
6e7d1f1994
@ -7,14 +7,15 @@ import android.text.format.DateFormat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.storage.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
|
||||
import de.danoeh.antennapod.databinding.FeedRefreshDialogBinding;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import de.danoeh.antennapod.databinding.ScrollableDialogBinding;
|
||||
import de.danoeh.antennapod.storage.preferences.UserPreferences;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
public class FeedRefreshIntervalDialog {
|
||||
private static final int[] INTERVAL_VALUES_HOURS = {1, 2, 4, 8, 12, 24, 72};
|
||||
@ -29,8 +30,10 @@ public class FeedRefreshIntervalDialog {
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
|
||||
builder.setTitle(R.string.feed_refresh_title);
|
||||
builder.setMessage(R.string.feed_refresh_sum);
|
||||
ScrollableDialogBinding scrollableDialogBinding = ScrollableDialogBinding.inflate(LayoutInflater.from(context));
|
||||
builder.setView(scrollableDialogBinding.getRoot());
|
||||
viewBinding = FeedRefreshDialogBinding.inflate(LayoutInflater.from(context));
|
||||
builder.setView(viewBinding.getRoot());
|
||||
scrollableDialogBinding.content.addView(viewBinding.getRoot());
|
||||
|
||||
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(context,
|
||||
android.R.layout.simple_spinner_item, buildSpinnerEntries());
|
||||
@ -68,7 +71,11 @@ public class FeedRefreshIntervalDialog {
|
||||
|
||||
viewBinding.radioGroup.setOnCheckedChangeListener((radioGroup, i) -> updateVisibility());
|
||||
|
||||
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
|
||||
AlertDialog dialog = builder.show();
|
||||
|
||||
scrollableDialogBinding.positiveButton.setText(R.string.confirm_label);
|
||||
scrollableDialogBinding.positiveButton.setOnClickListener(v -> {
|
||||
dialog.dismiss();
|
||||
if (viewBinding.intervalRadioButton.isChecked()) {
|
||||
UserPreferences.setUpdateInterval(INTERVAL_VALUES_HOURS[viewBinding.spinner.getSelectedItemPosition()]);
|
||||
AutoUpdateManager.restartUpdateAlarm(context);
|
||||
@ -89,8 +96,8 @@ public class FeedRefreshIntervalDialog {
|
||||
}
|
||||
});
|
||||
|
||||
builder.setNegativeButton(R.string.cancel_label, null);
|
||||
builder.show();
|
||||
scrollableDialogBinding.negativeButton.setText(R.string.cancel_label);
|
||||
scrollableDialogBinding.negativeButton.setOnClickListener((v) -> dialog.dismiss());
|
||||
}
|
||||
|
||||
private String[] buildSpinnerEntries() {
|
||||
|
37
app/src/main/res/layout/scrollable_dialog.xml
Normal file
37
app/src/main/res/layout/scrollable_dialog.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="32dp"
|
||||
android:paddingVertical="16dp"
|
||||
style="?android:attr/buttonBarStyle">
|
||||
|
||||
<Button
|
||||
android:id="@+id/negativeButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="?android:attr/buttonBarButtonStyle" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/positiveButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="?android:attr/buttonBarButtonStyle" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user