mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-03 13:43:20 -04:00
Merge branch 'osmdroid-phase2' of github.com:ScriptTactics/Meshtastic-Android into osmdroid-phase2
This commit is contained in:
@@ -237,11 +237,6 @@ class UIViewModel @Inject constructor(
|
||||
// We consider hasWifi = ESP32
|
||||
fun isESP32() = myNodeInfo.value?.hasWifi == true
|
||||
|
||||
fun hasAXP(): Boolean {
|
||||
val hasAXP = listOf(4, 7, 9) // mesh.proto 'HardwareModel' enums with AXP192 chip
|
||||
return hasAXP.contains(nodeDB.ourNodeInfo?.user?.hwModel?.number)
|
||||
}
|
||||
|
||||
/// hardware info about our local device (can be null)
|
||||
private val _myNodeInfo = MutableLiveData<MyNodeInfo?>()
|
||||
val myNodeInfo: LiveData<MyNodeInfo?> get() = _myNodeInfo
|
||||
@@ -360,16 +355,36 @@ class UIViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun requestShutdown() {
|
||||
meshService?.requestShutdown(DataPacket.ID_LOCAL)
|
||||
fun requestShutdown(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestShutdown(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun requestReboot() {
|
||||
meshService?.requestReboot(DataPacket.ID_LOCAL)
|
||||
fun requestReboot(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestReboot(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun requestFactoryReset() {
|
||||
meshService?.requestFactoryReset(DataPacket.ID_LOCAL)
|
||||
fun requestFactoryReset(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestFactoryReset(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun requestNodedbReset(idNum: Int) {
|
||||
try {
|
||||
meshService?.requestNodedbReset(idNum)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("RemoteException: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1341,7 +1341,7 @@ class MeshService : Service(), Logging {
|
||||
else {
|
||||
discardNodeDB()
|
||||
debug("Installing new node DB")
|
||||
myNodeInfo = newMyNodeInfo// Install myNodeInfo as current
|
||||
myNodeInfo = newMyNodeInfo // Install myNodeInfo as current
|
||||
|
||||
newNodes.forEach(::installNodeInfo)
|
||||
newNodes.clear() // Just to save RAM ;-)
|
||||
@@ -1383,24 +1383,30 @@ class MeshService : Service(), Logging {
|
||||
})
|
||||
}
|
||||
|
||||
private fun requestShutdown(nodeId: String) {
|
||||
sendToRadio(newMeshPacketTo(toNodeNum(nodeId)).buildAdminPacket {
|
||||
private fun requestShutdown(idNum: Int) {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
shutdownSeconds = 5
|
||||
})
|
||||
}
|
||||
|
||||
private fun requestReboot(nodeId: String) {
|
||||
sendToRadio(newMeshPacketTo(toNodeNum(nodeId)).buildAdminPacket {
|
||||
private fun requestReboot(idNum: Int) {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
rebootSeconds = 5
|
||||
})
|
||||
}
|
||||
|
||||
private fun requestFactoryReset(nodeId: String) {
|
||||
sendToRadio(newMeshPacketTo(toNodeNum(nodeId)).buildAdminPacket {
|
||||
private fun requestFactoryReset(idNum: Int) {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
factoryReset = 1
|
||||
})
|
||||
}
|
||||
|
||||
private fun requestNodedbReset(idNum: Int) {
|
||||
sendToRadio(newMeshPacketTo(idNum).buildAdminPacket {
|
||||
nodedbReset = 1
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the modern (REV2) API configuration flow
|
||||
*/
|
||||
@@ -1721,16 +1727,20 @@ class MeshService : Service(), Logging {
|
||||
stopLocationRequests()
|
||||
}
|
||||
|
||||
override fun requestShutdown(nodeId: String) = toRemoteExceptions {
|
||||
this@MeshService.requestShutdown(nodeId)
|
||||
override fun requestShutdown(idNum: Int) = toRemoteExceptions {
|
||||
this@MeshService.requestShutdown(idNum)
|
||||
}
|
||||
|
||||
override fun requestReboot(nodeId: String) = toRemoteExceptions {
|
||||
this@MeshService.requestReboot(nodeId)
|
||||
override fun requestReboot(idNum: Int) = toRemoteExceptions {
|
||||
this@MeshService.requestReboot(idNum)
|
||||
}
|
||||
|
||||
override fun requestFactoryReset(nodeId: String) = toRemoteExceptions {
|
||||
this@MeshService.requestFactoryReset(nodeId)
|
||||
override fun requestFactoryReset(idNum: Int) = toRemoteExceptions {
|
||||
this@MeshService.requestFactoryReset(idNum)
|
||||
}
|
||||
|
||||
override fun requestNodedbReset(idNum: Int) = toRemoteExceptions {
|
||||
this@MeshService.requestNodedbReset(idNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
|
||||
binding.lsSleepView.isEnabled = connected && model.config.power.isPowerSaving
|
||||
binding.positionBroadcastSwitch.isEnabled = connected
|
||||
binding.lsSleepSwitch.isEnabled = connected && model.isESP32()
|
||||
binding.shutdownButton.isEnabled = connected && model.hasAXP()
|
||||
binding.rebootButton.isEnabled = connected
|
||||
binding.factoryResetButton.isEnabled = connected
|
||||
}
|
||||
|
||||
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
|
||||
@@ -111,41 +108,5 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
|
||||
debug("User changed isPowerSaving to $isChecked")
|
||||
}
|
||||
}
|
||||
|
||||
binding.shutdownButton.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setMessage("${getString(R.string.shutdown)}?")
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
}
|
||||
.setPositiveButton(getString(R.string.okay)) { _, _ ->
|
||||
debug("User clicked requestShutdown")
|
||||
model.requestShutdown()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
binding.rebootButton.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setMessage("${getString(R.string.reboot)}?")
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
}
|
||||
.setPositiveButton(getString(R.string.okay)) { _, _ ->
|
||||
debug("User clicked requestReboot")
|
||||
model.requestReboot()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
binding.factoryResetButton.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.are_you_sure_factory_reset)
|
||||
.setMessage(R.string.factory_reset_description)
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
}
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
model.requestFactoryReset()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,12 +391,9 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
|
||||
val label = it.name + " " + formatAgo(it.expire)
|
||||
marker = MarkerWithLabel(map, label)
|
||||
marker.title = it.name
|
||||
marker.snippet = it.description
|
||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||
marker.position = GeoPoint(it.latitudeI.toDouble(), it.longitudeI.toDouble())
|
||||
marker.icon = ContextCompat.getDrawable(
|
||||
requireActivity(),
|
||||
R.drawable.ic_baseline_location_on_24
|
||||
)
|
||||
}
|
||||
marker
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.geeksville.mesh.ui
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.text.HtmlCompat
|
||||
@@ -12,13 +14,14 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.databinding.AdapterNodeLayoutBinding
|
||||
import com.geeksville.mesh.databinding.NodelistFragmentBinding
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.util.formatAgo
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.net.URLEncoder
|
||||
|
||||
@@ -35,6 +38,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
// Provide a direct reference to each of the views within a data item
|
||||
// Used to cache the views within the item layout for fast access
|
||||
class ViewHolder(itemView: AdapterNodeLayoutBinding) : RecyclerView.ViewHolder(itemView.root) {
|
||||
val chipNode = itemView.chipNode
|
||||
val nodeNameView = itemView.nodeNameView
|
||||
val distanceView = itemView.distanceView
|
||||
val coordsView = itemView.coordsView
|
||||
@@ -47,6 +51,90 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
|
||||
private val nodesAdapter = object : RecyclerView.Adapter<ViewHolder>() {
|
||||
|
||||
private var nodes = arrayOf<NodeInfo>()
|
||||
|
||||
private fun popup(view: View, position: Int) {
|
||||
val node = nodes[position]
|
||||
val user = node.user
|
||||
val showAdmin = position == 0 // TODO add admin channel check
|
||||
val popup = PopupMenu(requireContext(), view)
|
||||
popup.inflate(R.menu.menu_nodes)
|
||||
popup.menu.findItem(R.id.direct_message).isVisible = position > 0
|
||||
popup.menu.setGroupVisible(R.id.group_admin, showAdmin)
|
||||
popup.setOnMenuItemClickListener { item: MenuItem ->
|
||||
when (item.itemId) {
|
||||
R.id.direct_message -> {
|
||||
if (position > 0 && user != null) {
|
||||
debug("calling MessagesFragment filter: 0${user.id}")
|
||||
setFragmentResult(
|
||||
"requestKey",
|
||||
bundleOf(
|
||||
"contactKey" to "0${user.id}",
|
||||
"contactName" to user.longName
|
||||
)
|
||||
)
|
||||
parentFragmentManager.beginTransaction()
|
||||
.replace(R.id.mainActivityLayout, MessagesFragment())
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
R.id.reboot -> {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle("${getString(R.string.reboot)}\n${user?.longName}?")
|
||||
.setIcon(R.drawable.ic_twotone_warning_24)
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
}
|
||||
.setPositiveButton(getString(R.string.okay)) { _, _ ->
|
||||
debug("User clicked requestReboot")
|
||||
model.requestReboot(node.num)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
R.id.shutdown -> {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle("${getString(R.string.shutdown)}\n${user?.longName}?")
|
||||
.setIcon(R.drawable.ic_twotone_warning_24)
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
}
|
||||
.setPositiveButton(getString(R.string.okay)) { _, _ ->
|
||||
debug("User clicked requestShutdown")
|
||||
model.requestShutdown(node.num)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
R.id.factory_reset -> {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle("${getString(R.string.factory_reset)}\n${user?.longName}?")
|
||||
.setIcon(R.drawable.ic_twotone_warning_24)
|
||||
.setMessage(R.string.factory_reset_description)
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
}
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
debug("User clicked requestFactoryReset")
|
||||
model.requestFactoryReset(node.num)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
R.id.nodedb_reset -> {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle("${getString(R.string.nodedb_reset)}\n${user?.longName}?")
|
||||
.setIcon(R.drawable.ic_twotone_warning_24)
|
||||
.setMessage(R.string.nodedb_reset_description)
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
}
|
||||
.setPositiveButton(getString(R.string.okay)) { _, _ ->
|
||||
debug("User clicked requestNodedbReset")
|
||||
model.requestNodedbReset(node.num)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
popup.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when RecyclerView needs a new [ViewHolder] of the given type to represent
|
||||
* an item.
|
||||
@@ -110,7 +198,9 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
*/
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val n = nodes[position]
|
||||
val name = n.user?.longName ?: n.user?.id ?: "Unknown node"
|
||||
val user = n.user
|
||||
holder.chipNode.text = user?.shortName ?: "UNK"
|
||||
val name = user?.longName ?: "Unknown node"
|
||||
holder.nodeNameView.text = name
|
||||
|
||||
val pos = n.validPosition
|
||||
@@ -165,25 +255,15 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
holder.signalView.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
holder.chipNode.setOnClickListener {
|
||||
popup(it, position)
|
||||
}
|
||||
holder.itemView.setOnLongClickListener {
|
||||
val node = n.user
|
||||
if (position > 0 && node != null) {
|
||||
debug("calling MessagesFragment filter:${node.id}")
|
||||
setFragmentResult(
|
||||
"requestKey",
|
||||
bundleOf("contactKey" to "0${node.id}", "contactName" to name)
|
||||
)
|
||||
parentFragmentManager.beginTransaction()
|
||||
.replace(R.id.mainActivityLayout, MessagesFragment())
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
}
|
||||
popup(it, position)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private var nodes = arrayOf<NodeInfo>()
|
||||
|
||||
/// Called when our node DB changes
|
||||
fun onNodesChanged(nodesIn: Array<NodeInfo>) {
|
||||
if (nodesIn.size > 1)
|
||||
@@ -210,10 +290,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
|
||||
holder.batteryPctView.text = text
|
||||
holder.powerIcon.setImageDrawable(context?.let {
|
||||
ContextCompat.getDrawable(
|
||||
it,
|
||||
image
|
||||
)
|
||||
ContextCompat.getDrawable(it, image)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user