Skip to content

Commit

Permalink
feat: Dashboard Screen (ReVanced#18)
Browse files Browse the repository at this point in the history
* feat: add Dashboard Screen and Sources Screen

* fix: fix tab onClick not working

* refactor: remove AppBar

---------

Co-authored-by: CnC-Robert <CnC.Rob3rt@gmail.com>
  • Loading branch information
Aunali321 and CnC-Robert committed Apr 30, 2023
1 parent cb0150a commit 9065c0d
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/deploymentTargetDropDown.xml
/.idea/misc.xml
/.idea/gradle.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ dependencies {
implementation("androidx.activity:activity-compose:1.7.1")

// Compose
implementation(platform("androidx.compose:compose-bom:2023.04.00"))
implementation(platform("androidx.compose:compose-bom:2023.04.01"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.paging:paging-common-ktx:3.1.1")
implementation("androidx.core:core-ktx:1.10.0")

// Accompanist
val accompanistVersion = "0.30.1"
Expand All @@ -68,7 +70,7 @@ dependencies {


// ReVanced
implementation("app.revanced:revanced-patcher:6.4.3")
implementation("app.revanced:revanced-patcher:7.0.0")

// Koin
implementation("io.insert-koin:koin-android:3.4.0")
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/app/revanced/manager/compose/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.isSystemInDarkTheme
import app.revanced.manager.compose.domain.manager.PreferencesManager
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import app.revanced.manager.compose.destination.Destination
import app.revanced.manager.compose.domain.manager.PreferencesManager
import app.revanced.manager.compose.ui.screen.DashboardScreen
import app.revanced.manager.compose.ui.theme.ReVancedManagerTheme
import app.revanced.manager.compose.ui.theme.Theme
import dev.olshevski.navigation.reimagined.*
import dev.olshevski.navigation.reimagined.AnimatedNavHost
import dev.olshevski.navigation.reimagined.NavBackHandler
import dev.olshevski.navigation.reimagined.rememberNavController
import org.koin.android.ext.android.inject

class MainActivity : ComponentActivity() {
Expand All @@ -26,15 +29,17 @@ class MainActivity : ComponentActivity() {
darkTheme = prefs.theme == Theme.SYSTEM && isSystemInDarkTheme() || prefs.theme == Theme.DARK,
dynamicColor = prefs.dynamicColor
) {
val navController = rememberNavController<Destination>(startDestination = Destination.Home)
val navController = rememberNavController<Destination>(startDestination = Destination.Dashboard)

NavBackHandler(navController)

AnimatedNavHost(
controller = navController,
) { destination ->
when (destination) {
Destination.Home -> {} // TODO: Add screens
is Destination.Dashboard -> {
DashboardScreen()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ManagerApplication: Application() {
preferencesModule,
repositoryModule,
serviceModule,
viewModelModule
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import kotlinx.parcelize.Parcelize
sealed interface Destination: Parcelable {

@Parcelize
object Home: Destination
object Dashboard: Destination

} // TODO: Add screens
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package app.revanced.manager.compose.ui.screen

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.Notifications
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.revanced.manager.compose.R
import kotlinx.coroutines.launch

enum class DashboardPage(
val titleResId: Int,
) {
DASHBOARD(R.string.tab_apps),
SOURCES(R.string.tab_sources),
}


@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
@Composable
fun DashboardScreen() {
val pages: Array<DashboardPage> = DashboardPage.values()

val pagerState = rememberPagerState()
val coroutineScope = rememberCoroutineScope()

Scaffold(
topBar = {
TopAppBar(
title = { Text("ReVanced Manager") },
actions = {
IconButton(onClick = {}) {
Icon(imageVector = Icons.Outlined.Info, contentDescription = null)
}
IconButton(onClick = {}) {
Icon(imageVector = Icons.Outlined.Notifications, contentDescription = null)
}
IconButton(onClick = {}) {
Icon(imageVector = Icons.Outlined.Settings, contentDescription = null)
}
}
)
},
floatingActionButton = {
FloatingActionButton(onClick = {}) {
Icon(imageVector = Icons.Default.Add, contentDescription = null)
}
}
) { paddingValues ->
Column(Modifier.padding(paddingValues)) {
TabRow(selectedTabIndex = pagerState.currentPage) {
pages.forEachIndexed { index, page ->
val title = stringResource(id = page.titleResId)
Tab(
selected = pagerState.currentPage == index,
onClick = { coroutineScope.launch { pagerState.animateScrollToPage(index) } },
text = { Text(text = title) },
selectedContentColor = MaterialTheme.colorScheme.primary,
unselectedContentColor = MaterialTheme.colorScheme.onSurface,
)
}
}

HorizontalPager(
pageCount = pages.size,
state = pagerState,
userScrollEnabled = true,
contentPadding = paddingValues,
pageContent = { index ->
when (pages[index]) {
DashboardPage.DASHBOARD -> {
InstalledAppsScreen()
}

DashboardPage.SOURCES -> {
SourcesScreen()
}
}
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app.revanced.manager.compose.ui.screen

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.sp
import app.revanced.manager.compose.R

@Composable
fun InstalledAppsScreen() {
Box(Modifier.fillMaxSize()) {
Text(
text = stringResource(R.string.no_patched_apps_found),
fontSize = 24.sp,
modifier = Modifier
.align(alignment = Alignment.Center)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app.revanced.manager.compose.ui.screen

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.sp
import app.revanced.manager.compose.R

@Composable
fun SourcesScreen() {
Box(Modifier.fillMaxSize()) {
Text(
text = stringResource(R.string.no_sources_set),
fontSize = 24.sp,
modifier = Modifier
.align(alignment = Alignment.Center)
)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<resources>
<string name="app_name">ReVanced Manager</string>
<string name="dashboard">Dashboard</string>
<string name="tab_apps">Apps</string>
<string name="tab_sources">Sources</string>
<string name="no_sources_set">No sources set</string>
<string name="no_patched_apps_found">No patched apps found</string>
</resources>
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("com.android.application") version "7.4.2" apply false
id("com.android.library") version "7.4.2" apply false
id("com.android.application") version "8.0.0" apply false
id("com.android.library") version "8.0.0" apply false
id("org.jetbrains.kotlin.android") version "1.8.20" apply false
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

0 comments on commit 9065c0d

Please sign in to comment.