package cz.lamorak.wordgame;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.TextView;

import java.util.Collections;
import java.util.List;
import cz.lamorak.wordgame.model.Word;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
/**
 * Created by ondrej on 5.4.2017.
 */

public class GameActivity extends AppCompatActivity {

    private CompositeDisposable disposables;
    private List<Word> words;

    private TextView countdown;
    private TextView wordOriginal;
    private TextView wordGuess;
    private Button wrongButton;
    private Button correctButton;

    public static void call(final Context context) {
        final Intent intent = new Intent(context, GameActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game);

        disposables = new CompositeDisposable();

        countdown = (TextView) findViewById(R.id.countdown);
        wordOriginal = (TextView) findViewById(R.id.word_original);
        wordGuess = (TextView) findViewById(R.id.word_guess);
        correctButton = (Button) findViewById(R.id.button_correct);
        wrongButton = (Button) findViewById(R.id.button_wrong);

        disposables.add(
                WordGameApp.getServiceProvider()
                        .getWordService()
                        .loadWords()
                        .doOnNext(Collections::shuffle)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(this::startGame)
        );
    }

    @Override
    protected void onPause() {
        super.onPause();
        disposables.clear();
    }

    private void startGame(final List<Word> words) {
        this.words = words;
    }
}

@@ -268,16 +268,64 @@
 tView;%0A%0A
+import com.jakewharton.rxbinding2.view.RxView;%0A%0A
 import j
@@ -369,16 +369,54 @@
 l.List;%0A
+import java.util.concurrent.TimeUnit;%0A
 import c
@@ -446,16 +446,48 @@
 l.Word;%0A
+import io.reactivex.Observable;%0A
 import i
@@ -613,172 +613,413 @@
 vex.
-schedulers.Schedulers;%0A/**%0A * Created by ondrej on 5.4.2017.%0A */%0A%0Apublic class GameActivity extends AppCompatActivity %7B%0A%0A    private CompositeDisposable disposables
+disposables.Disposable;%0Aimport io.reactivex.schedulers.Schedulers;%0Aimport io.reactivex.subjects.PublishSubject;%0A%0A/**%0A * Created by ondrej on 5.4.2017.%0A */%0A%0Apublic class GameActivity extends AppCompatActivity %7B%0A%0A    private static final int WORD_LIMIT = 3; // seconds%0A%0A    private CompositeDisposable disposables;%0A    private Disposable wordTimerDisposable;%0A    private PublishSubject%3CBoolean%3E guessSubject
 ;%0A  
@@ -1602,16 +1602,64 @@
 sable();
+%0A        guessSubject = PublishSubject.create();
 %0A%0A      
@@ -2415,158 +2415,1529 @@
 d on
-Pause() %7B%0A        super.onPause();%0A        disposables.clear();%0A    %7D%0A%0A    private void startGame(final List%3CWord%3E words) %7B%0A        this.words = words
+Resume() %7B%0A        super.onResume();%0A        disposables.add(%0A                RxView.clicks(wrongButton)%0A                        .map(o -%3E false)%0A                        .subscribe(guessSubject::onNext)%0A        );%0A        disposables.add(%0A                RxView.clicks(correctButton)%0A                        .map(o -%3E true)%0A                        .subscribe(guessSubject::onNext)%0A        );%0A        disposables.add(%0A                guessSubject.subscribe(aBoolean -%3E displayWord())%0A        );%0A    %7D%0A%0A    @Override%0A    protected void onPause() %7B%0A        super.onPause();%0A        disposables.clear();%0A    %7D%0A%0A    private void startGame(final List%3CWord%3E words) %7B%0A        this.words = words;%0A        displayWord();%0A    %7D%0A%0A    private void displayWord() %7B%0A        if (words.size() %3C 2) %7B%0A            finishGame();%0A        %7D%0A        final Word word = words.remove(0);%0A        wordOriginal.setText(word.getEngllishWord());%0A        wordGuess.setText(word.getSpanishWord());%0A        wordGuess.setTranslationY(0);%0A        wordGuess.animate()%0A                .translationY(1000)%0A                .setDuration(3000L)%0A                .start();%0A%0A        if (wordTimerDisposable != null && !wordTimerDisposable.isDisposed()) %7B%0A            wordTimerDisposable.dispose();%0A        %7D%0A        wordTimerDisposable = Observable.timer(WORD_LIMIT, TimeUnit.SECONDS)%0A                        .observeOn(AndroidSchedulers.mainThread())%0A                        .subscribe(l -%3E guessSubject.onNext(false));%0A        disposables.add(wordTimerDisposable)
 ;%0A  

Implement dummy word displaying