fixed status shortener

This commit is contained in:
Mariotaku Lee 2016-12-07 22:01:27 +08:00
parent 6d315e1c89
commit 2cf8733ba9
3 changed files with 15 additions and 12 deletions

View File

@ -254,6 +254,7 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
String PERMISSION_READ = "read";
String PERMISSION_WRITE = "write";
String PERMISSION_DIRECT_MESSAGES = "direct_messages";
@Deprecated
String PERMISSION_ACCOUNTS = "accounts";
String PERMISSION_PREFERENCES = "preferences";

View File

@ -89,6 +89,7 @@ public abstract class AbsServiceInterface<I extends IInterface> implements IInte
mDisconnected = true;
mToken = ServiceUtils.bindToService(mContext, intent, mConnection);
if (mToken == null) return false;
mDisconnected = false;
while (mIInterface == null && !mDisconnected) {
try {
Thread.sleep(50L);

View File

@ -164,10 +164,11 @@ class UpdateStatusTask(
val accountKey = account.key
var uploadResult: MediaUploadResult? = sharedMedia[accountKey]
if (uploadResult == null) {
uploadResult = uploader.upload(update, accountKey, media)
if (uploadResult == null) {
// TODO error handling
continue
uploadResult = uploader.upload(update, accountKey, media) ?: run {
throw UploadException()
}
if (uploadResult.media_uris == null) {
throw UploadException(uploadResult.error_message ?: "Unknown error")
}
pending.mediaUploadResults[i] = uploadResult
if (uploadResult.shared_owners != null) {
@ -182,6 +183,7 @@ class UpdateStatusTask(
}
}
@Throws(UpdateStatusException::class)
private fun shortenStatus(shortener: StatusShortenerInterface?,
update: ParcelableStatusUpdate,
pending: PendingStatusUpdate) {
@ -194,10 +196,11 @@ class UpdateStatusTask(
val accountKey = account.key
var shortenResult: StatusShortenResult? = sharedShortened[accountKey]
if (shortenResult == null) {
shortenResult = shortener.shorten(update, accountKey, pending.overrideTexts[i])
if (shortenResult == null) {
// TODO error handling
continue
shortenResult = shortener.shorten(update, accountKey, pending.overrideTexts[i]) ?: run {
throw ShortenException()
}
if (shortenResult.shortened == null) {
throw ShortenException(shortenResult.error_message ?: "Unknown error")
}
pending.statusShortenResults[i] = shortenResult
if (shortenResult.shared_owners != null) {
@ -347,8 +350,7 @@ class UpdateStatusTask(
}
private fun statusShortenCallback(shortener: StatusShortenerInterface?, pendingUpdate: PendingStatusUpdate, updateResult: UpdateStatusResult) {
if (shortener == null) return
shortener.waitForService()
if (shortener == null || !shortener.waitForService()) return
for (i in 0..pendingUpdate.length - 1) {
val shortenResult = pendingUpdate.statusShortenResults[i]
val status = updateResult.statuses[i]
@ -358,8 +360,7 @@ class UpdateStatusTask(
}
private fun mediaUploadCallback(uploader: MediaUploaderInterface?, pendingUpdate: PendingStatusUpdate, updateResult: UpdateStatusResult) {
if (uploader == null) return
uploader.waitForService()
if (uploader == null || !uploader.waitForService()) return
for (i in 0..pendingUpdate.length - 1) {
val uploadResult = pendingUpdate.mediaUploadResults[i]
val status = updateResult.statuses[i]