added retweet state for status details
This commit is contained in:
parent
a6a18fb99c
commit
9f24304b0a
|
@ -30,6 +30,7 @@ import org.mariotaku.twidere.util.menu.TwidereMenuInfo;
|
|||
/**
|
||||
* Created by mariotaku on 15/1/16.
|
||||
*/
|
||||
@SuppressWarnings("RestrictedApi")
|
||||
public class ActionIconDrawable extends DrawableWrapper implements TwidereActionMenuItemView.IgnoreTinting {
|
||||
|
||||
private int mDefaultColor;
|
||||
|
|
|
@ -19,10 +19,15 @@
|
|||
|
||||
package org.mariotaku.ktextension
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.support.annotation.DrawableRes
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.view.MenuItemCompat
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.SubMenu
|
||||
import org.mariotaku.twidere.graphic.ActionIconDrawable
|
||||
|
||||
fun Menu.setItemAvailability(id: Int, available: Boolean) {
|
||||
val item = findItem(id) ?: return
|
||||
|
@ -64,3 +69,14 @@ fun Menu.setMenuItemShowAsActionFlags(id: Int, flags: Int) {
|
|||
fun Menu.findSubmenu(id: Int): SubMenu? {
|
||||
return findItem(id)?.subMenu
|
||||
}
|
||||
|
||||
|
||||
fun MenuItem.setActionIcon(context: Context, @DrawableRes iconRes: Int) {
|
||||
val oldIcon = this.icon
|
||||
if (oldIcon is ActionIconDrawable) {
|
||||
val starIcon = ContextCompat.getDrawable(context, iconRes)
|
||||
this.icon = ActionIconDrawable(starIcon, oldIcon.defaultColor)
|
||||
} else {
|
||||
setIcon(iconRes)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,9 @@ import android.widget.Toast
|
|||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.Bundle
|
||||
import org.mariotaku.ktextension.set
|
||||
import org.mariotaku.ktextension.setActionIcon
|
||||
import org.mariotaku.ktextension.setItemAvailability
|
||||
import org.mariotaku.microblog.library.mastodon.annotation.StatusVisibility
|
||||
import org.mariotaku.twidere.Constants.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.activity.AccountSelectorActivity
|
||||
|
@ -141,8 +143,26 @@ object MenuUtils {
|
|||
}
|
||||
val retweet = menu.findItem(R.id.retweet)
|
||||
if (retweet != null) {
|
||||
ActionIconDrawable.setMenuHighlight(retweet, TwidereMenuInfo(isMyRetweet, retweetHighlight))
|
||||
|
||||
when (status.extras?.visibility) {
|
||||
StatusVisibility.PRIVATE -> {
|
||||
retweet.isEnabled = false
|
||||
retweet.setActionIcon(context, R.drawable.ic_action_lock)
|
||||
}
|
||||
StatusVisibility.DIRECT -> {
|
||||
retweet.isEnabled = false
|
||||
retweet.setActionIcon(context, R.drawable.ic_action_message)
|
||||
retweet.setIcon(R.drawable.ic_action_message)
|
||||
}
|
||||
else -> {
|
||||
retweet.isEnabled = true
|
||||
retweet.setActionIcon(context, R.drawable.ic_action_retweet)
|
||||
}
|
||||
}
|
||||
|
||||
retweet.setTitle(if (isMyRetweet) R.string.action_cancel_retweet else R.string.action_retweet)
|
||||
|
||||
ActionIconDrawable.setMenuHighlight(retweet, TwidereMenuInfo(isMyRetweet, retweetHighlight))
|
||||
}
|
||||
val favorite = menu.findItem(R.id.favorite)
|
||||
if (favorite != null) {
|
||||
|
@ -160,13 +180,7 @@ object MenuUtils {
|
|||
provider.setIsFavorite(favorite, isFavorite)
|
||||
} else {
|
||||
if (useStar) {
|
||||
val oldIcon = favorite.icon
|
||||
if (oldIcon is ActionIconDrawable) {
|
||||
val starIcon = ContextCompat.getDrawable(context, R.drawable.ic_action_star)
|
||||
favorite.icon = ActionIconDrawable(starIcon, oldIcon.defaultColor)
|
||||
} else {
|
||||
favorite.setIcon(R.drawable.ic_action_star)
|
||||
}
|
||||
favorite.setActionIcon(context, R.drawable.ic_action_star)
|
||||
ActionIconDrawable.setMenuHighlight(favorite, TwidereMenuInfo(isFavorite, favoriteHighlight))
|
||||
} else {
|
||||
ActionIconDrawable.setMenuHighlight(favorite, TwidereMenuInfo(isFavorite, likeHighlight))
|
||||
|
@ -411,3 +425,4 @@ object MenuUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue