My commit in a jiffy :
1) Rename `signinSuccessful` to `connectionSuccessful` - because its `setValue` method only marks successful connection creation attempts and not signin attempts. 2) Set initial connections added through `accountRespository.insertAccount(..)` as invalid, they can later be marked valid once we are able to login successfully. 3) Add a `isValid` field in `RoomAccountModel`, along with it's respective getters and setters. 4) Add `isValid` getters and setters to `AccountModel` interface. What problem I currently am facing is, Just like `accountRepository.insertAccount(..)`, I tried `accountRepository.updateAccount(..)` which didn't seem to work. I interpreted this by observing the accountmodel status in `startUp`, after restarting the app field `isValid = invalid` should have turned to `isValid = valid` which was not expected. Please let me know what you think.
This commit is contained in:
parent
03dae46be0
commit
aeb2f25909
|
@ -114,7 +114,7 @@ public class LoginActivity extends AppCompatActivity implements TextView.OnEdito
|
|||
mPasswordView.setError(errorMessage);
|
||||
});
|
||||
|
||||
viewModel.getSigninSuccessful().observe(this, aBoolean -> {
|
||||
viewModel.getConnectionSuccessful().observe(this, aBoolean -> {
|
||||
if (Boolean.TRUE.equals(aBoolean)) {
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class LoginViewModel extends ViewModel {
|
|||
|
||||
private MutableLiveData<AccountModel> account = new MutableLiveData<>();
|
||||
|
||||
private MutableLiveData<Boolean> signinSuccessful = new MutableLiveData<>();
|
||||
private MutableLiveData<Boolean> connectionSuccessful = new MutableLiveData<>();
|
||||
|
||||
public LoginViewModel() {
|
||||
super();
|
||||
|
@ -49,8 +49,8 @@ public class LoginViewModel extends ViewModel {
|
|||
init(accountRepository.newAccountModel());
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getSigninSuccessful() {
|
||||
return signinSuccessful;
|
||||
public LiveData<Boolean> getConnectionSuccessful() {
|
||||
return connectionSuccessful;
|
||||
}
|
||||
|
||||
public enum JidError {
|
||||
|
@ -136,6 +136,7 @@ public class LoginViewModel extends ViewModel {
|
|||
accountModel.setEnabled(true);
|
||||
accountModel.setJid(bareJid);
|
||||
accountModel.setPassword(password);
|
||||
accountModel.setIsValid("invalid");
|
||||
Single<Long> id = accountRepository.insertAccount(accountModel);
|
||||
id.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -145,7 +146,7 @@ public class LoginViewModel extends ViewModel {
|
|||
accountModel.setId(aLong);
|
||||
Log.d(MercuryImApplication.TAG, "LoginActivity.loginDetailsEntered: Account " + aLong + " inserted.");
|
||||
connectionCenter.createConnection(accountModel);
|
||||
signinSuccessful.setValue(true);
|
||||
connectionSuccessful.setValue(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -126,8 +126,16 @@ public class ConnectionCenter {
|
|||
continue;
|
||||
}
|
||||
LOGGER.log(Level.INFO, "Connecting connection " + account.getId() + " (" + account.getJid().toString() + ")");
|
||||
connection.connect();
|
||||
LOGGER.log(Level.INFO, "Connected!");
|
||||
try {
|
||||
connection.connect();
|
||||
account.setIsValid("valid");
|
||||
accountRepository.updateAccount(account);
|
||||
LOGGER.log(Level.INFO, "Connected!");
|
||||
}
|
||||
catch ( SmackException e) {
|
||||
Logger.getAnonymousLogger().log(Level.WARNING,"Trouble logging in");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (!connection.getConnection().isConnected()) {
|
||||
continue;
|
||||
|
|
|
@ -25,6 +25,7 @@ public class RoomAccountModel extends AbstractAccountModel {
|
|||
public static final String KEY_PASSWORD = "password";
|
||||
public static final String KEY_ENABLED = "enabled";
|
||||
public static final String KEY_STATE = "state";
|
||||
public static final String KEY_ISVALID = "isValid";
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = KEY_ID)
|
||||
|
@ -43,6 +44,9 @@ public class RoomAccountModel extends AbstractAccountModel {
|
|||
@ColumnInfo(name = KEY_STATE)
|
||||
private String state;
|
||||
|
||||
@ColumnInfo(name = KEY_ISVALID)
|
||||
private String isValid;
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
|
@ -93,6 +97,17 @@ public class RoomAccountModel extends AbstractAccountModel {
|
|||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsValid(){
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsValid(String isValid) {
|
||||
this.isValid = isValid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String toString() {
|
||||
|
@ -101,7 +116,8 @@ public class RoomAccountModel extends AbstractAccountModel {
|
|||
KEY_JID + ": " + (getJid() != null ? getJid().toString() : "null") + ", " +
|
||||
KEY_PASSWORD + ": " + getPassword() + ", " +
|
||||
KEY_ENABLED + ": " + getEnabled() + ", " +
|
||||
KEY_STATE + ": " +getState() +
|
||||
KEY_STATE + ": " + getState() + ", " +
|
||||
KEY_ISVALID + ": " + getIsValid() +
|
||||
"]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,4 +71,13 @@ public interface AccountModel {
|
|||
String getState();
|
||||
|
||||
void setState(String state);
|
||||
|
||||
/**
|
||||
* Set wheather the jid-password combination works or not
|
||||
*
|
||||
* @return valid / invalid
|
||||
*/
|
||||
String getIsValid();
|
||||
|
||||
void setIsValid(String validity);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue