kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix launch responsiveness of story viewer.
rodzic
4758369f79
commit
b2b6f98294
|
@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.badges.gifts.flow
|
||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
|
|
@ -4,12 +4,13 @@ import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.lifecycle.LiveDataReactiveStreams
|
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import org.thoughtcrime.securesms.R
|
import org.thoughtcrime.securesms.R
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||||
import org.thoughtcrime.securesms.stories.StoryViewerArgs
|
import org.thoughtcrime.securesms.stories.StoryViewerArgs
|
||||||
import org.thoughtcrime.securesms.stories.viewer.page.StoryViewerPageFragment
|
import org.thoughtcrime.securesms.stories.viewer.page.StoryViewerPageFragment
|
||||||
|
import org.thoughtcrime.securesms.util.LifecycleDisposable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment which manages a vertical pager fragment of stories.
|
* Fragment which manages a vertical pager fragment of stories.
|
||||||
|
@ -26,6 +27,8 @@ class StoryViewerFragment : Fragment(R.layout.stories_viewer_fragment), StoryVie
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val lifecycleDisposable = LifecycleDisposable()
|
||||||
|
|
||||||
private val storyViewerArgs: StoryViewerArgs by lazy { requireArguments().getParcelable(ARGS)!! }
|
private val storyViewerArgs: StoryViewerArgs by lazy { requireArguments().getParcelable(ARGS)!! }
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
@ -38,7 +41,8 @@ class StoryViewerFragment : Fragment(R.layout.stories_viewer_fragment), StoryVie
|
||||||
storyPager.isUserInputEnabled = !it
|
storyPager.isUserInputEnabled = !it
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveDataReactiveStreams.fromPublisher(viewModel.state).observe(viewLifecycleOwner) { state ->
|
lifecycleDisposable.bindTo(viewLifecycleOwner)
|
||||||
|
lifecycleDisposable += viewModel.state.observeOn(AndroidSchedulers.mainThread()).subscribe { state ->
|
||||||
adapter.setPages(state.pages)
|
adapter.setPages(state.pages)
|
||||||
if (state.pages.isNotEmpty() && storyPager.currentItem != state.page) {
|
if (state.pages.isNotEmpty() && storyPager.currentItem != state.page) {
|
||||||
storyPager.setCurrentItem(state.page, state.previousPage > -1)
|
storyPager.setCurrentItem(state.page, state.previousPage > -1)
|
||||||
|
|
|
@ -268,14 +268,19 @@ class StoryViewerPageFragment :
|
||||||
when (parentState.crossfadeSource) {
|
when (parentState.crossfadeSource) {
|
||||||
is StoryViewerState.CrossfadeSource.TextModel -> storyCrossfader.setSourceView(parentState.crossfadeSource.storyTextPostModel)
|
is StoryViewerState.CrossfadeSource.TextModel -> storyCrossfader.setSourceView(parentState.crossfadeSource.storyTextPostModel)
|
||||||
is StoryViewerState.CrossfadeSource.ImageUri -> storyCrossfader.setSourceView(parentState.crossfadeSource.imageUri, parentState.crossfadeSource.imageBlur)
|
is StoryViewerState.CrossfadeSource.ImageUri -> storyCrossfader.setSourceView(parentState.crossfadeSource.imageUri, parentState.crossfadeSource.imageBlur)
|
||||||
else -> onReadyToAnimate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onReadyToAnimate()
|
||||||
} else {
|
} else {
|
||||||
viewModel.setIsSelectedPage(false)
|
viewModel.setIsSelectedPage(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lifecycleDisposable += viewModel.state.observeOn(AndroidSchedulers.mainThread()).subscribe { state ->
|
lifecycleDisposable += viewModel.state.observeOn(AndroidSchedulers.mainThread()).subscribe { state ->
|
||||||
|
if (!state.isReady) {
|
||||||
|
return@subscribe
|
||||||
|
}
|
||||||
|
|
||||||
if (state.posts.isNotEmpty() && state.selectedPostIndex in state.posts.indices) {
|
if (state.posts.isNotEmpty() && state.selectedPostIndex in state.posts.indices) {
|
||||||
val post = state.posts[state.selectedPostIndex]
|
val post = state.posts[state.selectedPostIndex]
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import io.reactivex.rxjava3.core.Observable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import org.signal.core.util.BreakIteratorCompat
|
import org.signal.core.util.BreakIteratorCompat
|
||||||
import org.signal.core.util.concurrent.SignalExecutors
|
import org.signal.core.util.concurrent.SignalExecutors
|
||||||
|
import org.signal.core.util.logging.Log
|
||||||
import org.thoughtcrime.securesms.conversation.ConversationMessage
|
import org.thoughtcrime.securesms.conversation.ConversationMessage
|
||||||
import org.thoughtcrime.securesms.database.DatabaseObserver
|
import org.thoughtcrime.securesms.database.DatabaseObserver
|
||||||
import org.thoughtcrime.securesms.database.NoSuchMessageException
|
import org.thoughtcrime.securesms.database.NoSuchMessageException
|
||||||
|
@ -28,6 +29,10 @@ import org.thoughtcrime.securesms.util.Base64
|
||||||
*/
|
*/
|
||||||
open class StoryViewerPageRepository(context: Context) {
|
open class StoryViewerPageRepository(context: Context) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = Log.tag(StoryViewerPageRepository::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
private val context = context.applicationContext
|
private val context = context.applicationContext
|
||||||
|
|
||||||
private fun getStoryRecords(recipientId: RecipientId): Observable<List<MessageRecord>> {
|
private fun getStoryRecords(recipientId: RecipientId): Observable<List<MessageRecord>> {
|
||||||
|
@ -104,7 +109,11 @@ open class StoryViewerPageRepository(context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val conversationObserver = DatabaseObserver.Observer {
|
val conversationObserver = DatabaseObserver.Observer {
|
||||||
|
try {
|
||||||
refresh(SignalDatabase.mms.getMessageRecord(record.id))
|
refresh(SignalDatabase.mms.getMessageRecord(record.id))
|
||||||
|
} catch (e: NoSuchMessageException) {
|
||||||
|
Log.w(TAG, "Message deleted during content refresh.", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationDependencies.getDatabaseObserver().registerConversationObserver(record.threadId, conversationObserver)
|
ApplicationDependencies.getDatabaseObserver().registerConversationObserver(record.threadId, conversationObserver)
|
||||||
|
|
|
@ -5,7 +5,8 @@ data class StoryViewerPageState(
|
||||||
val selectedPostIndex: Int = 0,
|
val selectedPostIndex: Int = 0,
|
||||||
val replyState: ReplyState = ReplyState.NONE,
|
val replyState: ReplyState = ReplyState.NONE,
|
||||||
val isFirstPage: Boolean = false,
|
val isFirstPage: Boolean = false,
|
||||||
val isDisplayingInitialState: Boolean = false
|
val isDisplayingInitialState: Boolean = false,
|
||||||
|
val isReady: Boolean = false
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Indicates which Reply method is available when the user swipes on the dialog
|
* Indicates which Reply method is available when the user swipes on the dialog
|
||||||
|
|
|
@ -63,6 +63,7 @@ class StoryViewerPageViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
state.copy(
|
state.copy(
|
||||||
|
isReady = true,
|
||||||
posts = posts,
|
posts = posts,
|
||||||
replyState = resolveSwipeToReplyState(state, startIndex),
|
replyState = resolveSwipeToReplyState(state, startIndex),
|
||||||
selectedPostIndex = startIndex,
|
selectedPostIndex = startIndex,
|
||||||
|
|
Ładowanie…
Reference in New Issue