bug fixes

This commit is contained in:
Mariotaku Lee 2016-05-27 09:51:37 +08:00
parent ea9efc2fb8
commit 8051556245
5 changed files with 69 additions and 51 deletions

View File

@ -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. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.0.2'
repositories { repositories {
jcenter() jcenter()
maven { url 'https://plugins.gradle.org/m2/' } maven { url 'https://plugins.gradle.org/m2/' }
@ -15,6 +16,7 @@ buildscript {
// should be excluded to avoid conflict // should be excluded to avoid conflict
exclude group: 'xerces' exclude group: 'xerces'
} }
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }

View File

@ -74,6 +74,7 @@ public class LinkHandlerActivity extends BaseActivity implements SystemWindowsIn
private boolean mFinishOnly; private boolean mFinishOnly;
private int mActionBarHeight; private int mActionBarHeight;
private CharSequence mSubtitle; private CharSequence mSubtitle;
private boolean mHideOffsetNotSupported;
@Override @Override
@ -268,8 +269,13 @@ public class LinkHandlerActivity extends BaseActivity implements SystemWindowsIn
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (fragment instanceof IToolBarSupportFragment) { if (fragment instanceof IToolBarSupportFragment) {
((IToolBarSupportFragment) fragment).setControlBarOffset(offset); ((IToolBarSupportFragment) fragment).setControlBarOffset(offset);
} else if (actionBar != null) { } else if (actionBar != null && !mHideOffsetNotSupported) {
try {
actionBar.setHideOffset((int) (getControlBarHeight() * offset)); actionBar.setHideOffset((int) (getControlBarHeight() * offset));
} catch (UnsupportedOperationException e) {
// Some device will throw this exception
mHideOffsetNotSupported = true;
}
} }
notifyControlBarOffsetChanged(); notifyControlBarOffsetChanged();
} }

View File

