improved quote status dialog

improved retweet icon state
This commit is contained in:
Mariotaku Lee 2017-05-17 16:11:32 +08:00
parent 9f24304b0a
commit a5303a2e01
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
33 changed files with 76 additions and 75 deletions

View File

@ -1,8 +1,10 @@
package org.mariotaku.twidere.extension.model
import org.mariotaku.ktextension.addAllTo
import org.mariotaku.microblog.library.mastodon.annotation.StatusVisibility
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.util.UriUtils
import org.mariotaku.twidere.util.Utils
val ParcelableStatus.originalId: String
@ -62,6 +64,19 @@ inline val ParcelableStatus.quoted_user_acct: String? get() = if (account_key.ho
"$quoted_user_screen_name@${quoted_user_key?.host}"
}
inline val ParcelableStatus.is_my_retweet: Boolean
get() = Utils.isMyRetweet(account_key, retweeted_by_user_key, my_retweet_id)
inline val ParcelableStatus.can_retweet: Boolean
get() {
if (user_is_protected) return false
return when (extras?.visibility) {
StatusVisibility.PRIVATE -> false
StatusVisibility.DIRECT -> false
else -> true
}
}
fun ParcelableStatus.toSummaryLine(): ParcelableActivity.SummaryLine {
val result = ParcelableActivity.SummaryLine()
result.key = user_key

View File

@ -139,7 +139,7 @@ abstract class AbsStatusDialogFragment : BaseDialogFragment() {
protected abstract fun Builder.setupAlertDialog()
protected abstract fun AlertDialog.onStatusLoaded(details: AccountDetails, status: ParcelableStatus,
protected abstract fun AlertDialog.onStatusLoaded(account: AccountDetails, status: ParcelableStatus,
savedInstanceState: Bundle?)
companion object {

View File

@ -57,7 +57,7 @@ class FavoriteConfirmDialogFragment : AbsStatusDialogFragment() {
setNegativeButton(android.R.string.cancel, null)
}
override fun AlertDialog.onStatusLoaded(details: AccountDetails, status: ParcelableStatus,
override fun AlertDialog.onStatusLoaded(account: AccountDetails, status: ParcelableStatus,
savedInstanceState: Bundle?) {
val positiveButton = getButton(BUTTON_POSITIVE)
if (preferences[iWantMyStarsBackKey]) {

View File

@ -42,16 +42,16 @@ import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.constant.IntentConstants.*
import org.mariotaku.twidere.constant.quickSendKey
import org.mariotaku.twidere.extension.applyTheme
import org.mariotaku.twidere.extension.model.can_retweet
import org.mariotaku.twidere.extension.model.is_my_retweet
import org.mariotaku.twidere.extension.model.textLimit
import org.mariotaku.twidere.fragment.BaseDialogFragment
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.draft.QuoteStatusActionExtras
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts
import org.mariotaku.twidere.service.LengthyOperationsService
import org.mariotaku.twidere.util.Analyzer
import org.mariotaku.twidere.util.EditTextEnterHandler
import org.mariotaku.twidere.util.LinkCreator
import org.mariotaku.twidere.util.Utils.isMyRetweet
import org.mariotaku.twidere.util.view.SimpleTextWatcher
import org.mariotaku.twidere.view.ComposeEditText
import org.mariotaku.twidere.view.StatusTextCountView
@ -82,14 +82,14 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
setNeutralButton(R.string.action_quote, null)
}
override fun AlertDialog.onStatusLoaded(details: AccountDetails, status: ParcelableStatus,
override fun AlertDialog.onStatusLoaded(account: AccountDetails, status: ParcelableStatus,
savedInstanceState: Bundle?) {
textCountView.maxLength = details.textLimit
textCountView.maxLength = account.textLimit
val useQuote = useQuote(!status.user_is_protected, details)
val canQuoteRetweet = canQuoteRetweet(account)
commentContainer.visibility = if (useQuote) View.VISIBLE else View.GONE
editComment.account = details
commentContainer.visibility = if (canQuoteRetweet) View.VISIBLE else View.GONE
editComment.account = account
val enterHandler = EditTextEnterHandler.attach(editComment, object : EditTextEnterHandler.EnterListener {
override fun shouldCallListener(): Boolean {
@ -97,7 +97,7 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
}
override fun onHitEnter(): Boolean {
if (retweetOrQuote(details, status, showProtectedConfirm)) {
if (retweetOrQuote(account, status, showProtectedConfirm)) {
dismiss()
return true
}
@ -107,7 +107,7 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
enterHandler.addTextChangedListener(object : SimpleTextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
updateTextCount(dialog, s, status, details)
dialog.updateTextCount(s, status, account)
}
})
@ -118,18 +118,10 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
}
getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener {
var dismissDialog = false
if (editComment.length() > 0) {
dismissDialog = retweetOrQuote(details, status, showProtectedConfirm)
} else if (isMyRetweet(status)) {
twitterWrapper.cancelRetweetAsync(details.key, status.id, status.my_retweet_id)
dismissDialog = true
} else if (useQuote(!status.user_is_protected, details)) {
dismissDialog = retweetOrQuote(details, status, showProtectedConfirm)
} else {
Analyzer.logException(IllegalStateException(status.toString()))
}
if (dismissDialog) {
if (status.is_my_retweet) {
twitterWrapper.cancelRetweetAsync(account.key, status.id, status.my_retweet_id)
dismiss()
} else if (retweetOrQuote(account, status, showProtectedConfirm)) {
dismiss()
}
}
@ -146,7 +138,7 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
}
editComment.setSelection(editComment.length())
updateTextCount(dialog, editComment.text, status, details)
dialog.updateTextCount(editComment.text, status, account)
}
override fun onCancel(dialog: DialogInterface?) {
@ -169,24 +161,24 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
}
}
private fun updateTextCount(dialog: DialogInterface, s: CharSequence, status: ParcelableStatus,
credentials: AccountDetails) {
if (dialog !is AlertDialog) return
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE) ?: return
if (s.isNotEmpty()) {
positiveButton.setText(R.string.comment)
positiveButton.isEnabled = true
} else if (isMyRetweet(status)) {
private fun DialogInterface.updateTextCount(s: CharSequence, status: ParcelableStatus, account: AccountDetails) {
if (this !is AlertDialog) return
val positiveButton = getButton(AlertDialog.BUTTON_POSITIVE) ?: return
if (status.is_my_retweet) {
positiveButton.setText(R.string.action_cancel_retweet)
positiveButton.isEnabled = true
} else if (useQuote(false, credentials)) {
positiveButton.setText(R.string.action_retweet)
} else if (canQuoteRetweet(account)) {
if (editComment.empty) {
positiveButton.setText(R.string.action_retweet)
} else {
positiveButton.setText(R.string.action_comment)
}
positiveButton.isEnabled = true
} else {
positiveButton.setText(R.string.action_retweet)
positiveButton.isEnabled = !status.user_is_protected
positiveButton.isEnabled = status.can_retweet
}
val textCountView = dialog.findViewById(R.id.commentTextCount) as StatusTextCountView
textCountView.textCount = validator.getTweetLength(s.toString())
}
@ -196,7 +188,7 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
val twitter = twitterWrapper
val dialog = dialog ?: return false
val editComment = dialog.findViewById(R.id.editComment) as EditText
if (useQuote(editComment.length() > 0, account)) {
if (canQuoteRetweet(account) && !editComment.empty) {
val quoteOriginalStatus = dialog.quoteOriginal.isChecked
var commentText: String
@ -250,8 +242,11 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() {
return true
}
private fun useQuote(preCondition: Boolean, account: AccountDetails): Boolean {
return preCondition || AccountType.FANFOU == account.type
private fun canQuoteRetweet(account: AccountDetails): Boolean {
return when (account.type) {
AccountType.FANFOU, AccountType.TWITTER -> true
else -> false
}
}
private fun Dialog.saveToDrafts() {

View File

@ -146,16 +146,13 @@ object MenuUtils {
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)
}
}

View File

@ -397,19 +397,13 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
when (status.extras?.visibility) {
StatusVisibility.PRIVATE -> {
retweetButton.isEnabled = false
retweetIcon.setImageResource(R.drawable.ic_action_lock)
retweetIcon.isEnabled = false
}
StatusVisibility.DIRECT -> {
retweetButton.isEnabled = false
retweetIcon.setImageResource(R.drawable.ic_action_message)
retweetIcon.isEnabled = false
}
else -> {
retweetButton.isEnabled = true
retweetIcon.setImageResource(R.drawable.ic_action_retweet)
retweetIcon.isEnabled = true
}
}

View File

@ -137,7 +137,7 @@
<string name="click_item_to_configure">اضغط على المحتوى للتكوين</string>
<string name="close_accounts_dashboard">إغلاق لوحة الحسابات</string>
<string name="color">اللون</string>
<string name="comment">تعليق</string>
<string name="action_comment">تعليق</string>
<string name="compact_cards">بطاقات مختصرة</string>
<string name="compact_cards_summary">عرض بطاقات أكثر على الشاشة</string>
<string name="compose_now">اكتب الان</string>

View File

@ -202,7 +202,7 @@
<string name="combined_notifications">Avisos combinaos</string>
<string name="combined_notifications_summary_off">Los avisos amosaránse de mou separtáu</string>
<string name="combined_notifications_summary_on">Agruparánse los avisos</string>
<string name="comment">Comentar</string>
<string name="action_comment">Comentar</string>
<string name="comment_hint">Comentariu&#8230;</string>
<string name="compact_cards">Tarxetes compautes</string>
<string name="compact_cards_summary">Amuesa más tarxetes na pantalla</string>

View File

@ -116,7 +116,7 @@
<string name="combined_notifications">Notificacions combinades</string>
<string name="combined_notifications_summary_off">Les notificacions es mostraran per separat</string>
<string name="combined_notifications_summary_on">Els notificacions es mostraran agrupades</string>
<string name="comment">Comentari</string>
<string name="action_comment">Comentari</string>
<string name="comment_hint">Comentari&#8230;</string>
<string name="compact_cards">Targetes més compactes</string>
<string name="compact_cards_summary">Fa que es vegin més piulades per pàgina</string>

View File

@ -205,7 +205,7 @@
<string name="combined_notifications">Kombinierte Benachrichtigungen</string>
<string name="combined_notifications_summary_off">Benachrichtigungen werden getrennt angezeigt</string>
<string name="combined_notifications_summary_on">Benachrichtigungen werden zusammengefasst</string>
<string name="comment">Kommentar</string>
<string name="action_comment">Kommentar</string>
<string name="comment_hint">Kommentar&#8230;</string>
<string name="compact_cards">Kompakte Karten</string>
<string name="compact_cards_summary">Mehr Karten anzeigen</string>

View File

@ -206,7 +206,7 @@
<string name="combined_notifications">Notificaciones combinadas</string>
<string name="combined_notifications_summary_off">Las notificaciones serán mostradas por separado</string>
<string name="combined_notifications_summary_on">Las notificaciones estarán agrupadas</string>
<string name="comment">Comentario</string>
<string name="action_comment">Comentario</string>
<string name="comment_hint">Comentario&#8230;</string>
<string name="compact_cards">Compactar tarjetas</string>
<string name="compact_cards_summary">Visualizar más tarjetas en pantalla</string>

View File

@ -203,7 +203,7 @@
<string name="combined_notifications">آگهی‌های ترکیبی</string>
<string name="combined_notifications_summary_off">آگهی‌ها به صورت تکی نمایش داده خواهند شد</string>
<string name="combined_notifications_summary_on">آگهی‌ها دسته‌بندی خواهند شد</string>
<string name="comment">نظر</string>
<string name="action_comment">نظر</string>
<string name="comment_hint">نظر&#8230;</string>
<string name="compact_cards">کارت‌های فشرده</string>
<string name="compact_cards_summary">نمایش کارت‌های بیش‌تر روی صفحه</string>

View File

@ -116,7 +116,7 @@
<string name="combined_notifications">Yhdistetyt ilmoitukset</string>
<string name="combined_notifications_summary_off">Ilmoitukset esitetään erillään</string>
<string name="combined_notifications_summary_on">Ilmoitukset ryhmitellään</string>
<string name="comment">Kommentti</string>
<string name="action_comment">Kommentti</string>
<string name="comment_hint">Kommentti&#8230;</string>
<string name="compact_cards">Tiiviit kortit</string>
<string name="compact_cards_summary">Näytä ruudulla enemmän kortteja</string>

View File

@ -205,7 +205,7 @@
<string name="combined_notifications">Notifications combinées</string>
<string name="combined_notifications_summary_off">Les notifications seront affichées séparément</string>
<string name="combined_notifications_summary_on">Les notifications seront groupées</string>
<string name="comment">Commenter</string>
<string name="action_comment">Commenter</string>
<string name="comment_hint">Commenter&#8230;</string>
<string name="compact_cards">Cartes compactes</string>
<string name="compact_cards_summary">Afficher plus de cartes à l\'écran</string>

View File

@ -206,7 +206,7 @@
<string name="combined_notifications">Notificacións combinadas</string>
<string name="combined_notifications_summary_off">As notificacións amosaranse separadamente</string>
<string name="combined_notifications_summary_on">Agruparanse as notificacións</string>
<string name="comment">Comentar</string>
<string name="action_comment">Comentar</string>
<string name="comment_hint">Comentar&#8230;</string>
<string name="compact_cards">Compactar cartóns</string>
<string name="compact_cards_summary">Amosa máis cartóns na pantalla</string>

View File

@ -99,7 +99,7 @@
<string name="clear_databases_summary">Očisti sve tweetove, profile, poruke. Podaci o vašem računu neće biti izgubljeni.</string>
<string name="clear_search_history">Očisti povijest pretraživanja</string>
<string name="color">Boja</string>
<string name="comment">Komentirat</string>
<string name="action_comment">Komentirat</string>
<string name="comment_hint">Komentiraj&#8230;</string>
<string name="compact_cards">Kompaktne kartice</string>
<string name="compact_cards_summary">Prikaži više kartice na zaslonu</string>

View File

@ -128,7 +128,7 @@
<string name="combined_notifications">Egyesített értesítések</string>
<string name="combined_notifications_summary_off">Elkülönítve jelennek meg az értesítések</string>
<string name="combined_notifications_summary_on">Csoportosítva jelennek meg az értesítések</string>
<string name="comment">Megjegyzés</string>
<string name="action_comment">Megjegyzés</string>
<string name="comment_hint">Megjegyzés&#8230;</string>
<string name="compact_cards">Kompakt kártyák</string>
<string name="compact_cards_summary">Több kártya megjelenítése a képernyőn</string>

View File

@ -179,7 +179,7 @@
<string name="combined_notifications">Notifikasi digabungkan</string>
<string name="combined_notifications_summary_off">Notifikasi akan ditampilkan terpisah</string>
<string name="combined_notifications_summary_on">Notifikasi akan digrupkan</string>
<string name="comment">Komentar</string>
<string name="action_comment">Komentar</string>
<string name="comment_hint">Komentar...</string>
<string name="compact_cards">Kartu compact</string>
<string name="compact_cards_summary">Tampilkan kartu lebih banyak</string>

View File

@ -113,7 +113,7 @@
<string name="combined_notifications">Notifiche raggruppate</string>
<string name="combined_notifications_summary_off">Le notifiche saranno mostrate separatamente</string>
<string name="combined_notifications_summary_on">Le notifiche saranno raggruppate</string>
<string name="comment">Commenta</string>
<string name="action_comment">Commenta</string>
<string name="comment_hint">Commento&#8230;</string>
<string name="compact_cards">Schede compatte</string>
<string name="compact_cards_summary">Visualizza più schede sullo schermo</string>

View File

@ -206,7 +206,7 @@
<string name="combined_notifications">合併された通知</string>
<string name="combined_notifications_summary_off">通知を個別表示</string>
<string name="combined_notifications_summary_on">通知をグループ化</string>
<string name="comment">コメント</string>
<string name="action_comment">コメント</string>
<string name="comment_hint">コメント&#8230;</string>
<string name="compact_cards">カードのコンパクト化</string>
<string name="compact_cards_summary">画面あたりのカード表示数を増やせます。</string>

View File

@ -205,7 +205,7 @@
<string name="combined_notifications">알림 합치기</string>
<string name="combined_notifications_summary_off">알림들이 따로따로 표시됩니다.</string>
<string name="combined_notifications_summary_on">알림들이 합쳐서 표시됩니다.</string>
<string name="comment">코멘트</string>
<string name="action_comment">코멘트</string>
<string name="comment_hint">코멘트&#8230;</string>
<string name="compact_cards">작은 카드</string>
<string name="compact_cards_summary">화면에 더 많은 카드를 표시합니다.</string>

View File

@ -113,7 +113,7 @@
<string name="combined_notifications">Gecombineerde meldingen</string>
<string name="combined_notifications_summary_off">Meldingen zullen los van elkaar worden weergegeven</string>
<string name="combined_notifications_summary_on">Meldingen zullen gegroepeerd worden</string>
<string name="comment">Opmerking</string>
<string name="action_comment">Opmerking</string>
<string name="comment_hint">Opmerking maken&#8230;</string>
<string name="compact_cards">Compacte kaarten</string>
<string name="compact_cards_summary">Toon meer kaarten op het scherm</string>

View File

@ -108,7 +108,7 @@
<string name="combined_notifications">Kombinerte varsler</string>
<string name="combined_notifications_summary_off">Varsler vises separat</string>
<string name="combined_notifications_summary_on">Varsler grupperes</string>
<string name="comment">Kommenter</string>
<string name="action_comment">Kommenter</string>
<string name="comment_hint">Kommenter&#8230;</string>
<string name="compact_cards">Kompakte kort</string>
<string name="compact_cards_summary">Vis flere kort på skjermen</string>

View File

@ -179,7 +179,7 @@
<string name="combined_notifications">Notificações agrupadas</string>
<string name="combined_notifications_summary_off">Notificações serão mostradas separadamente</string>
<string name="combined_notifications_summary_on">Notificações serão agrupadas</string>
<string name="comment">Comentar</string>
<string name="action_comment">Comentar</string>
<string name="comment_hint">Comentar&#8230;</string>
<string name="compact_cards">Compactar cartões</string>
<string name="compact_cards_summary">Exibir mais cartões na tela</string>

View File

@ -132,7 +132,7 @@
<string name="combined_notifications">Объединенные уведомления</string>
<string name="combined_notifications_summary_off">Уведомления будут показаны раздельно</string>
<string name="combined_notifications_summary_on">Уведомления будут сгруппированы</string>
<string name="comment">Комментировать</string>
<string name="action_comment">Комментировать</string>
<string name="comment_hint">Комментарий&#8230;</string>
<string name="compact_cards">Компактный вид карточек</string>
<string name="compact_cards_summary">Отображать на экране больше карточек</string>

View File

@ -197,7 +197,7 @@
<string name="combined_notifications">Kombinerade notifieringar</string>
<string name="combined_notifications_summary_off">Notifieringar kommer att visas separat</string>
<string name="combined_notifications_summary_on">Notifieringar kommer att grupperas</string>
<string name="comment">Kommentar</string>
<string name="action_comment">Kommentar</string>
<string name="comment_hint">Kommentar...</string>
<string name="compact_cards">Kompakta kort</string>
<string name="compact_cards_summary">Visa fler kort på skärmen</string>

View File

@ -203,7 +203,7 @@
<string name="combined_notifications">การแจ้งเตือนที่ถูกจัดกลุ่ม</string>
<string name="combined_notifications_summary_off">แยกการแจ้งเตือนออกจากกันเป็นอันๆ</string>
<string name="combined_notifications_summary_on">รวมการแจ้งเตือนเป็นกลุ่มเดียวกัน</string>
<string name="comment">แสดงความเห็น</string>
<string name="action_comment">แสดงความเห็น</string>
<string name="comment_hint">ความคิดเห็น...</string>
<string name="compact_cards">ขนาดกะทัดรัด</string>
<string name="compact_cards_summary">แสดงการ์ดเยอะๆ บนหน้าจอ</string>

View File

@ -116,7 +116,7 @@
<string name="combined_notifications">Kombine bildirimleri</string>
<string name="combined_notifications_summary_off">Bildirimler ayrı ayrı görüntülenir</string>
<string name="combined_notifications_summary_on">Bildirimler gruplandırılarak görüntülenir</string>
<string name="comment">Yorum</string>
<string name="action_comment">Yorum</string>
<string name="comment_hint">Yorum&#8230;</string>
<string name="compact_cards">Kompak kartlar</string>
<string name="compact_cards_summary">Ekranda daha fazla kart görüntüle</string>

View File

@ -117,7 +117,7 @@
<string name="combined_notifications">Груповані сповіщення</string>
<string name="combined_notifications_summary_off">Сповіщення відображаються окремо</string>
<string name="combined_notifications_summary_on">Сповіщення групуються</string>
<string name="comment">Коментувати</string>
<string name="action_comment">Коментувати</string>
<string name="comment_hint">Коментувати&#8230;</string>
<string name="compact_cards">Компактні картки</string>
<string name="compact_cards_summary">Відображати більше карток на екрані</string>

View File

@ -206,7 +206,7 @@
<string name="combined_notifications">合并通知</string>
<string name="combined_notifications_summary_off">通知将会分开显示</string>
<string name="combined_notifications_summary_on">通知将会被分组</string>
<string name="comment">评论</string>
<string name="action_comment">评论</string>
<string name="comment_hint">评论&#8230;</string>
<string name="compact_cards">紧凑卡片视图</string>
<string name="compact_cards_summary">在屏幕中显示更多卡片</string>

View File

@ -206,7 +206,7 @@
<string name="combined_notifications">已合併的通知</string>
<string name="combined_notifications_summary_off">通知將分開顯示</string>
<string name="combined_notifications_summary_on">通知將被分組</string>
<string name="comment">評論</string>
<string name="action_comment">評論</string>
<string name="comment_hint">評論&#8230;</string>
<string name="compact_cards">緊湊卡片視圖</string>
<string name="compact_cards_summary">在螢幕上顯示更多卡片</string>

View File

@ -206,7 +206,7 @@
<string name="combined_notifications">已合併的通知</string>
<string name="combined_notifications_summary_off">通知將分開顯示</string>
<string name="combined_notifications_summary_on">通知將被分組</string>
<string name="comment">評論</string>
<string name="action_comment">評論</string>
<string name="comment_hint">評論&#8230;</string>
<string name="compact_cards">緊湊卡片視圖</string>
<string name="compact_cards_summary">在螢幕上顯示更多卡片</string>

View File

@ -231,7 +231,7 @@
<string name="combined_notifications_summary_off">Notifications will be displayed separately</string>
<string name="combined_notifications_summary_on">Notifications will be grouped</string>
<string name="comment">Comment</string>
<string name="action_comment">Comment</string>
<string name="comment_hint">Comment…</string>
<string name="compact_cards">Compact cards</string>