created PDFGenerator daily.kt
This commit is contained in:
@@ -23,12 +23,16 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import `in`.sminnovations.smiadmin.data.Constant.STORAGE_PERMISSION_CODE
|
import `in`.sminnovations.smiadmin.data.Constant.STORAGE_PERMISSION_CODE
|
||||||
import `in`.sminnovations.smiadmin.R
|
import `in`.sminnovations.smiadmin.R
|
||||||
|
import `in`.sminnovations.smiadmin.ui.utils.DailyMonthYearPickerDialog
|
||||||
import `in`.sminnovations.smiadmin.ui.utils.ExportTask
|
import `in`.sminnovations.smiadmin.ui.utils.ExportTask
|
||||||
import `in`.sminnovations.smiadmin.ui.utils.MonthYearPickerDialog
|
import `in`.sminnovations.smiadmin.ui.utils.MonthYearPickerDialog
|
||||||
|
import `in`.sminnovations.smiadmin.ui.utils.dailyReportExport
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import java.util.Calendar
|
||||||
|
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
private lateinit var exportTask: ExportTask
|
private lateinit var exportTask: ExportTask
|
||||||
|
private lateinit var dailyReportExport: dailyReportExport
|
||||||
private var currentExcelTask: Job? = null
|
private var currentExcelTask: Job? = null
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@@ -37,9 +41,10 @@ class HomeFragment : Fragment() {
|
|||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
exportTask = ExportTask(this)
|
exportTask = ExportTask(this)
|
||||||
|
dailyReportExport = dailyReportExport(this)
|
||||||
|
|
||||||
return inflater.inflate(R.layout.fragment_home, container, false)
|
return inflater.inflate(R.layout.fragment_home, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
@@ -63,6 +68,13 @@ class HomeFragment : Fragment() {
|
|||||||
requestStoragePermission()
|
requestStoragePermission()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
view.findViewById<CardView>(R.id.cardDownloadDailyReport).setOnClickListener{
|
||||||
|
if(checkStoragePermission()){
|
||||||
|
showDailyMonthYearPicker()
|
||||||
|
}else{
|
||||||
|
requestStoragePermission()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showMonthYearPicker() {
|
private fun showMonthYearPicker() {
|
||||||
@@ -73,6 +85,15 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}.show(parentFragmentManager, "MonthYearPicker")
|
}.show(parentFragmentManager, "MonthYearPicker")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun showDailyMonthYearPicker(){
|
||||||
|
DailyMonthYearPickerDialog().apply {
|
||||||
|
setOnDateSelectedListener {
|
||||||
|
showDailyReportDialog(it,requireContext())
|
||||||
|
}
|
||||||
|
}.show(parentFragmentManager,"Daily Date Picker")
|
||||||
|
}
|
||||||
private fun showReportDialog(year: Int, month: Int, context: Context) {
|
private fun showReportDialog(year: Int, month: Int, context: Context) {
|
||||||
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_report_source, null)
|
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_report_source, null)
|
||||||
val dialog = AlertDialog.Builder(context)
|
val dialog = AlertDialog.Builder(context)
|
||||||
@@ -112,6 +133,19 @@ class HomeFragment : Fragment() {
|
|||||||
progressDialog.dismiss()
|
progressDialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun downloadAttendanceDailyReport(date : Calendar, source: String) {
|
||||||
|
currentExcelTask?.cancel()
|
||||||
|
|
||||||
|
val progressDialog = ProgressDialog(requireContext()).apply {
|
||||||
|
setMessage("Generating report...")
|
||||||
|
setCancelable(false)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
dailyReportExport.exportAttendance(date =date,source =source)
|
||||||
|
progressDialog.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun checkStoragePermission(): Boolean {
|
private fun checkStoragePermission(): Boolean {
|
||||||
return if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
return if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
||||||
ContextCompat.checkSelfPermission(
|
ContextCompat.checkSelfPermission(
|
||||||
@@ -154,6 +188,7 @@ class HomeFragment : Fragment() {
|
|||||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
// Permission granted, now show the picker
|
// Permission granted, now show the picker
|
||||||
showMonthYearPicker()
|
showMonthYearPicker()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
@@ -163,8 +198,36 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun showDailyReportDialog(date : Calendar, context: Context) {
|
||||||
|
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_report_source, null)
|
||||||
|
val dialog = AlertDialog.Builder(context)
|
||||||
|
.setView(dialogView)
|
||||||
|
.setCancelable(true)
|
||||||
|
.create()
|
||||||
|
|
||||||
|
val radioGroup = dialogView.findViewById<RadioGroup>(R.id.rgSource)
|
||||||
|
val downloadButton = dialogView.findViewById<Button>(R.id.btnDownload)
|
||||||
|
|
||||||
|
downloadButton.setOnClickListener {
|
||||||
|
val selectedSource = when (radioGroup.checkedRadioButtonId) {
|
||||||
|
R.id.rbSMI -> "SMI"
|
||||||
|
R.id.rbIISC -> "IISc"
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedSource != null) {
|
||||||
|
downloadAttendanceDailyReport(date, selectedSource)
|
||||||
|
dialog.dismiss()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, "Please select a source", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
dailyReportExport.cleanup()
|
||||||
exportTask.cleanup()
|
exportTask.cleanup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user