@Override
  public void onRefresh() {
    if (!isRefreshing) {
      isRefreshing = true;
      final ProgressDialog notificationsProgressDialog = new ProgressDialog(getActivity());
      notificationsProgressDialog.setMessage("Loading Notifications");
      notificationsProgressDialog.setCancelable(false);
      notificationsProgressDialog.show();
      FermatWorker worker =
          new FermatWorker() {
            @Override
            protected Object doInBackground() throws Exception {
              return getMoreData();
            }
          };
      worker.setContext(getActivity());
      worker.setCallBack(
          new FermatWorkerCallBack() {
            @SuppressWarnings("unchecked")
            @Override
            public void onPostExecute(Object... result) {
              notificationsProgressDialog.dismiss();
              isRefreshing = false;
              if (swipeRefresh != null) swipeRefresh.setRefreshing(false);
              if (result != null && result.length > 0) {
                if (getActivity() != null && adapter != null) {
                  artistCommunityInformations = (ArrayList<ArtistCommunityInformation>) result[0];
                  adapter.changeDataSet(artistCommunityInformations);
                  if (artistCommunityInformations.isEmpty()) {
                    showEmpty(true, emptyView);
                  } else {
                    showEmpty(false, emptyView);
                  }
                }
              } else showEmpty(adapter.getSize() < 0, emptyView);
            }

            @Override
            public void onErrorOccurred(Exception ex) {
              notificationsProgressDialog.dismiss();
              try {
                isRefreshing = false;
                if (swipeRefresh != null) swipeRefresh.setRefreshing(false);
                if (getActivity() != null)
                  Toast.makeText(getActivity(), ex.getMessage(), Toast.LENGTH_LONG).show();
                ex.printStackTrace();
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          });
      worker.execute();
    }
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_connect) {
      final ProgressDialog dialog = new ProgressDialog(getActivity());
      dialog.setMessage("Connecting please wait...");
      dialog.setCancelable(false);
      dialog.show();
      FermatWorker worker =
          new FermatWorker() {
            @Override
            protected Object doInBackground() throws Exception {
              List<ActorAssetIssuer> toConnect = new ArrayList<>();
              for (ActorIssuer actorIssuer : actors) {
                if (actorIssuer.selected) toConnect.add(actorIssuer.getRecord());
              }
              //// TODO: 20/11/15 get Actor asset issuer
              manager.connectToActorAssetIssuer(null, toConnect);
              return true;
            }
          };
      worker.setContext(getActivity());
      worker.setCallBack(
          new FermatWorkerCallBack() {
            @Override
            public void onPostExecute(Object... result) {
              dialog.dismiss();
              if (swipeRefreshLayout != null)
                swipeRefreshLayout.post(
                    new Runnable() {
                      @Override
                      public void run() {
                        onRefresh();
                      }
                    });
            }

            @Override
            public void onErrorOccurred(Exception ex) {
              dialog.dismiss();
              Toast.makeText(
                      getActivity(),
                      String.format("An exception has been thrown: %s", ex.getMessage()),
                      Toast.LENGTH_LONG)
                  .show();
              ex.printStackTrace();
            }
          });
      worker.execute();
      return true;
    }
    return super.onOptionsItemSelected(item);
  }
  // endless scroller
  @Override
  public void onLoadMoreData(int page, final int totalItemsCount) {
    adapter.setLoadingData(true);
    FermatWorker fermatWorker =
        new FermatWorker(getActivity().getApplicationContext(), this) {
          @Override
          protected Object doInBackground() throws Exception {
            return getMoreDataAsync(FermatRefreshTypes.NEW, totalItemsCount);
          }
        };

    fermatWorker.execute();
  }
Example #4
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    FermatWorker worker =
        new FermatWorker() {
          @Override
          protected Object doInBackground() throws Exception {
            if (manager == null)
              throw new NullPointerException("AssetUserWalletModuleManager is null");
            assetUserWalletList = manager.getAssetUserWalletBalances("walletPublicKeyTest");
            if (assetUserWalletList != null && !assetUserWalletList.isEmpty()) {
              bookAssets = new ArrayList<>();
              for (AssetUserWalletList assetUserWallet : assetUserWalletList) {
                DigitalAsset asset =
                    new DigitalAsset(
                        assetUserWallet.getDigitalAsset().getName(),
                        String.valueOf(
                            String.format(
                                "BookBalance: %d - AvailableBalance: %d",
                                assetUserWallet.getQuantityBookBalance(),
                                assetUserWallet.getQuantityAvailableBalance())));
                asset.setAssetPublicKey(assetUserWallet.getDigitalAsset().getPublicKey());
                asset.setWalletPublicKey("public_key");
                bookAssets.add(asset);
              }
            }
            return true;
          }
        };
    worker.setContext(getActivity());
    worker.setCallBack(
        new FermatWorkerCallBack() {
          @Override
          public void onPostExecute(Object... result) {
            if (getActivity() != null) {
              if (bookAssets != null && !bookAssets.isEmpty()) {
                if (adapter != null) adapter.changeDataSet(bookAssets);
              }
            }
          }

          @Override
          public void onErrorOccurred(Exception ex) {
            if (getActivity() != null)
              Toast.makeText(getActivity(), ex.getMessage(), Toast.LENGTH_LONG).show();
            CommonLogger.exception(this.getClass().getName(), ex.getMessage(), ex);
            ex.printStackTrace();
          }
        });
    worker.execute();
  }
  @Override
  public void onRefresh() {
    if (!isRefreshing) {
      isRefreshing = true;
      if (swipeRefreshLayout != null) swipeRefreshLayout.setRefreshing(true);
      FermatWorker worker =
          new FermatWorker() {
            @Override
            protected Object doInBackground() throws Exception {
              return getMoreData();
            }
          };
      worker.setContext(getActivity());
      worker.setCallBack(
          new FermatWorkerCallBack() {
            @SuppressWarnings("unchecked")
            @Override
            public void onPostExecute(Object... result) {
              isRefreshing = false;
              if (swipeRefreshLayout != null) swipeRefreshLayout.setRefreshing(false);
              if (result != null && result.length > 0) {
                if (getActivity() != null && adapter != null) {
                  actors = (ArrayList<ActorIssuer>) result[0];
                  adapter.changeDataSet(actors);
                  if (actors.isEmpty()) {
                    showEmpty(true, emptyView);
                  } else {
                    showEmpty(false, emptyView);
                  }
                }
              } else showEmpty(true, emptyView);
              //                    if (actors == null || actors.isEmpty() && getActivity() != null)
              // // for test purpose only
              //                        Toast.makeText(getActivity(), "There are no registered
              // actors...", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onErrorOccurred(Exception ex) {
              isRefreshing = false;
              if (swipeRefreshLayout != null) swipeRefreshLayout.setRefreshing(false);
              if (getActivity() != null)
                Toast.makeText(getActivity(), ex.getMessage(), Toast.LENGTH_LONG).show();
              ex.printStackTrace();
            }
          });
      worker.execute();
    }
  }
