2018-11-05 12:36:29 +01:00
|
|
|
package com.simplemobiletools.contacts.pro.adapters
|
2017-12-28 23:59:49 +01:00
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2018-10-15 14:19:32 +02:00
|
|
|
import androidx.viewpager.widget.PagerAdapter
|
2022-04-10 21:40:19 +02:00
|
|
|
import com.simplemobiletools.commons.extensions.getProperPrimaryColor
|
|
|
|
import com.simplemobiletools.commons.extensions.getProperTextColor
|
2020-05-23 20:00:02 +02:00
|
|
|
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
|
|
|
|
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
|
|
|
|
import com.simplemobiletools.commons.helpers.TAB_GROUPS
|
2019-12-06 22:51:06 +01:00
|
|
|
import com.simplemobiletools.contacts.pro.R
|
2019-12-06 20:49:12 +01:00
|
|
|
import com.simplemobiletools.contacts.pro.activities.SimpleActivity
|
2018-11-05 12:36:29 +01:00
|
|
|
import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment
|
2017-12-28 23:59:49 +01:00
|
|
|
|
2019-12-06 22:51:06 +01:00
|
|
|
class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList<Int>, val showTabs: Int) : PagerAdapter() {
|
2017-12-28 23:59:49 +01:00
|
|
|
|
|
|
|
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
2018-03-16 20:23:15 +01:00
|
|
|
val layout = getFragment(position)
|
2017-12-28 23:59:49 +01:00
|
|
|
val view = activity.layoutInflater.inflate(layout, container, false)
|
|
|
|
container.addView(view)
|
2018-08-02 12:05:21 +02:00
|
|
|
|
2023-08-07 16:13:37 +02:00
|
|
|
(view as MyViewPagerFragment<*>).apply {
|
2018-03-19 11:53:20 +01:00
|
|
|
setupFragment(activity)
|
2022-04-10 21:40:19 +02:00
|
|
|
setupColors(activity.getProperTextColor(), activity.getProperPrimaryColor())
|
2018-03-19 11:53:20 +01:00
|
|
|
}
|
2018-08-04 19:42:33 +02:00
|
|
|
|
2017-12-28 23:59:49 +01:00
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun destroyItem(container: ViewGroup, position: Int, item: Any) {
|
|
|
|
container.removeView(item as View)
|
|
|
|
}
|
|
|
|
|
2019-12-06 20:49:12 +01:00
|
|
|
override fun getCount() = currTabsList.filter { it and showTabs != 0 }.size
|
2018-08-02 12:05:21 +02:00
|
|
|
|
2017-12-28 23:59:49 +01:00
|
|
|
override fun isViewFromObject(view: View, item: Any) = view == item
|
2018-03-16 20:23:15 +01:00
|
|
|
|
2018-08-02 12:05:21 +02:00
|
|
|
private fun getFragment(position: Int): Int {
|
2018-08-03 13:52:44 +02:00
|
|
|
val fragments = arrayListOf<Int>()
|
2020-05-23 20:00:02 +02:00
|
|
|
if (showTabs and TAB_CONTACTS != 0) {
|
2019-12-06 22:51:06 +01:00
|
|
|
fragments.add(R.layout.fragment_contacts)
|
2018-08-02 12:05:21 +02:00
|
|
|
}
|
2018-08-03 13:52:44 +02:00
|
|
|
|
2020-05-23 20:00:02 +02:00
|
|
|
if (showTabs and TAB_FAVORITES != 0) {
|
2019-12-06 22:51:06 +01:00
|
|
|
fragments.add(R.layout.fragment_favorites)
|
2018-08-03 13:52:44 +02:00
|
|
|
}
|
|
|
|
|
2020-05-23 20:00:02 +02:00
|
|
|
if (showTabs and TAB_GROUPS != 0) {
|
2019-12-06 22:51:06 +01:00
|
|
|
fragments.add(R.layout.fragment_groups)
|
2018-08-03 13:52:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return fragments[position]
|
2018-03-16 20:23:15 +01:00
|
|
|
}
|
2017-12-28 23:59:49 +01:00
|
|
|
}
|