Skip to content

Commit

Permalink
信息通过tab分页显示
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwan committed Oct 16, 2021
1 parent 441ef94 commit 8a60fa0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
33 changes: 25 additions & 8 deletions app/src/main/java/com/benjaminwan/composelocation/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -75,11 +72,31 @@ class MainActivity : AppCompatActivity() {
var rmcState by remember { mutableStateOf<RMC?>(null) }
val rmc = nmeaToRMC(nmea.nmea)
if (rmc != null) rmcState = rmc
val tabs = listOf(stringResource(R.string.location_tab_1), stringResource(R.string.location_tab_2))
var selectedTab by remember { mutableStateOf(0) }
if (gpsEnable) {
LocationInfoCard(location, timeToFirstFixStr, satellitesCountStr)
if (ggaState != null) GGAInfoCard(ggaState!!)
if (rmcState != null) RMCInfoCard(rmcState!!)
SatelliteListCard(satellites)
TabRow(selectedTabIndex = selectedTab) {
tabs.forEachIndexed { index, s ->
Tab(
selected = index == selectedTab,
onClick = { selectedTab = index },
) {
Text(text = s, modifier = Modifier.padding(8.dp))
}
}
}
when (selectedTab) {
0 -> {
LocationInfoCard(location, timeToFirstFixStr, satellitesCountStr)
SatelliteListCard(satellites)
}
1 -> {
if (ggaState != null) GGAInfoCard(ggaState!!)
if (rmcState != null) RMCInfoCard(rmcState!!)
}
else -> {
}
}
} else {
Text(
text = stringResource(id = R.string.location_service_off_msg),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
<string name="title_tip">提示</string>
<string name="dialog_goto_setting">去设置</string>
<string name="location_service_off_msg">位置信息服务已关闭,请到设置选项中启用</string>
<string name="location_tab_1">定位信息</string>
<string name="location_tab_2">原始信息</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<string name="location_bearing">Bearing(°)</string>
<string name="location_bearing_accuracy">BearingAccuracy(°)</string>
<string name="location_satellites_count">Count(inUsed/inView/Total)</string>
<string name="location_tab_1">Detail</string>
<string name="location_tab_2">Raw Info</string>

<!-- satellite list-->
<string name="elevation_degrees">Elevation(°)</string>
Expand Down

0 comments on commit 8a60fa0

Please sign in to comment.