Skip to content

Commit

Permalink
IMPLEMENTATION: #6394 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
josejcb committed Jul 22, 2016
1 parent 8cb8211 commit 3a9a5e7
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand All @@ -17,26 +18,34 @@
import com.bitdubai.fermat_android_api.ui.enums.FermatRefreshTypes;
import com.bitdubai.fermat_android_api.ui.fragments.FermatListFragment;
import com.bitdubai.fermat_android_api.ui.interfaces.FermatListItemListeners;
import com.bitdubai.fermat_android_api.ui.interfaces.FermatWorkerCallBack;
import com.bitdubai.fermat_android_api.ui.util.FermatWorker;
import com.bitdubai.fermat_api.FermatBroadcastReceiver;
import com.bitdubai.fermat_api.FermatException;
import com.bitdubai.fermat_api.FermatIntentFilter;
import com.bitdubai.fermat_api.layer.all_definition.common.system.interfaces.error_manager.enums.UnexpectedSubAppExceptionSeverity;
import com.bitdubai.fermat_api.layer.all_definition.common.system.interfaces.error_manager.enums.UnexpectedUIExceptionSeverity;
import com.bitdubai.fermat_api.layer.all_definition.enums.UISource;
import com.bitdubai.fermat_api.layer.all_definition.navigation_structure.enums.Activities;
import com.bitdubai.fermat_api.layer.dmp_engine.sub_app_runtime.enums.SubApps;
import com.bitdubai.fermat_api.layer.osa_android.broadcaster.Broadcaster;
import com.bitdubai.fermat_api.layer.osa_android.broadcaster.BroadcasterType;
import com.bitdubai.fermat_api.layer.osa_android.broadcaster.FermatBundle;
import com.bitdubai.fermat_cbp_api.all_definition.constants.CBPBroadcasterConstants;
import com.bitdubai.fermat_cbp_api.layer.identity.crypto_customer.exceptions.CantListCryptoCustomerIdentityException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.IdentityBrokerPreferenceSettings;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.exceptions.CantListCryptoBrokersException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.interfaces.CryptoBrokerIdentityInformation;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.interfaces.CryptoBrokerIdentityModuleManager;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.exceptions.CantGetCryptoCustomerListException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.interfaces.CryptoCustomerIdentityInformation;
import com.bitdubai.sub_app.crypto_broker_identity.R;
import com.bitdubai.sub_app.crypto_broker_identity.common.adapters.CryptoBrokerIdentityInfoAdapter;
import com.bitdubai.sub_app.crypto_broker_identity.util.FragmentsCommons;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;

import static android.widget.Toast.makeText;

Expand All @@ -53,7 +62,9 @@ public class CryptoBrokerIdentityListFragment

// Data
private ArrayList<CryptoBrokerIdentityInformation> identityInformationList;
private List<CryptoCustomerIdentityInformation> identityCustomerInformationList;

private ExecutorService executor;
View emptyListViewsContainer;

private PresentationDialog presentationDialog;
Expand All @@ -80,6 +91,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onStart() {
super.onStart();
onRefreshCustomer();
onRefresh();
}

Expand Down Expand Up @@ -274,6 +286,85 @@ private void cleanSessionData() {
appSession.removeData(FragmentsCommons.ORIGINAL_IMAGE);
}

/**
* Checking if a customer profile is already created before a broker is created
*/
public void onRefreshCustomer() {
try{
final FermatWorker worker = new FermatWorker() {
@Override
protected Object doInBackground() throws Exception {
return getMoreDataAsyncCustomer();
}
};
worker.setContext(getActivity());
worker.setCallBack(new FermatWorkerCallBack() {
@SuppressWarnings("unchecked")
@Override
public void onPostExecute(Object... result) {
if (isAttached) {
if (result != null &&
result.length > 0) {
if (getActivity() != null) {
existentCustomerIdentityDialog();
}
}
}
}

@Override
public void onErrorOccurred(Exception ex) {
try{
worker.shutdownNow();
} catch (Exception e) {
e.printStackTrace();
}
}
});
worker.execute();
}catch (Exception ignore){
if (executor != null) {
executor.shutdown();
executor = null;
}
}
}

