Implement TokenScript management screen

pull/1344/head
ChintanRathod 5 years ago
parent 82d8122a2f
commit 94add59f14
  1. 1
      app/build.gradle
  2. 8
      app/src/main/AndroidManifest.xml
  3. 5
      app/src/main/java/com/alphawallet/app/di/BuildersModule.java
  4. 16
      app/src/main/java/com/alphawallet/app/di/TokenScriptManagementModule.java
  5. 9
      app/src/main/java/com/alphawallet/app/entity/tokenscript/TokenScriptFile.java
  6. 17
      app/src/main/java/com/alphawallet/app/service/AssetDefinitionService.java
  7. 14
      app/src/main/java/com/alphawallet/app/ui/AdvancedSettingsActivity.java
  8. 51
      app/src/main/java/com/alphawallet/app/ui/TokenScriptManagementActivity.java
  9. 69
      app/src/main/java/com/alphawallet/app/ui/widget/adapter/TokenScriptManagementAdapter.java
  10. 40
      app/src/main/java/com/alphawallet/app/viewmodel/TokenScriptManagementViewModel.java
  11. 26
      app/src/main/java/com/alphawallet/app/viewmodel/TokenScriptManagementViewModelFactory.java
  12. 15
      app/src/main/res/layout/activity_token_script_management.xml
  13. 62
      app/src/main/res/layout/item_tokenscript_management.xml
  14. 1
      app/src/main/res/values/strings.xml

@ -154,6 +154,7 @@ dependencies {
// Dagger core
implementation "com.google.dagger:dagger:$project.daggerVersion"
implementation 'com.android.support:appcompat-v7:28.0.0'
annotationProcessor "com.google.dagger:dagger-compiler:$project.daggerVersion"
// Dagger Android

@ -18,7 +18,7 @@
android:required="false" />
<application
android:name="com.alphawallet.app.App"
android:name=".App"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
@ -213,7 +213,7 @@
android:label="@string/token_function" />
<activity
android:name="com.alphawallet.app.ui.FunctionActivity"
android:name=".ui.FunctionActivity"
android:label="@string/token_function" />
<!--<service android:name="AlphaWalletFirebaseMessagingService">-->
@ -273,6 +273,10 @@
<activity
android:name=".ui.StaticViewer"
android:label="View Text" />
<activity android:name=".ui.TokenScriptManagementActivity"
android:label="@string/tokenscript_management"/>
</application>
</manifest>

@ -24,6 +24,7 @@ import com.alphawallet.app.ui.SplashActivity;
import com.alphawallet.app.ui.TokenDetailActivity;
import com.alphawallet.app.ui.TokenFunctionActivity;
import com.alphawallet.app.ui.TokenManagementActivity;
import com.alphawallet.app.ui.TokenScriptManagementActivity;
import com.alphawallet.app.ui.TransactionDetailActivity;
import com.alphawallet.app.ui.TransactionsFragment;
import com.alphawallet.app.ui.TransferTicketActivity;
@ -157,4 +158,8 @@ public abstract class BuildersModule {
@ContributesAndroidInjector(modules = AdvancedSettingsModule.class)
abstract AdvancedSettingsActivity bindAdvancedSettingsActivity();
@ActivityScope
@ContributesAndroidInjector(modules = TokenScriptManagementModule.class)
abstract TokenScriptManagementActivity bindTokenScriptManagementActivity();
}

@ -0,0 +1,16 @@
package com.alphawallet.app.di;
import com.alphawallet.app.service.AssetDefinitionService;
import com.alphawallet.app.viewmodel.TokenScriptManagementViewModelFactory;
import dagger.Module;
import dagger.Provides;
@Module
class TokenScriptManagementModule {
@Provides
TokenScriptManagementViewModelFactory tokenScriptManagementViewModelFactory(AssetDefinitionService assetDefinitionService)
{
return new TokenScriptManagementViewModelFactory(assetDefinitionService);
}
}

@ -20,6 +20,7 @@ public class TokenScriptFile extends File
private boolean active;
private boolean resourceFile;
private String fileName;
private String tokenName;
public TokenScriptFile()
{
@ -174,4 +175,12 @@ public class TokenScriptFile extends File
sigDescriptor.type = SigReturnType.NO_SIGNATURE;
}
}
public String getTokenName() {
return tokenName;
}
public void setTokenName(String tokenName) {
this.tokenName = tokenName;
}
}

