Skip to content
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

Can't move month view and it adds blank space below #138

Open
enarida opened this issue Mar 11, 2018 · 1 comment
Open

Can't move month view and it adds blank space below #138

enarida opened this issue Mar 11, 2018 · 1 comment

Comments

@enarida
Copy link

enarida commented Mar 11, 2018

When i try to swipe up to display the month view it adds a white space below and can't scroll up or down the month view.

screen shot 2018-03-12 at 12 22 27 am

@enarida
Copy link
Author

enarida commented Mar 11, 2018

Here's my Renderer Code

class DrawableEventRenderer : EventRenderer<DrawableCalendarEvents>() {

    override fun render(view: View, event: DrawableCalendarEvents) {

        val imageView = view.findViewById<ImageView>(R.id.view_agenda_event_image)
        val title = view.findViewById<TextView>(R.id.view_agenda_event_title)
        val location = view.findViewById<TextView>(R.id.view_agenda_event_location)
        val descriptionContainer = view.findViewById<LinearLayout>(R.id.view_agenda_event_description_container)
        val locationContainer = view.findViewById<LinearLayout>(R.id.view_agenda_event_location_container)

        descriptionContainer.visibility = View.VISIBLE

        imageView.setImageDrawable(view.context.resources.getDrawable(event.getDrawable()))

        title.setTextColor(view.resources.getColor(android.R.color.black))

        title.text = event.title
        location.text = event.location
        if (event.location.isNotEmpty()) {
            location.visibility = View.VISIBLE
            location.text = event.location
        } else {
            locationContainer.visibility = View.GONE
        }

        if (event.title == view.resources.getString(com.github.tibolte.agendacalendarview.R.string.agenda_event_no_events)) {
            title.setTextColor(view.resources.getColor(android.R.color.black))
        } else {
            title.setTextColor(view.resources.getColor(com.github.tibolte.agendacalendarview.R.color.theme_text_icons))
        }
        descriptionContainer.setBackgroundColor(event.color)
        location.setTextColor(view.resources.getColor(com.github.tibolte.agendacalendarview.R.color.theme_text_icons))
    }

    override fun getEventLayout(): Int {
        return R.layout.view_agenda_event
    }

    override fun getRenderType(): Class<DrawableCalendarEvents> {
        return DrawableCalendarEvents::class.java
    }

    // endregion
}

Calendar

class CalendarFragment : Fragment(), CalendarPickerController {

    private val TAG = "Calendar Fragment"
    private val httpAsync = AsyncHttpClient()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_calendar, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val agendaCalendar = view.findViewById<AgendaCalendarView>(R.id.agenda_calendar_view)

//      Array of events list
        val eventList = ArrayList<CalendarEvent>()
        mockList(eventList)

        val minDate = Calendar.getInstance()
        val maxDate = Calendar.getInstance()

        agendaCalendar.init(eventList, minDate, maxDate, Locale.getDefault(),this)
        agendaCalendar.addEventRenderer(DrawableEventRenderer())

    }

    // region Interface - CalendarPickerController
    override fun onDaySelected(dayItem: DayItem?) {
        Log.d(TAG, String.format("Selected day: %s", dayItem))
    }

    override fun onEventSelected(event: CalendarEvent) {
        Log.d(TAG, String.format("Selected event: %s", event))
    }

    override fun onScrollToDate(calendar: Calendar) {
        val appBar = (activity as AppCompatActivity).supportActionBar
        if (appBar != null) {
            appBar.title = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())
        }
    }

    private fun mockList(eventList: MutableList<CalendarEvent>) {

        httpAsync.get("https://api.myjson.com/bins/11nx99", object : JsonHttpResponseHandler() {
            override fun onSuccess(statusCode: Int, headers: Array<out Header>, response: JSONArray) {

                for (i in 0 until response.length()) {
                    val event = EventData.fromJson(response.getJSONObject(i))
                    val startTime = Calendar.getInstance()
                    val endTime = Calendar.getInstance()
                    startTime.set(Calendar.HOUR_OF_DAY, 14)
                    startTime.set(Calendar.MINUTE, 0)
                    endTime.set(Calendar.HOUR_OF_DAY, 15)
                    endTime.set(Calendar.MINUTE, 0)

                    val addEvent = DrawableCalendarEvents(event.title, event.description, "SCC", ContextCompat.getColor(context!!, R.color.blue_selected)
                            , startTime, endTime,true, android.R.drawable.ic_dialog_info)
                    eventList.add(addEvent)
                }

                val minDate = Calendar.getInstance()
                val maxDate = Calendar.getInstance()

                minDate.add(Calendar.MONTH, -2)
                minDate.set(Calendar.DAY_OF_MONTH, 1)
                maxDate.add(Calendar.YEAR, 1)

                val calendarManager = CalendarManager.getInstance(activity!!.applicationContext)
                calendarManager.buildCal(minDate, maxDate, Locale.getDefault())
                calendarManager.loadEvents(eventList)
            }

            override fun onFailure(statusCode: Int, headers: Array<out Header>?, throwable: Throwable?, errorResponse: JSONObject?) {
                println(throwable?.localizedMessage)
                if (context != null) {
                    Toast.makeText(context, "Please check your internet connection.", Toast.LENGTH_LONG).show()
                }
            }
        })
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant