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

week5.png 첨부 #42

Open
wants to merge 2 commits into
base: chaeyoung
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -12,24 +14,23 @@
android:supportsRtl="true"
android:theme="@style/Theme.GDSC"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="false">
</activity>

<activity
android:name=".TalkActivity"
android:exported="false">
</activity>

android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="false"></activity>
<activity
android:name=".FragmentActivity"
android:exported="false"></activity>
<activity
android:name=".WeatherActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.example.gdsc

import androidx.annotation.DrawableRes
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class MemberDto(
@SerialName("img")
val image: String,
val image: Int,
@SerialName("name")
val name: String
)
14 changes: 7 additions & 7 deletions app/src/main/java/com/example/gdsc/TalkAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView

class TalkAdapter :
ListAdapter<Talker, TalkAdapter.IntroductionViewHolder>(IntroductionDiffCallback()) {
ListAdapter<MemberDto, TalkAdapter.IntroductionViewHolder>(IntroductionDiffCallback()) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IntroductionViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item, parent, false)
Expand All @@ -28,21 +28,21 @@ class TalkAdapter :
private val memberName = view.findViewById<TextView>(R.id.tv_member_name)
private val memberTalk = view.findViewById<TextView>(R.id.tv_talk)
private val talkNumber = view.findViewById<Button>(R.id.btn_number)
fun bind(member: Talker) {
fun bind(member: MemberDto) {
memberImage.setImageDrawable(view.context.getDrawable(member.image))
memberName.text = member.name
memberTalk.text = member.talk
talkNumber.text = member.number
//memberTalk.text = member.talk
// talkNumber.text = member.number
}
}
}

class IntroductionDiffCallback : DiffUtil.ItemCallback<Talker>() {
override fun areItemsTheSame(oldItem: Talker, newItem: Talker): Boolean {
class IntroductionDiffCallback : DiffUtil.ItemCallback<MemberDto>() {
override fun areItemsTheSame(oldItem: MemberDto, newItem: MemberDto): Boolean {
return oldItem.name == newItem.name
}

override fun areContentsTheSame(oldItem: Talker, newItem: Talker): Boolean {
override fun areContentsTheSame(oldItem: MemberDto, newItem: MemberDto): Boolean {
return oldItem == newItem
}
}
39 changes: 39 additions & 0 deletions app/src/main/java/com/example/gdsc/WeatherActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.gdsc

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.example.gdsc.databinding.ActivityWeatherBinding
import retrofit2.Call
import retrofit2.Response

class WeatherActivity : AppCompatActivity() {
private lateinit var weatherBinding: ActivityWeatherBinding
private val getWeatherService = WeatherServicePool.getWeather
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
weatherBinding = ActivityWeatherBinding.inflate(layoutInflater)
setContentView(weatherBinding.root)
getWeatherApi()
}
private fun getWeatherApi() {
getWeatherService.getWeather().enqueue(object : retrofit2.Callback<WeatherDTO> {
override fun onResponse(
call: Call<WeatherDTO>, response: Response<WeatherDTO>
) {
if (response.isSuccessful) {
response.body()?.let {
weatherBinding.tvLog.text = response.body().toString()
Log.d("result", it.toString())
}
} else {
Log.d("error", "실패한 응답")
}
}

override fun onFailure(call: Call<WeatherDTO>, t: Throwable) {
t.message?.let { Log.d("error", it) } ?: "서버통신 실패(응답값 X)"
}
})
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/example/gdsc/WeatherApiFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.gdsc

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit

object WeatherApiFactory {
private const val BASE_URL =
"apis.data.go.kr/1360000/VilageFcstInfoService_2.0/"

val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}
}

object WeatherServicePool {
val getWeather = WeatherApiFactory.retrofit.create(WeatherApiService::class.java)
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/example/gdsc/WeatherApiService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.gdsc

import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query

interface WeatherApiService {
@GET("getUltraSrtNcst?serviceKey=Hz43%2FMh9cPK9LXQADpM12FtbTkugl4sCSu42kuk%2F%2BKQdx9EzFNhjmMevlwqfKXfcBB6a61xx97buoKe4f9OYHg%3D%3D")
fun getWeather(
@Query("numOfRows") numOfRows: Int = 1,
@Query("pageNo") pageNo: Int = 1,
@Query("dataType") dataType: String = "JSON",
@Query("baseDate") baseDate: String = "20231113",
@Query("baseTime") baseTime: String = "0600",
@Query("nx") nx: Int = 55,
@Query("ny") ny: Int = 127
): Call<WeatherDTO>
}


55 changes: 55 additions & 0 deletions app/src/main/java/com/example/gdsc/WeatherDTO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.example.gdsc
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class WeatherDTO(
@SerialName("response")
val response: Response
)
@Serializable
data class Response(
@SerialName("header")
val header: Header,
@SerialName("body")
val body: Body
)
@Serializable
data class Header(
@SerialName("resultCode")
val resultCode: String,
@SerialName("resultMsg")
val resultMsg: String
)
@Serializable
data class Body(
@SerialName("dataType")
val dataType: String,
@SerialName("items")
val items: Items,
@SerialName("pageNo")
val pageNo: Int,
@SerialName("numOfRows")
val numOfRows: Int,
@SerialName("totalCount")
val totalCount: Int
)
@Serializable
data class Items(
@SerialName("item")
val item: List<Item>
)
@Serializable
data class Item(
@SerialName("baseDate")
val baseDate: String,
@SerialName("baseTime")
val baseTime: String,
@SerialName("category")
val category: String,
@SerialName("nx")
val nx: Int,
@SerialName("ny")
val ny: Int,
@SerialName("obsrValue")
val obsrValue: String
)
Binary file added app/src/main/res/drawable/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/week5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_weather.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WeatherActivity">

<TextView
android:id="@+id/tv_log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="333dp"
android:gravity="center"
android:text="로그 결과값"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>