fix: remove constructor from `DeviceSettingsFragment`

pull/728/head
andrekir 2023-09-11 21:26:42 -03:00
rodzic e20e66b7f7
commit b93098cbce
4 zmienionych plików z 27 dodań i 6 usunięć

Wyświetl plik

@ -751,9 +751,10 @@ class MainActivity : AppCompatActivity(), Logging {
return true
}
R.id.radio_config -> {
val node = model.ourNodeInfo.value ?: return true
if (model.ourNodeInfo.value == null) return true
model.setDestNode(null)
supportFragmentManager.beginTransaction()
.add(R.id.mainActivityLayout, DeviceSettingsFragment(node))
.add(R.id.mainActivityLayout, DeviceSettingsFragment())
.addToBackStack(null)
.commit()
return true

Wyświetl plik

@ -183,6 +183,17 @@ class UIViewModel @Inject constructor(
.filterValues { it.data.waypoint!!.expire > System.currentTimeMillis() / 1000 }
}.asLiveData()
private val _destNode = MutableStateFlow<NodeInfo?>(null)
val destNode: StateFlow<NodeInfo?> get() = if (_destNode.value != null) _destNode else _ourNodeInfo
/**
* Sets the destination [NodeInfo] used in Radio Configuration.
* @param node Destination [NodeInfo] (or null for our local NodeInfo).
*/
fun setDestNode(node: NodeInfo?) {
_destNode.value = node
}
/**
* Called immediately after activity observes packetResponse
*/

Wyświetl plik

@ -102,7 +102,7 @@ import com.google.accompanist.themeadapter.appcompat.AppCompatTheme
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class DeviceSettingsFragment(val node: NodeInfo) : ScreenFragment("Radio Configuration"), Logging {
class DeviceSettingsFragment : ScreenFragment("Radio Configuration"), Logging {
private val model: UIViewModel by activityViewModels()
@ -115,8 +115,13 @@ class DeviceSettingsFragment(val node: NodeInfo) : ScreenFragment("Radio Configu
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setBackgroundColor(ContextCompat.getColor(context, R.color.colorAdvancedBackground))
setContent {
val node by model.destNode.collectAsStateWithLifecycle()
AppCompatTheme {
RadioConfigNavHost(node, model)
RadioConfigNavHost(
node!!,
model,
)
}
}
}
@ -163,7 +168,10 @@ sealed class PacketResponseState {
}
@Composable
fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
fun RadioConfigNavHost(
node: NodeInfo,
viewModel: UIViewModel = viewModel(),
) {
val navController = rememberNavController()
val connectionState by viewModel.connectionState.observeAsState()

Wyświetl plik

@ -129,8 +129,9 @@ class UsersFragment : ScreenFragment("Users"), Logging {
}
R.id.remote_admin -> {
debug("calling remote admin --> destNum: ${node.num.toUInt()}")
model.setDestNode(node)
parentFragmentManager.beginTransaction()
.replace(R.id.mainActivityLayout, DeviceSettingsFragment(node))
.replace(R.id.mainActivityLayout, DeviceSettingsFragment())
.addToBackStack(null)
.commit()
}