提交 50dfff59 编写于 作者: A amitshekhariitbhu

Implement show and hide loading for activity

上级 d1b2d2a1
......@@ -17,17 +17,23 @@
package com.mindorks.framework.mvvm.ui.base;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import com.mindorks.framework.mvvm.MvvmApp;
import com.mindorks.framework.mvvm.di.component.ActivityComponent;
import com.mindorks.framework.mvvm.di.component.DaggerActivityComponent;
import com.mindorks.framework.mvvm.di.module.ActivityModule;
import com.mindorks.framework.mvvm.ui.login.LoginActivity;
import com.mindorks.framework.mvvm.utils.CommonUtils;
import com.mindorks.framework.mvvm.utils.NetworkUtils;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
......@@ -39,6 +45,8 @@ public abstract class BaseActivity extends AppCompatActivity implements BaseFrag
private ActivityComponent mActivityComponent;
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -85,5 +93,34 @@ public abstract class BaseActivity extends AppCompatActivity implements BaseFrag
}
public void hideKeyboard() {
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
public void openActivityOnTokenExpire() {
startActivity(LoginActivity.getStartIntent(this));
finish();
}
public boolean isNetworkConnected() {
return NetworkUtils.isNetworkConnected(getApplicationContext());
}
public void showLoading() {
hideLoading();
mProgressDialog = CommonUtils.showLoadingDialog(this);
}
public void hideLoading() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.cancel();
}
}
}
......@@ -70,4 +70,9 @@ public class LoginActivity extends BaseActivity implements LoginCallback {
startActivity(intent);
finish();
}
@Override
public void handleError(Throwable throwable) {
// handle error
}
}
......@@ -24,4 +24,10 @@ public interface LoginCallback {
void openMainActivity();
void showLoading();
void hideLoading();
void handleError(Throwable throwable);
}
......@@ -16,7 +16,6 @@
package com.mindorks.framework.mvvm.ui.login;
import com.androidnetworking.error.ANError;
import com.mindorks.framework.mvvm.data.DataManager;
import com.mindorks.framework.mvvm.data.model.api.LoginRequest;
import com.mindorks.framework.mvvm.data.model.api.LoginResponse;
......@@ -43,6 +42,7 @@ public class LoginViewModel extends BaseViewModel<LoginCallback> {
}
public void onGoogleLoginClick() {
getCallback().showLoading();
getCompositeDisposable().add(getDataManager()
.doGoogleLoginApiCall(new LoginRequest.GoogleLoginRequest("test1", "test1"))
.subscribeOn(getSchedulerProvider().io())
......@@ -57,22 +57,20 @@ public class LoginViewModel extends BaseViewModel<LoginCallback> {
response.getUserName(),
response.getUserEmail(),
response.getGoogleProfilePicUrl());
getCallback().hideLoading();
getCallback().openMainActivity();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
// handle the login error here
if (throwable instanceof ANError) {
ANError anError = (ANError) throwable;
}
getCallback().hideLoading();
getCallback().handleError(throwable);
}
}));
}
public void onFbLoginClick() {
getCallback().showLoading();
getCompositeDisposable().add(getDataManager()
.doFacebookLoginApiCall(new LoginRequest.FacebookLoginRequest("test3", "test4"))
.subscribeOn(getSchedulerProvider().io())
......@@ -87,16 +85,14 @@ public class LoginViewModel extends BaseViewModel<LoginCallback> {
response.getUserName(),
response.getUserEmail(),
response.getGoogleProfilePicUrl());
getCallback().hideLoading();
getCallback().openMainActivity();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
// handle the login error here
if (throwable instanceof ANError) {
ANError anError = (ANError) throwable;
}
getCallback().hideLoading();
getCallback().handleError(throwable);
}
}));
}
......
......@@ -156,6 +156,7 @@ public class MainActivity extends BaseActivity implements MainCallback {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
hideKeyboard();
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册