Skip to content

Commit

Permalink
[kara/#33] fix : Miniplayer 동기화,Album Data,seekbar 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyowon0204 committed May 28, 2024
1 parent 7668960 commit 526de30
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 46 deletions.
36 changes: 20 additions & 16 deletions UMC_6th/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
id("kotlin-kapt")
}

android {
namespace = "com.example.myfirstapp"
compileSdk = 34


buildFeatures {
viewBinding = true
}
buildFeatures {
dataBinding = true
}

defaultConfig {
applicationId = "com.example.myfirstapp"
Expand Down Expand Up @@ -41,21 +45,21 @@ android {
}

dependencies {
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.8.0")
implementation("androidx.activity:activity-ktx:1.7.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.fragment:fragment-ktx:1.6.2")
implementation("me.relex:circleindicator:2.1.6")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")

// RoomDB

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation ("androidx.fragment:fragment-ktx:1.6.2")
implementation ("me.relex:circleindicator:2.1.6")
implementation("com.squareup.retrofit2:converter-gson:2.9.0") //gson
//RoomDB
implementation("androidx.room:room-ktx:2.6.1")
implementation("androidx.room:room-runtime:2.6.1")
kapt("androidx.room:room-compiler:2.6.1")
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
}
9 changes: 6 additions & 3 deletions UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<service
android:name=".ForegroundService"
android:enabled="true"
android:exported="true"></service>

<activity
android:name=".MainActivity"
android:exported="true"
Expand All @@ -24,9 +29,7 @@
</activity>
<activity
android:name=".SongActivity"
android:exported="true">
</activity>
android:exported="true"></activity>
</application>


</manifest>
6 changes: 6 additions & 0 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/Constant.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.myfirstapp

object Constant {
const val CHANNEL_ID = "ch123"
const val MUSIC_NOTIFICATION_ID = 123
}
49 changes: 49 additions & 0 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/CustomSnackbar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.example.myfirstapp

import android.view.LayoutInflater
import android.view.View
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import com.example.myfirstapp.databinding.CustomSnackbarBinding
import com.google.android.material.snackbar.Snackbar

class CustomSnackbar(view: View, private val message: String) {

companion object {

fun make(view: View, message: String) = CustomSnackbar(view, message)
}

private val context = view.context
private val snackbar = Snackbar.make(view, "", 5000)
private val snackbarLayout = snackbar.view as Snackbar.SnackbarLayout

private val inflater = LayoutInflater.from(context)
private val snackbarBinding: CustomSnackbarBinding
= DataBindingUtil.inflate(inflater, R.layout.custom_snackbar, null, false)

init {
initView()
initData()
}

private fun initView() {
with(snackbarLayout) {
removeAllViews()
setPadding(0, 0, 0, 0)
setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent))
addView(snackbarBinding.root, 0)
}
}

private fun initData() {
snackbarBinding.customSnackbarTv.text = message
snackbarBinding.customSnackbarBtn.setOnClickListener {
// OK 버튼을 클릭했을 때 실행할 동작을 정의할 수 있다.
}
}

fun show() {
snackbar.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ class HomeFragment : Fragment() , CommunicationInterface {
songDB = SongDatabase.getInstance(requireContext())!!
albumDatas.addAll(songDB.albumDao().getAlbums())
Log.d("albumlist", albumDatas.toString())
inputDummyAlbums()


val albumRVAdapter = AlbumRVAdapter(albumDatas)
binding.homeTodayAlbumRv.adapter = albumRVAdapter
binding.homeTodayAlbumRv.layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)
binding.homeTodayAlbumRv.layoutManager = LinearLayoutManager(requireActivity(),LinearLayoutManager.HORIZONTAL,false)

albumRVAdapter.setMyItemClickListener(object: AlbumRVAdapter.MyItemClickListener{
override fun onItemClick(album: Album) {
Expand Down
22 changes: 3 additions & 19 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MainActivity : AppCompatActivity() {
val songs = arrayListOf<Song>()
lateinit var songDB: SongDatabase
var nowPos = 0

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.Theme_MyApplication)
Expand Down Expand Up @@ -120,31 +121,14 @@ class MainActivity : AppCompatActivity() {
nowPos = getPlayingSongPosition(songId)
setMiniPlayer(songs[nowPos])
}
// override fun onStart() {
// super.onStart()
// val sharedPreferences = getSharedPreferences("song", MODE_PRIVATE)
// // songId는 SongActivity에서 onPause가 호출되었을 때
// // 재생 중이던 노래의 id(pk)이다.
// val songId = sharedPreferences.getInt("songId", 0)
//
// val songDB = SongDatabase.getInstance(this)!!
//
// song = if (songId == 0){ // 재생 중이던 노래가 없었으면
// songDB.songDao().getSong(1)
// } else{ // 재생 중이던 노래가 있었으면
// songDB.songDao().getSong(songId)
// }
//
// Log.d("song ID", song.id.toString())
// setMiniPlayer(song)
// }

private fun setMiniPlayer(song: Song){
binding.mainPlayTitleTv.text = song.title
binding.mainPlaySingerTv.text = song.singer
val sharedPreferences = getSharedPreferences("song", MODE_PRIVATE)
val second = sharedPreferences.getInt("second", 0)
Log.d("spfSecond", second.toString())
binding.mainMiniplayerProgressSb.progress = (song.second * 100000 / song.playTime)
binding.mainMiniplayerProgressSb.progress = (second * 100000 / song.playTime)
}
fun updateMainPlayerCl(album : Album) {
binding.mainPlayTitleTv.text = album.title
Expand Down
13 changes: 8 additions & 5 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/SongActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class SongActivity : AppCompatActivity() {
initSong()
initClickListener()


}

private fun initPlayList(){
Expand All @@ -43,11 +42,11 @@ class SongActivity : AppCompatActivity() {
}

binding.songMiniplayerPlayIv.setOnClickListener {
setPlayerStatus(true)
setPlayerStatus(false)
}

binding.songMiniplayerPauseIv.setOnClickListener {
setPlayerStatus(false)
setPlayerStatus(true)
}
binding.songMiniplayerNextIv.setOnClickListener {
moveSong(+1)
Expand All @@ -73,10 +72,12 @@ class SongActivity : AppCompatActivity() {
}
private fun moveSong(direct: Int){
if(nowPos + direct < 0){
Toast.makeText(this,"first song",Toast.LENGTH_SHORT).show()
CustomSnackbar.make(binding.root, "처음 곡입니다.").show()
//Toast.makeText(this,"first song",Toast.LENGTH_SHORT).show()
}
if(nowPos + direct >= songs.size){
Toast.makeText(this,"last song",Toast.LENGTH_SHORT).show()
CustomSnackbar.make(binding.root, "마지막 곡입니다").show()
//Toast.makeText(this,"last song",Toast.LENGTH_SHORT).show()
return
}
nowPos +=direct
Expand Down Expand Up @@ -110,6 +111,7 @@ class SongActivity : AppCompatActivity() {

}


private fun setPlayer(song : Song) {
binding.songMusicTitleTv.text = song.title
binding.songMusicSingerTv.text = song.singer
Expand Down Expand Up @@ -188,6 +190,7 @@ class SongActivity : AppCompatActivity() {
override fun onPause() {
super.onPause()
songs[nowPos].second = (songs[nowPos].playTime * binding.songSeekbarSb.progress) / 100000
Log.d("second", songs[nowPos].second.toString())
songs[nowPos].isPlaying = false
setPlayerStatus(false)

Expand Down
17 changes: 17 additions & 0 deletions UMC_6th/app/src/main/res/drawable/custom_snackbar_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">

<solid
android:color="@color/colorPrimaryGrey"/>

<corners
android:radius="5dp"/>

</shape>

</item>

</selector>
4 changes: 2 additions & 2 deletions UMC_6th/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/main_play_cl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="60dp"
app:layout_constraintBottom_toTopOf="@+id/mainBottomNavigation"
android:paddingVertical="5dp"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -31,7 +31,7 @@
android:background="@null"
android:paddingEnd="0dp"
android:paddingStart="0dp"
android:layout_marginBottom="-4dp"
android:layout_marginBottom="-5dp"
android:progressBackgroundTint="@color/song_player_bg"
android:progressTint="@color/song_player"
android:progress="0"
Expand Down
35 changes: 35 additions & 0 deletions UMC_6th/app/src/main/res/layout/custom_snackbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:paddingStart="15dp"
android:paddingEnd="15dp"
android:background="@drawable/custom_snackbar_bg">

<TextView
android:id="@+id/custom_snackbar_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom SnackBar!"
android:layout_marginRight="20dp"
android:padding="10dp"
android:textColor="@android:color/white"
android:textSize="17sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/custom_snackbar_btn"
android:layout_width="70dp"
android:layout_height="40dp"
android:text="OK"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit 526de30

Please sign in to comment.