Skip to content

Commit

Permalink
review code
Browse files Browse the repository at this point in the history
  • Loading branch information
xuewu.wei committed Sep 9, 2019
1 parent cd56b7f commit d3768e8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

public abstract class BaseContentFragment extends BaseFragment {

public static final String GET_ACTIVITY_IS_NULL = "get activity is null";
private CharSequence title;

/**
Expand All @@ -47,7 +48,7 @@ public final ActionBarActivity getActionBarActivity() {
public ActionBar getCustomActionBar() {
ActionBarActivity abActivity = (ActionBarActivity) this.getActivity();
if (abActivity == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
return abActivity.getCustomActionBar();
}
Expand Down Expand Up @@ -99,7 +100,7 @@ public void onDestroyView() {
public void setStatusBarColor(int color) {
ActionBarActivity abActivity = (ActionBarActivity) this.getActivity();
if (abActivity == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
abActivity.setStatusBarTintColor(color);
}
Expand All @@ -113,7 +114,7 @@ public void setStatusBarColor(int color) {
public void setNavigationBarTintColor(int color) {
ActionBarActivity abActivity = (ActionBarActivity) this.getActivity();
if (abActivity == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
abActivity.setNavigationBarTintColor(color);
}
Expand All @@ -125,7 +126,7 @@ public void setNavigationBarTintColor(int color) {
public void enableRefresh(boolean enable) {
ActionBarActivity abActivity = (ActionBarActivity) this.getActivity();
if (abActivity == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
abActivity.getCustomActionBar().enableRefresh(enable);
}
Expand All @@ -137,7 +138,7 @@ public void enableRefresh(boolean enable) {
public void refreshing(boolean refreshing) {
ActionBarActivity abActivity = (ActionBarActivity) this.getActivity();
if (abActivity == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
abActivity.getCustomActionBar().refreshing(refreshing);
}
Expand All @@ -152,7 +153,7 @@ public void refreshing(boolean refreshing) {
public ActionMode startCustomActionMode(ActionMode.Callback callback) {
ActionBarActivity abActivity = (ActionBarActivity) this.getActivity();
if (abActivity == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
return abActivity.startCustomActionMode(callback);
}
Expand All @@ -168,7 +169,7 @@ protected final void setMenuEnable(boolean enable) {
BaseContentFragment parent = (BaseContentFragment) this.getParentFragment();
if (parent == null) {
if (getActivity() == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else if (this.getParentFragment() == null) {
if (this.getActivity() instanceof BaseNavigationFragmentActivity) {
BaseNavigationFragmentActivity bfActivity = (BaseNavigationFragmentActivity) this.getActivity();
Expand All @@ -182,7 +183,7 @@ protected final void setMenuEnable(boolean enable) {

protected final void notifyMenuChange(int moduleId) {
if (getActivity() == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
if (this.getActivity() instanceof BaseNavigationFragmentActivity) {
BaseNavigationFragmentActivity bfActivity = (BaseNavigationFragmentActivity) this.getActivity();
Expand All @@ -195,7 +196,7 @@ private final void setActionBarUpIndicator() {
BaseContentFragment parent = (BaseContentFragment) this.getParentFragment();
if (parent == null) {
if (getActivity() == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
ActionBarActivity bfActivity = (ActionBarActivity) this.getActivity();
if (isCleanStack()) {
Expand Down Expand Up @@ -239,7 +240,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ActionBarActivity abActivity = (ActionBarActivity) this.getActivity();
if (abActivity == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
this.onMenuActionCreated(abActivity.getCustomActionBar().getActionMenu());
}
Expand Down
22 changes: 12 additions & 10 deletions uiframe/src/main/java/mobi/cangol/mobile/base/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
public abstract class BaseFragment extends Fragment {
public static final int RESULT_CANCELED = 0;
public static final int RESULT_OK = -1;
public static final String REQUEST_CODE_1 = "requestCode!=-1";
public static final String ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE = "IllegalStateException Fragment isEnable=false";
protected final String TAG = Log.makeLogTag(this.getClass());
protected CoreApplication app;
private long startTime;
Expand Down Expand Up @@ -389,7 +391,7 @@ public void showToast(int resId) {
CustomFragmentActivityDelegate bfActivity = (CustomFragmentActivityDelegate) this.getActivity();
bfActivity.showToast(resId);
} else {
Log.e("showToast IllegalStateException Fragment isEnable=false");
Log.e(ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE);
}
}

Expand All @@ -404,7 +406,7 @@ public void showToast(int resId, int duration) {
CustomFragmentActivityDelegate bfActivity = (CustomFragmentActivityDelegate) this.getActivity();
bfActivity.showToast(resId, duration);
} else {
Log.e("showToast IllegalStateException Fragment isEnable=false");
Log.e(ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE);
}
}

Expand All @@ -418,7 +420,7 @@ public void showToast(String str) {
CustomFragmentActivityDelegate bfActivity = (CustomFragmentActivityDelegate) this.getActivity();
bfActivity.showToast(str);
} else {
Log.e("showToast IllegalStateException Fragment isEnable=false");
Log.e(ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE);
}
}

Expand All @@ -433,7 +435,7 @@ public void showToast(String str, int duration) {
CustomFragmentActivityDelegate bfActivity = (CustomFragmentActivityDelegate) this.getActivity();
bfActivity.showToast(str,duration);
} else {
Log.e("showToast IllegalStateException Fragment isEnable=false");
Log.e(ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE);
}
}

Expand All @@ -451,7 +453,7 @@ public void showSoftInput(EditText editText) {
BaseActivityDelegate bfActivity = (BaseActivityDelegate) this.getActivity();
bfActivity.showSoftInput(editText);
} else {
Log.e("showSoftInput IllegalStateException Fragment isEnable=false");
Log.e(ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE);
}
}

Expand All @@ -460,7 +462,7 @@ public void hideSoftInput() {
BaseActivityDelegate bfActivity = (BaseActivityDelegate) this.getActivity();
bfActivity.hideSoftInput();
} else {
Log.e("hideSoftInput IllegalStateException Fragment isEnable=false");
Log.e(ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE);
}
}

Expand All @@ -469,7 +471,7 @@ public void hideSoftInput(EditText editText) {
BaseActivityDelegate bfActivity = (BaseActivityDelegate) this.getActivity();
bfActivity.hideSoftInput(editText);
} else {
Log.e("hideSoftInput IllegalStateException Fragment isEnable=false");
Log.e(ILLEGAL_STATE_EXCEPTION_FRAGMENT_IS_ENABLE_FALSE);
}
}
/**
Expand Down Expand Up @@ -533,7 +535,7 @@ public final void replaceFragmentForResult(Class<? extends BaseFragment> fragme
if (requestCode != -1) {
this.replaceFragment(fragmentClass, tag, args, new CustomFragmentTransaction().setTargetFragment(this, requestCode));
} else {
throw new IllegalStateException("requestCode!=-1");
throw new IllegalStateException(REQUEST_CODE_1);
}
}
public final void replaceFragmentForResult(Class<? extends BaseFragment> fragmentClass, String tag, Bundle args, int requestCode,CustomFragmentTransaction customFragmentTransaction) {
Expand All @@ -544,7 +546,7 @@ public final void replaceFragmentForResult(Class<? extends BaseFragment> fragme
this.replaceFragment(fragmentClass, tag, args, new CustomFragmentTransaction().setTargetFragment(this, requestCode));
}
} else {
throw new IllegalStateException("requestCode!=-1");
throw new IllegalStateException(REQUEST_CODE_1);
}
}
/**
Expand Down Expand Up @@ -627,7 +629,7 @@ public final void replaceParentFragmentForResult(Class<? extends BaseFragment>
if (requestCode != -1) {
this.replaceParentFragment(fragmentClass, tag, args, new CustomFragmentTransaction().setTargetFragment(this, requestCode));
} else {
throw new IllegalStateException("requestCode!=-1");
throw new IllegalStateException(REQUEST_CODE_1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public final void onBackPressed() {
/**
* 处理back事件
*/
@Override
public void onBack() {
Log.v(TAG, "onBack");
super.onBackPressed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.os.Bundle;

public abstract class BaseMenuFragment extends BaseFragment {
public static final String GET_ACTIVITY_IS_NULL = "getActivity is null";
private int currentModuleId;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ public void onSaveInstanceState(Bundle outState) {
public void setContentFragment(Class<? extends BaseContentFragment> fragmentClass, String tag, Bundle args) {

if (getActivity() == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
BaseNavigationFragmentActivity bfActivity = (BaseNavigationFragmentActivity) this.getActivity();
bfActivity.setContentFragment(fragmentClass, tag, args);
Expand All @@ -82,7 +83,7 @@ public void setContentFragment(Class<? extends BaseContentFragment> fragmentClas
public void setContentFragment(Class<? extends BaseContentFragment> fragmentClass, String tag, Bundle args, int moduleId) {

if (getActivity() == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
BaseNavigationFragmentActivity bfActivity = (BaseNavigationFragmentActivity) this.getActivity();
bfActivity.setContentFragment(fragmentClass, tag, args, moduleId);
Expand All @@ -97,7 +98,7 @@ public void setContentFragment(Class<? extends BaseContentFragment> fragmentClas
public void showMenu(boolean show) {

if (getActivity() == null) {
throw new IllegalStateException("getActivity is null");
throw new IllegalStateException(GET_ACTIVITY_IS_NULL);
} else {
BaseNavigationFragmentActivity bfActivity = (BaseNavigationFragmentActivity) this.getActivity();
bfActivity.showMenu(show);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ public void saveState(Bundle outState) {

public void restoreState(Bundle state) {
String[] stackTags = state.getStringArray(STATE_TAG);
if(stackTags!=null&&stackTags.length>0)
for (String tag : stackTags) {
BaseFragment f = (BaseFragment) fragmentManager.findFragmentByTag(tag);
stack.addFragment(f);
stack.addTag(tag);
if(stackTags!=null){
for (String tag : stackTags) {
BaseFragment f = (BaseFragment) fragmentManager.findFragmentByTag(tag);
stack.addFragment(f);
stack.addTag(tag);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import android.text.TextUtils;

import java.lang.ref.WeakReference;
import java.util.Stack;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/

public abstract class TabDrawerNavigationFragmentActivity extends BaseNavigationFragmentActivity {

public static final String GET_ACTIVITY_IS_TAB_DRAWER_NAVIGATION_FRAGMENT_ACTIVITY_DELEGATE = "getActivity is TabDrawerNavigationFragmentActivityDelegate";

@Override
public void onCreate(Bundle savedInstanceState) {
this.setNavigationFragmentActivityDelegate(new TabDrawerNavigationFragmentActivityDelegate(
Expand All @@ -47,23 +50,23 @@ public void setDrawerEnable(int gravity, boolean enable) {
if (getNavigationFragmentActivityDelegate() instanceof TabDrawerNavigationFragmentActivityDelegate) {
((TabDrawerNavigationFragmentActivityDelegate) getNavigationFragmentActivityDelegate()).setDrawerEnable(gravity, enable);
} else {
throw new IllegalStateException("getActivity is TabDrawerNavigationFragmentActivityDelegate");
throw new IllegalStateException(GET_ACTIVITY_IS_TAB_DRAWER_NAVIGATION_FRAGMENT_ACTIVITY_DELEGATE);
}
}

public void showDrawer(int gravity, boolean show) {
if (getNavigationFragmentActivityDelegate() instanceof TabDrawerNavigationFragmentActivityDelegate) {
((TabDrawerNavigationFragmentActivityDelegate) getNavigationFragmentActivityDelegate()).showDrawer(gravity, show);
} else {
throw new IllegalStateException("getActivity is TabDrawerNavigationFragmentActivityDelegate");
throw new IllegalStateException(GET_ACTIVITY_IS_TAB_DRAWER_NAVIGATION_FRAGMENT_ACTIVITY_DELEGATE);
}
}

public boolean isShowDrawer(int gravity) {
if (getNavigationFragmentActivityDelegate() instanceof TabDrawerNavigationFragmentActivityDelegate) {
return ((TabDrawerNavigationFragmentActivityDelegate) getNavigationFragmentActivityDelegate()).isShowDrawer(gravity);
} else {
throw new IllegalStateException("getActivity is TabDrawerNavigationFragmentActivityDelegate");
throw new IllegalStateException(GET_ACTIVITY_IS_TAB_DRAWER_NAVIGATION_FRAGMENT_ACTIVITY_DELEGATE);
}
}

Expand All @@ -72,23 +75,23 @@ public void setDrawer(int gravity, Class<? extends BaseFragment> fragmentClass,
if (getNavigationFragmentActivityDelegate() instanceof TabDrawerNavigationFragmentActivityDelegate) {
((TabDrawerNavigationFragmentActivityDelegate) getNavigationFragmentActivityDelegate()).setDrawer(gravity, drawerFragment);
} else {
throw new IllegalStateException("getActivity is TabDrawerNavigationFragmentActivityDelegate");
throw new IllegalStateException(GET_ACTIVITY_IS_TAB_DRAWER_NAVIGATION_FRAGMENT_ACTIVITY_DELEGATE);
}
}

public BaseFragment getDrawer(int gravity) {
if (getNavigationFragmentActivityDelegate() instanceof TabDrawerNavigationFragmentActivityDelegate) {
return ((TabDrawerNavigationFragmentActivityDelegate) getNavigationFragmentActivityDelegate()).getDrawer(gravity);
} else {
throw new IllegalStateException("getActivity is TabDrawerNavigationFragmentActivityDelegate");
throw new IllegalStateException(GET_ACTIVITY_IS_TAB_DRAWER_NAVIGATION_FRAGMENT_ACTIVITY_DELEGATE);
}
}

public void removeDrawer(int gravity) {
if (getNavigationFragmentActivityDelegate() instanceof TabDrawerNavigationFragmentActivityDelegate) {
((TabDrawerNavigationFragmentActivityDelegate) getNavigationFragmentActivityDelegate()).removeDrawer(gravity);
} else {
throw new IllegalStateException("getActivity is TabDrawerNavigationFragmentActivityDelegate");
throw new IllegalStateException(GET_ACTIVITY_IS_TAB_DRAWER_NAVIGATION_FRAGMENT_ACTIVITY_DELEGATE);
}
}
}
Expand Down

0 comments on commit d3768e8

Please sign in to comment.