Merge pull request #82 from TouchInstinct/fix/change-lyfecycle-logging
Fix/change lyfecycle logging
This commit is contained in:
commit
abfe52aacf
|
|
@ -257,6 +257,20 @@ public final class Lc {
|
|||
+ (caller != null ? " of object " + caller.getClass().getSimpleName() + '(' + Integer.toHexString(caller.hashCode()) + ')' : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns line of code from where this method called.
|
||||
*
|
||||
* @param caller Object who is calling for code point;
|
||||
* @param methodName String represents lifecycle method in which it was called
|
||||
* @return String represents code point.
|
||||
*/
|
||||
@Non
|
||||
@NonNull
|
||||
public static String getCodePoint(@Nullable final Object caller, final String methodName) {
|
||||
return methodName
|
||||
+ (caller != null ? " of object " + caller.getClass().getSimpleName() : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints stacktrace in log with specified tag.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ open class BaseFragment<TActivity : FragmentActivity, TState : Parcelable>(@Layo
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
lifecycle.addObserver(LifecycleLoggingObserver())
|
||||
lifecycle.addObserver(LifecycleLoggingObserver(this))
|
||||
butterKnifeUnbinder = ButterKnife.bind(this, view)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ abstract class BaseActivity : AppCompatActivity() {
|
|||
open val keyboardBehaviorDetector: KeyboardBehaviorDetector? = null
|
||||
|
||||
init {
|
||||
lifecycle.addObserver(LifecycleLoggingObserver())
|
||||
lifecycle.addObserver(LifecycleLoggingObserver(this))
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
|
||||
|
|
|
|||
|
|
@ -6,11 +6,38 @@ import androidx.lifecycle.OnLifecycleEvent
|
|||
import ru.touchin.roboswag.core.log.Lc
|
||||
import ru.touchin.roboswag.core.log.LcGroup
|
||||
|
||||
class LifecycleLoggingObserver : LifecycleObserver {
|
||||
class LifecycleLoggingObserver (
|
||||
private val lifecycleOwner: Any
|
||||
) : LifecycleObserver {
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||
fun onAnyLifecycleEvent() {
|
||||
LcGroup.UI_LIFECYCLE.i(Lc.getCodePoint(this))
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
||||
fun onCreateLifecycleEvent() {
|
||||
LcGroup.UI_LIFECYCLE.i(Lc.getCodePoint(lifecycleOwner, "onCreate"))
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
fun onStartLifecycleEvent() {
|
||||
LcGroup.UI_LIFECYCLE.i(Lc.getCodePoint(lifecycleOwner, "onStop"))
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
fun onResumeLifecycleEvent() {
|
||||
LcGroup.UI_LIFECYCLE.i(Lc.getCodePoint(lifecycleOwner, "onResume"))
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
fun onPauseLifecycleEvent() {
|
||||
LcGroup.UI_LIFECYCLE.i(Lc.getCodePoint(lifecycleOwner, "onPause"))
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||
fun onStopLifecycleEvent() {
|
||||
LcGroup.UI_LIFECYCLE.i(Lc.getCodePoint(lifecycleOwner, "onStop"))
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
fun onDestroyLifecycleEvent() {
|
||||
LcGroup.UI_LIFECYCLE.i(Lc.getCodePoint(lifecycleOwner, "onDestroy"))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ open class ViewController<TActivity : FragmentActivity, TState : Parcelable>(
|
|||
val view: View = creationContext.inflater.inflate(layoutRes, creationContext.container, false)
|
||||
|
||||
init {
|
||||
lifecycle.addObserver(LifecycleLoggingObserver())
|
||||
lifecycle.addObserver(LifecycleLoggingObserver(this))
|
||||
}
|
||||
|
||||
override fun getLifecycle(): Lifecycle = fragment.viewLifecycleOwner.lifecycle
|
||||
|
|
|
|||
Loading…
Reference in New Issue