From db0656f7b986912af4ea7d666380ab98b0fe006a Mon Sep 17 00:00:00 2001 From: geeksville Date: Wed, 8 Apr 2020 10:55:28 -0700 Subject: [PATCH] new channel view now works at least as well as the old channel view --- .../java/com/geeksville/mesh/ui/Channel.kt | 82 ++++++++++++++----- app/src/main/res/drawable/sl_lock_24dp.xml | 12 +++ app/src/main/res/layout/channel_fragment.xml | 44 ++++++++-- app/src/main/res/values/styles.xml | 10 +++ build.gradle | 4 +- 5 files changed, 121 insertions(+), 31 deletions(-) create mode 100644 app/src/main/res/drawable/sl_lock_24dp.xml diff --git a/app/src/main/java/com/geeksville/mesh/ui/Channel.kt b/app/src/main/java/com/geeksville/mesh/ui/Channel.kt index fa54ddbcb..12cf13e74 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/Channel.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/Channel.kt @@ -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(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(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, diff --git a/app/src/main/res/drawable/sl_lock_24dp.xml b/app/src/main/res/drawable/sl_lock_24dp.xml new file mode 100644 index 000000000..49aeeda17 --- /dev/null +++ b/app/src/main/res/drawable/sl_lock_24dp.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/channel_fragment.xml b/app/src/main/res/layout/channel_fragment.xml index ab14f82dd..f15ea2fa3 100644 --- a/app/src/main/res/layout/channel_fragment.xml +++ b/app/src/main/res/layout/channel_fragment.xml @@ -38,17 +38,47 @@ app:layout_constraintTop_toBottomOf="@+id/channelNameView" app:srcCompat="@drawable/qrcode" /> - + app:singleSelection="true" + app:selectionRequired="true" + app:layout_constraintTop_toBottomOf="@+id/channelOptions"> + +