-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
436 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.umc_6th | ||
|
||
object Constant { | ||
const val CHANNEL_ID = "ch123" | ||
const val MUSIC_NOTIFICATION_ID = 123 | ||
} |
62 changes: 62 additions & 0 deletions
62
UMC_6th/app/src/main/java/com/example/umc_6th/ForegroundService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.example.umc_6th | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Notification | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.app.Service | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.IBinder | ||
import androidx.annotation.RequiresApi | ||
|
||
class ForegroundService : Service() { | ||
|
||
override fun onBind(intent: Intent): IBinder? { | ||
return null | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
createNotificationChannel() | ||
} | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ | ||
showNotification() | ||
} | ||
return START_STICKY | ||
} | ||
|
||
@SuppressLint("ForegroundServiceType") | ||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun showNotification() { | ||
val notificationIntent = Intent(this,SongActivity::class.java) | ||
val pendingIntent = PendingIntent.getActivity( | ||
this,0,notificationIntent,PendingIntent.FLAG_IMMUTABLE | ||
) | ||
val notification = Notification | ||
.Builder(this, Constant.CHANNEL_ID) | ||
.setContentText("현재 음악이 재생 중 입니다.") | ||
.setSmallIcon(R.drawable.ic_flo_logo) | ||
.setContentIntent(pendingIntent) | ||
.build() | ||
|
||
startForeground(Constant.MUSIC_NOTIFICATION_ID, notification) | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ | ||
val serviceChannel = NotificationChannel( | ||
Constant.CHANNEL_ID,"Service Channel", | ||
NotificationManager.IMPORTANCE_DEFAULT | ||
) | ||
val manager = getSystemService( | ||
NotificationManager::class.java | ||
) | ||
|
||
manager.createNotificationChannel(serviceChannel) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
UMC_6th/app/src/main/java/com/example/umc_6th/LockerAlbumRVAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.example.umc_6th | ||
|
||
import android.util.SparseBooleanArray | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.recyclerview.widget.RecyclerView.Recycler | ||
import com.example.umc_6th.databinding.ItemLockerAlbumBinding | ||
|
||
class LockerAlbumRVAdapter (private var albumList: ArrayList<Album>) : RecyclerView.Adapter<LockerAlbumRVAdapter.ViewHolder>(){ | ||
|
||
private val switchStatus = SparseBooleanArray() | ||
private lateinit var itemClickListener : OnItemClickListener | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): LockerAlbumRVAdapter.ViewHolder { | ||
val binding: ItemLockerAlbumBinding = ItemLockerAlbumBinding.inflate(LayoutInflater.from(parent.context),parent,false) | ||
return ViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: LockerAlbumRVAdapter.ViewHolder, position: Int) { | ||
holder.bind(albumList[position]) | ||
holder.itemView.setOnClickListener { | ||
itemClickListener.onItemClick(albumList[position]) | ||
} | ||
|
||
holder.binding.itemLockerAlbumMoreIv.setOnClickListener { | ||
itemClickListener.onRemoveAlbum(position) | ||
} | ||
|
||
val switch = holder.binding.switchRV | ||
switch.isChecked = switchStatus[position] | ||
switch.setOnClickListener { | ||
if(switch.isChecked){ | ||
switchStatus.put(position,true) | ||
} | ||
else{ | ||
switchStatus.put(position,false) | ||
} | ||
notifyItemChanged(position) | ||
} | ||
} | ||
|
||
interface OnItemClickListener { | ||
fun onItemClick(album : Album) | ||
fun onRemoveAlbum(position: Int) { | ||
} | ||
} | ||
|
||
|
||
fun setItemClickListener(onItemClickListener: OnItemClickListener) { | ||
this.itemClickListener = onItemClickListener | ||
} | ||
|
||
fun addItem(album: Album){ | ||
albumList.add(album) | ||
notifyDataSetChanged() | ||
} | ||
|
||
fun removeItem(position: Int){ | ||
albumList.removeAt(position) | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getItemCount(): Int = albumList.size | ||
|
||
inner class ViewHolder(val binding:ItemLockerAlbumBinding) : RecyclerView.ViewHolder(binding.root){ | ||
fun bind(album: Album){ | ||
binding.itemLockerAlbumTitleTv.text = album.title | ||
binding.itemLockerAlbumSingerTv.text = album.singer | ||
binding.itemLockerAlbumCoverImgIv.setImageResource(album.coverImg!!) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.