Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BaseActivity extends AppCompatActivity implements MvpView {
- private static final String TAG = BaseActivity.class.getSimpleName();
- private static final String KEY_ACTIVITY_ID = "KEY_ACTIVITY_ID";
- private static final AtomicLong NEXT_ID = new AtomicLong(0);
- private static final Map<Long, ConfigPersistentComponent> sComponentsMap = new HashMap<>();
- private ActivityComponent mActivityComponent;
- private long mActivityId;
- int statusCode;
- protected Dialog progressDialog;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // set all activity to portrait
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- // Create the ActivityComponent and reuses cached ConfigPersistentComponent if this is
- // being called after a configuration change.
- mActivityId = savedInstanceState != null ?
- savedInstanceState.getLong(KEY_ACTIVITY_ID) : NEXT_ID.getAndIncrement();
- ConfigPersistentComponent configPersistentComponent;
- if (!sComponentsMap.containsKey(mActivityId)) {
- Log.d(TAG, "Creating new ConfigPersistentComponent id= " + mActivityId);
- configPersistentComponent = DaggerConfigPersistentComponent.builder()
- .applicationComponent(Apps.get(this).getComponent())
- .build();
- sComponentsMap.put(mActivityId, configPersistentComponent);
- } else {
- Log.i(TAG, "Reusing ConfigPersistentComponent id= " + mActivityId);
- configPersistentComponent = sComponentsMap.get(mActivityId);
- }
- mActivityComponent = configPersistentComponent.activityComponent(new ActivityModule(this));
- }
- public ActivityComponent activityComponent() {
- return mActivityComponent;
- }
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- Log.v(TAG, "onSaveInstanceState " + this.getClass().getSimpleName());
- super.onSaveInstanceState(outState);
- outState.putLong(KEY_ACTIVITY_ID, mActivityId);
- }
- @Override
- protected void onDestroy() {
- Log.v(TAG, "onDestroy " + this.getClass().getSimpleName());
- if (!isChangingConfigurations()) {
- Log.d(TAG, "Clearing ConfigPersistentComponent id= " + mActivityId);
- sComponentsMap.remove(mActivityId);
- }
- super.onDestroy();
- }
- @Override
- public void showLoading(boolean isShow) {
- Log.d(TAG, "BaseActivity showLoading");
- }
- @Override
- public void showNoDataFound(boolean isNoData) {
- }
- @Override
- public void showError(Throwable error) {
- }
- // @Override
- // public void showNoDataFound(boolean isNoData) {
- // Log.d(TAG, "BaseActivity showNoDataFound");
- //
- // String nMessage = getResources().getString(R.string.info_notfound);
- // showDialog(nMessage);
- // }
- // @Override
- // @CallSuper
- // public void showError(Throwable error) {
- //
- // Log.d(TAG, "BaseActivity showError");
- //
- // if (error instanceof HttpException) {
- // showDialog(((HttpException) error).message());
- // } else if (error instanceof SocketTimeoutException) {
- // showDialog(error.getMessage());
- // } else if (error instanceof IOException) {
- // showDialog(error.getMessage());
- // } else {
- // showDialog(error.getMessage());
- // }
- //
- // }
- protected String statusCode( Throwable error){
- HttpException exception = (HttpException) error;
- statusCode = ((HttpException) error).code();
- String nMessageCode = String.valueOf(statusCode);
- return nMessageCode;
- }
- public static boolean isOnline(Context c) {
- ConnectivityManager cm = (ConnectivityManager) c
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo netInfo = cm.getActiveNetworkInfo();
- if (netInfo != null && netInfo.isConnectedOrConnecting()) {
- return true;
- }
- return false;
- }
- // @Override
- // public void onResponse(Call call, ResponseProduct response) throws IOException {
- // int nA = response.code();
- // String nMessage = String.valueOf(nA);
- // showDialog(nMessage);
- //
- // }
- // protected void showDialog(final String message) {
- // final AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
- //
- // String nTitle = getResources().getString(R.string.warning_memotus_service);
- // builder.setTitle(R.string.warning);
- // if (message != null) {
- // builder.setMessage(Html.fromHtml(nTitle + " - ( " + message + " )"));
- // } else {
- // builder.setMessage("");
- // }
- // builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
- // @Override
- // public void onClick(DialogInterface dialog, int which) {
- // dialog.dismiss();
- // Intent i = new Intent(getApplicationContext(), MenuMainBeforeLogin.class);
- // startActivity(i);
- // finish();
- //
- // }
- // });
- // builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- // @Override
- // public void onClick(DialogInterface dialog, int which) {
- // dialog.dismiss();
- // Intent i = new Intent(getApplicationContext(), MenuMainBeforeLogin.class);
- // startActivity(i);
- // finish();
- //
- // }
- // });
- // if (!isFinishing()) {
- // builder.show();
- // }
- // }
- protected void showProgressDialog() {
- if (progressDialog == null || !progressDialog.isShowing()) {
- progressDialog = new ProgressDialog(this);
- progressDialog.setCanceledOnTouchOutside(false);
- if (!isFinishing()) {
- progressDialog.show();
- }
- }
- }
- protected void hideProgressDialog() {
- if (progressDialog != null && progressDialog.isShowing()) {
- if (!isFinishing()) {
- progressDialog.dismiss();
- }
- }
- }
- @Override
- public void showProgress() {
- showProgressDialog();
- }
- @Override
- public void hideProgress() {
- hideProgressDialog();
- }
- @Override
- public void onResponse(Call call, Response response) throws IOException {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement