splash screen
pin & unpin conversations
This commit is contained in:
@@ -82,15 +82,17 @@ dependencies {
|
|||||||
|
|
||||||
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
|
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
|
||||||
|
|
||||||
|
implementation("androidx.core:core-splashscreen:1.0.0-alpha02")
|
||||||
|
|
||||||
implementation("androidx.work:work-runtime-ktx:2.6.0")
|
implementation("androidx.work:work-runtime-ktx:2.6.0")
|
||||||
|
|
||||||
implementation("androidx.datastore:datastore-preferences:1.0.0")
|
implementation("androidx.datastore:datastore-preferences:1.0.0")
|
||||||
|
|
||||||
implementation("androidx.paging:paging-runtime-ktx:3.0.1")
|
implementation("androidx.paging:paging-runtime-ktx:3.0.1")
|
||||||
|
|
||||||
implementation("androidx.appcompat:appcompat:1.4.0-alpha03")
|
implementation("androidx.appcompat:appcompat:1.4.0-beta01")
|
||||||
implementation("com.google.android.material:material:1.5.0-alpha03")
|
implementation("com.google.android.material:material:1.5.0-alpha04")
|
||||||
implementation("androidx.core:core-ktx:1.7.0-beta01")
|
implementation("androidx.core:core-ktx:1.7.0-beta02")
|
||||||
implementation("androidx.preference:preference-ktx:1.1.1")
|
implementation("androidx.preference:preference-ktx:1.1.1")
|
||||||
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
|
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
|
||||||
implementation("androidx.recyclerview:recyclerview:1.2.1")
|
implementation("androidx.recyclerview:recyclerview:1.2.1")
|
||||||
@@ -118,16 +120,16 @@ dependencies {
|
|||||||
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
||||||
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
|
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
|
||||||
|
|
||||||
implementation("com.google.dagger:hilt-android:2.38.1")
|
implementation("com.google.dagger:hilt-android:2.39.1")
|
||||||
kapt("com.google.dagger:hilt-android-compiler:2.38.1")
|
kapt("com.google.dagger:hilt-android-compiler:2.39.1")
|
||||||
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
|
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
|
||||||
|
|
||||||
implementation("com.github.yogacp:android-viewbinding:1.0.3")
|
implementation("com.github.yogacp:android-viewbinding:1.0.3")
|
||||||
|
|
||||||
implementation("io.coil-kt:coil:1.3.2")
|
implementation("io.coil-kt:coil:1.4.0")
|
||||||
|
|
||||||
implementation("com.google.code.gson:gson:2.8.8")
|
implementation("com.google.code.gson:gson:2.8.8")
|
||||||
implementation("org.jsoup:jsoup:1.14.2")
|
implementation("org.jsoup:jsoup:1.14.3")
|
||||||
implementation("ch.acra:acra:4.11.1")
|
implementation("ch.acra:acra:4.11.1")
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,17 @@
|
|||||||
package com.meloda.fast.activity
|
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.R
|
||||||
import com.meloda.fast.base.BaseActivity
|
import com.meloda.fast.base.BaseActivity
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
@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 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)
|
suspend fun store(conversations: List<VkConversation>) = dao.insert(conversations)
|
||||||
|
|
||||||
|
|||||||
@@ -28,4 +28,14 @@ data class ConversationsGetRequest(
|
|||||||
@Parcelize
|
@Parcelize
|
||||||
data class ConversationsDeleteRequest(val peerId: Int) : Parcelable {
|
data class ConversationsDeleteRequest(val peerId: Int) : Parcelable {
|
||||||
val map get() = mapOf("peer_id" to peerId.toString())
|
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 ConversationsLoaded -> refreshConversations(event)
|
||||||
is ConversationsDelete -> deleteConversation(event.peerId)
|
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>) {
|
private fun fillRecyclerView(values: List<VkConversation>) {
|
||||||
adapter.values.clear()
|
adapter.values.clear()
|
||||||
adapter.values += values
|
adapter.values += values
|
||||||
adapter.notifyItemRangeChanged(0, adapter.itemCount)
|
adapter.submitList(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onItemClick(position: Int) {
|
private fun onItemClick(position: Int) {
|
||||||
val conversation = adapter[position]
|
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(
|
findNavController().navigate(
|
||||||
R.id.toMessagesHistory,
|
R.id.toMessagesHistory,
|
||||||
@@ -266,15 +275,36 @@ class ConversationsFragment :
|
|||||||
private fun showOptionsDialog(position: Int) {
|
private fun showOptionsDialog(position: Int) {
|
||||||
val conversation = adapter[position]
|
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 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()
|
val arrayParams = params.toTypedArray()
|
||||||
|
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setItems(arrayParams) { _, which ->
|
.setItems(arrayParams) { _, which ->
|
||||||
when (params[which]) {
|
when (params[which]) {
|
||||||
|
pin -> showPinConversationDialog(conversation)
|
||||||
delete -> showDeleteConversationDialog(conversation.id)
|
delete -> showDeleteConversationDialog(conversation.id)
|
||||||
}
|
}
|
||||||
}.show()
|
}.show()
|
||||||
@@ -295,4 +325,24 @@ class ConversationsFragment :
|
|||||||
adapter.notifyItemRemoved(index)
|
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.VkConversation
|
||||||
import com.meloda.fast.api.model.VkGroup
|
import com.meloda.fast.api.model.VkGroup
|
||||||
import com.meloda.fast.api.model.VkUser
|
import com.meloda.fast.api.model.VkUser
|
||||||
import com.meloda.fast.api.network.conversations.ConversationsDataSource
|
import com.meloda.fast.api.network.conversations.*
|
||||||
import com.meloda.fast.api.network.conversations.ConversationsDeleteRequest
|
|
||||||
import com.meloda.fast.api.network.conversations.ConversationsGetRequest
|
|
||||||
import com.meloda.fast.api.network.users.UsersDataSource
|
import com.meloda.fast.api.network.users.UsersDataSource
|
||||||
import com.meloda.fast.api.network.users.UsersGetRequest
|
import com.meloda.fast.api.network.users.UsersGetRequest
|
||||||
import com.meloda.fast.base.viewmodel.BaseViewModel
|
import com.meloda.fast.base.viewmodel.BaseViewModel
|
||||||
@@ -34,7 +32,7 @@ class ConversationsViewModel @Inject constructor(
|
|||||||
count = 30,
|
count = 30,
|
||||||
extended = true,
|
extended = true,
|
||||||
offset = offset,
|
offset = offset,
|
||||||
fields = "${VKConstants.ALL_FIELDS}"
|
fields = VKConstants.ALL_FIELDS
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -88,6 +86,23 @@ class ConversationsViewModel @Inject constructor(
|
|||||||
)
|
)
|
||||||
}, onAnswer = { sendEvent(ConversationsDelete(peerId)) })
|
}, 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(
|
data class ConversationsLoaded(
|
||||||
@@ -99,4 +114,8 @@ data class ConversationsLoaded(
|
|||||||
val groups: HashMap<Int, VkGroup>
|
val groups: HashMap<Int, VkGroup>
|
||||||
) : VkEvent()
|
) : 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()
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="ic_launcher_background">#4184F5</color>
|
<!-- <color name="ic_launcher_background">#4184F5</color>-->
|
||||||
|
<color name="ic_launcher_background">@color/a1_500</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -134,4 +134,10 @@
|
|||||||
<string name="confirm_delete_conversation">Delete the conversation?</string>
|
<string name="confirm_delete_conversation">Delete the conversation?</string>
|
||||||
<string name="action_sign_out">Sign out</string>
|
<string name="action_sign_out">Sign out</string>
|
||||||
<string name="sign_out_confirm_title">Sign out</string>
|
<string name="sign_out_confirm_title">Sign out</string>
|
||||||
|
<string name="conversation_context_action_unpin">Unpin</string>
|
||||||
|
<string name="conversation_context_action_pin">Pin</string>
|
||||||
|
<string name="confirm_unpin_conversation">Unpin the conversation?</string>
|
||||||
|
<string name="confirm_pin_conversation">Pin the conversation?</string>
|
||||||
|
<string name="action_pin">Pin</string>
|
||||||
|
<string name="action_unpin">Unpin</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -41,5 +41,10 @@
|
|||||||
<item name="dialogCornerRadius">12dp</item>
|
<item name="dialogCornerRadius">12dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.Splash" parent="Theme.SplashScreen">
|
||||||
|
<item name="windowSplashScreenBackground">@color/colorBackground</item>
|
||||||
|
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
|
||||||
|
<item name="postSplashScreenTheme">@style/AppTheme</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user