Esempio n. 1
0
 private void refreshFolder(Account account, String folderName) {
   // There has to be a cheaper way to get at the localFolder object than this
   Folder localFolder = null;
   try {
     if (account != null && folderName != null) {
       if (!account.isAvailable(FolderList.this)) {
         Log.i(K9.LOG_TAG, "not refreshing folder of unavailable account");
         return;
       }
       localFolder = account.getLocalStore().getFolder(folderName);
       int unreadMessageCount = localFolder.getUnreadMessageCount();
       FolderInfoHolder folderHolder = getFolder(folderName);
       if (folderHolder != null) {
         folderHolder.populate(context, localFolder, mAccount, unreadMessageCount);
         mHandler.dataChanged();
       }
     }
   } catch (Exception e) {
     Log.e(K9.LOG_TAG, "Exception while populating folder", e);
   } finally {
     if (localFolder != null) {
       localFolder.close();
     }
   }
 }
  void acctSelected(ServiceAcctInfo info) {
    Account acct = new Account();
    acct.name = info.desc;
    acct.service = info;

    DialogInterface.OnClickListener emptyClickListener =
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {}
        };

    AcctTables db = new AcctTables(this);
    try {
      db.openWritable();

      try {
        db.pushAccount(acct);
      } catch (SQLiteException e) {
        AlertDialog dlg =
            Utilities.buildAlert(
                this, e, "Unable to add account", "Internal Error", emptyClickListener);
        dlg.show();
        return;
      }
    } finally {
      db.close();
    }

    Intent i = getIntent();
    i.putExtra("acct_id", acct.ID);
    setResult(RESULT_OK, i);
    finish();
  }
Esempio n. 3
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();
    }
  }
  /**
   * Method fired when "add" button is clicked.
   *
   * @param v add button's <tt>View</tt>
   */
  public void onAddClicked(View v) {
    Spinner accountsSpiner = (Spinner) findViewById(R.id.selectAccountSpinner);

    Account selectedAcc = (Account) accountsSpiner.getSelectedItem();
    if (selectedAcc == null) {
      logger.error("No account selected");
      return;
    }

    ProtocolProviderService pps = selectedAcc.getProtocolProvider();
    if (pps == null) {
      logger.error("No provider registered for account " + selectedAcc.getAccountName());
      return;
    }

    View content = findViewById(android.R.id.content);
    String contactAddress = ViewUtil.getTextViewValue(content, R.id.editContactName);

    String displayName = ViewUtil.getTextViewValue(content, R.id.editDisplayName);
    if (displayName != null && displayName.length() > 0) {
      addRenameListener(pps, null, contactAddress, displayName);
    }

    Spinner groupSpinner = (Spinner) findViewById(R.id.selectGroupSpinner);
    ContactListUtils.addContact(
        pps, (MetaContactGroup) groupSpinner.getSelectedItem(), contactAddress);
    finish();
  }
Esempio n. 5
0
 private void setDisplayMode(FolderMode newMode) {
   mAccount.setFolderDisplayMode(newMode);
   mAccount.save(Preferences.getPreferences(this));
   if (mAccount.getFolderPushMode() != FolderMode.NONE) {
     MailService.actionRestartPushers(this, null);
   }
   onRefresh(false);
 }
Esempio n. 6
0
 @Override
 public void sendPendingMessagesFailed(Account account) {
   super.sendPendingMessagesFailed(account);
   if (account.equals(mAccount)) {
     refreshFolder(account, mAccount.getOutboxFolderName());
   }
 }
Esempio n. 7
0
 @Override
 public void folderStatusChanged(
     Account account, String folderName, int unreadMessageCount) {
   if (account.equals(mAccount)) {
     refreshFolder(account, folderName);
   }
 }
Esempio n. 8
0
 @Override
 public void listFoldersStarted(Account account) {
   if (account.equals(mAccount)) {
     mHandler.progress(true);
   }
   super.listFoldersStarted(account);
 }
Esempio n. 9
0
  private void initializeActivityView() {
    mAdapter = new FolderListAdapter();
    restorePreviousData();

    setListAdapter(mAdapter);

    setTitle(mAccount.getDescription());
  }
Esempio n. 10
0
          @Override
          public void sendPendingMessagesStarted(Account account) {
            super.sendPendingMessagesStarted(account);

            if (account.equals(mAccount)) {
              mHandler.dataChanged();
            }
          }
Esempio n. 11
0
  public static Intent actionHandleNotification(
      Context context, Account account, String initialFolder) {
    Intent intent =
        new Intent(
            Intent.ACTION_VIEW,
            Uri.parse("email://accounts/" + account.getAccountNumber()),
            context,
            FolderList.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
    intent.putExtra(EXTRA_FROM_NOTIFICATION, true);

    if (initialFolder != null) {
      intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
    }
    return intent;
  }
Esempio n. 12
0
          @Override
          public void synchronizeMailboxStarted(Account account, String folder) {
            super.synchronizeMailboxStarted(account, folder);
            if (account.equals(mAccount)) {

              mHandler.progress(true);
              mHandler.folderLoading(folder, true);
              mHandler.dataChanged();
            }
          }
Esempio n. 13
0
          @Override
          public void listFoldersFinished(Account account) {
            if (account.equals(mAccount)) {

              mHandler.progress(false);
              MessagingController.getInstance(getApplication()).refreshListener(mAdapter.mListener);
              mHandler.dataChanged();
            }
            super.listFoldersFinished(account);
          }
Esempio n. 14
0
 private void onClearFolder(Account account, String folderName) {
   // There has to be a cheaper way to get at the localFolder object than this
   LocalFolder localFolder = null;
   try {
     if (account == null || folderName == null || !account.isAvailable(FolderList.this)) {
       Log.i(K9.LOG_TAG, "not clear folder of unavailable account");
       return;
     }
     localFolder = account.getLocalStore().getFolder(folderName);
     localFolder.open(Folder.OpenMode.READ_WRITE);
     localFolder.clearAllMessages();
   } catch (Exception e) {
     Log.e(K9.LOG_TAG, "Exception while clearing folder", e);
   } finally {
     if (localFolder != null) {
       localFolder.close();
     }
   }
 }
Esempio n. 15
0
          @Override
          public void listFoldersFailed(Account account, String message) {
            if (account.equals(mAccount)) {

              mHandler.progress(false);

              if (Config.LOGV) {
                Log.v(K9.LOG_TAG, "listFoldersFailed " + message);
              }
            }
            super.listFoldersFailed(account, message);
          }
Esempio n. 16
0
          @Override
          public void synchronizeMailboxFinished(
              Account account, String folder, int totalMessagesInMailbox, int numNewMessages) {
            super.synchronizeMailboxFinished(
                account, folder, totalMessagesInMailbox, numNewMessages);
            if (account.equals(mAccount)) {
              mHandler.progress(false);
              mHandler.folderLoading(folder, false);

              refreshFolder(account, folder);
            }
          }
Esempio n. 17
0
          @Override
          public void setPushActive(Account account, String folderName, boolean enabled) {
            if (!account.equals(mAccount)) {
              return;
            }
            FolderInfoHolder holder = getFolder(folderName);

            if (holder != null) {
              holder.pushActive = enabled;

              mHandler.dataChanged();
            }
          }
Esempio n. 18
0
  public static Intent actionHandleAccountIntent(
      Context context, Account account, String initialFolder, boolean fromShortcut) {
    Intent intent = new Intent(context, FolderList.class);
    intent.putExtra(EXTRA_ACCOUNT, account.getUuid());

    if (initialFolder != null) {
      intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
    }

    if (fromShortcut) {
      intent.putExtra(EXTRA_FROM_SHORTCUT, true);
    }

    return intent;
  }
Esempio n. 19
0
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    getMenuInflater().inflate(R.menu.folder_context, menu);

    FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getItem(info.position);

    menu.setHeaderTitle(folder.displayName);

    if (!folder.name.equals(mAccount.getTrashFolderName()))
      menu.findItem(R.id.empty_trash).setVisible(false);

    if (folder.name.equals(mAccount.getOutboxFolderName())) {
      menu.findItem(R.id.check_mail).setVisible(false);
    } else {
      menu.findItem(R.id.send_messages).setVisible(false);
    }
    if (K9.ERROR_FOLDER_NAME.equals(folder.name)) {
      menu.findItem(R.id.expunge).setVisible(false);
    }

    menu.setHeaderTitle(folder.displayName);
  }
Esempio n. 20
0
  /**
   * On resume we refresh the folder list (in the background) and we refresh the messages for any
   * folder that is currently open. This guarantees that things like unread message count and read
   * status are updated.
   */
  @Override
  public void onResume() {
    super.onResume();

    if (!mAccount.isAvailable(this)) {
      Log.i(K9.LOG_TAG, "account unavaliabale, not showing folder-list but account-list");
      startActivity(new Intent(this, Accounts.class));
      finish();
      return;
    }
    if (mAdapter == null) initializeActivityView();

    MessagingController.getInstance(getApplication()).addListener(mAdapter.mListener);
    // mAccount.refresh(Preferences.getPreferences(this));
    MessagingController.getInstance(getApplication())
        .getAccountStats(this, mAccount, mAdapter.mListener);

    onRefresh(!REFRESH_REMOTE);

    MessagingController.getInstance(getApplication()).notifyAccountCancel(this, mAccount);
  }
