parent
							
								
									3ff98e534b
								
							
						
					
					
						commit
						67f882f2bc
					
				| @ -0,0 +1,101 @@ | ||||
| package io.legado.app.ui.widget | ||||
| 
 | ||||
| import android.content.Context | ||||
| import android.util.AttributeSet | ||||
| import android.view.Gravity | ||||
| import android.view.Menu | ||||
| import android.view.View | ||||
| import androidx.annotation.MenuRes | ||||
| import androidx.annotation.StringRes | ||||
| import androidx.appcompat.widget.LinearLayoutCompat | ||||
| import androidx.appcompat.widget.PopupMenu | ||||
| import io.legado.app.R | ||||
| import io.legado.app.utils.dp | ||||
| import io.legado.app.utils.visible | ||||
| import kotlinx.android.synthetic.main.view_select_action_bar.view.* | ||||
| import org.jetbrains.anko.sdk27.listeners.onClick | ||||
| 
 | ||||
| class SelectActionBar(context: Context, attrs: AttributeSet?) : LinearLayoutCompat(context, attrs) { | ||||
|     private var callBack: CallBack? = null | ||||
|     private var selMenu: PopupMenu? = null | ||||
| 
 | ||||
|     init { | ||||
|         setBackgroundResource(R.color.background_menu) | ||||
|         setPadding(16.dp, 6.dp, 16.dp, 6.dp) | ||||
|         gravity = Gravity.CENTER_VERTICAL | ||||
|         View.inflate(context, R.layout.view_select_action_bar, this) | ||||
|         cb_selected_all.setOnCheckedChangeListener { buttonView, isChecked -> | ||||
|             if (buttonView.isPressed) { | ||||
|                 callBack?.selectAll(isChecked) | ||||
|             } | ||||
|         } | ||||
|         btn_revert_selection.onClick { callBack?.revertSelection() } | ||||
|         btn_select_action_main.onClick { callBack?.onClickMainAction() } | ||||
|         iv_menu_more.onClick { selMenu?.show() } | ||||
|     } | ||||
| 
 | ||||
|     fun setMainActionText(text: String) { | ||||
|         btn_select_action_main.text = text | ||||
|         btn_select_action_main.visible() | ||||
|     } | ||||
| 
 | ||||
|     fun setMainActionText(@StringRes id: Int) { | ||||
|         btn_select_action_main.setText(id) | ||||
|         btn_select_action_main.visible() | ||||
|     } | ||||
| 
 | ||||
|     fun inflateMenu(@MenuRes resId: Int): Menu? { | ||||
|         selMenu = PopupMenu(context, iv_menu_more) | ||||
|         selMenu?.inflate(resId) | ||||
|         iv_menu_more.visible() | ||||
|         return selMenu?.menu | ||||
|     } | ||||
| 
 | ||||
|     fun setCallBack(callBack: CallBack) { | ||||
|         this.callBack = callBack | ||||
|     } | ||||
| 
 | ||||
|     fun setOnMenuItemClickListener(listener: PopupMenu.OnMenuItemClickListener) { | ||||
|         selMenu?.setOnMenuItemClickListener(listener) | ||||
|     } | ||||
| 
 | ||||
|     fun upCountView(selectCount: Int, allCount: Int) { | ||||
|         if (selectCount == 0) { | ||||
|             cb_selected_all.isChecked = false | ||||
|         } else { | ||||
|             cb_selected_all.isChecked = selectCount >= allCount | ||||
|         } | ||||
| 
 | ||||
|         //重置全选的文字 | ||||
|         if (cb_selected_all.isChecked) { | ||||
|             cb_selected_all.text = context.getString( | ||||
|                 R.string.select_cancel_count, | ||||
|                 selectCount, | ||||
|                 allCount | ||||
|             ) | ||||
|         } else { | ||||
|             cb_selected_all.text = context.getString( | ||||
|                 R.string.select_all_count, | ||||
|                 selectCount, | ||||
|                 allCount | ||||
|             ) | ||||
|         } | ||||
|         setMenuClickable(selectCount > 0) | ||||
|     } | ||||
| 
 | ||||
|     private fun setMenuClickable(isClickable: Boolean) { | ||||
|         btn_revert_selection.isEnabled = isClickable | ||||
|         btn_revert_selection.isClickable = isClickable | ||||
|         btn_select_action_main.isEnabled = isClickable | ||||
|         btn_select_action_main.isClickable = isClickable | ||||
|     } | ||||
| 
 | ||||
|     interface CallBack { | ||||
| 
 | ||||
|         fun selectAll(selectAll: Boolean) | ||||
| 
 | ||||
|         fun revertSelection() | ||||
| 
 | ||||
|         fun onClickMainAction() {} | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,50 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <merge xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:orientation="horizontal" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="wrap_content" | ||||
|     android:elevation="2dp"> | ||||
| 
 | ||||
|     <io.legado.app.lib.theme.view.ATECheckBox | ||||
|         android:id="@+id/cb_selected_all" | ||||
|         android:layout_width="0dp" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_weight="1" | ||||
|         android:padding="5dp" | ||||
|         android:text="@string/select_all_count" | ||||
|         android:textColor="@color/tv_text_default" /> | ||||
| 
 | ||||
|     <io.legado.app.lib.theme.view.ATEAccentStrokeTextView | ||||
|         android:id="@+id/btn_revert_selection" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_margin="5dp" | ||||
|         android:padding="5dp" | ||||
|         android:gravity="center" | ||||
|         android:minWidth="80dp" | ||||
|         android:text="@string/revert_selection" /> | ||||
| 
 | ||||
|     <io.legado.app.lib.theme.view.ATEAccentStrokeTextView | ||||
|         android:id="@+id/btn_select_action_main" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_margin="5dp" | ||||
|         android:padding="5dp" | ||||
|         android:minWidth="80dp" | ||||
|         android:gravity="center" | ||||
|         android:visibility="gone" | ||||
|         android:text="@string/app_name" /> | ||||
| 
 | ||||
|     <androidx.appcompat.widget.AppCompatImageView | ||||
|         android:id="@+id/iv_menu_more" | ||||
|         android:layout_width="36dp" | ||||
|         android:layout_height="36dp" | ||||
|         android:background="?attr/selectableItemBackgroundBorderless" | ||||
|         android:padding="6dp" | ||||
|         android:src="@drawable/ic_more_vert" | ||||
|         android:tint="@color/tv_text_default" | ||||
|         android:visibility="gone" | ||||
|         tools:ignore="RtlHardcoded" /> | ||||
| 
 | ||||
| </merge> | ||||
					Loading…
					
					
				
		Reference in new issue