Exemplo n.º 1
0
  private void invalidateAccountViews(View itemView, int currentIndex, int selectedIndex) {
    if (itemView == null) {
      for (int i = 0; i < mAccountsFrame.getChildCount() - 1; i++) {
        invalidateAccountViews(mAccountsFrame.getChildAt(i), i, selectedIndex);
      }
    } else {
      TextView title = (TextView) itemView.findViewById(R.id.title);
      ImageView icon = (ImageView) itemView.findViewById(R.id.icon);

      Account acc = mAccounts.get(currentIndex);
      switch (acc.type()) {
        default:
          icon.setImageResource(R.drawable.ic_folder);
          break;
        case Account.TYPE_GOOGLE_DRIVE:
          icon.setImageResource(R.drawable.ic_drive);
          break;
        case Account.TYPE_DROPBOX:
          icon.setImageResource(R.drawable.ic_dropbox);
          break;
      }

      boolean activated = currentIndex == selectedIndex;
      itemView.setActivated(activated);
      icon.getDrawable()
          .mutate()
          .setColorFilter(activated ? mSelectedColor : mRegularColor, PorterDuff.Mode.SRC_ATOP);
      itemView.setTag(currentIndex);
      title.setText(acc.name());
      title.setTextColor(activated ? mSelectedColor : mRegularColor);
    }
  }
Exemplo n.º 2
0
  public void reloadAccounts() {
    if (getActivity() == null) return;
    mAccounts = new ArrayList<>();
    View addAccountFrame = mAccountsFrame.findViewById(R.id.addAccountFrame);
    mAccountsFrame.removeAllViews();
    mAccountsFrame.addView(addAccountFrame);
    int mCurrent = Account.getActive(getActivity());

    if (mCurrent == -1) {
      Account acc = AccountProvider.add(getActivity(), null, Account.TYPE_LOCAL);
      mAccounts.add(acc);
      Account.setActive(getActivity(), acc);
      mCurrent = acc.id();
    }

    final int fCurrent = mCurrent;
    Account.getAll(
        getActivity(),
        new Account.AccountsCallback() {
          @Override
          public void onAccounts(Account[] accounts) {
            if (accounts == null || !isAdded()) return;
            for (int i = 0; i < accounts.length; i++) {
              Account a = accounts[i];
              mAccounts.add(a);
              boolean selected = a.id() == fCurrent;
              mAccountsFrame.addView(getAccountView(i, selected ? i : -1, mAccountsFrame), i);
              if (selected) getAlbums(a);
            }
            mAccountsFrame.requestLayout();
            mAccountsFrame.invalidate();
          }
        });
  }
Exemplo n.º 3
0
  public void getAlbums(Account account) {
    if (account != null) mCurrentAccount = account;
    mAdapter.clear();
    mAdapter.add(new NavDrawerAdapter.Entry(AlbumEntry.ALBUM_OVERVIEW, false, false));
    // TODO clear activity back stack to remove back stack of old account?
    mCurrentAccount.getAlbums(
        MediaAdapter.SortMode.NAME_DESC,
        MediaAdapter.FileFilterMode.ALL,
        new Account.AlbumCallback() {
          @Override
          public void onAlbums(AlbumEntry[] albums) {
            for (AlbumEntry a : albums)
              mAdapter.add(new NavDrawerAdapter.Entry(a.data(), false, false));
            if (mCurrentAccount.hasIncludedFolders()) {
              getIncludedFolders(albums);
            } else mAdapter.notifyDataSetChangedAndSort();
          }

          @Override
          public void onError(Exception e) {
            if (getActivity() == null) return;
            Utils.showErrorDialog(getActivity(), e);
          }
        });
  }
Exemplo n.º 4
0
  private void getIncludedFolders(AlbumEntry[] preAlbums) {
    mCurrentAccount.getIncludedFolders(
        preAlbums,
        new Account.AlbumCallback() {
          @Override
          public void onAlbums(AlbumEntry[] albums) {
            for (AlbumEntry a : albums)
              mAdapter.update(new NavDrawerAdapter.Entry(a.data(), false, true));
            mAdapter.add(new NavDrawerAdapter.Entry("", true, false));
            mAdapter.notifyDataSetChangedAndSort();
          }

          @Override
          public void onError(Exception e) {
            if (getActivity() == null) return;
            Utils.showErrorDialog(getActivity(), e);
          }
        });
  }