Skip to content

Commit

Permalink
Merge branch 'master' into 4600-dialog-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Oct 16, 2024
2 parents ef654f5 + d1e770d commit f79e129
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
11 changes: 8 additions & 3 deletions app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import androidx.preference.SwitchPreference
import io.realm.Realm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.ole.planet.myplanet.MainApplication.Companion.mRealm
import org.ole.planet.myplanet.MainApplication.Companion.setThemeMode
import org.ole.planet.myplanet.R
Expand Down Expand Up @@ -135,9 +138,11 @@ class SettingActivity : AppCompatActivity() {
preference.onPreferenceClickListener = OnPreferenceClickListener {
AlertDialog.Builder(requireActivity()).setTitle(R.string.are_you_sure)
.setPositiveButton(R.string.yes) { _: DialogInterface?, _: Int ->
clearRealmDb()
clearSharedPref()
restartApp()
CoroutineScope(Dispatchers.Main).launch {
clearRealmDb()
clearSharedPref()
restartApp()
}
}.setNegativeButton(R.string.no, null).show()
false
}
Expand Down
27 changes: 19 additions & 8 deletions app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.*
import com.google.android.material.textfield.TextInputLayout
import io.realm.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import okhttp3.ResponseBody
Expand Down Expand Up @@ -144,9 +148,11 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
AlertDialog.Builder(this, R.style.AlertDialogTheme)
.setMessage(message)
.setPositiveButton(getString(R.string.clear_data)) { _, _ ->
clearRealmDb()
clearSharedPref()
restartApp()
CoroutineScope(Dispatchers.Main).launch {
clearRealmDb()
clearSharedPref()
restartApp()
}
}
.setNegativeButton(getString(R.string.cancel)) { _, _ ->
onCancel()
Expand Down Expand Up @@ -850,12 +856,17 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
lateinit var cal_today: Calendar
lateinit var cal_last_Sync: Calendar

fun clearRealmDb() {
val realm = Realm.getDefaultInstance()
realm.executeTransaction { transactionRealm ->
transactionRealm.deleteAll()
suspend fun clearRealmDb() {
withContext(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
try {
realm.executeTransaction { transactionRealm ->
transactionRealm.deleteAll()
}
} finally {
realm.close()
}
}
realm.close()
}

fun clearSharedPref() {
Expand Down

0 comments on commit f79e129

Please sign in to comment.