From 4ff9aa18e4538ce96bf62534a9da203b879ec672 Mon Sep 17 00:00:00 2001 From: sharafzaman Date: Sun, 30 Sep 2018 02:11:29 +0530 Subject: [PATCH 1/7] setTitle bug fixed; --- .../java/nodebase/tech/akshaynexus/MasternodeListView.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java index 47544ec..8c8d47c 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -35,18 +35,13 @@ public class MasternodeListView extends BaseDrawerActivity implements MyRecycler protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { getLayoutInflater().inflate(R.layout.fragment_masternode,container); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); + setTitle("MasterNode"); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); totalcount = (TextView) findViewById(R.id.mncountlabel); navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, - 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<>(); From abdb2ef00d38274351c62f5911ca2b55ac3e4d5c Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 3 Oct 2018 10:22:50 +0300 Subject: [PATCH 2/7] stuff --- app/app.iml | 32 +++++--- app/build.gradle | 2 + .../tech/akshaynexus/MasternodeListView.java | 66 +++++++++++++++- .../akshaynexus/MyRecyclerViewAdapter.java | 2 +- .../nodebase/tech/akshaynexus/Utility.java | 75 +++++++++++++++++++ .../main/res/layout/fragment_masternode.xml | 4 + .../main/res/layout/masternode_list_model.xml | 39 +++++++++- 7 files changed, 202 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/nodebase/tech/akshaynexus/Utility.java 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/MasternodeListView.java b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java index 8c8d47c..03a3874 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -12,13 +12,28 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +<<<<<<< Updated upstream +======= +import android.util.Log; +>>>>>>> Stashed changes import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; 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 org.json.JSONObject; + import java.util.ArrayList; +import java.util.HashMap; import nodebase.org.nodebasewallet.R; import nodebase.org.nodebasewallet.ui.base.BaseDrawerActivity; @@ -30,18 +45,35 @@ public class MasternodeListView extends BaseDrawerActivity implements MyRecyclerViewAdapter.ItemClickListener, NavigationView.OnNavigationItemSelectedListener { MyRecyclerViewAdapter adapter; private DrawerLayout drawer; + ArrayList> masternodeapilist; + HashMap hashMap; + TextView totalcount; private NavigationView navigationView; @Override protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { getLayoutInflater().inflate(R.layout.fragment_masternode,container); +<<<<<<< Updated upstream + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); +======= + setTitle("Masternodes"); - setTitle("MasterNode"); +>>>>>>> Stashed changes drawer = (DrawerLayout) findViewById(R.id.drawer_layout); totalcount = (TextView) findViewById(R.id.mncountlabel); navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); +<<<<<<< Updated upstream + ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, + drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + drawer.addDrawerListener(toggle); + toggle.syncState(); +======= +setNavigationMenuItemChecked(3); +>>>>>>> Stashed changes // data to populate the RecyclerView with ArrayList animalNames = new ArrayList<>(); @@ -50,7 +82,31 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { animalNames.add("Camel"); animalNames.add("Sheep"); animalNames.add("Goat"); + 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.replaceAll("\t", ""); + inputString = inputString.replaceAll("\n", ""); + inputString = inputString.replaceAll(" ", ""); + inputString = inputString.replaceAll("\\s", ""); + String myJsonString=myJsonString.replaceAll("\\\\",""); + JSONArray dataa = new JSONArray(inputString); + hashMap = new HashMap<>(Utility.jsonToMap(dataa)) ; + } catch (JSONException e) { + e.printStackTrace(); + } + + + } + }); // set up the RecyclerView RecyclerView recyclerView = findViewById(R.id.rvMasternodeList); recyclerView.setLayoutManager(new LinearLayoutManager(this)); @@ -58,8 +114,8 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { adapter.setClickListener(this); recyclerView.setAdapter(adapter); totalcount.setText(animalNames.size() + ""); - recyclerView.addItemDecoration(new DividerItemDecoration(this, - DividerItemDecoration.VERTICAL)); +// recyclerView.addItemDecoration(new DividerItemDecoration(this, +// DividerItemDecoration.VERTICAL)); } @Override @@ -67,7 +123,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..73d155a 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java @@ -49,7 +49,7 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL ViewHolder(View itemView) { super(itemView); - myTextView = itemView.findViewById(R.id.MNName); + myTextView = itemView.findViewById(R.id.pubkeymn); itemView.setOnClickListener(this); } 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..4b07051 --- /dev/null +++ b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java @@ -0,0 +1,75 @@ +package nodebase.tech.akshaynexus; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class Utility { + + public static Map jsonToMap(Object json) throws JSONException { + + if(json instanceof JSONObject) + return _jsonToMap_((JSONObject)json) ; + + else if (json instanceof String) + { + JSONObject jsonObject = new JSONObject((String)json) ; + return _jsonToMap_(jsonObject) ; + } + return null ; + } + + + private static Map _jsonToMap_(JSONObject json) throws JSONException { + Map retMap = new HashMap(); + + if(json != JSONObject.NULL) { + retMap = toMap(json); + } + return retMap; + } + + + private static Map toMap(JSONObject object) throws JSONException { + Map map = new HashMap(); + + Iterator keysItr = object.keys(); + while(keysItr.hasNext()) { + String key = keysItr.next(); + Object value = object.get(key); + + if(value instanceof JSONArray) { + value = toList((JSONArray) value); + } + + else if(value instanceof JSONObject) { + value = toMap((JSONObject) value); + } + map.put(key, value); + } + return map; + } + + + public static List toList(JSONArray array) throws JSONException { + List list = new ArrayList(); + for(int i = 0; i < array.length(); i++) { + Object value = array.get(i); + if(value instanceof JSONArray) { + value = toList((JSONArray) value); + } + + else if(value instanceof JSONObject) { + value = toMap((JSONObject) value); + } + list.add(value); + } + return list; + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_masternode.xml b/app/src/main/res/layout/fragment_masternode.xml index c905d16..8fb4c63 100644 --- a/app/src/main/res/layout/fragment_masternode.xml +++ b/app/src/main/res/layout/fragment_masternode.xml @@ -26,7 +26,11 @@ >>>>>> Stashed changes android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" 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 From 0b39500327511f8047c215c0b013908ecd88390c Mon Sep 17 00:00:00 2001 From: sharafzaman Date: Wed, 3 Oct 2018 18:50:59 +0530 Subject: [PATCH 3/7] raw data converted to jsonarray; --- .../tech/akshaynexus/MasternodeListView.java | 24 +++++++------------ .../main/res/layout/fragment_masternode.xml | 4 ---- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java index 03a3874..331ca28 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -12,10 +12,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -<<<<<<< Updated upstream -======= import android.util.Log; ->>>>>>> Stashed changes import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -52,28 +49,24 @@ public class MasternodeListView extends BaseDrawerActivity implements MyRecycler @Override protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { getLayoutInflater().inflate(R.layout.fragment_masternode,container); -<<<<<<< Updated upstream Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); -======= + setTitle("Masternodes"); ->>>>>>> Stashed changes drawer = (DrawerLayout) findViewById(R.id.drawer_layout); totalcount = (TextView) findViewById(R.id.mncountlabel); navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); -<<<<<<< Updated upstream ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); -======= + setNavigationMenuItemChecked(3); ->>>>>>> Stashed changes // data to populate the RecyclerView with ArrayList animalNames = new ArrayList<>(); @@ -93,13 +86,12 @@ public void success(Request request, Response response, String data) { //do something when it is successful try { String inputString = data; - inputString = inputString.replaceAll("\t", ""); - inputString = inputString.replaceAll("\n", ""); - inputString = inputString.replaceAll(" ", ""); - inputString = inputString.replaceAll("\\s", ""); - String myJsonString=myJsonString.replaceAll("\\\\",""); - JSONArray dataa = new JSONArray(inputString); - hashMap = new HashMap<>(Utility.jsonToMap(dataa)) ; + inputString = inputString.replace("\\\\n", ""); + inputString = inputString.replace("\\\\\\", ""); + inputString = inputString.substring(3); + System.out.println(inputString); + JSONArray jsonArray = new JSONArray(inputString); + hashMap = new HashMap<>(Utility.jsonToMap(jsonArray)) ; } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/res/layout/fragment_masternode.xml b/app/src/main/res/layout/fragment_masternode.xml index 8fb4c63..c905d16 100644 --- a/app/src/main/res/layout/fragment_masternode.xml +++ b/app/src/main/res/layout/fragment_masternode.xml @@ -26,11 +26,7 @@ >>>>>> Stashed changes android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" From 045341e83f80c4ca9198d9786e565ed38e18d7e3 Mon Sep 17 00:00:00 2001 From: sharafzaman Date: Wed, 3 Oct 2018 19:21:46 +0530 Subject: [PATCH 4/7] Model class for data parsing data; --- .../nodebase/tech/akshaynexus/JsonData.java | 30 +++++++++++++++++++ .../tech/akshaynexus/MasternodeListView.java | 15 ++++------ .../akshaynexus/MyRecyclerViewAdapter.java | 18 ++++++----- .../nodebase/tech/akshaynexus/Utility.java | 8 ++--- 4 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/nodebase/tech/akshaynexus/JsonData.java 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 331ca28..e2955dc 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import nodebase.org.nodebasewallet.R; import nodebase.org.nodebasewallet.ui.base.BaseDrawerActivity; @@ -43,7 +44,7 @@ public class MasternodeListView extends BaseDrawerActivity implements MyRecycler MyRecyclerViewAdapter adapter; private DrawerLayout drawer; ArrayList> masternodeapilist; - HashMap hashMap; + List mJsonDataList = new ArrayList<>(); TextView totalcount; private NavigationView navigationView; @Override @@ -69,12 +70,6 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { setNavigationMenuItemChecked(3); // 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"); Fuel.get("http://24.190.71.106:81/url", null).responseString(new Handler() { @Override public void failure(Request request, Response response, FuelError error) { @@ -91,7 +86,7 @@ public void success(Request request, Response response, String data) { inputString = inputString.substring(3); System.out.println(inputString); JSONArray jsonArray = new JSONArray(inputString); - hashMap = new HashMap<>(Utility.jsonToMap(jsonArray)) ; + //mJsonDataList = Utility.jsonToMap(jsonArray); } catch (JSONException e) { e.printStackTrace(); } @@ -102,10 +97,10 @@ public void success(Request request, Response response, String data) { // set up the RecyclerView 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() + ""); +totalcount.setText(mJsonDataList.size() + ""); // recyclerView.addItemDecoration(new DividerItemDecoration(this, // DividerItemDecoration.VERTICAL)); } diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java b/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java index 73d155a..f711693 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,8 @@ 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 animal = mData.get(position).getPubKey(); + holder.mPubKeymn.setText(animal); } // total number of rows @@ -45,11 +45,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.pubkeymn); + mPubKeymn = itemView.findViewById(R.id.pubkeymn); + mStatus = itemView.findViewById(R.id.status); + mPayeeAddr = itemView.findViewById(R.id.payeeaddr); itemView.setOnClickListener(this); } @@ -61,7 +65,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 index 4b07051..9751b7a 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java @@ -30,13 +30,13 @@ private static Map _jsonToMap_(JSONObject json) throws JSONExcep Map retMap = new HashMap(); if(json != JSONObject.NULL) { - retMap = toMap(json); + retMap = toList(json); } return retMap; } - private static Map toMap(JSONObject object) throws JSONException { + private static Map toList(JSONObject object) throws JSONException { Map map = new HashMap(); Iterator keysItr = object.keys(); @@ -49,7 +49,7 @@ private static Map toMap(JSONObject object) throws JSONException } else if(value instanceof JSONObject) { - value = toMap((JSONObject) value); + value = toList((JSONObject) value); } map.put(key, value); } @@ -66,7 +66,7 @@ public static List toList(JSONArray array) throws JSONException { } else if(value instanceof JSONObject) { - value = toMap((JSONObject) value); + value = toList((JSONObject) value); } list.add(value); } From 5237564755c3975a90d2e53e0d6e89ba106a53e8 Mon Sep 17 00:00:00 2001 From: sharafzaman Date: Wed, 3 Oct 2018 19:41:00 +0530 Subject: [PATCH 5/7] Data parsing successful --- .../tech/akshaynexus/MasternodeListView.java | 10 +++++-- .../nodebase/tech/akshaynexus/Utility.java | 30 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java index e2955dc..a3e3e71 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -1,6 +1,7 @@ package nodebase.tech.akshaynexus; import android.content.Intent; +import android.speech.tts.UtteranceProgressListener; import android.support.annotation.NonNull; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -66,6 +67,7 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); + RecyclerView recyclerView = findViewById(R.id.rvMasternodeList); setNavigationMenuItemChecked(3); @@ -86,7 +88,9 @@ public void success(Request request, Response response, String data) { inputString = inputString.substring(3); System.out.println(inputString); JSONArray jsonArray = new JSONArray(inputString); - //mJsonDataList = Utility.jsonToMap(jsonArray); + mJsonDataList = Utility.jsonToList(jsonArray); + + //mJsonDataList = Utility.jsonToList(jsonArray); } catch (JSONException e) { e.printStackTrace(); } @@ -95,12 +99,12 @@ public void success(Request request, Response response, String data) { } }); // set up the RecyclerView - RecyclerView recyclerView = findViewById(R.id.rvMasternodeList); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); adapter = new MyRecyclerViewAdapter(this, mJsonDataList); adapter.setClickListener(this); recyclerView.setAdapter(adapter); -totalcount.setText(mJsonDataList.size() + ""); + totalcount.setText(mJsonDataList.size() + ""); // recyclerView.addItemDecoration(new DividerItemDecoration(this, // DividerItemDecoration.VERTICAL)); } diff --git a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java index 9751b7a..70f2c67 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java @@ -12,22 +12,25 @@ public class Utility { - public static Map jsonToMap(Object json) throws JSONException { + public static List jsonToList(JSONArray json) throws JSONException { + List jsonData = new ArrayList<>(); - if(json instanceof JSONObject) - return _jsonToMap_((JSONObject)json) ; - - else if (json instanceof String) - { - JSONObject jsonObject = new JSONObject((String)json) ; - return _jsonToMap_(jsonObject) ; + for (int i = 0; i < json.length(); ++i) { + jsonData.add(extractObject((JSONObject)json.get(i))); } - return null ; + 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); } - private static Map _jsonToMap_(JSONObject json) throws JSONException { - Map retMap = new HashMap(); + private static List _jsonToList_(JSONObject json) throws JSONException { + List retMap = new ArrayList<>(); if(json != JSONObject.NULL) { retMap = toList(json); @@ -36,8 +39,8 @@ private static Map _jsonToMap_(JSONObject json) throws JSONExcep } - private static Map toList(JSONObject object) throws JSONException { - Map map = new HashMap(); + private static List toList(JSONObject object) throws JSONException { + List map = new ArrayList<>(); Iterator keysItr = object.keys(); while(keysItr.hasNext()) { @@ -51,7 +54,6 @@ private static Map toList(JSONObject object) throws JSONExceptio else if(value instanceof JSONObject) { value = toList((JSONObject) value); } - map.put(key, value); } return map; } From 61de305a746e3dddf91b22ef440ee0dc609e3c92 Mon Sep 17 00:00:00 2001 From: sharafzaman Date: Wed, 3 Oct 2018 19:53:59 +0530 Subject: [PATCH 6/7] fill recyclerview with data; --- .../tech/akshaynexus/MasternodeListView.java | 13 +++++++------ .../tech/akshaynexus/MyRecyclerViewAdapter.java | 8 ++++++-- .../java/nodebase/tech/akshaynexus/Utility.java | 12 ++++++++++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java index a3e3e71..476bf46 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -45,7 +45,7 @@ public class MasternodeListView extends BaseDrawerActivity implements MyRecycler MyRecyclerViewAdapter adapter; private DrawerLayout drawer; ArrayList> masternodeapilist; - List mJsonDataList = new ArrayList<>(); + List mJsonDataList; TextView totalcount; private NavigationView navigationView; @Override @@ -67,7 +67,12 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); + mJsonDataList = Utility.getJsonData(); RecyclerView recyclerView = findViewById(R.id.rvMasternodeList); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapter = new MyRecyclerViewAdapter(this, mJsonDataList); + adapter.setClickListener(this); + recyclerView.setAdapter(adapter); setNavigationMenuItemChecked(3); @@ -88,7 +93,7 @@ public void success(Request request, Response response, String data) { inputString = inputString.substring(3); System.out.println(inputString); JSONArray jsonArray = new JSONArray(inputString); - mJsonDataList = Utility.jsonToList(jsonArray); + mJsonDataList = Utility.jsonToList(adapter, jsonArray); //mJsonDataList = Utility.jsonToList(jsonArray); } catch (JSONException e) { @@ -100,10 +105,6 @@ public void success(Request request, Response response, String data) { }); // set up the RecyclerView - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - adapter = new MyRecyclerViewAdapter(this, mJsonDataList); - adapter.setClickListener(this); - recyclerView.setAdapter(adapter); totalcount.setText(mJsonDataList.size() + ""); // recyclerView.addItemDecoration(new DividerItemDecoration(this, // DividerItemDecoration.VERTICAL)); diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java b/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java index f711693..e8f5001 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MyRecyclerViewAdapter.java @@ -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).getPubKey(); - holder.mPubKeymn.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 diff --git a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java index 70f2c67..573fa8f 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java @@ -1,5 +1,7 @@ package nodebase.tech.akshaynexus; +import android.content.Context; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -12,12 +14,14 @@ public class Utility { - public static List jsonToList(JSONArray json) throws JSONException { - List jsonData = new ArrayList<>(); + 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; } @@ -74,4 +78,8 @@ else if(value instanceof JSONObject) { } return list; } + + public static List getJsonData() { + return jsonData; + } } \ No newline at end of file From 18c16ea74f96d7639927a62b569b9241fd3528aa Mon Sep 17 00:00:00 2001 From: sharafzaman Date: Wed, 3 Oct 2018 20:10:32 +0530 Subject: [PATCH 7/7] Code cleanup; --- .../tech/akshaynexus/MasternodeListView.java | 14 ++--- .../nodebase/tech/akshaynexus/Utility.java | 52 ------------------- 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java index 476bf46..b8496a1 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/MasternodeListView.java @@ -1,19 +1,15 @@ package nodebase.tech.akshaynexus; import android.content.Intent; -import android.speech.tts.UtteranceProgressListener; +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; -import android.util.Log; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -28,7 +24,6 @@ import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; @@ -74,7 +69,7 @@ protected void onCreateView(Bundle savedInstanceState, ViewGroup container) { adapter.setClickListener(this); recyclerView.setAdapter(adapter); -setNavigationMenuItemChecked(3); + setNavigationMenuItemChecked(3); // data to populate the RecyclerView with Fuel.get("http://24.190.71.106:81/url", null).responseString(new Handler() { @@ -94,8 +89,7 @@ public void success(Request request, Response response, String data) { System.out.println(inputString); JSONArray jsonArray = new JSONArray(inputString); mJsonDataList = Utility.jsonToList(adapter, jsonArray); - - //mJsonDataList = Utility.jsonToList(jsonArray); + totalcount.setText(mJsonDataList.size() + ""); } catch (JSONException e) { e.printStackTrace(); } @@ -103,9 +97,7 @@ public void success(Request request, Response response, String data) { } }); - // set up the RecyclerView - totalcount.setText(mJsonDataList.size() + ""); // recyclerView.addItemDecoration(new DividerItemDecoration(this, // DividerItemDecoration.VERTICAL)); } diff --git a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java index 573fa8f..44a7961 100644 --- a/app/src/main/java/nodebase/tech/akshaynexus/Utility.java +++ b/app/src/main/java/nodebase/tech/akshaynexus/Utility.java @@ -1,16 +1,11 @@ package nodebase.tech.akshaynexus; -import android.content.Context; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Map; public class Utility { @@ -32,53 +27,6 @@ private static JsonData extractObject(JSONObject object) throws JSONException { return new JsonData(pubkey, status, payeeAddr); } - - private static List _jsonToList_(JSONObject json) throws JSONException { - List retMap = new ArrayList<>(); - - if(json != JSONObject.NULL) { - retMap = toList(json); - } - return retMap; - } - - - private static List toList(JSONObject object) throws JSONException { - List map = new ArrayList<>(); - - Iterator keysItr = object.keys(); - while(keysItr.hasNext()) { - String key = keysItr.next(); - Object value = object.get(key); - - if(value instanceof JSONArray) { - value = toList((JSONArray) value); - } - - else if(value instanceof JSONObject) { - value = toList((JSONObject) value); - } - } - return map; - } - - - public static List toList(JSONArray array) throws JSONException { - List list = new ArrayList(); - for(int i = 0; i < array.length(); i++) { - Object value = array.get(i); - if(value instanceof JSONArray) { - value = toList((JSONArray) value); - } - - else if(value instanceof JSONObject) { - value = toList((JSONObject) value); - } - list.add(value); - } - return list; - } - public static List getJsonData() { return jsonData; }