diff --git a/app/src/main/java/com/example/bondoyap/ui/graph/GraphFragment.kt b/app/src/main/java/com/example/bondoyap/ui/graph/GraphFragment.kt index 28c0565506749a7add8d571b6ef5425447f8434f..b9d913d30e715cea93fef5765bf2b7e99ae472b7 100644 --- a/app/src/main/java/com/example/bondoyap/ui/graph/GraphFragment.kt +++ b/app/src/main/java/com/example/bondoyap/ui/graph/GraphFragment.kt @@ -1,5 +1,6 @@ package com.example.bondoyap.ui.graph +import android.content.res.Configuration import androidx.fragment.app.viewModels import android.os.Bundle import androidx.fragment.app.Fragment @@ -7,6 +8,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.core.content.ContextCompat import com.example.bondoyap.R import com.github.mikephil.charting.charts.PieChart import com.github.mikephil.charting.components.Legend @@ -42,7 +44,7 @@ class GraphFragment : Fragment() { PieEntry(3f, "Entry 3") ) - val pieDataSet = PieDataSet(entries, "Pie Chart") + val pieDataSet = PieDataSet(entries, "") pieDataSet.colors = ColorTemplate.COLORFUL_COLORS.toList() val pieData = PieData(pieDataSet) @@ -51,16 +53,20 @@ class GraphFragment : Fragment() { pieChart.description.isEnabled = false val legend = pieChart.legend - legend.isEnabled = true - legend.orientation = Legend.LegendOrientation.HORIZONTAL - legend.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM - legend.horizontalAlignment = Legend.LegendHorizontalAlignment.CENTER + val orientation = resources.configuration.orientation + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + legend.horizontalAlignment = Legend.LegendHorizontalAlignment.RIGHT + legend.verticalAlignment = Legend.LegendVerticalAlignment.CENTER + } else { + legend.horizontalAlignment = Legend.LegendHorizontalAlignment.CENTER + legend.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM + } legend.setDrawInside(false) if (isDarkTheme()) { - legend.textColor = resources.getColor(R.color.white) + legend.textColor = ContextCompat.getColor(requireContext(), R.color.white) } else { - legend.textColor = resources.getColor(R.color.black) + legend.textColor = ContextCompat.getColor(requireContext(), R.color.black) } pieChart.invalidate() @@ -68,7 +74,7 @@ class GraphFragment : Fragment() { } private fun isDarkTheme(): Boolean { - val currentNightMode = resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK - return currentNightMode == android.content.res.Configuration.UI_MODE_NIGHT_YES + val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return currentNightMode == Configuration.UI_MODE_NIGHT_YES } } \ No newline at end of file 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 0000000000000000000000000000000000000000..37aba8c28c124c445dcfff4c0f11adb05d4dc31f --- /dev/null +++ b/app/src/main/res/layout-land/activity_main.xml @@ -0,0 +1,30 @@ +<?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" + android:id="@+id/container" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <com.google.android.material.bottomnavigation.BottomNavigationView + android:id="@+id/nav_view" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:background="?android:attr/windowBackground" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:menu="@menu/bottom_nav_menu" /> + + <fragment + android:id="@+id/nav_host_fragment_activity_main" + android:name="androidx.navigation.fragment.NavHostFragment" + android:layout_width="0dp" + android:layout_height="0dp" + app:defaultNavHost="true" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toTopOf="@id/nav_view" + app:navGraph="@navigation/mobile_navigation" /> + +</androidx.constraintlayout.widget.ConstraintLayout> 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 0000000000000000000000000000000000000000..e84b522c8852d3f09ae5c6e2f0ba0fedd872aad7 --- /dev/null +++ b/app/src/main/res/layout-land/fragment_graph.xml @@ -0,0 +1,35 @@ +<?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"> + + <com.github.mikephil.charting.charts.PieChart + android:id="@+id/pieChart" + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"/> + + + <TextView + android:id="@+id/legendTextView" + android:layout_width="wrap_content" + android:layout_height="0dp" + android:textAlignment="center" + android:layout_marginEnd="16dp" + app:layout_constraintTop_toTopOf="@id/pieChart" + app:layout_constraintBottom_toBottomOf="@id/pieChart" + app:layout_constraintStart_toEndOf="@id/pieChart" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintVertical_bias="0.5" + app:layout_constraintHorizontal_bias="1.0" /> + +</androidx.constraintlayout.widget.ConstraintLayout> diff --git a/app/src/main/res/layout/fragment_graph.xml b/app/src/main/res/layout/fragment_graph.xml index ad5cee2376a1605323218826d504cb8a2e498000..9190a62c7ca86d85080f31eeab40675ecd34d1ae 100644 --- a/app/src/main/res/layout/fragment_graph.xml +++ b/app/src/main/res/layout/fragment_graph.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> -<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" +<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" @@ -8,19 +9,21 @@ <com.github.mikephil.charting.charts.PieChart android:id="@+id/pieChart" - android:layout_width="match_parent" + android:layout_width="0dp" android:layout_height="0dp" - android:layout_weight="8" + app:layout_constraintDimensionRatio="1:1" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toTopOf="@id/legendTextView" /> + app:layout_constraintBottom_toTopOf="@id/legendTextView" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"/> <TextView android:id="@+id/legendTextView" - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="2" - android:textAlignment="center" + android:layout_width="wrap_content" + android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@id/pieChart" - app:layout_constraintBottom_toBottomOf="parent"/> + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"/> -</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file +</androidx.constraintlayout.widget.ConstraintLayout>