Skip to content
This repository was archived by the owner on Feb 17, 2020. It is now read-only.

Commit c1c3a65

Browse files
committed
Bring showRoom feature flag to favourites too
1 parent 393f9b4 commit c1c3a65

7 files changed

Lines changed: 59 additions & 37 deletions

File tree

app/src/main/java/net/squanchy/favorites/FavoritesComponent.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import net.squanchy.injection.ApplicationComponent
99
import net.squanchy.injection.applicationComponent
1010
import net.squanchy.navigation.NavigationModule
1111
import net.squanchy.navigation.Navigator
12+
import net.squanchy.remoteconfig.FeatureFlags
1213

1314
@ActivityLifecycle
1415
@Component(modules = [FavoritesModule::class, NavigationModule::class], dependencies = [ApplicationComponent::class])
@@ -19,6 +20,8 @@ internal interface FavoritesComponent {
1920
fun navigator(): Navigator
2021

2122
fun analytics(): Analytics
23+
24+
fun featureFlags(): FeatureFlags
2225
}
2326

2427
internal fun favoritesComponent(activity: AppCompatActivity): FavoritesComponent {

app/src/main/java/net/squanchy/favorites/FavoritesPageView.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import androidx.view.isVisible
88
import io.reactivex.Observable
99
import io.reactivex.android.schedulers.AndroidSchedulers
1010
import io.reactivex.disposables.CompositeDisposable
11-
import io.reactivex.functions.BiFunction
11+
import io.reactivex.functions.Function3
1212
import io.reactivex.schedulers.Schedulers
1313
import kotlinx.android.synthetic.main.merge_no_favorites_view.view.*
1414
import kotlinx.android.synthetic.main.view_page_favorites.view.*
@@ -19,6 +19,7 @@ import net.squanchy.favorites.view.FavoritesItem
1919
import net.squanchy.home.HomeActivity
2020
import net.squanchy.home.Loadable
2121
import net.squanchy.navigation.Navigator
22+
import net.squanchy.remoteconfig.FeatureFlags
2223
import net.squanchy.schedule.domain.view.Event
2324
import net.squanchy.support.unwrapToActivityContext
2425
import timber.log.Timber
@@ -32,6 +33,7 @@ class FavoritesPageView @JvmOverloads constructor(
3233
private lateinit var favoritesService: FavoritesService
3334
private lateinit var navigator: Navigator
3435
private lateinit var analytics: Analytics
36+
private lateinit var featureFlags: FeatureFlags
3537

3638
private val disposable = CompositeDisposable()
3739

@@ -41,6 +43,7 @@ class FavoritesPageView @JvmOverloads constructor(
4143
favoritesService = favoritesService()
4244
navigator = navigator()
4345
analytics = analytics()
46+
featureFlags = featureFlags()
4447
}
4548
}
4649
}
@@ -66,7 +69,8 @@ class FavoritesPageView @JvmOverloads constructor(
6669
Observable.combineLatest(
6770
favoritesService.favorites(),
6871
favoritesService.currentUserIsSignedIn(),
69-
BiFunction<List<FavoritesItem>, Boolean, LoadResult>(::LoadResult)
72+
featureFlags.showEventRoomInSchedule.toObservable(),
73+
Function3<List<FavoritesItem>, Boolean, Boolean, LoadResult>(::LoadResult)
7074
)
7175
.subscribeOn(Schedulers.io())
7276
.observeOn(AndroidSchedulers.mainThread())
@@ -92,14 +96,14 @@ class FavoritesPageView @JvmOverloads constructor(
9296

9397
private fun handleLoadSchedule(result: LoadResult) {
9498
when {
95-
result.favoriteItems.isNotEmpty() -> showFavorites(result.favoriteItems)
99+
result.favoriteItems.isNotEmpty() -> showFavorites(result.favoriteItems, result.showRoom)
96100
result.signedIn -> promptToFavorite()
97101
else -> promptToSign()
98102
}
99103
}
100104

101-
private fun showFavorites(favorites: List<FavoritesItem>) {
102-
favoritesListView.updateWith(favorites, ::navigateToEventDetails)
105+
private fun showFavorites(favorites: List<FavoritesItem>, showRoom: Boolean) {
106+
favoritesListView.updateWith(favorites, showRoom, ::navigateToEventDetails)
103107
favoritesListView.isVisible = true
104108
progressBar.isVisible = false
105109
emptyViewSignedOut.isVisible = false
@@ -137,5 +141,5 @@ class FavoritesPageView @JvmOverloads constructor(
137141

138142
private fun showSettings() = navigator.toSettings()
139143

140-
private data class LoadResult(val favoriteItems: List<FavoritesItem>, val signedIn: Boolean)
144+
private data class LoadResult(val favoriteItems: List<FavoritesItem>, val signedIn: Boolean, val showRoom: Boolean)
141145
}

app/src/main/java/net/squanchy/favorites/view/FavoritesAdapter.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ internal class FavoritesAdapter(
1717
private const val VIEW_TYPE_HEADER: Int = 2
1818
}
1919

20-
lateinit var favoriteClickListener: OnFavoriteClickListener
20+
private var favoriteClickListener: OnFavoriteClickListener? = null
21+
private var showRoom = false
2122

2223
private val layoutInflater = LayoutInflater.from(context)
2324

@@ -50,10 +51,25 @@ internal class FavoritesAdapter(
5051

5152
override fun onBindViewHolder(holder: FavoritesViewHolder<*>, position: Int) {
5253
when (holder) {
53-
is EventViewHolder -> holder.updateWith((getItem(position) as FavoritesItem.Favorite).event, favoriteClickListener)
54+
is EventViewHolder -> holder.updateWith((getItem(position) as FavoritesItem.Favorite).event, showRoom, favoriteClickListener)
5455
is HeaderViewHolder -> holder.updateWith((getItem(position) as FavoritesItem.Header).date)
5556
}
5657
}
58+
59+
fun updateWith(list: List<FavoritesItem>, showRoom: Boolean, listener: OnFavoriteClickListener) {
60+
this.showRoom = showRoom
61+
this.favoriteClickListener = listener
62+
super.submitList(list)
63+
}
64+
65+
@Deprecated(
66+
message = "Use updateWith() instead",
67+
replaceWith = ReplaceWith("updateWith(list, showRoom, eventClickListener)"),
68+
level = DeprecationLevel.ERROR
69+
)
70+
override fun submitList(list: MutableList<FavoritesItem>?) {
71+
throw UnsupportedOperationException("Use updateWith() instead")
72+
}
5773
}
5874

5975
private object DiffCallback : DiffUtil.ItemCallback<FavoritesItem>() {

app/src/main/java/net/squanchy/favorites/view/FavoritesListView.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ internal class FavoritesListView @JvmOverloads constructor(
2727
addItemDecoration(CardSpacingItemDecorator(horizontalSpacing, verticalSpacing))
2828
}
2929

30-
fun updateWith(newData: List<FavoritesItem>, listener: OnFavoriteClickListener) {
31-
adapter.favoriteClickListener = listener
30+
fun updateWith(newData: List<FavoritesItem>, showRoom: Boolean, listener: OnFavoriteClickListener) {
3231
setAdapterIfNone(adapter)
33-
34-
adapter.submitList(newData)
32+
adapter.updateWith(newData, showRoom, listener)
3533
}
3634
}

app/src/main/java/net/squanchy/favorites/view/FavoritesViewHolders.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ sealed class FavoritesViewHolder<T : View>(itemView: T) : RecyclerView.ViewHolde
1818

1919
class EventViewHolder(itemView: EventItemView) : FavoritesViewHolder<EventItemView>(itemView) {
2020

21-
fun updateWith(event: Event, listener: OnEventClickListener?) {
22-
(itemView as EventItemView).updateWith(event, showRoom = true, showFavorite = false)
21+
fun updateWith(event: Event, showRoom: Boolean, listener: OnEventClickListener?) {
22+
(itemView as EventItemView).updateWith(event, showRoom, showFavorite = false)
2323
itemView.setOnClickListener { listener?.invoke(event) }
2424
}
2525
}

app/src/main/java/net/squanchy/schedule/SchedulePageView.kt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ class SchedulePageView @JvmOverloads constructor(
101101

102102
private fun combineInPair(): BiFunction<Schedule, Boolean, Pair<Schedule, Boolean>> = BiFunction(::Pair)
103103

104+
private fun updateWith(schedule: Schedule, showRoom: Boolean, onEventClicked: (Event) -> Unit) {
105+
progressbar.isVisible = false
106+
107+
if (schedule.isEmpty) {
108+
viewpager.isVisible = false
109+
tabstrip.isVisible = false
110+
emptyView.isVisible = true
111+
return
112+
}
113+
114+
viewpager.isVisible = true
115+
tabstrip.isVisible = true
116+
emptyView.isVisible = false
117+
118+
viewPagerAdapter.updateWith(schedule.pages, showRoom, onEventClicked)
119+
if (viewpager.adapter == null) {
120+
viewpager.adapter = viewPagerAdapter
121+
}
122+
123+
progressbar.isVisible = false
124+
}
125+
104126
private fun onEventClicked(event: Event) {
105127
analytics.trackItemSelected(ContentType.SCHEDULE_ITEM, event.id)
106128
navigate.toEventDetails(event.id)
@@ -128,26 +150,4 @@ class SchedulePageView @JvmOverloads constructor(
128150
}
129151

130152
private fun hasTypefaceSpan(text: CharSequence?) = (text as? Spanned)?.hasTypefaceSpan() ?: false
131-
132-
fun updateWith(schedule: Schedule, showRoom: Boolean, onEventClicked: (Event) -> Unit) {
133-
progressbar.isVisible = false
134-
135-
if (schedule.isEmpty) {
136-
viewpager.isVisible = false
137-
tabstrip.isVisible = false
138-
emptyView.isVisible = true
139-
return
140-
}
141-
142-
viewpager.isVisible = true
143-
tabstrip.isVisible = true
144-
emptyView.isVisible = false
145-
146-
viewPagerAdapter.updateWith(schedule.pages, showRoom, onEventClicked)
147-
if (viewpager.adapter == null) {
148-
viewpager.adapter = viewPagerAdapter
149-
}
150-
151-
progressbar.isVisible = false
152-
}
153153
}

app/src/main/res/layout/item_schedule_event_talk.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
android:visibility="gone"
9393
app:layout_constraintTop_toTopOf="@+id/timestamp"
9494
app:layout_constraintEnd_toEndOf="parent"
95-
app:layout_constraintBottom_toBottomOf="@+id/timestamp" />
95+
app:layout_constraintBottom_toBottomOf="@+id/timestamp"
96+
tools:visibility="visible" />
9697

9798
</android.support.constraint.ConstraintLayout>
9899

0 commit comments

Comments
 (0)