@ -36,7 +36,7 @@ public interface IControlBarActivity {
final class ControlBarShowHideHelper { final class ControlBarShowHideHelper {
private static final long DURATION = 200l; private static final long DURATION = 200L;
private final IControlBarActivity mActivity; private final IControlBarActivity mActivity;
private int mControlAnimationDirection; private int mControlAnimationDirection;

View File

@ -26,7 +26,6 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Parcelable; 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.provider.TwidereDataStore.Drafts;
import org.mariotaku.twidere.task.twitter.UpdateStatusTask; import org.mariotaku.twidere.task.twitter.UpdateStatusTask;
import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.BitmapUtils;
import org.mariotaku.twidere.util.ContentValuesCreator; import org.mariotaku.twidere.util.ContentValuesCreator;
import org.mariotaku.twidere.util.MicroBlogAPIFactory; import org.mariotaku.twidere.util.MicroBlogAPIFactory;
import org.mariotaku.twidere.util.NotificationManagerWrapper; 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.TwidereValidator;
import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
import org.mariotaku.twidere.util.io.ContentLengthInputStream;
import org.mariotaku.twidere.util.io.ContentLengthInputStream.ReadListener; import org.mariotaku.twidere.util.io.ContentLengthInputStream.ReadListener;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -335,7 +331,7 @@ public class BackgroundOperationService extends IntentService implements Constan
startForeground(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotification(context, startForeground(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotification(context,
builder, 0, null)); builder, 0, null));
for (final ParcelableStatusUpdate item : statuses) { for (final ParcelableStatusUpdate item : statuses) {
UpdateStatusTask task = new UpdateStatusTask(context, new UpdateStatusTask.StateCallback() { final UpdateStatusTask task = new UpdateStatusTask(context, new UpdateStatusTask.StateCallback() {
@Override @Override
public void onStartUploadingMedia() { public void onStartUploadingMedia() {
@ -363,18 +359,30 @@ public class BackgroundOperationService extends IntentService implements Constan
} }
}); });
task.setParams(Pair.create(actionType, item)); 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) { if (result.exception != null) {
Log.w(LOGTAG, result.exception); Log.w(LOGTAG, result.exception);
} else { } else for (ParcelableStatus status : result.statuses) {
for (ParcelableStatus status : result.statuses) {
if (status == null) continue; if (status == null) continue;
final TweetEvent event = TweetEvent.create(context, status, TimelineType.OTHER); final TweetEvent event = TweetEvent.create(context, status, TimelineType.OTHER);
event.setAction(TweetEvent.Action.TWEET); event.setAction(TweetEvent.Action.TWEET);
HotMobiLogger.getInstance(context).log(status.account_key, event); HotMobiLogger.getInstance(context).log(status.account_key, event);
} }
} }
}
if (mPreferences.getBoolean(KEY_REFRESH_AFTER_TWEET)) { if (mPreferences.getBoolean(KEY_REFRESH_AFTER_TWEET)) {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
@ -413,33 +421,27 @@ public class BackgroundOperationService extends IntentService implements Constan
} }
default: { default: {
if (imageUri != null) { if (imageUri != null) {
final String path = getImagePathFromUri(this, Uri.parse(imageUri)); final Uri mediaUri = 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;
FileBody body = null; FileBody body = null;
try { try {
is = new ContentLengthInputStream(file); body = UpdateStatusTask.getBodyFromMedia(getContentResolver(), mediaUri,
is.setReadListener(new MessageMediaUploadListener(this, mNotificationManager, new MessageMediaUploadListener(this, mNotificationManager,
builder, text)); builder, text));
body = new FileBody(is, file.getName(), file.length(),
ContentType.parse(o.outMimeType));
final MediaUploadResponse uploadResp = uploadMedia(twitterUpload, body); final MediaUploadResponse uploadResp = uploadMedia(twitterUpload, body);
final DirectMessage response = twitter.sendDirectMessage(recipientId, final DirectMessage response = twitter.sendDirectMessage(recipientId,
text, uploadResp.getId()); text, uploadResp.getId());
directMessage = ParcelableDirectMessageUtils.fromDirectMessage(response, directMessage = ParcelableDirectMessageUtils.fromDirectMessage(response,
accountKey, true); accountKey, true);
} finally { } finally {
Utils.closeSilently(is);
Utils.closeSilently(body); Utils.closeSilently(body);
} }
final String path = getImagePathFromUri(this, mediaUri);
if (path != null) {
final File file = new File(path);
if (!file.delete()) { if (!file.delete()) {
Log.d(LOGTAG, String.format("unable to delete %s", path)); Log.d(LOGTAG, String.format("unable to delete %s", path));
} }
}
} else { } else {
final DirectMessage response = twitter.sendDirectMessage(recipientId, text); final DirectMessage response = twitter.sendDirectMessage(recipientId, text);
directMessage = ParcelableDirectMessageUtils.fromDirectMessage(response, directMessage = ParcelableDirectMessageUtils.fromDirectMessage(response,

View File

@ -117,8 +117,12 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
uploadMedia(uploader, update, pendingUpdate); uploadMedia(uploader, update, pendingUpdate);
shortenStatus(shortener, 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); mediaUploadCallback(uploader, pendingUpdate, result);
statusShortenCallback(shortener, pendingUpdate, result); statusShortenCallback(shortener, pendingUpdate, result);
@ -223,16 +227,17 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
} }
@NonNull @NonNull
private UpdateStatusResult requestUpdateStatus(ParcelableStatusUpdate statusUpdate, PendingStatusUpdate pendingUpdate) { private UpdateStatusResult requestUpdateStatus(ParcelableStatusUpdate statusUpdate, PendingStatusUpdate pendingUpdate) throws IOException {
stateCallback.onUpdatingStatus(); stateCallback.onUpdatingStatus();
UpdateStatusResult result = new UpdateStatusResult(new ParcelableStatus[pendingUpdate.length], UpdateStatusResult result = new UpdateStatusResult(new ParcelableStatus[pendingUpdate.length],
new Exception[pendingUpdate.length]); new MicroBlogException[pendingUpdate.length]);
for (int i = 0; i < pendingUpdate.length; i++) { for (int i = 0; i < pendingUpdate.length; i++) {
final ParcelableAccount account = statusUpdate.accounts[i]; final ParcelableAccount account = statusUpdate.accounts[i];
MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, account.account_key, true); MicroBlog microBlog = MicroBlogAPIFactory.getInstance(context, account.account_key, true);
Body body = null;
try { try {
switch (ParcelableAccountUtils.getAccountType(account)) { switch (ParcelableAccountUtils.getAccountType(account)) {
case ParcelableAccount.Type.FANFOU: { case ParcelableAccount.Type.FANFOU: {
@ -240,15 +245,15 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
if (!ArrayUtils.isEmpty(statusUpdate.media)) { if (!ArrayUtils.isEmpty(statusUpdate.media)) {
// Fanfou only allow one photo // Fanfou only allow one photo
if (statusUpdate.media.length > 1) { if (statusUpdate.media.length > 1) {
result.exceptions[i] = new UpdateStatusException( result.exceptions[i] = new MicroBlogException(
context.getString(R.string.error_too_many_photos_fanfou)); context.getString(R.string.error_too_many_photos_fanfou));
break; break;
} }
final Body body = getBodyFromMedia(context.getContentResolver(), body = getBodyFromMedia(context.getContentResolver(),
statusUpdate.media[0], new ContentLengthInputStream.ReadListener() { Uri.parse(statusUpdate.media[0].uri), new ContentLengthInputStream.ReadListener() {
@Override @Override
public void onRead(long length, long position) { public void onRead(long length, long position) {
stateCallback.onUploadingProgressChanged(-1, position, length);
} }
}); });
PhotoStatusUpdate photoUpdate = new PhotoStatusUpdate(body, PhotoStatusUpdate photoUpdate = new PhotoStatusUpdate(body,
@ -277,8 +282,8 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
} }
} catch (MicroBlogException e) { } catch (MicroBlogException e) {
result.exceptions[i] = e; result.exceptions[i] = e;
} catch (IOException e) { } finally {
result.exceptions[i] = e; Utils.closeSilently(body);
} }
} }
return result; return result;
@ -441,9 +446,10 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
ParcelableMediaUpdate media = update.media[i]; ParcelableMediaUpdate media = update.media[i];
final MediaUploadResponse resp; final MediaUploadResponse resp;
//noinspection TryWithIdenticalCatches //noinspection TryWithIdenticalCatches
Body body = null;
try { try {
final int index = i; 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 @Override
public void onRead(long length, long position) { public void onRead(long length, long position) {
stateCallback.onUploadingProgressChanged(index, position, length); stateCallback.onUploadingProgressChanged(index, position, length);
@ -458,6 +464,8 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
throw new UploadException(e); throw new UploadException(e);
} catch (MicroBlogException e) { } catch (MicroBlogException e) {
throw new UploadException(e); throw new UploadException(e);
} finally {
Utils.closeSilently(body);
} }
mediaIds[i] = resp.getId(); mediaIds[i] = resp.getId();
} }
@ -504,14 +512,14 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
} }
private FileBody getBodyFromMedia(final ContentResolver resolver, public static FileBody getBodyFromMedia(@NonNull final ContentResolver resolver,
final ParcelableMediaUpdate media, @NonNull final Uri mediaUri,
final ContentLengthInputStream.ReadListener readListener) throws IOException { @NonNull final ContentLengthInputStream.ReadListener
final Uri mediaUri = Uri.parse(media.uri); readListener) throws IOException {
final String mediaType = resolver.getType(mediaUri); final String mediaType = resolver.getType(mediaUri);
final InputStream is = resolver.openInputStream(mediaUri); final InputStream is = resolver.openInputStream(mediaUri);
if (is == null) { if (is == null) {
throw new FileNotFoundException(media.uri); throw new FileNotFoundException(mediaUri.toString());
} }
final long length = is.available(); final long length = is.available();
final ContentLengthInputStream cis = new ContentLengthInputStream(is, length); final ContentLengthInputStream cis = new ContentLengthInputStream(is, length);
@ -602,11 +610,11 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
@NonNull @NonNull
public final ParcelableStatus[] statuses; public final ParcelableStatus[] statuses;
@NonNull @NonNull
public final Exception[] exceptions; public final MicroBlogException[] exceptions;
public final UpdateStatusException exception; public final UpdateStatusException exception;
public UpdateStatusResult(@NonNull ParcelableStatus[] statuses, @NonNull Exception[] exceptions) { public UpdateStatusResult(@NonNull ParcelableStatus[] statuses, @NonNull MicroBlogException[] exceptions) {
this.statuses = statuses; this.statuses = statuses;
this.exceptions = exceptions; this.exceptions = exceptions;
this.exception = null; this.exception = null;
@ -615,7 +623,7 @@ public class UpdateStatusTask extends AbstractTask<Pair<String, ParcelableStatus
public UpdateStatusResult(UpdateStatusException exception) { public UpdateStatusResult(UpdateStatusException exception) {
this.exception = exception; this.exception = exception;
this.statuses = new ParcelableStatus[0]; this.statuses = new ParcelableStatus[0];
this.exceptions = new Exception[0]; this.exceptions = new MicroBlogException[0];
} }
} }