splash screen
pin & unpin conversations
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
package com.meloda.fast.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import com.meloda.fast.R
|
||||
import com.meloda.fast.base.BaseActivity
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : BaseActivity(R.layout.activity_main)
|
||||
class MainActivity : BaseActivity(R.layout.activity_main) {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
installSplashScreen()
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
}
|
||||
+2
@@ -13,7 +13,9 @@ class ConversationsDataSource @Inject constructor(
|
||||
|
||||
suspend fun delete(params: ConversationsDeleteRequest) = repo.delete(params.map)
|
||||
|
||||
suspend fun pin(params: ConversationsPinRequest) = repo.pin(params.map)
|
||||
|
||||
suspend fun unpin(params: ConversationsUnpinRequest) = repo.unpin(params.map)
|
||||
|
||||
suspend fun store(conversations: List<VkConversation>) = dao.insert(conversations)
|
||||
|
||||
|
||||
@@ -28,4 +28,14 @@ data class ConversationsGetRequest(
|
||||
@Parcelize
|
||||
data class ConversationsDeleteRequest(val peerId: Int) : Parcelable {
|
||||
val map get() = mapOf("peer_id" to peerId.toString())
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class ConversationsPinRequest(val peerId: Int) : Parcelable {
|
||||
val map get() = mapOf("peer_id" to peerId.toString())
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class ConversationsUnpinRequest(val peerId: Int) : Parcelable {
|
||||
val map get() = mapOf("peer_id" to peerId.toString())
|
||||
}
|
||||
@@ -187,6 +187,9 @@ class ConversationsFragment :
|
||||
|
||||
is ConversationsLoaded -> refreshConversations(event)
|
||||
is ConversationsDelete -> deleteConversation(event.peerId)
|
||||
|
||||
// TODO: 10-Oct-21 remove this and sort conversations list
|
||||
is ConversationsPin, is ConversationsUnpin -> viewModel.loadConversations()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,13 +243,19 @@ class ConversationsFragment :
|
||||
private fun fillRecyclerView(values: List<VkConversation>) {
|
||||
adapter.values.clear()
|
||||
adapter.values += values
|
||||
adapter.notifyItemRangeChanged(0, adapter.itemCount)
|
||||
adapter.submitList(values)
|
||||
}
|
||||
|
||||
private fun onItemClick(position: Int) {
|
||||
val conversation = adapter[position]
|
||||
val user = if (conversation.isUser()) adapter.profiles[conversation.id] else null
|
||||
val group = if (conversation.isGroup()) adapter.groups[conversation.id] else null
|
||||
|
||||
val user =
|
||||
if (conversation.isUser()) adapter.profiles[conversation.id]
|
||||
else null
|
||||
|
||||
val group =
|
||||
if (conversation.isGroup()) adapter.groups[conversation.id]
|
||||
else null
|
||||
|
||||
findNavController().navigate(
|
||||
R.id.toMessagesHistory,
|
||||
@@ -266,15 +275,36 @@ class ConversationsFragment :
|
||||
private fun showOptionsDialog(position: Int) {
|
||||
val conversation = adapter[position]
|
||||
|
||||
var canPinOneMoreDialog = true
|
||||
if (adapter.itemCount > 4) {
|
||||
val firstFiveDialogs = adapter.values.subList(0, 5)
|
||||
var pinnedCount = 0
|
||||
|
||||
firstFiveDialogs.forEach { if (it.isPinned) pinnedCount++ }
|
||||
if (pinnedCount == 5 && position > 4) {
|
||||
canPinOneMoreDialog = false
|
||||
}
|
||||
}
|
||||
|
||||
val pin = getString(
|
||||
if (conversation.isPinned) R.string.conversation_context_action_unpin
|
||||
else R.string.conversation_context_action_pin
|
||||
)
|
||||
|
||||
val delete = getString(R.string.conversation_context_action_delete)
|
||||
|
||||
val params = mutableListOf(delete)
|
||||
val params = mutableListOf<String>()
|
||||
|
||||
if (canPinOneMoreDialog) params += pin
|
||||
|
||||
params += delete
|
||||
|
||||
val arrayParams = params.toTypedArray()
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setItems(arrayParams) { _, which ->
|
||||
when (params[which]) {
|
||||
pin -> showPinConversationDialog(conversation)
|
||||
delete -> showDeleteConversationDialog(conversation.id)
|
||||
}
|
||||
}.show()
|
||||
@@ -295,4 +325,24 @@ class ConversationsFragment :
|
||||
adapter.notifyItemRemoved(index)
|
||||
}
|
||||
|
||||
private fun showPinConversationDialog(conversation: VkConversation) {
|
||||
val isPinned = conversation.isPinned
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(
|
||||
if (isPinned) R.string.confirm_unpin_conversation
|
||||
else R.string.confirm_pin_conversation
|
||||
)
|
||||
.setPositiveButton(
|
||||
if (isPinned) R.string.action_unpin
|
||||
else R.string.action_pin
|
||||
) { _, _ ->
|
||||
viewModel.pinConversation(
|
||||
peerId = conversation.id,
|
||||
pin = !isPinned
|
||||
)
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
}
|
||||
+24
-5
@@ -6,9 +6,7 @@ import com.meloda.fast.api.VKConstants
|
||||
import com.meloda.fast.api.model.VkConversation
|
||||
import com.meloda.fast.api.model.VkGroup
|
||||
import com.meloda.fast.api.model.VkUser
|
||||
import com.meloda.fast.api.network.conversations.ConversationsDataSource
|
||||
import com.meloda.fast.api.network.conversations.ConversationsDeleteRequest
|
||||
import com.meloda.fast.api.network.conversations.ConversationsGetRequest
|
||||
import com.meloda.fast.api.network.conversations.*
|
||||
import com.meloda.fast.api.network.users.UsersDataSource
|
||||
import com.meloda.fast.api.network.users.UsersGetRequest
|
||||
import com.meloda.fast.base.viewmodel.BaseViewModel
|
||||
@@ -34,7 +32,7 @@ class ConversationsViewModel @Inject constructor(
|
||||
count = 30,
|
||||
extended = true,
|
||||
offset = offset,
|
||||
fields = "${VKConstants.ALL_FIELDS}"
|
||||
fields = VKConstants.ALL_FIELDS
|
||||
)
|
||||
)
|
||||
},
|
||||
@@ -88,6 +86,23 @@ class ConversationsViewModel @Inject constructor(
|
||||
)
|
||||
}, onAnswer = { sendEvent(ConversationsDelete(peerId)) })
|
||||
}
|
||||
|
||||
fun pinConversation(
|
||||
peerId: Int,
|
||||
pin: Boolean
|
||||
) = viewModelScope.launch {
|
||||
if (pin) {
|
||||
makeJob(
|
||||
{ conversations.pin(ConversationsPinRequest(peerId)) },
|
||||
onAnswer = { sendEvent(ConversationsPin(peerId)) }
|
||||
)
|
||||
} else {
|
||||
makeJob(
|
||||
{ conversations.unpin(ConversationsUnpinRequest(peerId)) },
|
||||
onAnswer = { sendEvent(ConversationsUnpin(peerId)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class ConversationsLoaded(
|
||||
@@ -99,4 +114,8 @@ data class ConversationsLoaded(
|
||||
val groups: HashMap<Int, VkGroup>
|
||||
) : VkEvent()
|
||||
|
||||
data class ConversationsDelete(val peerId: Int) : VkEvent()
|
||||
data class ConversationsDelete(val peerId: Int) : VkEvent()
|
||||
|
||||
data class ConversationsPin(val peerId: Int) : VkEvent()
|
||||
|
||||
data class ConversationsUnpin(val peerId: Int) : VkEvent()
|
||||
Reference in New Issue
Block a user