diff --git a/build.gradle.kts b/build.gradle.kts index ef8b7f5..3b8ff6c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,4 +38,13 @@ dependencies { androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") implementation ("io.github.youth5201314:banner:2.2.3") implementation ("com.github.bumptech.glide:glide:4.15.1") + implementation("com.squareup.okhttp3:okhttp:4.11.0") + 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/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index c99e477..b0a6641 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,11 +1,11 @@ - + + + diff --git a/src/main/java/com/hnucm/c202201020141/Chat.java b/src/main/java/com/hnucm/c202201020141/Chat.java new file mode 100644 index 0000000..4a3cb7b --- /dev/null +++ b/src/main/java/com/hnucm/c202201020141/Chat.java @@ -0,0 +1,8 @@ +package com.hnucm.c202201020141; + +public class Chat { + public String name; + public String content; + public String time; + public String imgurl; +} diff --git a/src/main/java/com/hnucm/c202201020141/HomeActivity2.java b/src/main/java/com/hnucm/c202201020141/HomeActivity2.java new file mode 100644 index 0000000..e30b905 --- /dev/null +++ b/src/main/java/com/hnucm/c202201020141/HomeActivity2.java @@ -0,0 +1,133 @@ +package com.hnucm.c202201020141; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.scwang.smart.refresh.footer.ClassicsFooter; +import com.scwang.smart.refresh.header.ClassicsHeader; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; + +import java.util.ArrayList; +import java.util.List; + +public class HomeActivity2 extends AppCompatActivity { + RecyclerView recyclerView; + SmartRefreshLayout smartRefreshLayout; + MyAdpater myAdpater; + List chatList=new ArrayList<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + for(int i=0;i<20;i++){ + Chat chat=new Chat(); + chat.name="姓名"+i; + chat.content="聊天内容"+i; + chat.time="聊天时间"+i; + chatList.add(chat); + } + + + recyclerView=findViewById(R.id.recyclerView); + smartRefreshLayout=findViewById(R.id.smartlayout); + //设置下拉上拉样式 + smartRefreshLayout.setRefreshHeader(new ClassicsHeader(this)); + smartRefreshLayout.setRefreshFooter(new ClassicsFooter(this)); + smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + //清除原来数据 + smartRefreshLayout.finishRefresh(); + chatList.clear(); + //构造一些数据 ->todo 网络请求得到 + for(int i=0;i<20;i++){ + Chat chat=new Chat(); + chat.name="姓名"+i; + chat.content="聊天内容"+i; + chat.time="聊天时间"+i; + chatList.add(chat); + } + smartRefreshLayout.finishRefresh(2000); + //更新列表页面数据 + myAdpater.notifyDataSetChanged(); + } + }); + smartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + //上拉加载 + for(int i=0;i<20;i++){ + Chat chat=new Chat(); + chat.name="姓名"+i; + chat.content="聊天内容"+i; + chat.time="聊天时间"+i; + chatList.add(chat); + } + smartRefreshLayout.finishLoadMore(2000); + //更新列表页面数据 + myAdpater.notifyDataSetChanged(); + } + }); + myAdpater=new MyAdpater(); + recyclerView.setAdapter(myAdpater); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + } + public class MyViewHolder extends RecyclerView.ViewHolder{ + TextView textView; + TextView textView2; + TextView textView3; + ConstraintLayout Layout; + public MyViewHolder(@NonNull View itemView){ + super((itemView)); + textView=itemView.findViewById(R.id.textView); + textView2=itemView.findViewById(R.id.textView2); + textView3=itemView.findViewById(R.id.textView3); + Layout=itemView.findViewById(R.id.Layout); + } + } + public class MyAdpater extends RecyclerView.Adapter{ + //加载布局文件 + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view= LayoutInflater.from(HomeActivity2.this).inflate(R.layout.chat_item_layout,parent,false); + return new MyViewHolder(view); + } + //修改item中控件的值 按需加载 + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + Chat chat=chatList.get(position); + holder.textView.setText(chatList.get(position).name); + holder.textView2.setText(chatList.get(position).content); + holder.textView3.setText(chatList.get(position).time); + holder.Layout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent=new Intent(HomeActivity2.this, ChatActivity.class); + intent.putExtra("name",chat.name); + startActivity(intent); + } + }); + + } + //显示item的条数 + @Override + public int getItemCount() { + return chatList.size(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020141/HomeFragment.java b/src/main/java/com/hnucm/c202201020141/HomeFragment.java index fe323a9..754d6e0 100644 --- a/src/main/java/com/hnucm/c202201020141/HomeFragment.java +++ b/src/main/java/com/hnucm/c202201020141/HomeFragment.java @@ -1,5 +1,7 @@ package com.hnucm.c202201020141; +import android.app.AlertDialog; +import android.content.Intent; import android.os.Bundle; import androidx.fragment.app.Fragment; @@ -7,59 +9,57 @@ import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.youth.banner.Banner; +import com.youth.banner.adapter.BannerImageAdapter; +import com.youth.banner.holder.BannerImageHolder; +import com.youth.banner.indicator.CircleIndicator; + +import java.util.ArrayList; +import java.util.List; + -/** - * A simple {@link Fragment} subclass. - * Use the {@link HomeFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class HomeFragment 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 HomeFragment() { - // 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 HomeFragment. - */ - // TODO: Rename and change types and number of parameters - public static HomeFragment newInstance(String param1, String param2) { - HomeFragment fragment = new HomeFragment(); - 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 - return inflater.inflate(R.layout.fragment_home, container, false); + View view= inflater.inflate(R.layout.fragment_home, container, false); + + Banner banner=view.findViewById(R.id.banner); + Listlist=new ArrayList<>(); + list.add("http://106.53.194.250:30089/i/2024/06/14/666bd10fa2310.png"); + list.add("https://img.youjidi.net/uploadimg/image/20200118/20200118093534_87353.jpg"); + list.add("https://img95.699pic.com/element/40138/8242.png_860.png"); + + banner.setAdapter(new BannerImageAdapter(list) { + @Override + public void onBindView(BannerImageHolder holder, String data, int position, int size) { + //Glide 网络地址 ->添加网络请求权限 + Glide.with(holder.itemView) + .load(data) + .into(holder.imageView); + } + }); + + banner.setIndicatorRadius(100); + TextView textView27=view.findViewById(R.id.textView27); + textView27.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent=new Intent(getActivity(),HomeActivity2.class); + startActivity(intent); + } + }); + + + return view; } + + } \ No newline at end of file diff --git a/src/main/res/drawable/_2024_06_14_150140.png b/src/main/res/drawable/_2024_06_14_150140.png new file mode 100644 index 0000000..1ad11db Binary files /dev/null and b/src/main/res/drawable/_2024_06_14_150140.png differ diff --git a/src/main/res/drawable/_2024_06_14_150147.png b/src/main/res/drawable/_2024_06_14_150147.png new file mode 100644 index 0000000..f759513 Binary files /dev/null and b/src/main/res/drawable/_2024_06_14_150147.png differ diff --git a/src/main/res/drawable/_2024_06_14_150153.png b/src/main/res/drawable/_2024_06_14_150153.png new file mode 100644 index 0000000..d04079c Binary files /dev/null and b/src/main/res/drawable/_2024_06_14_150153.png differ diff --git a/src/main/res/drawable/_2024_06_14_150343.png b/src/main/res/drawable/_2024_06_14_150343.png new file mode 100644 index 0000000..689c899 Binary files /dev/null and b/src/main/res/drawable/_2024_06_14_150343.png differ diff --git a/src/main/res/drawable/_2024_06_14_191105.png b/src/main/res/drawable/_2024_06_14_191105.png new file mode 100644 index 0000000..156092a Binary files /dev/null and b/src/main/res/drawable/_2024_06_14_191105.png differ diff --git a/src/main/res/drawable/_2024_06_14_191544.png b/src/main/res/drawable/_2024_06_14_191544.png new file mode 100644 index 0000000..477c001 Binary files /dev/null and b/src/main/res/drawable/_2024_06_14_191544.png differ diff --git a/src/main/res/drawable/_4__1_.png b/src/main/res/drawable/_4__1_.png new file mode 100644 index 0000000..9e11b90 Binary files /dev/null and b/src/main/res/drawable/_4__1_.png differ diff --git a/src/main/res/drawable/_7.png b/src/main/res/drawable/_7.png new file mode 100644 index 0000000..9cc9856 Binary files /dev/null and b/src/main/res/drawable/_7.png differ diff --git a/src/main/res/layout/activity_home2.xml b/src/main/res/layout/activity_home2.xml new file mode 100644 index 0000000..22b6516 --- /dev/null +++ b/src/main/res/layout/activity_home2.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/res/layout/activity_login.xml b/src/main/res/layout/activity_login.xml index 7cc907d..3c07ccb 100644 --- a/src/main/res/layout/activity_login.xml +++ b/src/main/res/layout/activity_login.xml @@ -217,8 +217,9 @@ android:id="@+id/textView16" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginBottom="44dp" android:text="通过注册,我同意Online.C的 服务条款和隐私政策" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - tools:layout_editor_absoluteY="671dp" /> + app:layout_constraintStart_toStartOf="parent" /> \ No newline at end of file diff --git a/src/main/res/layout/chat_item_layout.xml b/src/main/res/layout/chat_item_layout.xml new file mode 100644 index 0000000..38f9f96 --- /dev/null +++ b/src/main/res/layout/chat_item_layout.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/fragment_home.xml b/src/main/res/layout/fragment_home.xml index 7eb0b33..2ff58a9 100644 --- a/src/main/res/layout/fragment_home.xml +++ b/src/main/res/layout/fragment_home.xml @@ -1,14 +1,132 @@ - + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file