diff --git a/app/src/androidTest/java/com/alphawallet/app/CustomSettingsTest.java b/app/src/androidTest/java/com/alphawallet/app/CustomSettingsTest.java new file mode 100644 index 0000000000..35c8638f36 --- /dev/null +++ b/app/src/androidTest/java/com/alphawallet/app/CustomSettingsTest.java @@ -0,0 +1,39 @@ +package com.alphawallet.app; + +import static com.alphawallet.app.assertions.Should.shouldSee; +import static com.alphawallet.app.steps.Steps.createNewWallet; +import static com.alphawallet.app.util.Helper.waitUntilLoaded; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + +import com.alphawallet.app.util.Helper; + +import org.junit.Test; + +import java.io.File; +import java.net.URL; + +public class CustomSettingsTest extends BaseE2ETest +{ + private static File getFileFromPath(Object obj) + { + ClassLoader classLoader = obj.getClass().getClassLoader(); + assert classLoader != null; + URL resource = classLoader.getResource("assets/custom_view_settings.json"); + return new File(resource.getPath()); + } + + @Test + public void fileObjectShouldNotBeNull() throws Exception + { + File file = getFileFromPath(this); + assertThat(file, notNullValue()); + + createNewWallet(); + Helper.wait(1); + shouldSee(R.id.back); + waitUntilLoaded(); + } + +} + diff --git a/app/src/main/assets/custom_view_settings.json b/app/src/main/assets/custom_view_settings.json new file mode 100644 index 0000000000..1677354c6b --- /dev/null +++ b/app/src/main/assets/custom_view_settings.json @@ -0,0 +1,41 @@ +{ + "exclusive_chains": [ + { + "chain": 1 + } + ], + "locked_chains": [ + { + "chain": 1 + }, + { + "chain": 4 + }, + { + "chain": 10 + } + ], + "locked_tokens": [ + { + "tokenAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", + "tokenName": "USD Coin", + "tokenSymbol": "USDC", + "tokenDecimals": 6, + "isEnabled": true, + "chainId": 1 + } + ], + "dark_mode": false, + "isShowContractAddress": true, + "startupDelay": 0, + "imageOverride": 0, + "isHideDappBrowser": false, + "isHideTabBar": false, + "isHasDirectTransfer": true, + "isCanChangeWallets": true, + "isHideEIP681": false, + "isCanAddTokens": true, + "isShowManageTokens": true, + "isShowAllNetworks": false, + "getDecimalPlaces": 5 +} diff --git a/app/src/main/java/com/alphawallet/app/di/RepositoriesModule.java b/app/src/main/java/com/alphawallet/app/di/RepositoriesModule.java index 56cf427dab..706c85aaa3 100644 --- a/app/src/main/java/com/alphawallet/app/di/RepositoriesModule.java +++ b/app/src/main/java/com/alphawallet/app/di/RepositoriesModule.java @@ -30,6 +30,7 @@ import com.alphawallet.app.service.AnalyticsService; import com.alphawallet.app.service.AnalyticsServiceType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.GasService; import com.alphawallet.app.service.IPFSService; import com.alphawallet.app.service.IPFSServiceType; @@ -178,9 +179,9 @@ TokenRepositoryType provideTokenRepository( @Singleton @Provides - TokenLocalSource provideRealmTokenSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository) + TokenLocalSource provideRealmTokenSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository, CustomSettings customSettings) { - return new TokensRealmSource(realmManager, ethereumNetworkRepository); + return new TokensRealmSource(realmManager, ethereumNetworkRepository, customSettings); } @Singleton @@ -196,9 +197,10 @@ TokensService provideTokensServices(EthereumNetworkRepositoryType ethereumNetwor TokenRepositoryType tokenRepository, TickerService tickerService, OpenSeaService openseaService, - AnalyticsServiceType analyticsService) + AnalyticsServiceType analyticsService, + CustomSettings customSettings) { - return new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, openseaService, analyticsService); + return new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, openseaService, analyticsService, customSettings); } @Singleton @@ -262,6 +264,13 @@ AssetDefinitionService providingAssetDefinitionServices(IPFSServiceType ipfsServ return new AssetDefinitionService(ipfsService, ctx, notificationService, realmManager, tokensService, tls, alphaService); } + @Singleton + @Provides + CustomSettings provideCustomSettings(@ApplicationContext Context context) + { + return new CustomSettings(context); + } + @Singleton @Provides KeyService provideKeyService(@ApplicationContext Context ctx, AnalyticsServiceType analyticsService) diff --git a/app/src/main/java/com/alphawallet/app/entity/CustomViewSettings.java b/app/src/main/java/com/alphawallet/app/entity/CustomViewSettings.java deleted file mode 100644 index 119b0873ba..0000000000 --- a/app/src/main/java/com/alphawallet/app/entity/CustomViewSettings.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.alphawallet.app.entity; - -import android.content.Context; - -import com.alphawallet.app.C; -import com.alphawallet.app.entity.tokens.Token; -import com.alphawallet.app.entity.tokens.TokenCardMeta; -import com.alphawallet.app.entity.tokens.TokenInfo; -import com.alphawallet.app.repository.entity.RealmToken; -import com.alphawallet.app.service.TokensService; -import com.alphawallet.app.ui.widget.entity.NetworkItem; -import com.alphawallet.ethereum.EthereumNetworkBase; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ConcurrentLinkedQueue; - -import static com.alphawallet.ethereum.EthereumNetworkBase.MAINNET_ID; - -public class CustomViewSettings -{ - public static final long primaryChain = MAINNET_ID; - private static final String primaryChainName = C.ETHEREUM_NETWORK_NAME; - - //You can use the settings in this file to customise the wallet appearance - - //IF you want to re-order the the way chains appear in the wallet, see this line in EthereumNetworkBase: - //private static final List hasValue = new ArrayList<>(Arrays.asList( ... - //... and read the comment above it - - //Ensures certain tokens are always visible, even if zero balance (see also 'showZeroBalance()' below). - //See also lockedChains. You can also lock the chains that are displayed on. - //If you leave the locked chains empty, the token will appear if the chain is selected - private static final List lockedTokens = Arrays.asList( - // new TokenInfo(String TokenAddress, String TokenName, String TokenSymbol, int TokenDecimals, boolean isEnabled, long ChainId) - //new TokenInfo("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "USD Coin", "USDC", 6, true, EthereumNetworkBase.MAINNET_ID), - //new TokenInfo("0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E", "Compound BAT", "CBAT", 8, true, EthereumNetworkBase.MAINNET_ID) - ); - - //List of chains that wallet can show - //If blank, enable the user filter select dialog, if there are any entries here, the select network dialog is disabled - //Note: you should always enable the chainId corresponding to the chainIDs in the lockedTokens. - private static final List lockedChains = Arrays.asList( - //EthereumNetworkBase.MAINNET_ID //EG only show Main, xdai, classic and two testnets. Don't allow user to select any others - //EthereumNetworkBase.XDAI_ID, - //EthereumNetworkBase.RINKEBY_ID, //You can mix testnets and mainnets, but probably shouldn't as it may result in people getting scammed - //EthereumNetworkBase.GOERLI_ID - ); - - public static final List alwaysVisibleChains = Arrays.asList( - EthereumNetworkBase.MAINNET_ID - ); - - public static boolean alwaysShow(long chainId) - { - return alwaysVisibleChains.contains(chainId); - } - - //TODO: Wallet can only show the above tokens - private static final boolean onlyShowTheseTokens = true; - - public static List getLockedTokens() - { - return lockedTokens; - } - - public static List getLockedChains() - { - return lockedChains; - } - - //TODO: Not yet implemented; code will probably live in TokensService & TokenRealmSource - public static boolean onlyShowLockedTokens() - { - return onlyShowTheseTokens; - } - - //Does main wallet page show tokens with zero balance? NB: any 'Locked' tokens above will always be shown - public static boolean showZeroBalance() { return false; } - - public static boolean tokenCanBeDisplayed(TokenCardMeta token) - { - return token.type == ContractType.ETHEREUM || token.isEnabled || isLockedToken(token.getChain(), token.getAddress()); - } - - private static boolean isLockedToken(long chainId, String contractAddress) - { - for (TokenInfo tInfo : lockedTokens) - { - if (tInfo.chainId == chainId && tInfo.address.equalsIgnoreCase(contractAddress)) return true; - } - - return false; - } - - public static ContractType checkKnownTokens(TokenInfo tokenInfo) - { - return ContractType.OTHER; - } - - public static boolean showContractAddress(Token token) - { - return true; - } - - public static long startupDelay() - { - return 0; - } - - public static int getImageOverride() - { - return 0; - } - - //Switch off dapp browser - public static boolean hideDappBrowser() - { - return false; - } - - //Hides the filter tab bar at the top of the wallet screen (ALL/CURRENCY/COLLECTIBLES) - public static boolean hideTabBar() - { - return false; - } - - //Use to switch off direct transfer, only use magiclink transfer - public static boolean hasDirectTransfer() - { - return true; - } - - //Allow multiple wallets (true) or single wallet mode (false) - public static boolean canChangeWallets() - { - return true; - } - - //Hide EIP681 generation (Payment request, generates a QR code another wallet user can scan to have all payment fields filled in) - public static boolean hideEIP681() { return false; } - - //In main wallet menu, if wallet allows adding new tokens - public static boolean canAddTokens() { return true; } - - //Implement minimal dappbrowser with no URL bar. You may want this if you want your browser to point to a specific website and only - // allow navigation within that website - // use this setting in conjunction with changing DEFAULT_HOMEPAGE in class EthereumNetworkBase - public static boolean minimiseBrowserURLBar() { return false; } - - //Allow showing token management view - public static boolean showManageTokens() { return true; } - - //Show all networks in Select Network screen. Set to `true` to show only filtered networks. - public static boolean showAllNetworks() { return false; } - - public static String getDecimalFormat() { return "0.####E0"; } - - public static int getDecimalPlaces() { return 5; } - - //set if the Input Amount defaults to Fiat or Crypto - public static boolean inputAmountFiatDefault() - { - return false; - } -} diff --git a/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java b/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java index da7d5ad0ee..43ce9bb294 100644 --- a/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java +++ b/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java @@ -72,11 +72,11 @@ import com.alphawallet.app.R; import com.alphawallet.app.entity.ContractLocator; import com.alphawallet.app.entity.ContractType; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.NetworkInfo; import com.alphawallet.app.entity.Wallet; import com.alphawallet.app.entity.tokens.Token; import com.alphawallet.app.entity.tokens.TokenInfo; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.util.Utils; import com.alphawallet.token.entity.ChainSpec; import com.google.gson.Gson; @@ -895,7 +895,7 @@ public List getSelectedFilters(boolean isMainNet) @Override public Long getDefaultNetwork(boolean isMainNet) { - return isMainNet ? CustomViewSettings.primaryChain : GOERLI_ID; + return isMainNet ? CustomSettings.primaryChain : GOERLI_ID; } @Override @@ -1084,14 +1084,9 @@ public static List extraChains() return null; } - public static List addDefaultNetworks() - { - return CustomViewSettings.alwaysVisibleChains; - } - public static ContractLocator getOverrideToken() { - return new ContractLocator("", CustomViewSettings.primaryChain, ContractType.ETHEREUM); + return new ContractLocator("", CustomSettings.primaryChain, ContractType.ETHEREUM); } @Override diff --git a/app/src/main/java/com/alphawallet/app/repository/TokensRealmSource.java b/app/src/main/java/com/alphawallet/app/repository/TokensRealmSource.java index d8c78b8ccc..7e11c5ff59 100644 --- a/app/src/main/java/com/alphawallet/app/repository/TokensRealmSource.java +++ b/app/src/main/java/com/alphawallet/app/repository/TokensRealmSource.java @@ -8,7 +8,6 @@ import android.util.Pair; import com.alphawallet.app.entity.ContractType; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.NetworkInfo; import com.alphawallet.app.entity.Wallet; import com.alphawallet.app.entity.nftassets.NFTAsset; @@ -25,6 +24,7 @@ import com.alphawallet.app.repository.entity.RealmTokenMapping; import com.alphawallet.app.repository.entity.RealmTokenTicker; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.RealmManager; import com.alphawallet.app.util.Utils; import com.alphawallet.token.entity.ContractAddress; @@ -62,10 +62,13 @@ public class TokensRealmSource implements TokenLocalSource { private final RealmManager realmManager; private final EthereumNetworkRepositoryType ethereumNetworkRepository; + private final CustomSettings customSettings; - public TokensRealmSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository) { + public TokensRealmSource(RealmManager realmManager, EthereumNetworkRepositoryType ethereumNetworkRepository, CustomSettings customSettings) + { this.realmManager = realmManager; this.ethereumNetworkRepository = ethereumNetworkRepository; + this.customSettings = customSettings; } @Override @@ -472,7 +475,7 @@ else if (!newBalance.equals(currentBalance) || !checkEthToken(realm, token)) } if (!realmToken.isVisibilityChanged() && realmToken.isEnabled() && newBalance != null && newBalance.equals("0") - && !(token.isEthereum() && CustomViewSettings.alwaysShow(token.tokenInfo.chainId))) + && !(token.isEthereum() && customSettings.alwaysShow(token.tokenInfo.chainId))) { realm.executeTransaction(r -> { realmToken.setEnabled(false); @@ -481,7 +484,7 @@ else if (!newBalance.equals(currentBalance) || !checkEthToken(realm, token)) } else if ((!realmToken.isVisibilityChanged() && !realmToken.isEnabled()) && (token.balance.compareTo(BigDecimal.ZERO) > 0 || - (token.isEthereum() && CustomViewSettings.alwaysShow(token.tokenInfo.chainId) && !realmToken.isEnabled()))) // enable if base token should be showing + (token.isEthereum() && customSettings.alwaysShow(token.tokenInfo.chainId) && !realmToken.isEnabled()))) // enable if base token should be showing { realm.executeTransaction(r -> { realmToken.setEnabled(true); @@ -492,7 +495,7 @@ else if ((!realmToken.isVisibilityChanged() && !realmToken.isEnabled()) && else { balanceChanged = true; - if (token.isEthereum() && CustomViewSettings.alwaysShow(token.tokenInfo.chainId)) token.tokenInfo.isEnabled = true; + if (token.isEthereum() && customSettings.alwaysShow(token.tokenInfo.chainId)) token.tokenInfo.isEnabled = true; //write token realm.executeTransaction(r -> { token.balance = balance; diff --git a/app/src/main/java/com/alphawallet/app/service/CustomSettings.java b/app/src/main/java/com/alphawallet/app/service/CustomSettings.java new file mode 100644 index 0000000000..bc3b3f7318 --- /dev/null +++ b/app/src/main/java/com/alphawallet/app/service/CustomSettings.java @@ -0,0 +1,389 @@ +package com.alphawallet.app.service; + +import static com.alphawallet.ethereum.EthereumNetworkBase.MAINNET_ID; + +import android.content.Context; +import android.util.LongSparseArray; + +import com.alphawallet.app.entity.ContractType; +import com.alphawallet.app.entity.tokens.Token; +import com.alphawallet.app.entity.tokens.TokenCardMeta; +import com.alphawallet.app.entity.tokens.TokenInfo; +import com.google.gson.Gson; +import com.google.gson.JsonElement; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; + +public class CustomSettings +{ + public final String CUSTOM_SETTINGS_FILENAME = "custom_view_settings.json"; + public static final long primaryChain = MAINNET_ID; + private final Context context; + ConcurrentLinkedQueue loadLockedCachedChains = new ConcurrentLinkedQueue<>(); + ConcurrentLinkedQueue loadExclusiveCachedChains = new ConcurrentLinkedQueue<>(); + private final LongSparseArray> loadLockedTokens = new LongSparseArray<>(); + public String getJsonString = ""; + public Boolean loaded = false; + + public CustomSettings(Context context) + { + this.context = context; + } + + public JSONArray loadDataFromJsonArray(String chainName) + { + JSONArray jsonArray = new JSONArray(); + try + { + + String lockedChains = loadJSONStringFromAsset(); + if (lockedChains != null) + { + JSONObject customSettingsJsonObject = new JSONObject(lockedChains); + jsonArray = customSettingsJsonObject.getJSONArray(chainName); + } + } + catch (JSONException err) + { + err.printStackTrace(); + } + + return jsonArray; + } + + //TODO: Cache locked chains & Tokens in an ConcurrentLinkedQueue / ConcurrentHashMap + // : The approach I would take is to have a 'load' function which first checks if there's already + // : data in the two cache mappings, if there's not then check the 'loaded' flag. If that is + // : set false then load and populate the Queue/Map + // : then, just use the mappings from there. Add a call to the load function each time you use the data. + // : Android can memory scavenge those mappings at any time if the wallet is paged out, + // : Then they'll be empty when the wallet is paged back in. + + public ArrayList getChainsFromJsonFile() //<-- TODO: chainName is redundant + { + ArrayList chains = new ArrayList<>(); + if (loadLockedCachedChains.size() <= 0) + { + JSONArray chainsArray = loadDataFromJsonArray("locked_chains"); + if (chainsArray.length() > 0) + { + try + { + for (int i = 0; i < chainsArray.length(); i++) + { + JSONObject chainObject = chainsArray.getJSONObject(i); + Long chain = chainObject.getLong("chain"); + chains.add(chain); + } + } + catch (JSONException err) + { + err.printStackTrace(); + } + loadLockedCachedChains.clear(); + loadLockedCachedChains.addAll(chains); + } + } + chains.addAll(loadLockedCachedChains); + return chains; + } + + public ConcurrentHashMap getLockedTokensFromJsonFile() //<-- TODO: chainName is redundant + { + ConcurrentHashMap chains = new ConcurrentHashMap<>(); + Gson gson = new Gson(); + JSONArray chainsArray = loadDataFromJsonArray("locked_tokens"); + if (chainsArray.length() > 0) + { + loadLockedTokens.clear(); + //TODO: use GSON class array load (see "private EtherscanTransaction[] getEtherscanTransactions" for how-to) + // : this will need a static class within this class + // : you can then traverse (for x : y) that list and have cleaner code + // : esp if you add a getTokenInfo from that static internal class. + TokenInfo[] lockedTokenInfo = gson.fromJson(chainsArray.toString(), TokenInfo[].class); + int i = 0; + for (TokenInfo tokenInfo : lockedTokenInfo) + { + chains.put(String.valueOf(i), tokenInfo); + loadLockedTokens.put(tokenInfo.chainId, chains); + i++; + } + } + + return chains; + } + + public JSONArray getChainsArrayJsonFile() //<--- TODO: Redundant + { + JSONArray chainsArray = new JSONArray(); + try + { + String lockedChains = loadJSONStringFromAsset(); + JSONObject customSettingsJsonObject = new JSONObject(lockedChains); + chainsArray = customSettingsJsonObject.getJSONArray("locked_chains"); + } + catch (JSONException err) + { + err.printStackTrace(); + } + + return chainsArray; + } + + //TODO: Doesn't need caching (no action) + public Boolean getDarkModeValueFromJsonFile(String chainName) + { + boolean darkModeValue = false; + try + { + String darkMode = loadJSONStringFromAsset(); + if (darkMode != null) + { + JSONObject customSettingsJsonObject = new JSONObject(darkMode); + darkModeValue = customSettingsJsonObject.getBoolean("dark_mode"); + } + } + catch (JSONException err) + { + err.printStackTrace(); + } + return darkModeValue; + } + + // Function Use: Universal function to check if Json is already loaded or not. If it is already loaded then we will return the value directly from the variable else we will load the json data from asset. + public String loadJSONStringFromAsset() + { + try + { + if (getJsonString.isEmpty()) + { + Reader reader = new InputStreamReader(context.getAssets().open(CUSTOM_SETTINGS_FILENAME)); + JsonElement json = new Gson().fromJson(reader, JsonElement.class); + getJsonString = json.toString(); + } + } + catch (IOException ex) + { + ex.printStackTrace(); + return null; + } + + return getJsonString; + } + + + //TODO: Caching + public Boolean alwaysShow(long chainId) + { + ArrayList exclusiveChains = new ArrayList<>(); + if (loadExclusiveCachedChains.size() <= 0) + { + JSONArray chainsArray = loadDataFromJsonArray("exclusive_chains"); + if (chainsArray.length() > 0) + { + try + { + for (int i = 0; i < chainsArray.length(); i++) + { + JSONObject chainObject = chainsArray.getJSONObject(i); + Long chain = chainObject.getLong("chain"); + exclusiveChains.add(chain); + } + } + catch (JSONException err) + { + err.printStackTrace(); + } + loadExclusiveCachedChains.clear(); + loadExclusiveCachedChains.addAll(exclusiveChains); + + } + } + exclusiveChains.addAll(loadExclusiveCachedChains); + return exclusiveChains.contains(chainId); + } + + //TODO: Requires caching, since this will be called very frequently + // : Use a (final) mapping of locked tokens, from a load. + // : You'll need to check if the list is empty and if so flag a 'loaded', so we don't spam this list + public Boolean tokenCanBeDisplayed(TokenCardMeta token) + { + final ArrayList lockedTokens = new ArrayList<>(); + if (loadLockedTokens.size() > 0) + { + return lockedTokens.addAll(loadLockedTokens.get(primaryChain).values()); + } + else + { + return token.type == ContractType.ETHEREUM || token.isEnabled || isLockedToken(token.getChain(), token.getAddress()); + } + + } + + //TODO: Caching + public Boolean isLockedToken(long chainId, String contractAddress) + { + final ConcurrentHashMap lockedTokens = getLockedTokensFromJsonFile(); + Map mapping = loadLockedTokens.get(chainId); + return mapping.containsKey(contractAddress.toLowerCase(Locale.ROOT)); + } + + public ContractType checkKnownTokens(TokenInfo tokenInfo) + { + return ContractType.OTHER; + } + + public boolean showContractAddress(Token token) + { + return getBooleanValueFromJson(false, "isShowContractAddress"); + } + + public long startupDelay() + { + long startupDelayValue = 0; + try + { + String startupDelay = loadJSONStringFromAsset(); + if (startupDelay != null) + { + JSONObject customSettingsJsonObject = new JSONObject(startupDelay); + startupDelayValue = customSettingsJsonObject.getLong("startupDelay"); + } + } + catch (JSONException err) + { + err.printStackTrace(); + } + return startupDelayValue; + } + + public int getImageOverride() + { + return getIntegerValueFromJson(0, "imageOverride"); + } + + //Switch off dapp browser + public boolean hideDappBrowser() + { + return getBooleanValueFromJson(false, "isHideDappBrowser"); + } + + //Hides the filter tab bar at the top of the wallet screen (ALL/CURRENCY/COLLECTIBLES) + public boolean hideTabBar() + { + return getBooleanValueFromJson(false, "isHideTabBar"); + } + + //Use to switch off direct transfer, only use magiclink transfer + public boolean hasDirectTransfer() + { + return getBooleanValueFromJson(true, "isHasDirectTransfer"); + } + + //Allow multiple wallets (true) or single wallet mode (false) + public boolean canChangeWallets() + { + return getBooleanValueFromJson(true, "isCanChangeWallets"); + } + + //Hide EIP681 generation (Payment request, generates a QR code another wallet user can scan to have all payment fields filled in) + public boolean hideEIP681() + { + return getBooleanValueFromJson(false, "isHideEIP681"); + } + + //In main wallet menu, if wallet allows adding new tokens + public boolean canAddTokens() + { + return getBooleanValueFromJson(true, "isCanAddTokens"); + } + + //Implement minimal dappbrowser with no URL bar. You may want this if you want your browser to point to a specific website and only + // allow navigation within that website + // use this setting in conjunction with changing DEFAULT_HOMEPAGE in class EthereumNetworkBase + //Implement minimal dappbrowser with no URL bar. You may want this if you want your browser to point to a specific website and only + // allow navigation within that website + // use this setting in conjunction with changing DEFAULT_HOMEPAGE in class EthereumNetworkBase + public static boolean minimiseBrowserURLBar() + { + return false; + } + + //Allow showing token management view + public boolean showManageTokens() + { + return getBooleanValueFromJson(true, "isShowManageTokens"); + } + + //Show all networks in Select Network screen. Set to `true` to show only filtered networks. + public boolean showAllNetworks() + { + return getBooleanValueFromJson(false, "isShowAllNetworks"); + } + + public String getDecimalFormat() + { + return "0.####E0"; + } + + public int getDecimalPlaces() + { + return getIntegerValueFromJson(5, "getDecimalPlaces"); + } + + //set if the Input Amount defaults to Fiat or Crypto + public static boolean inputAmountFiatDefault() + { + return false; + } + + //Common function for returning the boolean value + public boolean getBooleanValueFromJson(boolean variableName, String jsonString) + { + try + { + String isHideDappBrowser = loadJSONStringFromAsset(); + if (isHideDappBrowser != null) + { + JSONObject customSettingsJsonObject = new JSONObject(isHideDappBrowser); + variableName = customSettingsJsonObject.getBoolean(jsonString); + } + } + catch (JSONException err) + { + err.printStackTrace(); + } + return variableName; + } + + //Common function for returning the integer value + public int getIntegerValueFromJson(int jsonValue, String jsonString) + { + int integerValue = jsonValue; + try + { + String imageOverride = loadJSONStringFromAsset(); + if (imageOverride != null) + { + JSONObject customSettingsJsonObject = new JSONObject(imageOverride); + integerValue = customSettingsJsonObject.getInt(jsonString); + } + } + catch (JSONException err) + { + err.printStackTrace(); + } + return integerValue; + } +} diff --git a/app/src/main/java/com/alphawallet/app/service/PriceAlertsService.java b/app/src/main/java/com/alphawallet/app/service/PriceAlertsService.java index 1eb02a6d95..552dfa9553 100644 --- a/app/src/main/java/com/alphawallet/app/service/PriceAlertsService.java +++ b/app/src/main/java/com/alphawallet/app/service/PriceAlertsService.java @@ -5,8 +5,10 @@ import android.os.Binder; import android.os.IBinder; +import com.alphawallet.app.C; import androidx.annotation.Nullable; +import com.alphawallet.app.C; import com.alphawallet.app.R; import com.alphawallet.app.entity.CurrencyItem; import com.alphawallet.app.entity.Wallet; @@ -59,6 +61,9 @@ public class PriceAlertsService extends Service @Inject AssetDefinitionService assetDefinitionService; + @Inject + CustomSettings customSettings; + @Nullable private Disposable heartBeatTimer; @@ -205,4 +210,4 @@ private String getIndicatorText(boolean isAbove) } return getString(R.string.price_alert_indicator_below); } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/alphawallet/app/service/TokensService.java b/app/src/main/java/com/alphawallet/app/service/TokensService.java index ae77ae3a99..5cedd843ab 100644 --- a/app/src/main/java/com/alphawallet/app/service/TokensService.java +++ b/app/src/main/java/com/alphawallet/app/service/TokensService.java @@ -10,12 +10,10 @@ import androidx.annotation.Nullable; import com.alphawallet.app.BuildConfig; -import com.alphawallet.app.C; import com.alphawallet.app.analytics.Analytics; import com.alphawallet.app.entity.AnalyticsProperties; import com.alphawallet.app.entity.ContractLocator; import com.alphawallet.app.entity.ContractType; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.NetworkInfo; import com.alphawallet.app.entity.ServiceSyncCallback; import com.alphawallet.app.entity.Wallet; @@ -74,6 +72,7 @@ public class TokensService private final TickerService tickerService; private final OpenSeaService openseaService; private final AnalyticsServiceType analyticsService; + private final CustomSettings customSettings; private final List networkFilter; private ContractLocator focusToken; private final ConcurrentLinkedDeque unknownTokens; @@ -110,12 +109,15 @@ public TokensService(EthereumNetworkRepositoryType ethereumNetworkRepository, TokenRepositoryType tokenRepository, TickerService tickerService, OpenSeaService openseaService, - AnalyticsServiceType analyticsService) { + AnalyticsServiceType analyticsService, + CustomSettings customSettings) + { this.ethereumNetworkRepository = ethereumNetworkRepository; this.tokenRepository = tokenRepository; this.tickerService = tickerService; this.openseaService = openseaService; this.analyticsService = analyticsService; + this.customSettings = customSettings; networkFilter = new ArrayList<>(); setupFilter(ethereumNetworkRepository.hasSetNetworkFilters()); focusToken = null; @@ -401,9 +403,10 @@ public void stopUpdateCycle() public void setupFilter(boolean userUpdated) { networkFilter.clear(); - if (CustomViewSettings.getLockedChains().size() > 0) + ArrayList LockedChains = customSettings.getChainsFromJsonFile(); + if (LockedChains.size() > 0) { - networkFilter.addAll(CustomViewSettings.getLockedChains()); + networkFilter.addAll(LockedChains); } else { @@ -960,7 +963,8 @@ private void blankFiltersForZeroBalance(boolean mainNetActive) } } - for (Long lockedChain : CustomViewSettings.getLockedChains()) + ArrayList getLockedChains = customSettings.getChainsFromJsonFile(); + for (Long lockedChain : getLockedChains) { if (!networkFilter.contains(lockedChain)) networkFilter.add(lockedChain); } @@ -1005,7 +1009,13 @@ private void addLockedTokens() mainNetActive = ethereumNetworkRepository.isMainNetSelected(); final String wallet = currentAddress; //ensure locked tokens are displaying - Observable.fromIterable(CustomViewSettings.getLockedTokens()) + ConcurrentHashMap tokenInfoConcurrentHashMap = customSettings.getLockedTokensFromJsonFile(); + ArrayList lockedTokens = new ArrayList<>(); + for (int i = 0; i < tokenInfoConcurrentHashMap.size(); i++) + { + lockedTokens.add(tokenInfoConcurrentHashMap.get(String.valueOf(i))); + } + Observable.fromIterable(lockedTokens) .forEach(info -> addToken(info, wallet) .flatMapCompletable(token -> enableToken(wallet, token)) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/com/alphawallet/app/ui/AddTokenActivity.java b/app/src/main/java/com/alphawallet/app/ui/AddTokenActivity.java index cc1631caf5..1be1dd0708 100644 --- a/app/src/main/java/com/alphawallet/app/ui/AddTokenActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/AddTokenActivity.java @@ -56,9 +56,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import timber.log.Timber; - import dagger.hilt.android.AndroidEntryPoint; +import timber.log.Timber; @AndroidEntryPoint public class AddTokenActivity extends BaseActivity implements AddressReadyCallback, StandardFunctionInterface, TokensAdapterCallback @@ -119,8 +118,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { lastCheck = ""; - adapter = new TokensAdapter(this, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), - null); + adapter = new TokensAdapter(this, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), viewModel.getCustomSettings(), null); adapter.setHasStableIds(true); adapter.showTestNetTips(); adapter.setFilterType(TokenFilter.NO_FILTER); diff --git a/app/src/main/java/com/alphawallet/app/ui/AssetDisplayActivity.java b/app/src/main/java/com/alphawallet/app/ui/AssetDisplayActivity.java index 333f7e16a6..e9f8a426e5 100644 --- a/app/src/main/java/com/alphawallet/app/ui/AssetDisplayActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/AssetDisplayActivity.java @@ -439,7 +439,7 @@ private void displayTokens() { handler.removeCallbacks(this); progressView.setVisibility(View.GONE); - adapter = new NonFungibleTokenAdapter(functionBar, token, viewModel.getAssetDefinitionService(), viewModel.getOpenseaService()); + adapter = new NonFungibleTokenAdapter(functionBar, token, viewModel.getAssetDefinitionService(), viewModel.getOpenseaService(), viewModel.getCustomSettings()); functionBar.setupFunctions(this, viewModel.getAssetDefinitionService(), token, adapter, token.getArrayBalance()); functionBar.setWalletType(wallet.type); tokenView.setAdapter(adapter); diff --git a/app/src/main/java/com/alphawallet/app/ui/DappBrowserFragment.java b/app/src/main/java/com/alphawallet/app/ui/DappBrowserFragment.java index 3162e176cc..2984c9677b 100644 --- a/app/src/main/java/com/alphawallet/app/ui/DappBrowserFragment.java +++ b/app/src/main/java/com/alphawallet/app/ui/DappBrowserFragment.java @@ -61,7 +61,6 @@ import com.alphawallet.app.analytics.Analytics; import com.alphawallet.app.entity.AnalyticsProperties; import com.alphawallet.app.entity.CryptoFunctions; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.DApp; import com.alphawallet.app.entity.FragmentMessenger; import com.alphawallet.app.entity.NetworkInfo; @@ -79,6 +78,7 @@ import com.alphawallet.app.repository.TokenRepository; import com.alphawallet.app.repository.TokensRealmSource; import com.alphawallet.app.repository.entity.RealmToken; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.WalletConnectService; import com.alphawallet.app.ui.QRScanning.QRScannerActivity; import com.alphawallet.app.ui.widget.OnDappHomeNavClickListener; @@ -317,7 +317,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c { LocaleUtils.setActiveLocale(getContext()); loadOnInit = null; - int webViewID = CustomViewSettings.minimiseBrowserURLBar() ? R.layout.fragment_webview_compact : R.layout.fragment_webview; + int webViewID = CustomSettings.minimiseBrowserURLBar() ? R.layout.fragment_webview_compact : R.layout.fragment_webview; View view = inflater.inflate(webViewID, container, false); initViewModel(); initView(view); @@ -547,7 +547,7 @@ private void initView(@NotNull View view) //If you are wondering about the strange way the menus are inflated - this is required to ensure //that the menu text gets created with the correct localisation under every circumstance MenuInflater inflater = new MenuInflater(LocaleUtils.getActiveLocaleContext(getContext())); - if (CustomViewSettings.minimiseBrowserURLBar()) + if (CustomSettings.minimiseBrowserURLBar()) { inflater.inflate(R.menu.menu_scan, toolbar.getMenu()); } diff --git a/app/src/main/java/com/alphawallet/app/ui/Erc20DetailActivity.java b/app/src/main/java/com/alphawallet/app/ui/Erc20DetailActivity.java index c5cc6ed960..5d94030ff5 100644 --- a/app/src/main/java/com/alphawallet/app/ui/Erc20DetailActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/Erc20DetailActivity.java @@ -49,7 +49,6 @@ import com.alphawallet.app.widget.CertifiedToolbarView; import com.alphawallet.app.widget.FunctionButtonBar; import com.alphawallet.token.entity.XMLDsigDescriptor; -import com.bumptech.glide.Glide; import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; @@ -60,9 +59,6 @@ import java.util.List; import dagger.hilt.android.AndroidEntryPoint; -import io.reactivex.Single; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.schedulers.Schedulers; import io.realm.Realm; import io.realm.RealmResults; @@ -273,7 +269,7 @@ public boolean canScrollVertically() return false; } }); - tokenViewAdapter = new TokensAdapter(null, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), null); + tokenViewAdapter = new TokensAdapter(null, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), viewModel.getCustomSettings(), null); tokenViewAdapter.updateToken(tokenMeta, true); tokenView.setAdapter(tokenViewAdapter); setTokenListener(); diff --git a/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java b/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java index 92d24aa0af..e3e34f8981 100644 --- a/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java @@ -57,7 +57,6 @@ import com.alphawallet.app.api.v1.entity.request.ApiV1Request; import com.alphawallet.app.entity.ContractLocator; import com.alphawallet.app.entity.CryptoFunctions; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.ErrorEnvelope; import com.alphawallet.app.entity.FragmentMessenger; import com.alphawallet.app.entity.HomeCommsInterface; @@ -260,7 +259,7 @@ public void onPageScrollStateChanged(int state) viewModel.splashReset().observe(this, this::onRequireInit); viewModel.defaultWallet().observe(this, this::onDefaultWallet); - if (CustomViewSettings.hideDappBrowser()) + if (viewModel.getCustomSettings().hideDappBrowser()) { removeDappBrowser(); } @@ -1216,7 +1215,7 @@ public ActivityResultLauncher gasSelectLauncher() return getGasSettings; } - private static class ScreenSlidePagerAdapter extends FragmentStateAdapter + private class ScreenSlidePagerAdapter extends FragmentStateAdapter { public ScreenSlidePagerAdapter(@NonNull FragmentActivity fragmentActivity) { @@ -1235,7 +1234,7 @@ public Fragment createFragment(int position) case ACTIVITY: return new ActivityFragment(); case DAPP_BROWSER: - if (CustomViewSettings.hideDappBrowser()) + if (viewModel.getCustomSettings().hideDappBrowser()) { return new BaseFragment(); } @@ -1255,3 +1254,4 @@ public int getItemCount() } } } + diff --git a/app/src/main/java/com/alphawallet/app/ui/MyAddressActivity.java b/app/src/main/java/com/alphawallet/app/ui/MyAddressActivity.java index e7637977d1..f5dee6431c 100644 --- a/app/src/main/java/com/alphawallet/app/ui/MyAddressActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/MyAddressActivity.java @@ -1,5 +1,7 @@ package com.alphawallet.app.ui; +import static com.alphawallet.ethereum.EthereumNetworkBase.MAINNET_ID; + import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; @@ -19,7 +21,6 @@ import com.alphawallet.app.C; import com.alphawallet.app.R; import com.alphawallet.app.entity.AddressMode; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.EIP681Request; import com.alphawallet.app.entity.NetworkInfo; import com.alphawallet.app.entity.Wallet; @@ -27,9 +28,9 @@ import com.alphawallet.app.repository.TokenRepository; import com.alphawallet.app.ui.QRScanning.DisplayUtils; import com.alphawallet.app.ui.widget.entity.AmountReadyCallback; -import com.alphawallet.app.util.ens.AWEnsResolver; import com.alphawallet.app.util.KeyboardUtils; import com.alphawallet.app.util.QRUtils; +import com.alphawallet.app.util.ens.AWEnsResolver; import com.alphawallet.app.viewmodel.MyAddressViewModel; import com.alphawallet.app.widget.CopyTextView; import com.alphawallet.app.widget.InputAmount; @@ -44,8 +45,6 @@ import io.reactivex.schedulers.Schedulers; import timber.log.Timber; -import static com.alphawallet.ethereum.EthereumNetworkBase.MAINNET_ID; - @AndroidEntryPoint public class MyAddressActivity extends BaseActivity implements AmountReadyCallback { @@ -139,7 +138,7 @@ public void onDestroy() @Override public boolean onCreateOptionsMenu(Menu menu) { - if (CustomViewSettings.hideEIP681()) return super.onCreateOptionsMenu(menu); + if (viewModel.getCustomSettings().hideEIP681()) return super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.menu_receive, menu); switch (currentMode) diff --git a/app/src/main/java/com/alphawallet/app/ui/NFTAssetsFragment.java b/app/src/main/java/com/alphawallet/app/ui/NFTAssetsFragment.java index a3f168a5b4..ef7832af9f 100644 --- a/app/src/main/java/com/alphawallet/app/ui/NFTAssetsFragment.java +++ b/app/src/main/java/com/alphawallet/app/ui/NFTAssetsFragment.java @@ -164,7 +164,7 @@ private void initAndAttachAdapter(boolean isGridView) if (hasTokenScriptOverride(token)) { searchLayout.setVisibility(View.GONE); - adapter = new NonFungibleTokenAdapter(this, token, viewModel.getAssetDefinitionService(), viewModel.getOpenseaService(), isGridView); + adapter = new NonFungibleTokenAdapter(this, token, viewModel.getAssetDefinitionService(), viewModel.getOpenseaService(), isGridView, viewModel.getCustomSettings()); } else { diff --git a/app/src/main/java/com/alphawallet/app/ui/NewSettingsFragment.java b/app/src/main/java/com/alphawallet/app/ui/NewSettingsFragment.java index 98bdf77935..6fe1bc1593 100644 --- a/app/src/main/java/com/alphawallet/app/ui/NewSettingsFragment.java +++ b/app/src/main/java/com/alphawallet/app/ui/NewSettingsFragment.java @@ -38,7 +38,6 @@ import com.alphawallet.app.R; import com.alphawallet.app.analytics.Analytics; import com.alphawallet.app.entity.BackupOperationType; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.Wallet; import com.alphawallet.app.entity.WalletType; import com.alphawallet.app.interact.GenericWalletInteract; @@ -50,6 +49,8 @@ import com.alphawallet.app.widget.SettingsItemView; import com.google.android.material.card.MaterialCardView; +import org.json.JSONArray; + import java.util.Locale; import dagger.hilt.android.AndroidEntryPoint; @@ -338,7 +339,7 @@ private void addSettingsToLayout() walletSettingsLayout.addView(myAddressSetting, walletIndex++); - if (CustomViewSettings.canChangeWallets()) + if (viewModel.getCustomSettings().canChangeWallets()) walletSettingsLayout.addView(changeWalletSetting, walletIndex++); walletSettingsLayout.addView(backUpWalletSetting, walletIndex++); @@ -350,7 +351,8 @@ private void addSettingsToLayout() walletSettingsLayout.addView(walletConnectSetting, walletIndex++); - if (CustomViewSettings.getLockedChains().size() == 0) + JSONArray chainArrays = viewModel.getCustomSettings().getChainsArrayJsonFile(); + if (chainArrays.length() == 0) systemSettingsLayout.addView(selectNetworksSetting, systemIndex++); if (biometricsSetting != null) diff --git a/app/src/main/java/com/alphawallet/app/ui/RedeemAssetSelectActivity.java b/app/src/main/java/com/alphawallet/app/ui/RedeemAssetSelectActivity.java index 8ef9200e07..7fa8f22e39 100644 --- a/app/src/main/java/com/alphawallet/app/ui/RedeemAssetSelectActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/RedeemAssetSelectActivity.java @@ -1,5 +1,7 @@ package com.alphawallet.app.ui; +import static com.alphawallet.app.C.Key.TICKET_RANGE; + import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -9,7 +11,6 @@ import androidx.annotation.Nullable; import androidx.lifecycle.ViewModelProvider; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -30,9 +31,6 @@ import java.util.ArrayList; import java.util.List; - -import static com.alphawallet.app.C.Key.TICKET_RANGE; - import dagger.hilt.android.AndroidEntryPoint; /** @@ -106,7 +104,7 @@ private void setupRedeemSelector() invalidateOptionsMenu(); RecyclerView list = findViewById(R.id.listTickets); - adapter = new NonFungibleTokenAdapter(this, token, ticketRange.range.tokenIds, viewModel.getAssetDefinitionService()); + adapter = new NonFungibleTokenAdapter(this, token, ticketRange.range.tokenIds, viewModel.getAssetDefinitionService(), viewModel.getCustomSettings()); adapter.addQuantitySelector(); nextButton.setVisibility(View.GONE); diff --git a/app/src/main/java/com/alphawallet/app/ui/SearchActivity.java b/app/src/main/java/com/alphawallet/app/ui/SearchActivity.java index ff7f8468be..2f038086b8 100644 --- a/app/src/main/java/com/alphawallet/app/ui/SearchActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/SearchActivity.java @@ -64,11 +64,7 @@ private void initViewModel() private void initList() { - adapter = new TokensAdapter( - this, - viewModel.getAssetDefinitionService(), - viewModel.getTokensService(), - null); + adapter = new TokensAdapter(this, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), viewModel.getCustomSettings(), null); adapter.setHasStableIds(true); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter); diff --git a/app/src/main/java/com/alphawallet/app/ui/SelectNetworkActivity.java b/app/src/main/java/com/alphawallet/app/ui/SelectNetworkActivity.java index b935ad0158..e01e84715a 100644 --- a/app/src/main/java/com/alphawallet/app/ui/SelectNetworkActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/SelectNetworkActivity.java @@ -12,7 +12,6 @@ import com.alphawallet.app.C; import com.alphawallet.app.R; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.NetworkInfo; import com.alphawallet.app.repository.EthereumNetworkRepository; import com.alphawallet.app.ui.widget.adapter.SingleSelectNetworkAdapter; @@ -24,8 +23,6 @@ import java.util.Arrays; import java.util.List; -import javax.inject.Inject; - import dagger.hilt.android.AndroidEntryPoint; @AndroidEntryPoint @@ -159,7 +156,7 @@ private void setupFilters(Long selectedNetwork, List availableNetwo @Override public boolean onCreateOptionsMenu(Menu menu) { - if (!localSelectionMode && !CustomViewSettings.showAllNetworks()) + if (!localSelectionMode && !viewModel.getCustomSettings().showAllNetworks()) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_filter_network, menu); diff --git a/app/src/main/java/com/alphawallet/app/ui/SellDetailActivity.java b/app/src/main/java/com/alphawallet/app/ui/SellDetailActivity.java index 5133c33c10..6743c2af09 100644 --- a/app/src/main/java/com/alphawallet/app/ui/SellDetailActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/SellDetailActivity.java @@ -1,5 +1,13 @@ package com.alphawallet.app.ui; +import static com.alphawallet.app.C.EXTRA_PRICE; +import static com.alphawallet.app.C.EXTRA_STATE; +import static com.alphawallet.app.C.EXTRA_TOKENID_LIST; +import static com.alphawallet.app.C.Key.WALLET; +import static com.alphawallet.app.C.PRUNE_ACTIVITY; +import static com.alphawallet.app.entity.Operation.SIGN_DATA; +import static com.alphawallet.token.tools.Convert.getEthString; + import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.content.Context; @@ -52,17 +60,8 @@ import java.util.Locale; import java.util.MissingFormatArgumentException; -import timber.log.Timber; - -import static com.alphawallet.app.C.EXTRA_PRICE; -import static com.alphawallet.app.C.EXTRA_STATE; -import static com.alphawallet.app.C.EXTRA_TOKENID_LIST; -import static com.alphawallet.app.C.Key.WALLET; -import static com.alphawallet.app.C.PRUNE_ACTIVITY; -import static com.alphawallet.app.entity.Operation.SIGN_DATA; -import static com.alphawallet.token.tools.Convert.getEthString; - import dagger.hilt.android.AndroidEntryPoint; +import timber.log.Timber; /** * Created by James on 21/02/2018. @@ -138,7 +137,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { //we should import a token and a list of chosen ids list = findViewById(R.id.listTickets); - adapter = new NonFungibleTokenAdapter(this, token, selection, viewModel.getAssetDefinitionService()); + adapter = new NonFungibleTokenAdapter(this, token, selection, viewModel.getAssetDefinitionService(), viewModel.getCustomSettings()); list.setLayoutManager(new LinearLayoutManager(this)); list.setAdapter(adapter); diff --git a/app/src/main/java/com/alphawallet/app/ui/SplashActivity.java b/app/src/main/java/com/alphawallet/app/ui/SplashActivity.java index 90c1cf0046..03f2014826 100644 --- a/app/src/main/java/com/alphawallet/app/ui/SplashActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/SplashActivity.java @@ -16,7 +16,6 @@ import com.alphawallet.app.analytics.Analytics; import com.alphawallet.app.entity.AnalyticsProperties; import com.alphawallet.app.entity.CreateWalletCallbackInterface; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.Operation; import com.alphawallet.app.entity.Wallet; import com.alphawallet.app.entity.analytics.FirstWalletAction; @@ -106,7 +105,7 @@ private void onWallets(Wallet[] wallets) { } else { - handler.postDelayed(this, CustomViewSettings.startupDelay()); + handler.postDelayed(this, viewModel.getCustomSettings().startupDelay()); } } diff --git a/app/src/main/java/com/alphawallet/app/ui/TransferNFTActivity.java b/app/src/main/java/com/alphawallet/app/ui/TransferNFTActivity.java index b4bf33b8f6..0b45b81cfb 100644 --- a/app/src/main/java/com/alphawallet/app/ui/TransferNFTActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/TransferNFTActivity.java @@ -130,7 +130,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) //we should import a token and a list of chosen ids RecyclerView list = findViewById(R.id.listTickets); - NonFungibleTokenAdapter adapter = new NonFungibleTokenAdapter(null, token, assetSelection, viewModel.getAssetDefinitionService()); + NonFungibleTokenAdapter adapter = new NonFungibleTokenAdapter(null, token, assetSelection, viewModel.getAssetDefinitionService(), viewModel.getCustomSettings()); list.setLayoutManager(new LinearLayoutManager(this)); list.setAdapter(adapter); diff --git a/app/src/main/java/com/alphawallet/app/ui/TransferTicketDetailActivity.java b/app/src/main/java/com/alphawallet/app/ui/TransferTicketDetailActivity.java index 4aa9aefc67..a2086aa920 100644 --- a/app/src/main/java/com/alphawallet/app/ui/TransferTicketDetailActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/TransferTicketDetailActivity.java @@ -41,7 +41,6 @@ import com.alphawallet.app.R; import com.alphawallet.app.analytics.Analytics; import com.alphawallet.app.entity.AnalyticsProperties; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.DisplayState; import com.alphawallet.app.entity.ErrorEnvelope; import com.alphawallet.app.entity.SignAuthenticationCallback; @@ -188,7 +187,7 @@ private void initViews() //we should import a token and a list of chosen ids RecyclerView list = findViewById(R.id.listTickets); - adapter = new NonFungibleTokenAdapter(null, token, selection, viewModel.getAssetDefinitionService()); + adapter = new NonFungibleTokenAdapter(null, token, selection, viewModel.getAssetDefinitionService(), viewModel.getCustomSettings()); list.setLayoutManager(new LinearLayoutManager(this)); list.setAdapter(adapter); @@ -339,7 +338,7 @@ private DisplayState getNextState() switch (transferStatus) { case CHOOSE_QUANTITY: - if (CustomViewSettings.hasDirectTransfer()) + if (viewModel.getCustomSettings().hasDirectTransfer()) { newState = DisplayState.PICK_TRANSFER_METHOD; } @@ -960,4 +959,4 @@ private void estimateError(final Web3Transaction w3tx, final byte[] transactionB dialog.show(); } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/alphawallet/app/ui/WalletFragment.java b/app/src/main/java/com/alphawallet/app/ui/WalletFragment.java index 8c01d10254..fd68255537 100644 --- a/app/src/main/java/com/alphawallet/app/ui/WalletFragment.java +++ b/app/src/main/java/com/alphawallet/app/ui/WalletFragment.java @@ -43,7 +43,6 @@ import com.alphawallet.app.entity.BackupOperationType; import com.alphawallet.app.entity.BackupTokenCallback; import com.alphawallet.app.entity.ContractLocator; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.ErrorEnvelope; import com.alphawallet.app.entity.ServiceSyncCallback; import com.alphawallet.app.entity.TokenFilter; @@ -140,15 +139,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c View view = inflater.inflate(R.layout.fragment_wallet, container, false); LocaleUtils.setActiveLocale(getContext()); // Can't be placed before above line - if (CustomViewSettings.canAddTokens()) - { - toolbar(view, R.menu.menu_wallet, this::onMenuItemClick); - } - else - { - toolbar(view); - } - initResultLaunchers(); initViews(view); @@ -165,6 +155,15 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c viewModel.prepare(); + if (viewModel.getCustomSettings().canAddTokens()) + { + toolbar(view, R.menu.menu_wallet, this::onMenuItemClick); + } + else + { + toolbar(view); + } + addressAvatar.setWaiting(); getChildFragmentManager() @@ -223,8 +222,7 @@ private void initResultLaunchers() private void initList() { - adapter = new TokensAdapter(this, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), - tokenManagementLauncher); + adapter = new TokensAdapter(this, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), viewModel.getCustomSettings(), tokenManagementLauncher); adapter.setHasStableIds(true); setLinearLayoutManager(TokenFilter.ALL.ordinal()); recyclerView.setAdapter(adapter); @@ -274,7 +272,7 @@ private void initViews(@NonNull View view) private void onDefaultWallet(Wallet wallet) { - if (CustomViewSettings.showManageTokens()) + if (viewModel.getCustomSettings().showManageTokens()) { adapter.setWalletAddress(wallet.address); } @@ -443,7 +441,7 @@ public void onPause() private void initTabLayout(View view) { TabLayout tabLayout = view.findViewById(R.id.tab_layout); - if (CustomViewSettings.hideTabBar()) + if (viewModel.getCustomSettings().hideTabBar()) { tabLayout.setVisibility(View.GONE); return; diff --git a/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java b/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java index 375243573f..9235a4a7d7 100644 --- a/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java @@ -21,7 +21,6 @@ import com.alphawallet.app.C; import com.alphawallet.app.R; import com.alphawallet.app.entity.CreateWalletCallbackInterface; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.ErrorEnvelope; import com.alphawallet.app.entity.Operation; import com.alphawallet.app.entity.SyncCallback; @@ -228,7 +227,7 @@ public void onBackPressed() @Override public boolean onCreateOptionsMenu(Menu menu) { - if (CustomViewSettings.canChangeWallets()) getMenuInflater().inflate(R.menu.menu_add, menu); + if (viewModel.getCustomSettings().canChangeWallets()) getMenuInflater().inflate(R.menu.menu_add, menu); return super.onCreateOptionsMenu(menu); } diff --git a/app/src/main/java/com/alphawallet/app/ui/widget/adapter/NonFungibleTokenAdapter.java b/app/src/main/java/com/alphawallet/app/ui/widget/adapter/NonFungibleTokenAdapter.java index 49a9bfe842..9930ed0246 100644 --- a/app/src/main/java/com/alphawallet/app/ui/widget/adapter/NonFungibleTokenAdapter.java +++ b/app/src/main/java/com/alphawallet/app/ui/widget/adapter/NonFungibleTokenAdapter.java @@ -2,6 +2,9 @@ import static com.alphawallet.app.service.AssetDefinitionService.ASSET_SUMMARY_VIEW_NAME; +import android.app.Activity; +import static com.alphawallet.app.service.AssetDefinitionService.ASSET_SUMMARY_VIEW_NAME; + import android.content.Context; import android.util.Pair; import android.view.ViewGroup; @@ -17,6 +20,7 @@ import com.alphawallet.app.entity.tokens.ERC721Token; import com.alphawallet.app.entity.tokens.Token; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.OpenSeaService; import com.alphawallet.app.ui.widget.NonFungibleAdapterInterface; import com.alphawallet.app.ui.widget.TokensAdapterCallback; @@ -62,9 +66,9 @@ public class NonFungibleTokenAdapter extends TokensAdapter implements NonFungibl private boolean isGrid; public NonFungibleTokenAdapter(TokensAdapterCallback tokenClickListener, Token t, AssetDefinitionService service, - OpenSeaService opensea) + OpenSeaService opensea, CustomSettings customSettings) { - super(tokenClickListener, service); + super(tokenClickListener, service, customSettings); assetCount = 0; token = t; clickThrough = true; @@ -73,9 +77,9 @@ public NonFungibleTokenAdapter(TokensAdapterCallback tokenClickListener, Token t } public NonFungibleTokenAdapter(TokensAdapterCallback tokenClickListener, Token t, AssetDefinitionService service, - OpenSeaService opensea, boolean isGrid) + OpenSeaService opensea, boolean isGrid, CustomSettings customSettings) { - super(tokenClickListener, service); + super(tokenClickListener, service, customSettings); assetCount = 0; token = t; clickThrough = true; @@ -85,9 +89,9 @@ public NonFungibleTokenAdapter(TokensAdapterCallback tokenClickListener, Token t } public NonFungibleTokenAdapter(TokensAdapterCallback tokenClickListener, Token t, List tokenSelection, - AssetDefinitionService service) + AssetDefinitionService service, CustomSettings customSettings) { - super(tokenClickListener, service); + super(tokenClickListener, service, customSettings); assetCount = 0; token = t; clickThrough = false; @@ -96,9 +100,9 @@ public NonFungibleTokenAdapter(TokensAdapterCallback tokenClickListener, Token t } public NonFungibleTokenAdapter(TokensAdapterCallback tokenClickListener, Token t, ArrayList> assetSelection, - AssetDefinitionService service) + AssetDefinitionService service, CustomSettings customSettings) { - super(tokenClickListener, service); + super(tokenClickListener, service, customSettings); assetCount = 0; token = t; clickThrough = false; diff --git a/app/src/main/java/com/alphawallet/app/ui/widget/adapter/TokensAdapter.java b/app/src/main/java/com/alphawallet/app/ui/widget/adapter/TokensAdapter.java index 9972fe894a..50cccda1a9 100644 --- a/app/src/main/java/com/alphawallet/app/ui/widget/adapter/TokensAdapter.java +++ b/app/src/main/java/com/alphawallet/app/ui/widget/adapter/TokensAdapter.java @@ -3,9 +3,13 @@ import android.content.Intent; import android.view.ViewGroup; +import androidx.activity.result.ActivityResultLauncher; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.SortedList; + import com.alphawallet.app.R; import com.alphawallet.app.entity.ContractLocator; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.TokenFilter; import com.alphawallet.app.entity.tokendata.TokenGroup; import com.alphawallet.app.entity.tokens.TokenCardMeta; @@ -13,6 +17,7 @@ import com.alphawallet.app.repository.TokensMappingRepository; import com.alphawallet.app.repository.TokensRealmSource; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.widget.TokensAdapterCallback; import com.alphawallet.app.ui.widget.entity.ChainItem; @@ -44,11 +49,6 @@ import java.util.ArrayList; import java.util.List; -import androidx.activity.result.ActivityResultLauncher; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.SortedList; - public class TokensAdapter extends RecyclerView.Adapter { private static final String TAG = "TKNADAPTER"; @@ -56,6 +56,7 @@ public class TokensAdapter extends RecyclerView.Adapter private TokenFilter filterType = TokenFilter.ALL; protected final AssetDefinitionService assetService; protected final TokensService tokensService; + protected final CustomSettings customSettings; private final ActivityResultLauncher managementLauncher; private ContractLocator scrollToken; // designates a token that should be scrolled to @@ -114,22 +115,23 @@ public void onMoved(int fromPosition, int toPosition) protected TotalBalanceSortedItem total = new TotalBalanceSortedItem(null); - public TokensAdapter(TokensAdapterCallback tokensAdapterCallback, AssetDefinitionService aService, TokensService tService, - ActivityResultLauncher launcher) + public TokensAdapter(TokensAdapterCallback tokensAdapterCallback, AssetDefinitionService aService, TokensService tService, CustomSettings customSettings, ActivityResultLauncher launcher) { this.tokensAdapterCallback = tokensAdapterCallback; this.assetService = aService; this.tokensService = tService; + this.customSettings = customSettings; this.managementLauncher = launcher; new TokensMappingRepository(aService.getTokenLocalSource()); } - protected TokensAdapter(TokensAdapterCallback tokensAdapterCallback, AssetDefinitionService aService) + protected TokensAdapter(TokensAdapterCallback tokensAdapterCallback, AssetDefinitionService aService, CustomSettings customSettings) { this.tokensAdapterCallback = tokensAdapterCallback; this.assetService = aService; this.tokensService = null; + this.customSettings = customSettings; new TokensMappingRepository(aService.getTokenLocalSource()); this.managementLauncher = null; @@ -388,7 +390,7 @@ private boolean canDisplayToken(TokenCardMeta token) { if (token == null) return false; //Add token to display list if it's the base currency, or if it has balance - boolean allowThroughFilter = CustomViewSettings.tokenCanBeDisplayed(token); + boolean allowThroughFilter = customSettings.tokenCanBeDisplayed(token); allowThroughFilter = checkTokenValue(token, allowThroughFilter); switch (filterType) diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/AddTokenViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/AddTokenViewModel.java index d9256cd899..8fe6baaa51 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/AddTokenViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/AddTokenViewModel.java @@ -17,6 +17,7 @@ import com.alphawallet.app.interact.GenericWalletInteract; import com.alphawallet.app.repository.EthereumNetworkRepositoryType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.ImportTokenActivity; import com.alphawallet.app.ui.SendActivity; @@ -51,6 +52,7 @@ public class AddTokenViewModel extends BaseViewModel { private final FetchTransactionsInteract fetchTransactionsInteract; private final AssetDefinitionService assetDefinitionService; private final TokensService tokensService; + private final CustomSettings customSettings; private boolean foundNetwork; private int networkCount; @@ -77,12 +79,15 @@ public MutableLiveData wallet() { EthereumNetworkRepositoryType ethereumNetworkRepository, FetchTransactionsInteract fetchTransactionsInteract, AssetDefinitionService assetDefinitionService, - TokensService tokensService) { + TokensService tokensService, + CustomSettings customSettings) + { this.genericWalletInteract = genericWalletInteract; this.ethereumNetworkRepository = ethereumNetworkRepository; this.fetchTransactionsInteract = fetchTransactionsInteract; this.assetDefinitionService = assetDefinitionService; this.tokensService = tokensService; + this.customSettings = customSettings; } public void saveTokens(List toSave) @@ -304,4 +309,9 @@ public AssetDefinitionService getAssetDefinitionService() { return assetDefinitionService; } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/Erc20DetailViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/Erc20DetailViewModel.java index 1a7fe54bd7..41014ed721 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/Erc20DetailViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/Erc20DetailViewModel.java @@ -19,6 +19,7 @@ import com.alphawallet.app.router.SendTokenRouter; import com.alphawallet.app.service.AnalyticsServiceType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TokensService; import com.alphawallet.token.entity.SigReturnType; import com.alphawallet.token.entity.XMLDsigDescriptor; @@ -44,6 +45,7 @@ public class Erc20DetailViewModel extends BaseViewModel { private final AssetDefinitionService assetDefinitionService; private final TokensService tokensService; private final OnRampRepositoryType onRampRepository; + private final CustomSettings customSettings; @Nullable private Disposable scriptUpdate; @@ -54,13 +56,15 @@ public Erc20DetailViewModel(MyAddressRouter myAddressRouter, AssetDefinitionService assetDefinitionService, TokensService tokensService, OnRampRepositoryType onRampRepository, - AnalyticsServiceType analyticsService) + AnalyticsServiceType analyticsService, + CustomSettings customSettings) { this.myAddressRouter = myAddressRouter; this.fetchTransactionsInteract = fetchTransactionsInteract; this.assetDefinitionService = assetDefinitionService; this.tokensService = tokensService; this.onRampRepository = onRampRepository; + this.customSettings = customSettings; setAnalyticsService(analyticsService); } @@ -91,6 +95,11 @@ public TokensService getTokensService() return tokensService; } + public CustomSettings getCustomSettings() + { + return customSettings; + } + public FetchTransactionsInteract getTransactionsInteract() { return fetchTransactionsInteract; diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/HomeViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/HomeViewModel.java index 6ff2e07eff..361e82fbf8 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/HomeViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/HomeViewModel.java @@ -26,7 +26,6 @@ import com.alphawallet.app.C; import com.alphawallet.app.R; -import com.alphawallet.app.entity.AnalyticsProperties; import com.alphawallet.app.entity.CryptoFunctions; import com.alphawallet.app.entity.FragmentMessenger; import com.alphawallet.app.entity.GitHubRelease; @@ -50,6 +49,7 @@ import com.alphawallet.app.router.MyAddressRouter; import com.alphawallet.app.service.AnalyticsServiceType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.RealmManager; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.service.TransactionsService; @@ -58,10 +58,10 @@ import com.alphawallet.app.ui.HomeActivity; import com.alphawallet.app.ui.ImportWalletActivity; import com.alphawallet.app.ui.SendActivity; -import com.alphawallet.app.util.ens.AWEnsResolver; import com.alphawallet.app.util.QRParser; import com.alphawallet.app.util.RateApp; import com.alphawallet.app.util.Utils; +import com.alphawallet.app.util.ens.AWEnsResolver; import com.alphawallet.app.walletconnect.WCClient; import com.alphawallet.app.walletconnect.entity.WCUtils; import com.alphawallet.app.widget.EmailPromptView; @@ -109,6 +109,7 @@ public class HomeViewModel extends BaseViewModel { private final ImportTokenRouter importTokenRouter; private final LocaleRepositoryType localeRepository; private final AssetDefinitionService assetDefinitionService; + private final CustomSettings customSettings; private final GenericWalletInteract genericWalletInteract; private final FetchWalletsInteract fetchWalletsInteract; private final CurrencyRepositoryType currencyRepository; @@ -133,7 +134,7 @@ public class HomeViewModel extends BaseViewModel { LocaleRepositoryType localeRepository, ImportTokenRouter importTokenRouter, AssetDefinitionService assetDefinitionService, - GenericWalletInteract genericWalletInteract, + CustomSettings customSettings, GenericWalletInteract genericWalletInteract, FetchWalletsInteract fetchWalletsInteract, CurrencyRepositoryType currencyRepository, EthereumNetworkRepositoryType ethereumNetworkRepository, @@ -142,11 +143,13 @@ public class HomeViewModel extends BaseViewModel { AnalyticsServiceType analyticsService, ExternalBrowserRouter externalBrowserRouter, OkHttpClient httpClient, - RealmManager realmManager) { + RealmManager realmManager) + { this.preferenceRepository = preferenceRepository; this.importTokenRouter = importTokenRouter; this.localeRepository = localeRepository; this.assetDefinitionService = assetDefinitionService; + this.customSettings = customSettings; this.genericWalletInteract = genericWalletInteract; this.fetchWalletsInteract = fetchWalletsInteract; this.currencyRepository = currencyRepository; @@ -721,4 +724,9 @@ public void setNewWallet(String address, boolean isNewWallet) { preferenceRepository.setNewWallet(address, isNewWallet); } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/MyAddressViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/MyAddressViewModel.java index 7cc3298a44..dc29b94373 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/MyAddressViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/MyAddressViewModel.java @@ -3,6 +3,7 @@ import com.alphawallet.app.entity.NetworkInfo; import com.alphawallet.app.repository.EthereumNetworkRepositoryType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TokensService; import javax.inject.Inject; @@ -14,15 +15,19 @@ public class MyAddressViewModel extends BaseViewModel { private final EthereumNetworkRepositoryType ethereumNetworkRepository; private final TokensService tokenService; private final AssetDefinitionService assetDefinitionService; + private final CustomSettings customSettings; @Inject MyAddressViewModel( EthereumNetworkRepositoryType ethereumNetworkRepository, TokensService tokensService, - AssetDefinitionService assetDefinitionService) { + AssetDefinitionService assetDefinitionService, + CustomSettings customSettings) + { this.ethereumNetworkRepository = ethereumNetworkRepository; this.tokenService = tokensService; this.assetDefinitionService = assetDefinitionService; + this.customSettings = customSettings; } public TokensService getTokenService() { @@ -41,4 +46,9 @@ public AssetDefinitionService getAssetDefinitionService() { return assetDefinitionService; } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/NFTAssetsViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/NFTAssetsViewModel.java index 32ff45a6a5..1f6af6f6cb 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/NFTAssetsViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/NFTAssetsViewModel.java @@ -9,6 +9,7 @@ import com.alphawallet.app.entity.tokens.Token; import com.alphawallet.app.interact.FetchTransactionsInteract; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.OpenSeaService; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.Erc1155AssetListActivity; @@ -26,17 +27,20 @@ public class NFTAssetsViewModel extends BaseViewModel { private final AssetDefinitionService assetDefinitionService; private final TokensService tokensService; private final OpenSeaService openSeaService; + private final CustomSettings customSettings; @Inject public NFTAssetsViewModel(FetchTransactionsInteract fetchTransactionsInteract, AssetDefinitionService assetDefinitionService, TokensService tokensService, - OpenSeaService openSeaService) + OpenSeaService openSeaService, + CustomSettings customSettings) { this.fetchTransactionsInteract = fetchTransactionsInteract; this.assetDefinitionService = assetDefinitionService; this.tokensService = tokensService; this.openSeaService = openSeaService; + this.customSettings = customSettings; } public AssetDefinitionService getAssetDefinitionService() @@ -54,6 +58,11 @@ public TokensService getTokensService() return tokensService; } + public CustomSettings getCustomSettings() + { + return customSettings; + } + public Intent showAssetListDetails(Context context, Wallet wallet, Token token, NFTAsset asset) { Intent intent = new Intent(context, Erc1155AssetListActivity.class); diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/NewSettingsViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/NewSettingsViewModel.java index b9573d16d7..6af3d52bbf 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/NewSettingsViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/NewSettingsViewModel.java @@ -16,6 +16,7 @@ import com.alphawallet.app.repository.PreferenceRepositoryType; import com.alphawallet.app.router.ManageWalletsRouter; import com.alphawallet.app.router.MyAddressRouter; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TickerService; import com.alphawallet.app.service.AnalyticsServiceType; import com.alphawallet.app.service.TransactionsService; @@ -43,6 +44,7 @@ public class NewSettingsViewModel extends BaseViewModel private final CurrencyRepositoryType currencyRepository; private final TransactionsService transactionsService; private final TickerService tickerService; + private final CustomSettings customSettings; @Inject NewSettingsViewModel( @@ -54,7 +56,7 @@ public class NewSettingsViewModel extends BaseViewModel CurrencyRepositoryType currencyRepository, TransactionsService transactionsService, TickerService tickerService, - AnalyticsServiceType analyticsService) + AnalyticsServiceType analyticsService, CustomSettings customSettings) { this.genericWalletInteract = genericWalletInteract; this.myAddressRouter = myAddressRouter; @@ -64,6 +66,7 @@ public class NewSettingsViewModel extends BaseViewModel this.currencyRepository = currencyRepository; this.transactionsService = transactionsService; this.tickerService = tickerService; + this.customSettings = customSettings; setAnalyticsService(analyticsService); } @@ -180,4 +183,9 @@ public void setMarshMallowWarning(boolean shown) { preferenceRepository.setMarshMallowWarning(shown); } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/RedeemAssetSelectViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/RedeemAssetSelectViewModel.java index 2a952d563b..136173b866 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/RedeemAssetSelectViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/RedeemAssetSelectViewModel.java @@ -2,13 +2,12 @@ import android.content.Context; -import androidx.lifecycle.MutableLiveData; - import com.alphawallet.app.entity.Wallet; import com.alphawallet.app.entity.tokens.Token; import com.alphawallet.app.interact.GenericWalletInteract; import com.alphawallet.app.router.RedeemSignatureDisplayRouter; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.widget.entity.TicketRangeParcel; import com.alphawallet.token.entity.TicketRange; @@ -26,18 +25,21 @@ public class RedeemAssetSelectViewModel extends BaseViewModel { private final AssetDefinitionService assetDefinitionService; private final TokensService tokensService; private final GenericWalletInteract genericWalletInteract; + private final CustomSettings customSettings; @Inject public RedeemAssetSelectViewModel( RedeemSignatureDisplayRouter redeemSignatureDisplayRouter, AssetDefinitionService assetDefinitionService, TokensService tokensService, - GenericWalletInteract genericWalletInteract) + GenericWalletInteract genericWalletInteract, + CustomSettings customSettings) { this.redeemSignatureDisplayRouter = redeemSignatureDisplayRouter; this.assetDefinitionService = assetDefinitionService; this.tokensService = tokensService; this.genericWalletInteract = genericWalletInteract; + this.customSettings = customSettings; } public void showRedeemSignature(Context ctx, TicketRange range, Token token) @@ -59,4 +61,9 @@ public AssetDefinitionService getAssetDefinitionService() { return assetDefinitionService; } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/SelectNetworkViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/SelectNetworkViewModel.java index 01c87c9adb..de2c17bddc 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/SelectNetworkViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/SelectNetworkViewModel.java @@ -7,6 +7,7 @@ import com.alphawallet.app.repository.EthereumNetworkBase; import com.alphawallet.app.repository.EthereumNetworkRepositoryType; import com.alphawallet.app.repository.PreferenceRepositoryType; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.SelectNetworkFilterActivity; @@ -21,15 +22,17 @@ public class SelectNetworkViewModel extends BaseViewModel { private final EthereumNetworkRepositoryType networkRepository; private final TokensService tokensService; private final PreferenceRepositoryType preferenceRepository; + private final CustomSettings customSettings; @Inject public SelectNetworkViewModel(EthereumNetworkRepositoryType ethereumNetworkRepositoryType, TokensService tokensService, - PreferenceRepositoryType preferenceRepository) + PreferenceRepositoryType preferenceRepository, CustomSettings customSettings) { this.networkRepository = ethereumNetworkRepositoryType; this.tokensService = tokensService; this.preferenceRepository = preferenceRepository; + this.customSettings = customSettings; } public NetworkInfo[] getNetworkList() @@ -83,4 +86,9 @@ public long getSelectedNetwork() public TokensService getTokensService() { return tokensService; } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/SellDetailViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/SellDetailViewModel.java index d4fbb66ccf..14ba2dee16 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/SellDetailViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/SellDetailViewModel.java @@ -19,6 +19,7 @@ import com.alphawallet.app.repository.EthereumNetworkRepository; import com.alphawallet.app.router.SellDetailRouter; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.KeyService; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.SellDetailActivity; @@ -52,6 +53,7 @@ public class SellDetailViewModel extends BaseViewModel { private final SellDetailRouter sellDetailRouter; private final KeyService keyService; private final AssetDefinitionService assetDefinitionService; + private final CustomSettings customSettings; private byte[] linkMessage; @@ -61,13 +63,16 @@ public class SellDetailViewModel extends BaseViewModel { CreateTransactionInteract createTransactionInteract, SellDetailRouter sellDetailRouter, KeyService keyService, - AssetDefinitionService assetDefinitionService) { + AssetDefinitionService assetDefinitionService, + CustomSettings customSettings) + { this.findDefaultNetworkInteract = findDefaultNetworkInteract; this.tokensService = tokensService; this.createTransactionInteract = createTransactionInteract; this.sellDetailRouter = sellDetailRouter; this.keyService = keyService; this.assetDefinitionService = assetDefinitionService; + this.customSettings = customSettings; } private void initParser() @@ -152,6 +157,11 @@ public AssetDefinitionService getAssetDefinitionService() return assetDefinitionService; } + public CustomSettings getCustomSettings() + { + return customSettings; + } + public void getAuthorisation(Activity activity, SignAuthenticationCallback callback) { if (defaultWallet.getValue() != null) diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/SplashViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/SplashViewModel.java index d3cd360f48..ff6e2fc288 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/SplashViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/SplashViewModel.java @@ -16,6 +16,7 @@ import com.alphawallet.app.interact.FetchWalletsInteract; import com.alphawallet.app.repository.PreferenceRepositoryType; import com.alphawallet.app.service.AnalyticsServiceType; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.KeyService; import java.io.File; @@ -36,6 +37,7 @@ public class SplashViewModel extends BaseViewModel private final FetchWalletsInteract fetchWalletsInteract; private final PreferenceRepositoryType preferenceRepository; private final KeyService keyService; + private final CustomSettings customSettings; private final MutableLiveData wallets = new MutableLiveData<>(); private final MutableLiveData createWallet = new MutableLiveData<>(); @@ -44,11 +46,13 @@ public class SplashViewModel extends BaseViewModel SplashViewModel(FetchWalletsInteract fetchWalletsInteract, PreferenceRepositoryType preferenceRepository, KeyService keyService, - AnalyticsServiceType analyticsService) + AnalyticsServiceType analyticsService, + CustomSettings customSettings) { this.fetchWalletsInteract = fetchWalletsInteract; this.preferenceRepository = preferenceRepository; this.keyService = keyService; + this.customSettings = customSettings; setAnalyticsService(analyticsService); // increase launch count // this.preferenceRepository.incrementLaunchCount(); @@ -171,4 +175,9 @@ public void setInstallTime(long time) { preferenceRepository.setInstallTime(time); } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/TokenFunctionViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/TokenFunctionViewModel.java index c1045f22ad..424ec28304 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/TokenFunctionViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/TokenFunctionViewModel.java @@ -31,6 +31,7 @@ import com.alphawallet.app.repository.EthereumNetworkRepositoryType; import com.alphawallet.app.service.AnalyticsServiceType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.GasService; import com.alphawallet.app.service.KeyService; import com.alphawallet.app.service.OpenSeaService; @@ -95,6 +96,7 @@ public class TokenFunctionViewModel extends BaseViewModel private final CreateTransactionInteract createTransactionInteract; private final GasService gasService; private final TokensService tokensService; + private final CustomSettings customSettings; private final EthereumNetworkRepositoryType ethereumNetworkRepository; private final KeyService keyService; private final GenericWalletInteract genericWalletInteract; @@ -139,7 +141,8 @@ public class TokenFunctionViewModel extends BaseViewModel GenericWalletInteract genericWalletInteract, OpenSeaService openseaService, FetchTransactionsInteract fetchTransactionsInteract, - AnalyticsServiceType analyticsService) + AnalyticsServiceType analyticsService, + CustomSettings customSettings) { this.assetDefinitionService = assetDefinitionService; this.createTransactionInteract = createTransactionInteract; @@ -150,6 +153,7 @@ public class TokenFunctionViewModel extends BaseViewModel this.genericWalletInteract = genericWalletInteract; this.openseaService = openseaService; this.fetchTransactionsInteract = fetchTransactionsInteract; + this.customSettings = customSettings; setAnalyticsService(analyticsService); } @@ -158,6 +162,11 @@ public AssetDefinitionService getAssetDefinitionService() return assetDefinitionService; } + public CustomSettings getCustomSettings() + { + return customSettings; + } + public LiveData insufficientFunds() { return insufficientFunds; diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/TransferTicketDetailViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/TransferTicketDetailViewModel.java index bb9a1e16ce..79f57deae3 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/TransferTicketDetailViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/TransferTicketDetailViewModel.java @@ -26,6 +26,7 @@ import com.alphawallet.app.repository.TokenRepository; import com.alphawallet.app.service.AnalyticsServiceType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.GasService; import com.alphawallet.app.service.KeyService; import com.alphawallet.app.service.TokensService; @@ -67,6 +68,7 @@ public class TransferTicketDetailViewModel extends BaseViewModel private final AssetDefinitionService assetDefinitionService; private final GasService gasService; private final TokensService tokensService; + private final CustomSettings customSettings; private ParseMagicLink parser; private Token token; @@ -81,7 +83,8 @@ public class TransferTicketDetailViewModel extends BaseViewModel AssetDefinitionService assetDefinitionService, GasService gasService, AnalyticsServiceType analyticsService, - TokensService tokensService) + TokensService tokensService, + CustomSettings customSettings) { this.genericWalletInteract = genericWalletInteract; this.keyService = keyService; @@ -90,6 +93,7 @@ public class TransferTicketDetailViewModel extends BaseViewModel this.assetDefinitionService = assetDefinitionService; this.gasService = gasService; this.tokensService = tokensService; + this.customSettings = customSettings; setAnalyticsService(analyticsService); } @@ -312,6 +316,11 @@ public TokensService getTokenService() return tokensService; } + public CustomSettings getCustomSettings() + { + return customSettings; + } + public void openTransferState(Context context, Token token, String ticketIds, DisplayState transferStatus) { if (transferStatus != DisplayState.NO_ACTION) diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/WalletViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/WalletViewModel.java index 71e2e217fd..32e3741e00 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/WalletViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/WalletViewModel.java @@ -39,6 +39,7 @@ import com.alphawallet.app.router.TokenDetailRouter; import com.alphawallet.app.service.AnalyticsServiceType; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.RealmManager; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.NameThisWalletActivity; @@ -87,6 +88,7 @@ public class WalletViewModel extends BaseViewModel private final OnRampRepositoryType onRampRepository; private long lastBackupCheck = 0; private BottomSheetDialog dialog; + private final CustomSettings customSettings; private AWWalletConnectClient awWalletConnectClient; @Inject @@ -104,6 +106,7 @@ public class WalletViewModel extends BaseViewModel RealmManager realmManager, OnRampRepositoryType onRampRepository, AnalyticsServiceType analyticsService, + CustomSettings customSettings, AWWalletConnectClient awWalletConnectClient) { this.fetchTokensInteract = fetchTokensInteract; @@ -119,6 +122,7 @@ public class WalletViewModel extends BaseViewModel this.realmManager = realmManager; this.onRampRepository = onRampRepository; this.awWalletConnectClient = awWalletConnectClient; + this.customSettings = customSettings; setAnalyticsService(analyticsService); } @@ -216,6 +220,11 @@ public TokensService getTokensService() return tokensService; } + public CustomSettings getCustomSettings() + { + return customSettings; + } + public Token getTokenFromService(@NotNull Token token) { Token serviceToken = tokensService.getToken(token.tokenInfo.chainId, token.getAddress()); diff --git a/app/src/main/java/com/alphawallet/app/viewmodel/WalletsViewModel.java b/app/src/main/java/com/alphawallet/app/viewmodel/WalletsViewModel.java index b63b939ed6..b05d2197d7 100644 --- a/app/src/main/java/com/alphawallet/app/viewmodel/WalletsViewModel.java +++ b/app/src/main/java/com/alphawallet/app/viewmodel/WalletsViewModel.java @@ -33,6 +33,7 @@ import com.alphawallet.app.router.HomeRouter; import com.alphawallet.app.router.ImportWalletRouter; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.KeyService; import com.alphawallet.app.service.TickerService; import com.alphawallet.app.service.TokensService; @@ -73,6 +74,7 @@ public class WalletsViewModel extends BaseViewModel implements ServiceSyncCallba private final EthereumNetworkRepositoryType ethereumNetworkRepository; private final TokenRepositoryType tokenRepository; private final TickerService tickerService; + private final CustomSettings customSettings; private final MutableLiveData wallets = new MutableLiveData<>(); private final MutableLiveData defaultWallet = new MutableLiveData<>(); @@ -114,7 +116,8 @@ public class WalletsViewModel extends BaseViewModel implements ServiceSyncCallba TickerService tickerService, AssetDefinitionService assetService, PreferenceRepositoryType preferenceRepository, - @ApplicationContext Context context) + @ApplicationContext Context context, + CustomSettings customSettings) { this.setDefaultWalletInteract = setDefaultWalletInteract; this.fetchWalletsInteract = fetchWalletsInteract; @@ -128,7 +131,8 @@ public class WalletsViewModel extends BaseViewModel implements ServiceSyncCallba this.tickerService = tickerService; this.assetService = assetService; this.preferenceRepository = preferenceRepository; - this.tokensService = new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, null, null); + this.customSettings = customSettings; + this.tokensService = new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, null, null, this.customSettings); ensResolver = new AWEnsResolver(TokenRepository.getWeb3jService(MAINNET_ID), context); syncCallback = null; @@ -283,7 +287,7 @@ private void sendUnsyncedValue(Wallet wallet) private Single startWalletSync(Wallet wallet) { return Single.fromCallable(() -> { - TokensService svs = new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, null, null); + TokensService svs = new TokensService(ethereumNetworkRepository, tokenRepository, tickerService, null, null, customSettings); svs.setCurrentAddress(wallet.address.toLowerCase()); svs.startUpdateCycle(); svs.setCompletionCallback(this, 2); @@ -517,4 +521,9 @@ public void onDestroy() walletServices.clear(); currentWalletUpdates.clear(); } + + public CustomSettings getCustomSettings() + { + return customSettings; + } } diff --git a/app/src/main/java/com/alphawallet/app/widget/InputAmount.java b/app/src/main/java/com/alphawallet/app/widget/InputAmount.java index 4d49ba8deb..b2367e38de 100644 --- a/app/src/main/java/com/alphawallet/app/widget/InputAmount.java +++ b/app/src/main/java/com/alphawallet/app/widget/InputAmount.java @@ -13,7 +13,6 @@ import android.widget.TextView; import com.alphawallet.app.R; -import com.alphawallet.app.entity.CustomViewSettings; import com.alphawallet.app.entity.tokens.Token; import com.alphawallet.app.repository.TokenRepository; import com.alphawallet.app.repository.TokensRealmSource; @@ -21,6 +20,7 @@ import com.alphawallet.app.repository.entity.RealmToken; import com.alphawallet.app.repository.entity.RealmTokenTicker; import com.alphawallet.app.service.AssetDefinitionService; +import com.alphawallet.app.service.CustomSettings; import com.alphawallet.app.service.TickerService; import com.alphawallet.app.service.TokensService; import com.alphawallet.app.ui.widget.entity.AmountReadyCallback; @@ -89,7 +89,7 @@ public InputAmount(Context context, AttributeSet attrs) availableAmount = findViewById(R.id.text_available); allFunds = findViewById(R.id.text_all_funds); gasFetch = findViewById(R.id.gas_fetch_progress); - showingCrypto = !CustomViewSettings.inputAmountFiatDefault(); + showingCrypto = !CustomSettings.inputAmountFiatDefault(); amountReady = false; setupAttrs(context, attrs); diff --git a/app/src/test/java/com/alphawallet/app/viewmodel/HomeViewModelTest.java b/app/src/test/java/com/alphawallet/app/viewmodel/HomeViewModelTest.java index 601ba0d5ae..3b6e0a477d 100644 --- a/app/src/test/java/com/alphawallet/app/viewmodel/HomeViewModelTest.java +++ b/app/src/test/java/com/alphawallet/app/viewmodel/HomeViewModelTest.java @@ -25,7 +25,7 @@ public class HomeViewModelTest public void setUp() throws Exception { SharedPreferenceRepository sharedPreferenceRepository = new SharedPreferenceRepository(RuntimeEnvironment.getApplication()); - homeViewModel = new HomeViewModel(sharedPreferenceRepository, null, null, null, null, null, null, null, null, null, null, null, null, null); + homeViewModel = new HomeViewModel(sharedPreferenceRepository, null, null, null, null, null, null, null, null, null, null, null, null, null, null); } @Test