Convert adapters to Kotlin

This commit is contained in:
pokkst 2023-12-06 10:57:54 -06:00
parent 19b5a55932
commit 68dfd3797c
No known key found for this signature in database
GPG Key ID: EC4FAAA66859FAA4
5 changed files with 371 additions and 422 deletions

View File

@ -13,176 +13,170 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.mynero.wallet.adapter
package net.mynero.wallet.adapter;
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnLongClickListener
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import net.mynero.wallet.R
import net.mynero.wallet.model.CoinsInfo
import net.mynero.wallet.model.Wallet
import net.mynero.wallet.service.PrefService
import net.mynero.wallet.service.UTXOService
import net.mynero.wallet.util.Constants
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import net.mynero.wallet.R;
import net.mynero.wallet.model.CoinsInfo;
import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.service.PrefService;
import net.mynero.wallet.service.UTXOService;
import net.mynero.wallet.util.Constants;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.ViewHolder> {
private List<CoinsInfo> localDataSet; // <public-key, coinsinfo>
private final HashMap<String, CoinsInfo> selectedUtxos; // <public-key, coinsinfo>
private CoinsInfoAdapterListener listener = null;
private boolean editing = false;
class CoinsInfoAdapter(val listener: CoinsInfoAdapterListener?) :
RecyclerView.Adapter<CoinsInfoAdapter.ViewHolder>() {
private var localDataSet // <public-key, coinsinfo>
: List<CoinsInfo>
@JvmField
val selectedUtxos // <public-key, coinsinfo>
: HashMap<String?, CoinsInfo>
private var editing = false
/**
* Initialize the dataset of the Adapter.
*/
public CoinsInfoAdapter(CoinsInfoAdapterListener listener) {
this.listener = listener;
this.localDataSet = new ArrayList<>();
this.selectedUtxos = new HashMap<>();
init {
localDataSet = ArrayList()
selectedUtxos = HashMap()
}
public void submitList(HashMap<String, CoinsInfo> dataSet) {
this.localDataSet = new ArrayList<>(dataSet.values());
notifyDataSetChanged();
fun submitList(dataSet: HashMap<String?, CoinsInfo>) {
localDataSet = ArrayList(dataSet.values)
notifyDataSetChanged()
}
public void deselectUtxo(CoinsInfo coinsInfo) {
this.selectedUtxos.remove(coinsInfo.pubKey);
if(this.selectedUtxos.size() == 0) {
editing = false;
fun deselectUtxo(coinsInfo: CoinsInfo) {
selectedUtxos.remove(coinsInfo.pubKey)
if (selectedUtxos.size == 0) {
editing = false
}
notifyDataSetChanged()
}
notifyDataSetChanged();
fun selectUtxo(coinsInfo: CoinsInfo) {
editing = true
selectedUtxos[coinsInfo.pubKey] = coinsInfo
notifyDataSetChanged()
}
public void selectUtxo(CoinsInfo coinsInfo) {
editing = true;
this.selectedUtxos.put(coinsInfo.pubKey, coinsInfo);
notifyDataSetChanged();
operator fun contains(coinsInfo: CoinsInfo): Boolean {
return selectedUtxos.containsKey(coinsInfo.pubKey)
}
public boolean contains(CoinsInfo coinsInfo) {
return selectedUtxos.containsKey(coinsInfo.pubKey);
}
public void clear() {
this.selectedUtxos.clear();
editing = false;
notifyDataSetChanged();
}
public HashMap<String, CoinsInfo> getSelectedUtxos() {
return selectedUtxos;
fun clear() {
selectedUtxos.clear()
editing = false
notifyDataSetChanged()
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
// Create a new view, which defines the UI of the list item
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.utxo_selection_item, viewGroup, false);
return new ViewHolder(listener, view);
val view = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.utxo_selection_item, viewGroup, false)
return ViewHolder(listener, view)
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
CoinsInfo tx = localDataSet.get(position);
viewHolder.bind(editing, tx, selectedUtxos);
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val tx = localDataSet[position]
viewHolder.bind(editing, tx, selectedUtxos)
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return localDataSet.size();
override fun getItemCount(): Int {
return localDataSet.size
}
public interface CoinsInfoAdapterListener {
void onUtxoSelected(CoinsInfo coinsInfo);
interface CoinsInfoAdapterListener {
fun onUtxoSelected(coinsInfo: CoinsInfo?)
}
/**
* Provide a reference to the type of views that you are using
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private CoinsInfo coinsInfo;
private boolean editing = false;
private final CoinsInfoAdapterListener listener;
class ViewHolder(private val listener: CoinsInfoAdapterListener?, view: View) :
RecyclerView.ViewHolder(view), View.OnClickListener, OnLongClickListener {
private var coinsInfo: CoinsInfo? = null
private var editing = false
public ViewHolder(CoinsInfoAdapterListener listener, View view) {
super(view);
this.listener = listener;
view.setOnClickListener(this);
view.setOnLongClickListener(this);
init {
view.setOnClickListener(this)
view.setOnLongClickListener(this)
}
public void bind(boolean editing, CoinsInfo coinsInfo, HashMap<String, CoinsInfo> selectedUtxos) {
this.editing = editing;
this.coinsInfo = coinsInfo;
boolean selected = selectedUtxos.containsKey(coinsInfo.pubKey);
TextView pubKeyTextView = itemView.findViewById(R.id.utxo_pub_key_textview);
TextView amountTextView = itemView.findViewById(R.id.utxo_amount_textview);
TextView addressTextView = itemView.findViewById(R.id.utxo_address_textview);
TextView globalIdxTextView = itemView.findViewById(R.id.utxo_global_index_textview);
TextView outpointTextView = itemView.findViewById(R.id.utxo_outpoint_textview);
boolean streetModeEnabled = PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false);
String balanceString = streetModeEnabled ? Constants.STREET_MODE_BALANCE : Wallet.getDisplayAmount(coinsInfo.amount);
amountTextView.setText(itemView.getResources().getString(R.string.tx_amount_no_prefix, balanceString));
pubKeyTextView.setText(coinsInfo.pubKey);
addressTextView.setText(coinsInfo.address);
globalIdxTextView.setText(itemView.getResources().getString(R.string.global_index_text, coinsInfo.globalOutputIndex));
outpointTextView.setText(itemView.getResources().getString(R.string.outpoint_text, coinsInfo.hash + ":" + coinsInfo.localOutputIndex));
fun bind(
editing: Boolean,
coinsInfo: CoinsInfo,
selectedUtxos: HashMap<String?, CoinsInfo>
) {
this.editing = editing
this.coinsInfo = coinsInfo
val selected = selectedUtxos.containsKey(coinsInfo.pubKey)
val pubKeyTextView = itemView.findViewById<TextView>(R.id.utxo_pub_key_textview)
val amountTextView = itemView.findViewById<TextView>(R.id.utxo_amount_textview)
val addressTextView = itemView.findViewById<TextView>(R.id.utxo_address_textview)
val globalIdxTextView = itemView.findViewById<TextView>(R.id.utxo_global_index_textview)
val outpointTextView = itemView.findViewById<TextView>(R.id.utxo_outpoint_textview)
val streetModeEnabled =
PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false)
val balanceString =
if (streetModeEnabled) Constants.STREET_MODE_BALANCE else Wallet.getDisplayAmount(
coinsInfo.amount
)
amountTextView.text =
itemView.resources.getString(R.string.tx_amount_no_prefix, balanceString)
pubKeyTextView.text = coinsInfo.pubKey
addressTextView.text = coinsInfo.address
globalIdxTextView.text =
itemView.resources.getString(
R.string.global_index_text,
coinsInfo.globalOutputIndex
)
outpointTextView.text = itemView.resources.getString(
R.string.outpoint_text,
coinsInfo.hash + ":" + coinsInfo.localOutputIndex
)
if (selected) {
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_colorSecondary));
} else if(coinsInfo.isFrozen() || UTXOService.instance.isCoinFrozen(coinsInfo)) {
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_frozen_utxo));
} else if (!coinsInfo.isUnlocked()) {
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_locked_utxo));
itemView.backgroundTintList =
ContextCompat.getColorStateList(itemView.context, R.color.oled_colorSecondary)
} else if (coinsInfo.isFrozen || UTXOService.instance.isCoinFrozen(coinsInfo)) {
itemView.backgroundTintList =
ContextCompat.getColorStateList(itemView.context, R.color.oled_frozen_utxo)
} else if (!coinsInfo.isUnlocked) {
itemView.backgroundTintList =
ContextCompat.getColorStateList(itemView.context, R.color.oled_locked_utxo)
} else {
itemView.setBackgroundTintList(ContextCompat.getColorStateList(itemView.getContext(), R.color.oled_dialogBackgroundColor));
itemView.backgroundTintList =
ContextCompat.getColorStateList(
itemView.context,
R.color.oled_dialogBackgroundColor
)
}
}
@Override
public void onClick(View view) {
if(!editing) return;
boolean unlocked = coinsInfo.isUnlocked();
override fun onClick(view: View) {
if (!editing) return
val unlocked = coinsInfo?.isUnlocked == true
if (unlocked) {
listener.onUtxoSelected(coinsInfo);
listener?.onUtxoSelected(coinsInfo)
}
}
@Override
public boolean onLongClick(View view) {
if(editing) return false;
boolean unlocked = coinsInfo.isUnlocked();
override fun onLongClick(view: View): Boolean {
if (editing) return false
val unlocked = coinsInfo?.isUnlocked == true
if (unlocked) {
listener.onUtxoSelected(coinsInfo);
listener?.onUtxoSelected(coinsInfo)
}
return unlocked;
}
@Override
public boolean onLongClickUseDefaultHapticFeedback(@NonNull View v) {
return View.OnLongClickListener.super.onLongClickUseDefaultHapticFeedback(v);
return unlocked
}
}
}

View File

@ -13,140 +13,127 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.mynero.wallet.adapter
package net.mynero.wallet.adapter;
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import net.mynero.wallet.R
import net.mynero.wallet.data.DefaultNodes
import net.mynero.wallet.data.Node
import net.mynero.wallet.service.PrefService
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.recyclerview.widget.RecyclerView;
import net.mynero.wallet.R;
import net.mynero.wallet.data.DefaultNodes;
import net.mynero.wallet.data.Node;
import net.mynero.wallet.service.PrefService;
import java.util.ArrayList;
import java.util.List;
public class NodeSelectionAdapter extends RecyclerView.Adapter<NodeSelectionAdapter.ViewHolder> {
private List<Node> localDataSet;
private NodeSelectionAdapterListener listener = null;
class NodeSelectionAdapter(val listener: NodeSelectionAdapterListener?) :
RecyclerView.Adapter<NodeSelectionAdapter.ViewHolder>() {
private var localDataSet: List<Node>
/**
* Initialize the dataset of the Adapter.
*/
public NodeSelectionAdapter(NodeSelectionAdapterListener listener) {
this.listener = listener;
this.localDataSet = new ArrayList<>();
init {
localDataSet = ArrayList()
}
public void submitList(List<Node> dataSet) {
this.localDataSet = dataSet;
notifyDataSetChanged();
fun submitList(dataSet: List<Node>) {
localDataSet = dataSet
notifyDataSetChanged()
}
public void updateSelectedNode() {
notifyDataSetChanged();
fun updateSelectedNode() {
notifyDataSetChanged()
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
// Create a new view, which defines the UI of the list item
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.node_selection_item, viewGroup, false);
return new ViewHolder(listener, view);
val view = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.node_selection_item, viewGroup, false)
return ViewHolder(listener, view)
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
Node node = localDataSet.get(position);
viewHolder.bind(node);
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val node = localDataSet[position]
viewHolder.bind(node)
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return localDataSet.size();
override fun getItemCount(): Int {
return localDataSet.size
}
public interface NodeSelectionAdapterListener {
void onSelectNode(Node node);
boolean onSelectEditNode(Node node);
interface NodeSelectionAdapterListener {
fun onSelectNode(node: Node?)
fun onSelectEditNode(node: Node?): Boolean
}
/**
* Provide a reference to the type of views that you are using
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private final NodeSelectionAdapterListener listener;
public ViewHolder(NodeSelectionAdapterListener listener, View view) {
super(view);
this.listener = listener;
}
public void bind(Node node) {
Node currentNode = PrefService.getInstance().getNode();
boolean match = node.equals(currentNode);
class ViewHolder(private val listener: NodeSelectionAdapterListener?, view: View) :
RecyclerView.ViewHolder(
view
) {
fun bind(node: Node) {
val currentNode = PrefService.getInstance().node
val match = node == currentNode
if (match) {
itemView.setBackgroundColor(itemView.getResources().getColor(R.color.oled_colorSecondary));
itemView.setBackgroundColor(itemView.resources.getColor(R.color.oled_colorSecondary))
} else {
itemView.setBackgroundColor(itemView.getResources().getColor(android.R.color.transparent));
itemView.setBackgroundColor(itemView.resources.getColor(android.R.color.transparent))
}
TextView nodeNameTextView = itemView.findViewById(R.id.node_name_textview);
TextView nodeAddressTextView = itemView.findViewById(R.id.node_uri_textview);
TextView authTextView = itemView.findViewById(R.id.authenticated_textview);
nodeNameTextView.setText(node.getName());
nodeAddressTextView.setText(node.getAddress());
if(!node.getPassword().isEmpty()) {
authTextView.setVisibility(View.VISIBLE);
val nodeNameTextView = itemView.findViewById<TextView>(R.id.node_name_textview)
val nodeAddressTextView = itemView.findViewById<TextView>(R.id.node_uri_textview)
val authTextView = itemView.findViewById<TextView>(R.id.authenticated_textview)
nodeNameTextView.text = node.name
nodeAddressTextView.text = node.address
if (node.password.isNotEmpty()) {
authTextView.visibility = View.VISIBLE
}
ImageView nodeAnonymityNetworkImageView = itemView.findViewById(R.id.anonymity_network_imageview);
if(node.isOnion()) {
nodeAnonymityNetworkImageView.setVisibility(View.VISIBLE);
nodeAnonymityNetworkImageView.setImageResource(R.drawable.tor);
} else if(node.isI2P()) {
nodeAnonymityNetworkImageView.setVisibility(View.VISIBLE);
nodeAnonymityNetworkImageView.setImageResource(R.drawable.i2p);
val nodeAnonymityNetworkImageView =
itemView.findViewById<ImageView>(R.id.anonymity_network_imageview)
if (node.isOnion) {
nodeAnonymityNetworkImageView.visibility = View.VISIBLE
nodeAnonymityNetworkImageView.setImageResource(R.drawable.tor)
} else if (node.isI2P) {
nodeAnonymityNetworkImageView.visibility = View.VISIBLE
nodeAnonymityNetworkImageView.setImageResource(R.drawable.i2p)
} else {
nodeAnonymityNetworkImageView.setVisibility(View.GONE);
nodeAnonymityNetworkImageView.visibility = View.GONE
}
itemView.setOnLongClickListener(view -> {
if(match) {
Toast.makeText(itemView.getContext(), itemView.getResources().getString(R.string.cant_edit_current_node), Toast.LENGTH_SHORT).show();
return true;
} else if(isDefaultNode(node)) {
Toast.makeText(itemView.getContext(), itemView.getResources().getString(R.string.cant_edit_default_nodes), Toast.LENGTH_SHORT).show();
return true;
itemView.setOnLongClickListener {
if (match) {
Toast.makeText(
itemView.context,
itemView.resources.getString(R.string.cant_edit_current_node),
Toast.LENGTH_SHORT
).show()
return@setOnLongClickListener true
} else if (isDefaultNode(node)) {
Toast.makeText(
itemView.context,
itemView.resources.getString(R.string.cant_edit_default_nodes),
Toast.LENGTH_SHORT
).show()
return@setOnLongClickListener true
} else {
return listener.onSelectEditNode(node);
return@setOnLongClickListener listener?.onSelectEditNode(node) == true
}
});
itemView.setOnClickListener(view -> listener.onSelectNode(node));
}
itemView.setOnClickListener { listener?.onSelectNode(node) }
}
private boolean isDefaultNode(Node currentNode) {
boolean isDefault = false;
for(DefaultNodes defaultNode : DefaultNodes.values()) {
if(currentNode.toNodeString().equals(defaultNode.getNodeString()))
isDefault = true;
private fun isDefaultNode(currentNode: Node): Boolean {
var isDefault = false
for (defaultNode in DefaultNodes.values()) {
if (currentNode.toNodeString() == defaultNode.nodeString) isDefault = true
}
return isDefault;
return isDefault
}
}
}

View File

@ -13,119 +13,102 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.mynero.wallet.adapter
package net.mynero.wallet.adapter;
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import net.mynero.wallet.R
import net.mynero.wallet.data.Subaddress
import net.mynero.wallet.service.PrefService
import net.mynero.wallet.util.Constants
import net.mynero.wallet.util.Helper
import net.mynero.wallet.util.Helper.getDisplayAmount
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import net.mynero.wallet.R;
import net.mynero.wallet.data.Subaddress;
import net.mynero.wallet.model.CoinsInfo;
import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.service.PrefService;
import net.mynero.wallet.util.Constants;
import net.mynero.wallet.util.Helper;
import java.util.ArrayList;
import java.util.List;
public class SubaddressAdapter extends RecyclerView.Adapter<SubaddressAdapter.ViewHolder> {
private List<Subaddress> localDataSet;
private SubaddressAdapterListener listener = null;
class SubaddressAdapter(val listener: SubaddressAdapterListener?) :
RecyclerView.Adapter<SubaddressAdapter.ViewHolder>() {
private var localDataSet: List<Subaddress>
/**
* Initialize the dataset of the Adapter.
*/
public SubaddressAdapter(SubaddressAdapterListener listener) {
this.localDataSet = new ArrayList<>();
this.listener = listener;
init {
localDataSet = ArrayList()
}
public void submitList(List<Subaddress> dataSet) {
this.localDataSet = dataSet;
notifyDataSetChanged();
fun submitList(dataSet: List<Subaddress>) {
localDataSet = dataSet
notifyDataSetChanged()
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
// Create a new view, which defines the UI of the list item
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.address_item, viewGroup, false);
return new ViewHolder(view, listener);
val view = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.address_item, viewGroup, false)
return ViewHolder(view, listener)
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
Subaddress subaddress = localDataSet.get(position);
viewHolder.bind(subaddress);
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val subaddress = localDataSet[position]
viewHolder.bind(subaddress)
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return localDataSet.size();
override fun getItemCount(): Int {
return localDataSet.size
}
public interface SubaddressAdapterListener {
void onSubaddressSelected(Subaddress subaddress);
void onSubaddressEditLabel(Subaddress subaddress);
interface SubaddressAdapterListener {
fun onSubaddressSelected(subaddress: Subaddress?)
fun onSubaddressEditLabel(subaddress: Subaddress?)
}
/**
* Provide a reference to the type of views that you are using
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private SubaddressAdapterListener listener = null;
class ViewHolder(view: View, val listener: SubaddressAdapterListener?) : RecyclerView.ViewHolder(
view
) {
public ViewHolder(View view, SubaddressAdapterListener listener) {
super(view);
this.listener = listener;
}
public void bind(Subaddress subaddress) {
TextView addressTextView = itemView.findViewById(R.id.address_item_address_textview);
TextView addressLabelTextView = itemView.findViewById(R.id.address_label_textview);
TextView addressAmountTextView = itemView.findViewById(R.id.address_amount_textview);
addressTextView.setText(subaddress.address);
final String label = subaddress.getDisplayLabel();
final String address = itemView.getContext().getString(R.string.subbaddress_info_subtitle,
subaddress.addressIndex, subaddress.getSquashedAddress());
addressLabelTextView.setText(label.isEmpty() ? address : label);
final long amount = subaddress.amount;
fun bind(subaddress: Subaddress) {
val addressTextView =
itemView.findViewById<TextView>(R.id.address_item_address_textview)
val addressLabelTextView = itemView.findViewById<TextView>(R.id.address_label_textview)
val addressAmountTextView =
itemView.findViewById<TextView>(R.id.address_amount_textview)
addressTextView.text = subaddress.address
val label = subaddress.displayLabel
val address = itemView.context.getString(
R.string.subbaddress_info_subtitle,
subaddress.addressIndex, subaddress.squashedAddress
)
addressLabelTextView.text = label.ifEmpty { address }
val amount = subaddress.amount
if (amount > 0) {
boolean streetMode = PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false);
if(streetMode) {
addressAmountTextView.setText(itemView.getContext().getString(R.string.tx_list_amount_positive,
Constants.STREET_MODE_BALANCE));
val streetMode =
PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false)
if (streetMode) {
addressAmountTextView.text = itemView.context.getString(
R.string.tx_list_amount_positive,
Constants.STREET_MODE_BALANCE
)
} else {
addressAmountTextView.setText(itemView.getContext().getString(R.string.tx_list_amount_positive,
Helper.getDisplayAmount(amount, Helper.DISPLAY_DIGITS_INFO)));
addressAmountTextView.text = itemView.context.getString(
R.string.tx_list_amount_positive,
getDisplayAmount(amount, Helper.DISPLAY_DIGITS_INFO)
)
}
} else addressAmountTextView.text = ""
itemView.setOnClickListener { listener?.onSubaddressSelected(subaddress) }
itemView.setOnLongClickListener { _: View? ->
listener?.onSubaddressEditLabel(subaddress)
true
}
else
addressAmountTextView.setText("");
itemView.setOnClickListener(view -> listener.onSubaddressSelected(subaddress));
itemView.setOnLongClickListener(v -> {
listener.onSubaddressEditLabel(subaddress);
return true;
});
}
}
}

View File

@ -13,164 +13,149 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.mynero.wallet.adapter
package net.mynero.wallet.adapter;
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.progressindicator.CircularProgressIndicator
import net.mynero.wallet.R
import net.mynero.wallet.model.TransactionInfo
import net.mynero.wallet.service.PrefService
import net.mynero.wallet.util.Constants
import net.mynero.wallet.util.DateHelper.DATETIME_FORMATTER
import net.mynero.wallet.util.Helper
import net.mynero.wallet.util.Helper.getDisplayAmount
import net.mynero.wallet.util.ThemeHelper.getThemedColor
import java.util.Calendar
import java.util.Date
import static net.mynero.wallet.util.DateHelper.DATETIME_FORMATTER;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.progressindicator.CircularProgressIndicator;
import net.mynero.wallet.R;
import net.mynero.wallet.model.TransactionInfo;
import net.mynero.wallet.service.PrefService;
import net.mynero.wallet.util.Constants;
import net.mynero.wallet.util.Helper;
import net.mynero.wallet.util.ThemeHelper;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfoAdapter.ViewHolder> {
private List<TransactionInfo> localDataSet;
private TxInfoAdapterListener listener = null;
class TransactionInfoAdapter(val listener: TxInfoAdapterListener?) :
RecyclerView.Adapter<TransactionInfoAdapter.ViewHolder>() {
private var localDataSet: List<TransactionInfo>
/**
* Initialize the dataset of the Adapter.
*/
public TransactionInfoAdapter(TxInfoAdapterListener listener) {
this.listener = listener;
this.localDataSet = new ArrayList<>();
init {
localDataSet = ArrayList()
}
public void submitList(List<TransactionInfo> dataSet) {
this.localDataSet = dataSet;
notifyDataSetChanged();
fun submitList(dataSet: List<TransactionInfo>) {
localDataSet = dataSet
notifyDataSetChanged()
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
// Create a new view, which defines the UI of the list item
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.transaction_history_item, viewGroup, false);
return new ViewHolder(listener, view);
val view = LayoutInflater.from(viewGroup.context)
.inflate(R.layout.transaction_history_item, viewGroup, false)
return ViewHolder(listener, view)
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
TransactionInfo tx = localDataSet.get(position);
viewHolder.bind(tx);
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val tx = localDataSet[position]
viewHolder.bind(tx)
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return localDataSet.size();
override fun getItemCount(): Int {
return localDataSet.size
}
public interface TxInfoAdapterListener {
void onClickTransaction(TransactionInfo txInfo);
interface TxInfoAdapterListener {
fun onClickTransaction(txInfo: TransactionInfo?)
}
/**
* Provide a reference to the type of views that you are using
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private final int outboundColour;
private final int inboundColour;
private final int pendingColour;
private final int failedColour;
private TxInfoAdapterListener listener = null;
private TextView amountTextView = null;
class ViewHolder(val listener: TxInfoAdapterListener?, view: View) : RecyclerView.ViewHolder(view) {
private val outboundColour: Int
private val inboundColour: Int
private val pendingColour: Int
private val failedColour: Int
private var amountTextView: TextView? = null
public ViewHolder(TxInfoAdapterListener listener, View view) {
super(view);
inboundColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.positiveColor);
outboundColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.negativeColor);
pendingColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.neutralColor);
failedColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.neutralColor);
this.listener = listener;
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone(); //get the local time zone.
DATETIME_FORMATTER.setTimeZone(tz);
init {
inboundColour = getThemedColor(view.context, R.attr.positiveColor)
outboundColour = getThemedColor(view.context, R.attr.negativeColor)
pendingColour = getThemedColor(view.context, R.attr.neutralColor)
failedColour = getThemedColor(view.context, R.attr.neutralColor)
val cal = Calendar.getInstance()
val tz = cal.timeZone //get the local time zone.
DATETIME_FORMATTER.timeZone = tz
}
public void bind(TransactionInfo txInfo) {
boolean streetModeEnabled = PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false);
String displayAmount = streetModeEnabled ? Constants.STREET_MODE_BALANCE : Helper.getDisplayAmount(txInfo.amount, Helper.DISPLAY_DIGITS_INFO);
TextView confirmationsTextView = itemView.findViewById(R.id.tvConfirmations);
CircularProgressIndicator confirmationsProgressBar = itemView.findViewById(R.id.pbConfirmations);
confirmationsProgressBar.setMax(TransactionInfo.CONFIRMATION);
this.amountTextView = itemView.findViewById(R.id.tx_amount);
itemView.findViewById(R.id.tx_failed).setVisibility(View.GONE);
fun bind(txInfo: TransactionInfo) {
val streetModeEnabled =
PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false)
val displayAmount =
if (streetModeEnabled) Constants.STREET_MODE_BALANCE else getDisplayAmount(
txInfo.amount,
Helper.DISPLAY_DIGITS_INFO
)
val confirmationsTextView = itemView.findViewById<TextView>(R.id.tvConfirmations)
val confirmationsProgressBar =
itemView.findViewById<CircularProgressIndicator>(R.id.pbConfirmations)
confirmationsProgressBar.max = TransactionInfo.CONFIRMATION
amountTextView = itemView.findViewById(R.id.tx_amount)
itemView.findViewById<View>(R.id.tx_failed).visibility = View.GONE
if (txInfo.isFailed) {
((TextView) itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_negative, displayAmount));
itemView.findViewById(R.id.tx_failed).setVisibility(View.VISIBLE);
setTxColour(failedColour);
confirmationsTextView.setVisibility(View.GONE);
confirmationsProgressBar.setVisibility(View.GONE);
(itemView.findViewById<View>(R.id.tx_amount) as TextView).text =
itemView.context.getString(R.string.tx_list_amount_negative, displayAmount)
itemView.findViewById<View>(R.id.tx_failed).visibility = View.VISIBLE
setTxColour(failedColour)
confirmationsTextView.visibility = View.GONE
confirmationsProgressBar.visibility = View.GONE
} else if (txInfo.isPending) {
setTxColour(pendingColour);
confirmationsProgressBar.setIndeterminate(true);
confirmationsProgressBar.setVisibility(View.VISIBLE);
confirmationsTextView.setVisibility(View.GONE);
setTxColour(pendingColour)
confirmationsProgressBar.isIndeterminate = true
confirmationsProgressBar.visibility = View.VISIBLE
confirmationsTextView.visibility = View.GONE
} else if (txInfo.direction == TransactionInfo.Direction.Direction_In) {
setTxColour(inboundColour);
if (!txInfo.isConfirmed()) {
confirmationsProgressBar.setVisibility(View.VISIBLE);
final int confirmations = (int) txInfo.confirmations;
confirmationsProgressBar.setProgressCompat(confirmations, true);
final String confCount = Integer.toString(confirmations);
confirmationsTextView.setText(confCount);
if (confCount.length() == 1) // we only have space for character in the progress circle
confirmationsTextView.setVisibility(View.VISIBLE);
else
confirmationsTextView.setVisibility(View.GONE);
setTxColour(inboundColour)
if (!txInfo.isConfirmed) {
confirmationsProgressBar.visibility = View.VISIBLE
val confirmations = txInfo.confirmations.toInt()
confirmationsProgressBar.setProgressCompat(confirmations, true)
val confCount = confirmations.toString()
confirmationsTextView.text = confCount
if (confCount.length == 1) // we only have space for character in the progress circle
confirmationsTextView.visibility =
View.VISIBLE else confirmationsTextView.visibility = View.GONE
} else {
confirmationsProgressBar.setVisibility(View.GONE);
confirmationsTextView.setVisibility(View.GONE);
confirmationsProgressBar.visibility = View.GONE
confirmationsTextView.visibility = View.GONE
}
} else {
setTxColour(outboundColour);
confirmationsProgressBar.setVisibility(View.GONE);
confirmationsTextView.setVisibility(View.GONE);
setTxColour(outboundColour)
confirmationsProgressBar.visibility = View.GONE
confirmationsTextView.visibility = View.GONE
}
if (txInfo.direction == TransactionInfo.Direction.Direction_Out) {
((TextView) itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_negative, displayAmount));
(itemView.findViewById<View>(R.id.tx_amount) as TextView).text =
itemView.context.getString(R.string.tx_list_amount_negative, displayAmount)
} else {
((TextView) itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_positive, displayAmount));
(itemView.findViewById<View>(R.id.tx_amount) as TextView).text =
itemView.context.getString(R.string.tx_list_amount_positive, displayAmount)
}
(itemView.findViewById<View>(R.id.tx_datetime) as TextView).text =
getDateTime(txInfo.timestamp)
itemView.setOnClickListener { _: View? -> listener?.onClickTransaction(txInfo) }
}
((TextView) itemView.findViewById(R.id.tx_datetime)).setText(getDateTime(txInfo.timestamp));
itemView.setOnClickListener(view -> {
listener.onClickTransaction(txInfo);
});
private fun setTxColour(clr: Int) {
amountTextView?.setTextColor(clr)
}
private void setTxColour(int clr) {
amountTextView.setTextColor(clr);
}
private String getDateTime(long time) {
return DATETIME_FORMATTER.format(new Date(time * 1000));
private fun getDateTime(time: Long): String {
return DATETIME_FORMATTER.format(Date(time * 1000))
}
}
}

View File

@ -60,7 +60,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
freezeUtxosButton.setOnClickListener(view1 -> {
Toast.makeText(getContext(), "Toggling freeze status, please wait.", Toast.LENGTH_SHORT).show();
MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR.execute(() -> {
UTXOService.getInstance().toggleFrozen(adapter.getSelectedUtxos());
UTXOService.getInstance().toggleFrozen(adapter.selectedUtxos);
getActivity().runOnUiThread(() -> {
adapter.clear();
sendUtxosButton.setVisibility(View.GONE);
@ -71,7 +71,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
});
sendUtxosButton.setOnClickListener(view1 -> {
ArrayList<String> selectedKeyImages = new ArrayList<>();
for(CoinsInfo coinsInfo : adapter.getSelectedUtxos().values()) {
for(CoinsInfo coinsInfo : adapter.selectedUtxos.values()) {
selectedKeyImages.add(coinsInfo.keyImage);
}
SendBottomSheetDialog sendDialog = new SendBottomSheetDialog();
@ -81,7 +81,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
});
churnUtxosButton.setOnClickListener(view1 -> {
ArrayList<String> selectedKeyImages = new ArrayList<>();
for(CoinsInfo coinsInfo : adapter.getSelectedUtxos().values()) {
for(CoinsInfo coinsInfo : adapter.selectedUtxos.values()) {
selectedKeyImages.add(coinsInfo.keyImage);
}
SendBottomSheetDialog sendDialog = new SendBottomSheetDialog();
@ -126,7 +126,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
}
boolean frozenExists = false, unfrozenExists = false, bothExist = false;
for(CoinsInfo selectedUtxo : adapter.getSelectedUtxos().values()) {
for(CoinsInfo selectedUtxo : adapter.selectedUtxos.values()) {
if(selectedUtxo.isFrozen() || UTXOService.getInstance().isCoinFrozen(selectedUtxo))
frozenExists = true;
else {
@ -135,7 +135,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
}
bothExist = frozenExists && unfrozenExists;
if (adapter.getSelectedUtxos().isEmpty()) {
if (adapter.selectedUtxos.isEmpty()) {
sendUtxosButton.setVisibility(View.GONE);
churnUtxosButton.setVisibility(View.GONE);
freezeUtxosButton.setVisibility(View.GONE);