parent
f45c3facfd
commit
e077a3f4c5
@ -1,24 +1,49 @@
|
||||
package dev.lowrespalmtree.comet
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.lowrespalmtree.comet.Identities.Identity
|
||||
import dev.lowrespalmtree.comet.databinding.FragmentIdentityBinding
|
||||
import dev.lowrespalmtree.comet.utils.getFancySelectBgRes
|
||||
|
||||
class IdentitiesAdapter : RecyclerView.Adapter<HistoryAdapter.ViewHolder>() {
|
||||
class IdentitiesAdapter(private val listener: Listener) :
|
||||
RecyclerView.Adapter<IdentitiesAdapter.ViewHolder>() {
|
||||
private var identities = listOf<Identity>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryAdapter.ViewHolder {
|
||||
TODO("Not yet implemented")
|
||||
interface Listener {
|
||||
fun onIdentityClick(identity: Identity)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: HistoryAdapter.ViewHolder, position: Int) {
|
||||
TODO("Not yet implemented")
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
|
||||
ViewHolder(
|
||||
FragmentIdentityBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val item = identities[position]
|
||||
holder.binding.labelText.text = item.name.orEmpty()
|
||||
holder.binding.keyText.text = item.key
|
||||
holder.binding.container.setOnClickListener { listener.onIdentityClick(item) }
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
TODO("Not yet implemented")
|
||||
override fun getItemCount(): Int = identities.size
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun setIdentities(newIdentities: List<Identity>) {
|
||||
identities = newIdentities.toList()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inner class ViewHolder(val binding: FragmentIdentityBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
inner class ViewHolder(val binding: FragmentIdentityBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
itemView.setBackgroundResource(getFancySelectBgRes(itemView.context))
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package dev.lowrespalmtree.comet
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import dev.lowrespalmtree.comet.databinding.DialogIdentityBinding
|
||||
|
||||
class IdentityDialog(
|
||||
private val context: Context,
|
||||
private val identity: Identities.Identity,
|
||||
private val listener: Listener
|
||||
) {
|
||||
private lateinit var binding: DialogIdentityBinding
|
||||
|
||||
interface Listener {
|
||||
fun onSaveIdentity(identity: Identities.Identity)
|
||||
}
|
||||
|
||||
fun show() {
|
||||
binding = DialogIdentityBinding.inflate(LayoutInflater.from(context))
|
||||
binding.labelInput.setText(identity.name)
|
||||
binding.aliasText.text = identity.key
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle(R.string.edit_identity)
|
||||
.setView(binding.root)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
identity.name = binding.labelInput.text.toString()
|
||||
listener.onSaveIdentity(identity)
|
||||
}
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package dev.lowrespalmtree.comet
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import dev.lowrespalmtree.comet.Identities.Identity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
class IdentityEditorFragment : PreferenceFragmentCompat() {
|
||||
private val vm: IdentityEditorViewModel by viewModels()
|
||||
private lateinit var namePref: EditTextPreference
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.identity_preferences, rootKey)
|
||||
namePref = findPreference<EditTextPreference>("name")!!
|
||||
|
||||
// vm.identity.observe(viewLifecycleOwner) {
|
||||
// namePref.apply {
|
||||
// // TODO
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// arguments?.getLong("id")?.also { vm.loadIdentity(it) }
|
||||
}
|
||||
|
||||
class IdentityEditorViewModel : ViewModel() {
|
||||
val identity: MutableLiveData<Identity> by lazy { MutableLiveData<Identity>() }
|
||||
|
||||
fun loadIdentity(id: Long) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
identity.postValue(Identities.get(id))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package dev.lowrespalmtree.comet
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
|
||||
fun toast(context: Context, stringId: Int, length: Int = Toast.LENGTH_SHORT) =
|
||||
Toast.makeText(context, stringId, length).show()
|
@ -1,4 +1,4 @@
|
||||
package dev.lowrespalmtree.comet
|
||||
package dev.lowrespalmtree.comet.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
@ -0,0 +1,18 @@
|
||||
package dev.lowrespalmtree.comet.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.AttrRes
|
||||
import dev.lowrespalmtree.comet.R
|
||||
|
||||
fun toast(context: Context, stringId: Int, length: Int = Toast.LENGTH_SHORT) =
|
||||
Toast.makeText(context, stringId, length).show()
|
||||
|
||||
fun getDrawableFromAttr(context: Context, @AttrRes attr: Int) =
|
||||
TypedValue()
|
||||
.apply { context.theme.resolveAttribute(attr, this, true) }
|
||||
.resourceId
|
||||
|
||||
fun getFancySelectBgRes(context: Context) =
|
||||
getDrawableFromAttr(context, R.attr.selectableItemBackground)
|
@ -1,4 +1,4 @@
|
||||
package dev.lowrespalmtree.comet
|
||||
package dev.lowrespalmtree.comet.utils
|
||||
|
||||
import android.net.Uri
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/identity_name" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/labelInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/identity_name"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="text" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/identity_alias_title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/aliasText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textIsSelectable="true" />
|
||||
|
||||
</LinearLayout>
|
@ -1,43 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/card"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_margin="4dp"
|
||||
app:cardCornerRadius="4dp"
|
||||
app:cardElevation="4dp"
|
||||
android:foreground="?android:selectableItemBackground">
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<TextView
|
||||
android:id="@+id/uriText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text"
|
||||
android:layout_margin="8dp"
|
||||
android:fontFamily="@font/preformatted"
|
||||
android:typeface="monospace" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/uriText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/text"
|
||||
android:layout_margin="8dp"
|
||||
android:fontFamily="@font/preformatted"
|
||||
android:typeface="monospace" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/titleText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/text"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/titleText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/text"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
</LinearLayout>
|
@ -1,21 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/card"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_margin="4dp"
|
||||
app:cardCornerRadius="4dp"
|
||||
app:cardElevation="4dp"
|
||||
android:foreground="?android:selectableItemBackground">
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<TextView
|
||||
android:id="@+id/labelText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/text" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<TextView
|
||||
android:id="@+id/keyText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/text_light"
|
||||
android:fontFamily="@font/preformatted"
|
||||
android:typeface="monospace" />
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
</LinearLayout>
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:persistent="false">
|
||||
|
||||
<EditTextPreference
|
||||
android:key="name"
|
||||
android:title="@string/identity_name"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<Preference
|
||||
android:key="key_setup"
|
||||
android:title="@string/identity_key_setup" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in new issue