ThxSelectView.java 5.69 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10
package com.yidianling.dynamic.thank.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

万齐军 committed
11
import androidx.annotation.NonNull;
konghaorui committed
12 13 14 15 16 17 18 19 20 21 22 23

import com.yidianling.dynamic.R;
import com.yidianling.dynamic.thank.ThxStarMoney;

import java.util.List;

/**
 * 感谢的选择器
 * Created by softrice on 15/12/3.
 */
public class ThxSelectView extends LinearLayout {

万齐军 committed
24 25 26 27 28 29 30 31 32 33 34
    private LinearLayout ll_left;
    private TextView tv_left_up;
    private TextView tv_left_down;

    private LinearLayout ll_center;
    private TextView tv_center_up;
    private TextView tv_center_down;

    private LinearLayout ll_right;
    private TextView tv_right_up;
    private TextView tv_right_down;
konghaorui committed
35 36 37 38 39 40 41 42 43 44

    int selectId = -1;

    int selectColor = 0xFFEB5835;
    int disSelectColor = Color.WHITE;

    List<ThxStarMoney> star_money;

    public ThxSelectView(Context context) {
        super(context);
konghaorui committed
45
        inflate(context, R.layout.dynamic_ui_thx_select, this);
万齐军 committed
46
        bindView(this);
konghaorui committed
47 48 49 50 51
    }


    public ThxSelectView(Context context, AttributeSet attrs) {
        super(context, attrs);
konghaorui committed
52
        inflate(context, R.layout.dynamic_ui_thx_select, this);
万齐军 committed
53
        bindView(this);
konghaorui committed
54 55 56 57
    }

    public void select(int position) {
        if (position >= 0 && position < 3) {
konghaorui committed
58
            Drawable drawable = getResources().getDrawable(R.drawable.dynamic_love_white);
konghaorui committed
59 60 61 62
            cleanSelect();
            selectId = position;
            switch (position) {
                case 0:
konghaorui committed
63
                    ll_left.setBackgroundResource(R.drawable.dynamic_shape_red_bg);
konghaorui committed
64 65 66 67 68 69
                    tv_left_down.setTextColor(disSelectColor);
                    tv_left_up.setTextColor(disSelectColor);
                    tv_left_up.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
                    break;

                case 1:
konghaorui committed
70
                    ll_center.setBackgroundResource(R.drawable.dynamic_shape_red_bg);
konghaorui committed
71 72 73 74 75 76
                    tv_center_down.setTextColor(disSelectColor);
                    tv_center_up.setTextColor(disSelectColor);
                    tv_center_up.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
                    break;

                case 2:
konghaorui committed
77
                    ll_right.setBackgroundResource(R.drawable.dynamic_shape_red_bg);
konghaorui committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
                    tv_right_down.setTextColor(disSelectColor);
                    tv_right_up.setTextColor(disSelectColor);
                    tv_right_up.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
                    break;
            }
        }
    }

    public int getSelectId() {
        return selectId;
    }

    public int getStarNum() {
        if (selectId != -1 && star_money != null && star_money.size() >= 3)
            return star_money.get(selectId).star_num;
        return 0;
    }

    public float getMoney() {
        if (selectId != -1 && star_money != null && star_money.size() >= 3)
            return star_money.get(selectId).money;
        return 0;
    }

    void cleanSelect() {
konghaorui committed
103 104
        Drawable drawable = getResources().getDrawable(R.drawable.dynamic_love_red);
        ll_left.setBackgroundResource(R.drawable.dynamic_shape_red_round);
konghaorui committed
105 106 107 108
        tv_left_down.setTextColor(selectColor);
        tv_left_up.setTextColor(selectColor);
        tv_left_up.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);

konghaorui committed
109
        ll_center.setBackgroundResource(R.drawable.dynamic_shape_red_round);
konghaorui committed
110 111 112 113
        tv_center_down.setTextColor(selectColor);
        tv_center_up.setTextColor(selectColor);
        tv_center_up.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);

konghaorui committed
114
        ll_right.setBackgroundResource(R.drawable.dynamic_shape_red_round);
konghaorui committed
115 116 117 118 119 120
        tv_right_down.setTextColor(selectColor);
        tv_right_up.setTextColor(selectColor);
        tv_right_up.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);

    }

万齐军 committed
121
    private void click(@NonNull View view) {
konghaorui committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        if (view.getId() == R.id.ll_left) {
            select(0);
        } else if (view.getId() == R.id.ll_center) {
            select(1);
        } else if (view.getId() == R.id.ll_right) {
            select(2);
        }


    }


    public void setData(List<ThxStarMoney> star_money) {
        this.star_money = star_money;
        if (star_money != null && star_money.size() >= 3) {
            tv_left_down.setText("价值" + star_money.get(0).money + "元");
            tv_left_up.setText("×" + star_money.get(0).star_num);

            tv_center_down.setText("价值" + star_money.get(1).money + "元");
            tv_center_up.setText("×" + star_money.get(1).star_num);

            tv_right_down.setText("价值" + star_money.get(2).money + "元");
            tv_right_up.setText("×" + star_money.get(2).star_num);
        }
    }
万齐军 committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

    private void bindView(View bindSource) {
        ll_left = bindSource.findViewById(R.id.ll_left);
        tv_left_up = bindSource.findViewById(R.id.tv_left_up);
        tv_left_down = bindSource.findViewById(R.id.tv_left_down);
        ll_center = bindSource.findViewById(R.id.ll_center);
        tv_center_up = bindSource.findViewById(R.id.tv_center_up);
        tv_center_down = bindSource.findViewById(R.id.tv_center_down);
        ll_right = bindSource.findViewById(R.id.ll_right);
        tv_right_up = bindSource.findViewById(R.id.tv_right_up);
        tv_right_down = bindSource.findViewById(R.id.tv_right_down);
        ll_left.setOnClickListener(v -> {
            click(v);
        });
        ll_center.setOnClickListener(v -> {
            click(v);
        });
        ll_right.setOnClickListener(v -> {
            click(v);
        });
    }
konghaorui committed
168
}