Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
Expand All @@ -86,6 +87,7 @@ import org.smartregister.fhircore.engine.ui.theme.LoginButtonColor
import org.smartregister.fhircore.engine.ui.theme.LoginDarkColor
import org.smartregister.fhircore.engine.ui.theme.LoginFieldBackgroundColor
import org.smartregister.fhircore.engine.util.annotation.ExcludeFromJacocoGeneratedReport
import org.smartregister.fhircore.engine.util.extension.appVersion

const val APP_NAME_TEXT_TAG = "aapNameTextTag"
const val USERNAME_FIELD_TAG = "usernameFieldTag"
Expand Down Expand Up @@ -147,6 +149,8 @@ fun LoginPage(
val forgotPasswordColor = if (viewConfiguration.darkMode) Color.White else LoginButtonColor
var showForgotPasswordDialog by remember { mutableStateOf(false) }
val focusManager = LocalFocusManager.current
val context = LocalContext.current
val (versionCode, versionName) = remember { context.appVersion() }

Surface(
modifier =
Expand Down Expand Up @@ -335,12 +339,7 @@ fun LoginPage(
Text(
color = contentColor,
fontSize = 16.sp,
text =
stringResource(
id = R.string.app_version,
viewConfiguration.applicationVersionCode,
viewConfiguration.applicationVersion
),
text = stringResource(id = R.string.app_version, versionCode, versionName),
modifier = modifier.wrapContentWidth().padding(0.dp).testTag(LOGIN_FOOTER)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.smartregister.fhircore.engine.util.extension
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.drawable.Drawable
Expand Down Expand Up @@ -68,6 +69,18 @@ fun Context.setAppLocale(languageTag: String): Configuration? {
return configuration
}

/** Return a pair of application versionCode and versionName e.g. Pair(1, 0.0.1) */
fun Context.appVersion(): Pair<Long, String> {
val packageInfo: PackageInfo? = this.packageManager.getPackageInfo(this.packageName, 0)
val versionCode =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo?.longVersionCode
} else {
packageInfo?.versionCode?.toLong()
}
return Pair(versionCode ?: 1, packageInfo?.versionName?.substringBefore("-") ?: "0.0.1")
}

fun Context.getDrawable(name: String): Drawable {
var resourceId = this.resources.getIdentifier(name, "drawable", packageName)
if (resourceId == 0) resourceId = R.drawable.ic_app_logo
Expand Down