<commit_before>package org.eurofurence.connavigator.ui.adapter

import android.os.Parcelable
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import org.eurofurence.connavigator.database.Db
import org.eurofurence.connavigator.database.filterEvents
import org.eurofurence.connavigator.pref.AppPreferences
import org.eurofurence.connavigator.ui.fragments.EventRecyclerFragment
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.util.*

infix fun Date.sameDayAs(other: Date) =
        time / (24 * 60 * 60 * 1000) == other.time / (24 * 60 * 60 * 1000)

class DayEventPagerAdapter(val db: Db, fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
    override fun saveState(): Parcelable? {
        return null
    }
    val days by lazy { db.days }

    companion object {
        fun indexOfToday(db: Db) =
                Date().let { now ->
                    db.days.asc { it.date }.indexOfFirst { it.date sameDayAs now }
                }
    }

    override fun getPageTitle(position: Int): CharSequence? {
        if (AppPreferences.shortenDates) {
            return DateTime(days.asc { it.date }[position].date).dayOfWeek().asShortText
        } else {
            return DateTime(days.asc { it.date }[position].date).toString(DateTimeFormat.forPattern("MMM d"))
        }
    }


    override fun getItem(position: Int): Fragment? {
        return EventRecyclerFragment().withArguments(db.filterEvents()
                .onDay(days.asc { it.date }[position].id)
                .sortByStartTime())
    }

    override fun getCount(): Int {
        return days.size
    }
}

class RoomEventPagerAdapter(val db: Db, fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
    override fun saveState(): Parcelable? {
        return null
    }
    override fun getItem(position: Int): Fragment {
        return EventRecyclerFragment().withArguments(db.filterEvents()
                .inRoom(rooms.asc { it.name }[position].id)
                .sortByStartTime()
        )
    }

    override fun getPageTitle(position: Int) = rooms.asc { it.name }[position].name

    override fun getCount() = rooms.size

    val rooms by lazy { db.rooms }
}

class TrackEventPagerAdapter(val db: Db, fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
    override fun saveState(): Parcelable? {
        return null
    }
    override fun getItem(position: Int): Fragment {
        return EventRecyclerFragment().withArguments(db.filterEvents()
                .onTrack(tracks[position].id)
                .sortByStartTime()
        )
    }

    override fun getPageTitle(position: Int) = tracks[position].name

    override fun getCount() = tracks.size

    val tracks by lazy { db.tracks.asc { it.name } }
}<commit_msg>fix(events): show days instead of extra glyphs<commit_after>package org.eurofurence.connavigator.ui.adapter

import android.os.Parcelable
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import org.eurofurence.connavigator.database.Db
import org.eurofurence.connavigator.database.filterEvents
import org.eurofurence.connavigator.pref.AppPreferences
import org.eurofurence.connavigator.ui.fragments.EventRecyclerFragment
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.util.*

infix fun Date.sameDayAs(other: Date) =
        time / (24 * 60 * 60 * 1000) == other.time / (24 * 60 * 60 * 1000)

class DayEventPagerAdapter(val db: Db, fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
    override fun saveState(): Parcelable? {
        return null
    }
    val days by lazy { db.days }

    companion object {
        fun indexOfToday(db: Db) =
                Date().let { now ->
                    db.days.asc { it.date }.indexOfFirst { it.date sameDayAs now }
                }
    }

    override fun getPageTitle(position: Int): CharSequence? {
        if (AppPreferences.shortenDates) {
            return DateTime(days.asc { it.date }[position].date).dayOfWeek().asShortText
        } else {
            return DateTime(days.asc { it.date }[position].date).toString(DateTimeFormat.forPattern("MMM d"))
        }
    }


    override fun getItem(position: Int): Fragment? {
        return EventRecyclerFragment().withArguments(db.filterEvents()
                .onDay(days.asc { it.date }[position].id)
                .sortByStartTime())
    }

    override fun getCount(): Int {
        return days.size
    }
}

class RoomEventPagerAdapter(val db: Db, fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
    override fun saveState(): Parcelable? {
        return null
    }
    override fun getItem(position: Int): Fragment {
        return EventRecyclerFragment().withArguments(
                eventList = db.filterEvents()
                    .inRoom(rooms.asc { it.name }[position].id)
                    .sortByStartTime(),
                daysInsteadOfGlyphs = true
        )
    }

    override fun getPageTitle(position: Int) = rooms.asc { it.name }[position].name

    override fun getCount() = rooms.size

    val rooms by lazy { db.rooms }
}

class TrackEventPagerAdapter(val db: Db, fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
    override fun saveState(): Parcelable? {
        return null
    }
    override fun getItem(position: Int): Fragment {
        return EventRecyclerFragment().withArguments(
                eventList = db.filterEvents()
                    .onTrack(tracks[position].id)
                    .sortByStartTime(),
                daysInsteadOfGlyphs = true
        )
    }

    override fun getPageTitle(position: Int) = tracks[position].name

    override fun getCount() = tracks.size

    val tracks by lazy { db.tracks.asc { it.name } }
}
{'fraction_non_alphanumeric': 0.10263637870999834, 'fraction_numerical': 0.0076272591610014925, 'mean_word_length': 2.8056782334384858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3319614', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1689, 'n_words': 374}