Skip to content

Commit

Permalink
Replace kotlin extension with view bindings in LoginActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Oct 18, 2023
1 parent 3aa30d4 commit 375bb2c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app/src/main/java/com/infomaniak/drive/ui/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.infomaniak.drive.data.api.ErrorCode
import com.infomaniak.drive.data.cache.DriveInfosController
import com.infomaniak.drive.data.documentprovider.CloudStorageProvider
import com.infomaniak.drive.data.models.drive.DriveInfo
import com.infomaniak.drive.databinding.ActivityLoginBinding
import com.infomaniak.drive.ui.MainActivity
import com.infomaniak.drive.utils.AccountUtils
import com.infomaniak.drive.utils.getInfomaniakLogin
Expand All @@ -50,13 +51,14 @@ import com.infomaniak.lib.core.utils.SnackbarUtils.showSnackbar
import com.infomaniak.lib.core.utils.Utils.lockOrientationForSmallScreens
import com.infomaniak.lib.login.ApiToken
import com.infomaniak.lib.login.InfomaniakLogin
import kotlinx.android.synthetic.main.activity_login.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class LoginActivity : AppCompatActivity() {

private val binding by lazy { ActivityLoginBinding.inflate(layoutInflater) }

private val infomaniakLogin: InfomaniakLogin by lazy { getInfomaniakLogin() }

private val webViewLoginResultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
Expand All @@ -70,8 +72,8 @@ class LoginActivity : AppCompatActivity() {
else -> showError(getString(R.string.anErrorHasOccurred))
}
} else {
connectButton?.hideProgress(R.string.connect)
signInButton.isEnabled = true
binding.connectButton.hideProgress(R.string.connect)
binding.signInButton.isEnabled = true
}
}
}
Expand All @@ -80,10 +82,10 @@ class LoginActivity : AppCompatActivity() {
result.handleCreateAccountActivityResult()
}

override fun onCreate(savedInstanceState: Bundle?) {
override fun onCreate(savedInstanceState: Bundle?): Unit = with(binding) {
lockOrientationForSmallScreens()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
setContentView(root)

introViewpager.apply {
adapter = IntroPagerAdapter(supportFragmentManager, lifecycle)
Expand Down Expand Up @@ -127,7 +129,7 @@ class LoginActivity : AppCompatActivity() {
}
}

private fun ActivityResult.handleCreateAccountActivityResult() {
private fun ActivityResult.handleCreateAccountActivityResult() = with(binding) {
if (resultCode == RESULT_OK) {
val translatedError = data?.getStringExtra(InfomaniakLogin.ERROR_TRANSLATED_TAG)
when {
Expand Down Expand Up @@ -178,9 +180,9 @@ class LoginActivity : AppCompatActivity() {
}
}

private fun showError(error: String) {
private fun showError(error: String) = with(binding) {
showSnackbar(error)
connectButton?.hideProgress(R.string.connect)
connectButton.hideProgress(R.string.connect)
signInButton.isEnabled = true
if (!connectButton.isEnabled) connectButton.isEnabled = true
}
Expand All @@ -189,9 +191,9 @@ class LoginActivity : AppCompatActivity() {
startActivity(Intent(this, MainActivity::class.java).clearStack())
}

private fun launchNoDriveActivity() {
Intent(this, NoDriveActivity::class.java).apply { startActivity(this) }
connectButton?.hideProgress(R.string.connect)
private fun launchNoDriveActivity() = with(binding) {
Intent(this@LoginActivity, NoDriveActivity::class.java).apply { startActivity(this) }
connectButton.hideProgress(R.string.connect)
signInButton.isEnabled = true
}

Expand Down

0 comments on commit 375bb2c

Please sign in to comment.