-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge activities, add underlining to query, & add Info screen
- Loading branch information
Showing
29 changed files
with
690 additions
and
446 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
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
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
20 changes: 20 additions & 0 deletions
20
app/src/main/kotlin/io/github/jbarr21/appdialer/ui/AppDialerApp.kt
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,20 @@ | ||
package io.github.jbarr21.appdialer.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
import io.github.jbarr21.appdialer.ui.info.InfoScreen | ||
import io.github.jbarr21.appdialer.ui.main.MainScreen | ||
import io.github.jbarr21.appdialer.ui.settings.SettingsScreen | ||
|
||
@Composable | ||
fun AppDialerApp() { | ||
val navController = rememberNavController() | ||
NavHost(navController = navController, startDestination = Screen.Main.toString()) { | ||
composable(Screen.Main.toString()) { MainScreen(hiltViewModel(), navController) } | ||
composable(Screen.Settings.toString()) { SettingsScreen(hiltViewModel(), navController) } | ||
composable(Screen.Info.toString()) { InfoScreen(hiltViewModel(), navController) } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/kotlin/io/github/jbarr21/appdialer/ui/RootActivity.kt
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,24 @@ | ||
package io.github.jbarr21.appdialer.ui | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.core.view.WindowCompat | ||
import com.google.accompanist.insets.ProvideWindowInsets | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class RootActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
WindowCompat.setDecorFitsSystemWindows(window, false) | ||
setContent { | ||
ProvideWindowInsets { | ||
AppTheme { | ||
AppDialerApp() | ||
} | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/kotlin/io/github/jbarr21/appdialer/ui/Screen.kt
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,15 @@ | ||
package io.github.jbarr21.appdialer.ui | ||
|
||
sealed class Screen(val route: String) { | ||
object Main : Screen("main") | ||
object Settings : Screen("settings") | ||
object Info : Screen("info") | ||
|
||
companion object { | ||
val items = listOf( | ||
Main, | ||
Settings, | ||
Info | ||
) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/kotlin/io/github/jbarr21/appdialer/ui/common/AppDialerTopBar.kt
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,55 @@ | ||
package io.github.jbarr21.appdialer.ui.common | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TopAppBar | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.ArrowBack | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavController | ||
import com.google.accompanist.insets.statusBarsPadding | ||
import io.github.jbarr21.appdialer.ui.AppTheme | ||
|
||
@Composable | ||
fun AppDialerTopBar( | ||
title: String, | ||
navController: NavController, | ||
showStatusBar: Boolean = true, | ||
actions: @Composable RowScope.() -> Unit = {} | ||
) { | ||
val appBarColor = Color(0xFF2D2D2D) | ||
TopAppBar( | ||
title = { Text(title) }, | ||
backgroundColor = appBarColor, | ||
contentColor = MaterialTheme.colors.onSurface, | ||
modifier = if (showStatusBar) Modifier | ||
.background(appBarColor) | ||
.statusBarsPadding() else Modifier.padding(0.dp), | ||
actions = actions, | ||
navigationIcon = navController.previousBackStackEntry?.let { | ||
{ | ||
IconButton(onClick = { navController.popBackStack() }) { | ||
Icon(Icons.Default.ArrowBack, contentDescription = null) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun AppDialerTopBarPreview() { | ||
AppTheme(darkTheme = true) { | ||
AppDialerTopBar(title = "AppDialer", NavController(LocalContext.current)) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
app/src/main/kotlin/io/github/jbarr21/appdialer/ui/info/InfoScreen.kt
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,62 @@ | ||
package io.github.jbarr21.appdialer.ui.info | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.CircularProgressIndicator | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.Surface | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import androidx.navigation.NavController | ||
import io.github.jbarr21.appdialer.ui.AppTheme | ||
import io.github.jbarr21.appdialer.ui.common.AppDialerTopBar | ||
|
||
@Composable | ||
fun InfoScreen(viewModel: InfoViewModel = viewModel(), navController: NavController) { | ||
Scaffold(topBar = { AppDialerTopBar(title = "AppDialer Info", navController = navController) }) { | ||
InfoContent(viewModel.appStats) | ||
} | ||
} | ||
|
||
@Composable | ||
fun InfoContent(appStats: AppStats) { | ||
Surface(modifier = Modifier.fillMaxSize()) { | ||
Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(32.dp)) { | ||
if (appStats.isLoaded) { | ||
with (appStats) { | ||
listOf("Total = $totalCount", | ||
"Unique = $uniqueAppCount", | ||
"Main = $mainAppCount", | ||
"Work = $workAppCount" | ||
).let { | ||
Text(it.joinToString("\n")) | ||
} | ||
} | ||
} else { | ||
CircularProgressIndicator() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun InfoScreenPreview() { | ||
AppTheme(darkTheme = true) { | ||
InfoContent(AppStats(142, 121, 100, 42)) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun InfoScreenLoadingPreview() { | ||
AppTheme(darkTheme = true) { | ||
InfoContent(AppStats(-1, -1, -1, -1)) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/kotlin/io/github/jbarr21/appdialer/ui/info/InfoViewModel.kt
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,39 @@ | ||
package io.github.jbarr21.appdialer.ui.info | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import io.github.jbarr21.appdialer.data.AppRepo | ||
import io.github.jbarr21.appdialer.data.isMain | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class InfoViewModel @Inject constructor(private val appRepo: AppRepo) : ViewModel() { | ||
|
||
var appStats by mutableStateOf(AppStats(-1, -1, -1, -1)).also { loadApps() } | ||
|
||
private fun loadApps() { | ||
viewModelScope.launch { | ||
val apps = appRepo.loadApps(true) | ||
appStats = AppStats( | ||
totalCount = apps.size, | ||
uniqueAppCount = apps.groupBy { it.packageName + it.activityName }.size, | ||
mainAppCount = apps.filter { it.user.isMain }.size, | ||
workAppCount = apps.filter { !it.user.isMain }.size | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class AppStats( | ||
val totalCount: Int, | ||
val uniqueAppCount: Int, | ||
val mainAppCount: Int, | ||
val workAppCount: Int | ||
) { | ||
val isLoaded = totalCount >= 0 | ||
} |
Oops, something went wrong.