Conversation
| private fun showPermissionDeniedDialog() { | ||
| AlertDialog.Builder(this) | ||
| .setTitle("권한 필요!") | ||
| .setMessage("음악 파일을 표시하려면 권한이 필요합니다.\n\nAllow permission to show files") |
There was a problem hiding this comment.
strings.xml 써주세요.
기본적으로 사용자에게 보이는 메시지나 텍스트는 strings.xml을 사용하여 유지보수가 편리하게 만드는게 맞습니다.
| ) { isGranted -> | ||
| if (isGranted) { | ||
| loadMusicFiles() | ||
| Toast.makeText(this, "allow", Toast.LENGTH_SHORT).show() |
| import androidx.recyclerview.widget.RecyclerView | ||
| import java.io.File | ||
|
|
||
| data class MusicItem( |
There was a problem hiding this comment.
별도의 data class로 분리 바랍니다
|
|
||
| private fun loadMusicFiles() { | ||
|
|
||
| val file = File("/sdcard/Music/Lil_Tecca_Dark_Thoughts.mp3") |
There was a problem hiding this comment.
Scoped storage 도입 후, /sdcard에 직접 접근이 불가합니다.
따라서 이 코드는 동작하지 않습니다.
| private fun loadMusicFiles() { | ||
|
|
||
| val file = File("/sdcard/Music/Lil_Tecca_Dark_Thoughts.mp3") | ||
| if (file.exists()) { |
There was a problem hiding this comment.
파일이 존재하는지 확인해서 미디어 스캐닝을 시도하려고 하신 것 같은데, 이렇게 되면 파일이 존재할 때 미디어 스캐닝이 동작합니다.
또한, 위에서 말한것 처럼, /sdcard에 대한 접근이 불가하기 때문에, 작동하지 않습니다.
미디어 스캐닝을 시도하시려면 미디어 스캐닝을 시도하는 버튼을 만드시는게 좋아보입니다.
미디어 스캐닝을 앱 실행 시 매번 실행하면 되는거 아니냐고 생각하실 수 있는데, 미디어 스캐닝 자체가 꽤 무거운 작업이라 필요할 때만 실행해야 합니다.
| MediaScannerConnection.scanFile(this, arrayOf(file.absolutePath), null, null) | ||
| } | ||
|
|
||
| if (file.exists()) { |
| } | ||
| } | ||
|
|
||
| musicAdapter.notifyDataSetChanged() |
There was a problem hiding this comment.
notifyDataSetChanged의 경우, adapter 내의 데이터를 한꺼번에 업데이트 하는 코드입니다.
musicList.add 밑어 musicAdapter.notifyItemInserted(musicList.lastIndex)를 호출하는게 더 좋을 것 같습니다
| @@ -0,0 +1,59 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
There was a problem hiding this comment.
recyclerview의 아이템에 사용하는 xml 파일은 activity라는 이름을 가져선 안됩니다.
일반적으로 item_music과 같은 이름을 사용합니다.
| @@ -0,0 +1,33 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
There was a problem hiding this comment.
activity_permission이 아니라 activity_main에 있어야 하는 내용입니다.
| <string name="notification_channel_random" translatable="false" tools:ignore="ExtraTranslation">random</string> | ||
| <string name="channel_text" translatable="false" tools:ignore="ExtraTranslation">text</string> | ||
| <string name="result" translatable="false">Result: %1$d</string> | ||
| <string name="app_name" tools:ignore="DuplicateDefinition">Music Player</string> |
There was a problem hiding this comment.
app_name이 두번 선언되어 있습니다.
|
|
||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
| <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> | ||
| <uses-permission android:name="android.permission.INTERNET" /> |
|
|
||
| class MainActivity : AppCompatActivity() { | ||
|
|
||
| private lateinit var recyclerView: RecyclerView |
There was a problem hiding this comment.
RecyclerView를 굳이 lateinit으로 선언할 이유가 없어 보입니다.
real aggignment 9