-
Notifications
You must be signed in to change notification settings - Fork 0
hw-7 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rinstance
wants to merge
1
commit into
master
Choose a base branch
from
hw-7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
hw-7 #7
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| // ISongAidlInterface.aidl | ||
| package com.example.myapplication; | ||
|
|
||
| // Declare any non-default types here with import statements | ||
|
|
||
| interface ISongAidlInterface { | ||
| /** | ||
| * Demonstrates some basic types that you can use as parameters | ||
| * and return values in AIDL. | ||
| */ | ||
| void play(); | ||
| void pause(); | ||
| boolean isPlaying(); | ||
| boolean isMPReleased(); | ||
| int getDuration(); | ||
| int getCurrentPosition(); | ||
| void changeTime(int time); | ||
| void playNext(); | ||
| void playPrev(); | ||
|
|
||
| Song getSong(); | ||
| void setCurrentSong(int position); | ||
| void setCurrentSongFromBundle(in Bundle bundle); | ||
| } | ||
|
|
||
| parcelable Song; |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/example/myapplication/MainActivity.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,54 @@ | ||
| package com.example.myapplication | ||
|
|
||
| import android.content.ComponentName | ||
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.content.ServiceConnection | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import android.os.Bundle | ||
| import android.os.IBinder | ||
| import android.util.Log | ||
| import androidx.core.app.NotificationCompat | ||
| import com.example.myapplication.screens.songsList.SongsListFragment | ||
| import com.example.myapplication.service.SongService | ||
|
|
||
| class MainActivity : AppCompatActivity() { | ||
| var songService: ISongAidlInterface? = null | ||
| lateinit var builder: NotificationCompat.Builder | ||
| val CHANNEL_ID = "playerChannel" | ||
|
|
||
| private val aidlConnection = object : ServiceConnection { | ||
|
|
||
| override fun onServiceConnected(className: ComponentName, service: IBinder) { | ||
| songService = ISongAidlInterface.Stub.asInterface(service) | ||
| supportFragmentManager.beginTransaction(). | ||
| replace(R.id.frameLayout, SongsListFragment()).commit() | ||
| } | ||
|
|
||
| override fun onServiceDisconnected(className: ComponentName) { | ||
| songService = null | ||
| } | ||
| } | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_main) | ||
| } | ||
|
|
||
| override fun onStart() { | ||
| super.onStart() | ||
| val intent = | ||
| Intent(this, SongService::class.java) | ||
| bindService(intent, aidlConnection, Context.BIND_AUTO_CREATE) | ||
| } | ||
|
|
||
| override fun onDestroy() { | ||
| super.onDestroy() | ||
| Log.e("LOG_TAG", "MainActivity onServiceDisconnected") | ||
| songService?.let { | ||
| unbindService(aidlConnection) | ||
| songService = null | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or 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,44 @@ | ||
| package com.example.myapplication | ||
|
|
||
| import android.os.Parcel | ||
| import android.os.Parcelable | ||
| import androidx.annotation.DrawableRes | ||
| import androidx.annotation.RawRes | ||
|
|
||
| data class Song( | ||
| var author: String = "", | ||
| var name: String = "", | ||
| @DrawableRes var photoId: Int = 0, | ||
| @RawRes var songId: Int = 0 | ||
| ) : Parcelable { | ||
|
|
||
| companion object CREATOR : Parcelable.Creator<Song> { | ||
| override fun createFromParcel(parcel: Parcel): Song { | ||
| return Song(parcel) | ||
| } | ||
|
|
||
| override fun newArray(size: Int): Array<Song> { | ||
| return Array(size) { Song() } | ||
| } | ||
| } | ||
|
|
||
| private constructor(inParcel: Parcel) : this() { | ||
| readFromParcel(inParcel) | ||
| } | ||
|
|
||
| private fun readFromParcel(inParcel: Parcel) { | ||
| author = inParcel.readString() ?: "" | ||
| name = inParcel.readString() ?: "" | ||
| songId = inParcel.readInt() ?: 0 | ||
| photoId = inParcel.readInt() ?: 0 | ||
| } | ||
|
|
||
| override fun writeToParcel(outParcel: Parcel, flags: Int) { | ||
| outParcel.writeString(author) | ||
| outParcel.writeString(name) | ||
| outParcel.writeInt(songId) | ||
| outParcel.writeInt(photoId) | ||
| } | ||
|
|
||
| override fun describeContents(): Int = 0 | ||
| } |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/example/myapplication/adapters/SongAdapter.kt
This file contains hidden or 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,44 @@ | ||
| package com.example.myapplication.adapters | ||
|
|
||
|
|
||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.example.myapplication.Song | ||
| import com.example.myapplication.R | ||
| import kotlinx.android.extensions.LayoutContainer | ||
| import kotlinx.android.synthetic.main.item_song.* | ||
|
|
||
|
|
||
| class SongAdapter ( | ||
| private var list: ArrayList<Song>, | ||
| private val fragmentLambda: (View, Int) -> Unit | ||
| ) : RecyclerView.Adapter<SongAdapter.SongViewHolder>() { | ||
|
|
||
| inner class SongViewHolder( | ||
| override val containerView: View | ||
| ): RecyclerView.ViewHolder(containerView), LayoutContainer { | ||
|
|
||
| fun bind(song: Song, position: Int) { | ||
| with(song) { | ||
| tv_sm_title.text = name | ||
| tv_sm_author.text = author | ||
| iv_sm_album.setImageResource(song.photoId) | ||
| } | ||
|
|
||
| itemView.setOnClickListener{fragmentLambda(itemView,position)} | ||
| } | ||
| } | ||
|
|
||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SongViewHolder { | ||
| return SongViewHolder(LayoutInflater.from(parent.context). | ||
| inflate(R.layout.item_song, parent, false)) | ||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: SongViewHolder, position: Int) { | ||
| holder.bind(list[position], position) | ||
| } | ||
|
|
||
| override fun getItemCount(): Int = list.size | ||
| } |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/example/myapplication/repository/SongRepository.kt
This file contains hidden or 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,14 @@ | ||
| package com.example.myapplication.repository | ||
|
|
||
| import com.example.myapplication.Song | ||
| import com.example.myapplication.R | ||
|
|
||
| object SongRepository { | ||
| val songsList: List<Song> = arrayListOf( | ||
| Song("SLAVA","Снова я напиваюсь", R.drawable.straus, R.raw.again_drink), | ||
| Song("Dora","Втюрилась", R.drawable.straus, R.raw.dora), | ||
| Song("Нурминчик","Валим валим на гелике", R.drawable.straus, R.raw.valim), | ||
| Song("Нурминчик","Ауф", R.drawable.straus, R.raw.auf), | ||
| Song("Кто-то","Арабская", R.drawable.straus, R.raw.arabskay) | ||
| ) | ||
| } |
85 changes: 85 additions & 0 deletions
85
app/src/main/java/com/example/myapplication/screens/song/SongFragment.kt
This file contains hidden or 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,85 @@ | ||
| package com.example.myapplication.screens.song | ||
|
|
||
| import android.os.Bundle | ||
| import android.os.Handler | ||
| import androidx.fragment.app.Fragment | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import android.widget.SeekBar | ||
| import com.example.myapplication.ISongAidlInterface | ||
| import com.example.myapplication.MainActivity | ||
| import com.example.myapplication.R | ||
| import com.example.myapplication.Song | ||
| import kotlinx.android.synthetic.main.fragment_song.* | ||
|
|
||
| class SongFragment : Fragment() { | ||
| var service: ISongAidlInterface? = null | ||
|
|
||
| override fun onCreateView( | ||
| inflater: LayoutInflater, container: ViewGroup?, | ||
| savedInstanceState: Bundle? | ||
| ): View? { | ||
| return inflater.inflate(R.layout.fragment_song, container, false) | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| val activity = (activity as MainActivity?) | ||
| service = activity?.songService | ||
| changeUI(service?.song) | ||
| initialiseSeekBar() | ||
|
|
||
|
|
||
| iv_play.setOnClickListener { | ||
| if (service?.isPlaying == true) { | ||
| iv_play.setImageResource(R.drawable.ic_play) | ||
| service?.pause() | ||
| } else if (service?.isPlaying == false) { | ||
| iv_play.setImageResource(R.drawable.ic_pause) | ||
| service?.play() | ||
| } | ||
| } | ||
| iv_next.setOnClickListener { | ||
| service?.playNext() | ||
| changeUI(service?.song) | ||
| } | ||
| iv_prev.setOnClickListener { | ||
| service?.playPrev() | ||
| changeUI(service?.song) | ||
| } | ||
| seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | ||
| override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) { | ||
| if (p2) { | ||
| service?.changeTime(p1) | ||
| } | ||
| } | ||
|
|
||
| override fun onStartTrackingTouch(p0: SeekBar?) { | ||
| } | ||
|
|
||
| override fun onStopTrackingTouch(p0: SeekBar?) { | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| private fun changeUI(song: Song?) { | ||
| song?.photoId?.let { iv_album.setImageResource(it) } | ||
| tv_author.text = song?.author | ||
| tv_name.text = song?.name | ||
|
|
||
| } | ||
|
|
||
| private fun initialiseSeekBar() { | ||
| seekBar.max = service!!.duration | ||
| var handler: Handler = Handler() | ||
| handler.postDelayed(object : Runnable { | ||
| override fun run() { | ||
| seekBar.progress = service?.currentPosition!! | ||
| handler.postDelayed(this, 1000) | ||
| } | ||
| }, 0) | ||
| } | ||
|
|
||
|
|
||
| } |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/example/myapplication/screens/songsList/SongsListFragment.kt
This file contains hidden or 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,53 @@ | ||
| package com.example.myapplication.screens.songsList | ||
|
|
||
| import android.os.Bundle | ||
| import androidx.fragment.app.Fragment | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import com.example.myapplication.ISongAidlInterface | ||
| import com.example.myapplication.MainActivity | ||
| import com.example.myapplication.Song | ||
| import com.example.myapplication.adapters.SongAdapter | ||
| import com.example.myapplication.repository.SongRepository | ||
| import com.example.myapplication.screens.song.SongFragment | ||
| import com.example.myapplication.R | ||
| import kotlinx.android.synthetic.main.fragment_songs_list.* | ||
|
|
||
| class SongsListFragment : Fragment() { | ||
|
|
||
| private var adapter: SongAdapter? = null | ||
| var service: ISongAidlInterface? = null | ||
| override fun onCreateView( | ||
| inflater: LayoutInflater, container: ViewGroup?, | ||
| savedInstanceState: Bundle? | ||
| ): View? { | ||
| return inflater.inflate(R.layout.fragment_songs_list, container, false) | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
|
|
||
| val activity = (activity as MainActivity?) | ||
| service = activity?.songService | ||
| adapter = SongAdapter(SongRepository.songsList as ArrayList<Song>) { item, position -> | ||
| val transaction = activity?.supportFragmentManager?.beginTransaction() | ||
|
|
||
| transaction?.addToBackStack(null) | ||
| item.setOnClickListener { | ||
| if (service?.isMPReleased == true | ||
| || service?.song != SongRepository.songsList[position] | ||
| ) { | ||
| service?.setCurrentSong(position) | ||
| } | ||
|
|
||
| transaction?.replace( | ||
| R.id.frameLayout, | ||
| SongFragment() | ||
| )?.commit() | ||
|
|
||
| } | ||
| } | ||
| rv_song.adapter = adapter | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
обычно перенос строки идет после || , а не перед