1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-08 15:58:40 +01:00

improved refresh indicator position

This commit is contained in:
Mariotaku Lee 2017-09-01 18:17:01 +08:00
parent b0b4855803
commit 8a2dfc5778
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
2 changed files with 27 additions and 14 deletions

View File

@ -308,19 +308,15 @@ abstract class AbsContentRecyclerViewFragment<A : LoadMoreSupportAdapter<Recycle
} }
protected fun updateRefreshProgressOffset() { protected fun updateRefreshProgressOffset() {
val activity = activity
val insets = this.systemWindowsInsets val insets = this.systemWindowsInsets
if (activity !is IControlBarActivity || insets.top == 0 || swipeLayout == null || refreshing) { if (insets.top == 0 || swipeLayout == null || swipeLayout.isRefreshing) {
return return
} }
val progressCircleDiameter = swipeLayout.progressCircleDiameter val progressCircleDiameter = swipeLayout.progressCircleDiameter
if (progressCircleDiameter == 0) return if (progressCircleDiameter == 0) return
val density = resources.displayMetrics.density val progressViewStart = 0 - progressCircleDiameter
val controlBarOffsetPixels = Math.round(activity.controlBarHeight * (1 - activity.controlBarOffset)) val progressViewEnd = insets.top + resources.getDimensionPixelSize(R.dimen.element_spacing_normal)
val swipeStart = insets.top - controlBarOffsetPixels - progressCircleDiameter swipeLayout.setProgressViewOffset(false, progressViewStart, progressViewEnd)
// 64: SwipeRefreshLayout.DEFAULT_CIRCLE_TARGET
val swipeDistance = Math.round(64 * density)
swipeLayout.setProgressViewOffset(false, swipeStart, swipeStart + swipeDistance)
} }
interface RefreshCompleteListener { interface RefreshCompleteListener {

View File

@ -170,8 +170,10 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
private set private set
private var account: AccountDetails? = null private var account: AccountDetails? = null
private var relationship: ParcelableRelationship? = null private var relationship: ParcelableRelationship? = null
private var getUserInfoLoaderInitialized: Boolean = false
private var getFriendShipLoaderInitialized: Boolean = false private var systemWindowsInsets: Rect = Rect()
private var userInfoLoaderInitialized: Boolean = false
private var friendShipLoaderInitialized: Boolean = false
private var bannerWidth: Int = 0 private var bannerWidth: Int = 0
private var cardBackgroundColor: Int = 0 private var cardBackgroundColor: Int = 0
private var actionBarShadowColor: Int = 0 private var actionBarShadowColor: Int = 0
@ -571,9 +573,9 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
args.putParcelable(EXTRA_USER_KEY, userKey) args.putParcelable(EXTRA_USER_KEY, userKey)
args.putString(EXTRA_SCREEN_NAME, screenName) args.putString(EXTRA_SCREEN_NAME, screenName)
args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, omitIntentExtra) args.putBoolean(EXTRA_OMIT_INTENT_EXTRA, omitIntentExtra)
if (!getUserInfoLoaderInitialized) { if (!userInfoLoaderInitialized) {
lm.initLoader(LOADER_ID_USER, args, userInfoLoaderCallbacks) lm.initLoader(LOADER_ID_USER, args, userInfoLoaderCallbacks)
getUserInfoLoaderInitialized = true userInfoLoaderInitialized = true
} else { } else {
lm.restartLoader(LOADER_ID_USER, args, userInfoLoaderCallbacks) lm.restartLoader(LOADER_ID_USER, args, userInfoLoaderCallbacks)
} }
@ -676,6 +678,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
userFragmentView.windowInsetsListener = OnApplyWindowInsetsListener listener@ { _, insets -> userFragmentView.windowInsetsListener = OnApplyWindowInsetsListener listener@ { _, insets ->
insets.getSystemWindowInsets(systemWindowsInsets)
val top = insets.systemWindowInsetTop val top = insets.systemWindowInsetTop
profileContentContainer.setPadding(0, top, 0, 0) profileContentContainer.setPadding(0, top, 0, 0)
profileBannerSpace.statusBarHeight = top profileBannerSpace.statusBarHeight = top
@ -687,6 +690,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
} }
profileBannerSpace.toolbarHeight = toolbarHeight profileBannerSpace.toolbarHeight = toolbarHeight
} }
updateRefreshProgressOffset()
return@listener insets return@listener insets
} }
@ -1342,6 +1346,19 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
userProfileSwipeLayout.isRefreshing = false userProfileSwipeLayout.isRefreshing = false
} }
private fun updateRefreshProgressOffset() {
val insets = this.systemWindowsInsets
if (insets.top == 0 || userProfileSwipeLayout == null || userProfileSwipeLayout.isRefreshing) {
return
}
val progressCircleDiameter = userProfileSwipeLayout.progressCircleDiameter
if (progressCircleDiameter == 0) return
val progressViewStart = 0 - progressCircleDiameter
val progressViewEnd = profileBannerSpace.toolbarHeight + resources.getDimensionPixelSize(R.dimen.element_spacing_normal)
userProfileSwipeLayout.setProgressViewOffset(false, progressViewStart, progressViewEnd)
}
private fun getFriendship() { private fun getFriendship() {
val user = user ?: return val user = user ?: return
relationship = null relationship = null
@ -1350,9 +1367,9 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
val args = Bundle() val args = Bundle()
args.putParcelable(EXTRA_ACCOUNT_KEY, user.account_key) args.putParcelable(EXTRA_ACCOUNT_KEY, user.account_key)
args.putParcelable(EXTRA_USER, user) args.putParcelable(EXTRA_USER, user)
if (!getFriendShipLoaderInitialized) { if (!friendShipLoaderInitialized) {
lm.initLoader(LOADER_ID_FRIENDSHIP, args, friendshipLoaderCallbacks) lm.initLoader(LOADER_ID_FRIENDSHIP, args, friendshipLoaderCallbacks)
getFriendShipLoaderInitialized = true friendShipLoaderInitialized = true
} else { } else {
lm.restartLoader(LOADER_ID_FRIENDSHIP, args, friendshipLoaderCallbacks) lm.restartLoader(LOADER_ID_FRIENDSHIP, args, friendshipLoaderCallbacks)
} }