mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Fix issue where crossfader has wrong story on shared element animation start.
This commit is contained in:
committed by
Cody Henthorne
parent
2b8041d779
commit
a642876bda
@@ -54,6 +54,7 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.Mention;
|
||||
import org.thoughtcrime.securesms.database.model.MessageId;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.ParentStoryId;
|
||||
import org.thoughtcrime.securesms.database.model.Quote;
|
||||
|
||||
@@ -20,7 +20,6 @@ data class StoryViewerArgs(
|
||||
val recipientIds: List<RecipientId> = emptyList(),
|
||||
val isFromNotification: Boolean = false,
|
||||
val groupReplyStartPosition: Int = -1,
|
||||
val isUnviewedOnly: Boolean = false,
|
||||
val isFromInfoContextMenuAction: Boolean = false,
|
||||
val isFromQuote: Boolean = false,
|
||||
val isFromMyStories: Boolean = false
|
||||
@@ -35,7 +34,6 @@ data class StoryViewerArgs(
|
||||
private var recipientIds: List<RecipientId> = emptyList()
|
||||
private var isFromNotification: Boolean = false
|
||||
private var groupReplyStartPosition: Int = -1
|
||||
private var isUnviewedOnly: Boolean = false
|
||||
private var isFromInfoContextMenuAction: Boolean = false
|
||||
private var isFromQuote: Boolean = false
|
||||
|
||||
@@ -74,11 +72,6 @@ data class StoryViewerArgs(
|
||||
return this
|
||||
}
|
||||
|
||||
fun isUnviewedOnly(isUnviewedOnly: Boolean): Builder {
|
||||
this.isUnviewedOnly = isUnviewedOnly
|
||||
return this
|
||||
}
|
||||
|
||||
fun isFromQuote(isFromQuote: Boolean): Builder {
|
||||
this.isFromQuote = isFromQuote
|
||||
return this
|
||||
@@ -95,7 +88,6 @@ data class StoryViewerArgs(
|
||||
recipientIds = recipientIds,
|
||||
isFromNotification = isFromNotification,
|
||||
groupReplyStartPosition = groupReplyStartPosition,
|
||||
isUnviewedOnly = isUnviewedOnly,
|
||||
isFromInfoContextMenuAction = isFromInfoContextMenuAction,
|
||||
isFromQuote = isFromQuote
|
||||
)
|
||||
|
||||
@@ -272,7 +272,6 @@ class StoriesLandingFragment : DSLSettingsFragment(layoutId = R.layout.stories_l
|
||||
storyThumbUri = image,
|
||||
storyThumbBlur = blur,
|
||||
recipientIds = viewModel.getRecipientIds(model.data.isHidden, false),
|
||||
isUnviewedOnly = false,
|
||||
isFromInfoContextMenuAction = isFromInfoContextMenuAction
|
||||
)
|
||||
),
|
||||
|
||||
@@ -50,7 +50,6 @@ class StoryViewerFragment :
|
||||
storyViewerArgs.storyId,
|
||||
storyViewerArgs.isFromNotification,
|
||||
storyViewerArgs.groupReplyStartPosition,
|
||||
storyViewerArgs.isUnviewedOnly,
|
||||
storyViewerArgs.isFromMyStories,
|
||||
storyViewerArgs.isFromInfoContextMenuAction
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ class StoryViewerPagerAdapter(
|
||||
private val initialStoryId: Long,
|
||||
private val isFromNotification: Boolean,
|
||||
private val groupReplyStartPosition: Int,
|
||||
private val isUnviewedOnly: Boolean,
|
||||
private val isOutgoingOnly: Boolean,
|
||||
private val isFromInfoContextMenuAction: Boolean
|
||||
) : FragmentStateAdapter(fragment) {
|
||||
@@ -40,7 +39,7 @@ class StoryViewerPagerAdapter(
|
||||
}
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return StoryViewerPageFragment.create(pages[position], initialStoryId, isFromNotification, groupReplyStartPosition, isUnviewedOnly, isOutgoingOnly, isFromInfoContextMenuAction)
|
||||
return StoryViewerPageFragment.create(pages[position], initialStoryId, isFromNotification, groupReplyStartPosition, isOutgoingOnly, isFromInfoContextMenuAction)
|
||||
}
|
||||
|
||||
private class Callback(
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.thoughtcrime.securesms.database.MessageDatabase
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.database.model.DistributionListId
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.StoryViewState
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
@@ -15,7 +14,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
* Open for testing
|
||||
*/
|
||||
open class StoryViewerRepository {
|
||||
fun getFirstStory(recipientId: RecipientId, unviewedOnly: Boolean, storyId: Long): Single<MmsMessageRecord> {
|
||||
fun getFirstStory(recipientId: RecipientId, storyId: Long): Single<MmsMessageRecord> {
|
||||
return if (storyId > 0) {
|
||||
Single.fromCallable {
|
||||
SignalDatabase.mms.getMessageRecord(storyId) as MmsMessageRecord
|
||||
@@ -25,18 +24,20 @@ open class StoryViewerRepository {
|
||||
val recipient = Recipient.resolved(recipientId)
|
||||
val reader: MessageDatabase.Reader = if (recipient.isMyStory || recipient.isSelf) {
|
||||
SignalDatabase.mms.getAllOutgoingStories(false, 1)
|
||||
} else if (unviewedOnly) {
|
||||
SignalDatabase.mms.getUnreadStories(recipientId, 1)
|
||||
} else {
|
||||
SignalDatabase.mms.getAllStoriesFor(recipientId, 1)
|
||||
val unread = SignalDatabase.mms.getUnreadStories(recipientId, 1)
|
||||
if (unread.iterator().hasNext()) {
|
||||
unread
|
||||
} else {
|
||||
SignalDatabase.mms.getAllStoriesFor(recipientId, 1)
|
||||
}
|
||||
}
|
||||
|
||||
reader.use { it.next } as MmsMessageRecord
|
||||
reader.use { it.iterator().next() } as MmsMessageRecord
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getStories(hiddenStories: Boolean, unviewedOnly: Boolean, isOutgoingOnly: Boolean): Single<List<RecipientId>> {
|
||||
fun getStories(hiddenStories: Boolean, isOutgoingOnly: Boolean): Single<List<RecipientId>> {
|
||||
return Single.create<List<RecipientId>> { emitter ->
|
||||
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
|
||||
val myStories = Recipient.resolved(myStoriesId)
|
||||
@@ -54,16 +55,6 @@ open class StoryViewerRepository {
|
||||
} else {
|
||||
!it.shouldHideStory()
|
||||
}
|
||||
}.filter {
|
||||
if (unviewedOnly) {
|
||||
if (it.isSelf || it.isMyStory) {
|
||||
false
|
||||
} else {
|
||||
SignalDatabase.mms.getStoryViewState(it.id) == StoryViewState.UNVIEWED
|
||||
}
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}.map { it.id }
|
||||
|
||||
emitter.onSuccess(
|
||||
|
||||
@@ -94,7 +94,6 @@ class StoryViewerViewModel(
|
||||
} else {
|
||||
repository.getStories(
|
||||
hiddenStories = storyViewerArgs.isInHiddenStoryMode,
|
||||
unviewedOnly = storyViewerArgs.isUnviewedOnly,
|
||||
isOutgoingOnly = storyViewerArgs.isFromMyStories
|
||||
)
|
||||
}
|
||||
@@ -102,7 +101,7 @@ class StoryViewerViewModel(
|
||||
|
||||
fun refresh() {
|
||||
disposables.clear()
|
||||
disposables += repository.getFirstStory(storyViewerArgs.recipientId, storyViewerArgs.isUnviewedOnly, storyViewerArgs.storyId).subscribe { record ->
|
||||
disposables += repository.getFirstStory(storyViewerArgs.recipientId, storyViewerArgs.storyId).subscribe { record ->
|
||||
store.update {
|
||||
it.copy(
|
||||
crossfadeTarget = StoryViewerState.CrossfadeTarget.Record(record)
|
||||
|
||||
@@ -117,7 +117,6 @@ class StoryViewerPageFragment :
|
||||
StoryViewerPageViewModel.Factory(
|
||||
storyRecipientId,
|
||||
initialStoryId,
|
||||
isUnviewedOnly,
|
||||
isOutgoingOnly,
|
||||
StoryViewerPageRepository(
|
||||
requireContext()
|
||||
@@ -151,9 +150,6 @@ class StoryViewerPageFragment :
|
||||
private val groupReplyStartPosition: Int
|
||||
get() = requireArguments().getInt(ARG_GROUP_REPLY_START_POSITION, -1)
|
||||
|
||||
private val isUnviewedOnly: Boolean
|
||||
get() = requireArguments().getBoolean(ARG_IS_UNVIEWED_ONLY, false)
|
||||
|
||||
private val isOutgoingOnly: Boolean
|
||||
get() = requireArguments().getBoolean(ARG_IS_OUTGOING_ONLY, false)
|
||||
|
||||
@@ -1020,7 +1016,6 @@ class StoryViewerPageFragment :
|
||||
private const val ARG_STORY_ID = "arg.story.id"
|
||||
private const val ARG_IS_FROM_NOTIFICATION = "is_from_notification"
|
||||
private const val ARG_GROUP_REPLY_START_POSITION = "group_reply_start_position"
|
||||
private const val ARG_IS_UNVIEWED_ONLY = "is_unviewed_only"
|
||||
private const val ARG_IS_OUTGOING_ONLY = "is_outgoing_only"
|
||||
private const val ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION = "is_from_info_context_menu_action"
|
||||
|
||||
@@ -1029,7 +1024,6 @@ class StoryViewerPageFragment :
|
||||
initialStoryId: Long,
|
||||
isFromNotification: Boolean,
|
||||
groupReplyStartPosition: Int,
|
||||
isUnviewedOnly: Boolean,
|
||||
isOutgoingOnly: Boolean,
|
||||
isFromInfoContextMenuAction: Boolean
|
||||
): Fragment {
|
||||
@@ -1039,7 +1033,6 @@ class StoryViewerPageFragment :
|
||||
ARG_STORY_ID to initialStoryId,
|
||||
ARG_IS_FROM_NOTIFICATION to isFromNotification,
|
||||
ARG_GROUP_REPLY_START_POSITION to groupReplyStartPosition,
|
||||
ARG_IS_UNVIEWED_ONLY to isUnviewedOnly,
|
||||
ARG_IS_OUTGOING_ONLY to isOutgoingOnly,
|
||||
ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION to isFromInfoContextMenuAction,
|
||||
)
|
||||
|
||||
@@ -39,15 +39,13 @@ open class StoryViewerPageRepository(context: Context) {
|
||||
|
||||
fun isReadReceiptsEnabled(): Boolean = TextSecurePreferences.isReadReceiptsEnabled(context)
|
||||
|
||||
private fun getStoryRecords(recipientId: RecipientId, isUnviewedOnly: Boolean, isOutgoingOnly: Boolean): Observable<List<MessageRecord>> {
|
||||
private fun getStoryRecords(recipientId: RecipientId, isOutgoingOnly: Boolean): Observable<List<MessageRecord>> {
|
||||
return Observable.create { emitter ->
|
||||
val recipient = Recipient.resolved(recipientId)
|
||||
|
||||
fun refresh() {
|
||||
val stories = if (recipient.isMyStory) {
|
||||
SignalDatabase.mms.getAllOutgoingStories(false, 100)
|
||||
} else if (isUnviewedOnly) {
|
||||
SignalDatabase.mms.getUnreadStories(recipientId, 100)
|
||||
} else if (isOutgoingOnly) {
|
||||
SignalDatabase.mms.getOutgoingStoriesTo(recipientId)
|
||||
} else {
|
||||
@@ -148,8 +146,8 @@ open class StoryViewerPageRepository(context: Context) {
|
||||
return Stories.enqueueAttachmentsFromStoryForDownload(post.conversationMessage.messageRecord as MmsMessageRecord, true)
|
||||
}
|
||||
|
||||
fun getStoryPostsFor(recipientId: RecipientId, isUnviewedOnly: Boolean, isOutgoingOnly: Boolean): Observable<List<StoryPost>> {
|
||||
return getStoryRecords(recipientId, isUnviewedOnly, isOutgoingOnly)
|
||||
fun getStoryPostsFor(recipientId: RecipientId, isOutgoingOnly: Boolean): Observable<List<StoryPost>> {
|
||||
return getStoryRecords(recipientId, isOutgoingOnly)
|
||||
.switchMap { records ->
|
||||
val posts = records.map { getStoryPostFromRecord(recipientId, it) }
|
||||
if (posts.isEmpty()) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import kotlin.math.min
|
||||
class StoryViewerPageViewModel(
|
||||
private val recipientId: RecipientId,
|
||||
private val initialStoryId: Long,
|
||||
private val isUnviewedOnly: Boolean,
|
||||
private val isOutgoingOnly: Boolean,
|
||||
private val repository: StoryViewerPageRepository,
|
||||
val storyCache: StoryCache
|
||||
@@ -62,7 +61,7 @@ class StoryViewerPageViewModel(
|
||||
|
||||
fun refresh() {
|
||||
disposables.clear()
|
||||
disposables += repository.getStoryPostsFor(recipientId, isUnviewedOnly, isOutgoingOnly).subscribe { posts ->
|
||||
disposables += repository.getStoryPostsFor(recipientId, isOutgoingOnly).subscribe { posts ->
|
||||
store.update { state ->
|
||||
val isDisplayingInitialState = state.posts.isEmpty() && posts.isNotEmpty()
|
||||
val startIndex = if (state.posts.isEmpty() && initialStoryId > 0) {
|
||||
@@ -294,13 +293,12 @@ class StoryViewerPageViewModel(
|
||||
class Factory(
|
||||
private val recipientId: RecipientId,
|
||||
private val initialStoryId: Long,
|
||||
private val isUnviewedOnly: Boolean,
|
||||
private val isOutgoingOnly: Boolean,
|
||||
private val repository: StoryViewerPageRepository,
|
||||
private val storyCache: StoryCache
|
||||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return modelClass.cast(StoryViewerPageViewModel(recipientId, initialStoryId, isUnviewedOnly, isOutgoingOnly, repository, storyCache)) as T
|
||||
return modelClass.cast(StoryViewerPageViewModel(recipientId, initialStoryId, isOutgoingOnly, repository, storyCache)) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user