- Added CryptoNetEvents fired from Service classes

This commit is contained in:
Javier Varona 2018-04-28 21:38:35 -04:00
parent df60afb203
commit 4135217548
4 changed files with 112 additions and 0 deletions

View file

@ -0,0 +1,21 @@
package cy.agorise.crystalwallet.requestmanagers;
import cy.agorise.crystalwallet.enums.CryptoCoin;
/**
* An event fired from the service
*
*
* Created by Henry Varona on 4/28/2018.
*/
public abstract class CryptoNetEvent {
/**
* The cryptocoin this events belongs to
*/
protected CryptoCoin coin;
protected CryptoNetEvent(CryptoCoin coin){
this.coin = coin;
}
}

View file

@ -0,0 +1,48 @@
package cy.agorise.crystalwallet.requestmanagers;
import java.util.ArrayList;
import java.util.List;
/**
* This class will be used to communicate events related to crypto net accounts data
*
* Created by Henry Varona on 4/28/2018.
*/
public class CryptoNetEvents {
private List<CryptoNetEventsListener> listeners;
private static CryptoNetEvents instance;
/**
* Private constructor for singleton pattern
*/
private void CryptoNetEvents(){
}
/**
* Gets an instance of this manager
* @return the instance to manage the cryptonetinforequest
*/
public static CryptoNetEvents getInstance(){
if (CryptoNetEvents.instance == null){
CryptoNetEvents.instance = new CryptoNetEvents();
CryptoNetEvents.instance.listeners = new ArrayList<>();
}
return CryptoNetEvents.instance;
}
public void fireEvent(CryptoNetEvent event){
for (int i=0;i<this.listeners.size();i++){
this.listeners.get(i).onCryptoNetEvent(event);
}
}
public void removeListener(CryptoNetEventsListener listener){
this.listeners.remove(listener);
}
public void addListener(CryptoNetEventsListener listener){
this.listeners.add(listener);
}
}

View file

@ -0,0 +1,11 @@
package cy.agorise.crystalwallet.requestmanagers;
/**
* Service Events Listener
* Created by Henry Varona on 4/28/2018.
*/
public interface CryptoNetEventsListener {
public void onCryptoNetEvent(CryptoNetEvent event);
}

View file

@ -0,0 +1,32 @@
package cy.agorise.crystalwallet.requestmanagers;
import android.content.Context;
import cy.agorise.crystalwallet.enums.CryptoCoin;
import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
/**
* This event gets fired when a user crypto net account receives funds
*
* Created by henry on 4/28/2018.
*/
public class ReceivedFundsCryptoNetEvent extends CryptoNetEvent {
private CryptoNetAccount account;
public ReceivedFundsCryptoNetEvent(CryptoCoin coin, CryptoNetAccount account) {
super(coin);
this.account = account;
}
public CryptoNetAccount getAccount() {
return this.account;
}
public void setAccount(CryptoNetAccount account) {
this.account = account;
}
}