Unverified Commit b0d03bea authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #705 from RocketChat/feature-2.x/save-login

[NEW] Save login information and server settings
parents 813ede16 130d2bba
...@@ -11,16 +11,27 @@ android { ...@@ -11,16 +11,27 @@ android {
applicationId "chat.rocket.android" applicationId "chat.rocket.android"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion versions.targetSdk targetSdkVersion versions.targetSdk
versionCode 1 versionCode 1001
versionName "2.0.0-beta1" versionName "2.0.0-dev1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
} }
signingConfigs {
release {
storeFile project.rootProject.file('Rocket.jks').getCanonicalFile()
storePassword System.getenv("KEYSTORE_PASSWORD")
keyAlias System.getenv("KEY_ALIAS")
keyPassword System.getenv("KEY_PASSWORD")
}
}
buildTypes { buildTypes {
release { release {
signingConfig signingConfigs.release
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix ".dev"
} }
debug { debug {
...@@ -75,7 +86,8 @@ dependencies { ...@@ -75,7 +86,8 @@ dependencies {
implementation libraries.frescoImageViewer implementation libraries.frescoImageViewer
implementation libraries.kotshi kapt libraries.kotshiCompiler
implementation libraries.kotshiApi
implementation libraries.floatingSearchView implementation libraries.floatingSearchView
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
android:name=".authentication.ui.AuthenticationActivity" android:name=".authentication.ui.AuthenticationActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/AuthenticationTheme" android:theme="@style/AppTheme.SplashScreen"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
android:theme="@style/AppTheme" /> android:theme="@style/AppTheme" />
<activity <activity
android:name=".chatrooms.ui.MainActivity" android:name=".chatrooms.ui.ChatRoomsActivity"
android:theme="@style/ChatListTheme" /> android:theme="@style/ChatListTheme" />
<activity <activity
......
package chat.rocket.android.authentication.di package chat.rocket.android.authentication.di
import android.content.Context import android.content.Context
import chat.rocket.android.authentication.infraestructure.SharedPreferencesMultiServerTokenRepository
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.authentication.ui.AuthenticationActivity import chat.rocket.android.authentication.ui.AuthenticationActivity
import chat.rocket.android.dagger.scope.PerActivity import chat.rocket.android.dagger.scope.PerActivity
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.MultiServerTokenRepository
import com.squareup.moshi.Moshi
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
...@@ -13,4 +17,10 @@ class AuthenticationModule { ...@@ -13,4 +17,10 @@ class AuthenticationModule {
@Provides @Provides
@PerActivity @PerActivity
fun provideAuthenticationNavigator(activity: AuthenticationActivity, context: Context) = AuthenticationNavigator(activity, context) fun provideAuthenticationNavigator(activity: AuthenticationActivity, context: Context) = AuthenticationNavigator(activity, context)
@Provides
@PerActivity
fun provideMultiServerTokenRepository(repository: LocalRepository, moshi: Moshi): MultiServerTokenRepository {
return SharedPreferencesMultiServerTokenRepository(repository, moshi)
}
} }
\ No newline at end of file
package chat.rocket.android.authentication.domain.model
import se.ansman.kotshi.JsonSerializable
@JsonSerializable
data class TokenModel(val userId: String, val authToken: String)
\ No newline at end of file
...@@ -3,7 +3,7 @@ package chat.rocket.android.authentication.infraestructure ...@@ -3,7 +3,7 @@ package chat.rocket.android.authentication.infraestructure
import chat.rocket.common.model.Token import chat.rocket.common.model.Token
import chat.rocket.core.TokenRepository import chat.rocket.core.TokenRepository
class AuthTokenRepository : TokenRepository { class MemoryTokenRepository : TokenRepository {
var savedToken: Token? = null var savedToken: Token? = null
override fun get(): Token? { override fun get(): Token? {
......
package chat.rocket.android.authentication.infraestructure
import chat.rocket.android.authentication.domain.model.TokenModel
import chat.rocket.android.dagger.scope.PerActivity
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.MultiServerTokenRepository
import com.squareup.moshi.Moshi
@PerActivity
class SharedPreferencesMultiServerTokenRepository(private val repository: LocalRepository,
private val moshi: Moshi
) : MultiServerTokenRepository {
override fun get(server: String): TokenModel? {
val token = repository.get("$TOKEN_KEY$server")
val adapter = moshi.adapter<TokenModel>(TokenModel::class.java)
token?.let {
return adapter.fromJson(token)
}
return null
}
override fun save(server: String, token: TokenModel) {
val adapter = moshi.adapter<TokenModel>(TokenModel::class.java)
repository.save("$TOKEN_KEY$server", adapter.toJson(token))
}
}
const val TOKEN_KEY = "token_"
\ No newline at end of file
package chat.rocket.android.authentication.infraestructure
import chat.rocket.android.authentication.domain.model.TokenModel
import chat.rocket.android.util.DataToDomain
import chat.rocket.common.model.Token
object TokenMapper : DataToDomain<Token, TokenModel> {
override fun translate(data: Token): TokenModel {
return TokenModel(data.userId, data.authToken)
}
}
\ No newline at end of file
package chat.rocket.android.authentication.login.presentation package chat.rocket.android.authentication.login.presentation
import chat.rocket.android.authentication.domain.model.TokenModel
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper import chat.rocket.android.helper.NetworkHelper
...@@ -18,6 +19,7 @@ import javax.inject.Inject ...@@ -18,6 +19,7 @@ import javax.inject.Inject
class LoginPresenter @Inject constructor(private val view: LoginView, class LoginPresenter @Inject constructor(private val view: LoginView,
private val strategy: CancelStrategy, private val strategy: CancelStrategy,
private val navigator: AuthenticationNavigator, private val navigator: AuthenticationNavigator,
private val multiServerRepository: MultiServerTokenRepository,
private val localRepository: LocalRepository, private val localRepository: LocalRepository,
private val settingsInteractor: GetSettingsInteractor, private val settingsInteractor: GetSettingsInteractor,
private val serverInteractor: GetCurrentServerInteractor, private val serverInteractor: GetCurrentServerInteractor,
...@@ -90,7 +92,8 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -90,7 +92,8 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
view.showLoading() view.showLoading()
try { try {
client.login(usernameOrEmail, password) // TODO This function returns a user token so should we save it? val token = client.login(usernameOrEmail, password)
multiServerRepository.save(server, TokenModel(token.userId, token.authToken))
registerPushToken() registerPushToken()
navigator.toChatList() navigator.toChatList()
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
......
...@@ -7,7 +7,7 @@ import chat.rocket.android.authentication.login.ui.LoginFragment ...@@ -7,7 +7,7 @@ import chat.rocket.android.authentication.login.ui.LoginFragment
import chat.rocket.android.authentication.signup.ui.SignupFragment import chat.rocket.android.authentication.signup.ui.SignupFragment
import chat.rocket.android.authentication.twofactor.ui.TwoFAFragment import chat.rocket.android.authentication.twofactor.ui.TwoFAFragment
import chat.rocket.android.authentication.ui.AuthenticationActivity import chat.rocket.android.authentication.ui.AuthenticationActivity
import chat.rocket.android.chatrooms.ui.MainActivity import chat.rocket.android.chatrooms.ui.ChatRoomsActivity
import chat.rocket.android.util.addFragmentBackStack import chat.rocket.android.util.addFragmentBackStack
import chat.rocket.android.webview.webViewIntent import chat.rocket.android.webview.webViewIntent
...@@ -36,7 +36,7 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity, int ...@@ -36,7 +36,7 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity, int
} }
fun toChatList() { fun toChatList() {
val chatList = Intent(activity, MainActivity::class.java).apply { val chatList = Intent(activity, ChatRoomsActivity::class.java).apply {
//TODO any parameter to pass //TODO any parameter to pass
} }
activity.startActivity(chatList) activity.startActivity(chatList)
......
package chat.rocket.android.authentication.presentation
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.MultiServerTokenRepository
import chat.rocket.android.server.domain.SettingsRepository
import chat.rocket.common.model.Token
import chat.rocket.core.TokenRepository
import javax.inject.Inject
class AuthenticationPresenter @Inject constructor(private val navigator: AuthenticationNavigator,
private val getCurrentServerInteractor: GetCurrentServerInteractor,
private val multiServerRepository: MultiServerTokenRepository,
private val settingsRepository: SettingsRepository,
private val tokenRepository: TokenRepository) {
fun loadCredentials(callback: (authenticated: Boolean) -> Unit) {
val currentServer = getCurrentServerInteractor.get()
val serverToken = currentServer?.let { multiServerRepository.get(currentServer) }
val settings = currentServer?.let { settingsRepository.get(currentServer) }
if (currentServer == null || serverToken == null || settings == null) {
callback(false)
} else {
tokenRepository.save(Token(serverToken.userId, serverToken.authToken))
callback(true)
navigator.toChatList()
}
}
}
\ No newline at end of file
package chat.rocket.android.authentication.presentation
interface AuthenticationView {
fun showServerInput()
}
\ No newline at end of file
package chat.rocket.android.authentication.twofactor.presentation package chat.rocket.android.authentication.twofactor.presentation
import chat.rocket.android.authentication.domain.model.TokenModel
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper import chat.rocket.android.helper.NetworkHelper
import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.GetCurrentServerInteractor import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.MultiServerTokenRepository
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.launchUI import chat.rocket.android.util.launchUI
import chat.rocket.common.RocketChatAuthException import chat.rocket.common.RocketChatAuthException
...@@ -18,6 +20,7 @@ import javax.inject.Inject ...@@ -18,6 +20,7 @@ import javax.inject.Inject
class TwoFAPresenter @Inject constructor(private val view: TwoFAView, class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
private val strategy: CancelStrategy, private val strategy: CancelStrategy,
private val navigator: AuthenticationNavigator, private val navigator: AuthenticationNavigator,
private val multiServerRepository: MultiServerTokenRepository,
private val localRepository: LocalRepository, private val localRepository: LocalRepository,
private val serverInteractor: GetCurrentServerInteractor, private val serverInteractor: GetCurrentServerInteractor,
private val factory: RocketChatClientFactory) { private val factory: RocketChatClientFactory) {
...@@ -40,7 +43,8 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView, ...@@ -40,7 +43,8 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
view.showLoading() view.showLoading()
try { try {
// The token is saved via the client TokenProvider // The token is saved via the client TokenProvider
client.login(usernameOrEmail, password, twoFactorAuthenticationCode) val token = client.login(usernameOrEmail, password, twoFactorAuthenticationCode)
multiServerRepository.save(server, TokenModel(token.userId, token.authToken))
registerPushToken() registerPushToken()
navigator.toChatList() navigator.toChatList()
} catch (exception: RocketChatException) { } catch (exception: RocketChatException) {
......
...@@ -4,6 +4,7 @@ import android.os.Bundle ...@@ -4,6 +4,7 @@ import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.authentication.presentation.AuthenticationPresenter
import chat.rocket.android.authentication.server.ui.ServerFragment import chat.rocket.android.authentication.server.ui.ServerFragment
import chat.rocket.android.util.addFragment import chat.rocket.android.util.addFragment
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
...@@ -14,19 +15,32 @@ import javax.inject.Inject ...@@ -14,19 +15,32 @@ import javax.inject.Inject
class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
@Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment> @Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject lateinit var presenter: AuthenticationPresenter
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_authentication)
AndroidInjection.inject(this) AndroidInjection.inject(this)
presenter.loadCredentials { authenticated ->
addFragment("ServerFragment", R.id.fragment_container) { if (authenticated) {
ServerFragment.newInstance() // just call onCreate, and the presenter will call the navigator...
super.onCreate(savedInstanceState)
} else {
showServerInput(savedInstanceState)
}
} }
} }
override fun supportFragmentInjector(): AndroidInjector<Fragment> { override fun supportFragmentInjector(): AndroidInjector<Fragment> {
return fragmentDispatchingAndroidInjector return fragmentDispatchingAndroidInjector
} }
fun showServerInput(savedInstanceState: Bundle?) {
setContentView(R.layout.activity_authentication)
setTheme(R.style.AuthenticationTheme)
super.onCreate(savedInstanceState)
addFragment("ServerFragment", R.id.fragment_container) {
ServerFragment.newInstance()
}
}
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ package chat.rocket.android.chatrooms.di ...@@ -2,7 +2,7 @@ package chat.rocket.android.chatrooms.di
import android.content.Context import android.content.Context
import chat.rocket.android.chatrooms.presentation.ChatRoomsNavigator import chat.rocket.android.chatrooms.presentation.ChatRoomsNavigator
import chat.rocket.android.chatrooms.ui.MainActivity import chat.rocket.android.chatrooms.ui.ChatRoomsActivity
import chat.rocket.android.dagger.scope.PerActivity import chat.rocket.android.dagger.scope.PerActivity
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
...@@ -12,5 +12,5 @@ class ChatRoomsModule { ...@@ -12,5 +12,5 @@ class ChatRoomsModule {
@Provides @Provides
@PerActivity @PerActivity
fun provideAuthenticationNavigator(activity: MainActivity, context: Context) = ChatRoomsNavigator(activity, context) fun provideAuthenticationNavigator(activity: ChatRoomsActivity, context: Context) = ChatRoomsNavigator(activity, context)
} }
\ No newline at end of file
...@@ -3,9 +3,9 @@ package chat.rocket.android.chatrooms.presentation ...@@ -3,9 +3,9 @@ package chat.rocket.android.chatrooms.presentation
import android.content.Context import android.content.Context
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.chatroom.ui.chatRoomIntent import chat.rocket.android.chatroom.ui.chatRoomIntent
import chat.rocket.android.chatrooms.ui.MainActivity import chat.rocket.android.chatrooms.ui.ChatRoomsActivity
class ChatRoomsNavigator(private val activity: MainActivity, private val context: Context) { class ChatRoomsNavigator(private val activity: ChatRoomsActivity, private val context: Context) {
fun toChatRoom(chatRoomId: String, chatRoomName: String, chatRoomType: String, isChatRoomReadOnly: Boolean) { fun toChatRoom(chatRoomId: String, chatRoomName: String, chatRoomType: String, isChatRoomReadOnly: Boolean) {
activity.startActivity(context.chatRoomIntent(chatRoomId, chatRoomName, chatRoomType, isChatRoomReadOnly)) activity.startActivity(context.chatRoomIntent(chatRoomId, chatRoomName, chatRoomType, isChatRoomReadOnly))
......
...@@ -241,4 +241,8 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView, ...@@ -241,4 +241,8 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
} }
saveChatRoomsInteractor.save(currentServer, sortRooms(chatRooms)) saveChatRoomsInteractor.save(currentServer, sortRooms(chatRooms))
} }
fun disconnect() {
client.disconnect()
}
} }
\ No newline at end of file
...@@ -11,19 +11,23 @@ import dagger.android.DispatchingAndroidInjector ...@@ -11,19 +11,23 @@ import dagger.android.DispatchingAndroidInjector
import dagger.android.support.HasSupportFragmentInjector import dagger.android.support.HasSupportFragmentInjector
import javax.inject.Inject import javax.inject.Inject
class MainActivity : AppCompatActivity(), HasSupportFragmentInjector { class ChatRoomsActivity : AppCompatActivity(), HasSupportFragmentInjector {
@Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment> @Inject lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) AndroidInjection.inject(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_chat_rooms)
addFragment("ChatRoomsFragment", R.id.fragment_container) { addFragment("ChatRoomsFragment", R.id.fragment_container) {
ChatRoomsFragment.newInstance() ChatRoomsFragment.newInstance()
} }
} }
override fun onDestroy() {
super.onDestroy()
}
override fun supportFragmentInjector(): AndroidInjector<Fragment> { override fun supportFragmentInjector(): AndroidInjector<Fragment> {
return fragmentDispatchingAndroidInjector return fragmentDispatchingAndroidInjector
} }
......
...@@ -22,6 +22,7 @@ import kotlinx.coroutines.experimental.CommonPool ...@@ -22,6 +22,7 @@ import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.android.UI import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.async import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.experimental.launch
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class ChatRoomsFragment : Fragment(), ChatRoomsView { class ChatRoomsFragment : Fragment(), ChatRoomsView {
...@@ -39,6 +40,12 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -39,6 +40,12 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
override fun onDestroy() {
Timber.d("Called on destroy...")
presenter.disconnect()
super.onDestroy()
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.fragment_chat_rooms, container, false) override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.fragment_chat_rooms, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
......
...@@ -10,7 +10,7 @@ import chat.rocket.android.chatroom.di.ChatRoomFragmentProvider ...@@ -10,7 +10,7 @@ import chat.rocket.android.chatroom.di.ChatRoomFragmentProvider
import chat.rocket.android.chatroom.ui.ChatRoomActivity import chat.rocket.android.chatroom.ui.ChatRoomActivity
import chat.rocket.android.chatrooms.di.ChatRoomsFragmentProvider import chat.rocket.android.chatrooms.di.ChatRoomsFragmentProvider
import chat.rocket.android.chatrooms.di.ChatRoomsModule import chat.rocket.android.chatrooms.di.ChatRoomsModule
import chat.rocket.android.chatrooms.ui.MainActivity import chat.rocket.android.chatrooms.ui.ChatRoomsActivity
import chat.rocket.android.dagger.scope.PerActivity import chat.rocket.android.dagger.scope.PerActivity
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
...@@ -29,7 +29,7 @@ abstract class ActivityBuilder { ...@@ -29,7 +29,7 @@ abstract class ActivityBuilder {
@PerActivity @PerActivity
@ContributesAndroidInjector(modules = [ChatRoomsModule::class, ChatRoomsFragmentProvider::class]) @ContributesAndroidInjector(modules = [ChatRoomsModule::class, ChatRoomsFragmentProvider::class])
abstract fun bindMainActivity(): MainActivity abstract fun bindMainActivity(): ChatRoomsActivity
@PerActivity @PerActivity
@ContributesAndroidInjector(modules = [ChatRoomFragmentProvider::class]) @ContributesAndroidInjector(modules = [ChatRoomFragmentProvider::class])
......
...@@ -6,19 +6,22 @@ import android.content.Context ...@@ -6,19 +6,22 @@ import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import chat.rocket.android.BuildConfig import chat.rocket.android.BuildConfig
import chat.rocket.android.app.RocketChatDatabase import chat.rocket.android.app.RocketChatDatabase
import chat.rocket.android.authentication.infraestructure.AuthTokenRepository import chat.rocket.android.authentication.infraestructure.MemoryTokenRepository
import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.infrastructure.SharedPrefsLocalRepository import chat.rocket.android.infrastructure.SharedPrefsLocalRepository
import chat.rocket.android.server.domain.ChatRoomsRepository import chat.rocket.android.server.domain.ChatRoomsRepository
import chat.rocket.android.server.domain.CurrentServerRepository import chat.rocket.android.server.domain.CurrentServerRepository
import chat.rocket.android.server.domain.SettingsRepository import chat.rocket.android.server.domain.SettingsRepository
import chat.rocket.android.server.infraestructure.MemoryChatRoomsRepository import chat.rocket.android.server.infraestructure.MemoryChatRoomsRepository
import chat.rocket.android.server.infraestructure.MemorySettingsRepository
import chat.rocket.android.server.infraestructure.ServerDao import chat.rocket.android.server.infraestructure.ServerDao
import chat.rocket.android.server.infraestructure.SharedPreferencesSettingsRepository
import chat.rocket.android.server.infraestructure.SharedPrefsCurrentServerRepository import chat.rocket.android.server.infraestructure.SharedPrefsCurrentServerRepository
import chat.rocket.android.util.AppJsonAdapterFactory
import chat.rocket.android.util.TimberLogger import chat.rocket.android.util.TimberLogger
import chat.rocket.common.util.PlatformLogger import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.TokenRepository
import com.squareup.moshi.Moshi
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
import kotlinx.coroutines.experimental.Job import kotlinx.coroutines.experimental.Job
...@@ -31,7 +34,7 @@ class AppModule { ...@@ -31,7 +34,7 @@ class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideRocketChatClient(okHttpClient: OkHttpClient, repository: AuthTokenRepository, logger: PlatformLogger): RocketChatClient { fun provideRocketChatClient(okHttpClient: OkHttpClient, repository: TokenRepository, logger: PlatformLogger): RocketChatClient {
return RocketChatClient.create { return RocketChatClient.create {
httpClient = okHttpClient httpClient = okHttpClient
tokenRepository = repository tokenRepository = repository
...@@ -88,8 +91,8 @@ class AppModule { ...@@ -88,8 +91,8 @@ class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideAuthTokenRepository(): AuthTokenRepository { fun provideTokenRepository(): TokenRepository {
return AuthTokenRepository() return MemoryTokenRepository()
} }
@Provides @Provides
...@@ -105,7 +108,7 @@ class AppModule { ...@@ -105,7 +108,7 @@ class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideSharedPreferencesRepository(prefs: SharedPreferences): LocalRepository { fun provideLocalRepository(prefs: SharedPreferences): LocalRepository {
return SharedPrefsLocalRepository(prefs) return SharedPrefsLocalRepository(prefs)
} }
...@@ -117,8 +120,8 @@ class AppModule { ...@@ -117,8 +120,8 @@ class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideSettingsRepository(): SettingsRepository { fun provideSettingsRepository(localRepository: LocalRepository): SettingsRepository {
return MemorySettingsRepository() return SharedPreferencesSettingsRepository(localRepository)
} }
@Provides @Provides
...@@ -126,4 +129,10 @@ class AppModule { ...@@ -126,4 +129,10 @@ class AppModule {
fun provideChatRoomsRepository(): ChatRoomsRepository { fun provideChatRoomsRepository(): ChatRoomsRepository {
return MemoryChatRoomsRepository() return MemoryChatRoomsRepository()
} }
@Provides
@Singleton
fun provideMoshi(): Moshi {
return Moshi.Builder().add(AppJsonAdapterFactory.INSTANCE).build()
}
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ import android.text.Spanned ...@@ -20,7 +20,7 @@ import android.text.Spanned
import android.util.Log import android.util.Log
import chat.rocket.android.BuildConfig import chat.rocket.android.BuildConfig
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.chatrooms.ui.MainActivity import chat.rocket.android.chatrooms.ui.ChatRoomsActivity
import org.json.JSONObject import org.json.JSONObject
import java.io.Serializable import java.io.Serializable
import java.util.* import java.util.*
...@@ -455,7 +455,7 @@ object PushManager { ...@@ -455,7 +455,7 @@ object PushManager {
} }
private fun getContentIntent(context: Context, notificationId: Int, pushMessage: PushMessage, grouped: Boolean = false): PendingIntent { private fun getContentIntent(context: Context, notificationId: Int, pushMessage: PushMessage, grouped: Boolean = false): PendingIntent {
val notificationIntent = Intent(context, MainActivity::class.java) val notificationIntent = Intent(context, ChatRoomsActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
.putExtra(EXTRA_NOT_ID, notificationId) .putExtra(EXTRA_NOT_ID, notificationId)
.putExtra(EXTRA_HOSTNAME, pushMessage.host) .putExtra(EXTRA_HOSTNAME, pushMessage.host)
......
package chat.rocket.android.server.domain
import chat.rocket.android.authentication.domain.model.TokenModel
interface MultiServerTokenRepository {
fun get(server: String): TokenModel?
fun save(server: String, token: TokenModel)
}
\ No newline at end of file
package chat.rocket.android.server.infraestructure package chat.rocket.android.server.infraestructure
import chat.rocket.android.authentication.infraestructure.AuthTokenRepository
import chat.rocket.common.util.PlatformLogger import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.TokenRepository
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
...@@ -10,7 +10,7 @@ import javax.inject.Singleton ...@@ -10,7 +10,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class RocketChatClientFactory @Inject constructor(val okHttpClient: OkHttpClient, class RocketChatClientFactory @Inject constructor(val okHttpClient: OkHttpClient,
val repository: AuthTokenRepository, val repository: TokenRepository,
val logger: PlatformLogger) { val logger: PlatformLogger) {
private val cache = HashMap<String, RocketChatClient>() private val cache = HashMap<String, RocketChatClient>()
......
package chat.rocket.android.server.infraestructure package chat.rocket.android.server.infraestructure
import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.SettingsRepository import chat.rocket.android.server.domain.SettingsRepository
import chat.rocket.core.internal.SettingsAdapter
import chat.rocket.core.model.Value import chat.rocket.core.model.Value
class MemorySettingsRepository : SettingsRepository { class SharedPreferencesSettingsRepository(private val localRespository: LocalRepository) : SettingsRepository {
val cache = HashMap<String, Map<String, Value<Any>>>() private val adapter = SettingsAdapter()
override fun save(url: String, settings: Map<String, Value<Any>>) { override fun save(url: String, settings: Map<String, Value<Any>>) {
cache.put(url, settings) localRespository.save("$SETTINGS_KEY$url", adapter.toJson(settings))
} }
override fun get(url: String): Map<String, Value<Any>>? { override fun get(url: String): Map<String, Value<Any>>? {
return cache[url] val settings = localRespository.get("$SETTINGS_KEY$url")
settings?.let {
return adapter.fromJson(it)
}
return null
} }
companion object {
private const val SETTINGS_KEY = "settings_"
}
} }
\ No newline at end of file
...@@ -4,14 +4,16 @@ import android.content.SharedPreferences ...@@ -4,14 +4,16 @@ import android.content.SharedPreferences
import chat.rocket.android.server.domain.CurrentServerRepository import chat.rocket.android.server.domain.CurrentServerRepository
class SharedPrefsCurrentServerRepository(private val preferences: SharedPreferences) : CurrentServerRepository { class SharedPrefsCurrentServerRepository(private val preferences: SharedPreferences) : CurrentServerRepository {
private val CURRENT_SERVER = "current_server"
override fun save(url: String) { override fun save(url: String) {
preferences.edit().putString(CURRENT_SERVER, url).apply() preferences.edit().putString(CURRENT_SERVER_KEY, url).apply()
} }
override fun get(): String? { override fun get(): String? {
return preferences.getString(CURRENT_SERVER, null) return preferences.getString(CURRENT_SERVER_KEY, null)
} }
companion object {
private const val CURRENT_SERVER_KEY = "current_server"
}
} }
\ No newline at end of file
package chat.rocket.android.util
import com.squareup.moshi.JsonAdapter
import se.ansman.kotshi.KotshiJsonAdapterFactory
@KotshiJsonAdapterFactory
abstract class AppJsonAdapterFactory : JsonAdapter.Factory {
companion object {
val INSTANCE: AppJsonAdapterFactory = KotshiAppJsonAdapterFactory()
}
}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/colorPrimary"/>
</item>
<!--<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>-->
</layer-list>
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:theme="@style/ChatListTheme" android:theme="@style/ChatListTheme"
tools:context=".chatrooms.ui.MainActivity"> tools:context=".chatrooms.ui.ChatRoomsActivity">
<FrameLayout <FrameLayout
android:id="@+id/fragment_container" android:id="@+id/fragment_container"
......
...@@ -9,8 +9,13 @@ ...@@ -9,8 +9,13 @@
<item name="android:statusBarColor">@color/colorPrimaryDark</item> <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style> </style>
<style name="AppTheme.SplashScreen" parent="AppTheme" >
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
<style name="AuthenticationTheme" parent="Theme.AppCompat.NoActionBar"> <style name="AuthenticationTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:statusBarColor">@color/colorPrimaryDark</item> <item name="android:statusBarColor">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/colorPrimary</item>
</style> </style>
<style name="ChatListTheme" parent="AppTheme"> <style name="ChatListTheme" parent="AppTheme">
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
machine: machine:
environment: environment:
ANDROID_HOME: /usr/local/android-sdk-linux ANDROID_HOME: /usr/local/android-sdk-linux
GRADLE_OPTS: '-Xmx1024m -Dorg.gradle.jvmargs="-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError"' GRADLE_OPTS: '-Xmx1536M -Dorg.gradle.jvmargs="-Xmx1536M -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError"'
JAVA_OPTS: "-Xms518m -Xmx1024m" JAVA_OPTS: "-Xms518m -Xmx1536M"
pre: pre:
- git clone https://github.com/RocketChat/Rocket.Chat.Kotlin.SDK.git Rocket.Chat.Kotlin.SDK - git clone https://github.com/RocketChat/Rocket.Chat.Kotlin.SDK.git Rocket.Chat.Kotlin.SDK
......
...@@ -77,7 +77,8 @@ ext { ...@@ -77,7 +77,8 @@ ext {
frescoImageViewer : "com.github.stfalcon:frescoimageviewer:${versions.frescoImageViewer}", frescoImageViewer : "com.github.stfalcon:frescoimageviewer:${versions.frescoImageViewer}",
kotshi : "se.ansman.kotshi:api:${versions.kotshi}", kotshiApi : "se.ansman.kotshi:api:${versions.kotshi}",
kotshiCompiler : "se.ansman.kotshi:compiler:${versions.kotshi}",
floatingSearchView : "com.github.arimorty:floatingsearchview:${versions.floatingSearchView}", floatingSearchView : "com.github.arimorty:floatingsearchview:${versions.floatingSearchView}",
......
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