작성
·
214
0
package com.example.mango_content
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class MainActivity : AppCompatActivity() {
//데이터 넣을 리스트 변수 생성
private val items = mutableListOf<ContentsModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 리스트 데이터
// 데이터 클래스이기 때문에 차례대로 넣을 값만 넣어주면 된다
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/Quiver/shopPhotoList",
"https://image.toast.com/aaaaaqx/rv/s4XU7ZHko4NjDEkULtFHbAA/231108173855775(0).jpeg",
"퀴버(Quiver)"
)
)
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/bistrogama/shopPhotoList?pickup-date=231207&pickup-time=0342",
"https://image.toast.com/aaaaaqx/catchtable/shopinfo/s23522/23522_2221020170729696.jpg?detail750",
"비스트로 가마"
)
)
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/cucciolo_seoul/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0346",
"https://ugc-images.catchtable.co.kr/rv/s7YDg2g4TxcuMPb-Eds2nKQ/4179dd6517aa48e1900c08e8c9c769a5",
"쿠촐로 서울"
)
)
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/schedule_seongsu/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0352",
"https://ugc-images.catchtable.co.kr/rv/sXGZ4Ldt3lvBgj3V-4rxIsQ/e6ce38eef9ee412ca63da36dacabc57a",
"스케줄 성수"
)
)
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/Quiver/shopPhotoList",
"https://image.toast.com/aaaaaqx/rv/s4XU7ZHko4NjDEkULtFHbAA/231108173855775(0).jpeg",
"퀴버(Quiver)"
)
)
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/bistrogama/shopPhotoList?pickup-date=231207&pickup-time=0342",
"https://image.toast.com/aaaaaqx/catchtable/shopinfo/s23522/23522_2221020170729696.jpg?detail750",
"비스트로 가마"
)
)
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/cucciolo_seoul/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0346",
"https://ugc-images.catchtable.co.kr/rv/s7YDg2g4TxcuMPb-Eds2nKQ/4179dd6517aa48e1900c08e8c9c769a5",
"쿠촐로 서울"
)
)
items.add(
ContentsModel(
"https://app.catchtable.co.kr/ct/shop/schedule_seongsu/shopPhotoList?type=VISIT_RESERVATION&pickup-date=231207&pickup-time=0352",
"https://ugc-images.catchtable.co.kr/rv/sXGZ4Ldt3lvBgj3V-4rxIsQ/e6ce38eef9ee412ca63da36dacabc57a",
"스케줄 성수"
)
)
val recyclerview = findViewById<RecyclerView>(R.id.rv)
val rvAdapter = RVAdapter(baseContext,items)
recyclerview.adapter = rvAdapter
// 아이템 클릭 처리
rvAdapter.itemClick = object : RVAdapter.ItemClick {
override fun onClick(view: View, position: Int) {
val intent = Intent(baseContext, ViewActivity::class.java)
intent.putExtra("url", items[position].url )
startActivity(intent)
}
}
recyclerview.layoutManager = GridLayoutManager(this,2)
}
}
MainActivity.kt
package com.example.mango_content
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.view.menu.MenuView.ItemView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bumptech.glide.Glide
//viewmodel을 받을 것임
class RVAdapter(val context: Context, val List: MutableList<ContentsModel>) : RecyclerView.Adapter<RVAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RVAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.rv_item, parent, false)
return ViewHolder(v)
}
// 웹뷰 클릭 이벤트 생성
interface ItemClick {
fun onClick(view : View, position: Int)
}
var itemClick : ItemClick? = null
override fun onBindViewHolder(holder: RVAdapter.ViewHolder, position: Int) {
if (itemClick != null) {
holder.itemView.setOnClickListener {
v -> itemClick!!.onClick(v, position)
}
}
holder.bindItems(List[position])
}
override fun getItemCount(): Int {
return List.size
}
inner class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(item : ContentsModel) {
val rv_img = itemView.findViewById<ImageView>(R.id.rvImageArea)
val rv_text = itemView.findViewById<TextView>(R.id.rvTextArea)
rv_text.text = item.titleText
Glide.with(context)
.load(item.imageUrl)
.into(rv_img)
}
}
}
RVAdapter.kt
package com.example.mango_content
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
class ViewActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_view)
val webView = findViewById<WebView>(R.id.webView)
webView.loadUrl(intent.getStringExtra("url").toString())
}
}
ViewActivity.kt
<?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"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Mango_content"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".ViewActivity"
android:exported="false" />
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true"></activity>
</application>
</manifest>
manifest.xml
실행 했을 시, 다음과 같은 오류가 일어납니다.
망고플레이트가 서버 종료되어서 저는 캐치테이블 사이트를 이용하였습니다.
오류 구글링하여 매니패스트에
android:usesCleartextTraffic="true"
도 추가 하였는데 그대로 오류나서 질문 드립니다. ㅠㅠ