Example #6
0
  @Override
  public void onClick(View v) {
    int i = v.getId();
    if (i == R.id.positive_button) {
      if (actorIssuer != null) {
        issuerConnect = new ArrayList<>();
        FermatWorker worker =
            new FermatWorker() {
              @Override
              protected Object doInBackground() throws Exception {

                issuerConnect.add(actorIssuer.getRecord());

                getSession().getModuleManager().askActorAssetIssuerForConnection(issuerConnect);

                Intent broadcast =
                    new Intent(SessionConstantsAssetIssuerCommunity.LOCAL_BROADCAST_CHANNEL);
                broadcast.putExtra(
                    SessionConstantsAssetIssuerCommunity.BROADCAST_CONNECTED_UPDATE, true);
                sendLocalBroadcast(broadcast);
                return true;
              }
            };
        worker.setContext(getActivity());
        worker.setCallBack(
            new FermatWorkerCallBack() {
              @Override
              public void onPostExecute(Object... result) {
                dismiss();
                Toast.makeText(getContext(), R.string.connection_request_send, Toast.LENGTH_SHORT)
                    .show();
              }

              @Override
              public void onErrorOccurred(Exception ex) {
                dismiss();
                Toast.makeText(getActivity(), R.string.before_action, Toast.LENGTH_LONG).show();
              }
            });
        worker.execute();
        //                    Toast.makeText(getContext(), "Connection request sent",
        // Toast.LENGTH_SHORT).show();
      } else {
        super.toastDefaultError();
      }
    } else if (i == R.id.negative_button) {
      dismiss();
    }
  }
  private void doAppropriate(final String assetPublicKey) {
    final Activity activity = getActivity();
    final ProgressDialog dialog = new ProgressDialog(activity);
    dialog.setMessage(getResources().getString(R.string.dap_user_wallet_wait));
    dialog.setCancelable(false);
    dialog.show();
    FermatWorker task =
        new FermatWorker() {
          @Override
          protected Object doInBackground() throws Exception {
            //                    manager.distributionAssets(
            //                            asset.getAssetPublicKey(),
            //                            asset.getWalletPublicKey(),
            //                            asset.getActorAssetRedeemPoint()
            //                    );
            // TODO: only for Appropriate test
            moduleManager.appropriateAsset(assetPublicKey, null);
            return true;
          }
        };
    task.setContext(activity);
    task.setCallBack(
        new FermatWorkerCallBack() {
          @Override
          public void onPostExecute(Object... result) {
            dialog.dismiss();
            if (activity != null) {
              Toast.makeText(
                      activity,
                      getResources().getString(R.string.dap_user_wallet_appropriation_ok),
                      Toast.LENGTH_LONG)
                  .show();
            }
          }

          @Override
          public void onErrorOccurred(Exception ex) {
            dialog.dismiss();
            if (activity != null)
              Toast.makeText(
                      activity,
                      getResources().getString(R.string.dap_user_wallet_exception_retry),
                      Toast.LENGTH_SHORT)
                  .show();
          }
        });
    task.execute();
  }
Example #8
0
  private void doRedeem(
      final String assetPublicKey, final List<RedeemPoint> redeemPoints, final int assetAmount) {
    final ProgressDialog dialog = new ProgressDialog(activity);
    dialog.setMessage(getResources().getString(R.string.dap_user_wallet_wait));
    dialog.setCancelable(false);
    dialog.show();
    FermatWorker task =
        new FermatWorker() {
          @Override
          protected Object doInBackground() throws Exception {
            moduleManager.redeemAssetToRedeemPoint(
                assetPublicKey, null, Data.getRedeemPoints(redeemPoints), assetAmount);
            return true;
          }
        };

    task.setContext(activity);
    task.setCallBack(
        new FermatWorkerCallBack() {
          @Override
          public void onPostExecute(Object... result) {
            dialog.dismiss();
            if (activity != null) {
              refreshUIData();
              Toast.makeText(
                      activity,
                      getResources().getString(R.string.dap_user_wallet_redeem_ok),
                      Toast.LENGTH_LONG)
                  .show();
            }
          }

          @Override
          public void onErrorOccurred(Exception ex) {
            dialog.dismiss();
            if (activity != null)
              Toast.makeText(
                      activity,
                      getResources().getString(R.string.dap_user_wallet_exception_retry),
                      Toast.LENGTH_SHORT)
                  .show();
          }
        });
    task.execute();
  }
