Exemple #1
0
  @Override
  public void onNewIntent(Intent intent) {
    setIntent(intent); // onNewIntent doesn't autoset our "internal" intent

    String initialFolder;

    mUnreadMessageCount = 0;
    String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);

    if (mAccount == null) {
      // This shouldn't normally happen. But apparently it does. See issue 2261.
      finish();
      return;
    }

    initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
    boolean fromNotification = intent.getBooleanExtra(EXTRA_FROM_NOTIFICATION, false);
    if (fromNotification && mAccount.goToUnreadMessageSearch()) {
      MessagingController.getInstance(getApplication()).notifyAccountCancel(this, mAccount);
      openUnreadSearch(this, mAccount);
      finish();
    } else if (initialFolder != null && !K9.FOLDER_NONE.equals(initialFolder)) {
      onOpenFolder(initialFolder);
      finish();
    } else if (intent.getBooleanExtra(EXTRA_FROM_SHORTCUT, false)
        && !K9.FOLDER_NONE.equals(mAccount.getAutoExpandFolderName())) {
      onOpenFolder(mAccount.getAutoExpandFolderName());
      finish();
    } else {

      initializeActivityView();
    }
  }
Exemple #2
0
  public void onRefile(String dstFolder) {
    if (!mController.isMoveCapable(mAccount)) {
      return;
    }
    if (!mController.isMoveCapable(mMessage)) {
      Toast toast =
          Toast.makeText(
              getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
      toast.show();
      return;
    }

    if (K9.FOLDER_NONE.equalsIgnoreCase(dstFolder)) {
      return;
    }

    if (mAccount.getSpamFolderName().equals(dstFolder) && K9.confirmSpam()) {
      mDstFolder = dstFolder;
      showDialog(R.id.dialog_confirm_spam);
    } else {
      refileMessage(dstFolder);
    }
  }
Exemple #3
0
  public static void updateWidget(
      Context context, AppWidgetManager appWidgetManager, int appWidgetId, String accountUuid) {

    RemoteViews remoteViews =
        new RemoteViews(context.getPackageName(), R.layout.unread_widget_layout);

    int unreadCount = 0;
    String accountName = context.getString(R.string.app_name);
    Intent clickIntent = null;
    try {
      BaseAccount account = null;
      AccountStats stats = null;

      SearchAccount searchAccount = null;
      if (SearchAccount.UNIFIED_INBOX.equals(accountUuid)) {
        searchAccount = SearchAccount.createUnifiedInboxAccount(context);
      } else if (SearchAccount.ALL_MESSAGES.equals(accountUuid)) {
        searchAccount = SearchAccount.createAllMessagesAccount(context);
      }

      if (searchAccount != null) {
        account = searchAccount;
        MessagingController controller = MessagingController.getInstance(K9.app);
        stats = controller.getSearchAccountStatsSynchronous(searchAccount, null);
        clickIntent =
            MessageList.intentDisplaySearch(
                context, searchAccount.getRelatedSearch(), false, true, true);
      } else {
        Account realAccount = Preferences.getPreferences(context).getAccount(accountUuid);
        if (realAccount != null) {
          account = realAccount;
          stats = realAccount.getStats(context);

          if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
            clickIntent = FolderList.actionHandleAccountIntent(context, realAccount, null, false);
          } else {
            LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
            search.addAllowedFolder(realAccount.getAutoExpandFolderName());
            search.addAccountUuid(account.getUuid());
            clickIntent = MessageList.intentDisplaySearch(context, search, false, true, true);
          }
          clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        }
      }

      if (account != null) {
        accountName = account.getDescription();
      }

      if (stats != null) {
        unreadCount = stats.unreadMessageCount;
      }
    } catch (Exception e) {
      if (K9.DEBUG) {
        Log.e(K9.LOG_TAG, "Error getting widget configuration", e);
      }
    }

    if (unreadCount <= 0) {
      // Hide TextView for unread count if there are no unread messages.
      remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
    } else {
      remoteViews.setViewVisibility(R.id.unread_count, View.VISIBLE);

      String displayCount =
          (unreadCount <= MAX_COUNT)
              ? String.valueOf(unreadCount)
              : String.valueOf(MAX_COUNT) + "+";
      remoteViews.setTextViewText(R.id.unread_count, displayCount);
    }

    remoteViews.setTextViewText(R.id.account_name, accountName);

    if (clickIntent == null) {
      // If the widget configuration couldn't be loaded we open the configuration
      // activity when the user clicks the widget.
      clickIntent = new Intent(context, UnreadWidgetConfiguration.class);
      clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    }
    clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);

    remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
  }