Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 663957b7 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Rewrite HomeSetAdapter so that it uses a Material-style text field instead of...

Rewrite HomeSetAdapter so that it uses a Material-style text field instead of an old-style Spinner that doesn't work with dark mode anymore
parent 23235991
Loading
Loading
Loading
Loading
+23 −16
Original line number Diff line number Diff line
@@ -6,37 +6,44 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Filter
import android.widget.TextView
import at.bitfire.davdroid.DavUtils
import at.bitfire.davdroid.R
import at.bitfire.davdroid.model.HomeSet

class HomeSetAdapter(
        context: Context
): ArrayAdapter<HomeSet>(context, android.R.layout.simple_list_item_2, android.R.id.text1) {
): ArrayAdapter<HomeSet>(context, R.layout.text_list_item, android.R.id.text1) {

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val data = getItem(position)!!

        val v: View
        if (!data.displayName.isNullOrBlank()) {
            v = convertView ?: LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_2, null, false)
            v.findViewById<TextView>(android.R.id.text1).text = data.displayName
            v.findViewById<TextView>(android.R.id.text2).apply {
                text = data.url.toString()
                setSingleLine()
                ellipsize = TextUtils.TruncateAt.START
            }
        } else {
            v = convertView ?: LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_1, null, false)
        v = convertView ?: LayoutInflater.from(context).inflate(R.layout.text_list_item, parent, false)
        v.findViewById<TextView>(android.R.id.text1).apply {
            text = data.displayName ?: DavUtils.lastSegmentOfUrl(data.url)
        }
        v.findViewById<TextView>(android.R.id.text2).apply {
            text = data.url.toString()
            setSingleLine()
            ellipsize = TextUtils.TruncateAt.START
        }
        }
        return v
    }

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup) =
            getView(position, convertView, parent)


    override fun getFilter() = object: Filter() {
        override fun convertResultToString(resultValue: Any?): CharSequence {
            val homeSet = resultValue as HomeSet
            return homeSet.url.toString()
        }
        override fun performFiltering(constraint: CharSequence?) = FilterResults()
        override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
        }
    }

}
 No newline at end of file
+11 −14
Original line number Diff line number Diff line
@@ -62,23 +62,20 @@
                    android:text="@={model.description}" />
            </com.google.android.material.textfield.TextInputLayout>

            <TextView
                android:id="@+id/homesets_title"
                android:labelFor="@id/homeset"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/create_collection_home_set"
                android:layout_marginTop="16dp"
                app:layout_constraintTop_toBottomOf="@+id/description"
                app:layout_constraintStart_toStartOf="parent" />
            <Spinner
            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/homeset"
                android:layout_width="wrap_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adapter="@{model.homeSets}"
                android:selectedItemPosition="@={model.idxHomeSet}"
                app:layout_constraintTop_toBottomOf="@+id/description"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/homesets_title" />
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                android:hint="@string/create_collection_home_set">
                <AutoCompleteTextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="none"
                    android:adapter="@{model.homeSets}"/>
            </com.google.android.material.textfield.TextInputLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>

+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:theme="@style/Theme.MaterialComponents.DayNight"
    android:padding="8dp">

    <TextView
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/TextAppearance.MaterialComponents.Body1"
        tools:text="Line 1"/>

    <TextView
        android:id="@android:id/text2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        style="@style/TextAppearance.MaterialComponents.Caption"
        tools:text="Line 2"/>

</LinearLayout>
 No newline at end of file