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 no more api23 support #3088

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,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.8-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.
14 changes: 4 additions & 10 deletions app/src/androidTest/java/com/alphawallet/app/util/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.content.Context;
import android.view.KeyEvent;
import android.view.View;

import android.view.inputmethod.InputMethodManager;

import androidx.test.espresso.PerformException;
Expand All @@ -25,16 +24,13 @@
import androidx.test.espresso.util.HumanReadables;
import androidx.test.espresso.util.TreeIterables;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

import java.util.concurrent.TimeoutException;
import com.alphawallet.app.R;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

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

public class Helper
{
Expand Down Expand Up @@ -80,12 +76,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
61 changes: 43 additions & 18 deletions app/src/main/java/com/alphawallet/app/entity/tokens/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ public Ticket(Token oldTicket, List<BigInteger> balances)
}

@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 All @@ -88,23 +91,25 @@ public List<BigInteger> pruneIDList(String idListStr, int quantity)
// .map(s -> Numeric.toBigInt(s)).toList().blockingGet();
if (quantity >= idList.size()) return idList;
List<BigInteger> pruneList = new ArrayList<>();
for (int i = 0; i < quantity; i++) pruneList.add(idList.get(i));
for (int i = 0; i < quantity; i++)
{
pruneList.add(idList.get(i));
}

return pruneList;
}

@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 @@ -141,6 +146,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 @@ -181,6 +187,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 @@ -194,7 +201,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 @@ -230,7 +237,8 @@ private List<BigInteger> tokenIdsToTokenIndices(List<BigInteger> tokenIds)
}
}
}
catch (Exception e) {
catch (Exception e)
{
indexList = null;
}

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

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

Expand All @@ -296,7 +305,10 @@ public boolean hasArrayBalance()
}

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

@Override
public List<BigInteger> getNonZeroArrayBalance()
Expand All @@ -316,10 +328,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 +356,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 +370,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 @@ -273,15 +273,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 @@ -49,7 +49,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 @@ -82,6 +83,7 @@ public Observable<Integer> handleFeemasterImport(String url, Wallet wallet, long

/**
* Use API to determine tokenscript validity
*
* @param tokenScriptFile
* @return
*/
Expand Down Expand Up @@ -165,9 +167,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 @@ -206,7 +206,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 @@ -317,7 +318,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 @@ -976,16 +976,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