Gracefully error when client is not initialized
This commit is contained in:
parent
10b623545e
commit
a096cac24e
|
@ -129,28 +129,34 @@ public class CloudFragment extends Fragment {
|
||||||
dialog.setMessage("Loading");
|
dialog.setMessage("Loading");
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
new ListFolderTask(DropboxClientFactory.getClient(), new ListFolderTask.Callback() {
|
try {
|
||||||
@Override
|
new ListFolderTask(DropboxClientFactory.getClient(), new ListFolderTask.Callback() {
|
||||||
public void onDataLoaded(ListFolderResult result) {
|
@Override
|
||||||
dialog.dismiss();
|
public void onDataLoaded(ListFolderResult result) {
|
||||||
for (Metadata item : result.getEntries()) {
|
dialog.dismiss();
|
||||||
if (item.getName().equals(vmu)) {
|
for (Metadata item : result.getEntries()) {
|
||||||
if (item instanceof FileMetadata) {
|
if (item.getName().equals(vmu)) {
|
||||||
downloadFile((FileMetadata) item);
|
if (item instanceof FileMetadata) {
|
||||||
|
downloadFile((FileMetadata) item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception e) {
|
public void onError(Exception e) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
Log.e(getActivity().getLocalClassName(), "Failed to list folder.", e);
|
Log.e(getActivity().getLocalClassName(), "Failed to list folder.", e);
|
||||||
Toast.makeText(getActivity(),
|
Toast.makeText(getActivity(),
|
||||||
"An error has occurred", Toast.LENGTH_SHORT).show();
|
"An error has occurred", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}).execute(mPath);
|
}).execute(mPath);
|
||||||
|
} catch (IllegalStateException s) {
|
||||||
|
Log.e(getActivity().getLocalClassName(), "Failed to list folder.", s);
|
||||||
|
Toast.makeText(getActivity(),
|
||||||
|
"An error has occurred", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadFile(String fileUri) {
|
private void uploadFile(String fileUri) {
|
||||||
|
@ -160,21 +166,27 @@ public class CloudFragment extends Fragment {
|
||||||
dialog.setMessage("Uploading");
|
dialog.setMessage("Uploading");
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
new UploadFileTask(getActivity(), DropboxClientFactory.getClient(), new UploadFileTask.Callback() {
|
try {
|
||||||
@Override
|
new UploadFileTask(getActivity(), DropboxClientFactory.getClient(), new UploadFileTask.Callback() {
|
||||||
public void onUploadComplete(FileMetadata result) {
|
@Override
|
||||||
dialog.dismiss();
|
public void onUploadComplete(FileMetadata result) {
|
||||||
}
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception e) {
|
public void onError(Exception e) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
Log.e(getActivity().getLocalClassName(), "Failed to upload file.", e);
|
Log.e(getActivity().getLocalClassName(), "Failed to upload file.", e);
|
||||||
Toast.makeText(getActivity(),
|
Toast.makeText(getActivity(),
|
||||||
"An error has occurred", Toast.LENGTH_SHORT).show();
|
"An error has occurred", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}).execute(fileUri, mPath);
|
}).execute(fileUri, mPath);
|
||||||
|
} catch (IllegalStateException s) {
|
||||||
|
Log.e(getActivity().getLocalClassName(), "Failed to upload file.", s);
|
||||||
|
Toast.makeText(getActivity(),
|
||||||
|
"An error has occurred", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadFile(FileMetadata file) {
|
private void downloadFile(FileMetadata file) {
|
||||||
|
@ -184,21 +196,27 @@ public class CloudFragment extends Fragment {
|
||||||
dialog.setMessage("Downloading");
|
dialog.setMessage("Downloading");
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
new DownloadFileTask(getActivity(), DropboxClientFactory.getClient(), new DownloadFileTask.Callback() {
|
try {
|
||||||
@Override
|
new DownloadFileTask(getActivity(), DropboxClientFactory.getClient(), new DownloadFileTask.Callback() {
|
||||||
public void onDownloadComplete(File result) {
|
@Override
|
||||||
dialog.dismiss();
|
public void onDownloadComplete(File result) {
|
||||||
}
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception e) {
|
public void onError(Exception e) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
Log.e(getActivity().getLocalClassName(), "Failed to download file.", e);
|
Log.e(getActivity().getLocalClassName(), "Failed to download file.", e);
|
||||||
Toast.makeText(getActivity(),
|
Toast.makeText(getActivity(),
|
||||||
"An error has occurred", Toast.LENGTH_SHORT).show();
|
"An error has occurred", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}).execute(file);
|
}).execute(file);
|
||||||
|
} catch (IllegalStateException s) {
|
||||||
|
Log.e(getActivity().getLocalClassName(), "Failed to download file.", s);
|
||||||
|
Toast.makeText(getActivity(),
|
||||||
|
"An error has occurred", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ListFolderTask extends AsyncTask<String, Void, ListFolderResult> {
|
static class ListFolderTask extends AsyncTask<String, Void, ListFolderResult> {
|
||||||
|
|
Loading…
Reference in New Issue