From e07c355493df96152771947f2222133a947c9ee7 Mon Sep 17 00:00:00 2001 From: andre Date: Mon, 11 Feb 2019 03:17:38 +0100 Subject: [PATCH 1/2] Added navigate up extension method --- gradle.properties | 3 ++ nav/build.gradle | 1 + .../framework/arch/nav/ToolbarExtensions.kt | 34 +++++++++++++++++++ .../res/drawable/ic_arrow_back_white_24dp.xml | 30 ++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 nav/src/main/java/io/stanwood/framework/arch/nav/ToolbarExtensions.kt create mode 100644 nav/src/main/res/drawable/ic_arrow_back_white_24dp.xml diff --git a/gradle.properties b/gradle.properties index 02034d0..35abadb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,3 +25,6 @@ org.gradle.jvmargs=-Xmx1536m # org.gradle.parallel=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true \ No newline at end of file diff --git a/nav/build.gradle b/nav/build.gradle index 6c49fc5..16f283c 100644 --- a/nav/build.gradle +++ b/nav/build.gradle @@ -51,6 +51,7 @@ android { } dependencies { + implementation 'androidx.appcompat:appcompat:1.1.0-alpha01' api 'android.arch.navigation:navigation-fragment-ktx:1.0.0-beta01' api 'android.arch.navigation:navigation-ui-ktx:1.0.0-beta01' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" diff --git a/nav/src/main/java/io/stanwood/framework/arch/nav/ToolbarExtensions.kt b/nav/src/main/java/io/stanwood/framework/arch/nav/ToolbarExtensions.kt new file mode 100644 index 0000000..c8e5951 --- /dev/null +++ b/nav/src/main/java/io/stanwood/framework/arch/nav/ToolbarExtensions.kt @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 stanwood GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * 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. + */ + +package io.stanwood.framework.arch.nav + +import androidx.annotation.DrawableRes +import androidx.appcompat.widget.Toolbar +import androidx.fragment.app.FragmentManager +import androidx.navigation.findNavController + +fun Toolbar.addNavigateUp(fm: FragmentManager, @DrawableRes drawable: Int = R.drawable.ic_arrow_back_white_24dp) { + if (fm.backStackEntryCount > 0) { + navigationIcon = resources.getDrawable(drawable) + setNavigationOnClickListener { findNavController().navigateUp() } + } +} \ No newline at end of file diff --git a/nav/src/main/res/drawable/ic_arrow_back_white_24dp.xml b/nav/src/main/res/drawable/ic_arrow_back_white_24dp.xml new file mode 100644 index 0000000..0820f86 --- /dev/null +++ b/nav/src/main/res/drawable/ic_arrow_back_white_24dp.xml @@ -0,0 +1,30 @@ + + + + + From b9054aa0a3ea6d8df959b4373891a35dd142d9e6 Mon Sep 17 00:00:00 2001 From: andre Date: Mon, 11 Feb 2019 03:49:38 +0100 Subject: [PATCH 2/2] Fixed wrong import --- .../java/io/stanwood/framework/arch/di/module/FragmentModule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/di/src/main/java/io/stanwood/framework/arch/di/module/FragmentModule.kt b/di/src/main/java/io/stanwood/framework/arch/di/module/FragmentModule.kt index b7c8442..4d14977 100644 --- a/di/src/main/java/io/stanwood/framework/arch/di/module/FragmentModule.kt +++ b/di/src/main/java/io/stanwood/framework/arch/di/module/FragmentModule.kt @@ -21,7 +21,7 @@ package io.stanwood.framework.arch.di.module -import android.support.v4.app.Fragment +import androidx.fragment.app.Fragment import dagger.Binds import dagger.Module import io.stanwood.framework.arch.di.scope.FragmentScope