Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #678 from RocketChat/develop
Browse files Browse the repository at this point in the history
[RELEASE] Merge develop into master
  • Loading branch information
rafaelks authored Jan 4, 2018
2 parents 5bbd3f7 + 449e639 commit 94c2856
Show file tree
Hide file tree
Showing 93 changed files with 5,594 additions and 3,790 deletions.
11 changes: 6 additions & 5 deletions android-ddp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ android {
}
}
dependencies {
compile project(':log-wrapper')
compile extraDependencies.okHTTP
compile extraDependencies.rxJava
compile extraDependencies.boltTask
compile supportDependencies.annotation
api project(':log-wrapper')
implementation extraDependencies.okHTTP
implementation extraDependencies.rxJava
implementation extraDependencies.rxKotlin
implementation extraDependencies.boltTask
implementation supportDependencies.annotation
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public Task<RxWebSocketCallback.Close> getOnCloseCallback() {
}

public void close() {
impl.close(REASON_CLOSED_BY_USER, "closed by DDPClient#close()");
close(REASON_CLOSED_BY_USER);
}

public void close(int reason) {
impl.close(reason, "closed by DDPClient#close()");
}

/**
Expand Down
825 changes: 426 additions & 399 deletions android-ddp/src/main/java/chat/rocket/android_ddp/DDPClientImpl.java

Large diffs are not rendered by default.

78 changes: 42 additions & 36 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ 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' }
maven { url 'https://github.com/WickeDev/stetho-realm/raw/master/maven-repo' }
}

apply plugin: 'kotlin-android'
Expand All @@ -20,8 +21,8 @@ android {
applicationId "chat.rocket.android"
minSdkVersion 16
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 54
versionName "1.0.31"
versionCode 58
versionName "1.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
Expand Down Expand Up @@ -97,54 +98,59 @@ play {
track = "${track}"
}
ext {
playLibVersion = '11.6.0'
stethoVersion = '1.5.0'
stethoOkhttp3Version = '1.5.0'
stethoRealmVersion = '2.1.0'
stethoRealmVersion = '2.2.2'
rxbindingVersion = '2.0.0'
rxlifecycleVersion = '2.1.0'
icepickVersion = '3.2.0'
permissionsdispatcherVersion = '2.4.0'
}

dependencies {
compile project(':android-ddp')
compile project(':rocket-chat-android-widgets')
compile project(':persistence-realm')
compile extraDependencies.okHTTP
compile extraDependencies.rxJava
compile extraDependencies.boltTask
compile supportDependencies.multidex
compile supportDependencies.designSupportLibrary
compile supportDependencies.annotation
compile rxbindingDependencies.rxBinding
compile rxbindingDependencies.rxBindingSupport
compile rxbindingDependencies.rxBindingAppcompact
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$rootProject.ext.kotlinVersion"
compile "com.google.firebase:firebase-core:$playLibVersion"
compile "com.google.firebase:firebase-crash:$playLibVersion"
compile "com.google.android.gms:play-services-gcm:$playLibVersion"
compile "com.trello.rxlifecycle2:rxlifecycle:$rxlifecycleVersion"
compile "com.trello.rxlifecycle2:rxlifecycle-android:$rxlifecycleVersion"
compile "com.trello.rxlifecycle2:rxlifecycle-components:$rxlifecycleVersion"
compile 'nl.littlerobots.rxlint:rxlint:1.2'
compile "frankiesardo:icepick:$icepickVersion"
api project(':android-ddp')
api project(':rocket-chat-android-widgets')
api project(':persistence-realm')
implementation extraDependencies.okHTTP
implementation extraDependencies.rxJava
implementation extraDependencies.rxKotlin
implementation extraDependencies.boltTask
implementation supportDependencies.multidex
implementation supportDependencies.designSupportLibrary
implementation supportDependencies.annotation
implementation rxbindingDependencies.rxBinding
implementation rxbindingDependencies.rxBindingSupport
implementation rxbindingDependencies.rxBindingAppcompact
api "org.jetbrains.kotlin:kotlin-stdlib-jre8:$rootProject.ext.kotlinVersion"
implementation "com.google.firebase:firebase-core:$rootProject.ext.playLibVersion"
implementation "com.google.firebase:firebase-crash:$rootProject.ext.playLibVersion"
implementation "com.google.android.gms:play-services-gcm:$rootProject.ext.playLibVersion"
implementation "com.trello.rxlifecycle2:rxlifecycle:$rxlifecycleVersion"
implementation "com.trello.rxlifecycle2:rxlifecycle-android:$rxlifecycleVersion"
implementation "com.trello.rxlifecycle2:rxlifecycle-components:$rxlifecycleVersion"
implementation 'nl.littlerobots.rxlint:rxlint:1.2'
implementation "frankiesardo:icepick:$icepickVersion"
annotationProcessor "frankiesardo:icepick-processor:$icepickVersion"
compile "com.github.hotchemi:permissionsdispatcher:$permissionsdispatcherVersion"
implementation "com.github.hotchemi:permissionsdispatcher:$permissionsdispatcherVersion"
annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:$permissionsdispatcherVersion"
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
debugCompile "com.facebook.stetho:stetho:$stethoVersion"
implementation(extraDependencies.crouton) {
exclude group: 'com.android.support', module: 'support-v4'
}
implementation extraDependencies.androidJob
implementation extraDependencies.jstate
debugImplementation "com.facebook.stetho:stetho:$stethoVersion"
debugCompile "com.facebook.stetho:stetho-okhttp3:$stethoOkhttp3Version"
debugCompile "com.uphyca:stetho_realm:$stethoRealmVersion"
debugCompile "com.tspoon.traceur:traceur:1.0.1"
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.3'
testCompile "org.jetbrains.kotlin:kotlin-test:$rootProject.ext.kotlinVersion"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$rootProject.ext.kotlinVersion"
testCompile "org.jetbrains.kotlin:kotlin-reflect:$rootProject.ext.kotlinVersion"
testCompile "com.nhaarman:mockito-kotlin:1.5.0"
testCompile 'org.amshove.kluent:kluent:1.14'
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.3'
testImplementation "org.jetbrains.kotlin:kotlin-test:$rootProject.ext.kotlinVersion"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$rootProject.ext.kotlinVersion"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$rootProject.ext.kotlinVersion"
testImplementation "com.nhaarman:mockito-kotlin:1.5.0"
testImplementation 'org.amshove.kluent:kluent:1.14'
}
apply plugin: 'com.google.gms.google-services'
9 changes: 4 additions & 5 deletions app/src/debug/java/chat/rocket/android/helper/OkHttpHelper.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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
Expand All @@ -24,17 +22,18 @@ object OkHttpHelper {
return httpClientForUploadFile ?: throw AssertionError("httpClientForUploadFile set to null by another thread")
}

fun getClientForDownloadFile(context: Context): OkHttpClient {
if(httpClientForDownloadFile == null) {
fun getClientForDownloadFile(): OkHttpClient {
if (httpClientForDownloadFile == null) {
httpClientForDownloadFile = OkHttpClient.Builder()
.addNetworkInterceptor(StethoInterceptor())
.followRedirects(true)
.followSslRedirects(true)
.addInterceptor(CookieInterceptor(DefaultCookieProvider(RocketChatCache(context))))
.addInterceptor(CookieInterceptor(DefaultCookieProvider()))
.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.
Expand Down
57 changes: 31 additions & 26 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="chat.rocket.android">
package="chat.rocket.android">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />

<permission
android:name="chat.rocket.android.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
android:protectionLevel="signature" />

<uses-permission android:name="chat.rocket.android.permission.C2D_MESSAGE"/>
<uses-permission android:name="chat.rocket.android.permission.C2D_MESSAGE" />

<application
android:name=".RocketChatApplication"
Expand All @@ -26,39 +27,40 @@
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".activity.room.RoomActivity"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize"/>
android:windowSoftInputMode="adjustResize" />

<activity
android:name=".activity.AddServerActivity"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTop"/>
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize" />

<activity
android:name=".activity.LoginActivity"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize"/>
android:windowSoftInputMode="adjustResize" />

<service android:name=".service.RocketChatService"/>
<service android:name=".service.RocketChatService" />

<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="chat.rocket.android"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<category android:name="chat.rocket.android" />
</intent-filter>
</receiver>

Expand All @@ -67,16 +69,17 @@
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="chat.rocket.android"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="chat.rocket.android" />
</intent-filter>
</receiver>

<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />

<service android:name="com.google.firebase.iid.FirebaseInstanceIdService"
<service
android:name="com.google.firebase.iid.FirebaseInstanceIdService"
android:exported="true">
<intent-filter android:priority="-500">
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
Expand All @@ -87,22 +90,24 @@
android:name=".push.gcm.GCMIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>

<service
android:name=".push.gcm.GcmInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>

<receiver android:name=".push.PushManager$DeleteReceiver"
<receiver
android:name=".push.PushManager$DeleteReceiver"
android:exported="false" />

<receiver android:name=".push.PushManager$ReplyReceiver"
<receiver
android:name=".push.PushManager$ReplyReceiver"
android:exported="false" />

<meta-data
Expand Down
90 changes: 90 additions & 0 deletions app/src/main/java/chat/rocket/android/ConnectionStatusManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package chat.rocket.android

import chat.rocket.android.extensions.printStackTraceOnDebug
import chat.rocket.android.service.KeepAliveJob
import unquietcode.tools.esm.EnumStateMachine
import unquietcode.tools.esm.TransitionException

object ConnectionStatusManager {
enum class State {
OFFLINE, CONNECTING, ONLINE
}

private const val DEBUG = false
private val DEFAULT_CALLBACK = object : TransitionCallback {
override fun onTransitioned(success: Boolean) {
}
}
private val stateMachine: EnumStateMachine<State>

init {
stateMachine = EnumStateMachine(State.OFFLINE)

stateMachine.addTransitions(State.OFFLINE, State.CONNECTING)
stateMachine.addTransitions(State.CONNECTING, State.ONLINE, State.OFFLINE)
stateMachine.addTransitions(State.ONLINE, State.OFFLINE)
}

@Synchronized
fun transitionCount() = stateMachine.transitionCount()

@Synchronized
fun currentState() = stateMachine.currentState()

@Synchronized
fun setOnline(callback: TransitionCallback = DEFAULT_CALLBACK) {
KeepAliveJob.cancelPendingJobRequests()
tryTransitionTo(State.ONLINE, callback)
}

@Synchronized
fun setOnline() {
KeepAliveJob.cancelPendingJobRequests()
tryTransitionTo(State.ONLINE, DEFAULT_CALLBACK)
}

@Synchronized
fun setConnecting(callback: TransitionCallback = DEFAULT_CALLBACK) {
KeepAliveJob.cancelPendingJobRequests()
tryTransitionTo(State.CONNECTING, callback)
}

@Synchronized
fun setConnecting() {
KeepAliveJob.cancelPendingJobRequests()
tryTransitionTo(State.CONNECTING, DEFAULT_CALLBACK)
}

@Synchronized
fun setConnectionError(callback: TransitionCallback = DEFAULT_CALLBACK) {
KeepAliveJob.schedule()
tryTransitionTo(State.OFFLINE, callback)
}

@Synchronized
fun setConnectionError() {
KeepAliveJob.schedule()
tryTransitionTo(State.OFFLINE, DEFAULT_CALLBACK)
}

@Synchronized
fun setOffline() {
stateMachine.reset()
}

private fun tryTransitionTo(newState: State, callback: TransitionCallback) {
try {
stateMachine.transition(newState)
callback.onTransitioned(true)
} catch (e: TransitionException) {
if (DEBUG) {
e.printStackTraceOnDebug()
}
callback.onTransitioned(false)
}
}

interface TransitionCallback {
fun onTransitioned(success: Boolean)
}
}
Loading

0 comments on commit 94c2856

Please sign in to comment.