完善之前的网络请求,加入新接口,并加入banner组件,将登录的用户名传进用户页面,增加跳转

This commit is contained in:
tanc 2024-06-02 01:53:13 +08:00
parent 80662c9805
commit a7001f6d84
17 changed files with 196 additions and 92 deletions

View File

@ -21,7 +21,7 @@
android:name=".EnrollActivity"
android:exported="false" />
<activity
android:name=".welcome"
android:name=".MainActivity"
android:exported="false" />
<activity
android:name=".LoginMainActivity"
@ -42,7 +42,7 @@
android:name=".ViewStart"
android:exported="false" />
<activity
android:name=".MainActivity"
android:name=".welcome"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -6,6 +6,7 @@ import java.util.List;
public class Expert2 {
@SerializedName("code")
public Integer code;
@SerializedName("message")
@ -21,15 +22,8 @@ public class Expert2 {
@SerializedName("comment")
public String comment;
@SerializedName("number")
public NumberDTO number;
public String number;
@SerializedName("img")
public String img;
public static class NumberDTO {
@SerializedName("number1")
public Integer number1;
@SerializedName("number2")
public Integer number2;
}
}
}

View File

@ -86,6 +86,7 @@ public class LoginMainActivity extends AppCompatActivity {
while (cursor.moveToNext()) {
if (cursor != null && cursor.getString(cursor.getColumnIndex("password")).equals(userPassword)) {
Intent intent = new Intent(LoginMainActivity.this, MainActivity.class);
intent.putExtra("username", phoneNumber);
startActivity(intent);
finish();
flag = false;

View File

@ -1,5 +1,6 @@
package com.example.liyueling_final;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@ -18,6 +19,14 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String username = getIntent().getStringExtra("username");
Bundle bundle = new Bundle();
bundle.putString("username", username);
userFragment.setArguments(bundle);
studyFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction()
.add(R.id.constraintLayoutmainmajor,studyFragment)
.commit();

View File

@ -14,6 +14,10 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
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;
@ -29,7 +33,7 @@ public class MainexpertFragment extends Fragment {
MyAdpater myAdpater;
List<Expert1.DataDTO> expert1List = new ArrayList<>();
RecyclerView recyclerView2 ;
MyAdpater myAdpater2;
MyAdpater2 myAdpater2;
List<Expert2.DataDTO> expert2List = new ArrayList<>();
@Override
@ -37,6 +41,26 @@ public class MainexpertFragment extends Fragment {
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_mainexpert, container, false);
super.onCreate(savedInstanceState);
Banner banner = view.findViewById(R.id.banner);
List<String> list = new ArrayList<>();
list.add("https://img95.699pic.com/photo/50135/8179.jpg_wh300.jpg");
list.add("https://img.zcool.cn/community/010e885e01dc58a80120a8951d4d30.jpg@1280w_1l_2o_100sh.jpg");
list.add("https://img.zcool.cn/community/01bc575d39062ca80120695c4b71e6.jpg@2o.jpg");
list.add("https://img.zcool.cn/community/0176235d392960a80120695c2264b2.jpg@1280w_1l_2o_100sh.jpg");
banner.setAdapter(new BannerImageAdapter<String>(list) {
@Override
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
Glide.with(holder.itemView)
.load(data)
.into(holder.imageView);
}
});
banner.setIndicator(new CircleIndicator(getContext()));
banner.setIndicatorRadius(100);
Expert1Api expert1Api = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(Expert1Api.class);
Expert2Api expert2Api = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(Expert2Api.class);
for (int i = 1; i < 4; i++) {
@ -63,14 +87,14 @@ public class MainexpertFragment extends Fragment {
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
for (int i = 1; i < 4; i++) {
Call<Expert2> call = expert2Api.people2(i);
Call<Expert2> call2 = expert2Api.people2(i);
Log.i("123456", "onFailure: ");
call.enqueue(new Callback<Expert2>() {
call2.enqueue(new Callback<Expert2>() {
@Override
public void onResponse(Call<Expert2> call, Response<Expert2> response) {
Expert2 expert2 = response.body();
expert1List.addAll(expert2.data);
myAdpater.notifyDataSetChanged();
expert2List.addAll(expert2.data);
myAdpater2.notifyDataSetChanged();
}
@Override
@ -81,7 +105,7 @@ public class MainexpertFragment extends Fragment {
}
recyclerView2 = view.findViewById(R.id.recyclerview2);
myAdpater2 = new MyAdpater();
myAdpater2 = new MyAdpater2();
recyclerView2.setAdapter(myAdpater2);
recyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
@ -98,14 +122,16 @@ public class MainexpertFragment extends Fragment {
super(itemView);
textView = itemView.findViewById(R.id.name);
textView2 = itemView.findViewById(R.id.book);
textView3 = itemView.findViewById(R.id.introduce);
textView2 = itemView.findViewById(R.id.number);
textView3 = itemView.findViewById(R.id.comment);
textView4 = itemView.findViewById(R.id.number);
imageView = itemView.findViewById(R.id.imageView133);
}
}
public class MyAdpater extends RecyclerView.Adapter<MyviewHolder> {
//加载布局文件
@ -136,4 +162,48 @@ public class MainexpertFragment extends Fragment {
return expert1List.size();
}
}
public class MyViewHolder2 extends RecyclerView.ViewHolder {
TextView textView;
TextView textView2;
TextView textView3;
ImageView imageView;
// 其他控件声明
public MyViewHolder2(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.name);
textView2 = itemView.findViewById(R.id.comment);
textView3 = itemView.findViewById(R.id.number);
imageView = itemView.findViewById(R.id.imageView133);
}
}
public class MyAdpater2 extends RecyclerView.Adapter<MyViewHolder2> {
@NonNull
@Override
public MyViewHolder2 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.expert2_item_layout, parent, false);
return new MyViewHolder2(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder2 holder, int position) {
holder.textView.setText(expert2List.get(position).name);
holder.textView2.setText(expert2List.get(position).comment);
holder.textView3.setText(expert2List.get(position).number);
Glide.with(getActivity())
.load(getResources().getIdentifier(expert2List.get(position).img, "drawable", getContext().getPackageName()))
.into(holder.imageView);
}
@Override
public int getItemCount() {
return expert2List.size();
}
}
// 第二个 ViewHolder
}

View File

@ -7,13 +7,42 @@ import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
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;
public class MaingoodFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_maingood, container, false);
super.onCreate(savedInstanceState);
Banner banner = view.findViewById(R.id.banner);
List<String> list = new ArrayList<>();
list.add("https://img95.699pic.com/photo/50135/8179.jpg_wh300.jpg");
list.add("https://img.zcool.cn/community/010e885e01dc58a80120a8951d4d30.jpg@1280w_1l_2o_100sh.jpg");
list.add("https://img.zcool.cn/community/01bc575d39062ca80120695c4b71e6.jpg@2o.jpg");
list.add("https://img.zcool.cn/community/0176235d392960a80120695c2264b2.jpg@1280w_1l_2o_100sh.jpg");
banner.setAdapter(new BannerImageAdapter<String>(list) {
@Override
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
Glide.with(holder.itemView)
.load(data)
.into(holder.imageView);
}
});
banner.setIndicator(new CircleIndicator(getContext()));
banner.setIndicatorRadius(100);
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_maingood, container, false);
return view;
}
}

View File

@ -7,12 +7,41 @@ import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
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;
public class MainhomeFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_mainhome, container, false);
super.onCreate(savedInstanceState);
Banner banner = view.findViewById(R.id.banner);
List<String> list = new ArrayList<>();
list.add("https://img95.699pic.com/photo/50135/8179.jpg_wh300.jpg");
list.add("https://img.zcool.cn/community/010e885e01dc58a80120a8951d4d30.jpg@1280w_1l_2o_100sh.jpg");
list.add("https://img.zcool.cn/community/01bc575d39062ca80120695c4b71e6.jpg@2o.jpg");
list.add("https://img.zcool.cn/community/0176235d392960a80120695c2264b2.jpg@1280w_1l_2o_100sh.jpg");
banner.setAdapter(new BannerImageAdapter<String>(list) {
@Override
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
Glide.with(holder.itemView)
.load(data)
.into(holder.imageView);
}
});
banner.setIndicator(new CircleIndicator(getContext()));
banner.setIndicatorRadius(100);
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_mainhome, container, false);
return view;
}
}

View File

@ -5,19 +5,22 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
public class StudyFragment extends Fragment {
TextView textView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_study, container, false);
ConstraintLayout constraintLayout = view.findViewById(R.id.click);
String username = getArguments().getString("username");
textView = view.findViewById(R.id.username);
textView.setText(username);
constraintLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View File

@ -1,63 +1,25 @@
package com.example.liyueling_final;
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 androidx.fragment.app.Fragment;
/**
* A simple {@link Fragment} subclass.
* Use the {@link UserFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class UserFragment 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 UserFragment() {
// 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 UserFragment.
*/
// TODO: Rename and change types and number of parameters
public static UserFragment newInstance(String param1, String param2) {
UserFragment fragment = new UserFragment();
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);
}
}
TextView textView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_user, container, false);
View view = inflater.inflate(R.layout.fragment_user, container, false);
String username = getArguments().getString("username");
textView = view.findViewById(R.id.username);
textView.setText(username);
return view;
}
}

View File

@ -1,12 +1,14 @@
package com.example.liyueling_final;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
public class ViewAction extends AppCompatActivity {
WebView webView;
@ -16,6 +18,14 @@ public class ViewAction extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_action); // 先设置布局
ConstraintLayout constraintLayout4 = findViewById(R.id.back);
constraintLayout4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
webView = findViewById(R.id.webView); // 现在可以安全地查找视图
// 初始化 WebView 设置

View File

@ -29,16 +29,16 @@
app:layout_constraintStart_toEndOf="@+id/imageView134" />
<TextView
android:id="@+id/introduce"
android:id="@+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="用故事教你轻松看懂年报,买到好股票"
app:layout_constraintStart_toStartOf="@+id/book"
app:layout_constraintTop_toBottomOf="@+id/book" />
app:layout_constraintStart_toStartOf="@+id/number"
app:layout_constraintTop_toBottomOf="@+id/number" />
<TextView
android:id="@+id/book"
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"

View File

@ -31,7 +31,7 @@
app:layout_constraintTop_toBottomOf="@+id/imageView133" />
<TextView
android:id="@+id/book"
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"

View File

@ -108,15 +108,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView"
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/home_biao" />
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout

View File

@ -723,15 +723,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView"
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/home_biao" />
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout

View File

@ -831,15 +831,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView"
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/home_biao" />
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout

View File

@ -173,10 +173,10 @@
android:text="2017年加入我要好好学习天天向上~"
android:textColor="#7C7B7B"
app:layout_constraintStart_toEndOf="@+id/imageView13"
app:layout_constraintTop_toBottomOf="@+id/textView48" />
app:layout_constraintTop_toBottomOf="@+id/username" />
<TextView
android:id="@+id/textView48"
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"

View File

@ -195,10 +195,10 @@
android:text="正使用“微信账号”登陆"
android:textColor="#7C7B7B"
app:layout_constraintStart_toEndOf="@+id/imageView13"
app:layout_constraintTop_toBottomOf="@+id/textView48" />
app:layout_constraintTop_toBottomOf="@+id/username" />
<TextView
android:id="@+id/textView48"
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"