Exemplo n.º 1
0
  @Override
  public void openMessage(MessageReference messageReference) {
    Preferences prefs = Preferences.getPreferences(getApplicationContext());
    Account account = prefs.getAccount(messageReference.accountUuid);
    String folderName = messageReference.folderName;

    if (folderName.equals(account.getDraftsFolderName())) {
      MessageCompose.actionEditDraft(this, messageReference);
    } else {
      mMessageViewContainer.removeView(mMessageViewPlaceHolder);

      MessageViewFragment fragment = MessageViewFragment.newInstance(messageReference);
      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      ft.replace(R.id.message_view_container, fragment);
      mMessageViewFragment = fragment;
      ft.commit();

      if (mDisplayMode == DisplayMode.SPLIT_VIEW) {
        mMessageListFragment.setActiveMessage(messageReference);
      } else {
        showMessageView();
      }
    }
    invalidateOptionsMenu();
  }
Exemplo n.º 2
0
 private void displayViews() {
   switch (mDisplayMode) {
     case MESSAGE_LIST:
       {
         showMessageList();
         break;
       }
     case MESSAGE_VIEW:
       {
         showMessageView();
         break;
       }
     case SPLIT_VIEW:
       {
         mMessageListWasDisplayed = true;
         if (mMessageViewFragment == null) {
           showMessageViewPlaceHolder();
         } else {
           MessageReference activeMessage = mMessageViewFragment.getMessageReference();
           if (activeMessage != null) {
             mMessageListFragment.setActiveMessage(activeMessage);
           }
         }
         break;
       }
   }
 }
Exemplo n.º 3
0
 private boolean showPreviousMessage() {
   MessageReference ref = mMessageViewFragment.getMessageReference();
   if (ref != null) {
     if (mMessageListFragment.openPrevious(ref)) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 4
0
  private void showDefaultTitleView() {
    mActionBarMessageView.setVisibility(View.GONE);
    mActionBarMessageList.setVisibility(View.VISIBLE);

    if (mMessageListFragment != null) {
      mMessageListFragment.updateTitle();
    }

    mActionBarSubject.setMessageHeader(null);
  }
Exemplo n.º 5
0
  private void showMessageList() {
    mMessageListWasDisplayed = true;
    mDisplayMode = DisplayMode.MESSAGE_LIST;
    mViewSwitcher.showFirstView();

    mMessageListFragment.setActiveMessage(null);

    showDefaultTitleView();
    configureMenu(mMenu);
  }
Exemplo n.º 6
0
  private void showMessageViewPlaceHolder() {
    removeMessageViewFragment();

    // Add placeholder view if necessary
    if (mMessageViewPlaceHolder.getParent() == null) {
      mMessageViewContainer.addView(mMessageViewPlaceHolder);
    }

    mMessageListFragment.setActiveMessage(null);
  }
Exemplo n.º 7
0
  @Override
  public void showMoreFromSameSender(String senderAddress) {
    LocalSearch tmpSearch = new LocalSearch("From " + senderAddress);
    tmpSearch.addAccountUuids(mSearch.getAccountUuids());
    tmpSearch.and(Searchfield.SENDER, senderAddress, Attribute.CONTAINS);

    MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false, false);

    addMessageListFragment(fragment, true);
  }
Exemplo n.º 8
0
  @Override
  public void showThread(Account account, String folderName, long threadRootId) {
    showMessageViewPlaceHolder();

    LocalSearch tmpSearch = new LocalSearch();
    tmpSearch.addAccountUuid(account.getUuid());
    tmpSearch.and(Searchfield.THREAD_ID, String.valueOf(threadRootId), Attribute.EQUALS);

    MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, true, false);
    addMessageListFragment(fragment, true);
  }
