From 7fbff9c86cb6ec05e5fd7a01474f0778a49032d2 Mon Sep 17 00:00:00 2001
From: jejejery <13521131@std.stei.itb.ac.id>
Date: Wed, 13 Mar 2024 23:03:44 +0700
Subject: [PATCH] finalize graph fragment

---
 .idea/deploymentTargetDropDown.xml            | 13 ++-
 app/build.gradle.kts                          |  5 +
 .../java/com/ssk/bondoman/MainActivity.kt     |  3 +-
 .../ssk/bondoman/ui/graph/GraphFragment.kt    | 49 +++++++++-
 .../ssk/bondoman/ui/graph/GraphViewModel.kt   | 31 ++++++-
 .../ui/transaction/TransactionFragment.kt     |  7 ++
 .../main/res/layout-land/activity_main.xml    | 43 +++++++++
 .../main/res/layout-land/fragment_graph.xml   | 93 +++++++++++++++++++
 .../res/layout-land/fragment_transaction.xml  | 39 ++++++++
 app/src/main/res/layout/activity_main.xml     |  3 +
 app/src/main/res/layout/fragment_graph.xml    | 74 +++++++++++++--
 .../main/res/layout/fragment_transaction.xml  |  4 +-
 12 files changed, 346 insertions(+), 18 deletions(-)
 create mode 100644 app/src/main/res/layout-land/activity_main.xml
 create mode 100644 app/src/main/res/layout-land/fragment_graph.xml
 create mode 100644 app/src/main/res/layout-land/fragment_transaction.xml

diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 76681df..74d3b9c 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -4,6 +4,17 @@
     <value>
       <entry key="app">
         <State>
+          <runningDeviceTargetSelectedWithDropDown>
+            <Target>
+              <type value="RUNNING_DEVICE_TARGET" />
+              <deviceKey>
+                <Key>
+                  <type value="VIRTUAL_DEVICE_PATH" />
+                  <value value="C:\Users\seres\.android\avd\Pixel_3a_API_34_extension_level_7_x86_64.avd" />
+                </Key>
+              </deviceKey>
+            </Target>
+          </runningDeviceTargetSelectedWithDropDown>
           <targetSelectedWithDropDown>
             <Target>
               <type value="QUICK_BOOT_TARGET" />
@@ -15,7 +26,7 @@
               </deviceKey>
             </Target>
           </targetSelectedWithDropDown>
-          <timeTargetWasSelectedWithDropDown value="2024-03-13T00:29:24.764409600Z" />
+          <timeTargetWasSelectedWithDropDown value="2024-03-13T14:56:57.962285400Z" />
         </State>
       </entry>
     </value>
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 0992043..7232443 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -18,6 +18,8 @@ android {
         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
     }
 
