Skip to content

Commit

Permalink
[#139] fix : 보관함 리스트 및 디테일 API
Browse files Browse the repository at this point in the history
  • Loading branch information
serioushyeon committed Oct 28, 2024
1 parent 0fd2e64 commit 4f51ebe
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 275 deletions.
13 changes: 2 additions & 11 deletions app/src/main/java/com/project/balpyo/Home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.content.Intent
import android.graphics.drawable.AnimationDrawable
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.Log
Expand All @@ -17,8 +15,6 @@ import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewpager2.widget.ViewPager2
import com.project.balpyo.Home.Adapter.BannerVPAdapter
import com.project.balpyo.Storage.Adapter.StorageAdapter
import com.project.balpyo.Storage.ViewModel.StorageViewModel
import com.project.balpyo.MainActivity
Expand All @@ -36,7 +32,6 @@ class HomeFragment : Fragment() {
lateinit var mainActivity: MainActivity

lateinit var viewModel: StorageViewModel
private val handler = Handler(Looper.getMainLooper())

private lateinit var animationDrawable: AnimationDrawable

Expand All @@ -50,9 +45,8 @@ class HomeFragment : Fragment() {
animationDrawable = binding.imageViewLoading.drawable as AnimationDrawable
mainActivity.binding.bottomNavigation.menu.findItem(R.id.homeFragment).setChecked(true);

//flowControllerViewModel = ViewModelProvider(requireActivity())[FlowControllerViewModel::class.java]
viewModel = ViewModelProvider(mainActivity)[StorageViewModel::class.java]
viewModel.getStorageList(this@HomeFragment, mainActivity)
viewModel.getStorageList(mainActivity)

mainActivity.setTransparentStatusBar()

Expand Down Expand Up @@ -95,10 +89,7 @@ class HomeFragment : Fragment() {
storageAdapter.itemClickListener =
object : StorageAdapter.OnItemClickListener {
override fun onItemClick(position: Int) {
viewModel.getStorageDetail(this@HomeFragment, mainActivity, it.get(position).scriptId.toInt())
if(viewModel.storageList.value?.get(position)?.voiceFilePath != null) {
// flowControllerViewModel.setIsEdit(true)
}
viewModel.getStorageDetail(mainActivity, it[position].id.toInt())
findNavController().navigate(R.id.storageEditDeleteFragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,22 @@ import android.content.ClipboardManager
import android.content.Context
import android.content.Context.CLIPBOARD_SERVICE
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavOptions
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import com.project.balpyo.Home.HomeFragment
import com.project.balpyo.MainActivity
import com.project.balpyo.NotificationActivity
import com.project.balpyo.R
import com.project.balpyo.Script.Data.ScriptResultData
import com.project.balpyo.Script.ViewModel.GenerateScriptViewModel
import com.project.balpyo.Script.ViewModel.ScriptDetailViewModel
import com.project.balpyo.Utils.MyApplication
import com.project.balpyo.Utils.PreferenceHelper
import com.project.balpyo.api.ApiClient
import com.project.balpyo.api.TokenManager
import com.project.balpyo.api.request.StoreScriptRequest
import com.project.balpyo.api.response.StorageDetailResult
import com.project.balpyo.api.response.StoreScriptResponse
import com.project.balpyo.databinding.FragmentScriptResultBinding
import retrofit2.Call
Expand All @@ -51,7 +39,6 @@ class ScriptResultFragment : Fragment() {

var editable = false

var gptId = ""
var title = ""
var secTime = 0L

Expand All @@ -68,12 +55,11 @@ class ScriptResultFragment : Fragment() {

scriptViewModel.run {
scriptResult.observe(notificationActivity) {
gptId = it.gptId.toString()
title = it.title
secTime = it.secTime

binding.run {
editTextScript.setText(it.script)
editTextScript.setText(it.content)
var minute = (it.secTime.toInt()) / 60
var second = (it.secTime.toInt()) % 60

Expand Down Expand Up @@ -109,7 +95,8 @@ class ScriptResultFragment : Fragment() {
*/

buttonStore.setOnClickListener {
storeScript()
//TODO: script 저장이 필요한가? 생성과 동시에 보관함 저장? 버튼 눌러야 저장?
// storeScript()
}

editTextScript.setOnLongClickListener {
Expand Down Expand Up @@ -166,7 +153,7 @@ class ScriptResultFragment : Fragment() {
}
}

fun storeScript() {
/*fun storeScript() {
var apiClient = ApiClient(notificationActivity)
var tokenManager = TokenManager(notificationActivity)
Expand Down Expand Up @@ -208,5 +195,5 @@ class ScriptResultFragment : Fragment() {
Log.d("##", "onFailure 에러: " + t.message.toString());
}
})
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ class ScriptDetailViewModel : ViewModel() {
var tokenManager = TokenManager(mainActivity)

apiClient.apiService.getStorageDetail("${tokenManager.getUid()}", scriptId)?.enqueue(object :
Callback<StorageDetailResponse> {
override fun onResponse(call: Call<StorageDetailResponse>, response: Response<StorageDetailResponse>) {
Callback<StorageDetailResult> {
override fun onResponse(call: Call<StorageDetailResult>, response: Response<StorageDetailResult>) {
if (response.isSuccessful) {
// 정상적으로 통신이 성공된 경우
var result: StorageDetailResponse? = response.body()
var result: StorageDetailResult? = response.body()
Log.d("##", "onResponse 성공: " + result?.toString())

scriptResult.value = result?.result
scriptResult.value = result!!

} else {
// 통신이 실패한 경우(응답코드 3xx, 4xx 등)
var result: StorageDetailResponse? = response.body()
var result: StorageDetailResult? = response.body()
Log.d("##", "onResponse 실패")
Log.d("##", "onResponse 실패: " + response.code())
Log.d("##", "onResponse 실패: " + response.body())
Expand All @@ -47,7 +47,7 @@ class ScriptDetailViewModel : ViewModel() {
}
}

override fun onFailure(call: Call<StorageDetailResponse>, t: Throwable) {
override fun onFailure(call: Call<StorageDetailResult>, t: Throwable) {
// 통신 실패
Log.d("##", "onFailure 에러: " + t.message.toString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.project.balpyo.Storage.Adapter

import android.content.ContentValues.TAG
import android.content.Context
import android.text.SpannableString
import android.text.style.BackgroundColorSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.project.balpyo.R
import com.project.balpyo.api.data.Tag
import com.project.balpyo.api.response.StorageListResult
import com.project.balpyo.databinding.ItemStorageBinding

Expand Down Expand Up @@ -44,20 +43,20 @@ class SearchAdapter (var result: List<StorageListResult>) :
holder.run {
title.text = result[position].title
content.maxLines = 3
content.text = result[position].script?.let { highlightText(it) }
content.text = highlightText(result[position].content)

// 태그 초기화
tagNote.visibility = View.GONE
tagScript.visibility = View.GONE
tagTime.visibility = View.GONE
tagFlow.visibility = View.GONE

result[position].tag?.forEach {
result[position].tags.forEach {
when (it) {
"NOTE" -> tagNote.visibility = View.VISIBLE
"SCRIPT" -> tagScript.visibility = View.VISIBLE
"TIME" -> tagTime.visibility = View.VISIBLE
"FLOW" -> tagFlow.visibility = View.VISIBLE
Tag.NOTE.value -> tagNote.visibility = View.VISIBLE
Tag.SCRIPT.value -> tagScript.visibility = View.VISIBLE
Tag.TIME.value -> tagTime.visibility = View.VISIBLE
Tag.FLOW.value -> tagFlow.visibility = View.VISIBLE
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView
import com.project.balpyo.R
import com.project.balpyo.api.data.Tag
import com.project.balpyo.api.response.StorageListResult
import com.project.balpyo.databinding.ItemStorageBinding

Expand Down Expand Up @@ -39,20 +40,20 @@ class StorageAdapter (var result: List<StorageListResult>) :
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.run {
title.text = result[position].title
content.text = result[position].script?.let { getFirst20CharsIgnoringSpaces(it) }
content.text = getFirst20CharsIgnoringSpaces(result[position].content)

// 태그 초기화
tagNote.visibility = View.GONE
tagScript.visibility = View.GONE
tagTime.visibility = View.GONE
tagFlow.visibility = View.GONE

result[position].tag?.forEach {
result[position].tags.forEach {
when (it) {
"NOTE" -> tagNote.visibility = View.VISIBLE
"SCRIPT" -> tagScript.visibility = View.VISIBLE
"TIME" -> tagTime.visibility = View.VISIBLE
"FLOW" -> tagFlow.visibility = View.VISIBLE
Tag.NOTE.value -> tagNote.visibility = View.VISIBLE
Tag.SCRIPT.value -> tagScript.visibility = View.VISIBLE
Tag.TIME.value -> tagTime.visibility = View.VISIBLE
Tag.FLOW.value -> tagFlow.visibility = View.VISIBLE
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LoadScriptBottomSheetFragment : BottomSheetDialogFragment(), BottomSheetLi

for (i in it.indices) {
items.add(BottomSheetData(it[i].title))
scriptId.add(it[i].scriptId)
scriptId.add(it[i].id)
}

val adapter = LoadScriptBottomSheetAdapter(items, scriptId, viewModel, mainActivity, this@LoadScriptBottomSheetFragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@ package com.project.balpyo.Storage

import android.os.Bundle
import android.text.InputType
import android.text.method.ScrollingMovementMethod
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import com.project.balpyo.FlowController.ViewModel.FlowControllerViewModel
import com.project.balpyo.Storage.ViewModel.StorageViewModel
import com.project.balpyo.MainActivity
import com.project.balpyo.R
import com.project.balpyo.Storage.NoteBottomSheet.NoteBottomSheetFragment
import com.project.balpyo.Storage.StorageEditBottomSheet.StorageBottomSheetListener
import com.project.balpyo.Storage.StorageEditBottomSheet.StorageEditBottomSheetFragment
import com.project.balpyo.Utils.PreferenceHelper
Expand All @@ -28,7 +23,6 @@ import com.project.balpyo.databinding.FragmentStorageEditDeleteBinding
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import scala.None

class StorageEditDeleteFragment : Fragment(), StorageBottomSheetListener {
lateinit var binding: FragmentStorageEditDeleteBinding
Expand Down Expand Up @@ -62,10 +56,10 @@ class StorageEditDeleteFragment : Fragment(), StorageBottomSheetListener {
viewModel = ViewModelProvider(mainActivity)[StorageViewModel::class.java]
viewModel.run {
storageDetail.observe(mainActivity) {
binding.editTextScript.setText(it.script.toString())
binding.editTextScript.setText(it.content.toString())
binding.toolbar.textViewTitle.text = it.title.toString()
binding.textViewScriptTitle.text = it.title.toString()
scriptId = it.scriptId.toLong()
scriptId = it.id.toLong()
var minute = (it.secTime.toInt()) / 60
var second = (it.secTime.toInt()) % 60

Expand Down Expand Up @@ -165,9 +159,7 @@ class StorageEditDeleteFragment : Fragment(), StorageBottomSheetListener {
}

fun deleteScript() {
var apiClient = ApiClient(mainActivity)
var tokenManager = TokenManager(mainActivity)

val apiClient = ApiClient(mainActivity)
apiClient.apiService.deleteScript("Bearer ${PreferenceHelper.getUserToken(mainActivity)}",scriptId.toInt())?.enqueue(object :
Callback<Void> {
override fun onResponse(call: Call<Void>, response: Response<Void>) {
Expand All @@ -176,7 +168,7 @@ class StorageEditDeleteFragment : Fragment(), StorageBottomSheetListener {
var result: Void? = response.body()
Log.d("##", "onResponse 성공: " + result?.toString())

viewModel.getStorageList(this@StorageEditDeleteFragment, mainActivity)
viewModel.getStorageList(mainActivity)

findNavController().popBackStack()

Expand Down
Loading

0 comments on commit 4f51ebe

Please sign in to comment.