Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 192e35ca71 | |||
| ff77162654 | |||
| 82256a9785 | |||
| bbd27daee3 | |||
| 4a54fc1dd4 | |||
| 4fc5b26980 | |||
| daef586461 | |||
| 7a862cb061 | |||
| f2de564600 | |||
| 4c674c2583 | |||
| 22182bddb8 | |||
| ae9f4aea70 | |||
| edfc5b5300 | |||
| ee2dd68f09 | |||
| c3873c6e9d | |||
| f44410fcfe | |||
| 608a32c3be | |||
| 17428f0189 | |||
| 1701bc4f36 |
+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)
|
||||
@@ -174,6 +174,7 @@ object Screens {
|
||||
fun Main() = FragmentScreen { MainFragment() }
|
||||
fun AddressSearch() = FragmentScreen { AddressSearchFragment() }
|
||||
fun Profile(userId: Long) = FragmentScreen("Profile_$userId") { ProfileFragment(userId) }
|
||||
fun Browser(url: String) = ActivityScreen { Intent(Intent.ACTION_VIEW, Uri.parse(url)) }
|
||||
}
|
||||
```
|
||||
|
||||
@@ -221,6 +222,7 @@ For more complex use case check out the [GitFox (Android GitLab client)](https:/
|
||||
<a href="https://github.com/eduard1abdulmanov123/News"><img src="https://raw.githubusercontent.com/eduard1abdulmanov123/News/dev/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png" width="64" /> RSS Reader для Вести.Ru</a><br>
|
||||
<a href="https://play.google.com/store/apps/details?id=com.epam.connect.android"><img src="https://play-lh.googleusercontent.com/aN7R6BiR7yt7b3oEoBI30pVwzsdzaWe3TWpw8c9igqoOj79Pm2xVh4_C4qwjSKwjVio=s360" width="64" /> EPAM Connect</a><br>
|
||||
<a href="https://play.google.com/store/apps/details?id=org.consumerreports.ratings"><img src="https://play-lh.googleusercontent.com/dEdOwZOjXAdamytxY1TgY8LS-Hc9FKCcit5HP1RyaKqRAWjDJEyFSQS1XlqQPpeY5UI=s360" width="64" /> Consumer Reports: Product Reviews & Ratings</a><br>
|
||||
<a href="https://play.google.com/store/apps/details?id=ru.zakaz.android"><img src="https://play-lh.googleusercontent.com/jj18yK2dB2MHZ_QdO21aXyznGXteIF2q4mgxY4ubLhFv9gwZqHVDeu1i2FmanS-0Furm=s360" width="64" /> Zakaz.ru</a><br>
|
||||
|
||||
## Participants
|
||||
+ idea and code - Konstantin Tskhovrebov (@terrakok)
|
||||
|
||||
@@ -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.4'
|
||||
gitUrl = 'https://github.com/terrakok/Cicerone'
|
||||
allLicenses = ['MIT']
|
||||
libraryVersion = '7.0'
|
||||
}
|
||||
|
||||
// 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")
|
||||
@@ -10,12 +10,16 @@ abstract class BaseRouter {
|
||||
private val resultWire = ResultWire()
|
||||
|
||||
/**
|
||||
* Sets data listener with given key.
|
||||
* Sets data listener with given key
|
||||
* and returns [ResultListenerHandler] for availability to dispose subscription.
|
||||
*
|
||||
* After first call listener will be removed.
|
||||
*/
|
||||
fun setResultListener(key: String, listener: ResultListener) {
|
||||
resultWire.setResultListener(key, listener)
|
||||
fun setResultListener(
|
||||
key: String,
|
||||
listener: ResultListener
|
||||
): ResultListenerHandler {
|
||||
return resultWire.setResultListener(key, listener)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,6 +36,5 @@ abstract class BaseRouter {
|
||||
*/
|
||||
protected fun executeCommands(vararg commands: Command) {
|
||||
commandBuffer.executeCommands(commands)
|
||||
resultWire.flush()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.github.terrakok.cicerone
|
||||
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
/**
|
||||
* Interface definition for a result callback.
|
||||
*/
|
||||
@@ -9,22 +7,24 @@ fun interface ResultListener {
|
||||
fun onResult(data: Any)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for manual delete subscription and avoid leak
|
||||
*/
|
||||
fun interface ResultListenerHandler {
|
||||
fun dispose()
|
||||
}
|
||||
|
||||
internal class ResultWire {
|
||||
private val listeners = mutableMapOf<String, WeakReference<ResultListener>>()
|
||||
private val listeners = mutableMapOf<String, ResultListener>()
|
||||
|
||||
fun setResultListener(key: String, listener: ResultListener) {
|
||||
listeners[key] = WeakReference(listener)
|
||||
}
|
||||
|
||||
fun sendResult(key: String, data: Any) {
|
||||
listeners.remove(key)?.get()?.let { listener ->
|
||||
listener.onResult(data)
|
||||
fun setResultListener(key: String, listener: ResultListener): ResultListenerHandler {
|
||||
listeners[key] = listener
|
||||
return ResultListenerHandler {
|
||||
listeners.remove(key)
|
||||
}
|
||||
}
|
||||
|
||||
fun flush() {
|
||||
listeners.entries
|
||||
.filter { it.value.get() == null }
|
||||
.forEach { listeners.remove(it.key) }
|
||||
fun sendResult(key: String, data: Any) {
|
||||
listeners.remove(key)?.onResult(data)
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.github.terrakok.cicerone.androidx
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
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.
|
||||
@@ -20,9 +21,16 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
protected val fragmentFactory: FragmentFactory = fragmentManager.fragmentFactory
|
||||
) : Navigator {
|
||||
|
||||
protected val localStackCopy = mutableListOf<TransactionInfo>()
|
||||
protected val localStackCopy = mutableListOf<String>()
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
override fun applyCommands(commands: Array<out Command>) {
|
||||
mainHandler.post {
|
||||
applyCommandsSync(commands)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun applyCommandsSync(commands: Array<out Command>) {
|
||||
fragmentManager.executePendingTransactions()
|
||||
|
||||
//copy stack before apply commands
|
||||
@@ -40,8 +48,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,19 +67,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()
|
||||
@@ -80,10 +86,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,25 +110,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()
|
||||
}
|
||||
@@ -135,13 +141,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,9 +167,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
|
||||
}
|
||||
@@ -171,9 +178,9 @@ open class AppNavigator @JvmOverloads constructor(
|
||||
private fun checkAndStartActivity(screen: ActivityScreen) {
|
||||
// Check if we can start activity
|
||||
val activityIntent = screen.createIntent(activity)
|
||||
if (activityIntent.resolveActivity(activity.packageManager) != null) {
|
||||
try {
|
||||
activity.startActivity(activityIntent, screen.startActivityOptions)
|
||||
} else {
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
unexistingActivity(screen, activityIntent)
|
||||
}
|
||||
}
|
||||
@@ -197,7 +204,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.
|
||||
|
||||
+8
-1
@@ -1,5 +1,6 @@
|
||||
package com.github.terrakok.cicerone.sample.mvp.animation.profile
|
||||
|
||||
import com.github.terrakok.cicerone.ResultListenerHandler
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.Screens.SelectPhoto
|
||||
@@ -13,6 +14,7 @@ import moxy.MvpPresenter
|
||||
class ProfilePresenter(
|
||||
private val router: Router
|
||||
) : MvpPresenter<ProfileView>() {
|
||||
private var resultListenerHandler: ResultListenerHandler? = null
|
||||
|
||||
companion object {
|
||||
private const val RESULT_KEY = "photo_result"
|
||||
@@ -25,12 +27,17 @@ class ProfilePresenter(
|
||||
}
|
||||
|
||||
fun onPhotoClicked() {
|
||||
router.setResultListener(RESULT_KEY) { data ->
|
||||
resultListenerHandler = router.setResultListener(RESULT_KEY) { data ->
|
||||
viewState!!.showPhoto(data as Int)
|
||||
}
|
||||
router.navigateTo(SelectPhoto(RESULT_KEY))
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
resultListenerHandler?.dispose()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
fun onBackPressed() {
|
||||
router.exit()
|
||||
}
|
||||
|
||||
+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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {
|
||||
|
||||
private val navigator: Navigator = object : AppNavigator(this, R.id.main_container) {
|
||||
|
||||
override fun applyCommands(commands: Array<out Command>) {
|
||||
super.applyCommands(commands)
|
||||
override fun applyCommandsSync(commands: Array<out Command>) {
|
||||
super.applyCommandsSync(commands)
|
||||
supportFragmentManager.executePendingTransactions()
|
||||
printScreensScheme()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user