Passe Schuljahr-Fragment-Title an

master
Niko Diamadis 4 years ago
parent 5ac6f8270e
commit b5ba064b03
Signed by: niko
GPG Key ID: BE53B0B17B1B142E

@ -92,7 +92,12 @@ class ListingFragment : Fragment() {
binding.fab2.setOnClickListener {
closeFABMenu()
ExportBuilder(myContext, projectsAdapter.currentList, binding)
ExportBuilder(
myContext,
projectsAdapter.currentList,
binding,
sharedPref.getString("current_year_name", "")!!
)
}
binding.fab3.setOnClickListener {

@ -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")

@ -1,19 +1,16 @@
package com.cyb3rko.techniklogger.table
import com.itextpdf.text.BaseColor
import com.itextpdf.text.Element
import com.itextpdf.text.Font
import com.itextpdf.text.Phrase
import com.itextpdf.text.pdf.PdfPCell
class HeaderCell : PdfPCell() {
class HeaderCell(schuljahr: String) : PdfPCell() {
init {
setPhrase(Phrase(
"\nAutomatisch erstellt über die Technik-Logger App\n(Entwickler: Niko Diamadis)\n ",
Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD)
"\nSchuljahr $schuljahr\n ",
Font(Font.FontFamily.HELVETICA, 16f, Font.BOLD)
))
borderWidth = 0.2f
borderColor = BaseColor.GRAY
colspan = 4
rowspan = 3
verticalAlignment = Element.ALIGN_MIDDLE

@ -5,7 +5,7 @@ import com.itextpdf.text.Font
import com.itextpdf.text.Phrase
import com.itextpdf.text.pdf.PdfPCell
class NormalCell(title: String, centered: Boolean) : PdfPCell() {
class NormalCell(title: String) : PdfPCell() {
init {
setPhrase(Phrase(
title,
@ -13,6 +13,6 @@ class NormalCell(title: String, centered: Boolean) : PdfPCell() {
))
setPadding(6f)
verticalAlignment = Element.ALIGN_MIDDLE
if (centered) horizontalAlignment = Element.ALIGN_CENTER
horizontalAlignment = Element.ALIGN_CENTER
}
}

@ -6,11 +6,12 @@ import com.itextpdf.text.Font
import com.itextpdf.text.Phrase
import com.itextpdf.text.pdf.PdfPCell
class TimeCell(time: String) : PdfPCell() {
class TimeHeaderCell(time: String) : PdfPCell() {
init {
setPhrase(Phrase(
"Erstellung: $time Uhr",
Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD)
"Erstellung: $time Uhr\n\n Automatisch erstellt über die Technik-Logger App\n" +
"(Entwickler: Niko Diamadis)",
Font(Font.FontFamily.HELVETICA, 11f)
))
setPadding(8f)
borderWidth = 0.2f

@ -8,7 +8,7 @@
<fragment
android:id="@+id/navigation_years"
android:name="com.cyb3rko.techniklogger.fragments.YearsFragment"
android:label="Schuljahre"
android:label="Schuljahr"
tools:layout="@layout/fragment_years" />
<fragment

Loading…
Cancel
Save