Skip to content

Commit

Permalink
Done changes with https
Browse files Browse the repository at this point in the history
Designed new login screen for SAMS logo implementation
  • Loading branch information
nehav39 committed Oct 3, 2019
1 parent ab11b89 commit df648f1
Show file tree
Hide file tree
Showing 32 changed files with 535 additions and 297 deletions.
23 changes: 12 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ dependencies {
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.13-beta-2'


androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// mvvm
//mvvm
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation "android.arch.lifecycle:viewmodel:1.1.1"
// JSON Converter
Expand All @@ -60,14 +59,14 @@ dependencies {
//Permission libraby
implementation 'gun0912.ted:tedpermission:2.2.2'
//logging and interceptor
// implementation "com.squareup.okhttp3:logging-interceptor:3.14.1"
// implementation "com.squareup.okhttp3:logging-interceptor:3.14.1"

implementation "com.squareup.okhttp3:logging-interceptor:3.8.0"

// debug bridge
debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
//debug bridge
// debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
//image loaders
implementation 'com.squareup.picasso:picasso:2.71828'
// implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.bumptech.glide:glide:3.8.0'
//Uncomment below line to enable multidex support for Kitkat
implementation 'com.android.support:multidex:1.0.3'
Expand All @@ -76,14 +75,14 @@ dependencies {
//Google Guava
implementation 'com.google.guava:guava:27.1-jre'
//Storage librabry
implementation 'com.snatik:storage:2.1.0'
// implementation 'com.snatik:storage:2.1.0'
// dexter permission
// implementation 'com.karumi:dexter:5.0.0'
//Room database
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
implementation "android.arch.persistence.room:rxjava2:1.1.1"
// annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
// implementation "android.arch.persistence.room:runtime:1.1.1"
// annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
// implementation "android.arch.persistence.room:rxjava2:1.1.1"
//Parse SDK
implementation 'com.parse:parse-android:1.15.7'
//date and time
Expand All @@ -106,6 +105,8 @@ dependencies {
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation 'com.google.firebase:firebase-crash:16.2.1'

implementation 'com.rengwuxian.materialedittext:library:2.1.4'


}
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.widget.Toast;

import com.google.gson.Gson;
import com.rengwuxian.materialedittext.MaterialEditText;

import io.intelehealth.client.R;
import io.intelehealth.client.activities.homeActivity.HomeActivity;
Expand Down Expand Up @@ -68,8 +69,9 @@ public class LoginActivity extends AppCompatActivity {
Base64Utils base64Utils = new Base64Utils();
String encoded = null;
// UI references.
private AutoCompleteTextView mUsernameView;
private EditText mPasswordView;
private MaterialEditText mUsernameView;
private MaterialEditText mPasswordView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -117,24 +119,23 @@ public void onClick(View v) {
}
}
// Set up the login form.
mUsernameView = findViewById(R.id.email);
mUsernameView = findViewById(R.id.et_email);
// populateAutoComplete(); TODO: create our own autocomplete code
mPasswordView = findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int id, KeyEvent event) {
if (id == R.id.login || id == EditorInfo.IME_NULL) {
attemptLogin();
return true;
}
return false;
}
});
mPasswordView = findViewById(R.id.et_password);
// mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
// @Override
// public boolean onEditorAction(TextView v, int id, KeyEvent event) {
// if (id == R.id.login || id == EditorInfo.IME_NULL) {
// attemptLogin();
// return true;
// }
// return false;
// }
// });
Button mEmailSignInButton = findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Logger.logD(TAG, "button pressed");
attemptLogin();
}
});
Expand All @@ -154,35 +155,41 @@ private void attemptLogin() {
// }

// Reset errors.
mUsernameView.setError(null);
mPasswordView.setError(null);
// mUsernameView.setError(null);
// mPasswordView.setError(null);

// Store values at the time of the login attempt.
String email = mUsernameView.getText().toString();
String password = mPasswordView.getText().toString();

String email = mUsernameView.getText().toString().trim();
String password = mPasswordView.getText().toString().trim();

boolean cancel = false;
View focusView = null;
// boolean cancel = false;
// View focusView = null;

// Check for a valid email address.
if (TextUtils.isEmpty(email)) {
mUsernameView.setError(getString(R.string.enter_username));
mUsernameView.requestFocus();
return;
}
// Check for a valid password, if the user entered one.
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
mPasswordView.setError(getString(R.string.error_invalid_password));
focusView = mPasswordView;
cancel = true;
if (TextUtils.isEmpty(password)) {
mPasswordView.setError(getString(R.string.enter_password));
mPasswordView.requestFocus();
return;
}

// Check for a valid email address.
if (TextUtils.isEmpty(email)) {
mUsernameView.setError(getString(R.string.error_field_required));
focusView = mUsernameView;
cancel = true;
if (password.length() < 4) {
mPasswordView.setError(getString(R.string.error_invalid_password));
mPasswordView.requestFocus();
return;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else if (NetworkConnection.isOnline(this)) {

// if (cancel) {
// // There was an error; don't attempt login and focus the first
// // form field with an error.
// focusView.requestFocus();
// } else
if (NetworkConnection.isOnline(this)) {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
// showProgress(true);
Expand All @@ -201,7 +208,7 @@ private void attemptLogin() {
*/
private boolean isPasswordValid(String password) {
//TODO: Replace this with your own logic
return password.length() > 4;
return password.length() < 4;
}

private void showProgress(final boolean show) {
Expand Down Expand Up @@ -271,96 +278,96 @@ public void UserLoginTask(String mEmail, String mPassword) {
// Log.d(TAG, "UN: " + USERNAME);
// Log.d(TAG, "PW: " + PASSWORD);
String urlString = urlModifiers.loginUrl(sessionManager.getServerUrl());
Logger.logD(TAG, "usernaem and password" + mEmail + mPassword);
Logger.logD(TAG, "usernaem and password" + mEmail + mPassword);
encoded = base64Utils.encoded(mEmail, mPassword);
sessionManager.setEncoded(encoded);
sessionManager.setEncoded(encoded);
showProgress(true);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Observable<LoginModel> loginModelObservable = AppConstants.apiInterface.LOGIN_MODEL_OBSERVABLE(urlString, "Basic " + encoded);
loginModelObservable.subscribe(new Observer<LoginModel>() {
@Override
public void onSubscribe(Disposable d) {
Observable<LoginModel> loginModelObservable = AppConstants.apiInterface.LOGIN_MODEL_OBSERVABLE(urlString, "Basic " + encoded);
loginModelObservable.subscribe(new Observer<LoginModel>() {
@Override
public void onSubscribe(Disposable d) {

}
}

@Override
public void onNext(LoginModel loginModel) {
int responsCode = loginModel.hashCode();
Boolean authencated = loginModel.getAuthenticated();
Gson gson = new Gson();
Logger.logD(TAG, "success" + gson.toJson(loginModel));
sessionManager.setChwname(loginModel.getUser().getDisplay());
sessionManager.setCreatorID(loginModel.getUser().getUuid());
sessionManager.setSessionID(loginModel.getSessionId());
sessionManager.setProviderID(loginModel.getUser().getPerson().getUuid());
UrlModifiers urlModifiers = new UrlModifiers();
String url = urlModifiers.loginUrlProvider(sessionManager.getServerUrl(), loginModel.getUser().getUuid());
if (authencated) {
Observable<LoginProviderModel> loginProviderModelObservable = AppConstants.apiInterface.LOGIN_PROVIDER_MODEL_OBSERVABLE(url, "Basic " + encoded);
loginProviderModelObservable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableObserver<LoginProviderModel>() {
@Override
public void onNext(LoginProviderModel loginProviderModel) {
if (loginProviderModel.getResults().size() != 0) {
for (int i = 0; i < loginProviderModel.getResults().size(); i++) {
Log.i(TAG, "doInBackground: " + loginProviderModel.getResults().get(i).getUuid());
sessionManager.setProviderID(loginProviderModel.getResults().get(i).getUuid());
@Override
public void onNext(LoginModel loginModel) {
int responsCode = loginModel.hashCode();
Boolean authencated = loginModel.getAuthenticated();
Gson gson = new Gson();
Logger.logD(TAG, "success" + gson.toJson(loginModel));
sessionManager.setChwname(loginModel.getUser().getDisplay());
sessionManager.setCreatorID(loginModel.getUser().getUuid());
sessionManager.setSessionID(loginModel.getSessionId());
sessionManager.setProviderID(loginModel.getUser().getPerson().getUuid());
UrlModifiers urlModifiers = new UrlModifiers();
String url = urlModifiers.loginUrlProvider(sessionManager.getServerUrl(), loginModel.getUser().getUuid());
if (authencated) {
Observable<LoginProviderModel> loginProviderModelObservable = AppConstants.apiInterface.LOGIN_PROVIDER_MODEL_OBSERVABLE(url, "Basic " + encoded);
loginProviderModelObservable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableObserver<LoginProviderModel>() {
@Override
public void onNext(LoginProviderModel loginProviderModel) {
if (loginProviderModel.getResults().size() != 0) {
for (int i = 0; i < loginProviderModel.getResults().size(); i++) {
Log.i(TAG, "doInBackground: " + loginProviderModel.getResults().get(i).getUuid());
sessionManager.setProviderID(loginProviderModel.getResults().get(i).getUuid());
// success = true;
final Account account = new Account(mEmail, "io.intelehealth.openmrs");
manager.addAccountExplicitly(account, mPassword, null);
offlineLogin.invalidateLoginCredentials();
offlineLogin.setUpOfflineLogin(mEmail, mPassword);
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
intent.putExtra("login", true);
final Account account = new Account(mEmail, "io.intelehealth.openmrs");
manager.addAccountExplicitly(account, mPassword, null);
offlineLogin.invalidateLoginCredentials();
offlineLogin.setUpOfflineLogin(mEmail, mPassword);
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
intent.putExtra("login", true);
// startJobDispatcherService(LoginActivity.this);
startActivity(intent);
finish();
showProgress(false);
startActivity(intent);
finish();
showProgress(false);

sessionManager.setReturningUser(true);
sessionManager.setReturningUser(true);

}
}
}
}

@Override
public void onError(Throwable e) {
Logger.logD(TAG, "handle provider error" + e.getMessage());
@Override
public void onError(Throwable e) {
Logger.logD(TAG, "handle provider error" + e.getMessage());
// success = false;
showProgress(false);
}
showProgress(false);
}

@Override
public void onComplete() {
@Override
public void onComplete() {

}
});
}
}
});
}
}

@Override
public void onError(Throwable e) {
Logger.logD(TAG, "Login Failure" + e.getMessage());
@Override
public void onError(Throwable e) {
Logger.logD(TAG, "Login Failure" + e.getMessage());
// success = false;
showProgress(false);
showProgress(false);
// DialogUtils dialogUtils=new DialogUtils();
// dialogUtils.showerrorDialog(LoginActivity.this,"Error Login",getString(R.string.error_incorrect_password),"ok");
Toast.makeText(LoginActivity.this, getString(R.string.error_incorrect_password), Toast.LENGTH_SHORT).show();
mPasswordView.setError("");
mUsernameView.setError("");
mPasswordView.setText("");
mUsernameView.setText("");
mPasswordView.requestFocus();
}
Toast.makeText(LoginActivity.this, getString(R.string.error_incorrect_password), Toast.LENGTH_SHORT).show();
mPasswordView.setError("");
mUsernameView.setError("");
mPasswordView.setText("");
mUsernameView.setText("");
mPasswordView.requestFocus();
}

@Override
public void onComplete() {
Logger.logD(TAG, "completed");
}
});
@Override
public void onComplete() {
Logger.logD(TAG, "completed");
}
});


// return true;
Expand Down
Loading

0 comments on commit df648f1

Please sign in to comment.