parent
82d8122a2f
commit
94add59f14
@ -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); |
||||
} |
||||
} |
@ -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> |
Loading…
Reference in new issue