Skip to content

Commit

Permalink
refactor dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Nov 4, 2019
1 parent d344b00 commit 874fb0a
Show file tree
Hide file tree
Showing 24 changed files with 574 additions and 645 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ allprojects {
}

ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 19
targetSdkVersion = 28
compileSdkVersion = 28
targetSdkVersion = 29
compileSdkVersion = 29
appcompatVersion= '1.1.0'
materialVersion='1.2.0-alpha01'
annotationVersion='1.1.0-beta01'
Expand Down
1 change: 0 additions & 1 deletion lint/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = QMUI_LINT_VERSION

android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion

defaultConfig {
minSdkVersion 14
Expand Down
1 change: 0 additions & 1 deletion qmui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = QMUI_VERSION
//noinspection GroovyMissingReturnStatement
android {
compileSdkVersion parent.ext.compileSdkVersion
buildToolsVersion parent.ext.buildToolsVersion
lintOptions {
abortOnError false
}
Expand Down
402 changes: 92 additions & 310 deletions qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public abstract class QMUIBottomSheetBaseBuilder<T extends QMUIBottomSheetBaseBuilder> {
private Context mContext;
private QMUIBottomSheet mDialog;
protected QMUIBottomSheet mDialog;
private CharSequence mTitle;
private boolean mAddCancelBtn;
private String mCancelText;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.
*/

package com.qmuiteam.qmui.widget.dialog;

import android.graphics.Typeface;
import android.graphics.drawable.Drawable;

public class QMUIBottomSheetGridItemModel {
Drawable image = null;
int imageRes = 0;
int imageSkinTintColorAttr = 0;
int imageSkinSrcAttr = 0;
int textSkinColorAttr = 0;
CharSequence text;
Object tag = "";
Drawable subscript = null;
int subscriptRes = 0;
int subscriptSkinTintColorAttr = 0;
int subscriptSkinSrcAttr = 0;
Typeface typeface;

public QMUIBottomSheetGridItemModel(CharSequence text, Object tag) {
this.text = text;
this.tag = tag;
}

public QMUIBottomSheetGridItemModel image(Drawable image) {
this.image = image;
return this;
}

public QMUIBottomSheetGridItemModel image(int imageRes) {
this.imageRes = imageRes;
return this;
}

public QMUIBottomSheetGridItemModel subscript(Drawable image) {
this.subscript = image;
return this;
}

public QMUIBottomSheetGridItemModel subscript(int imageRes) {
this.subscriptRes = imageRes;
return this;
}


public QMUIBottomSheetGridItemModel skinTextColorAttr(int attr) {
this.textSkinColorAttr = attr;
return this;
}


public QMUIBottomSheetGridItemModel skinImageTintColorAttr(int attr) {
this.imageSkinTintColorAttr = attr;
return this;
}

public QMUIBottomSheetGridItemModel skinImageSrcAttr(int attr) {
this.imageSkinSrcAttr = attr;
return this;
}

public QMUIBottomSheetGridItemModel skinSubscriptTintColorAttr(int attr) {
this.subscriptSkinTintColorAttr = attr;
return this;
}

public QMUIBottomSheetGridItemModel skinSubscriptSrcAttr(int attr) {
this.subscriptSkinSrcAttr = attr;
return this;
}

public QMUIBottomSheetGridItemModel typeface(Typeface typeface) {
this.typeface = typeface;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* 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.
*/

package com.qmuiteam.qmui.widget.dialog;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
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.skin.defaultAttr.QMUISkinSimpleDefaultAttrProvider;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.widget.textview.QMUISpanTouchFixTextView;

import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;


public class QMUIBottomSheetGridItemView extends QMUIConstraintLayout {

private AppCompatImageView mIconIv;
private AppCompatImageView mSubscriptIv;
private TextView mTitleTv;


public QMUIBottomSheetGridItemView(Context context) {
this(context, null);
}

public QMUIBottomSheetGridItemView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public QMUIBottomSheetGridItemView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setChangeAlphaWhenPress(true);
int paddingVer = QMUIResHelper.getAttrDimen(context, R.attr.qmui_bottom_sheet_grid_item_padding_ver);
setPadding(0, paddingVer, 0, paddingVer);
mIconIv = new AppCompatImageView(context);
mIconIv.setId(View.generateViewId());
mIconIv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

int iconSize = QMUIResHelper.getAttrDimen(context, R.attr.qmui_bottom_sheet_grid_item_icon_size);
LayoutParams iconLp = new LayoutParams(iconSize, iconSize);
iconLp.leftToLeft = LayoutParams.PARENT_ID;
iconLp.rightToRight = LayoutParams.PARENT_ID;
iconLp.topToTop = LayoutParams.PARENT_ID;
addView(mIconIv, iconLp);

mTitleTv = new QMUISpanTouchFixTextView(context);
mTitleTv.setId(View.generateViewId());
QMUISkinSimpleDefaultAttrProvider provider = new QMUISkinSimpleDefaultAttrProvider();
provider.setDefaultSkinAttr(QMUISkinValueBuilder.TEXT_COLOR,
R.attr.qmui_skin_support_bottom_sheet_grid_item_text_color);
QMUIResHelper.assignTextViewWithAttr(mTitleTv, R.attr.qmui_bottom_sheet_grid_item_text_style);
QMUISkinHelper.setSkinDefaultProvider(mTitleTv, provider);

LayoutParams titleLp = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
titleLp.leftToLeft = LayoutParams.PARENT_ID;
titleLp.rightToRight = LayoutParams.PARENT_ID;
titleLp.topToBottom = mIconIv.getId();
titleLp.topMargin = QMUIResHelper.getAttrDimen(
context, R.attr.qmui_bottom_sheet_grid_item_text_margin_top);
addView(mTitleTv, titleLp);
}

public void render(QMUIBottomSheetGridItemModel model) {
QMUISkinValueBuilder builder = QMUISkinValueBuilder.acquire();
if (model.imageSkinSrcAttr != 0) {
builder.src(model.imageSkinSrcAttr);
QMUISkinHelper.setSkinValue(mIconIv, builder);
Drawable drawable = QMUISkinHelper.getSkinDrawable(mIconIv, model.imageSkinSrcAttr);
mIconIv.setImageDrawable(drawable);
} else {
Drawable drawable = model.image;
if (drawable == null && model.imageRes != 0) {
drawable = ContextCompat.getDrawable(getContext(), model.imageRes);
}
if (drawable != null) {
drawable.mutate();
}
mIconIv.setImageDrawable(drawable);
if (model.imageSkinTintColorAttr != 0) {
builder.tintColor(model.imageSkinTintColorAttr);
QMUISkinHelper.setSkinValue(mIconIv, builder);
QMUISkinManager.defaultInstance(getContext()).refreshTheme(mIconIv);
} else {
QMUISkinHelper.setSkinValue(mIconIv, "");
}
}
builder.clear();
mTitleTv.setText(model.text);
if (model.textSkinColorAttr != 0) {
builder.textColor(model.textSkinColorAttr);
}
QMUISkinHelper.setSkinValue(mTitleTv, builder);
QMUISkinManager.defaultInstance(getContext()).refreshTheme(mTitleTv);
if(model.typeface != null){
mTitleTv.setTypeface(model.typeface);
}
builder.clear();

if (model.subscriptRes != 0 || model.subscript != null || model.subscriptSkinSrcAttr != 0) {
if (mSubscriptIv == null) {
mSubscriptIv = new AppCompatImageView(getContext());
mSubscriptIv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
LayoutParams lp = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.rightToRight = mIconIv.getId();
lp.topToTop = mIconIv.getId();
addView(mSubscriptIv, lp);
}
mSubscriptIv.setVisibility(View.VISIBLE);
if (model.subscriptSkinSrcAttr != 0) {
builder.src(model.subscriptSkinSrcAttr);
QMUISkinHelper.setSkinValue(mSubscriptIv, builder);
Drawable drawable = QMUISkinHelper.getSkinDrawable(mSubscriptIv, model.subscriptSkinSrcAttr);
mIconIv.setImageDrawable(drawable);
} else {
Drawable drawable = model.subscript;
if (drawable == null && model.subscriptRes != 0) {
drawable = ContextCompat.getDrawable(getContext(), model.subscriptRes);
}
if (drawable != null) {
drawable.mutate();
}
mSubscriptIv.setImageDrawable(drawable);
if (model.subscriptSkinTintColorAttr != 0) {
builder.tintColor(model.subscriptSkinTintColorAttr);
QMUISkinHelper.setSkinValue(mSubscriptIv, builder);
QMUISkinManager.defaultInstance(getContext()).refreshTheme(mSubscriptIv);
} else {
QMUISkinHelper.setSkinValue(mSubscriptIv, "");
}
}
} else if (mSubscriptIv != null) {
mSubscriptIv.setVisibility(View.GONE);
}
builder.release();
}
}
Loading

0 comments on commit 874fb0a

Please sign in to comment.