Search in sources :

Example 6 with AccountBean

use of org.qii.weiciyuan.bean.AccountBean in project weiciyuan by qii.

the class Utility method showExpiredTokenDialogOrNotification.

public static void showExpiredTokenDialogOrNotification() {
    final Activity activity = GlobalContext.getInstance().getCurrentRunningActivity();
    boolean currentAccountTokenIsExpired = true;
    AccountBean currentAccount = GlobalContext.getInstance().getAccountBean();
    if (currentAccount != null) {
        currentAccountTokenIsExpired = !Utility.isTokenValid(currentAccount);
    }
    if (currentAccountTokenIsExpired && activity != null && !GlobalContext.getInstance().tokenExpiredDialogIsShowing) {
        if (activity.getClass() == AccountActivity.class) {
            return;
        }
        if (activity.getClass() == OAuthActivity.class) {
            return;
        }
        if (activity.getClass() == BlackMagicActivity.class) {
            return;
        }
        if (activity.getClass() == SSOActivity.class) {
            return;
        }
        final AccountBean needRefreshTokenAccount = currentAccount;
        activity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                new AlertDialog.Builder(activity).setTitle(R.string.dialog_title_error).setMessage(R.string.your_token_is_expired).setPositiveButton(R.string.logout_to_login_again, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.startActivity(AccountActivity.newIntent(needRefreshTokenAccount));
                        activity.finish();
                        GlobalContext.getInstance().tokenExpiredDialogIsShowing = false;
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                    //do nothing
                    }
                }).show();
                GlobalContext.getInstance().tokenExpiredDialogIsShowing = true;
            }
        });
    } else if (!currentAccountTokenIsExpired || activity == null) {
        Intent i = AccountActivity.newIntent();
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(GlobalContext.getInstance(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification.Builder builder = new Notification.Builder(GlobalContext.getInstance()).setContentTitle(GlobalContext.getInstance().getString(R.string.login_again)).setContentText(GlobalContext.getInstance().getString(R.string.have_account_whose_token_is_expired)).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(pendingIntent).setOnlyAlertOnce(true);
        NotificationManager notificationManager = (NotificationManager) GlobalContext.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(NotificationServiceHelper.getTokenExpiredNotificationId(), builder.build());
    } else if (GlobalContext.getInstance().tokenExpiredDialogIsShowing) {
        NotificationManager notificationManager = (NotificationManager) GlobalContext.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(NotificationServiceHelper.getTokenExpiredNotificationId());
    }
}
Also used : NotificationManager(android.app.NotificationManager) DialogInterface(android.content.DialogInterface) OAuthActivity(org.qii.weiciyuan.ui.login.OAuthActivity) SSOActivity(org.qii.weiciyuan.ui.login.SSOActivity) AccountActivity(org.qii.weiciyuan.ui.login.AccountActivity) FragmentActivity(android.support.v4.app.FragmentActivity) BlackMagicActivity(org.qii.weiciyuan.ui.blackmagic.BlackMagicActivity) Activity(android.app.Activity) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification) PendingIntent(android.app.PendingIntent) AccountBean(org.qii.weiciyuan.bean.AccountBean)

Example 7 with AccountBean

use of org.qii.weiciyuan.bean.AccountBean in project weiciyuan by qii.

the class FriendsTimeLineListNavAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null || convertView.getTag() == null) {
        LayoutInflater inflater = activity.getLayoutInflater();
        convertView = inflater.inflate(R.layout.spinner_selector_text_view, parent, false);
        holder = new ViewHolder();
        holder.textView = (TextView) convertView;
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    if (position != 0) {
        holder.textView.setText(valueArray[position]);
    } else {
        AccountBean accountBean = GlobalContext.getInstance().getAccountBean();
        holder.textView.setText(accountBean.getUsernick());
    }
    return convertView;
}
Also used : LayoutInflater(android.view.LayoutInflater) AccountBean(org.qii.weiciyuan.bean.AccountBean)

Example 8 with AccountBean

use of org.qii.weiciyuan.bean.AccountBean in project weiciyuan by qii.

the class AccountActivity method jumpToMainTimeLineActivity.

private void jumpToMainTimeLineActivity() {
    String id = SettingUtility.getDefaultAccountId();
    if (!TextUtils.isEmpty(id)) {
        AccountBean bean = AccountDBTask.getAccount(id);
        if (bean != null) {
            Intent start = MainTimeLineActivity.newIntent(bean);
            startActivity(start);
            finish();
        }
    }
}
Also used : Intent(android.content.Intent) AccountBean(org.qii.weiciyuan.bean.AccountBean)

Example 9 with AccountBean

use of org.qii.weiciyuan.bean.AccountBean in project weiciyuan by qii.

the class WriteCommentActivity method handleNotificationCommentOperation.

private void handleNotificationCommentOperation(Intent intent) {
    AccountBean accountBean = intent.getParcelableExtra("account");
    token = accountBean.getAccess_token();
    msg = intent.getParcelableExtra("msg");
    getEditTextView().setHint("@" + msg.getUser().getScreen_name() + ":" + msg.getText());
}
Also used : AccountBean(org.qii.weiciyuan.bean.AccountBean)

Example 10 with AccountBean

use of org.qii.weiciyuan.bean.AccountBean in project weiciyuan by qii.

the class WriteRepostActivity method handleDraftOperation.

private void handleDraftOperation(Intent intent) {
    AccountBean account = (AccountBean) intent.getParcelableExtra("account");
    token = account.getAccess_token();
    repostDraftBean = (RepostDraftBean) intent.getParcelableExtra("draft");
    getEditTextView().setText(repostDraftBean.getContent());
    msg = repostDraftBean.getMessageBean();
    if (msg.getRetweeted_status() != null) {
        getEditTextView().setHint("//@" + msg.getRetweeted_status().getUser().getScreen_name() + ":" + msg.getRetweeted_status().getText());
    } else {
        getEditTextView().setHint("@" + msg.getUser().getScreen_name() + ":" + msg.getText());
    }
}
Also used : AccountBean(org.qii.weiciyuan.bean.AccountBean)

Aggregations

AccountBean (org.qii.weiciyuan.bean.AccountBean)19 Intent (android.content.Intent)4 Notification (android.app.Notification)3 NotificationManager (android.app.NotificationManager)3 PendingIntent (android.app.PendingIntent)3 ArrayList (java.util.ArrayList)3 MessageBean (org.qii.weiciyuan.bean.MessageBean)3 UnreadBean (org.qii.weiciyuan.bean.UnreadBean)3 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 Cursor (android.database.Cursor)2 Handler (android.os.Handler)2 Parcelable (android.os.Parcelable)2 Gson (com.google.gson.Gson)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 CommentBean (org.qii.weiciyuan.bean.CommentBean)2 CommentListBean (org.qii.weiciyuan.bean.CommentListBean)2 MessageListBean (org.qii.weiciyuan.bean.MessageListBean)2 UserBean (org.qii.weiciyuan.bean.UserBean)2 WeiboException (org.qii.weiciyuan.support.error.WeiboException)2