@Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
      final ViewGroup row;
      if (convertView == null)
        row = (ViewGroup) getLayoutInflater(null).inflate(R.layout.block_row, null);
      else row = (ViewGroup) convertView;

      final StoredBlock storedBlock = getItem(position);
      final Block header = storedBlock.getHeader();

      final TextView rowHeight = (TextView) row.findViewById(R.id.block_list_row_height);
      final int height = storedBlock.getHeight();
      rowHeight.setText(Integer.toString(height));

      final TextView rowTime = (TextView) row.findViewById(R.id.block_list_row_time);
      final long timeMs = header.getTimeSeconds() * DateUtils.SECOND_IN_MILLIS;
      rowTime.setText(
          DateUtils.getRelativeDateTimeString(
              activity, timeMs, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));

      final TextView rowHash = (TextView) row.findViewById(R.id.block_list_row_hash);
      rowHash.setText(WalletUtils.formatHash(null, header.getHashAsString(), 8, 0, ' '));

      final int transactionChildCount = row.getChildCount() - ROW_BASE_CHILD_COUNT;
      int iTransactionView = 0;

      if (transactions != null) {
        final String precision =
            prefs.getString(
                Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION);
        final int btcPrecision = precision.charAt(0) - '0';
        final int btcShift = precision.length() == 3 ? precision.charAt(2) - '0' : 0;

        transactionsAdapter.setPrecision(btcPrecision, btcShift);

        for (final Transaction tx : transactions) {
          if (tx.getAppearsInHashes().containsKey(header.getHash())) {
            final View view;
            if (iTransactionView < transactionChildCount) {
              view = row.getChildAt(ROW_INSERT_INDEX + iTransactionView);
            } else {
              view = getLayoutInflater(null).inflate(R.layout.transaction_row_oneline, null);
              row.addView(view, ROW_INSERT_INDEX + iTransactionView);
            }

            transactionsAdapter.bindView(view, tx);

            iTransactionView++;
          }
        }
      }

      final int leftoverTransactionViews = transactionChildCount - iTransactionView;
      if (leftoverTransactionViews > 0)
        row.removeViews(ROW_INSERT_INDEX + iTransactionView, leftoverTransactionViews);

      return row;
    }
Exemplo n.º 2
0
  @Test
  public void testRemoveViews() {
    root.removeViews(0, 0);
    assertThat(root.getChildCount(), equalTo(3));

    root.removeViews(2, 1);
    assertThat(root.getChildCount(), equalTo(2));
    assertThat(root.getChildAt(0), sameInstance(child1));
    assertThat(root.getChildAt(1), sameInstance(child2));

    root.removeViews(0, 1);
    assertThat(root.getChildCount(), equalTo(1));
    assertThat(root.getChildAt(0), sameInstance(child2));

    root.removeViews(0, 1);
    assertThat(root.getChildCount(), equalTo(0));

    root.addView(child1);
    root.addView(child2);
    root.addView(child3);

    root.removeViews(1, 1);
    assertThat(root.getChildCount(), equalTo(2));
    assertThat(root.getChildAt(0), sameInstance(child1));
    assertThat(root.getChildAt(1), sameInstance((View) child3));

    root.removeViews(0, 2);
    assertThat(root.getChildCount(), equalTo(0));
  }
 @Override
 public void removeViews(int start, int count) {
   mDirtyHierarchy = true;
   super.removeViews(start, count);
 }
Exemplo n.º 4
0
 @Override
 public void removeViews(int start, int count) {
   super.removeViews(start, count);
   updateAngle();
 }