@ -517,7 +517,7 @@ public class AssetDefinitionService implements ParseResult, AttributeInterface
{
addContractsToNetwork(network,
networkAddresses(holdingContracts.addresses.get(network), tokenScriptFile.getAbsolutePath()),
false);
false, token);
}
return token;
}
@ -739,7 +739,7 @@ public class AssetDefinitionService implements ParseResult, AttributeInterface
assetLoadingLock.release();
}
private void addContractsToNetwork(Integer network, Map<String, File> newTokenDescriptionAddresses, boolean activeUpdate)
private void addContractsToNetwork(Integer network, Map<String, File> newTokenDescriptionAddresses, boolean activeUpdate,TokenDefinition tokenDef)
{
String externalDir = context.getExternalFilesDir("").getAbsolutePath();
if (assetDefinitions.get(network) == null) assetDefinitions.put(network, new ConcurrentHashMap<>());
@ -757,7 +757,9 @@ public class AssetDefinitionService implements ParseResult, AttributeInterface
removeFile(filename);
}
}
assetDefinitions.get(network).put(address, new TokenScriptFile(context, newTokenDescriptionAddresses.get(address).getAbsolutePath()));
TokenScriptFile tokenFile = new TokenScriptFile(context, newTokenDescriptionAddresses.get(address).getAbsolutePath());
tokenFile.setTokenName(tokenDef.getTokenName(1));
assetDefinitions.get(network).put(address, tokenFile);
}
}
@ -803,7 +805,7 @@ public class AssetDefinitionService implements ParseResult, AttributeInterface
//some Android versions don't have stream()
for (int network : holdingContracts.addresses.keySet())
{
addContractsToNetwork(network, networkAddresses(holdingContracts.addresses.get(network), asset), false);
addContractsToNetwork(network, networkAddresses(holdingContracts.addresses.get(network), asset), false, token);
XMLDsigDescriptor AWSig = new XMLDsigDescriptor();
String hash = tsf.calcMD5();
AWSig.result = "pass";
@ -848,7 +850,7 @@ public class AssetDefinitionService implements ParseResult, AttributeInterface
{
for (int network : holdingContracts.addresses.keySet())
{
addContractsToNetwork(network, networkAddresses(holdingContracts.addresses.get(network), file.getAbsolutePath()), update);
addContractsToNetwork(network, networkAddresses(holdingContracts.addresses.get(network), file.getAbsolutePath()), update,tokenDef);
}
return ContractLocator.fromContractInfo(holdingContracts);
@ -1196,6 +1198,11 @@ public class AssetDefinitionService implements ParseResult, AttributeInterface
}
}
public SparseArray<Map<String, TokenScriptFile>> getAssetDefinitions()
{
return assetDefinitions;
}
public Single<XMLDsigDescriptor> getSignatureData(int chainId, String contractAddress)
{
return Single.fromCallable(() -> {

@ -42,6 +42,7 @@ public class AdvancedSettingsActivity extends BaseActivity {
private SettingsItemView clearBrowserCache;
private SettingsItemView tokenScript;
private SettingsItemView changeLanguage;
private SettingsItemView tokenScriptManagement;
private SettingsItemView changeCurrency;
@Override
@ -92,6 +93,13 @@ public class AdvancedSettingsActivity extends BaseActivity {
.withListener(this::onChangeCurrencyClicked)
.build();
//TODO Change Icon
tokenScriptManagement = new SettingsItemView.Builder(this)
.withIcon(R.drawable.ic_settings_language)
.withTitle(R.string.tokenscript_management)
.withListener(this::onTokenScriptManagementClicked)
.build();
changeLanguage.setSubtitle(LocaleUtils.getDisplayLanguage(viewModel.getDefaultLocale(), viewModel.getDefaultLocale()));
}
@ -105,6 +113,7 @@ public class AdvancedSettingsActivity extends BaseActivity {
advancedSettingsLayout.addView(changeLanguage);
advancedSettingsLayout.addView(changeCurrency);
advancedSettingsLayout.addView(tokenScriptManagement);
}
private void onConsoleClicked() {
@ -137,6 +146,11 @@ public class AdvancedSettingsActivity extends BaseActivity {
startActivityForResult(intent, C.UPDATE_CURRENCY);
}
private void onTokenScriptManagementClicked() {
Intent intent = new Intent(this, TokenScriptManagementActivity.class);
startActivity(intent);
}
private void showXMLOverrideDialog() {
AWalletConfirmationDialog cDialog = new AWalletConfirmationDialog(this);
cDialog.setTitle(R.string.enable_xml_override_dir);

@ -0,0 +1,51 @@
package com.alphawallet.app.ui;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.alphawallet.app.R;
import com.alphawallet.app.entity.tokenscript.TokenScriptFile;
import com.alphawallet.app.ui.widget.adapter.TokenScriptManagementAdapter;
import com.alphawallet.app.viewmodel.TokenScriptManagementViewModel;
import com.alphawallet.app.viewmodel.TokenScriptManagementViewModelFactory;
import java.util.Map;
import javax.inject.Inject;
import dagger.android.AndroidInjection;
public class TokenScriptManagementActivity extends BaseActivity {
@Inject
TokenScriptManagementViewModelFactory tokenScriptManagementViewModelFactory;
private TokenScriptManagementViewModel viewModel;
private RecyclerView tokenScriptList;
@Override
protected void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_token_script_management);
toolbar();
setTitle(getString(R.string.tokenscript_management));
enableDisplayHomeAsUp();
tokenScriptList = findViewById(R.id.token_script_list);
tokenScriptList.setLayoutManager(new LinearLayoutManager(this));
viewModel = ViewModelProviders.of(this, tokenScriptManagementViewModelFactory)
.get(TokenScriptManagementViewModel.class);
Map<String, TokenScriptFile> tokenFiles = viewModel.getFileList();
if (tokenFiles != null)
{
tokenScriptList.setAdapter(new TokenScriptManagementAdapter(this, tokenFiles));
}
}
}

@ -0,0 +1,69 @@
package com.alphawallet.app.ui.widget.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.alphawallet.app.R;
import com.alphawallet.app.entity.tokenscript.TokenScriptFile;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class TokenScriptManagementAdapter extends RecyclerView.Adapter<TokenScriptManagementAdapter.TokenHolder> {
private Context context;
private LayoutInflater inflater;
private Map<String, TokenScriptFile> values;
private List<String> keyValues;
public TokenScriptManagementAdapter(Context context, Map<String, TokenScriptFile> values) {
this.context = context;
this.values = values;
inflater = LayoutInflater.from(context);
keyValues = new ArrayList<>(values.keySet());
}
@Override
public TokenHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i)
{
return new TokenHolder(inflater.inflate(R.layout.item_tokenscript_management,viewGroup,false));
}
@Override
public void onBindViewHolder(@NonNull TokenHolder tokenHolder, int pos) {
String tokenAddress = keyValues.get(pos);
TokenScriptFile tokenFile = values.get(tokenAddress);
tokenHolder.txtToken.setText(tokenFile.getTokenName());
tokenHolder.txtTokenAddress.setText(tokenAddress);
tokenHolder.txtTokenFile.setText(values.get(tokenAddress).getName());
}
@Override
public int getItemCount() {
return values.size();
}
class TokenHolder extends RecyclerView.ViewHolder {
TextView txtToken;
TextView txtTokenFile;
TextView txtTokenAddress;
public TokenHolder(@NonNull View itemView) {
super(itemView);
txtToken = itemView.findViewById(R.id.token_name);
txtTokenFile = itemView.findViewById(R.id.token_file);
txtTokenAddress = itemView.findViewById(R.id.token_address);
}
}
}

@ -0,0 +1,40 @@
package com.alphawallet.app.viewmodel;
import android.util.SparseArray;
import com.alphawallet.app.entity.tokenscript.TokenScriptFile;
import com.alphawallet.app.service.AssetDefinitionService;
import java.util.Map;
public class TokenScriptManagementViewModel extends BaseViewModel {
private final AssetDefinitionService assetDefinitionService;
public TokenScriptManagementViewModel(AssetDefinitionService assetDefinitionService) {
this.assetDefinitionService = assetDefinitionService;
}
public Map<String, TokenScriptFile> getFileList() {
Map<String, TokenScriptFile> tokenFiles = null;
SparseArray<Map<String, TokenScriptFile>> fileList = assetDefinitionService.getAssetDefinitions();
if (fileList != null && fileList.size() > 0) {
tokenFiles = fileList.valueAt(0);
for (int i = 1; i < fileList.size(); i++) {
Map<String, TokenScriptFile> tokens = fileList.valueAt(i);
boolean isValid = true;
for (TokenScriptFile file : tokens.values()) {
if (!file.isValidTokenScript()) {
isValid = false;
break;
}
}
if (isValid) {
tokenFiles.putAll(tokens);
}
}
}
return tokenFiles;
}
}

@ -0,0 +1,26 @@
package com.alphawallet.app.viewmodel;
import android.arch.lifecycle.ViewModel;
import android.arch.lifecycle.ViewModelProvider;
import android.support.annotation.NonNull;
import com.alphawallet.app.service.AssetDefinitionService;
import javax.inject.Inject;
public class TokenScriptManagementViewModelFactory implements ViewModelProvider.Factory {
private final AssetDefinitionService assetDefinitionService;
@Inject
public TokenScriptManagementViewModelFactory(AssetDefinitionService assetDefinitionService) {
this.assetDefinitionService = assetDefinitionService;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
return (T) new TokenScriptManagementViewModel(assetDefinitionService);
}
}

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.alphawallet.app.ui.TokenScriptManagementActivity">
<include layout="@layout/layout_simple_toolbar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/token_script_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/token_name"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_marginStart="@dimen/dp5"
android:layout_weight="0.5"
android:fontFamily="@font/font_regular"
android:gravity="center_vertical"
android:paddingStart="@dimen/dp16"
android:textColor="@color/black"
android:textSize="17sp"
tools:text="Setting Title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/alabaster"
android:minHeight="61dp"
android:orientation="vertical"
android:padding="@dimen/dp5">
<TextView
android:id="@+id/token_file"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/dp5"
android:fontFamily="@font/font_regular"
android:paddingStart="@dimen/dp16"
android:textColor="@color/black"
android:textSize="17sp"
tools:text="Setting Title" />
<TextView
android:id="@+id/token_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp5"
android:layout_marginEnd="@dimen/dp5"
android:ellipsize="end"
android:paddingStart="@dimen/dp12"
android:fontFamily="@font/font_light"
android:lines="1"
android:maxLines="1"
android:text="Setting Subtitle"
android:textColor="@color/dove"
android:textSize="12sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/silver" />
</LinearLayout>

@ -584,6 +584,7 @@
<string name="message_version_support_warning">Starting Version 2.3, AlphaWallet will no longer support devices running on Android 6.0 and below.</string>
<string name="hide_notification">Hide Notification</string>
<string name="card_view_not_found_error">%1$s not found</string>
<string name="tokenscript_management">Tokenscript Management</string>
<!-- Gas Slider -->
<string name="speed_gas">Speed (Gas)</string>

Loading…
Cancel
Save