using icon for follow button

This commit is contained in:
Mariotaku Lee 2017-04-07 15:21:56 +08:00
parent 9bfd764f12
commit 97146f213b
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 52 additions and 27 deletions

View File

@ -40,11 +40,15 @@ import android.nfc.NfcAdapter.CreateNdefMessageCallback
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.support.annotation.ColorRes
import android.support.annotation.DrawableRes
import android.support.annotation.StringRes
import android.support.annotation.UiThread
import android.support.v4.app.DialogFragment
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentActivity
import android.support.v4.app.LoaderManager.LoaderCallbacks
import android.support.v4.content.ContextCompat
import android.support.v4.content.FixedAsyncTaskLoader
import android.support.v4.content.Loader
import android.support.v4.content.res.ResourcesCompat
@ -284,7 +288,8 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
return
}
if (user.account_key.maybeEquals(user.key)) {
followContainer.follow.setText(R.string.action_edit)
setFollowEditButton(R.drawable.ic_action_edit, R.color.material_light_blue,
R.string.action_edit)
followContainer.follow.visibility = View.VISIBLE
relationship = userRelationship
return
@ -311,17 +316,21 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
pagesContent.visibility = View.VISIBLE
}
if (userRelationship.blocking) {
followContainer.follow.setText(R.string.action_unblock)
setFollowEditButton(R.drawable.ic_action_block, R.color.material_red,
R.string.action_unblock)
} else if (userRelationship.blocked_by) {
followContainer.follow.setText(R.string.action_block)
setFollowEditButton(R.drawable.ic_action_block, R.color.material_grey,
R.string.action_block)
} else if (userRelationship.following) {
followContainer.follow.setText(R.string.action_unfollow)
setFollowEditButton(R.drawable.ic_action_confirm, R.color.material_light_blue,
R.string.action_unfollow)
} else if (user.is_follow_request_sent) {
followContainer.follow.setText(R.string.requested)
setFollowEditButton(R.drawable.ic_action_time, R.color.material_light_blue,
R.string.label_follow_request_sent)
} else {
followContainer.follow.setText(R.string.action_follow)
setFollowEditButton(R.drawable.ic_action_add, android.R.color.white,
R.string.action_follow)
}
followContainer.follow.compoundDrawablePadding = Math.round(followContainer.follow.textSize * 0.25f)
followingYouIndicator.visibility = if (userRelationship.followed_by) View.VISIBLE else View.GONE
val resolver = context.applicationContext.contentResolver
@ -1529,6 +1538,17 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
updateTitleAlpha()
}
override var controlBarOffset: Float
get() = 0f
set(value) = Unit //Ignore
override val controlBarHeight: Int
get() = 0
override val shouldInitLoader: Boolean
get() = user != null
private fun updateTitleAlpha() {
val location = IntArray(2)
profileNameContainer.name.getLocationInWindow(location)
@ -1544,16 +1564,18 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
}
}
override var controlBarOffset: Float
get() = 0f
set(value) = Unit //Ignore
private fun ParcelableRelationship.check(user: ParcelableUser): Boolean {
if (account_key != user.account_key) {
return false
}
return user.extras != null && TextUtils.equals(user_key.id, user.extras.unique_id) || TextUtils.equals(user_key.id, user.key.id)
}
override val controlBarHeight: Int
get() = 0
override val shouldInitLoader: Boolean
get() = user != null
private fun setFollowEditButton(@DrawableRes icon: Int, @ColorRes color: Int, @StringRes label: Int) {
followContainer.follow.setImageResource(icon)
ViewCompat.setBackgroundTintList(followContainer.follow, ContextCompat.getColorStateList(context, color))
followContainer.follow.contentDescription = getString(label)
}
private class ActionBarDrawable(shadow: Drawable) : LayerDrawable(arrayOf(shadow, ActionBarColorDrawable.create(true))) {
@ -1619,6 +1641,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
}
internal class UserRelationshipLoader(
context: Context,
private val accountKey: UserKey?,
@ -1667,14 +1690,6 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
}
}
private fun ParcelableRelationship.check(user: ParcelableUser): Boolean {
if (account_key != user.account_key) {
return false
}
return user.extras != null && TextUtils.equals(user_key.id, user.extras.unique_id) || TextUtils.equals(user_key.id, user.key.id)
}
class AddRemoveUserListDialogFragment : BaseDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val lists = arguments.getParcelableArray(EXTRA_USER_LISTS).toTypedArray(ParcelableUserList.CREATOR)

View File

@ -1,6 +1,7 @@
package org.mariotaku.twidere.view
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.support.annotation.ColorInt
import android.support.v4.view.ViewCompat
@ -88,6 +89,11 @@ class IconActionButton(
}
}
override fun setBackgroundTintList(tint: ColorStateList?) {
super.setBackgroundTintList(tint)
updateColorFilter()
}
override fun isPostApplyTheme(): Boolean {
return false
}

View File

@ -65,13 +65,17 @@
android:minHeight="@dimen/element_size_normal"
android:minWidth="@dimen/element_size_normal">
<Button
<org.mariotaku.twidere.view.IconActionButton
android:id="@+id/follow"
style="?buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
tools:text="@string/action_follow"
app:iabColor="@android:color/transparent"
tools:backgroundTint="@color/color_stateful_follow"
tools:contentDescription="@string/action_follow"
tools:src="@drawable/ic_action_add"
tools:visibility="visible"/>
<ProgressBar

View File

@ -105,7 +105,6 @@
android:orientation="horizontal"
tools:visibility="visible">
<org.mariotaku.twidere.view.IconActionButton
android:id="@+id/unmute"
style="?buttonStyleSmall"

View File

@ -537,6 +537,7 @@
<string name="label_content_rating_r">R</string>
<string name="label_data_provider">Twidere database provider</string>
<string name="label_filters_subscription">Subscription</string>
<string name="label_follow_request_sent">Follow request sent</string>
<string name="label_format_buffer_time_source"><xliff:g example="12:00, April 1" id="time">%1$s</xliff:g> via <xliff:g example="api" id="source">%2$s</xliff:g></string>
<string name="label_location_coarse">Coarse (City)</string>
<string name="label_location_no_location">None</string>