Skip to content

Commit

Permalink
login: better sync and realm handling (fixes #2541) (#2543)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Sep 28, 2023
1 parent 6b47bf9 commit dd227ee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1061
versionName "0.10.61"
versionCode 1062
versionName "0.10.62"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,23 @@ public void onNothingSelected(AdapterView<?> adapterView) {
}

private void onChangeServerUrl() {
RealmCommunity selected = (RealmCommunity) spnCloud.getSelectedItem();
Utilities.log((selected == null) + " selected ");
if (selected == null) {
return;
try {
mRealm = Realm.getDefaultInstance();
RealmCommunity selected = (RealmCommunity) spnCloud.getSelectedItem();
Utilities.log((selected == null) + " selected ");
if (selected == null) {
return;
}
serverUrl.setText(selected.getLocalDomain());
protocol_checkin.check(R.id.radio_https);
settings.getString("serverProtocol", "https://");
serverPassword.setText(selected.getWeight() == 0 ? "0660" : "");
serverPassword.setEnabled(selected.getWeight() != 0);
} finally {
if (mRealm != null && !mRealm.isClosed()) {
mRealm.close();
}
}
serverUrl.setText(selected.getLocalDomain());
protocol_checkin.check(R.id.radio_https);
settings.getString("serverProtocol", "https://");
serverPassword.setText(selected.getWeight() == 0 ? "0660" : "");
serverPassword.setEnabled(selected.getWeight() != 0);
}

private void setUrlAndPin(boolean checked) {
Expand Down Expand Up @@ -512,14 +519,21 @@ public void onSuccess(String s) {

@Override
public void onUpdateAvailable(MyPlanet info, boolean cancelable) {
AlertDialog.Builder builder = DialogUtils.getUpdateDialog(this, info, progressDialog);
if (cancelable || NetworkUtils.getCustomDeviceName(this).endsWith("###")) {
builder.setNegativeButton(R.string.update_later, (dialogInterface, i) -> continueSyncProcess());
} else {
mRealm.executeTransactionAsync(realm -> realm.deleteAll());
try {
mRealm = Realm.getDefaultInstance();
AlertDialog.Builder builder = DialogUtils.getUpdateDialog(this, info, progressDialog);
if (cancelable || NetworkUtils.getCustomDeviceName(this).endsWith("###")) {
builder.setNegativeButton(R.string.update_later, (dialogInterface, i) -> continueSyncProcess());
} else {
mRealm.executeTransactionAsync(realm -> realm.deleteAll());
}
builder.setCancelable(cancelable);
builder.show();
} finally {
if (mRealm != null && !mRealm.isClosed()) {
mRealm.close();
}
}
builder.setCancelable(cancelable);
builder.show();
}

@Override
Expand Down Expand Up @@ -565,17 +579,24 @@ public void continueSyncProcess() {

@Override
public void onSelectedUser(RealmUserModel userModel) {
View v = getLayoutInflater().inflate(R.layout.layout_child_login, null);
EditText et = v.findViewById(R.id.et_child_password);
new AlertDialog.Builder(this).setView(v).setTitle(R.string.please_enter_your_password).setPositiveButton(R.string.login, (dialogInterface, i) -> {
String password = et.getText().toString();
if (authenticateUser(settings, userModel.getName(), password, false)) {
Toast.makeText(getApplicationContext(), getString(R.string.thank_you), Toast.LENGTH_SHORT).show();
onLogin();
} else {
alertDialogOkay(getString(R.string.err_msg_login));
try {
mRealm = Realm.getDefaultInstance();
View v = getLayoutInflater().inflate(R.layout.layout_child_login, null);
EditText et = v.findViewById(R.id.et_child_password);
new AlertDialog.Builder(this).setView(v).setTitle(R.string.please_enter_your_password).setPositiveButton(R.string.login, (dialogInterface, i) -> {
String password = et.getText().toString();
if (authenticateUser(settings, userModel.getName(), password, false)) {
Toast.makeText(getApplicationContext(), getString(R.string.thank_you), Toast.LENGTH_SHORT).show();
onLogin();
} else {
alertDialogOkay(getString(R.string.err_msg_login));
}
}).setNegativeButton(R.string.cancel, null).show();
} finally {
if (mRealm != null && !mRealm.isClosed()) {
mRealm.close();
}
}).setNegativeButton(R.string.cancel, null).show();
}
}

@Override
Expand Down

0 comments on commit dd227ee

Please sign in to comment.