From d690a2604a23dcd992fd3655e5b1eb2a7f942ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20D=C3=BCzg=C3=B6ren?= Date: Tue, 30 Apr 2019 19:24:13 +0200 Subject: [PATCH] Edited the Food Fragment Kotlin file, small changes to Settings Java, changed RecyclerView in Food Layout to match_parent --- .gitignore | 79 ++++++++++++++++--- .idea/vcs.xml | 6 ++ app/build.gradle | 1 + .../denizd/substitutionplan/FoodFragment.kt | 59 +++++++++++++- .../substitutionplan/FragmentSettings.java | 4 +- app/src/main/res/layout/food_layout.xml | 2 +- 6 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 2b75303..72f4d98 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,66 @@ -*.iml -.gradle -/local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml -.DS_Store -/build -/captures -.externalNativeBuild +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index f75e2dc..a5c7fc2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,6 +53,7 @@ dependencies { annotationProcessor "androidx.room:room-compiler:$room_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1" } repositories { mavenCentral() diff --git a/app/src/main/java/com/denizd/substitutionplan/FoodFragment.kt b/app/src/main/java/com/denizd/substitutionplan/FoodFragment.kt index c5671c1..21af750 100644 --- a/app/src/main/java/com/denizd/substitutionplan/FoodFragment.kt +++ b/app/src/main/java/com/denizd/substitutionplan/FoodFragment.kt @@ -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 + 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(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 + } + + } } \ No newline at end of file diff --git a/app/src/main/java/com/denizd/substitutionplan/FragmentSettings.java b/app/src/main/java/com/denizd/substitutionplan/FragmentSettings.java index 28ccece..500b937 100644 --- a/app/src/main/java/com/denizd/substitutionplan/FragmentSettings.java +++ b/app/src/main/java/com/denizd/substitutionplan/FragmentSettings.java @@ -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")) { diff --git a/app/src/main/res/layout/food_layout.xml b/app/src/main/res/layout/food_layout.xml index bb7de98..e0877e2 100644 --- a/app/src/main/res/layout/food_layout.xml +++ b/app/src/main/res/layout/food_layout.xml @@ -18,7 +18,7 @@