Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
fix ui chaos when logout
Browse files Browse the repository at this point in the history
  • Loading branch information
mcxiaoke committed Mar 11, 2016
1 parent 7ccd29a commit 473db34
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:theme="@style/AppTheme.WhiteBg"
android:launchMode="singleTask"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<meta-data
android:name="android.app.default_searchable"
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/com/mcxiaoke/minicat/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.mcxiaoke.minicat.api.ApiFactory;
import com.mcxiaoke.minicat.config.AccountInfo;
import com.mcxiaoke.minicat.config.AccountStore;
import com.mcxiaoke.minicat.controller.DataController;
import com.mcxiaoke.minicat.controller.UIController;
import com.mcxiaoke.minicat.dao.model.UserModel;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
Expand Down Expand Up @@ -52,12 +51,10 @@ public class AppContext extends Application {
private static AppContext instance;

public static void doLogin(Context context) {
clearAccountInfo(context);
DataController.clearDatabase(context);

if (DEBUG) {
Log.v(TAG, "doLogin()");
}
AppContext.clearAccountInfo(context);
UIController.showLogin(context);
}

Expand Down Expand Up @@ -139,7 +136,7 @@ public static AppContext getApp() {
}

public static boolean isVerified() {
return accountInfo.isVerified();
return accountInfo != null && accountInfo.isVerified();
}

public static synchronized void setActiveContext(Activity context) {
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/mcxiaoke/minicat/api/FanFouApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,9 @@ private String fetch(final RequestBuilder builder) throws ApiException {
Response response = request.send();
int statusCode = response.getCode();
String body = response.getBody();
// if (DEBUG) {
// debug("fetch() statusCode=" + statusCode + " builder info="
// + builder + " builder=" + builder);
// }
if (DEBUG) {
debug("fetch() statusCode=" + statusCode + " builder=" + builder);
}
if (statusCode >= 200 && statusCode < 300) {
return body;
}
Expand Down
24 changes: 2 additions & 22 deletions app/src/main/java/com/mcxiaoke/minicat/app/UIBaseSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static void debug(String message) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
debug("onCreate()");
debug("onCreate() "+this);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
// 这句话必须在setContentView调用之后才有效
//setProgressBarIndeterminateVisibility(false);
Expand Down Expand Up @@ -80,6 +80,7 @@ protected void onPause() {
@Override
protected void onDestroy() {
super.onDestroy();
debug("onDestroy() " + this);
}

@Override
Expand Down Expand Up @@ -179,27 +180,6 @@ private void startSearchUI() {
UIController.showSearchResults(this, null);
}

protected void onMenuLogoutClick() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("@" + AppContext.getScreenName());
builder.setMessage("确定注销当前登录帐号吗?");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
AppContext.doLogin(mContext);
finish();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}

protected void startRefresh() {
debug("startRefresh()");
}
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/java/com/mcxiaoke/minicat/app/UIHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ private void setUp() {
@Override
protected void onResume() {
super.onResume();
// if (mDrawerLayout.isDrawerOpen(mDrawFrame)) {
// mDrawerLayout.closeDrawer(Gravity.LEFT);
// if (AppContext.getAccountInfo() == null) {
// finish();
// }
}

Expand Down Expand Up @@ -500,6 +500,28 @@ public void onMenuItemSelected(int position, MenuItemResource menuItem) {
}
}


private void onMenuLogoutClick() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("@" + AppContext.getScreenName());
builder.setMessage("确定注销当前登录帐号吗?");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
AppContext.doLogin(mContext);
finish();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/mcxiaoke/minicat/app/UILogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.mcxiaoke.minicat.R;
import com.mcxiaoke.minicat.api.Api;
import com.mcxiaoke.minicat.api.ApiException;
import com.mcxiaoke.minicat.controller.DataController;
import com.mcxiaoke.minicat.controller.UIController;
import com.mcxiaoke.minicat.dao.model.UserModel;
import com.mcxiaoke.minicat.ui.widget.TextChangeListener;
Expand Down Expand Up @@ -252,7 +253,7 @@ protected ResultInfo doInBackground(Void... params) {
if (AppContext.DEBUG) {
log("xauth successful! ");
}

DataController.clearDatabase(getApplication());
UmengHelper.onLoginEvent(mContext, u.getId());
return new ResultInfo(LOGIN_AUTH_SUCCESS);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void showAbout(Activity context) {

public static void showLogin(Context context) {
Intent intent = new Intent(context, UILogin.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public void startRefresh() {
if (AppContext.DEBUG) {
Log.v(TAG, "startRefresh() busy=" + busy + " " + this);
}
if (!AppContext.isVerified()) {
return;
}
if (NetworkHelper.isNotConnected(getActivity())) {
return;
}
Expand Down Expand Up @@ -422,7 +425,6 @@ private void onError(Bundle data) {
return;
}
Utils.notify(getActivity(), errorMessage);
Utils.checkAuthorization(getActivity(), errorCode);
}

private void onRefreshComplete() {
Expand Down

0 comments on commit 473db34

Please sign in to comment.