Change default list height

This commit is contained in:
Rafał Borcz 2019-08-11 17:03:48 +02:00
parent d2379fe956
commit 0f30d1403a
4 changed files with 9 additions and 41 deletions

View file

@ -30,7 +30,7 @@ internal class DropdownListView : RecyclerView {
}
updateLayoutParams<FrameLayout.LayoutParams> {
val defaultHeight = context.dpToPx(144f).toInt()
val defaultHeight = context.dpToPx(116f).toInt()
val calculatedHeight = visibleRect.height() - (coordinators[1] + chipInput.height)
height = if (calculatedHeight < defaultHeight) defaultHeight else calculatedHeight

View file

@ -39,9 +39,4 @@ dependencies {
implementation "androidx.core:core-ktx:1.0.2"
implementation "com.google.android.material:material:1.1.0-alpha09"
implementation 'io.reactivex.rxjava2:rxjava:2.2.11'
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
}

View file

@ -1,52 +1,25 @@
package io.github.wulkanowy.materialchipsinput.sample
import android.Manifest.permission.READ_CONTACTS
import android.os.Bundle
import android.provider.ContactsContract.Contacts.CONTENT_URI
import android.provider.ContactsContract.Contacts.DISPLAY_NAME
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContentResolverCompat
import com.tbruyelle.rxpermissions2.RxPermissions
import io.github.wulkanowy.materialchipsinput.MaterialChipItem
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.subscribeBy
import kotlinx.android.synthetic.main.activity_main.*
import kotlin.random.Random
class MainActivity : AppCompatActivity() {
private var contactList: MutableList<ChipItem>? = null
private val disposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
contactList = mutableListOf()
disposable.add(RxPermissions(this)
.request(READ_CONTACTS)
.subscribeBy {
if (!it || contactList?.isNotEmpty() == true) return@subscribeBy
val list = mutableListOf<ChipItem>()
val contactsQuery = ContentResolverCompat.query(contentResolver, CONTENT_URI, null, null, null, null, null)
?: return@subscribeBy
repeat(30) {
list.add(ChipItem(Random.nextInt().toString(), Random.nextInt().toString()))
}
while (contactsQuery.moveToNext()) {
contactList?.add(ChipItem(
title = contactsQuery.run { getString(getColumnIndex(DISPLAY_NAME)) },
summary = ""
))
}
contactsQuery.close()
mainChipsInput.itemList = contactList ?: emptyList()
mainChipsInput.onTextChangeListener = { scroll.smoothScrollTo(0, scroll.bottom) }
})
}
override fun onDestroy() {
super.onDestroy()
disposable.clear()
mainChipsInput.itemList = list
mainChipsInput.onTextChangeListener = { scroll.smoothScrollTo(0, scroll.bottom) }
}
data class ChipItem(override val title: String, override val summary: String) : MaterialChipItem

View file

@ -36,7 +36,7 @@
<EditText
android:layout_width="match_parent"
android:layout_height="144dp"
android:layout_height="116dp"
android:background="@color/colorPrimary"
tools:ignore="Autofill,LabelFor,TextFields" />
</LinearLayout>