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

Android1 #212

Merged
merged 11 commits into from
May 15, 2024
53 changes: 32 additions & 21 deletions android/app/src/main/java/com/example/sharenote/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import android.animation.ObjectAnimator
import android.app.Activity
import android.content.ContentValues.TAG
import android.content.Intent
Expand Down Expand Up @@ -49,6 +50,9 @@ class HomeFragment : Fragment() {
private lateinit var menuBtn: ImageButton
private lateinit var profileForm: RelativeLayout

private lateinit var listLayout: RelativeLayout
private lateinit var listLayout_1: ImageView

private lateinit var MoveDraw: Button

private lateinit var emailTextView1: TextView
Expand Down Expand Up @@ -81,6 +85,9 @@ class HomeFragment : Fragment() {
menuBtn = view.findViewById(R.id.menuBtn)
profileForm = view.findViewById(R.id.profileForm)

listLayout = view.findViewById(R.id.listLayout)
listLayout_1 = view.findViewById(R.id.listLayout_1)

MoveDraw = view.findViewById(R.id.MoveDraw)


Expand Down Expand Up @@ -126,15 +133,19 @@ class HomeFragment : Fragment() {
showAccountMenuPopup()
}

// themesBtn ํด๋ฆญ ์‹œ buttonCreateNote์™€ recyclerViewNotes์˜ ๊ฐ€์‹œ์„ฑ์„ ํ† ๊ธ€ํ•ฉ๋‹ˆ๋‹ค.
val themesBtn = view.findViewById<ImageButton>(R.id.themesBtn)
themesBtn.setOnClickListener {
togglePagesVisibility(themesBtn)

listLayout_1.setOnClickListener {
// recyclerViewNotes์˜ ๊ฐ€์‹œ์„ฑ์„ ํ† ๊ธ€
if (recyclerView.visibility == View.VISIBLE) {
animateView(false)
} else {
animateView(true)
}
}

// Create Note ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ NoteActivity๋กœ ์ด๋™
val buttonCreatePage = view.findViewById<Button>(R.id.buttonCreateNote)
buttonCreatePage.setOnClickListener {
val buttonCreateNote = view.findViewById<ImageView>(R.id.listLayout_4)
buttonCreateNote.setOnClickListener {
createNote()
}

Expand Down Expand Up @@ -177,6 +188,7 @@ class HomeFragment : Fragment() {
override fun onWorkSpaceClick(workSpace: WorkSpace) {
// ์›Œํฌ์ŠคํŽ˜์ด์Šค๋ฅผ ํด๋ฆญํ–ˆ์„ ๋•Œ ์ฒ˜๋ฆฌํ•  ๋‚ด์šฉ์„ ์—ฌ๊ธฐ์— ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
saveRecentWorkspaceId(workSpace.id)
saveRecentWorkspaceName(workSpace.name)
val MainIntent = Intent(requireContext(), MainActivity::class.java)
startActivity(MainIntent)
requireActivity().finish()
Expand Down Expand Up @@ -333,23 +345,18 @@ class HomeFragment : Fragment() {



private fun togglePagesVisibility(themesBtn: ImageButton) {
// recyclerViewNotes์˜ ๊ฐ€์‹œ์„ฑ์„ ํ† ๊ธ€ํ•ฉ๋‹ˆ๋‹ค.
recyclerView.visibility = if (recyclerView.visibility == View.VISIBLE) {
View.GONE
} else {
View.VISIBLE
}
private fun animateView(visible: Boolean) {
// ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ƒ์„ฑ ๋ฐ ์„ค์ •
val rotationFrom = if (visible) -90f else 0f
val rotationTo = if (visible) 0f else -90f
val rotationAnimation = ObjectAnimator.ofFloat(listLayout_1, "rotation", rotationFrom, rotationTo)
rotationAnimation.duration = 200 // ์• ๋‹ˆ๋ฉ”์ด์…˜์˜ ์ง€์† ์‹œ๊ฐ„์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค (๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„)

// 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๊ฐ€ ์ˆจ๊ฒจ์ง„ ๊ฒฝ์šฐ
}
// ์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹œ์ž‘
rotationAnimation.start()

// ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
themesBtn.setImageResource(newImageResource)
// recyclerViewNotes์˜ ๊ฐ€์‹œ์„ฑ ๋ณ€๊ฒฝ
recyclerView.visibility = if (visible) View.VISIBLE else View.GONE
}


Expand Down Expand Up @@ -482,6 +489,10 @@ class HomeFragment : Fragment() {
SharedPreferencesUtil.saveRecentWorkspaceId(requireContext(), workspaceId)
}

private fun saveRecentWorkspaceName(workspaceName: String) {
SharedPreferencesUtil.saveRecentWorkspaceName(requireContext(), workspaceName)
}

private fun getRecentWorkspaceId(): String? {
return SharedPreferencesUtil.getRecentWorkspaceId(requireContext())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class MainActivity : AppCompatActivity() {
true
}
R.id.fragment_search -> {
// SearchFragment๋กœ ์ด๋™ํ•˜๋Š” ์ฝ”๋“œ ์ž‘์„ฑ
supportFragmentManager.beginTransaction()
.replace(R.id.main_container, SearchFragment())
.commit()
true
}
R.id.fragment_alert -> {
Expand Down
57 changes: 55 additions & 2 deletions android/app/src/main/java/com/example/sharenote/NoteActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.widget.EditText
import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.PopupWindow
import android.widget.RelativeLayout
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.ContentProviderCompat.requireContext
Expand All @@ -29,7 +30,7 @@ import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class NoteActivity : AppCompatActivity(), PageListAdapter.OnPageClickListener {
class NoteActivity : AppCompatActivity(), PageListAdapter.OnPageClickListener, PageListAdapter.OnSettingClickListener {

private lateinit var backTextView: TextView
private lateinit var createPageButton: ImageButton
Expand All @@ -51,7 +52,7 @@ class NoteActivity : AppCompatActivity(), PageListAdapter.OnPageClickListener {
recyclerView = findViewById(R.id.recyclerViewPages)
val layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
recyclerView.layoutManager = layoutManager
pageListAdapter = PageListAdapter(pages, this)
pageListAdapter = PageListAdapter(pages, this, this)
recyclerView.adapter = pageListAdapter

backTextView.setOnClickListener {
Expand Down Expand Up @@ -83,10 +84,15 @@ class NoteActivity : AppCompatActivity(), PageListAdapter.OnPageClickListener {
}

override fun onPageClick(page: Page) {
saveRecentPageId(page.id)
val intent = Intent(this, PageActivity::class.java)
startActivity(intent)
}

override fun onSettingClick(page: Page, position: Int) {
showSettingPopup(page, position)
}

/*
private fun loadPagesFromFirestore(recentNoteId: String) {
val db = FirebaseFirestore.getInstance()
Expand Down Expand Up @@ -226,6 +232,47 @@ class NoteActivity : AppCompatActivity(), PageListAdapter.OnPageClickListener {
}


fun showSettingPopup(page: Page, position: Int){
// ํŒ์—… ์ฐฝ์˜ ๋ ˆ์ด์•„์›ƒ์„ inflateํ•˜์—ฌ ๊ฐ€์ ธ์˜ด
val popupView = LayoutInflater.from(this).inflate(R.layout.setting_popup_layout, null)

// ํŒ์—… ์ฐฝ์„ ์ƒ์„ฑ
val settingPopupWindow = PopupWindow(
popupView,
700,
LinearLayout.LayoutParams.WRAP_CONTENT,
true
)


val titleEditText = popupView.findViewById<TextView>(R.id.titleEditText)
titleEditText.text = "Page ${position + 1}"


// ํŒ์—… ์ฐฝ ๋‚ด์˜ ๊ฐ ๋ ˆ์ด์•„์›ƒ์— ํด๋ฆญ ์ด๋ฒคํŠธ ์„ค์ •
val layout1 = popupView.findViewById<RelativeLayout>(R.id.layout1)
val layout2 = popupView.findViewById<RelativeLayout>(R.id.layout2)
val layout3 = popupView.findViewById<RelativeLayout>(R.id.layout3)

layout1.setOnClickListener {
// ํด๋ฆญ ์ด๋ฒคํŠธ ์„ค์ •
}

layout2.setOnClickListener {
// ํด๋ฆญ ์ด๋ฒคํŠธ ์„ค์ •
}

layout3.setOnClickListener {
// ํด๋ฆญ ์ด๋ฒคํŠธ ์„ค์ •
}


// ํŒ์—… ์ฐฝ์„ ํ™”๋ฉด์— ํ‘œ์‹œ
settingPopupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0)
}



private fun showOrgInfoPopup() {
val recentWorkspaceId = getRecentWorkSpaceId() ?: ""
val userId = getUserId() ?: ""
Expand All @@ -234,6 +281,12 @@ class NoteActivity : AppCompatActivity(), PageListAdapter.OnPageClickListener {
val popupView = LayoutInflater.from(this).inflate(R.layout.org_info_layout, null)


// ์›Œํฌ์ŠคํŽ˜์ด์Šค ์ด๋ฆ„์„ ํ‘œ์‹œํ•  ํ…์ŠคํŠธ๋ทฐ ์„ ์–ธ
val organizationTextView = popupView.findViewById<TextView>(R.id.Organization)

val workspaceName = SharedPreferencesUtil.getRecentWorkspaceName(this)
organizationTextView.text = workspaceName


// ํŒ์—… ์ฐฝ์„ ์ƒ์„ฑ
orgPopupWindow = PopupWindow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ class NoteListAdapter(private val onItemClick: (String) -> Unit) :
private val noteList = mutableListOf<Note>()

inner class NoteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
// ๋ทฐํ™€๋” ์ดˆ๊ธฐํ™” ๋ฐ ํด๋ฆญ ๋ฆฌ์Šค๋„ˆ ์„ค์ •
init {
itemView.setOnClickListener(this)
}

// ์•„์ดํ…œ ํด๋ฆญ ์‹œ ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์„œ๋“œ
override fun onClick(v: View?) {
val position = adapterPosition
if (position != RecyclerView.NO_POSITION) {
Expand All @@ -36,12 +34,14 @@ class NoteListAdapter(private val onItemClick: (String) -> Unit) :

override fun onBindViewHolder(holder: NoteViewHolder, position: Int) {
val currentItem = noteList[position]


// ์•„์ดํ…œ์˜ ์ œ๋ชฉ ์„ค์ •
holder.titleTextView.text = currentItem.title
}

override fun getItemCount() = noteList.size

// ์™ธ๋ถ€์—์„œ ๋…ธํŠธ ๋ชฉ๋ก์„ ์„ค์ •ํ•˜๋Š” ๋ฉ”์„œ๋“œ
fun setNotes(notes: List<Note>) {
noteList.clear()
noteList.addAll(notes)
Expand Down
68 changes: 50 additions & 18 deletions android/app/src/main/java/com/example/sharenote/PageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,43 +77,68 @@ class PageActivity : AppCompatActivity() {
}


//val imageUrl = intent.getStringExtra(UrlTestActivity.EXTRA_IMAGE_URL)
val imageUrl = intent.getStringExtra(PaintActivity.IMAGE_URL)

// WebView๊ฐ€ ๋กœ๋“œ๋˜๋ฉด ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
// ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ
uploadImageToEditor(imageUrl)
}
}



// SharedPreferencesUtil์„ ์‚ฌ์šฉํ•˜์—ฌ WorkSpaceId์™€ NoteId๋ฅผ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
val workspaceId = SharedPreferencesUtil.getRecentWorkspaceId(this)
val noteId = SharedPreferencesUtil.getRecentNoteId(this)
val pageId = SharedPreferencesUtil.getRecentPageId(this)

webView.loadUrl("https://sharenote.shop/organization/$workspaceId/$noteId")
webView.loadUrl("https://sharenote.shop/organization/$workspaceId/$noteId/$pageId")

// ํ”Œ๋กœํŒ… ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์—๋‹ˆ๋ฉ”์ด์…˜ ๋™์ž‘ ๊ธฐ๋Šฅ
floating.setOnClickListener {
toggleFab()
toggleFab()
}



fabDraw.setOnClickListener {
val intent = Intent(this, PaintActivity::class.java)
startActivityForResult(intent, REQUEST_IMAGE_SELECTION)
startActivity(intent)
finish()
yjsDisconnect()
}
}

/*
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_IMAGE_SELECTION && resultCode == Activity.RESULT_OK) {
val imageUriString = data?.getStringExtra(UrlTestActivity.EXTRA_IMAGE_URI)
Log.d("PageActivity", "Received image URI: $imageUriString")
// ๋กœ๊ทธ ํ™•์ธ
Log.d("PageActivity", "Selected image URI: $imageUriString")
// ์ž‘์—… ์ค‘์ธ ํ…์ŠคํŠธ ์ค„์— ์ด๋ฏธ์ง€ URL ์‚ฝ์ž…
if (!imageUriString.isNullOrEmpty()) {
Toast.makeText(this, "Selected image URL: $imageUriString", Toast.LENGTH_SHORT).show()
val script = """
var img = document.createElement('img');
img.src = '$imageUriString';
document.body.appendChild(img);
""".trimIndent()
webView.evaluateJavascript(script, null)
if (requestCode == 100 && resultCode == Activity.RESULT_OK) {
val imageUrl = data?.getStringExtra("imageUrl")
if (imageUrl != null) {
Log.d("PageActivity", "Received Image URL: $imageUrl")
Toast.makeText(this@PageActivity, imageUrl, Toast.LENGTH_SHORT).show()
} else {
Log.d("PageActivity", "Received Image URL is null")
Toast.makeText(this@PageActivity, "No image URL received", Toast.LENGTH_SHORT).show()
}
}
}*/



private fun uploadImageToEditor(imageUrl: String?) {
if (imageUrl != null) {
// ์ด๋ฏธ์ง€ URL์„ JavaScript ํ•จ์ˆ˜์— ์ „๋‹ฌ
val jsFunction = "uploadImageToEditor('$imageUrl')"
webView.evaluateJavascript(jsFunction, null)
} else {
// ์ด๋ฏธ์ง€ URL์ด null์ธ ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
Toast.makeText(this, "์ด๋ฏธ์ง€ URL์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.", Toast.LENGTH_SHORT).show()
}
}


Expand All @@ -125,12 +150,19 @@ class PageActivity : AppCompatActivity() {
if (webView.canGoBack()) {
//์›น์‚ฌ์ดํŠธ์—์„œ ๋’ค๋กœ๊ฐˆ ํŽ˜์ด์ง€๊ฐ€ ์กด์žฌ ํ•œ๋‹ค๋ฉด ์ˆ˜ํ–‰
webView.goBack() // ์›น์‚ฌ์ดํŠธ ๋’ค๋กœ๊ฐ€๊ธฐ
yjsDisconnect()

} else {
super.onBackPressed() // ๋ณธ๋ž˜์˜ ๋ฐฑ๋ฒ„ํŠผ ์ˆ˜ํ–‰(์•ˆ๋“œ๋กœ์ด๋“œ)
yjsDisconnect()
}
}

private fun yjsDisconnect(){
val jsCode = "yjsDisconnect()"
webView.evaluateJavascript(jsCode, null)
}

private fun toggleFab() {
// ํ”Œ๋กœํŒ… ์•ก์…˜ ๋ฒ„ํŠผ ๋‹ซ๊ธฐ - ์—ด๋ ค์žˆ๋Š” ํ”Œ๋กœํŒ… ๋ฒ„ํŠผ ์ง‘์–ด๋„ฃ๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ ์„ธํŒ…
if (isFabOpen) {
Expand Down
Loading
Loading