优化推荐页面UI

修复部分BUG
部分功能优化操作
添加新的功能-更换接口功能
This commit is contained in:
muqing 2024-01-11 17:05:21 +08:00
parent 3c13ae3d98
commit 4077f0a19b
25 changed files with 600 additions and 219 deletions

View File

@ -137,7 +137,6 @@ public class MediaPlayer extends android.media.MediaPlayer {
Glide.with(main.application)
.asBitmap()
.load(bfqkz.xm.picurl)
.error(R.drawable.icon)
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model,
@ -151,9 +150,10 @@ public class MediaPlayer extends android.media.MediaPlayer {
byte[] albumImage = id3v2Tag.getAlbumImage();
bfq.bitmap=
BitmapFactory.decodeByteArray(albumImage, 0, albumImage.length);
}
} catch (Exception a) {
gj.sc("yc:"+a);
gj.sc(getClass() + " yc:" + a);
}
if (bfqkz.notify != null) {
bfqkz.notify.tzl();

View File

@ -3,6 +3,7 @@ package com.muqingbfq.api;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -133,11 +134,14 @@ public class FileDownloader {
id3v2Tag.setTitle(x.name);
id3v2Tag.setArtist(x.zz);
id3v2Tag.setAlbum(x.zz);
id3v2Tag.setLyrics(bfq.lrc);
id3v2Tag.setLyrics(com.muqingbfq.api.url.Lrc(x.id));
ByteArrayOutputStream o = new ByteArrayOutputStream();
bfq.bitmap.compress(Bitmap.CompressFormat.JPEG, 100, o);
byte[] imageData = o.toByteArray();
id3v2Tag.setAlbumImage(imageData, "image/jpeg");
Request build = new Request.Builder().url(x.picurl)
.build();
Response execute = client.newCall(build).execute();
if (execute.isSuccessful()) {
id3v2Tag.setAlbumImage(execute.body().bytes(), "image/jpeg");
}
o.close();
mp3file.save(wj.mp3 + x.id);
outputFile.delete();

View File

@ -39,7 +39,7 @@ public class playlist extends Thread {
if (wj.cz(wj.gd + uid)) {
hq = wj.dqwb(wj.gd + uid);
} else {
hq = wl.hq(api + uid + "&limit=30");
hq = wl.hq(api + uid + "&limit=100" + "&cookie=" + wl.Cookie);
}
JSONObject json = new JSONObject(hq);
JSONArray songs = json.getJSONArray("songs");

View File

@ -151,6 +151,10 @@ public class url extends Thread {
}
}
public static String Lrc(String id) {
return wl.hq("/lyric?id=" + id);
}
public static String picurl(String id) {
String hq = wl.hq("/song/detail?ids=" + id);
try {

View File

@ -1,5 +1,7 @@
package com.muqingbfq.fragment;
import android.graphics.BitmapFactory;
import androidx.annotation.NonNull;
import com.google.android.material.slider.Slider;
@ -62,12 +64,7 @@ public class Media {
}
public Media(ActivityBfqBinding binding) {
binding.tdt.addOnChangeListener(new Slider.OnChangeListener() {
@Override
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
setTime_b(bfq_an.getTime((long) value));
}
});
binding.tdt.addOnChangeListener((slider, value, fromUser) -> setTime_b(bfq_an.getTime((long) value)));
binding.tdt.addOnSliderTouchListener(new Slider.OnSliderTouchListener() {
@Override
public void onStartTrackingTouch(@NonNull Slider slider) {
@ -139,6 +136,9 @@ public class Media {
if (bfq.view == null) {
return;
}
if (bfq.bitmap == null) {
bfq.bitmap= BitmapFactory.decodeResource(bfq.view.getResources(), R.drawable.icon);
}
main.handler.post(() -> bfq.binding.cardview.setImage(com.muqingbfq.bfq.bitmap));
}
}

View File

@ -6,8 +6,6 @@ import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@ -21,7 +19,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.muqingbfq.R;
import com.muqingbfq.activity_about_software;
import com.muqingbfq.XM;
import com.muqingbfq.api.playlist;
import com.muqingbfq.api.resource;
import com.muqingbfq.bfq_an;
@ -32,14 +30,13 @@ import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj;
import com.muqingbfq.mq.wl;
import com.muqingbfq.view.CardImage;
import com.muqingbfq.XM;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -61,7 +58,6 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
binding.lb.setLayoutManager(gridLayoutManager);
binding.lb.setAdapter(adapter);
String id = intent.getStringExtra("id");
// inflate.bfqDb.setBackground(gd.color);
new start(id);
}
@ -135,7 +131,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
XM xm = list.get(position);
CARD card = new CARD(xm);
CARD card = new CARD(position);
if (bool) {
holder.itemView.setOnClickListener(card);
holder.itemView.setOnLongClickListener(card);
@ -152,12 +148,13 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
public void run() {
super.run();
boolean an = playlist.hq(bfqkz.list, xm.id);
if (bfqkz.ms == 2) {
Collections.shuffle(bfqkz.list);
}
main.handler.post(() -> {
if (an) {
bfq_an.xyq();
tx.setImageResource(R.drawable.bf);
main.edit.putString(main.mp3, xm.id);
main.edit.commit();
gdid = xm.id;
}
notifyDataSetChanged();
@ -181,14 +178,16 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
class CARD implements View.OnClickListener
, View.OnLongClickListener {
XM xm;
int position;
public CARD(XM xm) {
this.xm = xm;
public CARD(int position) {
this.position = position;
}
@Override
public void onClick(View view) {
Context context = view.getContext();
XM xm = list.get(position);
Intent intent = new Intent(context, mp3.class);
intent.putExtra("id", xm.id);
intent.putExtra("name", xm.name);
@ -197,66 +196,60 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
@Override
public boolean onLongClick(View view) {
XM xm = list.get(position);
String[] stringArray = view.getResources()
.getStringArray(R.array.gd_list);
new MaterialAlertDialogBuilder(view.getContext()).setItems(stringArray, (dialog, id) -> {
new Thread() {
@Override
public void run() {
if (id == 0) {
String hq = wl.hq(playlist.api + xm.id + "&limit=100");
if (hq != null) {
wj.xrwb(wj.gd + xm.id, hq);
try {
JSONObject jsonObject = new JSONObject();
if (wj.cz(wj.gd_xz)) {
jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
if (!wj.cz(wj.gd + xm.id)) {
stringArray = new String[]{"下载歌单"};
}
new MaterialAlertDialogBuilder(view.getContext()).
setItems(stringArray, (dialog, id) -> {
new Thread() {
@Override
public void run() {
if (id == 0) {
String hq = wl.hq(playlist.api + xm.id + "&limit=100");
if (hq != null) {
wj.xrwb(wj.gd + xm.id, hq);
try {
JSONObject jsonObject = new JSONObject();
if (wj.cz(wj.gd_xz)) {
jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
}
XM fh = resource.Playlist_content(xm.id);
JSONObject json = new JSONObject();
json.put("name", fh.name);
json.put("picUrl", fh.picurl);
jsonObject.put(fh.id, json);
wj.xrwb(wj.gd_xz, jsonObject.toString());
main.handler.post(() -> notifyItemChanged(position));
} catch (JSONException e) {
gj.sc("list gd onclick thear " + e);
}
}
XM fh=resource.Playlist_content(xm.id);
JSONObject json = new JSONObject();
json.put("name", fh.name);
json.put("picUrl", fh.picurl);
jsonObject.put(fh.id, json);
wj.xrwb(wj.gd_xz, jsonObject.toString());
main.handler.post(new sx());
} catch (JSONException e) {
gj.sc("list gd onclick thear " + e);
}
}
} else if (id == 2) {
wj.sc(wj.gd + xm.id);
if (xm.id.equals("mp3_xz.json")) {
wj.sc(new File(wj.mp3));
} else if (id == 2) {
wj.sc(wj.gd + xm.id);
try {
JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
jsonObject.remove(xm.id);
list.remove(xm);
wj.xrwb(wj.gd_xz, jsonObject.toString());
} catch (JSONException e) {
gj.sc(e);
}
}
main.handler.post(() -> notifyItemChanged(position));
}
try {
JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
jsonObject.remove(xm.id);
list.remove(xm);
wj.xrwb(wj.gd_xz, jsonObject.toString());
} catch (JSONException e) {
gj.sc(e);
}
}
main.handler.post(new sx());
}
}.start();
// 在这里处理菜单项的点击事件
dialog.dismiss();
}).show();
}.start();
// 在这里处理菜单项的点击事件
dialog.dismiss();
}).show();
return false;
}
}
class sx implements Runnable {
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
notifyDataSetChanged();
}
}
}
static class VH extends RecyclerView.ViewHolder {

View File

@ -5,56 +5,158 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.muqingbfq.api.resource;
import com.muqingbfq.main;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.muqingbfq.MP3;
import com.muqingbfq.R;
import com.muqingbfq.XM;
import com.muqingbfq.api.resource;
import com.muqingbfq.api.url;
import com.muqingbfq.bfq;
import com.muqingbfq.bfqkz;
import com.muqingbfq.databinding.FragmentGdBinding;
import com.muqingbfq.databinding.ListMp3ImageBinding;
import com.muqingbfq.main;
import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wl;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class gd_adapter extends Fragment {
List<XM> list = new ArrayList<>();
List<MP3> listmp3 = new ArrayList<>();
FragmentGdBinding binding;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FrameLayout layout = new FrameLayout(getContext());
List<XM> list = new ArrayList<>();
RecyclerView recyclerView = new RecyclerView(layout.getContext());
int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f);
GridLayoutManager gridLayoutManager = new GridLayoutManager(layout.getContext(), k / 120);
recyclerView.setLayoutManager(gridLayoutManager);
layout.addView(recyclerView);
gd.baseadapter baseadapter = new gd.baseadapter(getContext(), list);
recyclerView.setAdapter(baseadapter);
binding = FragmentGdBinding.inflate(getLayoutInflater(), container, false);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
binding.recyclerview1.setHasFixedSize(true);
binding.recyclerview1.setNestedScrollingEnabled(false);
binding.recyclerview1.setLayoutManager(linearLayoutManager);
binding.recyclerview1.setAdapter(new gd.baseadapter(getContext(), list));
new Thread() {
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
super.run();
resource.recommend(list);
main.handler.post(new sx(baseadapter));
main.handler.post(new sx());
}
}.start();
return layout;
binding.recyclerview2.setFocusable(false);
binding.recyclerview2.setLayoutManager(new LinearLayoutManager(getContext()){
@Override
public boolean canScrollVertically() {
return false;
}
});
binding.recyclerview2.setAdapter(new RecyclerView.Adapter<VH_MP3>() {
@NonNull
@Override
public VH_MP3 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new VH_MP3(ListMp3ImageBinding.inflate(getLayoutInflater(), parent, false));
}
@SuppressLint("NotifyDataSetChanged")
@Override
public void onBindViewHolder(@NonNull VH_MP3 holder, int position) {
MP3 x = listmp3.get(position);
holder.binding.wb1.setText(x.name);
holder.binding.zz.setText(x.zz);
int color = ContextCompat.getColor(getContext(), R.color.text);
if (bfqkz.xm != null && x.id.equals(bfqkz.xm.id)) {
color = ContextCompat.getColor(getContext(), R.color.text_cz);
}
holder.binding.wb1.setTextColor(color);
holder.binding.zz.setTextColor(color);
holder.itemView.setOnClickListener(view -> {
if (bfqkz.xm == null || !bfqkz.xm.id.equals(x.id)) {
bfqkz.xm = x;
new url(x);
notifyDataSetChanged();
}
bfqkz.list.add(0, x);
// bfqkz.list.addAll(list);
bfq.start(getContext());
});
Glide.with(getContext()).load(x.picurl)
.apply(new RequestOptions().placeholder(R.drawable.ic_launcher_foreground))
.error(R.drawable.ic_launcher_foreground)
.into(holder.binding.imageView);
}
@Override
public int getItemCount() {
return listmp3.size();
}
});
mp3list();
return binding.getRoot();
}
private class sx implements Runnable {
RecyclerView.Adapter baseadapter;
public sx(RecyclerView.Adapter baseadapter) {
this.baseadapter = baseadapter;
}
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
baseadapter.notifyDataSetChanged();
class VH_MP3 extends RecyclerView.ViewHolder {
ListMp3ImageBinding binding;
public VH_MP3(@NonNull ListMp3ImageBinding itemView) {
super(itemView.getRoot());
this.binding = itemView;
}
}
private class sx implements Runnable {
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
binding.recyclerview1.getAdapter().notifyDataSetChanged();
}
}
public void mp3list() {
new Thread(){
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
super.run();
String hq = wl.hq("/recommend/songs" + "?cookie=" + wl.Cookie);
try {
JSONObject jsonObject = new JSONObject(hq);
JSONObject data = jsonObject.getJSONObject("data");
JSONArray dailySongs = data.getJSONArray("dailySongs");
for (int i = 0; i < dailySongs.length(); i++) {
JSONObject jsonObject1 = dailySongs.getJSONObject(i);
String id = jsonObject1.getString("id");
String name = jsonObject1.getString("name");
JSONArray ar = jsonObject1.getJSONArray("ar");
StringBuilder zz = new StringBuilder();
for (int j = 0; j < ar.length(); j++) {
zz.append(ar.getJSONObject(j).getString("name")).append(' ');
}
JSONObject al = jsonObject1.getJSONObject("al");
String picUrl = al.getString("picUrl");
listmp3.add(new MP3(id, name, zz.toString(), picUrl));
}
main.handler.post(() -> binding.recyclerview2.getAdapter().notifyDataSetChanged());
} catch (Exception e) {
gj.sc(e);
}
}
}.start();
}
}

View File

@ -18,7 +18,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.muqingbfq.MP3;
import com.muqingbfq.R;
import com.muqingbfq.XM;
import com.muqingbfq.api.FileDownloader;
import com.muqingbfq.api.playlist;
import com.muqingbfq.api.url;

View File

@ -25,6 +25,7 @@ import com.muqingbfq.login.user_editing;
import com.muqingbfq.login.user_logs;
import com.muqingbfq.login.user_message;
import com.muqingbfq.main;
import com.muqingbfq.mq.EditViewDialog;
import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj;
import com.muqingbfq.XM;
@ -47,7 +48,7 @@ public class wode extends Fragment {
{R.drawable.download, "下载音乐", "mp3_xz.json"},
{R.drawable.like, "喜欢音乐", "mp3_like.json"},
{R.drawable.icon, "本地搜索", ""},
{R.drawable.icon, "我的歌单", ""},
{R.drawable.fuwuzhongxing, "更换接口", "API"},
{R.drawable.icon, "导入歌单", ""},
{R.drawable.paihangbang, "排行榜", "排行榜"},
{R.drawable.icon, "开发中", ""}
@ -112,6 +113,23 @@ public class wode extends Fragment {
b.putExtra("name", s);
getContext().startActivity(b);
break;
case "API":
EditViewDialog editViewDialog = new EditViewDialog(getContext(), "更换接口API")
.setMessage("当前接口:\n" + main.api);
editViewDialog.setPositive(view1 -> {
String str = editViewDialog.getEditText();
boolean http = str.startsWith("http");
if (str.isEmpty() || !http) {
gj.ts(getContext(), "请输入正确的api");
} else {
gj.ts(getContext(), "更换成功");
main.api = str;
wj.xrwb(wj.filesdri+"API.mq", main.api);
editViewDialog.dismiss();
}
}).show();
break;
}
});
}

View File

@ -154,36 +154,6 @@ public class home extends AppCompatActivity {
}
});
}
@Override
protected void onStart() {
super.onStart();
stopService(new Intent(this, FloatingLyricsService.class));
}
ActivityResultLauncher<Intent> LyricsService =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (Settings.canDrawOverlays(this)) {
startService(new Intent(this, FloatingLyricsService.class));
}
});
@Override
protected void onStop() {
super.onStop();
if (!FloatingLyricsService.get()) {
return;
}
if (!Settings.canDrawOverlays(this)) {
// 无权限需要申请权限
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
LyricsService.launch(intent);
} else {
startService(new Intent(this, FloatingLyricsService.class));
}
}
@Override
protected void onPause() {
super.onPause();

View File

@ -1,19 +1,29 @@
package com.muqingbfq;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatDelegate;
import com.muqingbfq.login.visitor;
import com.muqingbfq.mq.FloatingLyricsService;
import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj;
import com.muqingbfq.mq.wl;
import java.io.File;
public class main extends Application {
public static Application application;
@ -24,10 +34,9 @@ public class main extends Application {
public static SharedPreferences sp;
public static SharedPreferences.Editor edit;
public static String mp3 = "mp3",
Cookie = "Cookie";
public static String account,token;
public int count = 0;
@SuppressLint("HardwareIds")
@Override
public void onCreate() {
@ -35,6 +44,17 @@ public class main extends Application {
if (wj.filesdri == null) {
new wj(this);
}
File file = new File(wj.filesdri + "API.mq");
if (file.exists()&&file.isFile()) {
String dqwb = wj.dqwb(file.toString());
if (!TextUtils.isEmpty(dqwb) && dqwb.startsWith("http")) {
api = dqwb;
} else {
file.delete();
}
} else {
wj.xrwb(file.toString(), main.api);
}
application = this;
// UUID.randomUUID().toString();
sp = getSharedPreferences("Set_up", MODE_PRIVATE);
@ -48,9 +68,9 @@ public class main extends Application {
com.muqingbfq.bfqkz.ms = 1;
}
try {
wl.Cookie = sp.getString(Cookie, "");
wl.Cookie = sp.getString("Cookie", "");
} catch (Exception e) {
edit.putString(Cookie, "");
edit.putString("Cookie", "");
wl.Cookie = "";
bj = true;
}
@ -58,7 +78,7 @@ public class main extends Application {
edit.commit();
}
wl.Cookie = main.sp.getString(main.Cookie, "");
wl.Cookie = main.sp.getString("Cookie", "");
if (wl.Cookie.equals("")) {
new visitor();
}
@ -71,6 +91,70 @@ public class main extends Application {
edit.apply();
}
AppCompatDelegate.setDefaultNightMode(i);
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
}
@Override
public void onActivityStarted(Activity activity) {
if (count == 0) { //后台切换到前台
gj.sc(">>>>>>>>>>>>>>>>>>>App切到前台");
if (FloatingLyricsService.lei != null) {
stopService(new Intent(main.this, FloatingLyricsService.class));
}
}
count++;
}
@Override
public void onActivityResumed(Activity activity) {
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
count--;
if (count == 0) { //后台切换到前台
gj.sc(">>>>>>>>>>>>>>>>>>>App切到后台");
new Thread(){
@Override
public void run() {
try {
sleep(1000);
} catch (InterruptedException e) {
e.toString();
}
// gj.sc(count);
if (count != 0) {
return;
}
if (!FloatingLyricsService.get()) {
return;
}
if (Settings.canDrawOverlays(main.this)) {
startService(new Intent(main.this, FloatingLyricsService.class));
}
super.run();
}
}.start();
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
});
}
public static SharedPreferences getSharedPreferences(String string) {

View File

@ -31,6 +31,7 @@ import java.lang.reflect.Type;
public class FloatingLyricsService extends Service implements View.OnClickListener, View.OnTouchListener {
private WindowManager windowManager;
private View layout;
public Runnable updateSeekBar = new Runnable() {
@Override
public void run() {
@ -38,12 +39,17 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
long position = bfqkz.mt.getCurrentPosition();
lrcView.setTimeLrc(position);
}
/* boolean appInForeground = gj.isAppInForeground(FloatingLyricsService.this);
if (appInForeground) {
layout.setVisibility(View.GONE);
} else {
layout.setVisibility(View.VISIBLE);
}*/
handler.postDelayed(this, 1000); // 每秒更新一次进度
}
};
@SuppressLint("StaticFieldLeak")
public static FloatingLyricsService lei;
public static boolean get() {
File file = new File(wj.filesdri + "FloatingLyricsService.json");
if (file.exists() && file.isFile()) {
@ -81,6 +87,8 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
}
@Override
public void onCreate() {
super.onCreate();
@ -168,6 +176,10 @@ public class FloatingLyricsService extends Service implements View.OnClickListen
new Gson().toJson(setup));
}
public static void baocun(SETUP setup) {
if (setup == null) {
return;
}
wj.xrwb(new File(wj.filesdri + "FloatingLyricsService.json").toString(),
new Gson().toJson(setup));
}

View File

@ -1,10 +1,13 @@
package com.muqingbfq.mq;
import android.app.ActivityManager;
import android.app.Service;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.util.Log;
@ -19,6 +22,7 @@ import org.json.JSONObject;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.List;
public class gj {
public static void ts(Context a, Object b) {
@ -29,17 +33,27 @@ public class gj {
main.handler.post(() -> Toast.makeText(context, b.toString(), Toast.LENGTH_SHORT).show());
}
public static boolean isAppInForeground(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Service.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfoList = activityManager.getRunningAppProcesses();
if (runningAppProcessInfoList == null) {
Log.d("runningAppProcess:", "runningAppProcessInfoList is null!");
return false;
}
for (ActivityManager.RunningAppProcessInfo processInfo : runningAppProcessInfoList) {
if (processInfo.processName.equals(context.getPackageName()) && (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND)) {
return true;
}
}
return false;
}
public static boolean isTablet(Context context) {
boolean b;
DisplayMetrics dm = context.getResources().getDisplayMetrics();
main.k = dm.widthPixels;
main.g = dm.heightPixels;
if (main.k > main.g) {
b = true;
} else {
b = false;
}
b = main.k > main.g;
return b;
}
public static void sc(Object a) {
@ -122,9 +136,7 @@ public class gj {
main.handler.post(() -> new MaterialAlertDialogBuilder(context)
.setTitle("更新" + bb)
.setMessage(msg+"\n"+"取消后不再提示更新你需要到关于软件手动检测")
.setNegativeButton("取消", (dialogInterface, i) -> {
wj.xrwb(wj.filesdri + "gx.mq", null);
})
.setNegativeButton("取消", (dialogInterface, i) -> wj.xrwb(wj.filesdri + "gx.mq", null))
.setPositiveButton("更新", (dialogInterface, i) -> context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(url))))
// new ApkDownloader(context).downloadAndInstall(url, wj.filesdri))

View File

@ -19,7 +19,7 @@ public class wl {
public static void setcookie(String cookie) {
wl.Cookie = cookie;
main.edit.putString(main.Cookie, cookie);
main.edit.putString("Cookie", cookie);
main.edit.commit();
}

View File

@ -12,7 +12,6 @@ import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
@ -126,8 +125,15 @@ public class sz extends AppCompatActivity {
});
}
public static class setlrc extends Fragment implements Slider.OnSliderTouchListener,
Slider.OnChangeListener {
ActivityResultLauncher<Intent> LyricsService =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (Settings.canDrawOverlays(getContext())) {
getContext().startService(new Intent(getContext(), FloatingLyricsService.class));
}
});
FloatingLyricsService.SETUP setup;
ActivitySzSetlrcBinding binding;
public Runnable updateSeekBar = new Runnable() {
@ -166,6 +172,8 @@ public class sz extends AppCompatActivity {
main.handler.postDelayed(this, 1000); // 每秒更新一次进度
}
};
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -203,17 +211,29 @@ public class sz extends AppCompatActivity {
.show());
binding.textSlide1.setText(String.valueOf(setup.size));
binding.textSlide2.setText(String.format(Locale.US,"%.2f",setup.Alpha));
if (setup.i != 0) {
binding.switchA1.setChecked(true);
}
main.handler.post(updateSeekBar);
}
if (setup.i != 0) {
binding.switchA1.setChecked(true);
}
binding.switchA1.setOnCheckedChangeListener((compoundButton, b) -> {
if (b) {
setup.i = 1;
if (setup != null) {
setup.i = 1;
}
if (!Settings.canDrawOverlays(getContext())) {
// 无权限需要申请权限
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getContext().getPackageName()));
LyricsService.launch(intent);
} else {
getContext().startService(new Intent(getContext(), FloatingLyricsService.class));
}
} else {
setup.i = 0;
if (setup != null) {
setup.i = 0;
}
home.appCompatActivity
.stopService(new Intent(home.appCompatActivity,
FloatingLyricsService.class));
@ -244,11 +264,18 @@ public class sz extends AppCompatActivity {
@Override
public void onStopTrackingTouch(@NonNull Slider slider) {
if (setup == null) {
return;
}
FloatingLyricsService.baocun(setup);
}
@Override
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
if (setup == null) {
return;
}
if (slider == binding.slide1) {
setup.size = (int) value;
binding.lrctext.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,

View File

@ -1,7 +1,6 @@
package com.muqingbfq.view;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
@ -83,7 +82,6 @@ public class LrcView extends RecyclerView {
AttributeSet attrs;
boolean Lrcline;
LinearLayoutManager linearLayoutManager;
public LrcView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.attrs = attrs;
@ -167,7 +165,7 @@ public class LrcView extends RecyclerView {
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 100f / displayMetrics.densityDpi;
return 50f / displayMetrics.densityDpi;
}
}
@ -236,19 +234,18 @@ public class LrcView extends RecyclerView {
@Override
public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View inflate = LayoutInflater.from(getContext()).inflate(R.layout.view_lrc, parent, false);
TextView textView = inflate.findViewById(R.id.text);
textView.setTextColor(TextColor);
textView.setTextSize(
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
getResources().getDisplayMetrics()));
textView.setAlpha(alpha);
inflate.setOnClickListener(LrcView.this.onClickListener);
return new VH(inflate);
}
@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
TextView textView = holder.textView;
textView.setTextColor(TextColor);
textView.setTextSize(
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
getResources().getDisplayMetrics()));
textView.setAlpha(alpha);
holder.itemView.setOnClickListener(LrcView.this.onClickListener);
if (Lrcline) {
if (addOnGlobalLayoutListener) {
// 注册布局监听器

View File

@ -0,0 +1,73 @@
package com.muqingbfq.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
public class RecyclerViewH extends RecyclerView {
public RecyclerViewH(@NonNull Context context) {
super(context);
}
public RecyclerViewH(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public RecyclerViewH(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
private boolean disallowIntercept = false;
private int startX = 0;
private int startY = 0;
boolean isDispatch = true;
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (isDispatch) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = (int) ev.getX();
startY = (int) ev.getY();
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
int endX = (int) ev.getX();
int endY = (int) ev.getY();
int disX = Math.abs(endX - startX);
int disY = Math.abs(endY - startY);
if (Math.abs(disY) > ViewConfiguration.get(getContext()).getScaledTouchSlop()) {
// 当前手指移动距离大于系统认定的最小滚动距离时不允许父容器拦截触摸事件
getParent().requestDisallowInterceptTouchEvent(true);
}else
/*
if (disX > disY) {
//为了解决RecyclerView嵌套RecyclerView时横向滑动的问题
if (disallowIntercept) {
getParent().requestDisallowInterceptTouchEvent(disallowIntercept);
} else {
getParent().requestDisallowInterceptTouchEvent(canScrollHorizontally(startX - endX));
}
} else {
getParent().requestDisallowInterceptTouchEvent(true);
}*/
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return super.dispatchTouchEvent(ev);
}
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
this.disallowIntercept = disallowIntercept;
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
}

View File

@ -0,0 +1,29 @@
<?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="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.muqingbfq.view.Text
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="26sp"
android:textColor="@color/text"/>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lb"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bfq_db"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.muqingbfq.fragment.bfq_db"
tools:layout="@layout/fragment_bfq_db" />
</LinearLayout>

View File

@ -36,19 +36,14 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="头像:" />
<com.google.android.material.card.MaterialCardView
android:layout_width="68dp"
android:layout_height="68dp">
<ImageView
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/icon" />
</com.google.android.material.card.MaterialCardView>
android:layout_width="68dp"
android:layout_height="68dp"
app:round="16dp"
android:layout_margin="16dp"
app:srcCompat="@drawable/ic_launcher_foreground" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
@ -116,19 +111,14 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="背景(此软件暂无使用背景):" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">
<ImageView
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/icon" />
</com.google.android.material.card.MaterialCardView>
app:round="16dp"
app:srcCompat="@drawable/ic_launcher_foreground" />
</LinearLayout>
<Button
android:id="@+id/user_end"

View File

@ -1,29 +1,56 @@
<?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="match_parent"
<androidx.core.widget.NestedScrollView 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:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.muqingbfq.view.Text
android:id="@+id/title"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="6dp"
android:text="每日趣荐"
android:textSize="26sp" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="26sp"
android:textColor="@color/text"/>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lb"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/bfq_db"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.muqingbfq.fragment.bfq_db"
tools:layout="@layout/fragment_bfq_db" />
</LinearLayout>
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
app:contentPadding="6dp">
<com.muqingbfq.view.RecyclerViewH
android:id="@+id/recyclerview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
tools:itemCount="6" />
</com.google.android.material.card.MaterialCardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="6dp"
android:text="每日一首"
android:textSize="26sp" />
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
app:contentPadding="6dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -19,11 +19,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/imageView"
android:layout_width="65dp"
android:layout_height="65dp"
android:src="@drawable/icon"
app:srcCompat="@drawable/ic_launcher_foreground"
android:layout_margin="6dp"
app:round="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@ -1,19 +1,17 @@
<?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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center_vertical"
android:orientation="horizontal"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
tools:ignore="UselessParent">
<TextView
android:id="@+id/wb1"
android:layout_width="match_parent"

View File

@ -0,0 +1,39 @@
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="?android:attr/selectableItemBackground"
android:padding="10dp">
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/imageView"
android:layout_width="56dp"
android:layout_height="56dp"
app:srcCompat="@drawable/ic_launcher_foreground"
app:round="6dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginStart="6dp">
<TextView
android:id="@+id/wb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/name"
android:textColor="@color/text"
android:textSize="16sp" />
<TextView
android:id="@+id/zz"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/text"
android:text="@string/zz" />
</LinearLayout>
</LinearLayout>

View File

@ -10,6 +10,7 @@
android:layout_height="56dp"
android:background="@null"
android:src="@drawable/icon"
android:padding="6dp"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/text1"

View File

@ -26,14 +26,14 @@
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/quxiao"
style="?android:attr/buttonBarButtonStyle" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="确定"