mirror of https://github.com/FongMi/TV.git
parent
2ed5cf3b3b
commit
b3005e19d3
@ -0,0 +1,87 @@ |
||||
package com.fongmi.android.tv.ui.dialog; |
||||
|
||||
import android.app.Activity; |
||||
import android.content.Intent; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.databinding.DialogInfoBinding; |
||||
import com.fongmi.android.tv.utils.Notify; |
||||
import com.fongmi.android.tv.utils.Util; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
import java.util.Map; |
||||
|
||||
public class InfoDialog { |
||||
|
||||
private final DialogInfoBinding binding; |
||||
private final Activity activity; |
||||
private AlertDialog dialog; |
||||
private CharSequence title; |
||||
private String header; |
||||
private String url; |
||||
|
||||
public static InfoDialog create(Activity activity) { |
||||
return new InfoDialog(activity); |
||||
} |
||||
|
||||
public InfoDialog(Activity activity) { |
||||
this.binding = DialogInfoBinding.inflate(LayoutInflater.from(this.activity = activity)); |
||||
} |
||||
|
||||
public InfoDialog title(CharSequence title) { |
||||
this.title = title; |
||||
return this; |
||||
} |
||||
|
||||
public InfoDialog headers(Map<String, String> headers) { |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String key : headers.keySet()) sb.append(key).append(" : ").append(headers.get(key)).append("\n"); |
||||
this.header = Util.substring(sb.toString()); |
||||
return this; |
||||
} |
||||
|
||||
public InfoDialog url(String url) { |
||||
this.url = url; |
||||
return this; |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
dialog = new MaterialAlertDialogBuilder(binding.getRoot().getContext()).setView(binding.getRoot()).create(); |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
binding.url.setText(url); |
||||
binding.title.setText(title); |
||||
binding.header.setText(header); |
||||
binding.url.setOnClickListener(this::onShare); |
||||
binding.url.setOnLongClickListener(this::onCopy); |
||||
} |
||||
|
||||
private void onShare(View view) { |
||||
Intent intent = new Intent(Intent.ACTION_SEND); |
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
||||
intent.putExtra(Intent.EXTRA_TEXT, url); |
||||
intent.putExtra("name", title); |
||||
intent.putExtra("title", title); |
||||
intent.setType("text/plain"); |
||||
activity.startActivity(Util.getChooser(intent)); |
||||
dialog.dismiss(); |
||||
} |
||||
|
||||
private boolean onCopy(View view) { |
||||
Notify.show(R.string.copied); |
||||
Util.copy(url); |
||||
return true; |
||||
} |
||||
} |
||||
@ -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="@android:color/white" |
||||
android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z" /> |
||||
</vector> |
||||
@ -1,10 +0,0 @@ |
||||
<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="@android:color/white" |
||||
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92s2.92,-1.31 2.92,-2.92c0,-1.61 -1.31,-2.92 -2.92,-2.92zM18,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM6,13c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,20.02c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1z" /> |
||||
</vector> |
||||
@ -0,0 +1,39 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<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="wrap_content" |
||||
android:orientation="vertical" |
||||
android:paddingStart="24dp" |
||||
android:paddingTop="16dp" |
||||
android:paddingEnd="24dp" |
||||
android:paddingBottom="16dp"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:linksClickable="false" |
||||
android:textColor="?android:attr/textColorPrimary" |
||||
android:textSize="14sp" |
||||
android:textStyle="bold" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/url" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
android:autoLink="all" |
||||
android:linksClickable="false" |
||||
android:textColor="?android:attr/textColorPrimary" |
||||
android:textSize="12sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/header" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="8dp" |
||||
android:textColor="?android:attr/textColorPrimary" |
||||
android:textSize="12sp" /> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue