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

최종 기능 구현 #6

Open
wants to merge 6 commits into
base: final
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
10 changes: 10 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
id("kotlin-kapt")
id("com.google.gms.google-services")

}

android {
Expand Down Expand Up @@ -51,6 +53,14 @@ dependencies {
// SendBird 라이브러리 추가
implementation(libs.sendbird.chat)

// Firebase 라이브러리 추가
implementation(platform("com.google.firebase:firebase-bom:33.1.2"))
implementation("com.google.firebase:firebase-analytics")

// Firebase Database 라이브러리 추가
implementation(platform("com.google.firebase:firebase-bom:32.3.1"))
implementation("com.google.firebase:firebase-database-ktx")

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
Expand Down
29 changes: 29 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "878525628040",
"project_id": "manolja-ef51e",
"storage_bucket": "manolja-ef51e.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:878525628040:android:d0bb43763de81365eba93d",
"android_client_info": {
"package_name": "com.example.manolja"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAlWZzeOgPSr_KOxMBDFCeMVhWeWBnCNBs"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:name=".MyApplication"
android:allowBackup="true"
Expand All @@ -12,9 +13,16 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Manolja"
android:theme="@style/AppTheme"
tools:targetApi="31">

<activity
android:name=".ui.activity.ChatActivity"
android:exported="false">
</activity>
<activity
android:name=".ui.activity.CertActivity"
android:exported="false">
</activity>
<activity
android:name=".ui.activity.MainActivity"
android:exported="true">
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/manolja/data/Coupon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.manolja.data

data class Coupon(
val name: String,
val location: String,
val discount: String,
val content: String
)
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/manolja/data/Message.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.manolja.data

data class Message(
val sender: String = "",
val text: String = "",
val timestamp: Long = System.currentTimeMillis(),
val isCurrentUser: Boolean = false
)
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/manolja/data/Quest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.manolja.data

data class Quest(
val name: String,
val location: String,
val reward: String
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package data
package com.example.manolja.data

data class RecordItem(
val date: String,
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/manolja/domain/Coupon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.manolja.domain

data class Coupon(
val name: String,
val location: String,
val discount: String,
val content: String
)
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/manolja/domain/Message.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.manolja.domain

data class Message(
val sender: String = "",
val text: String = "",
val timestamp: Long = System.currentTimeMillis(),
val isCurrentUser: Boolean = false
)
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/manolja/domain/Quest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.manolja.domain

data class Quest(
val name: String,
val location: String,
val reward: String
)
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/manolja/domain/RecordItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.manolja.domain

data class RecordItem(
val date: String,
var caption: String,
val imageUrl: String
)
93 changes: 93 additions & 0 deletions app/src/main/java/com/example/manolja/ui/activity/CertActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.example.manolja.ui.activity

import android.app.ProgressDialog
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.manolja.R
import java.io.IOException

class CertActivity : AppCompatActivity() {

private val PICK_IMAGE_REQUEST = 1
private lateinit var imageViewPreview: ImageView
private var imageUri: Uri? = null
private lateinit var progressDialog: ProgressDialog

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cert)

imageViewPreview = findViewById(R.id.imageViewPreview)
val buttonUpload: Button = findViewById(R.id.buttonUpload)
val buttonConfirm: Button = findViewById(R.id.buttonConfirm)
val buttonCancel: Button = findViewById(R.id.buttonCancel)

// ProgressDialog 초기화
progressDialog = ProgressDialog(this).apply {
setMessage("인증 중...")
setCancelable(false)
}

// 사진 업로드 버튼 클릭 리스너
buttonUpload.setOnClickListener { openFileChooser() }

// 확인 버튼 클릭 리스너
buttonConfirm.setOnClickListener {
if (imageUri != null) {
// 로딩 창 표시
progressDialog.show()

// 사진 업로드 로직 구현 (예: 서버에 업로드)
// 여기서는 업로드가 완료된 후 로직을 직접 호출합니다.
uploadImageAndFinish()
} else {
Toast.makeText(this, "사진을 선택해 주세요.", Toast.LENGTH_SHORT).show()
}
}

// 취소 버튼 클릭 리스너
buttonCancel.setOnClickListener { finish() } // 액티비티 종료
}

private fun openFileChooser() {
val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
intent.type = "image/*"
startActivityForResult(intent, PICK_IMAGE_REQUEST)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.data != null) {
imageUri = data.data
try {
val bitmap: Bitmap = MediaStore.Images.Media.getBitmap(contentResolver, imageUri)
imageViewPreview.setImageBitmap(bitmap)
} catch (e: IOException) {
e.printStackTrace()
}
}
}

private fun uploadImageAndFinish() {
// 업로드 시뮬레이션을 위해 3초 지연
Handler(Looper.getMainLooper()).postDelayed({
// 로딩 창 닫기
progressDialog.dismiss()

// 결과 전달: 인증 성공
val resultIntent = Intent()
resultIntent.putExtra("upload_success", true)
setResult(RESULT_OK, resultIntent)
finish() // CertActivity 종료
}, 3000) // 3000ms = 3초
}
}
89 changes: 89 additions & 0 deletions app/src/main/java/com/example/manolja/ui/activity/ChatActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.example.manolja.ui.activity

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.manolja.R
import com.example.manolja.domain.Message
import com.example.manolja.ui.adapter.MessageAdapter
import com.google.firebase.database.*

class ChatActivity : AppCompatActivity() {

private lateinit var messageRecyclerView: RecyclerView
private lateinit var messageAdapter: MessageAdapter
private lateinit var messageInput: EditText
private lateinit var sendButton: Button

private lateinit var database: DatabaseReference
private lateinit var messages: MutableList<Message>
private val currentUser = "김정희"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_chat)

messageRecyclerView = findViewById(R.id.message_recycler_view)
messageInput = findViewById(R.id.message_input)
sendButton = findViewById(R.id.send_button)

messages = mutableListOf()
messageAdapter = MessageAdapter(messages)
messageRecyclerView.layoutManager = LinearLayoutManager(this)
messageRecyclerView.adapter = messageAdapter

// Firebase 데이터베이스 참조 설정
database = FirebaseDatabase.getInstance().getReference("messages")

// 메시지 전송 버튼 클릭 리스너
sendButton.setOnClickListener {
val text = messageInput.text.toString().trim()
if (text.isNotEmpty()) {
sendMessage(text)
}
}

// Firebase 데이터베이스에서 메시지 불러오기
loadMessages()
}

private fun loadMessages() {
database.addChildEventListener(object : ChildEventListener {
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
val message = snapshot.getValue(Message::class.java)
message?.let {
val isCurrentUser = it.sender == currentUser
val newMessage = it.copy(isCurrentUser = isCurrentUser)
messages.add(newMessage)
messageAdapter.notifyItemInserted(messages.size - 1)
messageRecyclerView.scrollToPosition(messages.size - 1)
}
}

override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {
// 메시지가 수정된 경우 처리
}

override fun onChildRemoved(snapshot: DataSnapshot) {
// 메시지가 삭제된 경우 처리
}

override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {
// 메시지가 이동된 경우 처리
}

override fun onCancelled(error: DatabaseError) {
// 데이터 로드 취소 시 처리할 코드
}
})
}

private fun sendMessage(text: String) {
val message = Message(sender = currentUser, text = text, isCurrentUser = true)
database.push().setValue(message)
messageInput.text.clear()
}
}
41 changes: 41 additions & 0 deletions app/src/main/java/com/example/manolja/ui/adapter/MessageAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.manolja.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.manolja.R
import com.example.manolja.domain.Message

class MessageAdapter(private val messages: List<Message>) : RecyclerView.Adapter<MessageAdapter.MessageViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder {
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
return MessageViewHolder(view)
}

override fun onBindViewHolder(holder: MessageViewHolder, position: Int) {
val message = messages[position]
holder.bind(message)
}

override fun getItemCount(): Int = messages.size

override fun getItemViewType(position: Int): Int {
val message = messages[position]
return if (message.isCurrentUser) R.layout.item_message_right else R.layout.item_message_left
}

class MessageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val messageText: TextView = itemView.findViewById(R.id.message_text)
private val messageTime: TextView = itemView.findViewById(R.id.message_time)
private val messageSender: TextView = itemView.findViewById(R.id.message_sender)

fun bind(message: Message) {
messageText.text = message.text
messageTime.text = android.text.format.DateFormat.format("HH:mm", message.timestamp)
messageSender.text = message.sender
}
}
}
Loading