compose code cleanup

This commit is contained in:
Mariotaku Lee 2017-04-14 16:10:15 +08:00
parent b2e967847d
commit 0b1ccb45ab
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
1 changed files with 54 additions and 59 deletions

View File

@ -61,6 +61,7 @@ import nl.komponents.kovenant.task
import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.abstask.library.AbstractTask
import org.mariotaku.abstask.library.TaskStarter import org.mariotaku.abstask.library.TaskStarter
import org.mariotaku.kpreferences.get import org.mariotaku.kpreferences.get
import org.mariotaku.kpreferences.set
import org.mariotaku.ktextension.* import org.mariotaku.ktextension.*
import org.mariotaku.library.objectcursor.ObjectCursor import org.mariotaku.library.objectcursor.ObjectCursor
import org.mariotaku.pickncrop.library.MediaPickerActivity import org.mariotaku.pickncrop.library.MediaPickerActivity
@ -926,11 +927,16 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
editText.customSelectionActionModeCallback = this editText.customSelectionActionModeCallback = this
editTextContainer.touchDelegate = ComposeEditTextTouchDelegate(editTextContainer, editText) editTextContainer.touchDelegate = ComposeEditTextTouchDelegate(editTextContainer, editText)
} }
private fun addMedia(media: List<ParcelableMediaUpdate>) { private fun addMedia(media: List<ParcelableMediaUpdate>) {
mediaPreviewAdapter.addAll(media) mediaPreviewAdapter.addAll(media)
updateAttachedMediaView() updateAttachedMediaView()
} }
private fun removeMedia(list: List<ParcelableMediaUpdate>) {
mediaPreviewAdapter.removeAll(list)
}
private fun clearMedia() { private fun clearMedia() {
mediaPreviewAdapter.clear() mediaPreviewAdapter.clear()
updateAttachedMediaView() updateAttachedMediaView()
@ -941,11 +947,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
setMenu() setMenu()
} }
private fun displayNewDraftNotification(draftUri: Uri) {
val notificationUri = Drafts.CONTENT_URI_NOTIFICATIONS.withAppendedPath(draftUri.lastPathSegment)
contentResolver.insert(notificationUri, null)
}
// MARK: Begin intent handling // MARK: Begin intent handling
private fun handleIntent(intent: Intent): Boolean { private fun handleIntent(intent: Intent): Boolean {
@ -1276,10 +1277,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
private fun saveAccountSelection() { private fun saveAccountSelection() {
if (!shouldSaveAccounts) return if (!shouldSaveAccounts) return
val editor = preferences.edit() preferences[composeAccountsKey] = accountsAdapter.selectedAccountKeys
editor.putString(KEY_COMPOSE_ACCOUNTS, accountsAdapter.selectedAccountKeys.joinToString(","))
editor.apply()
} }
private fun setMenu() { private fun setMenu() {
@ -1402,19 +1400,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
} }
} }
private fun updateLocationState() {
if (kPreferences[attachLocationKey]) {
locationLabel.visibility = View.VISIBLE
if (recentLocation != null) {
setRecentLocation(recentLocation)
} else {
locationLabel.setText(R.string.getting_location)
}
} else {
locationLabel.visibility = View.GONE
}
}
private fun updateStatus() { private fun updateStatus() {
if (isFinishing || editText == null) return if (isFinishing || editText == null) return
@ -1437,6 +1422,30 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
finishComposing() finishComposing()
} }
private fun finishComposing() {
if (preferences[noCloseAfterTweetSentKey] && inReplyToStatus == null) {
possiblySensitive = false
shouldSaveAccounts = true
inReplyToStatus = null
mentionUser = null
draft = null
originalText = null
editText.text = null
clearMedia()
val intent = Intent(INTENT_ACTION_COMPOSE)
setIntent(intent)
handleIntent(intent)
showLabelAndHint(intent)
setMenu()
updateTextCount()
shouldSkipDraft = false
} else {
setResult(Activity.RESULT_OK)
shouldSkipDraft = true
finish()
}
}
private fun getStatusUpdate(): ParcelableStatusUpdate { private fun getStatusUpdate(): ParcelableStatusUpdate {
val accountKeys = accountsAdapter.selectedAccountKeys val accountKeys = accountsAdapter.selectedAccountKeys
if (accountKeys.isEmpty()) throw NoAccountException() if (accountKeys.isEmpty()) throw NoAccountException()
@ -1487,31 +1496,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
return update return update
} }
private fun finishComposing() {
if (preferences[noCloseAfterTweetSentKey] && inReplyToStatus == null) {
possiblySensitive = false
shouldSaveAccounts = true
inReplyToStatus = null
mentionUser = null
draft = null
originalText = null
editText.text = null
clearMedia()
val intent = Intent(INTENT_ACTION_COMPOSE)
setIntent(intent)
handleIntent(intent)
showLabelAndHint(intent)
setMenu()
updateTextCount()
shouldSkipDraft = false
} else {
setResult(Activity.RESULT_OK)
shouldSkipDraft = true
finish()
}
}
private fun updateTextCount() { private fun updateTextCount() {
val editable = editText.editableText ?: return val editable = editText.editableText ?: return
val text = editable.toString() val text = editable.toString()
@ -1535,13 +1519,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
} }
} }
private fun getTwitterReplyTextAndMentions(text: String = editText.text?.toString().orEmpty()):
ReplyTextAndMentions? {
val inReplyTo = inReplyToStatus ?: return null
if (!ignoreMentions) return null
return extractor.extractReplyTextAndMentions(text, inReplyTo)
}
private fun updateUpdateStatusIcon() { private fun updateUpdateStatusIcon() {
if (scheduleInfo != null) { if (scheduleInfo != null) {
updateStatusIcon.setImageResource(R.drawable.ic_action_time) updateStatusIcon.setImageResource(R.drawable.ic_action_time)
@ -1550,8 +1527,24 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
} }
} }
private fun removeMedia(list: List<ParcelableMediaUpdate>) { private fun updateLocationState() {
mediaPreviewAdapter.removeAll(list) if (kPreferences[attachLocationKey]) {
locationLabel.visibility = View.VISIBLE
if (recentLocation != null) {
setRecentLocation(recentLocation)
} else {
locationLabel.setText(R.string.getting_location)
}
} else {
locationLabel.visibility = View.GONE
}
}
private fun getTwitterReplyTextAndMentions(text: String = editText.text?.toString().orEmpty()):
ReplyTextAndMentions? {
val inReplyTo = inReplyToStatus ?: return null
if (!ignoreMentions) return null
return extractor.extractReplyTextAndMentions(text, inReplyTo)
} }
private fun saveToDrafts(): Uri? { private fun saveToDrafts(): Uri? {
@ -1569,6 +1562,11 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
return draftUri return draftUri
} }
private fun displayNewDraftNotification(draftUri: Uri) {
val notificationUri = Drafts.CONTENT_URI_NOTIFICATIONS.withAppendedPath(draftUri.lastPathSegment)
contentResolver.insert(notificationUri, null)
}
private fun ViewAnimator.setupViews() { private fun ViewAnimator.setupViews() {
fun AnimatorSet.setup() { fun AnimatorSet.setup() {
interpolator = DecelerateInterpolator() interpolator = DecelerateInterpolator()
@ -1801,9 +1799,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
return accounts.filter { selection[it.key] ?: false }.toTypedArray() return accounts.filter { selection[it.key] ?: false }.toTypedArray()
} }
val isSelectionEmpty: Boolean
get() = selectedAccountKeys.isEmpty()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AccountIconViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AccountIconViewHolder {
val view = inflater.inflate(R.layout.adapter_item_compose_account, parent, false) val view = inflater.inflate(R.layout.adapter_item_compose_account, parent, false)
return AccountIconViewHolder(this, view) return AccountIconViewHolder(this, view)