2019-05-26 11:35:36 +02:00
|
|
|
package com.denizd.substitutionplan
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
|
import android.content.res.Configuration
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.os.Handler
|
|
|
|
|
import android.preference.PreferenceManager
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
import android.widget.TextView
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import androidx.lifecycle.ViewModelProviders
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
|
|
|
import kotlin.collections.ArrayList
|
|
|
|
|
|
2019-07-22 19:10:25 +02:00
|
|
|
open class PlanFragment : Fragment(R.layout.plan) {
|
|
|
|
|
lateinit var recyclerView: RecyclerView
|
|
|
|
|
lateinit var mAdapter: CardAdapter
|
2019-05-26 11:35:36 +02:00
|
|
|
private lateinit var layoutManager: GridLayoutManager
|
2019-08-31 16:12:36 +02:00
|
|
|
var planCardList = ArrayList<Subst>()
|
2019-07-22 19:10:25 +02:00
|
|
|
lateinit var substViewModel: SubstViewModel
|
|
|
|
|
lateinit var mContext: Context
|
|
|
|
|
lateinit var prefs: SharedPreferences
|
|
|
|
|
lateinit var edit: SharedPreferences.Editor
|
2019-05-26 11:35:36 +02:00
|
|
|
|
2019-07-22 19:10:25 +02:00
|
|
|
lateinit var smileydown: TextView
|
|
|
|
|
lateinit var smileydowntext: TextView
|
|
|
|
|
lateinit var linearsmiley: LinearLayout
|
|
|
|
|
var persPlanEmpty: Boolean = true
|
|
|
|
|
val handler = Handler()
|
2019-05-26 11:35:36 +02:00
|
|
|
|
|
|
|
|
override fun onAttach(context: Context) {
|
|
|
|
|
super.onAttach(context)
|
|
|
|
|
mContext = context
|
|
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
|
|
super.onConfigurationChanged(newConfig)
|
2019-06-02 17:57:57 +02:00
|
|
|
val tabletSize = resources.getBoolean(R.bool.isTablet)
|
|
|
|
|
val grid = if (tabletSize) {
|
|
|
|
|
when (newConfig.orientation) {
|
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> 2
|
|
|
|
|
else -> 3
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
when (newConfig.orientation) {
|
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> 1
|
|
|
|
|
else -> 2
|
|
|
|
|
}
|
2019-05-26 11:35:36 +02:00
|
|
|
}
|
|
|
|
|
layoutManager = GridLayoutManager(mContext, grid)
|
|
|
|
|
recyclerView.layoutManager = layoutManager
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.pullToRefresh)
|
|
|
|
|
|
|
|
|
|
recyclerView = view.findViewById(R.id.linearRecycler)
|
|
|
|
|
recyclerView.hasFixedSize()
|
|
|
|
|
|
2019-06-02 17:57:57 +02:00
|
|
|
val tabletSize = resources.getBoolean(R.bool.isTablet)
|
|
|
|
|
val grid = if (tabletSize) {
|
|
|
|
|
when (resources.configuration.orientation) {
|
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> 2
|
|
|
|
|
else -> 3
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
when (resources.configuration.orientation) {
|
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> 1
|
|
|
|
|
else -> 2
|
|
|
|
|
}
|
2019-05-26 11:35:36 +02:00
|
|
|
}
|
2019-06-02 17:57:57 +02:00
|
|
|
|
2019-05-26 11:35:36 +02:00
|
|
|
layoutManager = GridLayoutManager(mContext, grid)
|
|
|
|
|
recyclerView.layoutManager = layoutManager
|
|
|
|
|
|
|
|
|
|
mAdapter = CardAdapter(planCardList)
|
|
|
|
|
recyclerView.adapter = mAdapter
|
|
|
|
|
|
2019-08-31 16:12:36 +02:00
|
|
|
if (prefs.getInt("firstTimeOpening", 0) == 1) {
|
2019-05-26 11:35:36 +02:00
|
|
|
if (!prefs.getBoolean("notif", false)) {
|
|
|
|
|
pullToRefresh.isRefreshing = true
|
2019-08-31 16:12:36 +02:00
|
|
|
DataFetcher(true, true, false, mContext, activity!!.application, view.rootView).execute()
|
|
|
|
|
prefs.edit().putInt("firstTimeOpening", 2).apply()
|
2019-05-26 11:35:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prefs.getBoolean("autoRefresh", false)) {
|
|
|
|
|
pullToRefresh.isRefreshing = true
|
|
|
|
|
DataFetcher(true, false, false, mContext, activity!!.application, view.rootView).execute()
|
|
|
|
|
}
|
2019-05-26 18:40:02 +02:00
|
|
|
substViewModel = ViewModelProviders.of(this).get(SubstViewModel::class.java)
|
2019-05-26 11:35:36 +02:00
|
|
|
|
|
|
|
|
pullToRefresh.setOnRefreshListener {
|
|
|
|
|
pullToRefresh.isRefreshing = true
|
|
|
|
|
DataFetcher(true, false, false, mContext, activity!!.application, view.rootView).execute()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|