Skip to content

Commit

Permalink
完善修改主题的动画,主题页面适配主题色等
Browse files Browse the repository at this point in the history
  • Loading branch information
luern0313 committed Jun 2, 2021
1 parent 2a771aa commit 633dd4a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand All @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/layout/item_theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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" />
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 633dd4a

Please sign in to comment.