Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f50a4d8106 | |||
| 3535f491f5 | |||
| 1c5b89d2ec | |||
| 127cce1fe4 | |||
| 3bea311400 | |||
| a0b3dfa71e | |||
| 0e9ff3f7f5 | |||
| 004faf77c4 | |||
| 214a6eddf1 | |||
| a4c94003ad | |||
| 4f7c1c1607 | |||
| 16f8fd833e | |||
| 77c3ecc76e | |||
| 062073cb37 | |||
| b9cddc290e |
@@ -1,5 +1,5 @@
|
||||
# Cicerone
|
||||
[](https://bintray.com/terrakok/terramaven/cicerone/_latestVersion)
|
||||
[](https://bintray.com/terrakok/terramaven/cicerone-kotlin/_latestVersion)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
[](https://android-arsenal.com/details/1/4700)
|
||||
@@ -56,7 +56,7 @@ class App : Application() {
|
||||
```
|
||||
|
||||
## How it works?
|
||||
<img src="https://github.com/terrakok/Cicerone/raw/develop/media/CiceroneDiagram.png" alt="drawing" width="800"/>
|
||||
<img src="https://github.com/terrakok/Cicerone/blob/master/media/CiceroneDiagram.png" alt="CiceroneDiagram.png" width="800"/>
|
||||
|
||||
Presenter calls navigation method of Router.
|
||||
|
||||
@@ -158,14 +158,57 @@ Additional you can use `FragmentFactory` for creating your screens:
|
||||
val SomeScreen = FragmentScreen("SomeScreenId") { factory: FragmentFactory -> ... }
|
||||
```
|
||||
|
||||
## Screen parameters and result listener
|
||||
```kotlin
|
||||
//you have to specify screen parameters via new FragmentScreen creation
|
||||
fun SelectPhoto(resultKey: String) = FragmentScreen("SelectPhoto") {
|
||||
SelectPhotoFragment.getNewInstance(resultKey)
|
||||
}
|
||||
```
|
||||
|
||||
```kotlin
|
||||
//listen result
|
||||
fun onSelectPhotoClicked() {
|
||||
router.setResultListener(RESULT_KEY) { data ->
|
||||
view.showPhoto(data as Bitmap)
|
||||
}
|
||||
router.navigateTo(SelectPhoto(RESULT_KEY))
|
||||
}
|
||||
|
||||
//send result
|
||||
fun onPhotoClick(photo: Bitmap) {
|
||||
router.sendResult(resultKey, photoRes)
|
||||
router.exit()
|
||||
}
|
||||
```
|
||||
|
||||
## Sample
|
||||
To see how to add, initialize and use the library and predefined navigators check out
|
||||
the [GitFox (Android GitLab client)](https://gitlab.com/terrakok/gitlab-client)
|
||||
To see how to add, initialize and use the library and predefined navigators see **sample project**
|
||||
(thank you [@Javernaut](https://github.com/Javernaut) for support new library version and migrate sample project to Kotlin!)
|
||||
|
||||
For more complex use case check out the [GitFox (Android GitLab client)](https://gitlab.com/terrakok/gitlab-client)
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Applications with Cicerone inside
|
||||
<a href="https://play.google.com/store/apps/details?id=ru.foodfox.client" target="_blank"><img src="https://lh3.googleusercontent.com/m_8FvRusYXPUNhoP4dqLUrOjaLvXnGSNc8gXd2p-QlzO1vQZV4RBiYxXFoY8wgSnggA" width="256" height="125" alt="Яндекс.Еда — доставка еды/продуктов. Food delivery" /></a><br>
|
||||
Яндекс.Еда — доставка еды/продуктов. Food delivery
|
||||
|
||||
<a href="https://play.google.com/store/apps/details?id=com.foodient.whisk" target="_blank"><img src="https://i.ytimg.com/vi/DSqp6tJkKkI/hqdefault.jpg" width="256" height="192" alt="Whisk: Recipe Saver, Meal Planner & Grocery List" /></a><br>
|
||||
Whisk: Recipe Saver, Meal Planner & Grocery List
|
||||
|
||||
<a href="https://github.com/eduard1abdulmanov123/News" target="_blank"><img src="https://raw.githubusercontent.com/eduard1abdulmanov123/News/dev/screenshots/1.1%20%D0%B4%D0%BB%D1%8F%20%D0%B2%D0%B5%D1%81%D1%82%D0%B8.%D1%80%D1%83.jpg" width="256" height="125" alt="RSS Reader для Вести.Ru" /></a><br>
|
||||
RSS Reader для Вести.Ru
|
||||
|
||||
<a href="https://play.google.com/store/apps/details?id=com.epam.connect.android" target="_blank"><img src="https://lh3.googleusercontent.com/GLMJhNoY37C1RfiwxHb-VBsCu0PgHSVhSmNWStisuSUBt_vUTmEGW4slERP-MgKqmqI" width="256" height="125" alt="EPAM Connect" /></a><br>
|
||||
EPAM Connect
|
||||
|
||||
<a href="https://play.google.com/store/apps/details?id=org.consumerreports.ratings" target="_blank"><img src="https://freesiteslike.com/wp-content/uploads/2017/05/consumer-reports.png" width="256" height="144" alt="Consumer Reports: Product Reviews & Ratings" /></a><br>
|
||||
Consumer Reports: Product Reviews & Ratings
|
||||
|
||||
|
||||
## Participants
|
||||
+ idea and code - Konstantin Tskhovrebov (@terrakok)
|
||||
+ architecture advice, documentation and publication - Vasili Chyrvon (@Jeevuz)
|
||||
|
||||
@@ -18,7 +18,7 @@ ext {
|
||||
bintrayName = 'cicerone-kotlin'
|
||||
publishedGroupId = 'com.github.terrakok'
|
||||
artifact = 'cicerone'
|
||||
libraryVersion = '6.0'
|
||||
libraryVersion = '6.3'
|
||||
gitUrl = 'https://github.com/terrakok/Cicerone'
|
||||
allLicenses = ['MIT']
|
||||
}
|
||||
|
||||
@@ -7,6 +7,23 @@ package com.github.terrakok.cicerone
|
||||
*/
|
||||
abstract class BaseRouter {
|
||||
internal val commandBuffer = CommandBuffer()
|
||||
private val resultWire = ResultWire()
|
||||
|
||||
/**
|
||||
* Sets data listener with given key.
|
||||
*
|
||||
* After first call listener will be removed.
|
||||
*/
|
||||
fun setResultListener(key: String, listener: (data: Any) -> Unit) {
|
||||
resultWire.setResultListener(key, listener)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends data to listener with given key.
|
||||
*/
|
||||
fun sendResult(key: String, data: Any) {
|
||||
resultWire.sendResult(key, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends navigation command array to [CommandBuffer].
|
||||
@@ -15,5 +32,6 @@ abstract class BaseRouter {
|
||||
*/
|
||||
protected fun executeCommands(vararg commands: Command) {
|
||||
commandBuffer.executeCommands(commands)
|
||||
resultWire.flush()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.github.terrakok.cicerone
|
||||
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
internal class ResultWire {
|
||||
private val listeners = mutableMapOf<String, WeakReference<(Any) -> Unit>>()
|
||||
|
||||
fun setResultListener(key: String, listener: (data: Any) -> Unit) {
|
||||
listeners[key] = WeakReference(listener)
|
||||
}
|
||||
|
||||
fun sendResult(key: String, data: Any) {
|
||||
listeners.remove(key)?.get()?.let { listener ->
|
||||
listener(data)
|
||||
}
|
||||
}
|
||||
|
||||
fun flush() {
|
||||
listeners.entries
|
||||
.filter { it.value.get() == null }
|
||||
.forEach { listeners.remove(it.key) }
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,12 @@ open class Router : BaseRouter() {
|
||||
* @param showOnlyTopScreenView if FALSE then all screen views show together
|
||||
*/
|
||||
fun newRootChain(vararg screens: Screen, showOnlyTopScreenView: Boolean = true) {
|
||||
val commands = screens.map { Forward(it, showOnlyTopScreenView) }
|
||||
val commands = screens.mapIndexed { index, screen ->
|
||||
if (index == 0)
|
||||
Replace(screen)
|
||||
else
|
||||
Forward(screen, showOnlyTopScreenView)
|
||||
}
|
||||
executeCommands(BackTo(null), *commands.toTypedArray())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.github.terrakok.cicerone
|
||||
|
||||
/**
|
||||
* Screen is class for description application screen.
|
||||
* Screen is interface for description application screen.
|
||||
*/
|
||||
abstract class Screen {
|
||||
open val screenKey: String = this::class.qualifiedName!!
|
||||
interface Screen {
|
||||
val screenKey: String get() = this::class.java.name
|
||||
}
|
||||
@@ -115,8 +115,8 @@ open class AppNavigator constructor(
|
||||
fragment
|
||||
)
|
||||
when (type) {
|
||||
ADD -> transaction.add(containerId, fragment)
|
||||
REPLACE -> transaction.replace(containerId, fragment)
|
||||
ADD -> transaction.add(containerId, fragment, screen.screenKey)
|
||||
REPLACE -> transaction.replace(containerId, fragment, screen.screenKey)
|
||||
}
|
||||
if (addToBackStack) {
|
||||
val transactionInfo = TransactionInfo(screen.screenKey, type)
|
||||
|
||||
@@ -7,16 +7,19 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentFactory
|
||||
import com.github.terrakok.cicerone.Screen
|
||||
|
||||
sealed class AppScreen : Screen()
|
||||
sealed class AppScreen : Screen
|
||||
|
||||
open class FragmentScreen(
|
||||
override val screenKey: String,
|
||||
private val key: String? = null,
|
||||
val createFragment: (FragmentFactory) -> Fragment
|
||||
) : AppScreen()
|
||||
) : AppScreen() {
|
||||
override val screenKey: String get() = key ?: super.screenKey
|
||||
}
|
||||
|
||||
open class ActivityScreen(
|
||||
override val screenKey: String,
|
||||
private val key: String? = null,
|
||||
val createIntent: (context: Context) -> Intent
|
||||
) : AppScreen() {
|
||||
override val screenKey: String get() = key ?: super.screenKey
|
||||
open val startActivityOptions: Bundle? = null
|
||||
}
|
||||
@@ -1,32 +1,16 @@
|
||||
package androidx.fragment.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* Created by Konstantin Tskhovrebov (aka @terrakok)
|
||||
* on 11.10.16
|
||||
*/
|
||||
|
||||
public class FragmentTransaction {
|
||||
public FragmentTransaction add(int containerViewId, Fragment fragment) {
|
||||
public FragmentTransaction add(int containerViewId, Fragment fragment, String tag) {
|
||||
throw new RuntimeException("Stub!");
|
||||
}
|
||||
|
||||
public final FragmentTransaction add(
|
||||
int containerViewId,
|
||||
Class<? extends Fragment> fragmentClass,
|
||||
Bundle args) {
|
||||
throw new RuntimeException("Stub!");
|
||||
}
|
||||
|
||||
public FragmentTransaction replace(int containerViewId, Fragment fragment) {
|
||||
throw new RuntimeException("Stub!");
|
||||
}
|
||||
|
||||
public final FragmentTransaction replace(
|
||||
int containerViewId,
|
||||
Class<? extends Fragment> fragmentClass,
|
||||
Bundle args) {
|
||||
public FragmentTransaction replace(int containerViewId, Fragment fragment, String tag) {
|
||||
throw new RuntimeException("Stub!");
|
||||
}
|
||||
|
||||
|
||||
@@ -20,43 +20,43 @@ import com.github.terrakok.cicerone.sample.ui.start.StartActivity
|
||||
*/
|
||||
object Screens {
|
||||
|
||||
fun sampleScreen(number: Int) = FragmentScreen("SampleScreen_$number") {
|
||||
fun Sample(number: Int) = FragmentScreen("Sample($number)") {
|
||||
SampleFragment.getNewInstance(number)
|
||||
}
|
||||
|
||||
fun startScreen() = ActivityScreen("StartScreen") {
|
||||
fun Start() = ActivityScreen {
|
||||
Intent(it, StartActivity::class.java)
|
||||
}
|
||||
|
||||
fun mainScreen() = ActivityScreen("MainScreen") {
|
||||
fun Main() = ActivityScreen {
|
||||
Intent(it, MainActivity::class.java)
|
||||
}
|
||||
|
||||
fun bottomNavigationScreen() = ActivityScreen("BottomNavigationScreen") {
|
||||
fun BottomNavigation() = ActivityScreen {
|
||||
Intent(it, BottomNavigationActivity::class.java)
|
||||
}
|
||||
|
||||
fun tabScreen(tabName: String) = FragmentScreen("FragmentScreen") {
|
||||
fun Tab(tabName: String) = FragmentScreen {
|
||||
TabContainerFragment.getNewInstance(tabName)
|
||||
}
|
||||
|
||||
fun forwardScreen(containerName: String, number: Int) = FragmentScreen("ForwardScreen") {
|
||||
fun Forward(containerName: String, number: Int) = FragmentScreen {
|
||||
ForwardFragment.getNewInstance(containerName, number)
|
||||
}
|
||||
|
||||
fun githubScreen() = ActivityScreen("GithubScreen") {
|
||||
fun Github() = ActivityScreen {
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/terrakok/Cicerone"))
|
||||
}
|
||||
|
||||
fun profileScreen() = ActivityScreen("ProfileScreen") {
|
||||
fun Profile() = ActivityScreen {
|
||||
Intent(it, ProfileActivity::class.java)
|
||||
}
|
||||
|
||||
fun profileInfoScreen() = FragmentScreen("ProfileInfoScreen") {
|
||||
fun ProfileInfo() = FragmentScreen {
|
||||
ProfileFragment()
|
||||
}
|
||||
|
||||
fun selectPhotoScreen() = FragmentScreen("SelectPhotoScreen") {
|
||||
SelectPhotoFragment()
|
||||
fun SelectPhoto(resultKey: String) = FragmentScreen {
|
||||
SelectPhotoFragment.getNewInstance(resultKey)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.github.terrakok.cicerone.sample.dagger
|
||||
|
||||
import com.github.terrakok.cicerone.sample.dagger.module.LocalNavigationModule
|
||||
import com.github.terrakok.cicerone.sample.dagger.module.NavigationModule
|
||||
import com.github.terrakok.cicerone.sample.dagger.module.PhotoSelectionModule
|
||||
import com.github.terrakok.cicerone.sample.ui.animations.ProfileActivity
|
||||
import com.github.terrakok.cicerone.sample.ui.animations.photos.SelectPhotoFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.animations.profile.ProfileFragment
|
||||
@@ -20,8 +19,7 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
@Component(modules = [
|
||||
NavigationModule::class,
|
||||
LocalNavigationModule::class,
|
||||
PhotoSelectionModule::class]
|
||||
LocalNavigationModule::class]
|
||||
)
|
||||
interface AppComponent {
|
||||
fun inject(activity: StartActivity)
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.github.terrakok.cicerone.sample.dagger.module
|
||||
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.PhotoSelection
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Created by terrakok 24.11.16
|
||||
*/
|
||||
@Module
|
||||
object PhotoSelectionModule {
|
||||
|
||||
private val photoSelection = PhotoSelection(R.drawable.ava_1)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePhotoSelection() = photoSelection
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package com.github.terrakok.cicerone.sample.mvp.animation
|
||||
|
||||
/**
|
||||
* Created by Konstantin Tskhovrebov (aka @terrakok) on 22.09.18.
|
||||
*/
|
||||
class PhotoSelection(private var selectedPhoto: Int) {
|
||||
|
||||
private var listener: Listener? = null
|
||||
|
||||
fun getSelectedPhoto(): Int {
|
||||
return selectedPhoto
|
||||
}
|
||||
|
||||
fun setSelectedPhoto(selectedPhoto: Int) {
|
||||
this.selectedPhoto = selectedPhoto
|
||||
listener?.onChange(selectedPhoto)
|
||||
}
|
||||
|
||||
fun setListener(listener: Listener?) {
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun onChange(selectedPhoto: Int)
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -2,7 +2,6 @@ package com.github.terrakok.cicerone.sample.mvp.animation.photos
|
||||
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.PhotoSelection
|
||||
import moxy.InjectViewState
|
||||
import moxy.MvpPresenter
|
||||
|
||||
@@ -11,7 +10,7 @@ import moxy.MvpPresenter
|
||||
*/
|
||||
@InjectViewState
|
||||
class SelectPhotoPresenter(
|
||||
private val photoSelection: PhotoSelection,
|
||||
private val resultKey: String,
|
||||
private val router: Router
|
||||
) : MvpPresenter<SelectPhotoView>() {
|
||||
|
||||
@@ -26,7 +25,7 @@ class SelectPhotoPresenter(
|
||||
}
|
||||
|
||||
fun onPhotoClick(photoRes: Int) {
|
||||
photoSelection.setSelectedPhoto(photoRes)
|
||||
router.sendResult(resultKey, photoRes)
|
||||
router.exit()
|
||||
}
|
||||
|
||||
|
||||
+12
-22
@@ -1,8 +1,8 @@
|
||||
package com.github.terrakok.cicerone.sample.mvp.animation.profile
|
||||
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.Screens.selectPhotoScreen
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.PhotoSelection
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.Screens.SelectPhoto
|
||||
import moxy.InjectViewState
|
||||
import moxy.MvpPresenter
|
||||
|
||||
@@ -11,37 +11,27 @@ import moxy.MvpPresenter
|
||||
*/
|
||||
@InjectViewState
|
||||
class ProfilePresenter(
|
||||
private val photoSelection: PhotoSelection,
|
||||
private val router: Router
|
||||
) : MvpPresenter<ProfileView>() {
|
||||
|
||||
companion object {
|
||||
private const val RESULT_KEY = "photo_result"
|
||||
private const val DEFAULT_PHOTO = R.drawable.ava_1
|
||||
}
|
||||
|
||||
override fun onFirstViewAttach() {
|
||||
super.onFirstViewAttach()
|
||||
updatePhoto()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
photoSelection.setListener(null)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun updatePhoto() {
|
||||
viewState!!.showPhoto(photoSelection.getSelectedPhoto())
|
||||
viewState!!.showPhoto(DEFAULT_PHOTO)
|
||||
}
|
||||
|
||||
fun onPhotoClicked() {
|
||||
router.navigateTo(selectPhotoScreen())
|
||||
router.setResultListener(RESULT_KEY) { data ->
|
||||
viewState!!.showPhoto(data as Int)
|
||||
}
|
||||
router.navigateTo(SelectPhoto(RESULT_KEY))
|
||||
}
|
||||
|
||||
fun onBackPressed() {
|
||||
router.exit()
|
||||
}
|
||||
|
||||
init {
|
||||
photoSelection.setListener(object : PhotoSelection.Listener {
|
||||
override fun onChange(selectedPhoto: Int) {
|
||||
updatePhoto()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package com.github.terrakok.cicerone.sample.mvp.bottom.forward
|
||||
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.Screens.forwardScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.githubScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.Forward
|
||||
import com.github.terrakok.cicerone.sample.Screens.Github
|
||||
import moxy.InjectViewState
|
||||
import moxy.MvpPresenter
|
||||
|
||||
@@ -25,11 +25,11 @@ class ForwardPresenter(
|
||||
}
|
||||
|
||||
fun onForwardPressed() {
|
||||
router.navigateTo(forwardScreen(container, number + 1))
|
||||
router.navigateTo(Forward(container, number + 1))
|
||||
}
|
||||
|
||||
fun onGithubPressed() {
|
||||
router.navigateTo(githubScreen())
|
||||
router.navigateTo(Github())
|
||||
}
|
||||
|
||||
fun onBackPressed() {
|
||||
|
||||
+17
-9
@@ -3,7 +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.sampleScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.Sample
|
||||
import moxy.InjectViewState
|
||||
import moxy.MvpPresenter
|
||||
import java.util.concurrent.Executors
|
||||
@@ -29,18 +29,26 @@ class SamplePresenter(
|
||||
}
|
||||
|
||||
fun onForwardCommandClick() {
|
||||
router.navigateTo(sampleScreen(screenNumber + 1))
|
||||
router.navigateTo(Sample(screenNumber + 1))
|
||||
}
|
||||
|
||||
fun onReplaceCommandClick() {
|
||||
router.replaceScreen(sampleScreen(screenNumber + 1))
|
||||
router.replaceScreen(Sample(screenNumber + 1))
|
||||
}
|
||||
|
||||
fun onNewChainCommandClick() {
|
||||
router.newChain(
|
||||
sampleScreen(screenNumber + 1),
|
||||
sampleScreen(screenNumber + 2),
|
||||
sampleScreen(screenNumber + 3)
|
||||
Sample(screenNumber + 1),
|
||||
Sample(screenNumber + 2),
|
||||
Sample(screenNumber + 3)
|
||||
)
|
||||
}
|
||||
|
||||
fun onNewRootChainCommandClick() {
|
||||
router.newRootChain(
|
||||
Sample(screenNumber + 1),
|
||||
Sample(screenNumber + 2),
|
||||
Sample(screenNumber + 3)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -49,20 +57,20 @@ class SamplePresenter(
|
||||
}
|
||||
|
||||
fun onNewRootCommandClick() {
|
||||
router.newRootScreen(sampleScreen(screenNumber + 1))
|
||||
router.newRootScreen(Sample(screenNumber + 1))
|
||||
}
|
||||
|
||||
fun onForwardWithDelayCommandClick() {
|
||||
future?.cancel(true)
|
||||
future = executorService.schedule({ //WARNING! Navigation must be only in UI thread.
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
router.navigateTo(sampleScreen(screenNumber + 1))
|
||||
router.navigateTo(Sample(screenNumber + 1))
|
||||
}
|
||||
}, 5, TimeUnit.SECONDS)
|
||||
}
|
||||
|
||||
fun onBackToCommandClick() {
|
||||
router.backTo(sampleScreen(3))
|
||||
router.backTo(Sample(3))
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
package com.github.terrakok.cicerone.sample.mvp.start
|
||||
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.Screens.bottomNavigationScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.mainScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.profileScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.BottomNavigation
|
||||
import com.github.terrakok.cicerone.sample.Screens.Main
|
||||
import com.github.terrakok.cicerone.sample.Screens.Profile
|
||||
import moxy.MvpPresenter
|
||||
|
||||
/**
|
||||
@@ -12,15 +12,15 @@ import moxy.MvpPresenter
|
||||
class StartActivityPresenter(private val router: Router) : MvpPresenter<StartActivityView>() {
|
||||
|
||||
fun onOrdinaryPressed() {
|
||||
router.navigateTo(mainScreen())
|
||||
router.navigateTo(Main())
|
||||
}
|
||||
|
||||
fun onMultiPressed() {
|
||||
router.navigateTo(bottomNavigationScreen())
|
||||
router.navigateTo(BottomNavigation())
|
||||
}
|
||||
|
||||
fun onResultWithAnimationPressed() {
|
||||
router.navigateTo(profileScreen())
|
||||
router.navigateTo(Profile())
|
||||
}
|
||||
|
||||
fun onBackPressed() {
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import com.github.terrakok.cicerone.Replace
|
||||
import com.github.terrakok.cicerone.androidx.AppNavigator
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.SampleApplication
|
||||
import com.github.terrakok.cicerone.sample.Screens.profileInfoScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.ProfileInfo
|
||||
import com.github.terrakok.cicerone.sample.ui.animations.photos.SelectPhotoFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.animations.profile.ProfileFragment
|
||||
import com.github.terrakok.cicerone.sample.ui.common.BackButtonListener
|
||||
@@ -32,7 +32,7 @@ class ProfileActivity : AppCompatActivity() {
|
||||
|
||||
setContentView(R.layout.activity_container)
|
||||
if (savedInstanceState == null) {
|
||||
navigator.applyCommands(arrayOf<Command>(Replace(profileInfoScreen())))
|
||||
navigator.applyCommands(arrayOf<Command>(Replace(ProfileInfo())))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-5
@@ -8,7 +8,6 @@ import android.widget.ImageView
|
||||
import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.sample.SampleApplication
|
||||
import com.github.terrakok.cicerone.sample.databinding.FragmentSelectPhotoBinding
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.PhotoSelection
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.photos.SelectPhotoPresenter
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.photos.SelectPhotoView
|
||||
import com.github.terrakok.cicerone.sample.ui.animations.ProfileActivity
|
||||
@@ -29,9 +28,6 @@ class SelectPhotoFragment : MvpAppCompatFragment(), SelectPhotoView, BackButtonL
|
||||
@Inject
|
||||
lateinit var router: Router
|
||||
|
||||
@Inject
|
||||
lateinit var photoSelection: PhotoSelection
|
||||
|
||||
@InjectPresenter
|
||||
lateinit var presenter: SelectPhotoPresenter
|
||||
|
||||
@@ -45,8 +41,11 @@ class SelectPhotoFragment : MvpAppCompatFragment(), SelectPhotoView, BackButtonL
|
||||
private val animationDestionationId: Int
|
||||
get() = arguments!!.getInt(ARG_ANIM_DESTINATION)
|
||||
|
||||
private val resultKey: String
|
||||
get() = arguments!!.getString(EXTRA_RESULT_KEY)!!
|
||||
|
||||
@ProvidePresenter
|
||||
fun providePresenter() = SelectPhotoPresenter(photoSelection, router)
|
||||
fun providePresenter() = SelectPhotoPresenter(resultKey, router)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
SampleApplication.INSTANCE.appComponent.inject(this)
|
||||
@@ -100,5 +99,14 @@ class SelectPhotoFragment : MvpAppCompatFragment(), SelectPhotoView, BackButtonL
|
||||
|
||||
companion object {
|
||||
private const val ARG_ANIM_DESTINATION = "arg_anim_dest"
|
||||
private const val EXTRA_RESULT_KEY = "extra_result_key"
|
||||
|
||||
fun getNewInstance(resultKey: String): SelectPhotoFragment {
|
||||
return SelectPhotoFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(EXTRA_RESULT_KEY, resultKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -8,7 +8,6 @@ import android.widget.ImageView
|
||||
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.mvp.animation.PhotoSelection
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.profile.ProfilePresenter
|
||||
import com.github.terrakok.cicerone.sample.mvp.animation.profile.ProfileView
|
||||
import com.github.terrakok.cicerone.sample.ui.animations.ProfileActivity
|
||||
@@ -31,11 +30,8 @@ class ProfileFragment : MvpAppCompatFragment(), ProfileView, BackButtonListener
|
||||
@InjectPresenter
|
||||
lateinit var presenter: ProfilePresenter
|
||||
|
||||
@Inject
|
||||
lateinit var photoSelection: PhotoSelection
|
||||
|
||||
@ProvidePresenter
|
||||
fun providePresenter() = ProfilePresenter(photoSelection, router)
|
||||
fun providePresenter() = ProfilePresenter(router)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
SampleApplication.INSTANCE.appComponent.inject(this)
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
||||
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.Screens.tabScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.Tab
|
||||
import com.github.terrakok.cicerone.sample.mvp.bottom.BottomNavigationPresenter
|
||||
import com.github.terrakok.cicerone.sample.mvp.bottom.BottomNavigationView
|
||||
import com.github.terrakok.cicerone.sample.ui.common.BackButtonListener
|
||||
@@ -87,7 +87,7 @@ class BottomNavigationActivity : MvpAppCompatActivity(), BottomNavigationView, R
|
||||
if (newFragment == null) {
|
||||
transaction.add(
|
||||
R.id.ab_container,
|
||||
tabScreen(tab).createFragment.invoke(fm.fragmentFactory), tab
|
||||
Tab(tab).createFragment.invoke(fm.fragmentFactory), tab
|
||||
)
|
||||
}
|
||||
if (currentFragment != null) {
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import com.github.terrakok.cicerone.Router
|
||||
import com.github.terrakok.cicerone.androidx.AppNavigator
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.SampleApplication
|
||||
import com.github.terrakok.cicerone.sample.Screens.forwardScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.Forward
|
||||
import com.github.terrakok.cicerone.sample.subnavigation.LocalCiceroneHolder
|
||||
import com.github.terrakok.cicerone.sample.ui.common.BackButtonListener
|
||||
import com.github.terrakok.cicerone.sample.ui.common.RouterProvider
|
||||
@@ -47,7 +47,7 @@ class TabContainerFragment : Fragment(), RouterProvider, BackButtonListener {
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
if (childFragmentManager.findFragmentById(R.id.ftc_container) == null) {
|
||||
cicerone.router.replaceScreen(forwardScreen(containerName, 0))
|
||||
cicerone.router.replaceScreen(Forward(containerName, 0))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.github.terrakok.cicerone.Replace
|
||||
import com.github.terrakok.cicerone.androidx.AppNavigator
|
||||
import com.github.terrakok.cicerone.sample.R
|
||||
import com.github.terrakok.cicerone.sample.SampleApplication
|
||||
import com.github.terrakok.cicerone.sample.Screens.sampleScreen
|
||||
import com.github.terrakok.cicerone.sample.Screens.Sample
|
||||
import com.github.terrakok.cicerone.sample.ui.common.BackButtonListener
|
||||
import moxy.MvpAppCompatActivity
|
||||
import java.lang.ref.WeakReference
|
||||
@@ -48,7 +48,7 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {
|
||||
screensSchemeTV = findViewById<View>(R.id.screens_scheme) as TextView
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
navigator.applyCommands(arrayOf<Command>(Replace(sampleScreen(1))))
|
||||
navigator.applyCommands(arrayOf<Command>(Replace(Sample(1))))
|
||||
} else {
|
||||
printScreensScheme()
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class SampleFragment : BaseFragment(), SampleView, BackButtonListener {
|
||||
binding.forwardCommand.setOnClickListener { presenter.onForwardCommandClick() }
|
||||
binding.replaceCommand.setOnClickListener { presenter.onReplaceCommandClick() }
|
||||
binding.newChainCommand.setOnClickListener { presenter.onNewChainCommandClick() }
|
||||
binding.newRootChainCommand.setOnClickListener { presenter.onNewRootChainCommandClick() }
|
||||
binding.newRootCommand.setOnClickListener { presenter.onNewRootCommandClick() }
|
||||
binding.forwardDelayCommand.setOnClickListener { presenter.onForwardWithDelayCommandClick() }
|
||||
binding.backToCommand.setOnClickListener { presenter.onBackToCommandClick() }
|
||||
|
||||
@@ -66,6 +66,18 @@
|
||||
android:text="New chain"
|
||||
android:textSize="28sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/new_root_chain_command"
|
||||
android:layout_width="0dp"
|
||||
android:layout_columnWeight="1"
|
||||
android:layout_margin="4dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_rowWeight="1"
|
||||
android:background="@color/purple"
|
||||
android:gravity="center"
|
||||
android:text="New root chain"
|
||||
android:textSize="28sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/new_root_command"
|
||||
android:layout_width="0dp"
|
||||
@@ -109,6 +121,7 @@
|
||||
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"
|
||||
|
||||
@@ -11,4 +11,5 @@
|
||||
<color name="greensea">#16a085</color>
|
||||
<color name="nephritis">#27ae60</color>
|
||||
<color name="belizehole">#2980b9</color>
|
||||
<color name="purple">#9329B9</color>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user