Skip to content
Open
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
51 changes: 50 additions & 1 deletion app/src/androidTest/java/lufra/youpidapp/ParametersUITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry
import org.hamcrest.Matchers
import org.hamcrest.Matchers.not
import org.junit.AfterClass
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -40,6 +41,11 @@ class ParametersUITest {
.perform(click())
onData(Matchers.anything()).atPosition(PLAYMODE_DEFAULT).perform(click())
onView(withId(R.id.checkbox_open_on_favorites)).perform(CustomViewActions.setChecked(false))
onView(withId(R.id.theme_spinner))
.perform(click())
onData(Matchers.anything()).atPosition(PLAYMODE_DEFAULT).perform(click())
// activity restarted, we come back to the parameterFragment
UIInstrumentedTestSuite.changeOfFragmentFromDrawer(3)
}

@Test
Expand Down Expand Up @@ -97,7 +103,6 @@ class ParametersUITest {
onView(withId(R.id.type_spinner))
.check(matches(isDisplayed()))
.check(matches(isClickable()))
//.check(matches(withSpinnerText(containsString(type2)))) depends des prefs
.check(isCompletelyBelow(withId(R.id.title)))
.perform(click())

Expand Down Expand Up @@ -187,6 +192,8 @@ class ParametersUITest {
val tc = InstrumentationRegistry.getInstrumentation().targetContext
val type1 = tc.getString(R.string.type1)
val type2 = tc.getString(R.string.type2)
val themeMode1 = tc.getString(R.string.day_mode)
val themeMode2 = tc.getString(R.string.night_mode)

// change the values
onView(withId(R.id.pitch_seekBar))
Expand All @@ -202,6 +209,14 @@ class ParametersUITest {
onData(Matchers.anything()).atPosition(1).perform(click())
onView(withId(R.id.type_spinner))
.check(matches(withSpinnerText(Matchers.containsString(type2))))
onView(withId(R.id.theme_spinner))
.check(matches(withSpinnerText(Matchers.containsString(themeMode1))))
.perform(click())
onData(Matchers.anything()).atPosition(1).perform(click())
// activity restarted, we come back to the parameterFragment
UIInstrumentedTestSuite.changeOfFragmentFromDrawer(3)
onView(withId(R.id.theme_spinner))
.check(matches(withSpinnerText(Matchers.containsString(themeMode2))))

// press the default button
onView(withId(R.id.default_settings_button)).perform(click())
Expand All @@ -212,5 +227,39 @@ class ParametersUITest {
onView(withId(R.id.checkbox_open_on_favorites)).check(matches(isChecked()))
onView(withId(R.id.type_spinner))
.check(matches(withSpinnerText(Matchers.containsString(type2))))
// activity restarted, we come back to the parameterFragment
UIInstrumentedTestSuite.changeOfFragmentFromDrawer(3)
onView(withId(R.id.theme_spinner))
.check(matches(withSpinnerText(Matchers.containsString(themeMode2))))
}

@Test
fun themeChooserTest() {
val tc = InstrumentationRegistry.getInstrumentation().targetContext

val themeMode1 = tc.getString(R.string.day_mode)
val themeMode2 = tc.getString(R.string.night_mode)

onView(withId(R.id.theme_spinner))
.check(matches(isDisplayed()))
.check(matches(isClickable()))
.check(matches(isFocusable()))
.check(isCompletelyBelow(withId(R.id.title)))
.check(matches(withSpinnerText(Matchers.containsString(themeMode1))))
.perform(click())
onData(Matchers.anything()).atPosition(1).perform(click())
// activity restarted, we come back to the parameterFragment
UIInstrumentedTestSuite.changeOfFragmentFromDrawer(3)
onView(withId(R.id.theme_spinner))
.check(matches(withSpinnerText(Matchers.containsString(themeMode2))))

// Check the parametersFragment nightMode
val whiteCol = R.color.white
onView(withId(R.id.title))
.check(matches(hasTextColor(whiteCol)))
onView(withId(R.id.type_of_reading))
.check(matches(hasTextColor(whiteCol)))
onView(withId(R.id.pitch))
.check(matches(hasTextColor(whiteCol)))
}
}
1 change: 1 addition & 0 deletions app/src/main/java/adapter/SoundAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SoundAdapter(_soundsList: List<Sound>, private val soundClickedListener: S
if (sound != null) {
if (sound!!.isFavourite) {
button.setIconResource(R.drawable.ic_baseline_star_border_24)
button.setIconTintResource(R.color.black)
DataPersistenceHelper.removeSoundFavorite(sound!!)
} else {
button.setIconResource(R.drawable.ic_baseline_star_24)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/fragments/BoiteFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import animation.TranslationAnim
import lufra.youpidapp.MainActivity
import lufra.youpidapp.PlayType
import lufra.youpidapp.R
import java.util.Timer
import java.util.*
import kotlin.concurrent.schedule
import kotlin.random.Random

Expand Down
23 changes: 16 additions & 7 deletions app/src/main/java/fragments/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package fragments

import adapter.SoundAdapter
import android.animation.Animator
import android.animation.AnimatorInflater
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import data.Sound
import adapter.SoundAdapter
import android.animation.*
import android.content.res.Configuration
import android.view.MenuItem
import android.widget.Button
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import data.Sound
import lufra.youpidapp.DataPersistenceHelper
import lufra.youpidapp.MainActivity
import lufra.youpidapp.R
Expand All @@ -38,7 +42,12 @@ open class MainFragment: MyFragment() {
}
private val animCleanup = object: SoundAdapter.CleanupAnimationListener {
override fun onUnbind(soundViewHolder: SoundAdapter.SoundViewHolder) {
soundViewHolder.button.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary))
val nightMode = AppCompatDelegate.getDefaultNightMode()
if (nightMode == AppCompatDelegate.MODE_NIGHT_YES) {
soundViewHolder.button.setBackgroundColor(ContextCompat.getColor(context, R.color.grey))
} else {
soundViewHolder.button.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary))
}
}
}
private val soundFilterListener = object : SearchView.OnQueryTextListener {
Expand Down
39 changes: 34 additions & 5 deletions app/src/main/java/fragments/ParameterFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import lufra.youpidapp.DataPersistenceHelper
import lufra.youpidapp.Discotheque
import lufra.youpidapp.MainActivity
import lufra.youpidapp.PlayType
import lufra.youpidapp.R
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat.recreate
import lufra.youpidapp.*

class ParameterFragment: MyFragment() {
private lateinit var context: MainActivity
private lateinit var typeSpinner: Spinner
private lateinit var pitchSeekBar: SeekBar
private lateinit var setDefaultButton: Button
private lateinit var openOnFavoritesCheckBox: CheckBox
private lateinit var themeSpinner: Spinner
override var TAG: String = "=====BOITEFRAGMENT====="

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {
Expand Down Expand Up @@ -53,6 +52,36 @@ class ParameterFragment: MyFragment() {
pitchSeekBar.progress = ((context.discotheque.getDefaultPitch() - 0.5f) * 20f).toInt()
}

themeSpinner = context.findViewById(R.id.theme_spinner)
val nightModeActivated = DataPersistenceHelper.isNightModeActivated()
val theme_spinner_position: Int
if (nightModeActivated) {
themeSpinner.setSelection(1)
theme_spinner_position = 1
} else {
themeSpinner.setSelection(0)
theme_spinner_position = 0
}
val nightMode = AppCompatDelegate.getDefaultNightMode()

//themeSpinner.setSelection()
//AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
themeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {}
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
if (p2 != theme_spinner_position) {
if (p2 == 0) { // DayMode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
DataPersistenceHelper.deactivateNightMode()
} else { // NightMode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
DataPersistenceHelper.activateNightMode()
}
recreate(context);
}
}
}

context.setTitle(R.string.parameters)
}

Expand Down
26 changes: 17 additions & 9 deletions app/src/main/java/lufra/youpidapp/ActionBarButtons.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package lufra.youpidapp

import android.view.Menu
import android.view.MenuItem
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.View
import android.view.*
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
Expand All @@ -19,17 +15,23 @@ class ActionBarButtons(activity: MainActivity) {
private var context: MainActivity = activity

fun addResearch(menu: Menu): MenuItem {
val iconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_baseline_search_24)
val col = ContextCompat.getColor(context, R.color.black)
iconDrawable?.setTint(col)
return menu.add(Menu.NONE, 0, Menu.NONE, R.string.search).apply {
icon = ContextCompat.getDrawable(context, R.drawable.ic_baseline_search_24)
icon = iconDrawable
actionView = SearchView(context)
setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM or MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW)
(actionView as SearchView).maxWidth = Integer.MAX_VALUE
}
}

