V1.0.2(10) 添加展示资源页 MainActivity2
This commit is contained in:
parent
f1fab3c303
commit
02f5642536
@ -1,2 +1,2 @@
|
||||
#Tue Oct 08 14:40:01 CST 2024
|
||||
json=-2012395295
|
||||
#Sat Oct 12 11:00:37 CST 2024
|
||||
json=-780482554
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#
|
||||
#Tue Oct 08 14:40:01 CST 2024
|
||||
#Sat Oct 12 11:00:37 CST 2024
|
||||
sdk_analysis_plugin_version=5.5.0
|
||||
set_multidex=true
|
||||
y87o4e7vb5bbqzuGVTFyOIfZiyBG0Nf0Ksq8S3m2MJOHf_A5BcWGJnKuQqoxwxVvtdQdiTC4O3MPzFwy8rJ9Cc=3cUMfTcsZKzlJevxK4IkNysgDAeQA4B5w332p3g8B9ZAgC54WQNZLVxuxnCx4sCHA5StLJnDTAFa68mFTi8rd8
|
||||
|
||||
@ -26,7 +26,7 @@ android {
|
||||
applicationId = "com.sound.prankparty"
|
||||
minSdk = 23
|
||||
targetSdk = 34
|
||||
versionCode = 9
|
||||
versionCode = 10
|
||||
versionName = "1.0.2"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@ -23,6 +23,9 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.PrankPartyDemo"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".Activity.MainActivity2"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".Activity.PrivacyActivity"
|
||||
android:exported="false" />
|
||||
@ -42,7 +45,7 @@
|
||||
android:name=".Activity.MainActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name="com.sound.prankparty.Activity.SplashActivity"
|
||||
android:name=".Activity.SplashActivity"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.StartUp">
|
||||
<intent-filter>
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
package com.sound.prankparty.Activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.sound.prankparty.Adapter.Main2RecyclerViewAdapter;
|
||||
import com.sound.prankparty.JSON.Category;
|
||||
import com.sound.prankparty.Utils.JsonParser;
|
||||
import com.sound.prankparty.Utils.LoadJSON;
|
||||
import com.sound.prankparty.databinding.ActivityMain2Binding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity2 extends AppCompatActivity {
|
||||
|
||||
private ActivityMain2Binding binding;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
binding = ActivityMain2Binding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
// 从 assets 文件夹中读取 JSON 文件
|
||||
String jsonString = LoadJSON.loadJSONFromAsset("prank.json");
|
||||
// 解析读取的 String
|
||||
List<Category> categories = JsonParser.parseJson(jsonString);
|
||||
|
||||
binding.mainRecycler.setLayoutManager(new GridLayoutManager(this, 1));
|
||||
binding.mainRecycler.setAdapter(new Main2RecyclerViewAdapter(this, categories));
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package com.sound.prankparty.Adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.sound.prankparty.JSON.Category;
|
||||
import com.sound.prankparty.JSON.SoundItem;
|
||||
import com.sound.prankparty.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main2RecyclerViewAdapter extends RecyclerView.Adapter<Main2RecyclerViewAdapter.Main2ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private List<Category> categoryList;
|
||||
|
||||
public Main2RecyclerViewAdapter(Context context, List<Category> categoryList) {
|
||||
this.context = context;
|
||||
this.categoryList = categoryList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Main2ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main2, parent, false);
|
||||
return new Main2ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Main2ViewHolder holder, int position) {
|
||||
// 获取当前的 Category
|
||||
Category category = categoryList.get(position);
|
||||
|
||||
// 设置Category相关的文字
|
||||
holder.categoryName.setText(category.getCategoryName());
|
||||
|
||||
// 设置SoundItem的RecyclerView
|
||||
List<SoundItem> soundItemList = category.getSoundItemList(); // 获取 Category 下的 SoundItem 列表
|
||||
SubSoundItemRecyclerViewAdapter soundItemAdapter = new SubSoundItemRecyclerViewAdapter(context, soundItemList, category.getCategoryName());
|
||||
holder.soundItemRecyclerView.setAdapter(soundItemAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return categoryList.size();
|
||||
}
|
||||
|
||||
static class Main2ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView categoryName;
|
||||
RecyclerView soundItemRecyclerView;
|
||||
|
||||
public Main2ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
categoryName = itemView.findViewById(R.id.item_textview_main2);
|
||||
soundItemRecyclerView = itemView.findViewById(R.id.sound_item_recyclerview);
|
||||
|
||||
// 初始化嵌套的RecyclerView
|
||||
soundItemRecyclerView.setLayoutManager(new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package com.sound.prankparty.Adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.sound.prankparty.JSON.SoundItem;
|
||||
import com.sound.prankparty.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SubSoundItemRecyclerViewAdapter extends RecyclerView.Adapter<SubSoundItemRecyclerViewAdapter.SoundItemViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private List<SoundItem> soundItemList;
|
||||
private String categoryName; // 传递CategoryName
|
||||
|
||||
public SubSoundItemRecyclerViewAdapter(Context context, List<SoundItem> soundItemList, String categoryName) {
|
||||
this.context = context;
|
||||
this.soundItemList = soundItemList;
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public SoundItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sub_sound, parent, false);
|
||||
return new SoundItemViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull SoundItemViewHolder holder, int position) {
|
||||
SoundItem soundItem = soundItemList.get(position);
|
||||
|
||||
// 设置SoundItem的图片和标题
|
||||
holder.soundTitle.setText(soundItem.getTitle());
|
||||
holder.categoryName.setText(categoryName); // 显示Category的名字
|
||||
|
||||
Glide.with(context)
|
||||
.load(soundItem.getPreUrl())
|
||||
.into(holder.imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return soundItemList.size();
|
||||
}
|
||||
|
||||
static class SoundItemViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView soundTitle;
|
||||
TextView categoryName;
|
||||
ImageView imageView;
|
||||
|
||||
public SoundItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
soundTitle = itemView.findViewById(R.id.sound_title);
|
||||
categoryName = itemView.findViewById(R.id.category_name);
|
||||
imageView = itemView.findViewById(R.id.sound_image);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
app/src/main/res/layout/activity_main2.xml
Normal file
16
app/src/main/res/layout/activity_main2.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".Activity.MainActivity2">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/main_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
20
app/src/main/res/layout/item_main2.xml
Normal file
20
app/src/main/res/layout/item_main2.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_textview_main2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textColor="#000"
|
||||
android:text="Category Name"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/sound_item_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"/>
|
||||
</LinearLayout>
|
||||
25
app/src/main/res/layout/item_sub_sound.xml
Normal file
25
app/src/main/res/layout/item_sub_sound.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/category_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#000"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/sound_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sound_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textColor="#000"/>
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue
Block a user