compose code cleanup
This commit is contained in:
parent
b2e967847d
commit
0b1ccb45ab
|
@ -61,6 +61,7 @@ import nl.komponents.kovenant.task
|
|||
import org.mariotaku.abstask.library.AbstractTask
|
||||
import org.mariotaku.abstask.library.TaskStarter
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.kpreferences.set
|
||||
import org.mariotaku.ktextension.*
|
||||
import org.mariotaku.library.objectcursor.ObjectCursor
|
||||
import org.mariotaku.pickncrop.library.MediaPickerActivity
|
||||
|
@ -926,11 +927,16 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
editText.customSelectionActionModeCallback = this
|
||||
editTextContainer.touchDelegate = ComposeEditTextTouchDelegate(editTextContainer, editText)
|
||||
}
|
||||
|
||||
private fun addMedia(media: List<ParcelableMediaUpdate>) {
|
||||
mediaPreviewAdapter.addAll(media)
|
||||
updateAttachedMediaView()
|
||||
}
|
||||
|
||||
private fun removeMedia(list: List<ParcelableMediaUpdate>) {
|
||||
mediaPreviewAdapter.removeAll(list)
|
||||
}
|
||||
|
||||
private fun clearMedia() {
|
||||
mediaPreviewAdapter.clear()
|
||||
updateAttachedMediaView()
|
||||
|
@ -941,11 +947,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
setMenu()
|
||||
}
|
||||
|
||||
private fun displayNewDraftNotification(draftUri: Uri) {
|
||||
val notificationUri = Drafts.CONTENT_URI_NOTIFICATIONS.withAppendedPath(draftUri.lastPathSegment)
|
||||
contentResolver.insert(notificationUri, null)
|
||||
}
|
||||
|
||||
// MARK: Begin intent handling
|
||||
|
||||
private fun handleIntent(intent: Intent): Boolean {
|
||||
|
@ -1276,10 +1277,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
|
||||
private fun saveAccountSelection() {
|
||||
if (!shouldSaveAccounts) return
|
||||
val editor = preferences.edit()
|
||||
|
||||
editor.putString(KEY_COMPOSE_ACCOUNTS, accountsAdapter.selectedAccountKeys.joinToString(","))
|
||||
editor.apply()
|
||||
preferences[composeAccountsKey] = accountsAdapter.selectedAccountKeys
|
||||
}
|
||||
|
||||
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() {
|
||||
if (isFinishing || editText == null) return
|
||||
|
||||
|
@ -1437,6 +1422,30 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
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 {
|
||||
val accountKeys = accountsAdapter.selectedAccountKeys
|
||||
if (accountKeys.isEmpty()) throw NoAccountException()
|
||||
|
@ -1487,31 +1496,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
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() {
|
||||
val editable = editText.editableText ?: return
|
||||
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() {
|
||||
if (scheduleInfo != null) {
|
||||
updateStatusIcon.setImageResource(R.drawable.ic_action_time)
|
||||
|
@ -1550,8 +1527,24 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
}
|
||||
}
|
||||
|
||||
private fun removeMedia(list: List<ParcelableMediaUpdate>) {
|
||||
mediaPreviewAdapter.removeAll(list)
|
||||
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 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? {
|
||||
|
@ -1569,6 +1562,11 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
return draftUri
|
||||
}
|
||||
|
||||
private fun displayNewDraftNotification(draftUri: Uri) {
|
||||
val notificationUri = Drafts.CONTENT_URI_NOTIFICATIONS.withAppendedPath(draftUri.lastPathSegment)
|
||||
contentResolver.insert(notificationUri, null)
|
||||
}
|
||||
|
||||
private fun ViewAnimator.setupViews() {
|
||||
fun AnimatorSet.setup() {
|
||||
interpolator = DecelerateInterpolator()
|
||||
|
@ -1801,9 +1799,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
return accounts.filter { selection[it.key] ?: false }.toTypedArray()
|
||||
}
|
||||
|
||||
val isSelectionEmpty: Boolean
|
||||
get() = selectedAccountKeys.isEmpty()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AccountIconViewHolder {
|
||||
val view = inflater.inflate(R.layout.adapter_item_compose_account, parent, false)
|
||||
return AccountIconViewHolder(this, view)
|
||||
|
|
Loading…
Reference in New Issue