Skip to content

Commit

Permalink
Update splash, Fix crash on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepijn98 committed May 27, 2022
1 parent 619532a commit 04072da
Show file tree
Hide file tree
Showing 22 changed files with 298 additions and 319 deletions.
19 changes: 9 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
object Versions {
private const val versionMajor = 2
private const val versionMinor = 0
private const val versionPatch = 0
private const val versionPatch = 1

const val minSdk = 28
const val targetSdk = 32
Expand All @@ -27,30 +27,28 @@ android {
targetSdk = Versions.targetSdk
versionCode = Versions.generateVersionCode()
versionName = Versions.generateVersionName()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true

proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")

isMinifyEnabled = false
isShrinkResources = false
isDebuggable = false
isJniDebuggable = false
isRenderscriptDebuggable = false
isPseudoLocalesEnabled = false

proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}

create("beta") {
versionNameSuffix = "-BETA"
applicationIdSuffix = ".beta"

isShrinkResources = false
isMinifyEnabled = false
isDebuggable = false
Expand All @@ -64,13 +62,14 @@ android {
getByName("debug") {
versionNameSuffix = "-DEBUG"
applicationIdSuffix = ".debug"

isShrinkResources = false
isMinifyEnabled = false
isDebuggable = true // Set to false whenever publishing debug app to play console otherwise the AAB/APK will show as not signed.
isJniDebuggable = true
isRenderscriptDebuggable = true
isRenderscriptDebuggable = true // Set to false whenever publishing debug app to play console otherwise the AAB/APK will show as not signed.
isPseudoLocalesEnabled = false

proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
Binary file removed app/src/debug/res/drawable/ic_launcher.png
Binary file not shown.
Binary file removed app/src/debug/res/drawable/ic_launcher_original.png
Binary file not shown.
Binary file removed app/src/debug/res/drawable/ic_launcher_round.png
Binary file not shown.
14 changes: 3 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand All @@ -15,12 +13,12 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Nekos"
tools:targetApi="31">
tools:targetApi="s">

<activity
android:name=".SplashActivity"
android:name=".MainActivity"
android:theme="@style/Theme.Nekos"
android:exported="true"
android:theme="@style/Theme.Nekos.Splash"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
<intent-filter>
Expand All @@ -29,12 +27,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:theme="@style/Theme.Nekos"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
</application>

</manifest>
1 change: 0 additions & 1 deletion app/src/main/header_register.svg

This file was deleted.

249 changes: 77 additions & 172 deletions app/src/main/java/dev/vdbroek/nekos/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,83 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.google.gson.Gson
import dev.vdbroek.nekos.components.*
import dev.vdbroek.nekos.models.Neko
import com.github.kittinunf.fuel.core.FuelManager
import dev.vdbroek.nekos.api.Nekos
import dev.vdbroek.nekos.api.UserState
import dev.vdbroek.nekos.components.NekosAppContent
import dev.vdbroek.nekos.ui.Screens
import dev.vdbroek.nekos.ui.screens.*
import dev.vdbroek.nekos.ui.screens.HomeScreenState
import dev.vdbroek.nekos.ui.theme.NekosTheme
import dev.vdbroek.nekos.ui.theme.ThemeState
import dev.vdbroek.nekos.utils.App
import dev.vdbroek.nekos.utils.LocalActivity
import dev.vdbroek.nekos.utils.dataStore

@Composable
fun EnterAnimation(content: @Composable () -> Unit) {
AnimatedVisibility(
visibleState = remember {
MutableTransitionState(
initialState = false
)
}.apply {
targetState = true
},
enter = fadeIn(animationSpec = tween(200), initialAlpha = 0.3f),
exit = fadeOut(animationSpec = tween(200))
) {
content()
}
}
import dev.vdbroek.nekos.utils.*
import kotlinx.coroutines.flow.first

@OptIn(ExperimentalMaterial3Api::class)
class MainActivity : ComponentActivity() {
private val noNavBar = listOf(
Screens.Login.route,
Screens.Register.route,
Screens.Post.route
)
private var isSplashActive by mutableStateOf(true)

override fun onCreate(savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
installSplashScreen()
.also {
it.setKeepOnScreenCondition { isSplashActive }
}
}

super.onCreate(savedInstanceState)

val (version, code) = App.getVersions(this)
App.version = version
App.versionCode = code
App.userAgent = "Nekos-Android/v$version (https://github.com/Pepijn98/Nekos)"

FuelManager.instance.basePath = App.baseUrl
FuelManager.instance.baseHeaders = mapOf("User-Agent" to App.userAgent)

lifecycleScope.launchWhenCreated {
dataStore.data
.first()
.also {
ThemeState.isDark = it[IS_DARK] ?: true
ThemeState.manual = it[MANUAL] ?: false
ThemeState.staggered = it[STAGGERED] ?: false

UserState.isLoggedIn = it[IS_LOGGED_IN] ?: false
if (UserState.isLoggedIn) {
UserState.token = it[TOKEN]
UserState.username = it[USERNAME]
}
}

val (tagsResponse) = Nekos.getTags()
if (tagsResponse != null) {
App.tags.addAll(tagsResponse.tags)
}

val (response, exception) = Nekos.getImages()
when {
response != null -> {
HomeScreenState.images.addAll(response.images.filter { !it.tags.contains(App.buggedTag) })
isSplashActive = false
}
exception != null -> finish()
}
}

setContent {
val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission()
Expand Down Expand Up @@ -112,141 +134,24 @@ class MainActivity : ComponentActivity() {
window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}

Scaffold(
contentColor = MaterialTheme.colorScheme.background,
bottomBar = {
if (!noNavBar.contains(currentRoute)) {
NekosNavBar(
navController = navController,
currentRoute = currentRoute
)
}
},
snackbarHost = {
Alert(
onDismiss = {
App.snackbarHost.isActive = false
App.snackbarHost.currentSnackbarData?.dismiss()
}
)
},
) { padding ->
NavHost(
if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.S) && isSplashActive) {
Box(
modifier = Modifier
.padding(padding),
navController = navController,
startDestination = Screens.Home.route
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
composable(
route = Screens.Home.route
) {
EnterAnimation {
HomeRefresh {
NekosAppBar(
navController = navController,
dataStore = dataStore,
route = currentRoute
) {
Home(
navController = navController
)
}
}
}
}

composable(
route = Screens.Post.route
) {
val jsonData = it.arguments?.getString("data")
val data = Gson().fromJson(jsonData, Neko::class.java)
EnterAnimation {
NekosAppBar(
navController = navController,
dataStore = dataStore,
route = currentRoute
) {
Post(
navController = navController,
data = data
)
}
}
}

composable(
route = Screens.Settings.route
) {
EnterAnimation {
NekosAppBar(
navController = navController,
dataStore = dataStore,
route = currentRoute
) {
Settings(dataStore = dataStore)
}
}
}

// -BEGIN: PROFILE FLOW
composable(
route = Screens.Login.route
) {
EnterAnimation {
Login(
dataStore = dataStore,
navController = navController
)
}
}

composable(
route = Screens.Register.route
) {
EnterAnimation {
Register(
navController = navController
)
}
}

composable(
route = Screens.Profile.route
) {
EnterAnimation {
NekosAppBar(
navController = navController,
dataStore = dataStore,
route = currentRoute
) { toolbarState ->
Profile(
scrollState = toolbarState,
navController = navController
)
}
}
}

composable(
route = Screens.User.route
) {
val userID = it.arguments?.getString("id") ?: return@composable
EnterAnimation {
NekosAppBar(
navController = navController,
dataStore = dataStore,
route = currentRoute
) { toolbarState ->
User(
scrollState = toolbarState,
navController = navController,
id = userID
)
}
}
}
// -END: PROFILE FLOW
Image(
modifier = Modifier
.size(112.dp),
painter = painterResource(id = R.drawable.ic_logo_squircle),
contentDescription = "Splash logo"
)
}
} else {
NekosAppContent(
navController = navController,
currentRoute = currentRoute
)
}
}
}
Expand Down
Loading

0 comments on commit 04072da

Please sign in to comment.