mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Converted Config Utils to Kotlin (#3674)
* Converted Config Utils to Kotlin * Changes made as per suggestion * Omitted this
This commit is contained in:
parent
6e60bbf8f5
commit
22c20687f3
2 changed files with 24 additions and 27 deletions
|
|
@ -1,27 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
|
||||
public class ConfigUtils {
|
||||
|
||||
public static boolean isBetaFlavour() {
|
||||
return BuildConfig.FLAVOR.equals("beta");
|
||||
}
|
||||
|
||||
private static String getVersionName(Context context) {
|
||||
try {
|
||||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return BuildConfig.VERSION_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getVersionNameWithSha(Context context) {
|
||||
return String.format(Locale.getDefault(), "%s~%s", getVersionName(context), BuildConfig.COMMIT_SHA);
|
||||
}
|
||||
}
|
||||
24
app/src/main/java/fr/free/nrw/commons/utils/ConfigUtils.kt
Normal file
24
app/src/main/java/fr/free/nrw/commons/utils/ConfigUtils.kt
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import fr.free.nrw.commons.BuildConfig
|
||||
|
||||
object ConfigUtils {
|
||||
@JvmStatic
|
||||
val isBetaFlavour: Boolean = BuildConfig.FLAVOR == "beta"
|
||||
|
||||
@JvmStatic
|
||||
private fun Context.getVersionName(): String {
|
||||
return try {
|
||||
packageManager.getPackageInfo(packageName, 0).versionName
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
BuildConfig.VERSION_NAME
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Context.getVersionNameWithSha(): String {
|
||||
return "${getVersionName()}~${BuildConfig.COMMIT_SHA}"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue