Skip to content

Commit

Permalink
Improvement/code cleanup (#231)
Browse files Browse the repository at this point in the history
- fix lint warnings;
- code cleanup in verification package;
- remove empty spaces;
- improve readability;
- improve formatting;
  • Loading branch information
MykhailoNester authored Oct 11, 2021
1 parent ec83d6d commit 738b442
Show file tree
Hide file tree
Showing 104 changed files with 658 additions and 835 deletions.
16 changes: 16 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.fasterxml.jackson.databind.ObjectMapper
import dgca.verifier.app.android.data.local.rules.EngineDatabase
import dgca.verifier.app.android.data.local.rules.RuleWithDescriptionsLocal
import dgca.verifier.app.android.data.local.model.RuleWithDescriptionsLocal
import dgca.verifier.app.android.data.local.rules.RulesDao
import dgca.verifier.app.android.data.local.rules.toRuleWithDescriptionLocal
import dgca.verifier.app.engine.data.RuleCertificateType
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/dgca/verifier/app/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import dagger.hilt.android.AndroidEntryPoint
import dgca.verifier.app.android.nfc.NdefParser
import dgca.verifier.app.android.reader.CodeReaderFragment
import timber.log.Timber

@AndroidEntryPoint
Expand All @@ -43,7 +44,10 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
if (!BuildConfig.DEBUG) {
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
}

setContentView(R.layout.activity_main)

navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class AnonymizationManager @Inject constructor() {
dateOfBirth = dateOfBirth
)
}

}

fun String.anonymize(): String {
Expand Down Expand Up @@ -143,5 +142,6 @@ fun String.anonymize(): String {
fun String.anonymizeCi(): String {
val ciPart = substring(lastIndexOf(":") + 1)
val ciAnonymize = "[A-Za-z0-9]".toRegex().replace(ciPart, "X")

return replaceAfterLast(":", ciAnonymize)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ class ConfigRepositoryImpl @Inject constructor(
private val remoteConfigDataSource: RemoteConfigDataSource
) : ConfigRepository {

override fun local(): ConfigDataSource {
return localConfigDataSource
}
override fun local(): ConfigDataSource = localConfigDataSource

override fun getConfig(): Config {
return remoteConfigDataSource.getConfig(
override fun getConfig(): Config =
remoteConfigDataSource.getConfig(
localConfigDataSource.getConfig().getContextUrl(BuildConfig.VERSION_NAME)
).apply {
localConfigDataSource.setConfig(this)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ package dgca.verifier.app.android.data
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import dgca.verifier.app.android.data.local.AppDatabase
import dgca.verifier.app.android.data.local.Key
import dgca.verifier.app.android.data.local.Preferences
import dgca.verifier.app.android.data.local.model.Key
import dgca.verifier.app.android.data.remote.ApiService
import dgca.verifier.app.android.security.KeyStoreCryptor
import dgca.verifier.app.decoder.base64ToX509Certificate
Expand All @@ -48,8 +48,7 @@ class VerifierRepositoryImpl @Inject constructor(

private val validCertList = mutableListOf<String>()
private val mutex = Mutex()
private val lastSyncLiveData: MutableLiveData<Long> =
MutableLiveData(preferences.lastKeysSyncTimeMillis)
private val lastSyncLiveData: MutableLiveData<Long> = MutableLiveData(preferences.lastKeysSyncTimeMillis)

override suspend fun fetchCertificates(statusUrl: String, updateUrl: String): Boolean? {
mutex.withLock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package dgca.verifier.app.android.data.local

import androidx.room.Database
import androidx.room.RoomDatabase
import dgca.verifier.app.android.data.local.model.Key

@Database(entities = [Key::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import dgca.verifier.app.android.data.local.model.Key

@Dao
interface KeyDao {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package dgca.verifier.app.android.data.local.countries
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import dgca.verifier.app.android.data.local.model.CountryLocal
import kotlinx.coroutines.flow.Flow

@Dao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@

package dgca.verifier.app.android.data.local.countries

import dgca.verifier.app.android.data.local.model.CountryLocal
import dgca.verifier.app.engine.data.source.local.countries.CountriesLocalDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import java.util.*

class DefaultCountriesLocalDataSource(private val countriesDao: CountriesDao) :
CountriesLocalDataSource {
class DefaultCountriesLocalDataSource(private val countriesDao: CountriesDao) : CountriesLocalDataSource {

override suspend fun updateCountries(countriesIsoCodes: List<String>) {
countriesDao.apply {
deleteAll()
Expand All @@ -37,9 +38,9 @@ class DefaultCountriesLocalDataSource(private val countriesDao: CountriesDao) :
}

override fun getCountries(): Flow<List<String>> =
countriesDao.getAll().map { it.map { it.toCountry() } }
countriesDao.getAll().map { it.map { countryLocal -> countryLocal.toCountry() } }
}

fun String.toCountryLocal(): CountryLocal = CountryLocal(isoCode = this.toLowerCase(Locale.ROOT))
fun String.toCountryLocal(): CountryLocal = CountryLocal(isoCode = toLowerCase(Locale.ROOT))

fun CountryLocal.toCountry(): String = this.isoCode
fun CountryLocal.toCountry(): String = isoCode
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by osarapulov on 7/26/21 11:56 AM
*/

package dgca.verifier.app.android.data.local.countries
package dgca.verifier.app.android.data.local.model

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* limitations under the License.
* ---license-end
*
* Created by osarapulov on 7/26/21 12:01 PM
* Created by mykhailo.nester on 10/10/2021, 10:51
*/

package dgca.verifier.app.android.data.local.rules
package dgca.verifier.app.android.data.local.model

import androidx.room.Entity
import androidx.room.ForeignKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by osarapulov on 4/29/21 11:32 PM
*/

package dgca.verifier.app.android.data.local
package dgca.verifier.app.android.data.local.model

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by osarapulov on 7/26/21 12:04 PM
*/

package dgca.verifier.app.android.data.local.rules
package dgca.verifier.app.android.data.local.model

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by osarapulov on 7/26/21 12:05 PM
*/

package dgca.verifier.app.android.data.local.rules
package dgca.verifier.app.android.data.local.model

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* limitations under the License.
* ---license-end
*
* Created by osarapulov on 7/26/21 12:06 PM
* Created by mykhailo.nester on 10/10/2021, 11:13
*/

package dgca.verifier.app.android.data.local.rules
package dgca.verifier.app.android.data.local.model

import androidx.room.Embedded
import androidx.room.Relation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by mykhailo.nester on 21/09/2021, 22:19
*/

package dgca.verifier.app.android.data.local.valuesets
package dgca.verifier.app.android.data.local.model

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by osarapulov on 7/26/21 12:08 PM
*/

package dgca.verifier.app.android.data.local.valuesets
package dgca.verifier.app.android.data.local.model

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class Converters {

@TypeConverter
fun localDateToTimestamp(localDate: LocalDate?): Long {
return (localDate?.atStartOfDay(UTC_ZONE_ID)
?: ZonedDateTime.now(UTC_ZONE_ID)).toInstant().toEpochMilli()
return (localDate?.atStartOfDay(UTC_ZONE_ID) ?: ZonedDateTime.now(UTC_ZONE_ID)).toInstant().toEpochMilli()
}

@TypeConverter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import dgca.verifier.app.android.data.local.countries.CountriesDao
import dgca.verifier.app.android.data.local.countries.CountryLocal
import dgca.verifier.app.android.data.local.valuesets.ValueSetIdentifierLocal
import dgca.verifier.app.android.data.local.valuesets.ValueSetLocal
import dgca.verifier.app.android.data.local.model.CountryLocal
import dgca.verifier.app.android.data.local.model.DescriptionLocal
import dgca.verifier.app.android.data.local.model.RuleIdentifierLocal
import dgca.verifier.app.android.data.local.model.RuleLocal
import dgca.verifier.app.android.data.local.model.ValueSetIdentifierLocal
import dgca.verifier.app.android.data.local.model.ValueSetLocal
import dgca.verifier.app.android.data.local.valuesets.ValueSetsDao

@Database(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@

package dgca.verifier.app.android.data.local.rules

import dgca.verifier.app.android.data.local.model.RuleIdentifierLocal
import dgca.verifier.app.engine.data.RuleIdentifier

fun RuleIdentifier.toRuleIdentifierLocal() = RuleIdentifierLocal(
identifier = this.identifier,
version = this.version,
country = this.country,
hash = this.hash
)
fun RuleIdentifier.toRuleIdentifierLocal() =
RuleIdentifierLocal(
identifier = identifier,
version = version,
country = country,
hash = hash
)

fun RuleIdentifierLocal.toRuleIdentifier() = RuleIdentifier(
identifier = this.identifier,
version = this.version,
country = this.country,
hash = this.hash
)
fun RuleIdentifierLocal.toRuleIdentifier() =
RuleIdentifier(
identifier = identifier,
version = version,
country = country,
hash = hash
)
Loading

0 comments on commit 738b442

Please sign in to comment.