Compare commits
17 Commits
1.0.1
...
ms/issue-5
Author | SHA1 | Date | |
---|---|---|---|
a914e5e0fd | |||
54a57b65ab | |||
5f373a19d7 | |||
ea6c9c4ee0 | |||
f052470700 | |||
41676a6b54 | |||
ff04fb3102 | |||
514d1dff4e | |||
1f255951a0 | |||
a0e55683c6 | |||
75c0e004f6 | |||
9850c9fd08 | |||
8494e9183e | |||
d316ede233 | |||
5b5a9c28f2 | |||
148fd55e92 | |||
1f8fb61d6a |
@ -15,8 +15,8 @@ android {
|
|||||||
applicationId "fr.sanchezm.attestationsCovid19"
|
applicationId "fr.sanchezm.attestationsCovid19"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 3
|
versionCode 6
|
||||||
versionName "1.0.1"
|
versionName "1.0.4"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@ -27,8 +27,32 @@ android {
|
|||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled true
|
||||||
|
shrinkResources true
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
buildConfigField "Integer", "DB_VERSION", db_version
|
||||||
|
buildConfigField "Boolean", "TEST", "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
beta {
|
||||||
|
minifyEnabled true
|
||||||
|
shrinkResources true
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
buildConfigField "Integer", "DB_VERSION", db_version
|
||||||
|
buildConfigField "Boolean", "TEST", "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
alpha {
|
||||||
|
minifyEnabled true
|
||||||
|
shrinkResources true
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
buildConfigField "Integer", "DB_VERSION", db_version
|
||||||
|
buildConfigField "Boolean", "TEST", "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
debug {
|
||||||
|
buildConfigField "Integer", "DB_VERSION", db_version
|
||||||
|
buildConfigField "Boolean", "TEST", "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,27 +73,30 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
// Android X
|
||||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||||
implementation 'androidx.core:core-ktx:1.2.0'
|
implementation 'androidx.core:core-ktx:1.2.0'
|
||||||
implementation 'com.google.android.material:material:1.1.0'
|
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||||
|
|
||||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.1'
|
|
||||||
implementation 'androidx.navigation:navigation-fragment:2.2.1'
|
|
||||||
implementation 'androidx.navigation:navigation-ui-ktx:2.2.1'
|
|
||||||
implementation 'androidx.navigation:navigation-ui:2.2.1'
|
|
||||||
|
|
||||||
|
|
||||||
// Room
|
|
||||||
// implementation 'androidx.room:room-runtime:2.2.5'
|
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
||||||
|
|
||||||
|
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
|
||||||
|
implementation 'androidx.navigation:navigation-fragment:2.2.2'
|
||||||
|
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
|
||||||
|
implementation 'androidx.navigation:navigation-ui:2.2.2'
|
||||||
|
|
||||||
|
// Design
|
||||||
|
implementation 'com.google.android.material:material:1.1.0'
|
||||||
|
|
||||||
|
// Room
|
||||||
|
// implementation 'androidx.room:room-runtime:2.2.5'
|
||||||
// kapt 'androidx.room:room-compiler:2.2.5'
|
// kapt 'androidx.room:room-compiler:2.2.5'
|
||||||
|
|
||||||
// PDF
|
// PDF
|
||||||
implementation 'com.tom_roush:pdfbox-android:1.8.10.1'
|
implementation 'com.tom_roush:pdfbox-android:1.8.10.1'
|
||||||
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
|
//noinspection GradleDependency
|
||||||
|
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
|
||||||
|
|
||||||
// Gson
|
// Gson
|
||||||
implementation 'com.google.code.gson:gson:2.8.6'
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
@ -79,8 +106,10 @@ dependencies {
|
|||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
|
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
|
||||||
|
|
||||||
|
implementation 'com.github.Ilhasoft:data-binding-validator:2.0.0'
|
||||||
|
|
||||||
|
// Test
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
|
||||||
}
|
}
|
||||||
|
2
app/proguard-rules.pro
vendored
@ -19,3 +19,5 @@
|
|||||||
# If you keep the line number information, uncomment this to
|
# If you keep the line number information, uncomment this to
|
||||||
# hide the original source file name.
|
# hide the original source file name.
|
||||||
#-renamesourcefileattribute SourceFile
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
|
-keep class com.shockwave.*
|
@ -8,12 +8,6 @@
|
|||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.CAMERA"
|
android:name="android.permission.CAMERA"
|
||||||
tools:node="remove" />
|
tools:node="remove" />
|
||||||
<uses-permission
|
|
||||||
android:name="android.permission.READ_PHONE_STATE"
|
|
||||||
tools:node="remove" />
|
|
||||||
<uses-permission
|
|
||||||
android:name="android.permission.INTERNET"
|
|
||||||
tools:node="remove" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
@ -21,6 +15,7 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
|
tools:replace="android:allowBackup"
|
||||||
android:theme="@style/AppTheme.Light">
|
android:theme="@style/AppTheme.Light">
|
||||||
<activity android:name=".QrCodeActivity" />
|
<activity android:name=".QrCodeActivity" />
|
||||||
<activity android:name=".PdfViewerActivity" />
|
<activity android:name=".PdfViewerActivity" />
|
||||||
|
@ -2,17 +2,27 @@ package fr.sanchezm.attestationsCovid19.data.db
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.dao.AttestationDao
|
import fr.sanchezm.attestationsCovid19.data.db.dao.AttestationDao
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.db.dao.ConfigDao
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.dao.ProfileDao
|
import fr.sanchezm.attestationsCovid19.data.db.dao.ProfileDao
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
|
|
||||||
class MyDatabase private constructor(private val savePath: String, private val filesPath: String) {
|
class MyDatabase private constructor(private val savePath: String, private val filesPath: String) {
|
||||||
|
|
||||||
private var _profileDao: ProfileDao? = null
|
private var _profileDao: ProfileDao? = null
|
||||||
private var _attestationDao: AttestationDao? = null
|
private var _attestationDao: AttestationDao? = null
|
||||||
|
private var _configDao: ConfigDao? = null
|
||||||
|
|
||||||
fun profileDao(): ProfileDao = _profileDao ?: ProfileDao(savePath).also { _profileDao = it }
|
fun profileDao(configRepository: ConfigRepository): ProfileDao =
|
||||||
|
_profileDao ?: ProfileDao(savePath, configRepository).also { _profileDao = it }
|
||||||
|
|
||||||
fun attestationDao(): AttestationDao =
|
fun attestationDao(configRepository: ConfigRepository): AttestationDao =
|
||||||
_attestationDao ?: AttestationDao(savePath, filesPath).also { _attestationDao = it }
|
_attestationDao ?: AttestationDao(
|
||||||
|
savePath,
|
||||||
|
filesPath,
|
||||||
|
configRepository
|
||||||
|
).also { _attestationDao = it }
|
||||||
|
|
||||||
|
fun configDao(): ConfigDao = _configDao ?: ConfigDao(savePath).also { _configDao = it }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Volatile
|
@Volatile
|
||||||
@ -24,40 +34,3 @@ class MyDatabase private constructor(private val savePath: String, private val f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.room.Database
|
|
||||||
import androidx.room.Room
|
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.dao.AttestationDao
|
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.dao.ProfileDao
|
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
|
||||||
|
|
||||||
@Database(
|
|
||||||
entities = [Profile::class],
|
|
||||||
version = 1
|
|
||||||
)
|
|
||||||
abstract class MyDatabase private constructor() : RoomDatabase() {
|
|
||||||
|
|
||||||
abstract fun profileDao(): ProfileDao
|
|
||||||
abstract fun attestationDao(): AttestationDao
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@Volatile
|
|
||||||
private var instance: MyDatabase? = null
|
|
||||||
private val LOCK = Any()
|
|
||||||
|
|
||||||
operator fun invoke(context: Context) = instance ?: synchronized(LOCK) {
|
|
||||||
instance ?: buildDatabase(context).also { instance = it }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildDatabase(context: Context) =
|
|
||||||
Room.databaseBuilder(
|
|
||||||
context.applicationContext,
|
|
||||||
MyDatabase::class.java, "data.db"
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
@ -6,13 +6,18 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.entity.Attestation
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Attestation
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
import fr.sanchezm.attestationsCovid19.utilities.PdfUtils
|
import fr.sanchezm.attestationsCovid19.utilities.PdfUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class AttestationDao(private val savePath: String, private val filesPath: String) {
|
class AttestationDao(
|
||||||
|
private val savePath: String,
|
||||||
|
private val filesPath: String,
|
||||||
|
private val configRepository: ConfigRepository
|
||||||
|
) {
|
||||||
|
|
||||||
private var _attestations = MutableLiveData<ArrayList<Attestation>>()
|
private val _attestations = MutableLiveData<ArrayList<Attestation>>()
|
||||||
private var fileName = "attestation.db"
|
private val fileName = "attestation.db"
|
||||||
private val type = object : TypeToken<ArrayList<Attestation>>() {}.type
|
private val type = object : TypeToken<ArrayList<Attestation>>() {}.type
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@ -23,9 +28,8 @@ class AttestationDao(private val savePath: String, private val filesPath: String
|
|||||||
_attestations.value?.elementAt(id)
|
_attestations.value?.elementAt(id)
|
||||||
|
|
||||||
fun addAttestation(attestation: Attestation) {
|
fun addAttestation(attestation: Attestation) {
|
||||||
_attestations.value = _attestations.value ?: ArrayList()
|
|
||||||
|
|
||||||
_attestations.value?.add(attestation)
|
_attestations.value?.add(attestation)
|
||||||
|
_attestations.value = _attestations.value
|
||||||
Log.d(TAG, "Add Attestation : $attestation")
|
Log.d(TAG, "Add Attestation : $attestation")
|
||||||
save()
|
save()
|
||||||
}
|
}
|
||||||
@ -66,6 +70,8 @@ class AttestationDao(private val savePath: String, private val filesPath: String
|
|||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
_attestations.value = Gson().fromJson(file.readText(Charsets.UTF_8), type)
|
_attestations.value = Gson().fromJson(file.readText(Charsets.UTF_8), type)
|
||||||
|
} else {
|
||||||
|
_attestations.value = ArrayList()
|
||||||
}
|
}
|
||||||
_attestations.value?.forEach {
|
_attestations.value?.forEach {
|
||||||
val filePath = PdfUtils.getPath(filesPath, it.createAt)
|
val filePath = PdfUtils.getPath(filesPath, it.createAt)
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package fr.sanchezm.attestationsCovid19.data.db.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import fr.sanchezm.attestationsCovid19.BuildConfig
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Config
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class ConfigDao(private val savePath: String) {
|
||||||
|
|
||||||
|
private val _config = MutableLiveData<Config>()
|
||||||
|
private val fileName = "config.db"
|
||||||
|
|
||||||
|
fun getConfig(): LiveData<Config> =
|
||||||
|
_config
|
||||||
|
|
||||||
|
fun updateConfig(config: Config) {
|
||||||
|
_config.value = config
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun load() {
|
||||||
|
val file = File("$savePath/$fileName")
|
||||||
|
|
||||||
|
if (file.exists()) {
|
||||||
|
_config.value = Gson().fromJson(file.readText(Charsets.UTF_8), Config::class.java)
|
||||||
|
_config.value?.versionCode = BuildConfig.VERSION_CODE
|
||||||
|
_config.value?.versionName = BuildConfig.VERSION_NAME
|
||||||
|
} else {
|
||||||
|
_config.value =
|
||||||
|
Config(
|
||||||
|
BuildConfig.DB_VERSION,
|
||||||
|
BuildConfig.VERSION_NAME,
|
||||||
|
BuildConfig.VERSION_CODE,
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun save() {
|
||||||
|
File("$savePath/$fileName").writeText(Gson().toJson(_config.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,48 +1,77 @@
|
|||||||
package fr.sanchezm.attestationsCovid19.data.db.dao
|
package fr.sanchezm.attestationsCovid19.data.db.dao
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
|
import fr.sanchezm.attestationsCovid19.BuildConfig
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
|
import fr.sanchezm.attestationsCovid19.utilities.DbMigration
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class ProfileDao(private val path: String) {
|
class ProfileDao(private val path: String, private val configRepository: ConfigRepository) {
|
||||||
|
|
||||||
private var _profile = MutableLiveData<Profile>()
|
private val _profile = MutableLiveData<ArrayList<Profile>>()
|
||||||
private var fileName = "profile.db"
|
private val fileName = "profile.db"
|
||||||
|
private val type = object : TypeToken<ArrayList<Profile>>() {}.type
|
||||||
|
|
||||||
fun getProfile(): LiveData<Profile> =
|
@Suppress("UNCHECKED_CAST")
|
||||||
_profile
|
fun getProfiles(): LiveData<List<Profile>> =
|
||||||
|
_profile as LiveData<List<Profile>>
|
||||||
|
|
||||||
fun updateProfile(profile: Profile) {
|
fun getProfile(id: Int): Profile? =
|
||||||
_profile.value = profile
|
_profile.value?.get(id)
|
||||||
|
|
||||||
|
fun getProfileId(profile: Profile): Int? =
|
||||||
|
_profile.value?.indexOf(profile)
|
||||||
|
|
||||||
|
fun addProfile(profile: Profile): Int {
|
||||||
|
_profile.value?.add(profile)
|
||||||
|
_profile.value = _profile.value
|
||||||
save()
|
save()
|
||||||
|
|
||||||
|
return _profile.value?.indexOf(profile)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
load()
|
val currentDbVersion = configRepository.getConfig().value!!.dbVersion
|
||||||
|
val appDbVersion = BuildConfig.DB_VERSION
|
||||||
|
|
||||||
|
if (currentDbVersion != appDbVersion) {
|
||||||
|
if (currentDbVersion == 1 && appDbVersion == 2) {
|
||||||
|
_profile.value = DbMigration.migrateProfileFrom1To2("$path/$fileName")
|
||||||
|
save()
|
||||||
|
configRepository.getConfig().value!!.let {
|
||||||
|
it.dbVersion = appDbVersion
|
||||||
|
configRepository.updateConfig(it)
|
||||||
|
}
|
||||||
|
Log.d(TAG, "Db version update from $currentDbVersion to $appDbVersion")
|
||||||
|
} else {
|
||||||
|
File("$path/$fileName").delete()
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
load()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun load() {
|
private fun load() {
|
||||||
val file = File("$path/$fileName")
|
val file = File("$path/$fileName")
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
_profile.value = Gson().fromJson(file.readText(Charsets.UTF_8), Profile::class.java)
|
_profile.value = Gson().fromJson(file.readText(Charsets.UTF_8), type)
|
||||||
} else {
|
} else {
|
||||||
_profile.value = Profile("", "", "", "", "", "", "")
|
_profile.value = ArrayList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun save() {
|
private fun save() {
|
||||||
File("$path/$fileName").writeText(Gson().toJson(_profile.value))
|
File("$path/$fileName").writeText(Gson().toJson(_profile.value))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//@Dao
|
companion object {
|
||||||
//interface ProfileDao {
|
private val TAG = ProfileDao::class.simpleName
|
||||||
// @Insert(onConflict = OnConflictStrategy.REPLACE)
|
}
|
||||||
// fun insert(profile: Profile)
|
}
|
||||||
//
|
|
||||||
// @Query(value = "SELECT * FROM profile WHERE id = $CURRENT_PROFILE_ID")
|
|
||||||
// fun getProfile(): LiveData<Profile>
|
|
||||||
//}
|
|
||||||
|
@ -5,7 +5,6 @@ import java.util.*
|
|||||||
|
|
||||||
const val PATTERN = "dd/MM/yyyy 'a' HH'h'mm"
|
const val PATTERN = "dd/MM/yyyy 'a' HH'h'mm"
|
||||||
|
|
||||||
//@Entity(tableName = "attestation")
|
|
||||||
data class Attestation(
|
data class Attestation(
|
||||||
val profile: Profile,
|
val profile: Profile,
|
||||||
val exitDate: String,
|
val exitDate: String,
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package fr.sanchezm.attestationsCovid19.data.db.entity
|
||||||
|
|
||||||
|
data class Config(
|
||||||
|
var dbVersion: Int,
|
||||||
|
var versionName: String,
|
||||||
|
var versionCode: Int,
|
||||||
|
var selectProfileId: Int
|
||||||
|
)
|
@ -1,6 +1,5 @@
|
|||||||
package fr.sanchezm.attestationsCovid19.data.db.entity
|
package fr.sanchezm.attestationsCovid19.data.db.entity
|
||||||
|
|
||||||
//@Entity(tableName = "profile")
|
|
||||||
data class Profile(
|
data class Profile(
|
||||||
val firstName: String,
|
val firstName: String,
|
||||||
val lastName: String,
|
val lastName: String,
|
||||||
@ -10,8 +9,6 @@ data class Profile(
|
|||||||
val city: String,
|
val city: String,
|
||||||
val postalCode: String
|
val postalCode: String
|
||||||
) {
|
) {
|
||||||
// @PrimaryKey
|
|
||||||
// var id: Int = CURRENT_PROFILE_ID
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "Nom: $lastName; Prenom: $firstName; Naissance: $birthday a $birthPlace; Adresse: $address $postalCode $city"
|
return "Nom: $lastName; Prenom: $firstName; Naissance: $birthday a $birthPlace; Adresse: $address $postalCode $city"
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package fr.sanchezm.attestationsCovid19.data.repository
|
||||||
|
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.db.dao.ConfigDao
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Config
|
||||||
|
|
||||||
|
class ConfigRepository private constructor(private val configDao: ConfigDao) {
|
||||||
|
|
||||||
|
fun getConfig() = configDao.getConfig()
|
||||||
|
|
||||||
|
fun updateConfig(config: Config) = configDao.updateConfig(config)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Volatile
|
||||||
|
private var instance: ConfigRepository? = null
|
||||||
|
|
||||||
|
fun getInstance(configDao: ConfigDao) =
|
||||||
|
instance ?: synchronized(this) {
|
||||||
|
instance ?: ConfigRepository(configDao).also { instance = it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,11 +6,14 @@ import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
|||||||
|
|
||||||
class ProfileRepository private constructor(private val profileDao: ProfileDao) {
|
class ProfileRepository private constructor(private val profileDao: ProfileDao) {
|
||||||
|
|
||||||
fun getProfile(): LiveData<Profile> =
|
fun getProfiles(): LiveData<List<Profile>> =
|
||||||
profileDao.getProfile()
|
profileDao.getProfiles()
|
||||||
|
|
||||||
fun insertProfile(profile: Profile) =
|
fun getProfile(id: Int): Profile? =
|
||||||
profileDao.updateProfile(profile)
|
profileDao.getProfile(id)
|
||||||
|
|
||||||
|
fun insertProfile(profile: Profile): Int =
|
||||||
|
profileDao.addProfile(profile)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Volatile
|
@Volatile
|
||||||
|
@ -10,6 +10,7 @@ import fr.sanchezm.attestationsCovid19.R
|
|||||||
import fr.sanchezm.attestationsCovid19.data.db.entity.Attestation
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Attestation
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.ProfileRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.ProfileRepository
|
||||||
import fr.sanchezm.attestationsCovid19.utilities.Event
|
import fr.sanchezm.attestationsCovid19.utilities.Event
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@ -18,6 +19,7 @@ import java.time.format.DateTimeFormatter
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class AddViewModel(
|
class AddViewModel(
|
||||||
|
private val configRepository: ConfigRepository,
|
||||||
private val profileRepository: ProfileRepository,
|
private val profileRepository: ProfileRepository,
|
||||||
private val attestationRepository: AttestationRepository
|
private val attestationRepository: AttestationRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
@ -79,15 +81,15 @@ class AddViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setProfileValue() {
|
private fun setProfileValue() {
|
||||||
val profile = profileRepository.getProfile()
|
val profile = profileRepository.getProfiles().value?.first()
|
||||||
|
|
||||||
firstName.value = profile.value?.firstName
|
firstName.value = profile?.firstName
|
||||||
lastName.value = profile.value?.lastName
|
lastName.value = profile?.lastName
|
||||||
birthday.value = profile.value?.birthday
|
birthday.value = profile?.birthday
|
||||||
birthPlace.value = profile.value?.birthPlace
|
birthPlace.value = profile?.birthPlace
|
||||||
address.value = profile.value?.address
|
address.value = profile?.address
|
||||||
city.value = profile.value?.city
|
city.value = profile?.city
|
||||||
postalCode.value = profile.value?.postalCode
|
postalCode.value = profile?.postalCode
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setDateHourToday() {
|
private fun setDateHourToday() {
|
||||||
|
@ -3,9 +3,11 @@ package fr.sanchezm.attestationsCovid19.ui.add
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.ProfileRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.ProfileRepository
|
||||||
|
|
||||||
class AddViewModelFactory(
|
class AddViewModelFactory(
|
||||||
|
private val configRepository: ConfigRepository,
|
||||||
private val profileRepository: ProfileRepository,
|
private val profileRepository: ProfileRepository,
|
||||||
private val attestationRepository: AttestationRepository
|
private val attestationRepository: AttestationRepository
|
||||||
) :
|
) :
|
||||||
@ -13,6 +15,6 @@ class AddViewModelFactory(
|
|||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
return AddViewModel(profileRepository, attestationRepository) as T
|
return AddViewModel(configRepository, profileRepository, attestationRepository) as T
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,9 +5,14 @@ import androidx.lifecycle.LiveData
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
import fr.sanchezm.attestationsCovid19.utilities.Event
|
import fr.sanchezm.attestationsCovid19.utilities.Event
|
||||||
|
|
||||||
class AttestationsViewModel(attestationRepository: AttestationRepository) : ViewModel() {
|
class AttestationsViewModel(
|
||||||
|
private val configRepository: ConfigRepository,
|
||||||
|
attestationRepository: AttestationRepository
|
||||||
|
) :
|
||||||
|
ViewModel() {
|
||||||
|
|
||||||
private val _startActivity = MutableLiveData<Event<Long>>()
|
private val _startActivity = MutableLiveData<Event<Long>>()
|
||||||
private var _displayNoAttestation = MutableLiveData<Int>()
|
private var _displayNoAttestation = MutableLiveData<Int>()
|
||||||
|
@ -3,13 +3,16 @@ package fr.sanchezm.attestationsCovid19.ui.attestations
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.ProfileRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
|
|
||||||
class AttestationsViewModelFactory(private val attestationRepository: AttestationRepository) :
|
class AttestationsViewModelFactory(
|
||||||
|
private val configRepository: ConfigRepository,
|
||||||
|
private val attestationRepository: AttestationRepository
|
||||||
|
) :
|
||||||
ViewModelProvider.NewInstanceFactory() {
|
ViewModelProvider.NewInstanceFactory() {
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
return AttestationsViewModel(attestationRepository) as T
|
return AttestationsViewModel(configRepository, attestationRepository) as T
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,12 +5,18 @@ import android.view.View
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import fr.sanchezm.attestationsCovid19.R
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.entity.Attestation
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Attestation
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
import fr.sanchezm.attestationsCovid19.utilities.Event
|
import fr.sanchezm.attestationsCovid19.utilities.Event
|
||||||
import fr.sanchezm.attestationsCovid19.utilities.QRCodeUtils
|
import fr.sanchezm.attestationsCovid19.utilities.QRCodeUtils
|
||||||
|
|
||||||
class QrCodeViewModel(private val attestationRepository: AttestationRepository) : ViewModel() {
|
class QrCodeViewModel(
|
||||||
|
private val configRepository: ConfigRepository,
|
||||||
|
private val attestationRepository: AttestationRepository
|
||||||
|
) :
|
||||||
|
ViewModel() {
|
||||||
|
|
||||||
private val _attestation = MutableLiveData<Attestation>()
|
private val _attestation = MutableLiveData<Attestation>()
|
||||||
|
|
||||||
@ -23,6 +29,7 @@ class QrCodeViewModel(private val attestationRepository: AttestationRepository)
|
|||||||
|
|
||||||
private val _startActivity = MutableLiveData<Event<Long>>()
|
private val _startActivity = MutableLiveData<Event<Long>>()
|
||||||
private val _finish = MutableLiveData<Event<Boolean>>()
|
private val _finish = MutableLiveData<Event<Boolean>>()
|
||||||
|
private val _error = MutableLiveData<Event<Int>>()
|
||||||
|
|
||||||
val attestation: LiveData<Attestation> = _attestation
|
val attestation: LiveData<Attestation> = _attestation
|
||||||
|
|
||||||
@ -35,6 +42,7 @@ class QrCodeViewModel(private val attestationRepository: AttestationRepository)
|
|||||||
|
|
||||||
val startActivity: LiveData<Event<Long>> = _startActivity
|
val startActivity: LiveData<Event<Long>> = _startActivity
|
||||||
val finish: LiveData<Event<Boolean>> = _finish
|
val finish: LiveData<Event<Boolean>> = _finish
|
||||||
|
val error: LiveData<Event<Int>> = _error
|
||||||
|
|
||||||
fun addData(createAt: Long, toCreate: Boolean) {
|
fun addData(createAt: Long, toCreate: Boolean) {
|
||||||
val att = attestationRepository.getAttestation(createAt)
|
val att = attestationRepository.getAttestation(createAt)
|
||||||
@ -64,6 +72,8 @@ class QrCodeViewModel(private val attestationRepository: AttestationRepository)
|
|||||||
) { success ->
|
) { success ->
|
||||||
if (success)
|
if (success)
|
||||||
displayQrCode()
|
displayQrCode()
|
||||||
|
else
|
||||||
|
_error.value = Event(R.string.error_failed_create_pdf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,16 @@ package fr.sanchezm.attestationsCovid19.ui.qrcode
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
|
|
||||||
class QrCodeViewModelFactory(private val attestationRepository: AttestationRepository) :
|
class QrCodeViewModelFactory(
|
||||||
|
private val configRepository: ConfigRepository,
|
||||||
|
private val attestationRepository: AttestationRepository
|
||||||
|
) :
|
||||||
ViewModelProvider.NewInstanceFactory() {
|
ViewModelProvider.NewInstanceFactory() {
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||||
return QrCodeViewModel(attestationRepository) as T
|
return QrCodeViewModel(configRepository, attestationRepository) as T
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package fr.sanchezm.attestationsCovid19.utilities
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
object DbMigration {
|
||||||
|
|
||||||
|
fun migrateProfileFrom1To2(filename: String): ArrayList<Profile> {
|
||||||
|
val file = File(filename)
|
||||||
|
val list = ArrayList<Profile>()
|
||||||
|
|
||||||
|
val profile: Profile = if (file.exists()) {
|
||||||
|
Gson().fromJson(file.readText(Charsets.UTF_8), Profile::class.java)
|
||||||
|
} else {
|
||||||
|
Profile("", "", "", "", "", "", "")
|
||||||
|
}
|
||||||
|
list.add(profile)
|
||||||
|
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import fr.sanchezm.attestationsCovid19.data.db.MyDatabase
|
import fr.sanchezm.attestationsCovid19.data.db.MyDatabase
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
|
import fr.sanchezm.attestationsCovid19.data.repository.ConfigRepository
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.ProfileRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.ProfileRepository
|
||||||
import fr.sanchezm.attestationsCovid19.ui.add.AddViewModelFactory
|
import fr.sanchezm.attestationsCovid19.ui.add.AddViewModelFactory
|
||||||
import fr.sanchezm.attestationsCovid19.ui.attestations.AttestationsViewModelFactory
|
import fr.sanchezm.attestationsCovid19.ui.attestations.AttestationsViewModelFactory
|
||||||
@ -11,41 +12,43 @@ import fr.sanchezm.attestationsCovid19.ui.qrcode.QrCodeViewModelFactory
|
|||||||
|
|
||||||
object InjectorUtils {
|
object InjectorUtils {
|
||||||
|
|
||||||
fun provideAddViewModelFactory(context: Context): AddViewModelFactory {
|
fun provideAddViewModelFactory(context: Context): AddViewModelFactory =
|
||||||
val profileRepository =
|
AddViewModelFactory(
|
||||||
ProfileRepository.getInstance(
|
getConfigRepo(context),
|
||||||
MyDatabase.invoke(context, getMyFilesDir(context)).profileDao()
|
getProfileRepo(context),
|
||||||
)
|
getAttestationRepo(context)
|
||||||
val attestationRepository =
|
)
|
||||||
AttestationRepository.getInstance(
|
|
||||||
MyDatabase.invoke(context, getMyFilesDir(context)).attestationDao()
|
|
||||||
)
|
|
||||||
|
|
||||||
return AddViewModelFactory(profileRepository, attestationRepository)
|
fun provideAttestationViewModel(context: Context): AttestationsViewModelFactory =
|
||||||
}
|
AttestationsViewModelFactory(
|
||||||
|
getConfigRepo(context),
|
||||||
|
getAttestationRepo(context)
|
||||||
|
)
|
||||||
|
|
||||||
fun provideAttestationViewModel(context: Context): AttestationsViewModelFactory {
|
fun provideQrCodeViewModel(context: Context): QrCodeViewModelFactory =
|
||||||
val attestationRepository =
|
QrCodeViewModelFactory(
|
||||||
AttestationRepository.getInstance(
|
getConfigRepo(context),
|
||||||
MyDatabase.invoke(context, getMyFilesDir(context)).attestationDao()
|
getAttestationRepo(context)
|
||||||
)
|
)
|
||||||
|
|
||||||
return AttestationsViewModelFactory(attestationRepository)
|
fun providePdfUtils(context: Context): PdfUtils =
|
||||||
}
|
PdfUtils.getInstance(context.assets, getMyFilesDir(context))
|
||||||
|
|
||||||
fun provideQrCodeViewModel(context: Context): QrCodeViewModelFactory {
|
private fun getMyFilesDir(context: Context): String =
|
||||||
val attestationRepository =
|
context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)?.path!!
|
||||||
AttestationRepository.getInstance(
|
|
||||||
MyDatabase.invoke(context, getMyFilesDir(context)).attestationDao()
|
|
||||||
)
|
|
||||||
|
|
||||||
return QrCodeViewModelFactory(attestationRepository)
|
private fun getAttestationRepo(context: Context): AttestationRepository =
|
||||||
}
|
AttestationRepository.getInstance(
|
||||||
|
MyDatabase.invoke(context, getMyFilesDir(context))
|
||||||
|
.attestationDao(getConfigRepo(context))
|
||||||
|
)
|
||||||
|
|
||||||
fun providePdfUtils(context: Context): PdfUtils {
|
private fun getProfileRepo(context: Context): ProfileRepository = ProfileRepository.getInstance(
|
||||||
return PdfUtils.getInstance(context.assets, getMyFilesDir(context))
|
MyDatabase.invoke(context, getMyFilesDir(context)).profileDao(getConfigRepo(context))
|
||||||
}
|
)
|
||||||
|
|
||||||
private fun getMyFilesDir(context: Context): String = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)?.path!!
|
private fun getConfigRepo(context: Context): ConfigRepository = ConfigRepository.getInstance(
|
||||||
|
MyDatabase.invoke(context, getMyFilesDir(context)).configDao()
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
@ -33,14 +33,17 @@ class PdfUtils private constructor(
|
|||||||
val acroForm = docCatalog.acroForm
|
val acroForm = docCatalog.acroForm
|
||||||
|
|
||||||
// Adding data
|
// Adding data
|
||||||
setFieldsData(acroForm, attestation)
|
if (setFieldsData(acroForm, attestation)) {
|
||||||
setCheckboxFields(acroForm, attestation)
|
setCheckboxFields(acroForm, attestation)
|
||||||
addPageWithQrCode(document, attestation)
|
addPageWithQrCode(document, attestation)
|
||||||
|
|
||||||
Log.v("PdfUtils", "Save File to ${getPath(attestation.createAt)}")
|
Log.v("PdfUtils", "Save File to ${getPath(attestation.createAt)}")
|
||||||
document.save(getPath(attestation.createAt))
|
document.save(getPath(attestation.createAt))
|
||||||
document.close()
|
document.close()
|
||||||
callback(true)
|
callback(true)
|
||||||
|
} else {
|
||||||
|
callback(false)
|
||||||
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
callback(false)
|
callback(false)
|
||||||
@ -106,29 +109,34 @@ class PdfUtils private constructor(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setFieldsData(acroForm: PDAcroForm, attestation: Attestation) {
|
private fun setFieldsData(acroForm: PDAcroForm, attestation: Attestation): Boolean {
|
||||||
val profile = attestation.profile
|
val profile = attestation.profile
|
||||||
|
|
||||||
// Init Fields
|
try {
|
||||||
val namesField = acroForm.getField("Nom et prénom") as PDTextField
|
// Init Fields
|
||||||
val birthdayField = acroForm.getField("Date de naissance") as PDTextField
|
val namesField = acroForm.getField("Nom et prénom") as PDTextField
|
||||||
val birthPlaceField = acroForm.getField("Lieu de naissance") as PDTextField
|
val birthdayField = acroForm.getField("Date de naissance") as PDTextField
|
||||||
val addressField = acroForm.getField("Adresse actuelle") as PDTextField
|
val birthPlaceField = acroForm.getField("Lieu de naissance") as PDTextField
|
||||||
val cityField = acroForm.getField("Ville") as PDTextField
|
val addressField = acroForm.getField("Adresse actuelle") as PDTextField
|
||||||
val dateField = acroForm.getField("Date") as PDTextField
|
val cityField = acroForm.getField("Ville") as PDTextField
|
||||||
val hourField = acroForm.getField("Heure") as PDTextField
|
val dateField = acroForm.getField("Date") as PDTextField
|
||||||
val minutesField = acroForm.getField("Minute") as PDTextField
|
val hourField = acroForm.getField("Heure") as PDTextField
|
||||||
|
val minutesField = acroForm.getField("Minute") as PDTextField
|
||||||
// val signatureField = acroForm.getField("Signature") as PDTextField
|
// val signatureField = acroForm.getField("Signature") as PDTextField
|
||||||
|
|
||||||
namesField.value = "${profile.firstName} ${profile.lastName}"
|
namesField.value = "${profile.firstName} ${profile.lastName}"
|
||||||
birthdayField.value = profile.birthday
|
birthdayField.value = profile.birthday
|
||||||
birthPlaceField.value = profile.birthPlace
|
birthPlaceField.value = profile.birthPlace
|
||||||
addressField.value = "${profile.address} ${profile.postalCode} ${profile.city}"
|
addressField.value = "${profile.address} ${profile.postalCode} ${profile.city}"
|
||||||
cityField.value = profile.city
|
cityField.value = profile.city
|
||||||
dateField.value = attestation.exitDate
|
dateField.value = attestation.exitDate
|
||||||
hourField.value = attestation.exitHour.split("h")[0]
|
hourField.value = attestation.exitHour.split("h")[0]
|
||||||
minutesField.value = attestation.exitHour.split("h")[1]
|
minutesField.value = attestation.exitHour.split("h")[1]
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "${e.message}")
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setCheckboxFields(acroForm: PDAcroForm, attestation: Attestation) {
|
private fun setCheckboxFields(acroForm: PDAcroForm, attestation: Attestation) {
|
||||||
@ -150,6 +158,7 @@ class PdfUtils private constructor(
|
|||||||
private var instance: PdfUtils? = null
|
private var instance: PdfUtils? = null
|
||||||
private val LOCK = Any()
|
private val LOCK = Any()
|
||||||
private const val folderPath = "attestations"
|
private const val folderPath = "attestations"
|
||||||
|
private val TAG = PdfUtils::class.simpleName
|
||||||
|
|
||||||
fun getInstance() = instance
|
fun getInstance() = instance
|
||||||
|
|
||||||
|
@ -88,7 +88,9 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="date"
|
android:inputType="date"
|
||||||
android:text="@={viewModel.birthday}" />
|
android:text="@={viewModel.birthday}"
|
||||||
|
app:validateDate='@{"dd/MM/yyyy"}'
|
||||||
|
app:validateDateMessage="@{@string/date_error_message}"/>
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
@ -117,7 +119,7 @@
|
|||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="textPostalAddress|textCapWords"
|
android:inputType="number|textCapWords"
|
||||||
android:text="@={viewModel.address}" />
|
android:text="@={viewModel.address}" />
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
@ -163,7 +165,9 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="date"
|
android:inputType="date"
|
||||||
android:text="@={viewModel.exitDate}" />
|
android:text="@={viewModel.exitDate}"
|
||||||
|
app:validateDate='@{"dd/MM/yyyy"}'
|
||||||
|
app:validateDateMessage="@{@string/date_error_message}"/>
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 2.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 4.5 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 1.5 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.6 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 5.3 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 6.4 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 5.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 8.1 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 13 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp
Normal file
After Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 15 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 11 KiB |
9
app/src/main/res/values/errors.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<!-- Validator -->
|
||||||
|
<string name="date_error_message">Votre date doit être au format 01/01/1970</string>
|
||||||
|
|
||||||
|
<string name="error_cannot_create_attestation">Erreur lors de la génération de l\'attestation, tout les champs ne sont pas compléter</string>
|
||||||
|
<string name="error_failed_create_pdf">Erreur lors de la génération de l\'attestion, veuillez vérifiez vos champs ou contacter le développeur.</string>
|
||||||
|
</resources>
|
@ -7,7 +7,6 @@
|
|||||||
<!-- Attestation Fragment -->
|
<!-- Attestation Fragment -->
|
||||||
<string name="attestation_title">Attestation de déplacement dérogatoire</string>
|
<string name="attestation_title">Attestation de déplacement dérogatoire</string>
|
||||||
<string name="attestation_subtitle">#RestonsChezNous</string>
|
<string name="attestation_subtitle">#RestonsChezNous</string>
|
||||||
<string name="error_cannot_create_attestation">Erreur lors de la génération de l\'attestation, tout les champs ne sont pas compléter</string>
|
|
||||||
<string name="attestation_generated">Attestation générer</string>
|
<string name="attestation_generated">Attestation générer</string>
|
||||||
<string name="no_attestation">Aucune attestation, veuillez en générer une.</string>
|
<string name="no_attestation">Aucune attestation, veuillez en générer une.</string>
|
||||||
|
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.3.72'
|
ext {
|
||||||
|
kotlin_version = '1.3.72'
|
||||||
|
db_version = '2'
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
@ -20,7 +24,7 @@ allprojects {
|
|||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
maven { url 'https://jitpack.io' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|