PageAdapter in matroid-viewable

25 views
Skip to first unread message

Antonio Stilo

unread,
Nov 6, 2015, 3:51:32 PM11/6/15
to macroid
Hello

I am pretty new to develop in scala and i am studying macroid so sorry if i ask something dumb but i have no clue of this problem:

I am trying to use a ViewPager using macroid-viewable, if i follow the official tutorial everything is fine and the ViewPager, but i need something different:
Instead of using .pagerAdapterTweak(...) i need a custom PagerAdapter cause i need to override the method getPageWidth() to have in the same view more then one page.


So i decided to subclass ViewablePagerAdapter everything compile fine but for some reason the page views provided by the Viewable are not rendered:

package com.timeslot.ui.main.fragments.navbar

import android.view.View
import macroid.{ActivityContext, AppContext}
import macroid.viewable.{Viewable, ViewablePagerAdapter}

class NavbarCalendarAdapter[A, +W <: View](data: Seq[A])(implicit ctx: ActivityContext, appCtx: AppContext, viewable: Viewable[A, W])
 
extends ViewablePagerAdapter(data: Seq[A]) {

 
override def getPageWidth(position: Int): Float = 1/3

}




package com.timeslot.ui.main.fragments.navbar

import android.graphics.Color
import android.os.Bundle
import android.support.v4.view.ViewPager
import android.view.ViewGroup.LayoutParams._
import android.view.{Gravity, LayoutInflater, ViewGroup}
import android.widget._
import com.timeslot.R
import com.timeslot.ui.main.fragments.{BaseFragment, Styles}
import com.timeslot.ui.main.style.Measure
import macroid.FullDsl._
import macroid.contrib._
import macroid.viewable.Viewable

/**
 * Created by astilo1 on 03/11/15.
 */


case class MenuDate(value:String)

class TopBarFragment extends BaseFragment {

 
val dates = List(MenuDate("Tu, 3 Nov"),MenuDate("We, 4 Nov"),MenuDate("Th, 5 Nov"),MenuDate("Tu, 6 Nov"),MenuDate("We, 7 Nov"),MenuDate("Th, 8 Nov"),MenuDate("Tu, 9 Nov"),MenuDate("We, 10 Nov"),MenuDate("Th, 11 Nov"))

 
var dateMenu = slot[ViewPager]

 
val lps = lp[LinearLayout](MATCH_PARENT, WRAP_CONTENT, 1.0f)


 
override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle) = getUi {

   
val lps = lp[LinearLayout](MATCH_PARENT, WRAP_CONTENT, Gravity.CENTER_HORIZONTAL) + padding(12,24,12,0)
   
val pagerLps = lp[LinearLayout](MATCH_PARENT, 64, Gravity.CENTER_HORIZONTAL) + padding(0,-6,0,0)

   
implicit def dateViewable: Viewable[MenuDate, TextView] =
     
Viewable[MenuDate] { myDate w[TextView] <~ TextTweaks.size(6 sp) <~ text(myDate.value) <~ TextTweaks.color(Color.RED) <~
        lp
[LinearLayout](WRAP_CONTENT, WRAP_CONTENT, Gravity.TOP)
     
}
   
val pageAdapter = new NavbarCalendarAdapter(dates)

    l
[LinearLayout](
        l
[LinearLayout](
          w
[ImageView] <~ ImageTweaks.res(R.drawable.navbar_me) <~ lp[LinearLayout](Measure.NAVBAR_ITEMS_SIZE, Measure.NAVBAR_ITEMS_SIZE, Gravity.LEFT) + padding(6,6,12,0),
          w[Space] <~ lp[LinearLayout](Measure.NAVBAR_ITEMS_GAP, Measure.NAVBAR_ITEMS_SIZE, Gravity.LEFT),
          w[ImageView] <~ ImageTweaks.res(R.drawable.navbar_logo) <~ lp[LinearLayout](Measure.NAVBAR_LOGO_SIZE , Measure.NAVBAR_LOGO_SIZE , Gravity.CENTER),
          w[Space] <~ lp[LinearLayout](Measure.NAVBAR_ITEMS_GAP, Measure.NAVBAR_ITEMS_SIZE, Gravity.LEFT),
          w[ImageView] <~ ImageTweaks.res(R.drawable.btn_plus_red) <~ lp[LinearLayout](Measure.NAVBAR_ITEMS_SIZE , Measure.NAVBAR_ITEMS_SIZE , Gravity.RIGHT) + padding(12,6,6,0)
       
) <~ lps <~ horizontal,
         l[LinearLayout](// dateViewable.pagerAdapterTweak(dates)
          w[Space] <~ lp[LinearLayout](Measure.NAVBAR_ITEMS_GAP, Measure.NAVBAR_ITEMS_SIZE, Gravity.LEFT),
          w[ViewPager] <~ wire(this.dateMenu) <~ PagerTweaks.adapter(pageAdapter) <~ pagerLps <~ BgTweaks.color(R.color.timeslot_light_grey) ,
          w[Space] <~ lp[LinearLayout](Measure.NAVBAR_ITEMS_GAP, Measure.NAVBAR_ITEMS_SIZE, Gravity.LEFT)
   
) <~ horizontal) <~ Styles.topBar
  }
}

So i don't know what is wrong but in my idea the viewable is passed implicitly to the constructor of my PagerAdapter and something get wrong.

Reply all
Reply to author
Forward
0 new messages