improved toolbar style for single tab configuration

This commit is contained in:
Mariotaku Lee 2017-10-12 17:28:02 +08:00
parent b464233e0d
commit 04c84eb86f
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
8 changed files with 75 additions and 32 deletions

View File

@ -136,6 +136,9 @@ public class Status {
@JsonField(name = "application")
Application application;
@JsonField(name = "language")
String language;
@JsonField(name = "emojis")
Emoji[] emojis;
@ -222,6 +225,10 @@ public class Status {
return application;
}
public String getLanguage() {
return language;
}
public Emoji[] getEmojis() {
return emojis;
}
@ -264,6 +271,7 @@ public class Status {
", mentions=" + Arrays.toString(mentions) +
", tags=" + Arrays.toString(tags) +
", application=" + application +
", language='" + language + '\'' +
", emojis=" + Arrays.toString(emojis) +
", sortId=" + sortId +
'}';

View File

@ -47,9 +47,11 @@ import android.support.v4.view.WindowInsetsCompat
import android.support.v4.view.unwrapped
import android.support.v4.widget.DrawerLayout
import android.support.v4.widget.DrawerLayoutAccessor
import android.support.v7.app.ActionBar
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatDelegate
import android.support.v7.graphics.drawable.DrawerArrowDrawable
import android.support.v7.widget.TintTypedArray
import android.util.SparseIntArray
import android.view.Gravity
@ -87,6 +89,7 @@ import org.mariotaku.twidere.constant.*
import org.mariotaku.twidere.extension.applyTheme
import org.mariotaku.twidere.extension.model.notificationBuilder
import org.mariotaku.twidere.extension.onShow
import org.mariotaku.twidere.extension.setVisible
import org.mariotaku.twidere.fragment.AccountsDashboardFragment
import org.mariotaku.twidere.fragment.BaseDialogFragment
import org.mariotaku.twidere.fragment.iface.IFloatingActionButtonFragment
@ -128,9 +131,11 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
private var updateUnreadCountTask: UpdateUnreadCountTask? = null
private val readStateChangeListener = OnSharedPreferenceChangeListener { _, _ -> updateUnreadCount() }
private val controlBarShowHideHelper = ControlBarShowHideHelper(this)
private val useTabNavigation get() = pagerAdapter.count > 1
override val controlBarHeight: Int
get() {
if (mainTabsContainer.visibility != View.VISIBLE) return toolbar.height
return mainTabs.height - mainTabs.stripHeight
}
@ -143,13 +148,21 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
private val homeDrawerToggleDelegate = object : ActionBarDrawerToggle.Delegate {
override fun setActionBarUpIndicator(upDrawable: Drawable, @StringRes contentDescRes: Int) {
drawerToggleButton.setImageDrawable(upDrawable)
drawerToggleButton.setColorFilter(ChameleonUtils.getColorDependent(overrideTheme.colorToolbar))
drawerToggleButton.contentDescription = getString(contentDescRes)
if (upDrawable is DrawerArrowDrawable) {
upDrawable.color = ChameleonUtils.getColorDependent(overrideTheme.colorToolbar)
}
if (useTabNavigation) {
drawerToggleButton.setImageDrawable(upDrawable)
drawerToggleButton.contentDescription = getString(contentDescRes)
} else {
supportActionBar?.setHomeAsUpIndicator(upDrawable)
supportActionBar?.setHomeActionContentDescription(contentDescRes)
}
}
override fun setActionBarDescription(@StringRes contentDescRes: Int) {
drawerToggleButton.contentDescription = getString(contentDescRes)
supportActionBar?.setHomeActionContentDescription(contentDescRes)
}
@SuppressLint("RestrictedApi")
@ -166,7 +179,11 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
}
override fun isNavigationVisible(): Boolean {
return true
return if (useTabNavigation) {
drawerToggleButton.visibility == View.VISIBLE
} else {
ActionBar.DISPLAY_HOME_AS_UP in (supportActionBar?.displayOptions ?: 0)
}
}
}
@ -242,12 +259,6 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
mainTabs.setDisplayBadge(preferences[unreadCountKey])
mainTabs.updateAppearance()
if (preferences[drawerToggleKey]) {
drawerToggleButton.visibility = View.VISIBLE
} else {
drawerToggleButton.visibility = View.GONE
}
if (preferences[fabVisibleKey]) {
actionsButton.visibility = View.VISIBLE
} else {
@ -607,6 +618,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
return 1 + toolbar.translationY / totalHeight
}
set(offset) {
if (mainTabsContainer.visibility != View.VISIBLE) return
val translationY = if (mainTabs.columns > 1) 0 else (controlBarHeight * (offset - 1)).toInt()
toolbar.translationY = translationY.toFloat()
windowOverlay.translationY = translationY.toFloat()
@ -638,9 +650,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
}
}
override fun getDrawerToggleDelegate(): ActionBarDrawerToggle.Delegate? {
return homeDrawerToggleDelegate
}
override fun getDrawerToggleDelegate() = homeDrawerToggleDelegate
fun closeAccountsDrawer() {
if (homeMenu == null) return
@ -806,6 +816,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
}
}
@SuppressLint("ResourceType")
private fun setupBars() {
val backgroundOption = currentThemeBackgroundOption
val isTransparent = ThemeUtils.isTransparentBackground(backgroundOption)
@ -815,6 +826,22 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
0xFF
}
actionsButton.alpha = actionBarAlpha / 255f
mainTabsContainer.setVisible(useTabNavigation)
if (useTabNavigation) {
toolbar.setContentInsetsRelative(0, 0)
drawerToggleButton.visibility = if (preferences[drawerToggleKey]) View.VISIBLE else View.GONE
} else {
val attrs = intArrayOf(R.attr.contentInsetStart, R.attr.contentInsetEnd)
val toolbarStyle = obtainStyledAttributes(null, attrs, R.attr.toolbarStyle,
0)
toolbar.setContentInsetsRelative(toolbarStyle.getDimensionPixelSize(0, 0),
toolbarStyle.getDimensionPixelSize(1, 0))
toolbarStyle.recycle()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
}
private fun setupHomeTabs() {
@ -823,7 +850,8 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
val hasNoTab = pagerAdapter.count == 0
emptyTabHint.visibility = if (hasNoTab) View.VISIBLE else View.GONE
mainPager.visibility = if (hasNoTab) View.GONE else View.VISIBLE
if (pagerAdapter.count > 1 && hasMultiColumns()) {
val useTabNavigation = useTabNavigation
if (useTabNavigation && hasMultiColumns()) {
mainPager.pageMargin = resources.getDimensionPixelOffset(R.dimen.home_page_margin)
mainPager.setPageMarginDrawable(ThemeUtils.getDrawableFromThemeAttribute(this, R.attr.dividerVertical))
pagerAdapter.hasMultipleColumns = true

View File

@ -20,17 +20,16 @@
package org.mariotaku.twidere.data
import android.content.ContentResolver
import android.database.ContentObserver
import android.net.Uri
import android.os.Handler
import android.os.Looper
import nl.komponents.kovenant.task
import nl.komponents.kovenant.ui.successUi
import org.mariotaku.ktextension.weak
import org.mariotaku.library.objectcursor.ObjectCursor
import org.mariotaku.twidere.extension.queryReference
/**
* Created by mariotaku on 2017/10/9.
*/
class ObjectCursorLiveData<T>(
val resolver: ContentResolver,
val uri: Uri,
@ -41,11 +40,20 @@ class ObjectCursorLiveData<T>(
val cls: Class<out T>
) : ReloadableLiveData<List<T>?>() {
private val reloadObserver = object : ContentObserver(MainThreadHandler) {
override fun onChange(selfChange: Boolean) {
if (hasActiveObservers()) {
loadData()
}
}
}
override fun onLoadData(callback: (List<T>?) -> Unit) {
val weakThis = weak()
task {
val (c) = resolver.queryReference(uri, projection, selection, selectionArgs) ?:
throw NullPointerException()
c.registerContentObserver(reloadObserver)
val i = ObjectCursor.indicesFrom(c, cls)
return@task ObjectCursor(c, i)
}.successUi { data ->
@ -61,7 +69,11 @@ class ObjectCursorLiveData<T>(
override fun onInactive() {
val oldValue = this.value
if (oldValue is ObjectCursor<*>) {
oldValue.cursor.unregisterContentObserver(reloadObserver)
oldValue.close()
}
value = null
}
object MainThreadHandler : Handler(Looper.getMainLooper())
}

View File

@ -24,20 +24,17 @@ import org.mariotaku.twidere.annotation.FilterScope
import org.mariotaku.twidere.model.refresh.RefreshTaskParam
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
/**
* Created by mariotaku on 2017/10/9.
*/
class HomeTimelineFragment : AbsTimelineFragment<RefreshTaskParam>() {
override val filterScope: Int = FilterScope.HOME
override val contentUri: Uri = Statuses.CONTENT_URI
override fun onCreateRefreshParam(position: Int): RefreshTaskParam {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
return getBaseRefreshTaskParam(this, position)
}
override fun getStatuses(param: RefreshTaskParam): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
if (!param.hasMaxIds) return twitterWrapper.refreshAll(param.accountKeys)
return twitterWrapper.getHomeTimelineAsync(param)
}
}

View File

@ -37,7 +37,7 @@ import org.mariotaku.twidere.model.tab.conf.UserExtraConfiguration
class UserTimelineTabConfiguration : TabConfiguration() {
override val name = StringHolder.resource(R.string.users_statuses)
override val name = StringHolder.resource(R.string.title_user_timeline)
override val icon = DrawableHolder.Builtin.USER

View File

@ -36,9 +36,6 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Statuses
import org.mariotaku.twidere.util.ErrorInfoStore
import org.mariotaku.twidere.util.sync.TimelineSyncManager
/**
* Created by mariotaku on 16/2/11.
*/
class GetHomeTimelineTask(context: Context) : GetStatusesTask<RefreshTaskParam>(context) {
override val contentUri: Uri = Statuses.CONTENT_URI

View File

@ -44,6 +44,7 @@
app:contentInsetStart="0dp">
<LinearLayout
android:id="@+id/mainTabsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

View File

@ -521,6 +521,9 @@
<string name="label_content_rating_r">R</string>
<string name="label_content_warning">Content warning</string>
<string name="label_data_provider">Twidere database provider</string>
<string name="label_drafts_all">All</string>
<string name="label_drafts_others">Others</string>
<string name="label_drafts_statuses">Tweets</string>
<string name="label_feedback_content">Content</string>
<string name="label_feedback_title">Title</string>
<string name="label_filter_apply_to">Apply to…</string>
@ -1277,6 +1280,7 @@
<string name="title_user_list_memberships">Belongs to</string>
<string name="title_user_list_ownerships">Created</string>
<string name="title_user_list_subscriptions">Subscriptions</string>
<string name="title_user_timeline">User timeline</string>
<string name="title_user_timeline_filter">Timeline filter</string>
<string name="title_userlist_subscribers">Subscribers</string>
<string name="title_users_favorited_this">Users favorited this</string>
@ -1363,8 +1367,4 @@
<string name="users_blocked">Blocked these users.</string>
<string name="users_lists_with_name"><xliff:g id="name">%s</xliff:g>\'s lists</string>
<string name="users_statuses">User\'s tweets</string>
<string name="label_drafts_all">All</string>
<string name="label_drafts_statuses">Tweets</string>
<string name="label_drafts_others">Others</string>
</resources>