mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
new channel view now works at least as well as the old channel view
This commit is contained in:
parent
012139cb01
commit
db0656f7b9
5 changed files with 121 additions and 31 deletions
|
|
@ -1,17 +1,22 @@
|
|||
package com.geeksville.mesh.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.AutoCompleteTextView
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.Observer
|
||||
import com.geeksville.analytics.DataPair
|
||||
import com.geeksville.android.GeeksvilleApplication
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.android.synthetic.main.channel_fragment.*
|
||||
|
||||
|
||||
object ChannelLog : Logging
|
||||
|
||||
|
|
@ -27,18 +32,69 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
return inflater.inflate(R.layout.channel_fragment, container, false)
|
||||
}
|
||||
|
||||
private fun onEditingChanged() {
|
||||
val isEditing = editableCheckbox.isChecked
|
||||
|
||||
channelOptions.isEnabled = false // Not yet ready
|
||||
shareButton.isEnabled = !isEditing
|
||||
channelNameView.isEnabled = isEditing
|
||||
qrView.visibility =
|
||||
if (isEditing) View.INVISIBLE else View.VISIBLE // Don't show the user a stale QR code
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
onEditingChanged() // Set initial state
|
||||
|
||||
editableCheckbox.setOnCheckedChangeListener { _, checked ->
|
||||
onEditingChanged()
|
||||
|
||||
if (!checked) {
|
||||
// User just locked it, we should warn and then apply changes to radio FIXME not ready yet
|
||||
Snackbar.make(
|
||||
editableCheckbox,
|
||||
"Changing channels is not yet supported",
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
model.radioConfig.observe(viewLifecycleOwner, Observer { config ->
|
||||
val channel = UIViewModel.getChannel(config)
|
||||
val channelNameEdit = view.findViewById<TextInputEditText>(R.id.channelNameEdit)
|
||||
|
||||
if (channel != null) {
|
||||
qrView.visibility = View.VISIBLE
|
||||
channelNameEdit.visibility = View.VISIBLE
|
||||
channelNameEdit.setText(channel.name)
|
||||
editableCheckbox.isEnabled = true
|
||||
|
||||
val d = BitmapDrawable(resources, channel.getChannelQR())
|
||||
qrView.setImageDrawable(d)
|
||||
// Share this particular channel if someone clicks share
|
||||
shareButton.setOnClickListener {
|
||||
GeeksvilleApplication.analytics.track(
|
||||
"share",
|
||||
DataPair("content_type", "channel")
|
||||
) // track how many times users share channels
|
||||
|
||||
val sendIntent: Intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, channel.getChannelUrl().toString())
|
||||
putExtra(
|
||||
Intent.EXTRA_TITLE,
|
||||
"A URL for joining a Meshtastic mesh"
|
||||
)
|
||||
type = "text/plain"
|
||||
}
|
||||
|
||||
val shareIntent = Intent.createChooser(sendIntent, null)
|
||||
requireActivity().startActivity(shareIntent)
|
||||
}
|
||||
} else {
|
||||
qrView.visibility = View.INVISIBLE
|
||||
channelNameEdit.visibility = View.INVISIBLE
|
||||
editableCheckbox.isEnabled = false
|
||||
}
|
||||
|
||||
val adapter = ArrayAdapter(
|
||||
|
|
@ -47,9 +103,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
arrayOf("Item 1", "Item 2", "Item 3", "Item 4")
|
||||
)
|
||||
|
||||
val editTextFilledExposedDropdown =
|
||||
view.findViewById<AutoCompleteTextView>(R.id.filled_exposed_dropdown)
|
||||
editTextFilledExposedDropdown.setAdapter(adapter)
|
||||
filled_exposed_dropdown.setAdapter(adapter)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -123,23 +177,7 @@ fun ChannelContent(channel: Channel?) {
|
|||
if (!channel.editable)
|
||||
OutlinedButton(modifier = LayoutPadding(start = 24.dp),
|
||||
onClick = {
|
||||
GeeksvilleApplication.analytics.track(
|
||||
"share",
|
||||
DataPair("content_type", "channel")
|
||||
) // track how many times users share channels
|
||||
|
||||
val sendIntent: Intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, channel.getChannelUrl().toString())
|
||||
putExtra(
|
||||
Intent.EXTRA_TITLE,
|
||||
"A URL for joining a Meshtastic mesh"
|
||||
)
|
||||
type = "text/plain"
|
||||
}
|
||||
|
||||
val shareIntent = Intent.createChooser(sendIntent, null)
|
||||
context.startActivity(shareIntent)
|
||||
}) {
|
||||
VectorImage(
|
||||
id = R.drawable.ic_twotone_share_24,
|
||||
|
|
|
|||
12
app/src/main/res/drawable/sl_lock_24dp.xml
Normal file
12
app/src/main/res/drawable/sl_lock_24dp.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:drawable="@drawable/ic_twotone_lock_24"
|
||||
android:state_checked="false"
|
||||
/>
|
||||
<item
|
||||
android:drawable="@drawable/ic_twotone_lock_open_24"
|
||||
android:state_checked="true"
|
||||
/>
|
||||
<item android:drawable="@drawable/ic_twotone_lock_24" />
|
||||
</selector>
|
||||
|
|
@ -38,17 +38,47 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/channelNameView"
|
||||
app:srcCompat="@drawable/qrcode" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/lockButton"
|
||||
style="@android:style/Widget.Material.ImageButton"
|
||||
<!--
|
||||
geeksville: no longer used but keeping as a good example of a button group. instead I use
|
||||
a toggleable icon.
|
||||
|
||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||
android:id="@+id/editGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="96dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:contentDescription="Lock/Unlock button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/channelOptions"
|
||||
app:srcCompat="@drawable/ic_twotone_lock_open_24" />
|
||||
app:singleSelection="true"
|
||||
app:selectionRequired="true"
|
||||
app:layout_constraintTop_toBottomOf="@+id/channelOptions">
|
||||
|
||||
<Button
|
||||
android:id="@+id/locked"
|
||||
style="@style/Widget.App.Button.OutlinedButton.IconOnly"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
app:icon="@drawable/ic_twotone_lock_24" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/unlocked"
|
||||
style="@style/Widget.App.Button.OutlinedButton.IconOnly"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
app:icon="@drawable/ic_twotone_lock_open_24" />
|
||||
</com.google.android.material.button.MaterialButtonToggleGroup>
|
||||
-->
|
||||
<CheckBox
|
||||
android:id="@+id/editableCheckbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="96dp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:button="@drawable/sl_lock_24dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/channelOptions"></CheckBox>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/shareButton"
|
||||
|
|
@ -58,7 +88,7 @@
|
|||
android:layout_marginEnd="96dp"
|
||||
android:contentDescription="Share button"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/lockButton"
|
||||
app:layout_constraintTop_toTopOf="@+id/editableCheckbox"
|
||||
app:srcCompat="@drawable/ic_twotone_share_24" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
|
|
|
|||
|
|
@ -18,4 +18,14 @@
|
|||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
<style name="Widget.App.Button.OutlinedButton.IconOnly" parent="Widget.MaterialComponents.Button.OutlinedButton">
|
||||
<item name="iconPadding">0dp</item>
|
||||
<item name="android:insetTop">0dp</item>
|
||||
<item name="android:insetBottom">0dp</item>
|
||||
<item name="android:paddingLeft">12dp</item>
|
||||
<item name="android:paddingRight">12dp</item>
|
||||
<item name="android:minWidth">48dp</item>
|
||||
<item name="android:minHeight">48dp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.61'
|
||||
ext.kotlin_version = '1.3.71'
|
||||
ext.coroutines_version = "1.3.5"
|
||||
|
||||
repositories {
|
||||
|
|
@ -22,7 +22,7 @@ buildscript {
|
|||
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta03'
|
||||
|
||||
// protobuf plugin - docs here https://github.com/google/protobuf-gradle-plugin
|
||||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.11'
|
||||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue