Stop refreshing while semester switching window open (#123)

This commit is contained in:
Rafał Borcz 2018-05-25 19:10:34 +02:00 committed by Mikołaj Pich
parent ffe8511e3f
commit 2288ceffb8
3 changed files with 18 additions and 6 deletions

View File

@ -40,5 +40,7 @@ public interface GradesContract {
void onStart(View view, OnFragmentIsReadyListener listener);
void onSemesterChange(int which);
void onSemesterSwitchActive();
}
}

View File

@ -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),

View File

@ -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<GradesContract.View>
}
}
@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<GradesContract.View>
}
getView().hideRefreshingBar();
FabricUtils.logRefresh("Grades", result, null);
FabricUtils.logRefresh("Grades", result, LocalDate.now().toString());
}
@Override
@ -165,10 +171,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
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<GradesContract.View>
loadingTask.cancel(true);
loadingTask = null;
}
}
@Override
public void onDestroy() {
isFirstSight = false;
cancelAsyncTasks();
super.onDestroy();
}
}