diff --git a/app/src/main/java/cn/luern0313/wristbilibili/adapter/ThemeAdapter.java b/app/src/main/java/cn/luern0313/wristbilibili/adapter/ThemeAdapter.java index 1864889..eaedb46 100644 --- a/app/src/main/java/cn/luern0313/wristbilibili/adapter/ThemeAdapter.java +++ b/app/src/main/java/cn/luern0313/wristbilibili/adapter/ThemeAdapter.java @@ -44,27 +44,21 @@ public ThemeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTyp } @Override - public void onBindViewHolder(@NonNull final ThemeViewHolder holder, int position) + public void onBindViewHolder(@NonNull final ThemeViewHolder holder, final int position) { holder.checkView.setVisibility(ThemeUtil.getCurrentThemePos() == position ? View.VISIBLE : View.INVISIBLE); holder.nameView.setText(ThemeUtil.themes[position].getName()); holder.colorView.setCardBackgroundColor(ctx.getResources().getColor(ThemeUtil.themes[position].getPreviewColor())); - final int finalPos = position; - holder.itemView.setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View v) - { - ThemeUtil.changeCurrentTheme(ThemeUtil.themes[finalPos]); - ThemeUtil.changeTheme(ctx, ThemeUtil.getCurrentTheme()); - int primary = ColorUtil.getColor(R.attr.colorPrimary, ctx); - int back = ColorUtil.getColor(android.R.attr.colorBackground, ctx); - int fore = ColorUtil.getColor(android.R.attr.textColor, ctx); - themeAdapterListener.onChangeTheme((ViewGroup) ((Activity) ctx).findViewById(R.id.theme_root), primary, fore); - themeAdapterListener.onAnimate(recyclerView, "backgroundColor", ((ColorDrawable) recyclerView.getBackground()).getColor(), back); - notifyDataSetChanged(); - } + holder.itemView.setOnClickListener(v -> { + ThemeUtil.changeCurrentTheme(ThemeUtil.themes[position]); + ThemeUtil.changeTheme(ctx, ThemeUtil.getCurrentTheme()); + int primary = ColorUtil.getColor(R.attr.colorPrimary, ctx); + int back = ColorUtil.getColor(android.R.attr.colorBackground, ctx); + int fore = ColorUtil.getColor(R.attr.colorTitle, ctx); + themeAdapterListener.onChangeTheme(((Activity) ctx).findViewById(R.id.theme_root), primary, fore); + themeAdapterListener.onAnimate(recyclerView, "backgroundColor", ((ColorDrawable) recyclerView.getBackground()).getColor(), back); + notifyDataSetChanged(); }); } diff --git a/app/src/main/java/cn/luern0313/wristbilibili/ui/ThemeActivity.java b/app/src/main/java/cn/luern0313/wristbilibili/ui/ThemeActivity.java index a7f3e31..c9f62f7 100644 --- a/app/src/main/java/cn/luern0313/wristbilibili/ui/ThemeActivity.java +++ b/app/src/main/java/cn/luern0313/wristbilibili/ui/ThemeActivity.java @@ -12,18 +12,17 @@ import android.widget.TextView; import androidx.annotation.ColorInt; -import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import cn.luern0313.wristbilibili.R; import cn.luern0313.wristbilibili.adapter.ThemeAdapter; -import cn.luern0313.wristbilibili.util.ListViewTouchListener; import cn.luern0313.wristbilibili.util.ThemeUtil; +import cn.luern0313.wristbilibili.util.ViewTouchListener; import cn.luern0313.wristbilibili.widget.TitleView; -public class ThemeActivity extends AppCompatActivity implements TitleView.TitleViewListener +public class ThemeActivity extends BaseActivity implements TitleView.TitleViewListener { private Context ctx; @@ -60,7 +59,7 @@ public void onChangeTheme(ViewGroup group, int primary, int fore) ThemeAdapter themeAdapter = new ThemeAdapter(ctx, getLayoutInflater(), themeAdapterListener, recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false)); recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); - recyclerView.setOnTouchListener(new ListViewTouchListener(recyclerView, (TitleView.TitleViewListener) ctx)); + recyclerView.setOnTouchListener(new ViewTouchListener(recyclerView, (TitleView.TitleViewListener) ctx)); recyclerView.setAdapter(themeAdapter); } @@ -72,11 +71,11 @@ private void changeTheme(ViewGroup group, @ColorInt int primary, @ColorInt int f View v = group.getChildAt(i); if(v instanceof ViewGroup) changeTheme((ViewGroup) v, primary, fore); - if(v.getId() == R.id.theme_title) - animate(v, "backgroundColor", ((ColorDrawable) v.getBackground()).getColor(), primary); - else if (v.getId() == R.id.theme_item_name) + if(v.getId() == R.id.theme_title && v instanceof TitleView) + animate(v.findViewById(R.id.title_layout), "backgroundColor", ((ColorDrawable) v.findViewById(R.id.title_layout).getBackground()).getColor(), primary); + else if (v.getId() == R.id.theme_item_name && v instanceof TextView) animate(v, "textColor", ((TextView) v).getTextColors().getDefaultColor(), fore); - else if (v.getId() == R.id.theme_item_check) + else if (v.getId() == R.id.theme_item_check && v instanceof ImageView) ((ImageView) v).getDrawable().applyTheme(getTheme()); } } diff --git a/app/src/main/java/cn/luern0313/wristbilibili/util/ColorUtil.java b/app/src/main/java/cn/luern0313/wristbilibili/util/ColorUtil.java index 8155d32..7317c1c 100644 --- a/app/src/main/java/cn/luern0313/wristbilibili/util/ColorUtil.java +++ b/app/src/main/java/cn/luern0313/wristbilibili/util/ColorUtil.java @@ -9,6 +9,11 @@ public class ColorUtil { + public static String getColorString(@AttrRes int attr, Context context) + { + return String.format("#%06X", 0xFFFFFF & getColor(attr, context.getTheme())); + } + public static @ColorInt int getColor(@AttrRes int attr, Context context) { return getColor(attr, context.getTheme()); diff --git a/app/src/main/res/layout/item_theme.xml b/app/src/main/res/layout/item_theme.xml index def0560..085a62c 100644 --- a/app/src/main/res/layout/item_theme.xml +++ b/app/src/main/res/layout/item_theme.xml @@ -15,8 +15,7 @@ android:id="@+id/theme_item_icon" android:layout_width="20dp" android:layout_height="0dp" - android:layout_marginStart="32dp" - android:elevation="0dp" + android:elevation="10dp" app:cardCornerRadius="4dp" app:layout_constraintBottom_toBottomOf="@+id/theme_item_name" app:layout_constraintStart_toStartOf="parent" @@ -29,6 +28,7 @@ android:layout_marginStart="8dp" android:layout_marginTop="12dp" android:layout_marginBottom="12dp" + android:textColor="?attr/colorTitle" android:textSize="14sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/theme_item_check" @@ -40,11 +40,10 @@ android:id="@+id/theme_item_check" android:layout_width="wrap_content" android:layout_height="0dp" - android:layout_marginEnd="32dp" android:scaleType="centerInside" android:visibility="visible" app:layout_constraintBottom_toBottomOf="@+id/theme_item_name" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@+id/theme_item_name" - app:srcCompat="@drawable/ic_check_12" /> + app:srcCompat="@drawable/icon_check_12" /> \ No newline at end of file