kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Use QuickChatAction model to add buttons in message fragment
Also fix replace the vertical scroll view with horizontalpull/462/head
rodzic
3c9e325d5c
commit
483eca94e9
|
@ -22,6 +22,7 @@ import com.geeksville.mesh.MessageStatus
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
import com.geeksville.mesh.databinding.AdapterMessageLayoutBinding
|
import com.geeksville.mesh.databinding.AdapterMessageLayoutBinding
|
||||||
import com.geeksville.mesh.databinding.MessagesFragmentBinding
|
import com.geeksville.mesh.databinding.MessagesFragmentBinding
|
||||||
|
import com.geeksville.mesh.model.QuickChatAction
|
||||||
import com.geeksville.mesh.model.UIViewModel
|
import com.geeksville.mesh.model.UIViewModel
|
||||||
import com.geeksville.mesh.service.MeshService
|
import com.geeksville.mesh.service.MeshService
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
|
@ -296,15 +297,30 @@ class MessagesFragment : Fragment(), Logging {
|
||||||
binding.sendButton.isEnabled = connected
|
binding.sendButton.isEnabled = connected
|
||||||
}
|
}
|
||||||
|
|
||||||
val test = Button(context)
|
for (action in model.quickChatActions) {
|
||||||
test.setLayoutParams(LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT))
|
val button = Button(context)
|
||||||
test.setText("RGR")
|
button.setText(action.name)
|
||||||
test.setOnClickListener {
|
if (action.mode == QuickChatAction.Mode.Instant) {
|
||||||
//model.messagesState.sendMessage("Roger", contactId)
|
button.backgroundTintList = ContextCompat.getColorStateList(requireActivity(), R.color.colorMyMsg)
|
||||||
binding.messageInputText.setText(binding.messageInputText.text?.append(" Roger"))
|
|
||||||
binding.messageInputText.setSelection(binding.messageInputText.text?.length ?: 0)
|
}
|
||||||
|
button.setOnClickListener {
|
||||||
|
if (action.mode == QuickChatAction.Mode.Append) {
|
||||||
|
val originalText = binding.messageInputText.text ?: ""
|
||||||
|
val needsSpace = !originalText.endsWith(' ') && originalText.isNotEmpty()
|
||||||
|
val newText = buildString {
|
||||||
|
append(originalText)
|
||||||
|
if (needsSpace) append(' ')
|
||||||
|
append(action.message)
|
||||||
|
}
|
||||||
|
binding.messageInputText.setText(newText)
|
||||||
|
binding.messageInputText.setSelection(newText.length)
|
||||||
|
} else {
|
||||||
|
model.messagesState.sendMessage(action.message, contactId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.quickChatLayout.addView(button)
|
||||||
}
|
}
|
||||||
binding.quickChatLayout.addView(test)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class ActionModeCallback : ActionMode.Callback {
|
private inner class ActionModeCallback : ActionMode.Callback {
|
||||||
|
|
|
@ -45,11 +45,13 @@
|
||||||
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
<ScrollView
|
<HorizontalScrollView
|
||||||
android:id="@+id/quickChatView"
|
android:id="@+id/quickChatView"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/textInputLayout"
|
app:layout_constraintBottom_toTopOf="@+id/textInputLayout"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent">
|
app:layout_constraintStart_toStartOf="parent">
|
||||||
|
@ -59,7 +61,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal" />
|
android:orientation="horizontal" />
|
||||||
</ScrollView>
|
</HorizontalScrollView>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/textInputLayout"
|
android:id="@+id/textInputLayout"
|
||||||
|
|
Ładowanie…
Reference in New Issue