Skip to content

Commit

Permalink
Merge pull request #212 from tukcomCD2024/Android1
Browse files Browse the repository at this point in the history
Android1
  • Loading branch information
Chan3711 authored May 15, 2024
2 parents c9db894 + a9a282d commit 94750c4
Show file tree
Hide file tree
Showing 29 changed files with 850 additions and 230 deletions.
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

0 comments on commit 94750c4

Please sign in to comment.