Skip to content

Commit

Permalink
Merge pull request #152 from Spikeysanju/Update-Navigation-Animation
Browse files Browse the repository at this point in the history
Update `NavHost` to `AnimatedNavHost` #151
  • Loading branch information
Spikeysanju authored Oct 13, 2021
2 parents 5cf78fd + 7308f90 commit 31ebaf0
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

16 changes: 13 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ plugins {
}

android {
compileSdk = 30
compileSdk = 31
buildToolsVersion = "30.0.3"

defaultConfig {
applicationId = "www.spikeysanju.jetquotes"
minSdk = 21
targetSdk = 30
targetSdk = 31
versionCode = 2
versionName = "1.4.0"
versionName = "1.4.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -72,6 +72,13 @@ android {

buildFeatures {
compose = true
kotlinOptions.freeCompilerArgs += "-Xopt-in=androidx.compose.material.ExperimentalMaterialApi"
kotlinOptions.freeCompilerArgs += "-Xopt-in=androidx.compose.foundation.ExperimentalFoundationApi"
kotlinOptions.freeCompilerArgs += "-Xopt-in=androidx.compose.ui.ExperimentalComposeUiApi"
kotlinOptions.freeCompilerArgs += "-Xopt-in=androidx.compose.animation.ExperimentalAnimationApi"
kotlinOptions.freeCompilerArgs += "-Xopt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi"
kotlinOptions.freeCompilerArgs += "-Xopt-in=com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi"
}

composeOptions {
Expand Down Expand Up @@ -128,5 +135,8 @@ dependencies {
// KotlinX Serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${rootProject.extra["kotlinSerializationVersion"]}")

// Accompanist Navigation
implementation("com.google.accompanist:accompanist-navigation-animation:${rootProject.extra["navigationAnimationVersion"]}")


}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<activity
android:name=".view.MainActivity"
android:label="@string/app_name"
android:exported="true"
android:theme="@style/Theme.JetQuotes.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

package www.spikeysanju.jetquotes.navigation

import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
Expand All @@ -37,10 +36,10 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.navArgument
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import www.spikeysanju.jetquotes.view.details.DetailScreen
import www.spikeysanju.jetquotes.view.favourites.FavouritesScreen
import www.spikeysanju.jetquotes.view.quotes.QuotesListScreen
Expand All @@ -52,13 +51,12 @@ object EndPoints {
const val AUTHOR = "author"
}

@ExperimentalMaterialApi
@Composable
fun NavGraph(toggleTheme: () -> Unit) {
val navController = rememberNavController()
val navController = rememberAnimatedNavController()
val actions = remember(navController) { MainActions(navController) }

NavHost(navController, startDestination = Screen.Home.route) {
AnimatedNavHost(navController, startDestination = Screen.Home.route) {
// Quotes List
composable(Screen.Home.route) {
val viewModel: MainViewModel = viewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
Expand All @@ -48,7 +47,6 @@ import www.spikeysanju.jetquotes.navigation.NavGraph
import www.spikeysanju.jetquotes.ui.JetQuotesTheme
import javax.inject.Inject

@ExperimentalMaterialApi
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,17 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.DismissDirection
import androidx.compose.material.DismissValue
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.FractionalThreshold
import androidx.compose.material.Icon
import androidx.compose.material.ListItem
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.SwipeToDismiss
import androidx.compose.material.Text
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.rememberDismissState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import www.spikeysanju.jetquotes.R
import www.spikeysanju.jetquotes.components.EmptyScreen
import www.spikeysanju.jetquotes.components.QuotesCard
import www.spikeysanju.jetquotes.components.TopBarWithBack
Expand All @@ -69,12 +56,11 @@ import www.spikeysanju.jetquotes.ui.red
import www.spikeysanju.jetquotes.utils.FavouriteViewState
import www.spikeysanju.jetquotes.view.viewModel.MainViewModel

@ExperimentalMaterialApi
@Composable
fun FavouritesScreen(viewModel: MainViewModel, actions: MainActions) {
Scaffold(topBar = {
TopBarWithBack(
title = "Favourites",
title = stringResource(R.string.text_favourites),
onBackClick = { actions.upPress() })

}, content = {
Expand Down Expand Up @@ -133,7 +119,7 @@ fun FavouritesScreen(viewModel: MainViewModel, actions: MainActions) {
) {
Icon(
icon,
contentDescription = "Localized description",
contentDescription = stringResource(R.string.text_swipe_to_delete),
modifier = Modifier
.scale(scale)
.clickable { viewModel.deleteFavourite(quote) },
Expand All @@ -146,7 +132,7 @@ fun FavouritesScreen(viewModel: MainViewModel, actions: MainActions) {
text = {
QuotesCard(quote = quote, actions = actions)
},
secondaryText = { Text("Swipe to Remove from favourites!") }
secondaryText = { Text(stringResource(R.string.text_swipe_to_remvoe)) }
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import www.spikeysanju.jetquotes.R
import www.spikeysanju.jetquotes.components.QuotesList
import www.spikeysanju.jetquotes.components.TopBar
import www.spikeysanju.jetquotes.navigation.MainActions
Expand All @@ -47,7 +49,7 @@ fun QuotesListScreen(
) {
Scaffold(topBar = {
TopBar(
title = "JetQuotes",
title = stringResource(R.string.text_jetquotes),
onToggle = { toggleTheme() },
onFavouritesClick = actions.gotoFavourites
)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@
<string name="text_favourites_icon">Favourites Icon</string>
<string name="text_cta_icons">CTA Icons</string>
<string name="text_search">Search Quotes</string>
<string name="text_favourites">Favourites</string>
<string name="text_swipe_to_delete">Swipe to Delete Quotes from Saved</string>
<string name="text_swipe_to_remvoe">Swipe to Remove from favourites!</string>
<string name="text_jetquotes">JetQuotes</string>
</resources>
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ buildscript {
val systemUIControllerVersion by extra("0.12.0")
val expressoVersion by extra("3.3.0")
val kotlinSerializationVersion by extra("1.2.1")
val navigationAnimationVersion by extra("0.19.0")

repositories {
google()
Expand Down
30 changes: 29 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#
# /*
# *
# * * MIT License
# * *
# * * Copyright (c) 2020 Sanju S
# * *
# * * Permission is hereby granted, free of charge, to any person obtaining a copy
# * * of this software and associated documentation files (the "Software"), to deal
# * * in the Software without restriction, including without limitation the rights
# * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# * * copies of the Software, and to permit persons to whom the Software is
# * * furnished to do so, subject to the following conditions:
# * *
# * * The above copyright notice and this permission notice shall be included in all
# * * copies or substantial portions of the Software.
# * *
# * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# * * SOFTWARE.
# *
# */
#

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
Expand All @@ -6,7 +34,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 --illegal-access=permit
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand Down

0 comments on commit 31ebaf0

Please sign in to comment.