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 { binding.fab2.setOnClickListener {
closeFABMenu() closeFABMenu()
ExportBuilder(myContext, projectsAdapter.currentList, binding) ExportBuilder(
myContext,
projectsAdapter.currentList,
binding,
sharedPref.getString("current_year_name", "")!!
)
} }
binding.fab3.setOnClickListener { binding.fab3.setOnClickListener {

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

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

@ -5,7 +5,7 @@ import com.itextpdf.text.Font
import com.itextpdf.text.Phrase import com.itextpdf.text.Phrase
import com.itextpdf.text.pdf.PdfPCell import com.itextpdf.text.pdf.PdfPCell
class NormalCell(title: String, centered: Boolean) : PdfPCell() { class NormalCell(title: String) : PdfPCell() {
init { init {
setPhrase(Phrase( setPhrase(Phrase(
title, title,
@ -13,6 +13,6 @@ class NormalCell(title: String, centered: Boolean) : PdfPCell() {
)) ))
setPadding(6f) setPadding(6f)
verticalAlignment = Element.ALIGN_MIDDLE 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.Phrase
import com.itextpdf.text.pdf.PdfPCell import com.itextpdf.text.pdf.PdfPCell
class TimeCell(time: String) : PdfPCell() { class TimeHeaderCell(time: String) : PdfPCell() {
init { init {
setPhrase(Phrase( setPhrase(Phrase(
"Erstellung: $time Uhr", "Erstellung: $time Uhr\n\n Automatisch erstellt über die Technik-Logger App\n" +
Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD) "(Entwickler: Niko Diamadis)",
Font(Font.FontFamily.HELVETICA, 11f)
)) ))
setPadding(8f) setPadding(8f)
borderWidth = 0.2f borderWidth = 0.2f

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

Loading…
Cancel
Save