diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt index efbca44b..2f771a09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/InsertOrEditContactActivity.kt @@ -18,8 +18,8 @@ import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener import com.simplemobiletools.contacts.pro.models.Contact import kotlinx.android.synthetic.main.activity_insert_edit_contact.* +import kotlinx.android.synthetic.main.fragment_contacts.* import kotlinx.android.synthetic.main.fragment_favorites.* -import kotlinx.android.synthetic.main.fragment_insert_or_edit_contacts.* class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { private val START_INSERT_ACTIVITY = 1 @@ -117,8 +117,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { } if (viewpager.adapter == null) { - val fragments = arrayListOf(R.layout.fragment_insert_or_edit_contacts, R.layout.fragment_favorites) - viewpager.adapter = ViewPagerAdapter(this, contactsFavoritesList, CONTACTS_TAB_MASK or FAVORITES_TAB_MASK, fragments) + viewpager.adapter = ViewPagerAdapter(this, contactsFavoritesList, CONTACTS_TAB_MASK or FAVORITES_TAB_MASK) } ContactsHelper(this).getContacts { contacts -> @@ -127,7 +126,7 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { } if (refreshTabsMask and CONTACTS_TAB_MASK != 0) { - insert_or_edit_contacts_fragment?.refreshContacts(contacts) + contacts_fragment?.refreshContacts(contacts) } if (refreshTabsMask and FAVORITES_TAB_MASK != 0) { @@ -185,4 +184,8 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener { } } } + + fun fabClicked() { + createNewContact() + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index b80fa62b..b052eed5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -532,8 +532,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { isGettingContacts = true if (viewpager.adapter == null) { - val fragments = arrayListOf(R.layout.fragment_contacts, R.layout.fragment_favorites, R.layout.fragment_groups) - viewpager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs, fragments) + viewpager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs) viewpager.currentItem = config.lastUsedViewPagerPage } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt index ed2f6019..ab141e80 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ViewPagerAdapter.kt @@ -3,13 +3,14 @@ package com.simplemobiletools.contacts.pro.adapters import android.view.View import android.view.ViewGroup import androidx.viewpager.widget.PagerAdapter +import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.activities.SimpleActivity import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment import com.simplemobiletools.contacts.pro.helpers.CONTACTS_TAB_MASK import com.simplemobiletools.contacts.pro.helpers.FAVORITES_TAB_MASK import com.simplemobiletools.contacts.pro.helpers.GROUPS_TAB_MASK -class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList, val showTabs: Int, val pagerFragments: ArrayList) : PagerAdapter() { +class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList, val showTabs: Int) : PagerAdapter() { override fun instantiateItem(container: ViewGroup, position: Int): Any { val layout = getFragment(position) @@ -34,15 +35,15 @@ class ViewPagerAdapter(val activity: SimpleActivity, val currTabsList: ArrayList private fun getFragment(position: Int): Int { val fragments = arrayListOf() if (showTabs and CONTACTS_TAB_MASK != 0) { - fragments.add(pagerFragments[0]) + fragments.add(R.layout.fragment_contacts) } if (showTabs and FAVORITES_TAB_MASK != 0) { - fragments.add(pagerFragments[1]) + fragments.add(R.layout.fragment_favorites) } if (showTabs and GROUPS_TAB_MASK != 0) { - fragments.add(pagerFragments[2]) + fragments.add(R.layout.fragment_groups) } return fragments[position] diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt index 78324aec..570aea70 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.activities.GroupContactsActivity +import com.simplemobiletools.contacts.pro.activities.InsertOrEditContactActivity import com.simplemobiletools.contacts.pro.activities.MainActivity import com.simplemobiletools.contacts.pro.activities.SimpleActivity import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter @@ -40,7 +41,11 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) if (this.activity == null) { this.activity = activity fragment_fab?.setOnClickListener { - fabClicked() + if (activity is InsertOrEditContactActivity) { + activity.fabClicked() + } else { + fabClicked() + } } fragment_placeholder_2?.setOnClickListener { diff --git a/app/src/main/res/layout/fragment_insert_or_edit_contacts.xml b/app/src/main/res/layout/fragment_insert_or_edit_contacts.xml deleted file mode 100644 index e39c717c..00000000 --- a/app/src/main/res/layout/fragment_insert_or_edit_contacts.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - -