From ff834476899dfdf3db5032fbc3e7f7a5c421fde2 Mon Sep 17 00:00:00 2001 From: Lennart Date: Sat, 13 Apr 2019 23:53:30 +0200 Subject: [PATCH] Adding fields 'theke_name' and 'product_name' to export functionality --- app/src/main/java/info/mathphys/schatztruhe/MainActivity.kt | 6 +++++- .../main/java/info/mathphys/schatztruhe/data/ProductDao.kt | 3 +++ .../info/mathphys/schatztruhe/data/ProductRepository.kt | 1 + .../java/info/mathphys/schatztruhe/data/ThekenViewModel.kt | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/mathphys/schatztruhe/MainActivity.kt b/app/src/main/java/info/mathphys/schatztruhe/MainActivity.kt index 99444d2..dee20c7 100644 --- a/app/src/main/java/info/mathphys/schatztruhe/MainActivity.kt +++ b/app/src/main/java/info/mathphys/schatztruhe/MainActivity.kt @@ -158,7 +158,7 @@ class MainActivity : AppCompatActivity() { val now = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") val datetimeStr = now.format(Date()) - val CSV_HEADER = "anzahl,product_id,theke_id,verschenkt,zeitpunkt,tablet_imei," + val CSV_HEADER = "anzahl,product_id,theke_id,theke_name,product_name,verschenkt,zeitpunkt,tablet_imei," val verkauftFile = File( Environment.getExternalStoragePublicDirectory( @@ -182,6 +182,10 @@ class MainActivity : AppCompatActivity() { fileWriter.append(',') fileWriter.append(item.theke_id.toString()) fileWriter.append(',') + fileWriter.append(mThekenViewModel.allTheken.value?.find { it-> it.id!!.equals(item.theke_id) }?.name) + fileWriter.append(',') + fileWriter.append(mThekenViewModel.anyProducts.find { it-> it.id!!.equals(item.product_id) }?.name) + fileWriter.append(',') fileWriter.append(item.verschenkt.toString()) fileWriter.append(',') fileWriter.append(SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(item.zeitpunkt)) diff --git a/app/src/main/java/info/mathphys/schatztruhe/data/ProductDao.kt b/app/src/main/java/info/mathphys/schatztruhe/data/ProductDao.kt index 6e9b883..f74892f 100644 --- a/app/src/main/java/info/mathphys/schatztruhe/data/ProductDao.kt +++ b/app/src/main/java/info/mathphys/schatztruhe/data/ProductDao.kt @@ -11,6 +11,9 @@ interface ProductDao { @Query("SELECT * from product_table JOIN bietet_an_table ON product_id=product_table.id WHERE theke_id=:theke_id ORDER BY name ASC") fun getAllProducts( theke_id:Long): LiveData > + @Query("SELECT * from product_table ORDER BY name ASC") + fun getAnyProducts(): List + @Insert fun insert(product: Product) diff --git a/app/src/main/java/info/mathphys/schatztruhe/data/ProductRepository.kt b/app/src/main/java/info/mathphys/schatztruhe/data/ProductRepository.kt index ccefef9..d5146d0 100644 --- a/app/src/main/java/info/mathphys/schatztruhe/data/ProductRepository.kt +++ b/app/src/main/java/info/mathphys/schatztruhe/data/ProductRepository.kt @@ -7,6 +7,7 @@ class ProductRepository(private val productDao: ProductDao,private val bietet_an val allProducts: LiveData> = productDao.getAllProducts(theke_id) + @WorkerThread suspend fun insert(product: Product) { productDao.insert(product) diff --git a/app/src/main/java/info/mathphys/schatztruhe/data/ThekenViewModel.kt b/app/src/main/java/info/mathphys/schatztruhe/data/ThekenViewModel.kt index cfa98ab..e9e5ae6 100644 --- a/app/src/main/java/info/mathphys/schatztruhe/data/ThekenViewModel.kt +++ b/app/src/main/java/info/mathphys/schatztruhe/data/ThekenViewModel.kt @@ -22,6 +22,7 @@ class ThekenViewModel(application: Application) : AndroidViewModel(application) private val bietet_anDao:bietet_anDao private val verkauft_repository: verkauftRepository val allTheken: LiveData> + val anyProducts: List val allverkauft: List init { val thekenDao = SchatzTruhenDatabase.getDatabase(application).thekeDao() @@ -32,6 +33,7 @@ class ThekenViewModel(application: Application) : AndroidViewModel(application) verkauft_repository= verkauftRepository(verkauftDao) product_repository = ProductRepository(productDao,bietet_anDao,-1) allTheken = repository.allTheken + anyProducts = productDao.getAnyProducts() allverkauft= verkauft_repository.allverkauft }