mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-16 11:11:41 +00:00
fix audio playback issue. Fixes #701
This commit is contained in:
parent
33f1e4c22d
commit
a30dc2e12a
4 changed files with 24 additions and 13 deletions
|
|
@ -75,6 +75,7 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.media.Image;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
|
@ -126,6 +127,9 @@ public class APIHelper implements Action1<Throwable> {
|
|||
@Inject
|
||||
CrashlyticsProxy crashlyticsProxy;
|
||||
|
||||
@Inject
|
||||
Context context;
|
||||
|
||||
// I think we don't need the APIHelper anymore we could just use ApiService
|
||||
public final ApiService apiService;
|
||||
final Observable.Transformer apiCallTransformer =
|
||||
|
|
@ -133,7 +137,7 @@ public class APIHelper implements Action1<Throwable> {
|
|||
.map(new Func1<HabitResponse, Object>() {
|
||||
@Override public Object call(HabitResponse habitResponse) {
|
||||
if (habitResponse.notifications != null) {
|
||||
PopupNotificationsManager popupNotificationsManager = PopupNotificationsManager.getInstance(APIHelper.this);
|
||||
PopupNotificationsManager popupNotificationsManager = PopupNotificationsManager.getInstance(APIHelper.this, context);
|
||||
popupNotificationsManager.showNotificationDialog(habitResponse.notifications);
|
||||
}
|
||||
return habitResponse.getData();
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ public class PopupNotificationsManager {
|
|||
|
||||
// @TODO: A queue for displaying alert dialogues
|
||||
|
||||
private PopupNotificationsManager(APIHelper apiHelper) {
|
||||
private PopupNotificationsManager(APIHelper apiHelper, Context context) {
|
||||
this.apiHelper = apiHelper;
|
||||
this.seenNotifications = new HashMap<>();
|
||||
context.getApplicationContext();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public static PopupNotificationsManager getInstance(APIHelper apiHelper) {
|
||||
public static PopupNotificationsManager getInstance(APIHelper apiHelper, Context context) {
|
||||
if (instance == null) {
|
||||
instance = new PopupNotificationsManager(apiHelper);
|
||||
instance = new PopupNotificationsManager(apiHelper, context);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,24 @@ package com.habitrpg.android.habitica.helpers;
|
|||
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SoundFile {
|
||||
public class SoundFile implements MediaPlayer.OnCompletionListener {
|
||||
private String theme;
|
||||
private String fileName;
|
||||
private File file;
|
||||
private MediaPlayer mp;
|
||||
private Boolean playerPrepared = false;
|
||||
private boolean isPlaying;
|
||||
|
||||
public SoundFile(String theme, String fileName){
|
||||
|
||||
this.theme = theme;
|
||||
this.fileName = fileName;
|
||||
mp = new MediaPlayer();
|
||||
mp.setOnCompletionListener(this);
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
|
|
@ -65,11 +68,16 @@ public class SoundFile {
|
|||
}
|
||||
|
||||
public void play(){
|
||||
prepareMediaPlayer();
|
||||
if(mp.isPlaying()) {
|
||||
mp.stop();
|
||||
if(isPlaying) {
|
||||
return;
|
||||
}
|
||||
|
||||
prepareMediaPlayer();
|
||||
isPlaying = true;
|
||||
mp.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mediaPlayer) {
|
||||
isPlaying = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class SoundManager {
|
|||
}
|
||||
|
||||
public Observable<List<SoundFile>> preloadAllFiles() {
|
||||
if(soundTheme == "off") {
|
||||
if(soundTheme.equals("off")) {
|
||||
return Observable.empty();
|
||||
}
|
||||
|
||||
|
|
@ -71,8 +71,7 @@ public class SoundManager {
|
|||
}
|
||||
|
||||
public void loadAndPlayAudio(String type){
|
||||
if(soundTheme == "off")
|
||||
{
|
||||
if(soundTheme.equals("off")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue