From e5b26e8b7bc10c34f9f8ebaaf4c212a97eea3949 Mon Sep 17 00:00:00 2001 From: muhammad Date: Sat, 5 Sep 2020 19:02:58 +0300 Subject: [PATCH] #1407 improvements to audio settings 1.When I play a Surat then I go into settings to chose to play from what Surat to what Surat and I click play only above verses, the audio of the Surat will restart. It really shouldn't have to restart and should just apply the settings and keep playing. It makes it harder for the kids to focus because it repeats when I apply the settings. A. removed the part where audio playback is stopped if playing now it pauses and continues on pressing play if in selected range restarts to new start ayah if not in selected range 2.There should be an option to remember the last selected setting being "play only above verses". I'm always having to manually select it. A.modified 'refreshview()' to read from former used settings which where stored in sharedprefferences on pressing apply button --- app/build.gradle | 1 + .../dao/audio/AudioPlaybackSettings.kt | 12 +++++ .../labs/androidquran/data/Constants.java | 1 + .../androidquran/service/AudioService.java | 9 +--- .../ui/fragment/AyahPlaybackFragment.java | 49 +++++++++++-------- .../labs/androidquran/util/QuranSettings.java | 20 +++++++- build.gradle | 2 +- 7 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/com/quran/labs/androidquran/dao/audio/AudioPlaybackSettings.kt diff --git a/app/build.gradle b/app/build.gradle index ae694e3554..210d10c0c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -172,6 +172,7 @@ dependencies { androidTestImplementation "androidx.test.espresso:espresso-core:${espressoVersion}" androidTestImplementation "androidx.test.espresso:espresso-intents:${espressoVersion}" implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' + implementation 'com.google.code.gson:gson:2.8.6' errorprone 'com.google.errorprone:error_prone_core:2.3.3' //noinspection GradleDynamicVersion diff --git a/app/src/main/java/com/quran/labs/androidquran/dao/audio/AudioPlaybackSettings.kt b/app/src/main/java/com/quran/labs/androidquran/dao/audio/AudioPlaybackSettings.kt new file mode 100644 index 0000000000..365d98c679 --- /dev/null +++ b/app/src/main/java/com/quran/labs/androidquran/dao/audio/AudioPlaybackSettings.kt @@ -0,0 +1,12 @@ +package com.quran.labs.androidquran.dao.audio + +import android.os.Parcelable +import com.quran.data.model.SuraAyah +import kotlinx.android.parcel.Parcelize + +@Parcelize +data class AudioPlaybackSettings(val start: SuraAyah, + val end: SuraAyah, + val verseRepeatCount: Int = 0, + val rangeRepeatCount: Int = 0, + val enforceRange: Boolean = false) : Parcelable diff --git a/app/src/main/java/com/quran/labs/androidquran/data/Constants.java b/app/src/main/java/com/quran/labs/androidquran/data/Constants.java index 04b6462576..2ce9ef1bb7 100644 --- a/app/src/main/java/com/quran/labs/androidquran/data/Constants.java +++ b/app/src/main/java/com/quran/labs/androidquran/data/Constants.java @@ -98,4 +98,5 @@ public class Constants { public static final String PREF_CHECKED_PARTIAL_IMAGES = "didCheckPartialImages"; public static final String PREF_CURRENT_AUDIO_REVISION = "currentAudioRevision"; public static final String PREF_SURA_TRANSLATED_NAME = "suraTranslatedName"; + public static final String PREF_AUDIO_PLAYBACK_SETTINGS = "audioPlaybackSettings"; } diff --git a/app/src/main/java/com/quran/labs/androidquran/service/AudioService.java b/app/src/main/java/com/quran/labs/androidquran/service/AudioService.java index 088ed40e8e..9fb0a5ed5e 100644 --- a/app/src/main/java/com/quran/labs/androidquran/service/AudioService.java +++ b/app/src/main/java/com/quran/labs/androidquran/service/AudioService.java @@ -414,15 +414,8 @@ private void handleIntent(Intent intent) { audioQueue = new AudioQueue(quranInfo, audioRequest, new AudioPlaybackInfo(start, 1, 1, basmallah)); Crashlytics.log("audio request has changed..."); - - if (player != null) { - player.stop(); - } - state = State.Stopped; - Crashlytics.log("stop if playing..."); } - - processTogglePlaybackRequest(); + processTogglePlaybackRequest(); } else if (ACTION_PLAY.equals(action)) { processPlayRequest(); } else if (ACTION_PAUSE.equals(action)) { diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahPlaybackFragment.java b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahPlaybackFragment.java index e84331327a..82c3afb767 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahPlaybackFragment.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/AyahPlaybackFragment.java @@ -14,10 +14,12 @@ import com.quran.data.core.QuranInfo; import com.quran.labs.androidquran.QuranApplication; import com.quran.labs.androidquran.R; +import com.quran.labs.androidquran.dao.audio.AudioPlaybackSettings; import com.quran.labs.androidquran.dao.audio.AudioRequest; import com.quran.data.model.SuraAyah; import com.quran.labs.androidquran.ui.PagerActivity; import com.quran.labs.androidquran.ui.helpers.HighlightType; +import com.quran.labs.androidquran.util.QuranSettings; import com.quran.labs.androidquran.util.QuranUtils; import com.quran.labs.androidquran.widgets.QuranSpinner; @@ -45,7 +47,10 @@ public class AyahPlaybackFragment extends AyahActionFragment { private ArrayAdapter startAyahAdapter; private ArrayAdapter endingAyahAdapter; - @Inject QuranInfo quranInfo; + @Inject + QuranInfo quranInfo; + @Inject + QuranSettings quranSettings; @Override public View onCreateView(LayoutInflater inflater, @@ -78,15 +83,15 @@ public View onCreateView(LayoutInflater inflater, repeatRangeSpinner.setAdapter(rangeAdapter); repeatRangeSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - updateEnforceBounds(position); - } + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + updateEnforceBounds(position); + } - @Override - public void onNothingSelected(AdapterView parent) { - } - }); + @Override + public void onNothingSelected(AdapterView parent) { + } + }); final ArrayAdapter verseAdapter = new ArrayAdapter<>(context, ITEM_LAYOUT, repeatOptions); verseAdapter.setDropDownViewResource( @@ -169,7 +174,12 @@ private void apply() { if (updatedRange) { pagerActivity.toggleActionBarVisibility(true); } + AudioPlaybackSettings lastAudioSettings = + new AudioPlaybackSettings(currentStart, currentEnding, verseRepeat, rangeRepeat, + enforceRange); + quranSettings.setLastAudioSettings(lastAudioSettings); } + } private void initializeSuraSpinner(final Context context, @@ -177,7 +187,7 @@ private void initializeSuraSpinner(final Context context, final ArrayAdapter ayahAdapter) { String[] suras = context.getResources(). getStringArray(R.array.sura_names); - for (int i=0; i parent, View view, int position, long int sura = position + 1; int ayahCount = quranInfo.getNumberOfAyahs(sura); CharSequence[] ayahs = new String[ayahCount]; - for (int i = 0; i < ayahCount; i++){ + for (int i = 0; i < ayahCount; i++) { ayahs[i] = QuranUtils.getLocalizedNumber(context, (i + 1)); } ayahAdapter.clear(); - for (int i=0; i