Skip to content

Commit

Permalink
Merge pull request #471 from mysteriumnetwork/bugfix/Fix-free-registr…
Browse files Browse the repository at this point in the history
…ation

Hide camera permission, added free registration on migration
  • Loading branch information
ArtemHryhorovGeniusee authored Nov 19, 2021
2 parents 2397054 + e6c8d4a commit 5fc102b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.CAMERA"
tools:node="remove" />

<application
android:name="updated.mysterium.vpn.App"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.flow.collect
import network.mysterium.vpn.R
import network.mysterium.vpn.databinding.ActivitySplashBinding
import network.mysterium.vpn.databinding.PopUpRetryRegistrationBinding
import org.koin.android.ext.android.inject
import updated.mysterium.vpn.App
import updated.mysterium.vpn.analytics.AnalyticEvent
Expand Down Expand Up @@ -165,6 +166,22 @@ class SplashActivity : BaseActivity() {
it.onSuccess { identity ->
if (identity.registered) {
navigateToConnectionOrHome(isBackTransition = false)
} else {
checkFreeRegistration()
}
}
it.onFailure { error ->
Log.e(TAG, error.localizedMessage ?: error.toString())
checkFreeRegistration()
}
}
}

private fun checkFreeRegistration() {
viewModel.checkFreeRegistration().observe(this) {
it.onSuccess { freeRegistration ->
if (freeRegistration) {
registerAccount()
} else {
navigateToTopUp()
}
Expand All @@ -176,6 +193,32 @@ class SplashActivity : BaseActivity() {
}
}

private fun registerAccount() {
viewModel.registerAccount().observe(this) {
it.onSuccess {
navigateToConnectionOrHome(isBackTransition = false)
}
it.onFailure { error ->
Log.e(TAG, error.localizedMessage ?: error.toString())
showRegistrationErrorPopUp()
}
}
}

private fun showRegistrationErrorPopUp() {
val bindingPopUp = PopUpRetryRegistrationBinding.inflate(layoutInflater)
val dialog = createPopUp(bindingPopUp.root, true)
bindingPopUp.tryAgainButton.setOnClickListener {
dialog.dismiss()
viewModel.registerAccount()
}
bindingPopUp.cancelButton.setOnClickListener {
dialog.dismiss()
finish()
}
dialog.show()
}

private fun ensureVpnServicePermission() {
val vpnServiceIntent = VpnService.prepare(this)
if (vpnServiceIntent == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mysterium.RegisterIdentityRequest
import updated.mysterium.vpn.common.extensions.liveDataResult
import updated.mysterium.vpn.common.livedata.SingleLiveEvent
import updated.mysterium.vpn.core.DeferredNode
Expand Down Expand Up @@ -129,4 +130,22 @@ class SplashViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
fun getIdentity() = liveDataResult {
IdentityModel(connectionUseCase.getIdentity())
}

fun checkFreeRegistration() = liveDataResult {
val address = connectionUseCase.getIdentity().address
loginUseCase.isFreeRegistrationAvailable(address)
}

fun registerAccount() = liveDataResult {
val identity = connectionUseCase.getIdentity()
val identityModel = IdentityModel(identity)
val req = RegisterIdentityRequest().apply {
identityAddress = identityModel.address
token?.let {
this.token = it
}
}
connectionUseCase.registerIdentity(req)
connectionUseCase.registrationFees()
}
}
2 changes: 1 addition & 1 deletion fastlane/android_version_code
Original file line number Diff line number Diff line change
@@ -1 +1 @@
107117
107118

0 comments on commit 5fc102b

Please sign in to comment.