Archived
Removed redundant dependencies for WorkManager and EasyPreferences, TaskDescription colour changed to colorAccent
This commit is contained in:
+3
-4
@@ -9,8 +9,8 @@ android {
|
||||
applicationId "com.denizd.substitutionplan"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 15
|
||||
versionName "2.0.3"
|
||||
versionCode 16
|
||||
versionName "2.0.4"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
@@ -38,7 +38,6 @@ dependencies {
|
||||
// implementation 'androidx.core:core-ktx:1.0.2'
|
||||
|
||||
implementation 'com.jaredrummler:android-device-names:1.1.8'
|
||||
implementation 'com.github.mukeshsolanki:easypreferences:1.0.6'
|
||||
|
||||
def lifecycle_version = "2.0.0"
|
||||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
|
||||
@@ -50,7 +49,7 @@ dependencies {
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
implementation "androidx.work:work-runtime-ktx:2.0.1"
|
||||
// implementation "androidx.work:work-runtime-ktx:2.0.1"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
||||
@@ -19,7 +19,6 @@ import android.widget.RemoteViews
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.madapps.prefrences.EasyPrefrences
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.select.Elements
|
||||
@@ -60,8 +59,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
private val edit = prefs.edit() as SharedPreferences.Editor
|
||||
private lateinit var pullToRefresh: SwipeRefreshLayout
|
||||
private lateinit var progressBar: ProgressBar
|
||||
private val easyPrefs = EasyPrefrences(mContext)
|
||||
private val substViewModel = SubstViewModel(mApplication)
|
||||
private val foodViewModel = FoodViewModel(mApplication)
|
||||
private val oldDateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
|
||||
private val newDateFormat = "yyyy-MM-dd, HH:mm:ss"
|
||||
private var sdf = SimpleDateFormat(oldDateFormat)
|
||||
@@ -85,6 +84,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
}
|
||||
|
||||
var foodInt = 0
|
||||
var priority = 0
|
||||
foodViewModel.deleteAll()
|
||||
while (foodInt in 0 until foodElements.size) {
|
||||
try { // what a mess this is!
|
||||
if (foodElements[foodInt].text().contains("Montag") ||
|
||||
@@ -99,9 +100,9 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
foodElements[foodInt + 3].text().contains("Donnerstag") ||
|
||||
foodElements[foodInt + 3].text().contains("Freitag") ||
|
||||
foodElements[foodInt + 3].text().contains("von")) {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text() + "\n"
|
||||
+ foodElements[foodInt + 2].text())
|
||||
+ foodElements[foodInt + 2].text(), priority))
|
||||
foodInt += 2
|
||||
} else if (foodElements[foodInt + 2].text().contains("Montag") ||
|
||||
foodElements[foodInt + 2].text().contains("Dienstag") ||
|
||||
@@ -109,27 +110,28 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
foodElements[foodInt + 2].text().contains("Donnerstag") ||
|
||||
foodElements[foodInt + 2].text().contains("Freitag") ||
|
||||
foodElements[foodInt + 2].text().contains("von")) {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text())
|
||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text(), priority))
|
||||
foodInt += 1
|
||||
}
|
||||
|
||||
} else {
|
||||
foodList.add(foodElements[foodInt].text())
|
||||
foodViewModel.insert(Food(foodElements[foodInt].text(), priority))
|
||||
}
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
try {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text() + "\n"
|
||||
+ foodElements[foodInt + 2].text())
|
||||
+ foodElements[foodInt + 2].text(), priority))
|
||||
break
|
||||
} catch (e1: IndexOutOfBoundsException) {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text())
|
||||
foodViewModel.insert(Food(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text(), priority))
|
||||
break
|
||||
}
|
||||
}
|
||||
foodInt++
|
||||
priority++
|
||||
mView?.let {
|
||||
progressBar.progress = foodInt
|
||||
}
|
||||
@@ -146,8 +148,6 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
easyPrefs.putListString("foodListPrefs", foodList)
|
||||
}
|
||||
|
||||
if (plan) {
|
||||
@@ -273,7 +273,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
manager.notify(1, notification)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (plan || menu) {
|
||||
mView?.let { v: View ->
|
||||
handler.postDelayed({ progressBar.startAnimation(fadeOut) }, 200)
|
||||
fadeOut.setAnimationListener(object: Animation.AnimationListener {
|
||||
@@ -284,14 +285,15 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
|
||||
}
|
||||
})
|
||||
pullToRefresh.isRefreshing = false
|
||||
val snackbarview = v.findViewById<View>(R.id.coordination)
|
||||
sdf.applyPattern(newDateFormat)
|
||||
val sb = StringBuilder()
|
||||
val lastupdated = sb.append(mContext.getText(R.string.lastupdatedK)).append(sdf.format(d)).toString()
|
||||
Snackbar.make(snackbarview, lastupdated, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
if (plan) {
|
||||
val snackbarview = v.findViewById<View>(R.id.coordination)
|
||||
sdf.applyPattern(newDateFormat)
|
||||
val sb = StringBuilder()
|
||||
val lastupdated = sb.append(mContext.getText(R.string.lastupdatedK)).append(sdf.format(d)).toString()
|
||||
Snackbar.make(snackbarview, lastupdated, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
class Food(val food: String)
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "food_table")
|
||||
class Food(val food: String, @PrimaryKey val priority: Int)
|
||||
|
||||
@@ -2,25 +2,15 @@ package com.denizd.substitutionplan
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.ProgressBar
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.madapps.prefrences.EasyPrefrences
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.select.Elements
|
||||
import java.lang.IndexOutOfBoundsException
|
||||
|
||||
class FoodFragment : Fragment(R.layout.food_layout) {
|
||||
|
||||
@@ -29,22 +19,19 @@ class FoodFragment : Fragment(R.layout.food_layout) {
|
||||
private lateinit var mContext: Context
|
||||
private lateinit var prefs: SharedPreferences
|
||||
private lateinit var edit: SharedPreferences.Editor
|
||||
private lateinit var easyPrefs: EasyPrefrences
|
||||
lateinit var foodListPopulation: ArrayList<String>
|
||||
lateinit var recyclerView: RecyclerView
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var foodViewModel: FoodViewModel
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
mContext = context
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||
edit = prefs.edit()
|
||||
easyPrefs = EasyPrefrences(mContext)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val pullToRefresh = view.findViewById<SwipeRefreshLayout>(R.id.pullToRefresh)
|
||||
foodListPopulation = ArrayList(easyPrefs.getListString("foodListPrefs"))
|
||||
|
||||
try {
|
||||
recyclerView = view.findViewById(R.id.linear_food)
|
||||
@@ -56,144 +43,26 @@ class FoodFragment : Fragment(R.layout.food_layout) {
|
||||
recyclerView.removeAllViews()
|
||||
} catch (ignored: NullPointerException) {}
|
||||
|
||||
for (i in 0 until foodListPopulation.size) {
|
||||
foodArrayList.add(Food(foodListPopulation[i]))
|
||||
mAdapter.setFood(foodArrayList)
|
||||
recyclerView.scheduleLayoutAnimation()
|
||||
}
|
||||
} catch (ignored: NullPointerException) {}
|
||||
|
||||
foodViewModel = ViewModelProviders.of(this).get(FoodViewModel::class.java)
|
||||
foodViewModel.allFoods?.observe(this, Observer<List<Food>> { foodList ->
|
||||
foodArrayList.clear()
|
||||
for (item in foodList) {
|
||||
foodArrayList.add(item)
|
||||
}
|
||||
recyclerView.scheduleLayoutAnimation()
|
||||
mAdapter.setFood(foodArrayList)
|
||||
})
|
||||
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
pullToRefresh.isRefreshing = true
|
||||
RepopulateFood(mContext, recyclerView, easyPrefs, mAdapter, foodArrayList, pullToRefresh, view.rootView).execute()
|
||||
DataFetcher(false, true, false, mContext, activity!!.application, view.rootView).execute()
|
||||
}
|
||||
|
||||
pullToRefresh.setOnRefreshListener {
|
||||
pullToRefresh.isRefreshing = true
|
||||
RepopulateFood(mContext, recyclerView, easyPrefs, mAdapter, foodArrayList, pullToRefresh, view.rootView).execute()
|
||||
}
|
||||
/* bad approach - I should be using the DataFetcher.kt class, but that requires figuring out how to access the RecyclerView and its adapter from
|
||||
* another class - the best approach would be to store the data in the database instead of using EasyPreferences, however, I'm not doing that now */
|
||||
}
|
||||
|
||||
class RepopulateFood(context: Context, recyclerView: RecyclerView, easyPrefs: EasyPrefrences,
|
||||
adapter: FoodAdapter, foodArrayList: ArrayList<Food>,
|
||||
swipeRefreshLayout: SwipeRefreshLayout, rootView: View) : AsyncTask<Void, Void, Void>() {
|
||||
|
||||
private val mContext = context
|
||||
private val mRecyclerView = recyclerView
|
||||
private val mEasyPrefs = easyPrefs
|
||||
private val mAdapter = adapter
|
||||
private val mFoodArrayList = foodArrayList
|
||||
private var foodList = ArrayList<String>()
|
||||
private lateinit var foodElements: Elements
|
||||
private lateinit var docFood: Document
|
||||
private val pullToRefresh = swipeRefreshLayout
|
||||
private lateinit var progressBar: ProgressBar
|
||||
val mRootView = rootView
|
||||
private val fadeOut = AnimationUtils.loadAnimation(context, R.anim.fade_out)
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var exceptionOccurred = false
|
||||
|
||||
override fun doInBackground(vararg params: Void?): Void? {
|
||||
try {
|
||||
docFood = Jsoup.connect("https://djd4rkn355.github.io/food.html").get()
|
||||
foodElements = docFood.select("th")
|
||||
|
||||
progressBar = mRootView.findViewById(R.id.progressBar)
|
||||
|
||||
progressBar.max = foodElements.size
|
||||
|
||||
var foodInt = 0
|
||||
while (foodInt in 0 until foodElements.size) {
|
||||
try { // what a mess this is!
|
||||
if (foodElements[foodInt].text().contains("Montag") ||
|
||||
foodElements[foodInt].text().contains("Dienstag") ||
|
||||
foodElements[foodInt].text().contains("Mittwoch") ||
|
||||
foodElements[foodInt].text().contains("Donnerstag") ||
|
||||
foodElements[foodInt].text().contains("Freitag")) {
|
||||
|
||||
if (foodElements[foodInt + 3].text().contains("Montag") ||
|
||||
foodElements[foodInt + 3].text().contains("Dienstag") ||
|
||||
foodElements[foodInt + 3].text().contains("Mittwoch") ||
|
||||
foodElements[foodInt + 3].text().contains("Donnerstag") ||
|
||||
foodElements[foodInt + 3].text().contains("Freitag") ||
|
||||
foodElements[foodInt + 3].text().contains("von")) {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text() + "\n"
|
||||
+ foodElements[foodInt + 2].text())
|
||||
foodInt += 2
|
||||
} else if (foodElements[foodInt + 2].text().contains("Montag") ||
|
||||
foodElements[foodInt + 2].text().contains("Dienstag") ||
|
||||
foodElements[foodInt + 2].text().contains("Mittwoch") ||
|
||||
foodElements[foodInt + 2].text().contains("Donnerstag") ||
|
||||
foodElements[foodInt + 2].text().contains("Freitag") ||
|
||||
foodElements[foodInt + 2].text().contains("von")) {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text())
|
||||
foodInt += 1
|
||||
}
|
||||
|
||||
} else {
|
||||
foodList.add(foodElements[foodInt].text())
|
||||
}
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
try {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text() + "\n"
|
||||
+ foodElements[foodInt + 2].text())
|
||||
break
|
||||
} catch (e1: IndexOutOfBoundsException) {
|
||||
foodList.add(foodElements[foodInt].text() + "\n"
|
||||
+ foodElements[foodInt + 1].text())
|
||||
break
|
||||
}
|
||||
}
|
||||
foodInt++
|
||||
progressBar.progress = foodInt
|
||||
}
|
||||
|
||||
progressBar.progress = 100
|
||||
|
||||
mEasyPrefs.putListString("foodListPrefs", foodList)
|
||||
} catch (e: Exception) { exceptionOccurred = true }
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: Void?) {
|
||||
super.onPostExecute(result)
|
||||
|
||||
if (!exceptionOccurred) {
|
||||
try {
|
||||
mRecyclerView.removeAllViews()
|
||||
mFoodArrayList.removeAll(mFoodArrayList)
|
||||
} catch (ignored: NullPointerException) {}
|
||||
|
||||
val foodListPopulation = ArrayList(mEasyPrefs.getListString("foodListPrefs"))
|
||||
|
||||
for (i in 0 until foodListPopulation.size) {
|
||||
mFoodArrayList.add(Food(foodListPopulation[i]))
|
||||
mAdapter.setFood(mFoodArrayList)
|
||||
}
|
||||
|
||||
mRecyclerView.scheduleLayoutAnimation()
|
||||
pullToRefresh.isRefreshing = false
|
||||
|
||||
handler.postDelayed({ progressBar.startAnimation(fadeOut) }, 200)
|
||||
fadeOut.setAnimationListener(object: Animation.AnimationListener {
|
||||
override fun onAnimationStart(arg0: Animation) {}
|
||||
override fun onAnimationRepeat(arg0: Animation) {}
|
||||
override fun onAnimationEnd(arg0: Animation) {
|
||||
progressBar.progress = 0
|
||||
}
|
||||
})
|
||||
} else {
|
||||
pullToRefresh.isRefreshing = false
|
||||
val snackbarview = mRootView.findViewById<View>(R.id.coordination)
|
||||
Snackbar.make(snackbarview, mContext.getText(R.string.nointernet), Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
|
||||
}
|
||||
DataFetcher(false, true, false, mContext, activity!!.application, view.rootView).execute()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
import android.app.Application
|
||||
import android.os.AsyncTask
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
|
||||
public class FoodRepository(application: Application) {
|
||||
|
||||
private val substDao: SubstDao?
|
||||
val allFoods: LiveData<List<Food>>?
|
||||
|
||||
init {
|
||||
val database = SubstDatabase.getFoodInstance(application)
|
||||
substDao = database?.substDao()
|
||||
allFoods = substDao?.allFoods
|
||||
}
|
||||
|
||||
fun insert(food: Food) {
|
||||
InsertAsync(substDao).execute(food)
|
||||
}
|
||||
|
||||
fun deleteAll() {
|
||||
DeleteAllAsync(substDao).execute()
|
||||
}
|
||||
|
||||
class InsertAsync(substDao: SubstDao?) : AsyncTask<Food, Void, Void>() {
|
||||
private val mSubstDao = substDao
|
||||
override fun doInBackground(vararg foods: Food): Void? {
|
||||
mSubstDao?.insertFood(foods[0])
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteAllAsync(substDao: SubstDao?) : AsyncTask<Void, Void, Void>() {
|
||||
private val mSubstDao = substDao
|
||||
override fun doInBackground(vararg voids: Void): Void? {
|
||||
mSubstDao?.deleteAllFoods()
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
|
||||
public class FoodViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
private val repository: FoodRepository = FoodRepository(application)
|
||||
val allFoods: LiveData<List<Food>>?
|
||||
|
||||
init {
|
||||
allFoods = repository.allFoods
|
||||
}
|
||||
|
||||
fun insert(food: Food) {
|
||||
repository.insert(food)
|
||||
}
|
||||
|
||||
fun deleteAll() {
|
||||
repository.deleteAll()
|
||||
}
|
||||
}
|
||||
@@ -109,10 +109,6 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
// } // TODO theming based on system settings for Android Q
|
||||
}
|
||||
|
||||
val bm = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher)
|
||||
val taskDesc = ActivityManager.TaskDescription(getString(R.string.app_name), bm, ContextCompat.getColor(this, R.color.background))
|
||||
setTaskDescription(taskDesc)
|
||||
|
||||
if (!prefs.getBoolean("showinfotab", true)) {
|
||||
bottomNav.menu.removeItem(R.id.openinfopanel)
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
||||
|
||||
class PlanFragment : Fragment(R.layout.plan) {
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var mAdapter: CardAdapter
|
||||
|
||||
@@ -197,7 +197,6 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
}
|
||||
R.id.btnLicences -> {
|
||||
createDialog("Licences", "Libraries:\n • Android Device Names © 2015 Jared Rummler, licensed under the Apache Licence, Version 2.0" +
|
||||
"\n • EasyPreferences © 2018 Mukesh Solanki, licensed under the MIT Licence" +
|
||||
"\n • jsoup HTML parser © 2009-2018 Jonathan Hedley, licensed under the open source MIT Licence" +
|
||||
"\n\nFont:\n • Manrope © 2018-2019 Michael Sharanda, licensed under the SIL Open Font Licence 1.1" +
|
||||
"\n\nIcons:\n • bqlqn\n • fjstudio\n • Freepik\n • Smashicons\n • © 2013-2019 Freepik Company S.L., licensed under Creative Commons BY 3.0" +
|
||||
@@ -387,7 +386,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
}
|
||||
"2018-04-20" -> {
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=Jc2xfYuLWgE"))
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=Jc2xfYuLWgE")) // Freak
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setPackage("com.google.android.youtube")
|
||||
startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
|
||||
@@ -20,4 +20,13 @@ public interface SubstDao {
|
||||
|
||||
@Query("DELETE FROM subst_table")
|
||||
fun deleteAllSubst()
|
||||
|
||||
@get:Query("SELECT * FROM food_table ORDER BY priority ASC")
|
||||
val allFoods: LiveData<List<Food>>
|
||||
|
||||
@Insert
|
||||
fun insertFood(food: Food)
|
||||
|
||||
@Query("DELETE FROM food_table")
|
||||
fun deleteAllFoods()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [Subst::class], version = 3, exportSchema = false)
|
||||
@Database(entities = [Subst::class, Food::class], version = 4, exportSchema = false)
|
||||
public abstract class SubstDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun substDao(): SubstDao
|
||||
@@ -26,5 +26,18 @@ public abstract class SubstDatabase : RoomDatabase() {
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
||||
fun getFoodInstance(context: Context): SubstDatabase? {
|
||||
if (instance == null) {
|
||||
synchronized (SubstDatabase::class) {
|
||||
instance = Room.databaseBuilder(context.applicationContext,
|
||||
SubstDatabase::class.java,
|
||||
"food_database")
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
}
|
||||
return instance
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,10 @@ import androidx.lifecycle.LiveData
|
||||
|
||||
public class SubstViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
private val repository: SubstRepository
|
||||
private val repository: SubstRepository = SubstRepository(application)
|
||||
val allSubst: LiveData<List<Subst>>?
|
||||
|
||||
init {
|
||||
repository = SubstRepository(application)
|
||||
allSubst = repository.allSubst
|
||||
}
|
||||
|
||||
|
||||
@@ -111,10 +111,8 @@
|
||||
<string name="courseWat">WAT</string>
|
||||
<string name="courseFor">Förderunterricht</string>
|
||||
<string name="courseWp">WP & Methodenstunde</string>
|
||||
<string name="neoncolours">Neonfarben</string>
|
||||
<string name="clearall">Alle löschen</string>
|
||||
<string name="allcolourscleared">Farben für alle Kurse wurden gelöscht</string>
|
||||
<string name="clearcolour">Farbe löschen</string>
|
||||
<string name="chromecompatible">Kein Chrome-kompatibler Browser gefunden</string>
|
||||
<string name="noyoutube">YouTube-App nicht gefunden</string>
|
||||
<string name="swipeindependent">Unabhängig von Wischgeste</string>
|
||||
|
||||
@@ -124,10 +124,7 @@
|
||||
<string name="courseFor">Special Education</string>
|
||||
<string name="courseWp">WP & "Methodenstunde"</string>
|
||||
|
||||
<string name="neoncolours">Neon colours</string>
|
||||
|
||||
<string name="clearall">Clear all</string>
|
||||
<string name="clearcolour">Clear colour</string>
|
||||
<string name="allcolourscleared">Colours for all courses have been cleared</string>
|
||||
|
||||
<string name="chromecompatible">No Chrome-compatible browser found</string>
|
||||
|
||||
@@ -25,11 +25,6 @@
|
||||
<item name="android:colorEdgeEffect">@color/accent</item>
|
||||
</style>
|
||||
|
||||
<style name="AlertDialogCustomLight" parent="Theme.MaterialComponents.Light.Dialog.Alert">
|
||||
<item name="android:background">#eeeeee</item>
|
||||
<item name="android:textColorPrimary">#212121</item>
|
||||
</style>
|
||||
|
||||
<style name="AlertDialog" parent="Theme.MaterialComponents.Light.Dialog.Alert">
|
||||
<item name="android:background">@color/lightbackground</item>
|
||||
<item name="android:textColorPrimary">@color/textcolor</item>
|
||||
|
||||
Reference in New Issue
Block a user