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);
}
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();
}
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();
}
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);
}
}
Aggregations