diff options
author | Thomas <tschneider.ac@gmail.com> | 2023-03-19 12:19:26 +0100 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2023-03-19 12:19:26 +0100 |
commit | 327fac5f5aec4999ae67d16d650a20573b779020 (patch) | |
tree | 7a0b71bae43742a6c13af4bf83d7da26dcac3257 | |
parent | 0a9c5162ca7bc1d6cdfab13561b4caf61c10db0d (diff) |
working track selectors
-rw-r--r-- | app/src/main/java/app/fedilab/android/peertube/helper/TrackSelectionDialog.java | 44 | ||||
-rw-r--r-- | app/src/main/res/layouts/peertube/layout/track_selection_dialog.xml | 16 |
2 files changed, 25 insertions, 35 deletions
diff --git a/app/src/main/java/app/fedilab/android/peertube/helper/TrackSelectionDialog.java b/app/src/main/java/app/fedilab/android/peertube/helper/TrackSelectionDialog.java index 897950679..eb7e2e2e2 100644 --- a/app/src/main/java/app/fedilab/android/peertube/helper/TrackSelectionDialog.java +++ b/app/src/main/java/app/fedilab/android/peertube/helper/TrackSelectionDialog.java @@ -8,15 +8,12 @@ import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatDialog; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; -import androidx.viewpager.widget.ViewPager; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Player; @@ -25,7 +22,7 @@ import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.trackselection.TrackSelectionOverride; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.ui.TrackSelectionView; -import com.google.android.material.tabs.TabLayout; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -35,6 +32,7 @@ import java.util.List; import java.util.Map; import app.fedilab.android.R; +import app.fedilab.android.databinding.TrackSelectionDialogBinding; /** * Dialog to select tracks. @@ -48,6 +46,7 @@ public final class TrackSelectionDialog extends DialogFragment { private int titleId; private DialogInterface.OnClickListener onClickListener; private DialogInterface.OnDismissListener onDismissListener; + private TrackSelectionDialogBinding binding; public TrackSelectionDialog() { tabFragments = new SparseArray<>(); @@ -214,11 +213,19 @@ public final class TrackSelectionDialog extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - // We need to own the view to let tab layout work correctly on all API levels. We can't use - // AlertDialog because it owns the view itself, so we use AppCompatDialog instead, themed using - // the AlertDialog theme overlay with force-enabled title. - AppCompatDialog dialog = - new AppCompatDialog(getActivity()); + MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(requireContext()); + binding = TrackSelectionDialogBinding.inflate(getLayoutInflater()); + materialAlertDialogBuilder.setView(binding.getRoot()); + Dialog dialog = materialAlertDialogBuilder.create(); + binding.trackSelectionDialogViewPager.setAdapter(new FragmentAdapter(getChildFragmentManager())); + binding.trackSelectionDialogTabLayout.setupWithViewPager(binding.trackSelectionDialogViewPager); + binding.trackSelectionDialogTabLayout.setVisibility(tabFragments.size() > 1 ? View.VISIBLE : View.GONE); + binding.trackSelectionDialogCancelButton.setOnClickListener(view -> dismiss()); + binding.trackSelectionDialogOkButton.setOnClickListener( + view -> { + onClickListener.onClick(getDialog(), DialogInterface.BUTTON_POSITIVE); + dismiss(); + }); dialog.setTitle(titleId); return dialog; } @@ -229,25 +236,6 @@ public final class TrackSelectionDialog extends DialogFragment { onDismissListener.onDismiss(dialog); } - @Override - public View onCreateView( - LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View dialogView = inflater.inflate(R.layout.track_selection_dialog, container, false); - TabLayout tabLayout = dialogView.findViewById(R.id.track_selection_dialog_tab_layout); - ViewPager viewPager = dialogView.findViewById(R.id.track_selection_dialog_view_pager); - Button cancelButton = dialogView.findViewById(R.id.track_selection_dialog_cancel_button); - Button okButton = dialogView.findViewById(R.id.track_selection_dialog_ok_button); - viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager())); - tabLayout.setupWithViewPager(viewPager); - tabLayout.setVisibility(tabFragments.size() > 1 ? View.VISIBLE : View.GONE); - cancelButton.setOnClickListener(view -> dismiss()); - okButton.setOnClickListener( - view -> { - onClickListener.onClick(getDialog(), DialogInterface.BUTTON_POSITIVE); - dismiss(); - }); - return dialogView; - } /** * Called when tracks are selected. diff --git a/app/src/main/res/layouts/peertube/layout/track_selection_dialog.xml b/app/src/main/res/layouts/peertube/layout/track_selection_dialog.xml index ba8e5acf1..066d64773 100644 --- a/app/src/main/res/layouts/peertube/layout/track_selection_dialog.xml +++ b/app/src/main/res/layouts/peertube/layout/track_selection_dialog.xml @@ -12,7 +12,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="wrap_content" android:orientation="vertical"> <androidx.viewpager.widget.ViewPager @@ -30,26 +30,28 @@ </androidx.viewpager.widget.ViewPager> - <LinearLayout + <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="end" + android:layout_margin="10dp" android:orientation="horizontal"> - <Button + <com.google.android.material.button.MaterialButton android:id="@+id/track_selection_dialog_cancel_button" - style="?android:attr/borderlessButtonStyle" + style="@style/Widget.Material3.Button.OutlinedButton" + android:layout_marginEnd="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@android:string/cancel" /> - <Button + <com.google.android.material.button.MaterialButton android:id="@+id/track_selection_dialog_ok_button" - style="?android:attr/borderlessButtonStyle" + style="@style/Widget.Material3.Button.OutlinedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@android:string/ok" /> - </LinearLayout> + </androidx.appcompat.widget.LinearLayoutCompat> </LinearLayout>
\ No newline at end of file |