Merge branch 'ad' into dev
This commit is contained in:
@@ -0,0 +1,298 @@
|
|||||||
|
package com.mogo.module.common.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.mogo.module.common.R;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public class CustomRatingBar extends LinearLayout {
|
||||||
|
private Context mContext;
|
||||||
|
/*
|
||||||
|
是否可点击
|
||||||
|
* */
|
||||||
|
private boolean mClickable;
|
||||||
|
/*
|
||||||
|
* 单元总数(心形/星星)
|
||||||
|
* */
|
||||||
|
private int elementCount;
|
||||||
|
/*
|
||||||
|
* 单元点击事件
|
||||||
|
* */
|
||||||
|
private OnRatingChangeListener mOnRatingBarChangeListener;
|
||||||
|
/*
|
||||||
|
* 每个单元的大小
|
||||||
|
* */
|
||||||
|
private float elementWidth;
|
||||||
|
|
||||||
|
private float elementHeight;
|
||||||
|
|
||||||
|
public float getElementWidth() {
|
||||||
|
return elementWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementWidth(float elementWidth) {
|
||||||
|
this.elementWidth = elementWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getElementHeight() {
|
||||||
|
return elementHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementHeight(float elementHeight) {
|
||||||
|
this.elementHeight = elementHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 每个单元间的距离
|
||||||
|
* */
|
||||||
|
private float elementPadding;
|
||||||
|
/*
|
||||||
|
*单元的显示数量,支持小数点
|
||||||
|
* */
|
||||||
|
private float elementStep;
|
||||||
|
/*
|
||||||
|
* 空白的默认单元图片
|
||||||
|
* */
|
||||||
|
private Drawable elementEmptyDrawable;
|
||||||
|
/*
|
||||||
|
* 选中后的单元图片
|
||||||
|
* */
|
||||||
|
private Drawable elementFillDrawable;
|
||||||
|
/*
|
||||||
|
* 半颗单元图片
|
||||||
|
* */
|
||||||
|
private Drawable elementHarfDrawable;
|
||||||
|
/*
|
||||||
|
* 每次点击单元所增加的量是半个还是整个
|
||||||
|
* */
|
||||||
|
private StepSize stepSize;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClickable() {
|
||||||
|
return mClickable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClickable(boolean clickable) {
|
||||||
|
mClickable = clickable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getElementCount() {
|
||||||
|
return elementCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementCount(int elementCount) {
|
||||||
|
this.elementCount = elementCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OnRatingChangeListener getOnRatingBarChangeListener() {
|
||||||
|
return mOnRatingBarChangeListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnRatingChangeListener(OnRatingChangeListener onRatingBarChangeListener) {
|
||||||
|
mOnRatingBarChangeListener = onRatingBarChangeListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getElementPadding() {
|
||||||
|
return elementPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementPadding(float elementPadding) {
|
||||||
|
this.elementPadding = elementPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getElementStep() {
|
||||||
|
return elementStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementStep(float elementStep) {
|
||||||
|
this.elementStep = elementStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable getElementEmptyDrawable() {
|
||||||
|
return elementEmptyDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementEmptyDrawable(Drawable elementEmptyDrawable) {
|
||||||
|
this.elementEmptyDrawable = elementEmptyDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable getElementFillDrawable() {
|
||||||
|
return elementFillDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementFillDrawable(Drawable elementFillDrawable) {
|
||||||
|
this.elementFillDrawable = elementFillDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable getElementHarfDrawable() {
|
||||||
|
return elementHarfDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElementHarfDrawable(Drawable elementHarfDrawable) {
|
||||||
|
this.elementHarfDrawable = elementHarfDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setStepSize(StepSize stepSize) {
|
||||||
|
this.stepSize = stepSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomRatingBar(Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
mContext = context;
|
||||||
|
setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomRatingBar);
|
||||||
|
elementWidth = mTypedArray.getDimension(R.styleable.CustomRatingBar_elenmentWidth,
|
||||||
|
context.getResources().getDimension(R.dimen.heart_ratingbar_width));
|
||||||
|
elementHeight = mTypedArray.getDimension(R.styleable.CustomRatingBar_elenmentHeight,
|
||||||
|
context.getResources().getDimension(R.dimen.heart_ratingbar_height));
|
||||||
|
elementPadding = mTypedArray.getDimension(R.styleable.CustomRatingBar_elenmentPadding, 10);
|
||||||
|
|
||||||
|
elementStep = mTypedArray.getFloat(R.styleable.CustomRatingBar_elenmentStep, 1.0f);
|
||||||
|
stepSize = StepSize.fromStep(mTypedArray.getInt(R.styleable.CustomRatingBar_stepSize, 1));
|
||||||
|
elementCount = mTypedArray.getInteger(R.styleable.CustomRatingBar_elenmentCount, 5);
|
||||||
|
stepSize = StepSize.Half;
|
||||||
|
|
||||||
|
Drawable drawable_empty_default = ContextCompat.getDrawable(context, R.drawable.icon_heart_unchoose);
|
||||||
|
Drawable drawable_harf_default = ContextCompat.getDrawable(context, R.drawable.icon_heart_second);
|
||||||
|
Drawable drawable_fill_default = ContextCompat.getDrawable(context, R.drawable.icon_heart_choose);
|
||||||
|
|
||||||
|
Drawable drawable_empty = mTypedArray.getDrawable(R.styleable.CustomRatingBar_elenmentEmpty);
|
||||||
|
Drawable drawable_harf = mTypedArray.getDrawable(R.styleable.CustomRatingBar_elenmentHarf);
|
||||||
|
Drawable drawable_fill = mTypedArray.getDrawable(R.styleable.CustomRatingBar_elenmentFill);
|
||||||
|
|
||||||
|
elementEmptyDrawable = drawable_empty != null ? drawable_empty : drawable_empty_default;
|
||||||
|
elementFillDrawable = drawable_harf != null ? drawable_harf : drawable_fill_default;
|
||||||
|
elementHarfDrawable = drawable_fill != null ? drawable_fill : drawable_harf_default;
|
||||||
|
mClickable = mTypedArray.getBoolean(R.styleable.CustomRatingBar_clickable, false);
|
||||||
|
mTypedArray.recycle();
|
||||||
|
for (int i = 0; i < elementCount; ++i) {
|
||||||
|
final ImageView imageView = getElenmentImageView();
|
||||||
|
imageView.setImageDrawable(elementEmptyDrawable);
|
||||||
|
imageView.setOnClickListener(
|
||||||
|
new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mClickable) {
|
||||||
|
//浮点数的整数部分
|
||||||
|
int fint = (int) elementStep;
|
||||||
|
BigDecimal b1 = new BigDecimal(Float.toString(elementStep));
|
||||||
|
BigDecimal b2 = new BigDecimal(Integer.toString(fint));
|
||||||
|
//浮点数的小数部分
|
||||||
|
float fPoint = b1.subtract(b2).floatValue();
|
||||||
|
if (fPoint == 0) {
|
||||||
|
fint -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indexOfChild(v) > fint) {
|
||||||
|
setRating(indexOfChild(v) + 1);
|
||||||
|
} else if (indexOfChild(v) == fint) {
|
||||||
|
if (stepSize == StepSize.Full) {//如果是满星 就不考虑半颗星了
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//点击之后默认每次先增加一颗星,再次点击变为半颗星
|
||||||
|
if (imageView.getDrawable().getCurrent().getConstantState().
|
||||||
|
equals(elementHarfDrawable.getConstantState())) {
|
||||||
|
setRating(indexOfChild(v) + 1);
|
||||||
|
} else {
|
||||||
|
setRating(indexOfChild(v) + 0.5f);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setRating(indexOfChild(v) + 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
addView(imageView);
|
||||||
|
}
|
||||||
|
setRating(elementStep);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageView getElenmentImageView() {
|
||||||
|
ImageView imageView = new ImageView(getContext());
|
||||||
|
LayoutParams layout = new LayoutParams(
|
||||||
|
Math.round(mContext.getResources().getDimension(R.dimen.heart_ratingbar_width)),
|
||||||
|
Math.round(mContext.getResources().getDimension(R.dimen.heart_ratingbar_width)));//设置每个单元格在线性布局的大小
|
||||||
|
layout.setMargins(0, 0, Math.round(elementPadding), 0);//设置每颗星星在线性布局的间距
|
||||||
|
imageView.setLayoutParams(layout);
|
||||||
|
imageView.setAdjustViewBounds(true);
|
||||||
|
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||||
|
imageView.setImageDrawable(elementEmptyDrawable);
|
||||||
|
imageView.setMinimumWidth((int) elementWidth);
|
||||||
|
imageView.setMaxWidth((int) elementWidth);
|
||||||
|
imageView.setMinimumHeight((int) elementHeight);
|
||||||
|
imageView.setMaxHeight((int) elementHeight);
|
||||||
|
return imageView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRating(float rating) {
|
||||||
|
if (rating > elementCount)
|
||||||
|
rating = elementCount;
|
||||||
|
|
||||||
|
if (mOnRatingBarChangeListener != null) {
|
||||||
|
mOnRatingBarChangeListener.onRatingChange(rating);
|
||||||
|
}
|
||||||
|
this.elementStep = rating;
|
||||||
|
//浮点数的整数部分
|
||||||
|
int fint = (int) rating;
|
||||||
|
BigDecimal b1 = new BigDecimal(Float.toString(rating));
|
||||||
|
BigDecimal b2 = new BigDecimal(Integer.toString(fint));
|
||||||
|
//浮点数的小数部分
|
||||||
|
float fPoint = b1.subtract(b2).floatValue();
|
||||||
|
|
||||||
|
//设置选中的单元
|
||||||
|
for (int i = 0; i < fint; ++i) {
|
||||||
|
((ImageView) getChildAt(i)).setImageDrawable(elementFillDrawable);
|
||||||
|
}
|
||||||
|
//设置没有选中的单元
|
||||||
|
for (int i = fint; i < elementCount; i++) {
|
||||||
|
((ImageView) getChildAt(i)).setImageDrawable(elementEmptyDrawable);
|
||||||
|
}
|
||||||
|
//小数点默认增加半个
|
||||||
|
if (fPoint > 0) {
|
||||||
|
((ImageView) getChildAt(fint)).setImageDrawable(elementHarfDrawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnRatingChangeListener {
|
||||||
|
void onRatingChange(float ratingCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每次增加的方式整颗还是半颗,枚举类型
|
||||||
|
* 类似于View.GONE
|
||||||
|
*/
|
||||||
|
public enum StepSize {
|
||||||
|
Half(0), Full(1);
|
||||||
|
int step;
|
||||||
|
|
||||||
|
StepSize(int step) {
|
||||||
|
this.step = step;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StepSize fromStep(int step) {
|
||||||
|
for (StepSize f : values()) {
|
||||||
|
if (f.step == step) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/customRatingBar">
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -1054,8 +1054,8 @@
|
|||||||
<dimen name="sp_48">48px</dimen>
|
<dimen name="sp_48">48px</dimen>
|
||||||
<dimen name="module_common_shadow_width">-10px</dimen>
|
<dimen name="module_common_shadow_width">-10px</dimen>
|
||||||
<dimen name="module_common_shadow_width_pos">10px</dimen>
|
<dimen name="module_common_shadow_width_pos">10px</dimen>
|
||||||
<dimen name="heart_ratingbar_width">36px</dimen>
|
<dimen name="heart_ratingbar_width">40px</dimen>
|
||||||
<dimen name="heart_ratingbar_height">30px</dimen>
|
<dimen name="heart_ratingbar_height">43px</dimen>
|
||||||
<dimen name="v2x_panel_loading_top">300px</dimen>
|
<dimen name="v2x_panel_loading_top">300px</dimen>
|
||||||
<dimen name="v2x_share_btn_width">281px</dimen>
|
<dimen name="v2x_share_btn_width">281px</dimen>
|
||||||
<dimen name="v2x_share_btn_height">90px</dimen>
|
<dimen name="v2x_share_btn_height">90px</dimen>
|
||||||
|
|||||||
@@ -8,9 +8,36 @@
|
|||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="CustomCircleImageView">
|
<declare-styleable name="CustomCircleImageView">
|
||||||
<attr format="dimension" name="civ_border_width"/>
|
<attr name="civ_border_width" format="dimension" />
|
||||||
<attr format="color" name="civ_border_color"/>
|
<attr name="civ_border_color" format="color" />
|
||||||
<attr format="boolean" name="civ_border_overlay"/>
|
<attr name="civ_border_overlay" format="boolean" />
|
||||||
<attr format="color" name="civ_fill_color"/>
|
<attr name="civ_fill_color" format="color" />
|
||||||
|
</declare-styleable>
|
||||||
|
<declare-styleable name="CustomRatingBar">
|
||||||
|
<!--宽-->
|
||||||
|
<attr name="elenmentWidth" format="dimension" />
|
||||||
|
<!--高-->
|
||||||
|
<attr name="elenmentHeight" format="dimension" />
|
||||||
|
<!--单元间距-->
|
||||||
|
<attr name="elenmentPadding" format="dimension" />
|
||||||
|
<!--单元总数-->
|
||||||
|
<attr name="elenmentCount" format="integer" />
|
||||||
|
<!--空资源-->
|
||||||
|
<attr name="elenmentEmpty" format="reference" />
|
||||||
|
<!--满资源-->
|
||||||
|
<attr name="elenmentFill" format="reference" />
|
||||||
|
<!--半资源-->
|
||||||
|
<attr name="elenmentHarf" format="reference" />
|
||||||
|
<!--是否可点击-->
|
||||||
|
<attr name="clickable" format="boolean" />
|
||||||
|
<!--当前进度-->
|
||||||
|
<attr name="elenmentStep" format="float" />
|
||||||
|
<!--进度方式 半个还是整个-->
|
||||||
|
|
||||||
|
<attr name="stepSize">
|
||||||
|
<enum name="Half" value="0" />
|
||||||
|
<enum name="Full" value="1" />
|
||||||
|
</attr>
|
||||||
|
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.alibaba.android.arouter.launcher.ARouter;
|
import com.alibaba.android.arouter.launcher.ARouter;
|
||||||
|
import com.mogo.module.common.view.CustomRatingBar;
|
||||||
import com.mogo.module.v2x.R;
|
import com.mogo.module.v2x.R;
|
||||||
import com.mogo.module.v2x.entity.panel.V2XShareEventDescription;
|
import com.mogo.module.v2x.entity.panel.V2XShareEventDescription;
|
||||||
import com.mogo.module.v2x.entity.panel.V2XShareEventItem;
|
import com.mogo.module.v2x.entity.panel.V2XShareEventItem;
|
||||||
@@ -90,7 +91,7 @@ public class V2XShareEventAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
if (likeNum != null) {
|
if (likeNum != null) {
|
||||||
((shareDescriptionViewHolder) holder).approveNumTextView.setText(likeNum);
|
((shareDescriptionViewHolder) holder).approveNumTextView.setText(likeNum);
|
||||||
}
|
}
|
||||||
((shareDescriptionViewHolder) holder).ratingBar.setRating((float) enthusiasmIndex);
|
((shareDescriptionViewHolder) holder).ratingBar.setRating((float) 2.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (holder instanceof shareItemViewHolder) {
|
} else if (holder instanceof shareItemViewHolder) {
|
||||||
@@ -171,7 +172,7 @@ public class V2XShareEventAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
class shareDescriptionViewHolder extends RecyclerView.ViewHolder {
|
class shareDescriptionViewHolder extends RecyclerView.ViewHolder {
|
||||||
private TextView shareNumTextView;
|
private TextView shareNumTextView;
|
||||||
private TextView approveNumTextView;
|
private TextView approveNumTextView;
|
||||||
private RatingBar ratingBar;
|
private CustomRatingBar ratingBar;
|
||||||
|
|
||||||
public shareDescriptionViewHolder(@NonNull View itemView) {
|
public shareDescriptionViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|||||||
@@ -105,12 +105,10 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="@dimen/v2x_index_rating_top">
|
android:paddingTop="@dimen/v2x_index_rating_top">
|
||||||
|
|
||||||
<RatingBar
|
<com.mogo.module.common.view.CustomRatingBar
|
||||||
android:id="@+id/rating_bar"
|
android:id="@+id/rating_bar"
|
||||||
style="@style/customHeartHeartRatingBarStyle"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:isIndicator="true" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/share_index_des"
|
android:id="@+id/share_index_des"
|
||||||
|
|||||||
Reference in New Issue
Block a user