Commit 960f6398 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais

Avoid focus issue on BottomeSheet

parent cfd14624
......@@ -32,6 +32,9 @@
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:choiceMode="singleChoice"
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="afterDescendants"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......
......@@ -71,6 +71,7 @@
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:text="1"
android:textSize="18sp"
......
......@@ -47,6 +47,9 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
private lateinit var options : List<CtxOption>
lateinit var receiver : CtxActionReceiver
private var itemPosition = -1
private lateinit var list: RecyclerView
override fun initialFocusedView(): View = list
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -74,7 +77,7 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<TextView>(R.id.ctx_title).text = arguments?.getString(CTX_TITLE_KEY) ?: ""
val list = view.findViewById<RecyclerView>(R.id.ctx_list)
list = view.findViewById<RecyclerView>(R.id.ctx_list)
list.layoutManager = LinearLayoutManager(requireContext())
list.adapter = ContextAdapter()
val flags = arguments?.getInt(CTX_FLAGS_KEY) ?: 0
......
......@@ -28,6 +28,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.BottomSheetBehavior;
......@@ -112,6 +113,12 @@ public abstract class PickTimeFragment extends VLCBottomSheetDialogFragment impl
return view;
}
@NotNull
@Override
public View initialFocusedView() {
return getView().findViewById(R.id.tim_pic_1);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
PlaybackService.Companion.getService().observe(this, this);
......
......@@ -29,6 +29,7 @@ import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.videolan.vlc.PlaybackService;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.BottomSheetBehavior;
......@@ -53,6 +54,12 @@ public class PlaybackSpeedDialog extends VLCBottomSheetDialogFragment implements
return new PlaybackSpeedDialog();
}
@NotNull
@Override
public View initialFocusedView() {
return mSeekSpeed;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
......
......@@ -62,6 +62,8 @@ class SavePlaylistDialog : VLCBottomSheetDialogFragment(), View.OnClickListener,
private lateinit var mMedialibrary: Medialibrary
private var mPlaylistId: Long = 0
override fun initialFocusedView(): View = mListView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mMedialibrary = VLCApplication.getMLInstance()
......
......@@ -54,6 +54,8 @@ class SelectChapterDialog : VLCBottomSheetDialogFragment(), Observer<PlaybackSer
private var service: PlaybackService? = null
override fun initialFocusedView(): View = chapterList
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.dialog_select_chapter, container)
......@@ -63,6 +65,7 @@ class SelectChapterDialog : VLCBottomSheetDialogFragment(), Observer<PlaybackSer
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
PlaybackService.service.observe(this, this)
}
......
......@@ -25,12 +25,24 @@ abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
val bsb = BottomSheetBehavior.from(it)
if (bsb.state == BottomSheetBehavior.STATE_COLLAPSED) bsb.state = getDefaultState()
}
dialog?.findViewById<View>(R.id.touch_outside)?.isFocusable = false
dialog?.findViewById<View>(R.id.touch_outside)?.isFocusableInTouchMode = false
}
}
override fun onResume() {
super.onResume()
initialFocusedView().isFocusable = true
initialFocusedView().isFocusableInTouchMode = true
initialFocusedView().requestFocus()
}
override fun onConfigurationChanged(newConfig: Configuration?) {
if (!needToManageOrientation()) {
super.onConfigurationChanged(newConfig)
......@@ -57,6 +69,13 @@ abstract class VLCBottomSheetDialogFragment : BottomSheetDialogFragment() {
*/
abstract fun needToManageOrientation(): Boolean
/**
* The initial view to be focused to avoid BottomSheetDialogFragment to steal it
* Both fields [isFocusable] and [isFocusableInTouchMode] will be set to true
*/
abstract fun initialFocusedView(): View
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment