mirror of
https://github.com/Tencent/QMUI_Android.git
synced 2026-10-18 05:01:04 +08:00
QMUICommonListItemView supports instance skin config
This commit is contained in:
@@ -24,7 +24,6 @@ import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewStub;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@@ -32,11 +31,9 @@ import android.widget.TextView;
|
||||
import com.qmuiteam.qmui.R;
|
||||
import com.qmuiteam.qmui.layout.QMUIConstraintLayout;
|
||||
import com.qmuiteam.qmui.skin.QMUISkinHelper;
|
||||
import com.qmuiteam.qmui.skin.QMUISkinManager;
|
||||
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder;
|
||||
import com.qmuiteam.qmui.util.QMUILangHelper;
|
||||
import com.qmuiteam.qmui.util.QMUIResHelper;
|
||||
import com.qmuiteam.qmui.util.QMUIViewHelper;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -136,8 +133,7 @@ public class QMUICommonListItemView extends QMUIConstraintLayout {
|
||||
protected TextView mDetailTextView;
|
||||
protected CheckBox mSwitch;
|
||||
private ImageView mRedDot;
|
||||
private ViewStub mNewTipViewStub;
|
||||
private View mNewTip;
|
||||
private ImageView mNewTipView;
|
||||
private Placeholder mAfterTitleHolder;
|
||||
private Placeholder mBeforeAccessoryHolder;
|
||||
|
||||
@@ -167,7 +163,7 @@ public class QMUICommonListItemView extends QMUIConstraintLayout {
|
||||
mImageView = findViewById(R.id.group_list_item_imageView);
|
||||
mTextView = findViewById(R.id.group_list_item_textView);
|
||||
mRedDot = findViewById(R.id.group_list_item_tips_dot);
|
||||
mNewTipViewStub = findViewById(R.id.group_list_item_tips_new);
|
||||
mNewTipView = findViewById(R.id.group_list_item_tips_new);
|
||||
mDetailTextView = findViewById(R.id.group_list_item_detailTextView);
|
||||
mAfterTitleHolder = findViewById(R.id.group_list_item_holder_after_title);
|
||||
mBeforeAccessoryHolder = findViewById(R.id.group_list_item_holder_before_accessory);
|
||||
@@ -208,12 +204,12 @@ public class QMUICommonListItemView extends QMUIConstraintLayout {
|
||||
mBeforeAccessoryHolder.setContentId(mRedDot.getId());
|
||||
mAfterTitleHolder.setContentId(View.NO_ID);
|
||||
}
|
||||
}else if(mNewTip != null && mNewTip.getVisibility() == View.VISIBLE){
|
||||
} else if (mNewTipView.getVisibility() == View.VISIBLE) {
|
||||
if (mTipPosition == TIP_POSITION_LEFT) {
|
||||
mAfterTitleHolder.setContentId(mNewTip.getId());
|
||||
mAfterTitleHolder.setContentId(mNewTipView.getId());
|
||||
mBeforeAccessoryHolder.setContentId(View.NO_ID);
|
||||
} else {
|
||||
mBeforeAccessoryHolder.setContentId(mNewTip.getId());
|
||||
mBeforeAccessoryHolder.setContentId(mNewTipView.getId());
|
||||
mAfterTitleHolder.setContentId(View.NO_ID);
|
||||
}
|
||||
}
|
||||
@@ -247,8 +243,8 @@ public class QMUICommonListItemView extends QMUIConstraintLayout {
|
||||
mBeforeAccessoryHolder.setContentId(mRedDot.getId());
|
||||
mAfterTitleHolder.setContentId(View.NO_ID);
|
||||
}
|
||||
if(isShow && mNewTip != null){
|
||||
mNewTip.setVisibility(View.GONE);
|
||||
if (isShow) {
|
||||
mNewTipView.setVisibility(View.GONE);
|
||||
checkDetailLeftMargin();
|
||||
}
|
||||
}
|
||||
@@ -261,36 +257,30 @@ public class QMUICommonListItemView extends QMUIConstraintLayout {
|
||||
*/
|
||||
public void showNewTip(boolean isShow) {
|
||||
if (isShow) {
|
||||
if (mNewTip == null) {
|
||||
mNewTip = mNewTipViewStub.inflate();
|
||||
}
|
||||
mNewTip.setId(QMUIViewHelper.generateViewId());
|
||||
mNewTip.setVisibility(View.VISIBLE);
|
||||
mNewTipView.setVisibility(View.VISIBLE);
|
||||
mRedDot.setVisibility(GONE);
|
||||
if (mTipPosition == TIP_POSITION_LEFT) {
|
||||
mAfterTitleHolder.setContentId(mNewTip.getId());
|
||||
mAfterTitleHolder.setContentId(mNewTipView.getId());
|
||||
mBeforeAccessoryHolder.setContentId(View.NO_ID);
|
||||
} else {
|
||||
mBeforeAccessoryHolder.setContentId(mNewTip.getId());
|
||||
mBeforeAccessoryHolder.setContentId(mNewTipView.getId());
|
||||
mAfterTitleHolder.setContentId(View.NO_ID);
|
||||
}
|
||||
} else {
|
||||
if (mNewTip != null && mNewTip.getVisibility() == View.VISIBLE) {
|
||||
mNewTip.setVisibility(View.GONE);
|
||||
}
|
||||
mNewTipView.setVisibility(View.GONE);
|
||||
}
|
||||
checkDetailLeftMargin();
|
||||
}
|
||||
|
||||
private void checkDetailLeftMargin(){
|
||||
private void checkDetailLeftMargin() {
|
||||
LayoutParams detailLp = (LayoutParams) mDetailTextView.getLayoutParams();
|
||||
if(mOrientation == VERTICAL){
|
||||
if (mOrientation == VERTICAL) {
|
||||
detailLp.leftMargin = 0;
|
||||
}else{
|
||||
if(mNewTip == null || mNewTip.getVisibility() == View.GONE || mTipPosition == TIP_POSITION_LEFT){
|
||||
} else {
|
||||
if (mNewTipView.getVisibility() == View.GONE || mTipPosition == TIP_POSITION_LEFT) {
|
||||
detailLp.leftMargin = QMUIResHelper.getAttrDimen(
|
||||
getContext(), R.attr.qmui_common_list_item_detail_h_margin_with_title);
|
||||
}else{
|
||||
} else {
|
||||
detailLp.leftMargin = QMUIResHelper.getAttrDimen(
|
||||
getContext(), R.attr.qmui_common_list_item_detail_h_margin_with_title_large);
|
||||
}
|
||||
@@ -412,10 +402,10 @@ public class QMUICommonListItemView extends QMUIConstraintLayout {
|
||||
}
|
||||
LayoutParams titleLp = (LayoutParams) mTextView.getLayoutParams();
|
||||
LayoutParams detailLp = (LayoutParams) mDetailTextView.getLayoutParams();
|
||||
if(mAccessoryView.getVisibility() != View.GONE){
|
||||
if (mAccessoryView.getVisibility() != View.GONE) {
|
||||
detailLp.goneRightMargin = detailLp.rightMargin;
|
||||
titleLp.goneRightMargin = titleLp.rightMargin;
|
||||
}else{
|
||||
} else {
|
||||
detailLp.goneRightMargin = 0;
|
||||
titleLp.goneRightMargin = 0;
|
||||
}
|
||||
@@ -463,8 +453,54 @@ public class QMUICommonListItemView extends QMUIConstraintLayout {
|
||||
}
|
||||
}
|
||||
|
||||
public void setSkinConfig(SkinConfig skinConfig) {
|
||||
QMUISkinValueBuilder builder = QMUISkinValueBuilder.acquire();
|
||||
if (skinConfig.iconTintColorRes != 0) {
|
||||
builder.tintColor(skinConfig.iconTintColorRes);
|
||||
}
|
||||
if (skinConfig.iconSrcRes != 0) {
|
||||
builder.src(skinConfig.iconSrcRes);
|
||||
}
|
||||
QMUISkinHelper.setSkinValue(mImageView, builder);
|
||||
|
||||
builder.clear();
|
||||
if (skinConfig.titleTextColorRes != 0) {
|
||||
builder.textColor(skinConfig.titleTextColorRes);
|
||||
}
|
||||
QMUISkinHelper.setSkinValue(mTextView, builder);
|
||||
|
||||
builder.clear();
|
||||
if (skinConfig.detailTextColorRes != 0) {
|
||||
builder.textColor(skinConfig.detailTextColorRes);
|
||||
}
|
||||
QMUISkinHelper.setSkinValue(mDetailTextView, builder);
|
||||
|
||||
builder.clear();
|
||||
if (skinConfig.newTipSrcRes != 0) {
|
||||
builder.src(skinConfig.newTipSrcRes);
|
||||
}
|
||||
QMUISkinHelper.setSkinValue(mNewTipView, builder);
|
||||
|
||||
builder.clear();
|
||||
if (skinConfig.tipDotColorRes != 0) {
|
||||
builder.bgTintColor(skinConfig.tipDotColorRes);
|
||||
}
|
||||
QMUISkinHelper.setSkinValue(mRedDot, builder);
|
||||
builder.release();
|
||||
}
|
||||
|
||||
|
||||
public interface LayoutParamConfig {
|
||||
ConstraintLayout.LayoutParams onConfig(ConstraintLayout.LayoutParams lp);
|
||||
}
|
||||
|
||||
public static class SkinConfig {
|
||||
|
||||
public int iconTintColorRes = R.attr.qmui_skin_support_common_list_icon_tint_color;
|
||||
public int iconSrcRes = 0;
|
||||
public int titleTextColorRes = R.attr.qmui_skin_support_common_list_title_color;
|
||||
public int detailTextColorRes = R.attr.qmui_skin_support_common_list_detail_color;
|
||||
public int newTipSrcRes = R.attr.qmui_skin_support_common_list_new_drawable;
|
||||
public int tipDotColorRes = R.attr.qmui_skin_support_common_list_red_point_tint_color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,17 +95,6 @@
|
||||
|
||||
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/group_list_item_tips_new"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout="@layout/qmui_common_list_item_tip_new_layout"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.Placeholder
|
||||
android:id="@+id/group_list_item_holder_after_title"
|
||||
android:layout_width="1px"
|
||||
@@ -115,6 +104,13 @@
|
||||
app:layout_constraintLeft_toRightOf="@+id/group_list_item_textView"
|
||||
app:layout_constraintTop_toTopOf="@+id/group_list_item_textView" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/group_list_item_tips_new"
|
||||
android:contentDescription="Update tips"
|
||||
android:visibility="gone"
|
||||
style="?attr/QMUITipNewStyle"
|
||||
app:qmui_skin_src="?attr/qmui_skin_support_common_list_new_drawable"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/group_list_item_tips_dot"
|
||||
style="?attr/QMUITipPointStyle"
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<!--
|
||||
Tencent is pleased to support the open source community by making QMUI_Android available.
|
||||
|
||||
Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
|
||||
Licensed under the MIT License (the "License"); you may not use this file except in
|
||||
compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://opensource.org/licenses/MIT
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
||||
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
either express or implied. See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView style="?attr/QMUITipNewStyle"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:contentDescription="Update tips"
|
||||
app:qmui_skin_src="?attr/qmui_skin_support_common_list_new_drawable"/>
|
||||
+6
-2
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.qmuiteam.qmuidemo.fragment.components;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -35,6 +34,7 @@ import com.qmuiteam.qmuidemo.lib.annotation.Widget;
|
||||
import com.qmuiteam.qmuidemo.manager.QDDataManager;
|
||||
import com.qmuiteam.qmuidemo.model.QDItemDescription;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
@@ -92,6 +92,11 @@ public class QDGroupListViewFragment extends BaseFragment {
|
||||
null,
|
||||
QMUICommonListItemView.HORIZONTAL,
|
||||
QMUICommonListItemView.ACCESSORY_TYPE_NONE);
|
||||
|
||||
// 去除 icon 的 tintColor 换肤设置
|
||||
QMUICommonListItemView.SkinConfig skinConfig = new QMUICommonListItemView.SkinConfig();
|
||||
skinConfig.iconTintColorRes = 0;
|
||||
itemWithDetail.setSkinConfig(skinConfig);
|
||||
itemWithDetail.setDetailText("在右方的详细信息");
|
||||
|
||||
QMUICommonListItemView itemWithDetailBelow = mGroupListView.createItemView("Item 3");
|
||||
@@ -136,7 +141,6 @@ public class QDGroupListViewFragment extends BaseFragment {
|
||||
height);
|
||||
|
||||
|
||||
|
||||
QMUICommonListItemView itemWithCustom = mGroupListView.createItemView("右方自定义 View");
|
||||
itemWithCustom.setAccessoryType(QMUICommonListItemView.ACCESSORY_TYPE_CUSTOM);
|
||||
QMUILoadingView loadingView = new QMUILoadingView(getActivity());
|
||||
|
||||
Reference in New Issue
Block a user