Skip to content

Commit

Permalink
New Memo app design - Continue: #55
Browse files Browse the repository at this point in the history
  • Loading branch information
tuancoltech committed May 1, 2024
1 parent 81e1d7b commit 981f1b9
Show file tree
Hide file tree
Showing 57 changed files with 20,764 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ data class GraphicNote(
@IgnoredOnParcel
val svg: SVG? = null,
@IgnoredOnParcel
override var resource: Resource? = null
override var resource: Resource? = null,
override var pendingForDelete: Boolean = false
) : Note, Parcelable
1 change: 1 addition & 0 deletions app/src/main/java/dev/arkbuilders/arkmemo/models/Note.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ interface Note {
val title: String
val description: String
var resource: Resource?
var pendingForDelete: Boolean
}
3 changes: 2 additions & 1 deletion app/src/main/java/dev/arkbuilders/arkmemo/models/TextNote.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ data class TextNote (
override val description: String = "",
val text: String = "",
@IgnoredOnParcel
override var resource: Resource? = null
override var resource: Resource? = null,
override var pendingForDelete: Boolean = false
): Note, Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class VoiceNote(
@IgnoredOnParcel
var path: Path = createTempFile(),
@IgnoredOnParcel
override var resource: Resource? = null
override var resource: Resource? = null,
override var pendingForDelete: Boolean = false
): Note, Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,3 @@ fun AppCompatActivity.resumeFragment(fragment: Fragment){
commit()
}
}

fun Context.getTextFromClipBoard(): String?{
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
return clipboardManager.primaryClip?.getItemAt(0)?.text?.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import dev.arkbuilders.arkmemo.ui.viewmodels.ArkMediaPlayerSideEffect
import dev.arkbuilders.arkmemo.ui.viewmodels.ArkMediaPlayerState
import dev.arkbuilders.arkmemo.ui.views.NotesCanvas
import dev.arkbuilders.arkmemo.utils.getAutoTitle
import dev.arkbuilders.arkmemo.utils.gone
import dev.arkbuilders.arkmemo.utils.replaceFragment
import dev.arkbuilders.arkmemo.utils.visible

Expand Down Expand Up @@ -75,6 +76,12 @@ class NotesListAdapterV2(
holder.canvasGraphicThumb.visible()
onThumbPrepare(note, holder.canvasGraphicThumb)
}

if (note.pendingForDelete) {
holder.tvDelete.visible()
} else {
holder.tvDelete.gone()
}
}

