diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index 54cb0af84..9f6f85edc 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -361,7 +361,7 @@ class MainActivity : AppCompatActivity(), Logging, var receiverRegistered = false private fun registerMeshReceiver() { - logAssert(!receiverRegistered) + unregisterMeshReceiver() val filter = IntentFilter() filter.addAction(MeshService.ACTION_MESH_CONNECTED) filter.addAction(MeshService.ACTION_NODE_CHANGE) @@ -392,7 +392,7 @@ class MainActivity : AppCompatActivity(), Logging, debug("Getting latest radioconfig from service") model.radioConfig.value = MeshProtos.RadioConfig.parseFrom(model.meshService!!.radioConfig) - + // Pull down our real node ID model.nodeDB.myId.value = service.myId @@ -500,7 +500,7 @@ class MainActivity : AppCompatActivity(), Logging, } } - private fun bindMeshService() { + fun bindMeshService() { debug("Binding to mesh service!") // we bind using the well known name, to make sure 3rd party apps could also if (model.meshService != null) @@ -512,7 +512,7 @@ class MainActivity : AppCompatActivity(), Logging, } } - private fun unbindMeshService() { + fun unbindMeshService() { // If we have received the service, and hence registered with // it, then now is the time to unregister. // if we never connected, do nothing @@ -535,10 +535,8 @@ class MainActivity : AppCompatActivity(), Logging, val bonded = RadioInterfaceService.getBondedDeviceAddress(this) != null - /* FIXME - not yet working if (!bonded) - AppStatus.currentScreen = Screen.settings - */ + pager.currentItem = 5 } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt index e6dddbc4c..d371eefe2 100644 --- a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt @@ -180,13 +180,14 @@ class RadioInterfaceService : Service(), Logging { // Force the service to reconnect val s = runningService if (s != null) { + info("shutting down old service") + s.setEnabled(false) // nasty, needed to force the next setEnabled call to reconnect info("Setting enable on the running radio service") s.setEnabled(addr != null) - } else { - if (addr != null) { - info("We have a device addr now, starting mesh service") - MeshService.startService(context) - } + } + if (addr != null) { + info("We have a device addr now, starting mesh service") + MeshService.startService(context) } } } diff --git a/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt index a96f92b50..eb21684cb 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MessagesFragment.kt @@ -16,6 +16,7 @@ import com.geeksville.mesh.model.TextMessage import com.geeksville.mesh.model.UIViewModel import kotlinx.android.synthetic.main.adapter_message_layout.view.* import kotlinx.android.synthetic.main.messages_fragment.* +import java.text.SimpleDateFormat // Allows usage like email.on(EditorInfo.IME_ACTION_NEXT, { confirm() }) fun EditText.on(actionId: Int, func: () -> Unit) { @@ -38,6 +39,7 @@ class MessagesFragment : ScreenFragment("Messages"), Logging { class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val username = itemView.username val messageText = itemView.messageText + val messageTime = itemView.messageTime } private val messagesAdapter = object : RecyclerView.Adapter() { @@ -121,6 +123,8 @@ class MessagesFragment : ScreenFragment("Messages"), Logging { } else { holder.messageText.text = msg.text } + + holder.messageTime.text = dateFormat.format(msg.date) } private var messages = arrayOf() @@ -164,21 +168,7 @@ class MessagesFragment : ScreenFragment("Messages"), Logging { messagesAdapter.onMessagesChanged(it) }) } + + private val dateFormat = SimpleDateFormat("h:mm a") } -/* - -private val dateFormat = SimpleDateFormat("h:mm a") - - - - ProvideEmphasis(emphasis = TimestampEmphasis) { - Text( - text = dateFormat.format(msg.date), - modifier = LayoutPadding(start = 8.dp), - style = MaterialTheme.typography.caption - ) - - - -*/ \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index 2dce31330..fe0aadc5e 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -19,8 +19,10 @@ import androidx.fragment.app.activityViewModels import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.MutableLiveData import androidx.lifecycle.Observer +import com.geeksville.android.GeeksvilleApplication import com.geeksville.android.Logging import com.geeksville.android.hideKeyboard +import com.geeksville.mesh.MainActivity import com.geeksville.mesh.R import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.service.RadioInterfaceService @@ -82,7 +84,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { // If nothing was selected, by default select the first thing we see if (selectedMacAddr == null && entry.bonded) - changeSelection(context, addr) + changeSelection(GeeksvilleApplication.currentActivity as MainActivity, addr) devices.value = oldDevs + Pair(addr, entry) // trigger gui updates } @@ -117,7 +119,10 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { // If nothing was selected, by default select the first thing we see if (selectedMacAddr == null) - changeSelection(context, testnodes.first().macAddress) + changeSelection( + GeeksvilleApplication.currentActivity as MainActivity, + testnodes.first().macAddress + ) } else { /// The following call might return null if the user doesn't have bluetooth access permissions val s: BluetoothLeScanner? = bluetoothAdapter.bluetoothLeScanner @@ -168,7 +173,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { fun onSelected(it: BTScanEntry): Boolean { // If the device is paired, let user select it, otherwise start the pairing flow if (it.bonded) { - changeSelection(context, it.macAddress) + changeSelection(GeeksvilleApplication.currentActivity as MainActivity, it.macAddress) return true } else { info("Starting bonding for $it") @@ -190,7 +195,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { if (state == BluetoothDevice.BOND_BONDED || state == BluetoothDevice.BOND_BONDING) { debug("Bonding completed, connecting service") changeSelection( - context, + GeeksvilleApplication.currentActivity as MainActivity, it.macAddress ) @@ -214,10 +219,14 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { } /// Change to a new macaddr selection, updating GUI and radio - fun changeSelection(context: Context, newAddr: String) { + fun changeSelection(context: MainActivity, newAddr: String) { info("Changing BT device to $newAddr") selectedMacAddr = newAddr RadioInterfaceService.setBondedDeviceAddress(context, newAddr) + + // Super ugly hack. we force the activity to reconnect FIXME, find a cleaner way + context.unbindMeshService() + context.bindMeshService() } } @@ -275,7 +284,14 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { deviceRadioGroup.addView(b) b.setOnClickListener { - b.isChecked = scanModel.onSelected(device) + scanProgressBar.visibility = View.INVISIBLE + if (!device.bonded) + scanStatusText.setText(R.string.starting_pairing) + + b.isSelected = scanModel.onSelected(device) + + if (!b.isSelected) + scanStatusText.setText(R.string.pairing_failed) } } diff --git a/app/src/main/res/layout/adapter_message_layout.xml b/app/src/main/res/layout/adapter_message_layout.xml index 1010e0ddc..3cc682446 100644 --- a/app/src/main/res/layout/adapter_message_layout.xml +++ b/app/src/main/res/layout/adapter_message_layout.xml @@ -1,6 +1,7 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e2d12e8b1..63791e3ba 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,7 +12,7 @@ User avatar 2.13 km hey I found the cache, it is over here next to the big tiger. I\'m kinda scared. - Some Username + SKH Send Text You haven\'t yet paired a Meshtastic compatible radio with this phone. Please pair a device and set your username.\n\nThis open-source application is in alpha-testing, if you find problems please post on our website chat.\n\nFor more information see our web page - www.meshtastic.org. Username unset @@ -23,4 +23,6 @@ Meshtastic_1267 This application requires bluetooth access. Please grant access in android settings. Error - this app requires bluetooth + Starting pairing + Pairing failed