Skip to content

Commit

Permalink
Add code style. Update .gitignore. Reformat code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dturner committed Jun 3, 2020
1 parent b8d9c07 commit e1f9074
Show file tree
Hide file tree
Showing 97 changed files with 1,494 additions and 1,149 deletions.
14 changes: 7 additions & 7 deletions .google/packaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ level: INTERMEDIATE
icon: screenshots/icon-web.png

apiRefs:
- android:android.support.v4.media.session.MediaSessionCompat
- android:android.support.v4.media.session.MediaControllerCompat
- androidx.media.MediaBrowserServiceCompat
- android:android.support.v4.media.MediaBrowserCompat
- androidx.media.app.NotificationCompat.MediaStyle
- android:com.google.android.exoplayer2.SimpleExoPlayer
- android:com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
- android:android.support.v4.media.session.MediaSessionCompat
- android:android.support.v4.media.session.MediaControllerCompat
- androidx.media.MediaBrowserServiceCompat
- android:android.support.v4.media.MediaBrowserCompat
- androidx.media.app.NotificationCompat.MediaStyle
- android:com.google.android.exoplayer2.SimpleExoPlayer
- android:com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector

license: apache2-android
129 changes: 129 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2017 Google Inc. All rights reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -83,7 +82,7 @@
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH"/>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
</intent-filter>
</service>

Expand Down
17 changes: 9 additions & 8 deletions app/src/main/java/com/example/android/uamp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class MainActivity : AppCompatActivity() {
volumeControlStream = AudioManager.STREAM_MUSIC

viewModel = ViewModelProviders
.of(this, InjectorUtils.provideMainActivityViewModel(this))
.get(MainActivityViewModel::class.java)
.of(this, InjectorUtils.provideMainActivityViewModel(this))
.get(MainActivityViewModel::class.java)

/**
* Observe [MainActivityViewModel.navigateToFragment] for [Event]s that request a
Expand All @@ -50,7 +50,8 @@ class MainActivity : AppCompatActivity() {
it?.getContentIfNotHandled()?.let { fragmentRequest ->
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(
R.id.fragmentContainer, fragmentRequest.fragment, fragmentRequest.tag)
R.id.fragmentContainer, fragmentRequest.fragment, fragmentRequest.tag
)
if (fragmentRequest.backStack) transaction.addToBackStack(null)
transaction.commit()
}
Expand All @@ -62,11 +63,11 @@ class MainActivity : AppCompatActivity() {
* the initial list of media items.
*/
viewModel.rootMediaId.observe(this,
Observer<String> { rootMediaId ->
if (rootMediaId != null) {
navigateToMediaItem(rootMediaId)
}
})
Observer<String> { rootMediaId ->
if (rootMediaId != null) {
navigateToMediaItem(rootMediaId)
}
})

/**
* Observe [MainActivityViewModel.navigateToMediaItem] for [Event]s indicating
Expand Down
31 changes: 16 additions & 15 deletions app/src/main/java/com/example/android/uamp/MediaItemAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@

package com.example.android.uamp

import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.android.uamp.MediaItemData.Companion.PLAYBACK_RES_CHANGED
import kotlinx.android.synthetic.main.fragment_mediaitem.view.albumArt
import kotlinx.android.synthetic.main.fragment_mediaitem.view.item_state
import kotlinx.android.synthetic.main.fragment_mediaitem.view.subtitle
import kotlinx.android.synthetic.main.fragment_mediaitem.view.title
import kotlinx.android.synthetic.main.fragment_mediaitem.view.*

/**
* [RecyclerView.Adapter] of [MediaItemData]s used by the [MediaItemFragment].
*/
class MediaItemAdapter(private val itemClickedListener: (MediaItemData) -> Unit
class MediaItemAdapter(
private val itemClickedListener: (MediaItemData) -> Unit
) : ListAdapter<MediaItemData, MediaViewHolder>(MediaItemData.diffCallback) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.fragment_mediaitem, parent, false)
.inflate(R.layout.fragment_mediaitem, parent, false)
return MediaViewHolder(view, itemClickedListener)
}

