Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2850 remove api23 support #2887

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ android {
versionName "3.60"

applicationId "io.stormbird.wallet"
minSdkVersion 23
minSdkVersion 24
targetSdkVersion 32
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
testInstrumentationRunnerArguments clearPackageData: 'true'
Expand Down Expand Up @@ -243,8 +243,7 @@ dependencies {
// WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!

// Ethereum client
//implementation "org.web3j:core:4.8.8-android"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.web3j:core:4.8.7-android"
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
implementation 'org.slf4j:slf4j-api:2.0.0-alpha7'
Expand Down
Binary file removed app/libs/abi-4.8.8-android.jar
Binary file not shown.
Binary file removed app/libs/core-4.8.8-android.jar
Binary file not shown.
Binary file removed app/libs/crypto-4.8.8-android.jar
Binary file not shown.
Binary file removed app/libs/rlp-4.8.8-android.jar
Binary file not shown.
Binary file removed app/libs/utils-4.8.8-android.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.hamcrest.Matchers;

import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

public class Helper
{
Expand Down Expand Up @@ -70,12 +71,10 @@ public void perform(final UiController uiController, final View view)

do
{
for (View child : TreeIterables.breadthFirstViewTraversal(view.getRootView()))
Iterable<View> views = TreeIterables.breadthFirstViewTraversal(view.getRootView());
if (Stream.of(views).anyMatch(matcher::matches))
{
if (matcher.matches(child))
{
return;
}
return;
}

uiController.loopMainThreadForAtLeast(50);
Expand Down
27 changes: 16 additions & 11 deletions app/src/main/java/com/alphawallet/app/entity/ContractLocator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.alphawallet.app.entity;

import static java.util.stream.Collectors.toList;

import android.os.Parcel;
import android.os.Parcelable;

Expand All @@ -9,6 +11,7 @@
import com.alphawallet.token.entity.ContractInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -44,21 +47,20 @@ protected ContractLocator(Parcel in)

public boolean equals(Token token)
{
return (token != null && address != null && chainId == token.tokenInfo.chainId && address.equalsIgnoreCase(token.getAddress()) );
return (token != null && address != null && chainId == token.tokenInfo.chainId && address.equalsIgnoreCase(token.getAddress()));
}

public boolean equals(TokenCardMeta token)
{
return TokensRealmSource.databaseKey(chainId, address).equalsIgnoreCase(token.tokenId);
}

/* replace this with a one-liner use of stream when we up our minSdkVersion to 24 */
public static ContractLocator[] fromAddresses(String[] addresses, long chainID) {
ContractLocator[] retval = new ContractLocator[addresses.length];
for (int i=0; i<addresses.length; i++) {
retval[i] = new ContractLocator(addresses[i], chainID);
}
return retval;
public static ContractLocator[] fromAddresses(String[] addresses, long chainID)
{
return Arrays.stream(addresses)
.map(address -> new ContractLocator(address, chainID))
.collect(toList())
.toArray(new ContractLocator[]{});
}

public static List<ContractLocator> fromContractInfo(ContractInfo cInfo)
Expand All @@ -76,14 +78,17 @@ public static List<ContractLocator> fromContractInfo(ContractInfo cInfo)
return retVal;
}

public static final Creator<ContractLocator> CREATOR = new Creator<ContractLocator>() {
public static final Creator<ContractLocator> CREATOR = new Creator<ContractLocator>()
{
@Override
public ContractLocator createFromParcel(Parcel in) {
public ContractLocator createFromParcel(Parcel in)
{
return new ContractLocator(in);
}

@Override
public ContractLocator[] newArray(int size) {
public ContractLocator[] newArray(int size)
{
return new ContractLocator[size];
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* Created by James on 2/02/2018.
*
* <p>
* TransactionDecoder currently only decode a transaction input in the
* string format, which is strictly a string starting with "0x" and
* with an even number of hex digits followed. (Probably should be
Expand Down Expand Up @@ -468,17 +468,13 @@ public Sign.SignatureData getSignatureData(TransactionInput data)

public int[] getIndices(TransactionInput data)
{
int[] indices = null;
if (data != null && data.arrayValues != null)
if (data == null || data.arrayValues == null)
{
indices = new int[data.arrayValues.size()];
for (int i = 0; i < data.arrayValues.size(); i++)
{
indices[i] = data.arrayValues.get(i).intValue();
}
return null;
}

return indices;
return data.arrayValues.stream()
.mapToInt(BigInteger::intValue)
.toArray();
}

public static String buildMethodId(String methodSignature)
Expand Down
66 changes: 46 additions & 20 deletions app/src/main/java/com/alphawallet/app/entity/tokens/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,37 @@ public class Ticket extends Token
private final List<BigInteger> balanceArray;
private boolean isMatchedInXML = false;

public Ticket(TokenInfo tokenInfo, List<BigInteger> balances, long blancaTime, String networkName, ContractType type) {
public Ticket(TokenInfo tokenInfo, List<BigInteger> balances, long blancaTime, String networkName, ContractType type)
{
super(tokenInfo, BigDecimal.ZERO, blancaTime, networkName, type);
this.balanceArray = balances;
balance = balanceArray != null ? BigDecimal.valueOf(balanceArray.size()) : BigDecimal.ZERO;
group = TokenGroup.NFT;
}

public Ticket(TokenInfo tokenInfo, String balances, long blancaTime, String networkName, ContractType type) {
public Ticket(TokenInfo tokenInfo, String balances, long blancaTime, String networkName, ContractType type)
{
super(tokenInfo, BigDecimal.ZERO, blancaTime, networkName, type);
this.balanceArray = stringHexToBigIntegerList(balances);
balance = BigDecimal.valueOf(balanceArray.size());
group = TokenGroup.NFT;
}

@Override
public String getStringBalanceForUI(int scale) {
public String getStringBalanceForUI(int scale)
{
return String.valueOf(getTokenCount());
}

@Override
public boolean hasPositiveBalance() {
public boolean hasPositiveBalance()
{
return (getTokenCount() > 0);
}

@Override
public String getFullBalance() {
public String getFullBalance()
{
if (balanceArray == null) return "no tokens";
else return Utils.bigIntListToString(balanceArray, true);
}
Expand Down Expand Up @@ -94,15 +99,14 @@ public List<BigInteger> pruneIDList(String idListStr, int quantity)
@Override
public int getTokenCount()
{
int count = 0;
if (balanceArray != null)
if (balanceArray == null)
{
for (BigInteger id : balanceArray)
{
if (id.compareTo(BigInteger.ZERO) != 0) count++;
}
return 0;
}
return count;

return (int) balanceArray.stream()
.filter(id -> id.compareTo(BigInteger.ZERO) != 0)
.count();
}

@Override
Expand Down Expand Up @@ -139,6 +143,7 @@ public int getContractType()

/**
* Convert a list of TicketID's into an Index list corresponding to those indices
*
* @param ticketIds
* @return
*/
Expand Down Expand Up @@ -179,6 +184,7 @@ public List<BigInteger> ticketIdListToIndexList(List<BigInteger> ticketIds)

/**
* Convert a String list of ticket IDs into a list of ticket indices
*
* @param userList
* @return
*/
Expand All @@ -192,7 +198,7 @@ public List<BigInteger> ticketIdStringToIndexList(String userList)
for (String id : ids)
{
//remove whitespace
String trim = id.trim();
String trim = id.trim();
BigInteger thisId = Numeric.toBigInt(trim);
idList.add(thisId);
}
Expand Down Expand Up @@ -228,7 +234,8 @@ private List<BigInteger> tokenIdsToTokenIndices(List<BigInteger> tokenIds)
}
}
}
catch (Exception e) {
catch (Exception e)
{
indexList = null;
}

Expand Down Expand Up @@ -288,7 +295,8 @@ protected org.web3j.abi.datatypes.DynamicArray getDynArray(List<BigInteger> indi
}

@Override
public boolean isToken() {
public boolean isToken()
{
return false;
}

Expand All @@ -299,13 +307,18 @@ public boolean hasArrayBalance()
}

@Override
public List<BigInteger> getArrayBalance() { return balanceArray; }
public List<BigInteger> getArrayBalance()
{
return balanceArray;
}

@Override
public List<BigInteger> getNonZeroArrayBalance()
{
List<BigInteger> nonZeroValues = new ArrayList<>();
for (BigInteger value : balanceArray) if (value.compareTo(BigInteger.ZERO) != 0 && !nonZeroValues.contains(value)) nonZeroValues.add(value);
for (BigInteger value : balanceArray)
if (value.compareTo(BigInteger.ZERO) != 0 && !nonZeroValues.contains(value))
nonZeroValues.add(value);
return nonZeroValues;
}

Expand All @@ -316,10 +329,21 @@ public boolean getIsSent(Transaction transaction)
}

@Override
public boolean isERC875() { return true; }
public boolean isNonFungible() { return true; }
public boolean isERC875()
{
return true;
}

public boolean isNonFungible()
{
return true;
}

@Override
public boolean hasGroupedTransfer() { return true; }
public boolean hasGroupedTransfer()
{
return true;
}

@Override
public boolean groupWithToken(TicketRange currentGroupingRange, TicketRangeElement newElement, long currentGroupTime)
Expand All @@ -333,6 +357,7 @@ public boolean groupWithToken(TicketRange currentGroupingRange, TicketRangeEleme
/**
* This function should return a String list of IDs suitable for submission to the token's transfer function
* For ERC875 it is a list of indices, so convert this list of TokenIDs to indices
*
* @param CSVstringIdList
* @return
*/
Expand All @@ -346,6 +371,7 @@ public String getTransferListFormat(String CSVstringIdList)
/**
* This function takes a list of tokenIds, and returns a BigInteger list suitable for this token's transfer function
* For ERC875 it is a list of indices, so convert this list of TokenIDs to indices
*
* @param tokenIds
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,7 @@ private String sanitiseString(String str)
}
else
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
return Html.fromHtml(str, FROM_HTML_MODE_COMPACT).toString();
}
else
{
//noinspection deprecation
return Html.fromHtml(str).toString();
}
return Html.fromHtml(str, FROM_HTML_MODE_COMPACT).toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class AlphaWalletService

public AlphaWalletService(OkHttpClient httpClient,
TransactionRepositoryType transactionRepository,
Gson gson) {
Gson gson)
{
this.httpClient = httpClient;
this.transactionRepository = transactionRepository;
this.gson = gson;
Expand Down Expand Up @@ -85,6 +86,7 @@ public Observable<Integer> handleFeemasterImport(String url, Wallet wallet, long

/**
* Use API to determine tokenscript validity
*
* @param tokenScriptFile
* @return
*/
Expand Down Expand Up @@ -166,9 +168,7 @@ private Single<int[]> generateTicketArray(String indices, Ticket ticket)
{
return Single.fromCallable(() -> {
List<Integer> ticketIndices = Utils.stringIntsToIntegerList(indices);
int[] indicesArray = new int[ticketIndices.size()];
for (int i = 0; i < ticketIndices.size(); i++) indicesArray[i] = ticketIndices.get(i);
return indicesArray;
return ticketIndices.stream().mapToInt(Integer::intValue).toArray();
});
}

Expand Down Expand Up @@ -207,7 +207,8 @@ private Single<Integer> sendFeemasterTransaction(
byte[] tradeSig,
String contractAddress,
List<BigInteger> tokenIds
) {
)
{
return Single.fromCallable(() -> {
Integer result = 500; //fail by default
try
Expand Down Expand Up @@ -318,7 +319,7 @@ public Single<Boolean> checkFeemasterService(String url, long chainId, String ad

okhttp3.Response response = httpClient.newCall(request).execute();
int resultCode = response.code();
if ((resultCode/100) == 2) result = true;
if ((resultCode / 100) == 2) result = true;
Timber.tag("RESP").d(response.body().string());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,16 +913,7 @@ private void onError(Throwable throwable)

private TokenDefinition parseFile(InputStream xmlInputStream) throws Exception
{
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
locale = context.getResources().getConfiguration().getLocales().get(0);
}
else
{
locale = context.getResources().getConfiguration().locale;
}

Locale locale = context.getResources().getConfiguration().getLocales().get(0);
return new TokenDefinition(
xmlInputStream, locale, this);
}
Expand Down
Loading