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