Skip to content

Commit

Permalink
Fix version check code.
Browse files Browse the repository at this point in the history
Fixes #38 issue #38
  • Loading branch information
richardneish committed Jan 9, 2018
1 parent 985750b commit 80a6462
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/src/main/java/in/andres/kandroid/ui/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class LoginActivity extends AppCompatActivity {

// UI references.
private EditText mServerURLView;
// private EditText mAPIKeyView;
// private EditText mAPIKeyView;
private EditText mUsernameView;
private EditText mPasswordView;
private View mProgressView;
Expand Down Expand Up @@ -239,9 +239,7 @@ public void onDismiss(DialogInterface dialog) {
editor.putString("username", username);
editor.putString("password", password);
editor.apply();
} else if (version[0] >= Constants.minKanboardVersion[0] &&
version[1] >= Constants.minKanboardVersion[1] &&
version[2] >= Constants.minKanboardVersion[2]) {
} else if (isSupportedVersion(version)) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("serverurl", serverurl.trim());
Expand All @@ -264,6 +262,12 @@ public void onDismiss(DialogInterface dialog) {
}
}

public static boolean isSupportedVersion(int[] version) {
return version[0] > Constants.minKanboardVersion[0] ||
(version[0] == Constants.minKanboardVersion[0] && version[1] > Constants.minKanboardVersion[1]) ||
(version[1] == Constants.minKanboardVersion[0] && version[1] == Constants.minKanboardVersion[1] && version[2] >= Constants.minKanboardVersion[2]);
}

private boolean isPasswordValid(String password) {
//TODO: Replace this with your own logic
return password.length() > 4;
Expand Down
25 changes: 25 additions & 0 deletions app/src/test/java/in/andres/kandroid/ui/LoginActivityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package in.andres.kandroid.ui;

import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class LoginActivityTest {

@Test
public void testUnsupportedVersion() {
assertFalse(LoginActivity.isSupportedVersion(new int[] {1, 0, 30}));
}

@Test
public void testOldSupportedVersion() {
assertTrue(LoginActivity.isSupportedVersion(new int[] {1, 0, 39}));
}

@Test
public void testRecentSupportedVersion() {
assertTrue(LoginActivity.isSupportedVersion(new int[] {1, 2, 0}));
}

}

0 comments on commit 80a6462

Please sign in to comment.