fixed upload media error

updated version code
This commit is contained in:
Mariotaku Lee 2015-09-01 18:44:45 +08:00
parent 63eb236c54
commit 05355969e9
5 changed files with 22 additions and 14 deletions

View File

@ -24,7 +24,7 @@ apply from: rootProject.file('global.gradle')
android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
@ -43,7 +43,7 @@ dependencies {
compile 'com.android.support:support-v4:23.0.0'
compile 'com.bluelinelabs:logansquare:1.1.0'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.github.mariotaku:RestFu:0.9.1'
compile 'com.github.mariotaku:RestFu:0.9.2'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.1'
compile 'com.github.mariotaku:SQLiteQB:ef3f596199'
compile fileTree(dir: 'libs', include: ['*.jar'])

View File

@ -14,7 +14,7 @@ android {
applicationId "org.mariotaku.twidere"
minSdkVersion 14
targetSdkVersion 23
versionCode 117
versionCode 118
versionName "0.3.0"
multiDexEnabled true
}
@ -71,7 +71,7 @@ dependencies {
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.1.4'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.pnikosis:materialish-progress:1.5'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.7'
compile 'com.github.johnpersano:supertoasts:1.3.4.1@aar'
compile 'com.github.mariotaku:MessageBubbleView:1.2'

View File

@ -284,8 +284,6 @@ public class BackgroundOperationService extends IntentService implements Constan
mResolver.delete(DirectMessages.Outbox.CONTENT_URI, delete_where, null);
mResolver.insert(DirectMessages.Outbox.CONTENT_URI, values);
showOkMessage(R.string.direct_message_sent, false);
} else {
final ContentValues values = createMessageDraft(accountId, recipientId, text, imageUri);
mResolver.insert(Drafts.CONTENT_URI, values);
@ -339,10 +337,9 @@ public class BackgroundOperationService extends IntentService implements Constan
} else if (data.account_id > 0) {
failedAccountIds.remove(data.account_id);
// BEGIN HotMobi
final TweetEvent event = TweetEvent.create(BackgroundOperationService.this, data,
TimelineType.OTHER);
final TweetEvent event = TweetEvent.create(this, data, TimelineType.OTHER);
event.setAction(TweetEvent.Action.TWEET);
HotMobiLogger.getInstance(BackgroundOperationService.this).log(data.account_id, event);
HotMobiLogger.getInstance(this).log(data.account_id, event);
// END HotMobi
}
}
@ -546,12 +543,14 @@ public class BackgroundOperationService extends IntentService implements Constan
} else {
contentType = ContentType.parse(o.outMimeType);
}
final MediaUploadResponse uploadResp = upload.uploadMedia(new FileTypedData(is, file.getName(), file.length(), contentType));
final MediaUploadResponse uploadResp = upload.uploadMedia(new FileTypedData(is,
file.getName(), file.length(), contentType));
mediaIds[i] = uploadResp.getId();
}
} catch (final FileNotFoundException e) {
Log.w(LOGTAG, e);
} catch (final TwitterException e) {
Log.w(LOGTAG, e);
final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e);
results.add(response);
continue;
@ -586,11 +585,13 @@ public class BackgroundOperationService extends IntentService implements Constan
final ParcelableStatus result = new ParcelableStatus(resultStatus, account.account_id, false);
results.add(SingleResponse.getInstance(result));
} catch (final TwitterException e) {
Log.w(LOGTAG, e);
final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e);
results.add(response);
}
}
} catch (final UpdateStatusException e) {
Log.w(LOGTAG, e);
final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e);
results.add(response);
}

View File

@ -37,13 +37,15 @@ import org.mariotaku.twidere.provider.TwidereDataStore.NetworkUsages;
import org.mariotaku.twidere.util.Utils;
import java.io.IOException;
import java.util.List;
/**
* Created by mariotaku on 15/6/24.
*/
public class NetworkUsageUtils implements Constants {
public static void initForHttpClient(Context context, OkHttpClient client) {
client.networkInterceptors().add(new NetworkUsageInterceptor(context));
final List<Interceptor> interceptors = client.networkInterceptors();
interceptors.add(new NetworkUsageInterceptor(context));
}
private static int sNetworkType;

View File

@ -36,7 +36,6 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import org.mariotaku.restfu.Utils;
import org.mariotaku.restfu.http.ContentType;
import org.mariotaku.restfu.http.RestHttpCallback;
import org.mariotaku.restfu.http.RestHttpClient;
@ -45,7 +44,9 @@ import org.mariotaku.restfu.http.RestHttpResponse;
import org.mariotaku.restfu.http.RestQueuedRequest;
import org.mariotaku.restfu.http.mime.TypedData;
import org.mariotaku.twidere.util.DebugModeUtils;
import org.mariotaku.twidere.util.Utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -54,6 +55,7 @@ import java.util.ArrayList;
import java.util.List;
import okio.BufferedSink;
import okio.Okio;
/**
* Created by mariotaku on 15/5/5.
@ -240,8 +242,11 @@ public class OkHttpRestClient implements RestHttpClient {
}
@Override
public void writeTo(@NonNull OutputStream os) throws IOException {
Utils.copyStream(stream(), os);
public long writeTo(@NonNull OutputStream os) throws IOException {
final BufferedSink sink = Okio.buffer(Okio.sink(os));
final long result = sink.writeAll(body.source());
sink.flush();
return result;
}
@NonNull