Skip to content

Commit

Permalink
Merge pull request #110 from tukcomCD2024/Android
Browse files Browse the repository at this point in the history
Android
  • Loading branch information
Chan3711 authored Mar 16, 2024
2 parents ac7d544 + 1637276 commit 3b9dc8a
Show file tree
Hide file tree
Showing 49 changed files with 1,892 additions and 356 deletions.
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

0 comments on commit 3b9dc8a

Please sign in to comment.