From 02f5642536564bb531e0eaf7dd0a2bbed8729cf9 Mon Sep 17 00:00:00 2001 From: lihongwei Date: Sat, 12 Oct 2024 11:02:47 +0800 Subject: [PATCH] =?UTF-8?q?V1.0.2(10)=20=E6=B7=BB=E5=8A=A0=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E8=B5=84=E6=BA=90=E9=A1=B5=20MainActivity2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .safedk/hashes.safedk | 4 +- .safedk/plugin.properties | 2 +- app/build.gradle.kts | 2 +- app/src/main/AndroidManifest.xml | 5 +- .../prankparty/Activity/MainActivity2.java | 36 ++++++++++ .../Adapter/Main2RecyclerViewAdapter.java | 70 +++++++++++++++++++ .../SubSoundItemRecyclerViewAdapter.java | 69 ++++++++++++++++++ app/src/main/res/layout/activity_main2.xml | 16 +++++ app/src/main/res/layout/item_main2.xml | 20 ++++++ app/src/main/res/layout/item_sub_sound.xml | 25 +++++++ 10 files changed, 244 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/sound/prankparty/Activity/MainActivity2.java create mode 100644 app/src/main/java/com/sound/prankparty/Adapter/Main2RecyclerViewAdapter.java create mode 100644 app/src/main/java/com/sound/prankparty/Adapter/SubSoundItemRecyclerViewAdapter.java create mode 100644 app/src/main/res/layout/activity_main2.xml create mode 100644 app/src/main/res/layout/item_main2.xml create mode 100644 app/src/main/res/layout/item_sub_sound.xml diff --git a/.safedk/hashes.safedk b/.safedk/hashes.safedk index 474f598..ad440ef 100644 --- a/.safedk/hashes.safedk +++ b/.safedk/hashes.safedk @@ -1,2 +1,2 @@ -#Tue Oct 08 14:40:01 CST 2024 -json=-2012395295 +#Sat Oct 12 11:00:37 CST 2024 +json=-780482554 diff --git a/.safedk/plugin.properties b/.safedk/plugin.properties index 7a0dbc0..d6f9cd4 100644 --- a/.safedk/plugin.properties +++ b/.safedk/plugin.properties @@ -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 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a58d6df..ceb6cb8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 201cf2f..c7fd32e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,6 +23,9 @@ android:supportsRtl="true" android:theme="@style/Theme.PrankPartyDemo" tools:targetApi="31"> + @@ -42,7 +45,7 @@ android:name=".Activity.MainActivity" android:exported="false" /> diff --git a/app/src/main/java/com/sound/prankparty/Activity/MainActivity2.java b/app/src/main/java/com/sound/prankparty/Activity/MainActivity2.java new file mode 100644 index 0000000..358172e --- /dev/null +++ b/app/src/main/java/com/sound/prankparty/Activity/MainActivity2.java @@ -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 categories = JsonParser.parseJson(jsonString); + + binding.mainRecycler.setLayoutManager(new GridLayoutManager(this, 1)); + binding.mainRecycler.setAdapter(new Main2RecyclerViewAdapter(this, categories)); + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sound/prankparty/Adapter/Main2RecyclerViewAdapter.java b/app/src/main/java/com/sound/prankparty/Adapter/Main2RecyclerViewAdapter.java new file mode 100644 index 0000000..22dde8c --- /dev/null +++ b/app/src/main/java/com/sound/prankparty/Adapter/Main2RecyclerViewAdapter.java @@ -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 { + + private Context context; + private List categoryList; + + public Main2RecyclerViewAdapter(Context context, List 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 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)); + } + } +} diff --git a/app/src/main/java/com/sound/prankparty/Adapter/SubSoundItemRecyclerViewAdapter.java b/app/src/main/java/com/sound/prankparty/Adapter/SubSoundItemRecyclerViewAdapter.java new file mode 100644 index 0000000..a1f4f0b --- /dev/null +++ b/app/src/main/java/com/sound/prankparty/Adapter/SubSoundItemRecyclerViewAdapter.java @@ -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 { + + private Context context; + private List soundItemList; + private String categoryName; // 传递CategoryName + + public SubSoundItemRecyclerViewAdapter(Context context, List 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); + } + } +} diff --git a/app/src/main/res/layout/activity_main2.xml b/app/src/main/res/layout/activity_main2.xml new file mode 100644 index 0000000..e5d9046 --- /dev/null +++ b/app/src/main/res/layout/activity_main2.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_main2.xml b/app/src/main/res/layout/item_main2.xml new file mode 100644 index 0000000..729f036 --- /dev/null +++ b/app/src/main/res/layout/item_main2.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/app/src/main/res/layout/item_sub_sound.xml b/app/src/main/res/layout/item_sub_sound.xml new file mode 100644 index 0000000..913ee5d --- /dev/null +++ b/app/src/main/res/layout/item_sub_sound.xml @@ -0,0 +1,25 @@ + + + + + + + +