<commit_before>package org.worshipsongs.preference

import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.preference.DialogPreference
import android.preference.PreferenceManager
import android.support.v7.widget.LinearLayoutManager
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.TextView

import com.woxthebox.draglistview.DragItem
import com.woxthebox.draglistview.DragListView

import org.worshipsongs.CommonConstants
import org.worshipsongs.R
import org.worshipsongs.adapter.ItemAdapter
import org.worshipsongs.domain.DragDrop
import org.worshipsongs.registry.FragmentRegistry

import java.util.ArrayList

/**
 * Author : Madasamy
 * Version : 3.x
 */

class TabChoicePreference(context: Context, attrs: AttributeSet) : DialogPreference(context, attrs), ItemAdapter.Listener
{
    private var configureDragDrops: ArrayList<DragDrop>? = null
    private var mDragListView: DragListView? = null
    private val sharedPreferences: SharedPreferences
    private val fragmentRegistry = FragmentRegistry()

    init
    {
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
        setItems()
        dialogLayoutResource = R.layout.tab_choice_layout
    }

    override fun onBindDialogView(view: View)
    {
        view.setBackgroundColor(context.resources.getColor(R.color.white))
        setDragListView(view)
        super.onBindDialogView(view)
    }

    override fun onDialogClosed(positiveResult: Boolean)
    {
        Log.i(TabChoicePreference::class.java.simpleName, "Tab choice preference $positiveResult")
        if (positiveResult)
        {
            val itemList = mDragListView!!.adapter.itemList as ArrayList<DragDrop>
            sharedPreferences.edit().putString(CommonConstants.TAB_CHOICE_KEY, DragDrop.toJson(itemList)).apply()
            sharedPreferences.edit().putBoolean(CommonConstants.UPDATE_NAV_ACTIVITY_KEY, true).apply()
        }
        super.onDialogClosed(positiveResult)
    }

    private fun setItems()
    {
        configureDragDrops = DragDrop.toArrays(sharedPreferences.getString(CommonConstants.TAB_CHOICE_KEY, ""))
        val defaultList = fragmentRegistry.getDragDrops(context as Activity)
        if (configureDragDrops == null || configureDragDrops!!.isEmpty())
        {
            configureDragDrops = defaultList
            sharedPreferences.edit().putString(CommonConstants.TAB_CHOICE_KEY, DragDrop.toJson(configureDragDrops)).apply()
        } else if (defaultList.size > configureDragDrops!!.size)
        {
            defaultList.removeAll(configureDragDrops!!)
            configureDragDrops!!.addAll(defaultList)
        }
    }

    private fun setDragListView(view: View)
    {
        mDragListView = view.findViewById<View>(R.id.drag_list_view) as DragListView
        mDragListView!!.recyclerView.isVerticalScrollBarEnabled = true
        mDragListView!!.setLayoutManager(LinearLayoutManager(context))
        val listAdapter = ItemAdapter(configureDragDrops!!, R.layout.tab_choice_item, R.id.image, false)
        listAdapter.setListener(this)
        mDragListView!!.setAdapter(listAdapter, true)
        mDragListView!!.setCanDragHorizontally(false)
        mDragListView!!.setCustomDragItem(MyDragItem(context, R.layout.tab_choice_item))
    }

