|
|
|
|
@ -17,19 +17,19 @@ import es.dmoral.toasty.Toasty
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.FileNotFoundException
|
|
|
|
|
import java.io.FileOutputStream
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import java.lang.Exception
|
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
import java.util.*
|
|
|
|
|
import kotlin.Exception
|
|
|
|
|
|
|
|
|
|
class ExportBuilder(
|
|
|
|
|
private val myContext: Context,
|
|
|
|
|
data: MutableList<ProjectEntry>,
|
|
|
|
|
private val binding: FragmentListingBinding
|
|
|
|
|
private val binding: FragmentListingBinding,
|
|
|
|
|
private val schuljahr: String
|
|
|
|
|
) : Document(PageSize.A4.rotate()) {
|
|
|
|
|
private val destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/"
|
|
|
|
|
private val directory = File(destination)
|
|
|
|
|
private val data = data.reversed()
|
|
|
|
|
private val destination = "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)}/"
|
|
|
|
|
private val directory = File(destination)
|
|
|
|
|
private lateinit var file: File
|
|
|
|
|
private val table = PdfPTable(4)
|
|
|
|
|
private val techniker = mutableListOf<List<String>>()
|
|
|
|
|
@ -43,7 +43,7 @@ class ExportBuilder(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
file = File(destination, "Arbeitseinsätze Technik - ${time.split(",")[0]}.pdf")
|
|
|
|
|
file = File(destination, "Einsätze Technik - ${time.split(",")[0]}.pdf")
|
|
|
|
|
file.createNewFile()
|
|
|
|
|
val fOut = FileOutputStream(file, false)
|
|
|
|
|
PdfWriter.getInstance(this, fOut)
|
|
|
|
|
@ -53,8 +53,9 @@ class ExportBuilder(
|
|
|
|
|
} catch (e: FileNotFoundException) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
Log.e("TechnikLogger.Export", e.toString())
|
|
|
|
|
} catch (e: IOException) {
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
Log.e("TechnikLogger.Export", e.toString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setMargins(0f, 0f, 36f, 36f)
|
|
|
|
|
@ -62,20 +63,20 @@ class ExportBuilder(
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this.open()
|
|
|
|
|
table.addCell(TimeCell(time))
|
|
|
|
|
table.addCell(HeaderCell())
|
|
|
|
|
table.addCell(TimeHeaderCell(time))
|
|
|
|
|
table.addCell(HeaderCell(schuljahr))
|
|
|
|
|
val columnHeaderTexts = listOf("Datum", "Veranstaltung", "Techniker", "Dauer insgesamt (h)")
|
|
|
|
|
repeat(4) {
|
|
|
|
|
table.addCell(ColumnHeaderCell(columnHeaderTexts[it]))
|
|
|
|
|
}
|
|
|
|
|
fetchTechniker(0)
|
|
|
|
|
fetchTechniker()
|
|
|
|
|
} catch (e: DocumentException) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
Log.e("TechnikLogger.Export", e.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun fetchTechniker(index: Int) {
|
|
|
|
|
private fun fetchTechniker(index: Int = 0) {
|
|
|
|
|
if (index < data.size) {
|
|
|
|
|
val query = ParseQuery.getQuery<ParseObject>("Teilnahme")
|
|
|
|
|
query.whereEqualTo("an", ParseObject.createWithoutData("Einsatz", data[index].objectId))
|
|
|
|
|
@ -104,8 +105,8 @@ class ExportBuilder(
|
|
|
|
|
projectEntry.name,
|
|
|
|
|
techniker[index].joinToString("\n"),
|
|
|
|
|
projectEntry.duration)
|
|
|
|
|
information.forEachIndexed { index2, string ->
|
|
|
|
|
table.addCell(NormalCell(string, index2 != 2))
|
|
|
|
|
information.forEachIndexed { _, string ->
|
|
|
|
|
table.addCell(NormalCell(string))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.add(table)
|
|
|
|
|
@ -114,7 +115,7 @@ class ExportBuilder(
|
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW)
|
|
|
|
|
val uri = FileProvider.getUriForFile(
|
|
|
|
|
myContext,
|
|
|
|
|
myContext.applicationContext.packageName + ".provider",
|
|
|
|
|
myContext.packageName + ".provider",
|
|
|
|
|
file
|
|
|
|
|
)
|
|
|
|
|
intent.setDataAndType(uri, "application/pdf")
|
|
|
|
|
|