mirror of https://github.com/FongMi/TV.git
parent
2a9a62d517
commit
db9fe9f831
@ -0,0 +1,65 @@ |
||||
package com.fongmi.android.tv.ui.custom.dialog; |
||||
|
||||
import android.content.DialogInterface; |
||||
import android.text.TextUtils; |
||||
import android.view.LayoutInflater; |
||||
import android.view.inputmethod.EditorInfo; |
||||
|
||||
import androidx.appcompat.app.AlertDialog; |
||||
import androidx.fragment.app.Fragment; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.databinding.DialogUaBinding; |
||||
import com.fongmi.android.tv.impl.UaCallback; |
||||
import com.fongmi.android.tv.utils.Prefers; |
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
||||
|
||||
public class UaDialog { |
||||
|
||||
private final DialogUaBinding binding; |
||||
private final UaCallback callback; |
||||
private AlertDialog dialog; |
||||
|
||||
public static UaDialog create(Fragment fragment) { |
||||
return new UaDialog(fragment); |
||||
} |
||||
|
||||
public UaDialog(Fragment fragment) { |
||||
this.callback = (UaCallback) fragment; |
||||
this.binding = DialogUaBinding.inflate(LayoutInflater.from(fragment.getContext())); |
||||
} |
||||
|
||||
public void show() { |
||||
initDialog(); |
||||
initView(); |
||||
initEvent(); |
||||
} |
||||
|
||||
private void initDialog() { |
||||
dialog = new MaterialAlertDialogBuilder(binding.getRoot().getContext()).setTitle(R.string.setting_player_ua).setView(binding.getRoot()).setPositiveButton(R.string.dialog_positive, this::onPositive).setNegativeButton(R.string.dialog_negative, this::onNegative).create(); |
||||
dialog.getWindow().setDimAmount(0); |
||||
dialog.show(); |
||||
} |
||||
|
||||
private void initView() { |
||||
String ua = Prefers.getUa(); |
||||
binding.text.setText(ua); |
||||
binding.text.setSelection(TextUtils.isEmpty(ua) ? 0 : ua.length()); |
||||
} |
||||
|
||||
private void initEvent() { |
||||
binding.text.setOnEditorActionListener((textView, actionId, event) -> { |
||||
if (actionId == EditorInfo.IME_ACTION_DONE) dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); |
||||
return true; |
||||
}); |
||||
} |
||||
|
||||
private void onPositive(DialogInterface dialog, int which) { |
||||
callback.setUa(binding.text.getText().toString().trim()); |
||||
dialog.dismiss(); |
||||
} |
||||
|
||||
private void onNegative(DialogInterface dialog, int which) { |
||||
dialog.dismiss(); |
||||
} |
||||
} |
||||
@ -0,0 +1,75 @@ |
||||
package com.fongmi.android.tv.ui.fragment; |
||||
|
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
import androidx.viewbinding.ViewBinding; |
||||
|
||||
import com.fongmi.android.tv.R; |
||||
import com.fongmi.android.tv.databinding.FragmentSettingPlayerBinding; |
||||
import com.fongmi.android.tv.impl.UaCallback; |
||||
import com.fongmi.android.tv.player.ExoUtil; |
||||
import com.fongmi.android.tv.ui.base.BaseFragment; |
||||
import com.fongmi.android.tv.ui.custom.dialog.UaDialog; |
||||
import com.fongmi.android.tv.utils.Prefers; |
||||
import com.fongmi.android.tv.utils.ResUtil; |
||||
|
||||
public class SettingPlayerFragment extends BaseFragment implements UaCallback { |
||||
|
||||
private FragmentSettingPlayerBinding mBinding; |
||||
private String[] http; |
||||
|
||||
public static SettingPlayerFragment newInstance() { |
||||
return new SettingPlayerFragment(); |
||||
} |
||||
|
||||
private String getSwitch(boolean value) { |
||||
return getString(value ? R.string.setting_on : R.string.setting_off); |
||||
} |
||||
|
||||
@Override |
||||
protected ViewBinding getBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { |
||||
return mBinding = FragmentSettingPlayerBinding.inflate(inflater, container, false); |
||||
} |
||||
|
||||
@Override |
||||
protected void initView() { |
||||
mBinding.uaText.setText(Prefers.getUa()); |
||||
mBinding.tunnelText.setText(getSwitch(Prefers.isTunnel())); |
||||
mBinding.httpText.setText((http = ResUtil.getStringArray(R.array.select_player_http))[Prefers.getHttp()]); |
||||
mBinding.tunnel.setVisibility(Prefers.getPlayer() == 0 ? View.VISIBLE : View.GONE); |
||||
mBinding.http.setVisibility(Prefers.getPlayer() == 0 ? View.VISIBLE : View.GONE); |
||||
} |
||||
|
||||
@Override |
||||
protected void initEvent() { |
||||
mBinding.ua.setOnClickListener(this::onUa); |
||||
mBinding.http.setOnClickListener(this::setHttp); |
||||
mBinding.tunnel.setOnClickListener(this::setTunnel); |
||||
} |
||||
|
||||
private void onUa(View view) { |
||||
UaDialog.create(this).show(); |
||||
} |
||||
|
||||
private void setHttp(View view) { |
||||
int index = Prefers.getHttp(); |
||||
Prefers.putHttp(index = index == http.length - 1 ? 0 : ++index); |
||||
mBinding.httpText.setText(http[index]); |
||||
ExoUtil.reset(); |
||||
} |
||||
|
||||
private void setTunnel(View view) { |
||||
Prefers.putTunnel(!Prefers.isTunnel()); |
||||
mBinding.tunnelText.setText(getSwitch(Prefers.isTunnel())); |
||||
} |
||||
|
||||
@Override |
||||
public void setUa(String ua) { |
||||
mBinding.uaText.setText(ua); |
||||
Prefers.putUa(ua); |
||||
} |
||||
} |
||||
@ -0,0 +1,25 @@ |
||||
<?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:paddingStart="24dp" |
||||
android:paddingTop="16dp" |
||||
android:paddingEnd="24dp"> |
||||
|
||||
<com.google.android.material.textfield.TextInputLayout |
||||
android:id="@+id/input" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"> |
||||
|
||||
<com.google.android.material.textfield.TextInputEditText |
||||
android:id="@+id/text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:imeOptions="actionDone" |
||||
android:importantForAutofill="no" |
||||
android:inputType="text" |
||||
android:singleLine="true" /> |
||||
|
||||
</com.google.android.material.textfield.TextInputLayout> |
||||
</LinearLayout> |
||||
@ -0,0 +1,125 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<com.google.android.material.appbar.AppBarLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@color/transparent"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginEnd="16dp" |
||||
android:text="@string/setting_player" |
||||
android:textColor="@color/white" |
||||
android:textSize="20sp" |
||||
android:textStyle="bold" |
||||
app:layout_scrollFlags="scroll|enterAlways" /> |
||||
|
||||
</com.google.android.material.appbar.AppBarLayout> |
||||
|
||||
<androidx.core.widget.NestedScrollView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:fillViewport="true" |
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical" |
||||
android:paddingStart="16dp" |
||||
android:paddingTop="16dp" |
||||
android:paddingEnd="16dp" |
||||
android:paddingBottom="16dp"> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/ua" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/shape_item" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:text="@string/setting_player_ua" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/uaText" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:ellipsize="middle" |
||||
android:gravity="end" |
||||
android:singleLine="true" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="okhttp/4.11.0" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/http" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:background="@drawable/shape_item" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:text="@string/setting_player_http" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/httpText" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:gravity="end" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="OkHttp" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/tunnel" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:background="@drawable/shape_item" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="16dp" |
||||
android:text="@string/setting_player_tunnel" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/tunnelText" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:gravity="end" |
||||
android:textColor="@color/white" |
||||
android:textSize="16sp" |
||||
tools:text="關" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
</androidx.core.widget.NestedScrollView> |
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
||||
Loading…
Reference in new issue