From e7448667cefe929988633f1e6634208ae6d27400 Mon Sep 17 00:00:00 2001 From: tanc <2512769611@qq.com> Date: Fri, 14 Jun 2024 15:40:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=89=A9=E4=B8=8B=E6=89=80=E6=9C=89?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=AE=8C=E5=96=84=E4=BB=A5=E5=8F=8A=E7=BE=8E?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=89=93?= =?UTF-8?q?=E4=B9=B1=E4=BB=A5=E5=8F=8A=E8=B7=B3=E8=BD=AC=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E4=BB=A5=E5=8F=8A=E5=9B=BE=E7=89=87=E5=8F=98=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 8 ++++ src/main/AndroidManifest.xml | 2 +- .../com/example/liyueling_final/Help2.java | 2 +- .../com/example/liyueling_final/Helpback.java | 47 +++++++++++-------- .../example/liyueling_final/MainFragment.java | 16 +++++++ .../liyueling_final/MainexpertFragment.java | 6 ++- .../liyueling_final/MainhomeFragment.java | 6 ++- .../liyueling_final/MainmajorFragment.java | 3 ++ .../liyueling_final/Study_pinglun.java | 5 +- .../example/liyueling_final/TypeFragment.java | 1 + .../{userApi.java => UserApi.java} | 5 +- .../example/liyueling_final/UserFragment.java | 2 + .../{welcome.java => Welcome.java} | 13 ++++- src/main/res/color/text.xml | 7 +++ .../drawable/default_button_background.xml | 4 -- .../drawable/selected_button_background.xml | 4 +- .../drawable/unselected_button_background.xml | 4 ++ src/main/res/layout/activity_helpback.xml | 13 +++-- src/main/res/layout/activity_main.xml | 12 +++-- src/main/res/layout/activity_welcome.xml | 2 +- src/main/res/layout/fragment_main.xml | 4 ++ src/main/res/values/colors.xml | 10 +++- src/main/res/values/themes.xml | 2 +- 23 files changed, 128 insertions(+), 50 deletions(-) rename src/main/java/com/example/liyueling_final/{userApi.java => UserApi.java} (69%) rename src/main/java/com/example/liyueling_final/{welcome.java => Welcome.java} (82%) create mode 100644 src/main/res/color/text.xml delete mode 100644 src/main/res/drawable/default_button_background.xml create mode 100644 src/main/res/drawable/unselected_button_background.xml diff --git a/build.gradle.kts b/build.gradle.kts index 8a31b2e..af7aca8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,5 +56,13 @@ dependencies { implementation ("io.github.lucksiege:ucrop:v3.11.2") implementation ("io.github.lucksiege:camerax:v3.11.2") implementation ("com.github.bumptech.glide:glide:4.15.1") + 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 9d670ad..fc877c2 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -79,7 +79,7 @@ android:name=".ViewStart" android:exported="false" /> diff --git a/src/main/java/com/example/liyueling_final/Help2.java b/src/main/java/com/example/liyueling_final/Help2.java index d732dae..ff9ab51 100644 --- a/src/main/java/com/example/liyueling_final/Help2.java +++ b/src/main/java/com/example/liyueling_final/Help2.java @@ -30,7 +30,7 @@ public class Help2 extends AppCompatActivity { PropertyValuesHolder propertyValuesHolder2 = PropertyValuesHolder.ofFloat("scaleY", 1,3,1); PropertyValuesHolder propertyValuesHolder3 = PropertyValuesHolder.ofFloat("alpha", 0,1); ValueAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageView, propertyValuesHolder, propertyValuesHolder2, propertyValuesHolder3); - animator.setDuration(1000); + animator.setDuration(500); animator.start(); } }); diff --git a/src/main/java/com/example/liyueling_final/Helpback.java b/src/main/java/com/example/liyueling_final/Helpback.java index 27bdf3c..048b6ea 100644 --- a/src/main/java/com/example/liyueling_final/Helpback.java +++ b/src/main/java/com/example/liyueling_final/Helpback.java @@ -3,13 +3,14 @@ package com.example.liyueling_final; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; -import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Helpback extends AppCompatActivity { Button button1, button2; + boolean isButton1Selected = false; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -22,31 +23,37 @@ public class Helpback extends AppCompatActivity { finish(); } }); - View.OnClickListener listener = new View.OnClickListener() { + + button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - switchButtonColors(); + isButton1Selected = !isButton1Selected; + updateButtonColors(); } - }; + }); - button1.setOnClickListener(listener); - button2.setOnClickListener(listener); + button2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isButton1Selected = !isButton1Selected; + updateButtonColors(); + } + }); } - private void switchButtonColors() { - // 获取当前按钮的背景颜色 - int button1BackgroundColor = ((ColorDrawable) button1.getBackground()).getColor(); - int button2BackgroundColor = ((ColorDrawable) button2.getBackground()).getColor(); + private void updateButtonColors() { + if (isButton1Selected) { + button1.setBackground(ContextCompat.getDrawable(this, R.drawable.selected_button_background)); + button1.setTextColor(ContextCompat.getColor(this, R.color.selected_button_text_color)); - // 获取当前按钮的文本颜色 - int button1TextColor = button1.getCurrentTextColor(); - int button2TextColor = button2.getCurrentTextColor(); + button2.setBackground(ContextCompat.getDrawable(this, R.drawable.unselected_button_background)); + button2.setTextColor(ContextCompat.getColor(this, R.color.unselected_button_text_color)); + } else { + button2.setBackground(ContextCompat.getDrawable(this, R.drawable.selected_button_background)); + button2.setTextColor(ContextCompat.getColor(this, R.color.selected_button_text_color)); - // 交换按钮的背景颜色和文本颜色 - button1.setBackgroundColor(button2BackgroundColor); - button2.setBackgroundColor(button1BackgroundColor); - - button1.setTextColor(button2TextColor); - button2.setTextColor(button1TextColor); + button1.setBackground(ContextCompat.getDrawable(this, R.drawable.unselected_button_background)); + button1.setTextColor(ContextCompat.getColor(this, R.color.unselected_button_text_color)); + } } -} \ No newline at end of file +} diff --git a/src/main/java/com/example/liyueling_final/MainFragment.java b/src/main/java/com/example/liyueling_final/MainFragment.java index d8fb98a..17a41a3 100644 --- a/src/main/java/com/example/liyueling_final/MainFragment.java +++ b/src/main/java/com/example/liyueling_final/MainFragment.java @@ -56,6 +56,10 @@ public class MainFragment extends Fragment { getActivity().getSupportFragmentManager().beginTransaction() .show(mainhomeFragment).hide(maingoodFragment).hide(mainexpertFragment).hide(mainmajorFragment) .commit(); + constraintLayout.setSelected(true); + constraintLayout2.setSelected(false); + constraintLayout3.setSelected(false); + constraintLayout4.setSelected(false); } }); @@ -67,6 +71,10 @@ public class MainFragment extends Fragment { getActivity().getSupportFragmentManager().beginTransaction() .show(maingoodFragment).hide(mainhomeFragment).hide(mainexpertFragment).hide(mainmajorFragment) .commit(); + constraintLayout2.setSelected(true); + constraintLayout.setSelected(false); + constraintLayout3.setSelected(false); + constraintLayout4.setSelected(false); } }); constraintLayout3.setOnClickListener(new View.OnClickListener() { @@ -75,6 +83,10 @@ public class MainFragment extends Fragment { getActivity().getSupportFragmentManager().beginTransaction() .show(mainmajorFragment).hide(maingoodFragment).hide(mainexpertFragment).hide(mainhomeFragment) .commit(); + constraintLayout3.setSelected(true); + constraintLayout2.setSelected(false); + constraintLayout.setSelected(false); + constraintLayout4.setSelected(false); } }); @@ -86,6 +98,10 @@ public class MainFragment extends Fragment { getActivity().getSupportFragmentManager().beginTransaction() .show(mainexpertFragment).hide(maingoodFragment).hide(mainhomeFragment).hide(mainmajorFragment) .commit(); + constraintLayout4.setSelected(true); + constraintLayout2.setSelected(false); + constraintLayout3.setSelected(false); + constraintLayout.setSelected(false); } }); // Inflate the layout for this fragment diff --git a/src/main/java/com/example/liyueling_final/MainexpertFragment.java b/src/main/java/com/example/liyueling_final/MainexpertFragment.java index f1ab29c..60f4c36 100644 --- a/src/main/java/com/example/liyueling_final/MainexpertFragment.java +++ b/src/main/java/com/example/liyueling_final/MainexpertFragment.java @@ -21,6 +21,7 @@ import com.youth.banner.indicator.CircleIndicator; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import retrofit2.Call; @@ -73,7 +74,7 @@ public class MainexpertFragment extends Fragment { R.drawable.img_21, R.drawable.img_22 ); - + Collections.shuffle(imageList); recyclerView3 = view.findViewById(R.id.RecyclerView3); myAdpater3 = new MyAdpater3(); recyclerView3.setAdapter(myAdpater3); @@ -92,7 +93,9 @@ public class MainexpertFragment extends Fragment { if (data.id < 7) { expert1List.add(data); } + } + Collections.shuffle(expert1List); myAdpater.notifyDataSetChanged(); } @@ -117,6 +120,7 @@ public class MainexpertFragment extends Fragment { expert2List.add(data); } } + Collections.shuffle(expert2List); myAdpater2.notifyDataSetChanged(); } diff --git a/src/main/java/com/example/liyueling_final/MainhomeFragment.java b/src/main/java/com/example/liyueling_final/MainhomeFragment.java index 322554f..a64b3e8 100644 --- a/src/main/java/com/example/liyueling_final/MainhomeFragment.java +++ b/src/main/java/com/example/liyueling_final/MainhomeFragment.java @@ -22,6 +22,7 @@ import com.youth.banner.holder.BannerImageHolder; import com.youth.banner.indicator.CircleIndicator; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import retrofit2.Call; @@ -110,7 +111,9 @@ public class MainhomeFragment extends Fragment { class_homelist2.add(data); } } - + Collections.shuffle(class_homelist0); + Collections.shuffle(class_homelist1); + Collections.shuffle(class_homelist2); myAdpater.notifyDataSetChanged(); recyclerView2.getAdapter().notifyDataSetChanged(); recyclerView3.getAdapter().notifyDataSetChanged(); @@ -134,6 +137,7 @@ public class MainhomeFragment extends Fragment { class2_homelist.add(data); } } + Collections.shuffle(class2_homelist); myAdpater2.notifyDataSetChanged(); } diff --git a/src/main/java/com/example/liyueling_final/MainmajorFragment.java b/src/main/java/com/example/liyueling_final/MainmajorFragment.java index 6d39d35..a9cff07 100644 --- a/src/main/java/com/example/liyueling_final/MainmajorFragment.java +++ b/src/main/java/com/example/liyueling_final/MainmajorFragment.java @@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import retrofit2.Call; @@ -48,6 +49,7 @@ public class MainmajorFragment extends Fragment { if(people.data.get(0).id<5){ peopleList.addAll(people.data); } + Collections.shuffle(peopleList); myAdpater.notifyDataSetChanged(); } @@ -65,6 +67,7 @@ public class MainmajorFragment extends Fragment { public void onResponse(Call call2, Response response) { Advertisement advertisement = response.body(); advertiselist.addAll(advertisement.data); + Collections.shuffle(advertiselist); myAdpater2.notifyDataSetChanged(); } diff --git a/src/main/java/com/example/liyueling_final/Study_pinglun.java b/src/main/java/com/example/liyueling_final/Study_pinglun.java index d62c4c2..1becff3 100644 --- a/src/main/java/com/example/liyueling_final/Study_pinglun.java +++ b/src/main/java/com/example/liyueling_final/Study_pinglun.java @@ -18,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import retrofit2.Call; @@ -28,6 +29,7 @@ public class Study_pinglun extends Fragment { RecyclerView recyclerView; MyAdpater myAdpater; List userList = new ArrayList<>(); + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -58,7 +60,7 @@ public class Study_pinglun extends Fragment { } }); - userApi userApi = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(userApi.class); + UserApi userApi = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(UserApi.class); for(int i=1;i<8;i++){ Call call = userApi.Comment(i); call.enqueue(new Callback() { @@ -66,6 +68,7 @@ public class Study_pinglun extends Fragment { public void onResponse(Call call, Response response) { User user = response.body(); userList.addAll(user.data); + Collections.shuffle(userList); myAdpater.notifyDataSetChanged(); } diff --git a/src/main/java/com/example/liyueling_final/TypeFragment.java b/src/main/java/com/example/liyueling_final/TypeFragment.java index 1135764..df4c691 100644 --- a/src/main/java/com/example/liyueling_final/TypeFragment.java +++ b/src/main/java/com/example/liyueling_final/TypeFragment.java @@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class TypeFragment extends Fragment implements AdapterView.OnItemClickListener { diff --git a/src/main/java/com/example/liyueling_final/userApi.java b/src/main/java/com/example/liyueling_final/UserApi.java similarity index 69% rename from src/main/java/com/example/liyueling_final/userApi.java rename to src/main/java/com/example/liyueling_final/UserApi.java index a0864b6..c6e5e25 100644 --- a/src/main/java/com/example/liyueling_final/userApi.java +++ b/src/main/java/com/example/liyueling_final/UserApi.java @@ -3,12 +3,9 @@ package com.example.liyueling_final; import retrofit2.Call; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; -import retrofit2.http.GET; -import retrofit2.http.Header; import retrofit2.http.POST; -import retrofit2.http.Query; -public interface userApi { +public interface UserApi { @FormUrlEncoded @POST("comment") Call Comment (@Field("id") Integer id); diff --git a/src/main/java/com/example/liyueling_final/UserFragment.java b/src/main/java/com/example/liyueling_final/UserFragment.java index 7e9b156..f64926c 100644 --- a/src/main/java/com/example/liyueling_final/UserFragment.java +++ b/src/main/java/com/example/liyueling_final/UserFragment.java @@ -36,6 +36,7 @@ import org.greenrobot.eventbus.ThreadMode; import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import retrofit2.Call; @@ -169,6 +170,7 @@ public class UserFragment extends Fragment { public void onResponse(Call call, Response response) { Chat chat = response.body(); chatlist.addAll(chat.data); + Collections.shuffle(chatlist); myAdpater.notifyDataSetChanged(); } diff --git a/src/main/java/com/example/liyueling_final/welcome.java b/src/main/java/com/example/liyueling_final/Welcome.java similarity index 82% rename from src/main/java/com/example/liyueling_final/welcome.java rename to src/main/java/com/example/liyueling_final/Welcome.java index d63e0e1..7fc13d1 100644 --- a/src/main/java/com/example/liyueling_final/welcome.java +++ b/src/main/java/com/example/liyueling_final/Welcome.java @@ -11,7 +11,12 @@ import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; -public class welcome extends AppCompatActivity { +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.bitmap.CircleCrop; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; +import com.bumptech.glide.request.RequestOptions; + +public class Welcome extends AppCompatActivity { TextView textView; ImageView imageView; ImageView imageView2; @@ -25,6 +30,10 @@ public class welcome extends AppCompatActivity { imageView = findViewById(R.id.imgx); imageView2 = findViewById(R.id.enter); imageView3 = findViewById(R.id.imageView143); + Glide.with(Welcome.this) + .load(R.drawable.img_117) + .apply(new RequestOptions().transform(new RoundedCorners(90))) + .into(imageView); PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofFloat("translationY",-100,0); PropertyValuesHolder propertyValuesHolder3 = PropertyValuesHolder.ofFloat("alpha",0,1); @@ -50,7 +59,7 @@ public class welcome extends AppCompatActivity { animator.start(); - Intent intent = new Intent(welcome.this, LoginMainActivity.class); + Intent intent = new Intent(Welcome.this, LoginMainActivity.class); startActivity(intent); } }); diff --git a/src/main/res/color/text.xml b/src/main/res/color/text.xml new file mode 100644 index 0000000..3954356 --- /dev/null +++ b/src/main/res/color/text.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/default_button_background.xml b/src/main/res/drawable/default_button_background.xml deleted file mode 100644 index 007efa7..0000000 --- a/src/main/res/drawable/default_button_background.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/main/res/drawable/selected_button_background.xml b/src/main/res/drawable/selected_button_background.xml index f6f5ac3..8583b6d 100644 --- a/src/main/res/drawable/selected_button_background.xml +++ b/src/main/res/drawable/selected_button_background.xml @@ -1,4 +1,4 @@ - - + + diff --git a/src/main/res/drawable/unselected_button_background.xml b/src/main/res/drawable/unselected_button_background.xml new file mode 100644 index 0000000..2a95350 --- /dev/null +++ b/src/main/res/drawable/unselected_button_background.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/main/res/layout/activity_helpback.xml b/src/main/res/layout/activity_helpback.xml index a80709f..b70f579 100644 --- a/src/main/res/layout/activity_helpback.xml +++ b/src/main/res/layout/activity_helpback.xml @@ -65,10 +65,11 @@ android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="16dp" + android:layout_centerHorizontal="true" + android:layout_marginTop="32dp" + android:background="@drawable/selected_button_background" android:text="问题" - android:background="@android:color/white" - android:textColor="@android:color/black" + android:textColor="@color/selected_button_text_color" app:layout_constraintStart_toStartOf="@+id/textView27" app:layout_constraintTop_toBottomOf="@+id/textView27" /> @@ -76,10 +77,12 @@ android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_below="@id/button1" + android:layout_centerHorizontal="true" android:layout_marginStart="32dp" - android:background="@android:color/black" + android:background="@drawable/unselected_button_background" android:text="建议" - android:textColor="@android:color/white" + android:textColor="@color/unselected_button_text_color" app:layout_constraintBottom_toBottomOf="@+id/button1" app:layout_constraintStart_toEndOf="@+id/button1" app:layout_constraintTop_toTopOf="@+id/button1" /> diff --git a/src/main/res/layout/activity_main.xml b/src/main/res/layout/activity_main.xml index 615f336..e05743e 100644 --- a/src/main/res/layout/activity_main.xml +++ b/src/main/res/layout/activity_main.xml @@ -45,7 +45,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/img_5" /> + app:srcCompat="@drawable/mainhome" /> @@ -79,7 +80,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/img_3" /> + app:srcCompat="@drawable/study" /> @@ -111,7 +113,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/img_2" /> + app:srcCompat="@drawable/user" /> @@ -143,7 +146,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/img_4" /> + app:srcCompat="@drawable/type" /> diff --git a/src/main/res/layout/activity_welcome.xml b/src/main/res/layout/activity_welcome.xml index 19687a8..3a1fe07 100644 --- a/src/main/res/layout/activity_welcome.xml +++ b/src/main/res/layout/activity_welcome.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".welcome"> + tools:context=".Welcome"> #FF000000 #FFFFFFFF #56AAFF - #000000 - #FFFFFF + #000000 + #FFFFFF + #000000 + #94959D + + #FFFFFF + #000000 + \ No newline at end of file diff --git a/src/main/res/values/themes.xml b/src/main/res/values/themes.xml index 0221072..e4bdbbc 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -1,6 +1,6 @@ -