Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
androidExtensions {
experimental = true
}
sourceSets { main { assets.srcDirs = ['/res/raw'] } }
}

dependencies {
Expand All @@ -30,8 +34,12 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//noinspection GradleCompatible
implementation 'com.android.support:design:28.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'


}
21 changes: 20 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,39 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidpractice2020">


<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<receiver
android:name=".notification.NotificationActionService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="actionprevious" />
<action android:name="actionplay" />
<action android:name="actionnext" />
<action android:name="actioncancel" />
</intent-filter>
</receiver>

<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.InfoSongActivity" />

<service android:name=".service.SoundService" />
</application>

</manifest>
Binary file added app/src/main/ic_next-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/ic_pause-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/ic_play-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/ic_prev-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/ic_stop-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions app/src/main/java/com/example/androidpractice2020/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.example.androidpractice2020.notification;

import android.app.Notification
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Build
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.example.androidpractice2020.R
import com.example.androidpractice2020.recyclerview.Song
import com.example.androidpractice2020.ui.InfoSongActivity


object CreateNotification {
val CHANNEL_ID: String
get() = "channel1"

val ACTION_PREVIUOS = "actionprevious"
val ACTION_PLAY = "actionplay"
val ACTION_NEXT = "actionnext"
val ACTION_MAIN = "actionmain"
val ACTION_CANCEL = "actioncancel"

fun createNotif(
context: Context,
track: Song,
id: Int
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

val notificationIntent: Intent = Intent(context, InfoSongActivity::class.java)
notificationIntent.putExtra("id", id)
notificationIntent.action = ACTION_MAIN

notificationIntent.flags =
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
val pendingIntent: PendingIntent =
PendingIntent.getActivity(
context,
0,
notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)

val intentCancel = Intent(context, NotificationActionService::class.java)
.setAction(ACTION_CANCEL)
val pendingIntentCancel = PendingIntent.getBroadcast(
context, 0,
intentCancel, PendingIntent.FLAG_UPDATE_CURRENT
)

val notificationManagerCompat =
NotificationManagerCompat.from(context)
val icon =
BitmapFactory.decodeResource(context.resources, track.cover)
val pendingIntentPrevious: PendingIntent?

val intentPrevious = Intent(context, NotificationActionService::class.java)
.setAction(ACTION_PREVIUOS)
pendingIntentPrevious = PendingIntent.getBroadcast(
context, 0,
intentPrevious, PendingIntent.FLAG_UPDATE_CURRENT
)
val intentPlay = Intent(context, NotificationActionService::class.java)
.setAction(ACTION_PLAY)
val pendingIntentPlay = PendingIntent.getBroadcast(
context, 0,
intentPlay, PendingIntent.FLAG_UPDATE_CURRENT
)
val pendingIntentNext: PendingIntent?
val intentNext = Intent(context, NotificationActionService::class.java)
.setAction(ACTION_NEXT)
pendingIntentNext = PendingIntent.getBroadcast(
context, 0,
intentNext, PendingIntent.FLAG_UPDATE_CURRENT
)

//create notification
val notification = NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(track.title)
.setTicker("MPlayer")
.setContentText(track.author)
.setLargeIcon(icon)
.setOngoing(true)
.setContentIntent(pendingIntent)
.addAction(android.R.drawable.ic_media_previous, "Previous", pendingIntentPrevious)
.addAction(android.R.drawable.ic_media_play, "Play/Pause", pendingIntentPlay)
.addAction(android.R.drawable.ic_media_next, "Next", pendingIntentNext)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.build()

notificationManagerCompat.notify(1, notification)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.androidpractice2020.notification

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class NotificationActionService : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
context.sendBroadcast(
Intent("TRACKS_TRACKS")
.putExtra("actionname", intent.action)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.androidpractice2020.recyclerview

import androidx.annotation.DrawableRes
import androidx.annotation.RawRes

data class Song (
val title: String, @DrawableRes val cover: Int, @RawRes val audio: Int, val author: String, val id : Int)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.androidpractice2020.recyclerview

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

class SongAdapter(var list: ArrayList<Song>, var itemClick: (Int) -> Unit) :
RecyclerView.Adapter<SongHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
SongHolder =
SongHolder.create(
parent,
itemClick
)

override fun onBindViewHolder(holder: SongHolder, position: Int) = holder.bind(list[position])

override fun getItemCount(): Int = list.size
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.androidpractice2020.recyclerview

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.androidpractice2020.R
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.song_item.*

class SongHolder(override val containerView: View, var itemClick: (Int) -> Unit) :
RecyclerView.ViewHolder(containerView), LayoutContainer {
fun bind(song: Song) {
title.text = song.title
author.text = song.author
imageView.setImageResource(song.cover)
itemView.setOnClickListener {
itemClick(song.id)
}
}

companion object {
fun create(parent: ViewGroup, itemClick: (Int) -> Unit): SongHolder =
SongHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.song_item,
parent,
false
),
itemClick
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.example.androidpractice2020.recyclerview

import com.example.androidpractice2020.R

object SongRepository {

val songList: ArrayList<Song> = arrayListOf(
Song(
"Monday",
R.drawable.rocket,
R.raw.monday,
"Rocket",
0
),
Song(
"Death Bed",
R.drawable.death_bed,
R.raw.death_bed,
"Powfu",
1
),
Song(
"Deep End",
R.drawable.deep_end,
R.raw.deep_end,
"Foushee",
2
),
Song(
"Money Long",
R.drawable.money_long,
R.raw.money_long,
"Kizaru",
3
),
Song(
"Дежавю",
R.drawable.money_long,
R.raw.dezhavu,
"Kizaru",
4
),
Song(
"Now That You're Gone",
R.drawable.now_that_gone,
R.raw.gone,
"Daniel Silver",
5
)
)

fun find(id: Int): Song {
return songList[id]
}
}
Loading