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(
|
class Model(
|
||||||
val onClick: () -> Unit
|
val hasOutgoingStories: Boolean,
|
||||||
|
val onClick: (Boolean) -> Unit,
|
||||||
|
val onClickThumbnail: () -> Unit
|
||||||
) : PreferenceModel<Model>() {
|
) : PreferenceModel<Model>() {
|
||||||
override fun areItemsTheSame(newItem: Model): Boolean = true
|
override fun areItemsTheSame(newItem: Model): Boolean = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ViewHolder(itemView: View) : MappingViewHolder<Model>(itemView) {
|
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 avatarView: AvatarView = itemView.findViewById(R.id.avatar)
|
||||||
private val badgeView: BadgeImageView = itemView.findViewById(R.id.badge)
|
private val badgeView: BadgeImageView = itemView.findViewById(R.id.badge)
|
||||||
|
|
||||||
override fun bind(model: Model) {
|
override fun bind(model: Model) {
|
||||||
itemView.setOnClickListener { model.onClick() }
|
itemView.setOnClickListener { model.onClick(model.hasOutgoingStories) }
|
||||||
|
thumbnail.setOnClickListener { model.onClickThumbnail() }
|
||||||
|
|
||||||
avatarView.displayProfileAvatar(Recipient.self())
|
avatarView.displayProfileAvatar(Recipient.self())
|
||||||
badgeView.setBadgeFromRecipient(Recipient.self())
|
badgeView.setBadgeFromRecipient(Recipient.self())
|
||||||
|
|
|
@ -110,7 +110,15 @@ class StoriesLandingFragment : DSLSettingsFragment(layoutId = R.layout.stories_l
|
||||||
if (state.displayMyStoryItem) {
|
if (state.displayMyStoryItem) {
|
||||||
customPref(
|
customPref(
|
||||||
MyStoriesItem.Model(
|
MyStoriesItem.Model(
|
||||||
|
state.hasOutgoingGroupStories,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
if (it) {
|
||||||
|
startActivity(Intent(requireContext(), MyStoriesActivity::class.java))
|
||||||
|
} else {
|
||||||
|
cameraFab.performClick()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onClickThumbnail = {
|
||||||
cameraFab.performClick()
|
cameraFab.performClick()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,19 +26,21 @@ class StoriesLandingRepository(context: Context) {
|
||||||
}.subscribeOn(Schedulers.io())
|
}.subscribeOn(Schedulers.io())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStories(): Observable<List<StoriesLandingItemData>> {
|
fun getStories(): Observable<StoriesResult> {
|
||||||
return Observable.create<Observable<List<StoriesLandingItemData>>> { emitter ->
|
return Observable.create<Observable<StoriesResult>> { emitter ->
|
||||||
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
|
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
|
||||||
val myStories = Recipient.resolved(myStoriesId)
|
val myStories = Recipient.resolved(myStoriesId)
|
||||||
|
|
||||||
fun refresh() {
|
fun refresh() {
|
||||||
val storyMap = mutableMapOf<Recipient, List<MessageRecord>>()
|
val storyMap = mutableMapOf<Recipient, List<MessageRecord>>()
|
||||||
|
var hasOutgoingGroupStories = false
|
||||||
SignalDatabase.mms.allStories.use {
|
SignalDatabase.mms.allStories.use {
|
||||||
while (it.next != null) {
|
while (it.next != null) {
|
||||||
val messageRecord = it.current
|
val messageRecord = it.current
|
||||||
val recipient = if (messageRecord.isOutgoing && !messageRecord.recipient.isGroup) {
|
val recipient = if (messageRecord.isOutgoing && !messageRecord.recipient.isGroup) {
|
||||||
myStories
|
myStories
|
||||||
} else if (messageRecord.isOutgoing && messageRecord.recipient.isGroup) {
|
} else if (messageRecord.isOutgoing && messageRecord.recipient.isGroup) {
|
||||||
|
hasOutgoingGroupStories = true
|
||||||
messageRecord.recipient
|
messageRecord.recipient
|
||||||
} else {
|
} else {
|
||||||
SignalDatabase.threads.getRecipientForThreadId(messageRecord.threadId)!!
|
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) }
|
val data: List<Observable<StoriesLandingItemData>> = storyMap.map { (sender, records) -> createStoriesLandingItemData(sender, records) }
|
||||||
if (data.isEmpty()) {
|
if (data.isEmpty()) {
|
||||||
emitter.onNext(Observable.just(emptyList()))
|
emitter.onNext(Observable.just(StoriesResult(emptyList(), false)))
|
||||||
} else {
|
} 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)
|
SignalDatabase.recipients.setHideStory(recipientId, hideStory)
|
||||||
}.subscribeOn(Schedulers.io())
|
}.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 storiesLandingItems: List<StoriesLandingItemData> = emptyList(),
|
||||||
val displayMyStoryItem: Boolean = false,
|
val displayMyStoryItem: Boolean = false,
|
||||||
val isHiddenContentVisible: Boolean = false,
|
val isHiddenContentVisible: Boolean = false,
|
||||||
|
val hasOutgoingGroupStories: Boolean = false,
|
||||||
val loadingState: LoadingState = LoadingState.INIT
|
val loadingState: LoadingState = LoadingState.INIT
|
||||||
) {
|
) {
|
||||||
enum class LoadingState {
|
enum class LoadingState {
|
||||||
|
|
|
@ -17,12 +17,13 @@ class StoriesLandingViewModel(private val storiesLandingRepository: StoriesLandi
|
||||||
val state: LiveData<StoriesLandingState> = store.stateLiveData
|
val state: LiveData<StoriesLandingState> = store.stateLiveData
|
||||||
|
|
||||||
init {
|
init {
|
||||||
disposables += storiesLandingRepository.getStories().subscribe { stories ->
|
disposables += storiesLandingRepository.getStories().subscribe { (stories, hasOutgoingGroupStories) ->
|
||||||
store.update { state ->
|
store.update { state ->
|
||||||
state.copy(
|
state.copy(
|
||||||
loadingState = StoriesLandingState.LoadingState.LOADED,
|
loadingState = StoriesLandingState.LoadingState.LOADED,
|
||||||
storiesLandingItems = stories.sorted(),
|
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