diff --git a/app/src/main/java/foundation/e/apps/MainActivity.kt b/app/src/main/java/foundation/e/apps/MainActivity.kt index 3c6d100cd5540830cdc0578529feb535999bd281..63d0ac77e0611112815b562a429e6b1c1d280ec0 100644 --- a/app/src/main/java/foundation/e/apps/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/MainActivity.kt @@ -258,7 +258,7 @@ class MainActivity : AppCompatActivity() { } } - private fun showSnackbarMessage(message: String) { + fun showSnackbarMessage(message: String) { Snackbar.make(binding.root, message, Snackbar.LENGTH_SHORT).show() } diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt index 1c896b79ade6969c5a7dc577c19f21d224a66dc9..d5f360c6bfd90ad6333e6e8b5eec747370fba894 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -45,6 +45,7 @@ import com.google.android.material.snackbar.Snackbar import com.google.android.material.textview.MaterialTextView import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.AppInfoFetchViewModel +import foundation.e.apps.MainActivity import foundation.e.apps.MainActivityViewModel import foundation.e.apps.PrivacyInfoViewModel import foundation.e.apps.R @@ -258,6 +259,10 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { observeDownloadStatus(view) fetchAppTracker(it) } + + applicationViewModel.errorMessageLiveData.observe(viewLifecycleOwner) { + (requireActivity() as MainActivity).showSnackbarMessage(getString(it)) + } } private fun observeDownloadStatus(view: View) { diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt b/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt index aa902b8f5fbae7a9f9f1446d266653afb420c112..ea96457cbf0e7ee1ca868e24f139090e6ae032dd 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt @@ -22,7 +22,9 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.aurora.gplayapi.data.models.AuthData +import com.aurora.gplayapi.exceptions.ApiException import dagger.hilt.android.lifecycle.HiltViewModel +import foundation.e.apps.R import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.manager.database.fusedDownload.FusedDownload @@ -47,17 +49,25 @@ class ApplicationViewModel @Inject constructor( val fusedApp: MutableLiveData = MutableLiveData() val appStatus: MutableLiveData = MutableLiveData() val downloadProgress = downloadProgressLD + private val _errorMessageLiveData: MutableLiveData = MutableLiveData() + val errorMessageLiveData: MutableLiveData = _errorMessageLiveData fun getApplicationDetails(id: String, packageName: String, authData: AuthData, origin: Origin) { viewModelScope.launch(Dispatchers.IO) { - fusedApp.postValue( - fusedAPIRepository.getApplicationDetails( - id, - packageName, - authData, - origin + try { + fusedApp.postValue( + fusedAPIRepository.getApplicationDetails( + id, + packageName, + authData, + origin + ) ) - ) + } catch (e: ApiException.AppNotFound) { + _errorMessageLiveData.postValue(R.string.app_not_found) + } catch (e: Exception) { + _errorMessageLiveData.postValue(R.string.unknown_error) + } } } @@ -107,7 +117,8 @@ class ApplicationViewModel @Inject constructor( fusedApp.value?.let { app -> val downloadingItem = downloadList.find { it.origin == app.origin && (it.packageName == app.package_name || it.id == app.package_name) } - appStatus.value = downloadingItem?.status ?: fusedAPIRepository.getFusedAppInstallationStatus(app) + appStatus.value = + downloadingItem?.status ?: fusedAPIRepository.getFusedAppInstallationStatus(app) } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fb2863aae72c4a2467ce86aee75621882ecbf62b..3e8be04122310c6aa884321c535d07900cc750c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -104,6 +104,7 @@ This app will be available later! Unknown Error! There is not enough space available to download this application! + Your application was not found. Update All