Skip to content

Commit

Permalink
Switch the audio toolbar to loading on play (#1116)
Browse files Browse the repository at this point in the history
Because streaming sometimes takes a while to take effect, people who
were trying to stream audio would often think nothing was happening
since there was no ui change. This patch updates it to show a loading
mode until the audio file begins to play.
  • Loading branch information
ahmedre authored Mar 21, 2019
1 parent a02538c commit f7aad64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
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

0 comments on commit f7aad64

Please sign in to comment.