Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af396eb974 | |||
| b37a6c979d | |||
| 701feee394 | |||
| b399dd3173 | |||
| 2a4969d756 | |||
| 8521b7e19d | |||
| 8b2eab847b | |||
| cbaabaf0bc | |||
| 192e35ca71 | |||
| ff77162654 | |||
| 82256a9785 | |||
| bbd27daee3 | |||
| 4a54fc1dd4 | |||
| 4fc5b26980 | |||
| daef586461 | |||
| 7a862cb061 | |||
| f2de564600 | |||
| 4c674c2583 | |||
| 22182bddb8 | |||
| ae9f4aea70 | |||
| edfc5b5300 | |||
| ee2dd68f09 |
+4
-1
@@ -10,4 +10,7 @@ local.properties
|
||||
**/*.iml
|
||||
|
||||
# Mac OS
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
||||
# GPG keys
|
||||
*.gpg
|
||||
@@ -1,5 +1,5 @@
|
||||
# Cicerone
|
||||
[](https://bintray.com/terrakok/terramaven/cicerone-kotlin/_latestVersion)
|
||||
[](https://repo1.maven.org/maven2/com/github/terrakok/cicerone/)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
[](https://android-arsenal.com/details/1/4700)
|
||||
@@ -152,12 +152,12 @@ Custom navigator can be useful sometimes:
|
||||
```kotlin
|
||||
private val navigator = object : AppNavigator(this, R.id.container) {
|
||||
override fun setupFragmentTransaction(
|
||||
screen: FragmentScreen,
|
||||
fragmentTransaction: FragmentTransaction,
|
||||
currentFragment: Fragment?,
|
||||
nextFragment: Fragment?
|
||||
nextFragment: Fragment
|
||||
) {
|
||||
super.setupFragmentTransaction(fragmentTransaction, currentFragment, nextFragment)
|
||||
fragmentTransaction.setReorderingAllowed(true)
|
||||
//setup your animation
|
||||
}
|
||||
|
||||
override fun applyCommands(commands: Array<out Command>) {
|
||||
|
||||
+4
-7
@@ -1,24 +1,21 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.4.10'
|
||||
ext.kotlin_version = '1.5.21'
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||
classpath 'com.android.tools.build:gradle:4.2.2'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// For the library uploading to the Bintray
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
apply plugin: 'com.github.dcendents.android-maven'
|
||||
|
||||
group = publishedGroupId // Maven Group ID for the artifact
|
||||
|
||||
install {
|
||||
repositories.mavenInstaller {
|
||||
// This generates POM.xml with proper parameters
|
||||
pom.project {
|
||||
packaging 'jar'
|
||||
groupId publishedGroupId
|
||||
artifactId artifact
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
|
||||
version = libraryVersion // Library version
|
||||
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||
|
||||
bintray {
|
||||
// User and ApiKey stored in local.properties
|
||||
user = properties.getProperty("bintrayUser")
|
||||
key = properties.getProperty("bintrayApiKey")
|
||||
configurations = ['archives']
|
||||
// Package info for Bintray
|
||||
pkg {
|
||||
repo = bintrayRepo
|
||||
name = bintrayName
|
||||
licenses = allLicenses
|
||||
vcsUrl = gitUrl
|
||||
publish = true
|
||||
}
|
||||
}
|
||||
|
||||
// Dependency to call only bintrayUpload task
|
||||
bintrayUpload.dependsOn install
|
||||
+4
-42
@@ -1,5 +1,4 @@
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
// This is important even if Android Studio claims it isn't
|
||||
// used. Android can't interpret Java 8 byte code.
|
||||
@@ -13,49 +12,12 @@ dependencies {
|
||||
}
|
||||
|
||||
ext {
|
||||
// This params is for the library uploading to the Bintray
|
||||
bintrayRepo = 'terramaven'
|
||||
bintrayName = 'cicerone-kotlin'
|
||||
publishedGroupId = 'com.github.terrakok'
|
||||
artifact = 'cicerone'
|
||||
libraryVersion = '6.6'
|
||||
gitUrl = 'https://github.com/terrakok/Cicerone'
|
||||
allLicenses = ['MIT']
|
||||
libraryVersion = '7.1'
|
||||
}
|
||||
|
||||
// Configuration of the library uploading to the Bintray
|
||||
// Note: Call 'bintrayUpload' task (it will execute 'install' task first)
|
||||
// I try to include as little properties as possible in these files
|
||||
project.archivesBaseName = 'cicerone' // to fix that project name different from artifact name
|
||||
apply from: 'androidmaven.gradle'
|
||||
apply from: 'bintray.gradle'
|
||||
project.archivesBaseName = artifact // to fix that project name different from artifact name
|
||||
|
||||
// Tasks for sources and javadocs jars
|
||||
task sourcesJar(type: Jar) {
|
||||
from sourceSets.main.kotlin.srcDirs
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives javadocJar
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
groupId = publishedGroupId
|
||||
artifactId = artifact
|
||||
version = libraryVersion
|
||||
|
||||
artifact sourcesJar
|
||||
artifact javadocJar
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
//apply from: 'publish-mavencentral.gradle'
|
||||
//for publication use './gradlew publishReleasePublicationToSonatypeRepository'
|
||||
@@ -0,0 +1,94 @@
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||
properties.each { name, value -> ext[name] = value }
|
||||
|
||||
group = publishedGroupId
|
||||
version = libraryVersion
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
from sourceSets.main.kotlin.srcDirs
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives javadocJar
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
release(MavenPublication) {
|
||||
groupId = publishedGroupId
|
||||
artifactId = artifact
|
||||
version = libraryVersion
|
||||
|
||||
artifact("$buildDir/libs/${artifact}-${version}.jar")
|
||||
artifact sourcesJar
|
||||
artifact javadocJar
|
||||
|
||||
pom {
|
||||
name = artifact
|
||||
description = 'Cicerone is a lightweight library that makes the navigation in an Android app easy.'
|
||||
url = 'https://github.com/terrakok/Cicerone'
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name = "MIT"
|
||||
url = "https://opensource.org/licenses/MIT"
|
||||
}
|
||||
}
|
||||
|
||||
developers {
|
||||
developer {
|
||||
id = 'terrakok'
|
||||
name = 'Konstantin Tskhovrebov'
|
||||
email = 'terrakok@gmail.com'
|
||||
}
|
||||
}
|
||||
|
||||
scm {
|
||||
developerConnection = 'scm:git:ssh://github.com/terrakok/Cicerone.git'
|
||||
url = 'https://github.com/terrakok/Cicerone'
|
||||
}
|
||||
|
||||
// A slightly hacky fix so that your POM will include any transitive dependencies
|
||||
// that your library builds upon
|
||||
withXml {
|
||||
def dependenciesNode = asNode().appendNode('dependencies')
|
||||
|
||||
project.configurations.implementation.allDependencies.each {
|
||||
def dependencyNode = dependenciesNode.appendNode('dependency')
|
||||
dependencyNode.appendNode('groupId', it.group)
|
||||
dependencyNode.appendNode('artifactId', it.name)
|
||||
dependencyNode.appendNode('version', it.version)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
credentials {
|
||||
username = ossrhUsername
|
||||
password = ossrhPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
tasks.getByName("publishReleasePublicationToSonatypeRepository").dependsOn("assemble", "sourcesJar", "javadocJar")
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.github.terrakok.cicerone
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
||||
/**
|
||||
* Passes navigation command to an active [Navigator]
|
||||
* or stores it in the pending commands queue to pass it later.
|
||||
@@ -7,6 +10,7 @@ package com.github.terrakok.cicerone
|
||||
internal class CommandBuffer : NavigatorHolder {
|
||||
private var navigator: Navigator? = null
|
||||
private val pendingCommands = mutableListOf<Array<out Command>>()
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
override fun setNavigator(navigator: Navigator) {
|
||||
this.navigator = navigator
|
||||
@@ -24,6 +28,8 @@ internal class CommandBuffer : NavigatorHolder {
|
||||
* @param commands navigation command array
|
||||
*/
|
||||
fun executeCommands(commands: Array<out Command>) {
|
||||
navigator?.applyCommands(commands) ?: pendingCommands.add(commands)
|
||||
mainHandler.post {
|
||||
navigator?.applyCommands(commands) ?: pendingCommands.add(commands)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,9 @@ open class Router : BaseRouter() {
|
||||
* Open new screen and add it to the screens chain.
|
||||
*
|
||||
* @param screen screen
|
||||
* @param clearContainer if FALSE then new screen shows over previous
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun navigateTo(screen: Screen, clearContainer: Boolean = true) {
|
||||
executeCommands(Forward(screen, clearContainer))
|
||||
fun navigateTo(screen: Screen) {
|
||||
executeCommands(Forward(screen))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,11 +55,9 @@ open class Router : BaseRouter() {
|
||||
* Opens several screens inside single transaction.
|
||||
*
|
||||
* @param screens
|
||||
* @param showOnlyTopScreenView if FALSE then all screen views show together
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun newChain(vararg screens: Screen, showOnlyTopScreenView: Boolean = true) {
|
||||
val commands = screens.map { Forward(it, showOnlyTopScreenView) }
|
||||
fun newChain(vararg screens: Screen) {
|
||||
val commands = screens.map { Forward(it) }
|
||||
executeCommands(*commands.toTypedArray())
|
||||
}
|
||||
|
||||
@@ -69,15 +65,13 @@ open class Router : BaseRouter() {
|
||||
* Clear current stack and open several screens inside single transaction.
|
||||
*
|
||||
* @param screens
|
||||
* @param showOnlyTopScreenView if FALSE then all screen views show together
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun newRootChain(vararg screens: Screen, showOnlyTopScreenView: Boolean = true) {
|
||||
fun newRootChain(vararg screens: Screen) {
|
||||
val commands = screens.mapIndexed { index, screen ->
|
||||
if (index == 0)
|
||||
Replace(screen)
|
||||
else
|
||||
Forward(screen, showOnlyTopScreenView)
|
||||
Forward(screen)
|
||||
}
|
||||
executeCommands(BackTo(null), *commands.toTypedArray())
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import androidx.fragment.app.*
|
||||
import com.github.terrakok.cicerone.*
|
||||
import com.github.terrakok.cicerone.androidx.TransactionInfo.Type.ADD
|
||||
import com.github.terrakok.cicerone.androidx.TransactionInfo.Type.REPLACE
|
||||
|
||||
/**
|
||||
* Navigator implementation for launch fragments and activities.
|
||||
@@ -21,7 +19,7 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
protected val fragmentFactory: FragmentFactory = fragmentManager.fragmentFactory
|
||||
) : Navigator {
|
||||
|
||||
protected val localStackCopy = mutableListOf<TransactionInfo>()
|
||||
protected val localStackCopy = mutableListOf<String>()
|
||||
|
||||
override fun applyCommands(commands: Array<out Command>) {
|
||||
fragmentManager.executePendingTransactions()
|
||||
@@ -41,8 +39,7 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
private fun copyStackToLocal() {
|
||||
localStackCopy.clear()
|
||||
for (i in 0 until fragmentManager.backStackEntryCount) {
|
||||
val str = fragmentManager.getBackStackEntryAt(i).name
|
||||
localStackCopy.add(TransactionInfo.fromString(str))
|
||||
localStackCopy.add(fragmentManager.getBackStackEntryAt(i).name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,19 +58,18 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
protected open fun forward(command: Forward) {
|
||||
when (val screen = command.screen as AppScreen) {
|
||||
when (val screen = command.screen) {
|
||||
is ActivityScreen -> {
|
||||
checkAndStartActivity(screen)
|
||||
}
|
||||
is FragmentScreen -> {
|
||||
val type = if (command.clearContainer) REPLACE else ADD
|
||||
commitNewFragmentScreen(screen, type, true)
|
||||
commitNewFragmentScreen(screen, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun replace(command: Replace) {
|
||||
when (val screen = command.screen as AppScreen) {
|
||||
when (val screen = command.screen) {
|
||||
is ActivityScreen -> {
|
||||
checkAndStartActivity(screen)
|
||||
activity.finish()
|
||||
@@ -81,10 +77,10 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
is FragmentScreen -> {
|
||||
if (localStackCopy.isNotEmpty()) {
|
||||
fragmentManager.popBackStack()
|
||||
val removed = localStackCopy.removeAt(localStackCopy.lastIndex)
|
||||
commitNewFragmentScreen(screen, removed.type, true)
|
||||
localStackCopy.removeAt(localStackCopy.lastIndex)
|
||||
commitNewFragmentScreen(screen, true)
|
||||
} else {
|
||||
commitNewFragmentScreen(screen, REPLACE, false)
|
||||
commitNewFragmentScreen(screen, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,25 +101,25 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
|
||||
protected open fun commitNewFragmentScreen(
|
||||
screen: FragmentScreen,
|
||||
type: TransactionInfo.Type,
|
||||
addToBackStack: Boolean
|
||||
) {
|
||||
val fragment = screen.createFragment(fragmentFactory)
|
||||
val transaction = fragmentManager.beginTransaction()
|
||||
transaction.setReorderingAllowed(true)
|
||||
setupFragmentTransaction(
|
||||
screen,
|
||||
transaction,
|
||||
fragmentManager.findFragmentById(containerId),
|
||||
fragment
|
||||
)
|
||||
when (type) {
|
||||
ADD -> transaction.add(containerId, fragment, screen.screenKey)
|
||||
REPLACE -> transaction.replace(containerId, fragment, screen.screenKey)
|
||||
if (screen.clearContainer) {
|
||||
transaction.replace(containerId, fragment, screen.screenKey)
|
||||
} else {
|
||||
transaction.add(containerId, fragment, screen.screenKey)
|
||||
}
|
||||
if (addToBackStack) {
|
||||
val transactionInfo = TransactionInfo(screen.screenKey, type)
|
||||
transaction.addToBackStack(transactionInfo.toString())
|
||||
localStackCopy.add(transactionInfo)
|
||||
transaction.addToBackStack(screen.screenKey)
|
||||
localStackCopy.add(screen.screenKey)
|
||||
}
|
||||
transaction.commit()
|
||||
}
|
||||
@@ -136,13 +132,13 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
backToRoot()
|
||||
} else {
|
||||
val screenKey = command.screen.screenKey
|
||||
val index = localStackCopy.indexOfFirst { it.screenKey == screenKey }
|
||||
val index = localStackCopy.indexOfFirst { it == screenKey }
|
||||
if (index != -1) {
|
||||
val forRemove = localStackCopy.subList(index, localStackCopy.size)
|
||||
fragmentManager.popBackStack(forRemove.first().toString(), 0)
|
||||
forRemove.clear()
|
||||
} else {
|
||||
backToUnexisting(command.screen as AppScreen)
|
||||
backToUnexisting(command.screen)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,9 +158,10 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
* @param nextFragment next screen fragment
|
||||
*/
|
||||
protected open fun setupFragmentTransaction(
|
||||
screen: FragmentScreen,
|
||||
fragmentTransaction: FragmentTransaction,
|
||||
currentFragment: Fragment?,
|
||||
nextFragment: Fragment?
|
||||
nextFragment: Fragment
|
||||
) {
|
||||
// Do nothing by default
|
||||
}
|
||||
@@ -198,7 +195,7 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
*
|
||||
* @param screen screen
|
||||
*/
|
||||
protected open fun backToUnexisting(screen: AppScreen) {
|
||||
protected open fun backToUnexisting(screen: Screen) {
|
||||
backToRoot()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,25 +7,40 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentFactory
|
||||
import com.github.terrakok.cicerone.Screen
|
||||
|
||||
sealed class AppScreen : Screen
|
||||
|
||||
fun interface Creator<A, R> {
|
||||
fun create(argument: A): R
|
||||
}
|
||||
|
||||
open class FragmentScreen @JvmOverloads constructor(
|
||||
private val key: String? = null,
|
||||
private val fragmentCreator: Creator<FragmentFactory, Fragment>
|
||||
) : AppScreen() {
|
||||
override val screenKey: String get() = key ?: super.screenKey
|
||||
fun createFragment(factory: FragmentFactory) = fragmentCreator.create(factory)
|
||||
interface FragmentScreen : Screen {
|
||||
val clearContainer: Boolean get() = true
|
||||
fun createFragment(factory: FragmentFactory): Fragment
|
||||
|
||||
companion object {
|
||||
operator fun invoke(
|
||||
key: String? = null,
|
||||
clearContainer: Boolean = true,
|
||||
fragmentCreator: Creator<FragmentFactory, Fragment>
|
||||
) = object : FragmentScreen {
|
||||
override val screenKey = key ?: fragmentCreator::class.java.name
|
||||
override val clearContainer = clearContainer
|
||||
override fun createFragment(factory: FragmentFactory) = fragmentCreator.create(factory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class ActivityScreen @JvmOverloads constructor(
|
||||
private val key: String? = null,
|
||||
private val intentCreator: Creator<Context, Intent>
|
||||
) : AppScreen() {
|
||||
override val screenKey: String get() = key ?: super.screenKey
|
||||
open val startActivityOptions: Bundle? = null
|
||||
fun createIntent(context: Context) = intentCreator.create(context)
|
||||
interface ActivityScreen : Screen {
|
||||
val startActivityOptions: Bundle? get() = null
|
||||
fun createIntent(context: Context): Intent
|
||||
|
||||
companion object {
|
||||
operator fun invoke(
|
||||
key: String? = null,
|
||||
startActivityOptions: Bundle? = null,
|
||||
intentCreator: Creator<Context, Intent>
|
||||
) = object : ActivityScreen {
|
||||
override val screenKey = key ?: intentCreator::class.java.name
|
||||
override val startActivityOptions = startActivityOptions
|
||||
override fun createIntent(context: Context) = intentCreator.create(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.github.terrakok.cicerone.androidx
|
||||
|
||||
data class TransactionInfo(
|
||||
val screenKey: String,
|
||||
val type: Type
|
||||
) {
|
||||
enum class Type(val symbol: Char) {
|
||||
ADD('+'),
|
||||
REPLACE('-');
|
||||
}
|
||||
|
||||
override fun toString() = screenKey + type.symbol
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromString(str: String) = TransactionInfo(
|
||||
str.dropLast(1),
|
||||
if (str.last() == Type.ADD.symbol) Type.ADD else Type.REPLACE
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,7 @@ interface Command
|
||||
/**
|
||||
* Opens new screen.
|
||||
*/
|
||||
data class Forward(
|
||||
val screen: Screen,
|
||||
val clearContainer: Boolean
|
||||
) : Command
|
||||
data class Forward(val screen: Screen) : Command
|
||||
|
||||
/**
|
||||
* Replaces the current screen.
|
||||
|
||||
+6
-6
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -42,10 +42,10 @@ android {
|
||||
}
|
||||
|
||||
ext {
|
||||
androidXVersion = "1.2.0"
|
||||
materialVersion = "1.2.1"
|
||||
moxyVersion = "2.2.0"
|
||||
daggerVersion = "2.29.1"
|
||||
androidXVersion = "1.3.0"
|
||||
materialVersion = "1.4.0"
|
||||
moxyVersion = "2.2.2"
|
||||
daggerVersion = "2.38"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -69,5 +69,5 @@ dependencies {
|
||||
implementation ('com.ashokvarma.android:bottom-navigation-bar:1.3.0') {
|
||||
exclude group: "com.android.support", module: "design"
|
||||
}
|
||||
implementation "androidx.core:core-ktx:1.3.2"
|
||||
implementation "androidx.core:core-ktx:1.6.0"
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.github.terrakok.cicerone.sample.ui.bottom.ForwardFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.bottom.TabContainerFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.main.MainActivity
|
||||
import com.github.terrakok.cicerone.sample.ui.main.SampleFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.main.SemiTransparentFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.start.StartActivity
|
||||
|
||||
/**
|
||||
@@ -59,4 +60,8 @@ object Screens {
|
||||
fun SelectPhoto(resultKey: String) = FragmentScreen {
|
||||
SelectPhotoFragment.getNewInstance(resultKey)
|
||||
}
|
||||
|
||||
fun SemiTransparent() = FragmentScreen(clearContainer = false) {
|
||||
SemiTransparentFragment()
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.github.terrakok.cicerone.sample.ui.bottom.BottomNavigationActivity
|
||||
import com.github.terrakok.cicerone.sample.ui.bottom.TabContainerFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.main.MainActivity
|
||||
import com.github.terrakok.cicerone.sample.ui.main.SampleFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.main.SemiTransparentFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.start.StartActivity
|
||||
import dagger.Component
|
||||
import javax.inject.Singleton
|
||||
@@ -37,4 +38,6 @@ interface AppComponent {
|
||||
fun inject(fragment: SelectPhotoFragment)
|
||||
|
||||
fun inject(activity: ProfileActivity)
|
||||
|
||||
fun inject(fragment: SemiTransparentFragment)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.github.terrakok.cicerone.sample.mvp.main
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.Screens
|
||||
import com.github.terrakok.cicerone.sample.Screens.Sample
|
||||
import moxy.InjectViewState
|
||||
import moxy.MvpPresenter
|
||||
@@ -56,6 +57,10 @@ class SamplePresenter(
|
||||
router.finishChain()
|
||||
}
|
||||
|
||||
fun onForwardNccCommandClick() {
|
||||
router.navigateTo(Screens.SemiTransparent())
|
||||
}
|
||||
|
||||
fun onNewRootCommandClick() {
|
||||
router.newRootScreen(Sample(screenNumber + 1))
|
||||
}
|
||||
|
||||
+11
-6
@@ -10,6 +10,7 @@ import com.github.terrakok.cicerone.Navigator
|
||||
import com.github.terrakok.cicerone.NavigatorHolder
|
||||
import com.github.terrakok.cicerone.Replace
|
||||
import com.github.terrakok.cicerone.androidx.AppNavigator
|
||||
import com.github.terrakok.cicerone.androidx.FragmentScreen
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.SampleApplication
|
||||
import com.github.terrakok.cicerone.sample.Screens.ProfileInfo
|
||||
@@ -47,14 +48,18 @@ class ProfileActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private val navigator: Navigator = object : AppNavigator(this, R.id.container) {
|
||||
|
||||
override fun setupFragmentTransaction(fragmentTransaction: FragmentTransaction, currentFragment: Fragment?, nextFragment: Fragment?) {
|
||||
override fun setupFragmentTransaction(
|
||||
screen: FragmentScreen,
|
||||
fragmentTransaction: FragmentTransaction,
|
||||
currentFragment: Fragment?,
|
||||
nextFragment: Fragment
|
||||
) {
|
||||
if (currentFragment is ProfileFragment
|
||||
&& nextFragment is SelectPhotoFragment) {
|
||||
&& nextFragment is SelectPhotoFragment) {
|
||||
setupSharedElementForProfileToSelectPhoto(
|
||||
currentFragment,
|
||||
nextFragment,
|
||||
fragmentTransaction
|
||||
currentFragment,
|
||||
nextFragment,
|
||||
fragmentTransaction
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import androidx.fragment.app.Fragment
|
||||
import moxy.MvpAppCompatFragment
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
abstract class BaseFragment : MvpAppCompatFragment() {
|
||||
abstract class BaseFragment : MvpAppCompatFragment(), ChainScreen {
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
|
||||
|
||||
@@ -5,4 +5,9 @@ import java.lang.ref.WeakReference
|
||||
|
||||
interface ChainHolder {
|
||||
val chain: MutableList<WeakReference<Fragment>>
|
||||
}
|
||||
|
||||
interface ChainScreen {
|
||||
val name: String
|
||||
val creationTime: Long
|
||||
}
|
||||
@@ -75,10 +75,10 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {
|
||||
}
|
||||
|
||||
private fun printScreensScheme() {
|
||||
val fragments = ArrayList<SampleFragment>()
|
||||
val fragments = ArrayList<ChainScreen>()
|
||||
for (fragmentReference in chain) {
|
||||
val fragment = fragmentReference.get()
|
||||
if (fragment != null && fragment is SampleFragment) {
|
||||
if (fragment != null && fragment is ChainScreen) {
|
||||
fragments.add(fragment)
|
||||
}
|
||||
}
|
||||
@@ -86,9 +86,9 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {
|
||||
val t = f1.creationTime - f2.creationTime
|
||||
if (t > 0) 1 else if (t < 0) -1 else 0
|
||||
}
|
||||
val keys = ArrayList<Int>()
|
||||
val keys = ArrayList<String>()
|
||||
for (fragment in fragments) {
|
||||
keys.add(fragment.number)
|
||||
keys.add(fragment.name)
|
||||
}
|
||||
screensSchemeTV.text = "Chain: $keys"
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ class SampleFragment : BaseFragment(), SampleView, BackButtonListener {
|
||||
@ProvidePresenter
|
||||
fun createSamplePresenter() = SamplePresenter(router, arguments!!.getInt(EXTRA_NUMBER))
|
||||
|
||||
val number: Int
|
||||
get() = arguments!!.getInt(EXTRA_NUMBER)
|
||||
val creationTime: Long
|
||||
override val name: String
|
||||
get() = arguments!!.getInt(EXTRA_NUMBER).toString()
|
||||
override val creationTime: Long
|
||||
get() = arguments!!.getLong(EXTRA_TIME, 0L)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -59,6 +59,7 @@ class SampleFragment : BaseFragment(), SampleView, BackButtonListener {
|
||||
binding.forwardDelayCommand.setOnClickListener { presenter.onForwardWithDelayCommandClick() }
|
||||
binding.backToCommand.setOnClickListener { presenter.onBackToCommandClick() }
|
||||
binding.finishChainCommand.setOnClickListener { presenter.onFinishChainCommandClick() }
|
||||
binding.forwardNccCommand.setOnClickListener { presenter.onForwardNccCommandClick() }
|
||||
}
|
||||
|
||||
override fun setTitle(title: String) {
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.github.terrakok.cicerone.sample.ui.main
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.SampleApplication
|
||||
import com.github.terrakok.cicerone.sample.databinding.FragmentSampleBinding
|
||||
import com.github.terrakok.cicerone.sample.databinding.FragmentSemitransparentBinding
|
||||
import com.github.terrakok.cicerone.sample.ui.common.BackButtonListener
|
||||
import moxy.MvpAppCompatFragment
|
||||
import javax.inject.Inject
|
||||
|
||||
class SemiTransparentFragment : BaseFragment(), BackButtonListener {
|
||||
lateinit var binding: FragmentSemitransparentBinding
|
||||
|
||||
@Inject
|
||||
lateinit var router: Router
|
||||
|
||||
override val name: String = "D"
|
||||
override val creationTime: Long = System.currentTimeMillis()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
SampleApplication.INSTANCE.appComponent.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = FragmentSemitransparentBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
binding.background.setOnClickListener { onBackPressed() }
|
||||
binding.backButton.setOnClickListener { onBackPressed() }
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
router.exit()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -121,11 +121,21 @@
|
||||
android:layout_margin="4dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_rowWeight="1"
|
||||
android:layout_columnSpan="2"
|
||||
android:background="@color/greensea"
|
||||
android:gravity="center"
|
||||
android:text="Finish chain"
|
||||
android:textSize="28sp"/>
|
||||
<TextView
|
||||
android:id="@+id/forward_ncc_command"
|
||||
android:layout_width="0dp"
|
||||
android:layout_columnWeight="1"
|
||||
android:layout_margin="4dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_rowWeight="1"
|
||||
android:background="@color/nephritis"
|
||||
android:gravity="center"
|
||||
android:text="Forward not clearing container"
|
||||
android:textSize="28sp"/>
|
||||
|
||||
</GridLayout>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/semitransparent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
tools:ignore="HardcodedText">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="40dp"
|
||||
android:background="@color/accent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="This is not a dialog.\n This is a regular screen."
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/back_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="16dp"
|
||||
android:minWidth="100dp"
|
||||
android:text="Back"
|
||||
android:textSize="20sp" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
@@ -4,6 +4,8 @@
|
||||
<color name="primary_dark">#c0392b</color>
|
||||
<color name="accent">#e67e22</color>
|
||||
|
||||
<color name="semitransparent">#99000000</color>
|
||||
|
||||
|
||||
<color name="alizarin">#e74c3c</color>
|
||||
<color name="carrot">#e67e22</color>
|
||||
|
||||
Reference in New Issue
Block a user