added option to adjust multi column tab width
This commit is contained in:
parent
f79a1913cc
commit
2a11976f17
|
@ -105,11 +105,11 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
private var selectedAccountToSearch: AccountDetails? = null
|
||||
|
||||
private lateinit var multiSelectHandler: MultiSelectEventHandler
|
||||
|
||||
private lateinit var pagerAdapter: SupportTabsAdapter
|
||||
|
||||
private lateinit var drawerToggle: ActionBarDrawerToggle
|
||||
|
||||
private var propertiesInitialized = false
|
||||
|
||||
private var updateUnreadCountTask: UpdateUnreadCountTask? = null
|
||||
private val readStateChangeListener = OnSharedPreferenceChangeListener { sharedPreferences, key -> updateUnreadCount() }
|
||||
private val controlBarShowHideHelper = ControlBarShowHideHelper(this)
|
||||
|
@ -201,18 +201,19 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
}
|
||||
supportRequestWindowFeature(AppCompatDelegate.FEATURE_ACTION_MODE_OVERLAY)
|
||||
setContentView(R.layout.activity_home)
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
drawerToggle = ActionBarDrawerToggle(this, homeMenu, R.string.open_accounts_dashboard,
|
||||
R.string.close_accounts_dashboard)
|
||||
pagerAdapter = SupportTabsAdapter(this, supportFragmentManager, mainTabs)
|
||||
propertiesInitialized = true
|
||||
|
||||
ThemeUtils.setCompatContentViewOverlay(window, EmptyDrawable())
|
||||
|
||||
val refreshOnStart = preferences.getBoolean(SharedPreferenceConstants.KEY_REFRESH_ON_START, false)
|
||||
var tabDisplayOptionInt = Utils.getTabDisplayOptionInt(this)
|
||||
|
||||
drawerToggle = ActionBarDrawerToggle(this, homeMenu, R.string.open_accounts_dashboard,
|
||||
R.string.close_accounts_dashboard)
|
||||
homeContent.setOnFitSystemWindowsListener(this)
|
||||
pagerAdapter = SupportTabsAdapter(this, supportFragmentManager, mainTabs)
|
||||
mainPager.adapter = pagerAdapter
|
||||
mainTabs.setViewPager(mainPager)
|
||||
mainTabs.setOnPageChangeListener(this)
|
||||
|
@ -327,10 +328,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
|
||||
override fun onAttachFragment(fragment: Fragment?) {
|
||||
super.onAttachFragment(fragment)
|
||||
// Must exclude fragments not belongs tabs, otherwise it will crash
|
||||
if (fragment !is AccountsDashboardFragment) {
|
||||
updateActionsButton()
|
||||
}
|
||||
updateActionsButton()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
|
@ -800,6 +798,11 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
mainPager.pageMargin = resources.getDimensionPixelOffset(R.dimen.home_page_margin)
|
||||
mainPager.setPageMarginDrawable(ThemeUtils.getDrawableFromThemeAttribute(this, R.attr.dividerVertical))
|
||||
pagerAdapter.hasMultipleColumns = true
|
||||
pagerAdapter.preferredColumnWidth = when (preferences[multiColumnWidthKey]) {
|
||||
"narrow" -> resources.getDimension(R.dimen.preferred_tab_column_width_narrow)
|
||||
"wide" -> resources.getDimension(R.dimen.preferred_tab_column_width_wide)
|
||||
else -> resources.getDimension(R.dimen.preferred_tab_column_width_normal)
|
||||
}
|
||||
mainTabs.columns = Math.floor(1.0 / pagerAdapter.getPageWidth(0)).toInt()
|
||||
} else {
|
||||
mainPager.pageMargin = 0
|
||||
|
@ -850,6 +853,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||
}
|
||||
|
||||
private fun updateActionsButton() {
|
||||
if (!propertiesInitialized) return
|
||||
val fragment = run {
|
||||
if (pagerAdapter.count == 0) return@run null
|
||||
val position = mainPager.currentItem
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.support.v4.app.FragmentManager
|
|||
import android.support.v4.view.PagerAdapter
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface
|
||||
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback
|
||||
import org.mariotaku.twidere.model.SupportTabSpec
|
||||
|
@ -46,6 +45,7 @@ class SupportTabsAdapter @JvmOverloads constructor(
|
|||
) : SupportFixedFragmentStatePagerAdapter(fm), TabProvider, TabListener {
|
||||
|
||||
var hasMultipleColumns: Boolean = false
|
||||
var preferredColumnWidth: Float = 0f
|
||||
|
||||
private val tab = ArrayList<SupportTabSpec>()
|
||||
|
||||
|
@ -54,7 +54,7 @@ class SupportTabsAdapter @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
fun addTab(cls: Class<out Fragment>, args: Bundle? = null, name: String,
|
||||
icon: DrawableHolder? = null, type: String? = null, position: Int = 0, tag: String? = null) {
|
||||
icon: DrawableHolder? = null, type: String? = null, position: Int = 0, tag: String? = null) {
|
||||
addTab(SupportTabSpec(name = name, icon = icon, cls = cls, args = args,
|
||||
position = position, type = type, tag = tag))
|
||||
}
|
||||
|
@ -96,10 +96,9 @@ class SupportTabsAdapter @JvmOverloads constructor(
|
|||
override fun getPageWidth(position: Int): Float {
|
||||
val columnCount = count
|
||||
if (columnCount == 0) return 1f
|
||||
if (hasMultipleColumns) {
|
||||
if (hasMultipleColumns && preferredColumnWidth > 0) {
|
||||
val resources = context.resources
|
||||
val screenWidth = resources.displayMetrics.widthPixels
|
||||
val preferredColumnWidth = resources.getDimension(R.dimen.preferred_tab_column_width)
|
||||
val pageWidth = preferredColumnWidth / screenWidth
|
||||
if (columnCount * preferredColumnWidth < screenWidth) {
|
||||
return 1f / columnCount
|
||||
|
|
|
@ -67,6 +67,7 @@ val autoRefreshCompatibilityModeKey = KBooleanKey("auto_refresh_compatibility_mo
|
|||
val floatingDetailedContentsKey = KBooleanKey("floating_detailed_contents", true)
|
||||
val localTrendsWoeIdKey = KIntKey(KEY_LOCAL_TRENDS_WOEID, 1)
|
||||
val phishingLinksWaringKey = KBooleanKey(KEY_PHISHING_LINK_WARNING, true)
|
||||
val multiColumnWidthKey = KStringKey("multi_column_tab_width", "normal")
|
||||
|
||||
object themeBackgroundAlphaKey : KSimpleKey<Int>(KEY_THEME_BACKGROUND_ALPHA, 0xFF) {
|
||||
override fun read(preferences: SharedPreferences): Int {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<resources>
|
||||
<dimen name="account_selector_popup_width">180dp</dimen>
|
||||
|
||||
|
@ -93,8 +93,11 @@
|
|||
|
||||
<dimen name="popup_width_account_selector">160dp</dimen>
|
||||
|
||||
<!-- Preferred size -->
|
||||
<dimen name="preferred_tab_column_width">420dp</dimen>
|
||||
<!-- Preferred tab column widths -->
|
||||
<eat-comment/>
|
||||
<dimen name="preferred_tab_column_width_narrow">320dp</dimen>
|
||||
<dimen name="preferred_tab_column_width_normal">400dp</dimen>
|
||||
<dimen name="preferred_tab_column_width_wide">480dp</dimen>
|
||||
|
||||
<dimen name="profile_image_size_activity_small">32dp</dimen>
|
||||
<dimen name="profile_image_size_direct_message">36dp</dimen>
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
</org.mariotaku.twidere.preference.TintedPreferenceCategory>
|
||||
<org.mariotaku.twidere.preference.EntrySummaryListPreference
|
||||
android:defaultValue="normal"
|
||||
android:entrieValues="@array/values_tab_column_width"
|
||||
android:entries="@array/entries_tab_column_width"
|
||||
android:entryValues="@array/values_tab_column_width"
|
||||
android:key="multi_column_tab_width"
|
||||
android:title="@string/preference_title_multi_column_tab_width">
|
||||
|
||||
|
|
Loading…
Reference in New Issue