This commit is contained in:
Mariotaku Lee 2017-02-28 15:58:15 +08:00
parent f258d1fe1f
commit 77e078f7f7
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
2 changed files with 54 additions and 7 deletions

View File

@ -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 {

View File

@ -30,6 +30,7 @@
<string name="action_center">Center</string>
<string name="action_clear">Clear</string>
<string name="action_compose">Compose</string>
<string name="action_compose_message_convert_to_status">Convert to tweet</string>
<string name="action_conversation_info">Conversation info</string>
<string name="action_create_conversation">Create conversation</string>
<string name="action_creating_list">creating list</string>
@ -596,6 +597,7 @@
<string name="message_direct_message_deleted">Direct message deleted.</string>
<string name="message_direct_message_sent">Direct message sent.</string>
<string name="message_error_invalid_account">Some account data are corrupted, Twidere will remove those accounts to prevent crash.</string>
<string name="message_format_compose_message_convert_to_status">This tweet will be sent as a message to <xliff:g id="name">%1$s</xliff:g>, continue? Converting to a normal tweet uses an extra character.</string>
<string name="message_format_conversation_avatar_update">Conversation avatar changed</string>
<string name="message_format_conversation_avatar_update_by_user"><xliff:g example="User" id="by_user">%1$s</xliff:g> changed conversation avatar</string>
<string name="message_format_conversation_name_update">Conversation name changed to <xliff:g example="User" id="name">%1$s</xliff:g></string>