Example #1
0
 public void saveCameraUploadRepoInfo(
     String repoId, String repoName, String dstDir, Account account) {
   editor.putString(SHARED_PREF_CAMERA_UPLOAD_REPO_ID, repoId);
   editor.putString(SHARED_PREF_CAMERA_UPLOAD_REPO_NAME, repoName);
   editor.putString(SHARED_PREF_CAMERA_UPLOAD_ACCOUNT_EMAIL, account.getEmail());
   editor.putString(SHARED_PREF_CAMERA_UPLOAD_ACCOUNT_SERVER, account.getServer());
   editor.putString(SHARED_PREF_CAMERA_UPLOAD_ACCOUNT_TOKEN, account.getToken());
   editor.commit();
 }
  public void onListItemClick(final View v, final int position, final long id) {
    NavContext nav = getNavContext();
    SeafRepo repo = null;

    if (mStep == STEP_CHOOSE_REPO) {
      repo = getReposAdapter().getItem(position);
      // mCurrentFolderText.setText(nav.getRepoName());
    } else if (mStep == STEP_CHOOSE_DIR) {
      repo = getDataManager().getCachedRepoByID(nav.getRepoID());
    }

    if (repo != null) {
      final boolean continueProcess =
          handleEncryptedRepo(
              repo,
              new TaskDialog.TaskDialogListener() {
                @Override
                public void onTaskSuccess() {
                  onListItemClick(v, position, id);
                }
              });

      if (!continueProcess) return;
    }

    switch (mStep) {
      case STEP_CHOOSE_ACCOUNT:
        setAccount(getAccountAdapter().getItem(position));
        mCurrentDir = mAccount.getDisplayName();
        setCurrentDirText(mCurrentDir);
        chooseRepo();
        break;
      case STEP_CHOOSE_REPO:
        if (!isOnlyChooseRepo) {
          nav.setRepoName(repo.name);
          nav.setRepoID(repo.id);
          nav.setDir("/", repo.root);
          chooseDir();
        }
        mCurrentDir = getString(R.string.settings_cuc_remote_lib_repo, repo.name);
        setCurrentDirText(mCurrentDir);
        SeafRepo seafRepo = getReposAdapter().getItem(position);
        onRepoSelected(mAccount, seafRepo);
        break;
      case STEP_CHOOSE_DIR:
        SeafDirent dirent = getDirentsAdapter().getItem(position);
        mCurrentDir += "/" + dirent.name;
        setCurrentDirText(mCurrentDir);

        if (dirent.type == SeafDirent.DirentType.FILE) {
          return;
        }

        nav.setDir(Utils.pathJoin(nav.getDirPath(), dirent.name), dirent.id);
        refreshDir();
        break;
    }
  }
    @Override
    protected List<Avatar> doInBackground(Void... params) {
      // reuse cached avatars
      avatars = avatarManager.getAvatarList();

      // contains accounts who don`t have avatars yet
      List<Account> acts = avatarManager.getAccountsWithoutAvatars();

      // contains new avatars in order to persist them to database
      List<Avatar> newAvatars = new ArrayList<Avatar>(acts.size());

      // load avatars from server
      for (Account account : acts) {
        httpConnection = new SeafConnection(account);

        String avatarRawData = null;
        try {
          avatarRawData = httpConnection.getAvatar(account.getEmail(), avatarSize);
        } catch (SeafException e) {
          e.printStackTrace();
          return avatars;
        }

        Avatar avatar = avatarManager.parseAvatar(avatarRawData);
        if (avatar == null) continue;

        avatar.setSignature(account.getSignature());

        avatars.add(avatar);

        newAvatars.add(avatar);
      }

      // save new added avatars to database
      avatarManager.saveAvatarList(newAvatars);

      return avatars;
    }
  private void chooseRepo(boolean forceRefresh) {
    mStep = STEP_CHOOSE_REPO;
    mUpLayout.setVisibility(View.VISIBLE);
    mCurrentDir = mAccount.getDisplayName();
    setCurrentDirText(mCurrentDir);

    setListAdapter(getReposAdapter());

    getNavContext().setRepoID(null);

    if (!Utils.isNetworkOn() || !forceRefresh) {
      List<SeafRepo> repos = getDataManager().getReposFromCache();
      if (repos != null) {
        updateAdapterWithRepos(repos);
        return;
      }
    }

    mLoadReposTask = new LoadReposTask(getDataManager());
    ConcurrentAsyncTask.execute(mLoadReposTask);
  }