supported edit alt text for dm
This commit is contained in:
parent
5e5aad22a9
commit
8ed618e0f1
|
@ -53,7 +53,6 @@ import android.util.Log
|
|||
import android.view.*
|
||||
import android.view.View.OnClickListener
|
||||
import android.view.View.OnLongClickListener
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.twitter.Extractor
|
||||
|
@ -63,10 +62,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
|
||||
|
@ -78,6 +74,7 @@ import org.mariotaku.twidere.extension.applyTheme
|
|||
import org.mariotaku.twidere.extension.model.getAccountUser
|
||||
import org.mariotaku.twidere.extension.model.unique_id_non_null
|
||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
import org.mariotaku.twidere.fragment.EditAltTextDialogFragment
|
||||
import org.mariotaku.twidere.fragment.PermissionRequestDialog
|
||||
import org.mariotaku.twidere.fragment.PermissionRequestDialog.PermissionRequestCancelCallback
|
||||
import org.mariotaku.twidere.fragment.ProgressDialogFragment
|
||||
|
@ -107,7 +104,7 @@ import javax.inject.Inject
|
|||
import android.Manifest.permission as AndroidPermission
|
||||
|
||||
class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener, OnLongClickListener,
|
||||
ActionMode.Callback, PermissionRequestCancelCallback {
|
||||
ActionMode.Callback, PermissionRequestCancelCallback, EditAltTextDialogFragment.EditAltTextCallback {
|
||||
|
||||
// Utility classes
|
||||
@Inject
|
||||
|
@ -666,13 +663,11 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
when (menuInfo.recyclerViewId) {
|
||||
R.id.attachedMediaPreview -> {
|
||||
val position = menuInfo.position
|
||||
val mediaUpdate = mediaPreviewAdapter.getItem(position)
|
||||
val args = Bundle()
|
||||
args.putString(EXTRA_TEXT, mediaUpdate.alt_text)
|
||||
args.putInt(EXTRA_POSITION, position)
|
||||
val df = EditAltTextDialogFragment()
|
||||
df.arguments = args
|
||||
df.show(supportFragmentManager, "edit_alt_text")
|
||||
val altText = mediaPreviewAdapter.getItem(position).alt_text
|
||||
executeAfterFragmentResumed { activity ->
|
||||
EditAltTextDialogFragment.show(activity.supportFragmentManager, position,
|
||||
altText)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -1656,32 +1651,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
internal class NoAddress
|
||||
}
|
||||
|
||||
class EditAltTextDialogFragment : BaseDialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(R.string.edit_description)
|
||||
builder.setView(R.layout.dialog_compose_edit_alt_text)
|
||||
builder.setNegativeButton(android.R.string.cancel, null)
|
||||
builder.setPositiveButton(android.R.string.ok) { dialog, which ->
|
||||
val editText = (dialog as Dialog).findViewById(R.id.edit_text) as EditText
|
||||
(activity as ComposeActivity).setMediaAltText(arguments.getInt(EXTRA_POSITION),
|
||||
ParseUtils.parseString(editText.text))
|
||||
}
|
||||
builder.setNeutralButton(R.string.action_clear) { dialogInterface, i ->
|
||||
(activity as ComposeActivity).setMediaAltText(arguments.getInt(EXTRA_POSITION), null)
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.setOnShowListener {
|
||||
it as AlertDialog
|
||||
it.applyTheme()
|
||||
val editText = it.findViewById(R.id.edit_text) as EditText
|
||||
editText.setText(arguments.getString(EXTRA_TEXT))
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
|
||||
private fun setMediaAltText(position: Int, altText: String?) {
|
||||
override fun onSetAltText(position: Int, altText: String?) {
|
||||
mediaPreviewAdapter.setAltText(position, altText)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.widget.EditText
|
||||
import org.mariotaku.ktextension.Bundle
|
||||
import org.mariotaku.ktextension.set
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_POSITION
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_TEXT
|
||||
import org.mariotaku.twidere.extension.applyTheme
|
||||
import org.mariotaku.twidere.util.ParseUtils
|
||||
|
||||
class EditAltTextDialogFragment : BaseDialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(R.string.edit_description)
|
||||
builder.setView(R.layout.dialog_compose_edit_alt_text)
|
||||
builder.setNegativeButton(android.R.string.cancel, null)
|
||||
val position = arguments.getInt(EXTRA_POSITION)
|
||||
builder.setPositiveButton(android.R.string.ok) { dialog, which ->
|
||||
val editText = (dialog as Dialog).findViewById(R.id.edit_text) as EditText
|
||||
val altText = ParseUtils.parseString(editText.text)
|
||||
callback?.onSetAltText(position, altText)
|
||||
}
|
||||
builder.setNeutralButton(R.string.action_clear) { dialogInterface, i ->
|
||||
callback?.onSetAltText(position, null)
|
||||
}
|
||||
val dialog = builder.create()
|
||||
dialog.setOnShowListener {
|
||||
it as AlertDialog
|
||||
it.applyTheme()
|
||||
val editText = it.findViewById(R.id.edit_text) as EditText
|
||||
editText.setText(arguments.getString(EXTRA_TEXT))
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
|
||||
private val callback: EditAltTextCallback?
|
||||
get() = targetFragment as? EditAltTextCallback ?: parentFragment as? EditAltTextCallback ?: context as? EditAltTextCallback
|
||||
|
||||
interface EditAltTextCallback {
|
||||
fun onSetAltText(position: Int, altText: String?)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun show(fm: FragmentManager, position: Int, altText: String?) {
|
||||
val df = EditAltTextDialogFragment()
|
||||
df.arguments = Bundle {
|
||||
this[Constants.EXTRA_TEXT] = altText
|
||||
this[Constants.EXTRA_POSITION] = position
|
||||
}
|
||||
df.show(fm, "edit_alt_text")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,9 +11,7 @@ import android.support.v4.content.Loader
|
|||
import android.support.v7.widget.FixedLinearLayoutManager
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.*
|
||||
import android.widget.Toast
|
||||
import com.squareup.otto.Subscribe
|
||||
import kotlinx.android.synthetic.main.fragment_messages_conversation.*
|
||||
|
@ -46,11 +44,12 @@ import org.mariotaku.twidere.task.compose.AbsDeleteMediaTask
|
|||
import org.mariotaku.twidere.util.DataStoreUtils
|
||||
import org.mariotaku.twidere.util.IntentUtils
|
||||
import org.mariotaku.twidere.util.PreviewGridItemDecoration
|
||||
import org.mariotaku.twidere.view.ExtendedRecyclerView
|
||||
import org.mariotaku.twidere.view.holder.compose.MediaPreviewViewHolder
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
class MessagesConversationFragment : AbsContentListRecyclerViewFragment<MessagesConversationAdapter>(),
|
||||
LoaderManager.LoaderCallbacks<List<ParcelableMessage>?> {
|
||||
LoaderManager.LoaderCallbacks<List<ParcelableMessage>?>, EditAltTextDialogFragment.EditAltTextCallback {
|
||||
private lateinit var mediaPreviewAdapter: MediaPreviewAdapter
|
||||
|
||||
private val accountKey: UserKey get() = arguments.getParcelable(EXTRA_ACCOUNT_KEY)
|
||||
|
@ -95,11 +94,14 @@ class MessagesConversationFragment : AbsContentListRecyclerViewFragment<Messages
|
|||
TaskStarter.execute(task)
|
||||
}
|
||||
|
||||
override fun onEditClick(position: Int, holder: MediaPreviewViewHolder) {
|
||||
attachedMediaPreview.showContextMenuForChild(holder.itemView)
|
||||
}
|
||||
}
|
||||
|
||||
attachedMediaPreview.layoutManager = FixedLinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
attachedMediaPreview.adapter = mediaPreviewAdapter
|
||||
attachedMediaPreview.addItemDecoration(PreviewGridItemDecoration(resources.getDimensionPixelSize(R.dimen.element_spacing_small)))
|
||||
registerForContextMenu(attachedMediaPreview)
|
||||
|
||||
sendMessage.setOnClickListener {
|
||||
performSendMessage()
|
||||
|
@ -193,6 +195,35 @@ class MessagesConversationFragment : AbsContentListRecyclerViewFragment<Messages
|
|||
twitterWrapper.getMessagesAsync(param)
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) {
|
||||
if (v === attachedMediaPreview) {
|
||||
menu.setHeaderTitle(R.string.edit_media)
|
||||
activity.menuInflater.inflate(R.menu.menu_attached_media_edit, menu)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
val menuInfo = item.menuInfo
|
||||
if (menuInfo is ExtendedRecyclerView.ContextMenuInfo) {
|
||||
when (menuInfo.recyclerViewId) {
|
||||
R.id.attachedMediaPreview -> {
|
||||
val position = menuInfo.position
|
||||
val altText = mediaPreviewAdapter.getItem(position).alt_text
|
||||
executeAfterFragmentResumed { fragment ->
|
||||
EditAltTextDialogFragment.show(fragment.childFragmentManager, position,
|
||||
altText)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onContextItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onSetAltText(position: Int, altText: String?) {
|
||||
mediaPreviewAdapter.setAltText(position, altText)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun onGetMessagesTaskEvent(event: GetMessagesTaskEvent) {
|
||||
if (!event.running && event.taskTag == loadMoreTaskTag) {
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/element_spacing_large">
|
||||
|
||||
<org.mariotaku.twidere.view.FixedEditText
|
||||
android:id="@+id/edit_text"
|
||||
|
|
Loading…
Reference in New Issue