Edited the Food Fragment Kotlin file, small changes to Settings Java, changed RecyclerView in Food Layout to match_parent

This commit is contained in:
Deniz Düzgören
2019-04-30 19:24:13 +02:00
parent a45e5cdfa0
commit d690a2604a
6 changed files with 134 additions and 17 deletions
@@ -1,4 +1,61 @@
package com.denizd.substitutionplan
class FoodFragment {
import android.content.SharedPreferences
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.madapps.prefrences.EasyPrefrences
class FoodFragment : Fragment(R.layout.food_layout) {
private lateinit var foodArrayList: ArrayList<Food>
private lateinit var recyclerView: RecyclerView
private val mAdapter = FoodAdapter(foodArrayList)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.food_layout, null)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val pullToRefresh = getView()?.findViewById(R.id.pullToRefresh) as SwipeRefreshLayout
val prefs = PreferenceManager.getDefaultSharedPreferences(activity) as SharedPreferences
val edit = prefs.edit() as SharedPreferences.Editor
val easyPrefs = EasyPrefrences(context!!)
val foodListPopulation = ArrayList<String>(easyPrefs.getListString("foodListPrefs"))
try {
recyclerView = getView()?.findViewById(R.id.linear_food) as RecyclerView
recyclerView.hasFixedSize()
recyclerView.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL ,false)
recyclerView.adapter = mAdapter
try {
recyclerView.removeAllViews()
} catch (e: NullPointerException) {}
for (i in 0..foodListPopulation.size) {
foodArrayList.add(Food(foodListPopulation[i]))
mAdapter.setFood(foodArrayList)
recyclerView.scheduleLayoutAnimation()
}
} catch (e: NullPointerException) {}
if (prefs.getBoolean("autoRefresh", false)) {
pullToRefresh.isRefreshing = true
// coroutines
}
pullToRefresh.setOnRefreshListener {
pullToRefresh.isRefreshing = true
// coroutines
}
}
}
@@ -556,8 +556,8 @@ public class FragmentSettings extends Fragment {
alertDialogDev.setView(dialogView);
alertDialogDev.show();
} else if (dialogEditText.getText().toString().equals("Tim Bergling")) {
Toast.makeText(getActivity(), "◢◤",
} else if (dialogEditText.getText().toString().equals("2018-04-20")) {
Toast.makeText(getActivity(), " ",
Toast.LENGTH_LONG).show();
} else if (dialogEditText.getText().toString().equals("Q1 Matchmaker")) {
+1 -1
View File
@@ -18,7 +18,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/linear_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layoutAnimation="@anim/layout_animation_fall_down">
</androidx.recyclerview.widget.RecyclerView>