Skip to content

Commit

Permalink
Merge pull request #23 from Mr-Pine/undo_unfav
Browse files Browse the repository at this point in the history
Bugfix, Add undo button and exit animation on remove favorite
  • Loading branch information
Mr-Pine authored Sep 8, 2022
2 parents 118d11b + 9323b47 commit 6324bd1
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 466 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

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

25 changes: 12 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ android {
keyPassword signingProperties.getProperty("signing.release.password")
}
}
compileSdk 31
compileSdk 33

defaultConfig {
applicationId "de.mr_pine.xkcdfeed"
minSdk 22
targetSdk 31
versionCode 3
versionName "1.1.1"
versionCode 4
versionName "1.2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -45,13 +45,12 @@ android {
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerExtensionVersion "1.3.1"
}
packagingOptions {
resources {
Expand All @@ -62,25 +61,25 @@ android {

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-util:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'

implementation 'androidx.activity:activity-compose:1.4.0'
implementation 'androidx.activity:activity-compose:1.5.1'

implementation platform('com.google.firebase:firebase-bom:29.0.3')
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-messaging-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx'

implementation 'com.google.android.gms:play-services-auth:20.1.0'
implementation 'com.google.android.gms:play-services-auth:20.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand All @@ -90,15 +89,15 @@ dependencies {
implementation "com.google.accompanist:accompanist-pager:$accompanist_version"
implementation "com.google.accompanist:accompanist-pager-indicators:$accompanist_version"
implementation "com.google.accompanist:accompanist-placeholder-material:$accompanist_version"
implementation 'androidx.navigation:navigation-compose:2.5.0-alpha03'
implementation 'androidx.navigation:navigation-compose:2.5.1'
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "com.android.volley:volley:1.2.1"
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation "androidx.compose.material:material-icons-extended:$compose_version"

implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'

implementation "io.coil-kt:coil-compose:2.0.0-rc02"
implementation "io.coil-kt:coil-compose:2.2.0"

implementation 'de.mr-pine.utils:zoomables:1.1.1'
}
Expand Down
166 changes: 91 additions & 75 deletions app/src/main/java/de/mr_pine/xkcdfeed/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ import android.text.format.DateFormat
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.padding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.*
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.intPreferencesKey
Expand All @@ -35,6 +42,7 @@ import de.mr_pine.xkcdfeed.composables.settings.Theme
import de.mr_pine.xkcdfeed.composables.settings.settingsDataStore
import de.mr_pine.xkcdfeed.composables.single.SingleViewContentStateful
import de.mr_pine.xkcdfeed.ui.theme.XKCDFeedTheme
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

Expand All @@ -52,13 +60,12 @@ class MainActivity : ComponentActivity() {

private lateinit var navController: NavHostController

@OptIn(
ExperimentalPagerApi::class,
androidx.compose.ui.ExperimentalComposeUiApi::class,
androidx.compose.foundation.ExperimentalFoundationApi::class,
androidx.compose.material.ExperimentalMaterialApi::class,
kotlinx.coroutines.ObsoleteCoroutinesApi::class
)

@ExperimentalPagerApi
@ExperimentalComposeUiApi
@ExperimentalFoundationApi
@ExperimentalMaterialApi
@ObsoleteCoroutinesApi
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "onCreate: ${intent.data}")
Expand Down Expand Up @@ -91,6 +98,8 @@ class MainActivity : ComponentActivity() {

val singleComicViewModel: SingleComicViewModel = viewModel()

val scaffoldState = rememberScaffoldState()

val mainViewModel: MainViewModel = ViewModelProvider(
this,
MainViewModelFactory(
Expand All @@ -100,6 +109,7 @@ class MainActivity : ComponentActivity() {
navController::navigate,
this.baseContext,
loginViewModel,
scaffoldState.snackbarHostState,
singleComicViewModel::addToComicCache,
singleComicViewModel::setComicCacheImageLoaded
)
Expand All @@ -124,82 +134,88 @@ class MainActivity : ComponentActivity() {
}
) {

val rootUri = "xkcd.com"
NavHost(navController = navController, startDestination = "mainView") {
composable(
"mainView", deepLinks = listOf(
navDeepLink { uriPattern = rootUri },
navDeepLink { uriPattern = "$rootUri/" },
navDeepLink { uriPattern = "www.$rootUri" },
navDeepLink { uriPattern = "www.$rootUri/" },
)
) {
MainContent(mainViewModel) {
navController.navigate("singleView/${it.id}")
}
lastDestination = "mainView"
}
composable("test") { Text("hello") }
composable(
route = "singleView/{number}",
arguments = listOf(navArgument("number") { type = NavType.IntType }),
deepLinks = listOf(
navDeepLink { uriPattern = "$rootUri/{number}/" },
navDeepLink { uriPattern = "$rootUri/{number}" },
navDeepLink { uriPattern = "www.$rootUri/{number}/" },
navDeepLink { uriPattern = "www.$rootUri/{number}" },
)
) { backStackEntry ->
val comicNumber = backStackEntry.arguments?.getInt("number")

if (lastDestination != "singleView") singleComicViewModel.currentComic =
comicNumber?.let { mainViewModel.loadComic(it) }

SingleViewContentStateful(
mainViewModel = mainViewModel,
singleViewModel = singleComicViewModel,
navigateHome = {
Log.d(TAG, "onCreate: navigating home $backStackEntry, $navController")
navController.navigateUp()
Scaffold(scaffoldState = scaffoldState) { paddingValues ->
val rootUri = "xkcd.com"
NavHost(navController = navController, startDestination = "mainView", modifier = Modifier.padding(paddingValues)) {
composable(
"mainView", deepLinks = listOf(
navDeepLink { uriPattern = rootUri },
navDeepLink { uriPattern = "$rootUri/" },
navDeepLink { uriPattern = "www.$rootUri" },
navDeepLink { uriPattern = "www.$rootUri/" },
)
) {
MainContent(mainViewModel) {
navController.navigate("singleView/${it.id}")
}
)
lastDestination = "singleView"
}
composable(
route = "singleView"
) {
if (singleComicViewModel.currentComic == null) {
singleComicViewModel.currentComic =
mainViewModel.loadComic(mainViewModel.latestComicNumber)
lastDestination = "mainView"
}
SingleViewContentStateful(
mainViewModel = mainViewModel,
singleViewModel = singleComicViewModel,
navigateHome = navController::navigateUp
)

lastDestination = "singleView"
}
composable(route = "settings") {
SettingsComposable(
navigateBack = { navController.navigateUp() },
loginViewModel = loginViewModel,
mainViewModel = mainViewModel,
context = this@MainActivity.baseContext,
onLoginChanged = {
scope.launch {
mainViewModel.initFavoriteList(
this@MainActivity,
true,
if (loginViewModel.signedIn) MainViewModel.ClearType.FIREBASE else MainViewModel.ClearType.LOCAL
composable("test") { Text("hello") }
composable(
route = "singleView/{number}",
arguments = listOf(navArgument("number") { type = NavType.IntType }),
deepLinks = listOf(
navDeepLink { uriPattern = "$rootUri/{number}/" },
navDeepLink { uriPattern = "$rootUri/{number}" },
navDeepLink { uriPattern = "www.$rootUri/{number}/" },
navDeepLink { uriPattern = "www.$rootUri/{number}" },
)
) { backStackEntry ->
val comicNumber = backStackEntry.arguments?.getInt("number")

if (lastDestination != "singleView") singleComicViewModel.currentComic =
comicNumber?.let { mainViewModel.loadComic(it) }

SingleViewContentStateful(
mainViewModel = mainViewModel,
singleViewModel = singleComicViewModel,
navigateHome = {
Log.d(
TAG,
"onCreate: navigating home $backStackEntry, $navController"
)
navController.navigateUp()
}
)
lastDestination = "singleView"
}
composable(
route = "singleView"
) {
if (singleComicViewModel.currentComic == null) {
singleComicViewModel.currentComic =
mainViewModel.loadComic(mainViewModel.latestComicNumber)
}
)
SingleViewContentStateful(
mainViewModel = mainViewModel,
singleViewModel = singleComicViewModel,
navigateHome = navController::navigateUp
)

lastDestination = "singleView"
}
composable(route = "settings") {
SettingsComposable(
navigateBack = { navController.navigateUp() },
loginViewModel = loginViewModel,
mainViewModel = mainViewModel,
context = this@MainActivity.baseContext,
onLoginChanged = {
scope.launch {
mainViewModel.initFavoriteList(
this@MainActivity,
true,
if (loginViewModel.signedIn) MainViewModel.ClearType.FIREBASE else MainViewModel.ClearType.LOCAL
)
}
}
)

lastDestination = "settings"
lastDestination = "settings"
}
}
}

}
}
}
Expand Down
Loading

0 comments on commit 6324bd1

Please sign in to comment.