diff --git a/app/app.iml b/app/app.iml index 31c9fe9..104c0a6 100644 --- a/app/app.iml +++ b/app/app.iml @@ -48,13 +48,6 @@ - - - - - - - @@ -62,6 +55,13 @@ + + + + + + + @@ -83,16 +83,24 @@ + + + + + + + + @@ -115,25 +123,30 @@ + - + + + + + @@ -147,6 +160,7 @@ + @@ -156,6 +170,7 @@ + @@ -171,7 +186,6 @@ - diff --git a/app/build.gradle b/app/build.gradle index 811d8ea..e942955 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -67,6 +67,8 @@ dependencies { compile 'com.android.support.constraint:constraint-layout:1.0.1' compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1' + compile 'com.github.kittinunf.fuel:fuel-android:1.15.0' //for Android + compile 'com.wang.avi:library:2.1.3' compile 'com.google.android:flexbox:0.3.0' compile 'za.co.riggaroo:materialhelptutorial:1.2.0' diff --git a/app/src/main/java/nodebase/tech/akshaynexus/JsonData.java b/app/src/main/java/nodebase/tech/akshaynexus/JsonData.java new file mode 100644 index 0000000..b87e83d --- /dev/null +++ b/app/src/main/java/nodebase/tech/akshaynexus/JsonData.java @@ -0,0 +1,30 @@ +package nodebase.tech.akshaynexus; + +/* + * Created by sh_zam on 3/10/18 + */ + +public class JsonData { + + private String mPubKey; + private String mStatus; + private String mPayeeAddress; + + public JsonData(String pubKey, String status, String payeeAddress) { + mPubKey = pubKey; + mStatus = status; + mPayeeAddress = payeeAddress; + } + + public String getPubKey() { + return mPubKey; + } + + public String getStatus() { + return mStatus; + } + + public String getPayeeAddress() { + return mPayeeAddress; + } +} diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java index 47544ec..b8496a1 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -1,14 +1,12 @@ package nodebase.tech.akshaynexus; import android.content.Intent; +import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; @@ -18,7 +16,18 @@ import android.widget.TextView; import android.widget.Toast; +import com.github.kittinunf.fuel.Fuel; +import com.github.kittinunf.fuel.core.FuelError; +import com.github.kittinunf.fuel.core.Handler; +import com.github.kittinunf.fuel.core.Request; +import com.github.kittinunf.fuel.core.Response; + +import org.json.JSONArray; +import org.json.JSONException; + import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import nodebase.org.nodebasewallet.R; import nodebase.org.nodebasewallet.ui.base.BaseDrawerActivity; @@ -30,6 +39,9 @@ public class MasternodeListView extends BaseDrawerActivity implements MyRecyclerViewAdapter.ItemClickListener, NavigationView.OnNavigationItemSelectedListener { MyRecyclerViewAdapter adapter; private DrawerLayout drawer; + ArrayList> masternodeapilist; + List mJsonDataList; + TextView totalcount; private NavigationView navigationView; @Override protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { @@ -37,6 +49,9 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); + + setTitle("Masternodes"); + drawer = (DrawerLayout) findViewById(R.id.drawer_layout); totalcount = (TextView) findViewById(R.id.mncountlabel); @@ -47,24 +62,44 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); - - // data to populate the RecyclerView with - ArrayList animalNames = new ArrayList<>(); - animalNames.add("Horse"); - animalNames.add("Cow"); - animalNames.add("Camel"); - animalNames.add("Sheep"); - animalNames.add("Goat"); - - // set up the RecyclerView + mJsonDataList = Utility.getJsonData(); RecyclerView recyclerView = findViewById(R.id.rvMasternodeList); recyclerView.setLayoutManager(new LinearLayoutManager(this)); - adapter = new MyRecyclerViewAdapter(this, animalNames); + adapter = new MyRecyclerViewAdapter(this, mJsonDataList); adapter.setClickListener(this); recyclerView.setAdapter(adapter); -totalcount.setText(animalNames.size() + ""); - recyclerView.addItemDecoration(new DividerItemDecoration(this, - DividerItemDecoration.VERTICAL)); + + setNavigationMenuItemChecked(3); + + // data to populate the RecyclerView with + Fuel.get("http://24.190.71.106:81/url", null).responseString(new Handler() { + @Override + public void failure(Request request, Response response, FuelError error) { + //do something when it is failure + } + + @Override + public void success(Request request, Response response, String data) { + //do something when it is successful + try { + String inputString = data; + inputString = inputString.replace("\\\\n", ""); + inputString = inputString.replace("\\\\\\", ""); + inputString = inputString.substring(3); + System.out.println(inputString); + JSONArray jsonArray = new JSONArray(inputString); + mJsonDataList = Utility.jsonToList(adapter, jsonArray); + totalcount.setText(mJsonDataList.size() + ""); + } catch (JSONException e) { + e.printStackTrace(); + } + + + } + }); + +// recyclerView.addItemDecoration(new DividerItemDecoration(this, +// DividerItemDecoration.VERTICAL)); } @Override @@ -72,7 +107,9 @@ public void onItemClick(View view, int position) { Toast.makeText(this, "You clicked " + adapter.getItem(position) + " on row number " + position, Toast.LENGTH_SHORT).show(); } - + protected void setNavigationMenuItemChecked(int pos){ + navigationView.getMenu().getItem(pos).setChecked(true); + } @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { // Handle navigation view item clicks here. diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java b/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java index d15ca83..e8f5001 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java @@ -12,12 +12,12 @@ public class MyRecyclerViewAdapter extends RecyclerView.Adapter { - private List mData; + private List mData; private LayoutInflater mInflater; private ItemClickListener mClickListener; // data is passed into the constructor - MyRecyclerViewAdapter(Context context, List data) { + MyRecyclerViewAdapter(Context context, List data) { this.mInflater = LayoutInflater.from(context); this.mData = data; } @@ -32,8 +32,12 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // binds the data to the TextView in each row @Override public void onBindViewHolder(ViewHolder holder, int position) { - String animal = mData.get(position); - holder.myTextView.setText(animal); + String pubKey = mData.get(position).getPubKey(); + String status = mData.get(position).getStatus(); + String payeeAddr = mData.get(position).getPayeeAddress(); + holder.mPubKeymn.setText(pubKey); + holder.mStatus.setText(status); + holder.mPayeeAddr.setText(payeeAddr); } // total number of rows @@ -45,11 +49,15 @@ public int getItemCount() { // stores and recycles views as they are scrolled off screen public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - TextView myTextView; + TextView mPubKeymn; + TextView mStatus; + TextView mPayeeAddr; ViewHolder(View itemView) { super(itemView); - myTextView = itemView.findViewById(R.id.MNName); + mPubKeymn = itemView.findViewById(R.id.pubkeymn); + mStatus = itemView.findViewById(R.id.status); + mPayeeAddr = itemView.findViewById(R.id.payeeaddr); itemView.setOnClickListener(this); } @@ -61,7 +69,7 @@ public void onClick(View view) { // convenience method for getting data at click position String getItem(int id) { - return mData.get(id); + return mData.get(id).getPubKey(); } // allows clicks events to be caught diff --git a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java new file mode 100644 index 0000000..44a7961 --- /dev/null +++ b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java @@ -0,0 +1,33 @@ +package nodebase.tech.akshaynexus; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class Utility { + + private static List jsonData = new ArrayList<>(); + + public static List jsonToList(MyRecyclerViewAdapter adapter, JSONArray json) throws JSONException { + + for (int i = 0; i < json.length(); ++i) { + jsonData.add(extractObject((JSONObject)json.get(i))); + } + adapter.notifyDataSetChanged(); + return jsonData; + } + + private static JsonData extractObject(JSONObject object) throws JSONException { + String pubkey = (String)object.get("txhash"); + String status = (String)object.get("status"); + String payeeAddr = (String)object.get("addr"); + return new JsonData(pubkey, status, payeeAddr); + } + + public static List getJsonData() { + return jsonData; + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/masternode_list_model.xml b/app/src/main/res/layout/masternode_list_model.xml index 30b4f12..c734505 100644 --- a/app/src/main/res/layout/masternode_list_model.xml +++ b/app/src/main/res/layout/masternode_list_model.xml @@ -1,15 +1,46 @@ - + + + android:layout_alignParentTop="true" + android:layout_alignStart="@+id/pubkeymn" + android:layout_marginTop="36dp" + android:text="Status:" + android:textSize="12sp" /> - \ No newline at end of file + + + \ No newline at end of file