bug fixes
This commit is contained in:
parent
ea9efc2fb8
commit
8051556245
|
@ -2,6 +2,7 @@ apply plugin: 'com.github.ben-manes.versions'
|
|||
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.0.2'
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url 'https://plugins.gradle.org/m2/' }
|
||||
|
@ -15,6 +16,7 @@ buildscript {
|
|||
// should be excluded to avoid conflict
|
||||
exclude group: 'xerces'
|
||||
}
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ public class LinkHandlerActivity extends BaseActivity implements SystemWindowsIn
|
|||
private boolean mFinishOnly;
|
||||
private int mActionBarHeight;
|
||||
private CharSequence mSubtitle;
|
||||
private boolean mHideOffsetNotSupported;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -268,8 +269,13 @@ public class LinkHandlerActivity extends BaseActivity implements SystemWindowsIn
|
|||
ActionBar actionBar = getSupportActionBar();
|
||||
if (fragment instanceof IToolBarSupportFragment) {
|
||||
((IToolBarSupportFragment) fragment).setControlBarOffset(offset);
|
||||
} else if (actionBar != null) {
|
||||
actionBar.setHideOffset((int) (getControlBarHeight() * offset));
|
||||
} else if (actionBar != null && !mHideOffsetNotSupported) {
|
||||
try {
|
||||
actionBar.setHideOffset((int) (getControlBarHeight() * offset));
|
||||
} catch (UnsupportedOperationException e) {
|
||||
// Some device will throw this exception
|
||||
mHideOffsetNotSupported = true;
|
||||
}
|
||||
}
|
||||
notifyControlBarOffsetChanged();
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public interface IControlBarActivity {
|
|||
|
||||
final class ControlBarShowHideHelper {
|
||||
|
||||
private static final long DURATION = 200l;
|
||||
private static final long DURATION = 200L;
|
||||
|
||||
private final IControlBarActivity mActivity;
|
||||
private int mControlAnimationDirection;
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.content.ContentValues;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
|
@ -76,7 +75,6 @@ import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages;
|
|||
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts;
|
||||
import org.mariotaku.twidere.task.twitter.UpdateStatusTask;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.BitmapUtils;
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator;
|
||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory;
|
||||
import org.mariotaku.twidere.util.NotificationManagerWrapper;
|
||||
|
@ -84,11 +82,9 @@ import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
|||
import org.mariotaku.twidere.util.TwidereValidator;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
||||
import org.mariotaku.twidere.util.io.ContentLengthInputStream;
|
||||
import org.mariotaku.twidere.util.io.ContentLengthInputStream.ReadListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -335,7 +331,7 @@ public class BackgroundOperationService extends IntentService implements Constan
|
|||
startForeground(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotification(context,
|
||||
builder, 0, null));
|
||||
for (final ParcelableStatusUpdate item : statuses) {
|
||||
UpdateStatusTask task = new UpdateStatusTask(context, new UpdateStatusTask.StateCallback() {
|
||||
final UpdateStatusTask task = new UpdateStatusTask(context, new UpdateStatusTask.StateCallback() {
|
||||
|
||||
@Override
|
||||
public void onStartUploadingMedia() {
|
||||
|
@ -363,16 +359,28 @@ public class BackgroundOperationService extends IntentService implements Constan
|
|||
}
|
||||
});
|
||||
task.setParams(Pair.create(actionType, item));
|
||||
UpdateStatusTask.UpdateStatusResult result = ManualTaskStarter.invokeExecute(task);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ManualTaskStarter.invokeBeforeExecute(task);
|
||||
}
|
||||
});
|
||||
|
||||
final UpdateStatusTask.UpdateStatusResult result = ManualTaskStarter.invokeExecute(task);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ManualTaskStarter.invokeAfterExecute(task, result);
|
||||
}
|
||||
});
|
||||
|
||||
if (result.exception != null) {
|
||||
Log.w(LOGTAG, result.exception);
|
||||
} else {
|
||||
for (ParcelableStatus status : result.statuses) {
|
||||
if (status == null) continue;
|
||||
final TweetEvent event = TweetEvent.create(context, status, TimelineType.OTHER);
|
||||
event.setAction(TweetEvent.Action.TWEET);
|
||||
HotMobiLogger.getInstance(context).log(status.account_key, event);
|
||||
}
|
||||
} else for (ParcelableStatus status : result.statuses) {
|
||||
if (status == null) continue;
|
||||
final TweetEvent event = TweetEvent.create(context, status, TimelineType.OTHER);
|
||||
event.setAction(TweetEvent.Action.TWEET);
|
||||
HotMobiLogger.getInstance(context).log(status.account_key, event);
|
||||
}
|
||||
}
|
||||
if (mPreferences.getBoolean(KEY_REFRESH_AFTER_TWEET)) {
|
||||
|
@ -413,32 +421,26 @@ public class BackgroundOperationService extends IntentService implements Constan
|
|||
}
|
||||
default: {
|
||||
if (imageUri != null) {
|
||||
final String path = getImagePathFromUri(this, Uri.parse(imageUri));
|
||||
if (path == null) throw new FileNotFoundException();
|
||||
final BitmapFactory.Options o = new BitmapFactory.Options();
|
||||
o.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(path, o);
|
||||
final File file = new File(path);
|
||||
BitmapUtils.downscaleImageIfNeeded(file, 100);
|
||||
ContentLengthInputStream is = null;
|
||||
final Uri mediaUri = Uri.parse(imageUri);
|
||||
FileBody body = null;
|
||||
try {
|
||||
is = new ContentLengthInputStream(file);
|
||||
is.setReadListener(new MessageMediaUploadListener(this, mNotificationManager,
|
||||
builder, text));
|
||||
body = new FileBody(is, file.getName(), file.length(),
|
||||
ContentType.parse(o.outMimeType));
|
||||
body = UpdateStatusTask.getBodyFromMedia(getContentResolver(), mediaUri,
|
||||
new MessageMediaUploadListener(this, mNotificationManager,
|
||||
builder, text));
|
||||
final MediaUploadResponse uploadResp = uploadMedia(twitterUpload, body);
|
||||
final DirectMessage response = twitter.sendDirectMessage(recipientId,
|
||||
text, uploadResp.getId());
|
||||
directMessage = ParcelableDirectMessageUtils.fromDirectMessage(response,
|
||||
accountKey, true);
|
||||
} finally {
|
||||
Utils.closeSilently(is);
|
||||
Utils.closeSilently(body);
|
||||
}
|
||||
if (!file.delete()) {
|
||||
Log.d(LOGTAG, String.format("unable to delete %s", path));
|
||||
final String path = getImagePathFromUri(this, mediaUri);
|
||||
if (path != null) {
|
||||
final File file = new File(path);
|
||||
if (!file.delete()) {
|
||||
Log.d(LOGTAG, String.format("unable to delete %s", path));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final DirectMessage response = twitter.sendDirectMessage(recipientId, text);
|
||||
|
|
|
@ -117,8 +117,12 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
uploadMedia(uploader, update, pendingUpdate);
|
||||
shortenStatus(shortener, update, pendingUpdate);
|
||||
|
||||
final UpdateStatusResult result = requestUpdateStatus(update, pendingUpdate);
|
||||
|
||||
final UpdateStatusResult result;
|
||||
try {
|
||||
result = requestUpdateStatus(update, pendingUpdate);
|
||||
} catch (IOException e) {
|
||||
return new UpdateStatusResult(new UpdateStatusException(e));
|
||||
}
|
||||
|
||||
mediaUploadCallback(uploader, pendingUpdate, result);
|
||||
statusShortenCallback(shortener, pendingUpdate, result);
|
||||
|
@ -223,16 +227,17 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
}
|
||||
|
||||
@NonNull
|
||||
private UpdateStatusResult requestUpdateStatus(ParcelableStatusUpdate statusUpdate, PendingStatusUpdate pendingUpdate) {
|
||||
private UpdateStatusResult requestUpdateStatus(ParcelableStatusUpdate statusUpdate, PendingStatusUpdate pendingUpdate) throws IOException {
|
||||
|
||||
stateCallback.onUpdatingStatus();
|
||||
|
||||
UpdateStatusResult result = new UpdateStatusResult(new ParcelableStatus[pendingUpdate.length],
|
||||
new Exception[pendingUpdate.length]);
|
||||
new MicroBlogException[pendingUpdate.length]);
|
||||
|
||||
for (int i = 0; i < pendingUpdate.length; i++) {
|
||||
final ParcelableAccount account = statusUpdate.accounts[i];
|
||||
MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, account.account_key, true);
|
||||
Body body = null;
|
||||
try {
|
||||
switch (ParcelableAccountUtils.getAccountType(account)) {
|
||||
case ParcelableAccount.Type.FANFOU: {
|
||||
|
@ -240,15 +245,15 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
if (!ArrayUtils.isEmpty(statusUpdate.media)) {
|
||||
// Fanfou only allow one photo
|
||||
if (statusUpdate.media.length > 1) {
|
||||
result.exceptions[i] = new UpdateStatusException(
|
||||
result.exceptions[i] = new MicroBlogException(
|
||||
context.getString(R.string.error_too_many_photos_fanfou));
|
||||
break;
|
||||
}
|
||||
final Body body = getBodyFromMedia(context.getContentResolver(),
|
||||
statusUpdate.media[0], new ContentLengthInputStream.ReadListener() {
|
||||
body = getBodyFromMedia(context.getContentResolver(),
|
||||
Uri.parse(statusUpdate.media[0].uri), new ContentLengthInputStream.ReadListener() {
|
||||
@Override
|
||||
public void onRead(long length, long position) {
|
||||
|
||||
stateCallback.onUploadingProgressChanged(-1, position, length);
|
||||
}
|
||||
});
|
||||
PhotoStatusUpdate photoUpdate = new PhotoStatusUpdate(body,
|
||||
|
@ -277,8 +282,8 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
}
|
||||
} catch (MicroBlogException e) {
|
||||
result.exceptions[i] = e;
|
||||
} catch (IOException e) {
|
||||
result.exceptions[i] = e;
|
||||
} finally {
|
||||
Utils.closeSilently(body);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -441,9 +446,10 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
ParcelableMediaUpdate media = update.media[i];
|
||||
final MediaUploadResponse resp;
|
||||
//noinspection TryWithIdenticalCatches
|
||||
Body body = null;
|
||||
try {
|
||||
final int index = i;
|
||||
final Body body = getBodyFromMedia(context.getContentResolver(), media, new ContentLengthInputStream.ReadListener() {
|
||||
body = getBodyFromMedia(context.getContentResolver(), Uri.parse(media.uri), new ContentLengthInputStream.ReadListener() {
|
||||
@Override
|
||||
public void onRead(long length, long position) {
|
||||
stateCallback.onUploadingProgressChanged(index, position, length);
|
||||
|
@ -458,6 +464,8 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
throw new UploadException(e);
|
||||
} catch (MicroBlogException e) {
|
||||
throw new UploadException(e);
|
||||
} finally {
|
||||
Utils.closeSilently(body);
|
||||
}
|
||||
mediaIds[i] = resp.getId();
|
||||
}
|
||||
|
@ -504,14 +512,14 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
}
|
||||
|
||||
|
||||
private FileBody getBodyFromMedia(final ContentResolver resolver,
|
||||
final ParcelableMediaUpdate media,
|
||||
final ContentLengthInputStream.ReadListener readListener) throws IOException {
|
||||
final Uri mediaUri = Uri.parse(media.uri);
|
||||
public static FileBody getBodyFromMedia(@NonNull final ContentResolver resolver,
|
||||
@NonNull final Uri mediaUri,
|
||||
@NonNull final ContentLengthInputStream.ReadListener
|
||||
readListener) throws IOException {
|
||||
final String mediaType = resolver.getType(mediaUri);
|
||||
final InputStream is = resolver.openInputStream(mediaUri);
|
||||
if (is == null) {
|
||||
throw new FileNotFoundException(media.uri);
|
||||
throw new FileNotFoundException(mediaUri.toString());
|
||||
}
|
||||
final long length = is.available();
|
||||
final ContentLengthInputStream cis = new ContentLengthInputStream(is, length);
|
||||
|
@ -602,11 +610,11 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
@NonNull
|
||||
public final ParcelableStatus[] statuses;
|
||||
@NonNull
|
||||
public final Exception[] exceptions;
|
||||
public final MicroBlogException[] exceptions;
|
||||
|
||||
public final UpdateStatusException exception;
|
||||
|
||||
public UpdateStatusResult(@NonNull ParcelableStatus[] statuses, @NonNull Exception[] exceptions) {
|
||||
public UpdateStatusResult(@NonNull ParcelableStatus[] statuses, @NonNull MicroBlogException[] exceptions) {
|
||||
this.statuses = statuses;
|
||||
this.exceptions = exceptions;
|
||||
this.exception = null;
|
||||
|
@ -615,7 +623,7 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
|
|||
public UpdateStatusResult(UpdateStatusException exception) {
|
||||
this.exception = exception;
|
||||
this.statuses = new ParcelableStatus[0];
|
||||
this.exceptions = new Exception[0];
|
||||
this.exceptions = new MicroBlogException[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue