예제 #1
0
 @Override
 public void listFoldersFailed(Account account, String message) {
   if (!account.equals(mAccount)) {
     return;
   }
   mHandler.progress(false);
 }
예제 #2
0
 @Override
 public void listFoldersFinished(Account account) {
   if (!account.equals(mAccount)) {
     return;
   }
   mHandler.progress(false);
 }
예제 #3
0
 @Override
 public void listFoldersStarted(Account account) {
   if (!account.equals(mAccount)) {
     return;
   }
   mHandler.progress(true);
 }
예제 #4
0
        @Override
        public void listFolders(Account account, Folder[] folders) {
          if (!account.equals(mAccount)) {
            return;
          }
          Account.FolderMode aMode = mMode;
          Preferences prefs = Preferences.getPreferences(getApplication().getApplicationContext());
          ArrayList<String> localFolders = new ArrayList<String>();

          for (Folder folder : folders) {
            String name = folder.getName();

            // Inbox needs to be compared case-insensitively
            if (mHideCurrentFolder
                && (name.equals(mFolder)
                    || (mAccount.getInboxFolderName().equalsIgnoreCase(mFolder)
                        && mAccount.getInboxFolderName().equalsIgnoreCase(name)))) {
              continue;
            }
            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);
            }

            localFolders.add(folder.getName());
          }

          if (mShowOptionNone) {
            localFolders.add(K9.FOLDER_NONE);
          }

          Collections.sort(
              localFolders,
              new Comparator<String>() {
                @Override
                public int compare(String aName, String bName) {
                  if (K9.FOLDER_NONE.equalsIgnoreCase(aName)) {
                    return -1;
                  }
                  if (K9.FOLDER_NONE.equalsIgnoreCase(bName)) {
                    return 1;
                  }
                  if (mAccount.getInboxFolderName().equalsIgnoreCase(aName)) {
                    return -1;
                  }
                  if (mAccount.getInboxFolderName().equalsIgnoreCase(bName)) {
                    return 1;
                  }

                  return aName.compareToIgnoreCase(bName);
                }
              });
          int selectedFolder = -1;

          /*
           * We're not allowed to change the adapter from a background thread, so we collect the
           * folder names and update the adapter in the UI thread (see finally block).
           */
          final List<String> folderList = new ArrayList<String>();
          try {
            int position = 0;
            for (String name : localFolders) {
              if (mAccount.getInboxFolderName().equalsIgnoreCase(name)) {
                folderList.add(getString(R.string.special_mailbox_name_inbox));
                mHeldInbox = name;
              } else if (!K9.ERROR_FOLDER_NAME.equals(name)
                  && !account.getOutboxFolderName().equals(name)) {
                folderList.add(name);
              }

              if (mSelectFolder != null) {
                /*
                 * Never select EXTRA_CUR_FOLDER (mFolder) if EXTRA_SEL_FOLDER
                 * (mSelectedFolder) was provided.
                 */

                if (name.equals(mSelectFolder)) {
                  selectedFolder = position;
                }
              } else if (name.equals(mFolder)
                  || (mAccount.getInboxFolderName().equalsIgnoreCase(mFolder)
                      && mAccount.getInboxFolderName().equalsIgnoreCase(name))) {
                selectedFolder = position;
              }
              position++;
            }
          } finally {
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    // Now we're in the UI-thread, we can safely change the contents of the adapter.
                    mAdapter.clear();
                    for (String folderName : folderList) {
                      mAdapter.add(folderName);
                    }

                    mAdapter.notifyDataSetChanged();

                    /*
                     * Only enable the text filter after the list has been
                     * populated to avoid possible race conditions because our
                     * FolderListFilter isn't really thread-safe.
                     */
                    getListView().setTextFilterEnabled(true);
                  }
                });
          }

          if (selectedFolder != -1) {
            mHandler.setSelectedFolder(selectedFolder);
          }
        }