-
Notifications
You must be signed in to change notification settings - Fork 0
Issue #17
mutablelist.any{} mutablelist.filter{} 등 mutablelist의 항목들을 다루는, 활용할 수 있는 기능들이 많다. mutablelist 따로 공부할 것
bitmap 사진을 bytearray로 변환해서 저장하는 것이 아닌 내부 저장소에 따로 파일을 만들어 저장하고 그 파일의 경로를 저장해서 가져올 때 사용
임시로 사진을 고를 때 권한을 물어봄 -> 추후 앱이 처음 실행될 때 권한을 물어보고 시작할 것
parameter로 fragment를 전달해줘야 한다 -> fragment에서 adapter 생성 시 fragment를 인자로 넘겨줘야 하는데 좋은 방법인 것 같지는 않음 -> 아래 방법 적용 가능?
private val setItemDone : (Int, Boolean) -> Unit
setItemDone(adapterPosition, false)
this.adapter = DailyCheckItemAdapter(list,requireContext()) { date, boolean -> setItemDone(date, boolean) }
private fun setItemDone(date: Int, boolean: Boolean) {
viewModel.setItemDone(date, boolean)
}
이런식으로 adapter를 선언하는 fragment에서 만든 함수를 매개변수로 전달해서 사용할 수 있음 -> adapter에서 viewmodel에 접근할 필요 없이 viewmodel에 접근하는 함수를 만들어줘서 전달하면 adapter에서도 사용 가능 --> fragment를 매개변수로 전달하지 않고 여기서 사용 가능할 것 같음
val builder = AlertDialog.Builder(requireContext())
builder.setMessage("저장하시겠습니까?")
.setPositiveButton("저장") { _, _ ->
setupDisplay("normal")
content = viewModel?.content?.value!!
photo = viewModel?.photo?.value
saveEditedMemo()
}
.setNegativeButton("취소", null)
.show()
}
{ } 는 DialogInterface의 메서드 활용을 생략한 것
사진 저장하기
private fun saveBitmapInFile(bitmap: Bitmap?, filename: String) {
if (bitmap != null) {
val file = File(this@DailyWritingDetailMemo.context?.filesDir, filename)
var outputStream: OutputStream? = null
try {
file.createNewFile()
outputStream = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream)
} finally {
outputStream?.close()
}
imgPath = file.absolutePath
}
}
사진 가져오기
val f = File(imgpath!!)
val options = BitmapFactory.Options()
options.inPreferredConfig = Bitmap.Config.ARGB_8888
val bitmap = BitmapFactory.decodeStream(FileInputStream(f), null, options)
val currentYear = SimpleDateFormat("yyyy", Locale.getDefault()).format(Date(System.currentTimeMillis())).toInt()
val currentMonth = SimpleDateFormat("MM", Locale.getDefault()).format(Date(System.currentTimeMillis())).toInt()
val currentDay = SimpleDateFormat("dd", Locale.getDefault()).format(Date(System.currentTimeMillis())).toInt()
val datePickerDialog = DatePickerDialog(requireContext(), {
_, _, _, day ->
viewModel.setMonthTimesDone(day)
}, currentYear, currentMonth , currentDay)
datePickerDialog.show()
모두 입력해야 오류 발생 X
Viewmodel에서 관찰하고 있는 값의 하위 목록만 바뀌면 안된다. 하위 목록을 바꾼 그 값의 value를 바꿔줘야, 즉 observe 하고 있는 값의 value 를 set 해줘야 observer에서 인식하는 듯하다. 그렇게 되면 하위 목록을 업데이트하고 전체 값을 대입하거나, 하위 목록을 관찰하는 observer를 새로 만들어줘야 할 것 같음. 나는 전자 사용