forked from upstream-mirrors/quik
Sync starred contacts and groups
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.mapper
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.provider.ContactsContract
|
||||
import com.moez.QKSMS.model.ContactGroup
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToContactGroupImpl @Inject constructor(
|
||||
private val context: Context
|
||||
) : CursorToContactGroup {
|
||||
|
||||
companion object {
|
||||
private val URI = ContactsContract.Groups.CONTENT_URI
|
||||
private val PROJECTION = arrayOf(
|
||||
ContactsContract.Groups._ID,
|
||||
ContactsContract.Groups.TITLE)
|
||||
private const val SELECTION = "${ContactsContract.Groups.AUTO_ADD}=0 " +
|
||||
"AND ${ContactsContract.Groups.DELETED}=0 " +
|
||||
"AND ${ContactsContract.Groups.FAVORITES}=0"
|
||||
|
||||
private const val ID = 0
|
||||
private const val TITLE = 1
|
||||
}
|
||||
|
||||
override fun map(from: Cursor): ContactGroup {
|
||||
return ContactGroup(from.getLong(ID), from.getString(TITLE))
|
||||
}
|
||||
|
||||
override fun getContactGroupsCursor(): Cursor? {
|
||||
return context.contentResolver.query(URI, PROJECTION, SELECTION, null, null)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.mapper
|
||||
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.provider.ContactsContract
|
||||
import javax.inject.Inject
|
||||
|
||||
class CursorToContactGroupMemberImpl @Inject constructor(
|
||||
private val context: Context
|
||||
) : CursorToContactGroupMember {
|
||||
|
||||
companion object {
|
||||
private val URI = ContactsContract.Data.CONTENT_URI
|
||||
private val PROJECTION = arrayOf(
|
||||
ContactsContract.Data.LOOKUP_KEY,
|
||||
ContactsContract.Data.DATA1)
|
||||
|
||||
private const val SELECTION = "${ContactsContract.Data.MIMETYPE}=?"
|
||||
private val SELECTION_ARGS = arrayOf(
|
||||
ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
|
||||
|
||||
private const val LOOKUP_KEY = 0
|
||||
private const val GROUP_ID = 1
|
||||
}
|
||||
|
||||
override fun map(from: Cursor): CursorToContactGroupMember.GroupMember {
|
||||
return CursorToContactGroupMember.GroupMember(from.getString(LOOKUP_KEY), from.getLong(GROUP_ID))
|
||||
}
|
||||
|
||||
override fun getGroupMembersCursor(): Cursor? {
|
||||
return context.contentResolver.query(URI, PROJECTION, SELECTION, SELECTION_ARGS, null)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,6 +39,7 @@ class CursorToContactImpl @Inject constructor(
|
||||
Phone.TYPE,
|
||||
Phone.LABEL,
|
||||
Phone.DISPLAY_NAME,
|
||||
Phone.STARRED,
|
||||
Phone.CONTACT_LAST_UPDATED_TIMESTAMP
|
||||
)
|
||||
|
||||
@@ -47,7 +48,8 @@ class CursorToContactImpl @Inject constructor(
|
||||
const val COLUMN_TYPE = 2
|
||||
const val COLUMN_LABEL = 3
|
||||
const val COLUMN_DISPLAY_NAME = 4
|
||||
const val CONTACT_LAST_UPDATED = 5
|
||||
const val COLUMN_STARRED = 5
|
||||
const val CONTACT_LAST_UPDATED = 6
|
||||
}
|
||||
|
||||
override fun map(from: Cursor) = Contact().apply {
|
||||
@@ -58,6 +60,7 @@ class CursorToContactImpl @Inject constructor(
|
||||
type = Phone.getTypeLabel(context.resources, from.getInt(COLUMN_TYPE),
|
||||
from.getString(COLUMN_LABEL)).toString()
|
||||
))
|
||||
starred = from.getInt(COLUMN_STARRED) != 0
|
||||
lastUpdate = from.getLong(CONTACT_LAST_UPDATED)
|
||||
}
|
||||
|
||||
@@ -68,4 +71,4 @@ class CursorToContactImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user