diff --git a/app/src/main/assets/data.json b/app/src/main/assets/data.json new file mode 100644 index 0000000..a3cb0d7 --- /dev/null +++ b/app/src/main/assets/data.json @@ -0,0 +1,211 @@ +{ + "fruit": [ + { + "id": 0, + "name": "一撃失心", + "rank": 0 + }, + { + "id": 1, + "name": "熱き友撃", + "rank": 1 + }, + { + "id": 2, + "name": "将来削り", + "rank": 2 + }, + { + "id": 3, + "name": "ケガ減り", + "rank": 3 + }, + { + "id": 4, + "name": "スコア稼ぎ", + "rank": 4 + }, + { + "id": 5, + "name": "Sランク", + "rank": 5 + }, + { + "id": 6, + "name": "スピクリ", + "rank": 6 + }, + { + "id": 7, + "name": "学び", + "rank": 7 + }, + { + "id": 8, + "name": "ちび癒し", + "rank": 8 + }, + { + "id": 9, + "name": "速必殺", + "rank": 9 + }, + { + "id": 10, + "name": "同族加撃", + "rank": 10 + }, + { + "id": 11, + "name": "同族加命", + "rank": 11 + }, + { + "id": 12, + "name": "同族加速", + "rank": 12 + }, + { + "id": 13, + "name": "戦型加撃", + "rank": 13 + }, + { + "id": 14, + "name": "戦型加命", + "rank": 14 + }, + { + "id": 15, + "name": "戦型加速", + "rank": 15 + }, + { + "id": 16, + "name": "撃種加撃", + "rank": 16 + }, + { + "id": 17, + "name": "撃種加命", + "rank": 17 + }, + { + "id": 18, + "name": "撃種加速", + "rank": 18 + }, + { + "id": 19, + "name": "毒がまん", + "rank": 19 + }, + { + "id": 20, + "name": "荒稼ぎ", + "rank": 20 + } + ], + "temple": [ + { + "id": 0, + "name": "獄炎の神殿(修羅場)", + "rank": 0 + }, + { + "id": 1, + "name": "獄炎の神殿(時の間)", + "rank": 1 + }, + { + "id": 2, + "name": "獄炎の神殿(銭の間)", + "rank": 2 + }, + { + "id": 3, + "name": "獄炎の神殿(秋の間)", + "rank": 3 + }, + { + "id": 4, + "name": "秘泉の神殿(修羅場)", + "rank": 4 + }, + { + "id": 5, + "name": "秘泉の神殿(時の間)", + "rank": 5 + }, + { + "id": 6, + "name": "秘泉の神殿(銭の間)", + "rank": 6 + }, + { + "id": 7, + "name": "秘泉の神殿(秋の間)", + "rank": 7 + }, + { + "id": 8, + "name": "樹縛の神殿(修羅場)", + "rank": 8 + }, + { + "id": 9, + "name": "樹縛の神殿(時の間)", + "rank": 9 + }, + { + "id": 10, + "name": "樹縛の神殿(銭の間)", + "rank": 10 + }, + { + "id": 11, + "name": "樹縛の神殿(秋の間)", + "rank": 11 + }, + { + "id": 12, + "name": "光明の神殿(修羅場)", + "rank": 12 + }, + { + "id": 13, + "name": "光明の神殿(時の間)", + "rank": 13 + }, + { + "id": 14, + "name": "光明の神殿(銭の間)", + "rank": 14 + }, + { + "id": 15, + "name": "光明の神殿(秋の間)", + "rank": 15 + }, + { + "id": 16, + "name": "常闇の神殿(修羅場)", + "rank": 16 + }, + { + "id": 17, + "name": "常闇の神殿(時の間)", + "rank": 17 + }, + { + "id": 18, + "name": "常闇の神殿(銭の間)", + "rank": 18 + }, + { + "id": 19, + "name": "常闇の神殿(秋の間)", + "rank": 19 + } + ] +} diff --git a/app/src/main/kotlin/jackall/moncalc/Const.kt b/app/src/main/kotlin/jackall/moncalc/Const.kt index 3e109f7..d327068 100644 --- a/app/src/main/kotlin/jackall/moncalc/Const.kt +++ b/app/src/main/kotlin/jackall/moncalc/Const.kt @@ -7,5 +7,6 @@ companion object { const val serviceChannelId = "mainService" const val notificationId = 1 + const val questDataVersion = 0 } } \ No newline at end of file diff --git a/app/src/main/kotlin/jackall/moncalc/activity/MainActivity.kt b/app/src/main/kotlin/jackall/moncalc/activity/MainActivity.kt index 4f5c828..6d5e1e7 100644 --- a/app/src/main/kotlin/jackall/moncalc/activity/MainActivity.kt +++ b/app/src/main/kotlin/jackall/moncalc/activity/MainActivity.kt @@ -5,19 +5,45 @@ import android.content.Intent import android.os.Bundle import android.support.v7.app.AppCompatActivity +import com.google.gson.Gson +import com.google.gson.stream.JsonReader +import jackall.moncalc.Const import jackall.moncalc.R +import jackall.moncalc.common.PreferenceKeys +import jackall.moncalc.common.PreferenceNames +import jackall.moncalc.db.FruitRealmHelper +import jackall.moncalc.db.TempleRealmHelper import jackall.moncalc.service.MainService +import jackall.moncalc.utils.MySharedPref +import jackall.moncalc.vo.MonstData import kotlinx.android.synthetic.main.activity_main.* +import java.io.InputStreamReader class MainActivity : AppCompatActivity() { + val mySharedPref by lazy { MySharedPref(this, PreferenceNames.CONFIG) } + val fruitRealmHelper by lazy { FruitRealmHelper() } + val templeRealmHelper by lazy { TempleRealmHelper() } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // TODO:レイアウトを決めてdatbinding,viewModelProvidersを有効にする val intent = Intent(this, MainService::class.java) + if ((mySharedPref.getValue(PreferenceKeys.QUESTDATAVERSION, Int::class.java, -1) as Int) < Const.questDataVersion) { + val inputStream = assets.open("data.json") + val jsonReader = JsonReader(InputStreamReader(inputStream)) + val monstData = Gson().fromJson(jsonReader, MonstData::class.java) + + fruitRealmHelper.update(monstData.fruit) + templeRealmHelper.update(monstData.temple) + + mySharedPref.putValue(PreferenceKeys.QUESTDATAVERSION, Int::class.java, Const.questDataVersion) + + println("db update") + } start_service_btn.setOnClickListener { if (!isMainServiceRunning()) @@ -30,6 +56,12 @@ } } + override fun onDestroy() { + super.onDestroy() + fruitRealmHelper.close() + templeRealmHelper.close() + } + private fun isMainServiceRunning(): Boolean { val manager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager for (serviceInfo in manager.getRunningServices(Integer.MAX_VALUE)) { diff --git a/app/src/main/kotlin/jackall/moncalc/common/PreferenceKeys.kt b/app/src/main/kotlin/jackall/moncalc/common/PreferenceKeys.kt index ba24b0f..13c64ac 100644 --- a/app/src/main/kotlin/jackall/moncalc/common/PreferenceKeys.kt +++ b/app/src/main/kotlin/jackall/moncalc/common/PreferenceKeys.kt @@ -7,5 +7,6 @@ */ enum class PreferenceKeys(val preferenceNames: PreferenceNames, val valueClass: Class<*>, val key: String) { VIEWX(PreferenceNames.CONFIG, Int::class.java, "viewX"), - VIEWY(PreferenceNames.CONFIG, Int::class.java, "viewY") + VIEWY(PreferenceNames.CONFIG, Int::class.java, "viewY"), + QUESTDATAVERSION(PreferenceNames.CONFIG, Int::class.java, "questDataVersion") } \ No newline at end of file diff --git a/app/src/main/kotlin/jackall/moncalc/vo/MonstData.kt b/app/src/main/kotlin/jackall/moncalc/vo/MonstData.kt new file mode 100644 index 0000000..44fbcb5 --- /dev/null +++ b/app/src/main/kotlin/jackall/moncalc/vo/MonstData.kt @@ -0,0 +1,9 @@ +package jackall.moncalc.vo + +/** + * Created by matsumoto_k on 2017/11/03. + */ +data class MonstData( + val fruit: List, + val temple: List +) \ No newline at end of file