Commit a5963579 authored by divyanshu's avatar divyanshu

join community

parent d4ee1595
package chat.rocket.android.authentication.onboarding.presentation
import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.behaviours.showMessage
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.server.domain.GetAccountsInteractor
import chat.rocket.android.server.domain.RefreshSettingsInteractor
import chat.rocket.android.server.domain.SaveConnectingServerInteractor
import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extensions.isValidUrl
import javax.inject.Inject
class OnBoardingPresenter @Inject constructor(
private val view: OnBoardingView,
private val strategy: CancelStrategy,
private val navigator: AuthenticationNavigator
private val navigator: AuthenticationNavigator,
private val serverInteractor: SaveConnectingServerInteractor,
private val refreshSettingsInteractor: RefreshSettingsInteractor,
private val getAccountsInteractor: GetAccountsInteractor
) {
fun createServer(){
navigator.toWebPage("https://cloud.rocket.chat/trial")
}
fun connect(server: String) {
//code that leads to login screen (smart lock will be implemented after this)
connectToServer(server) {
navigator.toLoginOptions()
}
}
private fun connectToServer(server: String, block: () -> Unit) {
if (!server.isValidUrl()) {
view.showInvalidServerUrlMessage()
} else {
launchUI(strategy) {
// Check if we already have an account for this server...
val account = getAccountsInteractor.get().firstOrNull { it.serverUrl == server }
if (account != null) {
navigator.toChatList(server)
return@launchUI
}
view.showLoading()
try {
refreshSettingsInteractor.refresh(server)
serverInteractor.save(server)
block()
} catch (ex: Exception) {
view.showMessage(ex)
} finally {
view.hideLoading()
}
}
}
}
}
\ No newline at end of file
package chat.rocket.android.authentication.onboarding.presentation
import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView
interface OnBoardingView : LoadingView{
interface OnBoardingView : LoadingView, MessageView {
/**
* Shows an invalid server URL message.
*/
fun showInvalidServerUrlMessage()
}
\ No newline at end of file
......@@ -12,16 +12,17 @@ import chat.rocket.android.authentication.onboarding.presentation.OnBoardingPres
import chat.rocket.android.authentication.onboarding.presentation.OnBoardingView
import chat.rocket.android.authentication.server.ui.ServerFragment
import chat.rocket.android.authentication.ui.AuthenticationActivity
import chat.rocket.android.util.extensions.addFragmentBackStack
import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.*
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.app_bar_chat_room.*
import kotlinx.android.synthetic.main.fragment_authentication_on_boarding.*
import javax.inject.Inject
class OnBoardingFragment : Fragment(), OnBoardingView {
@Inject
lateinit var presenter: OnBoardingPresenter
private var protocol = "https://"
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? = container?.inflate(R.layout.fragment_authentication_on_boarding)
......@@ -45,9 +46,7 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
}
}
button_join_community.setOnClickListener {
(activity as AuthenticationActivity).addFragmentBackStack("ServerFragment", R.id.fragment_container) {
ServerFragment.newInstance(deepLinkInfo)
}
connectToCommunityServer()
}
button_create_server.setOnClickListener {
presenter.createServer()
......@@ -60,14 +59,41 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
}
override fun showLoading() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
ui{
view_loading.setVisible(true)
}
}
override fun hideLoading() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
ui{
view_loading.setVisible(false)
}
}
override fun showInvalidServerUrlMessage() = showMessage(getString(R.string.msg_invalid_server_url))
override fun showMessage(resId: Int) {
ui {
showToast(resId)
}
}
override fun showMessage(message: String) {
ui {
showToast(message)
}
}
override fun showGenericErrorMessage() {
showMessage(getString(R.string.msg_generic_error))
}
private fun connectToCommunityServer() {
ui {
val url = "open.rocket.chat"
presenter.connect("$protocol${url.sanitize()}")
}
}
companion object {
fun newInstance() = OnBoardingFragment()
}
......
......@@ -71,7 +71,7 @@ class ServerFragment : Fragment(), ServerView {
}
text_server_protocol.adapter = ArrayAdapter<String>(activity,
R.layout.spinner_list, arrayOf("https://", "http://"))
android.R.layout.simple_dropdown_item_1line, arrayOf("https://", "http://"))
text_server_protocol.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
when(position) {
......
......@@ -166,11 +166,21 @@
android:textStyle="bold"
android:textColor="#fff"
android:letterSpacing="0.04"
android:text="Connect with a server"
android:text="Create a new server"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/image_new_server" />
</RelativeLayout>
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/view_loading"
style="@style/Authentication.AVLoadingIndicatorView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:visibility="gone"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="48dp"
android:textSize="16sp"
android:textColor="@color/colorPrimaryText"
android:textAlignment="center"
android:background="@color/colorWhite"
android:padding="12dp"
tools:text="https" />
\ No newline at end of file
......@@ -13,7 +13,7 @@
<item name="searchViewStyle">@style/ChatRoom.SearchView</item>
</style>
<style name="AuthenticationTheme" parent="Theme.AppCompat.NoActionBar">
<style name="AuthenticationTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/colorWhite</item>
</style>
......
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