Skip to content

Commit 363425d

Browse files
authored
Merge pull request #13 from llastkrakw/dev
apply song to ui 🎶, first release for production
2 parents 4063c76 + e88ee48 commit 363425d

34 files changed

+218
-8
lines changed

app/src/main/java/com/llastkrakw/nevernote/MainActivity.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import androidx.recyclerview.widget.RecyclerView
2323
import androidx.viewpager2.adapter.FragmentStateAdapter
2424
import androidx.viewpager2.widget.ViewPager2
2525
import com.google.android.material.bottomsheet.BottomSheetBehavior
26+
import com.llastkrakw.nevernote.core.constants.DELETE_SONG
2627
import com.llastkrakw.nevernote.core.constants.IS_NOTIFICATION_TASK_EXTRA
28+
import com.llastkrakw.nevernote.core.constants.SUCCESS_SONG
29+
import com.llastkrakw.nevernote.core.constants.TAP_SONG
30+
import com.llastkrakw.nevernote.core.extension.playUiSong
31+
import com.llastkrakw.nevernote.core.extension.toast
2732
import com.llastkrakw.nevernote.core.utilities.ViewUtils.Companion.getLocationOnScreen
2833
import com.llastkrakw.nevernote.core.utilities.ViewUtils.Companion.setTextViewDrawableColor
2934
import com.llastkrakw.nevernote.databinding.ActivityMainBinding
@@ -91,6 +96,7 @@ class MainActivity : AppCompatActivity() {
9196
}
9297

