7 changed files with 367 additions and 91 deletions
			
			
		| @ -0,0 +1,134 @@ | |||||||
|  | package cc.niushuai.dididone.ui.component; | ||||||
|  | 
 | ||||||
|  | import android.content.Context; | ||||||
|  | import android.graphics.Color; | ||||||
|  | import android.view.View; | ||||||
|  | import android.widget.ImageView; | ||||||
|  | import android.widget.TextView; | ||||||
|  | 
 | ||||||
|  | import androidx.annotation.NonNull; | ||||||
|  | import androidx.recyclerview.widget.RecyclerView; | ||||||
|  | 
 | ||||||
|  | import com.lxj.easyadapter.EasyAdapter; | ||||||
|  | import com.lxj.easyadapter.MultiItemTypeAdapter; | ||||||
|  | import com.lxj.easyadapter.ViewHolder; | ||||||
|  | import com.lxj.xpopup.core.BottomPopupView; | ||||||
|  | import com.lxj.xpopup.util.XPopupUtils; | ||||||
|  | import com.lxj.xpopup.widget.VerticalRecyclerView; | ||||||
|  | import com.mikepenz.iconics.IconicsDrawable; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Comparator; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.function.Consumer; | ||||||
|  | 
 | ||||||
|  | import cc.niushuai.dididone.R; | ||||||
|  | import cc.niushuai.dididone.biz.BizGlobal; | ||||||
|  | import cc.niushuai.dididone.biz.entity.Project; | ||||||
|  | import cc.niushuai.dididone.util.Toasts; | ||||||
|  | import cn.hutool.core.collection.CollUtil; | ||||||
|  | import cn.hutool.core.util.StrUtil; | ||||||
|  | 
 | ||||||
|  | public class ProjectPopupView extends BottomPopupView { | ||||||
|  | 
 | ||||||
|  |     private VerticalRecyclerView recyclerView; | ||||||
|  |     private List<Project> data; | ||||||
|  |     private EasyAdapter<Project> commonAdapter; | ||||||
|  | 
 | ||||||
|  |     private Consumer<Project> callback; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     public ProjectPopupView(@NonNull Context context) { | ||||||
|  |         super(context); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public ProjectPopupView(@NonNull Context context, Consumer<Project> callback) { | ||||||
|  |         super(context); | ||||||
|  |         this.callback = callback; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected int getImplLayoutId() { | ||||||
|  |         return R.layout.project_popup_view; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected void onCreate() { | ||||||
|  |         super.onCreate(); | ||||||
|  | 
 | ||||||
|  |         recyclerView = findViewById(R.id.ppv_recyclerView); | ||||||
|  |         data = getProjectList(); | ||||||
|  |         int projectCount = data.size(); | ||||||
|  | 
 | ||||||
|  |         if (data.isEmpty()) { | ||||||
|  |             Project e = new Project(); | ||||||
|  |             e.setName("先去添加打卡项吧~"); | ||||||
|  |             e.setIcon("cmd_alert_decagram_outline"); | ||||||
|  |             e.setIconColor(Color.RED); | ||||||
|  |             data.add(e); | ||||||
|  |             projectCount = 0; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         ((TextView) findViewById(R.id.ppv_title)).setText(StrUtil.format("全部{}条打卡项", projectCount)); | ||||||
|  |         commonAdapter = new EasyAdapter<Project>(data, R.layout.project_popup_view_item) { | ||||||
|  |             @Override | ||||||
|  |             protected void bind(@NonNull ViewHolder holder, @NonNull Project item, final int position) { | ||||||
|  | 
 | ||||||
|  |                 Project project = data.get(position); | ||||||
|  | 
 | ||||||
|  |                 ImageView iconView = holder.getView(R.id.ppv_item_icon); | ||||||
|  |                 iconView.setImageDrawable( | ||||||
|  |                         new IconicsDrawable(getContext()) | ||||||
|  |                                 .icon(project.getIcon()) | ||||||
|  |                                 .color(project.getIconColor()) | ||||||
|  |                                 .sizeDp(50)); | ||||||
|  | 
 | ||||||
|  |                 TextView txtView = holder.getView(R.id.ppv_item_txt); | ||||||
|  |                 txtView.setText(project.getName()); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |         commonAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() { | ||||||
|  |             @Override | ||||||
|  |             public void onItemClick(@NonNull View view, @NonNull RecyclerView.ViewHolder viewHolder, int position) { | ||||||
|  | 
 | ||||||
|  |                 // 打卡
 | ||||||
|  |                 callback.accept(data.get(position)); | ||||||
|  | 
 | ||||||
|  |                 dismiss(); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             @Override | ||||||
|  |             public boolean onItemLongClick(@NonNull View view, @NonNull RecyclerView.ViewHolder viewHolder, int position) { | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         recyclerView.setAdapter(commonAdapter); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void newRecord(Project project) { | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private List<Project> getProjectList() { | ||||||
|  |         List<Project> list = CollUtil.list(false, BizGlobal.CACHE_PROJECT.values()); | ||||||
|  |         list.sort((e1, e2) -> e2.getCreateDate().compareTo(e1.getCreateDate())); | ||||||
|  |         return list; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected void onShow() { | ||||||
|  |         super.onShow(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected void onDismiss() { | ||||||
|  |         super.onDismiss(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected int getMaxHeight() { | ||||||
|  |         return (int) (XPopupUtils.getScreenHeight(getContext()) * .5f); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,30 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="wrap_content" | ||||||
|  |     android:background="@drawable/bg_miui10" | ||||||
|  |     android:maxHeight="500dp" | ||||||
|  |     android:orientation="vertical"> | ||||||
|  | 
 | ||||||
|  |     <com.google.android.material.appbar.AppBarLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:background="@drawable/bg_miui10"> | ||||||
|  | 
 | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/ppv_title" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:padding="20dp" | ||||||
|  |             android:text="全部1314条打卡项" | ||||||
|  |             android:textColor="#000" | ||||||
|  |             android:textSize="20sp" /> | ||||||
|  |     </com.google.android.material.appbar.AppBarLayout> | ||||||
|  | 
 | ||||||
|  |     <com.lxj.xpopup.widget.VerticalRecyclerView | ||||||
|  |         android:id="@+id/ppv_recyclerView" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="0dp" | ||||||
|  |         android:layout_weight="1" /> | ||||||
|  | 
 | ||||||
|  | </LinearLayout> | ||||||
| @ -0,0 +1,23 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     android:id="@+id/ppv_item_layout" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="wrap_content" | ||||||
|  |     android:padding="20dp"> | ||||||
|  | 
 | ||||||
|  |     <ImageView | ||||||
|  |         android:id="@+id/ppv_item_icon" | ||||||
|  |         android:layout_width="50dp" | ||||||
|  |         android:layout_height="50dp" | ||||||
|  |         android:layout_centerVertical="true" /> | ||||||
|  | 
 | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/ppv_item_txt" | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_centerVertical="true" | ||||||
|  |         android:layout_marginLeft="20dp" | ||||||
|  |         android:layout_toRightOf="@id/ppv_item_icon" | ||||||
|  |         android:textSize="14dp" /> | ||||||
|  | 
 | ||||||
|  | </RelativeLayout> | ||||||
					Loading…
					
					
				
		Reference in new issue