Vereinheitliche Klassen-Namen

master
Niko Diamadis 4 years ago
parent 8e6293b53e
commit 16fbfaee4d
Signed by: niko
GPG Key ID: BE53B0B17B1B142E

@ -2,7 +2,7 @@ package com.cyb3rko.techniklogger.data
import java.util.*
data class ProjectEntry(
data class Mission(
val date: Date,
val duration: String,
val location: String,

@ -51,9 +51,23 @@ object ParseController {
}
}
internal fun fetchProjects(
internal fun fetchMission(
objectId: String?,
action: (entry: ParseObject?, e: ParseException?) -> Unit
) {
val query = getQuery<ParseObject>(CLASS_EINSATZ)
query.getInBackground(objectId) { entry, e ->
if (e == null) {
action(entry, null)
} else {
action(null, e)
}
}
}
internal fun fetchMissions(
year: String?,
action: (projects: List<ProjectEntry>, e: ParseException?) -> Unit
action: (missions: List<Mission>, e: ParseException?) -> Unit
) {
val query = getQuery<ParseObject>("Einsatz")
query.orderByDescending(COLUMN_EINSATZ_DATUM)
@ -66,12 +80,12 @@ object ParseController {
)
query.findInBackground { objects, e ->
if (e == null) {
val data = mutableListOf<ProjectEntry>()
val data = mutableListOf<Mission>()
objects.forEach {
val dates = it.getString(COLUMN_EINSATZ_DATUM)!!.split(",")
val time = if (dates.size > 1) dates[1] else ""
data.add(
ProjectEntry(
Mission(
SimpleDateFormat("yyyy.MM.dd", Locale.GERMANY).parse(dates[0])!!,
it.getInt(COLUMN_EINSATZ_DAUER).toString(),
it.getString(COLUMN_EINSATZ_ORT)!!,
@ -88,27 +102,13 @@ object ParseController {
}
}
internal fun fetchProject(
objectId: String?,
action: (project: ParseObject?, e: ParseException?) -> Unit
) {
val query = getQuery<ParseObject>(CLASS_EINSATZ)
query.getInBackground(objectId) { entry, e ->
if (e == null) {
action(entry, null)
} else {
action(null, e)
}
}
}
internal fun fetchSingleTeilnahme(
projectId: String,
internal fun fetchParticipation(
missionId: String,
technikerId: String,
action: (entry: ParseObject?, e: ParseException?) -> Unit
) {
val query = getQuery<ParseObject>(CLASS_TEILNAHME, false)
query.whereEqualTo(COLUMN_TEILNAHME_AN, ParseObject.createWithoutData(CLASS_EINSATZ, projectId))
query.whereEqualTo(COLUMN_TEILNAHME_AN, ParseObject.createWithoutData(CLASS_EINSATZ, missionId))
query.whereEqualTo(COLUMN_TEILNAHME_VON, ParseObject.createWithoutData(CLASS_EINSATZ, technikerId))
query.getFirstInBackground { entry, e ->
if (e == null) {
@ -117,13 +117,13 @@ object ParseController {
}
}
internal fun fetchTeilnahmen(
projectId: String,
internal fun fetchParticipations(
missionId: String,
includeTechniker: Boolean,
action: (entries: List<ParseObject>, e: ParseException?) -> Unit
) {
val query = getQuery<ParseObject>(CLASS_TEILNAHME, false)
query.whereEqualTo("an", ParseObject.createWithoutData(CLASS_EINSATZ, projectId))
query.whereEqualTo("an", ParseObject.createWithoutData(CLASS_EINSATZ, missionId))
if (includeTechniker) query.include("von")
query.findInBackground { entries, e ->
if (e == null) {

@ -1,6 +1,6 @@
package com.cyb3rko.techniklogger.data
data class ProjectTechniker(
data class Participation(
var dauer: String,
val name: String,
val objectId: String,

@ -17,7 +17,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.cyb3rko.techniklogger.*
import com.cyb3rko.techniklogger.data.ParseController
import com.cyb3rko.techniklogger.databinding.FragmentListingBinding
import com.cyb3rko.techniklogger.recycler.ProjectsAdapter
import com.cyb3rko.techniklogger.recycler.MissionAdapter
import com.cyb3rko.techniklogger.table.ExportBuilder
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import es.dmoral.toasty.Toasty
@ -29,7 +29,7 @@ class ListingFragment : Fragment() {
private lateinit var myContext: Context
private var adminMode: Boolean? = null
private lateinit var projectsAdapter: ProjectsAdapter
private lateinit var projectsAdapter: MissionAdapter
private var isFABOpen = false
private lateinit var sharedPref: SharedPreferences
private lateinit var sharedPrefEditor: SharedPreferences.Editor
@ -51,7 +51,7 @@ class ListingFragment : Fragment() {
binding.loadingAnimation.playAnimation()
projectsAdapter = ProjectsAdapter({ objectId: String ->
projectsAdapter = MissionAdapter({ objectId: String ->
val action = ListingFragmentDirections.navigateToProject(objectId)
findNavController().navigate(action)
}, {
@ -144,7 +144,7 @@ class ListingFragment : Fragment() {
}
private fun loadEntries() {
ParseController.fetchProjects(
ParseController.fetchMissions(
sharedPref.getString(CURRENT_YEAR, "")
) { entries, e ->
if (e == null) {

@ -18,9 +18,9 @@ import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.cyb3rko.techniklogger.*
import com.cyb3rko.techniklogger.data.ParseController
import com.cyb3rko.techniklogger.databinding.FragmentProjectBinding
import com.cyb3rko.techniklogger.data.ProjectTechniker
import com.cyb3rko.techniklogger.recycler.ProjectTechnikerAdapter
import com.cyb3rko.techniklogger.databinding.FragmentMissionBinding
import com.cyb3rko.techniklogger.data.Participation
import com.cyb3rko.techniklogger.recycler.ParticipationAdapter
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.timepicker.MaterialTimePicker
import com.google.android.material.timepicker.TimeFormat
@ -30,12 +30,12 @@ import java.sql.Time
import java.text.DecimalFormat
@SuppressLint("SetTextI18n")
class ProjectFragment : Fragment() {
private var _binding: FragmentProjectBinding? = null
class MissionFragment : Fragment() {
private var _binding: FragmentMissionBinding? = null
private lateinit var myContext: Context
private val args: ProjectFragmentArgs by navArgs()
private val args: MissionFragmentArgs by navArgs()
private lateinit var technikerAdapter: ProjectTechnikerAdapter
private lateinit var technikerAdapter: ParticipationAdapter
private var adminMode = false
private var objectId = ""
private var dauer = ""
@ -49,7 +49,7 @@ class ProjectFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentProjectBinding.inflate(inflater, container, false)
_binding = FragmentMissionBinding.inflate(inflater, container, false)
val root = binding.root
myContext = requireContext()
@ -58,7 +58,7 @@ class ProjectFragment : Fragment() {
objectId = args.objectId
technikerAdapter = ProjectTechnikerAdapter {
technikerAdapter = ParticipationAdapter {
if (adminMode || it.name == sharedPref.getString(NAME, "")) {
val uhrzeit = if (it.uhrzeit == "0") time else it.uhrzeit
val message = "<strong><u>Arbeitszeit:</u></strong><br/>$uhrzeit Uhr<br/><br/>" +
@ -139,7 +139,7 @@ class ProjectFragment : Fragment() {
saveInBackground()
}
} else {
ParseController.fetchSingleTeilnahme(objectId, it.objectId) { entry, e ->
ParseController.fetchParticipation(objectId, it.objectId) { entry, e ->
if (e == null) {
it.teilnahmeKey = entry!!.objectId
val dauerFloat = it.dauer.toFloat()
@ -170,7 +170,7 @@ class ProjectFragment : Fragment() {
if (it.teilnahmeKey != "0") {
ParseObject.createWithoutData(CLASS_TEILNAHME, it.teilnahmeKey).deleteInBackground()
} else {
ParseController.fetchSingleTeilnahme(objectId, it.objectId) { entry, e ->
ParseController.fetchParticipation(objectId, it.objectId) { entry, e ->
if (e == null) {
entry!!.deleteInBackground {
if (it != null) {
@ -213,7 +213,7 @@ class ProjectFragment : Fragment() {
.setTitle("Techniker entfernen")
.setMessage("Möchtest du alle eingetragenen Techniker entfernen?")
.setPositiveButton("Ja") { _, _ ->
ParseController.fetchTeilnahmen(objectId, false) { entries, e ->
ParseController.fetchParticipations(objectId, false) { entries, e ->
if (e == null) {
ParseObject.deleteAllInBackground(entries)
technikerAdapter.submitList(listOf())
@ -247,29 +247,29 @@ class ProjectFragment : Fragment() {
}
private fun loadData() {
ParseController.fetchProject(objectId) { project, e ->
ParseController.fetchMission(objectId) { mission, e ->
if (e == null) {
binding.titleView.text = project!!.getString(COLUMN_EINSATZ_NAME)
binding.locationView.text = project.getString(COLUMN_EINSATZ_ORT)
val dates = project.getString(COLUMN_EINSATZ_DATUM)!!.split(",")
binding.titleView.text = mission!!.getString(COLUMN_EINSATZ_NAME)
binding.locationView.text = mission.getString(COLUMN_EINSATZ_ORT)
val dates = mission.getString(COLUMN_EINSATZ_DATUM)!!.split(",")
val dateParts = dates[0].split(".")
val date = "${dateParts[2]}.${dateParts[1]}.${dateParts[0]}"
dauer = project.getNumber(COLUMN_EINSATZ_DAUER)!!.toString()
dauer = mission.getNumber(COLUMN_EINSATZ_DAUER)!!.toString()
if (dates.size > 1) time = dates[1]
val time = if (dates.size > 1) ", ${dates[1]}" else ", $dauer h"
binding.dateView.text = date + time
ParseController.fetchTeilnahmen(objectId, true) { entries, e2 ->
ParseController.fetchParticipations(objectId, true) { entries, e2 ->
if (e2 == null) {
if (entries.isNotEmpty()) {
val techniker = mutableListOf<ProjectTechniker>()
val techniker = mutableListOf<Participation>()
entries.forEach {
val teilnehmenderTechniker = it.getParseObject(COLUMN_TEILNAHME_VON)!!
val dauerEntry = it.getNumber(COLUMN_EINSATZ_DAUER)!!
val dauer = if (dauerEntry == 0) project.getNumber(COLUMN_TEILNAHME_DAUER)!!.toString() else dauerEntry.toString()
val dauer = if (dauerEntry == 0) mission.getNumber(COLUMN_TEILNAHME_DAUER)!!.toString() else dauerEntry.toString()
val time = it.getString(COLUMN_EINSATZ_UHRZEIT)!!
techniker.add(
ProjectTechniker(
Participation(
dauer,
teilnehmenderTechniker.getString(COLUMN_EINSATZ_NAME)!!,
teilnehmenderTechniker.objectId,

@ -18,7 +18,7 @@ import com.cyb3rko.techniklogger.COLUMN_EINSATZ_JAHR
import com.cyb3rko.techniklogger.CURRENT_YEAR
import com.cyb3rko.techniklogger.SHARED_PREFERENCE
import com.cyb3rko.techniklogger.data.ParseController
import com.cyb3rko.techniklogger.databinding.FragmentEinsatzPusherBinding
import com.cyb3rko.techniklogger.databinding.FragmentMissionPusherBinding
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.timepicker.MaterialTimePicker
@ -30,10 +30,10 @@ import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.*
class EinsatzPusherFragment : Fragment() {
private var _binding: FragmentEinsatzPusherBinding? = null
class MissionPusherFragment : Fragment() {
private var _binding: FragmentMissionPusherBinding? = null
private lateinit var myContext: Context
private val args: EinsatzPusherFragmentArgs by navArgs()
private val args: MissionPusherFragmentArgs by navArgs()
private lateinit var childKey: String
private var date = ""
@ -55,7 +55,7 @@ class EinsatzPusherFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentEinsatzPusherBinding.inflate(inflater, container, false)
_binding = FragmentMissionPusherBinding.inflate(inflater, container, false)
val root = binding.root
myContext = requireContext()
@ -129,7 +129,7 @@ class EinsatzPusherFragment : Fragment() {
.setTitle("Einsatz entfernen")
.setMessage("Möchtest du diesen Einsatz entfernen?")
.setPositiveButton("Ja") { _, _ ->
ParseController.fetchTeilnahmen(childKey, false) { entries, e ->
ParseController.fetchParticipations(childKey, false) { entries, e ->
if (e == null) {
ParseObject.deleteAllInBackground(entries) {
entry.deleteInBackground {

@ -9,18 +9,18 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.cyb3rko.techniklogger.R
import com.cyb3rko.techniklogger.data.ProjectEntry
import com.cyb3rko.techniklogger.data.Mission
import java.text.SimpleDateFormat
import java.util.*
class ProjectsAdapter(
class MissionAdapter(
val action: (objectId: String) -> Unit,
val actionLong: (project: ProjectEntry) -> Boolean
) : ListAdapter<ProjectEntry, ProjectsAdapter.ViewHolder>(ProjectDiffCallback) {
val actionLong: (mission: Mission) -> Boolean
) : ListAdapter<Mission, MissionAdapter.ViewHolder>(MissionDiffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_recycler_projects, parent, false)
.inflate(R.layout.item_mission, parent, false)
return ViewHolder(view)
}
@ -53,12 +53,12 @@ class ProjectsAdapter(
val textView: TextView = view.findViewById(R.id.item_text)
}
object ProjectDiffCallback : DiffUtil.ItemCallback<ProjectEntry>() {
override fun areItemsTheSame(oldItem: ProjectEntry, newItem: ProjectEntry): Boolean {
object MissionDiffCallback : DiffUtil.ItemCallback<Mission>() {
override fun areItemsTheSame(oldItem: Mission, newItem: Mission): Boolean {
return oldItem.objectId == newItem.objectId
}
override fun areContentsTheSame(oldItem: ProjectEntry, newItem: ProjectEntry): Boolean {
override fun areContentsTheSame(oldItem: Mission, newItem: Mission): Boolean {
return oldItem.date == newItem.date &&
oldItem.duration == newItem.duration &&
oldItem.location == newItem.location &&

@ -8,11 +8,11 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.cyb3rko.techniklogger.R
import com.cyb3rko.techniklogger.data.ProjectTechniker
import com.cyb3rko.techniklogger.data.Participation
class ProjectTechnikerAdapter(
val action: (techniker: ProjectTechniker) -> Unit
) : ListAdapter<ProjectTechniker, ProjectTechnikerAdapter.ViewHolder>(ProjectTechnikerDiffCallback) {
class ParticipationAdapter(
val action: (techniker: Participation) -> Unit
) : ListAdapter<Participation, ParticipationAdapter.ViewHolder>(ParticipationDiffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
@ -34,12 +34,12 @@ class ProjectTechnikerAdapter(
val titleView: TextView = view.findViewById(R.id.title)
}
object ProjectTechnikerDiffCallback : DiffUtil.ItemCallback<ProjectTechniker>() {
override fun areItemsTheSame(oldItem: ProjectTechniker, newItem: ProjectTechniker): Boolean {
object ParticipationDiffCallback : DiffUtil.ItemCallback<Participation>() {
override fun areItemsTheSame(oldItem: Participation, newItem: Participation): Boolean {
return oldItem.objectId == newItem.objectId
}
override fun areContentsTheSame(oldItem: ProjectTechniker, newItem: ProjectTechniker): Boolean {
override fun areContentsTheSame(oldItem: Participation, newItem: Participation): Boolean {
return oldItem.dauer == newItem.dauer &&
oldItem.name == newItem.name &&
oldItem.teilnahmeKey == newItem.teilnahmeKey &&

@ -17,7 +17,7 @@ class YearAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_recycler_year, parent, false)
.inflate(R.layout.item_year, parent, false)
return ViewHolder(view)
}

@ -8,7 +8,7 @@ import android.view.View
import androidx.core.content.FileProvider
import com.cyb3rko.techniklogger.data.ParseController
import com.cyb3rko.techniklogger.databinding.FragmentListingBinding
import com.cyb3rko.techniklogger.data.ProjectEntry
import com.cyb3rko.techniklogger.data.Mission
import com.itextpdf.text.*
import com.itextpdf.text.pdf.PdfPTable
import com.itextpdf.text.pdf.PdfWriter
@ -23,9 +23,9 @@ import kotlin.Exception
class ExportBuilder(
private val myContext: Context,
data: MutableList<ProjectEntry>,
data: MutableList<Mission>,
private val binding: FragmentListingBinding,
private val schuljahr: String
year: String
) : Document(PageSize.A4.rotate()) {
private val data = data.reversed()
private val destination = "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)}/"
@ -64,7 +64,7 @@ class ExportBuilder(
try {
this.open()
table.addCell(TimeHeaderCell(time))
table.addCell(HeaderCell(schuljahr))
table.addCell(HeaderCell(year))
val columnHeaderTexts = listOf("Datum", "Veranstaltung", "Techniker", "Dauer insgesamt (h)")
repeat(4) {
table.addCell(ColumnHeaderCell(columnHeaderTexts[it]))
@ -78,7 +78,7 @@ class ExportBuilder(
private fun fetchTechniker(index: Int = 0) {
if (index < data.size) {
ParseController.fetchTeilnahmen(data[index].objectId, true) { entries, e ->
ParseController.fetchParticipations(data[index].objectId, true) { entries, e ->
if (e == null) {
val tempList = mutableListOf<String>()
var aktuellerTechniker: ParseObject
@ -96,12 +96,12 @@ class ExportBuilder(
}
private fun export() {
data.forEachIndexed { index, projectEntry ->
data.forEachIndexed { index, mission ->
val information = listOf(
SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(projectEntry.date),
projectEntry.name,
SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(mission.date),
mission.name,
techniker[index].joinToString("\n"),
projectEntry.duration)
mission.duration)
information.forEachIndexed { _, string ->
table.addCell(NormalCell(string))
}

@ -17,17 +17,17 @@
tools:layout="@layout/fragment_listing">
<action
android:id="@+id/navigateToProject"
app:destination="@id/navigation_project" />
app:destination="@id/navigation_mission" />
<action
android:id="@+id/navigateToPusher"
app:destination="@id/navigation_einsatz_pusher" />
app:destination="@id/navigation_mission_pusher" />
</fragment>
<fragment
android:id="@+id/navigation_project"
android:name="com.cyb3rko.techniklogger.fragments.ProjectFragment"
android:id="@+id/navigation_mission"
android:name="com.cyb3rko.techniklogger.fragments.MissionFragment"
android:label="Einsatz"
tools:layout="@layout/fragment_project" >
tools:layout="@layout/fragment_mission" >
<argument
android:name="objectId"
app:argType="string"
@ -38,10 +38,10 @@
</fragment>
<fragment
android:id="@+id/navigation_einsatz_pusher"
android:name="com.cyb3rko.techniklogger.fragments.EinsatzPusherFragment"
android:id="@+id/navigation_mission_pusher"
android:name="com.cyb3rko.techniklogger.fragments.MissionPusherFragment"
android:label="Einsatz bearbeiten"
tools:layout="@layout/fragment_einsatz_pusher">
tools:layout="@layout/fragment_mission_pusher">
<action
android:id="@+id/navigateToListing"
app:destination="@id/navigation_listing" />

Loading…
Cancel
Save