Skip to content
Permalink
Browse files

Update function param multi-line code style

  • Loading branch information
chrisbanes committed Dec 17, 2019
1 parent 2bb521f commit 1a50ed32a4a65c77945adb5915dec28bc8cd926d
Showing with 337 additions and 74 deletions.
  1. +3 −1 .idea/codeStyles/Project.xml
  2. +4 −1 app/src/main/java/app/tivi/home/HomeActivityViewModel.kt
  3. +4 −1 base-android/src/main/java/app/tivi/extensions/LiveDataExtensions.kt
  4. +4 −1 base-android/src/main/java/app/tivi/util/Event.kt
  5. +5 −1 common-databinding/src/main/java/app/tivi/TiviFragmentWithBinding.kt
  6. +5 −1 common-databinding/src/main/java/app/tivi/databinding/TiviBindingAdapters.kt
  7. +5 −1 common-epoxy/src/main/java/app/tivi/common/epoxy/StickyHeaderScrollListener.kt
  8. +5 −1 common-epoxy/src/main/java/app/tivi/common/epoxy/spanOverrides.kt
  9. +4 −1 common-ui-view/src/main/java/app/tivi/extensions/RecyclerViewExtensions.kt
  10. +5 −1 common-ui-view/src/main/java/app/tivi/ui/ScrimUtil.kt
  11. +9 −2 common-ui-view/src/main/java/app/tivi/ui/StatusBarHeightBehavior.kt
  12. +5 −1 common-ui-view/src/main/java/app/tivi/ui/animations/AnimationUtils.kt
  13. +5 −1 common-ui-view/src/main/java/app/tivi/ui/transitions/GridToGridTransitioner.kt
  14. +5 −1 common-ui-view/src/main/java/app/tivi/ui/transitions/ViewChangeBounds.kt
  15. +10 −2 common-ui-view/src/main/java/app/tivi/ui/widget/PopupMenuButton.kt
  16. +12 −2 common-ui-view/src/main/java/app/tivi/ui/widget/TiviMotionLayout.kt
  17. +5 −1 common-ui-view/src/main/java/app/tivi/ui/widget/TopLeftCutoutBackgroundView.kt
  18. +4 −1 common-ui-view/src/main/java/app/tivi/ui/widget/TwoThreeImageView.kt
  19. +4 −1 data/src/main/java/app/tivi/data/daos/EpisodeWatchEntryDao.kt
  20. +10 −2 data/src/main/java/app/tivi/data/daos/EpisodesDao.kt
  21. +12 −3 data/src/main/java/app/tivi/data/repositories/episodes/EpisodeWatchStore.kt
  22. +15 −3 data/src/main/java/app/tivi/data/repositories/episodes/SeasonsEpisodesDataSource.kt
  23. +8 −2 data/src/main/java/app/tivi/data/repositories/episodes/SeasonsEpisodesRepository.kt
  24. +4 −1 data/src/main/java/app/tivi/data/repositories/episodes/SeasonsEpisodesStore.kt
  25. +5 −1 data/src/main/java/app/tivi/data/repositories/episodes/TmdbEpisodeDataSource.kt
  26. +5 −1 data/src/main/java/app/tivi/data/repositories/episodes/TraktEpisodeDataSource.kt
  27. +12 −3 data/src/main/java/app/tivi/data/repositories/episodes/TraktSeasonsEpisodesDataSource.kt
  28. +4 −1 data/src/main/java/app/tivi/data/repositories/followedshows/FollowedShowsRepository.kt
  29. +4 −1 data/src/main/java/app/tivi/data/repositories/followedshows/FollowedShowsStore.kt
  30. +4 −1 data/src/main/java/app/tivi/data/repositories/popularshows/PopularShowsDataSource.kt
  31. +8 −2 data/src/main/java/app/tivi/data/repositories/popularshows/PopularShowsStore.kt
  32. +4 −1 data/src/main/java/app/tivi/data/repositories/popularshows/TraktPopularShowsDataSource.kt
  33. +4 −1 data/src/main/java/app/tivi/data/repositories/recommendedshows/RecommendedShowsStore.kt
  34. +4 −1 data/src/main/java/app/tivi/data/repositories/relatedshows/RelatedShowsStore.kt
  35. +4 −1 data/src/main/java/app/tivi/data/repositories/shows/ShowRepository.kt
  36. +5 −1 data/src/main/java/app/tivi/data/repositories/shows/ShowStore.kt
  37. +4 −1 data/src/main/java/app/tivi/data/repositories/trendingshows/TraktTrendingShowsDataSource.kt
  38. +4 −1 data/src/main/java/app/tivi/data/repositories/trendingshows/TrendingShowsDataSource.kt
  39. +8 −2 data/src/main/java/app/tivi/data/repositories/trendingshows/TrendingShowsStore.kt
  40. +4 −1 data/src/main/java/app/tivi/data/repositories/watchedshows/WatchedShowsRepository.kt
  41. +4 −1 data/src/main/java/app/tivi/data/repositories/watchedshows/WatchedShowsStore.kt
  42. +4 −1 ui-discover/src/main/java/app/tivi/home/discover/DiscoverViewModel.kt
  43. +9 −2 ui-episodedetails/src/main/java/app/tivi/episodedetails/EpisodeDetailsFragment.kt
  44. +16 −3 ui-followed/src/main/java/app/tivi/home/followed/FollowedEpoxyController.kt
  45. +5 −1 ui-followed/src/main/java/app/tivi/home/followed/FollowedFragment.kt
  46. +4 −1 ui-followed/src/main/java/app/tivi/home/followed/FollowedViewModel.kt
  47. +4 −1 ui-recommended/src/main/java/app/tivi/home/recommended/RecommendedShowsViewModel.kt
  48. +4 −1 ui-search/src/main/java/app/tivi/home/search/SearchViewModel.kt
  49. +16 −3 ui-showdetails/src/main/java/app/tivi/showdetails/details/ShowDetailsAction.kt
  50. +5 −1 ui-showdetails/src/main/java/app/tivi/showdetails/details/ShowDetailsFragment.kt
  51. +4 −1 ui-showdetails/src/main/java/app/tivi/showdetails/details/ShowDetailsViewState.kt
  52. +18 −3 ui-watched/src/main/java/app/tivi/home/watched/WatchedEpoxyController.kt
  53. +5 −1 ui-watched/src/main/java/app/tivi/home/watched/WatchedFragment.kt
  54. +4 −1 ui-watched/src/main/java/app/tivi/home/watched/WatchedViewModel.kt
