Skip to content

Commit

Permalink
Merge branch 'fix/crashes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHadiSatrio committed Jan 6, 2024
2 parents 4d38dbe + 3a9f710 commit 9c66f6d
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ class DeleteAMomentActivity : AppCompatActivity() {
)
)
)
)
)()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.hadisatrio.libs.kotlin.foundation.event.EventSinks
import com.hadisatrio.libs.kotlin.foundation.event.EventSource
import com.hadisatrio.libs.kotlin.foundation.event.EventSources
import com.hadisatrio.libs.kotlin.foundation.event.SelectionEvent
import com.hadisatrio.libs.kotlin.foundation.event.SkippingEventSource
import com.hadisatrio.libs.kotlin.foundation.presentation.AdaptingPresenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenters
Expand Down Expand Up @@ -116,10 +117,13 @@ class EditAMomentActivity : AppCompatActivity() {
journal3Application.eventSourceDecor.apply(
EventSources(
journal3Application.globalEventSource,
LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_RESUME,
eventFactory = { RefreshRequestEvent("lifecycle") }
SkippingEventSource(
count = 1,
origin = LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_RESUME,
eventFactory = { RefreshRequestEvent("lifecycle") }
)
),
LifecycleTriggeredEventSource(
lifecycleOwner = this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.hadisatrio.libs.kotlin.foundation.event.EventSinks
import com.hadisatrio.libs.kotlin.foundation.event.EventSource
import com.hadisatrio.libs.kotlin.foundation.event.EventSources
import com.hadisatrio.libs.kotlin.foundation.event.SelectionEvent
import com.hadisatrio.libs.kotlin.foundation.event.SkippingEventSource
import com.hadisatrio.libs.kotlin.foundation.presentation.AdaptingPresenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenters
Expand Down Expand Up @@ -70,10 +71,13 @@ class EditAStoryActivity : AppCompatActivity() {
journal3Application.eventSourceDecor.apply(
EventSources(
journal3Application.globalEventSource,
LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_RESUME,
eventFactory = { RefreshRequestEvent("lifecycle") }
SkippingEventSource(
count = 1,
origin = LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_RESUME,
eventFactory = { RefreshRequestEvent("lifecycle") }
)
),
LifecycleTriggeredEventSource(
lifecycleOwner = this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.hadisatrio.libs.android.foundation.widget.recyclerview.ViewRenderer
import com.hadisatrio.libs.kotlin.foundation.event.CancellationEvent
import com.hadisatrio.libs.kotlin.foundation.event.EventSource
import com.hadisatrio.libs.kotlin.foundation.event.EventSources
import com.hadisatrio.libs.kotlin.foundation.event.SkippingEventSource
import com.hadisatrio.libs.kotlin.foundation.presentation.AdaptingPresenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenter
import kotlin.math.roundToInt
Expand Down Expand Up @@ -112,10 +113,13 @@ class ReflectionStoriesListFragment : StoriesListFragment() {
journal3Application.eventSourceDecor.apply(
EventSources(
journal3Application.globalEventSource,
LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_START,
eventFactory = { RefreshRequestEvent("lifecycle") }
SkippingEventSource(
count = 1,
origin = LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_START,
eventFactory = { RefreshRequestEvent("lifecycle") }
)
),
LifecycleTriggeredEventSource(
lifecycleOwner = this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.hadisatrio.libs.android.foundation.widget.recyclerview.RecyclerViewIt
import com.hadisatrio.libs.kotlin.foundation.event.CancellationEvent
import com.hadisatrio.libs.kotlin.foundation.event.EventSource
import com.hadisatrio.libs.kotlin.foundation.event.EventSources
import com.hadisatrio.libs.kotlin.foundation.event.SkippingEventSource
import com.hadisatrio.libs.kotlin.foundation.presentation.AdaptingPresenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenter

Expand Down Expand Up @@ -72,10 +73,13 @@ class UserStoriesListFragment : StoriesListFragment() {
journal3Application.eventSourceDecor.apply(
EventSources(
journal3Application.globalEventSource,
LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_START,
eventFactory = { RefreshRequestEvent("lifecycle") }
SkippingEventSource(
count = 1,
origin = LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_START,
eventFactory = { RefreshRequestEvent("lifecycle") }
)
),
LifecycleTriggeredEventSource(
lifecycleOwner = this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import com.hadisatrio.libs.kotlin.foundation.event.EventSinks
import com.hadisatrio.libs.kotlin.foundation.event.EventSource
import com.hadisatrio.libs.kotlin.foundation.event.EventSources
import com.hadisatrio.libs.kotlin.foundation.event.SelectionEvent
import com.hadisatrio.libs.kotlin.foundation.event.SkippingEventSource
import com.hadisatrio.libs.kotlin.foundation.presentation.AdaptingPresenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenter
import com.hadisatrio.libs.kotlin.foundation.presentation.Presenters
Expand Down Expand Up @@ -112,10 +113,13 @@ class ViewStoryActivity : AppCompatActivity() {
journal3Application.eventSourceDecor.apply(
EventSources(
journal3Application.globalEventSource,
LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_RESUME,
eventFactory = { RefreshRequestEvent("lifecycle") }
SkippingEventSource(
count = 1,
origin = LifecycleTriggeredEventSource(
lifecycleOwner = this,
lifecycleEvent = Lifecycle.Event.ON_START,
eventFactory = { RefreshRequestEvent("lifecycle") }
)
),
LifecycleTriggeredEventSource(
lifecycleOwner = this,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2022 Hadi Satrio
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.hadisatrio.libs.kotlin.foundation.event

import com.badoo.reaktive.observable.Observable
import com.badoo.reaktive.observable.skip

class SkippingEventSource(
private val count: Number,
private val origin: EventSource
) : EventSource {

override fun events(): Observable<Event> {
return origin.events().skip(count.toLong())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2022 Hadi Satrio
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.hadisatrio.libs.kotlin.foundation.event

import com.badoo.reaktive.subject.publish.PublishSubject
import com.badoo.reaktive.test.observable.test
import com.hadisatrio.libs.kotlin.foundation.event.fake.FakeEvent
import com.hadisatrio.libs.kotlin.foundation.event.fake.FakeEventSource
import io.kotest.matchers.collections.shouldHaveSize
import kotlin.test.Test

class SkippingEventSourceTest {

@Test
fun `Skips N elements of the given stream`() {
val count = 10
val origin = FakeEventSource(PublishSubject())
val source = SkippingEventSource(count, origin)

val events = source.events().test()
repeat(count * 2) { origin.produce(FakeEvent()) }

events.values.shouldHaveSize(count)
}
}

0 comments on commit 9c66f6d

Please sign in to comment.