package nice3point.by.schedule.CardSheduleFragment

import android.app.Activity
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView

import nice3point.by.schedule.Adapters.RVAdapter
import nice3point.by.schedule.R
import nice3point.by.schedule.TechnicalModule

class VCardFragment : Fragment(), iVCardFragment {
    private lateinit var day_ofWeek: TextView
    private lateinit var presenter: PCardFragment
    private lateinit var instanceBundle: Bundle
    private lateinit var activity: Activity
    private lateinit var rv: RecyclerView

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {

        val view = inflater!!.inflate(R.layout.recyclerview_activity, container, false)

        rv = view.findViewById(R.id.rv)
        day_ofWeek = view.findViewById(R.id.day_ofWeek)

        presenter = PCardFragment(this)

        instanceBundle = this.arguments
        activity = getActivity()

        presenter.requestAdapter()

        day_ofWeek.text = TechnicalModule.dayInString(presenter.getLoadDay())

        return view
    }

    override fun getInstanceBundle(): Bundle {
        return instanceBundle
    }

    override fun getFragmentActivity(): Activity {
        return activity
    }

    override fun setRVAdapter(adapter: RVAdapter) {
        rv.layoutManager = LinearLayoutManager(context)
        rv.setHasFixedSize(true)
        rv.adapter = adapter
    }

    override fun activityDestroyed() {
        presenter.activityDestroyed()
    }

    companion object {

        private val ARG_POS = "Position"
        private val ARG_DAY = "Day"

        fun newInstance(day_of_week: Int, pos: Int): VCardFragment {
            val fragment = VCardFragment()
            val args = Bundle()
            args.putInt(ARG_DAY, day_of_week)
            args.putInt(ARG_POS, pos)
            fragment.arguments = args
            return fragment
        }
    }
}
