Add handler to My Stories row to open my stories
If there are sent group stories.
This commit is contained in:
parent
1bb04035ab
commit
2a7d515932
5 changed files with 29 additions and 8 deletions
|
@ -20,18 +20,22 @@ object MyStoriesItem {
|
|||
}
|
||||
|
||||
class Model(
|
||||
val onClick: () -> Unit
|
||||
val hasOutgoingStories: Boolean,
|
||||
val onClick: (Boolean) -> Unit,
|
||||
val onClickThumbnail: () -> Unit
|
||||
) : PreferenceModel<Model>() {
|
||||
override fun areItemsTheSame(newItem: Model): Boolean = true
|
||||
}
|
||||
|
||||
private class ViewHolder(itemView: View) : MappingViewHolder<Model>(itemView) {
|
||||
|
||||
private val thumbnail: View = itemView.findViewById(R.id.story)
|
||||
private val avatarView: AvatarView = itemView.findViewById(R.id.avatar)
|
||||
private val badgeView: BadgeImageView = itemView.findViewById(R.id.badge)
|
||||
|
||||
override fun bind(model: Model) {
|
||||
itemView.setOnClickListener { model.onClick() }
|
||||
itemView.setOnClickListener { model.onClick(model.hasOutgoingStories) }
|
||||
thumbnail.setOnClickListener { model.onClickThumbnail() }
|
||||
|
||||
avatarView.displayProfileAvatar(Recipient.self())
|
||||
badgeView.setBadgeFromRecipient(Recipient.self())
|
||||
|
|
|
@ -110,7 +110,15 @@ class StoriesLandingFragment : DSLSettingsFragment(layoutId = R.layout.stories_l
|
|||
if (state.displayMyStoryItem) {
|
||||
customPref(
|
||||
MyStoriesItem.Model(
|
||||
state.hasOutgoingGroupStories,
|
||||
onClick = {
|
||||
if (it) {
|
||||
startActivity(Intent(requireContext(), MyStoriesActivity::class.java))
|
||||
} else {
|
||||
cameraFab.performClick()
|
||||
}
|
||||
},
|
||||
onClickThumbnail = {
|
||||
cameraFab.performClick()
|
||||
}
|
||||
)
|
||||
|
|
|
@ -26,19 +26,21 @@ class StoriesLandingRepository(context: Context) {
|
|||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
fun getStories(): Observable<List<StoriesLandingItemData>> {
|
||||
return Observable.create<Observable<List<StoriesLandingItemData>>> { emitter ->
|
||||
fun getStories(): Observable<StoriesResult> {
|
||||
return Observable.create<Observable<StoriesResult>> { emitter ->
|
||||
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
|
||||
val myStories = Recipient.resolved(myStoriesId)
|
||||
|
||||
fun refresh() {
|
||||
val storyMap = mutableMapOf<Recipient, List<MessageRecord>>()
|
||||
var hasOutgoingGroupStories = false
|
||||
SignalDatabase.mms.allStories.use {
|
||||
while (it.next != null) {
|
||||
val messageRecord = it.current
|
||||
val recipient = if (messageRecord.isOutgoing && !messageRecord.recipient.isGroup) {
|
||||
myStories
|
||||
} else if (messageRecord.isOutgoing && messageRecord.recipient.isGroup) {
|
||||
hasOutgoingGroupStories = true
|
||||
messageRecord.recipient
|
||||
} else {
|
||||
SignalDatabase.threads.getRecipientForThreadId(messageRecord.threadId)!!
|
||||
|
@ -50,9 +52,9 @@ class StoriesLandingRepository(context: Context) {
|
|||
|
||||
val data: List<Observable<StoriesLandingItemData>> = storyMap.map { (sender, records) -> createStoriesLandingItemData(sender, records) }
|
||||
if (data.isEmpty()) {
|
||||
emitter.onNext(Observable.just(emptyList()))
|
||||
emitter.onNext(Observable.just(StoriesResult(emptyList(), false)))
|
||||
} else {
|
||||
emitter.onNext(Observable.combineLatest(data) { it.toList() as List<StoriesLandingItemData> })
|
||||
emitter.onNext(Observable.combineLatest(data) { StoriesResult(it.toList() as List<StoriesLandingItemData>, hasOutgoingGroupStories) })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,4 +122,9 @@ class StoriesLandingRepository(context: Context) {
|
|||
SignalDatabase.recipients.setHideStory(recipientId, hideStory)
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
data class StoriesResult(
|
||||
val data: List<StoriesLandingItemData>,
|
||||
val hasOutgoingGroupStories: Boolean
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ data class StoriesLandingState(
|
|||
val storiesLandingItems: List<StoriesLandingItemData> = emptyList(),
|
||||
val displayMyStoryItem: Boolean = false,
|
||||
val isHiddenContentVisible: Boolean = false,
|
||||
val hasOutgoingGroupStories: Boolean = false,
|
||||
val loadingState: LoadingState = LoadingState.INIT
|
||||
) {
|
||||
enum class LoadingState {
|
||||
|
|
|
@ -17,12 +17,13 @@ class StoriesLandingViewModel(private val storiesLandingRepository: StoriesLandi
|
|||
val state: LiveData<StoriesLandingState> = store.stateLiveData
|
||||
|
||||
init {
|
||||
disposables += storiesLandingRepository.getStories().subscribe { stories ->
|
||||
disposables += storiesLandingRepository.getStories().subscribe { (stories, hasOutgoingGroupStories) ->
|
||||
store.update { state ->
|
||||
state.copy(
|
||||
loadingState = StoriesLandingState.LoadingState.LOADED,
|
||||
storiesLandingItems = stories.sorted(),
|
||||
displayMyStoryItem = stories.isEmpty() || stories.none { it.storyRecipient.isMyStory }
|
||||
displayMyStoryItem = stories.isEmpty() || stories.none { it.storyRecipient.isMyStory },
|
||||
hasOutgoingGroupStories = hasOutgoingGroupStories
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue