Skip to content

Commit

Permalink
Replace MATCH_PARENT and WRAP_CONTENT with Anko propertiers
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniolg committed Mar 15, 2017
1 parent 2409e73 commit e323750
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class ImageTitleAdapter(listener: (ImageTitle) -> Unit)
setTextAppearanceC(R.style.TextAppearance_AppCompat_Subhead_Inverse)
maxLines = 1
ellipsize = TextUtils.TruncateAt.END
}.lparams(width = MATCH_PARENT)
}.lparams(width = matchParent)

}.lparams(width = MATCH_PARENT)
}.lparams(width = matchParent)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class AlbumLayout : ActivityAnkoComponent<AlbumActivity> {
image = squareImageView {
id = View.generateViewId()
backgroundResource = android.R.color.darker_gray
}.lparams(width = MATCH_PARENT)
}.lparams(width = matchParent)

toolbar = toolbar(R.style.ThemeOverlay_AppCompat_Dark_ActionBar)
.lparams(width = MATCH_PARENT) {
.lparams(width = matchParent) {
topMargin = dimen(R.dimen.statusbar_height)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import android.support.v4.view.ViewPager
import android.support.v7.widget.Toolbar
import android.view.Gravity
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.ImageView
import com.antonioleiva.bandhookkotlin.R
import com.antonioleiva.bandhookkotlin.ui.activity.ActivityAnkoComponent
Expand All @@ -25,7 +23,9 @@ import org.jetbrains.anko.design.collapsingToolbarLayout
import org.jetbrains.anko.design.coordinatorLayout
import org.jetbrains.anko.design.tabLayout
import org.jetbrains.anko.dip
import org.jetbrains.anko.matchParent
import org.jetbrains.anko.support.v4.viewPager
import org.jetbrains.anko.wrapContent

class ArtistLayout : ActivityAnkoComponent<ArtistActivity> {

Expand All @@ -51,29 +51,29 @@ class ArtistLayout : ActivityAnkoComponent<ArtistActivity> {

image = squareImageView {
fitsSystemWindows = true
}.lparamsC(MATCH_PARENT) {
}.lparamsC(matchParent) {
collapseMode = COLLAPSE_MODE_PARALLAX
}

toolbar = toolbar {
popupTheme = R.style.ThemeOverlay_AppCompat_Light
gravity = Gravity.TOP
titleMarginTop = dip(16)
}.lparamsC(width = MATCH_PARENT, height = dip(88)) {
}.lparamsC(width = matchParent, height = dip(88)) {
collapseMode = COLLAPSE_MODE_PIN
}

tabLayout = tabLayout {
setSelectedTabIndicatorColor(Color.WHITE)
}.lparamsC(width = MATCH_PARENT) {
}.lparamsC(width = matchParent) {
gravity = Gravity.BOTTOM
}

}.lparams(width = MATCH_PARENT) {
}.lparams(width = matchParent) {
scrollFlags = SCROLL_FLAG_SCROLL or SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
}

}.lparams(width = MATCH_PARENT)
}.lparams(width = matchParent)

viewPager = viewPager {
id = View.generateViewId()
Expand All @@ -88,7 +88,7 @@ class ArtistLayout : ActivityAnkoComponent<ArtistActivity> {
* For some reason, the regular lparams is returning FrameLayout LayoutParams, instead of the ones
* for CollapsingToolbarLayout. This fixes it.
*/
private fun <T : android.view.View> T.lparamsC(width: kotlin.Int = WRAP_CONTENT, height: kotlin.Int = WRAP_CONTENT, init: CollapsingToolbarLayout.LayoutParams.() -> kotlin.Unit = {}): T {
private fun <T : android.view.View> T.lparamsC(width: kotlin.Int = wrapContent, height: kotlin.Int = wrapContent, init: CollapsingToolbarLayout.LayoutParams.() -> kotlin.Unit = {}): T {
val params = CollapsingToolbarLayout.LayoutParams(width, height)
params.init()
layoutParams = params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.support.design.widget.AppBarLayout
import android.support.design.widget.AppBarLayout.LayoutParams.*
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import com.antonioleiva.bandhookkotlin.R
import com.antonioleiva.bandhookkotlin.ui.activity.ActivityAnkoComponent
import com.antonioleiva.bandhookkotlin.ui.custom.AutofitRecyclerView
Expand All @@ -15,6 +14,7 @@ import org.jetbrains.anko.appcompat.v7.toolbar
import org.jetbrains.anko.backgroundResource
import org.jetbrains.anko.design.appBarLayout
import org.jetbrains.anko.design.coordinatorLayout
import org.jetbrains.anko.matchParent

class MainLayout : ActivityAnkoComponent<MainActivity> {

Expand All @@ -28,14 +28,14 @@ class MainLayout : ActivityAnkoComponent<MainActivity> {
appBarLayout {
toolbar = toolbar(R.style.ThemeOverlay_AppCompat_Dark_ActionBar) {
backgroundResource = R.color.primary
}.lparams(width = MATCH_PARENT) {
}.lparams(width = matchParent) {
scrollFlags = SCROLL_FLAG_SNAP or SCROLL_FLAG_SCROLL or SCROLL_FLAG_ENTER_ALWAYS
}
}.lparams(width = MATCH_PARENT)
}.lparams(width = matchParent)

recycler = autoFitRecycler()
.apply(AutofitRecyclerView::style)
.lparams(MATCH_PARENT, MATCH_PARENT) {
.lparams(matchParent, matchParent) {
behavior = AppBarLayout.ScrollingViewBehavior()
}
}
Expand Down

0 comments on commit e323750

Please sign in to comment.