begin letting users edit ownername

1.2-legacy
geeksville 2020-02-18 10:40:02 -08:00
rodzic 8a7de21814
commit 91cf6b7253
5 zmienionych plików z 69 dodań i 19 usunięć

Wyświetl plik

@ -23,11 +23,9 @@ import com.geeksville.mesh.model.UIState
import com.geeksville.mesh.service.*
import com.geeksville.mesh.ui.MeshApp
import com.geeksville.mesh.ui.ScanState
import com.geeksville.mesh.ui.getInitials
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.common.api.ApiException
import com.google.android.gms.tasks.Task
import java.nio.charset.Charset
@ -153,12 +151,6 @@ class MainActivity : AppCompatActivity(), Logging,
}
private fun setOwner() {
// Note: we are careful to not set a new unique ID
val name = UIState.ownerName.value
UIState.meshService!!.setOwner(null, name, getInitials(name))
}
private fun sendTestPackets() {
exceptionReporter {
val m = UIState.meshService!!
@ -182,9 +174,8 @@ class MainActivity : AppCompatActivity(), Logging,
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MeshApp()
}
val prefs = getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
UIState.ownerName = prefs.getString("owner", "Unknown Owner")!!
// Ensures Bluetooth is available on the device and it is enabled. If not,
// displays a dialog requesting user permission to enable Bluetooth.
@ -200,6 +191,10 @@ class MainActivity : AppCompatActivity(), Logging,
requestPermission()
setContent {
MeshApp()
}
/* not yet working
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
@ -229,7 +224,7 @@ class MainActivity : AppCompatActivity(), Logging,
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode === RC_SIGN_IN) {
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
val task: Task<GoogleSignInAccount> =
@ -239,16 +234,16 @@ class MainActivity : AppCompatActivity(), Logging,
}
private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
/*
try {
val account =
completedTask.getResult(ApiException::class.java)
val account = completedTask.getResult(ApiException::class.java)
// Signed in successfully, show authenticated UI.
//updateUI(account)
} catch (e: ApiException) { // The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
warn("signInResult:failed code=" + e.statusCode)
//updateUI(null)
}
} */
}
private var receiverRegistered = false
@ -289,7 +284,7 @@ class MainActivity : AppCompatActivity(), Logging,
readRadioConfig()
// everytime the radio reconnects, we slam in our current owner data, the radio is smart enough to only broadcast if needed
setOwner()
UIState.setOwner(this)
}
}

Wyświetl plik

@ -1,9 +1,12 @@
package com.geeksville.mesh.model
import android.content.Context
import android.util.Base64
import androidx.compose.mutableStateOf
import androidx.core.content.edit
import com.geeksville.mesh.IMeshService
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.ui.getInitials
/// FIXME - figure out how to merge this staate with the AppStatus Model
object UIState {
@ -21,7 +24,7 @@ object UIState {
/// our name in hte radio
/// Note, we generate owner initials automatically for now
val ownerName = mutableStateOf("fixme readfromprefs")
var ownerName: String = "fixme readfromprefs"
/// Return an URL that represents the current channel values
val channelUrl
@ -31,4 +34,19 @@ object UIState {
return "https://www.meshtastic.org/c/$enc"
}
// clean up all this nasty owner state management FIXME
fun setOwner(context: Context, s: String? = null) {
if (s != null) {
ownerName = s
val prefs = context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
prefs.edit(commit = true) {
putString("owner", s)
}
}
// Note: we are careful to not set a new unique ID
meshService!!.setOwner(null, ownerName, getInitials(ownerName))
}
}

Wyświetl plik

@ -42,6 +42,7 @@ object ScanState : Logging {
if (callback != null) {
debug("stopping scan")
scanner!!.stopScan(callback)
callback = null
} else
debug("not stopping bt scanner")
}
@ -59,7 +60,7 @@ fun BTScanScreen() {
/// Note: may be null on platforms without a bluetooth driver (ie. the emulator)
val bluetoothAdapter =
(context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager)?.adapter
(context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter
onActive {
ScanUIState.selectedMacAddr = RadioInterfaceService.getBondedDeviceAddress(context)
@ -67,6 +68,7 @@ fun BTScanScreen() {
val scanCallback = object : ScanCallback() {
override fun onScanFailed(errorCode: Int) {
val msg = "Unexpected bluetooth scan failure: $errorCode"
// error code2 seeems to be indicate hung bluetooth stack
ScanUIState.errorText = msg
ScanState.reportError(msg)
}

Wyświetl plik

@ -130,9 +130,12 @@ private fun AppContent(openDrawer: () -> Unit) {
// VerticalScroller breaks flexible layouts - because verticalscrollers have 'infinite' height
// VerticalScroller(modifier = LayoutFlexible(1f)) {
//if (screen != Screen.settings)
// ScanState.stopScan() // Nasty hack to teardown the bt scanner
when (screen) {
Screen.messages -> MessagesContent()
Screen.settings -> BTScanScreen()
Screen.settings -> SettingsContent()
Screen.users -> HomeContent()
Screen.channel -> ChannelContent()
else -> TODO()

Wyświetl plik

@ -0,0 +1,32 @@
package com.geeksville.mesh.ui
import androidx.compose.Composable
import androidx.ui.layout.Column
import androidx.ui.layout.LayoutPadding
import androidx.ui.layout.LayoutSize
import androidx.ui.material.MaterialTheme
import androidx.ui.tooling.preview.Preview
import androidx.ui.unit.dp
import com.geeksville.android.Logging
object SettingsLog : Logging
@Composable
fun SettingsContent() {
val typography = MaterialTheme.typography()
Column(modifier = LayoutSize.Fill + LayoutPadding(16.dp)) {
}
}
@Preview
@Composable
fun previewSettings() {
// another bug? It seems modaldrawerlayout not yet supported in preview
MaterialTheme(colors = palette) {
SettingsContent()
}
}