Skip to content

Watches Page UI Recreation in kotlin #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: kmp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ class KMPApiBridge @Inject constructor(
activity.startActivity(intent)
}
}
override fun openWatchesView() {
activity?.let {
Timber.d("Opening watches view")
val intent = Intent(activity.context, MainActivity::class.java)
intent.putExtra("navigationPath", Routes.Home.WATCHES_PAGE)
activity.startActivity(intent)
}
}
}
24 changes: 24 additions & 0 deletions android/app/src/main/kotlin/io/rebble/cobble/pigeons/Pigeons.java
Original file line number Diff line number Diff line change
Expand Up @@ -5458,6 +5458,8 @@ public interface KMPApi {

void openLockerView();

void openWatchesView();

/** The codec used by KMPApi. */
static @NonNull MessageCodec<Object> getCodec() {
return KMPApiCodec.INSTANCE;
Expand Down Expand Up @@ -5510,6 +5512,28 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable KMPApi api
channel.setMessageHandler(null);
}
}
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.KMPApi.openWatchesView", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
try {
api.openWatchesView();
wrapped.add(0, null);
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
}
}
}
6 changes: 6 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
<string name="bluetooth_off">Bluetooth is off</string>
<string name="warnings">Warnings</string>
<string name="jobs">Background Jobs</string>
<string name="disconnected">Disconnected</string>
<string name="connect_watch">Connect to watch</string>
<string name="disconnect_watch">Disconnect from watch</string>
<string name="check_for_updates">Check for updates</string>
<string name="download_update">Download Update</string>
<string name="forget_watch">Forget Watch</string>
</resources>
22 changes: 22 additions & 0 deletions android/shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="bootUrlWarningTitle">Boot URL change requested</string>
<string name="bootUrlWarningBody">An external source requested to change the boot URL, ensure you trust this source as changing to a malicious source shares all web services data with it!\n%s</string>

<string name="connected">Connected</string>
<string name="connecting">Watch connecting</string>
<string name="bluetooth_off">Bluetooth is off</string>
<string name="warnings">Warnings</string>
<string name="jobs">Background Jobs</string>
<string name="disconnected">Disconnected</string>
<string name="connect_watch">Connect to watch</string>
<string name="disconnect_watch">Disconnect from watch</string>
<string name="check_for_updates">Check for updates</string>
<string name="update_available">Update Available</string>
<string name="download_update">Download Update</string>
<string name="forget_watch">Forget Watch</string>
<string name="my_watches">My watches</string>
<string name="nothing_connected">Nothing Connected</string>
<string name="bg_service_stopped">Background service stopped</string>
<string name="other_watches">Other Watches</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.rebble.cobble.shared.data

data class WatchItem(
val name: String,
val softwareVersion: String,
val isConnected: Boolean,
val updateAvailable: Boolean
//TODO Possibly have a variable for the watch icon here
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package io.rebble.cobble.shared.ui.common
import android.shared.generated.resources.RebbleIcons
import android.shared.generated.resources.Res
import androidx.compose.foundation.layout.width
import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.Font
Expand Down Expand Up @@ -43,15 +45,15 @@ object RebbleIcons {
@Composable
fun rocket(modifier: Modifier = Modifier.width(24.dp)) = TextIcon(font(), Char(0xe80d), modifier = modifier)
@Composable
fun unpairFromWatch(modifier: Modifier = Modifier.width(24.dp)) = TextIcon(font(), Char(0xe80e), modifier = modifier)
fun unpairFromWatch(modifier: Modifier = Modifier.width(24.dp), tint: Color = LocalContentColor.current) = TextIcon(font(), Char(0xe80e), modifier = modifier, tint = tint)
@Composable
fun applyUpdate(modifier: Modifier = Modifier.width(24.dp)) = TextIcon(font(), Char(0xe80f), modifier = modifier)
fun applyUpdate(modifier: Modifier = Modifier.width(24.dp), tint: Color = LocalContentColor.current) = TextIcon(font(), Char(0xe80f), modifier = modifier, tint = tint)
@Composable
fun checkForUpdates(modifier: Modifier = Modifier.width(24.dp)) = TextIcon(font(), Char(0xe810), modifier = modifier)
fun checkForUpdates(modifier: Modifier = Modifier.width(24.dp), tint: Color = LocalContentColor.current) = TextIcon(font(), Char(0xe810), modifier = modifier, tint = tint)
@Composable
fun disconnectFromWatch(modifier: Modifier = Modifier.width(24.dp)) = TextIcon(font(), Char(0xe811), modifier = modifier)
fun disconnectFromWatch(modifier: Modifier = Modifier.width(24.dp), tint: Color = LocalContentColor.current) = TextIcon(font(), Char(0xe811), modifier = modifier, tint = tint)
@Composable
fun connectToWatch(modifier: Modifier = Modifier.width(24.dp)) = TextIcon(font(), Char(0xe812), modifier = modifier)
fun connectToWatch(modifier: Modifier = Modifier.width(24.dp), tint: Color = LocalContentColor.current) = TextIcon(font(), Char(0xe812), modifier = modifier, tint = tint)
@Composable
fun devices(modifier: Modifier = Modifier.width(24.dp)) = TextIcon(font(), Char(0xe813), modifier = modifier)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ object Routes {
const val LOCKER_APPS = "locker_apps"
const val LOCKER_WATCHFACES = "locker_watchfaces"
const val TEST_PAGE = "test_page"
const val WATCHES_PAGE = "watches_page"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ fun MainView(navController: NavHostController = rememberNavController()) {
composable(Routes.Home.TEST_PAGE) {
HomeScaffold(HomePage.TestPage, onNavChange = navController::navigate)
}
composable(Routes.Home.WATCHES_PAGE) {
HomeScaffold(HomePage.WatchesPage, onNavChange = navController::navigate)
}
dialog("${Routes.DIALOG_APP_INSTALL}?uri={uri}", arguments = listOf(navArgument("uri") {
nullable = false
type = NavType.StringType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
Expand All @@ -15,11 +17,13 @@ import io.rebble.cobble.shared.ui.common.RebbleIcons
import io.rebble.cobble.shared.ui.nav.Routes
import io.rebble.cobble.shared.ui.view.home.locker.Locker
import io.rebble.cobble.shared.ui.view.home.locker.LockerTabs
import io.rebble.cobble.shared.ui.view.home.watches.WatchesPage
import kotlinx.coroutines.launch

open class HomePage {
class Locker(val tab: LockerTabs) : HomePage()
object TestPage : HomePage()
object WatchesPage : HomePage()
}

@Composable
Expand All @@ -28,6 +32,7 @@ fun HomeScaffold(page: HomePage, onNavChange: (String) -> Unit) {
val scope = rememberCoroutineScope()
val searchingState = remember { mutableStateOf(false) }
Scaffold(
contentWindowInsets = WindowInsets(0.dp), // Needed in scaffold for edgetoedge to work
snackbarHost = { SnackbarHost(snackbarHostState) },
/*topBar = {
TopAppBar(
Expand All @@ -51,6 +56,13 @@ fun HomeScaffold(page: HomePage, onNavChange: (String) -> Unit) {
icon = { RebbleIcons.locker() },
label = { Text("Locker") }
)

NavigationBarItem(
selected = page is HomePage.WatchesPage,
onClick = { onNavChange(Routes.Home.WATCHES_PAGE) },
icon = { RebbleIcons.devices() },
label = { Text("Devices") }
)
}
},
floatingActionButton = {
Expand All @@ -67,6 +79,18 @@ fun HomeScaffold(page: HomePage, onNavChange: (String) -> Unit) {
},
)
}
is HomePage.WatchesPage -> {
FloatingActionButton(
modifier = Modifier
.padding(16.dp),
onClick = {
searchingState.value = false //TODO Change this so that it actually goes into pairing mode.
},
content = {
Icon(Icons.Filled.Add, "Pair a watch")
}
)
}
}
}
) { innerPadding ->
Expand All @@ -84,6 +108,9 @@ fun HomeScaffold(page: HomePage, onNavChange: (String) -> Unit) {
}
})
}
is HomePage.WatchesPage -> {
WatchesPage()
}
}
}
}
Expand Down
Loading