@Override protected void onPostResume() { super.onPostResume(); Session.getInstance().addObserver(this); updateUIOnLoginOut(); AppVersion appVersion = Session.getInstance().getAppVersion(); if (ConnectedApp.APPVERSION_CHECK_ENABLED && appVersion != null && appVersion.forceUpdate()) setNavigationDisabled(true); }
protected void updateUserHeader() { final MenuItem userHeaderMenu = (mOptionsMenu != null) ? mOptionsMenu.findItem(R.id.menu_user_header) : null; if (userHeaderMenu != null) { View userHeaderView = MenuItemCompat.getActionView(userHeaderMenu); if (userHeaderView == null) { userHeaderView = getLayoutInflater().inflate(R.layout.actionbar_user_header, null, false); userHeaderView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onOptionsItemSelected(userHeaderMenu); } }); MenuItemCompat.setShowAsAction(userHeaderMenu, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.setActionView(userHeaderMenu, userHeaderView); } UserHeader header = Session.getInstance().getCustomerHeader(); if (header != null) { ((TextView) userHeaderView.findViewById(R.id.text1)).setText("hi"); userHeaderMenu.setTitle(header.userName.getUserNameDisplay()); userHeaderMenu.setVisible(true); } else { userHeaderMenu.setTitle("Login"); userHeaderMenu.setVisible(false); } } }
@Override public void update(Observable observable, Object data) { if (isFinishing()) return; final Session.WhatChanged whatChanged = (Session.WhatChanged) data; Log.d(TAG, "Session changed: " + whatChanged); if (Session.getInstance() == observable) runOnUiThread( new Runnable() { @Override public void run() { switch (whatChanged) { case USER_HEADER: onUserHeader(); break; case RE_AUTH: onReAuth(); break; case LOG_IN_OUT: updateUIOnLoginOut(); break; case APP_VERSION: final AppVersion appVersion = Session.getInstance().getAppVersion(); if (shouldShowUpdateDialog(appVersion)) { // Need to update String msg; DialogInterface.OnClickListener dlUpdateListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse(appVersion.getAppDownloadURL())); startActivity(intent); finish(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this) .setCancelable(false) .setIcon(R.drawable.ic_launcher) .setTitle(R.string.app_update_available_heading) .setPositiveButton(R.string.ok, dlUpdateListener); View view; Context c; if (Build.VERSION.SDK_INT >= 11) { c = builder.getContext(); } else c = BaseActivity.this; view = LayoutInflater.from(c).inflate(R.layout.dialog_scrollview_msg, null); TextView textView = (TextView) view.findViewById(R.id.text1); if (appVersion.forceUpdate()) { int stringRes = R.string.app_force_update_store; msg = getString( stringRes, appVersion.getLatestClientVersion(), appVersion.getVersionUpdateDate(), appVersion.getWhatsNew()); builder.setCancelable(false); setNavigationDisabled(true); } else { // Version, date, changes int stringRes = R.string.app_update_available_store; msg = getString( stringRes, appVersion.getLatestClientVersion(), appVersion.getVersionUpdateDate(), appVersion.getWhatsNew()); builder.setNegativeButton(R.string.cancel, null); } textView.setText(Html.fromHtml(msg)); textView.setMovementMethod(LinkMovementMethod.getInstance()); builder.setView(view); builder.show(); } break; } for (BaseFragment activeFragment : ListUtils.ofType(getActiveFragments(), BaseFragment.class)) { activeFragment.onSessionChanged(whatChanged); } } }); }
@Override public void onStop() { super.onStop(); Session.getInstance().deleteObserver(this); }
public void onLogoutClicked() { Session.getInstance().executeLogout(); Intent intent = new Intent(this, HomeActivity.class); startActivity(intent); finish(); }
/** UI hook when a user logs in or out */ protected void updateUIOnLoginOut() { onUserHeader(); if (!Session.getInstance().isLoggedIn() && !Session.getInstance().isExecutingAutoLogin()) onReAuth(); }