|
|
@@ -1,8 +1,24 @@
|
|
|
package com.kfzs.cfyl.media.fragment;
|
|
|
|
|
|
|
|
|
+import android.graphics.Color;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.graphics.drawable.GradientDrawable;
|
|
|
+import android.support.v7.widget.GridLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.BaseViewHolder;
|
|
|
import com.kfzs.cfyl.media.BaseFragment;
|
|
|
import com.kfzs.cfyl.media.R;
|
|
|
+import com.kfzs.cfyl.media.util.ListUtil;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import rx.functions.Action1;
|
|
|
|
|
|
/**
|
|
|
* Created by realicing on 2018/12/20.
|
|
|
@@ -11,10 +27,81 @@ import com.kfzs.cfyl.media.R;
|
|
|
public class FgtColorList extends BaseFragment {
|
|
|
@Override
|
|
|
public int getLayoutId() {
|
|
|
- return R.layout.media_common_rv;
|
|
|
+ return R.layout.media_fgt_color_list;
|
|
|
}
|
|
|
|
|
|
+ private RecyclerView media_recyclerView;
|
|
|
+ private List<Integer> list = new ArrayList<>();
|
|
|
+ private List<Integer> colorList = new ArrayList<>();
|
|
|
+ private int curPosition;
|
|
|
@Override
|
|
|
public void onViewCreated() {
|
|
|
+ tryInitList();
|
|
|
+ media_recyclerView = findViewById(R.id.media_recyclerView);
|
|
|
+ media_recyclerView.setLayoutManager(new GridLayoutManager(media_recyclerView.getContext(), list.size()));
|
|
|
+ final BaseQuickAdapter<Integer, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<Integer, BaseViewHolder>(R.layout.media_item_color, list) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void convert(BaseViewHolder helper, Integer item) {
|
|
|
+ int position = helper.getAdapterPosition();
|
|
|
+ if(position == curPosition) {
|
|
|
+ helper.setBackgroundRes(R.id.media_item_color_out_iv, R.drawable.media_shape_ring_white);
|
|
|
+ } else {
|
|
|
+ helper.setBackgroundColor(R.id.media_item_color_out_iv, Color.TRANSPARENT);
|
|
|
+ }
|
|
|
+ helper.setBackgroundRes(R.id.media_item_color_in_iv, item);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ baseQuickAdapter.bindToRecyclerView(media_recyclerView);
|
|
|
+ baseQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
|
|
+ selectPosition(position);
|
|
|
+ int lastPosition = curPosition;
|
|
|
+ curPosition = position;
|
|
|
+ if(lastPosition != curPosition){
|
|
|
+ baseQuickAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void selectPosition(int position) {
|
|
|
+ Integer item = ListUtil.getItem(colorList, position);
|
|
|
+ if(item != null){
|
|
|
+ if(selectColorAction1 != null){
|
|
|
+ selectColorAction1.call(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Action1<Integer> selectColorAction1;
|
|
|
+ public FgtColorList loadData(Action1<Integer> selectColorAction1){
|
|
|
+ this.selectColorAction1 = selectColorAction1;
|
|
|
+ tryInitList();
|
|
|
+ selectPosition(curPosition);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void tryInitList() {
|
|
|
+ if(list.isEmpty()){
|
|
|
+ list.add(R.drawable.media_shape_oval_white);
|
|
|
+ list.add(R.drawable.media_shape_oval_black);
|
|
|
+ list.add(R.drawable.media_shape_oval_red_ff1d11);
|
|
|
+ list.add(R.drawable.media_shape_oval_fbf606);
|
|
|
+ list.add(R.drawable.media_shape_oval_14e213);
|
|
|
+ list.add(R.drawable.media_shape_oval_1b9bff);
|
|
|
+ list.add(R.drawable.media_shape_oval_8c05ff);
|
|
|
+ }
|
|
|
+ if(colorList.isEmpty()){
|
|
|
+ colorList.add(Color.WHITE);
|
|
|
+ colorList.add(Color.BLACK);
|
|
|
+ colorList.add(Color.parseColor("#ff1d11"));
|
|
|
+ colorList.add(Color.parseColor("#fbf606"));
|
|
|
+ colorList.add(Color.parseColor("#14e213"));
|
|
|
+ colorList.add(Color.parseColor("#1b9bff"));
|
|
|
+ colorList.add(Color.parseColor("#8c05ff"));
|
|
|
+ }
|
|
|
}
|
|
|
}
|