+
+
     buildTypes {
         release {
             isMinifyEnabled = false
@@ -49,12 +51,15 @@ dependencies {
     implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
     implementation("androidx.navigation:navigation-fragment-ktx:2.3.5")
     implementation("androidx.navigation:navigation-ui-ktx:2.3.5")
+    implementation("androidx.compose.ui:ui-unit:1.0.1")
     implementation("nl.joery.animatedbottombar:library:1.1.0")
 
     implementation("com.squareup.retrofit2:retrofit:2.9.0")
     implementation("com.squareup.retrofit2:converter-gson:2.9.0")
     implementation("androidx.annotation:annotation:1.7.1")
     implementation("androidx.legacy:legacy-support-v4:1.0.0")
+    implementation("ir.mahozad.android:pie-chart:0.7.0")
+
 
     testImplementation("junit:junit:4.13.2")
     //For runBlockingTest, CoroutineDispatcher etc.
diff --git a/app/src/main/java/com/ssk/bondoman/MainActivity.kt b/app/src/main/java/com/ssk/bondoman/MainActivity.kt
index 0ece24e..6cc6567 100644
--- a/app/src/main/java/com/ssk/bondoman/MainActivity.kt
+++ b/app/src/main/java/com/ssk/bondoman/MainActivity.kt
@@ -1,5 +1,6 @@
 package com.ssk.bondoman
 
+import android.content.pm.ActivityInfo
 import android.os.Bundle
 import android.view.Menu
 import androidx.appcompat.app.AppCompatActivity
@@ -13,8 +14,8 @@ class MainActivity : AppCompatActivity() {
     private lateinit var navController: NavController
 
     override fun onCreate(savedInstanceState: Bundle?) {
+        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
         super.onCreate(savedInstanceState)
-
         binding = ActivityMainBinding.inflate(layoutInflater)
         setContentView(binding.root)
 
diff --git a/app/src/main/java/com/ssk/bondoman/ui/graph/GraphFragment.kt b/app/src/main/java/com/ssk/bondoman/ui/graph/GraphFragment.kt
index ad03607..913dbe0 100644
--- a/app/src/main/java/com/ssk/bondoman/ui/graph/GraphFragment.kt
+++ b/app/src/main/java/com/ssk/bondoman/ui/graph/GraphFragment.kt
@@ -1,13 +1,20 @@
 package com.ssk.bondoman.ui.graph
 
+import android.content.pm.ActivityInfo
+import android.graphics.Color
 import android.os.Bundle
+import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.widget.TextView
 import androidx.fragment.app.Fragment
 import androidx.lifecycle.ViewModelProvider
+import androidx.compose.ui.unit.dp
 import com.ssk.bondoman.databinding.FragmentGraphBinding
+import ir.mahozad.android.PieChart
+import ir.mahozad.android.component.Wrapping
+import ir.mahozad.android.unit.Dimension
 
 class GraphFragment : Fragment() {
 
@@ -28,10 +35,33 @@ class GraphFragment : Fragment() {
         _binding = FragmentGraphBinding.inflate(inflater, container, false)
         val root: View = binding.root
 
-        val textView: TextView = binding.textGraph
-        graphViewModel.text.observe(viewLifecycleOwner) {
-            textView.text = it
+        //Pembelian && Penjualan
+        val textViewPembelian: TextView = binding.pembelian
+        val textViewPenjualan: TextView = binding.penjualan
+
+        graphViewModel.textPembelian.observe(viewLifecycleOwner) {
+            textViewPembelian.text = "Pembelian: 60.000" // should change later according to DB
+        }
+        graphViewModel.textPenjualan.observe(viewLifecycleOwner) {
+            textViewPenjualan.text = "Penjualan: 40.000" // should change later according to DB
+        }
+
+        //PieChart
+        val pieChart = binding.pieChart
+
+        pieChart.slices = graphViewModel.TSGraph.value!!
+        graphViewModel.TSGraph.observe(viewLifecycleOwner) { another_slices ->
+            // Update slices when TSGraph changes
+
+            pieChart.apply {
+//                layoutParams.width = Dimension.DP(400f).dp.toInt()
+//                layoutParams.height = Dimension.DP(400f).dp.toInt()
+                slices = another_slices
+
+            }
         }
+
+
         return root
     }
 
@@ -39,4 +69,17 @@ class GraphFragment : Fragment() {
         super.onDestroyView()
         _binding = null
     }
+
+    override fun onResume() {
+        super.onResume()
+        getActivity()?.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
+
+    }
+
+    override fun onPause(){
+        super.onPause()
+        getActivity()?.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+    }
+
+
 }
\ No newline at end of file
diff --git a/app/src/main/java/com/ssk/bondoman/ui/graph/GraphViewModel.kt b/app/src/main/java/com/ssk/bondoman/ui/graph/GraphViewModel.kt
index 5bdeb23..ae41f8f 100644
--- a/app/src/main/java/com/ssk/bondoman/ui/graph/GraphViewModel.kt
+++ b/app/src/main/java/com/ssk/bondoman/ui/graph/GraphViewModel.kt
@@ -1,13 +1,38 @@
 package com.ssk.bondoman.ui.graph
 
+import android.graphics.Color
 import androidx.lifecycle.LiveData
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
+import ir.mahozad.android.PieChart
+import ir.mahozad.android.PieChart.Slice
 
 class GraphViewModel : ViewModel() {
 
-    private val _text = MutableLiveData<String>().apply {
-        value = "This is graph Fragment"
+    private val _textPembelian = MutableLiveData<String>().apply {
+        value = "Pembelian: "
+    }
+    val textPembelian: LiveData<String> = _textPembelian
+
+    private val _textPenjualan = MutableLiveData<String>().apply {
+        value = "Penjualan: "
+    }
+    val textPenjualan: LiveData<String> = _textPenjualan
+
+    private val _TSGraph = MutableLiveData<List<Slice>>().apply{
+        value = listOf(
+            Slice(0.4f, Color.BLUE),
+            Slice(0.6f, Color.CYAN)
+        )
+    }
+
+    val TSGraph : LiveData<List<Slice>> = _TSGraph
+
+    fun getPurchaseAmount(value : Int) : String{
+        return "Pembelian: $value"
+    }
+
+    fun getSalesAmount(value : Int) : String{
+        return "Penjualan: $value"
     }
-    val text: LiveData<String> = _text
 }
\ No newline at end of file
diff --git a/app/src/main/java/com/ssk/bondoman/ui/transaction/TransactionFragment.kt b/app/src/main/java/com/ssk/bondoman/ui/transaction/TransactionFragment.kt
index 7614be9..7e0b048 100644
--- a/app/src/main/java/com/ssk/bondoman/ui/transaction/TransactionFragment.kt
+++ b/app/src/main/java/com/ssk/bondoman/ui/transaction/TransactionFragment.kt
@@ -1,5 +1,6 @@
 package com.ssk.bondoman.ui.transaction
 
+import android.content.pm.ActivityInfo
 import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
@@ -25,6 +26,9 @@ class TransactionFragment : Fragment() {
         container: ViewGroup?,
         savedInstanceState: Bundle?
     ): View {
+        // allow potrait and landscape mode in this fragment
+
+
         _binding = FragmentTransactionBinding.inflate(inflater, container, false)
         val root: View = binding.root
 
@@ -50,8 +54,11 @@ class TransactionFragment : Fragment() {
         }
     }
 
+
     override fun onDestroyView() {
         super.onDestroyView()
         _binding = null
     }
+
+
 }
diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml
new file mode 100644
index 0000000..8721f9e
--- /dev/null
+++ b/app/src/main/res/layout-land/activity_main.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/container"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:paddingTop="?attr/actionBarSize">
+
+    <nl.joery.animatedbottombar.AnimatedBottomBar
+        android:id="@+id/nav_view"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="#FFF"
+        app:abb_indicatorAppearance="round"
+        app:abb_indicatorHeight="4dp"
+        app:abb_indicatorMargin="16dp"
+        app:abb_selectedIndex="0"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:abb_selectedTabType="text"
+        app:abb_textStyle="bold"
+        app:abb_tabs="@menu/bottom_nav_menu" />
+
+
+    <fragment
+        android:id="@+id/nav_host_fragment_activity_main"
+        android:name="androidx.navigation.fragment.NavHostFragment"
+        android:layout_width="733dp"
+        android:layout_height="293dp"
+        android:visibility="visible"
+        app:defaultNavHost="true"
+        app:layout_constraintBottom_toTopOf="@id/nav_view"
+        app:layout_constraintHorizontal_bias="0.0"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_bias="0.0"
+        app:navGraph="@navigation/mobile_navigation"
+        tools:ignore="FragmentTagUsage" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout-land/fragment_graph.xml b/app/src/main/res/layout-land/fragment_graph.xml
new file mode 100644
index 0000000..5b7f876
--- /dev/null
+++ b/app/src/main/res/layout-land/fragment_graph.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".ui.graph.GraphFragment">
+
+
+    <LinearLayout
+        android:layout_width="248dp"
+        android:layout_height="141dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toStartOf="@+id/linearLayout"
+        app:layout_constraintHorizontal_bias="0.462"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_bias="0.131">
+
+        <ir.mahozad.android.PieChart
+            android:id="@+id/pie_chart"
+            android:layout_width="279dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintVertical_bias="0.431" />
+    </LinearLayout>
+
+    <LinearLayout
+        android:id="@+id/linearLayout"
+        android:layout_width="228dp"
+        android:layout_height="153dp"
+        android:layout_marginEnd="100dp"
+        android:orientation="vertical"
+        android:padding="16dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_bias="0.064">
+
+        <LinearLayout
+            android:layout_width="196dp"
+            android:layout_height="51dp"
+            android:orientation="horizontal"
+            android:padding="16dp">
+
+            <View
+                android:layout_width="11dp"
+                android:layout_height="10dp"
+                android:layout_marginStart="8dp"
+                android:background="#FF0000FF" />
+
+            <!-- Teks "Pembelian" -->
+            <TextView
+                android:id="@+id/pembelian"
+                android:layout_width="122dp"
+                android:layout_height="22dp"
+                android:layout_marginStart="8dp"
+                android:text="Pembelian"
+                android:textColor="@android:color/black"
+                android:textSize="12sp" />
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="198dp"
+            android:layout_height="47dp"
+            android:orientation="horizontal"
+            android:padding="16dp">
+
+            <View
+                android:layout_width="6dp"
+                android:layout_height="10dp"
+                android:layout_marginStart="8dp"
+                android:background="#FF00FFFF" />
+
+            <!-- Teks "Penjualan" -->
+            <TextView
+                android:id="@+id/penjualan"
+                android:layout_width="122dp"
+                android:layout_height="22dp"
+                android:layout_marginStart="8dp"
+                android:text="Penjualan: 60000"
+                android:textColor="@android:color/black"
+                android:textSize="12sp" />
+
+        </LinearLayout>
+
+
+    </LinearLayout>
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout-land/fragment_transaction.xml b/app/src/main/res/layout-land/fragment_transaction.xml
new file mode 100644
index 0000000..cabcd1e
--- /dev/null
+++ b/app/src/main/res/layout-land/fragment_transaction.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".ui.transaction.TransactionFragment">
+
+
+    <TextView
+        android:id="@+id/text_transaction"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="8dp"
+        android:layout_marginTop="8dp"
+        android:layout_marginEnd="8dp"
+        android:text="Daftar Transaksi"
+        android:textAlignment="center"
+        android:textSize="20sp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.0"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_bias="0.0" />
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/transaction_list"
+        android:layout_width="494dp"
+        android:layout_height="268dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.497"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/text_transaction"
+        app:layout_constraintVertical_bias="0.333" />
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index ecb504c..43bea8c 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -29,11 +29,14 @@
         android:name="androidx.navigation.fragment.NavHostFragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:visibility="visible"
         app:defaultNavHost="true"
         app:layout_constraintBottom_toTopOf="@id/nav_view"
+        app:layout_constraintHorizontal_bias="0.0"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintVertical_bias="0.0"
         app:navGraph="@navigation/mobile_navigation"
         tools:ignore="FragmentTagUsage" />
 
diff --git a/app/src/main/res/layout/fragment_graph.xml b/app/src/main/res/layout/fragment_graph.xml
index 54053ee..d5c9d2b 100644
--- a/app/src/main/res/layout/fragment_graph.xml
+++ b/app/src/main/res/layout/fragment_graph.xml
@@ -6,17 +6,75 @@
     android:layout_height="match_parent"
     tools:context=".ui.graph.GraphFragment">
 
-    <TextView
-        android:id="@+id/text_graph"
+    <ir.mahozad.android.PieChart
+        android:id="@+id/pie_chart"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="80dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:textAlignment="center"
-        android:textSize="20sp"
+        android:orientation="vertical"
+        android:padding="16dp"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.0"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toBottomOf="@+id/pie_chart"
+        app:layout_constraintVertical_bias="0.141">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            android:padding="16dp">
+
+            <View
+                android:layout_width="11dp"
+                android:layout_height="10dp"
+                android:layout_marginStart="8dp"
+                android:background="#FF0000FF" />
+
+            <!-- Teks "Pembelian" -->
+            <TextView
+                android:id="@+id/pembelian"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="8dp"
+                android:text="Pembelian"
+                android:textColor="@android:color/black"
+                android:textSize="18sp" />
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            android:padding="16dp">
+            <!-- Kotak kosong dengan latar belakang biru -->
+
+            <!-- Teks "Penjualan" -->
+            <View
+                android:layout_width="10dp"
+                android:layout_height="10dp"
+                android:layout_marginStart="8dp"
+                android:background="#FF00FFFF" />
+
+            <TextView
+                android:id="@+id/penjualan"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="8dp"
+                android:text="Penjualan"
+                android:textColor="@android:color/black"
+                android:textSize="18sp" />
+        </LinearLayout>
+
+
+    </LinearLayout>
+
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_transaction.xml b/app/src/main/res/layout/fragment_transaction.xml
index 9e25538..bd90562 100644
--- a/app/src/main/res/layout/fragment_transaction.xml
+++ b/app/src/main/res/layout/fragment_transaction.xml
@@ -26,8 +26,8 @@
 
     <androidx.recyclerview.widget.RecyclerView
         android:id="@+id/transaction_list"
-        android:layout_width="348dp"
-        android:layout_height="390dp"
+        android:layout_width="339dp"
+        android:layout_height="539dp"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintHorizontal_bias="0.492"
-- 
GitLab