mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
Merge pull request #4550 from FineFindus/feat/channel-group-creation-feedback
feat(channelGroups): disable confirm button if creation is not possible
This commit is contained in:
commit
43b4ec6606
@ -11,6 +11,9 @@ interface SubscriptionGroupsDao {
|
|||||||
@Query("SELECT * FROM subscriptionGroups")
|
@Query("SELECT * FROM subscriptionGroups")
|
||||||
suspend fun getAll(): List<SubscriptionGroup>
|
suspend fun getAll(): List<SubscriptionGroup>
|
||||||
|
|
||||||
|
@Query("SELECT EXISTS(SELECT * FROM subscriptionGroups WHERE name = :name)")
|
||||||
|
suspend fun exists(name: String): Boolean
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun createGroup(subscriptionGroup: SubscriptionGroup)
|
suspend fun createGroup(subscriptionGroup: SubscriptionGroup)
|
||||||
|
|
||||||
|
@ -9,14 +9,17 @@ import androidx.core.widget.addTextChangedListener
|
|||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.SubscriptionHelper
|
import com.github.libretube.api.SubscriptionHelper
|
||||||
import com.github.libretube.api.obj.Subscription
|
import com.github.libretube.api.obj.Subscription
|
||||||
import com.github.libretube.databinding.DialogEditChannelGroupBinding
|
import com.github.libretube.databinding.DialogEditChannelGroupBinding
|
||||||
|
import com.github.libretube.db.DatabaseHolder
|
||||||
import com.github.libretube.db.obj.SubscriptionGroup
|
import com.github.libretube.db.obj.SubscriptionGroup
|
||||||
import com.github.libretube.ui.adapters.SubscriptionGroupChannelsAdapter
|
import com.github.libretube.ui.adapters.SubscriptionGroupChannelsAdapter
|
||||||
import com.github.libretube.ui.models.SubscriptionsViewModel
|
import com.github.libretube.ui.models.SubscriptionsViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class EditChannelGroupSheet(
|
class EditChannelGroupSheet(
|
||||||
@ -31,13 +34,17 @@ class EditChannelGroupSheet(
|
|||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View {
|
||||||
binding = DialogEditChannelGroupBinding.inflate(layoutInflater)
|
binding = DialogEditChannelGroupBinding.inflate(layoutInflater)
|
||||||
binding.groupName.setText(group.name)
|
binding.groupName.setText(group.name)
|
||||||
|
|
||||||
binding.channelsRV.layoutManager = LinearLayoutManager(context)
|
binding.channelsRV.layoutManager = LinearLayoutManager(context)
|
||||||
fetchSubscriptions()
|
fetchSubscriptions()
|
||||||
|
|
||||||
|
binding.groupName.addTextChangedListener {
|
||||||
|
updateConfirmStatus()
|
||||||
|
}
|
||||||
|
|
||||||
binding.searchInput.addTextChangedListener {
|
binding.searchInput.addTextChangedListener {
|
||||||
showChannels(channels, it?.toString())
|
showChannels(channels, it?.toString())
|
||||||
}
|
}
|
||||||
@ -46,6 +53,7 @@ class EditChannelGroupSheet(
|
|||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateConfirmStatus()
|
||||||
binding.confirm.setOnClickListener {
|
binding.confirm.setOnClickListener {
|
||||||
group.name = binding.groupName.text.toString()
|
group.name = binding.groupName.text.toString()
|
||||||
if (group.name.isBlank()) return@setOnClickListener
|
if (group.name.isBlank()) return@setOnClickListener
|
||||||
@ -78,8 +86,33 @@ class EditChannelGroupSheet(
|
|||||||
group
|
group
|
||||||
) {
|
) {
|
||||||
group = it
|
group = it
|
||||||
|
updateConfirmStatus()
|
||||||
}
|
}
|
||||||
binding.subscriptionsContainer.isVisible = true
|
binding.subscriptionsContainer.isVisible = true
|
||||||
binding.progress.isVisible = false
|
binding.progress.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateConfirmStatus() {
|
||||||
|
with(binding) {
|
||||||
|
val name = groupName.text.toString()
|
||||||
|
groupName.error = getGroupNameError(name)
|
||||||
|
|
||||||
|
confirm.isEnabled = groupName.error == null && group.channels.isNotEmpty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getGroupNameError(name: String): String? {
|
||||||
|
if (name.isBlank()) {
|
||||||
|
return getString(R.string.group_name_error_empty)
|
||||||
|
}
|
||||||
|
|
||||||
|
val groupExists = runBlocking(Dispatchers.IO) {
|
||||||
|
DatabaseHolder.Database.subscriptionGroupsDao().exists(name)
|
||||||
|
}
|
||||||
|
if (groupExists) {
|
||||||
|
return getString(R.string.group_name_error_exists)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,6 +406,8 @@
|
|||||||
<string name="channel_groups">Channel groups</string>
|
<string name="channel_groups">Channel groups</string>
|
||||||
<string name="new_group">New</string>
|
<string name="new_group">New</string>
|
||||||
<string name="group_name">Group name</string>
|
<string name="group_name">Group name</string>
|
||||||
|
<string name="group_name_error_empty">Please enter a name</string>
|
||||||
|
<string name="group_name_error_exists">Please choose a name that is unique</string>
|
||||||
<string name="edit_group">Edit group</string>
|
<string name="edit_group">Edit group</string>
|
||||||
<string name="play_automatically">Play automatically</string>
|
<string name="play_automatically">Play automatically</string>
|
||||||
<string name="play_automatically_summary">Start playing video automatically when selecting</string>
|
<string name="play_automatically_summary">Start playing video automatically when selecting</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user