Exemplo n.º 9
0
 @Override
 public void goBack() {
   FragmentManager fragmentManager = getSupportFragmentManager();
   if (mDisplayMode == DisplayMode.MESSAGE_VIEW) {
     showMessageList();
   } else if (fragmentManager.getBackStackEntryCount() > 0) {
     fragmentManager.popBackStack();
   } else if (mMessageListFragment.isManualSearch()) {
     finish();
   } else if (!mSingleFolderMode) {
     onAccounts();
   } else {
     onShowFolderList();
   }
 }
Exemplo n.º 10
0
  /**
   * Create fragment instances if necessary.
   *
   * @see #findFragments()
   */
  private void initializeFragments() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.addOnBackStackChangedListener(this);

    boolean hasMessageListFragment = (mMessageListFragment != null);

    if (!hasMessageListFragment) {
      FragmentTransaction ft = fragmentManager.beginTransaction();
      mMessageListFragment =
          MessageListFragment.newInstance(
              mSearch, false, (K9.isThreadedViewEnabled() && !mNoThreading));
      ft.add(R.id.message_list_container, mMessageListFragment);
      ft.commit();
    }

    // Check if the fragment wasn't restarted and has a MessageReference in the arguments. If
    // so, open the referenced message.
    if (!hasMessageListFragment && mMessageViewFragment == null && mMessageReference != null) {
      openMessage(mMessageReference);
    }
  }
