Use AlertDialog for episode filters (#3981)
This commit is contained in:
parent
eae200b0dc
commit
ea58748b22
|
@ -1,38 +1,33 @@
|
|||
package de.danoeh.antennapod.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.FeedFilter;
|
||||
|
||||
/**
|
||||
* Displays a dialog with a text box for filtering episodes and two radio buttons for exclusion/inclusion
|
||||
*/
|
||||
public abstract class EpisodeFilterDialog extends Dialog {
|
||||
public abstract class EpisodeFilterDialog extends AlertDialog.Builder {
|
||||
|
||||
private final FeedFilter initialFilter;
|
||||
|
||||
public EpisodeFilterDialog(Context context, FeedFilter filter) {
|
||||
|
||||
super(context);
|
||||
this.initialFilter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.episode_filter_dialog);
|
||||
final EditText etxtEpisodeFilterText = findViewById(R.id.etxtEpisodeFilterText);
|
||||
final RadioButton radioInclude = findViewById(R.id.radio_filter_include);
|
||||
final RadioButton radioExclude = findViewById(R.id.radio_filter_exclude);
|
||||
final Button butConfirm = findViewById(R.id.butConfirm);
|
||||
final Button butCancel = findViewById(R.id.butCancel);
|
||||
|
||||
initialFilter = filter;
|
||||
setTitle(R.string.episode_filters_label);
|
||||
setOnCancelListener(dialog -> onCancelled());
|
||||
View rootView = View.inflate(context, R.layout.episode_filter_dialog, null);
|
||||
setView(rootView);
|
||||
|
||||
final EditText etxtEpisodeFilterText = rootView.findViewById(R.id.etxtEpisodeFilterText);
|
||||
final RadioButton radioInclude = rootView.findViewById(R.id.radio_filter_include);
|
||||
final RadioButton radioExclude = rootView.findViewById(R.id.radio_filter_exclude);
|
||||
|
||||
if (initialFilter.includeOnly()) {
|
||||
radioInclude.setChecked(true);
|
||||
|
@ -46,25 +41,19 @@ public abstract class EpisodeFilterDialog extends Dialog {
|
|||
etxtEpisodeFilterText.setText("");
|
||||
}
|
||||
|
||||
setNegativeButton(R.string.cancel_label, null);
|
||||
setPositiveButton(R.string.confirm_label, (dialog, which) -> {
|
||||
String includeString = "";
|
||||
String excludeString = "";
|
||||
if (radioInclude.isChecked()) {
|
||||
includeString = etxtEpisodeFilterText.getText().toString();
|
||||
} else {
|
||||
excludeString = etxtEpisodeFilterText.getText().toString();
|
||||
}
|
||||
|
||||
butCancel.setOnClickListener(v -> cancel());
|
||||
butConfirm.setOnClickListener(v -> {
|
||||
|
||||
String includeString = "";
|
||||
String excludeString = "";
|
||||
if (radioInclude.isChecked()) {
|
||||
includeString = etxtEpisodeFilterText.getText().toString();
|
||||
} else {
|
||||
excludeString = etxtEpisodeFilterText.getText().toString();
|
||||
}
|
||||
|
||||
onConfirmed(new FeedFilter(includeString, excludeString));
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
protected void onCancelled() {
|
||||
|
||||
onConfirmed(new FeedFilter(includeString, excludeString));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected abstract void onConfirmed(FeedFilter filter);
|
||||
|
|
|
@ -2,94 +2,39 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/radio_filter_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio_filter_include"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/episode_filters_include" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio_filter_exclude"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/episode_filters_exclude" />
|
||||
</RadioGroup>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etxtEpisodeFilterText"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:lines="8"
|
||||
android:minLines="1"
|
||||
android:maxLines="20"
|
||||
android:scrollbars="vertical"
|
||||
android:hint="@string/episode_filters_hint"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:cursorVisible="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/footer"
|
||||
<RadioGroup
|
||||
android:id="@+id/radio_filter_group"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="48dp">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dip"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="?android:attr/dividerVertical" />
|
||||
|
||||
<View
|
||||
android:id="@+id/horizontal_divider"
|
||||
android:layout_width="1dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:background="?android:attr/dividerVertical" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/butCancel"
|
||||
<RadioButton
|
||||
android:id="@+id/radio_filter_include"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toLeftOf="@id/horizontal_divider"
|
||||
android:layout_toStartOf="@id/horizontal_divider"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:text="@string/cancel_label" />
|
||||
android:text="@string/episode_filters_include" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/butConfirm"
|
||||
<RadioButton
|
||||
android:id="@+id/radio_filter_exclude"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toRightOf="@id/horizontal_divider"
|
||||
android:layout_toEndOf="@id/horizontal_divider"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:text="@string/confirm_label" />
|
||||
</RelativeLayout>
|
||||
android:text="@string/episode_filters_exclude" />
|
||||
</RadioGroup>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etxtEpisodeFilterText"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:lines="8"
|
||||
android:minLines="1"
|
||||
android:maxLines="20"
|
||||
android:scrollbars="vertical"
|
||||
android:hint="@string/episode_filters_hint"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:cursorVisible="true" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue