Skip to content

Commit

Permalink
productlist
Browse files Browse the repository at this point in the history
  • Loading branch information
shetyeshivani committed Dec 5, 2016
1 parent 87771e0 commit 4ff5db6
Show file tree
Hide file tree
Showing 13 changed files with 532 additions and 8 deletions.
128 changes: 128 additions & 0 deletions app/src/main/java/com/neosoft/neostore/adapter/TableAdapter.java
Original file line number Diff line number Diff line change
@@ -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<DataModel> mData;
private static LayoutInflater inflater=null;
public Resources res;
DataModel tempValues=null;
int i=0;

public TableAdapter(Context context, List<DataModel> 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);
}
}
}

Original file line number Diff line number Diff line change
@@ -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;
}


}
Original file line number Diff line number Diff line change
@@ -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<DataModel> 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<DataModel> getData() {
return data;
}

public void setData(List<DataModel> 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 + '\'' +
'}';
}

}
19 changes: 17 additions & 2 deletions app/src/main/java/com/neosoft/neostore/serviceapi/GetServices.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ProductResponseModel> ser = new Services<>(url.toString(), responseListener,ProductResponseModel.class);
ser.execute();
}

// http://staging.php-dev.in:8844/trainingapp/api/products/getList?product_category_id=2
}
14 changes: 13 additions & 1 deletion app/src/main/java/com/neosoft/neostore/serviceapi/Services.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ public class Services<U> extends AsyncTask<Void, Void, String> {
private RequestBody requestBody;
private ApiResponse<U> apiResponse;
private Class<U> responseType;
private Request request;

public Services(String url, RequestBody requestBody, ApiResponse apiResponse,
Class<U> responseType) {
this.url = url;
this.requestBody = requestBody;
this.apiResponse = apiResponse;
this.responseType = responseType;
request = new Request.Builder().url(url).post(requestBody).build();
}

public Services(String url, ApiResponse<U> apiResponse, Class<U> 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) {
Expand All @@ -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");
Expand All @@ -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));
}
}
Expand Down
Loading

0 comments on commit 4ff5db6

Please sign in to comment.