Exemplo n.º 11
0
  /**
   * Hide menu items not appropriate for the current context.
   *
   * <p><strong>Note:</strong> Please adjust the comments in {@code
   * res/menu/message_list_option.xml} if you change the visibility of a menu item in this method.
   *
   * @param menu The {@link Menu} instance that should be modified. May be {@code null}; in that
   *     case the method does nothing and immediately returns.
   */
  private void configureMenu(Menu menu) {
    if (menu == null) {
      return;
    }

    // Set visibility of account/folder settings menu items
    if (mMessageListFragment == null) {
      menu.findItem(R.id.account_settings).setVisible(false);
      menu.findItem(R.id.folder_settings).setVisible(false);
    } else {
      menu.findItem(R.id.account_settings).setVisible(mMessageListFragment.isSingleAccountMode());
      menu.findItem(R.id.folder_settings).setVisible(mMessageListFragment.isSingleFolderMode());
    }

    /*
     * Set visibility of menu items related to the message view
     */

    if (mDisplayMode == DisplayMode.MESSAGE_LIST
        || mMessageViewFragment == null
        || !mMessageViewFragment.isInitialized()) {
      menu.findItem(R.id.next_message).setVisible(false);
      menu.findItem(R.id.previous_message).setVisible(false);
      menu.findItem(R.id.delete).setVisible(false);
      menu.findItem(R.id.single_message_options).setVisible(false);
      menu.findItem(R.id.refile).setVisible(false);
      menu.findItem(R.id.toggle_unread).setVisible(false);
      menu.findItem(R.id.select_text).setVisible(false);
      menu.findItem(R.id.toggle_message_view_theme).setVisible(false);
      menu.findItem(R.id.show_headers).setVisible(false);
      menu.findItem(R.id.hide_headers).setVisible(false);
    } else {
      // hide prev/next buttons in split mode
      if (mDisplayMode != DisplayMode.MESSAGE_VIEW) {
        menu.findItem(R.id.next_message).setVisible(false);
        menu.findItem(R.id.previous_message).setVisible(false);
      } else {
        MessageReference ref = mMessageViewFragment.getMessageReference();
        boolean initialized =
            (mMessageListFragment != null && mMessageListFragment.isLoadFinished());
        boolean canDoPrev = (initialized && !mMessageListFragment.isFirst(ref));
        boolean canDoNext = (initialized && !mMessageListFragment.isLast(ref));

        MenuItem prev = menu.findItem(R.id.previous_message);
        prev.setEnabled(canDoPrev);
        prev.getIcon().setAlpha(canDoPrev ? 255 : 127);

        MenuItem next = menu.findItem(R.id.next_message);
        next.setEnabled(canDoNext);
        next.getIcon().setAlpha(canDoNext ? 255 : 127);
      }

      MenuItem toggleTheme = menu.findItem(R.id.toggle_message_view_theme);
      if (K9.useFixedMessageViewTheme()) {
        toggleTheme.setVisible(false);
      } else {
        // Set title of menu item to switch to dark/light theme
        if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
          toggleTheme.setTitle(R.string.message_view_theme_action_light);
        } else {
          toggleTheme.setTitle(R.string.message_view_theme_action_dark);
        }
        toggleTheme.setVisible(true);
      }

      // Set title of menu item to toggle the read state of the currently displayed message
      if (mMessageViewFragment.isMessageRead()) {
        menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_unread_action);
      } else {
        menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_read_action);
      }

      menu.findItem(R.id.copy).setVisible(mMessageViewFragment.isCopyCapable());

      // Jellybean has built-in long press selection support
      menu.findItem(R.id.select_text).setVisible(Build.VERSION.SDK_INT < 16);

      if (mMessageViewFragment.isMoveCapable()) {
        menu.findItem(R.id.move).setVisible(true);
        menu.findItem(R.id.archive).setVisible(mMessageViewFragment.canMessageBeArchived());
        menu.findItem(R.id.spam).setVisible(mMessageViewFragment.canMessageBeMovedToSpam());
      } else {
        menu.findItem(R.id.move).setVisible(false);
        menu.findItem(R.id.archive).setVisible(false);
        menu.findItem(R.id.spam).setVisible(false);
      }

      if (mMessageViewFragment.allHeadersVisible()) {
        menu.findItem(R.id.show_headers).setVisible(false);
      } else {
        menu.findItem(R.id.hide_headers).setVisible(false);
      }
    }

    /*
     * Set visibility of menu items related to the message list
     */

    // Hide both search menu items by default and enable one when appropriate
    menu.findItem(R.id.search).setVisible(false);
    menu.findItem(R.id.search_remote).setVisible(false);

    if (mDisplayMode == DisplayMode.MESSAGE_VIEW
        || mMessageListFragment == null
        || !mMessageListFragment.isInitialized()) {
      menu.findItem(R.id.check_mail).setVisible(false);
      menu.findItem(R.id.set_sort).setVisible(false);
      menu.findItem(R.id.select_all).setVisible(false);
      menu.findItem(R.id.send_messages).setVisible(false);
      menu.findItem(R.id.expunge).setVisible(false);
    } else {
      menu.findItem(R.id.set_sort).setVisible(true);
      menu.findItem(R.id.select_all).setVisible(true);

      if (!mMessageListFragment.isSingleAccountMode()) {
        menu.findItem(R.id.expunge).setVisible(false);
        menu.findItem(R.id.check_mail).setVisible(false);
        menu.findItem(R.id.send_messages).setVisible(false);
      } else {
        menu.findItem(R.id.send_messages).setVisible(mMessageListFragment.isOutbox());

        if (mMessageListFragment.isRemoteFolder()) {
          menu.findItem(R.id.check_mail).setVisible(true);
          menu.findItem(R.id.expunge).setVisible(mMessageListFragment.isAccountExpungeCapable());
        } else {
          menu.findItem(R.id.check_mail).setVisible(false);
          menu.findItem(R.id.expunge).setVisible(false);
        }
      }

      // If this is an explicit local search, show the option to search on the server
      if (!mMessageListFragment.isRemoteSearch() && mMessageListFragment.isRemoteSearchAllowed()) {
        menu.findItem(R.id.search_remote).setVisible(true);
      } else if (!mMessageListFragment.isManualSearch()) {
        menu.findItem(R.id.search).setVisible(true);
      }
    }
  }
