Add icon and colours to quick chat settings

pull/462/head
Douile 2022-08-16 12:25:10 +01:00
rodzic 01e24ff6a4
commit b1b554d97d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DC9D70626CEF33D0
5 zmienionych plików z 81 dodań i 12 usunięć

Wyświetl plik

@ -5,12 +5,13 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.geeksville.mesh.R
import com.geeksville.mesh.database.entity.QuickChatAction
class QuickChatActionAdapter internal constructor(
context: Context,
private val context: Context,
private val onEdit: (action: QuickChatAction) -> Unit,
private val repositionAction: (fromPos: Int, toPos: Int) -> Unit,
private val commitAction: () -> Unit,
@ -20,9 +21,11 @@ class QuickChatActionAdapter internal constructor(
private var actions = emptyList<QuickChatAction>()
inner class ActionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val container: View = itemView.findViewById(R.id.quickChatActionContainer)
val actionName: TextView = itemView.findViewById(R.id.quickChatActionName)
val actionValue: TextView = itemView.findViewById(R.id.quickChatActionValue)
val actionEdit: View = itemView.findViewById(R.id.quickChatActionEdit)
val actionInstant: View = itemView.findViewById(R.id.quickChatActionInstant)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ActionViewHolder {
@ -34,12 +37,18 @@ class QuickChatActionAdapter internal constructor(
val current = actions[position]
holder.actionName.text = current.name
holder.actionValue.text = current.message
val isInstant = current.mode == QuickChatAction.Mode.Instant
holder.actionInstant.visibility = if (isInstant) View.VISIBLE else View.INVISIBLE
if (isInstant) {
holder.container.backgroundTintList = ContextCompat.getColorStateList(context, R.color.colorMyMsg)
} else {
holder.container.backgroundTintList = null
}
holder.actionEdit.setOnClickListener {
onEdit(current)
}
}
internal fun setActions(actions: List<QuickChatAction>) {
this.actions = actions
notifyDataSetChanged()

Wyświetl plik

@ -6,6 +6,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.asLiveData
@ -65,7 +68,9 @@ class QuickChatSettingsFragment : ScreenFragment("Quick Chat settings"), Logging
val builder = createEditDialog(requireContext(), "Edit quick chat")
builder.nameInput.setText(action.name)
builder.messageInput.setText(action.message)
builder.modeSwitch.isChecked = action.mode == QuickChatAction.Mode.Instant
val isInstant = action.mode == QuickChatAction.Mode.Instant
builder.modeSwitch.isChecked = isInstant
builder.instantImage.visibility = if (isInstant) View.VISIBLE else View.INVISIBLE
builder.builder.setNegativeButton(R.string.delete) { _, _ ->
model.deleteQuickChatAction(action)
@ -110,7 +115,8 @@ class QuickChatSettingsFragment : ScreenFragment("Quick Chat settings"), Logging
val builder: MaterialAlertDialogBuilder,
val nameInput: EditText,
val messageInput: EditText,
val modeSwitch: SwitchMaterial
val modeSwitch: SwitchMaterial,
val instantImage: ImageView
) {
fun isNotEmpty(): Boolean = nameInput.text.isNotEmpty() and messageInput.text.isNotEmpty()
}
@ -137,11 +143,19 @@ class QuickChatSettingsFragment : ScreenFragment("Quick Chat settings"), Logging
val nameInput: EditText = layout.findViewById(R.id.addQuickChatName)
val messageInput: EditText = layout.findViewById(R.id.addQuickChatMessage)
val modeSwitch: SwitchMaterial = layout.findViewById(R.id.addQuickChatMode)
val instantImage: ImageView = layout.findViewById(R.id.addQuickChatInsant)
instantImage.visibility = if (modeSwitch.isChecked) View.VISIBLE else View.INVISIBLE
var nameHasChanged = false
modeSwitch.setOnCheckedChangeListener { _, _ ->
modeSwitch.setText(if (modeSwitch.isChecked) R.string.mode_instant else R.string.mode_append)
if (modeSwitch.isChecked) {
modeSwitch.setText(R.string.mode_instant)
instantImage.visibility = View.VISIBLE
} else {
modeSwitch.setText(R.string.mode_append)
instantImage.visibility = View.INVISIBLE
}
}
messageInput.addTextChangedListener { text ->
@ -156,6 +170,6 @@ class QuickChatSettingsFragment : ScreenFragment("Quick Chat settings"), Logging
builder.setView(layout)
return DialogBuilder(builder, nameInput, messageInput, modeSwitch)
return DialogBuilder(builder, nameInput, messageInput, modeSwitch, instantImage)
}
}

Wyświetl plik

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M4,18l8.5,-6L4,6v12zM13,6v12l8.5,-6L13,6z"/>
</vector>

Wyświetl plik

@ -8,6 +8,7 @@
<com.google.android.material.card.MaterialCardView
style="@style/Widget.App.CardView"
android:id="@+id/quickChatActionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
@ -16,6 +17,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/quickChatActionInstant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_fast_forward_24" />
<TextView
android:id="@+id/quickChatActionName"
android:layout_width="wrap_content"
@ -23,7 +34,7 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/quickChatActionInstant"
app:layout_constraintTop_toTopOf="parent" />
<TextView
@ -34,7 +45,7 @@
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/quickChatActionInstant"
app:layout_constraintTop_toBottomOf="@+id/quickChatActionName" />
<ImageButton

Wyświetl plik

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -25,11 +27,39 @@
android:inputType="textShortMessage"
android:minHeight="48dp" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/addQuickChatMode"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/mode_append" />
android:orientation="horizontal">
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/addQuickChatInsant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_fast_forward_24" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/addQuickChatMode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="@string/mode_append"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/addQuickChatInsant"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>