commit e7a053d35d32871d60e8ae260913be5ceae7eba8 Author: Levi Date: Fri Dec 20 22:11:35 2024 +0800 Android代码12月20日提交 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..4dcf4fb --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,66 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.coursedesign" + compileSdk = 34 + + defaultConfig { + applicationId = "com.example.coursedesign" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) + + implementation ("de.hdodenhof:circleimageview:3.1.0") + + // 基础依赖包,必须要依赖 + implementation ("com.geyifeng.immersionbar:immersionbar:3.2.2") + // kotlin扩展(可选) + implementation ("com.geyifeng.immersionbar:immersionbar-ktx:3.2.2") + // fragment快速实现(可选)已废弃 + implementation ("com.geyifeng.immersionbar:immersionbar-components:3.2.2") + + implementation ("com.github.bumptech.glide:glide:4.15.1") + implementation ("io.github.youth5201314:banner:2.2.3") + implementation ("com.github.bumptech.glide:glide:4.15.1") + implementation ("com.geyifeng.immersionbar:immersionbar:3.2.2") + implementation ("com.geyifeng.immersionbar:immersionbar-components:3.2.2") + implementation ("io.github.scwang90:refresh-layout-kernel:2.1.0") //核心必须依赖 + implementation ("io.github.scwang90:refresh-header-classics:2.1.0") //经典刷新头 + implementation ("io.github.scwang90:refresh-header-radar:2.1.0") //雷达刷新头 + implementation ("io.github.scwang90:refresh-header-falsify:2.1.0") //虚拟刷新头 + implementation ("io.github.scwang90:refresh-header-material:2.1.0") //谷歌刷新头 + implementation ("io.github.scwang90:refresh-header-two-level:2.1.0") //二级刷新头 + implementation ("io.github.scwang90:refresh-footer-ball:2.1.0") //球脉冲加载 + implementation ("io.github.scwang90:refresh-footer-classics:2.1.0") +} \ No newline at end of file diff --git a/proguard-rules.pro b/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/src/androidTest/java/com/example/coursedesign/ExampleInstrumentedTest.java b/src/androidTest/java/com/example/coursedesign/ExampleInstrumentedTest.java new file mode 100644 index 0000000..72b2af8 --- /dev/null +++ b/src/androidTest/java/com/example/coursedesign/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.coursedesign; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.coursedesign", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml new file mode 100644 index 0000000..923a511 --- /dev/null +++ b/src/main/AndroidManifest.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/AddCommodityActivity.java b/src/main/java/com/example/coursedesign/AddCommodityActivity.java new file mode 100644 index 0000000..cfdb8b9 --- /dev/null +++ b/src/main/java/com/example/coursedesign/AddCommodityActivity.java @@ -0,0 +1,24 @@ +package com.example.coursedesign; + +import android.os.Bundle; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class AddCommodityActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_add_commodity); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/CommodityActivity.java b/src/main/java/com/example/coursedesign/CommodityActivity.java new file mode 100644 index 0000000..9bd631d --- /dev/null +++ b/src/main/java/com/example/coursedesign/CommodityActivity.java @@ -0,0 +1,74 @@ +package com.example.coursedesign; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.Glide; + +public class CommodityActivity extends AppCompatActivity { + + MyAdapter myAdapter; + RecyclerView recyclerView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_commodity); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + recyclerView = findViewById(R.id.recyclerView3); + myAdapter = new MyAdapter(); + recyclerView.setAdapter(myAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(CommodityActivity.this)); + } + + public class MyAdapter extends RecyclerView.Adapter { + + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(CommodityActivity.this).inflate(R.layout.comment_item_layout, parent, false); + MyViewHolder myViewHolder = new MyViewHolder(view); + return myViewHolder; + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 4; + } + } + + public class MyViewHolder extends RecyclerView.ViewHolder { + + public MyViewHolder(@NonNull View itemView) { + super(itemView); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/FavoriteFragment.java b/src/main/java/com/example/coursedesign/FavoriteFragment.java new file mode 100644 index 0000000..53bbb59 --- /dev/null +++ b/src/main/java/com/example/coursedesign/FavoriteFragment.java @@ -0,0 +1,70 @@ +package com.example.coursedesign; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; + +public class FavoriteFragment extends Fragment { + + MyAdapter myAdapter; + RecyclerView recyclerView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_favorite, container, false); + + recyclerView = view.findViewById(R.id.recycleView2); + myAdapter = new MyAdapter(); + recyclerView.setAdapter(myAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); + + return view; + } + + public class MyAdapter extends RecyclerView.Adapter { + + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.commodity_item_layout, parent, false); + MyViewHolder myViewHolder = new MyViewHolder(view); + return myViewHolder; + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 4; + } + } + + public class MyViewHolder extends RecyclerView.ViewHolder { + + + public MyViewHolder(@NonNull View itemView) { + super(itemView); + + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/HomeActivity.java b/src/main/java/com/example/coursedesign/HomeActivity.java new file mode 100644 index 0000000..062c380 --- /dev/null +++ b/src/main/java/com/example/coursedesign/HomeActivity.java @@ -0,0 +1,119 @@ +package com.example.coursedesign; + +import android.content.Intent; +import android.os.Bundle; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class HomeActivity extends AppCompatActivity { + + HomeFragment homeFragment; + FavoriteFragment favoriteFragment; + MessageFragment messageFragment; + MineFragment mineFragment; + ConstraintLayout home; + ConstraintLayout favorite; + ConstraintLayout add; + ConstraintLayout message; + ConstraintLayout mine; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_home); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + homeFragment = new HomeFragment(); + favoriteFragment = new FavoriteFragment(); + messageFragment = new MessageFragment(); + mineFragment = new MineFragment(); + + getSupportFragmentManager().beginTransaction().add(R.id.fragment, homeFragment).commit(); + getSupportFragmentManager().beginTransaction().add(R.id.fragment, favoriteFragment).commit(); + getSupportFragmentManager().beginTransaction().add(R.id.fragment, messageFragment).commit(); + getSupportFragmentManager().beginTransaction().add(R.id.fragment, mineFragment).commit(); + getSupportFragmentManager().beginTransaction() + .show(homeFragment) + .hide(favoriteFragment) + .hide(messageFragment) + .hide(mineFragment) + .commit(); + + home = findViewById(R.id.constraintLayout2); + favorite = findViewById(R.id.commodityLayout); + add = findViewById(R.id.constraintLayout3); + message = findViewById(R.id.constraintLayout4); + mine = findViewById(R.id.constraintLayout5); + + home.setSelected(true); + favorite.setSelected(false); + message.setSelected(false); + mine.setSelected(false); + + home.setOnClickListener(v -> { + home.setSelected(true); + favorite.setSelected(false); + message.setSelected(false); + mine.setSelected(false); + getSupportFragmentManager().beginTransaction() + .show(homeFragment) + .hide(favoriteFragment) + .hide(messageFragment) + .hide(mineFragment) + .commit(); + }); + + favorite.setOnClickListener(v -> { + home.setSelected(false); + favorite.setSelected(true); + message.setSelected(false); + mine.setSelected(false); + getSupportFragmentManager().beginTransaction() + .show(favoriteFragment) + .hide(homeFragment) + .hide(messageFragment) + .hide(mineFragment) + .commit(); + }); + + message.setOnClickListener(v -> { + home.setSelected(false); + favorite.setSelected(false); + message.setSelected(true); + mine.setSelected(false); + getSupportFragmentManager().beginTransaction() + .show(messageFragment) + .hide(homeFragment) + .hide(favoriteFragment) + .hide(mineFragment) + .commit(); + }); + + mine.setOnClickListener(v -> { + home.setSelected(false); + favorite.setSelected(false); + message.setSelected(false); + mine.setSelected(true); + getSupportFragmentManager().beginTransaction() + .show(mineFragment) + .hide(homeFragment) + .hide(favoriteFragment) + .hide(messageFragment) + .commit(); + }); + + add.setOnClickListener(v -> { + startActivity(new Intent(HomeActivity.this, AddCommodityActivity.class)); + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/HomeFragment.java b/src/main/java/com/example/coursedesign/HomeFragment.java new file mode 100644 index 0000000..d8369cb --- /dev/null +++ b/src/main/java/com/example/coursedesign/HomeFragment.java @@ -0,0 +1,73 @@ +package com.example.coursedesign; + +import android.content.Intent; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public class HomeFragment extends Fragment { + + MyAdapter myAdapter; + RecyclerView recyclerView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_home, container, false); + + recyclerView = view.findViewById(R.id.recycleView); + myAdapter = new MyAdapter(); + recyclerView.setAdapter(myAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); + + return view; + } + + public class MyAdapter extends RecyclerView.Adapter { + + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.commodity_item_layout, parent, false); + MyViewHolder myViewHolder = new MyViewHolder(view); + return myViewHolder; + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + + holder.constraintLayout.setOnClickListener(new View.OnClickListener(){ + + @Override + public void onClick(View v) { + Intent intent = new Intent(getActivity(), CommodityActivity.class); + startActivity(intent); + } + }); + } + + @Override + public int getItemCount() { + return 10; + } + } + + public class MyViewHolder extends RecyclerView.ViewHolder { + + ConstraintLayout constraintLayout; + + public MyViewHolder(@NonNull View itemView) { + super(itemView); + constraintLayout = itemView.findViewById(R.id.commodityLayout); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/LoginActivity.java b/src/main/java/com/example/coursedesign/LoginActivity.java new file mode 100644 index 0000000..280559e --- /dev/null +++ b/src/main/java/com/example/coursedesign/LoginActivity.java @@ -0,0 +1,45 @@ +package com.example.coursedesign; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.Button; +import android.widget.EditText; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class LoginActivity extends AppCompatActivity { + + EditText phone, password; + Button login, register; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_login); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + phone = findViewById(R.id.editTextPhone); + password = findViewById(R.id.editTextTextPassword); + login = findViewById(R.id.button2); + register = findViewById(R.id.button); + + //登录按钮监听 + login.setOnClickListener(v -> { + startActivity(new Intent(LoginActivity.this, HomeActivity.class)); + }); + + //注册按钮监听 + register.setOnClickListener(v -> { + startActivity(new Intent(LoginActivity.this, RegistrationActivity.class)); + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/MainActivity.java b/src/main/java/com/example/coursedesign/MainActivity.java new file mode 100644 index 0000000..41bb5e9 --- /dev/null +++ b/src/main/java/com/example/coursedesign/MainActivity.java @@ -0,0 +1,48 @@ +package com.example.coursedesign; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(2000); + //判断用户是否登录 + SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE); + boolean isLogin = sharedPreferences.getBoolean("isLogin",false); + if(isLogin){ + Intent intent = new Intent(MainActivity.this, HomeActivity.class); + startActivity(intent); + }else{ + Intent intent = new Intent(MainActivity.this, LoginActivity.class); + startActivity(intent); + } + finish(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + }); + thread.start(); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/MessageFragment.java b/src/main/java/com/example/coursedesign/MessageFragment.java new file mode 100644 index 0000000..0dc1072 --- /dev/null +++ b/src/main/java/com/example/coursedesign/MessageFragment.java @@ -0,0 +1,65 @@ +package com.example.coursedesign; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link MessageFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class MessageFragment extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public MessageFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment MessageFragment. + */ + // TODO: Rename and change types and number of parameters + public static MessageFragment newInstance(String param1, String param2) { + MessageFragment fragment = new MessageFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_message, container, false); + return view; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/MineFragment.java b/src/main/java/com/example/coursedesign/MineFragment.java new file mode 100644 index 0000000..b31776c --- /dev/null +++ b/src/main/java/com/example/coursedesign/MineFragment.java @@ -0,0 +1,29 @@ +package com.example.coursedesign; + +import android.content.Intent; +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +public class MineFragment extends Fragment { + + Button button; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_mine, container, false); + + button = view.findViewById(R.id.button7); + button.setOnClickListener(v -> { + startActivity(new Intent(getActivity(), MyReleaseActivity.class)); + }); + return view; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/MyReleaseActivity.java b/src/main/java/com/example/coursedesign/MyReleaseActivity.java new file mode 100644 index 0000000..be65e77 --- /dev/null +++ b/src/main/java/com/example/coursedesign/MyReleaseActivity.java @@ -0,0 +1,67 @@ +package com.example.coursedesign; + +import android.os.Bundle; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class MyReleaseActivity extends AppCompatActivity { + + OnSaleFragment onSaleFragment; + NotOnSaleFragment notOnSaleFragment; + TextView onSaleTV, notOnSaleTV, backTV; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_my_release); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + backTV = findViewById(R.id.textView26); + onSaleTV = findViewById(R.id.textView27); + notOnSaleTV = findViewById(R.id.textView28); + + onSaleTV.setSelected(true); + notOnSaleTV.setSelected(false); + + onSaleFragment = new OnSaleFragment(); + notOnSaleFragment = new NotOnSaleFragment(); + + getSupportFragmentManager().beginTransaction() + .add(R.id.fragment2, onSaleFragment) + .add(R.id.fragment2, notOnSaleFragment) + .hide(notOnSaleFragment) + .commit(); + + onSaleTV.setOnClickListener(v -> { + onSaleTV.setSelected(true); + notOnSaleTV.setSelected(false); + getSupportFragmentManager().beginTransaction() + .show(onSaleFragment) + .hide(notOnSaleFragment) + .commit(); + }); + + notOnSaleTV.setOnClickListener(v -> { + onSaleTV.setSelected(false); + notOnSaleTV.setSelected(true); + getSupportFragmentManager().beginTransaction() + .show(notOnSaleFragment) + .hide(onSaleFragment) + .commit(); + }); + + backTV.setOnClickListener(v -> { + finish(); + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/NotOnSaleFragment.java b/src/main/java/com/example/coursedesign/NotOnSaleFragment.java new file mode 100644 index 0000000..4469078 --- /dev/null +++ b/src/main/java/com/example/coursedesign/NotOnSaleFragment.java @@ -0,0 +1,61 @@ +package com.example.coursedesign; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public class NotOnSaleFragment extends Fragment { + + MyAdapter myAdapter; + RecyclerView recyclerView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_not_on_sale, container, false); + recyclerView = view.findViewById(R.id.recycleView4); + myAdapter = new MyAdapter(); + recyclerView.setAdapter(myAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); + return view; + } + + public class MyAdapter extends RecyclerView.Adapter { + + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.release_item_layout, parent, false); + MyViewHolder myViewHolder = new MyViewHolder(view); + return myViewHolder; + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 4; + } + } + + public class MyViewHolder extends RecyclerView.ViewHolder { + ConstraintLayout constraintLayout; + + public MyViewHolder(@NonNull View itemView) { + super(itemView); + + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/OnSaleFragment.java b/src/main/java/com/example/coursedesign/OnSaleFragment.java new file mode 100644 index 0000000..c08eadc --- /dev/null +++ b/src/main/java/com/example/coursedesign/OnSaleFragment.java @@ -0,0 +1,68 @@ +package com.example.coursedesign; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; + +public class OnSaleFragment extends Fragment { + + MyAdapter myAdapter; + RecyclerView recyclerView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_on_sale, container, false); + recyclerView = view.findViewById(R.id.recycleView3); + myAdapter = new MyAdapter(); + recyclerView.setAdapter(myAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); + return view; + } + + public class MyAdapter extends RecyclerView.Adapter { + + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.release_item_layout, parent, false); + MyViewHolder myViewHolder = new MyViewHolder(view); + return myViewHolder; + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 3; + } + } + + public class MyViewHolder extends RecyclerView.ViewHolder { + ConstraintLayout constraintLayout; + + public MyViewHolder(@NonNull View itemView) { + super(itemView); + + } + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/RegistrationActivity.java b/src/main/java/com/example/coursedesign/RegistrationActivity.java new file mode 100644 index 0000000..0ff3d24 --- /dev/null +++ b/src/main/java/com/example/coursedesign/RegistrationActivity.java @@ -0,0 +1,39 @@ +package com.example.coursedesign; + +import android.os.Bundle; +import android.widget.Button; +import android.widget.EditText; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class RegistrationActivity extends AppCompatActivity { + + EditText username,phone,password; + Button register; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_registration); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + username = findViewById(R.id.editTextText); + phone = findViewById(R.id.editTextPhone); + password = findViewById(R.id.editTextTextPassword); + register = findViewById(R.id.button3); + + // 注册按钮监听 + register.setOnClickListener(v -> { + + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/coursedesign/SoldOutFragment.java b/src/main/java/com/example/coursedesign/SoldOutFragment.java new file mode 100644 index 0000000..f7e539f --- /dev/null +++ b/src/main/java/com/example/coursedesign/SoldOutFragment.java @@ -0,0 +1,61 @@ +package com.example.coursedesign; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public class SoldOutFragment extends Fragment { + + MyAdapter myAdapter; + RecyclerView recyclerView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_sold_out, container, false); + recyclerView = view.findViewById(R.id.recycleView4); + myAdapter = new MyAdapter(); + recyclerView.setAdapter(myAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); + return view; + } + + public class MyAdapter extends RecyclerView.Adapter { + + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.release_item_layout, parent, false); + MyViewHolder myViewHolder = new MyViewHolder(view); + return myViewHolder; + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 6; + } + } + + public class MyViewHolder extends RecyclerView.ViewHolder { + ConstraintLayout constraintLayout; + + public MyViewHolder(@NonNull View itemView) { + super(itemView); + + } + } +} \ No newline at end of file diff --git a/src/main/res/color/color.xml b/src/main/res/color/color.xml new file mode 100644 index 0000000..cc0defa --- /dev/null +++ b/src/main/res/color/color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/color/color2.xml b/src/main/res/color/color2.xml new file mode 100644 index 0000000..bc88452 --- /dev/null +++ b/src/main/res/color/color2.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/add.png b/src/main/res/drawable/add.png new file mode 100644 index 0000000..206f0d9 Binary files /dev/null and b/src/main/res/drawable/add.png differ diff --git a/src/main/res/drawable/avatar.jpg b/src/main/res/drawable/avatar.jpg new file mode 100644 index 0000000..ba2f84a Binary files /dev/null and b/src/main/res/drawable/avatar.jpg differ diff --git a/src/main/res/drawable/background.jpg b/src/main/res/drawable/background.jpg new file mode 100644 index 0000000..b1a8894 Binary files /dev/null and b/src/main/res/drawable/background.jpg differ diff --git a/src/main/res/drawable/favorite.xml b/src/main/res/drawable/favorite.xml new file mode 100644 index 0000000..2f40fa7 --- /dev/null +++ b/src/main/res/drawable/favorite.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/favorite_select.png b/src/main/res/drawable/favorite_select.png new file mode 100644 index 0000000..cb27289 Binary files /dev/null and b/src/main/res/drawable/favorite_select.png differ diff --git a/src/main/res/drawable/favorite_shape.xml b/src/main/res/drawable/favorite_shape.xml new file mode 100644 index 0000000..e841c92 --- /dev/null +++ b/src/main/res/drawable/favorite_shape.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/favorite_shape_select.png b/src/main/res/drawable/favorite_shape_select.png new file mode 100644 index 0000000..a5062ff Binary files /dev/null and b/src/main/res/drawable/favorite_shape_select.png differ diff --git a/src/main/res/drawable/favorite_shape_unselect.png b/src/main/res/drawable/favorite_shape_unselect.png new file mode 100644 index 0000000..501830d Binary files /dev/null and b/src/main/res/drawable/favorite_shape_unselect.png differ diff --git a/src/main/res/drawable/favorite_unselect.png b/src/main/res/drawable/favorite_unselect.png new file mode 100644 index 0000000..d41cac6 Binary files /dev/null and b/src/main/res/drawable/favorite_unselect.png differ diff --git a/src/main/res/drawable/home.xml b/src/main/res/drawable/home.xml new file mode 100644 index 0000000..2304b66 --- /dev/null +++ b/src/main/res/drawable/home.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/home_select.png b/src/main/res/drawable/home_select.png new file mode 100644 index 0000000..79a5f94 Binary files /dev/null and b/src/main/res/drawable/home_select.png differ diff --git a/src/main/res/drawable/home_unselect.png b/src/main/res/drawable/home_unselect.png new file mode 100644 index 0000000..a0402fc Binary files /dev/null and b/src/main/res/drawable/home_unselect.png differ diff --git a/src/main/res/drawable/ic_launcher_background.xml b/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/res/drawable/ic_launcher_foreground.xml b/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/message.xml b/src/main/res/drawable/message.xml new file mode 100644 index 0000000..e60b786 --- /dev/null +++ b/src/main/res/drawable/message.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/message_select.png b/src/main/res/drawable/message_select.png new file mode 100644 index 0000000..696ba0a Binary files /dev/null and b/src/main/res/drawable/message_select.png differ diff --git a/src/main/res/drawable/message_unselect.png b/src/main/res/drawable/message_unselect.png new file mode 100644 index 0000000..68a34d8 Binary files /dev/null and b/src/main/res/drawable/message_unselect.png differ diff --git a/src/main/res/drawable/mine.xml b/src/main/res/drawable/mine.xml new file mode 100644 index 0000000..3f45fc4 --- /dev/null +++ b/src/main/res/drawable/mine.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/mine_select.png b/src/main/res/drawable/mine_select.png new file mode 100644 index 0000000..948d5eb Binary files /dev/null and b/src/main/res/drawable/mine_select.png differ diff --git a/src/main/res/drawable/mine_unselect.png b/src/main/res/drawable/mine_unselect.png new file mode 100644 index 0000000..fa640b8 Binary files /dev/null and b/src/main/res/drawable/mine_unselect.png differ diff --git a/src/main/res/drawable/shape.xml b/src/main/res/drawable/shape.xml new file mode 100644 index 0000000..4387bd0 --- /dev/null +++ b/src/main/res/drawable/shape.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/shape2.xml b/src/main/res/drawable/shape2.xml new file mode 100644 index 0000000..89e5ae0 --- /dev/null +++ b/src/main/res/drawable/shape2.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/activity_add_commodity.xml b/src/main/res/layout/activity_add_commodity.xml new file mode 100644 index 0000000..c7f7dbf --- /dev/null +++ b/src/main/res/layout/activity_add_commodity.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + +