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

Android #110

Merged
merged 14 commits into from
Mar 16, 2024
Merged
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
Binary file added .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.8.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation ("androidx.drawerlayout:drawerlayout:1.2.0")
implementation("com.google.android.gms:play-services-auth:20.7.0")
implementation("com.google.firebase:firebase-auth-ktx:22.3.1")
implementation("com.google.firebase:firebase-firestore:24.10.1")
implementation("com.google.firebase:firebase-storage-ktx:20.3.0")

implementation ("com.squareup.retrofit2:retrofit:2.9.0")
implementation ("com.squareup.retrofit2:converter-gson:2.9.0")
implementation ("com.squareup.retrofit2:adapter-rxjava2:2.9.0")

implementation ("androidx.preference:preference-ktx:1.1.1")
implementation ("pl.droidsonroids.gif:android-gif-drawable:1.2.19")


implementation ("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation ("com.github.bumptech.glide:glide:4.12.0")
implementation("androidx.preference:preference:1.2.1")
annotationProcessor ("com.github.bumptech.glide:compiler:4.12.0")

testImplementation("junit:junit:4.13.2")
Expand Down
22 changes: 15 additions & 7 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ShareNote"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".OrganizationActivity"
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=".NoteActivity"
android:exported="false" />
Expand All @@ -25,13 +39,7 @@
android:exported="false" />
<activity
android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="false" />
Expand Down
13 changes: 13 additions & 0 deletions android/app/src/main/java/com/example/sharenote/ApiService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.sharenote

import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST

interface ApiService {

// νšŒμ›κ°€μž…μ„ μ²˜λ¦¬ν•˜λŠ” POST μš”μ²­μ„ μ •μ˜ν•©λ‹ˆλ‹€.
@POST("signUp")
fun signUpUser(@Body userData: UserData): Call<Void>
}
196 changes: 195 additions & 1 deletion android/app/src/main/java/com/example/sharenote/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
import android.content.Intent
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.PopupWindow
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.sharenote.LoginActivity
import com.example.sharenote.Note
import com.example.sharenote.NoteActivity
import com.example.sharenote.OrganizationActivity
import com.example.sharenote.R
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import com.google.firebase.firestore.FirebaseFirestore

class HomeFragment : Fragment(), NoteListAdapter.OnNoteClickListener {

private lateinit var auth: FirebaseAuth
private lateinit var recyclerView: RecyclerView
private lateinit var noteListAdapter: NoteListAdapter
private lateinit var emailTextView: TextView
private lateinit var menuBtn: ImageButton
private lateinit var profileForm: RelativeLayout

private lateinit var emailTextView1: TextView
private lateinit var popupView: View // νŒμ—… λ·°
private lateinit var setting_circle: ImageView

private var notes: MutableList<Note> = mutableListOf()




override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -32,6 +51,47 @@ class HomeFragment : Fragment(), NoteListAdapter.OnNoteClickListener {
recyclerView.layoutManager = LinearLayoutManager(requireContext())
noteListAdapter = NoteListAdapter(notes, this)
recyclerView.adapter = noteListAdapter
menuBtn = view.findViewById(R.id.menuBtn)
profileForm = view.findViewById(R.id.profileForm)

// account_layout을 νŒμ—…μœΌλ‘œ μ‚¬μš©ν•˜κΈ° μœ„ν•΄ νŒμ—… λ·°λ₯Ό μ΄ˆκΈ°ν™”ν•©λ‹ˆλ‹€.
popupView = layoutInflater.inflate(R.layout.account_layout, null)
emailTextView1 = popupView.findViewById(R.id.email)

setting_circle = popupView.findViewById(R.id.setting_circle)



// emailTextViewλ₯Ό μ°ΎμŠ΅λ‹ˆλ‹€.
emailTextView = view.findViewById(R.id.emailtextView)



// μ‚¬μš©μž 이메일을 ν‘œμ‹œν•©λ‹ˆλ‹€.
displayUserEmail()

profileForm.setOnClickListener {
// account_layout을 ν™”λ©΄ μ•„λž˜μ— 절반 크기둜 λ³΄μ—¬μ€Œ
showPopupAccount()
}

// menuBtn을 ν΄λ¦­ν–ˆμ„ λ•Œ νŒμ—… 메뉴λ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€.
menuBtn.setOnClickListener {
showPopupMenu()
}



setting_circle.setOnClickListener {
showAccountMenuPopup()
}


// themesBtn 클릭 μ‹œ buttonCreateNote와 recyclerViewNotes의 κ°€μ‹œμ„±μ„ ν† κΈ€ν•©λ‹ˆλ‹€.
val themesBtn = view.findViewById<ImageButton>(R.id.themesBtn)
themesBtn.setOnClickListener {
toggleNotesVisibility(themesBtn)
}

// Create Note λ²„νŠΌ 클릭 μ‹œ NoteActivity둜 이동
val buttonCreateNote = view.findViewById<Button>(R.id.buttonCreateNote)
Expand All @@ -55,11 +115,131 @@ class HomeFragment : Fragment(), NoteListAdapter.OnNoteClickListener {
override fun onNoteClick(note: Note) {
val intent = Intent(requireContext(), NoteActivity::class.java)
intent.putExtra("note_id", note.id)
intent.putExtra("note_title", note.title)
intent.putExtra("note_text", note.text)
intent.putExtra("note_image_uri", note.imageUri)
startActivity(intent)
}


private fun showPopupAccount() {
// PopupWindow 생성
val popupWindow = PopupWindow(
popupView,
ViewGroup.LayoutParams.MATCH_PARENT,
1200,
true
)

popupWindow.isOutsideTouchable = true

// PopupWindowλ₯Ό ν‘œμ‹œν•  μœ„μΉ˜ μ„€μ • (μ•„λž˜μͺ½μ— ν‘œμ‹œ)
popupWindow?.showAtLocation(view, Gravity.BOTTOM, 0, 0)

// νŒμ—… μ°½μ—μ„œ 각 ν•­λͺ©μ„ 클릭할 λ•Œμ˜ λ™μž‘ μ •μ˜
val settingLayoutView = popupView.findViewById<RelativeLayout>(R.id.logoutLayout)
settingLayoutView.setOnClickListener {
auth.signOut()
val loginIntent = Intent(requireContext(), LoginActivity::class.java)
startActivity(loginIntent)
requireActivity().finish()
popupWindow.dismiss() // νŒμ—… μ°½ λ‹«κΈ°
}
}

private fun showAccountMenuPopup() {
val inflater = LayoutInflater.from(requireContext())
val popupView = inflater.inflate(R.layout.menu_account, null)

val popupWindow = PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)

// νŒμ—… 창이 ν™”λ©΄ λ°”κΉ₯을 ν„°μΉ˜ν•˜λ©΄ λ‹«νžˆλ„λ‘ μ„€μ •
popupWindow.isOutsideTouchable = true

// νŒμ—… 창을 클릭 κ°€λŠ₯ν•˜λ„λ‘ μ„€μ •
popupWindow.isFocusable = true

// νŒμ—… 창을 ν‘œμ‹œν•  μœ„μΉ˜ μ„€μ •
popupWindow.showAsDropDown(setting_circle) // settingCircleImageViewκ°€ 클릭된 μœ„μΉ˜μ— 따라 νŒμ—… 창이 ν‘œμ‹œλ©λ‹ˆλ‹€.

// μ›Œν¬μŠ€νŽ˜μ΄μŠ€ 생성 λ˜λŠ” μ°Έμ—¬ ν•­λͺ© 클릭 μ‹œ 처리
val workSpaceLayout = popupView.findViewById<RelativeLayout>(R.id.workSpaceLayout)
workSpaceLayout.setOnClickListener {
startActivity(Intent(requireContext(), OrganizationActivity::class.java))
popupWindow.dismiss() // νŒμ—… μ°½ λ‹«κΈ°
}

// λ‘œκ·Έμ•„μ›ƒ ν•­λͺ© 클릭 μ‹œ 처리
val logoutLayout = popupView.findViewById<RelativeLayout>(R.id.logout_Layout)
logoutLayout.setOnClickListener {
auth.signOut()
val loginIntent = Intent(requireContext(), LoginActivity::class.java)
startActivity(loginIntent)
requireActivity().finish()
popupWindow.dismiss() // νŒμ—… μ°½ λ‹«κΈ°
}
}


private fun showPopupMenu() {
val popupView = layoutInflater.inflate(R.layout.menu_layout, null)
val popupWindow = PopupWindow(
popupView,
700,
ViewGroup.LayoutParams.WRAP_CONTENT
)

// νŒμ—… 창이 ν™”λ©΄ λ°”κΉ₯을 ν„°μΉ˜ν•˜λ©΄ λ‹«νžˆλ„λ‘ μ„€μ •
popupWindow.isOutsideTouchable = true

// νŒμ—… 창을 뷰의 μ•„λž˜μ— ν‘œμ‹œ
popupWindow.showAsDropDown(menuBtn)

// νŒμ—… μ°½μ—μ„œ 각 ν•­λͺ©μ„ 클릭할 λ•Œμ˜ λ™μž‘ μ •μ˜
val settingLayoutView = popupView.findViewById<RelativeLayout>(R.id.settingLayout)
settingLayoutView.setOnClickListener {
// μ„€μ • 메뉴 클릭 μ‹œ μ‹€ν–‰ν•  μž‘μ—… μΆ”κ°€
popupWindow.dismiss() // νŒμ—… μ°½ λ‹«κΈ°
}

val memberLayoutView = popupView.findViewById<RelativeLayout>(R.id.memberLayout)
memberLayoutView.setOnClickListener {
// 멀버 메뉴 클릭 μ‹œ μ‹€ν–‰ν•  μž‘μ—… μΆ”κ°€
popupWindow.dismiss() // νŒμ—… μ°½ λ‹«κΈ°
}

val trashLayoutView = popupView.findViewById<RelativeLayout>(R.id.trashLayout)
trashLayoutView.setOnClickListener {
// νœ΄μ§€ν†΅ 메뉴 클릭 μ‹œ μ‹€ν–‰ν•  μž‘μ—… μΆ”κ°€
popupWindow.dismiss() // νŒμ—… μ°½ λ‹«κΈ°
}
}


private fun toggleNotesVisibility(themesBtn: ImageButton) {
// recyclerViewNotes의 κ°€μ‹œμ„±μ„ ν† κΈ€ν•©λ‹ˆλ‹€.
recyclerView.visibility = if (recyclerView.visibility == View.VISIBLE) {
View.GONE
} else {
View.VISIBLE
}

// themesBtn 이미지λ₯Ό λ³€κ²½ν•©λ‹ˆλ‹€.
val newImageResource = if (recyclerView.visibility == View.VISIBLE) {
R.drawable.baseline_keyboard_arrow_right_24 // ν† κΈ€ ν›„ recyclerViewκ°€ λ³΄μ΄λŠ” 경우
} else {
R.drawable.baseline_keyboard_arrow_down_24 // ν† κΈ€ ν›„ recyclerViewκ°€ μˆ¨κ²¨μ§„ 경우
}

// μƒˆλ‘œμš΄ μ΄λ―Έμ§€λ‘œ μ„€μ •ν•©λ‹ˆλ‹€.
themesBtn.setImageResource(newImageResource)
}


private fun createNote() {
val intent = Intent(requireContext(), NoteActivity::class.java)
startActivity(intent)
Expand All @@ -73,9 +253,10 @@ class HomeFragment : Fragment(), NoteListAdapter.OnNoteClickListener {
notes.clear()
for (document in result) {
val noteID = document.getString("id") ?: ""
val noteTitle = document.getString("title") ?:""
val noteText = document.getString("text") ?: ""
val noteImageUri = document.getString("imageUri") ?: ""
val note = Note(noteID, noteText, noteImageUri)
val note = Note(noteID, noteTitle, noteText, noteImageUri)
notes.add(note)
}
noteListAdapter.notifyDataSetChanged()
Expand All @@ -85,4 +266,17 @@ class HomeFragment : Fragment(), NoteListAdapter.OnNoteClickListener {
// Log.e(TAG, "Error getting documents: ", exception)
}
}


private fun displayUserEmail() {
// FirebaseAuth μΈμŠ€ν„΄μŠ€λ₯Ό μ‚¬μš©ν•˜μ—¬ ν˜„μž¬ μ‚¬μš©μžλ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€.
val user: FirebaseUser? = auth.currentUser
// μ‚¬μš©μžκ°€ λ‘œκ·ΈμΈλ˜μ–΄ μžˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.
user?.let {
// μ‚¬μš©μžκ°€ λ‘œκ·ΈμΈλ˜μ–΄ μžˆλ‹€λ©΄, 이메일을 가져와 TextView에 μ„€μ •ν•©λ‹ˆλ‹€.
val userEmail = user.email
emailTextView.text = userEmail
emailTextView1.text = userEmail
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.sharenote

import HomeFragment
import MyPageFragment
import SettingsFragment
import android.content.Intent
import android.os.Bundle
import android.widget.Button
Expand Down Expand Up @@ -48,7 +49,7 @@ class MainActivity : AppCompatActivity() {
}
R.id.fragment_settings -> {
supportFragmentManager.beginTransaction()
.replace(R.id.main_container, MyPageFragment())
.replace(R.id.main_container, SettingsFragment())
.commit()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MyPageActivity : AppCompatActivity() {
setContentView(R.layout.activity_my_page)

findViewById<Button>(R.id.backButton).setOnClickListener {
startActivity(Intent(this, MainActivity::class.java))
finish()
}

Expand Down Expand Up @@ -209,9 +208,7 @@ class MyPageActivity : AppCompatActivity() {
Toast.makeText(this, "μ‚¬μš©μž λΉ„λ°€λ²ˆν˜Έ μ—…λ°μ΄νŠΈμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€: $e", Toast.LENGTH_SHORT).show()
}
}
// λ§ˆμ΄νŽ˜μ΄μ§€λ‘œ 이동
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)

finish() // ν˜„μž¬ μ•‘ν‹°λΉ„ν‹° μ’…λ£Œ
} else {
// λΉ„λ°€λ²ˆν˜Έ μ—…λ°μ΄νŠΈ μ‹€νŒ¨
Expand Down
Loading
Loading