mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Improve: Optimize Repositories Page
This commit is contained in:
parent
32baac8f98
commit
f1cb882aaa
@ -4,7 +4,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
import com.google.android.material.textview.MaterialTextView
|
|
||||||
import com.looker.droidify.R
|
import com.looker.droidify.R
|
||||||
import com.looker.droidify.database.Database
|
import com.looker.droidify.database.Database
|
||||||
import com.looker.droidify.entity.Repository
|
import com.looker.droidify.entity.Repository
|
||||||
@ -19,8 +18,7 @@ class RepositoriesAdapter(
|
|||||||
enum class ViewType { REPOSITORY }
|
enum class ViewType { REPOSITORY }
|
||||||
|
|
||||||
private class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
private class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
val name = itemView.findViewById<MaterialTextView>(R.id.name)!!
|
val switch = itemView.findViewById<SwitchMaterial>(R.id.repository_switch)!!
|
||||||
val enabled = itemView.findViewById<SwitchMaterial>(R.id.enabled)!!
|
|
||||||
|
|
||||||
var listenSwitch = true
|
var listenSwitch = true
|
||||||
}
|
}
|
||||||
@ -42,11 +40,11 @@ class RepositoriesAdapter(
|
|||||||
): RecyclerView.ViewHolder {
|
): RecyclerView.ViewHolder {
|
||||||
return ViewHolder(parent.inflate(R.layout.repository_item)).apply {
|
return ViewHolder(parent.inflate(R.layout.repository_item)).apply {
|
||||||
itemView.setOnClickListener { onClick(getRepository(adapterPosition)) }
|
itemView.setOnClickListener { onClick(getRepository(adapterPosition)) }
|
||||||
enabled.setOnCheckedChangeListener { _, isChecked ->
|
switch.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if (listenSwitch) {
|
if (listenSwitch) {
|
||||||
if (!onSwitch(getRepository(adapterPosition), isChecked)) {
|
if (!onSwitch(getRepository(adapterPosition), isChecked)) {
|
||||||
listenSwitch = false
|
listenSwitch = false
|
||||||
enabled.isChecked = !isChecked
|
switch.isChecked = !isChecked
|
||||||
listenSwitch = true
|
listenSwitch = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,8 +57,8 @@ class RepositoriesAdapter(
|
|||||||
val repository = getRepository(position)
|
val repository = getRepository(position)
|
||||||
val lastListenSwitch = holder.listenSwitch
|
val lastListenSwitch = holder.listenSwitch
|
||||||
holder.listenSwitch = false
|
holder.listenSwitch = false
|
||||||
holder.enabled.isChecked = repository.enabled
|
holder.switch.isChecked = repository.enabled
|
||||||
holder.listenSwitch = lastListenSwitch
|
holder.listenSwitch = lastListenSwitch
|
||||||
holder.name.text = repository.name
|
holder.switch.text = repository.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.google.android.material.switchmaterial.SwitchMaterial xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="54dp"
|
android:layout_height="54dp"
|
||||||
|
android:id="@+id/repository_switch"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal"/>
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
|
||||||
android:id="@+id/name"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:textSize="16sp" />
|
|
||||||
|
|
||||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
|
||||||
android:id="@+id/enabled"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:paddingStart="12dp"
|
|
||||||
android:paddingEnd="12dp" />
|
|
||||||
|
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user