public void existentCustomerIdentityDialog() {
try {
PresentationDialog pd = new PresentationDialog.Builder(getActivity(), appSession)
.setSubTitle(R.string.cbp_broker_identity_welcome_subTitle)
.setBody(R.string.cbp_broker_identity_existent_customer)
.setTemplateType(PresentationDialog.TemplateType.TYPE_PRESENTATION_WITHOUT_IDENTITIES)
.setIconRes(R.drawable.bi_icon)
.setCheckButtonAndTextVisible(0)
.setIsCheckEnabled(false)
.setBannerRes(R.drawable.banner_identity)
.setVIewColor(R.color.background_toolbar)
.build();
pd.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
getActivity().onBackPressed();
}
});
pd.show();
} catch (Exception e) {
e.printStackTrace();
}
}

public List<CryptoCustomerIdentityInformation> getMoreDataAsyncCustomer() {
List<CryptoCustomerIdentityInformation> data = new ArrayList<>();
try {
data = appSession.getModuleManager().getAllCryptoCustomersIdentities(0, 0);
} catch (CantGetCryptoCustomerListException ex) {
appSession.getErrorManager().reportUnexpectedSubAppException(SubApps.CBP_CRYPTO_BROKER_IDENTITY,
UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT, ex);
}
return data;
}

/**
* Receiver class implemented
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<string name="cbp_broker_identity_welcome_subTitle">Welcome to the Broker Identity.</string>
<string name="cbp_broker_identity_welcome_body">From here you will be able to create an Broker type identity.\n\nThis Identity, will identify you in the system as an broker, and give you access to all tasks and applications you need.\n\nOther broker or customer will be able to request connection to you by finding you with the information you provide here.</string>
<string name="cbp_broker_identity_gps">Please, turn on your GPS to register your location, then others can find you and you can find peers near to you.</string>
<string name="cbp_broker_identity_existent_customer">You already have a profile on this platform as Customer. For instance, this app will be closed since it is not allowed to create a Broker profile too.</string>
<string name="cbi_accuracy_km">Accuracy (Km)</string>
<string name="cbi_accuracy_hint">0 - 1000</string>
<string name="cbi_frequency">Frequency</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@


import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -22,10 +21,14 @@
import com.bitdubai.fermat_android_api.ui.enums.FermatRefreshTypes;
import com.bitdubai.fermat_android_api.ui.fragments.FermatListFragment;
import com.bitdubai.fermat_android_api.ui.interfaces.FermatListItemListeners;
import com.bitdubai.fermat_android_api.ui.interfaces.FermatWorkerCallBack;
import com.bitdubai.fermat_android_api.ui.util.FermatWorker;
import com.bitdubai.fermat_api.FermatException;
import com.bitdubai.fermat_api.layer.all_definition.common.system.interfaces.error_manager.enums.UnexpectedSubAppExceptionSeverity;
import com.bitdubai.fermat_api.layer.all_definition.navigation_structure.enums.Activities;
import com.bitdubai.fermat_api.layer.dmp_engine.sub_app_runtime.enums.SubApps;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.exceptions.CantListCryptoBrokersException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.interfaces.CryptoBrokerIdentityInformation;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.IdentityCustomerPreferenceSettings;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.exceptions.CantGetCryptoCustomerListException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.interfaces.CryptoCustomerIdentityInformation;
Expand All @@ -37,6 +40,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;

import static android.widget.Toast.makeText;

Expand All @@ -58,6 +62,7 @@ public class CryptoCustomerIdentityListFragment
private CryptoCustomerIdentityListFilter filter;
private PresentationDialog presentationDialog;

private ExecutorService executor;
private View layout;

public static CryptoCustomerIdentityListFragment newInstance() {
Expand All @@ -67,9 +72,8 @@ public static CryptoCustomerIdentityListFragment newInstance() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

onRefreshBroker();
cleanSessionData();

onRefresh();
}

Expand Down Expand Up @@ -291,4 +295,82 @@ private void cleanSessionData() {
if (appSession.getData(FragmentsCommons.ORIGINAL_IMAGE) != null)
appSession.removeData(FragmentsCommons.ORIGINAL_IMAGE);
}

/**
* Checking if a broker profile is already created before a customer is created
*/
public void onRefreshBroker() {
try{
final FermatWorker worker = new FermatWorker() {
@Override
protected Object doInBackground() throws Exception {
return getMoreDataAsyncBroker();
}
};
worker.setContext(getActivity());
worker.setCallBack(new FermatWorkerCallBack() {
@SuppressWarnings("unchecked")
@Override
public void onPostExecute(Object... result) {
if (isAttached) {
if (result != null &&
result.length > 0) {
if (getActivity() != null) {
existentBrokerIdentityDialog();
}
}
}
}

@Override
public void onErrorOccurred(Exception ex) {
try{
worker.shutdownNow();
} catch (Exception e) {
e.printStackTrace();
}
}
});
worker.execute();
}catch (Exception ignore){
if (executor != null) {
executor.shutdown();
executor = null;
}
}
}

