Skip to content

Commit

Permalink
reorganize app code to become more like default M3 theming. Add ui pa…
Browse files Browse the repository at this point in the history
…ckage name.
  • Loading branch information
atsushieno committed Apr 17, 2024
1 parent 48d6b59 commit bde69a3
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 173 deletions.
6 changes: 2 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AAPApkInstaller"
tools:targetApi="33"
tools:targetApi="34"
android:enableOnBackInvokedCallback="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.AAPApkInstaller">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import dev.atsushieno.cipackageinstaller.AppModel
import dev.atsushieno.cipackageinstaller.CIPackageInstallerActivity
import dev.atsushieno.cipackageinstaller.ui.view.CIPackageInstallerActivity
import dev.atsushieno.cipackageinstaller.GitHubRepositoryInformation
import dev.atsushieno.cipackageinstaller.GitHubRepositoryStore

class MainActivity : CIPackageInstallerActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/res/values/colors.xml

This file was deleted.

4 changes: 0 additions & 4 deletions app/src/main/res/values/themes.xml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInstaller
import android.os.Build
import android.util.Log
import java.lang.RuntimeException

class PackageInstallerReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.atsushieno.cipackageinstaller.ui.view

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier

open class CIPackageInstallerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CIPackageInstallerTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
TopLevelNavHost()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.atsushieno.cipackageinstaller
package dev.atsushieno.cipackageinstaller.ui.view

import android.widget.Toast
import androidx.compose.foundation.border
Expand All @@ -11,7 +11,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
Expand All @@ -26,6 +25,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.atsushieno.cipackageinstaller.AppModel

@Composable
fun MainScreen(onItemClicked: (repo: Int) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.atsushieno.cipackageinstaller
package dev.atsushieno.cipackageinstaller.ui.view

import android.icu.text.DecimalFormat
import android.os.Build
Expand All @@ -21,6 +21,9 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import dev.atsushieno.cipackageinstaller.AppModel
import dev.atsushieno.cipackageinstaller.CIPackageInstallerException
import dev.atsushieno.cipackageinstaller.Repository
import kotlinx.coroutines.Dispatchers

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dev.atsushieno.cipackageinstaller.ui.theme
package dev.atsushieno.cipackageinstaller.ui.view

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
Expand All @@ -15,28 +16,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat

private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
)

private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40

/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
)

@Composable
fun CIPackageInstallerTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
Expand All @@ -50,8 +29,8 @@ fun CIPackageInstallerTheme(
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}

darkTheme -> DarkColorScheme
else -> LightColorScheme
darkTheme -> darkColorScheme()
else -> lightColorScheme()
}
val view = LocalView.current
if (!view.isInEditMode) {
Expand All @@ -64,7 +43,7 @@ fun CIPackageInstallerTheme(

MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
typography = Typography(),
content = content
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.atsushieno.cipackageinstaller.ui.view

import androidx.compose.runtime.Composable
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument

sealed class Routes(val route: String) {
data object Home : Routes("Home")
data object AppDetails : Routes("AppDetails/{index}") {
fun createRoute(index: Int) = "AppDetails/$index"
}
}

@Composable
fun TopLevelNavHost() {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = Routes.Home.route) {
composable(Routes.Home.route) {
MainScreen(onItemClicked = { index ->
navController.navigate(Routes.AppDetails.createRoute(index))
})
}
composable(
Routes.AppDetails.route,
arguments = listOf(navArgument("index") { type = NavType.IntType })
) {
RepositoryDetails(navController, index = it.arguments!!.getInt("index", 0))
}
}
}
10 changes: 0 additions & 10 deletions cipackageinstaller/src/main/res/values/colors.xml

This file was deleted.

3 changes: 0 additions & 3 deletions cipackageinstaller/src/main/res/values/strings.xml

This file was deleted.

3 changes: 0 additions & 3 deletions cipackageinstaller/src/main/res/values/themes.xml

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
activity-compose = "1.8.2"
androidx-junit = "1.1.5"
compose-bom = "2024.03.00"
compose-bom = "2024.04.00"
core-ktx = "1.12.0"
espresso-core = "3.5.1"
github-api = "1.321"
Expand Down

0 comments on commit bde69a3

Please sign in to comment.