Skip to content

Commit

Permalink
Merge pull request #378 from mysteriumnetwork/bugfix/Fix_reconnecting…
Browse files Browse the repository at this point in the history
…_pop_ups

Fix reconncting
  • Loading branch information
ArtemHryhorovGeniusee authored Jun 7, 2021
2 parents 1152fc2 + ef4e8ef commit bca701c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ abstract class BaseActivity : AppCompatActivity() {
if (!isAvailable) {
wifiNetworkErrorPopUp()
} else {
wifiErrorDialog?.dismiss()
wifiErrorDialog = null
retryLoading()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class BaseViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
private val connectionUseCase = useCaseProvider.connection()
private val settingsUseCase = useCaseProvider.settings()
private var isInternetChecking = false
private var isDoubleCheck = false

fun checkCurrentConnection() {
viewModelScope.launch {
Expand All @@ -58,7 +59,13 @@ class BaseViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
isInternetChecking = true
val handler = CoroutineExceptionHandler { _, _ ->
isInternetChecking = false
_isInternetNotAvailable.postValue(false)
if (!isDoubleCheck) {
isDoubleCheck = true
checkInternetConnection()
} else {
isDoubleCheck = false
_isInternetNotAvailable.postValue(false)
}
}
viewModelScope.launch(handler) {
val exitValue = withContext(Dispatchers.Default) {
Expand All @@ -69,7 +76,13 @@ class BaseViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
if (exitValue == 0) {
_isInternetNotAvailable.postValue(true)
} else {
_isInternetNotAvailable.postValue(false)
if (!isDoubleCheck) {
isDoubleCheck = true
checkInternetConnection()
} else {
isDoubleCheck = false
_isInternetNotAvailable.postValue(false)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class ConnectionActivity : BaseActivity() {
this.proposal = proposal
if (
viewModel.connectionState.value == ConnectionState.CONNECTED ||
viewModel.connectionState.value == ConnectionState.CONNECTING
viewModel.connectionState.value == ConnectionState.CONNECTING ||
viewModel.connectionState.value == ConnectionState.ON_HOLD ||
viewModel.connectionState.value == ConnectionState.IP_NOT_CHANGED
) {
manualDisconnecting()
viewModel.disconnect().observe(this, { result ->
Expand Down Expand Up @@ -166,14 +168,14 @@ class ConnectionActivity : BaseActivity() {

private fun handleConnectionChange(connection: ConnectionState) {
when (connection) {
ConnectionState.NOTCONNECTED -> disconnect()
ConnectionState.NOTCONNECTED -> loadIpAddress()
ConnectionState.CONNECTING -> inflateConnectingCardView()
ConnectionState.CONNECTED -> {
isDisconnectedByUser = false
loadIpAddress()
inflateConnectedCardView()
}
ConnectionState.DISCONNECTING -> {
binding.connectedStatusImageView.visibility = View.INVISIBLE
binding.connectionState.showDisconnectingState()
checkDisconnectingReason()
}
Expand Down Expand Up @@ -232,6 +234,9 @@ class ConnectionActivity : BaseActivity() {
ConnectionState.ON_HOLD -> {
binding.titleTextView.text = getString(R.string.manual_connect_on_hold)
}
ConnectionState.DISCONNECTING -> {
binding.titleTextView.text = getString(R.string.manual_connect_disconnecting)
}
}
}

Expand Down Expand Up @@ -264,7 +269,9 @@ class ConnectionActivity : BaseActivity() {
inflateConnectingCardView()
if (
viewModel.connectionState.value == ConnectionState.CONNECTED ||
viewModel.connectionState.value == ConnectionState.CONNECTING
viewModel.connectionState.value == ConnectionState.CONNECTING ||
viewModel.connectionState.value == ConnectionState.ON_HOLD ||
viewModel.connectionState.value == ConnectionState.IP_NOT_CHANGED
) {
manualDisconnecting()
viewModel.disconnect().observe(this, {
Expand All @@ -284,7 +291,6 @@ class ConnectionActivity : BaseActivity() {
result.onFailure {
Log.e(TAG, "Data loading failed")
binding.ipTextView.text = getString(R.string.manual_connect_unknown)
wifiNetworkErrorPopUp()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ class ConnectionViewModel(useCaseProvider: UseCaseProvider) : ViewModel() {
private suspend fun disconnectIfConnectedNode() {
if (
_connectionState.value == ConnectionState.CONNECTED ||
_connectionState.value == ConnectionState.ON_HOLD
_connectionState.value == ConnectionState.ON_HOLD ||
_connectionState.value == ConnectionState.IP_NOT_CHANGED
) {
disconnectNode()
}
Expand Down
2 changes: 1 addition & 1 deletion fastlane/android_version_code
Original file line number Diff line number Diff line change
@@ -1 +1 @@
107101
107102

0 comments on commit bca701c

Please sign in to comment.