-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from anilibria/feature/TR-265-teams
Feature/tr 265 teams
- Loading branch information
Showing
39 changed files
with
971 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
26 changes: 26 additions & 0 deletions
26
app-mobile/src/main/java/ru/radiationx/anilibria/presentation/teams/States.kt
This file contains 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,26 @@ | ||
package ru.radiationx.anilibria.presentation.teams | ||
|
||
import ru.radiationx.data.entity.domain.team.TeamRole | ||
|
||
data class TeamsState( | ||
val hasQuery: Boolean = false, | ||
val headerRoles: List<TeamRole>, | ||
val teams: List<TeamState> | ||
) | ||
|
||
data class TeamState( | ||
val section: TeamSectionState, | ||
val users: List<TeamUserState> | ||
) | ||
|
||
data class TeamSectionState( | ||
val title: String, | ||
val description: String? | ||
) | ||
|
||
data class TeamUserState( | ||
val nickname: String, | ||
val color: Int?, | ||
val roles: List<String>, | ||
val tags: List<String>, | ||
) |
119 changes: 119 additions & 0 deletions
119
app-mobile/src/main/java/ru/radiationx/anilibria/presentation/teams/TeamsPresenter.kt
This file contains 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,119 @@ | ||
package ru.radiationx.anilibria.presentation.teams | ||
|
||
import com.jakewharton.rxrelay2.BehaviorRelay | ||
import ru.radiationx.anilibria.presentation.common.BasePresenter | ||
import ru.radiationx.anilibria.presentation.common.IErrorHandler | ||
import ru.radiationx.data.analytics.features.TeamsAnalytics | ||
import ru.radiationx.data.entity.common.DataWrapper | ||
import ru.radiationx.data.entity.domain.team.Team | ||
import ru.radiationx.data.entity.domain.team.Teams | ||
import ru.radiationx.data.repository.TeamsRepository | ||
import ru.radiationx.shared_app.common.SystemUtils | ||
import ru.terrakok.cicerone.Router | ||
import toothpick.InjectConstructor | ||
|
||
@InjectConstructor | ||
class TeamsPresenter( | ||
router: Router, | ||
private val repository: TeamsRepository, | ||
private val errorHandler: IErrorHandler, | ||
private val systemUtils: SystemUtils, | ||
private val analytics: TeamsAnalytics | ||
) : BasePresenter<TeamsView>(router) { | ||
|
||
private val currentDataRelay = | ||
BehaviorRelay.createDefault<DataWrapper<Teams>>(DataWrapper(null)) | ||
|
||
private val queryRelay = BehaviorRelay.createDefault(Query()) | ||
|
||
override fun onFirstViewAttach() { | ||
super.onFirstViewAttach() | ||
repository | ||
.requestUpdate() | ||
.subscribe({}, { | ||
it.printStackTrace() | ||
}) | ||
.addToDisposable() | ||
repository | ||
.observeTeams() | ||
.doOnSubscribe { viewState.setLoading(true) } | ||
.subscribe({ | ||
viewState.setLoading(false) | ||
currentDataRelay.accept(DataWrapper(it)) | ||
}, { | ||
viewState.setLoading(false) | ||
errorHandler.handle(it) | ||
}) | ||
.addToDisposable() | ||
|
||
currentDataRelay | ||
.filter { it.data != null } | ||
.map { it.data!! } | ||
.map { it.toState() } | ||
.flatMap { teamStates -> | ||
queryRelay.map { query -> | ||
teamStates.filterBy(query) | ||
} | ||
} | ||
.subscribe { | ||
viewState.showData(it) | ||
} | ||
.addToDisposable() | ||
} | ||
|
||
fun setQueryText(text: String) { | ||
queryRelay.accept(queryRelay.value!!.copy(text = text)) | ||
} | ||
|
||
fun onHeaderActionClick() { | ||
analytics.joinClick() | ||
systemUtils.externalLink("https://t.me/joinlibria_bot") | ||
} | ||
|
||
private fun Teams.toState(): TeamsState = TeamsState( | ||
false, | ||
headerRoles, | ||
teams.toState() | ||
) | ||
|
||
private fun List<Team>.toState(): List<TeamState> = map { team -> | ||
val section = TeamSectionState(team.title, team.description) | ||
val users = team.users.map { user -> | ||
val tags = mutableListOf<String>().apply { | ||
if (user.isIntern) { | ||
add("Стажер") | ||
} | ||
if (user.isVacation) { | ||
add("В отпуске") | ||
} | ||
} | ||
TeamUserState( | ||
user.nickname, | ||
user.roles.find { it.color != null }?.color, | ||
user.roles.map { it.title }, | ||
tags | ||
) | ||
} | ||
TeamState(section, users) | ||
} | ||
|
||
private fun TeamsState.filterBy(query: Query): TeamsState { | ||
val newTeams = teams.map { teamState -> | ||
val newUsers = teamState.users | ||
.filter { user -> | ||
query.text.isEmpty() | ||
|| user.nickname.contains(query.text, true) | ||
|| user.roles.any { it.contains(query.text, true) } | ||
|| user.tags.any { it.contains(query.text, true) } | ||
} | ||
teamState.copy(users = newUsers) | ||
}.filter { | ||
it.users.isNotEmpty() | ||
} | ||
return copy(teams = newTeams, hasQuery = query.text.isNotEmpty()) | ||
} | ||
|
||
private data class Query( | ||
val text: String = "" | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
app-mobile/src/main/java/ru/radiationx/anilibria/presentation/teams/TeamsView.kt
This file contains 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,16 @@ | ||
package ru.radiationx.anilibria.presentation.teams | ||
|
||
import moxy.MvpView | ||
import moxy.viewstate.strategy.AddToEndSingleStrategy | ||
import moxy.viewstate.strategy.StateStrategyType | ||
|
||
|
||
interface TeamsView : MvpView { | ||
|
||
@StateStrategyType(AddToEndSingleStrategy::class) | ||
fun showData(data: TeamsState) | ||
|
||
@StateStrategyType(AddToEndSingleStrategy::class) | ||
fun setLoading(isLoading: Boolean) | ||
|
||
} |
This file contains 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 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 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.