2017-09-12 02:07:43 +00:00
|
|
|
package cy.agorise.crystalwallet.models;
|
|
|
|
|
|
|
|
import android.arch.persistence.room.ColumnInfo;
|
|
|
|
import android.arch.persistence.room.Entity;
|
2017-09-25 02:59:46 +00:00
|
|
|
import android.arch.persistence.room.ForeignKey;
|
2017-10-26 02:46:42 +00:00
|
|
|
import android.arch.persistence.room.Ignore;
|
2017-11-02 02:31:31 +00:00
|
|
|
import android.arch.persistence.room.Index;
|
2017-09-12 02:07:43 +00:00
|
|
|
import android.arch.persistence.room.PrimaryKey;
|
2017-09-18 02:38:05 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2018-06-10 18:35:06 +00:00
|
|
|
import android.support.v7.util.DiffUtil;
|
2017-09-12 02:07:43 +00:00
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
2017-09-13 16:12:22 +00:00
|
|
|
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
|
|
|
|
2017-09-12 02:07:43 +00:00
|
|
|
/**
|
2017-09-13 21:52:36 +00:00
|
|
|
* Represents a generic CryptoNet Transaction
|
|
|
|
*
|
2017-09-12 02:07:43 +00:00
|
|
|
* Created by Henry Varona on 11/9/2017.
|
|
|
|
*/
|
2017-11-02 02:31:31 +00:00
|
|
|
@Entity(
|
|
|
|
tableName="crypto_coin_transaction",
|
|
|
|
indices={
|
|
|
|
@Index(value={"account_id"}),
|
|
|
|
@Index(value={"id_currency"})
|
|
|
|
},
|
|
|
|
foreignKeys = {
|
|
|
|
@ForeignKey(
|
|
|
|
entity = CryptoNetAccount.class,
|
|
|
|
parentColumns = "id",
|
|
|
|
childColumns = "account_id",
|
|
|
|
onDelete = ForeignKey.CASCADE
|
|
|
|
),
|
|
|
|
@ForeignKey(entity = CryptoCurrency.class,
|
|
|
|
parentColumns = "id",
|
|
|
|
childColumns = "id_currency",
|
|
|
|
onDelete = ForeignKey.CASCADE
|
2017-09-25 02:59:46 +00:00
|
|
|
)
|
2017-11-02 02:31:31 +00:00
|
|
|
}
|
|
|
|
)
|
2017-09-12 02:07:43 +00:00
|
|
|
public class CryptoCoinTransaction {
|
|
|
|
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
|
|
|
* The account associated with this transaction
|
|
|
|
*/
|
2017-10-26 02:46:42 +00:00
|
|
|
@Ignore
|
2017-09-12 02:07:43 +00:00
|
|
|
protected CryptoNetAccount account;
|
|
|
|
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
|
|
|
* The id on the database
|
|
|
|
*/
|
2017-09-12 02:07:43 +00:00
|
|
|
@PrimaryKey(autoGenerate = true)
|
|
|
|
@ColumnInfo(name="id")
|
2017-09-27 02:24:23 +00:00
|
|
|
protected long id;
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
|
|
|
* The full date of this transaction
|
|
|
|
*/
|
2017-09-12 02:07:43 +00:00
|
|
|
@ColumnInfo(name="date")
|
|
|
|
protected Date date;
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
|
|
|
* If this transaction is input of the account associated with it
|
|
|
|
*/
|
2017-09-12 02:07:43 +00:00
|
|
|
@ColumnInfo(name="is_input")
|
|
|
|
protected boolean isInput;
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
|
|
|
* The id of the account assoiciated, this is used for the foreign key definition
|
|
|
|
*/
|
2017-09-12 02:07:43 +00:00
|
|
|
@ColumnInfo(name="account_id")
|
2017-09-27 02:24:23 +00:00
|
|
|
protected long accountId;
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
|
|
|
* The amount of asset is moved in this transaction
|
|
|
|
*/
|
2017-09-13 16:12:22 +00:00
|
|
|
@ColumnInfo(name="amount")
|
2017-10-16 00:23:44 +00:00
|
|
|
protected long amount;
|
2017-09-14 02:09:58 +00:00
|
|
|
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
2017-09-25 02:59:46 +00:00
|
|
|
* The id of the Crypto Currency to use in the database
|
2017-09-13 21:52:36 +00:00
|
|
|
*/
|
2017-09-25 02:59:46 +00:00
|
|
|
@ColumnInfo(name="id_currency")
|
|
|
|
protected int idCurrency;
|
2017-09-13 21:52:36 +00:00
|
|
|
/**
|
|
|
|
* If this transaction is confirmed
|
|
|
|
*/
|
2017-09-13 16:12:22 +00:00
|
|
|
@ColumnInfo(name="is_confirmed")
|
|
|
|
protected boolean isConfirmed;
|
2017-09-12 02:07:43 +00:00
|
|
|
|
2017-09-14 03:13:37 +00:00
|
|
|
/**
|
|
|
|
* The address or account the amount of assets comes from
|
|
|
|
*/
|
2017-09-14 01:06:51 +00:00
|
|
|
@ColumnInfo(name="from")
|
|
|
|
protected String from;
|
2017-09-14 03:13:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The address or account the amount of assets goes to
|
|
|
|
*/
|
2017-09-14 01:06:51 +00:00
|
|
|
@ColumnInfo(name="to")
|
|
|
|
protected String to;
|
|
|
|
|
2017-09-14 03:13:37 +00:00
|
|
|
public String getFrom() { return from; }
|
2017-09-14 01:06:51 +00:00
|
|
|
|
2017-09-14 03:13:37 +00:00
|
|
|
public void setFrom(String from) { this.from = from; }
|
2017-09-14 01:06:51 +00:00
|
|
|
|
2017-09-14 03:13:37 +00:00
|
|
|
public String getTo() { return to; }
|
2017-09-14 01:06:51 +00:00
|
|
|
|
2017-09-14 03:13:37 +00:00
|
|
|
public void setTo(String to) { this.to = to; }
|
2017-09-14 01:06:51 +00:00
|
|
|
|
2017-09-27 02:24:23 +00:00
|
|
|
public long getAccountId() {
|
2017-09-12 02:07:43 +00:00
|
|
|
return accountId;
|
|
|
|
}
|
|
|
|
|
2017-09-27 02:24:23 +00:00
|
|
|
public void setAccountId(long accountId) {
|
2017-09-12 02:07:43 +00:00
|
|
|
this.accountId = accountId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CryptoNetAccount getAccount() {
|
|
|
|
return account;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAccount(CryptoNetAccount account) {
|
|
|
|
this.account = account;
|
|
|
|
}
|
|
|
|
|
2017-09-27 02:24:23 +00:00
|
|
|
public long getId() {
|
2017-09-12 02:07:43 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2017-09-27 02:24:23 +00:00
|
|
|
public void setId(long id) {
|
2017-09-12 02:07:43 +00:00
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Date getDate() {
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDate(Date date) {
|
|
|
|
this.date = date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getInput() {
|
|
|
|
return isInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInput(boolean input) {
|
|
|
|
this.isInput = input;
|
|
|
|
}
|
2017-09-14 03:13:37 +00:00
|
|
|
|
|
|
|
public boolean isConfirmed() { return isConfirmed; }
|
|
|
|
|
|
|
|
public void setConfirmed(boolean confirmed) { isConfirmed = confirmed; }
|
|
|
|
|
2017-10-16 00:23:44 +00:00
|
|
|
public long getAmount() { return amount; }
|
2017-09-14 03:13:37 +00:00
|
|
|
|
2017-10-16 00:23:44 +00:00
|
|
|
public void setAmount(long amount) { this.amount = amount; }
|
2017-09-14 03:13:37 +00:00
|
|
|
|
2017-09-25 02:59:46 +00:00
|
|
|
public int getIdCurrency() { return idCurrency; }
|
2017-09-14 03:13:37 +00:00
|
|
|
|
2017-09-25 02:59:46 +00:00
|
|
|
public void setIdCurrency(int idCurrency) { this.idCurrency = idCurrency; }
|
2017-09-18 02:38:05 +00:00
|
|
|
|
|
|
|
|
2018-06-10 18:35:06 +00:00
|
|
|
public static final DiffUtil.ItemCallback<CryptoCoinTransaction> DIFF_CALLBACK = new DiffUtil.ItemCallback<CryptoCoinTransaction>() {
|
2017-09-18 02:38:05 +00:00
|
|
|
@Override
|
|
|
|
public boolean areItemsTheSame(
|
|
|
|
@NonNull CryptoCoinTransaction oldTransaction, @NonNull CryptoCoinTransaction newTransaction) {
|
|
|
|
return oldTransaction.getId() == newTransaction.getId();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean areContentsTheSame(
|
|
|
|
@NonNull CryptoCoinTransaction oldTransaction, @NonNull CryptoCoinTransaction newTransaction) {
|
|
|
|
return oldTransaction.equals(newTransaction);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
|
|
|
|
CryptoCoinTransaction that = (CryptoCoinTransaction) o;
|
|
|
|
|
|
|
|
if (isInput != that.isInput) return false;
|
|
|
|
if (accountId != that.accountId) return false;
|
|
|
|
if (amount != that.amount) return false;
|
2017-09-25 02:59:46 +00:00
|
|
|
if (idCurrency != that.idCurrency) return false;
|
2017-09-18 02:38:05 +00:00
|
|
|
if (isConfirmed != that.isConfirmed) return false;
|
|
|
|
if (date != null ? !date.equals(that.date) : that.date != null) return false;
|
|
|
|
if (from != null ? !from.equals(that.from) : that.from != null) return false;
|
|
|
|
return to != null ? to.equals(that.to) : that.to == null;
|
|
|
|
|
|
|
|
}
|
2017-09-12 02:07:43 +00:00
|
|
|
}
|