mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-24 21:25:35 +01:00
Updated scroll logic + removed old approach
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
parent
2960e693ce
commit
23e5435092
@ -59,6 +59,8 @@ class ConversationItem(
|
||||
IFilterable<String?> {
|
||||
private var header: GenericTextHeaderItem? = null
|
||||
private val chatMessage = model.lastMessage?.asModel()
|
||||
var mHolder: ConversationItemViewHolder? = null
|
||||
|
||||
|
||||
constructor(
|
||||
conversation: ConversationModel,
|
||||
@ -97,6 +99,7 @@ class ConversationItem(
|
||||
position: Int,
|
||||
payloads: List<Any>
|
||||
) {
|
||||
mHolder = holder
|
||||
val appContext = sharedApplication!!.applicationContext
|
||||
holder.binding.dialogName.setTextColor(
|
||||
ResourcesCompat.getColor(
|
||||
|
@ -195,7 +195,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_BREAKOUT_ROOM
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_MODERATOR
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_RECORDING_STATE
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SCROLL_OFFSET
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM
|
||||
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
|
||||
@ -370,7 +369,6 @@ class ChatActivity :
|
||||
|
||||
var myFirstMessage: CharSequence? = null
|
||||
var checkingLobbyStatus: Boolean = false
|
||||
private var listScrollOffset: Int = 0
|
||||
|
||||
private var conversationVoiceCallMenuItem: MenuItem? = null
|
||||
private var conversationVideoMenuItem: MenuItem? = null
|
||||
@ -394,10 +392,6 @@ class ChatActivity :
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
val intent = Intent(this@ChatActivity, ConversationsListActivity::class.java)
|
||||
val bundle = bundleOf()
|
||||
bundle.putInt(KEY_SCROLL_OFFSET, listScrollOffset)
|
||||
bundle.putString(KEY_ROOM_TOKEN, roomToken)
|
||||
intent.putExtras(bundle)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
@ -554,7 +548,6 @@ class ChatActivity :
|
||||
val extras: Bundle? = intent.extras
|
||||
|
||||
roomToken = extras?.getString(KEY_ROOM_TOKEN).orEmpty()
|
||||
listScrollOffset = extras?.getInt(KEY_SCROLL_OFFSET, 0) ?: 0
|
||||
|
||||
sharedText = extras?.getString(BundleKeys.KEY_SHARED_TEXT).orEmpty()
|
||||
|
||||
|
@ -51,7 +51,6 @@ import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.work.Data
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
@ -142,7 +141,6 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FORWARD_MSG_FLAG
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FORWARD_MSG_TEXT
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SCROLL_OFFSET
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SCROLL_TO_NOTIFICATION_CATEGORY
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SHARED_TEXT
|
||||
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
|
||||
@ -237,8 +235,6 @@ class ConversationsListActivity :
|
||||
private var conversationsListBottomDialog: ConversationsListBottomDialog? = null
|
||||
private var searchHelper: MessageSearchHelper? = null
|
||||
private var searchViewDisposable: Disposable? = null
|
||||
private var roomTokenFromIntent: String? = null
|
||||
private var scrollOffset: Int = 0
|
||||
private var filterState =
|
||||
mutableMapOf(
|
||||
MENTION to false,
|
||||
@ -311,8 +307,6 @@ class ConversationsListActivity :
|
||||
showNotificationWarning()
|
||||
|
||||
showShareToScreen = hasActivityActionSendIntent()
|
||||
roomTokenFromIntent = intent.extras?.getString(KEY_ROOM_TOKEN)
|
||||
scrollOffset = intent.extras?.getInt(KEY_SCROLL_OFFSET, 0) ?: 0
|
||||
|
||||
if (!eventBus.isRegistered(this)) {
|
||||
eventBus.register(this)
|
||||
@ -432,17 +426,9 @@ class ConversationsListActivity :
|
||||
.firstOrNull { ConversationUtils.isNoteToSelfConversation(it) }
|
||||
val isNoteToSelfAvailable = noteToSelf != null
|
||||
handleNoteToSelfShortcut(isNoteToSelfAvailable, noteToSelf?.token ?: "")
|
||||
if (roomTokenFromIntent != null) {
|
||||
val item = adapter?.currentItems?.first {
|
||||
it is ConversationItem && it.model.token == roomTokenFromIntent
|
||||
}
|
||||
val pos = adapter?.currentItems?.indexOf(item)
|
||||
pos?.let {
|
||||
val layoutManager = binding.recyclerView.layoutManager as LinearLayoutManager
|
||||
layoutManager.scrollToPosition(scrollOffset)
|
||||
}
|
||||
roomTokenFromIntent = null
|
||||
}
|
||||
|
||||
val pair = appPreferences.conversationListPositionAndOffset
|
||||
layoutManager?.scrollToPositionWithOffset(pair.first, pair.second)
|
||||
}.collect()
|
||||
}
|
||||
|
||||
@ -1890,14 +1876,18 @@ class ConversationsListActivity :
|
||||
|
||||
val bundle = Bundle()
|
||||
bundle.putString(KEY_ROOM_TOKEN, selectedConversation!!.token)
|
||||
// bundle.putString(KEY_ROOM_ID, selectedConversation!!.roomId)
|
||||
bundle.putString(KEY_SHARED_TEXT, textToPaste)
|
||||
if (selectedMessageId != null) {
|
||||
bundle.putString(BundleKeys.KEY_MESSAGE_ID, selectedMessageId)
|
||||
selectedMessageId = null
|
||||
}
|
||||
val firstVisible = layoutManager?.findFirstVisibleItemPosition() ?: 0
|
||||
bundle.putInt(KEY_SCROLL_OFFSET, firstVisible)
|
||||
val firstItem = adapter?.getItem(firstVisible)
|
||||
val firstTop = (firstItem as ConversationItem).mHolder?.itemView?.top
|
||||
val firstOffset = firstTop?.minus(44) ?: 0
|
||||
|
||||
appPreferences.setConversationListPositionAndOffset(firstVisible, firstOffset)
|
||||
|
||||
val intent = Intent(context, ChatActivity::class.java)
|
||||
intent.putExtras(bundle)
|
||||
startActivity(intent)
|
||||
|
@ -81,7 +81,6 @@ object BundleKeys {
|
||||
const val KEY_FIELD_MAP: String = "KEY_FIELD_MAP"
|
||||
const val KEY_CHAT_URL: String = "KEY_CHAT_URL"
|
||||
const val KEY_SCROLL_TO_NOTIFICATION_CATEGORY: String = "KEY_SCROLL_TO_NOTIFICATION_CATEGORY"
|
||||
const val KEY_SCROLL_OFFSET: String = "KEY_SCROLL_OFFSET"
|
||||
const val KEY_FOCUS_INPUT: String = "KEY_FOCUS_INPUT"
|
||||
const val KEY_FROM_QR: String = "KEY_FROM_QR"
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import android.annotation.SuppressLint;
|
||||
|
||||
import com.nextcloud.talk.ui.PlaybackSpeed;
|
||||
|
||||
import kotlin.Pair;
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
public interface AppPreferences {
|
||||
|
||||
@ -185,5 +187,9 @@ public interface AppPreferences {
|
||||
|
||||
void setShowRegularNotificationWarning(boolean value);
|
||||
|
||||
void setConversationListPositionAndOffset(int position, int offset);
|
||||
|
||||
Pair<Integer, Integer> getConversationListPositionAndOffset();
|
||||
|
||||
void clear();
|
||||
}
|
||||
|
@ -412,6 +412,28 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
|
||||
}
|
||||
}
|
||||
|
||||
override fun setConversationListPositionAndOffset(position: Int, offset: Int) {
|
||||
runBlocking<Unit> {
|
||||
async {
|
||||
writeString(CONVERSATION_LIST_POSITION_OFFSET, "$position,$offset")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getConversationListPositionAndOffset(): Pair<Int, Int> {
|
||||
val pairString = runBlocking {
|
||||
async { readString(CONVERSATION_LIST_POSITION_OFFSET).first() }
|
||||
}.getCompleted()
|
||||
|
||||
if (pairString.isEmpty()) return Pair(0,0)
|
||||
|
||||
val pairArr = pairString.split(',')
|
||||
val position = pairArr[0].toInt()
|
||||
val offset = pairArr[1].toInt()
|
||||
|
||||
return Pair(position, offset)
|
||||
}
|
||||
|
||||
override fun setPhoneBookIntegrationLastRun(currentTimeMillis: Long) =
|
||||
runBlocking<Unit> {
|
||||
async {
|
||||
@ -626,6 +648,7 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
|
||||
const val VOICE_MESSAGE_PLAYBACK_SPEEDS = "voice_message_playback_speeds"
|
||||
const val SHOW_REGULAR_NOTIFICATION_WARNING = "show_regular_notification_warning"
|
||||
const val LAST_NOTIFICATION_WARNING = "last_notification_warning"
|
||||
const val CONVERSATION_LIST_POSITION_OFFSET = "CONVERSATION_LIST_POSITION_OFFSET"
|
||||
private fun String.convertStringToArray(): Array<Float> {
|
||||
var varString = this
|
||||
val floatList = mutableListOf<Float>()
|
||||
|
Loading…
Reference in New Issue
Block a user