Commit c22c8f0a authored by Rafael Kellermann Streit's avatar Rafael Kellermann Streit Committed by GitHub

Merge pull request #407 from filipedelimabrito/iss287

Update Stetho version/build configuration.
parents 6d4ef307 a6980d0e
......@@ -3,9 +3,7 @@ apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
maven { url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' }
}
apply plugin: 'kotlin-android'
......@@ -64,7 +62,16 @@ android {
}
buildTypes {
debug {
debuggable true
versionNameSuffix '-DEBUG'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
......@@ -86,6 +93,16 @@ android {
//avoiding okio error: https://github.com/square/okhttp/issues/896
lintConfig file("lint.xml")
}
sourceSets {
debug {
manifest.srcFile 'src/debug/AndroidManifest.xml'
}
release {
manifest.srcFile 'src/release/AndroidManifest.xml'
}
}
}
play {
......@@ -95,7 +112,9 @@ play {
ext {
playLibVersion = '11.0.4'
stethoVersion = '1.4.2'
stethoVersion = '1.5.0'
stethoOkhttp3Version = '1.5.0'
stethoRealmVersion = '2.1.0'
rxbindingVersion = '2.0.0'
rxlifecycleVersion = '2.1.0'
icepickVersion = '3.2.0'
......@@ -124,9 +143,9 @@ dependencies {
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile "com.facebook.stetho:stetho:$stethoVersion"
compile "com.facebook.stetho:stetho-okhttp3:$stethoVersion"
compile 'com.uphyca:stetho_realm:2.1.0'
debugCompile "com.facebook.stetho:stetho:$stethoVersion"
debugCompile "com.facebook.stetho:stetho-okhttp3:$stethoOkhttp3Version"
debugCompile "com.uphyca:stetho_realm:$stethoRealmVersion"
compile "com.jakewharton.rxbinding2:rxbinding:$rxbindingVersion"
compile "com.jakewharton.rxbinding2:rxbinding-support-v4:$rxbindingVersion"
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="chat.rocket.android"
xmlns:tools="http://schemas.android.com/tools">
<application
tools:replace="android:name"
android:name=".RocketChatApplicationDebug"/>
</manifest>
\ No newline at end of file
package chat.rocket.android;
import android.os.StrictMode;
import com.facebook.stetho.Stetho;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;
public class RocketChatApplicationDebug extends RocketChatApplication {
@Override
public void onCreate() {
super.onCreate();
enableStrictMode();
enableStetho();
}
private void enableStrictMode() {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
}
private void enableStetho() {
Stetho.initialize(Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
.build());
}
}
package chat.rocket.android.helper
import android.content.Context
import chat.rocket.android.RocketChatCache
import chat.rocket.android.api.rest.CookieInterceptor
import chat.rocket.android.api.rest.DefaultCookieProvider
import com.facebook.stetho.okhttp3.StethoInterceptor
import java.util.concurrent.TimeUnit
import okhttp3.OkHttpClient
object OkHttpHelper {
fun getClientForUploadFile(): OkHttpClient {
if (httpClientForUploadFile == null) {
httpClientForUploadFile = OkHttpClient.Builder().build()
}
return httpClientForUploadFile ?: throw AssertionError("httpClientForUploadFile set to null by another thread")
}
fun getClientForDownloadFile(context: Context): OkHttpClient {
if(httpClientForDownloadFile == null) {
httpClientForDownloadFile = OkHttpClient.Builder()
.addNetworkInterceptor(StethoInterceptor())
.addInterceptor(CookieInterceptor(DefaultCookieProvider(RocketChatCache(context))))
.build()
}
return httpClientForDownloadFile ?: throw AssertionError("httpClientForDownloadFile set to null by another thread")
}
/**
* Returns the OkHttpClient instance for WebSocket connection.
* @return The OkHttpClient WebSocket connection instance.
*/
fun getClientForWebSocket(): OkHttpClient {
if (httpClientForWS == null) {
httpClientForWS = OkHttpClient.Builder()
.readTimeout(0, TimeUnit.NANOSECONDS)
.build()
}
return httpClientForWS ?: throw AssertionError("httpClientForWS set to null by another thread")
}
private var httpClientForUploadFile: OkHttpClient? = null
private var httpClientForDownloadFile: OkHttpClient? = null
private var httpClientForWS: OkHttpClient? = null
}
\ No newline at end of file
package chat.rocket.android;
import android.os.StrictMode;
import android.support.multidex.MultiDexApplication;
import chat.rocket.android.helper.OkHttpHelper;
import com.crashlytics.android.Crashlytics;
import com.facebook.stetho.Stetho;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;
import io.fabric.sdk.android.Fabric;
import java.util.List;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.core.models.ServerInfo;
......@@ -19,12 +16,9 @@ import chat.rocket.persistence.realm.RocketChatPersistenceRealm;
* Customized Application-class for Rocket.Chat
*/
public class RocketChatApplication extends MultiDexApplication {
@Override
public void onCreate() {
if (BuildConfig.DEBUG) {
enableStrictMode();
}
super.onCreate();
Fabric.with(this, new Crashlytics());
......@@ -35,31 +29,6 @@ public class RocketChatApplication extends MultiDexApplication {
RealmStore.put(serverInfo.getHostname());
}
if (BuildConfig.DEBUG) {
enableStetho();
}
RocketChatWidgets.initialize(this, OkHttpHelper.getClientForDownloadFile(this));
}
private void enableStrictMode() {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
}
private void enableStetho() {
Stetho.initialize(Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
.build());
RocketChatWidgets.initialize(this, OkHttpHelper.INSTANCE.getClientForDownloadFile(this));
}
}
}
\ No newline at end of file
......@@ -2,13 +2,13 @@ package chat.rocket.android.api;
import android.support.annotation.Nullable;
import chat.rocket.android.helper.OkHttpHelper;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.UUID;
import bolts.Task;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.log.RCLog;
import chat.rocket.android_ddp.DDPClient;
......@@ -25,7 +25,7 @@ public class DDPClientWrapper {
private final String hostname;
private DDPClientWrapper(String hostname) {
ddpClient = new DDPClient(OkHttpHelper.getClientForWebSocket());
ddpClient = new DDPClient(OkHttpHelper.INSTANCE.getClientForWebSocket());
this.hostname = hostname;
}
......
package chat.rocket.android.fragment.add_server;
import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.helper.OkHttpHelper;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.rest.DefaultServerPolicyApi;
import chat.rocket.android.api.rest.ServerPolicyApi;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.helper.ServerPolicyApiValidationHelper;
import chat.rocket.android.helper.ServerPolicyHelper;
import chat.rocket.android.service.ConnectivityManagerApi;
......@@ -29,7 +29,7 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.
}
public void connectToEnforced(final String hostname) {
final ServerPolicyApi serverPolicyApi = new DefaultServerPolicyApi(OkHttpHelper.getClientForUploadFile(), hostname);
final ServerPolicyApi serverPolicyApi = new DefaultServerPolicyApi(OkHttpHelper.INSTANCE.getClientForUploadFile(), hostname);
final ServerPolicyApiValidationHelper validationHelper = new ServerPolicyApiValidationHelper(serverPolicyApi);
clearSubscriptions();
......
package chat.rocket.android.helper;
import android.content.Context;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import java.util.concurrent.TimeUnit;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.rest.CookieInterceptor;
import chat.rocket.android.api.rest.DefaultCookieProvider;
import okhttp3.OkHttpClient;
/**
* Helper class for OkHttp client.
*/
public class OkHttpHelper {
private static OkHttpClient httpClientForUploadFile;
private static OkHttpClient httpClientForDownloadFile;
private static OkHttpClient httpClientForWS;
public static OkHttpClient getClientForDownloadFile(Context context) {
if (httpClientForDownloadFile == null) {
httpClientForDownloadFile = new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.addInterceptor(
new CookieInterceptor(new DefaultCookieProvider(new RocketChatCache(context))))
.build();
}
return httpClientForDownloadFile;
}
public static OkHttpClient getClientForUploadFile() {
if (httpClientForUploadFile == null) {
httpClientForUploadFile = new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
}
return httpClientForUploadFile;
}
/**
* acquire OkHttpClient instance for WebSocket connection.
*/
public static OkHttpClient getClientForWebSocket() {
if (httpClientForWS == null) {
httpClientForWS = new OkHttpClient.Builder().readTimeout(0, TimeUnit.NANOSECONDS)
.addNetworkInterceptor(new StethoInterceptor())
.build();
}
return httpClientForWS;
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package chat.rocket.android.service.observer;
import android.content.Context;
import android.net.Uri;
import chat.rocket.android.helper.OkHttpHelper;
import io.realm.Realm;
import io.realm.RealmResults;
import org.json.JSONArray;
......@@ -13,7 +14,6 @@ import java.util.List;
import bolts.Task;
import chat.rocket.android.api.FileUploadingHelper;
import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.log.RCLog;
import chat.rocket.core.SyncState;
import chat.rocket.persistence.realm.models.internal.FileUploading;
......@@ -167,7 +167,7 @@ public class FileUploadingToUrlObserver extends AbstractModelObserver<FileUpload
.post(bodyBuilder.build())
.build();
Response response = OkHttpHelper.getClientForUploadFile().newCall(request).execute();
Response response = OkHttpHelper.INSTANCE.getClientForUploadFile().newCall(request).execute();
if (response.isSuccessful()) {
return Task.forResult(downloadUrl);
} else {
......
......@@ -2,6 +2,7 @@ package chat.rocket.android.service.observer;
import android.content.Context;
import android.net.Uri;
import chat.rocket.android.helper.OkHttpHelper;
import io.realm.Realm;
import io.realm.RealmResults;
import org.json.JSONObject;
......@@ -11,7 +12,6 @@ import java.util.List;
import bolts.Task;
import chat.rocket.android.api.FileUploadingHelper;
import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.log.RCLog;
import chat.rocket.core.SyncState;
import chat.rocket.persistence.realm.models.ddp.RealmUser;
......@@ -143,7 +143,7 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
.post(RequestBody.create(contentType, buffer, 0, read))
.build();
Response response = OkHttpHelper.getClientForUploadFile().newCall(request).execute();
Response response = OkHttpHelper.INSTANCE.getClientForUploadFile().newCall(request).execute();
if (response.isSuccessful()) {
final JSONObject obj = new JSONObject()
.put(FileUploading.ID, uplId)
......
<manifest package="chat.rocket.android"/>
package chat.rocket.android.helper
import android.content.Context
import chat.rocket.android.RocketChatCache
import chat.rocket.android.api.rest.CookieInterceptor
import chat.rocket.android.api.rest.DefaultCookieProvider
import java.util.concurrent.TimeUnit
import okhttp3.OkHttpClient
object OkHttpHelper {
fun getClientForUploadFile(): OkHttpClient {
if (httpClientForUploadFile == null) {
httpClientForUploadFile = OkHttpClient.Builder().build()
}
return httpClientForUploadFile ?: throw AssertionError("httpClientForUploadFile set to null by another thread")
}
fun getClientForDownloadFile(context: Context): OkHttpClient {
if(httpClientForDownloadFile == null) {
httpClientForDownloadFile = OkHttpClient.Builder()
.addInterceptor(CookieInterceptor(DefaultCookieProvider(RocketChatCache(context))))
.build()
}
return httpClientForDownloadFile ?: throw AssertionError("httpClientForDownloadFile set to null by another thread")
}
/**
* Returns the OkHttpClient instance for WebSocket connection.
* @return The OkHttpClient WebSocket connection instance.
*/
fun getClientForWebSocket(): OkHttpClient {
if (httpClientForWS == null) {
httpClientForWS = OkHttpClient.Builder()
.readTimeout(0, TimeUnit.NANOSECONDS)
.build()
}
return httpClientForWS ?: throw AssertionError("httpClientForWS set to null by another thread")
}
private var httpClientForUploadFile: OkHttpClient? = null
private var httpClientForDownloadFile: OkHttpClient? = null
private var httpClientForWS: OkHttpClient? = null
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment