mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-03-30 11:00:19 +02:00
Refactored and added column count animation
This commit is contained in:
parent
6b33eb68a2
commit
5ef3e16f17
@ -240,6 +240,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeViewType() {
|
||||
ChangeViewTypeDialog(this) {
|
||||
refreshMenuItems()
|
||||
favorites_fragment?.updateFavouritesAdapter()
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeColumnCount() {
|
||||
val items = (CONTACTS_GRID_MIN_COLUMNS_COUNT..CONTACTS_GRID_MAX_COLUMNS_COUNT).map {
|
||||
RadioItem(it, resources.getQuantityString(R.plurals.column_counts, it, it))
|
||||
@ -250,7 +257,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
val newColumnCount = it as Int
|
||||
if (currentColumnCount != newColumnCount) {
|
||||
config.contactsGridColumnCount = newColumnCount
|
||||
favorites_fragment.updateFavoritesColumnCount()
|
||||
favorites_fragment?.columnCountChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -683,11 +690,4 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
||||
checkWhatsNew(this, BuildConfig.VERSION_CODE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeViewType() {
|
||||
ChangeViewTypeDialog(this) {
|
||||
refreshMenuItems()
|
||||
favorites_fragment?.updateFavoritesColumnCount()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import kotlinx.android.synthetic.main.fragment_favorites.view.favorites_fragment
|
||||
import kotlinx.android.synthetic.main.fragment_layout.view.fragment_list
|
||||
|
||||
class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
private var favouriteContacts = listOf<Contact>()
|
||||
|
||||
override fun fabClicked() {
|
||||
finishActMode()
|
||||
showAddFavoritesDialog()
|
||||
@ -45,7 +47,8 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
||||
}
|
||||
|
||||
fun setupContactsFavoritesAdapter(contacts: List<Contact>) {
|
||||
setupViewVisibility(contacts.isNotEmpty())
|
||||
favouriteContacts = contacts
|
||||
setupViewVisibility(favouriteContacts.isNotEmpty())
|
||||
val currAdapter = fragment_list.adapter
|
||||
|
||||
val viewType = context.config.viewType
|
||||
@ -57,7 +60,7 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
||||
|
||||
ContactsAdapter(
|
||||
activity = activity as SimpleActivity,
|
||||
contactItems = contacts.toMutableList(),
|
||||
contactItems = favouriteContacts.toMutableList(),
|
||||
refreshListener = activity as RefreshContactsListener,
|
||||
location = location,
|
||||
viewType = viewType,
|
||||
@ -91,11 +94,15 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
||||
showPhoneNumbers = context.config.showPhoneNumbers
|
||||
showContactThumbnails = context.config.showContactThumbnails
|
||||
this.viewType = viewType
|
||||
updateItems(contacts)
|
||||
updateItems(favouriteContacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateFavouritesAdapter() {
|
||||
setupContactsFavoritesAdapter(favouriteContacts)
|
||||
}
|
||||
|
||||
private fun setFavoritesViewType(viewType: Int) {
|
||||
val spanCount = context.config.contactsGridColumnCount
|
||||
|
||||
@ -109,8 +116,11 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
|
||||
fragment_list.layoutManager = layoutManager
|
||||
}
|
||||
|
||||
fun updateFavoritesColumnCount() {
|
||||
setupContactsFavoritesAdapter(favouriteContacts)
|
||||
fun columnCountChanged() {
|
||||
(fragment_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.contactsGridColumnCount
|
||||
fragment_list?.adapter?.apply {
|
||||
notifyItemRangeChanged(0, favouriteContacts.size)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveCustomOrderToPrefs(items: List<Contact>) {
|
||||
|
@ -34,7 +34,6 @@ import java.util.Locale
|
||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet) {
|
||||
protected var activity: SimpleActivity? = null
|
||||
protected var allContacts = ArrayList<Contact>()
|
||||
protected var favouriteContacts = listOf<Contact>()
|
||||
|
||||
private var lastHashCode = 0
|
||||
private var contactsIgnoringSearch = listOf<Contact>()
|
||||
@ -121,11 +120,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
}
|
||||
|
||||
allContacts = contacts
|
||||
favouriteContacts = contacts.filter { it.starred == 1 }.sortFavourites(activity!!.config.isCustomOrderSelected)
|
||||
val filtered = when (this) {
|
||||
is GroupsFragment -> contacts
|
||||
is FavoritesFragment -> {
|
||||
favouriteContacts
|
||||
contacts.filter { it.starred == 1 }.sortFavourites(activity!!.config.isCustomOrderSelected)
|
||||
}
|
||||
|
||||
else -> {
|
||||
@ -139,7 +137,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
currentHash += it.getHashWithoutPrivatePhoto()
|
||||
}
|
||||
|
||||
if (currentHash != lastHashCode || skipHashComparing || filtered.size == 0) {
|
||||
if (currentHash != lastHashCode || skipHashComparing || filtered.isEmpty()) {
|
||||
skipHashComparing = false
|
||||
lastHashCode = currentHash
|
||||
activity?.runOnUiThread {
|
||||
|
Loading…
x
Reference in New Issue
Block a user