removed unused class
This commit is contained in:
parent
401a7cdfbc
commit
f258d1fe1f
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 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.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.twitter.Validator;
|
||||
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.account.StatusNetAccountExtras;
|
||||
|
||||
public class TwidereValidator {
|
||||
|
||||
private final Validator mValidator;
|
||||
|
||||
public TwidereValidator() {
|
||||
mValidator = new Validator();
|
||||
}
|
||||
|
||||
public static int getTextLimit(@NonNull AccountDetails[] credentials) {
|
||||
int limit = -1;
|
||||
for (AccountDetails details : credentials) {
|
||||
int currentLimit = getTextLimit(details);
|
||||
if (currentLimit != 0) {
|
||||
if (limit <= 0) {
|
||||
limit = currentLimit;
|
||||
} else {
|
||||
limit = Math.min(limit, currentLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param credentials Account for getting limit
|
||||
* @return Text limit, <= 0 if no limit
|
||||
*/
|
||||
public static int getTextLimit(@NonNull AccountDetails credentials) {
|
||||
if (credentials.type == null) {
|
||||
return Validator.MAX_TWEET_LENGTH;
|
||||
}
|
||||
switch (credentials.type) {
|
||||
case AccountType.STATUSNET: {
|
||||
StatusNetAccountExtras extra = (StatusNetAccountExtras) credentials.extras;
|
||||
if (extra != null) {
|
||||
return extra.getTextLimit();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Validator.MAX_TWEET_LENGTH;
|
||||
}
|
||||
|
||||
public int getTweetLength(@Nullable final String text) {
|
||||
if (text == null) return 0;
|
||||
return mValidator.getTweetLength(text);
|
||||
}
|
||||
|
||||
public boolean isValidDirectMessage(final CharSequence text) {
|
||||
return !TextUtils.isEmpty(text);
|
||||
}
|
||||
|
||||
}
|
|
@ -35,7 +35,7 @@ import org.mariotaku.twidere.TwidereConstants.*
|
|||
import org.mariotaku.twidere.adapter.AccountDetailsAdapter
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
import org.mariotaku.twidere.extension.model.is_oauth
|
||||
import org.mariotaku.twidere.extension.model.isOAuth
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.util.DataStoreUtils
|
||||
|
@ -101,7 +101,7 @@ class AccountSelectorActivity : BaseActivity(), OnItemClickListener {
|
|||
if (extraKeys != null) {
|
||||
return@filter extraKeys.contains(it.key)
|
||||
}
|
||||
if (oauthOnly && !it.is_oauth) {
|
||||
if (oauthOnly && !it.isOAuth) {
|
||||
return@filter false
|
||||
}
|
||||
if (USER_TYPE_TWITTER_COM == accountHost) {
|
||||
|
|
|
@ -56,6 +56,7 @@ import android.view.View.OnLongClickListener
|
|||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.twitter.Extractor
|
||||
import com.twitter.Validator
|
||||
import kotlinx.android.synthetic.main.activity_compose.*
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import org.apache.commons.lang3.ObjectUtils
|
||||
|
@ -75,6 +76,7 @@ import org.mariotaku.twidere.adapter.MediaPreviewAdapter
|
|||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.extension.applyTheme
|
||||
import org.mariotaku.twidere.extension.model.getAccountUser
|
||||
import org.mariotaku.twidere.extension.model.textLimit
|
||||
import org.mariotaku.twidere.extension.model.unique_id_non_null
|
||||
import org.mariotaku.twidere.fragment.BaseDialogFragment
|
||||
import org.mariotaku.twidere.fragment.EditAltTextDialogFragment
|
||||
|
@ -113,7 +115,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
@Inject
|
||||
lateinit var extractor: Extractor
|
||||
@Inject
|
||||
lateinit var validator: TwidereValidator
|
||||
lateinit var validator: Validator
|
||||
@Inject
|
||||
lateinit var locationManager: LocationManager
|
||||
|
||||
|
@ -1097,7 +1099,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
} else {
|
||||
editText.accountKey = accounts[0].key
|
||||
}
|
||||
statusTextCount.maxLength = TwidereValidator.getTextLimit(accounts)
|
||||
statusTextCount.maxLength = accounts.textLimit
|
||||
setMenu()
|
||||
}
|
||||
|
||||
|
@ -1318,9 +1320,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
}
|
||||
|
||||
private fun updateStatus() {
|
||||
if (isFinishing) return
|
||||
if (isFinishing || editText == null) return
|
||||
val hasMedia = hasMedia()
|
||||
val text = if (editText != null) ParseUtils.parseString(editText.text) else null
|
||||
val text = editText.text.toString()
|
||||
val tweetLength = validator.getTweetLength(text)
|
||||
val maxLength = statusTextCount.maxLength
|
||||
if (accountsAdapter.isSelectionEmpty) {
|
||||
|
@ -1376,20 +1378,13 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
}
|
||||
|
||||
private fun updateTextCount() {
|
||||
var text = editText.text?.toString() ?: return
|
||||
if (defaultFeatures.isMediaLinkCountsInStatus && media.isNotEmpty()) {
|
||||
text += " https://twitter.com/example/status/12345678901234567890/photos/1"
|
||||
}
|
||||
val text = editText.text?.toString() ?: return
|
||||
statusTextCount.textCount = validator.getTweetLength(text)
|
||||
}
|
||||
|
||||
internal class ComposeLocationListener(activity: ComposeActivity) : LocationListener {
|
||||
|
||||
val activityRef: WeakReference<ComposeActivity>
|
||||
|
||||
init {
|
||||
activityRef = WeakReference(activity)
|
||||
}
|
||||
private val activityRef = WeakReference(activity)
|
||||
|
||||
override fun onLocationChanged(location: Location) {
|
||||
val activity = activityRef.get() ?: return
|
||||
|
@ -1409,12 +1404,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||
}
|
||||
|
||||
internal class AccountIconViewHolder(val adapter: AccountIconsAdapter, itemView: View) : ViewHolder(itemView), OnClickListener {
|
||||
val iconView: ShapedImageView
|
||||
val nameView: TextView
|
||||
private val iconView = itemView.findViewById(android.R.id.icon) as ShapedImageView
|
||||
private val nameView = itemView.findViewById(android.R.id.text1) as TextView
|
||||
|
||||
init {
|
||||
iconView = itemView.findViewById(android.R.id.icon) as ShapedImageView
|
||||
nameView = itemView.findViewById(android.R.id.text1) as TextView
|
||||
itemView.setOnClickListener(this)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package org.mariotaku.twidere.extension.model
|
||||
|
||||
import android.content.Context
|
||||
import com.twitter.Validator
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
import org.mariotaku.twidere.model.account.AccountExtras
|
||||
import org.mariotaku.twidere.model.account.StatusNetAccountExtras
|
||||
import org.mariotaku.twidere.model.account.TwitterAccountExtras
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials
|
||||
import org.mariotaku.twidere.model.account.cred.OAuthCredentials
|
||||
|
@ -45,10 +47,10 @@ fun <T> AccountDetails.newMicroBlogInstance(
|
|||
return credentials.newMicroBlogInstance(context, type, extraRequestParams, cls)
|
||||
}
|
||||
|
||||
val AccountDetails.is_oauth: Boolean
|
||||
val AccountDetails.isOAuth: Boolean
|
||||
get() = credentials_type == Credentials.Type.OAUTH || credentials_type == Credentials.Type.XAUTH
|
||||
|
||||
val AccountDetails.size_limit: UpdateStatusTask.SizeLimit
|
||||
val AccountDetails.mediaSizeLimit: UpdateStatusTask.SizeLimit
|
||||
get() = when (type) {
|
||||
AccountType.TWITTER -> {
|
||||
val imageLimit = AccountExtras.ImageLimit.ofSize(2048, 1536)
|
||||
|
@ -57,3 +59,36 @@ val AccountDetails.size_limit: UpdateStatusTask.SizeLimit
|
|||
}
|
||||
else -> UpdateStatusTask.SizeLimit(AccountExtras.ImageLimit(), AccountExtras.VideoLimit.unsupported())
|
||||
}
|
||||
/**
|
||||
* Text limit when composing a status, 0 for no limit
|
||||
*/
|
||||
val AccountDetails.textLimit: Int get() {
|
||||
if (type == null) {
|
||||
return Validator.MAX_TWEET_LENGTH
|
||||
}
|
||||
when (type) {
|
||||
AccountType.STATUSNET -> {
|
||||
val extras = this.extras as? StatusNetAccountExtras
|
||||
if (extras != null) {
|
||||
return extras.textLimit
|
||||
}
|
||||
}
|
||||
}
|
||||
return Validator.MAX_TWEET_LENGTH
|
||||
}
|
||||
|
||||
val Array<AccountDetails>.textLimit: Int
|
||||
get() {
|
||||
var limit = -1
|
||||
forEach { details ->
|
||||
val currentLimit = details.textLimit
|
||||
if (currentLimit != 0) {
|
||||
if (limit <= 0) {
|
||||
limit = currentLimit
|
||||
} else {
|
||||
limit = Math.min(limit, currentLimit)
|
||||
}
|
||||
}
|
||||
}
|
||||
return limit
|
||||
}
|
|
@ -22,6 +22,7 @@ package org.mariotaku.twidere.fragment
|
|||
import android.content.Context
|
||||
import android.support.v4.app.DialogFragment
|
||||
import com.squareup.otto.Bus
|
||||
import com.twitter.Validator
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
|
@ -39,7 +40,7 @@ open class BaseDialogFragment : DialogFragment() {
|
|||
@Inject
|
||||
lateinit var kPreferences: KPreferences
|
||||
@Inject
|
||||
lateinit var validator: TwidereValidator
|
||||
lateinit var validator: Validator
|
||||
@Inject
|
||||
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
|
||||
@Inject
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.os.Bundle
|
|||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.text.BidiFormatter
|
||||
import com.squareup.otto.Bus
|
||||
import com.twitter.Validator
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.util.*
|
||||
|
@ -57,7 +58,7 @@ open class BaseFragment : Fragment(), IBaseFragment<BaseFragment> {
|
|||
@Inject
|
||||
lateinit var errorInfoStore: ErrorInfoStore
|
||||
@Inject
|
||||
lateinit var validator: TwidereValidator
|
||||
lateinit var validator: Validator
|
||||
@Inject
|
||||
lateinit var extraFeaturesService: ExtraFeaturesService
|
||||
@Inject
|
||||
|
|
|
@ -44,13 +44,13 @@ import org.mariotaku.twidere.annotation.AccountType
|
|||
import org.mariotaku.twidere.constant.IntentConstants.*
|
||||
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_QUICK_SEND
|
||||
import org.mariotaku.twidere.extension.applyTheme
|
||||
import org.mariotaku.twidere.extension.model.textLimit
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.service.LengthyOperationsService
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.EditTextEnterHandler
|
||||
import org.mariotaku.twidere.util.LinkCreator
|
||||
import org.mariotaku.twidere.util.TwidereValidator
|
||||
import org.mariotaku.twidere.util.Utils.isMyRetweet
|
||||
import org.mariotaku.twidere.view.ComposeEditText
|
||||
import org.mariotaku.twidere.view.StatusTextCountView
|
||||
|
@ -95,7 +95,7 @@ class RetweetQuoteDialogFragment : BaseDialogFragment() {
|
|||
val holder = StatusViewHolder(adapter, itemContent)
|
||||
holder.displayStatus(status = status, displayInReplyTo = false, displayExtraType = true)
|
||||
|
||||
textCountView.maxLength = TwidereValidator.getTextLimit(details)
|
||||
textCountView.maxLength = details.textLimit
|
||||
|
||||
itemMenu.visibility = View.GONE
|
||||
actionButtons.visibility = View.GONE
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.mariotaku.twidere.service
|
|||
|
||||
import android.app.IntentService
|
||||
import com.twitter.Extractor
|
||||
import com.twitter.Validator
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
|
||||
import javax.inject.Inject
|
||||
|
@ -15,7 +16,7 @@ abstract class BaseIntentService(tag: String) : IntentService(tag) {
|
|||
@Inject
|
||||
lateinit var notificationManager: NotificationManagerWrapper
|
||||
@Inject
|
||||
lateinit var validator: TwidereValidator
|
||||
lateinit var validator: Validator
|
||||
@Inject
|
||||
lateinit var extractor: Extractor
|
||||
@Inject
|
||||
|
|
|
@ -37,7 +37,8 @@ import org.mariotaku.twidere.TwidereConstants.*
|
|||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.app.TwidereApplication
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.extension.model.size_limit
|
||||
import org.mariotaku.twidere.extension.model.mediaSizeLimit
|
||||
import org.mariotaku.twidere.extension.model.textLimit
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.account.AccountExtras
|
||||
import org.mariotaku.twidere.model.analyzer.UpdateStatus
|
||||
|
@ -213,7 +214,7 @@ class UpdateStatusTask(
|
|||
for (i in 0 until pending.length) {
|
||||
val account = update.accounts[i]
|
||||
val text = pending.overrideTexts[i]
|
||||
val textLimit = TwidereValidator.getTextLimit(account)
|
||||
val textLimit = account.textLimit
|
||||
if (textLimit >= 0 && text.length <= textLimit) {
|
||||
continue
|
||||
}
|
||||
|
@ -262,7 +263,7 @@ class UpdateStatusTask(
|
|||
if (statusUpdate.media.isNotNullOrEmpty()) {
|
||||
// Fanfou only allow one photo
|
||||
fanfouUpdateStatusWithPhoto(microBlog, statusUpdate, pendingUpdate,
|
||||
pendingUpdate.overrideTexts[i], account.size_limit, i)
|
||||
pendingUpdate.overrideTexts[i], account.mediaSizeLimit, i)
|
||||
} else {
|
||||
twitterUpdateStatus(microBlog, statusUpdate, pendingUpdate,
|
||||
pendingUpdate.overrideTexts[i], i)
|
||||
|
@ -647,7 +648,7 @@ class UpdateStatusTask(
|
|||
//noinspection TryWithIdenticalCatches
|
||||
var body: MediaStreamBody? = null
|
||||
try {
|
||||
val sizeLimit = account.size_limit
|
||||
val sizeLimit = account.mediaSizeLimit
|
||||
body = getBodyFromMedia(context, mediaLoader, media, sizeLimit,
|
||||
chucked, ContentLengthInputStream.ReadListener { length, position ->
|
||||
callback?.onUploadingProgressChanged(index, position, length)
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.nostra13.universalimageloader.utils.L
|
|||
import com.squareup.otto.Bus
|
||||
import com.squareup.otto.ThreadEnforcer
|
||||
import com.twitter.Extractor
|
||||
import com.twitter.Validator
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import edu.tsinghua.hotmobi.HotMobiLogger
|
||||
|
@ -233,8 +234,8 @@ class ApplicationModule(private val application: Application) {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun twidereValidator(): TwidereValidator {
|
||||
return TwidereValidator()
|
||||
fun validator(): Validator {
|
||||
return Validator()
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.mariotaku.twidere.util.dagger
|
||||
|
||||
import android.content.Context
|
||||
import com.twitter.Validator
|
||||
import edu.tsinghua.hotmobi.HotMobiLogger
|
||||
import okhttp3.ConnectionPool
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
|
@ -52,7 +53,7 @@ class DependencyHolder internal constructor(context: Context) {
|
|||
lateinit var dns: TwidereDns
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var validator: TwidereValidator
|
||||
lateinit var validator: Validator
|
||||
internal set
|
||||
@Inject
|
||||
lateinit var preferences: SharedPreferencesWrapper
|
||||
|
|
Loading…
Reference in New Issue