JunZhang
5 years ago
committed by
GitHub
31 changed files with 786 additions and 347 deletions
@ -0,0 +1,60 @@ |
|||||
|
/* |
||||
|
* Copyright (c) 2020 Cobo |
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.cobo.cold.ui.fragment.main; |
||||
|
|
||||
|
import com.cobo.coinlib.utils.Coins; |
||||
|
|
||||
|
import java.text.NumberFormat; |
||||
|
|
||||
|
public class TransactionItem { |
||||
|
final int id; |
||||
|
final String amount; |
||||
|
final String address; |
||||
|
|
||||
|
public TransactionItem(int id, long amount, String address) { |
||||
|
this.id = id; |
||||
|
this.amount = formatSatoshi(amount); |
||||
|
this.address = address; |
||||
|
} |
||||
|
|
||||
|
static String formatSatoshi(long satoshi) { |
||||
|
double value = satoshi / Math.pow(10, 8); |
||||
|
NumberFormat nf = NumberFormat.getInstance(); |
||||
|
nf.setMaximumFractionDigits(20); |
||||
|
return nf.format(value) + " " + Coins.BTC.coinCode(); |
||||
|
} |
||||
|
|
||||
|
public int getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
public String getAmount() { |
||||
|
return amount; |
||||
|
} |
||||
|
|
||||
|
public String getAddress() { |
||||
|
return address; |
||||
|
} |
||||
|
|
||||
|
public enum ItemType { |
||||
|
INPUT, |
||||
|
OUTPUT, |
||||
|
FROM, |
||||
|
TO, |
||||
|
} |
||||
|
} |
@ -0,0 +1,91 @@ |
|||||
|
/* |
||||
|
* Copyright (c) 2020 Cobo |
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.cobo.cold.ui.fragment.main; |
||||
|
|
||||
|
import android.content.Context; |
||||
|
import android.view.View; |
||||
|
|
||||
|
import com.cobo.cold.R; |
||||
|
import com.cobo.cold.databinding.TxDetailItemBinding; |
||||
|
import com.cobo.cold.ui.common.BaseBindingAdapter; |
||||
|
|
||||
|
import java.util.Collections; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class TransactionItemAdapter extends BaseBindingAdapter<TransactionItem, TxDetailItemBinding> { |
||||
|
|
||||
|
private TransactionItem.ItemType type; |
||||
|
private List<String> changeAddress; |
||||
|
|
||||
|
public TransactionItemAdapter(Context context, TransactionItem.ItemType type) { |
||||
|
this(context, type, Collections.emptyList()); |
||||
|
} |
||||
|
|
||||
|
public TransactionItemAdapter(Context context, |
||||
|
TransactionItem.ItemType type, |
||||
|
List<String> changeAddress) { |
||||
|
super(context); |
||||
|
this.type = type; |
||||
|
this.changeAddress = changeAddress; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected int getLayoutResId(int viewType) { |
||||
|
return R.layout.tx_detail_item; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onBindItem(TxDetailItemBinding binding, TransactionItem item) { |
||||
|
boolean isChange = changeAddress.contains(item.address); |
||||
|
if (getItemCount() == 1 && type == TransactionItem.ItemType.TO) { |
||||
|
binding.info.setText(item.address); |
||||
|
binding.label.setText(context.getString(R.string.tx_to)); |
||||
|
} else { |
||||
|
binding.info.setText(item.amount + "\n" + item.address); |
||||
|
binding.label.setText(getLabel(item.id)); |
||||
|
} |
||||
|
if (isChange && (type == TransactionItem.ItemType.TO |
||||
|
|| type == TransactionItem.ItemType.OUTPUT)) { |
||||
|
binding.change.setVisibility(View.VISIBLE); |
||||
|
} else { |
||||
|
binding.change.setVisibility(View.GONE); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private String getLabel(int index) { |
||||
|
int resId; |
||||
|
switch (type) { |
||||
|
case TO: |
||||
|
resId = R.string.receive_address; |
||||
|
break; |
||||
|
case FROM: |
||||
|
resId = R.string.send_address; |
||||
|
break; |
||||
|
case INPUT: |
||||
|
resId = R.string.input; |
||||
|
break; |
||||
|
case OUTPUT: |
||||
|
resId = R.string.output; |
||||
|
break; |
||||
|
default: |
||||
|
return ""; |
||||
|
} |
||||
|
|
||||
|
return context.getString(resId, index + 1); |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
/* |
||||
|
* Copyright (c) 2020 Cobo |
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
|
||||
|
package com.cobo.cold.viewmodel; |
||||
|
|
||||
|
public class XpubNotMatchException extends Exception { |
||||
|
public XpubNotMatchException(String message) { |
||||
|
super(message); |
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- |
||||
|
~ Copyright (c) 2020 Cobo |
||||
|
~ |
||||
|
~ This program is free software: you can redistribute it and/or modify |
||||
|
~ it under the terms of the GNU General Public License as published by |
||||
|
~ the Free Software Foundation, either version 3 of the License, or |
||||
|
~ (at your option) any later version. |
||||
|
~ |
||||
|
~ This program is distributed in the hope that it will be useful, |
||||
|
~ but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
~ GNU General Public License for more details. |
||||
|
~ |
||||
|
~ You should have received a copy of the GNU General Public License |
||||
|
~ in the file COPYING. If not, see <http://www.gnu.org/licenses/>. |
||||
|
--> |
||||
|
|
||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
<solid android:color="#ffff00" /> |
||||
|
<corners android:radius="5dp"/> |
||||
|
</shape> |
Loading…
Reference in new issue