diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/PagerActivity.java b/app/src/main/java/com/quran/labs/androidquran/ui/PagerActivity.java index f0f6a38326..78db469d67 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/PagerActivity.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/PagerActivity.java @@ -1224,8 +1224,8 @@ public void handleDownloadTemporaryError(int errorId) { @Override public void handleDownloadSuccess() { refreshQuranPages(); - audioPresenter.onDownloadSuccess(); audioStatusBar.switchMode(AudioStatusBar.STOPPED_MODE); + audioPresenter.onDownloadSuccess(); } @Override @@ -1491,6 +1491,7 @@ public void handlePlayback(AudioRequest request) { i.putExtra(AudioService.EXTRA_PLAY_INFO, request); lastAudioRequest = request; audioStatusBar.setRepeatCount(request.getRepeatInfo()); + audioStatusBar.switchMode(AudioStatusBar.LOADING_MODE); } Crashlytics.log("starting foreground service for audio playback"); @@ -1595,6 +1596,7 @@ public void onCancelPressed(boolean cancelDownload) { startService(i); } else { audioStatusBar.switchMode(AudioStatusBar.STOPPED_MODE); + startService(audioUtils.getAudioIntent(this, AudioService.ACTION_STOP)); } } diff --git a/app/src/main/java/com/quran/labs/androidquran/widgets/AudioStatusBar.java b/app/src/main/java/com/quran/labs/androidquran/widgets/AudioStatusBar.java index 5669c863d6..6bafeea5a5 100644 --- a/app/src/main/java/com/quran/labs/androidquran/widgets/AudioStatusBar.java +++ b/app/src/main/java/com/quran/labs/androidquran/widgets/AudioStatusBar.java @@ -31,15 +31,17 @@ import androidx.annotation.DrawableRes; import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; +import androidx.annotation.StringRes; import androidx.core.view.ViewCompat; public class AudioStatusBar extends LeftToRightLinearLayout { public static final int STOPPED_MODE = 1; public static final int DOWNLOADING_MODE = 2; - public static final int PLAYING_MODE = 3; - public static final int PAUSED_MODE = 4; - public static final int PROMPT_DOWNLOAD_MODE = 5; + public static final int LOADING_MODE = 3; + public static final int PLAYING_MODE = 4; + public static final int PAUSED_MODE = 5; + public static final int PROMPT_DOWNLOAD_MODE = 6; private Context context; private int currentMode; @@ -160,8 +162,8 @@ public void switchMode(int mode) { showStoppedMode(); } else if (mode == PROMPT_DOWNLOAD_MODE) { showPromptForDownloadMode(); - } else if (mode == DOWNLOADING_MODE) { - showDownloadingMode(); + } else if (mode == DOWNLOADING_MODE || mode == LOADING_MODE) { + showProgress(mode); } else if (mode == PLAYING_MODE) { showPlayingMode(false); } else { @@ -348,23 +350,24 @@ private void addDownloadOver3gPrompt() { addView(mPromptText, params); } - private void showDownloadingMode() { - currentMode = DOWNLOADING_MODE; + private void showProgress(int mode) { + currentMode = mode; removeAllViews(); + final int text = mode == DOWNLOADING_MODE ? R.string.downloading_title : R.string.index_loading; if (isRtl) { - addDownloadProgress(); + addDownloadProgress(text); addSeparator(); addButton(R.drawable.ic_cancel, false); } else { addButton(R.drawable.ic_cancel, false); addSeparator(); - addDownloadProgress(); + addDownloadProgress(text); } } - private void addDownloadProgress() { + private void addDownloadProgress(@StringRes int text) { LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); @@ -380,7 +383,7 @@ private void addDownloadProgress() { progressText.setTextColor(Color.WHITE); progressText.setGravity(Gravity.CENTER_VERTICAL); progressText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textFontSize); - progressText.setText(R.string.downloading_title); + progressText.setText(text); ll.addView(progressText, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); @@ -525,7 +528,7 @@ public void onClick(View view) { haveCriticalError = false; switchMode(STOPPED_MODE); } else { - audioBarListener.onCancelPressed(currentMode != PROMPT_DOWNLOAD_MODE); + audioBarListener.onCancelPressed(currentMode == DOWNLOADING_MODE); } break; case R.drawable.ic_accept: