From f9dc122af5cdb2a90762ffaf934280a2a7a2caf8 Mon Sep 17 00:00:00 2001 From: choelzl Date: Fri, 7 Apr 2023 01:12:03 +0200 Subject: [PATCH] [m] UI & Cleaning --- .../beendroid/activity/FoldingListAdapter.kt | 54 ++++++++++++------- .../helcel/beendroid/activity/MainActivity.kt | 2 +- app/src/main/res/anim/slide.xml | 8 +++ .../main/res/drawable/chevron_right_solid.xml | 9 ++++ app/src/main/res/layout/activity_main.xml | 22 +++++--- app/src/main/res/layout/item_list.xml | 42 ++++++++++----- app/src/main/res/navigation/nav_graph.xml | 8 --- 7 files changed, 98 insertions(+), 47 deletions(-) create mode 100644 app/src/main/res/anim/slide.xml create mode 100644 app/src/main/res/drawable/chevron_right_solid.xml delete mode 100644 app/src/main/res/navigation/nav_graph.xml diff --git a/app/src/main/java/net/helcel/beendroid/activity/FoldingListAdapter.kt b/app/src/main/java/net/helcel/beendroid/activity/FoldingListAdapter.kt index 23c2308..8999fe6 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/FoldingListAdapter.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/FoldingListAdapter.kt @@ -5,7 +5,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.CheckBox +import android.widget.ImageView import android.widget.TextView +import androidx.appcompat.content.res.AppCompatResources import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import net.helcel.beendroid.R @@ -32,21 +34,27 @@ class FoldingListAdapter(private val ctx: Context, l: List) : override fun onBindViewHolder(holder: FoldingListViewHolder, position: Int) { val el = cg.toList()[position] holder.bind(el) - holder.itemView.setOnClickListener { - holder.checkBox.toggle() - } - holder.itemView.setOnLongClickListener { - if (el.second) { - cg[el.first] = false - }else { - cg.forEach { - cg[it.key] = it.key == el.first - } + holder.textView.setOnClickListener { holder.checkBox.toggle() } + + val expandLambda = { _:View -> + if (el.first.children.isEmpty() || el.first.type == LocType.STATE) { + false + } else { + cg[el.first] = !el.second + if (!el.second) + cg.filter { (it.key != el.first) && (cg[it.key] == true) }.keys.forEach { + cg[it] = false + notifyItemChanged(cg.toList().map { e -> e.first }.indexOf(it)) + } + + notifyItemChanged(position) + true } - notifyItemChanged(position) - true + } + holder.itemView.setOnLongClickListener(expandLambda) + holder.expand.setOnClickListener { expandLambda(it) } } override fun getItemCount(): Int { @@ -54,24 +62,34 @@ class FoldingListAdapter(private val ctx: Context, l: List) : } class FoldingListViewHolder(private val ctx: Context, itemView: View) : RecyclerView.ViewHolder(itemView) { - private val textView: TextView + val textView: TextView + val expand: ImageView val checkBox: CheckBox private val subItemView: View + private val list: RecyclerView init { textView = itemView.findViewById(R.id.textView) + expand = itemView.findViewById(R.id.expand) + expand.setImageDrawable(AppCompatResources.getDrawable(ctx,R.drawable.chevron_right_solid)) checkBox = itemView.findViewById(R.id.checkBox) subItemView = itemView.findViewById(R.id.sub_item) + list = itemView.findViewById(R.id.list_list) + list.layoutManager = LinearLayoutManager(ctx, RecyclerView.VERTICAL, false) + } fun bind(el: Pair) { + expand.rotation = if(el.second) 90f else 0f subItemView.visibility = if (el.second) View.VISIBLE else View.GONE - textView.text = el.first.fullName - if(el.first.type == LocType.STATE || el.first.children.isEmpty()) - return - val list: RecyclerView = itemView.findViewById(R.id.list_list) - list.layoutManager = LinearLayoutManager(ctx, RecyclerView.VERTICAL, false) + + textView.text = el.first.fullName + if(el.first.type == LocType.STATE || el.first.children.isEmpty()){ + expand.visibility = View.GONE + return + } + textView.parent.parent.requestChildFocus(textView,textView) list.adapter = FoldingListAdapter(ctx, el.first.children) } diff --git a/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt b/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt index 08b9a17..690a8b5 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt @@ -34,7 +34,7 @@ class MainActivity : AppCompatActivity() { val fm = cm.values.fold("") { acc, e -> acc + e.data } val svg = SVG.getFromString("$fm") - val bitmap = Bitmap.createBitmap(1200,1200, Bitmap.Config.ARGB_8888) + val bitmap = Bitmap.createBitmap(1200,900, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) canvas.drawRGB(255, 255, 255) diff --git a/app/src/main/res/anim/slide.xml b/app/src/main/res/anim/slide.xml new file mode 100644 index 0000000..b4c3a07 --- /dev/null +++ b/app/src/main/res/anim/slide.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/app/src/main/res/drawable/chevron_right_solid.xml b/app/src/main/res/drawable/chevron_right_solid.xml new file mode 100644 index 0000000..a66bef1 --- /dev/null +++ b/app/src/main/res/drawable/chevron_right_solid.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e55fe94..ea24711 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,15 +8,23 @@ - + android:layout_height="wrap_content" + android:layout_weight="1"> + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_list.xml b/app/src/main/res/layout/item_list.xml index fa6e36a..0f03410 100644 --- a/app/src/main/res/layout/item_list.xml +++ b/app/src/main/res/layout/item_list.xml @@ -9,33 +9,49 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + app:layout_constraintTop_toTopOf="parent" + tools:ignore="HardcodedText" /> - + + + app:layout_constraintBottom_toBottomOf="@id/checkBox" + app:layout_constraintEnd_toStartOf="@+id/checkBox" + app:layout_constraintStart_toEndOf="@+id/expand" + app:layout_constraintTop_toTopOf="@+id/expand" + app:layout_constraintVertical_bias="1.0" /> - - - \ No newline at end of file