-
Notifications
You must be signed in to change notification settings - Fork 54
APPS-3601: Banner block #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8ffca77
Add banner redux and domain layer
rostikjoystick ff496c3
Add banner item layout
rostikjoystick ccb6c4d
Add banner feature to catalog feature
rostikjoystick 7cf4702
Add banner adapter delegate
rostikjoystick 093c739
Handle banner click
rostikjoystick 6519162
Do not provide auth
rostikjoystick 52462c3
Add error message
rostikjoystick edf1dd9
Handle nullable types and screens; Add banner resource mapper
rostikjoystick ee2979c
Add banner support to home screen
rostikjoystick c1eefe0
Add default value for testing purposes
rostikjoystick 8bf8130
Fix crashes and update test json
rostikjoystick f05a271
Fix height
rostikjoystick 485d976
Re-add on config change
rostikjoystick 67e9b92
Clean up
rostikjoystick f043572
Use content language instead of locale
rostikjoystick c6f2019
Update item banner layout
rostikjoystick 675f159
Add paddings
rostikjoystick 95b6471
Update getBanners
rostikjoystick af10fcc
Add extension for binding
rostikjoystick 343019e
Get context from view in binding extension
rostikjoystick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/main/java/org/stepik/android/domain/banner/interactor/BannerInteractor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package org.stepik.android.domain.banner.interactor | ||
|
|
||
| import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
| import com.google.gson.Gson | ||
| import com.google.gson.reflect.TypeToken | ||
| import io.reactivex.Single | ||
| import org.stepic.droid.configuration.RemoteConfig | ||
| import org.stepic.droid.preferences.SharedPreferenceHelper | ||
| import org.stepik.android.domain.banner.model.Banner | ||
| import java.lang.Exception | ||
| import javax.inject.Inject | ||
|
|
||
| class BannerInteractor | ||
| @Inject | ||
| constructor( | ||
| private val firebaseRemoteConfig: FirebaseRemoteConfig, | ||
| private val sharedPreferenceHelper: SharedPreferenceHelper, | ||
| private val gson: Gson | ||
| ) { | ||
| fun getBanners(screen: Banner.Screen): Single<List<Banner>> = | ||
| Single.fromCallable { | ||
| val bannersJson = firebaseRemoteConfig.getString(RemoteConfig.BANNERS_ANDROID) | ||
| if (bannersJson.isEmpty()) { | ||
| emptyList() | ||
| } else { | ||
| try { | ||
| val banners = | ||
| gson.fromJson<List<Banner>>( | ||
| bannersJson, | ||
| TypeToken.getParameterized( | ||
| ArrayList::class.java, | ||
| Banner::class.java | ||
| ).type | ||
| ) | ||
|
|
||
| val language = sharedPreferenceHelper.languageForFeatured | ||
|
|
||
| banners.filter { | ||
| it.type != null && | ||
| it.screen != null && | ||
| it.language == language && | ||
| it.screen == screen | ||
| } | ||
| } catch (e: Exception) { | ||
| emptyList() | ||
| } | ||
| } | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/org/stepik/android/domain/banner/model/Banner.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.stepik.android.domain.banner.model | ||
|
|
||
| import com.google.gson.annotations.SerializedName | ||
|
|
||
| data class Banner( | ||
| @SerializedName("title") | ||
| val title: String, | ||
| @SerializedName("type") | ||
| val type: ColorType?, | ||
| @SerializedName("lang") | ||
| val language: String, | ||
| @SerializedName("description") | ||
| val description: String, | ||
| @SerializedName("url") | ||
| val url: String, | ||
| @SerializedName("screen") | ||
| val screen: Screen?, | ||
| @SerializedName("position") | ||
| val position: Int | ||
| ) { | ||
| enum class ColorType(val type: String) { | ||
| @SerializedName("blue") | ||
| BLUE("blue"), | ||
|
|
||
| @SerializedName("violet") | ||
| VIOLET("violet"), | ||
|
|
||
| @SerializedName("green") | ||
| GREEN("green") | ||
| } | ||
|
|
||
| enum class Screen(val screen: String) { | ||
| @SerializedName("catalog") | ||
| CATALOG("catalog"), | ||
|
|
||
| @SerializedName("home") | ||
| HOME("home") | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
app/src/main/java/org/stepik/android/presentation/banner/BannerFeature.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.stepik.android.presentation.banner | ||
|
|
||
| import org.stepik.android.domain.banner.model.Banner | ||
|
|
||
| interface BannerFeature { | ||
| sealed class State { | ||
| object Idle : State() | ||
| object Loading : State() | ||
| object Empty : State() | ||
| data class Content(val banners: List<Banner>) : State() | ||
| } | ||
|
|
||
| sealed class Message { | ||
| data class InitMessage( | ||
| val screen: Banner.Screen, | ||
| val forceUpdate: Boolean = false | ||
| ) : Message() | ||
| object BannersError : Message() | ||
| data class BannersResult(val banners: List<Banner>) : Message() | ||
| } | ||
|
|
||
| sealed class Action { | ||
| data class LoadBanners(val screen: Banner.Screen) : Action() | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...src/main/java/org/stepik/android/presentation/banner/dispatcher/BannerActionDispatcher.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package org.stepik.android.presentation.banner.dispatcher | ||
|
|
||
| import io.reactivex.Scheduler | ||
| import io.reactivex.rxkotlin.plusAssign | ||
| import io.reactivex.rxkotlin.subscribeBy | ||
| import org.stepic.droid.di.qualifiers.BackgroundScheduler | ||
| import org.stepic.droid.di.qualifiers.MainScheduler | ||
| import org.stepik.android.domain.banner.interactor.BannerInteractor | ||
| import org.stepik.android.presentation.banner.BannerFeature | ||
| import ru.nobird.android.presentation.redux.dispatcher.RxActionDispatcher | ||
| import javax.inject.Inject | ||
|
|
||
| class BannerActionDispatcher | ||
| @Inject | ||
| constructor( | ||
| private val bannerInteractor: BannerInteractor, | ||
| @BackgroundScheduler | ||
| private val backgroundScheduler: Scheduler, | ||
| @MainScheduler | ||
| private val mainScheduler: Scheduler | ||
| ) : RxActionDispatcher<BannerFeature.Action, BannerFeature.Message>() { | ||
| override fun handleAction(action: BannerFeature.Action) { | ||
| when (action) { | ||
| is BannerFeature.Action.LoadBanners -> { | ||
| compositeDisposable += bannerInteractor | ||
| .getBanners(action.screen) | ||
| .observeOn(mainScheduler) | ||
| .subscribeOn(backgroundScheduler) | ||
| .subscribeBy( | ||
| onSuccess = { onNewMessage(BannerFeature.Message.BannersResult(it)) }, | ||
| onError = { onNewMessage(BannerFeature.Message.BannersError) } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/org/stepik/android/presentation/banner/reducer/BannerReducer.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package org.stepik.android.presentation.banner.reducer | ||
|
|
||
| import org.stepik.android.presentation.banner.BannerFeature.State | ||
| import org.stepik.android.presentation.banner.BannerFeature.Message | ||
| import org.stepik.android.presentation.banner.BannerFeature.Action | ||
| import ru.nobird.app.presentation.redux.reducer.StateReducer | ||
| import javax.inject.Inject | ||
|
|
||
| class BannerReducer | ||
| @Inject | ||
| constructor() : StateReducer<State, Message, Action> { | ||
| override fun reduce(state: State, message: Message): Pair<State, Set<Action>> = | ||
| when (message) { | ||
| is Message.InitMessage -> { | ||
| if (state is State.Idle || message.forceUpdate) { | ||
| State.Loading to setOf(Action.LoadBanners(message.screen)) | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
| is Message.BannersError -> { | ||
| if (state is State.Loading) { | ||
| State.Empty to emptySet() | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
| is Message.BannersResult -> { | ||
| if (state is State.Loading) { | ||
| val newState = | ||
| if (message.banners.isEmpty()) { | ||
| State.Empty | ||
| } else { | ||
| State.Content(message.banners) | ||
| } | ||
| newState to emptySet() | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
| } ?: state to emptySet() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.