mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
feat(channelGroups): disallow creation of already existing groups
This commit is contained in:
parent
7f72a3eaeb
commit
b2f3c8ecbe
@ -11,6 +11,9 @@ interface SubscriptionGroupsDao {
|
||||
@Query("SELECT * FROM subscriptionGroups")
|
||||
suspend fun getAll(): List<SubscriptionGroup>
|
||||
|
||||
@Query("SELECT EXISTS(SELECT * FROM subscriptionGroups WHERE name = :name)")
|
||||
suspend fun exists(name: String): Boolean
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun createGroup(subscriptionGroup: SubscriptionGroup)
|
||||
|
||||
|
@ -13,11 +13,13 @@ import com.github.libretube.R
|
||||
import com.github.libretube.api.SubscriptionHelper
|
||||
import com.github.libretube.api.obj.Subscription
|
||||
import com.github.libretube.databinding.DialogEditChannelGroupBinding
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.db.obj.SubscriptionGroup
|
||||
import com.github.libretube.ui.adapters.SubscriptionGroupChannelsAdapter
|
||||
import com.github.libretube.ui.models.SubscriptionsViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class EditChannelGroupSheet(
|
||||
@ -32,7 +34,7 @@ class EditChannelGroupSheet(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
): View {
|
||||
binding = DialogEditChannelGroupBinding.inflate(layoutInflater)
|
||||
binding.groupName.setText(group.name)
|
||||
|
||||
@ -92,15 +94,25 @@ class EditChannelGroupSheet(
|
||||
|
||||
private fun updateConfirmStatus() {
|
||||
with(binding) {
|
||||
val isGroupNameBlank = groupName.text?.isBlank() == true
|
||||
val name = groupName.text.toString()
|
||||
groupName.error = getGroupNameError(name)
|
||||
|
||||
groupName.error = if (isGroupNameBlank) {
|
||||
requireContext().getString(R.string.group_name_error)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
confirm.isEnabled = !isGroupNameBlank && group.channels.isNotEmpty()
|
||||
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,7 +406,8 @@
|
||||
<string name="channel_groups">Channel groups</string>
|
||||
<string name="new_group">New</string>
|
||||
<string name="group_name">Group name</string>
|
||||
<string name="group_name_error">Please enter a 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="play_automatically">Play automatically</string>
|
||||
<string name="play_automatically_summary">Start playing video automatically when selecting</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user