Skip to content

Commit

Permalink
- support secondary key index for 'get table'
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnibble committed Oct 24, 2018
1 parent 6eb426e commit bb05120
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "io.plactal.eoscommander"
minSdkVersion 18
targetSdkVersion 27
versionCode 19
versionName "2.5.1"
versionCode 20
versionName "2.6.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

// 벡터 이미지
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ public Observable<EosChainInfo> getChainInfo(){
return mNodeosApi.readInfo("get_info");
}

public Observable<String> getTable( String accountName, String code, String table,
String tableKey, String lowerBound, String upperBound, int limit ){
public Observable<String> getTable( String accountName, String code, String table
,int indexPos, String keyType, String encodeType,String lowerBound, String upperBound, int limit ){

return mNodeosApi.getTable(
new GetTableRequest(accountName, code, table, tableKey, lowerBound, upperBound, limit))
new GetTableRequest(accountName, code, table, indexPos , keyType, encodeType, lowerBound, upperBound, limit))
.map( tableResult -> Utils.prettyPrintJson(tableResult));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public class GetTableRequest {
private String table;

@Expose
private String table_key = "";
private String key_type = "";

@Expose
private int index_position = 0;

@Expose
private String encode_type = "";

@Expose
private String lower_bound= "";
Expand All @@ -38,12 +44,16 @@ public class GetTableRequest {



public GetTableRequest( String scope, String code, String table, String tableKey, String lowerBound, String upperBound, int limit ) {
public GetTableRequest( String scope, String code, String table,
int indexPos, String keyType, String encodeType, String lowerBound, String upperBound, int limit ) {
this.scope = scope;
this.code = code;
this.table = table;

this.table_key = StringUtils.isEmpty( tableKey ) ? "" : tableKey;
this.key_type = keyType;
this.encode_type = encodeType;
this.index_position = indexPos < 0 ? 0 : indexPos;

this.lower_bound = StringUtils.isEmpty( lowerBound) ? "" : lowerBound;
this.upper_bound = StringUtils.isEmpty( upperBound) ? "" : upperBound;
this.limit = limit <= 0 ? DEFAULT_FETCH_LIMIT : limit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public class BasePresenter<V extends MvpView> implements MvpPresenter<V> {
private SchedulerProvider mSchedulerProvider;
private CompositeDisposable mCompositeDisposable;

protected RefValue<Long> mAccountHistoryVersion = new RefValue<>(0L);

@Override
public void attachView(V mvpView) {
mMvpView = mvpView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
Expand Down Expand Up @@ -55,6 +56,10 @@ public class GetTableFragment extends BaseFragment implements GetTableMvpView {
private AppCompatSpinner mTableNameSpinner;
private ArrayAdapter<String> mTableNameAdapter;

private AppCompatSpinner mIndexPosSpinner;
private AppCompatSpinner mIndexTypeSpinner;
private AppCompatSpinner mIndexEncodingSpinner;

private View mRootView;


Expand Down Expand Up @@ -93,6 +98,63 @@ protected void setUpView(View view) {
mTableNameSpinner = view.findViewById( R.id.sp_table_list);

setupAccountHistory();

mPresenter.onFinishedSetupView();
}

@Override
public void populateKeyInfo( List<String> posNames, List<String> types, List<String> typeEncodings) {

// index position
mIndexPosSpinner = setDropDownList( R.id.sp_key_pos_list, posNames, null );


AdapterView.OnItemSelectedListener typeOrEncodingSelectionListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mPresenter.onIndexTypeOrEncodingSelected( mIndexTypeSpinner.getSelectedItemPosition(), mIndexEncodingSpinner.getSelectedItemPosition());
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};

// index type
mIndexTypeSpinner = setDropDownList(R.id.sp_key_type_list, types, typeOrEncodingSelectionListener );

// index encoding
mIndexEncodingSpinner = setDropDownList( R.id.sp_key_type_encode_list, typeEncodings, typeOrEncodingSelectionListener );


// initialize spinner selection.
if ( mIndexPosSpinner != null ) mIndexPosSpinner.setSelection(0);

if ( mIndexTypeSpinner != null ) mIndexTypeSpinner.setSelection(0);


if ( mIndexEncodingSpinner != null ) mIndexEncodingSpinner.setSelection(0);
}

private AppCompatSpinner setDropDownList(int dropDownListId, List<String> data, AdapterView.OnItemSelectedListener itemSelectedListener) {
AppCompatSpinner spinner = mRootView.findViewById( dropDownListId );
if ( spinner == null ) {
return null;
}

ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
spinner.setAdapter( adapter );

if ( itemSelectedListener != null ) {
spinner.setOnItemSelectedListener(itemSelectedListener);
}

return spinner;
}

public void setTypeEncodingSelection( int position ) {
if ( mIndexEncodingSpinner != null ) mIndexEncodingSpinner.setSelection( position );
}

private void onGetTable() {
Expand All @@ -102,8 +164,12 @@ private void onGetTable() {
}

mPresenter.getTable ( mScope.getText().toString()
, mTvCode.getText().toString(), mTableNameSpinner.getSelectedItem().toString(),
getEditString( R.id.et_key), getEditString(R.id.et_lower_bound), getEditString(R.id.et_upper_bound), getEditString(R.id.et_limit));
, mTvCode.getText().toString(), mTableNameSpinner.getSelectedItem().toString()
, mIndexPosSpinner.getSelectedItemPosition()
, mIndexTypeSpinner.getSelectedItemPosition()
, mIndexEncodingSpinner.getSelectedItemPosition()
, getEditString(R.id.et_lower_bound), getEditString(R.id.et_upper_bound), getEditString(R.id.et_limit));

}

private String getEditString( int id ) {
Expand Down Expand Up @@ -149,4 +215,5 @@ public void showTableList( List<String> tables ) {
showToast( R.string.table_loaded );

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@
public interface GetTableMvpView extends MvpView {
void showTableResult(String result, String statusInfo);
void showTableList( List<String> tables );

void populateKeyInfo( List<String> posNames, List<String> types, List<String> typeEncodings);

void setTypeEncodingSelection( int position );
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package io.plactal.eoscommander.ui.gettable;

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

Expand All @@ -46,10 +47,57 @@ public class GetTablePresenter extends BasePresenter<GetTableMvpView> {
@Inject
EoscDataManager mDataManager;

private static final String[] KEY_INDEX_POSITION = { "primary (first)", "2nd", "3rd", "4th", "5th"
, "6th", "7th", "8th", "9th", "10th"};
private static final int FIRST_POS_INDEX_VAL = 1;


private static final String[] KEY_INDEX_TYPES = { "name(account_name)", "i64", "i128", "i256", "float64", "float128", "ripemd160", "sha256" };
private static final int KEY_INDEX_TYPES_POSITION_I256 = 3;
private static final int KEY_INDEX_TYPES_POSITION_RIPEMD160 = 6;


private static final String[] KEY_INDEX_ENCODINGS = { "dec", "hex" };
private static final int KEY_INDEX_ENCODINGS_POS_DEC = 0;
private static final int KEY_INDEX_ENCODINGS_POS_HEX = 1;

@Inject
public GetTablePresenter(){
}

public void onFinishedSetupView(){

getMvpView().populateKeyInfo( Arrays.asList( KEY_INDEX_POSITION )
, Arrays.asList( KEY_INDEX_TYPES ), Arrays.asList( KEY_INDEX_ENCODINGS ) );

}

public void onIndexTypeOrEncodingSelected(int typePosSelected, int encodingPosSelected ){
// match type and encoding!

// KEY_INDEX_TYPES = { "name(account_name)", "i64", "i128", "i256", "float64", "float128", "ripemd160", "sha256" }

// (i64 , i128 , float64, float128) only support "dec" encoding ( encodePos 0 )
// i256 - supports both 'dec' and 'hex'
// ripemd160 and sha256 is 'hex' only

if ( typePosSelected >= KEY_INDEX_TYPES_POSITION_RIPEMD160 ) { // ripemd160, sha256
// only hex!
if ( KEY_INDEX_ENCODINGS_POS_HEX != encodingPosSelected ) {
getMvpView().setTypeEncodingSelection( KEY_INDEX_ENCODINGS_POS_HEX );
}

return;
}

if ( KEY_INDEX_TYPES_POSITION_I256 != typePosSelected ) {
// only dec !
if ( KEY_INDEX_ENCODINGS_POS_DEC != encodingPosSelected ) {
getMvpView().setTypeEncodingSelection( KEY_INDEX_ENCODINGS_POS_DEC );
}
}
}

private List<String> getTableNames( List<EosAbiTable> abiTables ) {
if ( null == abiTables ){
return new ArrayList<>();
Expand Down Expand Up @@ -92,9 +140,17 @@ public void onNext(List<String> result) {
);
}

public void getTable(String accountName, String contract, String table, String tableKey, String lowerBound, String upperBound, String limit ) {
private int getIndexPosValue( int position) {
return position + FIRST_POS_INDEX_VAL;
}

public void getTable(String accountName, String contract, String table,
int keyPosition, int keyType, int keyEncoding, String lowerBound, String upperBound, String limit ) {

addDisposable(
mDataManager.getTable( accountName, contract, table, tableKey, lowerBound, upperBound, Utils.parseIntSafely(limit, 0))
mDataManager.getTable( accountName, contract, table
, getIndexPosValue( keyPosition ), KEY_INDEX_TYPES[ keyType ], KEY_INDEX_ENCODINGS[ keyEncoding ],
lowerBound, upperBound, Utils.parseIntSafely(limit, 0))
.doOnNext( result -> mDataManager.addAccountHistory( accountName, contract) )
.subscribeOn(getSchedulerProvider().io())
.observeOn(getSchedulerProvider().ui())
Expand Down
83 changes: 82 additions & 1 deletion app/src/main/res/layout/fragment_get_table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginBottom="48dp"
android:orientation="horizontal"
android:background="@drawable/round_border_input">
<TextView
Expand All @@ -73,6 +73,86 @@
android:spinnerMode="dropdown"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:background="@drawable/round_border_input">
<TextView
android:id="@+id/label_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:padding="8dp"
android:gravity="center"
android:textColor="@color/colorPrimary"
android:text="@string/index" />

<android.support.v7.widget.AppCompatSpinner
android:id="@+id/sp_key_pos_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignBaseline="@+id/label_key"
android:theme="@style/ThemeOverlay.AppCompat.Light"
android:padding="8dp"
android:spinnerMode="dropdown"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:background="@drawable/round_border_input">
<TextView
android:id="@+id/label_key_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center"
android:textColor="@color/colorPrimary"
android:text="@string/index_type" />

<android.support.v7.widget.AppCompatSpinner
android:id="@+id/sp_key_type_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignBaseline="@+id/label_key_type"
android:theme="@style/ThemeOverlay.AppCompat.Light"
android:padding="8dp"
android:spinnerMode="dropdown"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="48dp"
android:orientation="horizontal"
android:background="@drawable/round_border_input">
<TextView
android:id="@+id/key_type_encode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center"
android:textColor="@color/colorPrimary"
android:text="@string/encode_type" />

<android.support.v7.widget.AppCompatSpinner
android:id="@+id/sp_key_type_encode_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignBaseline="@+id/key_type_encode"
android:theme="@style/ThemeOverlay.AppCompat.Light"
android:padding="8dp"
android:spinnerMode="dropdown"/>
</LinearLayout>

<!--
<EditText
android:id="@+id/et_key"
android:layout_width="match_parent"
Expand All @@ -86,6 +166,7 @@
android:imeOptions="actionNext"
android:nextFocusDown="@+id/et_lower_bound"
android:hint="@string/table_key" />
-->

<EditText
android:id="@+id/et_lower_bound"
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,22 @@
<string name="decimal">decimal</string>

<string name="cannot_del_wallet_unlocked">You cannot delete wallet unlocked!</string>
<string name="index">index: </string>
<string name="index_type">index type: </string>
<string name="encode_type">encode type: </string>

<!--
<string-array name="key_type_array">
<item>i64</item>
<item>i128</item>
<item>i64</item>
<item>i64</item>
<item>i64</item>
<item>i64</item>
<item>i64</item>
</string-array>
<string name="dec">dec</string>
<string name="hex">hex</string>
-->
</resources>

0 comments on commit bb05120

Please sign in to comment.