Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Change Theme in the Settings page #43

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
package divyansh.tech.animeclassroom.settings

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import dagger.hilt.android.AndroidEntryPoint
import divyansh.tech.animeclassroom.R
import divyansh.tech.animeclassroom.databinding.FragmentHomeBinding
import divyansh.tech.animeclassroom.databinding.FragmentSearchBinding
import divyansh.tech.animeclassroom.generated.callback.OnClickListener
import kotlinx.android.synthetic.main.fragment_settings.*

//Todo: Use FragmentSettingsBinding

@AndroidEntryPoint
class SettingsFragment: Fragment(R.layout.fragment_settings) {
class SettingsFragment: Fragment(){

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.fragment_settings, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setUpListeners()
}

private fun setUpListeners() {
ui_mode.setOnClickListener{showUIDialog()}
}

private fun showUIDialog() {
val uiModes = resources.getStringArray(R.array.ui_mode)
val checkedItem = 0

val alertDialogBuilder = AlertDialog.Builder(requireContext())
alertDialogBuilder.setTitle("Choose ui Mode")
alertDialogBuilder.setSingleChoiceItems(uiModes, checkedItem){ dialog, checked ->
setUiMode(checked)
dialog.dismiss()
}
val alertDialog = alertDialogBuilder.create().apply {
setCancelable(true)
show()
}
}

private fun setUiMode(checked: Int) {
when(checked){
0 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_arrow_forward_ios_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M5.88,4.12L13.76,12l-7.88,7.88L8,22l10,-10L8,2z"/>
</vector>
74 changes: 67 additions & 7 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
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"
android:orientation="vertical">

<TextView
android:layout_height="match_parent"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="80dp"
android:fontFamily="sans-serif-medium"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:paddingRight="20dp"
android:paddingBottom="10dp"
android:text="@string/settings"
android:textColor="@color/home_header"
android:textSize="36sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:id="@+id/settings_layout"
android:layout_width="match_parent"
android:text="Settings"
/>
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/app_background"
android:paddingTop="20dp"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ui_mode"
android:layout_width="match_parent"
android:layout_height="56dp"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
android:background="@color/secondary_background">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/change_theme"
android:fontFamily="sans-serif-medium"
android:textSize="16sp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="16dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:src="@drawable/ic_baseline_arrow_forward_ios_24"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@
<string name="plot_summary">Plot Summary</string>

<string name="no_result_for_searched_query">No results for searched query</string>

<string name="change_theme">Change Theme</string>
<string-array name="ui_mode">
<item>Light Mode</item>
<item>Night Mode</item>
<item>System</item>
</string-array>

</resources>