@@ -8,7 +8,6 @@
</option>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="CONTINUATION_INDENT_IN_PARAMETER_LISTS" value="false" />
</JetCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
@@ -130,6 +129,9 @@
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="FIELD_ANNOTATION_WRAP" value="1" />
<option name="VARIABLE_ANNOTATION_WRAP" value="1" />
<indentOptions>
@@ -80,7 +80,10 @@ class HomeActivityViewModel @AssistedInject constructor(
}

companion object : MvRxViewModelFactory<HomeActivityViewModel, HomeActivityViewState> {
override fun create(viewModelContext: ViewModelContext, state: HomeActivityViewState): HomeActivityViewModel? {
override fun create(
viewModelContext: ViewModelContext,
state: HomeActivityViewState
): HomeActivityViewModel? {
val fragment: HomeActivity = viewModelContext.activity()
return fragment.homeNavigationViewModelFactory.create(state)
}
@@ -27,7 +27,10 @@ inline fun <T> LiveData<T>.observeK(owner: LifecycleOwner, crossinline observer:
this.observe(owner, Observer { observer(it) })
}

inline fun <T> LiveData<T>.observeNotNull(owner: LifecycleOwner, crossinline observer: (T) -> Unit) {
inline fun <T> LiveData<T>.observeNotNull(
owner: LifecycleOwner,
crossinline observer: (T) -> Unit
) {
this.observe(owner, Observer { it?.run(observer) })
}

@@ -59,6 +59,9 @@ class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Obser
}
}

inline fun <T> LiveData<Event<T>>.observeEvent(owner: LifecycleOwner, crossinline observer: (T) -> Unit) {
inline fun <T> LiveData<Event<T>>.observeEvent(
owner: LifecycleOwner,
crossinline observer: (T) -> Unit
) {
observe(owner, EventObserver { observer(it) })
}
@@ -31,7 +31,11 @@ abstract class TiviFragmentWithBinding<V : ViewDataBinding> : TiviFragment() {
var binding: V? = null
private set

final override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
final override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return createBinding(inflater, container, savedInstanceState)
.also { binding = it }
.root
@@ -114,7 +114,11 @@ fun roundedCornerOutlineProvider(view: View, oldRadius: Float, radius: Float) {
}

@BindingAdapter("textAppearanceAttr")
fun textAppearanceAttr(view: TextView, oldTextAppearanceStyleAttr: Int, textAppearanceStyleAttr: Int) {
fun textAppearanceAttr(
view: TextView,
oldTextAppearanceStyleAttr: Int,
textAppearanceStyleAttr: Int
) {
if (oldTextAppearanceStyleAttr != textAppearanceStyleAttr) {
view.setTextAppearance(view.context.resolveThemeReferenceResId(textAppearanceStyleAttr))
}
@@ -94,7 +94,11 @@ class StickyHeaderScrollListener(
return false
}

private fun getChildInContact(parent: RecyclerView, contactPoint: Int, currentHeaderPos: Int): View? {
private fun getChildInContact(
parent: RecyclerView,
contactPoint: Int,
currentHeaderPos: Int
): View? {
for (i in 0 until parent.childCount) {
var heightTolerance = 0
val child = parent.getChildAt(i)
@@ -23,5 +23,9 @@ object TotalSpanOverride : EpoxyModel.SpanSizeOverrideCallback {
}

object HalfSpanOverride : EpoxyModel.SpanSizeOverrideCallback {
override fun getSpanSize(totalSpanCount: Int, position: Int, itemCount: Int) = (totalSpanCount / 2).coerceAtLeast(1)
override fun getSpanSize(
totalSpanCount: Int,
position: Int,
itemCount: Int
) = (totalSpanCount / 2).coerceAtLeast(1)
}
@@ -23,7 +23,10 @@ import app.tivi.ui.recyclerview.TiviLinearSmoothScroller
import kotlin.coroutines.resume
import kotlinx.coroutines.suspendCancellableCoroutine

fun <VH : RecyclerView.ViewHolder> RecyclerView.Adapter<VH>.createAndBind(parent: ViewGroup, position: Int): VH {
fun <VH : RecyclerView.ViewHolder> RecyclerView.Adapter<VH>.createAndBind(
parent: ViewGroup,
position: Int
): VH {
val vh = onCreateViewHolder(parent, getItemViewType(position))
onBindViewHolder(vh, position)
return vh
@@ -41,7 +41,11 @@ object ScrimUtil {
* [this post](https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf) for more
* details.
*/
fun makeCubicGradientScrimDrawable(@ColorInt baseColor: Int, numStops: Int, gravity: Int): Drawable {
fun makeCubicGradientScrimDrawable(
@ColorInt baseColor: Int,
numStops: Int,
gravity: Int
): Drawable {
// Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
var cacheKeyHash = baseColor
cacheKeyHash = 31 * cacheKeyHash + numStops
@@ -22,8 +22,15 @@ import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.WindowInsetsCompat

class StatusBarHeightBehavior(context: Context, attrs: AttributeSet?) : CoordinatorLayout.Behavior<View>(context, attrs) {
override fun onApplyWindowInsets(coordinatorLayout: CoordinatorLayout, child: View, insets: WindowInsetsCompat): WindowInsetsCompat {
class StatusBarHeightBehavior(
context: Context,
attrs: AttributeSet?
) : CoordinatorLayout.Behavior<View>(context, attrs) {
override fun onApplyWindowInsets(
coordinatorLayout: CoordinatorLayout,
child: View,
insets: WindowInsetsCompat
): WindowInsetsCompat {
val lp = child.layoutParams
lp.height = insets.systemWindowInsetTop
child.layoutParams = lp
@@ -16,4 +16,8 @@

package app.tivi.ui.animations

fun lerp(startValue: Float, endValue: Float, fraction: Float) = startValue + fraction * (endValue - startValue)
fun lerp(
startValue: Float,
endValue: Float,
fraction: Float
) = startValue + fraction * (endValue - startValue)
@@ -73,7 +73,11 @@ object GridToGridTransitioner {
* @param fragment The fragment to setup
* @param fadeElementIds An array of view ids which will fade rather than slide. This will typically be your toolbar
*/
fun setupSecondFragment(fragment: Fragment, vararg fadeElementIds: Int, onTransitionEnd: () -> Unit) {
fun setupSecondFragment(
fragment: Fragment,
vararg fadeElementIds: Int,
onTransitionEnd: () -> Unit
) {
fragment.sharedElementEnterTransition = ColumnedChangeBounds().apply {
interpolator = FAST_OUT_SLOW_IN_INTERPOLATOR
duration = GRID_SHARED_ELEMENT_ENTER_DURATION
@@ -260,7 +260,11 @@ open class ViewChangeBounds : Transition() {

val BOTTOM_RIGHT_PROPERTY: Property<PointFBounds, PointF> =
object : Property<PointFBounds, PointF>(PointF::class.java, "bottomRight") {
override fun set(bounds: PointFBounds, bottomRight: PointF) = bounds.setBottomRight(bottomRight)
override fun set(
bounds: PointFBounds,
bottomRight: PointF
) = bounds.setBottomRight(bottomRight)

override fun get(bounds: PointFBounds): PointF? = bounds.getBottomRight()
}

@@ -30,8 +30,16 @@ import app.tivi.common.ui.R

class PopupMenuButton : AppCompatImageButton {
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, android.R.attr.actionOverflowButtonStyle)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
constructor(
context: Context,
attrs: AttributeSet?
) : this(context, attrs, android.R.attr.actionOverflowButtonStyle)

constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr) {
val a = context.obtainStyledAttributes(attrs, R.styleable.PopupMenuButton)
val menuRes = a.getResourceId(R.styleable.PopupMenuButton_menu, -1)
if (menuRes != -1) {
@@ -41,7 +41,12 @@ class TiviMotionLayout @JvmOverloads constructor(

init {
super.setTransitionListener(object : TransitionListener {
override fun onTransitionTrigger(motionLayout: MotionLayout, triggerId: Int, positive: Boolean, progress: Float) {
override fun onTransitionTrigger(
motionLayout: MotionLayout,
triggerId: Int,
positive: Boolean,
progress: Float
) {
listeners.forEach {
it.onTransitionTrigger(motionLayout, triggerId, positive, progress)
}
@@ -53,7 +58,12 @@ class TiviMotionLayout @JvmOverloads constructor(
}
}

override fun onTransitionChange(motionLayout: MotionLayout, startId: Int, endId: Int, progress: Float) {
override fun onTransitionChange(
motionLayout: MotionLayout,
startId: Int,
endId: Int,
progress: Float
) {
listeners.forEach {
it.onTransitionChange(motionLayout, startId, endId, progress)
}
@@ -31,7 +31,11 @@ class TopLeftCutoutBackgroundView : View {

constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr) {
val a = context.obtainStyledAttributes(attrs, R.styleable.TopLeftCutoutBackgroundView)
color = a.getColor(R.styleable.TopLeftCutoutBackgroundView_backgroundColor, Color.MAGENTA)
maxCutSize = a.getDimension(R.styleable.TopLeftCutoutBackgroundView_topLeftCutSize, 0f)
@@ -21,7 +21,10 @@ import android.util.AttributeSet
import android.view.View.MeasureSpec.EXACTLY
import androidx.appcompat.widget.AppCompatImageView

class TwoThreeImageView(context: Context?, attrs: AttributeSet?) : AppCompatImageView(context, attrs) {
class TwoThreeImageView(
context: Context?,
attrs: AttributeSet?
) : AppCompatImageView(context, attrs) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val height = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec) * 3 / 2, EXACTLY)
super.onMeasure(widthMeasureSpec, height)
@@ -61,7 +61,10 @@ abstract class EpisodeWatchEntryDao : EntityDao<EpisodeWatchEntry> {
INNER JOIN shows ON s.show_id = shows.id
WHERE shows.id = :showId AND ew.pending_action = :pendingAction
""")
internal abstract suspend fun entriesForShowIdWithPendingAction(showId: Long, pendingAction: String): List<EpisodeWatchEntry>
internal abstract suspend fun entriesForShowIdWithPendingAction(
showId: Long,
pendingAction: String
): List<EpisodeWatchEntry>

@Query("""
SELECT ew.* FROM episode_watch_entries AS ew
@@ -59,10 +59,18 @@ abstract class EpisodesDao : EntityDao<Episode> {
abstract fun observeLatestWatchedEpisodeForShowId(showId: Long): Flow<EpisodeWithSeason?>

@Query(nextEpisodeForShowIdAfter)
abstract fun observeNextEpisodeForShowAfter(showId: Long, seasonNumber: Int, episodeNumber: Int): Flow<EpisodeWithSeason?>
abstract fun observeNextEpisodeForShowAfter(
showId: Long,
seasonNumber: Int,
episodeNumber: Int
): Flow<EpisodeWithSeason?>

@Query(nextAiredEpisodeForShowIdAfter)
abstract fun observeNextAiredEpisodeForShowAfter(showId: Long, seasonNumber: Int, episodeNumber: Int): Flow<EpisodeWithSeason?>
abstract fun observeNextAiredEpisodeForShowAfter(
showId: Long,
seasonNumber: Int,
episodeNumber: Int
): Flow<EpisodeWithSeason?>

companion object {
const val latestWatchedEpisodeForShowId = """
@@ -65,17 +65,26 @@ class EpisodeWatchStore @Inject constructor(
return episodeWatchEntryDao.updateEntriesToPendingAction(ids, action.value)
}

suspend fun addNewShowWatchEntries(showId: Long, watches: List<EpisodeWatchEntry>) = transactionRunner {
suspend fun addNewShowWatchEntries(
showId: Long,
watches: List<EpisodeWatchEntry>
) = transactionRunner {
val currentWatches = episodeWatchEntryDao.entriesForShowIdWithNoPendingAction(showId)
episodeWatchSyncer.sync(currentWatches, watches, removeNotMatched = false)
}

suspend fun syncShowWatchEntries(showId: Long, watches: List<EpisodeWatchEntry>) = transactionRunner {
suspend fun syncShowWatchEntries(
showId: Long,
watches: List<EpisodeWatchEntry>
) = transactionRunner {
val currentWatches = episodeWatchEntryDao.entriesForShowIdWithNoPendingAction(showId)
episodeWatchSyncer.sync(currentWatches, watches)
}

suspend fun syncEpisodeWatchEntries(episodeId: Long, watches: List<EpisodeWatchEntry>) = transactionRunner {
suspend fun syncEpisodeWatchEntries(
episodeId: Long,
watches: List<EpisodeWatchEntry>
) = transactionRunner {
val currentWatches = episodeWatchEntryDao.watchesForEpisode(episodeId)
episodeWatchSyncer.sync(currentWatches, watches)
}
@@ -24,9 +24,21 @@ import org.threeten.bp.OffsetDateTime

interface SeasonsEpisodesDataSource {
suspend fun getSeasonsEpisodes(showId: Long): Result<List<Pair<Season, List<Episode>>>>
suspend fun getShowEpisodeWatches(showId: Long, since: OffsetDateTime? = null): Result<List<Pair<Episode, EpisodeWatchEntry>>>
suspend fun getEpisodeWatches(episodeId: Long, since: OffsetDateTime? = null): Result<List<EpisodeWatchEntry>>
suspend fun getSeasonWatches(seasonId: Long, since: OffsetDateTime? = null): Result<List<Pair<Episode, EpisodeWatchEntry>>>
suspend fun getShowEpisodeWatches(
showId: Long,
since: OffsetDateTime? = null
): Result<List<Pair<Episode, EpisodeWatchEntry>>>

suspend fun getEpisodeWatches(
episodeId: Long,
since: OffsetDateTime? = null
): Result<List<EpisodeWatchEntry>>

suspend fun getSeasonWatches(
seasonId: Long,
since: OffsetDateTime? = null
): Result<List<Pair<Episode, EpisodeWatchEntry>>>

suspend fun addEpisodeWatches(watches: List<EpisodeWatchEntry>): Result<Unit>
suspend fun removeEpisodeWatches(watches: List<EpisodeWatchEntry>): Result<Unit>
}
@@ -58,7 +58,10 @@ class SeasonsEpisodesRepository @Inject constructor(

fun observeNextEpisodeToWatch(showId: Long) = seasonsEpisodesStore.observeShowNextEpisodeToWatch(showId)

suspend fun needShowSeasonsUpdate(showId: Long, expiry: Instant = instantInPast(days = 7)): Boolean {
suspend fun needShowSeasonsUpdate(
showId: Long,
expiry: Instant = instantInPast(days = 7)
): Boolean {
return seasonsLastRequestStore.isRequestBefore(showId, expiry)
}

@@ -161,7 +164,10 @@ class SeasonsEpisodesRepository @Inject constructor(
}
}

suspend fun needShowEpisodeWatchesSync(showId: Long, expiry: Instant = instantInPast(hours = 1)): Boolean {
suspend fun needShowEpisodeWatchesSync(
showId: Long,
expiry: Instant = instantInPast(hours = 1)
): Boolean {
return episodeWatchLastLastRequestStore.isRequestBefore(showId, expiry)
}

@@ -91,7 +91,10 @@ class SeasonsEpisodesStore @Inject constructor(
seasonsDao.updateSeasonIgnoreFlag(seasonId, !followed)
}

suspend fun updatePreviousSeasonFollowed(seasonId: Long, followed: Boolean) = transactionRunner {
suspend fun updatePreviousSeasonFollowed(
seasonId: Long,
followed: Boolean
) = transactionRunner {
for (id in seasonsDao.showPreviousSeasonIds(seasonId)) {
seasonsDao.updateSeasonIgnoreFlag(id, !followed)
}
@@ -31,7 +31,11 @@ class TmdbEpisodeDataSource @Inject constructor(
private val tmdb: Tmdb,
private val episodeMapper: TmdbEpisodeToEpisode
) : EpisodeDataSource {
override suspend fun getEpisode(showId: Long, seasonNumber: Int, episodeNumber: Int): Result<Episode> {
override suspend fun getEpisode(
showId: Long,
seasonNumber: Int,
episodeNumber: Int
): Result<Episode> {
return tmdb.tvEpisodesService()
.episode(tmdbIdMapper.map(showId), seasonNumber, episodeNumber, null)
.executeWithRetry()

0 comments on commit 1a50ed3

Please sign in to comment.
You can’t perform that action at this time.