now handling unexpected ws close

This commit is contained in:
leca 2024-11-14 04:02:36 +03:00
parent 988272070d
commit e5772bcad3
6 changed files with 31 additions and 27 deletions

View File

@ -190,24 +190,26 @@ fun isInternetConnectionAvailable(context: Context): Boolean {
} }
fun noInternetConnectionAvailableNotification(context: Context) { fun noInternetConnectionAvailableNotification(context: Context) {
AlertDialog.Builder(context) (context as Activity).runOnUiThread {
.setMessage(context.getString(R.string.no_internet_connection)) AlertDialog.Builder(context)
.setPositiveButton(R.string.quit) { _, _ -> .setMessage(context.getString(R.string.no_internet_connection))
exitProcess(0) .setPositiveButton(R.string.quit) { _, _ ->
} exitProcess(0)
.setNeutralButton(R.string.logout) { _, _ -> }
val sharedPreferences = EncryptedSharedPreferences.create( .setNeutralButton(R.string.logout) { _, _ ->
"sensitive", val sharedPreferences = EncryptedSharedPreferences.create(
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), "sensitive",
context, MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, context,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
) EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
sharedPreferences.edit().putString("token", "").apply() sharedPreferences.edit().putString("token", "").apply()
sharedPreferences.edit().putString("server", "").apply() sharedPreferences.edit().putString("server", "").apply()
sharedPreferences.edit().putStringSet("groups", emptySet()).apply() sharedPreferences.edit().putStringSet("groups", emptySet()).apply()
sharedPreferences.edit().putString("currentGroup", "").apply() sharedPreferences.edit().putString("currentGroup", "").apply()
exitProcess(0) exitProcess(0)
}.show() }.show()
}
} }

View File

@ -139,10 +139,12 @@ class WebSocketClient(private val context: Context, private val server: String)
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
Log.d("QWERTYUIOP", "Closing ws. Reason: $reason") Log.d("QWERTYUIOP", "Closing ws. Reason: $reason")
noInternetConnectionAvailableNotification(context)
} }
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
Log.d("QWERTYUIOP","Connection failed: ${t.message}") Log.d("QWERTYUIOP","Connection failed: ${t.message}")
noInternetConnectionAvailableNotification(context)
} }
}) })
} }

View File

@ -62,7 +62,7 @@
android:ems="10" android:ems="10"
android:id="@+id/barcodeTextEdit" app:layout_constraintTop_toBottomOf="@+id/imageView" android:id="@+id/barcodeTextEdit" app:layout_constraintTop_toBottomOf="@+id/imageView"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="8dp" android:hint="Barcode" android:textColorHint="#737373" android:layout_marginTop="8dp" android:hint="@string/barcode" android:textColorHint="#737373"
android:layout_marginStart="5dp"/> android:layout_marginStart="5dp"/>
<CheckBox <CheckBox
android:text="@string/no_barcode" android:text="@string/no_barcode"

View File

@ -2,7 +2,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#141218"> >
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -114,10 +114,10 @@
<string name="image_compress_factor">Степень сжатия изображения</string> <string name="image_compress_factor">Степень сжатия изображения</string>
<string name="current_group">Текущая группа</string> <string name="current_group">Текущая группа</string>
<string name="cancel">Отмена</string> <string name="cancel">Отмена</string>
<string name="no_internet_connection">No internet connection available. Please, connect to a network.</string> <string name="no_internet_connection">Не могу установить соединение с сервером. Возможно, вы отключены от сети?</string>
<string name="ok">Ok</string> <string name="ok">Ок</string>
<string name="logout">Log out</string> <string name="logout">Выйти</string>
<string name="online_only_feature">This feature is online only</string> <string name="online_only_feature">Эта возможность доступна только с онлайн аккаунтом</string>
<string-array name="languages"> <string-array name="languages">
<item>en-US</item> <item>en-US</item>
<item>ru-RU</item> <item>ru-RU</item>

View File

@ -112,8 +112,8 @@
<string name="image_compress_factor">Image compression factor</string> <string name="image_compress_factor">Image compression factor</string>
<string name="current_group">Current group</string> <string name="current_group">Current group</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="no_internet_connection">No internet connection available. Please, connect to a network.</string> <string name="no_internet_connection">Cannot reach the server. Maybe, you lost internet connection?</string>
<string name="ok">Ok</string> <string name="ok">OK</string>
<string name="logout">Log out</string> <string name="logout">Log out</string>
<string name="online_only_feature">This feature is online only</string> <string name="online_only_feature">This feature is online only</string>
<string-array name="languages"> <string-array name="languages">