Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add english session access #192

Merged
merged 9 commits into from Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,6 +3,7 @@
import android.support.annotation.NonNull;

import java.util.List;
import java.util.Locale;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -13,6 +14,7 @@
import io.github.droidkaigi.confsched2017.model.Contributor;
import io.github.droidkaigi.confsched2017.model.Session;
import io.github.droidkaigi.confsched2017.model.SessionFeedback;
import io.github.droidkaigi.confsched2017.util.LocaleUtil;
import io.reactivex.Single;
import retrofit2.Response;

Expand All @@ -37,10 +39,11 @@ public DroidKaigiClient(DroidKaigiService droidKaigiService, GithubService githu
}

public Single<List<Session>> getSessions(@NonNull String languageId) {
// TODO
switch (languageId) {
default:
case LocaleUtil.LANG_JA:
return droidKaigiService.getSessionsJa();
default:
return droidKaigiService.getSessionsEn();
}
}

Expand Down
Expand Up @@ -8,4 +8,7 @@ interface DroidKaigiService {

@GET("/2017/sessions.json")
fun getSessionsJa(): Single<List<Session>>

@GET("/2017/en/sessions.json")
fun getSessionsEn(): Single<List<Session>>
}
Expand Up @@ -14,10 +14,6 @@
@Table
public class Session {

public static final String LANG_EN_ID = "EN";

public static final String LANG_JA_ID = "JA";

@PrimaryKey(auto = false)
@Column(indexed = true)
@SerializedName("id")
Expand Down
Expand Up @@ -8,13 +8,18 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import io.github.droidkaigi.confsched2017.BuildConfig;
import io.github.droidkaigi.confsched2017.pref.DefaultPrefs;

public class LocaleUtil {

public static final String LANG_JA = "ja";

public static final String LANG_EN = "en";

private static final String TAG = LocaleUtil.class.getSimpleName();

private static final TimeZone CONFERENCE_TIMEZONE = TimeZone.getTimeZone(BuildConfig.CONFERENCE_TIMEZONE);
Expand Down
Expand Up @@ -99,9 +99,9 @@ public Completable loadSession(int sessionId) {

private int decideLanguageResId(@NonNull String languageId) {
switch (languageId) {
case Session.LANG_EN_ID:
case LocaleUtil.LANG_EN:
return R.string.lang_en;
case Session.LANG_JA_ID:
case LocaleUtil.LANG_JA:
return R.string.lang_ja;
default:
return R.string.lang_en;
Expand Down
Expand Up @@ -8,6 +8,7 @@ import io.github.droidkaigi.confsched2017.api.service.GithubService
import io.github.droidkaigi.confsched2017.api.service.GoogleFormService
import io.github.droidkaigi.confsched2017.model.Session
import io.github.droidkaigi.confsched2017.util.DummyCreator
import io.github.droidkaigi.confsched2017.util.LocaleUtil
import io.reactivex.Single
import org.junit.Test
import org.mockito.Mockito
Expand All @@ -27,20 +28,21 @@ class DroidKaigiClientTest {
fun getSessions() {
val expected = Array(10) { DummyCreator.newSession(it) }.toList()
droidKaigiService.getSessionsJa().invoked.thenReturn(Single.just(expected))
droidKaigiService.getSessionsEn().invoked.thenReturn(Single.just(expected))

client.getSessions(Session.LANG_JA_ID).test().run {
client.getSessions(LocaleUtil.LANG_JA).test().run {
assertNoErrors()
assertResult(expected)
assertComplete()
}

// TODO: multilingual
client.getSessions(Session.LANG_EN_ID).test().run {
client.getSessions(LocaleUtil.LANG_EN).test().run {
assertNoErrors()
assertResult(expected)
assertComplete()
}
droidKaigiService.verify(Mockito.times(2)).getSessionsJa()
droidKaigiService.verify(Mockito.times(1)).getSessionsJa()
droidKaigiService.verify(Mockito.times(1)).getSessionsEn()
}

@Test
Expand Down
Expand Up @@ -6,6 +6,7 @@ import com.sys1yagi.kmockito.verify
import io.github.droidkaigi.confsched2017.api.DroidKaigiClient
import io.github.droidkaigi.confsched2017.model.OrmaDatabase
import io.github.droidkaigi.confsched2017.model.Session
import io.github.droidkaigi.confsched2017.util.LocaleUtil
import io.reactivex.Completable
import io.reactivex.Single
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -73,19 +74,19 @@ class SessionsRepositoryTest {
}

// TODO I want to use enum for language id.
repository.findAll(Session.LANG_JA_ID)
repository.findAll(LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
assertResult(sessions)
assertComplete()

client.verify().getSessions(eq(Session.LANG_JA_ID))
client.verify().getSessions(eq(LocaleUtil.LANG_JA))
ormaDatabase.verify().transactionAsCompletable(any())
cachedSessions.verify(never()).values
}

repository.findAll(Session.LANG_JA_ID)
repository.findAll(LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
Expand Down Expand Up @@ -113,20 +114,20 @@ class SessionsRepositoryTest {
this.cachedSessions = cachedSessions
}

repository.findAll(Session.LANG_JA_ID)
repository.findAll(LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
assertResult(sessions)
assertComplete()

client.verify().getSessions(eq(Session.LANG_JA_ID))
client.verify().getSessions(eq(LocaleUtil.LANG_JA))
cachedSessions.verify(never()).values
}

repository.setIdDirty(true)

repository.findAll(Session.LANG_JA_ID)
repository.findAll(LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
Expand Down Expand Up @@ -196,7 +197,7 @@ class SessionsRepositoryTest {
SessionsRemoteDataSource(client)
)

repository.find(3, Session.LANG_JA_ID)
repository.find(3, LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
Expand All @@ -215,7 +216,7 @@ class SessionsRepositoryTest {
SessionsRemoteDataSource(client)
)

repository.find(3, Session.LANG_JA_ID)
repository.find(3, LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
Expand All @@ -236,7 +237,7 @@ class SessionsRepositoryTest {
}

repository.setIdDirty(false)
repository.find(1, Session.LANG_JA_ID)
repository.find(1, LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
Expand Down Expand Up @@ -270,7 +271,7 @@ class SessionsRepositoryTest {

repository.cachedSessions = cachedSessions
repository.setIdDirty(false)
repository.find(12, Session.LANG_JA_ID)
repository.find(12, LocaleUtil.LANG_JA)
.test()
.run {
assertNoErrors()
Expand Down