updated version code

This commit is contained in:
Mariotaku Lee 2016-02-13 21:00:54 +08:00
parent 0003e62ba1
commit 978b494c42
6 changed files with 7 additions and 345 deletions

View File

@ -23,7 +23,7 @@ android {
applicationId "org.mariotaku.twidere"
minSdkVersion 14
targetSdkVersion 23
versionCode 143
versionCode 144
versionName "3.0.5 (snapshot)"
multiDexEnabled true
@ -110,6 +110,7 @@ dependencies {
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
compile 'com.github.mariotaku:PickNCrop:0.9.3'
compile 'com.github.mariotaku.RestFu:library:0.9.19'
compile 'com.github.mariotaku.RestFu:okhttp3:0.9.19'
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.lnikkila:extendedtouchview:0.1.0'
compile 'com.google.dagger:dagger:2.0.2'

View File

@ -44,7 +44,7 @@ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
flatDir { dirs "$projectDir/lib" }
}
@@ -122,10 +122,10 @@
@@ -123,10 +123,10 @@
compile project(':twidere.component.common')
compile project(':twidere.component.nyan')

View File

@ -112,6 +112,7 @@ public class NetworkDiagnosticsFragment extends BaseFragment {
publishProgress(new LogText("version_code: " + BuildConfig.VERSION_CODE), LogText.LINEBREAK);
publishProgress(new LogText("version_name: " + BuildConfig.VERSION_NAME), LogText.LINEBREAK);
publishProgress(new LogText("flavor: " + BuildConfig.FLAVOR), LogText.LINEBREAK);
publishProgress(new LogText("debug: " + BuildConfig.DEBUG), LogText.LINEBREAK);
publishProgress(LogText.LINEBREAK);
publishProgress(new LogText("Basic system information: "));
publishProgress(new LogText(String.valueOf(mContext.getResources().getConfiguration())));

View File

@ -7,9 +7,9 @@ import android.text.TextUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.mariotaku.restfu.http.RestHttpClient;
import org.mariotaku.restfu.okhttp.OkHttpRestClient;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.util.dagger.DependencyHolder;
import org.mariotaku.twidere.util.net.OkHttpRestClient;
import org.mariotaku.twidere.util.net.TwidereProxySelector;
import java.io.IOException;
@ -54,7 +54,7 @@ public class HttpClientFactory implements Constants {
final ConnectionPool connectionPool) {
final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false);
builder.connectTimeout(prefs.getInt(KEY_CONNECTION_TIMEOUT, 10), TimeUnit.SECONDS);
builder.retryOnConnectionFailure(false);
builder.retryOnConnectionFailure(true);
builder.connectionPool(connectionPool);
if (enableProxy) {
final String proxyType = prefs.getString(KEY_PROXY_TYPE, null);

View File

@ -40,11 +40,11 @@ import org.mariotaku.restfu.http.MultiValueMap;
import org.mariotaku.restfu.http.RestHttpClient;
import org.mariotaku.restfu.http.mime.FormBody;
import org.mariotaku.restfu.http.mime.SimpleBody;
import org.mariotaku.restfu.okhttp.OkHttpRestClient;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.TwitterOAuth;
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
import org.mariotaku.twidere.util.net.OkHttpRestClient;
import org.mariotaku.twidere.util.net.SimpleCookieJar;
import java.io.IOException;

View File

@ -1,340 +0,0 @@
/*
* Copyright (c) 2015 mariotaku
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mariotaku.twidere.util.net;
import org.mariotaku.restfu.Pair;
import org.mariotaku.restfu.http.ContentType;
import org.mariotaku.restfu.http.HttpCall;
import org.mariotaku.restfu.http.HttpCallback;
import org.mariotaku.restfu.http.HttpRequest;
import org.mariotaku.restfu.http.HttpResponse;
import org.mariotaku.restfu.http.MultiValueMap;
import org.mariotaku.restfu.http.RestHttpClient;
import org.mariotaku.restfu.http.mime.Body;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RealCallAccessor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.http.HttpEngine;
import okio.BufferedSink;
import okio.Okio;
/**
* Created by mariotaku on 16/2/4.
*/
public class OkHttpRestClient implements RestHttpClient {
private OkHttpClient client;
public OkHttpRestClient(OkHttpClient client) {
setClient(client);
}
@Override
public HttpCall newCall(final HttpRequest httpRequest) {
final Request.Builder builder = new Request.Builder();
final OkRequestBody requestBody = OkRequestBody.wrap(httpRequest.getBody());
builder.method(httpRequest.getMethod(), requestBody);
builder.url(httpRequest.getUrl());
final MultiValueMap<String> headers = httpRequest.getHeaders();
if (headers != null) {
for (Pair<String, String> header : headers.toList()) {
builder.addHeader(header.first, header.second);
}
}
final OkCall call = new OkCall(this, client.newCall(builder.build()));
if (requestBody != null) {
requestBody.setCall(call);
}
return call;
}
@Override
public void enqueue(final HttpCall call, final HttpCallback callback) {
call.enqueue(callback);
}
public OkHttpClient getClient() {
return client;
}
public void setClient(OkHttpClient client) {
if (client == null) throw new NullPointerException();
this.client = client;
}
static class OkRequestBody extends RequestBody {
private final Body body;
private OkCall call;
public OkRequestBody(Body body) {
this.body = body;
}
public static OkRequestBody wrap(Body body) {
if (body == null) return null;
return new OkRequestBody(body);
}
@Override
public MediaType contentType() {
final ContentType contentType = body.contentType();
if (contentType == null) return null;
return MediaType.parse(contentType.toHeader());
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
call.setEstablished(true);
body.writeTo(sink.outputStream());
}
@Override
public long contentLength() throws IOException {
return body.length();
}
public void setCall(OkCall call) {
this.call = call;
}
}
private static class OkResponse extends HttpResponse {
private final Response response;
private Body body;
public OkResponse(Response response) {
this.response = response;
}
@Override
public int getStatus() {
return response.code();
}
@Override
public MultiValueMap<String> getHeaders() {
final Headers headers = response.headers();
return new MultiValueMap<>(headers.toMultimap(), true);
}
@Override
public String getHeader(String name) {
return response.header(name);
}
@Override
public List<String> getHeaders(String name) {
return response.headers(name);
}
@Override
public Body getBody() {
if (body != null) return body;
return body = new OkResponseBody(response.body());
}
@Override
public void close() throws IOException {
if (body != null) {
body.close();
body = null;
}
}
}
private static class OkResponseBody implements Body {
private final ResponseBody body;
public OkResponseBody(ResponseBody body) {
this.body = body;
}
@Override
public ContentType contentType() {
final MediaType mediaType = body.contentType();
if (mediaType == null) return null;
return ContentType.parse(mediaType.toString());
}
@Override
public String contentEncoding() {
return null;
}
@Override
public long length() throws IOException {
return body.contentLength();
}
@Override
public long writeTo(OutputStream os) throws IOException {
final BufferedSink sink = Okio.buffer(Okio.sink(os));
final long result = sink.writeAll(body.source());
sink.flush();
return result;
}
@Override
public InputStream stream() throws IOException {
return body.byteStream();
}
@Override
public void close() throws IOException {
body.close();
}
}
static class OkCall implements HttpCall {
private final OkHttpRestClient client;
private final Call call;
private boolean established;
public OkCall(OkHttpRestClient client, Call call) {
this.client = client;
this.call = call;
}
@Override
public HttpResponse execute() throws IOException {
final RequestRunnable runnable = new RequestRunnable(this, client.client.connectTimeoutMillis());
final Thread thread = new Thread(runnable);
thread.setPriority(Thread.currentThread().getPriority());
thread.start();
while (runnable.shouldWait()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// Ignore
}
}
return new OkResponse(runnable.getResponse());
}
@Override
public void enqueue(HttpCallback callback) {
call.enqueue(new OkCallback(callback));
}
public void cancel() {
call.cancel();
}
@Override
public boolean isCanceled() {
return call.isCanceled();
}
@Override
public void close() throws IOException {
}
boolean isEstablished() {
return established;
}
void setEstablished(boolean established) {
this.established = established;
}
private static class RequestRunnable implements Runnable {
private final OkCall call;
private final long timeout;
private long start = -1;
private Response response;
private IOException exception;
private boolean finished;
public RequestRunnable(OkCall call, long timeout) {
this.call = call;
this.timeout = timeout;
}
@Override
public void run() {
finished = false;
call.setEstablished(false);
start = System.currentTimeMillis();
try {
response = call.call.execute();
} catch (IOException e) {
exception = e;
}
finished = true;
}
public boolean shouldWait() {
return !finished && (start < 0 || call.isEstablished() || !reachedTimeout());
}
private boolean reachedTimeout() {
return System.currentTimeMillis() - start > timeout;
}
public Response getResponse() throws IOException {
if (exception != null) throw exception;
if (response == null) {
if (reachedTimeout()) {
final SocketTimeoutException exception = new SocketTimeoutException("Request timed out after " + timeout + " ms");
final HttpEngine httpEngine = RealCallAccessor.getHttpEngine(call.call);
if (httpEngine != null) {
httpEngine.streamAllocation.connectionFailed(exception);
}
throw exception;
} else {
throw new IOException("Request cancelled");
}
}
return response;
}
}
}
private static class OkCallback implements Callback {
private final HttpCallback callback;
public OkCallback(HttpCallback callback) {
this.callback = callback;
}
@Override
public void onFailure(Call call, IOException e) {
this.callback.failure(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
this.callback.response(new OkResponse(response));
}
}
}