9398
add.setOnClickListener {
99+
this@MainActivity.playUiSong(TAP_SONG)
94100
when(viewPager.currentItem){
95101
0 -> {
96102
val intent = Intent(this@MainActivity, AddNoteActivity::class.java)
@@ -115,6 +121,7 @@ class MainActivity : AppCompatActivity() {
115121
})
116122

117123
addFolderBottomSheet.addFolderButton.setOnClickListener {
124+
this@MainActivity.playUiSong(TAP_SONG)
118125
showAddFolderDialog()
119126
}
120127

@@ -156,6 +163,7 @@ class MainActivity : AppCompatActivity() {
156163

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

165173
R.id.action_delete_note ->{
166174
Log.d("multi", "delete note")
175+
this.playUiSong(DELETE_SONG)
167176
noteViewModel.deleteNotes()
168177
true
169178
}
170179

171180
R.id.action_select_all_note ->{
181+
this.playUiSong(TAP_SONG)
172182
noteViewModel.allNoteSelected.value?.let{
173183
if (it)
174184
noteViewModel.deselectAll()
@@ -180,6 +190,7 @@ class MainActivity : AppCompatActivity() {
180190
}
181191

182192
R.id.action_folder_note ->{
193+
this.playUiSong(TAP_SONG)
183194
toggleBottomSheet()
184195
true
185196
}
@@ -229,16 +240,22 @@ class MainActivity : AppCompatActivity() {
229240
val cancelButton = folderView.findViewById<TextView>(R.id.add_folder_cancel)
230241

231242
addButton.setOnClickListener {
243+
this.playUiSong(TAP_SONG)
232244
editText.text?.let {
233245
if(it.toString().isNotEmpty()){
234246
val folder = Folder(null, it.toString(), Date())
235247
noteViewModel.insertFolder(folder)
248+
this.playUiSong(SUCCESS_SONG)
236249
alertDialog.cancel()
237250
}
251+
else{
252+
toast("You can't add empty folder !")
253+
}
238254
}
239255
}
240256

241257
cancelButton.setOnClickListener {
258+
this.playUiSong(TAP_SONG)
242259
alertDialog.cancel()
243260
}
244261

app/src/main/java/com/llastkrakw/nevernote/core/constants/Global.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.net.Uri
66
import android.os.Build
77
import android.os.Looper
88
import android.provider.MediaStore
9+
import com.llastkrakw.nevernote.R
910
import com.llastkrakw.nevernote.core.extension.getFilenameExtension
1011
import java.util.*
1112

@@ -29,6 +30,15 @@ const val RECORDING_STOPPED = 1
2930
const val RECORDING_PAUSED = 2
3031
const val RECORDING_CANCELED = 4
3132

33+
// UI Song
34+
const val TAP_SONG = R.raw.ui_tap_variant
35+
const val DELETE_SONG = R.raw.navigation_transition_left
36+
const val SUCCESS_SONG = R.raw.hero_simple_celebration
37+
const val SELECTION_SONG = R.raw.navigation_selection_complete_celebration
38+
const val DESELECTION_SONG = R.raw.ui_unlock
39+
const val BACK_SONG = R.raw.navigation_backward_selection
40+
41+
3242
// shared preferences
3343
const val SAVE_RECORDINGS = "save_recordings"
3444
const val EXTENSION = "extension"

app/src/main/java/com/llastkrakw/nevernote/core/extension/Context.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.Context
66
import android.content.SharedPreferences
77
import android.database.Cursor
88
import android.media.MediaMetadataRetriever
9+
import android.media.MediaPlayer
910
import android.net.Uri
1011
import android.os.Build
1112
import android.os.Environment
@@ -40,6 +41,7 @@ fun getCurrentFormattedDateTime(): String {
4041
return simpleDateFormat.format(Date(System.currentTimeMillis()))
4142
}
4243

44+
4345
fun Context.isPathOnSD(path: String) = sdCardPath.isNotEmpty() && path.startsWith(sdCardPath)
4446

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

340+
fun Context.playUiSong(songId : Int){
341+
val mediaPlayer: MediaPlayer? = MediaPlayer.create(this, songId).apply {
342+
setOnCompletionListener {
343+
release()
344+
}
345+
}
346+
347+
mediaPlayer?.start()
348+
}
349+
338350

app/src/main/java/com/llastkrakw/nevernote/feature/note/adapters/AddFolderAdapter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import androidx.recyclerview.widget.DiffUtil
1010
import androidx.recyclerview.widget.ListAdapter
1111
import androidx.recyclerview.widget.RecyclerView
1212
import com.llastkrakw.nevernote.R
13+
import com.llastkrakw.nevernote.core.constants.SUCCESS_SONG
14+
import com.llastkrakw.nevernote.core.extension.playUiSong
1315
import com.llastkrakw.nevernote.feature.note.datas.entities.FolderWithNotes
1416
import com.llastkrakw.nevernote.feature.note.viewModels.NoteViewModel
1517
import com.llastkrakw.nevernote.views.notes.activities.FolderDetailActivity
@@ -52,6 +54,7 @@ class AddFolderAdapter(private val noteViewModel: NoteViewModel, private val own
5254

5355
override fun onClick(v: View?) {
5456
noteViewModel.addNotesToFolder(currentFolderWithNotes)
57+
v?.context?.playUiSong(SUCCESS_SONG)
5558
}
5659

5760
}

app/src/main/java/com/llastkrakw/nevernote/feature/note/adapters/FolderAdapter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import androidx.recyclerview.widget.DiffUtil
1010
import androidx.recyclerview.widget.ListAdapter
1111
import androidx.recyclerview.widget.RecyclerView
1212
import com.llastkrakw.nevernote.R
13+
import com.llastkrakw.nevernote.core.constants.TAP_SONG
14+
import com.llastkrakw.nevernote.core.extension.playUiSong
1315
import com.llastkrakw.nevernote.feature.note.datas.entities.FolderWithNotes
1416
import com.llastkrakw.nevernote.feature.note.viewModels.NoteViewModel
1517
import com.llastkrakw.nevernote.views.notes.activities.FolderDetailActivity
@@ -50,6 +52,7 @@ class FolderAdapter(private val noteViewModel: NoteViewModel, private val owner:
5052
}
5153

5254
override fun onClick(v: View?) {
55+
v?.context?.playUiSong(TAP_SONG)
5356
val intentDetail = Intent(v?.context, FolderDetailActivity::class.java)
5457
intentDetail.putExtra(EXTRA_FOLDER, currentFolderWithNotes)
5558
v?.context?.startActivity(intentDetail)

app/src/main/java/com/llastkrakw/nevernote/feature/note/adapters/NoteAdapter.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import androidx.recyclerview.widget.RecyclerView
2020
import com.llastkrakw.nevernote.R
2121
import com.llastkrakw.nevernote.core.constants.MAX_CONTENT
2222
import com.llastkrakw.nevernote.core.constants.MAX_TITLE
23+
import com.llastkrakw.nevernote.core.constants.SELECTION_SONG
24+
import com.llastkrakw.nevernote.core.constants.TAP_SONG
2325
import com.llastkrakw.nevernote.core.extension.dateExpired
26+
import com.llastkrakw.nevernote.core.extension.playUiSong
2427
import com.llastkrakw.nevernote.core.utilities.FormatUtils.Companion.toSimpleString
2528
import com.llastkrakw.nevernote.core.utilities.SpanUtils.Companion.toSpannable
2629
import com.llastkrakw.nevernote.feature.note.datas.entities.NoteWithFoldersAndRecords
@@ -119,6 +122,7 @@ class NoteAdapter(private val noteViewModel: NoteViewModel, private val owner: L
119122
override fun onLongClick(v: View?): Boolean {
120123
if (v != null) {
121124
Log.d("multi", owner.toString())
125+
v.context?.playUiSong(SELECTION_SONG)
122126
noteViewModel.selectedNotes.observe(owner, {
123127

124128
if(it.contains(currentNote.note)){
@@ -143,17 +147,20 @@ class NoteAdapter(private val noteViewModel: NoteViewModel, private val owner: L
143147
if(it.isNotEmpty()){
144148
Log.d("multi", it.toString())
145149
if(it.contains(currentNote.note)){
150+
v?.context?.playUiSong(TAP_SONG)
146151
Log.d("multi", "note clicked ${currentNote.note.noteId}")
147152
check.visibility = View.GONE
148153
noteViewModel.deselectNote(currentNote.note)
149154
}
150155
else{
156+
v?.context?.playUiSong(SELECTION_SONG)
151157
Log.d("multi", "note clicked ${currentNote.note.noteId}")
152158
check.visibility = View.VISIBLE
153159
noteViewModel.selectNote(currentNote.note)
154160
}
155161
}
156162
else{
163+
v?.context?.playUiSong(TAP_SONG)
157164
Log.d("categorize", "notes detail")
158165
intentDetail.putExtra(NOTE_EXTRA, currentNote)
159166
v?.context?.startActivity(intentDetail)

app/src/main/java/com/llastkrakw/nevernote/feature/note/adapters/OtherNoteAdapter.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import androidx.recyclerview.widget.RecyclerView
1919
import com.llastkrakw.nevernote.R
2020
import com.llastkrakw.nevernote.core.constants.MAX_CONTENT
2121
import com.llastkrakw.nevernote.core.constants.MAX_TITLE
22+
import com.llastkrakw.nevernote.core.constants.SELECTION_SONG
23+
import com.llastkrakw.nevernote.core.constants.TAP_SONG
2224
import com.llastkrakw.nevernote.core.extension.dateExpired
25+
import com.llastkrakw.nevernote.core.extension.playUiSong
2326
import com.llastkrakw.nevernote.core.utilities.FormatUtils.Companion.toSimpleString
2427
import com.llastkrakw.nevernote.core.utilities.SpanUtils.Companion.toSpannable
2528
import com.llastkrakw.nevernote.feature.note.datas.entities.Note
@@ -121,6 +124,7 @@ class OtherNoteAdapter(private val noteViewModel: NoteViewModel, private val own
121124
override fun onLongClick(v: View?): Boolean {
122125
if (v != null) {
123126
Log.d("multi", owner.toString())
127+
v.context?.playUiSong(SELECTION_SONG)
124128
noteViewModel.selectedNotes.observe(owner, {
125129

126130
if(it.contains(currentNote)){
@@ -147,11 +151,13 @@ class OtherNoteAdapter(private val noteViewModel: NoteViewModel, private val own
147151
Log.d("multi", it.toString())
148152
if(it.contains(currentNote)){
149153
Log.d("multi", "note clicked ${currentNote.noteId}")
154+
v?.context?.playUiSong(TAP_SONG)
150155
check.visibility = View.GONE
151156
noteViewModel.deselectNote(currentNote)
152157
}
153158
else{
154159
Log.d("multi", "note clicked ${currentNote.noteId}")
160+
v?.context?.playUiSong(SELECTION_SONG)
155161
check.visibility = View.VISIBLE
156162
noteViewModel.selectNote(currentNote)
157163
}
@@ -166,6 +172,7 @@ class OtherNoteAdapter(private val noteViewModel: NoteViewModel, private val own
166172

167173
if(noteWithFolders != null){
168174
Log.d("go_detail", noteWithFolders.note.noteId.toString())
175+
v?.context?.playUiSong(TAP_SONG)
169176
intentDetail.putExtra(NOTE_EXTRA, noteWithFolders)
170177
v?.context?.startActivity(intentDetail)
171178
}

app/src/main/java/com/llastkrakw/nevernote/feature/note/services/RecorderService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class RecorderService : Service(), MediaScannerConnection.MediaScannerConnection
218218
if (newRecordRef != null) {
219219
noteRepository.insertRecordRef(newRecordRef)
220220
}
221+
playUiSong(SUCCESS_SONG)
221222
toast(msg, Toast.LENGTH_LONG)
222223
}
223224

app/src/main/java/com/llastkrakw/nevernote/feature/note/viewModels/NoteViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ class NoteViewModel(private val noteRepository: NoteRepository, private val app:
8787
emit(id)
8888
}
8989
Log.d("note_update", "note ${note.noteTitle} was added")
90-
app.toast("note ${toSpannable(note.noteTitle)} was added")
90+
if (note.noteContent.isNotEmpty())
91+
app.toast("note ${toSpannable(note.noteTitle)} was added")
9192
}
9293

9394

9495
fun updateNote(note: Note) = viewModelScope.launch {
9596
Log.d("note_update", note.noteContent)
9697
noteRepository.updateNote(note)
97-
app.toast("note ${toSpannable(note.noteTitle)} was update")
98+
if (note.noteContent.isNotEmpty())
99+
app.toast("note ${toSpannable(note.noteTitle)} was updated")
98100
}
99101

100102

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

127128
fun selectAll(){
@@ -150,7 +151,6 @@ class NoteViewModel(private val noteRepository: NoteRepository, private val app:
150151
it.remove(note)
151152
Log.d("multi", "notes ${it.size}")
152153
}
153-
app.toast("note ${toSpannable(note.noteTitle)} was deselected")
154154
}
155155

156156

app/src/main/java/com/llastkrakw/nevernote/feature/task/adapters/TaskAdapter.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import androidx.recyclerview.widget.DiffUtil
1616
import androidx.recyclerview.widget.ListAdapter
1717
import androidx.recyclerview.widget.RecyclerView
1818
import com.llastkrakw.nevernote.R
19+
import com.llastkrakw.nevernote.core.constants.DESELECTION_SONG
20+
import com.llastkrakw.nevernote.core.constants.SELECTION_SONG
1921
import com.llastkrakw.nevernote.core.extension.dateExpired
22+
import com.llastkrakw.nevernote.core.extension.playUiSong
2023
import com.llastkrakw.nevernote.feature.task.datas.entities.Task
2124
import com.llastkrakw.nevernote.feature.task.viewModels.TaskViewModel
2225
import java.util.*
@@ -56,6 +59,10 @@ class TaskAdapter(private val taskViewModel: TaskViewModel, private val owner: L
5659

5760
status.setOnClickListener {
5861
(it as CheckBox).isChecked.let { isChecked ->
62+
if (isChecked)
63+
itemView.context.playUiSong(SELECTION_SONG)
64+
else
65+
itemView.context.playUiSong(DESELECTION_SONG)
5966
task.taskStatus = isChecked
6067
taskViewModel.updateTask(task)
6168
}

0 commit comments

Comments
 (0)