Skip to content

Commit

Permalink
ktlint
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Feb 19, 2024
1 parent 5f9001f commit 6067107
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
19 changes: 10 additions & 9 deletions app/src/main/java/org/dhis2/usescases/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ import androidx.databinding.DataBindingUtil
import com.google.android.material.composethemeadapter.MdcTheme
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.io.BufferedReader
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStreamReader
import java.io.StringWriter
import javax.inject.Inject
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.dhis2.App
import org.dhis2.R
Expand Down Expand Up @@ -65,6 +58,13 @@ import org.dhis2.utils.session.PIN_DIALOG_TAG
import org.dhis2.utils.session.PinDialog
import org.hisp.dhis.android.core.user.openid.IntentWithRequestCode
import timber.log.Timber
import java.io.BufferedReader
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStreamReader
import java.io.StringWriter
import javax.inject.Inject

const val EXTRA_SKIP_SYNC = "SKIP_SYNC"
const val EXTRA_SESSION_EXPIRED = "EXTRA_SESSION_EXPIRED"
Expand Down Expand Up @@ -114,8 +114,9 @@ class LoginActivity : ActivityGlobalAbstract(), LoginContracts.View {
} catch (e: IOException) {
Timber.e("Failed to load file: ", e.message.toString())
}
if (file.exists())
if (file.exists()) {
presenter.onImportDataBase(file)
}
}
}

Expand Down Expand Up @@ -258,7 +259,7 @@ class LoginActivity : ActivityGlobalAbstract(), LoginContracts.View {

private fun checkUrl(urlString: String): Boolean {
return URLUtil.isValidUrl(urlString) &&
Patterns.WEB_URL.matcher(urlString).matches() && urlString.toHttpUrlOrNull() != null
Patterns.WEB_URL.matcher(urlString).matches() && urlString.toHttpUrlOrNull() != null
}

override fun setTestingCredentials() {
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/org/dhis2/usescases/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import java.io.File
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import org.dhis2.commons.Constants.PREFS_URLS
Expand Down Expand Up @@ -47,6 +46,7 @@ import org.hisp.dhis.android.core.systeminfo.SystemInfo
import org.hisp.dhis.android.core.user.openid.OpenIDConnectConfig
import retrofit2.Response
import timber.log.Timber
import java.io.File

const val VERSION = "version"

Expand Down Expand Up @@ -77,7 +77,7 @@ class LoginViewModel(
val loginProgressVisible: LiveData<Boolean> = _loginProgressVisible

private val _hasAccounts = MutableLiveData<Boolean>()
val hasAccounts : LiveData<Boolean> = _hasAccounts
val hasAccounts: LiveData<Boolean> = _hasAccounts

init {
this.userManager?.let {
Expand Down Expand Up @@ -367,13 +367,13 @@ class LoginViewModel(

fun areSameCredentials(): Boolean {
return (
preferenceProvider.areCredentialsSet() &&
preferenceProvider.areSameCredentials(
serverUrl.value!!,
userName.value!!,
password.value!!,
)
).also { areSameCredentials -> if (!areSameCredentials) saveUserCredentials() }
preferenceProvider.areCredentialsSet() &&
preferenceProvider.areSameCredentials(
serverUrl.value!!,
userName.value!!,
password.value!!,
)
).also { areSameCredentials -> if (!areSameCredentials) saveUserCredentials() }
}

private fun saveUserCredentials() {
Expand Down Expand Up @@ -530,8 +530,8 @@ class LoginViewModel(

private fun checkData() {
val newValue = !serverUrl.value.isNullOrEmpty() &&
!userName.value.isNullOrEmpty() &&
!password.value.isNullOrEmpty()
!userName.value.isNullOrEmpty() &&
!password.value.isNullOrEmpty()
if (isDataComplete.value == null || isDataComplete.value != newValue) {
isDataComplete.value = newValue
}
Expand Down Expand Up @@ -566,7 +566,8 @@ class LoginViewModel(
}
val importedMetadata = try {
importResult.await()
}catch (e:Exception){
}
catch (e: Exception) {
view.displayMessage(resourceManager.parseD2Error(e))
Timber.e(e)
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.dhis2.utils.analytics.AnalyticsHelper
class LoginViewModelFactory(
private val view: LoginContracts.View,
private val preferenceProvider: PreferenceProvider,
private val resources:ResourceManager,
private val resources: ResourceManager,
private val schedulerProvider: SchedulerProvider,
private val fingerPrintController: FingerPrintController,
private val analyticsHelper: AnalyticsHelper,
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/org/dhis2/usescases/login/ui/LoginScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor
@Composable
fun LoginTopBar(
version: String,
onImportDatabase: () -> Unit
onImportDatabase: () -> Unit,
) {
var expanded by remember { mutableStateOf(false) }

ConstraintLayout(
modifier = Modifier
.fillMaxWidth()
.height(80.dp)
.background(MaterialTheme.colors.primary)
.background(MaterialTheme.colors.primary),
) {
val (logoLayout, versionLabel) = createRefs()

Expand All @@ -65,29 +65,30 @@ fun LoginTopBar(
}
.padding(horizontal = 4.dp),
horizontalArrangement = spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically,
) {
Spacer(
modifier = Modifier
.size(48.dp)
.size(48.dp),
)
Image(
modifier = Modifier
.weight(1f)
.height(48.dp),
painter = painterResource(id = R.drawable.ic_dhis_white),
contentDescription = "dhis2 logo"
contentDescription = "dhis2 logo",
)

Box {
IconButton(
modifier = Modifier
.size(48.dp),
onClick = { expanded = true }) {
onClick = { expanded = true },
) {
Icon(
imageVector = Icons.Filled.MoreVert,
contentDescription = "More options",
tint = MaterialTheme.colors.onPrimary
tint = MaterialTheme.colors.onPrimary,
)
}

Expand All @@ -102,12 +103,12 @@ fun LoginTopBar(
.height(48.dp)
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = spacedBy(16.dp)
horizontalArrangement = spacedBy(16.dp),
) {
Icon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_import_db),
contentDescription = "Import database",
tint = MaterialTheme.colors.primary
tint = MaterialTheme.colors.primary,
)

Text(
Expand All @@ -119,7 +120,7 @@ fun LoginTopBar(
fontWeight = FontWeight.Medium,
color = Color.Black,
letterSpacing = 0.5.sp,
)
),
)
}
}
Expand All @@ -140,7 +141,7 @@ fun LoginTopBar(
fontWeight = FontWeight.Medium,
color = TextColor.OnPrimary,
letterSpacing = 0.5.sp,
)
),
)
}
}
Expand All @@ -151,4 +152,4 @@ private fun PreviewLoginTopBar() {
DHIS2Theme {
LoginTopBar(version = "v2.9") {}
}
}
}

0 comments on commit 6067107

Please sign in to comment.