display pet name in menu popup

This commit is contained in:
Phillip Thelen 2020-07-13 17:28:26 +02:00
parent 241599a785
commit 2dbbac0b41
3 changed files with 31 additions and 8 deletions

View file

@ -1,7 +1,23 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/BottomMenu" style="@style/BottomMenu"
android:clickable="false"> android:clickable="false">
<TextView
android:id="@+id/title_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Title"
android:gravity="center"
style="@style/Subheader1"
android:background="@color/gray_700"
android:padding="8dp"/>
<LinearLayout
android:id="@+id/menu_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout> </LinearLayout>

View file

@ -58,7 +58,7 @@
<dimen name="row_title_bottommargin">2dp</dimen> <dimen name="row_title_bottommargin">2dp</dimen>
<dimen name="pet_width">84dp</dimen> <dimen name="pet_width">84dp</dimen>
<dimen name="mount_width">120dp</dimen> <dimen name="mount_width">120dp</dimen>
<dimen name="bottom_menu_padding">28dp</dimen> <dimen name="bottom_menu_padding">20dp</dimen>
<dimen name="pet_image_width">68dp</dimen> <dimen name="pet_image_width">68dp</dimen>
<dimen name="pet_image_height">65dp</dimen> <dimen name="pet_image_height">65dp</dimen>
<dimen name="mount_image_width">81dp</dimen> <dimen name="mount_image_width">81dp</dimen>

View file

@ -5,13 +5,15 @@ import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.habitrpg.android.habitica.R import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.databinding.MenuBottomSheetBinding
class BottomSheetMenu(context: Context) : BottomSheetDialog(context), View.OnClickListener { class BottomSheetMenu(context: Context) : BottomSheetDialog(context), View.OnClickListener {
private var contentView = layoutInflater.inflate(R.layout.menu_bottom_sheet, null) as LinearLayout private var binding = MenuBottomSheetBinding.inflate(layoutInflater)
private var runnable: ((Int) -> Unit)? = null private var runnable: ((Int) -> Unit)? = null
init { init {
setContentView(contentView) setContentView(binding.root)
binding.titleView.visibility = View.GONE
} }
fun setSelectionRunnable(runnable: (Int) -> Unit) { fun setSelectionRunnable(runnable: (Int) -> Unit) {
@ -24,19 +26,24 @@ class BottomSheetMenu(context: Context) : BottomSheetDialog(context), View.OnCli
} }
} }
override fun setTitle(title: CharSequence?) {
binding.titleView.text = title
binding.titleView.visibility = View.VISIBLE
}
fun addMenuItem(menuItem: BottomSheetMenuItem) { fun addMenuItem(menuItem: BottomSheetMenuItem) {
val item = menuItem.inflate(this.context, layoutInflater, this.contentView) val item = menuItem.inflate(this.context, layoutInflater, this.binding.menuItems)
item.setOnClickListener(this) item.setOnClickListener(this)
this.contentView.addView(item) this.binding.menuItems.addView(item)
} }
fun removeMenuItem(index: Int) { fun removeMenuItem(index: Int) {
this.contentView.removeViewAt(index) this.binding.menuItems.removeViewAt(index)
} }
override fun onClick(v: View) { override fun onClick(v: View) {
if (this.runnable != null) { if (this.runnable != null) {
val index = this.contentView.indexOfChild(v) val index = this.binding.menuItems.indexOfChild(v)
if (index != -1) { if (index != -1) {
runnable?.let { it(index) } runnable?.let { it(index) }
this.dismiss() this.dismiss()