Skip to content

Commit

Permalink
Make sure the sentences are updated when returning to the study sessi…
Browse files Browse the repository at this point in the history
…on fragment and some bug fixes.
  • Loading branch information
chickendude committed Jan 21, 2019
1 parent 7bd01d6 commit 957dd46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/ch/ralena/natibo/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void onCreate() {
RealmConfiguration config = new RealmConfiguration.Builder()
.name("natibo.realm")
.schemaVersion(1)
// .deleteRealmIfMigrationNeeded()
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
import ch.ralena.natibo.adapter.SentenceGroupAdapter;
import ch.ralena.natibo.object.Course;
import ch.ralena.natibo.object.Day;
import ch.ralena.natibo.object.Sentence;
import ch.ralena.natibo.object.SentenceGroup;
import ch.ralena.natibo.service.StudySessionService;
import io.reactivex.disposables.Disposable;
import io.realm.Realm;
import io.realm.RealmList;

public class StudySessionFragment extends Fragment {
private static final String TAG = StudySessionFragment.class.getSimpleName();
Expand Down Expand Up @@ -120,11 +118,11 @@ private void loadGlobalViews(View view) {

private void connectToService() {
serviceDisposable = activity.getSessionPublish().subscribe(service -> {
studySessionService = service;
if (course.getCurrentDay().getCurrentSentenceGroup() != null)
nextSentence(course.getCurrentDay().getCurrentSentenceGroup());
else
sessionFinished(course.getCurrentDay());
studySessionService = service;
sentenceDisposable = studySessionService.sentenceObservable().subscribe(this::nextSentence);
finishDisposable = studySessionService.finishObservable().subscribe(this::sessionFinished);
setPaused(studySessionService.getPlaybackStatus() == null || studySessionService.getPlaybackStatus() == StudySessionService.PlaybackStatus.PAUSED);
Expand Down Expand Up @@ -178,8 +176,8 @@ private void sessionFinished(Day day) {
}

private void nextSentence(SentenceGroup sentenceGroup) {
updatePlayPauseImage();
sentencesLayout.setVisibility(View.VISIBLE);
RealmList<Sentence> sentences = sentenceGroup.getSentences();
adapter.updateSentenceGroup(sentenceGroup);

// update number of reps remaining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,15 @@ public void onReceive(Context context, Intent intent) {

// if the app is playing, we don't need to reload the sentence.
// if nothing is playing, we'll need to load the sentence and start it.
if (playbackStatus != PlaybackStatus.PLAYING) {
if (playbackStatus != PlaybackStatus.PLAYING && !day.isCompleted()) {
loadSentence();
play();
}

// when returning to the screen, make sure the sentences are updated
if (sentenceGroup != null) {
sentencePublish.onNext(sentenceGroup);
}
}
}

Expand Down

0 comments on commit 957dd46

Please sign in to comment.