allow renaming local private groups
This commit is contained in:
parent
30a7c1770d
commit
bd8dffb549
|
@ -15,7 +15,6 @@ import com.simplemobiletools.contacts.dialogs.RenameGroupDialog
|
|||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.dbHelper
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.helpers.FIRST_GROUP_ID
|
||||
import com.simplemobiletools.contacts.helpers.GROUPS_TAB_MASK
|
||||
import com.simplemobiletools.contacts.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.models.Group
|
||||
|
@ -99,7 +98,7 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, val
|
|||
selectedPositions.sortedDescending().forEach {
|
||||
val group = groups[it]
|
||||
groupsToRemove.add(group)
|
||||
if (group.id >= FIRST_GROUP_ID) {
|
||||
if (group.isPrivateSecretGroup()) {
|
||||
activity.dbHelper.deleteGroup(group.id)
|
||||
} else {
|
||||
ContactsHelper(activity).deleteGroup(group.id)
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.support.v7.app.AlertDialog
|
|||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.extensions.dbHelper
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.models.Group
|
||||
import kotlinx.android.synthetic.main.dialog_rename_group.view.*
|
||||
|
@ -12,7 +13,7 @@ class RenameGroupDialog(val activity: BaseSimpleActivity, val group: Group, val
|
|||
init {
|
||||
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_group, null).apply {
|
||||
rename_group_name.setText(group.title)
|
||||
rename_group_title.setText(group.title)
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
|
@ -20,20 +21,25 @@ class RenameGroupDialog(val activity: BaseSimpleActivity, val group: Group, val
|
|||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.rename) {
|
||||
showKeyboard(view.rename_group_name)
|
||||
showKeyboard(view.rename_group_title)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val newName = view.rename_group_name.value
|
||||
if (newName.isEmpty()) {
|
||||
val newTitle = view.rename_group_title.value
|
||||
if (newTitle.isEmpty()) {
|
||||
activity.toast(R.string.empty_name)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (!newName.isAValidFilename()) {
|
||||
if (!newTitle.isAValidFilename()) {
|
||||
activity.toast(R.string.invalid_name)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
ContactsHelper(activity).renameGroup(group, newName)
|
||||
group.title = newTitle
|
||||
if (group.isPrivateSecretGroup()) {
|
||||
activity.dbHelper.renameGroup(group)
|
||||
} else {
|
||||
ContactsHelper(activity).renameGroup(group)
|
||||
}
|
||||
callback()
|
||||
dismiss()
|
||||
}
|
||||
|
|
|
@ -418,13 +418,13 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
return null
|
||||
}
|
||||
|
||||
fun renameGroup(group: Group, newTitle: String) {
|
||||
fun renameGroup(group: Group) {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
ContentProviderOperation.newUpdate(ContactsContract.Groups.CONTENT_URI).apply {
|
||||
val selection = "${ContactsContract.Groups._ID} = ?"
|
||||
val selectionArgs = arrayOf(group.id.toString())
|
||||
withSelection(selection, selectionArgs)
|
||||
withValue(ContactsContract.Groups.TITLE, newTitle)
|
||||
withValue(ContactsContract.Groups.TITLE, group.title)
|
||||
operations.add(build())
|
||||
}
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
}
|
||||
|
||||
fun updateGroup(group: Group): Boolean {
|
||||
fun renameGroup(group: Group): Boolean {
|
||||
val contactValues = fillGroupValues(group)
|
||||
val selection = "$COL_ID = ?"
|
||||
val selectionArgs = arrayOf(group.id.toString())
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.contacts.models
|
||||
|
||||
import com.simplemobiletools.contacts.helpers.FIRST_GROUP_ID
|
||||
import java.io.Serializable
|
||||
|
||||
data class Group(var id: Long, var title: String, var contactsCount: Int = 0) : Serializable {
|
||||
|
@ -10,4 +11,6 @@ data class Group(var id: Long, var title: String, var contactsCount: Int = 0) :
|
|||
fun addContact() = contactsCount++
|
||||
|
||||
fun getBubbleText() = title
|
||||
|
||||
fun isPrivateSecretGroup() = id >= FIRST_GROUP_ID
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/rename_group_name"
|
||||
android:id="@+id/rename_group_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textCapWords"
|
||||
|
|
Loading…
Reference in New Issue