Skip to content

Commit

Permalink
Adding fields 'theke_name' and 'product_name' to export functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart committed Apr 13, 2019
1 parent 4d2650f commit ff83447
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/src/main/java/info/mathphys/schatztruhe/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Product> >

@Query("SELECT * from product_table ORDER BY name ASC")
fun getAnyProducts(): List<Product>

@Insert
fun insert(product: Product)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ProductRepository(private val productDao: ProductDao,private val bietet_an

val allProducts: LiveData<List<Product>> = productDao.getAllProducts(theke_id)


@WorkerThread
suspend fun insert(product: Product) {
productDao.insert(product)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ThekenViewModel(application: Application) : AndroidViewModel(application)
private val bietet_anDao:bietet_anDao
private val verkauft_repository: verkauftRepository
val allTheken: LiveData<List<Theke>>
val anyProducts: List<Product>
val allverkauft: List<verkauft>
init {
val thekenDao = SchatzTruhenDatabase.getDatabase(application).thekeDao()
Expand All @@ -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
}

Expand Down

0 comments on commit ff83447

Please sign in to comment.