mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
fixed new dm in user profile
This commit is contained in:
parent
af76d09078
commit
50ae1ecefd
@ -36,8 +36,8 @@ android {
|
||||
applicationId "org.mariotaku.twidere"
|
||||
minSdkVersion project.properties['overrideMinSdkVersion'] ?: 14
|
||||
targetSdkVersion 25
|
||||
versionCode 319
|
||||
versionName '3.5.2'
|
||||
versionCode 320
|
||||
versionName '3.5.3'
|
||||
multiDexEnabled true
|
||||
|
||||
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")'
|
||||
|
@ -39,4 +39,8 @@ operator fun Bundle.set(key: String, value: Array<String>?) {
|
||||
|
||||
fun <T> Bundle.getTypedArray(key: String, creator: Parcelable.Creator<T>): Array<T> {
|
||||
return getParcelableArray(key).toTypedArray(creator)
|
||||
}
|
||||
|
||||
fun <T> Bundle.getNullableTypedArray(key: String, creator: Parcelable.Creator<T>): Array<T>? {
|
||||
return getParcelableArray(key)?.toTypedArray(creator)
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.extension.text
|
||||
|
||||
import android.text.Editable
|
||||
|
||||
fun Editable.appendCompat(text: CharSequence, what: Any, flags: Int) {
|
||||
val start = length
|
||||
append(text)
|
||||
val end = length
|
||||
setSpan(what, start, end, flags)
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.extension.text
|
||||
|
||||
import android.text.SpannableStringBuilder
|
||||
|
||||
fun SpannableStringBuilder.appendCompat(text: CharSequence, what: Any, flags: Int) {
|
||||
val start = length
|
||||
append(text)
|
||||
val end = length
|
||||
setSpan(what, start, end, flags)
|
||||
}
|
@ -945,15 +945,17 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
startActivity(intent)
|
||||
}
|
||||
R.id.send_direct_message -> {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme(SCHEME_TWIDERE)
|
||||
builder.authority(AUTHORITY_MESSAGES)
|
||||
builder.path(PATH_MESSAGES_CONVERSATION_NEW)
|
||||
builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, user.account_key.toString())
|
||||
builder.appendQueryParameter(QUERY_PARAM_USER_KEY, user.key.toString())
|
||||
val am = AccountManager.get(activity)
|
||||
val builder = Uri.Builder().apply {
|
||||
scheme(SCHEME_TWIDERE)
|
||||
authority(AUTHORITY_MESSAGES)
|
||||
path(PATH_MESSAGES_CONVERSATION_NEW)
|
||||
appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, user.account_key.toString())
|
||||
}
|
||||
val intent = Intent(Intent.ACTION_VIEW, builder.build())
|
||||
intent.putExtra(EXTRA_ACCOUNT, AccountUtils.getAccountDetails(AccountManager.get(activity), user.account_key, true))
|
||||
intent.putExtra(EXTRA_USER, user)
|
||||
intent.putExtra(EXTRA_ACCOUNT, AccountUtils.getAccountDetails(am, user.account_key,
|
||||
true))
|
||||
intent.putExtra(EXTRA_USERS, arrayOf(user))
|
||||
startActivity(intent)
|
||||
}
|
||||
R.id.set_color -> {
|
||||
|
@ -31,15 +31,14 @@ import android.support.v4.content.Loader
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.text.Editable
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.TextUtils
|
||||
import android.text.style.ReplacementSpan
|
||||
import android.view.*
|
||||
import com.bumptech.glide.Glide
|
||||
import kotlinx.android.synthetic.main.fragment_messages_conversation_new.*
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.Bundle
|
||||
import org.mariotaku.ktextension.set
|
||||
import org.mariotaku.ktextension.setItemAvailability
|
||||
import org.mariotaku.ktextension.*
|
||||
import org.mariotaku.library.objectcursor.ObjectCursor
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.R
|
||||
@ -47,6 +46,7 @@ import org.mariotaku.twidere.adapter.SelectableUsersAdapter
|
||||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.constant.nameFirstKey
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.extension.text.appendCompat
|
||||
import org.mariotaku.twidere.fragment.BaseFragment
|
||||
import org.mariotaku.twidere.loader.CacheUserSearchLoader
|
||||
import org.mariotaku.twidere.model.ParcelableMessageConversation
|
||||
@ -71,11 +71,24 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
|
||||
AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true)
|
||||
}
|
||||
|
||||
private val selectedRecipients: List<ParcelableUser>
|
||||
private var selectedRecipients: List<ParcelableUser>
|
||||
get() {
|
||||
val text = editParticipants.editableText ?: return emptyList()
|
||||
return text.getSpans(0, text.length, ParticipantSpan::class.java).map(ParticipantSpan::user)
|
||||
}
|
||||
set(value) {
|
||||
val roundRadius = resources.getDimension(R.dimen.element_spacing_xsmall)
|
||||
val spanPadding = resources.getDimension(R.dimen.element_spacing_xsmall)
|
||||
val nameFirst = preferences[nameFirstKey]
|
||||
editParticipants.text = SpannableStringBuilder().apply {
|
||||
value.forEach { user ->
|
||||
val displayName = userColorNameManager.getDisplayName(user, nameFirst)
|
||||
val span = ParticipantSpan(user, displayName, roundRadius, spanPadding)
|
||||
appendCompat(user.screen_name, span, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var loaderInitialized: Boolean = false
|
||||
private var performSearchRequestRunnable: Runnable? = null
|
||||
@ -141,7 +154,7 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
|
||||
val spanPadding = resources.getDimension(R.dimen.element_spacing_xsmall)
|
||||
usersAdapter.itemCheckedListener = itemChecked@ { pos, checked ->
|
||||
val text: Editable = editParticipants.editableText ?: return@itemChecked false
|
||||
val user = usersAdapter.getUser(pos) ?: return@itemChecked false
|
||||
val user = usersAdapter.getUser(pos)
|
||||
if (checked) {
|
||||
text.getSpans(0, text.length, PendingQuerySpan::class.java).forEach { pending ->
|
||||
val start = text.getSpanStart(pending)
|
||||
@ -152,10 +165,8 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
|
||||
}
|
||||
val displayName = userColorNameManager.getDisplayName(user, nameFirst)
|
||||
val span = ParticipantSpan(user, displayName, roundRadius, spanPadding)
|
||||
val start = text.length
|
||||
text.append("${user.screen_name} ")
|
||||
val end = text.length - 1
|
||||
text.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
text.appendCompat(user.screen_name, span, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
text.append(" ")
|
||||
} else {
|
||||
text.getSpans(0, text.length, ParticipantSpan::class.java).forEach { span ->
|
||||
if (user != span.user) {
|
||||
@ -175,6 +186,14 @@ class MessageNewConversationFragment : BaseFragment(), LoaderCallbacks<List<Parc
|
||||
updateCheckState()
|
||||
return@itemChecked true
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
val users = arguments.getNullableTypedArray(EXTRA_USERS, ParcelableUser.CREATOR)
|
||||
if (users != null) {
|
||||
selectedRecipients = users.toList()
|
||||
editParticipants.setSelection(editParticipants.length())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
|
Loading…
x
Reference in New Issue
Block a user