From 77e078f7f799f668590c0c00769c8a323add475e Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 28 Feb 2017 15:58:15 +0800 Subject: [PATCH] fixed #618 --- .../twidere/activity/ComposeActivity.kt | 59 ++++++++++++++++--- twidere/src/main/res/values/strings.xml | 2 + 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt index 9223abb03..a7cfeb680 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt @@ -63,10 +63,7 @@ import org.apache.commons.lang3.ObjectUtils import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.abstask.library.TaskStarter import org.mariotaku.kpreferences.get -import org.mariotaku.ktextension.checkAnySelfPermissionsGranted -import org.mariotaku.ktextension.getTypedArray -import org.mariotaku.ktextension.setItemChecked -import org.mariotaku.ktextension.toTypedArray +import org.mariotaku.ktextension.* import org.mariotaku.pickncrop.library.MediaPickerActivity import org.mariotaku.twidere.Constants.* import org.mariotaku.twidere.R @@ -74,6 +71,7 @@ import org.mariotaku.twidere.TwidereConstants import org.mariotaku.twidere.adapter.BaseRecyclerViewAdapter import org.mariotaku.twidere.adapter.MediaPreviewAdapter import org.mariotaku.twidere.constant.* +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SCREEN_NAME import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.extension.model.getAccountUser import org.mariotaku.twidere.extension.model.textLimit @@ -293,8 +291,17 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } private fun confirmAndUpdateStatus() { - if (isQuotingProtectedStatus) { - RetweetProtectedStatusWarnFragment().show(supportFragmentManager, + val matchResult = Regex("[DM] +([a-z0-9_]{1,20}) +[^ ]+").matchEntire(editText.text) + if (matchResult != null) { + val screenName = matchResult.groupValues[1] + val df = DirectMessageConfirmFragment() + df.arguments = Bundle { + this[EXTRA_SCREEN_NAME] = screenName + } + df.show(supportFragmentManager, "send_direct_message_confirm") + } else if (isQuotingProtectedStatus) { + val df = RetweetProtectedStatusWarnFragment() + df.show(supportFragmentManager, "retweet_protected_status_warning_message") } else { updateStatus() @@ -1669,7 +1676,6 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } } } - } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { @@ -1687,6 +1693,45 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } } + class DirectMessageConfirmFragment : BaseDialogFragment(), DialogInterface.OnClickListener { + + private val screenName: String get() = arguments.getString(EXTRA_SCREEN_NAME) + + override fun onClick(dialog: DialogInterface, which: Int) { + val activity = activity + when (which) { + DialogInterface.BUTTON_POSITIVE -> { + if (activity is ComposeActivity) { + activity.updateStatus() + } + } + DialogInterface.BUTTON_NEUTRAL -> { + if (activity is ComposeActivity) { + // Insert a ZWSP into status text + activity.editText.text.insert(1, "\u200b") + activity.updateStatus() + } + } + } + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val context = activity + val builder = AlertDialog.Builder(context) + builder.setMessage(getString(R.string.message_format_compose_message_convert_to_status, + "@$screenName")) + builder.setPositiveButton(R.string.action_send, this) + builder.setNeutralButton(R.string.action_compose_message_convert_to_status, this) + builder.setNegativeButton(android.R.string.cancel, null) + val dialog = builder.create() + dialog.setOnShowListener { + it as AlertDialog + it.applyTheme() + } + return dialog + } + } + class AttachedMediaItemTouchHelperCallback(adapter: SimpleItemTouchHelperCallback.ItemTouchHelperAdapter) : SimpleItemTouchHelperCallback(adapter) { override fun isLongPressDragEnabled(): Boolean { diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index c667a43c4..f8a4030c8 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -30,6 +30,7 @@ Center Clear Compose + Convert to tweet Conversation info Create conversation creating list @@ -596,6 +597,7 @@ Direct message deleted. Direct message sent. Some account data are corrupted, Twidere will remove those accounts to prevent crash. + This tweet will be sent as a message to %1$s, continue? Converting to a normal tweet uses an extra character. Conversation avatar changed %1$s changed conversation avatar Conversation name changed to %1$s