Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ConversationItem(
IFilterable<String?> {
private var header: GenericTextHeaderItem? = null
private val chatMessage = model.lastMessage?.asModel()
var mHolder: ConversationItemViewHolder? = null

constructor(
conversation: ConversationModel,
Expand Down Expand Up @@ -97,6 +98,7 @@ class ConversationItem(
position: Int,
payloads: List<Any>
) {
mHolder = holder
val appContext = sharedApplication!!.applicationContext
holder.binding.dialogName.setTextColor(
ResourcesCompat.getColor(
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ class ChatActivity :
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
val intent = Intent(this@ChatActivity, ConversationsListActivity::class.java)
intent.putExtras(Bundle())
startActivity(intent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ class ConversationsListActivity :
showSearchOrToolbar()
}

override fun onPause() {
super.onPause()
val firstVisible = layoutManager?.findFirstVisibleItemPosition() ?: 0
val firstItem = adapter?.getItem(firstVisible)
val firstTop = (firstItem as ConversationItem).mHolder?.itemView?.top
val firstOffset = firstTop?.minus(CONVERSATION_ITEM_HEIGHT) ?: 0

appPreferences.setConversationListPositionAndOffset(firstVisible, firstOffset)
}

// if edge to edge is used, add an empty item at the bottom of the list
@Suppress("MagicNumber")
private fun addEmptyItemForEdgeToEdgeIfNecessary() {
Expand Down Expand Up @@ -426,6 +436,9 @@ class ConversationsListActivity :
.firstOrNull { ConversationUtils.isNoteToSelfConversation(it) }
val isNoteToSelfAvailable = noteToSelf != null
handleNoteToSelfShortcut(isNoteToSelfAvailable, noteToSelf?.token ?: "")

val pair = appPreferences.conversationListPositionAndOffset
layoutManager?.scrollToPositionWithOffset(pair.first, pair.second)
}.collect()
}

Expand Down Expand Up @@ -1873,7 +1886,6 @@ 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)
Expand Down Expand Up @@ -2221,5 +2233,6 @@ class ConversationsListActivity :
private const val SIXTEEN_HOURS_IN_SECONDS: Long = 57600
const val LONG_1000: Long = 1000
private const val NOTE_TO_SELF_SHORTCUT_ID = "NOTE_TO_SELF_SHORTCUT_ID"
private const val CONVERSATION_ITEM_HEIGHT = 44
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the nicest solution but fine for me as the handling will be replaced with Compose anyway

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import com.nextcloud.talk.ui.PlaybackSpeed;

import kotlin.Pair;

@SuppressLint("NonConstantResourceId")
public interface AppPreferences {

Expand Down Expand Up @@ -185,5 +187,9 @@ public interface AppPreferences {

void setShowRegularNotificationWarning(boolean value);

void setConversationListPositionAndOffset(int position, int offset);

Pair<Integer, Integer> getConversationListPositionAndOffset();

void clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>()
Expand Down
Loading