improved account switch indicator
This commit is contained in:
parent
25a80edb05
commit
b5306d6d25
|
@ -21,6 +21,7 @@ package org.mariotaku.twidere.view;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mariotaku on 15/6/6.
|
* Created by mariotaku on 15/6/6.
|
||||||
|
@ -37,4 +38,25 @@ public class ProfileImageView extends ShapedImageView {
|
||||||
public ProfileImageView(final Context context, final AttributeSet attrs, final int defStyle) {
|
public ProfileImageView(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
|
||||||
|
final int width = MeasureSpec.getSize(widthMeasureSpec), height = MeasureSpec.getSize(heightMeasureSpec);
|
||||||
|
final ViewGroup.LayoutParams lp = getLayoutParams();
|
||||||
|
if (lp.height == ViewGroup.LayoutParams.MATCH_PARENT && lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
||||||
|
super.onMeasure(makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY), makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY));
|
||||||
|
} else if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT && lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
||||||
|
super.onMeasure(makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY), makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY));
|
||||||
|
} else {
|
||||||
|
if (width > height) {
|
||||||
|
super.onMeasure(makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY), makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY));
|
||||||
|
} else {
|
||||||
|
super.onMeasure(makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY), makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int makeSpec(int spec, int mode) {
|
||||||
|
return MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(spec), mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,8 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||||
|
|
||||||
private var accountsAdapter: AccountSelectorAdapter? = null
|
private var accountsAdapter: AccountSelectorAdapter? = null
|
||||||
|
|
||||||
|
private val hasNextAccountIndicator by lazy { accountsHeader.hasNextAccountIndicator }
|
||||||
|
private val hasPrevAccountIndicator by lazy { accountsHeader.hasPrevAccountIndicator }
|
||||||
private val accountsSelector by lazy { accountsHeader.otherAccountsList }
|
private val accountsSelector by lazy { accountsHeader.otherAccountsList }
|
||||||
private val navigationView by lazy { view as NavigationView }
|
private val navigationView by lazy { view as NavigationView }
|
||||||
private val accountsHeader by lazy { navigationView.getHeaderView(0) }
|
private val accountsHeader by lazy { navigationView.getHeaderView(0) }
|
||||||
|
@ -112,6 +114,15 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
|
||||||
layoutManager.orientation = LinearLayoutManager.HORIZONTAL
|
layoutManager.orientation = LinearLayoutManager.HORIZONTAL
|
||||||
layoutManager.stackFromEnd = true
|
layoutManager.stackFromEnd = true
|
||||||
accountsSelector.adapter = accountsAdapter
|
accountsSelector.adapter = accountsAdapter
|
||||||
|
accountsSelector.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
|
||||||
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
|
val adapter = accountsAdapter ?: return
|
||||||
|
val pagePosition = position + positionOffset
|
||||||
|
hasPrevAccountIndicator.alpha = TwidereMathUtils.clamp(pagePosition, 0f, 1f)
|
||||||
|
hasNextAccountIndicator.alpha = TwidereMathUtils.clamp(adapter.count - (pagePosition
|
||||||
|
+ 1 / adapter.getPageWidth(position)), 0f, 1f)
|
||||||
|
}
|
||||||
|
})
|
||||||
accountsSelector.setPageTransformer(false, AccountsSelectorTransformer)
|
accountsSelector.setPageTransformer(false, AccountsSelectorTransformer)
|
||||||
val menuInflater = SupportMenuInflater(context)
|
val menuInflater = SupportMenuInflater(context)
|
||||||
menuInflater.inflate(R.menu.action_dashboard_timeline_toggle, accountDashboardMenu.menu)
|
menuInflater.inflate(R.menu.action_dashboard_timeline_toggle, accountDashboardMenu.menu)
|
||||||
|
|
|
@ -17,22 +17,23 @@
|
||||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<org.mariotaku.twidere.view.SquareFrameLayout
|
<FrameLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:padding="@dimen/element_spacing_msmall"
|
android:padding="@dimen/element_spacing_small"
|
||||||
tools:layout_height="48dp">
|
tools:layout_height="48dp">
|
||||||
|
|
||||||
<org.mariotaku.twidere.view.ProfileImageView
|
<org.mariotaku.twidere.view.ProfileImageView
|
||||||
android:id="@android:id/icon"
|
android:id="@android:id/icon"
|
||||||
style="?profileImageStyle"
|
style="?profileImageStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
app:sivBorder="true"
|
app:sivBorder="true"
|
||||||
app:sivBorderWidth="1.5dp"
|
app:sivBorderWidth="1.5dp"
|
||||||
tools:src="@mipmap/ic_launcher"/>
|
tools:src="@mipmap/ic_launcher"/>
|
||||||
|
|
||||||
</org.mariotaku.twidere.view.SquareFrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
@ -52,8 +52,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
android:paddingBottom="@dimen/element_spacing_normal"
|
android:paddingBottom="@dimen/element_spacing_normal"
|
||||||
android:paddingLeft="@dimen/element_spacing_large"
|
|
||||||
android:paddingRight="@dimen/element_spacing_large"
|
|
||||||
android:paddingTop="@dimen/element_spacing_normal">
|
android:paddingTop="@dimen/element_spacing_normal">
|
||||||
|
|
||||||
<org.mariotaku.twidere.view.ProfileImageView
|
<org.mariotaku.twidere.view.ProfileImageView
|
||||||
|
@ -62,6 +60,8 @@
|
||||||
android:layout_width="@dimen/icon_size_profile_image_dashboard_current"
|
android:layout_width="@dimen/icon_size_profile_image_dashboard_current"
|
||||||
android:layout_height="@dimen/icon_size_profile_image_dashboard_current"
|
android:layout_height="@dimen/icon_size_profile_image_dashboard_current"
|
||||||
android:layout_marginBottom="@dimen/element_spacing_mlarge"
|
android:layout_marginBottom="@dimen/element_spacing_mlarge"
|
||||||
|
android:layout_marginLeft="@dimen/element_spacing_large"
|
||||||
|
android:layout_marginStart="@dimen/element_spacing_large"
|
||||||
android:layout_marginTop="@dimen/element_spacing_mlarge"
|
android:layout_marginTop="@dimen/element_spacing_mlarge"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
app:sivBorder="true"
|
app:sivBorder="true"
|
||||||
|
@ -73,24 +73,50 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignBottom="@id/profileImage"
|
android:layout_alignBottom="@id/profileImage"
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignTop="@id/profileImage"
|
android:layout_alignTop="@id/profileImage"
|
||||||
android:layout_marginBottom="@dimen/element_spacing_large"
|
android:layout_marginBottom="@dimen/element_spacing_large"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_toEndOf="@+id/hasPrevAccountIndicator"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_toLeftOf="@+id/hasNextAccountIndicator"
|
||||||
android:layout_toEndOf="@id/profileImage"
|
android:layout_toRightOf="@+id/hasPrevAccountIndicator"
|
||||||
android:layout_toRightOf="@id/profileImage"
|
android:layout_toStartOf="@+id/hasNextAccountIndicator"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
tools:listitem="@layout/adapter_item_dashboard_account"
|
tools:listitem="@layout/adapter_item_dashboard_account"
|
||||||
tools:paddingStart="@dimen/element_spacing_large"
|
tools:paddingStart="@dimen/element_spacing_large"
|
||||||
tools:visibility="visible"/>
|
tools:visibility="visible"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/hasNextAccountIndicator"
|
||||||
|
android:layout_width="@dimen/element_spacing_large"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@+id/otherAccountsList"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignTop="@+id/otherAccountsList"
|
||||||
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
android:src="@drawable/ic_indicator_arrow_next"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/hasPrevAccountIndicator"
|
||||||
|
android:layout_width="@dimen/element_spacing_large"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@+id/otherAccountsList"
|
||||||
|
android:layout_alignTop="@+id/otherAccountsList"
|
||||||
|
android:layout_toEndOf="@id/profileImage"
|
||||||
|
android:layout_toRightOf="@id/profileImage"
|
||||||
|
android:background="?selectableItemBackgroundBorderless"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
android:src="@drawable/ic_indicator_arrow_prev"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_below="@id/profileImage"
|
android:layout_below="@id/profileImage"
|
||||||
|
android:layout_marginEnd="@dimen/element_spacing_large"
|
||||||
|
android:layout_marginLeft="@dimen/element_spacing_large"
|
||||||
|
android:layout_marginRight="@dimen/element_spacing_large"
|
||||||
|
android:layout_marginStart="@dimen/element_spacing_large"
|
||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
|
@ -108,7 +134,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
android:singleLine="true"
|
android:maxLines="1"
|
||||||
android:textAppearance="?android:textAppearanceSmall"
|
android:textAppearance="?android:textAppearanceSmall"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
@ -119,7 +145,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
android:singleLine="true"
|
android:maxLines="1"
|
||||||
android:textAppearance="?android:textAppearanceSmall"
|
android:textAppearance="?android:textAppearanceSmall"
|
||||||
android:textColor="@color/material_grey"
|
android:textColor="@color/material_grey"
|
||||||
tools:text="\@username"/>
|
tools:text="\@username"/>
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg width="12px" height="24px" viewBox="0 0 12 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<!-- Generator: Sketch 41.2 (35397) - http://www.bohemiancoding.com/sketch -->
|
||||||
|
<title>ic_indicator_arrow_next</title>
|
||||||
|
<desc>Created with Sketch.</desc>
|
||||||
|
<defs></defs>
|
||||||
|
<g id="Miscellaneous" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||||
|
<g id="ic_indicator_arrow_next">
|
||||||
|
<polygon id="Shape" fill="#FFFFFF" points="3.99999991 6 2.58999991 7.41 7.16999991 12 2.58999991 16.59 3.99999991 18 9.99999991 12"></polygon>
|
||||||
|
<polygon id="Shape" points="0 0 24 0 24 24 0 24"></polygon>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 752 B |
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg width="12px" height="24px" viewBox="0 0 12 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<!-- Generator: Sketch 41.2 (35397) - http://www.bohemiancoding.com/sketch -->
|
||||||
|
<title>ic_indicator_arrow_prev</title>
|
||||||
|
<desc>Created with Sketch.</desc>
|
||||||
|
<defs></defs>
|
||||||
|
<g id="Miscellaneous" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||||
|
<g id="ic_indicator_arrow_prev">
|
||||||
|
<polygon id="Shape" fill="#FFFFFF" points="9.41 7.41 8 6 2 12 8 18 9.41 16.59 4.83 12"></polygon>
|
||||||
|
<polygon id="Shape" points="0 0 24 0 24 24 0 24"></polygon>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 707 B |
Loading…
Reference in New Issue