Esempio n. 21
0
          @Override
          public void synchronizeMailboxFailed(Account account, String folder, String message) {
            super.synchronizeMailboxFailed(account, folder, message);
            if (!account.equals(mAccount)) {
              return;
            }

            mHandler.progress(false);

            mHandler.folderLoading(folder, false);

            //   String mess = truncateStatus(message);

            //   mHandler.folderStatus(folder, mess);
            FolderInfoHolder holder = getFolder(folder);

            if (holder != null) {
              holder.lastChecked = 0;
            }

            mHandler.dataChanged();
          }
Esempio n. 22
0
  private void openUnreadSearch(Context context, final Account account) {
    String description =
        getString(
            R.string.search_title, mAccount.getDescription(), getString(R.string.unread_modifier));

    SearchSpecification searchSpec =
        new SearchSpecification() {
          // interface has no override            @Override
          public String[] getAccountUuids() {
            return new String[] {account.getUuid()};
          }

          // interface has no override            @Override
          public Flag[] getForbiddenFlags() {
            return UNREAD_FLAG_ARRAY;
          }

          // interface has no override            @Override
          public String getQuery() {
            return "";
          }

          @Override
          public Flag[] getRequiredFlags() {
            return null;
          }

          @Override
          public boolean isIntegrate() {
            return false;
          }

          @Override
          public String[] getFolderNames() {
            return null;
          }
        };
    MessageList.actionHandle(context, description, searchSpec);
  }
Esempio n. 23
0
          @Override
          public void listFolders(Account account, Folder[] folders) {
            if (account.equals(mAccount)) {

              List<FolderInfoHolder> newFolders = new LinkedList<FolderInfoHolder>();
              List<FolderInfoHolder> topFolders = new LinkedList<FolderInfoHolder>();

              Account.FolderMode aMode = account.getFolderDisplayMode();
              Preferences prefs =
                  Preferences.getPreferences(getApplication().getApplicationContext());
              for (Folder folder : folders) {
                try {
                  folder.refresh(prefs);

                  Folder.FolderClass fMode = folder.getDisplayClass();

                  if ((aMode == Account.FolderMode.FIRST_CLASS
                          && fMode != Folder.FolderClass.FIRST_CLASS)
                      || (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS
                          && fMode != Folder.FolderClass.FIRST_CLASS
                          && fMode != Folder.FolderClass.SECOND_CLASS)
                      || (aMode == Account.FolderMode.NOT_SECOND_CLASS
                          && fMode == Folder.FolderClass.SECOND_CLASS)) {
                    continue;
                  }
                } catch (MessagingException me) {
                  Log.e(
                      K9.LOG_TAG,
                      "Couldn't get prefs to check for displayability of folder "
                          + folder.getName(),
                      me);
                }

                FolderInfoHolder holder = null;

                int folderIndex = getFolderIndex(folder.getName());
                if (folderIndex >= 0) {
                  holder = (FolderInfoHolder) getItem(folderIndex);
                }
                int unreadMessageCount = 0;
                try {
                  unreadMessageCount = folder.getUnreadMessageCount();
                } catch (Exception e) {
                  Log.e(
                      K9.LOG_TAG,
                      "Unable to get unreadMessageCount for "
                          + mAccount.getDescription()
                          + ":"
                          + folder.getName());
                }

                if (holder == null) {
                  holder = new FolderInfoHolder(context, folder, mAccount, unreadMessageCount);
                } else {
                  holder.populate(context, folder, mAccount, unreadMessageCount);
                }
                if (folder.isInTopGroup()) {
                  topFolders.add(holder);
                } else {
                  newFolders.add(holder);
                }
              }
              Collections.sort(newFolders);
              Collections.sort(topFolders);
              topFolders.addAll(newFolders);
              mHandler.newFolders(topFolders);
            }
            super.listFolders(account, folders);
          }
Esempio n. 24
0
 @Override
 public void accountSizeChanged(Account account, long oldSize, long newSize) {
   if (account.equals(mAccount)) {
     mHandler.accountSizeChanged(oldSize, newSize);
   }
 }
Esempio n. 25
0
 @Override
 public void emptyTrashCompleted(Account account) {
   if (account.equals(mAccount)) {
     refreshFolder(account, mAccount.getTrashFolderName());
   }
 }