Skip to content

Commit

Permalink
Merge pull request #3369 from nextcloud/backport/3365/stable-3.4.x
Browse files Browse the repository at this point in the history
[stable-3.4.x] Trashbin: do UI changes of async only if activity is still up and running
  • Loading branch information
tobiasKaminsky authored Dec 14, 2018
2 parents d5a107d + 7ca15a2 commit e613c01
Showing 1 changed file with 26 additions and 13 deletions.
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);
}
}
}
}

0 comments on commit e613c01

Please sign in to comment.