睡觉ø
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package org.astral.findmaimaiultra.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.astral.findmaimaiultra.R;
|
||||
import org.astral.findmaimaiultra.been.lx.Song;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongAdapter extends RecyclerView.Adapter<SongAdapter.ViewHolder> {
|
||||
|
||||
private List<Song> songs;
|
||||
private OnItemClickListener listener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(Song song);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public SongAdapter(List<Song> songs) {
|
||||
this.songs = songs;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_song, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
Song song = songs.get(position);
|
||||
holder.title.setText(song.getTitle());
|
||||
holder.artist.setText(song.getArtist());
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (listener != null) {
|
||||
listener.onItemClick(song);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return songs.size();
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView title;
|
||||
TextView artist;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.song_title);
|
||||
artist = itemView.findViewById(R.id.song_artist);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,13 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -22,17 +26,20 @@ import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import okhttp3.*;
|
||||
import org.astral.findmaimaiultra.R;
|
||||
import org.astral.findmaimaiultra.adapter.MusicRatingAdapter;
|
||||
import org.astral.findmaimaiultra.adapter.SongAdapter;
|
||||
import org.astral.findmaimaiultra.adapter.SuggestMusicRatingAdapter;
|
||||
import org.astral.findmaimaiultra.been.faker.MaiUser;
|
||||
import org.astral.findmaimaiultra.been.faker.MusicRating;
|
||||
@@ -468,7 +475,96 @@ public class MusicFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void setRatingProject() {
|
||||
// 创建弹窗
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext(), R.style.CustomDialogStyle);
|
||||
View dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.rating_project_dialog, null);
|
||||
builder.setView(dialogView);
|
||||
|
||||
// 初始化搜索框和列表
|
||||
TextInputEditText searchInput = dialogView.findViewById(R.id.search_input);
|
||||
RecyclerView songList = dialogView.findViewById(R.id.song_list);
|
||||
songList.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
|
||||
// 初始化适配器
|
||||
List<Song> filteredList = new ArrayList<>(songs.values());
|
||||
SongAdapter adapter = new SongAdapter(filteredList);
|
||||
songList.setAdapter(adapter);
|
||||
|
||||
// 搜索框监听
|
||||
searchInput.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
String query = s.toString().trim().toLowerCase();
|
||||
filteredList.clear();
|
||||
for (Song song : songs.values()) {
|
||||
if (song.getTitle().toLowerCase().contains(query) ||
|
||||
String.valueOf(song.getId()).contains(query) ||
|
||||
song.getArtist().toLowerCase().contains(query) ||
|
||||
song.getGenre().toLowerCase().contains(query)) {
|
||||
filteredList.add(song);
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
});
|
||||
|
||||
// 列表项点击事件
|
||||
adapter.setOnItemClickListener(song -> {
|
||||
showSongDetailDialog(song);
|
||||
});
|
||||
|
||||
builder.setPositiveButton("关闭", (dialog, which) -> dialog.dismiss());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void showSongDetailDialog(Song song) {
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext(), R.style.CustomDialogStyle);
|
||||
View dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_song_detail, null);
|
||||
builder.setView(dialogView);
|
||||
|
||||
// 设置歌曲详情
|
||||
TextView songTitle = dialogView.findViewById(R.id.song_title);
|
||||
TextView songArtist = dialogView.findViewById(R.id.song_artist);
|
||||
songTitle.setText(song.getTitle());
|
||||
songArtist.setText(song.getArtist());
|
||||
|
||||
// 初始化表格
|
||||
TableLayout tableLayout = dialogView.findViewById(R.id.song_table);
|
||||
for (int i = 0; i < 4; i++) { // 4 行
|
||||
TableRow row = new TableRow(requireContext());
|
||||
for (int j = 0; j < 5; j++) { // 5 列
|
||||
TextView cell = new TextView(requireContext());
|
||||
cell.setText("数据 " + (i * 5 + j + 1)); // 示例数据
|
||||
cell.setPadding(8, 8, 8, 8);
|
||||
row.addView(cell);
|
||||
}
|
||||
tableLayout.addView(row);
|
||||
}
|
||||
|
||||
// 设置额外的 TextView
|
||||
TextView extraInfo = dialogView.findViewById(R.id.extra_info);
|
||||
extraInfo.setText("额外信息:这里可以显示更多内容");
|
||||
|
||||
// 设置按钮点击事件
|
||||
MaterialButton addToPlanButton = dialogView.findViewById(R.id.add_to_plan_button);
|
||||
addToPlanButton.setOnClickListener(v -> {
|
||||
// 将歌曲添加到计划中
|
||||
addToPlan(song);
|
||||
Toast.makeText(requireContext(), "已添加到计划", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
builder.setPositiveButton("关闭", (dialog, which) -> dialog.dismiss());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void addToPlan(Song song) {
|
||||
// 实现将歌曲添加到计划的逻辑
|
||||
}
|
||||
|
||||
private void sortMusicRatingsByRating() {
|
||||
@@ -559,6 +655,9 @@ public class MusicFragment extends Fragment {
|
||||
MusicRating m = b100.get(x);
|
||||
int nowache = m.getAchievement();
|
||||
int target = 0;
|
||||
if (nowache>=1005000) {
|
||||
continue;
|
||||
}
|
||||
if (nowache >= 1000000 && nowache < 1005000) {
|
||||
target = 1005001;
|
||||
} else if (nowache >= 995000 && nowache < 1000000) {
|
||||
@@ -590,6 +689,9 @@ public class MusicFragment extends Fragment {
|
||||
}
|
||||
int nowache = m.getAchievement();
|
||||
int target = 0;
|
||||
if (nowache>=1005000) {
|
||||
continue;
|
||||
}
|
||||
if (nowache >= 1000000 && nowache < 1005000) {
|
||||
target = 1005001;
|
||||
} else if (nowache >= 995000 && nowache < 1000000) {
|
||||
|
||||
52
app/src/main/res/layout/dialog_song_detail.xml
Normal file
52
app/src/main/res/layout/dialog_song_detail.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- 歌曲标题和作者 -->
|
||||
<TextView
|
||||
android:id="@+id/song_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="歌曲标题"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_artist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="歌曲作者"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginBottom="16dp" />
|
||||
|
||||
<!-- 表格 -->
|
||||
<TableLayout
|
||||
android:id="@+id/song_table"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="*" />
|
||||
|
||||
<!-- 额外信息 -->
|
||||
<TextView
|
||||
android:id="@+id/extra_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="额外信息"
|
||||
android:layout_marginTop="16dp" />
|
||||
|
||||
<!-- 添加到计划按钮 -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/add_to_plan_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="添加到计划"
|
||||
android:layout_marginTop="16dp" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
28
app/src/main/res/layout/item_song.xml
Normal file
28
app/src/main/res/layout/item_song.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Song Title"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_artist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Artist Name"
|
||||
android:textSize="14sp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="#757575" />
|
||||
|
||||
</LinearLayout>
|
||||
31
app/src/main/res/layout/item_song_search_result.xml
Normal file
31
app/src/main/res/layout/item_song_search_result.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<!-- res/layout/item_song_search_result.xml -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/colorOnSurfaceVariant" />
|
||||
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
25
app/src/main/res/layout/rating_project_dialog.xml
Normal file
25
app/src/main/res/layout/rating_project_dialog.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!-- res/layout/dialog_rating_project.xml -->
|
||||
<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">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="搜索歌曲(支持 ID, 歌曲名, 作者, 难度)">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/search_input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/song_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp" />
|
||||
|
||||
</LinearLayout>
|
||||
39
app/src/main/res/layout/song_detail_dialog.xml
Normal file
39
app/src/main/res/layout/song_detail_dialog.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<!-- res/layout/dialog_song_detail.xml -->
|
||||
<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">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_id"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_author"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_genre"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/song_level"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user