<commit_before>package org.eurofurence.connavigator.ui

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import io.reactivex.disposables.Disposables
import org.eurofurence.connavigator.database.HasDb
import org.eurofurence.connavigator.database.lazyLocateDb
import org.eurofurence.connavigator.ui.communication.ContentAPI
import org.eurofurence.connavigator.ui.fragments.InfoGroupFragment
import org.eurofurence.connavigator.util.extensions.applyOnRoot
import org.eurofurence.connavigator.util.v2.plus
import org.jetbrains.anko.*
import org.jetbrains.anko.support.v4.UI
import org.jetbrains.anko.support.v4.withArguments


class FragmentViewInfoGroups : Fragment(), ContentAPI, HasDb {
    override val db by lazyLocateDb()
    val ui = ViewInfoGroupsUi()

    var subscriptions = Disposables.empty()

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?) =
            UI { ui.createView(this) }.view

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

        applyOnRoot { changeTitle("Convention Information") }

        fillUi()
        subscriptions += db.subscribe {
            fillUi()
        }
    }

    private fun fillUi() {
        val transaction = childFragmentManager.beginTransaction()

        // Remove existing instances
        db.knowledgeGroups.items
                .map { it.id.toString() }
                .map { childFragmentManager.findFragmentByTag(it) }
                .filter { it != null }
                .forEach { transaction.remove(it) }

        // create new instances
        db.knowledgeGroups.items
                .sortedBy { it.order }
                .map { Pair(InfoGroupFragment().withArguments("id" to it.id.toString()), it.id.toString()) }
                .forEach { transaction.add(1, it.first, it.second) }

        transaction.commit()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        subscriptions.dispose()
        subscriptions = Disposables.empty()
    }
}

class ViewInfoGroupsUi : AnkoComponent<Fragment> {
    override fun createView(ui: AnkoContext<Fragment>) = with(ui) {
        scrollView {
            verticalLayout {
                topPadding = dip(10)
                id = 1
            }
        }
    }

}<commit_msg>Wrap linear layout for some reason<commit_after>package org.eurofurence.connavigator.ui

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import io.reactivex.disposables.Disposables
import org.eurofurence.connavigator.database.HasDb
import org.eurofurence.connavigator.database.lazyLocateDb
import org.eurofurence.connavigator.ui.communication.ContentAPI
import org.eurofurence.connavigator.ui.fragments.InfoGroupFragment
import org.eurofurence.connavigator.util.extensions.applyOnRoot
import org.eurofurence.connavigator.util.v2.plus
import org.jetbrains.anko.*
import org.jetbrains.anko.support.v4.UI
import org.jetbrains.anko.support.v4.withArguments


class FragmentViewInfoGroups : Fragment(), ContentAPI, HasDb {
    override val db by lazyLocateDb()
    val ui = ViewInfoGroupsUi()

    var subscriptions = Disposables.empty()

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?) =
            UI { ui.createView(this) }.view

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

        applyOnRoot { changeTitle("Convention Information") }

        fillUi()
        subscriptions += db.subscribe {
            fillUi()
        }
    }

    private fun fillUi() {
        val transaction = childFragmentManager.beginTransaction()

        // Remove existing instances
        db.knowledgeGroups.items
                .map { it.id.toString() }
                .map { childFragmentManager.findFragmentByTag(it) }
                .filter { it != null }
                .forEach { transaction.remove(it) }

        // create new instances
        db.knowledgeGroups.items
                .sortedBy { it.order }
                .map { Pair(InfoGroupFragment().withArguments("id" to it.id.toString()), it.id.toString()) }
                .forEach { transaction.add(1, it.first, it.second) }

        transaction.commit()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        subscriptions.dispose()
        subscriptions = Disposables.empty()
    }
}

class ViewInfoGroupsUi : AnkoComponent<Fragment> {
    override fun createView(ui: AnkoContext<Fragment>) = with(ui) {
        scrollView {
            relativeLayout {
                verticalLayout {
                    topPadding = dip(10)
                    id = 1
                }
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.09603841536614646, 'fraction_numerical': 0.003201280512204882, 'mean_word_length': 2.662271062271062, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5938843', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1362, 'n_words': 266}