change code
This commit is contained in:
@@ -53,13 +53,11 @@ dependencies {
|
|||||||
implementation("androidx.recyclerview:recyclerview:1.3.2")
|
implementation("androidx.recyclerview:recyclerview:1.3.2")
|
||||||
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
||||||
implementation("com.squareup.retrofit2:converter-simplexml:2.9.0")
|
implementation("com.squareup.retrofit2:converter-simplexml:2.9.0")
|
||||||
dependencies {
|
implementation("com.squareup.okhttp3:okhttp:4.11.0")
|
||||||
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
implementation("com.squareup.moshi:moshi-kotlin:1.15.0")
|
||||||
implementation("com.squareup.retrofit2:converter-simplexml:2.9.0")
|
implementation("org.jsoup:jsoup:1.15.4")
|
||||||
implementation("com.squareup.okhttp3:okhttp:4.11.0")
|
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
|
||||||
implementation("com.squareup.moshi:moshi-kotlin:1.15.0")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.example.curation_train_app
|
||||||
|
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.http.GET
|
||||||
|
|
||||||
|
interface HtmlClient {
|
||||||
|
@GET("kinki.html")
|
||||||
|
fun getHtml(): Call<ResponseBody>
|
||||||
|
}
|
||||||
@@ -10,9 +10,18 @@ import android.widget.ImageView
|
|||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.example.curation_train_app.ai.AiClient
|
import com.example.curation_train_app.ai.AiClient
|
||||||
import com.example.curation_train_app.CharacterSettings
|
import com.example.curation_train_app.CharacterSettings
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
|
||||||
|
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.Call
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
@@ -26,7 +35,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
val drawableId = when (charId) {
|
val drawableId = when (charId) {
|
||||||
"reimu" -> R.drawable.reimu_normal
|
"reimu" -> R.drawable.reimu_normal
|
||||||
"marisa" -> R.drawable.marisa_normal
|
"marisa" -> R.drawable.marisa_normal
|
||||||
"flan" -> R.drawable.flandre_normal
|
"flandre" -> R.drawable.flandre_normal
|
||||||
"sanae" -> R.drawable.sanae_normal
|
"sanae" -> R.drawable.sanae_normal
|
||||||
"akane" -> R.drawable.akane_normal
|
"akane" -> R.drawable.akane_normal
|
||||||
"momoka" -> R.drawable.momoka_normal
|
"momoka" -> R.drawable.momoka_normal
|
||||||
@@ -63,18 +72,17 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
loadTraffic()
|
||||||
loadRss()
|
loadRss()
|
||||||
|
|
||||||
// ▼ リリース枠(表示テスト) ▼
|
|
||||||
val releaseBox = findViewById<LinearLayout>(R.id.layoutRelease)
|
|
||||||
val releaseTitle = findViewById<TextView>(R.id.textReleaseTitle)
|
|
||||||
val releaseBody = findViewById<TextView>(R.id.textReleaseBody)
|
|
||||||
|
|
||||||
releaseTitle.text = "JR西日本:新着情報"
|
val recyclerNews = findViewById<RecyclerView>(R.id.recyclerNews)
|
||||||
releaseBody.text = "最新リリースがここに入る"
|
recyclerNews.layoutManager =
|
||||||
|
LinearLayoutManager(this)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
releaseBox.visibility = View.VISIBLE
|
|
||||||
// ▲ リリース枠 ▲
|
// ▲ リリース枠 ▲
|
||||||
|
|
||||||
// ▼ 地域セレクト画面へ ▼
|
// ▼ 地域セレクト画面へ ▼
|
||||||
@@ -136,6 +144,84 @@ class MainActivity : ComponentActivity() {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadTraffic() {
|
||||||
|
Thread {
|
||||||
|
try {
|
||||||
|
val retrofit = Retrofit.Builder()
|
||||||
|
.baseUrl("https://trafficinfo.westjr.co.jp/")
|
||||||
|
.addConverterFactory(ScalarsConverterFactory.create())
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val client = retrofit.create(HtmlClient::class.java)
|
||||||
|
|
||||||
|
val response = client.getHtml().execute()
|
||||||
|
val html = response.body()?.string() ?: ""
|
||||||
|
|
||||||
|
val doc = Jsoup.parse(html)
|
||||||
|
val items = mutableListOf<NewsItem>()
|
||||||
|
|
||||||
|
val list = doc.select("div.jisyo") // ← 運行情報の1ブロック
|
||||||
|
|
||||||
|
for (block in list) {
|
||||||
|
val title = block.select("h2.jisyo_title").text()
|
||||||
|
val body = block.select("div.jisyo_contents p").text()
|
||||||
|
|
||||||
|
if (title.isNotEmpty()) {
|
||||||
|
items.add(
|
||||||
|
NewsItem(
|
||||||
|
company = "JR西日本",
|
||||||
|
title = title,
|
||||||
|
body = body
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 総合判定 ---
|
||||||
|
var hasSuspension = false
|
||||||
|
var hasDelay = false
|
||||||
|
var hasInfo = false
|
||||||
|
|
||||||
|
for (item in items) {
|
||||||
|
when (item.company) { // ← company に status 入れてるよね?
|
||||||
|
"運転見合わせ" -> hasSuspension = true
|
||||||
|
"遅延" -> hasDelay = true
|
||||||
|
"情報あり" -> hasInfo = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val resultTitle = when {
|
||||||
|
hasSuspension -> "運転見合わせがあります"
|
||||||
|
hasDelay -> "遅延が発生しています"
|
||||||
|
hasInfo -> "運行に関するお知らせがあります"
|
||||||
|
else -> "平常運転"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
runOnUiThread {
|
||||||
|
// 最上段のテキスト書き換え
|
||||||
|
val titleView = findViewById<TextView>(R.id.textTitle)
|
||||||
|
titleView.text = "近畿エリア:$resultTitle"
|
||||||
|
|
||||||
|
// RecyclerView を更新
|
||||||
|
val recycler = findViewById<RecyclerView>(R.id.recyclerNews)
|
||||||
|
recycler.adapter = NewsAdapter(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun emotionToExpression(type: EmotionType): String {
|
fun emotionToExpression(type: EmotionType): String {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
EmotionType.HAPPY -> "happy"
|
EmotionType.HAPPY -> "happy"
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ package com.example.curation_train_app
|
|||||||
|
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.simplexml.SimpleXmlConverterFactory
|
import retrofit2.converter.simplexml.SimpleXmlConverterFactory
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
class RssApi {
|
class RssApi {
|
||||||
|
|
||||||
private val retrofit = Retrofit.Builder()
|
private val retrofit = Retrofit.Builder()
|
||||||
.baseUrl("https://www.westjr.co.jp/press/article/index.xml")
|
.baseUrl("https://www.westjr.co.jp/press/article/")
|
||||||
.addConverterFactory(SimpleXmlConverterFactory.create())
|
.addConverterFactory(SimpleXmlConverterFactory.create())
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
@@ -14,7 +15,15 @@ class RssApi {
|
|||||||
|
|
||||||
fun loadRss(): RssFeed? {
|
fun loadRss(): RssFeed? {
|
||||||
val response = client.getFeed().execute()
|
val response = client.getFeed().execute()
|
||||||
|
|
||||||
|
Log.d(
|
||||||
|
"RSS_DEBUG",
|
||||||
|
"code=${response.code()}, body=${response.body()}, error=${response.errorBody()?.string()}"
|
||||||
|
)
|
||||||
|
|
||||||
return response.body()
|
return response.body()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ package com.example.curation_train_app
|
|||||||
|
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
|
||||||
interface RssClient {
|
interface RssClient {
|
||||||
@GET("article/index.xml")
|
|
||||||
|
@GET("index.xml")
|
||||||
fun getFeed(): Call<RssFeed>
|
fun getFeed(): Call<RssFeed>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
android:text="○○線:平常運転"
|
android:text="○○線:平常運転"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="8dp"
|
||||||
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textFavorite"
|
android:id="@+id/textFavorite"
|
||||||
@@ -53,7 +54,7 @@
|
|||||||
android:layout_margin="12dp"
|
android:layout_margin="12dp"
|
||||||
android:background="@drawable/comment_background_white"
|
android:background="@drawable/comment_background_white"
|
||||||
android:elevation="2dp"
|
android:elevation="2dp"
|
||||||
android:visibility="visible">
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textReleaseTitle"
|
android:id="@+id/textReleaseTitle"
|
||||||
@@ -93,7 +94,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="△△電鉄"
|
android:text="△△電鉄"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textNoticeBody"
|
android:id="@+id/textNoticeBody"
|
||||||
@@ -101,7 +103,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="(運行情報の本文が入ります)"
|
android:text="(運行情報の本文が入ります)"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp"
|
||||||
android:layout_marginTop="4dp" />
|
android:layout_marginTop="4dp"
|
||||||
|
android:visibility="gone"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
@@ -109,7 +112,7 @@
|
|||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerNews"
|
android:id="@+id/recyclerNews"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:padding="8dp" />
|
android:padding="8dp" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user