Advertisement
rifki_cs29

HomeFragment

Dec 9th, 2020
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.09 KB | None | 0 0
  1. class HomeFragment : Fragment() {
  2.     private var jumlahMonitoring : Int = 0
  3.     private var jumlahHistory: Int = 0
  4.  
  5.     override fun onCreate(savedInstanceState: Bundle?) {
  6.         super.onCreate(savedInstanceState)
  7.  
  8.         val inflater = TransitionInflater.from(requireContext())
  9.         enterTransition = inflater.inflateTransition(R.transition.fade_in)
  10.         exitTransition = inflater.inflateTransition(R.transition.fade_out)
  11.     }
  12.  
  13.     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
  14.         return inflater.inflate(R.layout.fragment_home, container, false)
  15.     }
  16.  
  17.     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  18.         super.onViewCreated(view, savedInstanceState)
  19.  
  20.         val mPreference = context?.getSharedPreferences("my_esign_preff", Context.MODE_PRIVATE)
  21.         val token = mPreference?.getString("access_token", "")
  22.         Log.e("test","tokendiHome: $token")
  23.  
  24.         AndroidNetworking.get("http://apps.floo.id:54000/api/v1/mobile/transaction/document-monitoring")
  25.             .addHeaders("Authorization", "Bearer $token")
  26.             .setPriority(Priority.LOW)
  27.             .build()
  28.             .getAsJSONObject(object : JSONObjectRequestListener {
  29.                 override fun onResponse(response: JSONObject) {
  30.                     try {
  31.                         jumlahMonitoring = response.getInt("totalCount")
  32.                         Log.e("test", "jumlahMonitoring: $jumlahMonitoring")
  33.                     } catch (e: Exception) {
  34.                         e.printStackTrace()
  35.                     }
  36.                 }
  37.  
  38.                 override fun onError(anError: ANError?) {
  39.  
  40.                 }
  41.             })
  42.  
  43.         AndroidNetworking.get("http://apps.floo.id:54000/api/v1/mobile/transaction/document-history")
  44.             .addHeaders("Authorization", "Bearer $token")
  45.             .setPriority(Priority.LOW)
  46.             .build()
  47.             .getAsJSONObject(object : JSONObjectRequestListener {
  48.                 override fun onResponse(response: JSONObject) {
  49.                     try {
  50.                         jumlahHistory = response.getInt("totalCount")
  51.                         Log.e("test", "jumlahHistory: $jumlahHistory")
  52.                     } catch (e: Exception) {
  53.                         e.printStackTrace()
  54.                     }
  55.                 }
  56.  
  57.                 override fun onError(anError: ANError?) {
  58.  
  59.                 }
  60.             })
  61.  
  62.  
  63.         val pieChart : AAChartModel = AAChartModel()
  64.             .chartType(AAChartType.Bar)
  65.             .title("PI Sign")
  66.             .backgroundColor("#d9f4ff")
  67.             .dataLabelsEnabled(true)
  68.             .series(
  69.                 arrayOf(
  70.                     AASeriesElement()
  71.                         .name("Monitoring")
  72.                         .data(arrayOf(jumlahMonitoring)),
  73.                     AASeriesElement()
  74.                         .name("History")
  75.                         .data(arrayOf(jumlahHistory))
  76.                 )
  77.             )
  78.  
  79.         chart_pie.aa_drawChartWithChartModel(pieChart)
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement