From 9918c4584fd4652689bd00b32ef9af9bab0c3a31 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Tue, 19 Jul 2022 23:47:49 +0300 Subject: [PATCH] Cleanup code using AS code inspection --- .../CredentialViewPagerAdapter.kt | 2 +- .../LoadCredentialDetailsViewModel.kt | 2 - .../model/CredentialToDetailsModelMapper.kt | 1 - .../CredentialsListFragment.kt | 2 - .../filters/CredentialFilters.kt | 2 +- .../VerifyCredentialQrViewModel.kt | 72 ------------------- .../layout/view_credential_item_detailed.xml | 6 +- app/src/main/res/values/strings.xml | 1 + .../data/repository/LoginRepositoryImpl.kt | 1 - 9 files changed, 6 insertions(+), 83 deletions(-) delete mode 100644 app/src/main/java/by/alexandr7035/affinidi_id/presentation/scan_credential_qr/VerifyCredentialQrViewModel.kt diff --git a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/CredentialViewPagerAdapter.kt b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/CredentialViewPagerAdapter.kt index 2e9fc50c..b59f2352 100644 --- a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/CredentialViewPagerAdapter.kt +++ b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/CredentialViewPagerAdapter.kt @@ -8,7 +8,7 @@ import java.lang.IllegalStateException class CredentialViewPagerAdapter( private val tabsCount: Int, - private val parentFragment: Fragment + parentFragment: Fragment ): FragmentStateAdapter(parentFragment) { override fun getItemCount(): Int { return tabsCount diff --git a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/LoadCredentialDetailsViewModel.kt b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/LoadCredentialDetailsViewModel.kt index 43e28f89..2ef9f1bc 100644 --- a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/LoadCredentialDetailsViewModel.kt +++ b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/LoadCredentialDetailsViewModel.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import by.alexandr7035.affinidi_id.core.extensions.debug import by.alexandr7035.affinidi_id.domain.model.credentials.get_from_qr_code.ObtainVcFromQrCodeReqModel import by.alexandr7035.affinidi_id.domain.model.credentials.get_from_qr_code.ObtainVcFromQrCodeResModel import by.alexandr7035.affinidi_id.domain.model.credentials.stored_credentials.GetCredentialByIdReqModel @@ -17,7 +16,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import timber.log.Timber import javax.inject.Inject @HiltViewModel diff --git a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/model/CredentialToDetailsModelMapper.kt b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/model/CredentialToDetailsModelMapper.kt index 3727598f..229e433f 100644 --- a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/model/CredentialToDetailsModelMapper.kt +++ b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credential_details/model/CredentialToDetailsModelMapper.kt @@ -1,7 +1,6 @@ package by.alexandr7035.affinidi_id.presentation.credential_details.model import by.alexandr7035.affinidi_id.domain.model.credentials.stored_credentials.Credential -import by.alexandr7035.affinidi_id.presentation.credential_details.model.CredentialDetailsUi interface CredentialToDetailsModelMapper { fun map(credential: Credential): CredentialDetailsUi.Success diff --git a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/CredentialsListFragment.kt b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/CredentialsListFragment.kt index bbe82dc4..1cd5d2b4 100644 --- a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/CredentialsListFragment.kt +++ b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/CredentialsListFragment.kt @@ -1,6 +1,5 @@ package by.alexandr7035.affinidi_id.presentation.credentials_list -import android.net.wifi.hotspot2.pps.Credential import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -22,7 +21,6 @@ import by.kirich1409.viewbindingdelegate.viewBinding import com.google.android.material.tabs.TabLayout import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber -import java.lang.RuntimeException @AndroidEntryPoint diff --git a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/filters/CredentialFilters.kt b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/filters/CredentialFilters.kt index 10258a4f..78f2b636 100644 --- a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/filters/CredentialFilters.kt +++ b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/credentials_list/filters/CredentialFilters.kt @@ -1,6 +1,6 @@ package by.alexandr7035.affinidi_id.presentation.credentials_list.filters -sealed class CredentialFilters() { +sealed class CredentialFilters { object All: CredentialFilters() object Active: CredentialFilters() diff --git a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/scan_credential_qr/VerifyCredentialQrViewModel.kt b/app/src/main/java/by/alexandr7035/affinidi_id/presentation/scan_credential_qr/VerifyCredentialQrViewModel.kt deleted file mode 100644 index 444eae24..00000000 --- a/app/src/main/java/by/alexandr7035/affinidi_id/presentation/scan_credential_qr/VerifyCredentialQrViewModel.kt +++ /dev/null @@ -1,72 +0,0 @@ -package by.alexandr7035.affinidi_id.presentation.scan_credential_qr - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import by.alexandr7035.affinidi_id.core.livedata.SingleLiveEvent -import by.alexandr7035.affinidi_id.domain.model.credentials.get_from_qr_code.ObtainVcFromQrCodeReqModel -import by.alexandr7035.affinidi_id.domain.model.credentials.get_from_qr_code.ObtainVcFromQrCodeResModel -import by.alexandr7035.affinidi_id.domain.model.credentials.verify_vc.VerifyVcReqModel -import by.alexandr7035.affinidi_id.domain.usecase.credentials.ObtainCredentialWithQrCodeUseCase -import by.alexandr7035.affinidi_id.domain.usecase.credentials.VerifyCredentialUseCase -import by.alexandr7035.affinidi_id.presentation.credential_details.model.CredentialDetailsUi -import by.alexandr7035.affinidi_id.presentation.credential_details.model.CredentialToDetailsModelMapper -import by.alexandr7035.affinidi_id.presentation.common.credentials.verification.VerificationModelUi -import by.alexandr7035.affinidi_id.presentation.common.credentials.verification.VerificationResultToUiMapper -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import javax.inject.Inject - -@HiltViewModel -class VerifyCredentialQrViewModel @Inject constructor( - private val obtainCredentialWithQrCodeUseCase: ObtainCredentialWithQrCodeUseCase, - private val credentialToDetailsModelMapper: CredentialToDetailsModelMapper, - private val verifyCredentialUseCase: VerifyCredentialUseCase, - private val verificationResultToUiMapper: VerificationResultToUiMapper, -) : ViewModel() { - - private val credentialLiveData = MutableLiveData() - private val verificationLiveData = SingleLiveEvent() - - fun obtainCredential(credentialLink: String) { - viewModelScope.launch(Dispatchers.IO) { - val res = obtainCredentialWithQrCodeUseCase.execute(ObtainVcFromQrCodeReqModel(credentialLink)) - - val uiModel = when (res) { - is ObtainVcFromQrCodeResModel.Success -> { - credentialToDetailsModelMapper.map(credential = res.credential) - } - - is ObtainVcFromQrCodeResModel.Fail -> { - CredentialDetailsUi.Fail(res.errorType) - } - } - - withContext(Dispatchers.Main) { - credentialLiveData.value = uiModel - } - } - } - - fun verifyCredential(rawVc: String) { - viewModelScope.launch(Dispatchers.IO) { - val res = verifyCredentialUseCase.execute( - VerifyVcReqModel( - rawVc = rawVc - ) - ) - - withContext(Dispatchers.Main) { - // Map domain result to ui model for verification snackbar - verificationLiveData.value = verificationResultToUiMapper.map(res) - } - } - } - - fun getCredentialLiveData(): LiveData = credentialLiveData - - fun getVerificationLiveData(): LiveData = verificationLiveData -} \ No newline at end of file diff --git a/app/src/main/res/layout/view_credential_item_detailed.xml b/app/src/main/res/layout/view_credential_item_detailed.xml index aebf88a2..4bf15f03 100644 --- a/app/src/main/res/layout/view_credential_item_detailed.xml +++ b/app/src/main/res/layout/view_credential_item_detailed.xml @@ -87,7 +87,7 @@ @@ -105,7 +105,7 @@ android:id="@+id/statusValue" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="did:elem:123..3434" + tools:text="did:elem:123..3434" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@id/statusLabel" app:layout_constraintBottom_toBottomOf="@id/statusLabel"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 48295655..b584378a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -109,5 +109,6 @@ Proof Claims + Issued by \ No newline at end of file diff --git a/data/src/main/java/by/alexandr7035/data/repository/LoginRepositoryImpl.kt b/data/src/main/java/by/alexandr7035/data/repository/LoginRepositoryImpl.kt index 5aa3e5c8..cdf03670 100644 --- a/data/src/main/java/by/alexandr7035/data/repository/LoginRepositoryImpl.kt +++ b/data/src/main/java/by/alexandr7035/data/repository/LoginRepositoryImpl.kt @@ -5,7 +5,6 @@ import by.alexandr7035.affinidi_id.domain.model.login.LogOutModel import by.alexandr7035.affinidi_id.domain.model.login.SignInModel import by.alexandr7035.affinidi_id.domain.repository.LoginRepository import by.alexandr7035.data.datasource.cache.credentials.CredentialsCacheDataSource -import by.alexandr7035.data.datasource.cache.credentials.CredentialsDAO import by.alexandr7035.data.datasource.cache.secrets.SecretsStorage import by.alexandr7035.data.datasource.cloud.ApiCallHelper import by.alexandr7035.data.datasource.cloud.ApiCallWrapper