fun addStop(menu: Menu): MenuItem {
val iconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_baseline_stop_24)
val col = ContextCompat.getColor(context, R.color.black)
iconDrawable?.setTint(col)
return menu.add(Menu.NONE, 1, Menu.NONE, R.string.stop).apply {
icon = ContextCompat.getDrawable(context, R.drawable.ic_baseline_stop_24)
icon = iconDrawable
setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
setOnMenuItemClickListener {
context.discotheque.stopAll()
Expand All @@ -42,8 +44,11 @@ class ActionBarButtons(activity: MainActivity) {
}

fun addParameters(menu: Menu): MenuItem {
val iconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_baseline_settings_24)
val col = ContextCompat.getColor(context, R.color.black)
iconDrawable?.setTint(col)
return menu.add(Menu.NONE, 2, Menu.NONE, R.string.parameters).apply {
icon =ContextCompat.getDrawable(context, R.drawable.ic_baseline_settings_24)
icon = iconDrawable
setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
setOnMenuItemClickListener {
context.openFragment(ParameterFragment::class.java.name)
Expand All @@ -53,8 +58,11 @@ class ActionBarButtons(activity: MainActivity) {
}

fun addTypeLecture(menu: Menu): MenuItem {
val iconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_baseline_playlist_play_24)
val col = ContextCompat.getColor(context, R.color.black)
iconDrawable?.setTint(col)
return menu.add(R.string.type).apply {
icon = ContextCompat.getDrawable(context, R.drawable.ic_baseline_playlist_play_24)
icon = iconDrawable
setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
setOnMenuItemClickListener {
dialogAndSetType()
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/lufra/youpidapp/DataPersistenceHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import android.content.Context
import android.content.SharedPreferences
import android.content.res.Resources
import android.util.Log
import android.widget.Toast
import data.Sound
import org.json.JSONObject
import java.io.File
import java.io.FileReader
import java.io.IOException
import java.util.Properties
import java.util.*

object DataPersistenceHelper {
private const val TAG = "==== HELPER ===="
private const val fileName = "config.properties"
private const val PLAYTYPE = "PlayType"
private const val PITCH = "Pitch"
private const val OPEN_ON_FAVORITES = "OpenOnFavorites"
private const val NIGHTMODE_ACTIVATED = "NightModeActivated"
private lateinit var f: File
private lateinit var youpiDB: MyDatabase

Expand Down Expand Up @@ -111,6 +111,18 @@ object DataPersistenceHelper {
sharedPref.edit().putBoolean(OPEN_ON_FAVORITES, openOnFavorites).apply()
}

fun activateNightMode() {
sharedPref.edit().putBoolean(NIGHTMODE_ACTIVATED, true).apply()
}

fun deactivateNightMode() {
sharedPref.edit().putBoolean(NIGHTMODE_ACTIVATED, false).apply()
}

fun isNightModeActivated() : Boolean {
return sharedPref.getBoolean(NIGHTMODE_ACTIVATED, false)
}
Comment on lines +114 to +124

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'habitude quand il y a un night mode dans les app, il y a pas un mode "système default"?


fun getSounds(): List<Sound> {
val jsonSoundsArray = jsonObj.getJSONArray("sounds")
return (0 until jsonSoundsArray.length()).map { jsonSoundsArray[it] as JSONObject }.map {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/lufra/youpidapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.*
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.Toolbar
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
Expand Down Expand Up @@ -39,6 +40,7 @@ class MainActivity : AppCompatActivity() {
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)

drawerLayout.addDrawerListener(toggle)
toggle.syncState()
toolbar.setTitle(R.string.app_name)
Expand All @@ -49,6 +51,12 @@ class MainActivity : AppCompatActivity() {
discotheque.setType(DataPersistenceHelper.getPreferredPlayType())
discotheque.setPitch(DataPersistenceHelper.getPreferredPitch())

val isNightModeActivated = DataPersistenceHelper.isNightModeActivated()
if (isNightModeActivated) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
// TODO à voir si il faut recreate l'activity ici
}

//NavigationView
navView = this.findViewById(R.id.nav_view)
setDrawer()
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/animator-night/fade.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="backgroundColor"
android:duration="1000"
android:valueFrom="@color/colorPrimaryDark"
android:valueTo="@color/grey"
android:startOffset="0"
android:repeatCount="0" />
18 changes: 18 additions & 0 deletions app/src/main/res/drawable-night/drawer_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
<shape android:shape="rectangle" >
<solid android:color="@color/grey" />
</shape>
</item>

<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="@color/colorPrimary" />
</shape>
</item>
</layer-list>
Binary file added app/src/main/res/drawable/covid_neg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading