Commit 6618ec0b authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Merge branch 'userstatus-on-toolbar' of...

Merge branch 'userstatus-on-toolbar' of github.com:filipedelimabrito/Rocket.Chat.Android into userstatus-on-toolbar
parents 187cf002 20fb4670
...@@ -62,7 +62,16 @@ android { ...@@ -62,7 +62,16 @@ android {
} }
buildTypes { buildTypes {
debug {
debuggable true
versionNameSuffix '-DEBUG'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
release { release {
debuggable false
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release signingConfig signingConfigs.release
...@@ -89,6 +98,10 @@ android { ...@@ -89,6 +98,10 @@ android {
debug { debug {
manifest.srcFile 'src/debug/AndroidManifest.xml' manifest.srcFile 'src/debug/AndroidManifest.xml'
} }
release {
manifest.srcFile 'src/release/AndroidManifest.xml'
}
} }
} }
...@@ -160,6 +173,7 @@ dependencies { ...@@ -160,6 +173,7 @@ dependencies {
provided 'io.reactivex.rxjava2:rxjava:2.1.0' provided 'io.reactivex.rxjava2:rxjava:2.1.0'
provided 'io.reactivex:rxjava:1.3.0' provided 'io.reactivex:rxjava:1.3.0'
provided "com.github.akarnokd:rxjava2-interop:0.10.2" provided "com.github.akarnokd:rxjava2-interop:0.10.2"
provided 'com.hadisatrio:Optional:v1.0.1'
} }
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'
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; package chat.rocket.android;
import android.support.multidex.MultiDexApplication; import android.support.multidex.MultiDexApplication;
import chat.rocket.android.helper.OkHttpHelper;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
import java.util.List; import java.util.List;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.persistence.realm.RealmStore; import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.android.service.ConnectivityManager; import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.core.models.ServerInfo; import chat.rocket.core.models.ServerInfo;
...@@ -29,6 +29,6 @@ public class RocketChatApplication extends MultiDexApplication { ...@@ -29,6 +29,6 @@ public class RocketChatApplication extends MultiDexApplication {
RealmStore.put(serverInfo.getHostname()); RealmStore.put(serverInfo.getHostname());
} }
RocketChatWidgets.initialize(this, OkHttpHelper.getClientForDownloadFile(this)); RocketChatWidgets.initialize(this, OkHttpHelper.INSTANCE.getClientForDownloadFile(this));
} }
} }
\ No newline at end of file
...@@ -2,13 +2,13 @@ package chat.rocket.android.api; ...@@ -2,13 +2,13 @@ package chat.rocket.android.api;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import chat.rocket.android.helper.OkHttpHelper;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import java.util.UUID; import java.util.UUID;
import bolts.Task; import bolts.Task;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
import chat.rocket.android_ddp.DDPClient; import chat.rocket.android_ddp.DDPClient;
...@@ -25,7 +25,7 @@ public class DDPClientWrapper { ...@@ -25,7 +25,7 @@ public class DDPClientWrapper {
private final String hostname; private final String hostname;
private DDPClientWrapper(String hostname) { private DDPClientWrapper(String hostname) {
ddpClient = new DDPClient(OkHttpHelper.getClientForWebSocket()); ddpClient = new DDPClient(OkHttpHelper.INSTANCE.getClientForWebSocket());
this.hostname = hostname; this.hostname = hostname;
} }
......
package chat.rocket.android.fragment.add_server; package chat.rocket.android.fragment.add_server;
import chat.rocket.android.BackgroundLooper; import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.helper.OkHttpHelper;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import chat.rocket.android.RocketChatCache; import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.rest.DefaultServerPolicyApi; import chat.rocket.android.api.rest.DefaultServerPolicyApi;
import chat.rocket.android.api.rest.ServerPolicyApi; import chat.rocket.android.api.rest.ServerPolicyApi;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.helper.ServerPolicyApiValidationHelper; import chat.rocket.android.helper.ServerPolicyApiValidationHelper;
import chat.rocket.android.helper.ServerPolicyHelper; import chat.rocket.android.helper.ServerPolicyHelper;
import chat.rocket.android.service.ConnectivityManagerApi; import chat.rocket.android.service.ConnectivityManagerApi;
...@@ -29,7 +29,7 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract. ...@@ -29,7 +29,7 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.
} }
public void connectToEnforced(final String hostname) { 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); final ServerPolicyApiValidationHelper validationHelper = new ServerPolicyApiValidationHelper(serverPolicyApi);
clearSubscriptions(); clearSubscriptions();
......
...@@ -14,7 +14,9 @@ public interface RoomContract { ...@@ -14,7 +14,9 @@ public interface RoomContract {
void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl); void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl);
void render(Room room, @Nullable User user); void render(Room room);
void showUserStatus(User user);
void updateHistoryState(boolean hasNext, boolean isLoaded); void updateHistoryState(boolean hasNext, boolean isLoaded);
......
...@@ -525,7 +525,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -525,7 +525,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void render(Room room, @Nullable User user) { public void render(Room room) {
setToolbarTitle(room.getName()); setToolbarTitle(room.getName());
boolean unreadMessageExists = room.isAlert(); boolean unreadMessageExists = room.isAlert();
...@@ -543,8 +543,10 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -543,8 +543,10 @@ public class RoomFragment extends AbstractChatRoomFragment implements
setToolbarRoomIcon(R.drawable.ic_padlock_opaque_black_24dp); setToolbarRoomIcon(R.drawable.ic_padlock_opaque_black_24dp);
return; return;
} }
}
if (user != null) { @Override
public void showUserStatus(User user) {
switch (user.getStatus()) { switch (user.getStatus()) {
case User.STATUS_ONLINE: case User.STATUS_ONLINE:
setToolbarRoomIcon(R.drawable.ic_at_online_24dp); setToolbarRoomIcon(R.drawable.ic_at_online_24dp);
...@@ -560,7 +562,6 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -560,7 +562,6 @@ public class RoomFragment extends AbstractChatRoomFragment implements
break; break;
} }
} }
}
@Override @Override
public void updateHistoryState(boolean hasNext, boolean isLoaded) { public void updateHistoryState(boolean hasNext, boolean isLoaded) {
......
...@@ -5,6 +5,7 @@ import android.support.annotation.Nullable; ...@@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import com.hadisatrio.optional.Optional; import com.hadisatrio.optional.Optional;
import io.reactivex.Single; import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
...@@ -217,29 +218,25 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -217,29 +218,25 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.map(Optional::get) .map(Optional::get)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(room -> { .subscribe(this::processRoom, Logger::report);
addSubscription(subscription);
}
private void processRoom(Room room) {
view.render(room);
if (room.isDirectMessage()) { if (room.isDirectMessage()) {
getUserByUsername(room, room.getName()); getUserByUsername(room.getName());
} else {
view.render(room, null);
} }
},
Logger::report
);
addSubscription(subscription);
} }
private void getUserByUsername(Room room, String username) { private void getUserByUsername(String username) {
final Disposable subscription = userRepository.getByUsername(username) Disposable disposable = userRepository.getByUsername(username)
.distinctUntilChanged() .distinctUntilChanged()
.filter(Optional::isPresent) .filter(Optional::isPresent)
.map(Optional::get) .map(Optional::get)
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribe(view::showUserStatus, Logger::report);
.observeOn(AndroidSchedulers.mainThread()) addSubscription(disposable);
.subscribe(user -> view.render(room, user),
Logger::report
);
addSubscription(subscription);
} }
private void getRoomHistoryStateInfo() { private void getRoomHistoryStateInfo() {
......
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; ...@@ -2,6 +2,7 @@ package chat.rocket.android.service.observer;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import chat.rocket.android.helper.OkHttpHelper;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmResults; import io.realm.RealmResults;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -13,7 +14,6 @@ import java.util.List; ...@@ -13,7 +14,6 @@ import java.util.List;
import bolts.Task; import bolts.Task;
import chat.rocket.android.api.FileUploadingHelper; import chat.rocket.android.api.FileUploadingHelper;
import chat.rocket.android.helper.LogIfError; import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
import chat.rocket.core.SyncState; import chat.rocket.core.SyncState;
import chat.rocket.persistence.realm.models.internal.FileUploading; import chat.rocket.persistence.realm.models.internal.FileUploading;
...@@ -167,7 +167,7 @@ public class FileUploadingToUrlObserver extends AbstractModelObserver<FileUpload ...@@ -167,7 +167,7 @@ public class FileUploadingToUrlObserver extends AbstractModelObserver<FileUpload
.post(bodyBuilder.build()) .post(bodyBuilder.build())
.build(); .build();
Response response = OkHttpHelper.getClientForUploadFile().newCall(request).execute(); Response response = OkHttpHelper.INSTANCE.getClientForUploadFile().newCall(request).execute();
if (response.isSuccessful()) { if (response.isSuccessful()) {
return Task.forResult(downloadUrl); return Task.forResult(downloadUrl);
} else { } else {
......
...@@ -2,6 +2,7 @@ package chat.rocket.android.service.observer; ...@@ -2,6 +2,7 @@ package chat.rocket.android.service.observer;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import chat.rocket.android.helper.OkHttpHelper;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmResults; import io.realm.RealmResults;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -11,7 +12,6 @@ import java.util.List; ...@@ -11,7 +12,6 @@ import java.util.List;
import bolts.Task; import bolts.Task;
import chat.rocket.android.api.FileUploadingHelper; import chat.rocket.android.api.FileUploadingHelper;
import chat.rocket.android.helper.LogIfError; import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
import chat.rocket.core.SyncState; import chat.rocket.core.SyncState;
import chat.rocket.persistence.realm.models.ddp.RealmUser; import chat.rocket.persistence.realm.models.ddp.RealmUser;
...@@ -143,7 +143,7 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo ...@@ -143,7 +143,7 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
.post(RequestBody.create(contentType, buffer, 0, read)) .post(RequestBody.create(contentType, buffer, 0, read))
.build(); .build();
Response response = OkHttpHelper.getClientForUploadFile().newCall(request).execute(); Response response = OkHttpHelper.INSTANCE.getClientForUploadFile().newCall(request).execute();
if (response.isSuccessful()) { if (response.isSuccessful()) {
final JSONObject obj = new JSONObject() final JSONObject obj = new JSONObject()
.put(FileUploading.ID, uplId) .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
...@@ -67,5 +67,7 @@ dependencies { ...@@ -67,5 +67,7 @@ dependencies {
compile 'com.parse.bolts:bolts-tasks:1.4.0' compile 'com.parse.bolts:bolts-tasks:1.4.0'
provided 'com.hadisatrio:Optional:v1.0.1'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }
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