public void existentBrokerIdentityDialog() {
try {
PresentationDialog pd = new PresentationDialog.Builder(getActivity(), appSession)
.setSubTitle(R.string.cbp_customer_identity_welcome_subTitle)
.setBody(R.string.cbp_customer_identity_existent_broker)
.setTemplateType(PresentationDialog.TemplateType.TYPE_PRESENTATION_WITHOUT_IDENTITIES)
.setCheckButtonAndTextVisible(0)
.setIsCheckEnabled(false)
.setBannerRes(R.drawable.banner_identity_customer)
.setVIewColor(R.color.ccc_color_dialog_identity)
.build();
pd.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
getActivity().onBackPressed();
}
});
pd.show();
} catch (Exception e) {
e.printStackTrace();
}
}

public List<CryptoBrokerIdentityInformation> getMoreDataAsyncBroker() {
List<CryptoBrokerIdentityInformation> data = new ArrayList<>();
try {
data = appSession.getModuleManager().listIdentities(0, 0);
} catch (CantListCryptoBrokersException ex) {
appSession.getErrorManager().reportUnexpectedSubAppException(SubApps.CBP_CRYPTO_CUSTOMER_IDENTITY,
UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT, ex);
}
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="cbp_customer_identity_welcome_subTitle">Welcome to the Customer Identity.</string>
<string name="cbp_customer_identity_welcome_body">From here you will be able to create an Customer type identity.\n\nThis Identity, will identify you in the system as an Customer, and give you access to all tasks and applications you need.\n\nOther broker or customer will be able to request connection to you by finding you with the information you provide here.</string>
<string name="cbp_customer_identity_gps">Please, turn on your GPS to register your location, then others can find you and you can find peers near to you.</string>
<string name="cbp_customer_identity_existent_broker">You already have a profile on this platform as Broker. For instance, this app will be closed since it is not allowed to create a Customer profile too.</string>
<string name="cci_accuracy_km">Accuracy (Km)</string>
<string name="cci_accuracy_hint">0 - 1000</string>
<string name="cci_frequency">Frequency</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.exceptions.CantPublishCryptoBrokerException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.exceptions.CantUnHideCryptoBrokerException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.exceptions.CryptoBrokerNotFoundException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.interfaces.CryptoCustomerIdentityInformation;

import java.io.Serializable;
import java.util.List;
Expand All @@ -27,6 +28,14 @@
public interface CryptoBrokerIdentityModuleManager extends ModuleManager<IdentityBrokerPreferenceSettings, ActiveActorIdentityInformation>,
ModuleSettingsImpl<IdentityBrokerPreferenceSettings>, Serializable {


/**
* The method <code>getAllCryptoCustomerIdentities</code> returns the list of all crypto Customer
*
* @return the list of crypto Customer
* @throws com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.exceptions.CantGetCryptoCustomerListException
*/
List<CryptoCustomerIdentityInformation> getAllCryptoCustomersIdentities(int max, int offset) throws com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.exceptions.CantGetCryptoCustomerListException;
/**
* The method <code>createCryptoBrokerIdentity</code> is used to create a new crypto Broker identity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.bitdubai.fermat_api.layer.osa_android.location_system.exceptions.CantGetDeviceLocationException;
import com.bitdubai.fermat_api.layer.all_definition.enums.GeoFrequency;
import com.bitdubai.fermat_cbp_api.layer.identity.crypto_broker.exceptions.CantUpdateCustomerIdentityException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.exceptions.CantListCryptoBrokersException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.exceptions.CantPublishCryptoBrokerException;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.interfaces.CryptoBrokerIdentityInformation;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.IdentityCustomerPreferenceSettings;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_customer_identity.exceptions.CouldNotPublishCryptoCustomerException;

Expand All @@ -26,6 +28,13 @@
public interface CryptoCustomerIdentityModuleManager extends ModuleManager<IdentityCustomerPreferenceSettings, ActiveActorIdentityInformation>,
ModuleSettingsImpl<IdentityCustomerPreferenceSettings>, Serializable {

/**
* The method <code>listIdentities</code> returns the list of all crypto Broker published
*
* @return the list of crypto Broker published
* @throws CantListCryptoBrokersException if something goes wrong.
*/
List<CryptoBrokerIdentityInformation> listIdentities(int max, int offset) throws CantListCryptoBrokersException;
/**
* The method <code>createCryptoCustomerIdentity</code> is used to create a new crypto Customer identity
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.bitdubai.fermat_api.layer.osa_android.file_system.PluginFileSystem;
import com.bitdubai.fermat_api.layer.osa_android.location_system.LocationManager;
import com.bitdubai.fermat_cbp_api.layer.identity.crypto_broker.interfaces.CryptoBrokerIdentityManager;
import com.bitdubai.fermat_cbp_api.layer.identity.crypto_customer.interfaces.CryptoCustomerIdentityManager;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.IdentityBrokerPreferenceSettings;
import com.bitdubai.fermat_cbp_api.layer.sub_app_module.crypto_broker_identity.interfaces.CryptoBrokerIdentityModuleManager;
import com.bitdubai.fermat_cbp_plugin.layer.sub_app_module.crypto_broker_identity.developer.bitdubai.version_1.structure.CryptoBrokerIdentityModuleManagerImpl;
Expand All @@ -32,6 +33,9 @@ public class CryptoBrokerIdentitySubAppModulePluginRoot extends AbstractModule<I
@NeededPluginReference(platform = Platforms.CRYPTO_BROKER_PLATFORM, layer = Layers.IDENTITY, plugin = Plugins.CRYPTO_BROKER)
CryptoBrokerIdentityManager identityManager;

@NeededPluginReference(platform = Platforms.CRYPTO_BROKER_PLATFORM, layer = Layers.IDENTITY, plugin = Plugins.CRYPTO_CUSTOMER)
CryptoCustomerIdentityManager customerIdentityManager;

@NeededAddonReference(platform = Platforms.OPERATIVE_SYSTEM_API, layer = Layers.SYSTEM, addon = Addons.PLUGIN_FILE_SYSTEM)
PluginFileSystem pluginFileSystem;

Expand All @@ -53,7 +57,8 @@ public CryptoBrokerIdentityModuleManager getModuleManager() throws CantGetModule
pluginFileSystem,
pluginId,
this,
locationManager
locationManager,
customerIdentityManager
);

this.serviceStatus = ServiceStatus.STARTED;
Expand Down
Loading

0 comments on commit 3a9a5e7

Please sign in to comment.