|
|
|
|
@ -1,8 +1,12 @@
|
|
|
|
|
package com.cyb3rko.techniklogger.table
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.os.Environment
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.View
|
|
|
|
|
import androidx.core.content.FileProvider
|
|
|
|
|
import com.cyb3rko.techniklogger.databinding.FragmentListingBinding
|
|
|
|
|
import com.cyb3rko.techniklogger.recycler.ProjectViewState
|
|
|
|
|
import com.itextpdf.text.*
|
|
|
|
|
import com.itextpdf.text.pdf.PdfPTable
|
|
|
|
|
@ -14,24 +18,32 @@ 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.*
|
|
|
|
|
|
|
|
|
|
class ExportBuilder(val myContext: Context, data: MutableList<ProjectViewState.ProjectEntry>) : Document(PageSize.A4.rotate()) {
|
|
|
|
|
class ExportBuilder(
|
|
|
|
|
private val myContext: Context,
|
|
|
|
|
data: MutableList<ProjectViewState.ProjectEntry>,
|
|
|
|
|
private val binding: FragmentListingBinding
|
|
|
|
|
) : Document(PageSize.A4.rotate()) {
|
|
|
|
|
private val destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/"
|
|
|
|
|
private val directory = File(destination)
|
|
|
|
|
private val data = data.reversed()
|
|
|
|
|
private lateinit var file: File
|
|
|
|
|
private val table = PdfPTable(4)
|
|
|
|
|
private val techniker = mutableListOf<List<String>>()
|
|
|
|
|
private val time = SimpleDateFormat("dd.MM.yyyy, HH:mm", Locale.GERMANY).format(Date())
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
binding.fabBgLayout.visibility = View.VISIBLE
|
|
|
|
|
binding.progressBar.visibility = View.VISIBLE
|
|
|
|
|
if (!directory.exists()) {
|
|
|
|
|
directory.mkdirs()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
val file = File(destination, "Arbeitseinsätze Technik - ${time.split(",")[0]}.pdf")
|
|
|
|
|
file = File(destination, "Arbeitseinsätze Technik - ${time.split(",")[0]}.pdf")
|
|
|
|
|
file.createNewFile()
|
|
|
|
|
val fOut = FileOutputStream(file, false)
|
|
|
|
|
PdfWriter.getInstance(this, fOut)
|
|
|
|
|
@ -98,6 +110,23 @@ class ExportBuilder(val myContext: Context, data: MutableList<ProjectViewState.P
|
|
|
|
|
}
|
|
|
|
|
this.add(table)
|
|
|
|
|
this.close()
|
|
|
|
|
Toasty.success(myContext, "Liste in Downloads gespeichert").show()
|
|
|
|
|
|
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW)
|
|
|
|
|
val uri = FileProvider.getUriForFile(
|
|
|
|
|
myContext,
|
|
|
|
|
myContext.applicationContext.packageName + ".provider",
|
|
|
|
|
file
|
|
|
|
|
)
|
|
|
|
|
intent.setDataAndType(uri, "application/pdf")
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY xor Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
myContext.startActivity(intent)
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
Toasty.error(myContext, "Öffnen der Datei fehlgeschlagen").show()
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
}
|
|
|
|
|
binding.progressBar.visibility = View.GONE
|
|
|
|
|
binding.fabBgLayout.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|