Search in sources :

Example 1 with DriveListItem

use of org.odk.collect.android.logic.DriveListItem in project collect by opendatakit.

the class GoogleDriveActivity method getFiles.

private void getFiles() {
    StringBuilder messageBuilder = new StringBuilder();
    for (int i = 0; i < toDownload.size(); i++) {
        DriveListItem o = toDownload.get(i);
        messageBuilder.append(o.getName());
        if (i != toDownload.size() - 1) {
            messageBuilder.append(", ");
        }
    }
    alertMsg = getString(R.string.drive_get_file, messageBuilder.toString());
    showDialog(PROGRESS_DIALOG);
    getFileTask = new GetFileTask();
    getFileTask.setGoogleDriveFormDownloadListener(this);
    getFileTask.execute(toDownload);
}
Also used : DriveListItem(org.odk.collect.android.logic.DriveListItem)

Example 2 with DriveListItem

use of org.odk.collect.android.logic.DriveListItem in project collect by opendatakit.

the class GoogleDriveActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.drive_layout);
    super.onCreate(savedInstanceState);
    setProgressBarVisibility(true);
    initToolbar();
    parentId = null;
    alertShowing = false;
    toDownload = new ArrayList<>();
    filteredList = new ArrayList<>();
    driveList = new ArrayList<>();
    if (savedInstanceState != null && savedInstanceState.containsKey(MY_DRIVE_KEY)) {
        // recover state on rotate
        myDrive = savedInstanceState.getBoolean(MY_DRIVE_KEY);
        String[] patharray = savedInstanceState.getStringArray(PATH_KEY);
        currentPath = buildPath(patharray);
        parentId = savedInstanceState.getString(PARENT_KEY);
        alertMsg = savedInstanceState.getString(ALERT_MSG_KEY);
        alertShowing = savedInstanceState.getBoolean(ALERT_SHOWING_KEY);
        ArrayList<DriveListItem> dl = savedInstanceState.getParcelableArrayList(DRIVE_ITEMS_KEY);
        filteredList.addAll(dl);
    } else {
        // new
        myDrive = false;
        if (!isDeviceOnline()) {
            createAlertDialog(getString(R.string.no_connection));
        }
    }
    // restore any task state
    if (getLastCustomNonConfigurationInstance() instanceof RetrieveDriveFileContentsAsyncTask) {
        retrieveDriveFileContentsAsyncTask = (RetrieveDriveFileContentsAsyncTask) getLastNonConfigurationInstance();
        setProgressBarIndeterminateVisibility(true);
    } else {
        getFileTask = (GetFileTask) getLastNonConfigurationInstance();
        if (getFileTask != null) {
            getFileTask.setGoogleDriveFormDownloadListener(this);
        }
    }
    if (getFileTask != null && getFileTask.getStatus() == AsyncTask.Status.FINISHED) {
        try {
            dismissDialog(PROGRESS_DIALOG);
        } catch (Exception e) {
            Timber.i("Exception was thrown while dismissing a dialog.");
        }
    }
    if (alertShowing) {
        try {
            dismissDialog(PROGRESS_DIALOG);
        } catch (Exception e) {
            // don't care...
            Timber.i("Exception was thrown while dismissing a dialog.");
        }
        createAlertDialog(alertMsg);
    }
    rootButton = findViewById(R.id.root_button);
    if (myDrive) {
        rootButton.setText(getString(R.string.go_shared));
    } else {
        rootButton.setText(getString(R.string.go_drive));
    }
    rootButton.setOnClickListener(this);
    backButton = findViewById(R.id.back_button);
    backButton.setEnabled(parentId != null);
    backButton.setOnClickListener(this);
    downloadButton = findViewById(R.id.download_button);
    downloadButton.setOnClickListener(this);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setItemsCanFocus(false);
    sortingOptions = new String[] { getString(R.string.sort_by_name_asc), getString(R.string.sort_by_name_desc) };
    accountsManager = new GoogleAccountsManager(this);
    accountsManager.setListener(this);
    driveHelper = accountsManager.getDriveHelper();
    getResultsFromApi();
}
Also used : DriveListItem(org.odk.collect.android.logic.DriveListItem) GoogleAccountsManager(org.odk.collect.android.utilities.gdrive.GoogleAccountsManager) UserRecoverableAuthIOException(com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException) IOException(java.io.IOException) MultipleFoldersFoundException(org.odk.collect.android.exception.MultipleFoldersFoundException)

Example 3 with DriveListItem

use of org.odk.collect.android.logic.DriveListItem in project collect by opendatakit.

the class GoogleDriveActivity method updateAdapter.

@Override
protected void updateAdapter() {
    CharSequence charSequence = getFilterText();
    filteredList.clear();
    if (charSequence.length() > 0) {
        for (DriveListItem item : driveList) {
            if (item.getName().toLowerCase(Locale.US).contains(charSequence.toString().toLowerCase(Locale.US))) {
                filteredList.add(item);
            }
        }
    } else {
        filteredList.addAll(driveList);
    }
    sortList();
    if (adapter == null) {
        adapter = new FileArrayAdapter(this, filteredList);
        listView.setAdapter(adapter);
    } else {
        adapter.notifyDataSetChanged();
    }
    adapter.notifyDataSetChanged();
    checkPreviouslyCheckedItems();
}
Also used : DriveListItem(org.odk.collect.android.logic.DriveListItem) FileArrayAdapter(org.odk.collect.android.adapters.FileArrayAdapter)

Example 4 with DriveListItem

use of org.odk.collect.android.logic.DriveListItem in project collect by opendatakit.

the class GoogleDriveActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    DriveListItem item = filteredList.get(position);
    if (item != null && item.getType() == DriveListItem.DIR) {
        if (isDeviceOnline()) {
            toDownload.clear();
            driveList.clear();
            clearSearchView();
            listFiles(item.getDriveId());
            folderIdStack.push(item.getDriveId());
            currentPath.push(item.getName());
        } else {
            createAlertDialog(getString(R.string.no_connection));
        }
    } else {
        // file clicked, download the file, mark checkbox.
        CheckBox cb = view.findViewById(R.id.checkbox);
        cb.setChecked(!cb.isChecked());
        if (toDownload.contains(item) && !cb.isChecked()) {
            toDownload.remove(item);
        } else {
            toDownload.add(item);
        }
        downloadButton.setEnabled(toDownload.size() > 0);
    }
}
Also used : DriveListItem(org.odk.collect.android.logic.DriveListItem) CheckBox(android.widget.CheckBox)

Aggregations

DriveListItem (org.odk.collect.android.logic.DriveListItem)4 CheckBox (android.widget.CheckBox)1 UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)1 IOException (java.io.IOException)1 FileArrayAdapter (org.odk.collect.android.adapters.FileArrayAdapter)1 MultipleFoldersFoundException (org.odk.collect.android.exception.MultipleFoldersFoundException)1 GoogleAccountsManager (org.odk.collect.android.utilities.gdrive.GoogleAccountsManager)1