@Override
  public NotificationPainter getNotificationPainter(FermatBundle fermatBundle) {
    try {
      LossProtectedWalletSettings lossProtectedWalletSettings;
      int notificationID = fermatBundle.getInt(NotificationBundleConstants.NOTIFICATION_ID);
      String involvedActor = fermatBundle.getString("InvolvedActor");
      long amount = Long.parseLong(String.valueOf(fermatBundle.get("Amount")));

      boolean enabledNotification = true;
      this.lossWalletSession = this.getFullyLoadedSession();
      if (lossWalletSession != null) {
        String walletPublicKey = lossWalletSession.getAppPublicKey();
        if (lossWalletSession.getModuleManager() != null) {
          moduleManager = lossWalletSession.getModuleManager();

          // enable notification settings

          lossProtectedWalletSettings = moduleManager.loadAndGetSettings(walletPublicKey);
          enabledNotification = lossProtectedWalletSettings.getNotificationEnabled();
        }

        if (enabledNotification)
          return LossProtectedWalletBuildNotificationPainter.getNotification(
              notificationID,
              involvedActor,
              amount,
              Activities.CWP_WALLET_RUNTIME_WALLET_LOSS_PROTECTED_WALLET_BITDUBAI_VERSION_1_MAIN
                  .getCode());
        else
          return new LossProtectedWalletNotificationPainter(
              "",
              "",
              "",
              "",
              false,
              Activities.CWP_WALLET_RUNTIME_WALLET_LOSS_PROTECTED_WALLET_BITDUBAI_VERSION_1_MAIN
                  .getCode());

      } else return null;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Ejemplo n.º 2
0
  // Store instance variables based on arguments passed
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {

      fermatWalletManager = fermatSession.getModuleManager();
      errorManager = fermatSession.getErrorManager();

      page = getArguments().getInt("someInt", 0);
      providerName = getArguments().getString("providerName");
      providerId = UUID.fromString(getArguments().getString("providerId"));

      if (fermatSession.getData(SessionConstant.FIAT_CURRENCY) != null)
        fiatCurrency = (String) fermatSession.getData(SessionConstant.FIAT_CURRENCY);
      else fiatCurrency = FiatCurrency.US_DOLLAR.getCode();

      getAndShowMarketExchangeRateData();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  public void onClick(View v) {
    int i = v.getId();
    if (i == R.id.cancel_btn) {
      // activity.finish();
      dismiss();
    } else if (i == R.id.accept_btn) {
      try {

        lossProtectedWallet.send(
            cryptoAmount,
            destinationAddress,
            notes,
            appSession.getAppPublicKey(),
            lossProtectedWallet.getSelectedActorIdentity().getPublicKey(),
            Actors.INTRA_USER,
            deliveredByActorPublicKey,
            deliveredByActorType,
            ReferenceWallet.BASIC_WALLET_BITCOIN_WALLET,
            blockchainNetworkType,
            CryptoCurrency.BITCOIN,
            fee,
            feeOrigin);
      } catch (CantSendLossProtectedCryptoException e) {
        e.printStackTrace();
        Toast.makeText(this.activity, "Unexpected error", Toast.LENGTH_SHORT).show();
      } catch (LossProtectedInsufficientFundsException e) {
        e.printStackTrace();
        Toast.makeText(this.activity, "Not enough funds to perform action", Toast.LENGTH_SHORT)
            .show();
        /*    } catch (CantGetLossProtectedBalanceException e) {
                Toast.makeText(this.activity, "Unexpected error", Toast.LENGTH_SHORT).show();
        */ } catch (Exception e) {
        Toast.makeText(
                activity.getApplicationContext(),
                "oooopps, we have a problem here",
                Toast.LENGTH_SHORT)
            .show();
        e.printStackTrace();
      }

      Toast.makeText(this.activity, "Sending...", Toast.LENGTH_SHORT).show();
      dismiss();
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {

      _executor = Executors.newFixedThreadPool(2);

      setHasOptionsMenu(true);
      // setting up  module

      moduleManager = appSession.getModuleManager();
      errorManager = appSession.getErrorManager();

      intraUserSubAppSession = appSession;

      try {
        intraUserWalletSettings =
            moduleManager.loadAndGetSettings(intraUserSubAppSession.getAppPublicKey());
      } catch (Exception e) {
        intraUserWalletSettings = null;
      }

      if (intraUserSubAppSession.getAppPublicKey() != null) // the identity not exist yet
      {
        if (intraUserWalletSettings == null) {
          intraUserWalletSettings = new IntraUserWalletSettings();
          intraUserWalletSettings.setIsPresentationHelpEnabled(true);
          intraUserSubAppSession
              .getModuleManager()
              .persistSettings(intraUserSubAppSession.getAppPublicKey(), intraUserWalletSettings);
        }
      }

      mNotificationsCount = moduleManager.getIntraUsersWaitingYourAcceptanceCount();
      new FetchCountTask().execute();

      toolbar = getToolbar();
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(10);
      }

      // consult net work status

      _executor.submit(
          new Runnable() {
            @Override
            public void run() {
              try {
                handler.postDelayed(
                    new Runnable() {
                      public void run() {
                        NetworkStatus networkStatus = null;
                        try {
                          networkStatus = getFermatNetworkStatus();
                        } catch (CantGetCommunicationNetworkStatusException e) {
                          e.printStackTrace();
                        }
                        switch (networkStatus) {
                          case CONNECTED:
                            // setUpReferences();
                            break;
                          case DISCONNECTED:
                            showErrorFermatNetworkDialog();
                            break;
                        }
                      }
                    },
                    500);
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          });

      // getting location and setting device locacion
      location = moduleManager.getLocationManager();

      if (location == null) {
        //  showErrorGPS();
        Toast.makeText(getActivity(), "Please, turn ON your GPS", Toast.LENGTH_SHORT);
      }

      IntraUserLoginIdentity identity = moduleManager.getActiveIntraUserIdentity();

      distance = identity.getAccuracy();

      // turnGPSOn();

    } catch (Exception ex) {
      CommonLogger.exception(TAG, ex.getMessage(), ex);
      errorManager.reportUnexpectedUIException(
          UISource.ACTIVITY, UnexpectedUIExceptionSeverity.CRASH, ex);
    }
  }
  private void showCriptoUsersCache() {

    IntraUserModuleManager moduleManager = intraUserSubAppSession.getModuleManager();
    if (moduleManager == null) {
      getActivity().onBackPressed();
    } else {
      invalidate();
    }
    if (lstIntraUserInformations != null) {
      if (lstIntraUserInformations.isEmpty()) {
        getActivity()
            .runOnUiThread(
                new Runnable() {
                  public void run() {
                    showEmpty(true, emptyView);
                    swipeRefresh.post(
                        new Runnable() {
                          @Override
                          public void run() {
                            swipeRefresh.setRefreshing(true);
                            onRefresh();
                          }
                        });
                  }
                });

      } else {

        getActivity()
            .runOnUiThread(
                new Runnable() {
                  public void run() {
                    adapter.changeDataSet(lstIntraUserInformations);
                    Handler handler = new Handler();
                    handler.postDelayed(
                        new Runnable() {
                          @Override
                          public void run() {
                            onRefresh();
                          }
                        },
                        500);
                  }
                });
      }
    } else {

      getActivity()
          .runOnUiThread(
              new Runnable() {
                public void run() {
                  adapter.changeDataSet(lstIntraUserInformations);
                  Handler handler = new Handler();
                  handler.postDelayed(
                      new Runnable() {
                        @Override
                        public void run() {
                          onRefresh();
                        }
                      },
                      500);
                }
              });
    }
  }
  @Override
  public NotificationPainter getNotificationPainter(String code) {
    NotificationPainter notification = null;
    try {
      boolean enabledNotification = true;

      this.assetRedeemPointCommunitySubAppSession = this.getFullyLoadedSession();
      if (assetRedeemPointCommunitySubAppSession != null) {
        if (assetRedeemPointCommunitySubAppSession.getModuleManager() != null) {
          enabledNotification =
              assetRedeemPointCommunitySubAppSession
                  .getModuleManager()
                  .loadAndGetSettings(assetRedeemPointCommunitySubAppSession.getAppPublicKey())
                  .getNotificationEnabled();
        }
      }

      if (enabledNotification) {
        String[] params = code.split("_");
        String notificationType = params[0];
        String senderActorPublicKey = params[1];

        switch (notificationType) {
          case "CONNECTION-REQUEST":
            if (assetRedeemPointCommunitySubAppSession.getModuleManager() != null) {
              // find last notification by sender actor public key
              ActorAssetRedeemPoint senderActor =
                  assetRedeemPointCommunitySubAppSession
                      .getModuleManager()
                      .getLastNotification(senderActorPublicKey);
              notification =
                  new RedeemAssetCommunityNotificationPainter(
                      "New Connection Request",
                      "Was Received From: " + senderActor.getName(),
                      "",
                      "");
            } else {
              notification =
                  new RedeemAssetCommunityNotificationPainter(
                      "New Connection Request", "A new connection request was received.", "", "");
            }
            break;
          case "CRYPTO-REQUEST":
            if (assetRedeemPointCommunitySubAppSession.getModuleManager() != null) {
              // find last notification by sender actor public key
              ActorAssetRedeemPoint senderActor =
                  assetRedeemPointCommunitySubAppSession
                      .getModuleManager()
                      .getLastNotification(senderActorPublicKey);
              notification =
                  new RedeemAssetCommunityNotificationPainter(
                      "CryptoAddress Arrive",
                      "A New CryptoAddress was Received From: " + senderActorPublicKey,
                      "",
                      "");
            } else {
              notification =
                  new RedeemAssetCommunityNotificationPainter(
                      "CryptoAddress Arrive", "Was Received for: " + senderActorPublicKey, "", "");
            }
            break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return notification;
  }