Skip to content

Commit

Permalink
apply song to ui 🎶, first release for production
Browse files Browse the repository at this point in the history
  • Loading branch information
llastkrakw committed Aug 22, 2021
1 parent 73f1f2e commit e88ee48
Show file tree
Hide file tree
Showing 34 changed files with 218 additions and 8 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/com/llastkrakw/nevernote/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.llastkrakw.nevernote.core.constants.DELETE_SONG
import com.llastkrakw.nevernote.core.constants.IS_NOTIFICATION_TASK_EXTRA
import com.llastkrakw.nevernote.core.constants.SUCCESS_SONG
import com.llastkrakw.nevernote.core.constants.TAP_SONG
import com.llastkrakw.nevernote.core.extension.playUiSong
import com.llastkrakw.nevernote.core.extension.toast
import com.llastkrakw.nevernote.core.utilities.ViewUtils.Companion.getLocationOnScreen
import com.llastkrakw.nevernote.core.utilities.ViewUtils.Companion.setTextViewDrawableColor
import com.llastkrakw.nevernote.databinding.ActivityMainBinding
Expand Down Expand Up @@ -91,6 +96,7 @@ class MainActivity : AppCompatActivity() {
}

add.setOnClickListener {
this@MainActivity.playUiSong(TAP_SONG)
when(viewPager.currentItem){
0 -> {
val intent = Intent(this@MainActivity, AddNoteActivity::class.java)
Expand All @@ -115,6 +121,7 @@ class MainActivity : AppCompatActivity() {
})

addFolderBottomSheet.addFolderButton.setOnClickListener {
this@MainActivity.playUiSong(TAP_SONG)
showAddFolderDialog()
}

Expand Down Expand Up @@ -156,6 +163,7 @@ class MainActivity : AppCompatActivity() {

override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
R.id.action_switch_layout -> {
this@MainActivity.playUiSong(TAP_SONG)
(noteViewModel.isGrid.value!!).let {
noteViewModel.toggleLayoutNoteManager(!it)
}
Expand All @@ -164,11 +172,13 @@ class MainActivity : AppCompatActivity() {

R.id.action_delete_note ->{
Log.d("multi", "delete note")
this.playUiSong(DELETE_SONG)
noteViewModel.deleteNotes()
true
}

R.id.action_select_all_note ->{
this.playUiSong(TAP_SONG)
noteViewModel.allNoteSelected.value?.let{
if (it)
noteViewModel.deselectAll()
Expand All @@ -180,6 +190,7 @@ class MainActivity : AppCompatActivity() {
}

R.id.action_folder_note ->{
this.playUiSong(TAP_SONG)
toggleBottomSheet()
true
}
Expand Down Expand Up @@ -229,16 +240,22 @@ class MainActivity : AppCompatActivity() {
val cancelButton = folderView.findViewById<TextView>(R.id.add_folder_cancel)

addButton.setOnClickListener {
this.playUiSong(TAP_SONG)
editText.text?.let {
if(it.toString().isNotEmpty()){
val folder = Folder(null, it.toString(), Date())
noteViewModel.insertFolder(folder)
this.playUiSong(SUCCESS_SONG)
alertDialog.cancel()
}
else{
toast("You can't add empty folder !")
}
}
}

cancelButton.setOnClickListener {
this.playUiSong(TAP_SONG)
alertDialog.cancel()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Build
import android.os.Looper
import android.provider.MediaStore
import com.llastkrakw.nevernote.R
import com.llastkrakw.nevernote.core.extension.getFilenameExtension
import java.util.*

Expand All @@ -29,6 +30,15 @@ const val RECORDING_STOPPED = 1
const val RECORDING_PAUSED = 2
const val RECORDING_CANCELED = 4

// UI Song
const val TAP_SONG = R.raw.ui_tap_variant
const val DELETE_SONG = R.raw.navigation_transition_left
const val SUCCESS_SONG = R.raw.hero_simple_celebration
const val SELECTION_SONG = R.raw.navigation_selection_complete_celebration
const val DESELECTION_SONG = R.raw.ui_unlock
const val BACK_SONG = R.raw.navigation_backward_selection


// shared preferences
const val SAVE_RECORDINGS = "save_recordings"
const val EXTENSION = "extension"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.SharedPreferences
import android.database.Cursor
import android.media.MediaMetadataRetriever
import android.media.MediaPlayer
import android.net.Uri
import android.os.Build
import android.os.Environment
Expand Down Expand Up @@ -40,6 +41,7 @@ fun getCurrentFormattedDateTime(): String {
return simpleDateFormat.format(Date(System.currentTimeMillis()))
}


fun Context.isPathOnSD(path: String) = sdCardPath.isNotEmpty() && path.startsWith(sdCardPath)

fun Context.getStorageDirectories(): Array<String> {
Expand Down Expand Up @@ -335,4 +337,14 @@ private val physicalPaths = arrayListOf(
"/storage/usbdisk2"
)

fun Context.playUiSong(songId : Int){
val mediaPlayer: MediaPlayer? = MediaPlayer.create(this, songId).apply {
setOnCompletionListener {
release()
}
}

mediaPlayer?.start()
}


Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.llastkrakw.nevernote.R
import com.llastkrakw.nevernote.core.constants.SUCCESS_SONG
import com.llastkrakw.nevernote.core.extension.playUiSong
import com.llastkrakw.nevernote.feature.note.datas.entities.FolderWithNotes
import com.llastkrakw.nevernote.feature.note.viewModels.NoteViewModel
import com.llastkrakw.nevernote.views.notes.activities.FolderDetailActivity
Expand Down Expand Up @@ -52,6 +54,7 @@ class AddFolderAdapter(private val noteViewModel: NoteViewModel, private val own

override fun onClick(v: View?) {
noteViewModel.addNotesToFolder(currentFolderWithNotes)
v?.context?.playUiSong(SUCCESS_SONG)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.llastkrakw.nevernote.R
import com.llastkrakw.nevernote.core.constants.TAP_SONG
import com.llastkrakw.nevernote.core.extension.playUiSong
import com.llastkrakw.nevernote.feature.note.datas.entities.FolderWithNotes
import com.llastkrakw.nevernote.feature.note.viewModels.NoteViewModel
import com.llastkrakw.nevernote.views.notes.activities.FolderDetailActivity
Expand Down Expand Up @@ -50,6 +52,7 @@ class FolderAdapter(private val noteViewModel: NoteViewModel, private val owner:
}

override fun onClick(v: View?) {
v?.context?.playUiSong(TAP_SONG)
val intentDetail = Intent(v?.context, FolderDetailActivity::class.java)
intentDetail.putExtra(EXTRA_FOLDER, currentFolderWithNotes)
v?.context?.startActivity(intentDetail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import androidx.recyclerview.widget.RecyclerView
import com.llastkrakw.nevernote.R
import com.llastkrakw.nevernote.core.constants.MAX_CONTENT
import com.llastkrakw.nevernote.core.constants.MAX_TITLE
import com.llastkrakw.nevernote.core.constants.SELECTION_SONG
import com.llastkrakw.nevernote.core.constants.TAP_SONG
import com.llastkrakw.nevernote.core.extension.dateExpired
import com.llastkrakw.nevernote.core.extension.playUiSong
import com.llastkrakw.nevernote.core.utilities.FormatUtils.Companion.toSimpleString
import com.llastkrakw.nevernote.core.utilities.SpanUtils.Companion.toSpannable
import com.llastkrakw.nevernote.feature.note.datas.entities.NoteWithFoldersAndRecords
Expand Down Expand Up @@ -119,6 +122,7 @@ class NoteAdapter(private val noteViewModel: NoteViewModel, private val owner: L
override fun onLongClick(v: View?): Boolean {
if (v != null) {
Log.d("multi", owner.toString())
v.context?.playUiSong(SELECTION_SONG)
noteViewModel.selectedNotes.observe(owner, {

if(it.contains(currentNote.note)){
Expand All @@ -143,17 +147,20 @@ class NoteAdapter(private val noteViewModel: NoteViewModel, private val owner: L
if(it.isNotEmpty()){
Log.d("multi", it.toString())
if(it.contains(currentNote.note)){
v?.context?.playUiSong(TAP_SONG)
Log.d("multi", "note clicked ${currentNote.note.noteId}")
check.visibility = View.GONE
noteViewModel.deselectNote(currentNote.note)
}
else{
v?.context?.playUiSong(SELECTION_SONG)
Log.d("multi", "note clicked ${currentNote.note.noteId}")
check.visibility = View.VISIBLE
noteViewModel.selectNote(currentNote.note)
}
}
else{
v?.context?.playUiSong(TAP_SONG)
Log.d("categorize", "notes detail")
intentDetail.putExtra(NOTE_EXTRA, currentNote)
v?.context?.startActivity(intentDetail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import androidx.recyclerview.widget.RecyclerView
import com.llastkrakw.nevernote.R
import com.llastkrakw.nevernote.core.constants.MAX_CONTENT
import com.llastkrakw.nevernote.core.constants.MAX_TITLE
import com.llastkrakw.nevernote.core.constants.SELECTION_SONG
import com.llastkrakw.nevernote.core.constants.TAP_SONG
import com.llastkrakw.nevernote.core.extension.dateExpired
import com.llastkrakw.nevernote.core.extension.playUiSong
import com.llastkrakw.nevernote.core.utilities.FormatUtils.Companion.toSimpleString
import com.llastkrakw.nevernote.core.utilities.SpanUtils.Companion.toSpannable
import com.llastkrakw.nevernote.feature.note.datas.entities.Note
Expand Down Expand Up @@ -121,6 +124,7 @@ class OtherNoteAdapter(private val noteViewModel: NoteViewModel, private val own
override fun onLongClick(v: View?): Boolean {
if (v != null) {
Log.d("multi", owner.toString())
v.context?.playUiSong(SELECTION_SONG)
noteViewModel.selectedNotes.observe(owner, {

if(it.contains(currentNote)){
Expand All @@ -147,11 +151,13 @@ class OtherNoteAdapter(private val noteViewModel: NoteViewModel, private val own
Log.d("multi", it.toString())
if(it.contains(currentNote)){
Log.d("multi", "note clicked ${currentNote.noteId}")
v?.context?.playUiSong(TAP_SONG)
check.visibility = View.GONE
noteViewModel.deselectNote(currentNote)
}
else{
Log.d("multi", "note clicked ${currentNote.noteId}")
v?.context?.playUiSong(SELECTION_SONG)
check.visibility = View.VISIBLE
noteViewModel.selectNote(currentNote)
}
Expand All @@ -166,6 +172,7 @@ class OtherNoteAdapter(private val noteViewModel: NoteViewModel, private val own

if(noteWithFolders != null){
Log.d("go_detail", noteWithFolders.note.noteId.toString())
v?.context?.playUiSong(TAP_SONG)
intentDetail.putExtra(NOTE_EXTRA, noteWithFolders)
v?.context?.startActivity(intentDetail)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class RecorderService : Service(), MediaScannerConnection.MediaScannerConnection
if (newRecordRef != null) {
noteRepository.insertRecordRef(newRecordRef)
}
playUiSong(SUCCESS_SONG)
toast(msg, Toast.LENGTH_LONG)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ class NoteViewModel(private val noteRepository: NoteRepository, private val app:
emit(id)
}
Log.d("note_update", "note ${note.noteTitle} was added")
app.toast("note ${toSpannable(note.noteTitle)} was added")
if (note.noteContent.isNotEmpty())
app.toast("note ${toSpannable(note.noteTitle)} was added")
}


fun updateNote(note: Note) = viewModelScope.launch {
Log.d("note_update", note.noteContent)
noteRepository.updateNote(note)
app.toast("note ${toSpannable(note.noteTitle)} was update")
if (note.noteContent.isNotEmpty())
app.toast("note ${toSpannable(note.noteTitle)} was updated")
}


Expand All @@ -121,7 +123,6 @@ class NoteViewModel(private val noteRepository: NoteRepository, private val app:
Log.d("multi", "notes ${it.size}")
}
_isClear.postValue(false)
app.toast("note ${toSpannable(note.noteTitle)} was selected")
}

fun selectAll(){
Expand Down Expand Up @@ -150,7 +151,6 @@ class NoteViewModel(private val noteRepository: NoteRepository, private val app:
it.remove(note)
Log.d("multi", "notes ${it.size}")
}
app.toast("note ${toSpannable(note.noteTitle)} was deselected")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.llastkrakw.nevernote.R
import com.llastkrakw.nevernote.core.constants.DESELECTION_SONG
import com.llastkrakw.nevernote.core.constants.SELECTION_SONG
import com.llastkrakw.nevernote.core.extension.dateExpired
import com.llastkrakw.nevernote.core.extension.playUiSong
import com.llastkrakw.nevernote.feature.task.datas.entities.Task
import com.llastkrakw.nevernote.feature.task.viewModels.TaskViewModel
import java.util.*
Expand Down Expand Up @@ -56,6 +59,10 @@ class TaskAdapter(private val taskViewModel: TaskViewModel, private val owner: L

status.setOnClickListener {
(it as CheckBox).isChecked.let { isChecked ->
if (isChecked)
itemView.context.playUiSong(SELECTION_SONG)
else
itemView.context.playUiSong(DESELECTION_SONG)
task.taskStatus = isChecked
taskViewModel.updateTask(task)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ class TaskViewModel(private val taskRepository: TaskRepository, private val app
task.taskId = taskRepository.insertTask(task)
if (selectedTime != null)
addTaskReminder(task, selectedTime)
app.toast("task ${task.taskContent} was added")
}

fun deleteTask(task: Task) = viewModelScope.launch {
taskRepository.deleteTask(task)
app.toast("task ${task.taskContent} was deleted")
}

fun updateTask(task: Task) = viewModelScope.launch {
taskRepository.updateTask(task)
app.toast("task ${task.taskContent} was update")
}

@RequiresApi(Build.VERSION_CODES.O)
Expand Down
Loading

0 comments on commit e88ee48

Please sign in to comment.