handling received channel URLs now works okayish

pull/28/head
geeksville 2020-04-09 17:06:41 -07:00
rodzic 2b588ac7e7
commit eba6fef9fa
3 zmienionych plików z 46 dodań i 7 usunięć

Wyświetl plik

@ -25,6 +25,7 @@ import androidx.lifecycle.Observer
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.geeksville.android.Logging
import com.geeksville.android.ServiceClient
import com.geeksville.mesh.model.Channel
import com.geeksville.mesh.model.TextMessage
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.service.*
@ -34,6 +35,7 @@ import com.geeksville.util.exceptionReporter
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.tasks.Task
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.activity_main.*
import java.nio.charset.Charset
@ -306,6 +308,8 @@ class MainActivity : AppCompatActivity(), Logging,
handleIntent(intent)
}
private var requestedChannelUrl: Uri? = null
/// Handle any itents that were passed into us
private fun handleIntent(intent: Intent) {
val appLinkAction = intent.action
@ -313,8 +317,14 @@ class MainActivity : AppCompatActivity(), Logging,
// Were we asked to open one our channel URLs?
if (Intent.ACTION_VIEW == appLinkAction) {
debug("Asked to open a channel URL - FIXME, ask user if they want to switch to that channel. If so send the config to the radio")
val requestedChannelUrl = appLinkData
debug("Asked to open a channel URL - ask user if they want to switch to that channel. If so send the config to the radio")
requestedChannelUrl = appLinkData
// if the device is connected already, process it now
if (model.isConnected == MeshService.ConnectionState.CONNECTED)
perhapsChangeChannel()
// We now wait for the device to connect, once connected, we ask the user if they want to switch to the new channel
}
}
@ -386,7 +396,7 @@ class MainActivity : AppCompatActivity(), Logging,
// everytime the radio reconnects, we slam in our current owner data, the radio is smart enough to only broadcast if needed
model.setOwner()
model.meshService?.let { service ->
debug("Getting latest radioconfig from service")
model.radioConfig.value =
@ -401,10 +411,33 @@ class MainActivity : AppCompatActivity(), Logging,
}.toMap()
model.nodeDB.nodes.value = nodes
// we have a connection to our device now, do the channel change
perhapsChangeChannel()
}
}
}
private fun perhapsChangeChannel() {
// If the is opening a channel URL, handle it now
requestedChannelUrl?.let { url ->
val channel = Channel(url)
requestedChannelUrl = null
MaterialAlertDialogBuilder(this)
.setTitle(R.string.new_channel_rcvd)
.setMessage(getString(R.string.do_you_want_switch).format(channel.name))
.setNeutralButton(R.string.cancel) { _, _ ->
// Do nothing
}
.setPositiveButton(R.string.accept) { _, _ ->
debug("Setting channel from URL")
model.setChannel(channel.settings)
}
.show()
}
}
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
return try {
super.dispatchTouchEvent(ev)

Wyświetl plik

@ -130,12 +130,12 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
).show() */
MaterialAlertDialogBuilder(requireContext())
.setTitle("Change channel")
.setMessage("Are you sure you want to change the channel? All communication with other nodes will stop until you share the new channel settings.")
.setNeutralButton("Cancel") { _, _ ->
.setTitle(R.string.change_channel)
.setMessage(R.string.are_you_sure_channel)
.setNeutralButton(R.string.cancel) { _, _ ->
setGUIfromModel()
}
.setPositiveButton("Accept") { _, _ ->
.setPositiveButton(getString(R.string.accept)) { _, _ ->
// Generate a new channel with only the changes the user can change in the GUI
UIViewModel.getChannel(model.radioConfig.value)?.let { old ->
val newSettings = old.settings.toBuilder()

Wyświetl plik

@ -26,4 +26,10 @@
<string name="starting_pairing">Starting pairing</string>
<string name="pairing_failed">Pairing failed</string>
<string name="url_for_join">A URL for joining a Meshtastic mesh</string>
<string name="accept">Accept</string>
<string name="cancel">Cancel</string>
<string name="change_channel">Change channel</string>
<string name="are_you_sure_channel">Are you sure you want to change the channel? All communication with other nodes will stop until you share the new channel settings.</string>
<string name="new_channel_rcvd">New Channel URL received</string>
<string name="do_you_want_switch">Do you want to switch to the \'%s\' channel?</string>
</resources>