Archived
Refactoring, using view binding in all fragments, app now targets API 29, replaced deprecated support library PreferenceManager and Custom Tabs with AndroidX equivalents, version bump to 2.3.3
This commit is contained in:
@@ -5,46 +5,48 @@ import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.preference.PreferenceManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.denizd.substitutionplan.*
|
||||
import com.denizd.substitutionplan.R
|
||||
import com.denizd.substitutionplan.adapters.SubstitutionAdapter
|
||||
import com.denizd.substitutionplan.database.SubstViewModel
|
||||
import com.denizd.substitutionplan.databinding.PlanBinding
|
||||
import com.denizd.substitutionplan.models.Substitution
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
internal open class PlanFragment : Fragment(R.layout.plan) {
|
||||
internal lateinit var recyclerView: RecyclerView
|
||||
internal open class PlanFragment : Fragment() {
|
||||
internal lateinit var mAdapter: SubstitutionAdapter
|
||||
internal var planCardList = ArrayList<Substitution>()
|
||||
private lateinit var substViewModel: SubstViewModel
|
||||
private lateinit var mContext: Context
|
||||
internal lateinit var prefs: SharedPreferences
|
||||
|
||||
internal lateinit var personalPlanEmptyEmoticon: TextView
|
||||
internal lateinit var personalPlanEmptyText: TextView
|
||||
internal lateinit var personalPlanEmptyLayout: LinearLayout
|
||||
internal var isPersonalPlanEmpty: Boolean = true
|
||||
internal val handler = Handler()
|
||||
internal var substitutionPlan: LiveData<List<Substitution>>? = null
|
||||
|
||||
internal lateinit var binding: PlanBinding
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
mContext = context
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = PlanBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
recyclerView.layoutManager = GridLayoutManager(mContext, getGridColumnCount(newConfig))
|
||||
binding.recyclerView.layoutManager = GridLayoutManager(mContext, getGridColumnCount(newConfig))
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@@ -56,24 +58,24 @@ internal open class PlanFragment : Fragment(R.layout.plan) {
|
||||
substViewModel.allSubstitutionsOriginal
|
||||
}
|
||||
|
||||
val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.pullToRefresh)
|
||||
recyclerView = view.findViewById(R.id.linearRecycler)
|
||||
recyclerView.hasFixedSize()
|
||||
recyclerView.layoutManager = GridLayoutManager(mContext, getGridColumnCount(resources.configuration))
|
||||
mAdapter = SubstitutionAdapter(planCardList, prefs)
|
||||
recyclerView.adapter = mAdapter
|
||||
binding.recyclerView.apply {
|
||||
hasFixedSize()
|
||||
layoutManager = GridLayoutManager(mContext, getGridColumnCount(resources.configuration))
|
||||
adapter = mAdapter
|
||||
}
|
||||
|
||||
if (prefs.getInt("firstTimeOpening", 0) == 1) {
|
||||
substViewModel.refresh(swipeRefreshLayout = pullToRefresh, rootView = view.rootView, refreshMenu = true)
|
||||
substViewModel.refresh(swipeRefreshLayout = binding.swipeRefreshLayout, rootView = view.rootView, refreshMenu = true)
|
||||
prefs.edit().putInt("firstTimeOpening", 2).apply()
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
substViewModel.refresh(swipeRefreshLayout = pullToRefresh, rootView = view.rootView, refreshMenu = false)
|
||||
substViewModel.refresh(swipeRefreshLayout = binding.swipeRefreshLayout, rootView = view.rootView, refreshMenu = false)
|
||||
}
|
||||
|
||||
pullToRefresh.setOnRefreshListener {
|
||||
substViewModel.refresh(swipeRefreshLayout = pullToRefresh, rootView = view.rootView, refreshMenu = false)
|
||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||
substViewModel.refresh(swipeRefreshLayout = binding.swipeRefreshLayout, rootView = view.rootView, refreshMenu = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user