Exemplo n.º 12
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
      case android.R.id.home:
        {
          goBack();
          return true;
        }
      case R.id.compose:
        {
          mMessageListFragment.onCompose();
          return true;
        }
      case R.id.toggle_message_view_theme:
        {
          onToggleTheme();
          return true;
        }
        // MessageList
      case R.id.check_mail:
        {
          mMessageListFragment.checkMail();
          return true;
        }
      case R.id.set_sort_date:
        {
          mMessageListFragment.changeSort(SortType.SORT_DATE);
          return true;
        }
      case R.id.set_sort_arrival:
        {
          mMessageListFragment.changeSort(SortType.SORT_ARRIVAL);
          return true;
        }
      case R.id.set_sort_subject:
        {
          mMessageListFragment.changeSort(SortType.SORT_SUBJECT);
          return true;
        }
        //            case R.id.set_sort_sender: {
        //                mMessageListFragment.changeSort(SortType.SORT_SENDER);
        //                return true;
        //            }
      case R.id.set_sort_flag:
        {
          mMessageListFragment.changeSort(SortType.SORT_FLAGGED);
          return true;
        }
      case R.id.set_sort_unread:
        {
          mMessageListFragment.changeSort(SortType.SORT_UNREAD);
          return true;
        }
      case R.id.set_sort_attach:
        {
          mMessageListFragment.changeSort(SortType.SORT_ATTACHMENT);
          return true;
        }
      case R.id.select_all:
        {
          mMessageListFragment.selectAll();
          return true;
        }
      case R.id.app_settings:
        {
          onEditPrefs();
          return true;
        }
      case R.id.account_settings:
        {
          onEditAccount();
          return true;
        }
      case R.id.search:
        {
          mMessageListFragment.onSearchRequested();
          return true;
        }
      case R.id.search_remote:
        {
          mMessageListFragment.onRemoteSearch();
          return true;
        }
        // MessageView
      case R.id.next_message:
        {
          showNextMessage();
          return true;
        }
      case R.id.previous_message:
        {
          showPreviousMessage();
          return true;
        }
      case R.id.delete:
        {
          mMessageViewFragment.onDelete();
          return true;
        }
      case R.id.reply:
        {
          mMessageViewFragment.onReply();
          return true;
        }
      case R.id.reply_all:
        {
          mMessageViewFragment.onReplyAll();
          return true;
        }
      case R.id.forward:
        {
          mMessageViewFragment.onForward();
          return true;
        }
      case R.id.share:
        {
          mMessageViewFragment.onSendAlternate();
          return true;
        }
      case R.id.toggle_unread:
        {
          mMessageViewFragment.onToggleRead();
          return true;
        }
      case R.id.archive:
        {
          mMessageViewFragment.onArchive();
          return true;
        }
      case R.id.spam:
        {
          mMessageViewFragment.onSpam();
          return true;
        }
      case R.id.move:
        {
          mMessageViewFragment.onMove();
          return true;
        }
      case R.id.copy:
        {
          mMessageViewFragment.onCopy();
          return true;
        }
      case R.id.select_text:
        {
          mMessageViewFragment.onSelectText();
          return true;
        }
      case R.id.show_headers:
      case R.id.hide_headers:
        {
          mMessageViewFragment.onToggleAllHeadersView();
          updateMenu();
          return true;
        }
    }

    if (!mSingleFolderMode) {
      // None of the options after this point are "safe" for search results
      // TODO: This is not true for "unread" and "starred" searches in regular folders
      return false;
    }

    switch (itemId) {
      case R.id.send_messages:
        {
          mMessageListFragment.onSendPendingMessages();
          return true;
        }
      case R.id.folder_settings:
        {
          if (mFolderName != null) {
            FolderSettings.actionSettings(this, mAccount, mFolderName);
          }
          return true;
        }
      case R.id.expunge:
        {
          mMessageListFragment.onExpunge();
          return true;
        }
      default:
        {
          return super.onOptionsItemSelected(item);
        }
    }
  }
Exemplo n.º 13
0
 @Override
 public boolean onSearchRequested() {
   return mMessageListFragment.onSearchRequested();
 }
