|
|
|
|
@ -1,30 +1,24 @@ |
|
|
|
|
package com.fongmi.android.tv.ui.custom.dialog; |
|
|
|
|
|
|
|
|
|
import android.app.Dialog; |
|
|
|
|
import android.content.DialogInterface; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.view.KeyEvent; |
|
|
|
|
import android.view.LayoutInflater; |
|
|
|
|
import android.view.View; |
|
|
|
|
import android.view.ViewGroup; |
|
|
|
|
import android.view.WindowManager; |
|
|
|
|
import android.view.inputmethod.EditorInfo; |
|
|
|
|
import android.widget.FrameLayout; |
|
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
import androidx.annotation.Nullable; |
|
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
|
import androidx.fragment.app.FragmentActivity; |
|
|
|
|
import androidx.viewbinding.ViewBinding; |
|
|
|
|
|
|
|
|
|
import com.fongmi.android.tv.databinding.DialogPassBinding; |
|
|
|
|
import com.fongmi.android.tv.impl.PassCallback; |
|
|
|
|
import com.fongmi.android.tv.utils.ResUtil; |
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior; |
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog; |
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; |
|
|
|
|
|
|
|
|
|
public class PassDialog extends BottomSheetDialogFragment { |
|
|
|
|
public class PassDialog extends BaseDialog { |
|
|
|
|
|
|
|
|
|
private final PassCallback callback; |
|
|
|
|
private DialogPassBinding binding; |
|
|
|
|
@ -38,43 +32,15 @@ public class PassDialog extends BottomSheetDialogFragment { |
|
|
|
|
this.callback = (PassCallback) activity; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
@Override |
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
|
|
|
|
binding = DialogPassBinding.inflate(inflater, container, false); |
|
|
|
|
return binding.getRoot(); |
|
|
|
|
protected ViewBinding getBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { |
|
|
|
|
return binding = DialogPassBinding.inflate(inflater, container, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
@Override |
|
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) { |
|
|
|
|
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState); |
|
|
|
|
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); |
|
|
|
|
dialog.setOnShowListener((DialogInterface f) -> setBehavior(dialog)); |
|
|
|
|
return dialog; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setBehavior(BottomSheetDialog dialog) { |
|
|
|
|
FrameLayout bottomSheet = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet); |
|
|
|
|
BottomSheetBehavior<FrameLayout> behavior = BottomSheetBehavior.from(bottomSheet); |
|
|
|
|
behavior.setState(BottomSheetBehavior.STATE_EXPANDED); |
|
|
|
|
behavior.setSkipCollapsed(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
|
|
|
|
super.onViewCreated(view, savedInstanceState); |
|
|
|
|
initEvent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initEvent() { |
|
|
|
|
binding.positive.setOnClickListener(this::onPass); |
|
|
|
|
binding.pass.setOnEditorActionListener(this::onEditorAction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean onEditorAction(TextView view, int actionId, KeyEvent event) { |
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) binding.positive.performClick(); |
|
|
|
|
return true; |
|
|
|
|
binding.pass.setOnEditorActionListener(this::onDone); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onPass(View view) { |
|
|
|
|
@ -83,15 +49,14 @@ public class PassDialog extends BottomSheetDialogFragment { |
|
|
|
|
dismiss(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean onDone(TextView view, int actionId, KeyEvent event) { |
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) binding.positive.performClick(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onResume() { |
|
|
|
|
super.onResume(); |
|
|
|
|
getDialog().getWindow().setLayout(ResUtil.dp2px(250), -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onDestroyView() { |
|
|
|
|
super.onDestroyView(); |
|
|
|
|
binding = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|