feat(login): 优化登录流程并添加 IP 地址设置功能- 移除了无用的 Activity 声明和注释- 调整了 fragment_bflb_db 中布局参数的设置
- 新增了 DialogEditText 自定义对话框用于 IP 地址输入 - 优化了 HomeSteer 类中的登录逻辑,支持保存和读取 IP 地址- 更新了 main 类中的 API地址初始化方式 - 新增了 wl 类中的 getCookie静态方法用于获取 Cookie
This commit is contained in:
parent
756cd6e75c
commit
4857237d8d
20
app/debug/output-metadata.json
Normal file
20
app/debug/output-metadata.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.muqingbfq",
|
||||
"variantName": "debug",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "2.6.0",
|
||||
"outputFile": "Cloud_music-debug-v2.6.0.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
|
@ -52,10 +52,6 @@
|
|||
<activity android:name=".login.user_logs" />
|
||||
<activity android:name=".clean.fragment_clean" />
|
||||
<activity android:name=".activity_search" />
|
||||
<!-- <activity-->
|
||||
<!-- android:name=".bfq"-->
|
||||
<!-- android:configChanges="keyboardHidden|screenSize"-->
|
||||
<!-- android:theme="@style/fragment_dialog" />-->
|
||||
<activity android:name=".fragment.mp3" />
|
||||
<activity android:name=".fragment.gd" />
|
||||
<activity android:name=".activity_about_software" />
|
||||
|
|
46
app/src/main/java/com/muqingbfq/Dialog/DialogEditText.java
Normal file
46
app/src/main/java/com/muqingbfq/Dialog/DialogEditText.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package com.muqingbfq.Dialog;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.dialog.MaterialDialogs;
|
||||
import com.muqingbfq.databinding.DialogEdittextBinding;
|
||||
|
||||
public class DialogEditText extends MaterialAlertDialogBuilder {
|
||||
public final DialogEdittextBinding binding;
|
||||
|
||||
public AlertDialog alertDialog;
|
||||
public DialogEditText(Context context, String[] strings) {
|
||||
super(context);
|
||||
binding = DialogEdittextBinding.inflate(LayoutInflater.from(context));
|
||||
ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1);
|
||||
for (String s : strings) {
|
||||
stringArrayAdapter.add(s);
|
||||
}
|
||||
binding.edittext.setAdapter(stringArrayAdapter);
|
||||
setView(binding.getRoot());
|
||||
}
|
||||
|
||||
public void setPositiveButton(@Nullable Button.OnClickListener listener) {
|
||||
binding.Yes.setOnClickListener(listener);
|
||||
}
|
||||
|
||||
public void setNegativeButton(@Nullable Button.OnClickListener listener) {
|
||||
binding.No.setOnClickListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog show() {
|
||||
alertDialog = super.show();
|
||||
return alertDialog;
|
||||
}
|
||||
}
|
|
@ -6,13 +6,16 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.muqingbfq.Dialog.DialogEditText;
|
||||
import com.muqingbfq.fragment.wode;
|
||||
import com.muqingbfq.login.user_logs;
|
||||
import com.muqingbfq.mq.EditViewDialog;
|
||||
|
@ -22,6 +25,8 @@ import com.muqingbfq.view.Edit;
|
|||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class HomeSteer {
|
||||
home home;
|
||||
ActivityResultLauncher<Intent> dlintent;
|
||||
|
@ -34,7 +39,7 @@ public class HomeSteer {
|
|||
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||
// 处理返回结果
|
||||
Intent data = result.getData();
|
||||
boolean bool = data.getBooleanExtra("bool", false);
|
||||
boolean bool = Objects.requireNonNull(data).getBooleanExtra("bool", false);
|
||||
if (bool) {
|
||||
Yes();
|
||||
return;
|
||||
|
@ -48,50 +53,55 @@ public class HomeSteer {
|
|||
}
|
||||
|
||||
public void One() {
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(home);
|
||||
materialAlertDialogBuilder.setTitle("引导登陆");
|
||||
materialAlertDialogBuilder.setItems(new String[]{"游客", "登陆"}, (dialog, which) -> {
|
||||
if (which == 0) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
//获取游客Cookie
|
||||
String hq = wl.hq("/register/anonimous");
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(hq);
|
||||
wl.setcookie(jsonObject.getString("cookie"));
|
||||
home.runOnUiThread(() -> Yes());
|
||||
} catch (Exception e) {
|
||||
home.runOnUiThread(() -> Toast.makeText(home, "游客登陆失败:" + e.getMessage(), Toast.LENGTH_SHORT).show());
|
||||
gj.sc(e);
|
||||
wl.getCookie();
|
||||
if (wl.Cookie.isEmpty()) {
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(home);
|
||||
materialAlertDialogBuilder.setTitle("引导登陆");
|
||||
materialAlertDialogBuilder.setItems(new String[]{"游客", "登陆"}, (dialog, which) -> {
|
||||
if (which == 0) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
//获取游客Cookie
|
||||
String hq = wl.hq("/register/anonimous");
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(hq);
|
||||
wl.setcookie(jsonObject.getString("cookie"));
|
||||
home.runOnUiThread(() -> Yes());
|
||||
} catch (Exception e) {
|
||||
home.runOnUiThread(() -> Toast.makeText(home, "游客登陆失败:" + e.getMessage(), Toast.LENGTH_SHORT).show());
|
||||
gj.sc(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
} else if (which == 1) {
|
||||
dlintent.launch(new Intent(home, user_logs.class));
|
||||
}
|
||||
});
|
||||
materialAlertDialogBuilder.show();
|
||||
}.start();
|
||||
} else if (which == 1) {
|
||||
dlintent.launch(new Intent(home, user_logs.class));
|
||||
}
|
||||
});
|
||||
materialAlertDialogBuilder.show();
|
||||
}else{
|
||||
Yes();
|
||||
}
|
||||
}
|
||||
|
||||
public void Yes() {
|
||||
|
||||
}
|
||||
|
||||
String[] stringIp = new String[]{"https://ncm.nekogan.com", "https://api.csm.sayqz.com"};
|
||||
|
||||
/**
|
||||
* 设置IP地址
|
||||
*/
|
||||
public void SetIP() {
|
||||
SharedPreferences nickname = home.getSharedPreferences("Set_up", Context.MODE_PRIVATE);
|
||||
if (nickname.getString("IP", "").isEmpty()) {
|
||||
EditViewDialog editViewDialog = new EditViewDialog(home, "IP");
|
||||
editViewDialog.setMessage("请输入部署了NeteaseCloudMusicApi的服务器地址,\n例如" +
|
||||
"https://api.csm.sayqz.com");
|
||||
// editViewDialog.setPositive()
|
||||
editViewDialog.buttonb.setEnabled(false);
|
||||
editViewDialog.editText.setMaxLines(1);
|
||||
editViewDialog.editText.addTextChangedListener(new Edit.TextWatcher() {
|
||||
main.api = nickname.getString("IP", "");
|
||||
if (TextUtils.isEmpty(main.api)) {
|
||||
|
||||
DialogEditText dialogEditText = getDialogEditText(nickname);
|
||||
|
||||
dialogEditText.binding.edittext.addTextChangedListener(new Edit.TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) {
|
||||
|
||||
|
@ -100,7 +110,7 @@ public class HomeSteer {
|
|||
@Override
|
||||
public void onTextChanged(CharSequence var1, int var2, int var3, int var4) {
|
||||
//正则表达式检查是否为 https://api.csm.sayqz.com这样的
|
||||
editViewDialog.buttonb.setEnabled(var1.toString().matches("^(https?://).+[^/]"));
|
||||
dialogEditText.binding.Yes.setEnabled(var1.toString().matches("^(https?://).+[^/]"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,16 +118,26 @@ public class HomeSteer {
|
|||
|
||||
}
|
||||
});
|
||||
editViewDialog.setPositive(v -> {
|
||||
main.api = editViewDialog.getEditText();
|
||||
nickname.edit().putString("IP", editViewDialog.getEditText()).apply();
|
||||
One();
|
||||
editViewDialog.dismiss();
|
||||
});
|
||||
editViewDialog.show();
|
||||
dialogEditText.show();
|
||||
} else {
|
||||
main.api = nickname.getString("IP", "");
|
||||
One();
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private DialogEditText getDialogEditText(SharedPreferences nickname) {
|
||||
DialogEditText dialogEditText = new DialogEditText(home, stringIp);
|
||||
dialogEditText.setTitle("IP");
|
||||
dialogEditText.setMessage("请输入部署了NeteaseCloudMusicApi的服务器地址");
|
||||
dialogEditText.setPositiveButton((view) -> {
|
||||
main.api = dialogEditText.binding.edittext.getText().toString();
|
||||
nickname.edit().putString("IP", main.api).apply();
|
||||
One();
|
||||
dialogEditText.alertDialog.dismiss();
|
||||
|
||||
});
|
||||
dialogEditText.binding.Yes.isEnabled();
|
||||
dialogEditText.setNegativeButton((view) -> home.finish());
|
||||
return dialogEditText;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class bflb_db extends BottomSheetDialog {
|
|||
if (view != null) {
|
||||
// 设置宽度
|
||||
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
|
||||
layoutParams.width = (int) (getContext().getResources().getDisplayMetrics().widthPixels * 0.6); // 占屏幕宽度的 60%
|
||||
layoutParams.height = (int) (getContext().getResources().getDisplayMetrics().widthPixels * 0.6); // 占屏幕宽度的 60%
|
||||
view.setLayoutParams(layoutParams);
|
||||
}
|
||||
}
|
||||
|
@ -71,12 +71,6 @@ public class bflb_db extends BottomSheetDialog {
|
|||
super.onCreate(savedInstanceState);
|
||||
binding = FragmentBflbDbBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
// 设置高度
|
||||
// DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
// WindowManager windowManager = (WindowManager) getContext().getSystemService(WINDOW_SERVICE);
|
||||
// windowManager.getDefaultDisplay().getMetrics(displayMetrics);
|
||||
// binding.getRoot().getLayoutParams().height = displayMetrics.heightPixels - displayMetrics.heightPixels / 3;
|
||||
// binding.getRoot().requestLayout();
|
||||
|
||||
|
||||
// 设置固定的高度(例如 500dp)
|
||||
|
|
|
@ -69,7 +69,7 @@ public class home extends AppCompatActivity<ActivityHomeBinding> {
|
|||
controllerFuture.addListener(() -> {
|
||||
|
||||
}, MoreExecutors.directExecutor());
|
||||
if (Strings.isNullOrEmpty(wl.Cookie)) {
|
||||
if (Strings.isNullOrEmpty(main.api) || Strings.isNullOrEmpty(wl.Cookie)) {
|
||||
new HomeSteer(this) {
|
||||
@Override
|
||||
public void Yes() {
|
||||
|
@ -132,7 +132,7 @@ public class home extends AppCompatActivity<ActivityHomeBinding> {
|
|||
return list.size();
|
||||
}
|
||||
});
|
||||
binding.viewPager.setCurrentItem(0,false);
|
||||
binding.viewPager.setCurrentItem(0, false);
|
||||
if (!gj.isTablet(this)) {
|
||||
binding.linearLayout4.post(() -> {
|
||||
int height = binding.linearLayout4.getHeight();
|
||||
|
@ -148,13 +148,13 @@ public class home extends AppCompatActivity<ActivityHomeBinding> {
|
|||
MaterialCardView childAt = (MaterialCardView) binding.tablayout.linearLayout.getChildAt(i);
|
||||
if (i == 0) {
|
||||
//背景高亮
|
||||
childAt.setCardBackgroundColor(gj.getThemeColor(v.getContext(), com.google.android.material.R.attr.colorPrimaryContainer));
|
||||
childAt.setCardBackgroundColor(gj.getThemeColor(v.getContext(), com.google.android.material.R.attr.colorPrimaryContainer));
|
||||
} else {
|
||||
//背景恢复
|
||||
childAt.setCardBackgroundColor(gj.getThemeColor(v.getContext(), com.google.android.material.R.attr.colorSurface));
|
||||
}
|
||||
}
|
||||
binding.viewPager.setCurrentItem(0,false);
|
||||
binding.viewPager.setCurrentItem(0, false);
|
||||
});
|
||||
binding.tablayout.addView("我的", R.drawable.user).setOnClickListener(v -> {
|
||||
for (int i = 0; i < binding.tablayout.sizeView; i++) {
|
||||
|
@ -167,7 +167,7 @@ public class home extends AppCompatActivity<ActivityHomeBinding> {
|
|||
childAt.setCardBackgroundColor(gj.getThemeColor(v.getContext(), com.google.android.material.R.attr.colorSurface));
|
||||
}
|
||||
}
|
||||
binding.viewPager.setCurrentItem(1,false);
|
||||
binding.viewPager.setCurrentItem(1, false);
|
||||
});
|
||||
toolbar();
|
||||
SearchUI();
|
||||
|
|
|
@ -29,7 +29,8 @@ import java.util.List;
|
|||
public class main extends Application {
|
||||
public static Application application;
|
||||
public static Handler handler = new Handler(Looper.getMainLooper());
|
||||
public static String api = "https://api.csm.sayqz.com";
|
||||
public static String api;
|
||||
// https://ncm.nekogan.com
|
||||
// public static String http = "https://www.muqingkaifazhe.top/muqingbfq.php"; 过时的更新检测
|
||||
public static SharedPreferences sp;
|
||||
public static SharedPreferences.Editor edit;
|
||||
|
|
|
@ -31,6 +31,9 @@ public class wl {
|
|||
main.edit.putString("Cookie", cookie);
|
||||
main.edit.commit();
|
||||
}
|
||||
public static void getCookie(){
|
||||
Cookie = main.sp.getString("Cookie", "");
|
||||
}
|
||||
|
||||
public static String hq(String url) {
|
||||
try {
|
||||
|
|
44
app/src/main/res/layout/dialog_edittext.xml
Normal file
44
app/src/main/res/layout/dialog_edittext.xml
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:orientation="vertical"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="13dp">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/edittext"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="LabelFor" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/No"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginHorizontal="3dp"
|
||||
android:text="取消"/>
|
||||
<Button
|
||||
android:id="@+id/Yes"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="3dp"
|
||||
android:layout_weight="1"
|
||||
android:text="确定"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user