Exemplo n.º 14
0
  /**
   * Handle hotkeys
   *
   * <p>This method is called by {@link #dispatchKeyEvent(KeyEvent)} before any view had the chance
   * to consume this key event.
   *
   * @param keyCode The value in {@code event.getKeyCode()}.
   * @param event Description of the key event.
   * @return {@code true} if this event was consumed.
   */
  public boolean onCustomKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
      case KeyEvent.KEYCODE_VOLUME_UP:
        {
          if (mMessageViewFragment != null
              && mDisplayMode != DisplayMode.MESSAGE_LIST
              && K9.useVolumeKeysForNavigationEnabled()) {
            showPreviousMessage();
            return true;
          } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW
              && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveUp();
            return true;
          }

          break;
        }
      case KeyEvent.KEYCODE_VOLUME_DOWN:
        {
          if (mMessageViewFragment != null
              && mDisplayMode != DisplayMode.MESSAGE_LIST
              && K9.useVolumeKeysForNavigationEnabled()) {
            showNextMessage();
            return true;
          } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW
              && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveDown();
            return true;
          }

          break;
        }
      case KeyEvent.KEYCODE_C:
        {
          mMessageListFragment.onCompose();
          return true;
        }
      case KeyEvent.KEYCODE_Q:
        {
          onShowFolderList();
          return true;
        }
      case KeyEvent.KEYCODE_O:
        {
          mMessageListFragment.onCycleSort();
          return true;
        }
      case KeyEvent.KEYCODE_I:
        {
          mMessageListFragment.onReverseSort();
          return true;
        }
      case KeyEvent.KEYCODE_DEL:
      case KeyEvent.KEYCODE_D:
        {
          if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onDelete();
          } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onDelete();
          }
          return true;
        }
      case KeyEvent.KEYCODE_S:
        {
          mMessageListFragment.toggleMessageSelect();
          return true;
        }
      case KeyEvent.KEYCODE_G:
        {
          if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleFlagged();
          } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleFlagged();
          }
          return true;
        }
      case KeyEvent.KEYCODE_M:
        {
          if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onMove();
          } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onMove();
          }
          return true;
        }
      case KeyEvent.KEYCODE_V:
        {
          if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onArchive();
          } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onArchive();
          }
          return true;
        }
      case KeyEvent.KEYCODE_Y:
        {
          if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onCopy();
          } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onCopy();
          }
          return true;
        }
      case KeyEvent.KEYCODE_Z:
        {
          if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleRead();
          } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleRead();
          }
          return true;
        }
      case KeyEvent.KEYCODE_F:
        {
          if (mMessageViewFragment != null) {
            mMessageViewFragment.onForward();
          }
          return true;
        }
      case KeyEvent.KEYCODE_A:
        {
          if (mMessageViewFragment != null) {
            mMessageViewFragment.onReplyAll();
          }
          return true;
        }
      case KeyEvent.KEYCODE_R:
        {
          if (mMessageViewFragment != null) {
            mMessageViewFragment.onReply();
          }
          return true;
        }
      case KeyEvent.KEYCODE_J:
      case KeyEvent.KEYCODE_P:
        {
          if (mMessageViewFragment != null) {
            showPreviousMessage();
          }
          return true;
        }
      case KeyEvent.KEYCODE_N:
      case KeyEvent.KEYCODE_K:
        {
          if (mMessageViewFragment != null) {
            showNextMessage();
          }
          return true;
        }
        /* FIXME
        case KeyEvent.KEYCODE_Z: {
            mMessageViewFragment.zoom(event);
            return true;
        }*/
      case KeyEvent.KEYCODE_H:
        {
          Toast toast = Toast.makeText(this, R.string.message_list_help_key, Toast.LENGTH_LONG);
          toast.show();
          return true;
        }
    }

    return false;
  }
Exemplo n.º 15
0
 @Override
 public void onSwipeLeftToRight(MotionEvent e1, MotionEvent e2) {
   if (mMessageListFragment != null && mDisplayMode != DisplayMode.MESSAGE_VIEW) {
     mMessageListFragment.onSwipeLeftToRight(e1, e2);
   }
 }