Skip to content

Commit

Permalink
Merge pull request #11 from stanwood/feature/toolbar-extension
Browse files Browse the repository at this point in the history
Added navigate up extension method
  • Loading branch information
aclassen authored Feb 11, 2019
2 parents c5c95b0 + b9054aa commit 1a9b6da
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions nav/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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() }
}
}
30 changes: 30 additions & 0 deletions nav/src/main/res/drawable/ic_arrow_back_white_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
~ 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.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>

0 comments on commit 1a9b6da

Please sign in to comment.