Skip to content
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
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

329 changes: 0 additions & 329 deletions .idea/other.xml

This file was deleted.

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {

defaultConfig {
applicationId = "com.example.whatsub"
minSdk = 33
minSdk = 29
targetSdk = 33
versionCode = 1
versionName = "1.0"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- // WebView나 네크워크 관련 작업을 위한 인터넷 권한-->
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -23,6 +26,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".NewsDetailActivity"
android:label="News Detail">
</activity>

</application>

</manifest>
73 changes: 73 additions & 0 deletions app/src/main/java/com/example/whatsub/HeadlinesFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.example.whatsub

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.whatsub.databinding.FragmentHeadlinesBinding

class HeadlinesFragment : Fragment() {

private var _binding: FragmentHeadlinesBinding? = null
private val binding get() = _binding!!

private val newsList = listOf(
News("비싼 월세와 고물가에 지갑 닫은 '1인 가구'... \"소비 회복 제약\"", "Economy", "https://n.news.naver.com/mnews/article/469/0000836610"),
News("‘전원 재계약’ (여자)아이들 민니, 데뷔 첫 솔로 데뷔..“1월 발매 목표” [공식입장]", "Entertainment", "https://m.entertain.naver.com/article/109/0005206649"),
News("통영 내리막길서 15톤 덤프트럭과 승용차 '쾅'…14중 추돌 사고", "Society", "https://n.news.naver.com/article/031/0000890030"),
News("'충격의 대반전' SON에 손뗐다던 바르셀로나, 사실 손흥민 영입에 진심...파티+토레스 정리해 연봉 마련 계획", "Sports", "https://m.sports.naver.com/wfootball/article/076/0004222656"),
News("'탐욕스러운 노이어, 쓸데없이 또 튀어나왔다'…19년 만의 첫 퇴장, 볼 대신 상대 선수 가격", "Sports", "https://m.sports.naver.com/wfootball/article/117/0003893679"),
News("[단독] 韓 '양자인터넷' 시동…\"내년초 100㎞ 전송시연\"", "Technology", "https://n.news.naver.com/mnews/article/011/0004422632"),
News("현대차·기아, 11월 美판매 2개월 연속 두자릿수 증가(종합)", "Economy", "https://n.news.naver.com/mnews/article/001/0015084009"),
News("ETRI, 노코드 신경망 자동생성 프레임워크 공개...세미나 사전신청만 500명 넘어", "Technology", "https://n.news.naver.com/mnews/article/092/0002355064"),
News("AWS, 공유 정책 폐지…MSP \"멀티클라우드 기조 견제\"", "Technology", "https://n.news.naver.com/mnews/article/092/0002355060"),
News("유네스코, '한국 장 담그기 문화' 인류무형문화유산 등재", "Society", "https://n.news.naver.com/mnews/article/008/0005123173"),
)

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentHeadlinesBinding.inflate(inflater, container, false)

// RecyclerView 설정
val newsAdapter = NewsAdapter(newsList) { news ->
//뉴스 클릭 시 뉴스 URL 전달
val intent = Intent(context, NewsDetailActivity::class.java).apply {
putExtra("newsTitle", news.title)
putExtra("newsUrl", news.url) // 여기서 URL을 전달
}
startActivity(intent)
}

//RecyclerView에 Adapter 연결
binding.recyclerView.adapter = newsAdapter

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val adapter = NewsAdapter(newsList) { news ->
// 뉴스 항목 클릭 시 NewsDetailActivity로 데이터 전달
val intent = Intent(context, NewsDetailActivity::class.java).apply {
putExtra("newsTitle", news.title)
putExtra("newsUrl", news.url)
}
startActivity(intent) // NewsDetailActivity로 이동
}

binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
38 changes: 38 additions & 0 deletions app/src/main/java/com/example/whatsub/NewsAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.whatsub

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

data class News(val title: String, val description: String, val url: String)

class NewsAdapter(
private val newsList: List<News>,
private val onItemClick: (News) -> Unit
) : RecyclerView.Adapter<NewsAdapter.NewsViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NewsViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(android.R.layout.simple_list_item_2, parent, false)
return NewsViewHolder(view)
}

override fun onBindViewHolder(holder: NewsViewHolder, position: Int) {
val news = newsList[position]
holder.titleTextView.text = news.title
holder.descriptionTextView.text = news.description
holder.itemView.setOnClickListener { onItemClick(news) }
}

override fun getItemCount(): Int {
return newsList.size
}

class NewsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val titleTextView: TextView = itemView.findViewById(android.R.id.text1)
val descriptionTextView: TextView = itemView.findViewById(android.R.id.text2)
}
}
60 changes: 60 additions & 0 deletions app/src/main/java/com/example/whatsub/NewsDetailActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.example.whatsub

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import com.example.whatsub.databinding.ActivityNewsDetailBinding

class NewsDetailActivity : AppCompatActivity() {
private lateinit var binding: ActivityNewsDetailBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityNewsDetailBinding.inflate(layoutInflater)
setContentView(binding.root)

// 뉴스 제목 설정
val newsTitle = intent.getStringExtra("newsTitle")
// newsTitle 값이 null이면 로그로 확인
Log.d("NewsDetailActivity", "newsTitle: $newsTitle")
binding.newsTitle.text = newsTitle

// WebView로 기사 URL 열기
val newsUrl = intent.getStringExtra("newsUrl")
// newsUrl 값이 null이면 로그로 확인
Log.d("NewsDetailActivity", "newsUrl: $newsUrl")

// URL이 null이 아니면 WebView로 로드
if (newsUrl != null) {
binding.webView.apply {
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
view?.loadUrl(request?.url.toString())
return true
}

override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: android.webkit.WebResourceError?
) {
super.onReceivedError(view, request, error)
Log.e("NewsDetailActivity", "WebView error: ${error?.description}")
}

override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
Log.d("NewsDetailActivity", "Page finished loading: $url")
}
}
loadUrl(newsUrl)
}
}
}
}
30 changes: 30 additions & 0 deletions app/src/main/res/layout/activity_news_detail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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=".NewsDetailActivity">

<TextView
android:id="@+id/newsTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="@android:color/black"
android:layout_margin="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<WebView
android:id="@+id/webView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/newsTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
20 changes: 20 additions & 0 deletions app/src/main/res/layout/fragment_headlines.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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=".HeadlinesFragment">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/mobile_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<fragment
android:id="@+id/navigation_news"
android:name="com.example.whatsub.ui.news.NewsFragment"
android:name="com.example.whatsub.HeadlinesFragment"
android:label="News"
tools:layout="@layout/fragment_news" />
</navigation>
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.5.1"
agp = "8.7.3"
kotlin = "1.9.0"
coreKtx = "1.13.1"
junit = "4.13.2"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Nov 30 17:46:43 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists