Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trashbin: do UI changes of async only if activity is still up and running #3365

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public class TrashbinActivity extends FileActivity implements TrashbinActivityIn
private TrashbinListAdapter trashbinListAdapter;
private TrashbinPresenter trashbinPresenter;

private boolean active = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -107,6 +109,8 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onStart() {
super.onStart();

active = true;

setupContent();
}

Expand Down Expand Up @@ -229,6 +233,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
protected void onPause() {
super.onPause();
active = false;

trashbinListAdapter.cancelAllPendingTasks();
}

Expand All @@ -253,13 +259,17 @@ public void onSortingOrderChosen(FileSortOrder sortOrder) {

@Override
public void showTrashbinFolder(List<Object> trashbinFiles) {
trashbinListAdapter.setTrashbinFiles(trashbinFiles, true);
swipeListRefreshLayout.setRefreshing(false);
if (active) {
trashbinListAdapter.setTrashbinFiles(trashbinFiles, true);
swipeListRefreshLayout.setRefreshing(false);
}
}

@Override
public void removeFile(TrashbinFile file) {
trashbinListAdapter.removeFile(file);
if (active) {
trashbinListAdapter.removeFile(file);
}
}

@Override
Expand All @@ -269,23 +279,26 @@ public void removeAllFiles() {

@Override
public void showSnackbarError(int message, TrashbinFile file) {
swipeListRefreshLayout.setRefreshing(false);
Snackbar.make(recyclerView, String.format(getString(message), file.getFileName()), Snackbar.LENGTH_LONG).show();
if (active) {
swipeListRefreshLayout.setRefreshing(false);
Snackbar.make(recyclerView, String.format(getString(message), file.getFileName()), Snackbar.LENGTH_LONG)
.show();
}
}

@Override
public void showError(int message) {
if (swipeListRefreshLayout != null) {
if (active) {
swipeListRefreshLayout.setRefreshing(false);
}

if (emptyContentMessage != null && emptyContentHeadline != null && emptyContentIcon != null) {
emptyContentHeadline.setText(R.string.common_error);
emptyContentIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_list_empty_error));
emptyContentMessage.setText(message);
if (emptyContentMessage != null) {
emptyContentHeadline.setText(R.string.common_error);
emptyContentIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_list_empty_error));
emptyContentMessage.setText(message);

emptyContentMessage.setVisibility(View.VISIBLE);
emptyContentIcon.setVisibility(View.VISIBLE);
emptyContentMessage.setVisibility(View.VISIBLE);
emptyContentIcon.setVisibility(View.VISIBLE);
}
}
}
}