package cn.ycoder.android.library;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.ArrayRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.util.TypedValue;
import cn.ycoder.android.library.tool.ActivitiesManager;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

/**
 * @author 启研
 * @created at 2017/3/9.
 */
public class BaseActivity extends RxAppCompatActivity {

  private ProgressDialog dialog;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivitiesManager.getInstance().pushActivity(this);
    dialog = new ProgressDialog(this);
    TypedValue value = new TypedValue();
    if (getTheme().resolveAttribute(R.attr.indeterminateProgressBar, value, true)) {
      dialog.setIndeterminateDrawable(ContextCompat.getDrawable(getBaseContext(),value.resourceId));
    }
    dialog.setIndeterminate(true);
    dialog.setMessage("请稍候...");
    dialog.setCanceledOnTouchOutside(false);
  }

  /**
   * 显示加载条
   */
  public void showProgress(boolean show) {
    showProgress(show, "请稍候...");
  }

  /**
   * 显示加载条
   */
  protected void showProgress(boolean show, String msg) {
    if (show) {
      dialog.setMessage(msg);
      dialog.show();
    } else {
      dialog.dismiss();
    }
  }

  /**
   * 显示不同文案
   */
  public void showProgress(String loadMessage) {
    showProgress(true, loadMessage);
  }

  public Activity context() {
    return this;
  }

  /**
   * 获取字符串
   */
  public String string(@StringRes int resId) {
    return getString(resId);
  }

  /**
   * 获取字符数组
   */
  public String[] array(@ArrayRes int resId) {
    return getResources().getStringArray(resId);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    showProgress(false);
  }

  @Override
  public void onBackPressed() {
    super.onBackPressed();
    ActivitiesManager.getInstance().finishActivity(this);
  }
}

@@ -391,16 +391,68 @@
 anager;%0A
+import com.alibaba.android.arouter.facade.Postcard;%0A
 import c
@@ -617,16 +617,87 @@
 tivity %7B
+%0A  public final static String TAG_HISTORY_POSTCARD = %22historyPostcard%22;
 %0A%0A  priv
@@ -2209,14 +2209,423 @@
 (this);%0A
+    if (destroyClearPostcard() && BaseApplication.getInstance() != null) %7B%0A      Postcard postcard = (Postcard) BaseApplication.getInstance()%0A          .getTag(TAG_HISTORY_POSTCARD);%0A      if (postcard != null) %7B%0A        //%E6%B8%85%E7%90%86%E6%84%8F%E5%9B%BE%0A        BaseApplication.getInstance().setTag(TAG_HISTORY_POSTCARD,null);%0A      %7D%0A    %7D%0A  %7D%0A%0A  /**%0A   * %E9%94%80%E6%AF%81%E7%9A%84%E6%97%B6%E5%80%99%E6%B8%85%E7%90%86%E6%84%8F%E5%9B%BE%0A   */%0A  protected boolean destroyClearPostcard() %7B%0A    return true;%0A
   %7D%0A%7D%0A

修正：增加清理Aroute历史访问