From 2288ceffb8cab6101499ec6d9b82c0cfcb4d8c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Fri, 25 May 2018 19:10:34 +0200 Subject: [PATCH] Stop refreshing while semester switching window open (#123) --- .../ui/main/grades/GradesContract.java | 2 ++ .../ui/main/grades/GradesFragment.java | 1 + .../ui/main/grades/GradesPresenter.java | 21 +++++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesContract.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesContract.java index a48b340d..07ca0d73 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesContract.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesContract.java @@ -40,5 +40,7 @@ public interface GradesContract { void onStart(View view, OnFragmentIsReadyListener listener); void onSemesterChange(int which); + + void onSemesterSwitchActive(); } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java index 32c1f3d3..5a31736b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java @@ -80,6 +80,7 @@ public class GradesFragment extends BaseFragment implements GradesContract.View @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_filter) { + presenter.onSemesterSwitchActive(); CharSequence[] items = new CharSequence[]{ getResources().getString(R.string.semester_text, 1), getResources().getString(R.string.semester_text, 2), diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesPresenter.java index 1e99bbde..493cc545 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesPresenter.java @@ -3,6 +3,8 @@ package io.github.wulkanowy.ui.main.grades; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.threeten.bp.LocalDate; + import java.util.ArrayList; import java.util.List; @@ -57,11 +59,15 @@ public class GradesPresenter extends BasePresenter } } + @Override + public void onSemesterSwitchActive() { + cancelAsyncTasks(); + } + @Override public void onSemesterChange(int which) { semesterName = which + 1; getView().setCurrentSemester(which); - reloadGrades(); Answers.getInstance().logCustom(new CustomEvent("Semester change") @@ -123,7 +129,7 @@ public class GradesPresenter extends BasePresenter } getView().hideRefreshingBar(); - FabricUtils.logRefresh("Grades", result, null); + FabricUtils.logRefresh("Grades", result, LocalDate.now().toString()); } @Override @@ -165,10 +171,7 @@ public class GradesPresenter extends BasePresenter listener.onFragmentIsReady(); } - @Override - public void onDestroy() { - isFirstSight = false; - + private void cancelAsyncTasks() { if (refreshTask != null) { refreshTask.cancel(true); refreshTask = null; @@ -177,6 +180,12 @@ public class GradesPresenter extends BasePresenter loadingTask.cancel(true); loadingTask = null; } + } + + @Override + public void onDestroy() { + isFirstSight = false; + cancelAsyncTasks(); super.onDestroy(); } }