Skip to content

Commit 1f1d9b7

Browse files
committed
release version 1.2.3
1 parent f8cc77d commit 1f1d9b7

File tree

18 files changed

+248
-152
lines changed

18 files changed

+248
-152
lines changed

flairframework/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ android {
99
compileSdkVersion 28
1010

1111
defaultConfig {
12-
minSdkVersion 16
12+
minSdkVersion 19
1313
targetSdkVersion 28
14-
versionCode 10202
15-
versionName "1.2.2"
14+
versionCode 10203
15+
versionName "1.2.3"
1616

1717
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1818
}

flairframework/src/main/java/com/rasalexman/flairframework/common/adapters/FlairPagerAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.rasalexman.flairframework.interfaces.IMediator
1111
* @param mediators
1212
* the list of registered mediators ex listOf(mediator<T1>(),mediator<T2>(),mediator<T3>())
1313
*/
14-
class FlairPagerAdapter(private val mediators:List<IMediator>, private val tabNames:List<String> = listOf()) : PagerAdapter() {
14+
open class FlairPagerAdapter(private val mediators:List<IMediator>, private val tabNames:List<String>) : PagerAdapter() {
1515

1616
override fun isViewFromObject(p0: View, p1: Any): Boolean {
1717
return p0 == (p1 as? View)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.rasalexman.flairframework.core.animation
2+
3+
import android.view.ViewTreeObserver
4+
5+
/**
6+
* Animation PreDraw Listener used as event handler when view added to container stage and it was initialized
7+
*/
8+
class AnimationPreDrawListener(private var toView: android.view.View?, private var startAnimationHandler: (() -> Unit)?) : ViewTreeObserver.OnPreDrawListener {
9+
/**
10+
* Does animation initialized and started
11+
*/
12+
private var hasRun: Boolean = false
13+
14+
/**
15+
* Wait until ui is drawing on screen
16+
*/
17+
override fun onPreDraw(): Boolean = onReadyOrAborted()
18+
19+
/**
20+
* When animation is ready to be played
21+
*/
22+
private fun onReadyOrAborted(): Boolean {
23+
if (!hasRun) {
24+
hasRun = true
25+
toView?.let { view ->
26+
val observer = view.viewTreeObserver
27+
if (observer.isAlive) {
28+
observer.removeOnPreDrawListener(this)
29+
startAnimationHandler?.let { it() }
30+
}
31+
}
32+
}
33+
startAnimationHandler = null
34+
toView = null
35+
return true
36+
}
37+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.rasalexman.flairframework.core.animation
2+
3+
import android.animation.Animator
4+
import android.animation.AnimatorListenerAdapter
5+
6+
/**
7+
* Base animation Listener adapter for handle when animation is comlete or cancel
8+
*/
9+
class BaseAnimationListenerAdapter(private var finishAnimationHandler: ((Animator) -> Unit)? = null) : AnimatorListenerAdapter() {
10+
/**
11+
* When animation cancel we gonna clear it
12+
*/
13+
override fun onAnimationCancel(animation: Animator) {
14+
finishAnimationHandler?.let { it(animation) }
15+
finishAnimationHandler = null
16+
super.onAnimationCancel(animation)
17+
}
18+
19+
/**
20+
* When animation ends we hide mediator with given params and clear animation
21+
*/
22+
override fun onAnimationEnd(animation: Animator) {
23+
onAnimationCancel(animation)
24+
super.onAnimationEnd(animation)
25+
}
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.rasalexman.flairframework.core.animation
2+
3+
import android.animation.Animator
4+
import com.rasalexman.flairframework.interfaces.IAnimator
5+
import com.rasalexman.flairframework.interfaces.hide
6+
7+
abstract class BaseAnimator : IAnimator {
8+
9+
/**
10+
* Animation listener adapter
11+
*/
12+
private var listenerAdapter: BaseAnimationListenerAdapter? = null
13+
14+
/**
15+
* Prepare animation for play
16+
*/
17+
protected open fun startAnimation() {
18+
val animator: Animator = getAnimator()
19+
animator.duration = duration
20+
listenerAdapter = BaseAnimationListenerAdapter(::finishAnimation)
21+
animator.addListener(listenerAdapter)
22+
to?.onAnimationStart(!popLast)
23+
from?.onAnimationStart(!popLast)
24+
animator.start()
25+
}
26+
27+
/**
28+
* Clear the reference to given mediator instances
29+
*/
30+
protected open fun finishAnimation(animation: Animator) {
31+
animation.removeAllListeners()
32+
animation.end()
33+
animation.cancel()
34+
to?.onAnimationFinish(!popLast)
35+
from?.onAnimationFinish(!popLast)
36+
from?.hide(null, popLast)
37+
clearAnimator()
38+
}
39+
40+
/**
41+
* Clear all references
42+
*/
43+
private fun clearAnimator() {
44+
listenerAdapter = null
45+
from = null
46+
to = null
47+
}
48+
}
Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package com.rasalexman.flairframework.core.animation
22

33
import android.animation.Animator
4-
import android.animation.AnimatorListenerAdapter
54
import android.animation.AnimatorSet
65
import android.animation.ObjectAnimator
76
import android.view.View
8-
import android.view.ViewTreeObserver
9-
import com.rasalexman.flairframework.interfaces.IAnimator
107
import com.rasalexman.flairframework.interfaces.IMediator
11-
import com.rasalexman.flairframework.interfaces.hide
128

139
/**
1410
* Created by a.minkin on 24.11.2017.
@@ -28,7 +24,7 @@ import com.rasalexman.flairframework.interfaces.hide
2824
* Need to remove last mediator
2925
*
3026
*/
31-
class LinearAnimator(override var from: IMediator? = null, override var to: IMediator? = null, override var isShow: Boolean = true, override var duration: Long = 500, override var popLast: Boolean = false) : IAnimator {
27+
class LinearAnimator(override var from: IMediator? = null, override var to: IMediator? = null, override var isShow: Boolean = true, override var duration: Long = 500, override var popLast: Boolean = false) : BaseAnimator() {
3228

3329
/**
3430
* Get current animation
@@ -63,80 +59,9 @@ class LinearAnimator(override var from: IMediator? = null, override var to: IMed
6359
*/
6460
override fun playAnimation() {
6561
to?.let {
66-
it.viewComponent?.viewTreeObserver?.addOnPreDrawListener(AnimationPreDrawListener(to!!.viewComponent))
62+
it.viewComponent?.viewTreeObserver?.addOnPreDrawListener(AnimationPreDrawListener(to!!.viewComponent, ::startAnimation))
6763
} ?: from?.let {
6864
startAnimation()
6965
}
7066
}
71-
72-
/**
73-
* Prepare animation for play
74-
*/
75-
private fun startAnimation() {
76-
val animator: Animator = getAnimator()
77-
if (duration > 0) {
78-
animator.duration = duration
79-
}
80-
animator.addListener(object : AnimatorListenerAdapter() {
81-
/**
82-
* When animation cancel we gonna clear it
83-
*/
84-
override fun onAnimationCancel(animation: Animator) {
85-
clearAnimation(animation)
86-
}
87-
88-
/**
89-
* When animation ends we hide mediator with given params and clear animation
90-
*/
91-
override fun onAnimationEnd(animation: Animator) {
92-
from?.hide(null, popLast)
93-
clearAnimation(animation)
94-
}
95-
96-
/**
97-
* Clear the reference to given mediator instances
98-
*/
99-
private fun clearAnimation(animation: Animator) {
100-
from = null
101-
to = null
102-
animation.removeAllListeners()
103-
animation.end()
104-
animation.cancel()
105-
}
106-
})
107-
animator.start()
108-
}
109-
110-
/**
111-
* Animation PreDraw Listener used as event handler when view added to stage and initialized
112-
*/
113-
inner class AnimationPreDrawListener(private var toView: android.view.View?) : ViewTreeObserver.OnPreDrawListener {
114-
// does animation running
115-
private var hasRun: Boolean = false
116-
/**
117-
* Wait until ui is drawing on screen
118-
*/
119-
override fun onPreDraw(): Boolean {
120-
onReadyOrAborted()
121-
return true
122-
}
123-
124-
125-
/**
126-
* When animation is ready to be played
127-
*/
128-
private fun onReadyOrAborted() {
129-
if (!hasRun) {
130-
hasRun = true
131-
toView?.let {
132-
val observer = it.viewTreeObserver
133-
if (observer.isAlive) {
134-
observer.removeOnPreDrawListener(this)
135-
startAnimation()
136-
}
137-
}
138-
}
139-
toView = null
140-
}
141-
}
14267
}

flairframework/src/main/java/com/rasalexman/flairframework/core/controller/Controller.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.rasalexman.flairframework.core.controller
22

3+
import android.util.ArrayMap
34
import com.rasalexman.flairframework.core.view.View
45
import com.rasalexman.flairframework.interfaces.ICommand
56
import com.rasalexman.flairframework.interfaces.IController
@@ -17,7 +18,7 @@ class Controller private constructor(override var multitonKey: String) : IContro
1718
/**
1819
* Mapping of Notification names to Command Class references
1920
*/
20-
override val commandMap: MutableMap<String, ICommand?> = mutableMapOf()
21+
override val commandMap = ArrayMap<String, ICommand?>()
2122

2223
/**
2324
* Local reference to View
@@ -31,7 +32,7 @@ class Controller private constructor(override var multitonKey: String) : IContro
3132
/**
3233
* Global storage for all instances of Controller
3334
*/
34-
override val instanceMap: MutableMap<String, Controller> = mutableMapOf()
35+
override val instanceMap = ArrayMap<String, Controller>()
3536
/**
3637
* `Controller` Multiton Factory method.
3738
* @return the Multiton core of `Controller` or create new if not exist

flairframework/src/main/java/com/rasalexman/flairframework/core/model/Model.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.rasalexman.flairframework.core.model
22

3+
import android.util.ArrayMap
34
import com.rasalexman.flairframework.interfaces.IMapper
45
import com.rasalexman.flairframework.interfaces.IModel
56
import com.rasalexman.flairframework.interfaces.IProxy
@@ -12,10 +13,10 @@ open class Model private constructor(override var multitonKey: String) : IModel
1213
/**
1314
* Mapping of proxyNames to IProxy instances.
1415
*/
15-
override val proxyMap: MutableMap<String, IProxy<*>> = mutableMapOf()
16+
override val proxyMap = ArrayMap<String, IProxy<*>>()
1617

1718
companion object : IMapper<Model> {
18-
override val instanceMap: MutableMap<String, Model> = mutableMapOf()
19+
override val instanceMap = ArrayMap<String, Model>()
1920
/**
2021
* `Model` Multiton Factory method.
2122
*

flairframework/src/main/java/com/rasalexman/flairframework/core/view/View.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.os.Bundle
77
import android.support.v4.app.Fragment
88
import android.support.v4.app.FragmentManager
99
import android.support.v7.app.AppCompatActivity
10+
import android.util.ArrayMap
1011
import android.view.Menu
1112
import android.view.MenuInflater
1213
import android.view.MenuItem
@@ -15,6 +16,7 @@ import com.rasalexman.flairframework.core.FlairActivity
1516
import com.rasalexman.flairframework.ext.clear
1617
import com.rasalexman.flairframework.interfaces.*
1718
import com.rasalexman.flairframework.patterns.observer.Notification
19+
import java.lang.ref.WeakReference
1820

1921

2022
/**
@@ -28,9 +30,9 @@ class View : Fragment(), IView, Application.ActivityLifecycleCallbacks {
2830
override var multitonKey: String = ""
2931

3032
// Mapping of Notification names to Observer lists
31-
override val observerMap: MutableMap<String, MutableList<IObserver>> = mutableMapOf()
33+
override val observerMap = ArrayMap<String, MutableList<IObserver>>()
3234
// Mapping of Mediator names to Mediator instances
33-
override val mediatorMap: MutableMap<String, IMediator> = mutableMapOf()
35+
override val mediatorMap = ArrayMap<String, IMediator>()
3436

3537
// List of current added mediators on the screen
3638
override val mediatorBackStack: MutableList<IMediator> = mutableListOf()
@@ -40,7 +42,7 @@ class View : Fragment(), IView, Application.ActivityLifecycleCallbacks {
4042
/**
4143
* Reference to the Activity attached on core
4244
*/
43-
override var currentActivity: FlairActivity? = null
45+
override var currentActivity: WeakReference<FlairActivity>? = null
4446
/**
4547
* Instance of ui container
4648
*/
@@ -60,12 +62,13 @@ class View : Fragment(), IView, Application.ActivityLifecycleCallbacks {
6062
const val ACTIVITY_DESTROYED = "destroyed"
6163
const val ACTIVITY_STATE_SAVE = "state_save"
6264

63-
override val instanceMap: MutableMap<String, View> = mutableMapOf()
65+
override val instanceMap = ArrayMap<String, View>()
6466
/**
6567
* View Singleton Factory method.
6668
*
6769
* @return the Singleton core of `View`
6870
*/
71+
@Synchronized
6972
fun getInstance(key: String): View = instance(key) {
7073
val viewInstance = View()
7174
viewInstance.multitonKey = key
@@ -115,7 +118,7 @@ class View : Fragment(), IView, Application.ActivityLifecycleCallbacks {
115118
currentContainer = container ?: activity.window.decorView.findViewById(android.R.id.content)
116119
// only if there is no attach
117120
if (!isAlreadyRegistered) {
118-
currentActivity = activity
121+
currentActivity = WeakReference(activity)
119122
val fragmentManager: FragmentManager? = (activity as? AppCompatActivity)?.supportFragmentManager
120123
fragmentManager?.beginTransaction()?.add(this, multitonKey)?.commitAllowingStateLoss()
121124
activity.application.registerActivityLifecycleCallbacks(this)
@@ -127,7 +130,7 @@ class View : Fragment(), IView, Application.ActivityLifecycleCallbacks {
127130
* Detach current activity from view core
128131
*/
129132
private fun detachActivity() {
130-
currentActivity?.let {
133+
currentActivity?.get()?.let {
131134
val fragmentManager: FragmentManager? = (it as? AppCompatActivity)?.supportFragmentManager
132135
fragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
133136
// unregister lifecyrcle callbacks
@@ -218,6 +221,7 @@ class View : Fragment(), IView, Application.ActivityLifecycleCallbacks {
218221

219222
override fun onActivityDestroyed(activity: Activity?) {
220223
notifyObservers(Notification(ACTIVITY_DESTROYED, activity))
224+
detachActivity()
221225
}
222226

223227
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {

0 commit comments

Comments
 (0)