populate Groups tab with the contact groups
This commit is contained in:
parent
707f3ee4a0
commit
796cb13c9c
|
@ -29,7 +29,7 @@ import kotlinx.android.synthetic.main.item_edit_address.view.*
|
|||
import kotlinx.android.synthetic.main.item_edit_email.view.*
|
||||
import kotlinx.android.synthetic.main.item_edit_phone_number.view.*
|
||||
import kotlinx.android.synthetic.main.item_event.view.*
|
||||
import kotlinx.android.synthetic.main.item_group.view.*
|
||||
import kotlinx.android.synthetic.main.item_edit_group.view.*
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import java.util.*
|
||||
|
@ -331,7 +331,7 @@ class EditContactActivity : ContactActivity() {
|
|||
groups.forEachIndexed { index, group ->
|
||||
var groupHolder = contact_groups_holder.getChildAt(index)
|
||||
if (groupHolder == null) {
|
||||
groupHolder = layoutInflater.inflate(R.layout.item_group, contact_groups_holder, false)
|
||||
groupHolder = layoutInflater.inflate(R.layout.item_edit_group, contact_groups_holder, false)
|
||||
contact_groups_holder.addView(groupHolder)
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ class EditContactActivity : ContactActivity() {
|
|||
}
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
layoutInflater.inflate(R.layout.item_group, contact_groups_holder, false).apply {
|
||||
layoutInflater.inflate(R.layout.item_edit_group, contact_groups_holder, false).apply {
|
||||
contact_group.apply {
|
||||
alpha = 0.5f
|
||||
text = getString(R.string.no_groups)
|
||||
|
|
|
@ -95,6 +95,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
if (storedShowContactThumbnails != configShowContactThumbnails) {
|
||||
contacts_fragment?.showContactThumbnailsChanged(configShowContactThumbnails)
|
||||
favorites_fragment?.showContactThumbnailsChanged(configShowContactThumbnails)
|
||||
groups_fragment?.showContactThumbnailsChanged(configShowContactThumbnails)
|
||||
}
|
||||
|
||||
val configTextColor = config.textColor
|
||||
|
@ -104,6 +105,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
}
|
||||
contacts_fragment?.textColorChanged(configTextColor)
|
||||
favorites_fragment?.textColorChanged(configTextColor)
|
||||
groups_fragment?.textColorChanged(configTextColor)
|
||||
}
|
||||
|
||||
val configBackgroundColor = config.backgroundColor
|
||||
|
@ -117,6 +119,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
main_tabs_holder.getTabAt(viewpager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
contacts_fragment?.primaryColorChanged(configPrimaryColor)
|
||||
favorites_fragment?.primaryColorChanged(configPrimaryColor)
|
||||
groups_fragment?.primaryColorChanged(configPrimaryColor)
|
||||
}
|
||||
|
||||
val configStartNameWithSurname = config.startNameWithSurname
|
||||
|
@ -132,6 +135,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
|
||||
contacts_fragment?.onActivityResume()
|
||||
favorites_fragment?.onActivityResume()
|
||||
groups_fragment?.onActivityResume()
|
||||
refreshContacts(true, true)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private lateinit var contactDrawable: Drawable
|
||||
var config = activity.config
|
||||
private var config = activity.config
|
||||
var startNameWithSurname: Boolean
|
||||
var showContactThumbnails: Boolean
|
||||
var showPhoneNumbers: Boolean
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package com.simplemobiletools.contacts.adapters
|
||||
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.models.Group
|
||||
import kotlinx.android.synthetic.main.item_group.view.*
|
||||
import java.util.*
|
||||
|
||||
class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList<Group>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
|
||||
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private var config = activity.config
|
||||
private var smallPadding = activity.resources.getDimension(R.dimen.small_margin).toInt()
|
||||
private var bigPadding = activity.resources.getDimension(R.dimen.normal_margin).toInt()
|
||||
|
||||
var showContactThumbnails = config.showContactThumbnails
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_groups
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {
|
||||
menu.apply {
|
||||
findItem(R.id.cab_edit).isVisible = isOneItemSelected()
|
||||
}
|
||||
}
|
||||
|
||||
override fun prepareItemSelection(view: View) {}
|
||||
|
||||
override fun markItemSelection(select: Boolean, view: View?) {
|
||||
view?.group_frame?.isSelected = select
|
||||
}
|
||||
|
||||
override fun actionItemPressed(id: Int) {
|
||||
if (selectedPositions.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
when (id) {
|
||||
R.id.cab_edit -> editGroup()
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectableItemCount() = groups.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_group, parent)
|
||||
|
||||
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||
val group = groups[position]
|
||||
val view = holder.bindView(group, true) { itemView, layoutPosition ->
|
||||
setupView(itemView, group)
|
||||
}
|
||||
bindViewHolder(holder, position, view)
|
||||
}
|
||||
|
||||
override fun getItemCount() = groups.size
|
||||
|
||||
fun updateItems(newItems: ArrayList<Group>) {
|
||||
groups = newItems
|
||||
notifyDataSetChanged()
|
||||
finishActMode()
|
||||
}
|
||||
|
||||
private fun editGroup() {
|
||||
|
||||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(activity) {
|
||||
deleteContacts()
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteContacts() {
|
||||
if (selectedPositions.isEmpty()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupView(view: View, group: Group) {
|
||||
view.apply {
|
||||
group_name.apply {
|
||||
setTextColor(textColor)
|
||||
text = String.format(activity.getString(R.string.groups_placeholder), group.title, group.contactsCount.toString())
|
||||
setPadding(if (showContactThumbnails) smallPadding else bigPadding, smallPadding, smallPadding, 0)
|
||||
}
|
||||
|
||||
group_tmb.beVisibleIf(showContactThumbnails)
|
||||
if (showContactThumbnails) {
|
||||
group_tmb.applyColorFilter(textColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,21 +3,37 @@ package com.simplemobiletools.contacts.fragments
|
|||
import android.content.Context
|
||||
import android.support.design.widget.CoordinatorLayout
|
||||
import android.util.AttributeSet
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.contacts.activities.MainActivity
|
||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||
import com.simplemobiletools.contacts.adapters.GroupsAdapter
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.interfaces.FragmentInterface
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.fragment_groups.view.*
|
||||
|
||||
class GroupsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), FragmentInterface {
|
||||
var activity: MainActivity? = null
|
||||
override fun setupFragment(activity: MainActivity) {
|
||||
this.activity = activity
|
||||
if (this.activity == null) {
|
||||
this.activity = activity
|
||||
groups_fab.setOnClickListener {
|
||||
|
||||
}
|
||||
|
||||
updateViewStuff()
|
||||
}
|
||||
}
|
||||
|
||||
override fun textColorChanged(color: Int) {
|
||||
(groups_list.adapter as GroupsAdapter).updateTextColor(color)
|
||||
}
|
||||
|
||||
override fun primaryColorChanged(color: Int) {
|
||||
groups_fastscroller.updatePrimaryColor()
|
||||
groups_fastscroller.updateBubblePrimaryColor()
|
||||
}
|
||||
|
||||
override fun refreshContacts(contacts: ArrayList<Contact>) {
|
||||
|
@ -33,5 +49,44 @@ class GroupsFragment(context: Context, attributeSet: AttributeSet) : Coordinator
|
|||
storedGroup?.addContact()
|
||||
}
|
||||
}
|
||||
|
||||
val currAdapter = groups_list.adapter
|
||||
if (currAdapter == null) {
|
||||
GroupsAdapter(activity as SimpleActivity, storedGroups, groups_list, groups_fastscroller) {
|
||||
|
||||
}.apply {
|
||||
setupDragListener(true)
|
||||
addVerticalDividers(true)
|
||||
groups_list.adapter = this
|
||||
}
|
||||
|
||||
groups_fastscroller.setScrollTo(0)
|
||||
groups_fastscroller.setViews(groups_list) {
|
||||
val item = (groups_list.adapter as GroupsAdapter).groups.getOrNull(it)
|
||||
groups_fastscroller.updateBubbleText(item?.getBubbleText() ?: "")
|
||||
}
|
||||
} else {
|
||||
(currAdapter as GroupsAdapter).apply {
|
||||
showContactThumbnails = activity.config.showContactThumbnails
|
||||
updateItems(storedGroups)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun showContactThumbnailsChanged(showThumbnails: Boolean) {
|
||||
(groups_list.adapter as? GroupsAdapter)?.apply {
|
||||
showContactThumbnails = showThumbnails
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
fun onActivityResume() {
|
||||
updateViewStuff()
|
||||
}
|
||||
|
||||
private fun updateViewStuff() {
|
||||
context.updateTextColors(groups_wrapper.parent as ViewGroup)
|
||||
groups_fastscroller.updateBubbleColors()
|
||||
groups_fastscroller.allowBubbleDisplay = context.config.showInfoBubble
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
}
|
||||
}
|
||||
|
||||
fun showContactThumbnailsChanged(showThumbnails: Boolean) {
|
||||
override fun showContactThumbnailsChanged(showThumbnails: Boolean) {
|
||||
(fragment_list.adapter as? ContactsAdapter)?.apply {
|
||||
showContactThumbnails = showThumbnails
|
||||
notifyDataSetChanged()
|
||||
|
|
|
@ -11,4 +11,6 @@ interface FragmentInterface {
|
|||
fun primaryColorChanged(color: Int)
|
||||
|
||||
fun refreshContacts(contacts: ArrayList<Contact>)
|
||||
|
||||
fun showContactThumbnailsChanged(showThumbnails: Boolean)
|
||||
}
|
||||
|
|
|
@ -2,4 +2,6 @@ package com.simplemobiletools.contacts.models
|
|||
|
||||
data class Group(var id: Long, var title: String, var contactsCount: Int = 0) {
|
||||
fun addContact() = contactsCount++
|
||||
|
||||
fun getBubbleText() = title
|
||||
}
|
||||
|
|
|
@ -333,7 +333,7 @@
|
|||
android:layout_toRightOf="@+id/contact_name_image"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/item_group"/>
|
||||
<include layout="@layout/item_edit_group"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -1,8 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.simplemobiletools.contacts.fragments.GroupsFragment
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/groups_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/groups_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/groups_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.FastScroller
|
||||
android:id="@+id/groups_fastscroller"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical"/>
|
||||
|
||||
</com.simplemobiletools.commons.views.FastScroller>
|
||||
</RelativeLayout>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
||||
android:id="@+id/groups_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/activity_margin"
|
||||
android:src="@drawable/ic_plus"/>
|
||||
|
||||
</com.simplemobiletools.contacts.fragments.GroupsFragment>
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
android:id="@+id/contact_tmb"
|
||||
android:layout_width="@dimen/normal_icon_size"
|
||||
android:layout_height="@dimen/normal_icon_size"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:src="@drawable/ic_person"/>
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
android:id="@+id/contact_tmb"
|
||||
android:layout_width="@dimen/normal_icon_size"
|
||||
android:layout_height="@dimen/normal_icon_size"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:src="@drawable/ic_person"/>
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/contact_group_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/contact_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@+id/contact_group_remove"
|
||||
android:layout_toStartOf="@+id/contact_group_remove"
|
||||
android:alpha="0.5"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:paddingLeft="@dimen/small_margin"
|
||||
android:paddingRight="@dimen/small_margin"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:text="@string/no_groups"
|
||||
android:textSize="@dimen/bigger_text_size"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_group_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/contact_group"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignTop="@+id/contact_group"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="@dimen/medium_margin"
|
||||
android:layout_marginLeft="@dimen/small_margin"
|
||||
android:layout_marginRight="@dimen/small_margin"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="@drawable/button_background"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:src="@drawable/ic_minus"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,41 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/contact_group_holder"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/group_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="@drawable/selector">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/contact_group"
|
||||
<RelativeLayout
|
||||
android:id="@+id/group_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@+id/contact_group_remove"
|
||||
android:layout_toStartOf="@+id/contact_group_remove"
|
||||
android:alpha="0.5"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/normal_margin"
|
||||
android:paddingLeft="@dimen/small_margin"
|
||||
android:paddingRight="@dimen/small_margin"
|
||||
android:paddingTop="@dimen/normal_margin"
|
||||
android:text="@string/no_groups"
|
||||
android:textSize="@dimen/bigger_text_size"/>
|
||||
android:paddingRight="@dimen/activity_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_group_remove"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/contact_group"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignTop="@+id/contact_group"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="@dimen/medium_margin"
|
||||
android:layout_marginLeft="@dimen/small_margin"
|
||||
android:layout_marginRight="@dimen/small_margin"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="@drawable/button_background"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:src="@drawable/ic_minus"
|
||||
android:visibility="gone"/>
|
||||
<ImageView
|
||||
android:id="@+id/group_tmb"
|
||||
android:layout_width="@dimen/normal_icon_size"
|
||||
android:layout_height="@dimen/normal_icon_size"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="@dimen/medium_margin"
|
||||
android:src="@drawable/ic_group"/>
|
||||
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:id="@+id/group_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/contact_item_height"
|
||||
android:layout_toRightOf="@+id/group_tmb"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:textSize="@dimen/big_text_size"
|
||||
tools:text="Family"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/cab_edit"
|
||||
android:icon="@drawable/ic_rename"
|
||||
android:title="@string/edit_contact"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_select_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
android:title="@string/select_all"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/cab_delete"
|
||||
android:icon="@drawable/ic_delete"
|
||||
android:title="@string/delete"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
|
@ -5,4 +5,6 @@
|
|||
<string name="release_11">Added Address and Notes fields</string>
|
||||
<string name="release_10">Allow storing contacts in a local database, hidden from other apps</string>
|
||||
|
||||
<string name="groups_placeholder">%1$s (%2$s)</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue