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

7주차 미션 / 안드로이드 2조 황지영 #10

Open
wants to merge 14 commits into
base: jiyoung
Choose a base branch
from
Open
12 changes: 10 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import org.jetbrains.kotlin.storage.CacheResetOnProcessCanceled.enabled
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
}

android {
namespace = "com.example.carrotmarket"
compileSdk = 33
compileSdk = 34

buildFeatures {
viewBinding = true
Expand Down Expand Up @@ -44,9 +45,16 @@ dependencies {

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
implementation("com.google.android.material:material:1.8.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation ("com.github.bumptech.glide:glide:4.13.0")
annotationProcessor ("com.github.bumptech.glide:compiler:4.13.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

//RoomDB
implementation("androidx.room:room-runtime:2.6.0")
annotationProcessor("androidx.room:room-compiler:2.6.0")
kapt("androidx.room:room-compiler:2.6.0")
}
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools" >

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

<application
android:allowBackup="true"
Expand All @@ -11,7 +13,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
tools:targetApi="31" >
<activity
android:name=".AlarmActivity"
android:exported="false" />
Expand All @@ -20,7 +22,7 @@
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/example/carrotmarket/AlarmActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.carrotmarket.databinding.ActivityAlarmBinding
import com.example.carrotmarket.databinding.ActivityStuffInfoBinding
import com.google.android.material.tabs.TabLayoutMediator

class AlarmActivity : AppCompatActivity() {
//View binding 적용
lateinit var binding : ActivityAlarmBinding
private val tablist = arrayListOf("활동 알림", "키워드 알림")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_alarm)
binding = ActivityAlarmBinding.inflate(layoutInflater)

initView()

//기능 추가
//뒤로 가기 아이콘 선택하면 HomeFragment 페이지로 넘어가도록 설정
binding.tvAlarmPreviousArrow.setOnClickListener {
Expand All @@ -22,4 +26,13 @@ class AlarmActivity : AppCompatActivity() {


}

private fun initView() {
binding.alarmMainVp.adapter = AlarmTabLayoutVPAdapter(this)

TabLayoutMediator(binding.alarmMainTb, binding.alarmMainVp){tab, position ->
tab.text = tablist[position]

}.attach()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.carrotmarket

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter

class AlarmTabLayoutVPAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
override fun getItemCount(): Int = 2

override fun createFragment(position: Int): Fragment {
return when(position){
0 -> ExerciseAlarmFragment()
else -> KeywordAlarmFragment()
}
}

}
28 changes: 28 additions & 0 deletions app/src/main/java/com/example/carrotmarket/ExerciseAlarmAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.carrotmarket

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.carrotmarket.databinding.ItemExerciseAlarmBinding

class ExerciseAlarmAdapter(val exerciseList : ArrayList<ExerciseAlarmDataClass>) : RecyclerView.Adapter<ExerciseAlarmAdapter.ViewHolder>() {

inner class ViewHolder(val binding: ItemExerciseAlarmBinding) : RecyclerView.ViewHolder(binding.root){
fun bind(exerciseInfo : ExerciseAlarmDataClass){
binding.tvExerciseAlarmTitle.text = exerciseInfo.exerciseAlarmTitle
binding.tvExerciseAlarmMeet.text = exerciseInfo.exerciseAlarmMeet
binding.tvExerciseAlarmTime.text = exerciseInfo.exerciseAlarmTime
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExerciseAlarmAdapter.ViewHolder {
val binding = ItemExerciseAlarmBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return ViewHolder(binding)
}

override fun onBindViewHolder(holder: ExerciseAlarmAdapter.ViewHolder, position: Int) {
holder.bind(exerciseList[position])
}

override fun getItemCount(): Int = exerciseList.size

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.carrotmarket

data class ExerciseAlarmDataClass(
var exerciseAlarmTitle : String,
var exerciseAlarmMeet : String,
var exerciseAlarmTime : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.carrotmarket

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.carrotmarket.databinding.FragmentExerciseAlarmBinding

class ExerciseAlarmFragment : Fragment() {

private lateinit var binding : FragmentExerciseAlarmBinding
private var exerciseAdapter : ExerciseAlarmAdapter?= null
private var exerciseList : ArrayList<ExerciseAlarmDataClass> = arrayListOf()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentExerciseAlarmBinding.inflate(layoutInflater)

initExerciseRecyclerView()
initInfoExample()
return binding.root
}

private fun initInfoExample() {
exerciseList.addAll(
arrayListOf(
ExerciseAlarmDataClass("황졍민님, 아직 당근마켓 새 이름을 모르시나요?","새로워진 당신 근처의 당근을 만나보세요","하루 전"),
ExerciseAlarmDataClass("💌 10월 가계부가 도착했어요!","#당근 #당근가계부 #자원재순환 #따뜻한 거래","3일 전"),
ExerciseAlarmDataClass("황졍민님, 동네생활에 댓글을 작성하셨네요!","더 많은 활동을 통해 '동네 활동가'에 도전해보세요.","3주전"),
ExerciseAlarmDataClass("황졍민님, 동네생활 이웃에게 공감을 받으셨네요!","더 많은 활동을 통해 '동네 활동가'에 도전해보세요","4주전"),
ExerciseAlarmDataClass("🎉황졍민님, 축하합니다! 동네 산책 배지를 획득했어요. 지금 확인해보세요."," ","5주전"),
ExerciseAlarmDataClass("황졍민님, 동네생활에 글을 작성하셨네요!","더 많은 활동을 통해 '동네 활동가'에 도전해보세요.","6주전"),
ExerciseAlarmDataClass("나눔을 실천하시는 황졍민님께 소식 도착🧡","10월은 나눔의 날, 쌀쌀해진 날을 따뜻하게 만든 나눔 사연을 전해요","7주전"),
ExerciseAlarmDataClass("\uD83D\uDC8C9월 가계부가 도착했어요!","#당근 #당근가계부 #자원재순환 #따뜻한 거래","8주전")
)
)
}

private fun initExerciseRecyclerView() {
exerciseAdapter = ExerciseAlarmAdapter(exerciseList)
binding.rvExerciseAlarm.adapter = exerciseAdapter
binding.rvExerciseAlarm.layoutManager = LinearLayoutManager(requireContext(),
LinearLayoutManager.VERTICAL, false)
}

}
82 changes: 74 additions & 8 deletions app/src/main/java/com/example/carrotmarket/HomeFragment.kt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,99 @@ 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.carrotmarket.databinding.FragmentHomeBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class HomeFragment : Fragment() {
lateinit var binding: FragmentHomeBinding

//프로퍼티로 productlist 만듦
var productList:ArrayList<MyProduct> = arrayListOf()

//DB 객체 만듦
var myProducrDatabase : MyProductDatabase ?= null

//만든 ProductAdapter 활용
private var productAdapter:ProductAdapter?=null

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentHomeBinding.inflate(layoutInflater)

//기능 추가
//상품 아이템 박스 선택하면 상세 상품 페이지로 넘어가도록 설정
binding.clItem1.setOnClickListener {
val intent = Intent(requireContext(), StuffInfoActivity::class.java)
startActivity(intent)
}

//알람 아이콘 선택하면 알람 페이지로 넘어가도록 설정
binding.ivHomeAlarm.setOnClickListener {
val intent = Intent(requireContext(), AlarmActivity::class.java)
startActivity(intent)
}

//데이터베이스 가져오기
myProducrDatabase = MyProductDatabase.getInstance(requireContext())
return binding.root

}

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

CoroutineScope(Dispatchers.IO).launch {
//Homefragment의 Product(데이터)를 구성하는 함수
initProduct()
val products = myProducrDatabase!!.getMyProductDAO().getMyProducts()

withContext(Dispatchers.Main){
(binding.rvProduct.adapter as ProductAdapter).setData(products)
}

}
//ProductAdapter에 대한 작업
initRecyclerView()
}



private fun initRecyclerView() {
productAdapter = ProductAdapter(productList)

//binding의 rv_Product의 adapter를 만들어 놓은 productAdapter로 설정
binding.rvProduct.adapter = productAdapter

//layoutmanager을 사용해서 Vertical = 세로 형태로 레이아웃을 출력하기 위해 orientation 설정
binding.rvProduct.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL,false)

//productAdapter에 setOnItemClickListener 호출
productAdapter!!.setOnItemClickListener(object :ProductAdapter.OnItemClickListener{
override fun onItemClick(myProductEntity: MyProduct) {
//item 클릭했을 때 상세화면으로 전환
val intent = Intent(requireContext(), StuffInfoActivity::class.java)
//상세 product에 대한 데이터 전송
intent.putExtra("key",myProductEntity)
startActivity(intent)
}
})

}

private fun initProduct() {
myProducrDatabase!!.getMyProductDAO().addMyProduct(
MyProduct("생귤탱귤 제주 감귤 판매🍊","서귀포시","끌올 1분 전","20,000원","6","5" , R.drawable.image)
)

// MyProduct("생귤탱귤 제주 감귤 판매🍊","서귀포시","끌올 1분 전","20,000원","6","5" , R.drawable.image),
// MyProduct("급처) 러쉬 스프레이","계양구 계산동", "끌올 1분 전","10,000원","8","11" , R.drawable.img_1),
// MyProduct("미니 고데기(거의 새거)✨","계양구 작전동", "8초 전","10,000원","0","4" , R.drawable.img_3),
// MyProduct("🧡9월 이달의 아트🧡","원종동","5분 전","40,000원","6","5" , R.drawable.img_4),
// MyProduct("코닥 필름카메라","작동","41분 전","10,000원","1","1" , R.drawable.img_5),
// MyProduct("조말론 블랙베리 향수 100ml","서울특별시 양천구","2시간 전","130,000원","2","1" , R.drawable.img_11),
// MyProduct("한성 키보드","서울특별시 강서구","8시간 전","90,000원","4","5" , R.drawable.img_7),
// MyProduct("하늘색 플레어 스커트","부평구 삼산동", "4시간 전","20,000원","3","7" , R.drawable.img_9)

}

Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/example/carrotmarket/KeywordAlarmAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.carrotmarket

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.carrotmarket.databinding.ItemKeywordAlarmBinding

class KeywordAlarmAdapter(val keywordList : ArrayList<KeywordAlarmDataClass>) : RecyclerView.Adapter<KeywordAlarmAdapter.ViewHolder>() {

inner class ViewHolder(val binding : ItemKeywordAlarmBinding) : RecyclerView.ViewHolder(binding.root){

fun bind(keywordInfo : KeywordAlarmDataClass){
binding.tvKeywordAlarmTitle.text = keywordInfo.keywordAlarmTitle
binding.tvKeywordAlarmMeet.text = keywordInfo.keywordAlarmMeet
binding.tvKeywordAlarmTime.text = keywordInfo.keywordAlarmTime
}
}

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): KeywordAlarmAdapter.ViewHolder {
val binding = ItemKeywordAlarmBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return ViewHolder(binding)
}

override fun onBindViewHolder(holder: KeywordAlarmAdapter.ViewHolder, position: Int) {
holder.bind(keywordList[position])
}

override fun getItemCount(): Int = keywordList.size
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.carrotmarket

data class KeywordAlarmDataClass(
var keywordAlarmTitle : String,
var keywordAlarmMeet : String,
var keywordAlarmTime : String
)
Loading