Skip to content

Commit d362f35

Browse files
committed
Respond to api server for share created problems
1 parent 68e62c8 commit d362f35

36 files changed

+812
-170
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/captures/
88
.externalNativeBuild
99
/gradle/
10+
*.apk

app/build.gradle

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ androidExtensions {
99

1010
android {
1111
compileSdkVersion 26
12-
buildToolsVersion "26.0.1"
12+
buildToolsVersion "26.0.2"
1313
defaultConfig {
1414
applicationId "jp.co.seesaa.geckour.picrossmaker"
1515
minSdkVersion 21
@@ -40,51 +40,66 @@ android {
4040
}
4141

4242
dependencies {
43-
def android_support_version = '26.0.0-alpha1'
44-
def orma_version = '4.2.3'
43+
def android_support_version = '26.1.0'
44+
def stetho_version = '1.5.0'
45+
def orma_version = '4.2.5'
4546
def rxLifecycle_version = '2.0.1'
46-
def coroutines_version = '0.13'
47+
def coroutines_version = '0.19.3'
48+
def retrofit_version = '2.3.0'
49+
def okhttp_version = '3.8.0'
4750

48-
compile fileTree(dir: 'libs', include: ['*.jar'])
51+
implementation fileTree(dir: 'libs', include: ['*.jar'])
4952
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
5053
exclude group: 'com.android.support', module: 'support-annotations'
5154
})
5255
testCompile 'junit:junit:4.12'
53-
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
56+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
5457

55-
kapt 'com.android.databinding:compiler:2.3.1'
58+
kapt 'com.android.databinding:compiler:3.0.1'
5659

57-
compile "com.android.support:appcompat-v7:$android_support_version"
58-
compile "com.android.support:support-v4:$android_support_version"
59-
compile "com.android.support:design:$android_support_version"
60-
compile "com.android.support:recyclerview-v7:$android_support_version"
61-
compile 'com.android.support.constraint:constraint-layout:1.0.2'
60+
implementation "com.android.support:appcompat-v7:$android_support_version"
61+
implementation "com.android.support:support-v4:$android_support_version"
62+
implementation "com.android.support:design:$android_support_version"
63+
implementation "com.android.support:recyclerview-v7:$android_support_version"
64+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
6265

63-
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
64-
compile "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
66+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
67+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
6568

66-
compile 'io.reactivex.rxjava2:rxjava:2.0.8'
67-
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
68-
compile 'io.reactivex.rxjava2:rxkotlin:2.0.0'
69-
compile "com.trello.rxlifecycle2:rxlifecycle:$rxLifecycle_version"
70-
compile "com.trello.rxlifecycle2:rxlifecycle-components:$rxLifecycle_version"
71-
compile "com.trello.rxlifecycle2:rxlifecycle-kotlin:$rxLifecycle_version"
69+
implementation "com.facebook.stetho:stetho:$stetho_version"
70+
implementation "com.facebook.stetho:stetho-okhttp3:$stetho_version"
7271

73-
compile 'com.squareup.retrofit2:converter-moshi:2.2.0'
74-
compile 'com.google.code.gson:gson:2.8.0'
72+
implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
73+
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
74+
implementation 'io.reactivex.rxjava2:rxkotlin:2.0.0'
75+
implementation "com.trello.rxlifecycle2:rxlifecycle:$rxLifecycle_version"
76+
implementation "com.trello.rxlifecycle2:rxlifecycle-components:$rxLifecycle_version"
77+
implementation "com.trello.rxlifecycle2:rxlifecycle-kotlin:$rxLifecycle_version"
7578

76-
compile 'com.jakewharton.timber:timber:4.5.1'
79+
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
80+
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
81+
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
82+
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
83+
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
7784

78-
compile 'com.github.yamamotoj:pikkel:0.3.3'
85+
implementation 'com.google.code.gson:gson:2.8.2'
7986

80-
compile group: 'org.ow2.sat4j', name: 'org.ow2.sat4j.core', version: '2.3.5'
87+
implementation 'com.jakewharton.timber:timber:4.5.1'
88+
89+
implementation 'com.github.yamamotoj:pikkel:0.3.3'
90+
91+
implementation group: 'org.ow2.sat4j', name: 'org.ow2.sat4j.core', version: '2.3.5'
8192

8293
kapt "com.github.gfx.android.orma:orma-processor:$orma_version"
83-
compile "com.github.gfx.android.orma:orma:$orma_version"
94+
implementation "com.github.gfx.android.orma:orma:$orma_version"
8495
}
8596

8697
repositories {
8798
mavenCentral()
8899
maven { url "https://jitpack.io" }
89100
maven { url "http://dl.bintray.com/kotlin/kotlin-eap-1.1" }
101+
maven {
102+
url 'https://maven.google.com/'
103+
name 'Google'
104+
}
90105
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="jp.co.seesaa.geckour.picrossmaker">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
46

57
<application
68
android:name=".App"
Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,31 @@
11
package jp.co.seesaa.geckour.picrossmaker
22

33
import android.app.Application
4+
import com.facebook.stetho.Stetho
45
import com.google.gson.Gson
56
import com.google.gson.GsonBuilder
67
import jp.co.seesaa.geckour.picrossmaker.model.OrmaProvider
7-
import kotlinx.coroutines.experimental.CommonPool
8-
import kotlinx.coroutines.experimental.CoroutineScope
9-
import kotlinx.coroutines.experimental.Job
10-
import kotlinx.coroutines.experimental.android.UI
11-
import kotlinx.coroutines.experimental.launch
12-
import kotlin.coroutines.experimental.CoroutineContext
8+
import jp.co.seesaa.geckour.picrossmaker.util.OkHttpProvider
9+
import timber.log.Timber
1310

1411
class App : Application() {
1512

1613
companion object {
17-
val gson: Gson = GsonBuilder().apply {}.create()
14+
val gson: Gson = GsonBuilder().apply {
15+
serializeNulls()
16+
setLenient()
17+
}.create()
1818
}
1919

2020
override fun onCreate() {
2121
super.onCreate()
2222

23+
if (BuildConfig.DEBUG) {
24+
Timber.plant(Timber.DebugTree())
25+
Stetho.initializeWithDefaults(this)
26+
}
27+
2328
OrmaProvider.init(this)
29+
OkHttpProvider.init()
2430
}
25-
}
26-
27-
fun <T> async(context: CoroutineContext = CommonPool, block: suspend CoroutineScope.() -> T) =
28-
kotlinx.coroutines.experimental.async(context, block = block)
29-
30-
fun ui(managerList: ArrayList<Job>, onError: (Throwable) -> Unit = {}, block: suspend CoroutineScope.() -> Unit) =
31-
launch(UI) {
32-
try {
33-
block()
34-
} catch (e: Exception) {
35-
e.printStackTrace()
36-
onError(e)
37-
}
38-
}.apply {
39-
managerList.add(this)
40-
}
31+
}

app/src/main/java/jp/co/seesaa/geckour/picrossmaker/activity/MainActivity.kt

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import android.content.DialogInterface
44
import android.databinding.DataBindingUtil
55
import android.os.Bundle
66
import android.support.design.widget.NavigationView
7-
import android.support.v4.view.GravityCompat
87
import android.util.Size
8+
import android.view.Gravity
9+
import android.view.LayoutInflater
910
import android.view.Menu
1011
import android.view.MenuItem
12+
import android.widget.Toolbar
1113
import com.trello.rxlifecycle2.components.RxActivity
1214
import jp.co.seesaa.geckour.picrossmaker.fragment.ProblemsFragment
1315
import jp.co.seesaa.geckour.picrossmaker.R
1416
import jp.co.seesaa.geckour.picrossmaker.databinding.ActivityMainBinding
1517
import jp.co.seesaa.geckour.picrossmaker.fragment.DraftProblemsFragment
1618
import jp.co.seesaa.geckour.picrossmaker.fragment.EditorFragment
19+
import jp.co.seesaa.geckour.picrossmaker.fragment.SearchFragment
1720
import jp.co.seesaa.geckour.picrossmaker.util.MyAlertDialogFragment
1821
import jp.co.seesaa.geckour.picrossmaker.util.MyAlertDialogFragment.Companion.showSnackbar
1922

@@ -24,7 +27,12 @@ class MainActivity : RxActivity(), NavigationView.OnNavigationItemSelectedListen
2427
override fun onCreate(savedInstanceState: Bundle?) {
2528
super.onCreate(savedInstanceState)
2629
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
27-
setActionBar(binding.appBarMain.toolbar)
30+
binding.appBarMain?.appBar?.apply {
31+
val toolbar = LayoutInflater.from(this@MainActivity).inflate(R.layout.toolbar_main, null) as Toolbar
32+
removeAllViews()
33+
addView(toolbar)
34+
setActionBar(toolbar)
35+
}
2836

2937
binding.navView.setNavigationItemSelectedListener(this)
3038

@@ -35,11 +43,12 @@ class MainActivity : RxActivity(), NavigationView.OnNavigationItemSelectedListen
3543
}
3644

3745
override fun onBackPressed() {
38-
val drawer = binding.drawerLayout
39-
if (drawer.isDrawerOpen(GravityCompat.START)) {
40-
drawer.closeDrawer(GravityCompat.START)
41-
} else {
42-
super.onBackPressed()
46+
binding.drawerLayout.apply {
47+
if (isDrawerOpen(Gravity.START)) {
48+
closeDrawer(Gravity.START)
49+
} else {
50+
super.onBackPressed()
51+
}
4352
}
4453
}
4554

@@ -56,12 +65,12 @@ class MainActivity : RxActivity(), NavigationView.OnNavigationItemSelectedListen
5665
when (id) {
5766
R.id.nav_problem -> {
5867
val fragment = ProblemsFragment.newInstance()
59-
fragmentManager.beginTransaction().replace(R.id.container, fragment).addToBackStack(null).commit()
68+
fragmentManager.beginTransaction().replace(R.id.container, fragment).addToBackStack(ProblemsFragment.tag).commit()
6069
}
6170

6271
R.id.nav_draft -> {
6372
val fragment = DraftProblemsFragment.newInstance()
64-
fragmentManager.beginTransaction().replace(R.id.container, fragment).addToBackStack(null).commit()
73+
fragmentManager.beginTransaction().replace(R.id.container, fragment).addToBackStack(DraftProblemsFragment.tag).commit()
6574
}
6675

6776
R.id.nav_editor -> {
@@ -79,17 +88,18 @@ class MainActivity : RxActivity(), NavigationView.OnNavigationItemSelectedListen
7988

8089
}
8190

82-
R.id.nav_share -> {
83-
91+
R.id.nav_search -> {
92+
val fragment = SearchFragment.createInstance()
93+
fragmentManager.beginTransaction().replace(R.id.container, fragment).addToBackStack(SearchFragment.tag).commit()
8494
}
8595
}
8696

87-
binding.drawerLayout.closeDrawer(GravityCompat.START)
97+
binding.drawerLayout.closeDrawer(Gravity.START)
8898
return true
8999
}
90100

91101
override fun onCanvasSizeError(size: Size) {
92-
showSnackbar(binding.appBarMain.contentMain.container, R.string.problem_fragment_error_invalid_size)
102+
binding.appBarMain?.contentMain?.container?.let { showSnackbar(it, R.string.problem_fragment_error_invalid_size) }
93103
}
94104

95105
override fun onResultAlertDialog(dialogInterface: DialogInterface, requestCode: MyAlertDialogFragment.RequestCode, resultCode: Int, result: Any?) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package jp.co.seesaa.geckour.picrossmaker.api
2+
3+
import io.reactivex.Single
4+
import jp.co.seesaa.geckour.picrossmaker.App.Companion.gson
5+
import jp.co.seesaa.geckour.picrossmaker.api.model.Problem
6+
import jp.co.seesaa.geckour.picrossmaker.api.model.Result
7+
import jp.co.seesaa.geckour.picrossmaker.api.service.ApiService
8+
import jp.co.seesaa.geckour.picrossmaker.util.OkHttpProvider
9+
import retrofit2.Retrofit
10+
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
11+
import retrofit2.converter.gson.GsonConverterFactory
12+
13+
class ApiClient {
14+
15+
companion object {
16+
private val baseUrl = "172.16.21.15:8080"
17+
}
18+
19+
private val service = Retrofit.Builder().client(OkHttpProvider.client)
20+
.baseUrl("http://$baseUrl/")
21+
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
22+
.addConverterFactory(GsonConverterFactory.create(gson))
23+
.build()
24+
.create(ApiService::class.java)
25+
26+
fun registerProblem(problem: Problem): Single<Result<String>> = service.registerProblem(problem)
27+
28+
fun search(title: String?, genre: String?): Single<Result<Result.Data<Result.Data.Problems>>> = service.search(title, genre)
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package jp.co.seesaa.geckour.picrossmaker.api.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class Problem(
6+
val id: Long? = null,
7+
8+
val title: String,
9+
10+
val genres: List<String>,
11+
12+
@SerializedName("keys_horizontal")
13+
val keysHorizontal: List<List<Int>>,
14+
15+
@SerializedName("keys_vertical")
16+
val keysVertical: List<List<Int>>,
17+
18+
val thumb: String?,
19+
20+
@SerializedName("created_at")
21+
val createdAt: Long = System.currentTimeMillis(),
22+
23+
@SerializedName("edited_at")
24+
val editedAt: Long = System.currentTimeMillis()
25+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package jp.co.seesaa.geckour.picrossmaker.api.model
2+
3+
data class Result<out T>(
4+
val success: Boolean,
5+
val message: T
6+
) {
7+
data class Data<out T>(
8+
val data: T
9+
) {
10+
data class Problems(
11+
val problems: List<Problem>
12+
)
13+
}
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package jp.co.seesaa.geckour.picrossmaker.api.service
2+
3+
import io.reactivex.Single
4+
import jp.co.seesaa.geckour.picrossmaker.api.model.Problem
5+
import jp.co.seesaa.geckour.picrossmaker.api.model.Result
6+
import retrofit2.http.Body
7+
import retrofit2.http.GET
8+
import retrofit2.http.POST
9+
import retrofit2.http.Query
10+
11+
interface ApiService {
12+
13+
@POST("api/v1/post")
14+
fun registerProblem(
15+
@Body
16+
problem: Problem
17+
): Single<Result<String>>
18+
19+
@GET("api/v1/search")
20+
fun search(
21+
@Query("title")
22+
title: String?,
23+
24+
@Query("genre")
25+
genre: String?
26+
): Single<Result<Result.Data<Result.Data.Problems>>>
27+
}

0 commit comments

Comments
 (0)