override fun onBindViewHolder(holder: MediaViewHolder,
position: Int,
payloads: MutableList<Any>) {
override fun onBindViewHolder(
holder: MediaViewHolder,
position: Int,
payloads: MutableList<Any>
) {

val mediaItem = getItem(position)
var fullRefresh = payloads.isEmpty()
Expand All @@ -71,8 +71,8 @@ class MediaItemAdapter(private val itemClickedListener: (MediaItemData) -> Unit
holder.playbackState.setImageResource(mediaItem.playbackRes)

Glide.with(holder.albumArt)
.load(mediaItem.albumArtUri)
.into(holder.albumArt)
.load(mediaItem.albumArtUri)
.into(holder.albumArt)
}
}

Expand All @@ -81,8 +81,9 @@ class MediaItemAdapter(private val itemClickedListener: (MediaItemData) -> Unit
}
}

class MediaViewHolder(view: View,
itemClickedListener: (MediaItemData) -> Unit
class MediaViewHolder(
view: View,
itemClickedListener: (MediaItemData) -> Unit
) : RecyclerView.ViewHolder(view) {

val titleView: TextView = view.title
Expand Down
31 changes: 17 additions & 14 deletions app/src/main/java/com/example/android/uamp/MediaItemData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package com.example.android.uamp

import android.net.Uri
import android.support.v4.media.MediaBrowserCompat
import androidx.recyclerview.widget.DiffUtil
import android.support.v4.media.MediaBrowserCompat.MediaItem
import androidx.recyclerview.widget.DiffUtil
import com.example.android.uamp.viewmodels.MediaItemFragmentViewModel

/**
Expand All @@ -32,12 +32,13 @@ import com.example.android.uamp.viewmodels.MediaItemFragmentViewModel
* [MediaItemFragmentViewModel.subscriptionCallback].
*/
data class MediaItemData(
val mediaId: String,
val title: String,
val subtitle: String,
val albumArtUri: Uri,
val browsable: Boolean,
var playbackRes: Int) {
val mediaId: String,
val title: String,
val subtitle: String,
val albumArtUri: Uri,
val browsable: Boolean,
var playbackRes: Int
) {

companion object {
/**
Expand Down Expand Up @@ -66,17 +67,19 @@ data class MediaItemData(
* - If something else changed, then refresh the full item for simplicity.
*/
val diffCallback = object : DiffUtil.ItemCallback<MediaItemData>() {
override fun areItemsTheSame(oldItem: MediaItemData,
newItem: MediaItemData): Boolean =
oldItem.mediaId == newItem.mediaId
override fun areItemsTheSame(
oldItem: MediaItemData,
newItem: MediaItemData
): Boolean =
oldItem.mediaId == newItem.mediaId

override fun areContentsTheSame(oldItem: MediaItemData, newItem: MediaItemData) =
oldItem.mediaId == newItem.mediaId && oldItem.playbackRes == newItem.playbackRes
oldItem.mediaId == newItem.mediaId && oldItem.playbackRes == newItem.playbackRes

override fun getChangePayload(oldItem: MediaItemData, newItem: MediaItemData) =
if (oldItem.playbackRes != newItem.playbackRes) {
PLAYBACK_RES_CHANGED
} else null
if (oldItem.playbackRes != newItem.playbackRes) {
PLAYBACK_RES_CHANGED
} else null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import com.example.android.uamp.R
import com.example.android.uamp.utils.InjectorUtils
import com.example.android.uamp.viewmodels.MainActivityViewModel
import com.example.android.uamp.viewmodels.MediaItemFragmentViewModel
import kotlinx.android.synthetic.main.fragment_mediaitem_list.list
import kotlinx.android.synthetic.main.fragment_mediaitem_list.loadingSpinner
import kotlinx.android.synthetic.main.fragment_mediaitem_list.networkError
import kotlinx.android.synthetic.main.fragment_mediaitem_list.*

/**
* A fragment representing a list of MediaItems.
Expand Down
Loading

0 comments on commit e1f9074

Please sign in to comment.