From 4ff5db67ff080faa6eb07e404b7cfc0d7d33d085 Mon Sep 17 00:00:00 2001 From: shetyeshivani Date: Mon, 5 Dec 2016 20:35:55 +0530 Subject: [PATCH] productlist --- .../neostore/adapter/TableAdapter.java | 128 ++++++++++++++++++ .../neostore/model/Product/DataModel.java | 72 ++++++++++ .../model/Product/ProductResponseModel.java | 97 +++++++++++++ .../neostore/serviceapi/GetServices.java | 19 ++- .../neosoft/neostore/serviceapi/Services.java | 14 +- .../com/neosoft/neostore/ui/HomeActivity.java | 12 ++ .../neosoft/neostore/ui/HomepageFragment.java | 4 +- .../neosoft/neostore/ui/LoginActivity.java | 12 ++ .../neosoft/neostore/ui/TableFragment.java | 73 ++++++++++ app/src/main/res/layout/fragment_tables.xml | 15 ++ app/src/main/res/layout/row_tablelist.xml | 87 ++++++++++++ app/src/main/res/values/colors.xml | 3 +- app/src/main/res/values/styles.xml | 4 +- 13 files changed, 532 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/neosoft/neostore/adapter/TableAdapter.java create mode 100644 app/src/main/java/com/neosoft/neostore/model/Product/DataModel.java create mode 100644 app/src/main/java/com/neosoft/neostore/model/Product/ProductResponseModel.java create mode 100644 app/src/main/java/com/neosoft/neostore/ui/TableFragment.java create mode 100644 app/src/main/res/layout/fragment_tables.xml create mode 100644 app/src/main/res/layout/row_tablelist.xml diff --git a/app/src/main/java/com/neosoft/neostore/adapter/TableAdapter.java b/app/src/main/java/com/neosoft/neostore/adapter/TableAdapter.java new file mode 100644 index 0000000..92ece79 --- /dev/null +++ b/app/src/main/java/com/neosoft/neostore/adapter/TableAdapter.java @@ -0,0 +1,128 @@ +package com.neosoft.neostore.adapter; + +import android.content.Context; +import android.content.res.Resources; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.RatingBar; +import android.widget.TextView; + +import com.neosoft.neostore.model.Product.DataModel; +import com.neosoft.neostore.R; +import com.neosoft.neostore.ui.TableFragment; + +import java.util.ArrayList; +import java.util.List; + + +public class TableAdapter extends BaseAdapter implements View.OnClickListener { + private List mData; + private static LayoutInflater inflater=null; + public Resources res; + DataModel tempValues=null; + int i=0; + + public TableAdapter(Context context, List data, Resources resLocal) { + mData=data; + res = resLocal; + inflater = ( LayoutInflater )context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + @Override + public void onClick(View v) { + Log.v("TableAdapter", "=====Row button clicked====="); + } + + @Override + public int getCount() { + if(mData.size()<=0) + return 1; + return mData.size(); + } + + @Override + public Object getItem(int position) { + return position; + } + + @Override + public long getItemId(int position) { + return position; + } + + public static class ViewHolder{ + TextView tableName; + TextView tableStoreName; + TextView tableRs; + TextView tablePrice; + RatingBar tableRatingBar; + ImageView tableImage; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + View vi = convertView; + ViewHolder holder; + if(convertView==null){ + vi = inflater.inflate(R.layout.row_tablelist, null); + holder = new ViewHolder(); + holder.tableName = (TextView) vi.findViewById(R.id.textTableName); + holder.tableStoreName=(TextView)vi.findViewById(R.id.textTableStoreName); + holder.tablePrice = (TextView) vi.findViewById(R.id.textTablePrice); + holder.tableRs=(TextView)vi.findViewById(R.id.textTableRs); + holder.tableRatingBar=(RatingBar) vi.findViewById(R.id.tableRatingBar); + holder.tableImage=(ImageView)vi.findViewById(R.id.imgTables); + vi.setTag( holder ); + } + else + holder=(ViewHolder)vi.getTag(); + + if(mData.size()<=0) + { + holder.tableName.setText("No Data"); + + } + else + { + tempValues=null; + tempValues = ( DataModel ) mData.get( position ); + + + Log.e("Table Title",mData.get(position).getTableTitle()); + + holder.tableName.setText( tempValues.getTableTitle() ); + holder.tableStoreName.setText( tempValues.getTableShop() ); + holder.tablePrice.setText( tempValues.getTablePrice() ); + // holder.tableRs.setText( tempValues.getTableRs() ); + // holder.tableRatingBar.setRating(Float.parseFloat(tempValues.getTableRating())); + holder.tableImage.setImageResource(res.getIdentifier( + ""+tempValues.getTableImage() + ,null,null)); + + vi.setOnClickListener(new OnItemClickListener(position)); + } + return vi; + } + + private class OnItemClickListener implements View.OnClickListener { + + private int mPosition; + + OnItemClickListener(int position){ + mPosition = position; + } + + @Override + public void onClick(View arg0) { + + TableFragment fragment = new TableFragment(); + fragment.onItemClick(mPosition); + } + } +} + diff --git a/app/src/main/java/com/neosoft/neostore/model/Product/DataModel.java b/app/src/main/java/com/neosoft/neostore/model/Product/DataModel.java new file mode 100644 index 0000000..26c2d10 --- /dev/null +++ b/app/src/main/java/com/neosoft/neostore/model/Product/DataModel.java @@ -0,0 +1,72 @@ +package com.neosoft.neostore.model.Product; + +import com.google.gson.annotations.SerializedName; + +public class DataModel { + + @SerializedName("product_images") + private String tableImage; + + @SerializedName("name") + private String tableTitle; + + @SerializedName("producer") + private String tableShop; + + @SerializedName("cost") + private String tablePrice; + + @SerializedName("rating") + private String tableRating; + + //private String tableRs; + public String getTableImage() { + return tableImage; + } + + public void setTableImage(String tableImage) { + this.tableImage = tableImage; + } + + public String getTableTitle() { + return tableTitle; + } + + public void setTableTitle(String tableTitle) { + this.tableTitle = tableTitle; + } + + public String getTableShop() { + return tableShop; + } + + public void setTableShop(String tableShop) { + this.tableShop = tableShop; + } + + public String getTablePrice() { + return tablePrice; + } + + public void setTablePrice(String tablePrice) { + this.tablePrice = tablePrice; + } + + /*public String getTableRs() { + return tableRs; + } + + public void setTableRs(String tableRs) { + this.tableRs = tableRs; + }*/ + + public String getTableRating() { + return tableRating; + } + + public void setTableRating(String tableRating) { + this.tableRating = tableRating; + } + + +} diff --git a/app/src/main/java/com/neosoft/neostore/model/Product/ProductResponseModel.java b/app/src/main/java/com/neosoft/neostore/model/Product/ProductResponseModel.java new file mode 100644 index 0000000..fdae67a --- /dev/null +++ b/app/src/main/java/com/neosoft/neostore/model/Product/ProductResponseModel.java @@ -0,0 +1,97 @@ +package com.neosoft.neostore.model.Product; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; +import java.util.List; + +public class ProductResponseModel { + @SerializedName("status") + @Expose + private Integer status; + @SerializedName("data") + @Expose + private List data; + @SerializedName("message") + @Expose + private String message; + @SerializedName("user_msg") + @Expose + private String userMsg; + + /** + * + * @return + * The status + */ + public Integer getStatus() { + return status; + } + + /** + * + * @param status + * The status + */ + public void setStatus(Integer status) { + this.status = status; + } + + /** + * + * @return + * The data + */ + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + /** + * + * @return + * The message + */ + public String getMessage() { + return message; + } + + /** + * + * @param message + * The message + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * + * @return + * The userMsg + */ + public String getUserMsg() { + return userMsg; + } + + /** + * + * @param userMsg + * The user_msg + */ + public void setUserMsg(String userMsg) { + this.userMsg = userMsg; + } + + @Override public String toString() { + return "ProductResponseModel{" + + "status=" + status + + ", data=" + data + + ", message='" + message + '\'' + + ", userMsg='" + userMsg + '\'' + + '}'; + } + +} diff --git a/app/src/main/java/com/neosoft/neostore/serviceapi/GetServices.java b/app/src/main/java/com/neosoft/neostore/serviceapi/GetServices.java index 435e43a..38d5c46 100644 --- a/app/src/main/java/com/neosoft/neostore/serviceapi/GetServices.java +++ b/app/src/main/java/com/neosoft/neostore/serviceapi/GetServices.java @@ -1,11 +1,11 @@ package com.neosoft.neostore.serviceapi; -import android.util.Log; - +import com.neosoft.neostore.model.Product.ProductResponseModel; import com.neosoft.neostore.model.login.LoginResponseModel; import com.neosoft.neostore.model.register.RegisterResponseModel; import okhttp3.FormBody; +import okhttp3.HttpUrl; import okhttp3.RequestBody; import static com.neosoft.neostore.serviceapi.UserAPI.LOGIN_URL; @@ -39,4 +39,19 @@ public void register(String fname, String lname, String email, String pass, Stri ser.execute(); } + public void getProductlist(String productid, ApiResponse responseListener) + { + + HttpUrl url = new HttpUrl.Builder().scheme("http") + .host("staging.php-dev.in") + .port(8844) + .addPathSegments("trainingapp/api/products/getList") + .addQueryParameter("product_category_id",productid) + .build(); +// Request request = new Request.Builder().url(PRODUCTS_URL).get(requestBody).build(); + Services ser = new Services<>(url.toString(), responseListener,ProductResponseModel.class); + ser.execute(); + } + +// http://staging.php-dev.in:8844/trainingapp/api/products/getList?product_category_id=2 } diff --git a/app/src/main/java/com/neosoft/neostore/serviceapi/Services.java b/app/src/main/java/com/neosoft/neostore/serviceapi/Services.java index a752427..afd8f75 100644 --- a/app/src/main/java/com/neosoft/neostore/serviceapi/Services.java +++ b/app/src/main/java/com/neosoft/neostore/serviceapi/Services.java @@ -21,6 +21,7 @@ public class Services extends AsyncTask { private RequestBody requestBody; private ApiResponse apiResponse; private Class responseType; + private Request request; public Services(String url, RequestBody requestBody, ApiResponse apiResponse, Class responseType) { @@ -28,13 +29,20 @@ public Services(String url, RequestBody requestBody, ApiResponse apiResponse, this.requestBody = requestBody; this.apiResponse = apiResponse; this.responseType = responseType; + request = new Request.Builder().url(url).post(requestBody).build(); + } + + public Services(String url, ApiResponse apiResponse, Class responseType) { + this.url = url; + this.apiResponse = apiResponse; + this.responseType = responseType; + request = new Request.Builder().url(url).get().build(); } @Override protected String doInBackground(Void... requestBodies) { String responseString = null; try { OkHttpClient client = new OkHttpClient(); - Request request = new Request.Builder().url(url).post(requestBody).build(); Response response = client.newCall(request).execute(); responseString = response.body().string().toString(); } catch (IOException e) { @@ -45,6 +53,7 @@ public Services(String url, RequestBody requestBody, ApiResponse apiResponse, @Override protected void onPostExecute(String response) { super.onPostExecute(response); + Log.e("zzzzzzz",response); int status = 0; try { status = (new JSONObject(response)).getInt("status"); @@ -56,6 +65,9 @@ public Services(String url, RequestBody requestBody, ApiResponse apiResponse, apiResponse.onError("Error"); } else { Gson gson = new Gson(); + + Log.e("zzzz",response+""); + apiResponse.onSuccess(gson.fromJson(response, responseType)); } } diff --git a/app/src/main/java/com/neosoft/neostore/ui/HomeActivity.java b/app/src/main/java/com/neosoft/neostore/ui/HomeActivity.java index 869a055..baaca68 100644 --- a/app/src/main/java/com/neosoft/neostore/ui/HomeActivity.java +++ b/app/src/main/java/com/neosoft/neostore/ui/HomeActivity.java @@ -35,6 +35,10 @@ private void loadFragment(int i) { break; case 1: break; + case 2: + getFragmentManager().beginTransaction().add(R.id.container, + new TableFragment(),TableFragment.class.getSimpleName()) + .commit(); default: break; } @@ -70,6 +74,14 @@ public void onBackPressed() { public boolean onNavigationItemSelected(@NonNull MenuItem item) { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); + + switch (item.getItemId()){ + case R.id.nav_tables: + getFragmentManager().beginTransaction().add(R.id.container, + new TableFragment(),HomepageFragment.class.getSimpleName()) + .commit(); + break; + } return true; } diff --git a/app/src/main/java/com/neosoft/neostore/ui/HomepageFragment.java b/app/src/main/java/com/neosoft/neostore/ui/HomepageFragment.java index c823f78..5da1850 100644 --- a/app/src/main/java/com/neosoft/neostore/ui/HomepageFragment.java +++ b/app/src/main/java/com/neosoft/neostore/ui/HomepageFragment.java @@ -17,9 +17,7 @@ import me.relex.circleindicator.CircleIndicator; -/** - * Created by webwerks1 on 1/12/16. - */ + public class HomepageFragment extends Fragment { diff --git a/app/src/main/java/com/neosoft/neostore/ui/LoginActivity.java b/app/src/main/java/com/neosoft/neostore/ui/LoginActivity.java index 9a5be2b..3781e24 100644 --- a/app/src/main/java/com/neosoft/neostore/ui/LoginActivity.java +++ b/app/src/main/java/com/neosoft/neostore/ui/LoginActivity.java @@ -25,6 +25,18 @@ public class LoginActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); + GetServices apiServices = new GetServices(); + apiServices.getProductlist("1", new ApiResponse() { + @Override + public void onSuccess(Object response) { + + } + + @Override + public void onError(String message) { + + } + }); String status = sharedpreferences.getString(STATUS, null); if (status != null) { if (status.equals(STATUS_IN)) { diff --git a/app/src/main/java/com/neosoft/neostore/ui/TableFragment.java b/app/src/main/java/com/neosoft/neostore/ui/TableFragment.java new file mode 100644 index 0000000..54813cf --- /dev/null +++ b/app/src/main/java/com/neosoft/neostore/ui/TableFragment.java @@ -0,0 +1,73 @@ +package com.neosoft.neostore.ui; + +import android.app.Fragment; +import android.content.res.Resources; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; + +import android.widget.ListView; +import com.neosoft.neostore.R; +import com.neosoft.neostore.adapter.TableAdapter; +import com.neosoft.neostore.model.Product.DataModel; +import com.neosoft.neostore.model.Product.ProductResponseModel; +import com.neosoft.neostore.serviceapi.ApiResponse; +import com.neosoft.neostore.serviceapi.GetServices; + +import java.util.ArrayList; + + +public class TableFragment extends Fragment { + private View rootView; + ListView list; + TableAdapter adapter; + public TableFragment TableListView = null; + public ArrayList CustomListViewValuesArr = new ArrayList(); + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + rootView = inflater.inflate(R.layout.fragment_tables, container, false); + final Resources res =getResources(); + list= ( ListView )rootView.findViewById(R.id.table_list); + GetServices services= new GetServices(); + services.getProductlist("1", new ApiResponse() { + @Override + public void onSuccess(Object response) { + Log.e("zzz", response.toString()); + ProductResponseModel responseModel = (ProductResponseModel) response; + for(DataModel model:responseModel.getData()){ + Log.e("DATA",model.getTableTitle() + " :::::"); + } + adapter=new TableAdapter(getActivity(), responseModel.getData(),res ); + list.setAdapter( adapter ); + } + @Override + public void onError(String message) { + Log.e("zzz", message); + } + }); + list.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + + } + }); + return rootView; + } + + public void onItemClick(int mPosition) + { + DataModel tempValues = (DataModel)CustomListViewValuesArr.get(mPosition); + } + +} + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_tables.xml b/app/src/main/res/layout/fragment_tables.xml new file mode 100644 index 0000000..f32f7fa --- /dev/null +++ b/app/src/main/res/layout/fragment_tables.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_tablelist.xml b/app/src/main/res/layout/row_tablelist.xml new file mode 100644 index 0000000..4f52116 --- /dev/null +++ b/app/src/main/res/layout/row_tablelist.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 4a65d6b..7925f26 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -6,6 +6,7 @@ #FFFFFF #BB0100 #9E0100 - #4F4F4F + #4f4f4f #2C2B2B + #FFD700 \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 21167a0..668af07 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -15,7 +15,9 @@ - +