Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.siakad.student.menu.rencanastudi
- import android.content.Intent
- import android.graphics.Color
- import android.os.Build
- import android.os.Bundle
- import android.util.Log
- import android.view.LayoutInflater
- import android.view.View
- import android.view.ViewGroup
- import android.widget.Toast
- import androidx.annotation.RequiresApi
- import androidx.appcompat.app.AppCompatActivity
- import androidx.core.content.ContextCompat
- import androidx.navigation.findNavController
- import androidx.navigation.fragment.findNavController
- import com.siakad.student.R
- import com.siakad.student.activity.base.BaseFragment
- import com.siakad.student.config.connection.Resource
- import com.siakad.student.config.crypts.EncDec
- import com.siakad.student.config.endpoint.RencanaStudi
- import com.siakad.student.config.response.ResponseModel
- import com.siakad.student.config.util.ProgressDialogManager
- import com.siakad.student.config.util.handleApiError
- import com.siakad.student.config.util.visible
- import com.siakad.student.databinding.FragmentRencanaStudiBinding
- import com.siakad.student.menu.home.MenuActivity
- import kotlinx.coroutines.flow.first
- import kotlinx.coroutines.runBlocking
- import org.json.JSONObject
- class RencanaStudiFragment : BaseFragment<RencanaStudiVM, FragmentRencanaStudiBinding, RencanaStudiRepo>() {
- private val TAG = "KRS"
- @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
- override fun onActivityCreated(savedInstanceState: Bundle?) {
- super.onActivityCreated(savedInstanceState)
- (activity as AppCompatActivity).setSupportActionBar(binding.topAppBar)
- binding.topAppBar.apply {
- navigationIcon = ContextCompat.getDrawable(context, R.drawable.ic_back)
- setNavigationOnClickListener {
- activity?.finish()
- }
- }
- getRencanaStudi()
- }
- fun getRencanaStudi() {
- val jsonObject = JSONObject()
- jsonObject.put("nim", runBlocking { userPrefrences.nimFlow.first() })
- jsonObject.put("thnakademik", runBlocking { userPrefrences.thakademik.first() })
- jsonObject.put("idprogramstudi", runBlocking { userPrefrences.idprogramstudi.first() })
- val param = EncDec().toEncrypt(jsonObject.toString())
- val streams = param?.replace("\\n", "")
- streams?.let { it -> viewModel.getKrs_reg(it) }
- val progressDialogManager = context?.let { it -> ProgressDialogManager(it).loader(getString(
- R.string.message_progress_loading)) }
- viewModel.rencanaStudiResponse.observe(viewLifecycleOwner, {
- when (it) {
- is Resource.Loading -> progressDialogManager?.show()
- is Resource.Success -> {
- val responseModel: ResponseModel = it.value
- val decrypt = EncDec().toDerypt(responseModel.streams)
- val jsonObject = JSONObject(decrypt)
- binding.tvIndekPrestasi.text = jsonObject.getString("ip")
- binding.tvSksMax.text = jsonObject.getString("sksmax")
- //NOTE: Kebalik antara tvskstempuh dan tvskssisa, sksrencanastudi == tempuh
- binding.tvSksTempuh.text = jsonObject.getString("skssisa")
- binding.tvSksSisa.text = jsonObject.getString("sksrencanastudi")
- var statusDosenWali = jsonObject.getString("statusdosenwali")
- var catatan = jsonObject.getString("catatan")
- var pemberitahuan = jsonObject.getString("pemberitahuan")
- var stskrs = jsonObject.getString("stskrs")
- var stsKuesioner = jsonObject.getString("stskuesioner")
- when (stskrs) {
- "0" -> {
- // proses ambil matkul
- binding.cardProses.setOnClickListener { v ->
- findNavController().navigate(R.id.action_rencanaStudiFragment_to_prosesFragment)
- }
- binding.cardMenunggu.setOnClickListener { v ->
- Toast.makeText(context, getString(R.string.label_pengambilan_matakuliah), Toast.LENGTH_SHORT).show()
- }
- binding.cardDone.setOnClickListener { v ->
- Toast.makeText(context, getString(R.string.label_pengambilan_matakuliah), Toast.LENGTH_SHORT).show()
- }
- }
- "1" -> {
- // telah disetujui oleh dosen wali
- binding.cardProses.setOnClickListener { v ->
- Toast.makeText(context,"Oops! ${getString(R.string.label_rencana_studi_telah_disetujui)}", Toast.LENGTH_SHORT).show()
- }
- binding.cardMenunggu.setOnClickListener { v ->
- Toast.makeText(context, "Oops! ${getString(R.string.label_rencana_studi_telah_disetujui)}", Toast.LENGTH_SHORT).show()
- }
- binding.cardDone.setOnClickListener { v ->
- findNavController().navigate(R.id.action_rencanaStudiFragment_to_doneFragment)
- }
- }
- "2" -> {
- // menunggu disetujui oleh dosen wali
- binding.cardProses.setOnClickListener { v ->
- Toast.makeText(context, getString(R.string.label_persetujuan_oleh_dosen_wali), Toast.LENGTH_SHORT).show()
- }
- binding.cardMenunggu.setOnClickListener { v ->
- findNavController().navigate(R.id.action_rencanaStudiFragment_to_waitFragment)
- }
- binding.cardDone.setOnClickListener { v ->
- Toast.makeText(context, getString(R.string.label_persetujuan_oleh_dosen_wali), Toast.LENGTH_SHORT).show()
- }
- }
- }
- progressDialogManager?.dismiss()
- }
- is Resource.Failure -> {
- progressDialogManager?.dismiss()
- handleApiError(it)
- }
- }
- })
- }
- override fun getViewModel()= RencanaStudiVM::class.java
- override fun getFragmentBinding(
- inflater: LayoutInflater,
- container: ViewGroup?
- ) = FragmentRencanaStudiBinding.inflate(inflater, container, false)
- override fun getFragmentRepository() :RencanaStudiRepo {
- val token = runBlocking { userPrefrences.authToken.first() }
- val api = clientRemote.buildApi(RencanaStudi::class.java, token)
- return RencanaStudiRepo(api)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement