- Now the user configured received funds sounds gets played instead of woohoo default sound

This commit is contained in:
Javier Varona 2018-05-02 20:41:44 -04:00
parent 4276fd0e7c
commit 2f37534bc2
3 changed files with 47 additions and 5 deletions

View file

@ -86,7 +86,7 @@ public class CrystalApplication extends Application {
}
//The crystal notifier is initialized
CrystalWalletNotifier crystalWalletNotifier = new CrystalWalletNotifier(getApplicationContext());
CrystalWalletNotifier crystalWalletNotifier = new CrystalWalletNotifier(this);
CryptoNetEvents.getInstance().addListener(crystalWalletNotifier);
//Next line is for use the bitshares main net

View file

@ -1,12 +1,18 @@
package cy.agorise.crystalwallet.notifiers;
import android.app.Application;
import android.content.Context;
import android.media.MediaPlayer;
import java.io.File;
import java.io.IOException;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetEvent;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetEventsListener;
import cy.agorise.crystalwallet.requestmanagers.ReceivedFundsCryptoNetEvent;
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;
/**
* Created by Henry Varona on 29/4/2018.
@ -15,9 +21,42 @@ import cy.agorise.crystalwallet.requestmanagers.ReceivedFundsCryptoNetEvent;
public class CrystalWalletNotifier implements CryptoNetEventsListener{
private Context context;
private MediaPlayer receivedFundsMediaPlayer;
private Application application;
public CrystalWalletNotifier(Context context){
this.context = context;
public CrystalWalletNotifier(Application application){
this.context = application.getApplicationContext();
this.application = application;
loadReceivedFundsSound();
}
public void loadReceivedFundsSound(){
GeneralSettingListViewModel generalSettingListViewModel = new GeneralSettingListViewModel(this.application);
GeneralSetting receivedFundsSoundGeneralSetting = generalSettingListViewModel.getGeneralSettingByName(GeneralSetting.SETTING_NAME_RECEIVED_FUNDS_SOUND_PATH);
File receivedFundsSoundFile = null;
if ((receivedFundsSoundGeneralSetting != null)){
if (!receivedFundsSoundGeneralSetting.getValue().equals("")) {
receivedFundsSoundFile = new File(receivedFundsSoundGeneralSetting.getValue());
if (!receivedFundsSoundFile.exists()){
receivedFundsSoundFile = null;
}
}
}
if (receivedFundsSoundFile != null){
receivedFundsMediaPlayer = new MediaPlayer();
try {
receivedFundsMediaPlayer.setDataSource(receivedFundsSoundGeneralSetting.getValue());
receivedFundsMediaPlayer.prepare();
} catch (IOException e) {
receivedFundsMediaPlayer = MediaPlayer.create(this.context, R.raw.woohoo);
}
} else {
receivedFundsMediaPlayer = MediaPlayer.create(this.context, R.raw.woohoo);
}
}
public void onCryptoNetEvent(CryptoNetEvent event) {
@ -27,7 +66,6 @@ public class CrystalWalletNotifier implements CryptoNetEventsListener{
}
private void playReceivedFundsSound() {
MediaPlayer defaultMediaPlayer = MediaPlayer.create(this.context, R.raw.woohoo);
defaultMediaPlayer.start();
receivedFundsMediaPlayer.start();
}
}

View file

@ -41,4 +41,8 @@ public class GeneralSettingListViewModel extends AndroidViewModel {
public GeneralSetting getGeneralSettingByName(String name){
return this.db.generalSettingDao().getSettingByName(name);
}
public LiveData<GeneralSetting> getGeneralSettingLiveDataByName(String name){
return this.db.generalSettingDao().getByName(name);
}
}