diff --git a/app/build.gradle b/app/build.gradle index f1fe17370b..692cb22441 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 26 targetSdkVersion 34 - versionCode 2140 - versionName "0.21.40" + versionCode 2141 + versionName "0.21.41" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt index 5a7f192220..68e8ac05f1 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt @@ -10,8 +10,10 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter +import android.widget.ListView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import androidx.core.content.ContextCompat import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceChangeListener @@ -23,6 +25,7 @@ import io.realm.Realm import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import org.ole.planet.myplanet.MainApplication.Companion.context import org.ole.planet.myplanet.MainApplication.Companion.mRealm import org.ole.planet.myplanet.MainApplication.Companion.setThemeMode import org.ole.planet.myplanet.R @@ -107,7 +110,7 @@ class SettingActivity : AppCompatActivity() { val darkMode = findPreference<Preference>("dark_mode") darkMode?.setOnPreferenceClickListener { - darkMode() + darkMode(requireActivity()) true } @@ -267,36 +270,56 @@ class SettingActivity : AppCompatActivity() { dialog.show() } - private fun darkMode() { - val options = arrayOf(getString(R.string.dark_mode_off), getString(R.string.dark_mode_on), getString(R.string.dark_mode_follow_system)) - val currentMode = getCurrentThemeMode() - val checkedItem = when (currentMode) { - ThemeMode.LIGHT -> 0 - ThemeMode.DARK -> 1 - else -> 2 - } + companion object { + fun darkMode(context: Context) { + val options = arrayOf(context.getString(R.string.dark_mode_off), context.getString(R.string.dark_mode_on),context.getString(R.string.dark_mode_follow_system)) + val currentMode = getCurrentThemeMode(context) + val checkedItem = when (currentMode) { + ThemeMode.LIGHT -> 0 + ThemeMode.DARK -> 1 + else -> 2 + } - val builder = AlertDialog.Builder(requireContext()) - .setTitle(getString(R.string.select_theme_mode)) - .setSingleChoiceItems(ArrayAdapter(requireContext(), R.layout.checked_list_item, options), checkedItem) { dialog, which -> - val selectedMode = when (which) { - 0 -> ThemeMode.LIGHT - 1 -> ThemeMode.DARK - 2 -> ThemeMode.FOLLOW_SYSTEM - else -> ThemeMode.FOLLOW_SYSTEM + val builder = AlertDialog.Builder(context, R.style.CustomAlertDialogStyle) + .setTitle(context.getString(R.string.select_theme_mode)) + .setSingleChoiceItems(ArrayAdapter(context, R.layout.checked_list_item, options), checkedItem) { dialog, which -> + val selectedMode = when (which) { + 0 -> ThemeMode.LIGHT + 1 -> ThemeMode.DARK + 2 -> ThemeMode.FOLLOW_SYSTEM + else -> ThemeMode.FOLLOW_SYSTEM + } + setThemeMode(context, selectedMode) + dialog.dismiss() } - setThemeMode(selectedMode) - dialog.dismiss() - } - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, null) - val dialog = builder.create() - dialog.show() - } + val dialog = builder.create() + dialog.show() - private fun getCurrentThemeMode(): String { - val sharedPreferences = requireContext().getSharedPreferences(PREFS_NAME, MODE_PRIVATE) - return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM + val window = dialog.window + window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + } + + private fun getCurrentThemeMode(context: Context): String { + val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE) + return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM + } + + private fun setThemeMode(context: Context, themeMode: String) { + val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE) + with(sharedPreferences.edit()) { + putString("theme_mode", themeMode) + apply() + } + AppCompatDelegate.setDefaultNightMode( + when (themeMode) { + ThemeMode.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO + ThemeMode.DARK -> AppCompatDelegate.MODE_NIGHT_YES + else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + } + ) + } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt index 1432276248..d0eed59e4f 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt @@ -19,6 +19,7 @@ import org.ole.planet.myplanet.callback.SyncListener import org.ole.planet.myplanet.databinding.* import org.ole.planet.myplanet.datamanager.* import org.ole.planet.myplanet.model.* +import org.ole.planet.myplanet.ui.SettingActivity import org.ole.planet.myplanet.ui.community.HomeCommunityDialogFragment import org.ole.planet.myplanet.ui.feedback.FeedbackFragment import org.ole.planet.myplanet.ui.userprofile.* @@ -110,6 +111,10 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { } } }) + val selectDarkModeButton = findViewById<ImageButton>(R.id.themeToggleButton) + selectDarkModeButton?.setOnClickListener{ + SettingActivity.SettingFragment.darkMode(this) + } } private fun declareElements() { diff --git a/app/src/main/res/drawable/moon_24dp.png b/app/src/main/res/drawable/moon_24dp.png new file mode 100644 index 0000000000..26ac0d8fa2 Binary files /dev/null and b/app/src/main/res/drawable/moon_24dp.png differ diff --git a/app/src/main/res/drawable/moon_35.png b/app/src/main/res/drawable/moon_35.png new file mode 100644 index 0000000000..4f748d24fa Binary files /dev/null and b/app/src/main/res/drawable/moon_35.png differ diff --git a/app/src/main/res/drawable/sun_24dp.png b/app/src/main/res/drawable/sun_24dp.png new file mode 100644 index 0000000000..7272d70af8 Binary files /dev/null and b/app/src/main/res/drawable/sun_24dp.png differ diff --git a/app/src/main/res/drawable/sun_35.png b/app/src/main/res/drawable/sun_35.png new file mode 100644 index 0000000000..1599faeff8 Binary files /dev/null and b/app/src/main/res/drawable/sun_35.png differ diff --git a/app/src/main/res/drawable/white_moon_24dp.png b/app/src/main/res/drawable/white_moon_24dp.png new file mode 100644 index 0000000000..56bca0d0e9 Binary files /dev/null and b/app/src/main/res/drawable/white_moon_24dp.png differ diff --git a/app/src/main/res/layout-large-land/activity_login.xml b/app/src/main/res/layout-large-land/activity_login.xml index a058ffce53..54904c34a7 100644 --- a/app/src/main/res/layout-large-land/activity_login.xml +++ b/app/src/main/res/layout-large-land/activity_login.xml @@ -211,12 +211,25 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + <ImageButton + android:id="@+id/themeToggleButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:background="@null" + android:contentDescription="@string/select_theme_mode" + android:paddingStart="@dimen/_10dp" + android:paddingTop="6dp" + android:paddingEnd="@dimen/_10dp" + app:srcCompat="@drawable/sun_35" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/logoImageView" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center|top" - android:layout_marginTop="20dp" + android:layout_marginTop="110dp" android:contentDescription="@string/ole_logo" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout-night/activity_login.xml b/app/src/main/res/layout-night/activity_login.xml index ee0471a934..1882200620 100644 --- a/app/src/main/res/layout-night/activity_login.xml +++ b/app/src/main/res/layout-night/activity_login.xml @@ -247,15 +247,27 @@ <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_marginTop="40dp"> + android:layout_height="match_parent"> + <ImageButton + android:id="@+id/themeToggleButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:background="@null" + android:contentDescription="@string/select_theme_mode" + android:paddingStart="@dimen/_10dp" + android:paddingTop="6dp" + android:paddingEnd="@dimen/_10dp" + app:srcCompat="@drawable/moon_35" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/logoImageView" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center|top" - android:layout_marginTop="20dp" + android:layout_marginTop="100dp" android:contentDescription="@string/ole_logo" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout-normal-land/activity_login.xml b/app/src/main/res/layout-normal-land/activity_login.xml index 30dd003753..8f86eaa022 100644 --- a/app/src/main/res/layout-normal-land/activity_login.xml +++ b/app/src/main/res/layout-normal-land/activity_login.xml @@ -211,12 +211,25 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + <ImageButton + android:id="@+id/themeToggleButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:background="@null" + android:contentDescription="@string/select_theme_mode" + android:paddingStart="@dimen/_10dp" + android:paddingTop="6dp" + android:paddingEnd="@dimen/_10dp" + app:srcCompat="@drawable/sun_35" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/logoImageView" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center|top" - android:layout_marginTop="10dp" + android:layout_marginTop="110dp" android:contentDescription="@string/ole_logo" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout-xlarge-land/activity_login.xml b/app/src/main/res/layout-xlarge-land/activity_login.xml index d642f097ab..019bc14da1 100644 --- a/app/src/main/res/layout-xlarge-land/activity_login.xml +++ b/app/src/main/res/layout-xlarge-land/activity_login.xml @@ -216,6 +216,19 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + <ImageButton + android:id="@+id/themeToggleButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:background="@null" + android:contentDescription="@string/select_theme_mode" + android:paddingStart="@dimen/_10dp" + android:paddingTop="6dp" + android:paddingEnd="@dimen/_10dp" + app:srcCompat="@drawable/sun_35" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/logoImageView" android:layout_width="100dp" diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 9370b9633d..8519f2ce04 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -245,15 +245,27 @@ <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_marginTop="40dp"> + android:layout_height="match_parent"> + <ImageButton + android:id="@+id/themeToggleButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:background="@null" + android:contentDescription="@string/select_theme_mode" + android:paddingStart="@dimen/_10dp" + android:paddingTop="6dp" + android:paddingEnd="@dimen/_10dp" + app:srcCompat="@drawable/sun_35" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/logoImageView" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center|top" - android:layout_marginTop="20dp" + android:layout_marginTop="110dp" android:contentDescription="@string/ole_logo" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/custom_dialog_layout.xml b/app/src/main/res/layout/custom_dialog_layout.xml new file mode 100644 index 0000000000..a1e3a7b1a6 --- /dev/null +++ b/app/src/main/res/layout/custom_dialog_layout.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- res/layout/custom_dialog_layout.xml --> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="16dp"> + + <!-- Add your dialog content here --> + <TextView + android:id="@+id/dialog_title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Dialog Title" + android:textSize="18sp" + android:textStyle="bold" /> + <ListView + android:id="@+id/dialog_list" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> +</LinearLayout> diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index e6aaf8079f..ec55dc3ed6 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -30,6 +30,7 @@ <string name="menu_logout">تسجيل الخروج</string> <string name="menu_feedback">ملاحظات</string> <string name="system_name">myPlanet</string> + <string name="select">يختار</string> <string name="txt_myLibrary">مكتبتي</string> <string name="txt_myCourses">دوراتي</string> <string name="txt_myMeetups">تجمعاتي</string> diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4f01459850..f899b86d94 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -30,6 +30,7 @@ <string name="menu_logout">Cerrar sesión</string> <string name="menu_feedback">Retroalimentación</string> <string name="system_name">myPlanet</string> + <string name="select">Seleccionar</string> <string name="txt_myLibrary">miBiblioteca</string> <string name="txt_myCourses">misCursos</string> <string name="txt_myMeetups">misEncuentros</string> diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index c5e32d4b9a..7e9dca5951 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -30,6 +30,7 @@ <string name="menu_logout">Déconnexion</string> <string name="menu_feedback">Retour d\'information</string> <string name="system_name">myPlanet</string> + <string name="select">Sélectionner</string> <string name="txt_myLibrary">maBibliothèque</string> <string name="txt_myCourses">mesCours</string> <string name="txt_myMeetups">mesRencontres</string> diff --git a/app/src/main/res/values-ne/strings.xml b/app/src/main/res/values-ne/strings.xml index ed4b98b562..20d2f9ff4f 100644 --- a/app/src/main/res/values-ne/strings.xml +++ b/app/src/main/res/values-ne/strings.xml @@ -30,6 +30,7 @@ <string name="menu_logout">लगआउट</string> <string name="menu_feedback">प्रतिक्रिया</string> <string name="system_name">myPlanet</string> + <string name="select">चयन गर्नुहोस्</string> <string name="txt_myLibrary">मेरो पुस्तकालय</string> <string name="txt_myCourses">मेरो पाठ्यक्रमहरू</string> <string name="txt_myMeetups">मेरो मिठिङहरू</string> diff --git a/app/src/main/res/values-so/strings.xml b/app/src/main/res/values-so/strings.xml index 109e3c18bb..4cc6778ff5 100644 --- a/app/src/main/res/values-so/strings.xml +++ b/app/src/main/res/values-so/strings.xml @@ -30,6 +30,7 @@ <string name="menu_logout">ka bax</string> <string name="menu_feedback">jawaab celin</string> <string name="system_name">myPlanet</string> + <string name="select">Dooro</string> <string name="txt_myLibrary">maktabadayda</string> <string name="txt_myCourses">coursyadayda</string> <string name="txt_myMeetups">myMeetups</string>