-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from getditto/rr/tool-entry-point
Tools Entry Point
- Loading branch information
Showing
22 changed files
with
597 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// libs. will show an IDE error. This is a bug with Android Studio/IntelliJ. This issue is | ||
// is tracked here: https://youtrack.jetbrains.com/issue/KTIJ-19369 | ||
// Workaround is to suppress the error until the issue linked above is fixed | ||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
alias(libs.plugins.com.android.library) | ||
alias(libs.plugins.org.jetbrains.kotlin.android) | ||
} | ||
|
||
extra["libraryGroupId"] = "live.ditto" | ||
extra["libraryArtifactId"] = "dittotoolsviewer" | ||
extra["libraryVersion"] = "1.0.0" | ||
|
||
apply { | ||
from("${rootProject.projectDir}/gradle/deploy.gradle") | ||
from("${rootProject.projectDir}/gradle/android-common.gradle") | ||
} | ||
|
||
android { | ||
namespace = "live.ditto.dittotoolsviewer" | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.core.ktx) | ||
implementation(libs.androidx.appcompat.appcompat) | ||
implementation(libs.material) | ||
|
||
implementation(platform(libs.androidx.compose.composeBom)) | ||
implementation(libs.androidx.compose.ui.ui) | ||
implementation(libs.androidx.compose.ui.uiToolingPreview) | ||
implementation(libs.androidx.navigation.navigationCompose) | ||
implementation(libs.androidx.compose.material3.material3) | ||
|
||
implementation(libs.live.ditto.ditto) | ||
implementation(libs.live.ditto.databrowser) | ||
implementation(libs.live.ditto.exportlogs) | ||
implementation(libs.live.ditto.presenceviewer) | ||
implementation(libs.live.ditto.diskusage) | ||
implementation(libs.live.ditto.health) | ||
implementation(libs.live.ditto.heartbeat) | ||
implementation(libs.live.ditto.presencedegradationreporter) | ||
implementation(libs.live.ditto.healthmetrics) | ||
implementation(libs.live.ditto.exporter) | ||
|
||
testImplementation(libs.junit.junit) | ||
|
||
androidTestImplementation(libs.androidx.test.ext.junit) | ||
androidTestImplementation(libs.espresso.core) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package live.ditto.dittotoolsviewer.presentation | ||
|
||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Build | ||
import androidx.compose.material3.BottomAppBar | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ExtendedFloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
import ditto.live.dittopresenceviewer.DittoPresenceViewer | ||
import live.ditto.Ditto | ||
import live.ditto.dittodatabrowser.DittoDataBrowser | ||
import live.ditto.dittodiskusage.DittoDiskUsage | ||
import live.ditto.dittoexportlogs.ExportLogs | ||
import live.ditto.dittotoolsviewer.R | ||
import live.ditto.dittotoolsviewer.presentation.navigation.Screens | ||
import live.ditto.dittotoolsviewer.presentation.viewmodel.ToolsViewerViewModel | ||
import live.ditto.health.HealthScreen | ||
import live.ditto.presencedegradationreporter.PresenceDegradationReporterScreen | ||
|
||
/** | ||
* A Composable that you can include in your app that will give a single entry point for all Ditto | ||
* Tools. | ||
* | ||
* @param modifier an optional modifier if you need to adjust the layout to fit the view | ||
* @param ditto your instance of [Ditto] that is required | ||
* @param onExitTools an optional lambda function that will be called whenever a user taps the | ||
* "Exit Tools" button. Use this to do any back navigation or dismissal/hiding of the Tools Viewer | ||
*/ | ||
@Composable | ||
fun DittoToolsViewer( | ||
modifier: Modifier = Modifier, | ||
ditto: Ditto, | ||
onExitTools: () -> Unit = { } | ||
) { | ||
DittoToolsViewerScaffold( | ||
modifier = modifier, | ||
ditto = ditto, | ||
onExitTools = onExitTools | ||
) | ||
} | ||
|
||
@Composable | ||
private fun DittoToolsViewerScaffold( | ||
modifier: Modifier, | ||
ditto: Ditto, | ||
onExitTools: () -> Unit, | ||
viewModel: ToolsViewerViewModel = ToolsViewerViewModel() | ||
) { | ||
|
||
val navController = rememberNavController() | ||
|
||
Scaffold( | ||
modifier = modifier, | ||
bottomBar = { | ||
BottomAppBar( | ||
actions = { | ||
Button(onClick = { onExitTools() }) { | ||
Text(text = "Exit Tools") | ||
} | ||
}, | ||
floatingActionButton = { | ||
MenuFloatingActionButton { | ||
if (navController.currentDestination?.route != Screens.MainScreen.route) { | ||
navController.popBackStack() | ||
} | ||
} | ||
} | ||
) | ||
} | ||
) { contentPadding -> | ||
ToolsViewerContent( | ||
navController = navController, | ||
viewModel = viewModel, | ||
contentPadding = contentPadding, | ||
ditto = ditto | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ToolsViewerContent( | ||
navController: NavHostController, | ||
viewModel: ToolsViewerViewModel, | ||
contentPadding: PaddingValues, | ||
ditto: Ditto, | ||
) { | ||
ToolsViewerNavHost( | ||
navController = navController, | ||
contentPadding = contentPadding, | ||
ditto = ditto, | ||
toolMenuItems = viewModel.toolsMenuItems() | ||
) | ||
} | ||
|
||
@Composable | ||
private fun ToolsViewerNavHost( | ||
navController: NavHostController, | ||
contentPadding: PaddingValues, | ||
ditto: Ditto, | ||
toolMenuItems: List<ToolMenuItem> | ||
) { | ||
NavHost( | ||
modifier = Modifier.padding(contentPadding), | ||
navController = navController, | ||
startDestination = Screens.MainScreen.route, | ||
) { | ||
composable(Screens.MainScreen.route) { | ||
ToolsMenu( | ||
navController = navController, | ||
menuItems = toolMenuItems, | ||
) | ||
} | ||
composable(Screens.PresenceViewerScreen.route) { | ||
DittoPresenceViewer(ditto = ditto) | ||
} | ||
composable(Screens.DataBrowserScreen.route) { | ||
DittoDataBrowser(ditto = ditto) | ||
} | ||
composable(Screens.ExportLogsScreen.route) { | ||
ExportLogs( | ||
onDismiss = { | ||
navController.popBackStack() | ||
} | ||
) | ||
} | ||
composable(Screens.DiskUsageScreen.route) { | ||
DittoDiskUsage(ditto = ditto) | ||
} | ||
composable(Screens.HealthScreen.route) { | ||
HealthScreen() | ||
} | ||
composable(Screens.HeartbeatScreen.route) { | ||
HeartbeatScreen(ditto = ditto) | ||
} | ||
composable(Screens.PresenceDegradationReporterScreen.route) { | ||
PresenceDegradationReporterScreen(ditto = ditto) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun MenuFloatingActionButton(onClick: () -> Unit) { | ||
ExtendedFloatingActionButton( | ||
onClick = { onClick() }, | ||
icon = { Icon(Icons.Filled.Build, stringResource(R.string.tools_menu_content_description)) }, | ||
text = { Text(text = stringResource(R.string.tools_menu)) } | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun MenuFloatingActionButtonPreview() { | ||
MenuFloatingActionButton( | ||
onClick = { } | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.