    override fun enableButton(enable: Boolean)
    {
        (dialog as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = enable
    }

    private class MyDragItem internal constructor(context: Context, layoutId: Int) : DragItem(context, layoutId)
    {

        override fun onBindDragView(clickedView: View, dragView: View)
        {
            val text = (clickedView.findViewById<View>(R.id.text) as TextView).text
            (dragView.findViewById<View>(R.id.text) as TextView).text = text
            dragView.findViewById<View>(R.id.item_layout).setBackgroundColor(dragView.resources.getColor(R.color.list_item_background))
        }
    }

}
<commit_msg>#528 Fixed compilation failures<commit_after>package org.worshipsongs.preference

import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.preference.DialogPreference
import android.preference.PreferenceManager
import android.support.v7.widget.LinearLayoutManager
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.TextView

import com.woxthebox.draglistview.DragItem
import com.woxthebox.draglistview.DragListView

import org.worshipsongs.CommonConstants
import org.worshipsongs.R
import org.worshipsongs.adapter.ItemAdapter
import org.worshipsongs.domain.DragDrop
import org.worshipsongs.registry.FragmentRegistry

import java.util.ArrayList

/**
 * Author : Madasamy
 * Version : 3.x
 */

class TabChoicePreference(context: Context, attrs: AttributeSet) : DialogPreference(context, attrs), ItemAdapter.Listener
{
    private var configureDragDrops: ArrayList<DragDrop>? = null
    private var mDragListView: DragListView? = null
    private var defaultSharedPreferences: SharedPreferences? = null
    private val fragmentRegistry = FragmentRegistry()

    init
    {
        defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
        setItems()
        dialogLayoutResource = R.layout.tab_choice_layout
    }

    override fun onBindDialogView(view: View)
    {
        view.setBackgroundColor(context.resources.getColor(R.color.white))
        setDragListView(view)
        super.onBindDialogView(view)
    }

    override fun onDialogClosed(positiveResult: Boolean)
    {
        Log.i(TabChoicePreference::class.java.simpleName, "Tab choice preference $positiveResult")
        if (positiveResult)
        {
            val itemList = mDragListView!!.adapter.itemList as ArrayList<DragDrop>
            defaultSharedPreferences!!.edit().putString(CommonConstants.TAB_CHOICE_KEY, DragDrop.toJson(itemList)).apply()
            defaultSharedPreferences!!.edit().putBoolean(CommonConstants.UPDATE_NAV_ACTIVITY_KEY, true).apply()
        }
        super.onDialogClosed(positiveResult)
    }

    private fun setItems()
    {
        configureDragDrops = DragDrop.toArrays(sharedPreferences.getString(CommonConstants.TAB_CHOICE_KEY, ""))
        val defaultList = fragmentRegistry.getDragDrops(context as Activity)
        if (configureDragDrops == null || configureDragDrops!!.isEmpty())
        {
            configureDragDrops = defaultList
            defaultSharedPreferences!!.edit().putString(CommonConstants.TAB_CHOICE_KEY, DragDrop.toJson(configureDragDrops)).apply()
        } else if (defaultList.size > configureDragDrops!!.size)
        {
            defaultList.removeAll(configureDragDrops!!)
            configureDragDrops!!.addAll(defaultList)
        }
    }

    private fun setDragListView(view: View)
    {
        mDragListView = view.findViewById<View>(R.id.drag_list_view) as DragListView
        mDragListView!!.recyclerView.isVerticalScrollBarEnabled = true
        mDragListView!!.setLayoutManager(LinearLayoutManager(context))
        val listAdapter = ItemAdapter(configureDragDrops!!, R.layout.tab_choice_item, R.id.image, false)
        listAdapter.setListener(this)
        mDragListView!!.setAdapter(listAdapter, true)
        mDragListView!!.setCanDragHorizontally(false)
        mDragListView!!.setCustomDragItem(MyDragItem(context, R.layout.tab_choice_item))
    }

    override fun enableButton(enable: Boolean)
    {
        (dialog as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = enable
    }

    private class MyDragItem internal constructor(context: Context, layoutId: Int) : DragItem(context, layoutId)
    {

        override fun onBindDragView(clickedView: View, dragView: View)
        {
            val text = (clickedView.findViewById<View>(R.id.text) as TextView).text
            (dragView.findViewById<View>(R.id.text) as TextView).text = text
            dragView.findViewById<View>(R.id.item_layout).setBackgroundColor(dragView.resources.getColor(R.color.list_item_background))
        }
    }

}

{'fraction_non_alphanumeric': 0.09015695340065702, 'fraction_numerical': 0.0008516851198442633, 'mean_word_length': 3.887039239001189, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '2497597', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2251, 'n_words': 374}