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

Switch the audio toolbar to loading on play #1116

Merged
merged 1 commit into from
Mar 21, 2019
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
Expand Up @@ -1224,8 +1224,8 @@ public void handleDownloadTemporaryError(int errorId) {
@Override
public void handleDownloadSuccess() {
refreshQuranPages();
audioPresenter.onDownloadSuccess();
audioStatusBar.switchMode(AudioStatusBar.STOPPED_MODE);
audioPresenter.onDownloadSuccess();
}

@Override
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1595,6 +1596,7 @@ public void onCancelPressed(boolean cancelDownload) {
startService(i);
} else {
audioStatusBar.switchMode(AudioStatusBar.STOPPED_MODE);
startService(audioUtils.getAudioIntent(this, AudioService.ACTION_STOP));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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:
Expand Down