From 50f3b08c595a56618aca5532560f2c5173684287 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Tue, 27 Jul 2021 13:31:58 -0400 Subject: [PATCH] Consolidate edittext alert dialogs into one layout --- .../local/bookmark/BookmarkFragment.java | 17 ++++++++++------ .../local/dialog/PlaylistCreationDialog.java | 14 +++++++------ .../local/playlist/LocalPlaylistFragment.java | 17 +++++++++------- .../PeertubeInstanceListFragment.java | 20 ++++++++++--------- app/src/main/res/layout/dialog_bookmark.xml | 17 ---------------- ...playlist_name.xml => dialog_edit_text.xml} | 11 ++++------ 6 files changed, 44 insertions(+), 52 deletions(-) delete mode 100644 app/src/main/res/layout/dialog_bookmark.xml rename app/src/main/res/layout/{dialog_playlist_name.xml => dialog_edit_text.xml} (68%) diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index a58bb4cd5..794e5a33a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -2,11 +2,11 @@ package org.schabi.newpipe.local.bookmark; import android.os.Bundle; import android.os.Parcelable; +import android.text.InputType; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -22,6 +22,7 @@ import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.playlist.PlaylistLocalItem; import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; +import org.schabi.newpipe.databinding.DialogEditTextBinding; import org.schabi.newpipe.error.ErrorInfo; import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.local.BaseLocalListFragment; @@ -255,14 +256,18 @@ public final class BookmarkFragment extends BaseLocalListFragment - changeLocalPlaylistName(selectedItem.uid, editText.getText().toString())) + changeLocalPlaylistName( + selectedItem.uid, + dialogBinding.dialogEditText.getText().toString())) .setNegativeButton(R.string.cancel, null) .setNeutralButton(R.string.delete, (dialog, which) -> { showDeleteDialog(selectedItem.name, diff --git a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistCreationDialog.java b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistCreationDialog.java index 40ea27e8c..f48c72d04 100644 --- a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistCreationDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistCreationDialog.java @@ -2,8 +2,7 @@ package org.schabi.newpipe.local.dialog; import android.app.Dialog; import android.os.Bundle; -import android.view.View; -import android.widget.EditText; +import android.text.InputType; import android.widget.Toast; import androidx.annotation.NonNull; @@ -13,6 +12,7 @@ import androidx.appcompat.app.AlertDialog; import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; import org.schabi.newpipe.database.stream.model.StreamEntity; +import org.schabi.newpipe.databinding.DialogEditTextBinding; import org.schabi.newpipe.local.playlist.LocalPlaylistManager; import java.util.List; @@ -43,16 +43,18 @@ public final class PlaylistCreationDialog extends PlaylistDialog { return super.onCreateDialog(savedInstanceState); } - final View dialogView = View.inflate(getContext(), R.layout.dialog_playlist_name, null); - final EditText nameInput = dialogView.findViewById(R.id.playlist_name); + final DialogEditTextBinding dialogBinding + = DialogEditTextBinding.inflate(getLayoutInflater()); + dialogBinding.dialogEditText.setHint(R.string.name); + dialogBinding.dialogEditText.setInputType(InputType.TYPE_CLASS_TEXT); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(requireContext()) .setTitle(R.string.create_playlist) - .setView(dialogView) + .setView(dialogBinding.getRoot()) .setCancelable(true) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.create, (dialogInterface, i) -> { - final String name = nameInput.getText().toString(); + final String name = dialogBinding.dialogEditText.getText().toString(); final LocalPlaylistManager playlistManager = new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext())); final Toast successToast = Toast.makeText(getActivity(), diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 947b21767..788a4d062 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.os.Parcelable; +import android.text.InputType; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -13,7 +14,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; import android.widget.Toast; import androidx.annotation.NonNull; @@ -32,6 +32,7 @@ import org.schabi.newpipe.database.history.model.StreamHistoryEntry; import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; import org.schabi.newpipe.database.stream.model.StreamEntity; import org.schabi.newpipe.database.stream.model.StreamStateEntity; +import org.schabi.newpipe.databinding.DialogEditTextBinding; import org.schabi.newpipe.databinding.LocalPlaylistHeaderBinding; import org.schabi.newpipe.databinding.PlaylistControlBinding; import org.schabi.newpipe.error.ErrorInfo; @@ -526,18 +527,20 @@ public class LocalPlaylistFragment extends BaseLocalListFragment - changePlaylistName(nameEdit.getText().toString())); + changePlaylistName(dialogBinding.dialogEditText.getText().toString())); dialogBuilder.show(); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java b/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java index c7cfb1f5f..207d1ffc6 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java @@ -12,7 +12,6 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RadioButton; @@ -35,6 +34,7 @@ import com.grack.nanojson.JsonStringWriter; import com.grack.nanojson.JsonWriter; import org.schabi.newpipe.R; +import org.schabi.newpipe.databinding.DialogEditTextBinding; import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.PeertubeHelper; @@ -207,20 +207,22 @@ public class PeertubeInstanceListFragment extends Fragment { } private void showAddItemDialog(final Context c) { - final EditText urlET = new EditText(c); - urlET.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); - urlET.setHint(R.string.peertube_instance_add_help); - final AlertDialog dialog = new AlertDialog.Builder(c) + final DialogEditTextBinding dialogBinding + = DialogEditTextBinding.inflate(getLayoutInflater()); + dialogBinding.dialogEditText.setInputType( + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); + dialogBinding.dialogEditText.setHint(R.string.peertube_instance_add_help); + + new AlertDialog.Builder(c) .setTitle(R.string.peertube_instance_add_title) .setIcon(R.drawable.place_holder_peertube) + .setView(dialogBinding.getRoot()) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.finish, (dialog1, which) -> { - final String url = urlET.getText().toString(); + final String url = dialogBinding.dialogEditText.getText().toString(); addInstance(url); }) - .create(); - dialog.setView(urlET, 50, 0, 50, 0); - dialog.show(); + .show(); } private void addInstance(final String url) { diff --git a/app/src/main/res/layout/dialog_bookmark.xml b/app/src/main/res/layout/dialog_bookmark.xml deleted file mode 100644 index 010f66049..000000000 --- a/app/src/main/res/layout/dialog_bookmark.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/dialog_playlist_name.xml b/app/src/main/res/layout/dialog_edit_text.xml similarity index 68% rename from app/src/main/res/layout/dialog_playlist_name.xml rename to app/src/main/res/layout/dialog_edit_text.xml index 0e0747381..ff0366e23 100644 --- a/app/src/main/res/layout/dialog_playlist_name.xml +++ b/app/src/main/res/layout/dialog_edit_text.xml @@ -8,14 +8,11 @@ android:paddingRight="@dimen/video_item_search_padding"> + android:maxLines="1" />