allow customizing the default tab to open at app start
This commit is contained in:
parent
053b30320d
commit
9b9d0231a5
|
@ -340,7 +340,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
|
||||
private fun setupTabColors() {
|
||||
handledShowTabs = config.showTabs
|
||||
val lastUsedPage = config.lastUsedViewPagerPage
|
||||
val lastUsedPage = getDefaultTab()
|
||||
main_tabs_holder.apply {
|
||||
background = ColorDrawable(config.backgroundColor)
|
||||
setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
|
@ -406,14 +406,14 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
skippedTabs++
|
||||
} else {
|
||||
val tab = main_tabs_holder.newTab().setIcon(getTabIcon(index))
|
||||
main_tabs_holder.addTab(tab, index - skippedTabs, config.lastUsedViewPagerPage == index - skippedTabs)
|
||||
main_tabs_holder.addTab(tab, index - skippedTabs, getDefaultTab() == index - skippedTabs)
|
||||
}
|
||||
}
|
||||
|
||||
// selecting the proper tab sometimes glitches, add an extra selector to make sure we have it right
|
||||
main_tabs_holder.onGlobalLayout {
|
||||
Handler().postDelayed({
|
||||
main_tabs_holder.getTabAt(config.lastUsedViewPagerPage)?.select()
|
||||
main_tabs_holder.getTabAt(getDefaultTab())?.select()
|
||||
invalidateOptionsMenu()
|
||||
}, 100L)
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
|
||||
if (viewpager.adapter == null) {
|
||||
viewpager.adapter = ViewPagerAdapter(this, tabsList, config.showTabs)
|
||||
viewpager.currentItem = config.lastUsedViewPagerPage
|
||||
viewpager.currentItem = getDefaultTab()
|
||||
}
|
||||
|
||||
ContactsHelper(this).getContacts { contacts ->
|
||||
|
@ -595,6 +595,15 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
|
||||
private fun getAllFragments() = arrayListOf(contacts_fragment, favorites_fragment, groups_fragment)
|
||||
|
||||
private fun getDefaultTab(): Int {
|
||||
return when (config.defaultTab) {
|
||||
TAB_LAST_USED -> config.lastUsedViewPagerPage
|
||||
TAB_CONTACTS -> 0
|
||||
TAB_FAVORITES -> 1
|
||||
else -> 2
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkDialerMigrationDialog() {
|
||||
if (config.appRunCount < 3) {
|
||||
config.wasDialerMigrationShown = true
|
||||
|
|
|
@ -3,13 +3,11 @@ package com.simplemobiletools.contacts.pro.activities
|
|||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.baseConfig
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getFontSizeText
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.FONT_SIZE_EXTRA_LARGE
|
||||
import com.simplemobiletools.commons.helpers.FONT_SIZE_LARGE
|
||||
import com.simplemobiletools.commons.helpers.FONT_SIZE_MEDIUM
|
||||
import com.simplemobiletools.commons.helpers.FONT_SIZE_SMALL
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.dialogs.ManageVisibleFieldsDialog
|
||||
|
@ -43,6 +41,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
setupShowDialpadButton()
|
||||
setupShowPrivateContacts()
|
||||
setupOnContactClick()
|
||||
setupDefaultTab()
|
||||
updateTextColors(settings_holder)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
@ -70,6 +69,29 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupDefaultTab() {
|
||||
settings_default_tab.text = getDefaultTabText()
|
||||
settings_default_tab_holder.setOnClickListener {
|
||||
val items = arrayListOf(
|
||||
RadioItem(TAB_CONTACTS, getString(R.string.contacts_tab)),
|
||||
RadioItem(TAB_FAVORITES, getString(R.string.favorites_tab)),
|
||||
RadioItem(TAB_GROUPS, getString(R.string.groups_tab)),
|
||||
RadioItem(TAB_LAST_USED, getString(R.string.last_used_tab)))
|
||||
|
||||
RadioGroupDialog(this@SettingsActivity, items, config.defaultTab) {
|
||||
config.defaultTab = it as Int
|
||||
settings_default_tab.text = getDefaultTabText()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDefaultTabText() = getString(when (baseConfig.defaultTab) {
|
||||
TAB_CONTACTS -> R.string.contacts_tab
|
||||
TAB_FAVORITES -> R.string.favorites_tab
|
||||
TAB_GROUPS -> R.string.groups_tab
|
||||
else -> R.string.last_used_tab
|
||||
})
|
||||
|
||||
private fun setupFontSize() {
|
||||
settings_font_size.text = getFontSizeText()
|
||||
settings_font_size_holder.setOnClickListener {
|
||||
|
|
|
@ -97,6 +97,38 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_default_tab_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_default_tab_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toStartOf="@+id/settings_default_tab"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:text="@string/default_tab_to_open" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_default_tab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="@dimen/medium_margin"
|
||||
android:background="@null"
|
||||
android:clickable="false" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_font_size_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue