From adaf5f6075b5f06b187459db21fe7fa8d67ea887 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 2 Nov 2023 19:22:56 +0300 Subject: [PATCH] settings: more realm stability (fixes #2670) (#2671) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../ole/planet/myplanet/ui/sync/LoginActivity.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 119d18a5fa..ccdea927b7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1130 - versionName "0.11.30" + versionCode 1131 + versionName "0.11.31" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java index 6f06ab8f8d..2734f130e4 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java @@ -725,8 +725,9 @@ private void onLogin() { } public void settingDialog() { + Realm sRealm = null; try { - mRealm = Realm.getDefaultInstance(); + sRealm = Realm.getDefaultInstance(); DialogServerUrlBinding dialogServerUrlBinding = DialogServerUrlBinding.inflate(LayoutInflater.from(this)); MaterialDialog.Builder builder = new MaterialDialog.Builder(LoginActivity.this); builder.title(R.string.action_settings) @@ -741,7 +742,7 @@ public void settingDialog() { positiveAction = dialog.getActionButton(DialogAction.POSITIVE); spnCloud = dialogServerUrlBinding.spnCloud; - List communities = mRealm.where(RealmCommunity.class).sort("weight", Sort.ASCENDING).findAll(); + List communities = sRealm.where(RealmCommunity.class).sort("weight", Sort.ASCENDING).findAll(); List nonEmptyCommunities = new ArrayList<>(); for (RealmCommunity community : communities) { if (community.isValid() && !TextUtils.isEmpty(community.getName())) { @@ -779,8 +780,8 @@ public void onNothingSelected(AdapterView adapterView) { dialog.show(); sync(dialog); } finally { - if (mRealm != null && !mRealm.isClosed()) { - mRealm.close(); + if (sRealm != null && !sRealm.isClosed()) { + sRealm.close(); } } } @@ -789,11 +790,10 @@ private void onChangeServerUrl() { try { mRealm = Realm.getDefaultInstance(); RealmCommunity selected = (RealmCommunity) spnCloud.getSelectedItem(); - Utilities.log((selected == null) + " selected "); if (selected == null) { return; } - if (selected.isValid()){ + if (selected.isValid()) { serverUrl.setText(selected.getLocalDomain()); protocol_checkin.check(R.id.radio_https); settings.getString("serverProtocol", "https://");