override fun getItemCount() = notes.size
Expand Down Expand Up @@ -128,6 +135,7 @@ class NotesListAdapterV2(
val btnPlayPause = binding.ivPlayAudio
val layoutAudioView = binding.layoutAudioView
val canvasGraphicThumb = binding.canvasGraphicThumb
val tvDelete = binding.tvDelete

private val clickNoteToEditListener = View.OnClickListener {
var tag = EditTextNotesFragment.TAG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package dev.arkbuilders.arkmemo.ui.dialogs

import android.app.Dialog
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.models.Note
import dev.arkbuilders.arkmemo.ui.fragments.deleteNote
import dev.arkbuilders.arkmemo.ui.views.toast

class NoteDeleteDialog: DialogFragment() {
class NoteDeleteDialog(private val mOnPositiveClicked: (() -> Unit)? = null,
private val mOnNegativeClicked: (() -> Unit)? = null) : DialogFragment() {

private var note: Note? = null

Expand All @@ -24,12 +26,19 @@ class NoteDeleteDialog: DialogFragment() {
.setNegativeButton(R.string.ark_memo_cancel)
{ dialog, _ ->
dialog.cancel()
mOnNegativeClicked?.invoke()
}
.setPositiveButton(R.string.ark_memo_ok){ dialog, _ ->
if(note != null) {
parentFragment?.deleteNote(note!!)
toast(requireContext(), getString(R.string.note_deleted))
mOnPositiveClicked?.let {
mOnPositiveClicked.invoke()
dialog.cancel()
} ?: let {
if(note != null) {
Log.v("tuancoltech", "Calling deleteNote: " + note + " with parentFragment: " + parentFragment)
parentFragment?.deleteNote(note!!)
toast(requireContext(), getString(R.string.note_deleted))
dialog.cancel()
}
}
}
return builder.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.arkbuilders.arkmemo.ui.dialogs

import android.app.Dialog
import android.os.Bundle
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.databinding.DialogSaveNoteRemindBinding

class SaveNoteDialog(private val onPositiveClick: (() -> Unit)? = null,
private val onNegativeClicked: (() -> Unit)? = null): DialogFragment() {

private lateinit var mBinding: DialogSaveNoteRemindBinding
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
mBinding = DialogSaveNoteRemindBinding.inflate(layoutInflater)
val dialog = Dialog(requireContext(), R.style.MemoDialog)
dialog.window?.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT
)
dialog.setContentView(mBinding.root)
initViewActions()
return dialog
}

private fun initViewActions() {
mBinding.ivClose.setOnClickListener {
dismiss()
}

mBinding.tvSave.setOnClickListener {
onPositiveClick?.invoke()
dismiss()
}

mBinding.tvDiscard.setOnClickListener {
onNegativeClicked?.invoke()
dismiss()
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.arkbuilders.arkmemo.ui.fragments

import android.content.res.ColorStateList
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
Expand All @@ -10,6 +11,7 @@ import android.widget.ImageView
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
Expand All @@ -23,6 +25,8 @@ import dev.arkbuilders.arkmemo.ui.activities.MainActivity
import dev.arkbuilders.arkmemo.ui.viewmodels.ArkMediaPlayerSideEffect
import dev.arkbuilders.arkmemo.ui.viewmodels.ArkMediaPlayerState
import dev.arkbuilders.arkmemo.ui.viewmodels.ArkMediaPlayerViewModel
import dev.arkbuilders.arkmemo.utils.gone
import dev.arkbuilders.arkmemo.utils.visible
import kotlinx.coroutines.launch
import java.time.LocalDate
import java.time.format.DateTimeFormatter
Expand All @@ -43,6 +47,7 @@ class ArkMediaPlayerFragment: BaseEditNoteFragment() {
private lateinit var btnSave: Button

private lateinit var note: VoiceNote
private var mIsRecording = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -95,6 +100,19 @@ class ArkMediaPlayerFragment: BaseEditNoteFragment() {
arkMediaPlayerViewModel.onPlayOrPauseClick(note.path.toString())
}
seekBar.setOnSeekBarChangeListener(seekBarChangeListener)

binding.layoutAudioRecord.ivRecord.setOnClickListener {
if (mIsRecording) {
binding.layoutAudioRecord.ivRecord.setImageResource(R.drawable.ic_record_big)
binding.layoutAudioRecord.ivRecord.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(activity, R.color.warning))
binding.layoutAudioRecord.animRecording.gone()
} else {
binding.layoutAudioRecord.ivRecord.setImageResource(R.drawable.ic_record_ongoing)
binding.layoutAudioRecord.ivRecord.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(activity, R.color.warning_100))
binding.layoutAudioRecord.animRecording.visible()
}
mIsRecording = !mIsRecording
}
}

private fun showState(state: ArkMediaPlayerState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionBu
import dagger.hilt.android.AndroidEntryPoint
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.databinding.FragmentEditNotesBinding
import dev.arkbuilders.arkmemo.databinding.FragmentEditNotesV2Binding
import dev.arkbuilders.arkmemo.models.VoiceNote
import dev.arkbuilders.arkmemo.ui.activities.MainActivity
import dev.arkbuilders.arkmemo.ui.viewmodels.NotesViewModel
import dev.arkbuilders.arkmemo.ui.viewmodels.RecorderSideEffect
import dev.arkbuilders.arkmemo.ui.viewmodels.RecorderState
import dev.arkbuilders.arkmemo.ui.viewmodels.ArkRecorderViewModel
import dev.arkbuilders.arkmemo.ui.views.WaveView
import dev.arkbuilders.arkmemo.utils.gone
import dev.arkbuilders.arkmemo.utils.observeSaveResult
import dev.arkbuilders.arkmemo.utils.visible
import kotlinx.coroutines.launch
import java.time.LocalDate
import java.time.format.DateTimeFormatter

@AndroidEntryPoint
class ArkRecorderFragment: Fragment(R.layout.fragment_edit_notes) {
class ArkRecorderFragment: Fragment(R.layout.fragment_edit_notes_v2) {

private val activity by lazy { requireActivity() as MainActivity }
private val binding by viewBinding(FragmentEditNotesBinding::bind)
private val binding by viewBinding(FragmentEditNotesV2Binding::bind)

private var shouldRecord = false
private val audioRecordingPermissionLauncher =
Expand Down Expand Up @@ -87,7 +90,7 @@ class ArkRecorderFragment: Fragment(R.layout.fragment_edit_notes) {
LocalDate.now().format(DateTimeFormatter.ISO_DATE)
)
var title = ""
val etTitle = binding.noteTitle
val etTitle = binding.edtTitle
val etTitleWatcher = object: TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}

Expand All @@ -98,11 +101,17 @@ class ArkRecorderFragment: Fragment(R.layout.fragment_edit_notes) {
override fun afterTextChanged(s: Editable?) {}
}

binding.recorderViewBinding.recorderView.isVisible = true
binding.toolbar.ivBack.setOnClickListener {
activity.onBackPressedDispatcher.onBackPressed()
}
binding.toolbar.ivRightActionIcon.setImageResource(R.drawable.ic_delete_note)

// binding.recorderViewBinding.recorderView.isVisible = true
binding.layoutAudioRecord.root.visible()
btnSave = binding.btnSave
ivRecord = binding.recorderViewBinding.ivRecord
ivPauseResume = binding.recorderViewBinding.ivPauseResume
tvDuration = binding.recorderViewBinding.tvDuration
ivRecord = /*binding.recorderViewBinding.ivRecord*/binding.layoutAudioRecord.ivRecord
ivPauseResume = /*binding.recorderViewBinding.ivPauseResume*/binding.layoutAudioRecord.ivPauseResume
tvDuration = /*binding.recorderViewBinding.tvDuration*/binding.layoutAudioRecord.tvDuration
waveView = binding.recorderViewBinding.waveView

ivPauseResume.isEnabled = false
Expand Down Expand Up @@ -135,24 +144,28 @@ class ArkRecorderFragment: Fragment(R.layout.fragment_edit_notes) {
RecorderSideEffect.StartRecording -> {
val stopIcon = ResourcesCompat.getDrawable(
resources,
R.drawable.ic_stop,
R.drawable.ic_record_ongoing,
null
)
waveView.resetWave()
ivRecord.setImageDrawable(stopIcon)
ivPauseResume.isEnabled = true
btnSave.isEnabled = false
binding.layoutAudioRecord.animRecording.visible()
binding.layoutAudioRecord.animSoundWave.visible()
}
RecorderSideEffect.StopRecording -> {
val recordIcon = ResourcesCompat.getDrawable(
resources,
R.drawable.ic_record,
R.drawable.ic_record_big,
null
)
ivRecord.setImageDrawable(recordIcon)
ivPauseResume.isEnabled = false
btnSave.isEnabled = true
showPauseIcon()
binding.layoutAudioRecord.animRecording.gone()
binding.layoutAudioRecord.animSoundWave.gone()
}
RecorderSideEffect.PauseRecording -> {
val resumeIcon = ResourcesCompat.getDrawable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ open class BaseEditNoteFragment: Fragment(R.layout.fragment_edit_notes_v2) {
}
}

binding.ivBack.setOnClickListener {
binding.toolbar.ivBack.setOnClickListener {
activity?.onBackPressedDispatcher?.onBackPressed()
}

if (this is ArkMediaPlayerFragment) {
binding.ivPin.gone()
binding.tvDone.visible()
binding.toolbar.ivRightActionIcon.gone()
binding.toolbar.tvRightActionText.visible()
binding.groupTextControls.gone()
binding.layoutGraphicsControl.root.gone()
binding.layoutAudioRecord.root.visible()
} else {
binding.ivPin.visible()
binding.tvDone.gone()
binding.toolbar.ivRightActionIcon.visible()
binding.toolbar.tvRightActionText.gone()
binding.layoutAudioRecord.root.gone()

if (this is EditTextNotesFragment) {
Expand All @@ -50,11 +50,11 @@ open class BaseEditNoteFragment: Fragment(R.layout.fragment_edit_notes_v2) {
}

if (this is EditGraphicNotesFragment) {
binding.tvDone.visible()
binding.ivPin.gone()
binding.toolbar.tvRightActionText.visible()
binding.toolbar.ivRightActionIcon.gone()
} else {
binding.tvDone.gone()
binding.ivPin.visible()
binding.toolbar.tvRightActionText.gone()
binding.toolbar.ivRightActionIcon.visible()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dagger.hilt.android.AndroidEntryPoint
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.models.TextNote
import dev.arkbuilders.arkmemo.ui.activities.MainActivity
import dev.arkbuilders.arkmemo.ui.dialogs.SaveNoteDialog
import dev.arkbuilders.arkmemo.ui.viewmodels.NotesViewModel
import dev.arkbuilders.arkmemo.utils.observeSaveResult

Expand Down Expand Up @@ -98,9 +99,21 @@ class EditTextNotesFragment: BaseEditNoteFragment() {
}

binding.editTextDescription.setText(this.note.description)
binding.ivBack.setOnClickListener {
activity.onBackPressedDispatcher.onBackPressed()
binding.toolbar.ivBack.setOnClickListener {
showSaveNoteDialog()
}
binding.toolbar.ivRightActionIcon.setImageResource(R.drawable.ic_delete_note)
}

private fun showSaveNoteDialog() {
val saveNoteDialog = SaveNoteDialog(
onPositiveClick = {
activity.onBackPressedDispatcher.onBackPressed()
},
onNegativeClicked = {
activity.onBackPressedDispatcher.onBackPressed()
})
saveNoteDialog.show(parentFragmentManager, SaveNoteDialog::class.java.name)
}
companion object{
const val TAG = "Edit Text Notes"
Expand Down
Loading

0 comments on commit 981f1b9

Please sign in to comment.