Example #9
0
  private void loadSelectedActorIdentityInBackground() {

    FermatWorker fermatWorker =
        new FermatWorker(getActivity()) {
          @Override
          protected Object doInBackground() throws Exception {
            if (selectedActorIdentity == null) return moduleManager.getSelectedActorIdentity();
            return selectedActorIdentity;
          }
        };

    fermatWorker.setCallBack(
        new FermatWorkerCallBack() {
          @Override
          public void onPostExecute(Object... result) {
            try {
              selectedActorIdentity = (ActiveActorIdentityInformation) result[0];
              Bitmap image =
                  BitmapFactory.decodeByteArray(
                      selectedActorIdentity.getImage(), 0, selectedActorIdentity.getImage().length);
              BitmapDrawable bitmapDrawable =
                  new BitmapDrawable(getResources(), getRoundedShape(image, 120));
              toolbar.setLogo(bitmapDrawable);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }

          @Override
          public void onErrorOccurred(Exception ex) {
            final ErrorManager errorManager = appSession.getErrorManager();
            errorManager.reportUnexpectedSubAppException(
                SubApps.CBP_CRYPTO_BROKER_COMMUNITY,
                DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
                ex);
          }
        });

    fermatWorker.execute();
  }
  @Override
  public void onRefresh() {
    if (!isRefreshing) {
      isRefreshing = true;
      FermatWorker worker =
          new FermatWorker() {
            @Override
            protected Object doInBackground() throws Exception {
              return getMoreData();
            }
          };
      worker.setContext(getActivity());
      worker.setCallBack(
          new FermatWorkerCallBack() {
            @SuppressWarnings("unchecked")
            @Override
            public void onPostExecute(Object... result) {
              isRefreshing = false;
              if (swipeRefresh != null) swipeRefresh.setRefreshing(false);
              if (result != null && result.length > 0) {
                if (getActivity() != null && adapter != null) {
                  lstIntraUserInformations = (ArrayList<IntraUserInformation>) result[0];
                  adapter.changeDataSet(lstIntraUserInformations);
                }
              }
            }

            @Override
            public void onErrorOccurred(Exception ex) {
              isRefreshing = false;
              if (swipeRefresh != null) swipeRefresh.setRefreshing(false);
              if (getActivity() != null)
                Toast.makeText(getActivity(), ex.getMessage(), Toast.LENGTH_LONG).show();
              ex.printStackTrace();
            }
          });
      worker.execute();
    }
  }
Example #11
0
  private void getAndShowMarketExchangeRateData() {
    final int MAX_DECIMAL_FOR_RATE = 2;
    final int MIN_DECIMAL_FOR_RATE = 2;
    FermatWorker fermatWorker =
        new FermatWorker(getActivity()) {
          @Override
          protected Object doInBackground() {
            ExchangeRate rate = null;
            try {
              rate =
                  fermatWalletManager.getCurrencyExchange(
                      providerId, FiatCurrency.getByCode(fiatCurrency));
            } catch (Exception e) {
              e.printStackTrace();
            }
            return rate;
          }
        };
    fermatWorker.setCallBack(
        new FermatWorkerCallBack() {
          @Override
          public void onPostExecute(Object... result) {
            if (result != null && result.length > 0) {
              ExchangeRate rate = (ExchangeRate) result[0];
              if (rate != null) {
                // progressBar.setVisibility(View.GONE);
                tvLabelRate.setText(
                    String.valueOf(
                        WalletUtils.formatAmountStringWithDecimalEntry(
                            rate.getPurchasePrice(), MAX_DECIMAL_FOR_RATE, MIN_DECIMAL_FOR_RATE)));
              } else {
                // ErrorExchangeRateConnectionDialog dialog_error = new
                // ErrorExchangeRateConnectionDialog(getActivity());
                // dialog_error.show();
                Toast.makeText(
                        getActivity(),
                        "Cant't Get Exhange Rate Info, check your internet connection.",
                        Toast.LENGTH_SHORT)
                    .show();
              }
            } else {
              // ErrorExchangeRateConnectionDialog dialog_error = new
              // ErrorExchangeRateConnectionDialog(getActivity());
              // dialog_error.show();
              Toast.makeText(
                      getActivity(),
                      "Cant't Get Exhange Rate Info, check your internet connection.",
                      Toast.LENGTH_SHORT)
                  .show();
            }
          }

          @Override
          public void onErrorOccurred(Exception ex) {
            // progressBar.setVisibility(View.GONE);

            if (errorManager != null)
              errorManager.reportUnexpectedWalletException(
                  Wallets.CWP_WALLET_RUNTIME_WALLET_BITCOIN_WALLET_ALL_BITDUBAI,
                  UnexpectedWalletExceptionSeverity
                      .DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
                  ex);
            else Log.e("Exchange Rate", ex.getMessage(), ex);
            // ErrorExchangeRateConnectionDialog dialog_error = new
            // ErrorExchangeRateConnectionDialog(getActivity());
            // dialog_error.show();
          }
        });
    fermatWorker.execute();
  }
Example #12
0
  @Override
  public boolean onMenuItemClick(MenuItem menuItem) {
    if (menuItem.getItemId() == R.id.action_appropriate) {
      final ProgressDialog dialog = new ProgressDialog(getActivity());
      dialog.setMessage("Please wait...");
      dialog.setCancelable(false);
      dialog.show();
      FermatWorker task =
          new FermatWorker() {
            @Override
            protected Object doInBackground() throws Exception {
              // TODO GET THE AMOUNT TO APPROPRIATE.
              manager.appropriateAsset(asset.getAssetPublicKey(), null);
              return true;
            }
          };
      task.setContext(getActivity());
      task.setCallBack(
          new FermatWorkerCallBack() {
            @Override
            public void onPostExecute(Object... result) {
              dialog.dismiss();
              if (getActivity() != null) {
                Toast.makeText(
                        getActivity(),
                        "Appropriation of the asset has started successfully. The process will be completed in a couple of minutes.",
                        Toast.LENGTH_LONG)
                    .show();
              }
            }

            @Override
            public void onErrorOccurred(Exception ex) {
              dialog.dismiss();
              if (getActivity() != null)
                Toast.makeText(
                        getActivity(),
                        "Fermat Has detected an exception. Please retry again.",
                        Toast.LENGTH_SHORT)
                    .show();
            }
          });
      task.execute();
      return true;
    } else if (menuItem.getItemId() == R.id.action_redeem) {
      final ProgressDialog dialog = new ProgressDialog(getActivity());
      dialog.setMessage("Please wait...");
      dialog.setCancelable(false);
      dialog.show();
      FermatWorker task =
          new FermatWorker() {
            @Override
            protected Object doInBackground() throws Exception {
              manager.redeemAssetToRedeemPoint(asset.getAssetPublicKey(), null, null);
              return true;
            }
          };
      task.setContext(getActivity());
      task.setCallBack(
          new FermatWorkerCallBack() {
            @Override
            public void onPostExecute(Object... result) {
              dialog.dismiss();
              if (getActivity() != null) {
                Toast.makeText(
                        getActivity(),
                        "Redemption of the asset has successfully started.\n\n "
                            + "The process will take some minutes and if not accepted at the destination, it will be rollback.",
                        Toast.LENGTH_LONG)
                    .show();
              }
            }

            @Override
            public void onErrorOccurred(Exception ex) {
              dialog.dismiss();
              if (getActivity() != null)
                Toast.makeText(
                        getActivity(),
                        "Fermat Has detected an exception. Please retry again.",
                        Toast.LENGTH_SHORT)
                    .show();
            }
          });
      task.execute();
      return true;
    }
    return false;
  }