mirror of https://github.com/FongMi/TV.git
parent
d3ab11c522
commit
2e0df3127c
@ -0,0 +1,66 @@ |
||||
package com.fongmi.android.tv.ui.custom.dialog; |
||||
|
||||
import android.text.TextUtils; |
||||
import android.util.Patterns; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.inputmethod.EditorInfo; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.fragment.app.Fragment; |
||||
|
||||
import com.fongmi.android.tv.App; |
||||
import com.fongmi.android.tv.databinding.DialogLinkBinding; |
||||
import com.fongmi.android.tv.ui.activity.DetailActivity; |
||||
import com.fongmi.android.tv.utils.Utils; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
public class LinkDialog { |
||||
|
||||
private final DialogLinkBinding binding; |
||||
private final AlertDialog dialog; |
||||
|
||||
public static LinkDialog create(Fragment fragment) { |
||||
return new LinkDialog(fragment); |
||||
} |
||||
|
||||
public LinkDialog(Fragment fragment) { |
||||
this.binding = DialogLinkBinding.inflate(LayoutInflater.from(fragment.getContext())); |
||||
this.dialog = new MaterialAlertDialogBuilder(fragment.getActivity()).setView(binding.getRoot()).create(); |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
CharSequence text = Utils.getClipText(); |
||||
if (!TextUtils.isEmpty(text) && Patterns.WEB_URL.matcher(text).matches()) binding.text.setText(text); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
binding.positive.setOnClickListener(this::onPositive); |
||||
binding.negative.setOnClickListener(this::onNegative); |
||||
binding.text.setOnEditorActionListener((textView, actionId, event) -> { |
||||
if (actionId == EditorInfo.IME_ACTION_DONE) binding.positive.performClick(); |
||||
return true; |
||||
}); |
||||
} |
||||
|
||||
private void onPositive(View view) { |
||||
String text = binding.text.getText().toString().trim(); |
||||
if (!text.isEmpty()) DetailActivity.push(App.activity(), text); |
||||
dialog.dismiss(); |
||||
} |
||||
|
||||
private void onNegative(View view) { |
||||
dialog.dismiss(); |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:tint="#FFFFFF" |
||||
android:viewportWidth="24" |
||||
android:viewportHeight="24"> |
||||
<path |
||||
android:fillColor="#FFFFFF" |
||||
android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z" /> |
||||
</vector> |
||||
@ -0,0 +1,49 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
android:padding="16dp"> |
||||
|
||||
<EditText |
||||
android:id="@+id/text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="10dp" |
||||
android:hint="@string/dialog_config_url" |
||||
android:imeOptions="actionDone" |
||||
android:importantForAutofill="no" |
||||
android:inputType="textUri" |
||||
android:singleLine="true" |
||||
android:textSize="16sp" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/positive" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/shape_text" |
||||
android:gravity="center" |
||||
android:text="@string/dialog_positive" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/negative" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
||||
android:background="@drawable/shape_text" |
||||
android:gravity="center" |
||||
android:text="@string/dialog_negative" |
||||
android:textColor="@color/white" |
||||
android:textSize="14sp" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
Loading…
Reference in new issue