1)DealsActivity.java
================
package com.bluegreen.masmas.customer.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bluegreen.masmas.customer.AsyncTask.AddWalletAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.AsyncCallListener;
import com.bluegreen.masmas.customer.AsyncTask.DealsAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.DealsAsynckTask_loadmore;
import com.bluegreen.masmas.customer.AsyncTask.DeleteWalletAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.FollowUnFollowLocationAsyncTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllLocationAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllLocationAsynckTask_loadMore;
import com.bluegreen.masmas.customer.AsyncTask.GetCategoriesAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.LocationFollowingAsyncTask;
import com.bluegreen.masmas.customer.AsyncTask.PostDataAsync;
import com.bluegreen.masmas.customer.AsyncTask.ReturnResult;
import com.bluegreen.masmas.customer.R;
import com.bluegreen.masmas.customer.Utility.Consts;
import com.bluegreen.masmas.customer.Utility.GPSTracker;
import com.bluegreen.masmas.customer.Utility.LanguageChange;
import com.bluegreen.masmas.customer.Utility.MasMas;
import com.bluegreen.masmas.customer.Utility.NetworkConnection;
import com.bluegreen.masmas.customer.Utility.Utils;
import com.bluegreen.masmas.customer.adapter.DealsAdapter;
import com.bluegreen.masmas.customer.adapter.SearchLocationAdapter;
import com.bluegreen.masmas.customer.model.CategoryModel;
import com.bluegreen.masmas.customer.model.DealDetailImagesModel;
import com.bluegreen.masmas.customer.model.DealsModle;
import com.bluegreen.masmas.customer.model.LocationModel;
import com.bluegreen.masmas.customer.model.SubCategoriesModel;
import com.bluegreen.masmas.customer.navigation.ViewDrawer;
import com.bluegreen.masmas.customer.navigation.onUpdateListner;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenu;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuCreator;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuItem;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuListView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
/**
* Created by Manisha on 08/09/2015.
*/
public class DealsActivity extends Activity implements View.OnClickListener,SwipeMenuListView.IXListViewListener {
private ImageView imgDeals_menu;
private TextView txtHeader_deals, txtFilterbtn, txtMapDeal;
DrawerLayout drawerLayout;
ViewDrawer drawerView;
private SwipeMenuListView lstDeal;
private SwipeMenuListView lstLocation;
private DealsAdapter mDealsAdapter;
private String cust_id = "";
private boolean isFromMenu = false;
private TextView txtHome, txtNearBy, txtLike;
private ImageView imgHome, imgNearBy, imgLike, imgClose, imgFilterClose;
private String myLat = "", myLng = "";
private String type = Consts.HOME;
private String type_location = Consts.HOME;
private AutoCompleteTextView edt_search_deal;
private ArrayList<DealsModle> alstDeals;
private ArrayList<DealsModle> alstHome;
private ArrayList<DealsModle> alstNearBy;
private ArrayList<DealsModle> alstLike;
private ArrayList<LocationModel> alstLocation;
private ArrayList<LocationModel> alstLocatonHome;
private ArrayList<LocationModel> alstLocatonNearBy;
private ArrayList<LocationModel> alstLocatonFollowing;
private DealDetailImagesModel mDealDetailImagesModel;
private ArrayList<DealDetailImagesModel> alstLocationImages;
private SearchLocationAdapter mSearchLocationAdapter;
private TextView btnDeals, btnLocation;
private RelativeLayout rlytLocation;
public Boolean isDeal = false;
private ArrayList<LocationModel> alstSearchLocationFilter;
public boolean islike = false;
private TextView txtNoDeal, txtFilterText;
private ArrayAdapter<String> aadpDeal;
private ArrayList<String> alstSearchDealName;
private ArrayList<String> alstSearchLocationName;
private LinearLayout lytLocation, lytFilter;
private boolean isSkipNow = false;
private String cat_id = "0", sub_cat_id = "0";
private LocationModel locationModel;
public static HashMap<String, List<SubCategoriesModel>> hashmapSubCategory, hashmapMoreSubCategories;
public static ArrayList<CategoryModel> alstCategory, alstMoreCategories;
public static ArrayList<SubCategoriesModel> alstSubCategory, alstMoreSubCategories;
private onUpdateListner mOnUpdateListner;
private Boolean is_first = false;
private String strSort = "";
private String strUserEmail, strUserPass;
public DealsAsynckTask mDealsAsynckTask = null;
public DealsAsynckTask_loadmore mDealsAsynckTask_loadmore = null;
public GetAllLocationAsynckTask mGetAllLocationAsynckTask = null;
GetAllLocationAsynckTask_loadMore mGetAllLocationAsynckTask_loadmore=null;
private ArrayList<LocationModel> alstMapLocation;
EditText dummyEditTextFocus;
String nextLocationStart="0";
String nextStart="0";
private Handler mHandler;
//c creatorFollow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, Context.MODE_MULTI_PROCESS);
boolean is_login = Utils.sharedPreferences.getBoolean(Consts.IS_LOGIN, false);
String language = Utils.sharedPreferences.getString(Consts.LANGUAGE, Consts.SPANISH);
if (Utils.validateString(language)) {
LanguageChange.setlanguage(this, language);
}
setContentView(R.layout.activity_deals_dashboard);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.header));
}
// Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, MODE_PRIVATE);
is_first = Utils.sharedPreferences.getBoolean(Consts.IS_FIRST, false);
strUserEmail = Utils.sharedPreferences.getString(Consts.USER_EMAIL, "");
strUserPass = Utils.sharedPreferences.getString(Consts.PASSWORD, "");
alstMapLocation = new ArrayList<LocationModel>();
Utils.storeString(Consts.TYPE, Consts.HOME);
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
Log.e("", "is_first::::" + is_first);
if (is_login)
{
callLogin(strUserEmail, strUserPass);
}
if (is_first) {
inItData();
} else {
Utils.storeBoolean(Consts.IS_FIRST, true);
inItDrawerData();
GetAllCategories();
}
}
// msg : categories for locations are coming soon.
public void inItDrawerData() {
alstCategory = new ArrayList<CategoryModel>();
alstSubCategory = new ArrayList<SubCategoriesModel>();
hashmapSubCategory = new HashMap<String, List<SubCategoriesModel>>();
alstMoreCategories = new ArrayList<CategoryModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
hashmapMoreSubCategories = new HashMap<String, List<SubCategoriesModel>>();
}
public void inItData() {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
GPSTracker gps = new GPSTracker(this);
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
strSort = Utils.sharedPreferences.getString(Consts.SORT_FILTER, "");
isSkipNow = Utils.sharedPreferences.getBoolean(Consts.SKIP_NOW, false);
cust_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
imgDeals_menu = (ImageView) findViewById(R.id.imgDeals_menu);
imgDeals_menu.setOnClickListener(this);
txtHeader_deals = (TextView) findViewById(R.id.txtHeader_deals);
if (Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false)) {
txtHeader_deals.setText(getResources().getString(R.string.deals));
} else {
txtHeader_deals.setText(getResources().getString(R.string.locations));
}
dummyEditTextFocus = (EditText) findViewById(R.id.dummyEditTextFocus);
dummyEditTextFocus.requestFocus();
txtFilterbtn = (TextView) findViewById(R.id.txtFilterbtn);
txtFilterbtn.setOnClickListener(this);
txtNoDeal = (TextView) findViewById(R.id.txtNoDeal);
txtMapDeal = (TextView) findViewById(R.id.txtMapDeal);
txtMapDeal.setOnClickListener(this);
txtHome = (TextView) findViewById(R.id.txtHome);
txtHome.setOnClickListener(this);
txtNearBy = (TextView) findViewById(R.id.txtNearBy);
txtNearBy.setOnClickListener(this);
txtLike = (TextView) findViewById(R.id.txtLike);
txtLike.setOnClickListener(this);
lytLocation = (LinearLayout) findViewById(R.id.lytLocation);
lytLocation.setVisibility(View.VISIBLE);
lstLocation = (SwipeMenuListView) findViewById(R.id.lstLocation);
rlytLocation = (RelativeLayout) findViewById(R.id.rlytLocation);
rlytLocation.setVisibility(View.GONE);
btnDeals = (TextView) findViewById(R.id.btnDeals);
btnDeals.setOnClickListener(this);
btnLocation = (TextView) findViewById(R.id.btnLocation);
btnLocation.setOnClickListener(this);
imgHome = (ImageView) findViewById(R.id.imgHome);
imgNearBy = (ImageView) findViewById(R.id.imgNearBy);
imgLike = (ImageView) findViewById(R.id.imgLike);
imgClose = (ImageView) findViewById(R.id.imgClose);
imgClose.setOnClickListener(this);
lytFilter = (LinearLayout) findViewById(R.id.lytFilter);
imgFilterClose = (ImageView) findViewById(R.id.imgFilterClose);
imgFilterClose.setOnClickListener(this);
txtFilterText = (TextView) findViewById(R.id.txtFilterText);
alstDeals = new ArrayList<DealsModle>();
alstHome = new ArrayList<DealsModle>();
alstNearBy = new ArrayList<DealsModle>();
alstLike = new ArrayList<DealsModle>();
alstLocation = new ArrayList<LocationModel>();
alstLocatonHome = new ArrayList<LocationModel>();
alstLocatonNearBy = new ArrayList<LocationModel>();
alstLocatonFollowing = new ArrayList<LocationModel>();
alstLocationImages = new ArrayList<DealDetailImagesModel>();
alstSearchLocationFilter = new ArrayList<LocationModel>();
alstSearchDealName = new ArrayList<String>();
alstSearchLocationName = new ArrayList<String>();
edt_search_deal = (AutoCompleteTextView) findViewById(R.id.edt_search_deal);
edt_search_deal.setText("");
edt_search_deal.setThreshold(1);
edt_search_deal.setOnClickListener(this);
lstDeal = (SwipeMenuListView) findViewById(R.id.lstDeals);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setVisibility(View.VISIBLE);
drawerView = (ViewDrawer) findViewById(R.id.drawer);
drawerView.setVisibility(View.VISIBLE);
mHandler = new Handler();
lstLocation.setXListViewListener(this);
lstLocation.setPullLoadEnable(true);
lstDeal.setXListViewListener(this);
lstDeal.setPullLoadEnable(true);
// check if GPS enabled
if (gps.getIsGPSTrackingEnabled())
{
myLat = String.valueOf(gps.getLatitude());
myLng = String.valueOf(gps.getLongitude());
/* myLat = "-0.18287";
myLng = "-78.477663";*/
//self.STRLatitude = @"-0.182875";
//self.STRLongitude = @"-78.477663";
// myLat = "23.012658";
// myLng = "72.521739";
// Log.e("", "myLat:::" + myLat);
// Log.e("", "myLng:::" + myLng);
}
Intent intent = getIntent();
if (intent.getAction() != null) {
alstDeals.clear();
alstSearchDealName.clear();
alstSearchLocationName.clear();
alstHome.clear();
alstNearBy.clear();
if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_FILTER)) {
// isDeal = true;
Utils.storeBoolean(Consts.IS_DEAL, true);
Utils.storeBoolean(Consts.FILTER_RESULT, true);
lytFilter.setVisibility(View.VISIBLE);
txtFilterText.setText(Utils.sharedPreferences.getString(Consts.FILTER_TEXT, ""));
dealVisible();
Bundle mBundle = intent.getBundleExtra(Consts.FILTER_DEAL_BUNDLE);
if (mBundle != null) {
alstHome = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
alstNearBy = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
alstDeals = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
// sortDealData(strSort);
// Handle Deals sorting as per type
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
edt_search_deal.setAdapter(aadpDeal);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_MENU)) {
cat_id = Utils.sharedPreferences.getString(Consts.CATEGORY_ID, "0");
sub_cat_id = Utils.sharedPreferences.getString(Consts.SUB_CATEGORY_ID, "0");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, false);
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
strSort = Utils.sharedPreferences.getString(Consts.SORT_FILTER, "");
if (isDeal) {
dealVisible();
Log.e("", "cat_id::" + cat_id);
Log.e("", "sub_cat_id::" + sub_cat_id);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("0") && !sub_cat_id.equalsIgnoreCase("0")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("0")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
} else {
locationVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("0") && !sub_cat_id.equalsIgnoreCase("0")) {
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, "0");
}else if (sub_cat_id.equalsIgnoreCase("0"))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, "0");
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, "0");
}
}
}
} else if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_FILTER_LOCATION)) {
// isDeal = false;
Utils.storeBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, true);
locationVisible();
Bundle mBundle = intent.getBundleExtra(Consts.FILTER_LOCATION_BUNDLE);
txtFilterText.setText(Utils.sharedPreferences.getString(Consts.FILTER_TEXT, ""));
alstSearchLocationName.clear();
alstSearchLocationFilter.clear();
alstLocatonHome.clear();
alstLocatonNearBy.clear();
alstSearchLocationFilter = (ArrayList<LocationModel>) mBundle.getSerializable(Consts.FILTER_LOCATION_ARRAY);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
Log.e("", "Location Name:::" + alstSearchLocationFilter.get(i).getLocation_name());
Log.e("", "Price Type:::" + alstSearchLocationFilter.get(i).getPrice_type());
Log.e("", "Rate:::" + alstSearchLocationFilter.get(i).getRate());
}
alstLocatonHome.addAll(alstSearchLocationFilter);
alstLocatonNearBy.addAll(alstSearchLocationFilter);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
if (alstSearchLocationFilter.size() > 0) {
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
}
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("1")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int x = 0; x < alstSearchLocationFilter.size(); x++) {
Log.e("", "Loc Name:::" + alstSearchLocationFilter.get(x).getLocation_name());
alstSearchLocationName.add(alstSearchLocationFilter.get(x).getLocation_name());
}
if (alstSearchLocationFilter.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
} else {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, false);
if (isDeal) {
dealVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else {
locationVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, "0");
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, "0");
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, "0");
}
}
}
}
// edt_search_deal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
// public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_NEXT)) {
// Log.i("", "Enter pressed=>>>>");
// InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
// }
// return false;
// }
// });
edt_search_deal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
}
});
edt_search_deal.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
edt_search_deal.setAdapter(aadpDeal);
// edt_search_deal.showDropDown();
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
String text = edt_search_deal.getText().toString().toLowerCase(Locale.getDefault());
if (mDealsAdapter != null) {
mDealsAdapter.filter(text);
}
} else {
String text = edt_search_deal.getText().toString().toLowerCase(Locale.getDefault());
if (mSearchLocationAdapter != null) {
mSearchLocationAdapter.filter(text);
}
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
});
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu, int position) {
SwipeMenuItem AddItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
AddItem.setIcon(R.drawable.add_wallet);
AddItem.setTitle("");
AddItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
AddItem.setTitleColor(getResources().getColor(R.color.white));
AddItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(WalletItem);
SwipeMenuItem RemoveItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
RemoveItem.setIcon(R.drawable.remove_wallet);
RemoveItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
RemoveItem.setTitleColor(getResources().getColor(R.color.white));
RemoveItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(RemoveItem);
if (alstDeals != null) {
if (alstDeals.size() > 0) {
if (alstDeals.get(position).getIsWallet().equalsIgnoreCase("0")) {
menu.addMenuItem(AddItem);
} else {
menu.addMenuItem(RemoveItem);
}
}
}
}
};
lstDeal.setMenuCreator(creator);
lstDeal.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
if (isSkipNow) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.you_are_not_register_user));
} else {
final DealsModle mModel = alstDeals.get(position);
Log.e(" ", "position:::::" + position);
Log.e(" ", "index::::" + index);
//Toast.makeText(DealsActivity.this, "Postion::" + position, Toast.LENGTH_SHORT).show();
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.internet_problem));
} else {
String customenr_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
String deal_id = mModel.getDeal_id();
if (mModel.getIsWallet().equalsIgnoreCase("0")) {
AddToWalletSevice(customenr_id, deal_id, mModel);
} else {
showDeleteDealDialog(DealsActivity.this, customenr_id, deal_id, mModel);
}
}
}
return false;
}
});
// lstDeal.setOnScrollListener(new AbsListView.OnScrollListener() {
// @Override
// public void onScrollStateChanged(AbsListView view, int scrollState) {
//
// }
//
// @Override
// public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// int lastInScreen = firstVisibleItem + visibleItemCount;
// // is the bottom item visible & not loading more already ? Load more !
// String nextStart ="0";
// if (isDeal) {
// if ((lastInScreen == totalItemCount) && mDealsAsynckTask == null) {
// if (alstDeals != null) {
// if (alstDeals.size() > 0) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
// DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
// } else if (sub_cat_id.equalsIgnoreCase("")) {
// DealsSevice("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
// } else {
// DealsSevice("home", cust_id, "0", "0", myLat, myLng,nextStart);
// }
// }
// }
// }
// }
// }
// }
// });
lstDeal.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {
@Override
public void onSwipeStart(int position) {
// Toast.makeText(DealsActivity.this, "Swip Start", Toast.LENGTH_SHORT).show();
}
@Override
public void onSwipeEnd(int position) {
// Toast.makeText(DealsActivity.this, "Swip End", Toast.LENGTH_SHORT).show();
}
});
lstDeal.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// Toast.makeText(DealsActivity.this.getApplicationContext(), position + " long click", Toast.LENGTH_LONG).show();
return false;
}
});
lstDeal.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(DealsActivity.this, DealDetailActivity.class);
intent.putExtra(Consts.DEAL_ID, alstDeals.get(i).getDeal_id());
// intent.putExtra("lat", myLat);
// intent.putExtra("long", myLng);
// MasMas.tracker().send(new HitBuilders.EventBuilder("D_" + alstDeals.get(i).getDeal_id(), "Deal_Click")
// .setLabel("CM_" + cust_id)
// .build());
MasMas.getInstance().trackEvent("D_" + alstDeals.get(i).getDeal_id(), "Deal Click", "CM_" + cust_id);
if (alstDeals.get(i).getAlstLocation() != null) {
if (alstDeals.get(i).getAlstLocation().size() > 0) {
//Log.e("", "LOCIDDDD:::::" + alstDeals.get(i).getAlstLocation().get(0).getLocation_id());
intent.putExtra(Consts.LOCATION_ID, alstDeals.get(i).getAlstLocation().get(0).getLocation_id());
}
}
startActivity(intent);
}
});
SwipeMenuCreator creatorFollow = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu, int position) {
SwipeMenuItem FollowItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
FollowItem.setIcon(R.drawable.follow);
FollowItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
FollowItem.setTitleColor(getResources().getColor(R.color.white));
FollowItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(WalletItem);
SwipeMenuItem UnFollowItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
UnFollowItem.setIcon(R.drawable.unfollow);
UnFollowItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
UnFollowItem.setTitleColor(getResources().getColor(R.color.white));
UnFollowItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(RemoveItem);
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
Log.e("Follow","Follow:::"+alstSearchLocationFilter.get(position).getLocation_name());
Log.e("Follow","Follow:::"+alstSearchLocationFilter.get(position).getIs_following());
if (alstSearchLocationFilter.get(position).getIs_following().equalsIgnoreCase("0")) {
menu.addMenuItem(FollowItem);
} else {
menu.addMenuItem(UnFollowItem);
}
}
}
}
};
lstLocation.setMenuCreator(creatorFollow);
lstLocation.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
if (isSkipNow) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.you_are_not_register_user));
} else {
final LocationModel mModel = alstSearchLocationFilter.get(position);
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
String customer_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "0");
String location_id = mModel.getLocation_id();
if (mModel.getIs_following().equalsIgnoreCase("0")) {
showUnFollowLocationDialog(customer_id, location_id, "1", mModel, type_location);
} else {
showUnFollowLocationDialog(customer_id, location_id, "0", mModel, type_location);
}
}
}
return false;
}
});
lstLocation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// MasMas.tracker().send(new HitBuilders.EventBuilder("L_"+alstSearchLocationFilter.get(i).getLocation_id(), "Location_Click")
// .setLabel("CM_" +cust_id)
// .build());
MasMas.getInstance().trackEvent("L_" + alstSearchLocationFilter.get(i).getLocation_id(), "Location Click", "CM_" + cust_id);
Intent mIntent = new Intent(DealsActivity.this, LocationDetailActivity.class);
Log.e("", "Location ID :::::" + alstSearchLocationFilter.get(i).getLocation_id());
mIntent.putExtra(Consts.LOCATION_ID, alstSearchLocationFilter.get(i).getLocation_id());
mIntent.putExtra("price_type", alstSearchLocationFilter.get(i).getPrice_type());
startActivity(mIntent);
}
});
}
@Override
protected void onResume() {
super.onResume();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
public void AddToWalletSevice(String customenr_id, String deal_id, final DealsModle mDealsModle) {
AddWalletAsynckTask mAddWalletAsynckTask = new AddWalletAsynckTask(DealsActivity.this);
mAddWalletAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "Add To wallet Response ::::::::" + result.toString());
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mDealsModle.getIsWallet().equalsIgnoreCase("0")) {
mDealsModle.setIsWallet("1");
} else {
mDealsModle.setIsWallet("0");
}
int pos = alstDeals.indexOf(mDealsModle);
alstDeals.set(pos, mDealsModle);
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.deals_success_msg), Toast.LENGTH_LONG).show();
// Utils.SimpleAlertMessage(mContext, mContext.getResources().getString(R.string.deals_success_msg));
}
mDealsAdapter.notifyDataSetChanged();
if (!Utils.checkInternetConnection(DealsActivity.this))
{
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
}
else {
if (type.equalsIgnoreCase(Consts.HOME)) {
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (alstNearBy.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstNearBy.size(); a++) {
alstSearchDealName.add(alstNearBy.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstNearBy, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
/// }
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// DealsLikeSevice("home", cust_id, cat_id, sub_cat_id,myLat,myLng);
// }
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
alstLike.clear();
for (int a = 0; a < alstDeals.size(); a++) {
if (alstDeals.get(a).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(a));
}
}
for (int a = 0; a < alstLike.size(); a++) {
alstSearchDealName.add(alstLike.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstLike, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
}
} else
{
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.deals_success_msg));
}
} catch (Exception e) {
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mAddWalletAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customenr_id, deal_id);
} else {
mAddWalletAsynckTask.execute(customenr_id, deal_id);
}
}
public void DeleteWalletSevice(Context mContext, String customenr_id, String deal_id, final DealsModle mDealsModle) {
DeleteWalletAsynckTask mDeleteWalletAsynckTask = new DeleteWalletAsynckTask(mContext);
mDeleteWalletAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mDealsModle.getIsWallet().equalsIgnoreCase("0")) {
mDealsModle.setIsWallet("1");
} else {
mDealsModle.setIsWallet("0");
}
int pos = alstDeals.indexOf(mDealsModle);
alstDeals.set(pos, mDealsModle);
}
mDealsAdapter.notifyDataSetChanged();
if (type.equalsIgnoreCase(Consts.HOME)) {
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (alstNearBy.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstNearBy.size(); a++) {
alstSearchDealName.add(alstNearBy.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
// }
} else if (type.equalsIgnoreCase("like")) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// DealsLikeSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng);
// }
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
alstLike.clear();
for (int a = 0; a < alstDeals.size(); a++) {
if (alstDeals.get(a).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(a));
}
}
for (int a = 0; a < alstLike.size(); a++) {
alstSearchDealName.add(alstLike.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstLike, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
}
} catch (Exception e) {
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDeleteWalletAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customenr_id, deal_id);
} else {
mDeleteWalletAsynckTask.execute(customenr_id, deal_id);
}
}
/**
* Function to show settings alert dialog.
* On pressing the Settings button it will launch Settings Options.
*/
public void showDeleteDealDialog(final Context mContext, final String customenr_id, final String deal_id, final DealsModle mDealsModle) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle(R.string.app_name);
alertDialog.setMessage(mContext.getResources().getString(R.string.are_u_sure_you_want_to_delete_deals));
alertDialog.setNegativeButton(mContext.getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton(mContext.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
DeleteWalletSevice(mContext, customenr_id, deal_id, mDealsModle);
}
});
alertDialog.show();
}
public void showUnFollowLocationDialog(final String customer_id, final String location_id, final String is_Following, final LocationModel mLocationModel, final String type) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle(R.string.app_name);
if (is_Following.equalsIgnoreCase("1")) {
alertDialog.setMessage(getResources().getString(R.string.are_u_sure_you_want_to_follow_this_location));
} else {
alertDialog.setMessage(getResources().getString(R.string.are_u_sure_you_want_to_unfollow_this_location));
}
alertDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
unFollow_Follow_Location(customer_id, location_id, is_Following, mLocationModel, type);
}
});
alertDialog.show();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.txtFilterbtn:
edt_search_deal.setText("");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Intent mFilterIntent = new Intent(this, FilterActivity.class);
startActivity(mFilterIntent);
finish();
} else {
Intent mFilterIntent = new Intent(this, FilterLocationActivity.class);
startActivity(mFilterIntent);
finish();
}
break;
case R.id.txtMapDeal:
edt_search_deal.setText("");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Intent mIntent = new Intent(DealsActivity.this, DealsMapActivity.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST", (Serializable) alstDeals);
mIntent.putExtra("BUNDLE", args);
startActivity(mIntent);
} else {
Intent mIntent = new Intent(DealsActivity.this, LocationMapActivity.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST_LOCATION", (Serializable) alstSearchLocationFilter);
// for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
// Log.e("Lat", "Lat:::" + alstSearchLocationFilter.get(i).getLatitude());
// Log.e("Lag", "Lag:::" + alstSearchLocationFilter.get(i).getLongitude());
// }
mIntent.putExtra("BUNDLE_LOCATION", args);
startActivity(mIntent);
}
break;
case R.id.imgDeals_menu:
edt_search_deal.setText("");
edt_search_deal.dismissDropDown();
drawerLayout.openDrawer(drawerView);
break;
case R.id.imgFilterClose:
Utils.storeString(Consts.SORT_FILTER, "deal_name");
lytFilter.setVisibility(View.GONE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
break;
case R.id.txtHome:
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.HOME);
islike = false;
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstDeals.clear();
alstDeals.addAll(alstHome);
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getDeal_name().compareTo(object2.getDeal_name());
}
});
alstSearchDealName.clear();
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
// Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
break;
case R.id.txtNearBy:
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.NEAR_BY);
islike = false;
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.header));
imgNearBy.setVisibility(View.VISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstDeals.clear();
alstDeals.addAll(alstNearBy);
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.NEAR_BY);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
lstLocation.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.header));
imgNearBy.setVisibility(View.VISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
// Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
break;
case R.id.txtLike:
if (isSkipNow) {
dialogSkipNow(this);
} else {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.LIKE);
islike = true;
edt_search_deal.setText("");
lytLocation.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.header));
imgLike.setVisibility(View.VISIBLE);
alstLike.clear();
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.FOLLOWING);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.header));
imgLike.setVisibility(View.VISIBLE);
alstSearchLocationName.clear();
alstLocatonFollowing.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("1")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
}
break;
case R.id.edt_search_deal:
if (islike) {
lytLocation.setVisibility(View.GONE);
} else {
lytLocation.setVisibility(View.VISIBLE);
}
break;
case R.id.btnDeals:
Utils.storeBoolean(Consts.IS_DEAL, true);
lytFilter.setVisibility(View.GONE);
txtLike.setText(getResources().getString(R.string.like));
dealVisible();
txtHeader_deals.setText(getResources().getString(R.string.deals));
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
break;
case R.id.btnLocation:
lytFilter.setVisibility(View.GONE);
Utils.storeBoolean(Consts.IS_DEAL, false);
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
txtHeader_deals.setText(getResources().getString(R.string.locations));
txtLike.setText(getResources().getString(R.string.profile_following_btn));
lstDeal.setVisibility(View.GONE);
locationVisible();
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
break;
case R.id.imgClose:
edt_search_deal.setText("");
lstDeal.setVisibility(View.VISIBLE);
if (edt_search_deal != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edt_search_deal.getWindowToken(), 0);
}
break;
default:
break;
}
}
private void locationVisible() {
lstDeal.setVisibility(View.GONE);
rlytLocation.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.VISIBLE);
edt_search_deal.setText("");
btnDeals.setBackgroundResource(R.drawable.ractangle_tab_left_normal);
btnDeals.setTextColor(getResources().getColor(R.color.black));
btnLocation.setBackgroundResource(R.drawable.ractangle_tab_right);
btnLocation.setTextColor(getResources().getColor(R.color.white));
rlytLocation.setVisibility(View.VISIBLE);
}
private void dealVisible() {
lstLocation.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
rlytLocation.setVisibility(View.GONE);
edt_search_deal.setText("");
btnDeals.setBackgroundResource(R.drawable.ractangle_tab_left);
btnDeals.setTextColor(getResources().getColor(R.color.white));
btnLocation.setBackgroundResource(R.drawable.ractangle_tab_right_normal);
btnLocation.setTextColor(getResources().getColor(R.color.black));
}
public void DealsSevice(final String deal_type, String cust_id, String cat_id, String sub_cat_id, String latitude, String longitude, String next_start) {
if (mDealsAsynckTask == null) {
mDealsAsynckTask = new DealsAsynckTask(this);
mDealsAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
mDealsAsynckTask = null;
if (result != null) {
try {
alstHome.clear();
alstNearBy.clear();
alstLike.clear();
alstDeals.clear();
alstLocation.clear();
alstLocationImages.clear();
// alstSearchLoaction.clear();
alstSearchDealName.clear();
alstSearchLocationName.clear();
alstSearchLocationFilter.clear();
DealsModle dealsModel = null;
LocationModel locationModel = null;
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
lstDeal.setVisibility(View.VISIBLE);
txtNoDeal.setVisibility(View.INVISIBLE);
alstDeals = new ArrayList<DealsModle>();
alstHome = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("home");
for (int i = 0; i < mJsonArray.length(); i++) {
dealsModel = new DealsModle();
JSONObject mData = mJsonArray.getJSONObject(i);
dealsModel.setDeal_id(mData.optString("deal_id"));
dealsModel.setM_fullname(mData.optString("m_fullname"));
dealsModel.setMerchant_id(mData.optString("merchant_id"));
dealsModel.setMaximum_redumption(mData.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mData.optString("merchant_user_id"));
dealsModel.setCategory_id(mData.optString("category_id"));
dealsModel.setDeal_name(mData.optString("deal_name"));
dealsModel.setDeal_desc(mData.optString("deal_desc"));
dealsModel.setStart_date(mData.optString("start_date"));
dealsModel.setEnd_date(mData.optString("end_date"));
dealsModel.setIs_active(mData.optString("is_active"));
dealsModel.setRate(mData.optString("rate"));
dealsModel.setComments(mData.optString("comments"));
dealsModel.setImage(mData.optString("image"));
dealsModel.setDeals_left(mData.optString("deals_left"));
dealsModel.setIsLike(mData.optString("is_liked"));
Log.e("", "LIKE::::::" + mData.optString("is_liked"));
dealsModel.setIsWallet(mData.optString("is_wallet"));
dealsModel.setPopularity_count(mData.optString("popularity_count"));
dealsModel.setDistanceKm(mData.optString("distance_in_km"));
JSONArray mLocationArray = mData.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
alstHome.add(dealsModel);
// alstNearBy.add(dealsModel);
}
alstNearBy = new ArrayList<DealsModle>();
JSONArray mJsonArrayNearBy = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayNearBy.length(); i++) {
dealsModel = new DealsModle();
JSONObject mDataNearBy = mJsonArrayNearBy.getJSONObject(i);
dealsModel.setDeal_id(mDataNearBy.optString("deal_id"));
dealsModel.setM_fullname(mDataNearBy.optString("m_fullname"));
dealsModel.setMerchant_id(mDataNearBy.optString("merchant_id"));
dealsModel.setMaximum_redumption(mDataNearBy.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mDataNearBy.optString("merchant_user_id"));
dealsModel.setCategory_id(mDataNearBy.optString("category_id"));
dealsModel.setDeal_name(mDataNearBy.optString("deal_name"));
dealsModel.setDeal_desc(mDataNearBy.optString("deal_desc"));
dealsModel.setStart_date(mDataNearBy.optString("start_date"));
dealsModel.setEnd_date(mDataNearBy.optString("end_date"));
dealsModel.setIs_active(mDataNearBy.optString("is_active"));
dealsModel.setRate(mDataNearBy.optString("rate"));
dealsModel.setComments(mDataNearBy.optString("comments"));
dealsModel.setImage(mDataNearBy.optString("image"));
dealsModel.setDeals_left(mDataNearBy.optString("deals_left"));
dealsModel.setIsLike(mDataNearBy.optString("is_liked"));
Log.e("", "LIKE::::::" + mDataNearBy.optString("is_liked"));
dealsModel.setIsWallet(mDataNearBy.optString("is_wallet"));
dealsModel.setPopularity_count(mDataNearBy.optString("popularity_count"));
dealsModel.setDistanceKm(mDataNearBy.optString("distance_in_km"));
JSONArray mLocationArray = mDataNearBy.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
// alstHome.add(dealsModel);
alstNearBy.add(dealsModel);
}
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
//sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else if (strStatus.equalsIgnoreCase("2")) {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDealsAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
} else {
mDealsAsynckTask.execute(deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
}
}
}
public void DealsSevice_loadmore(final String deal_type, String cust_id, String cat_id, String sub_cat_id, String latitude, String longitude, String next_start) {
mDealsAsynckTask_loadmore = new DealsAsynckTask_loadmore(this);
mDealsAsynckTask_loadmore.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
lstDeal.stopLoadMore();
lstDeal.stopRefresh();
if (result != null) {
try {
DealsModle dealsModel = null;
LocationModel locationModel = null;
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
// alstDeals = new ArrayList<DealsModle>();
//alstHome = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("home");
for (int i = 0; i < mJsonArray.length(); i++) {
dealsModel = new DealsModle();
JSONObject mData = mJsonArray.getJSONObject(i);
dealsModel.setDeal_id(mData.optString("deal_id"));
dealsModel.setM_fullname(mData.optString("m_fullname"));
dealsModel.setMerchant_id(mData.optString("merchant_id"));
dealsModel.setMaximum_redumption(mData.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mData.optString("merchant_user_id"));
dealsModel.setCategory_id(mData.optString("category_id"));
dealsModel.setDeal_name(mData.optString("deal_name"));
dealsModel.setDeal_desc(mData.optString("deal_desc"));
dealsModel.setStart_date(mData.optString("start_date"));
dealsModel.setEnd_date(mData.optString("end_date"));
dealsModel.setIs_active(mData.optString("is_active"));
dealsModel.setRate(mData.optString("rate"));
dealsModel.setComments(mData.optString("comments"));
dealsModel.setImage(mData.optString("image"));
dealsModel.setDeals_left(mData.optString("deals_left"));
dealsModel.setIsLike(mData.optString("is_liked"));
Log.e("", "LIKE::::::" + mData.optString("is_liked"));
dealsModel.setIsWallet(mData.optString("is_wallet"));
dealsModel.setPopularity_count(mData.optString("popularity_count"));
dealsModel.setDistanceKm(mData.optString("distance_in_km"));
JSONArray mLocationArray = mData.optJSONArray("locations");
// alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
alstHome.add(dealsModel);
// alstNearBy.add(dealsModel);
}
alstNearBy = new ArrayList<DealsModle>();
JSONArray mJsonArrayNearBy = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayNearBy.length(); i++) {
dealsModel = new DealsModle();
JSONObject mDataNearBy = mJsonArrayNearBy.getJSONObject(i);
dealsModel.setDeal_id(mDataNearBy.optString("deal_id"));
dealsModel.setM_fullname(mDataNearBy.optString("m_fullname"));
dealsModel.setMerchant_id(mDataNearBy.optString("merchant_id"));
dealsModel.setMaximum_redumption(mDataNearBy.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mDataNearBy.optString("merchant_user_id"));
dealsModel.setCategory_id(mDataNearBy.optString("category_id"));
dealsModel.setDeal_name(mDataNearBy.optString("deal_name"));
dealsModel.setDeal_desc(mDataNearBy.optString("deal_desc"));
dealsModel.setStart_date(mDataNearBy.optString("start_date"));
dealsModel.setEnd_date(mDataNearBy.optString("end_date"));
dealsModel.setIs_active(mDataNearBy.optString("is_active"));
dealsModel.setRate(mDataNearBy.optString("rate"));
dealsModel.setComments(mDataNearBy.optString("comments"));
dealsModel.setImage(mDataNearBy.optString("image"));
dealsModel.setDeals_left(mDataNearBy.optString("deals_left"));
dealsModel.setIsLike(mDataNearBy.optString("is_liked"));
Log.e("", "LIKE::::::" + mDataNearBy.optString("is_liked"));
dealsModel.setIsWallet(mDataNearBy.optString("is_wallet"));
dealsModel.setPopularity_count(mDataNearBy.optString("popularity_count"));
dealsModel.setDistanceKm(mDataNearBy.optString("distance_in_km"));
JSONArray mLocationArray = mDataNearBy.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
// alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
// alstHome.add(dealsModel);
alstNearBy.add(dealsModel);
}
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
//sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
//mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
mDealsAdapter.notifyDataSetChanged();
// lstDeal.setAdapter(mDealsAdapter);
}
}
else
{
lstDeal.hide_layout();
mDealsAdapter.notifyDataSetChanged();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDealsAsynckTask_loadmore.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
} else {
mDealsAsynckTask_loadmore.execute(deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
}
}
private boolean isDuplicate(LocationModel locationModel) {
if (locationModel != null) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (locationModel.getLocation_id().equalsIgnoreCase(alstSearchLocationFilter.get(i).getLocation_id())) {
return true;
}
}
}
return false;
}
public void GetAllLocation(String customer_id, String location_type,String cat_id,String sub_cat_id ,String c_latitude, String c_longitude, String next_start) {
if (mGetAllLocationAsynckTask == null) {
mGetAllLocationAsynckTask = new GetAllLocationAsynckTask(this);
mGetAllLocationAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
mGetAllLocationAsynckTask = null;
if (result != null) {
Log.e("result", "Location result::::::::" + result.toString());
try {
alstLocatonHome.clear();
alstLocatonNearBy.clear();
alstLocatonFollowing.clear();
locationModel = null;
alstSearchLocationFilter.clear();
alstLocationImages.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextLocationStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
JSONArray mLocationArray = mJsonResponse.getJSONArray("home");
txtNoDeal.setVisibility(View.GONE);
lstLocation.setVisibility(View.VISIBLE);
alstLocatonHome = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setCity(mLocationObj.optString("city"));
locationModel.setState(mLocationObj.optString("state"));
locationModel.setCountry(mLocationObj.optString("country"));
locationModel.setZipcode(mLocationObj.optString("zipcode"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setTags(mLocationObj.optString("tags"));
locationModel.setEmail(mLocationObj.optString("email"));
locationModel.setWebsite(mLocationObj.optString("website"));
locationModel.setDisp_attire(mLocationObj.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObj.optString("is_deleted"));
locationModel.setCreated(mLocationObj.optString("created"));
locationModel.setAvg_rate(mLocationObj.optString("avg_rate"));
locationModel.setCity_name(mLocationObj.optString("city_name"));
locationModel.setDistance_in_km(mLocationObj.optString("distance_in_km"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
locationModel.setIs_following(mLocationObj.optString("is_following"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
alstLocatonHome.add(locationModel);
//alstLocatonNearBy.add(locationModel);
}
JSONArray mLocationNearBy = mJsonResponse.getJSONArray("data");
if (mLocationNearBy != null) {
if (mLocationNearBy.length() > 0) {
alstLocatonNearBy = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationNearBy.length(); j++) {
JSONObject mLocationObjNearBy = mLocationNearBy.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObjNearBy.optString("location_id"));
locationModel.setLocation_name(mLocationObjNearBy.optString("location_name"));
locationModel.setLocation_desc(mLocationObjNearBy.optString("location_desc"));
locationModel.setLatitude(mLocationObjNearBy.optString("latitude"));
locationModel.setLongitude(mLocationObjNearBy.optString("longitude"));
locationModel.setContact(mLocationObjNearBy.optString("contact"));
locationModel.setAddress1(mLocationObjNearBy.optString("address1"));
locationModel.setAddress2(mLocationObjNearBy.optString("address2"));
locationModel.setLocation_timing(mLocationObjNearBy.optString("location_timing"));
locationModel.setCity(mLocationObjNearBy.optString("city"));
locationModel.setState(mLocationObjNearBy.optString("state"));
locationModel.setCountry(mLocationObjNearBy.optString("country"));
locationModel.setZipcode(mLocationObjNearBy.optString("zipcode"));
locationModel.setPrice_type(mLocationObjNearBy.optString("price_type"));
locationModel.setTags(mLocationObjNearBy.optString("tags"));
locationModel.setEmail(mLocationObjNearBy.optString("email"));
locationModel.setWebsite(mLocationObjNearBy.optString("website"));
locationModel.setDisp_attire(mLocationObjNearBy.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObjNearBy.optString("is_deleted"));
locationModel.setCreated(mLocationObjNearBy.optString("created"));
locationModel.setAvg_rate(mLocationObjNearBy.optString("avg_rate"));
locationModel.setCity_name(mLocationObjNearBy.optString("city_name"));
locationModel.setDistance_in_km(mLocationObjNearBy.optString("distance_in_km"));
locationModel.setRate(mLocationObjNearBy.optString("rate"));
locationModel.setComments(mLocationObjNearBy.optString("comments"));
locationModel.setIs_following(mLocationObjNearBy.optString("is_following"));
JSONArray locationImageNearBy = mLocationObjNearBy.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImageNearBy != null) {
if (locationImageNearBy.length() > 0) {
for (int k = 0; k < locationImageNearBy.length(); k++) {
JSONObject mlocationImageObj1 = locationImageNearBy.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj1.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// alstLocatonHome.add(locationModel);
alstLocatonNearBy.add(locationModel);
}
}
}
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
// if (alstSearchLocationFilter.size() > 0) {
// Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
// @Override
// public int compare(final LocationModel object1, final LocationModel object2) {
// return object1.getLocation_name().compareTo(object2.getLocation_name());
// }
// });
// }
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (!alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("0")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
lstLocation.setVisibility(View.GONE);
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
lstLocation.setVisibility(View.GONE);
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.no_location_found), Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.e("Lat", "Lat:::" + c_latitude);
Log.e("Long", "Long:::" + c_longitude);
mGetAllLocationAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customer_id, location_type, cat_id,sub_cat_id,c_latitude, c_longitude, next_start);
} else {
mGetAllLocationAsynckTask.execute(customer_id, location_type,cat_id,sub_cat_id,c_latitude, c_longitude, next_start);
}
}
}
public void GetAllLocation_loadmore(String customer_id, String location_type,String cat_id ,String sub_cat_id,String c_latitude, String c_longitude, String next_start) {
mGetAllLocationAsynckTask_loadmore = new GetAllLocationAsynckTask_loadMore(this);
mGetAllLocationAsynckTask_loadmore.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response)
{
}
@Override
public void onResponseReceived(String result) {
lstLocation.stopRefresh();
lstLocation.stopLoadMore();
if (result != null) {
try {
JSONObject mJsonResult = new JSONObject(result);
// lstLocation.hide_layout();
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextLocationStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
JSONArray mLocationArray = mJsonResponse.getJSONArray("home");
//alstLocatonHome = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setCity(mLocationObj.optString("city"));
locationModel.setState(mLocationObj.optString("state"));
locationModel.setCountry(mLocationObj.optString("country"));
locationModel.setZipcode(mLocationObj.optString("zipcode"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setTags(mLocationObj.optString("tags"));
locationModel.setEmail(mLocationObj.optString("email"));
locationModel.setWebsite(mLocationObj.optString("website"));
locationModel.setDisp_attire(mLocationObj.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObj.optString("is_deleted"));
locationModel.setCreated(mLocationObj.optString("created"));
locationModel.setAvg_rate(mLocationObj.optString("avg_rate"));
locationModel.setCity_name(mLocationObj.optString("city_name"));
locationModel.setDistance_in_km(mLocationObj.optString("distance_in_km"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
locationModel.setIs_following(mLocationObj.optString("is_following"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
alstLocatonHome.add(locationModel);
//alstLocatonNearBy.add(locationModel);
}
JSONArray mLocationNearBy = mJsonResponse.getJSONArray("data");
if (mLocationNearBy != null) {
if (mLocationNearBy.length() > 0) {
alstLocatonNearBy = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationNearBy.length(); j++) {
JSONObject mLocationObjNearBy = mLocationNearBy.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObjNearBy.optString("location_id"));
locationModel.setLocation_name(mLocationObjNearBy.optString("location_name"));
locationModel.setLocation_desc(mLocationObjNearBy.optString("location_desc"));
locationModel.setLatitude(mLocationObjNearBy.optString("latitude"));
locationModel.setLongitude(mLocationObjNearBy.optString("longitude"));
locationModel.setContact(mLocationObjNearBy.optString("contact"));
locationModel.setAddress1(mLocationObjNearBy.optString("address1"));
locationModel.setAddress2(mLocationObjNearBy.optString("address2"));
locationModel.setLocation_timing(mLocationObjNearBy.optString("location_timing"));
locationModel.setCity(mLocationObjNearBy.optString("city"));
locationModel.setState(mLocationObjNearBy.optString("state"));
locationModel.setCountry(mLocationObjNearBy.optString("country"));
locationModel.setZipcode(mLocationObjNearBy.optString("zipcode"));
locationModel.setPrice_type(mLocationObjNearBy.optString("price_type"));
locationModel.setTags(mLocationObjNearBy.optString("tags"));
locationModel.setEmail(mLocationObjNearBy.optString("email"));
locationModel.setWebsite(mLocationObjNearBy.optString("website"));
locationModel.setDisp_attire(mLocationObjNearBy.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObjNearBy.optString("is_deleted"));
locationModel.setCreated(mLocationObjNearBy.optString("created"));
locationModel.setAvg_rate(mLocationObjNearBy.optString("avg_rate"));
locationModel.setCity_name(mLocationObjNearBy.optString("city_name"));
locationModel.setDistance_in_km(mLocationObjNearBy.optString("distance_in_km"));
locationModel.setRate(mLocationObjNearBy.optString("rate"));
locationModel.setComments(mLocationObjNearBy.optString("comments"));
locationModel.setIs_following(mLocationObjNearBy.optString("is_following"));
JSONArray locationImageNearBy = mLocationObjNearBy.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImageNearBy != null) {
if (locationImageNearBy.length() > 0) {
for (int k = 0; k < locationImageNearBy.length(); k++) {
JSONObject mlocationImageObj1 = locationImageNearBy.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj1.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// alstLocatonHome.add(locationModel);
alstLocatonNearBy.add(locationModel);
}
}
}
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
// if (alstSearchLocationFilter.size() > 0) {
// Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
// @Override
// public int compare(final LocationModel object1, final LocationModel object2) {
// return object1.getLocation_name().compareTo(object2.getLocation_name());
// }
// });
// }
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++)
{
if (!alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("0")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
//mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
// lstLocation.setAdapter(mSearchLocationAdapter);
mSearchLocationAdapter.notifyDataSetChanged();
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
}
}
else
{
lstLocation.hide_layout();
mSearchLocationAdapter.notifyDataSetChanged();
}
}
} catch (JSONException e)
{
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.e("Lat", "Lat:::" + c_latitude);
Log.e("Long", "Long:::" + c_longitude);
mGetAllLocationAsynckTask_loadmore.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customer_id,cat_id,sub_cat_id,location_type, c_latitude, c_longitude, next_start);
} else {
mGetAllLocationAsynckTask_loadmore.execute(customer_id, location_type,cat_id,sub_cat_id, c_latitude, c_longitude, next_start);
}
}
public void unFollow_Follow_Location(final String cust_id, String location_id, final String is_following, final LocationModel mLocationModel, final String location_type) {
FollowUnFollowLocationAsyncTask mFollowUnFollowAsyncTask = new FollowUnFollowLocationAsyncTask(this);
mFollowUnFollowAsyncTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mLocationModel.getIs_following().equalsIgnoreCase("0")) {
// mLocationModel.setIs_following("1");
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.you_have_follow_this_location), Toast.LENGTH_LONG).show();
} else {
// mLocationModel.setIs_following("0");
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.you_have_unfollow_this_location), Toast.LENGTH_LONG).show();
}
// int pos = alstSearchLocationFilter.indexOf(mLocationModel);
// alstSearchLocationFilter.set(pos, mLocationModel);
// mSearchLocationAdapter.notifyDataSetChanged();
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (location_type.equalsIgnoreCase(Consts.HOME))
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
else if (location_type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
else if (location_type.equalsIgnoreCase(Consts.FOLLOWING)) {
mLocationModel.setIs_following("0");
// int follow_pos = alstSearchLocationFilter.indexOf(mLocationModel);
alstSearchLocationFilter.remove(mLocationModel);
mSearchLocationAdapter.notifyDataSetChanged();
if (alstSearchLocationFilter.size() <= 0) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
}
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
// Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.please_try_again), Toast.LENGTH_LONG).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mFollowUnFollowAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cust_id, location_id, is_following);
} else {
mFollowUnFollowAsyncTask.execute(cust_id, location_id, is_following);
}
}
public void FollowingLocation(String cust_id) {
LocationFollowingAsyncTask mFollowingsAsynckTask = new LocationFollowingAsyncTask(this);
mFollowingsAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
alstSearchLocationFilter.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
txtNoDeal.setVisibility(View.GONE);
alstSearchLocationFilter = new ArrayList<LocationModel>();
JSONArray mJsonArrayLocation = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayLocation.length(); i++) {
locationModel = new LocationModel();
JSONObject mLocationData = mJsonArrayLocation.getJSONObject(i);
locationModel.setLocation_id(mLocationData.optString("location_id"));
locationModel.setLocation_name(mLocationData.optString("location_name"));
locationModel.setLocation_desc(mLocationData.optString("mLocationData"));
locationModel.setAddress1(mLocationData.optString("address1"));
locationModel.setFollower_id(mLocationData.optString("follower_id"));
locationModel.setIs_following(mLocationData.optString("is_following"));
locationModel.setIs_block(mLocationData.optString("is_block"));
locationModel.setComments(mLocationData.optString("comments"));
locationModel.setRate(mLocationData.optString("rate"));
locationModel.setImage(mLocationData.optString("image"));
alstSearchLocationFilter.add(locationModel);
// strLocationCount = String.valueOf(mJsonArrayLocation.length());
}
// txtLocation.setText(getResources().getString(R.string.you_are_following) + " " + strLocationCount + " " + getResources().getString(R.string.locations));
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mFollowingsAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cust_id);
} else {
mFollowingsAsynckTask.execute(cust_id);
}
}
public void GetAllCategories() {
GetCategoriesAsynckTask mGetCategoriesAsynckTask = new GetCategoriesAsynckTask(this);
mGetCategoriesAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
CategoryModel mCategoryModel = null;
SubCategoriesModel mSubCategoriesModel = null;
alstCategory.clear();
alstMoreCategories.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
alstCategory = new ArrayList<CategoryModel>();
alstMoreCategories = new ArrayList<CategoryModel>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("data");
if (mJsonArray != null) {
for (int i = 0; i < mJsonArray.length() + 1; i++) {
if (i == 0) {
mCategoryModel = new CategoryModel();
//JSONObject mData = mJsonArray.optJSONObject(i);
mCategoryModel.setCatId("0");
mCategoryModel.setCatName(getResources().getString(R.string.all));
mCategoryModel.setCatImage("");
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstCategory.add(mCategoryModel);
alstMoreCategories.add(mCategoryModel);
alstSubCategory = new ArrayList<SubCategoriesModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
hashmapSubCategory.put("0", alstSubCategory);
hashmapMoreSubCategories.put("0", alstMoreSubCategories);
} else if (i < 5) {
mCategoryModel = new CategoryModel();
JSONObject mData = mJsonArray.optJSONObject(i - 1);
mCategoryModel.setCatId(mData.optString("category_id"));
mCategoryModel.setCatName(mData.optString("category_name"));
mCategoryModel.setCatImage(mData.optString("image"));
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstCategory.add(mCategoryModel);
alstMoreCategories.add(mCategoryModel);
JSONArray mSubArray = mData.optJSONArray("subcategories");
alstSubCategory = new ArrayList<SubCategoriesModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
if (mSubArray != null) {
if (mSubArray.length() > 0) {
for (int j = 0; j < mSubArray.length(); j++) {
mSubCategoriesModel = new SubCategoriesModel();
JSONObject mSubObj = mSubArray.optJSONObject(j);
mSubCategoriesModel.setStrSubCatId(mSubObj.optString("category_id"));
mSubCategoriesModel.setStrSubCatName(mSubObj.optString("category_name"));
mSubCategoriesModel.setStrSubCatImage(mSubObj.optString("image"));
mSubCategoriesModel.setIsChecked(false);
alstSubCategory.add(mSubCategoriesModel);
alstMoreSubCategories.add(mSubCategoriesModel);
}
// mCategoryModel.setAlstSubCat(alstSubCategory);
}
}
hashmapSubCategory.put(mData.optString("category_id"), alstSubCategory);
hashmapMoreSubCategories.put(mData.optString("category_id"), alstMoreSubCategories);
}
// else if (i == 5) {
// mCategoryModel = new CategoryModel();
// //JSONObject mData = mJsonArray.optJSONObject(i);
// mCategoryModel.setCatId("-1");
// mCategoryModel.setCatName(getResources().getString(R.string.more_categories));
// mCategoryModel.setCatImage("");
// mCategoryModel.setIsChecked(false);
// mCategoryModel.setIsChildChecked(false);
// alstCategory.add(mCategoryModel);
// alstSubCategory = new ArrayList<SubCategoriesModel>();
// hashmapSubCategory.put("-1", alstSubCategory);
else {
mCategoryModel = new CategoryModel();
JSONObject mData = mJsonArray.optJSONObject(i - 1);
mCategoryModel.setCatId(mData.optString("category_id"));
mCategoryModel.setCatName(mData.optString("category_name"));
mCategoryModel.setCatImage(mData.optString("image"));
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstMoreCategories.add(mCategoryModel);
JSONArray mSubArray = mData.optJSONArray("subcategories");
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
if (mSubArray != null) {
if (mSubArray.length() > 0) {
for (int j = 0; j < mSubArray.length(); j++) {
mSubCategoriesModel = new SubCategoriesModel();
JSONObject mSubObj = mSubArray.optJSONObject(j);
mSubCategoriesModel.setStrSubCatId(mSubObj.optString("category_id"));
mSubCategoriesModel.setStrSubCatName(mSubObj.optString("category_name"));
mSubCategoriesModel.setStrSubCatImage(mSubObj.optString("image"));
mSubCategoriesModel.setIsChecked(false);
alstMoreSubCategories.add(mSubCategoriesModel);
}
// mCategoryModel.setAlstSubCat(alstSubCategory);
}
}
hashmapMoreSubCategories.put(mData.optString("category_id"), alstMoreSubCategories);
}
}
//
// for (int i = 0; i < alstCategory.size(); i++) {
// Log.e("", "Category:::::" + alstCategory.get(i).getCatName());
// }
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setVisibility(View.VISIBLE);
drawerView = (ViewDrawer) findViewById(R.id.drawer);
drawerView.setVisibility(View.VISIBLE);
mOnUpdateListner = (onUpdateListner) drawerView;
mOnUpdateListner.onUpdate();
inItData();
}
}
else
{
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mGetCategoriesAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
mGetCategoriesAsynckTask.execute();
}
}
public void dialogSkipNow(Context context) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(getResources().getString(R.string.app_name));
alertDialogBuilder
.setMessage(getResources().getString(R.string.you_have_not_register_yet))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.register_now), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
Intent intent = new Intent(DealsActivity.this, RegistrationActivity.class);
startActivity(intent);
finish();
}
})
.setNegativeButton(getResources().getString(R.string.register_later), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
// Utils.storeString(Consts.USER_ID, "");
// Utils.storeString(Consts.CUSTOMER_ID, "");
// Utils.storeString(Consts.USER_NAME, "");
// Utils.storeString(Consts.USER_EMAIL, "");
// Utils.storeString(Consts.PROFILE_PIC_URL, "");
// Utils.storeString(Consts.COVER_PIC_URL, "");
Utils.storeBoolean(Consts.SKIP_NOW, true);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return false;
}
return super.onKeyDown(keyCode, event);
}
public void sortDealData(String strSort) {
if (Utils.validateString(strSort)) {
if (alstDeals.size() > 0) {
if (strSort.equalsIgnoreCase("deal_id")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getStart_date().compareTo(object2.getStart_date());
}
});
} else if (strSort.equalsIgnoreCase("deal_name")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getDeal_name().compareTo(object2.getDeal_name());
}
});
} else if (strSort.equalsIgnoreCase("comments")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getPopularity_count().compareTo(object2.getPopularity_count());
}
});
}
}
}
}
public void callLogin(String strUserEmail, String strUserPass) {
ReturnResult retrunResultObj = new ReturnResult() {
@Override
public void resultData(Object object, String tag) {
if (object != null) {
try {
JSONObject jObj = (JSONObject) object;
JSONObject response = jObj.getJSONObject("response");
String status = response.getString("status");
if (status != null) {
if (status.equalsIgnoreCase("1")) {
Utils.storeString(Consts.USER_ID, response.getString("user_id"));
Utils.storeString(Consts.CUSTOMER_ID, response.getString("customer_id"));
Utils.storeString(Consts.USER_NAME, response.getString("full_name"));
Utils.storeString(Consts.USER_EMAIL, response.getString("email"));
Utils.storeString(Consts.PROFILE_PIC_URL, response.getString("profile_image"));
Utils.storeString(Consts.COVER_PIC_URL, response.getString("cover_image"));
Utils.storeBoolean(Consts.SKIP_NOW, false);
Utils.storeBoolean(Consts.IS_LOGIN, true);
} else if (status.equalsIgnoreCase("2")) {
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.email_validation), Toast.LENGTH_SHORT).show();
} else if (status.equalsIgnoreCase("-4"))
AlertMessageLogin(getString(R.string.your_account_has_been_blocked_please_contact_masmas));
else if (status.equalsIgnoreCase("-5"))
AlertMessageLogin(getString(R.string.your_account_has_been_deleted_from_database));
}
//else
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.please_try_again), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
} else {
// Toast.makeText(DealsActivity.this, getString(R.string.please_try_again), Toast.LENGTH_LONG).show();
}
}
};
List<NameValuePair> nameValuePairsParams = new ArrayList<NameValuePair>();
nameValuePairsParams.add(new BasicNameValuePair("email", strUserEmail));
nameValuePairsParams.add(new BasicNameValuePair("password", strUserPass));
nameValuePairsParams.add(new BasicNameValuePair("device_token", "yrr"));
nameValuePairsParams.add(new BasicNameValuePair("ut_id", "2"));
if (new NetworkConnection().checkInternetConnection(this)) {
new PostDataAsync(DealsActivity.this, retrunResultObj, Consts.BASE_URL + "Customer/Login", nameValuePairsParams, "login").execute();
} else {
Toast.makeText(DealsActivity.this, getString(R.string.internet_problem), Toast.LENGTH_LONG).show();
}
}
public void AlertMessageLogin(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg);
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Utils.storeBoolean(Consts.IS_LOGIN, false);
Intent mIntent = new Intent(DealsActivity.this, LoginActivity.class);
startActivity(mIntent);
finish();
}
});
AlertDialog alert11 = builder.show();
alert11.show();
}
@Override
public void onRefresh()
{
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if(isDeal)
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice_loadmore("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
else
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation_loadmore(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
}
}, 2000);
}
@Override
public void onLoadMore() {
{
mHandler.postDelayed(new Runnable() {
@Override
public void run()
{
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if(isDeal)
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, sub_cat_id, myLat,myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice_loadmore("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
else
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation_loadmore(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
}
}, 2000);
}
}
}
================
package com.bluegreen.masmas.customer.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bluegreen.masmas.customer.AsyncTask.AddWalletAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.AsyncCallListener;
import com.bluegreen.masmas.customer.AsyncTask.DealsAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.DealsAsynckTask_loadmore;
import com.bluegreen.masmas.customer.AsyncTask.DeleteWalletAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.FollowUnFollowLocationAsyncTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllLocationAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllLocationAsynckTask_loadMore;
import com.bluegreen.masmas.customer.AsyncTask.GetCategoriesAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.LocationFollowingAsyncTask;
import com.bluegreen.masmas.customer.AsyncTask.PostDataAsync;
import com.bluegreen.masmas.customer.AsyncTask.ReturnResult;
import com.bluegreen.masmas.customer.R;
import com.bluegreen.masmas.customer.Utility.Consts;
import com.bluegreen.masmas.customer.Utility.GPSTracker;
import com.bluegreen.masmas.customer.Utility.LanguageChange;
import com.bluegreen.masmas.customer.Utility.MasMas;
import com.bluegreen.masmas.customer.Utility.NetworkConnection;
import com.bluegreen.masmas.customer.Utility.Utils;
import com.bluegreen.masmas.customer.adapter.DealsAdapter;
import com.bluegreen.masmas.customer.adapter.SearchLocationAdapter;
import com.bluegreen.masmas.customer.model.CategoryModel;
import com.bluegreen.masmas.customer.model.DealDetailImagesModel;
import com.bluegreen.masmas.customer.model.DealsModle;
import com.bluegreen.masmas.customer.model.LocationModel;
import com.bluegreen.masmas.customer.model.SubCategoriesModel;
import com.bluegreen.masmas.customer.navigation.ViewDrawer;
import com.bluegreen.masmas.customer.navigation.onUpdateListner;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenu;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuCreator;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuItem;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuListView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
/**
* Created by Manisha on 08/09/2015.
*/
public class DealsActivity extends Activity implements View.OnClickListener,SwipeMenuListView.IXListViewListener {
private ImageView imgDeals_menu;
private TextView txtHeader_deals, txtFilterbtn, txtMapDeal;
DrawerLayout drawerLayout;
ViewDrawer drawerView;
private SwipeMenuListView lstDeal;
private SwipeMenuListView lstLocation;
private DealsAdapter mDealsAdapter;
private String cust_id = "";
private boolean isFromMenu = false;
private TextView txtHome, txtNearBy, txtLike;
private ImageView imgHome, imgNearBy, imgLike, imgClose, imgFilterClose;
private String myLat = "", myLng = "";
private String type = Consts.HOME;
private String type_location = Consts.HOME;
private AutoCompleteTextView edt_search_deal;
private ArrayList<DealsModle> alstDeals;
private ArrayList<DealsModle> alstHome;
private ArrayList<DealsModle> alstNearBy;
private ArrayList<DealsModle> alstLike;
private ArrayList<LocationModel> alstLocation;
private ArrayList<LocationModel> alstLocatonHome;
private ArrayList<LocationModel> alstLocatonNearBy;
private ArrayList<LocationModel> alstLocatonFollowing;
private DealDetailImagesModel mDealDetailImagesModel;
private ArrayList<DealDetailImagesModel> alstLocationImages;
private SearchLocationAdapter mSearchLocationAdapter;
private TextView btnDeals, btnLocation;
private RelativeLayout rlytLocation;
public Boolean isDeal = false;
private ArrayList<LocationModel> alstSearchLocationFilter;
public boolean islike = false;
private TextView txtNoDeal, txtFilterText;
private ArrayAdapter<String> aadpDeal;
private ArrayList<String> alstSearchDealName;
private ArrayList<String> alstSearchLocationName;
private LinearLayout lytLocation, lytFilter;
private boolean isSkipNow = false;
private String cat_id = "0", sub_cat_id = "0";
private LocationModel locationModel;
public static HashMap<String, List<SubCategoriesModel>> hashmapSubCategory, hashmapMoreSubCategories;
public static ArrayList<CategoryModel> alstCategory, alstMoreCategories;
public static ArrayList<SubCategoriesModel> alstSubCategory, alstMoreSubCategories;
private onUpdateListner mOnUpdateListner;
private Boolean is_first = false;
private String strSort = "";
private String strUserEmail, strUserPass;
public DealsAsynckTask mDealsAsynckTask = null;
public DealsAsynckTask_loadmore mDealsAsynckTask_loadmore = null;
public GetAllLocationAsynckTask mGetAllLocationAsynckTask = null;
GetAllLocationAsynckTask_loadMore mGetAllLocationAsynckTask_loadmore=null;
private ArrayList<LocationModel> alstMapLocation;
EditText dummyEditTextFocus;
String nextLocationStart="0";
String nextStart="0";
private Handler mHandler;
//c creatorFollow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, Context.MODE_MULTI_PROCESS);
boolean is_login = Utils.sharedPreferences.getBoolean(Consts.IS_LOGIN, false);
String language = Utils.sharedPreferences.getString(Consts.LANGUAGE, Consts.SPANISH);
if (Utils.validateString(language)) {
LanguageChange.setlanguage(this, language);
}
setContentView(R.layout.activity_deals_dashboard);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.header));
}
// Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, MODE_PRIVATE);
is_first = Utils.sharedPreferences.getBoolean(Consts.IS_FIRST, false);
strUserEmail = Utils.sharedPreferences.getString(Consts.USER_EMAIL, "");
strUserPass = Utils.sharedPreferences.getString(Consts.PASSWORD, "");
alstMapLocation = new ArrayList<LocationModel>();
Utils.storeString(Consts.TYPE, Consts.HOME);
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
Log.e("", "is_first::::" + is_first);
if (is_login)
{
callLogin(strUserEmail, strUserPass);
}
if (is_first) {
inItData();
} else {
Utils.storeBoolean(Consts.IS_FIRST, true);
inItDrawerData();
GetAllCategories();
}
}
// msg : categories for locations are coming soon.
public void inItDrawerData() {
alstCategory = new ArrayList<CategoryModel>();
alstSubCategory = new ArrayList<SubCategoriesModel>();
hashmapSubCategory = new HashMap<String, List<SubCategoriesModel>>();
alstMoreCategories = new ArrayList<CategoryModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
hashmapMoreSubCategories = new HashMap<String, List<SubCategoriesModel>>();
}
public void inItData() {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
GPSTracker gps = new GPSTracker(this);
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
strSort = Utils.sharedPreferences.getString(Consts.SORT_FILTER, "");
isSkipNow = Utils.sharedPreferences.getBoolean(Consts.SKIP_NOW, false);
cust_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
imgDeals_menu = (ImageView) findViewById(R.id.imgDeals_menu);
imgDeals_menu.setOnClickListener(this);
txtHeader_deals = (TextView) findViewById(R.id.txtHeader_deals);
if (Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false)) {
txtHeader_deals.setText(getResources().getString(R.string.deals));
} else {
txtHeader_deals.setText(getResources().getString(R.string.locations));
}
dummyEditTextFocus = (EditText) findViewById(R.id.dummyEditTextFocus);
dummyEditTextFocus.requestFocus();
txtFilterbtn = (TextView) findViewById(R.id.txtFilterbtn);
txtFilterbtn.setOnClickListener(this);
txtNoDeal = (TextView) findViewById(R.id.txtNoDeal);
txtMapDeal = (TextView) findViewById(R.id.txtMapDeal);
txtMapDeal.setOnClickListener(this);
txtHome = (TextView) findViewById(R.id.txtHome);
txtHome.setOnClickListener(this);
txtNearBy = (TextView) findViewById(R.id.txtNearBy);
txtNearBy.setOnClickListener(this);
txtLike = (TextView) findViewById(R.id.txtLike);
txtLike.setOnClickListener(this);
lytLocation = (LinearLayout) findViewById(R.id.lytLocation);
lytLocation.setVisibility(View.VISIBLE);
lstLocation = (SwipeMenuListView) findViewById(R.id.lstLocation);
rlytLocation = (RelativeLayout) findViewById(R.id.rlytLocation);
rlytLocation.setVisibility(View.GONE);
btnDeals = (TextView) findViewById(R.id.btnDeals);
btnDeals.setOnClickListener(this);
btnLocation = (TextView) findViewById(R.id.btnLocation);
btnLocation.setOnClickListener(this);
imgHome = (ImageView) findViewById(R.id.imgHome);
imgNearBy = (ImageView) findViewById(R.id.imgNearBy);
imgLike = (ImageView) findViewById(R.id.imgLike);
imgClose = (ImageView) findViewById(R.id.imgClose);
imgClose.setOnClickListener(this);
lytFilter = (LinearLayout) findViewById(R.id.lytFilter);
imgFilterClose = (ImageView) findViewById(R.id.imgFilterClose);
imgFilterClose.setOnClickListener(this);
txtFilterText = (TextView) findViewById(R.id.txtFilterText);
alstDeals = new ArrayList<DealsModle>();
alstHome = new ArrayList<DealsModle>();
alstNearBy = new ArrayList<DealsModle>();
alstLike = new ArrayList<DealsModle>();
alstLocation = new ArrayList<LocationModel>();
alstLocatonHome = new ArrayList<LocationModel>();
alstLocatonNearBy = new ArrayList<LocationModel>();
alstLocatonFollowing = new ArrayList<LocationModel>();
alstLocationImages = new ArrayList<DealDetailImagesModel>();
alstSearchLocationFilter = new ArrayList<LocationModel>();
alstSearchDealName = new ArrayList<String>();
alstSearchLocationName = new ArrayList<String>();
edt_search_deal = (AutoCompleteTextView) findViewById(R.id.edt_search_deal);
edt_search_deal.setText("");
edt_search_deal.setThreshold(1);
edt_search_deal.setOnClickListener(this);
lstDeal = (SwipeMenuListView) findViewById(R.id.lstDeals);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setVisibility(View.VISIBLE);
drawerView = (ViewDrawer) findViewById(R.id.drawer);
drawerView.setVisibility(View.VISIBLE);
mHandler = new Handler();
lstLocation.setXListViewListener(this);
lstLocation.setPullLoadEnable(true);
lstDeal.setXListViewListener(this);
lstDeal.setPullLoadEnable(true);
// check if GPS enabled
if (gps.getIsGPSTrackingEnabled())
{
myLat = String.valueOf(gps.getLatitude());
myLng = String.valueOf(gps.getLongitude());
/* myLat = "-0.18287";
myLng = "-78.477663";*/
//self.STRLatitude = @"-0.182875";
//self.STRLongitude = @"-78.477663";
// myLat = "23.012658";
// myLng = "72.521739";
// Log.e("", "myLat:::" + myLat);
// Log.e("", "myLng:::" + myLng);
}
Intent intent = getIntent();
if (intent.getAction() != null) {
alstDeals.clear();
alstSearchDealName.clear();
alstSearchLocationName.clear();
alstHome.clear();
alstNearBy.clear();
if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_FILTER)) {
// isDeal = true;
Utils.storeBoolean(Consts.IS_DEAL, true);
Utils.storeBoolean(Consts.FILTER_RESULT, true);
lytFilter.setVisibility(View.VISIBLE);
txtFilterText.setText(Utils.sharedPreferences.getString(Consts.FILTER_TEXT, ""));
dealVisible();
Bundle mBundle = intent.getBundleExtra(Consts.FILTER_DEAL_BUNDLE);
if (mBundle != null) {
alstHome = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
alstNearBy = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
alstDeals = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
// sortDealData(strSort);
// Handle Deals sorting as per type
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
edt_search_deal.setAdapter(aadpDeal);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_MENU)) {
cat_id = Utils.sharedPreferences.getString(Consts.CATEGORY_ID, "0");
sub_cat_id = Utils.sharedPreferences.getString(Consts.SUB_CATEGORY_ID, "0");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, false);
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
strSort = Utils.sharedPreferences.getString(Consts.SORT_FILTER, "");
if (isDeal) {
dealVisible();
Log.e("", "cat_id::" + cat_id);
Log.e("", "sub_cat_id::" + sub_cat_id);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("0") && !sub_cat_id.equalsIgnoreCase("0")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("0")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
} else {
locationVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("0") && !sub_cat_id.equalsIgnoreCase("0")) {
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, "0");
}else if (sub_cat_id.equalsIgnoreCase("0"))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, "0");
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, "0");
}
}
}
} else if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_FILTER_LOCATION)) {
// isDeal = false;
Utils.storeBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, true);
locationVisible();
Bundle mBundle = intent.getBundleExtra(Consts.FILTER_LOCATION_BUNDLE);
txtFilterText.setText(Utils.sharedPreferences.getString(Consts.FILTER_TEXT, ""));
alstSearchLocationName.clear();
alstSearchLocationFilter.clear();
alstLocatonHome.clear();
alstLocatonNearBy.clear();
alstSearchLocationFilter = (ArrayList<LocationModel>) mBundle.getSerializable(Consts.FILTER_LOCATION_ARRAY);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
Log.e("", "Location Name:::" + alstSearchLocationFilter.get(i).getLocation_name());
Log.e("", "Price Type:::" + alstSearchLocationFilter.get(i).getPrice_type());
Log.e("", "Rate:::" + alstSearchLocationFilter.get(i).getRate());
}
alstLocatonHome.addAll(alstSearchLocationFilter);
alstLocatonNearBy.addAll(alstSearchLocationFilter);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
if (alstSearchLocationFilter.size() > 0) {
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
}
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("1")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int x = 0; x < alstSearchLocationFilter.size(); x++) {
Log.e("", "Loc Name:::" + alstSearchLocationFilter.get(x).getLocation_name());
alstSearchLocationName.add(alstSearchLocationFilter.get(x).getLocation_name());
}
if (alstSearchLocationFilter.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
} else {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, false);
if (isDeal) {
dealVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else {
locationVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, "0");
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, "0");
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, "0");
}
}
}
}
// edt_search_deal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
// public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_NEXT)) {
// Log.i("", "Enter pressed=>>>>");
// InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
// }
// return false;
// }
// });
edt_search_deal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
}
});
edt_search_deal.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
edt_search_deal.setAdapter(aadpDeal);
// edt_search_deal.showDropDown();
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
String text = edt_search_deal.getText().toString().toLowerCase(Locale.getDefault());
if (mDealsAdapter != null) {
mDealsAdapter.filter(text);
}
} else {
String text = edt_search_deal.getText().toString().toLowerCase(Locale.getDefault());
if (mSearchLocationAdapter != null) {
mSearchLocationAdapter.filter(text);
}
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
});
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu, int position) {
SwipeMenuItem AddItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
AddItem.setIcon(R.drawable.add_wallet);
AddItem.setTitle("");
AddItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
AddItem.setTitleColor(getResources().getColor(R.color.white));
AddItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(WalletItem);
SwipeMenuItem RemoveItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
RemoveItem.setIcon(R.drawable.remove_wallet);
RemoveItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
RemoveItem.setTitleColor(getResources().getColor(R.color.white));
RemoveItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(RemoveItem);
if (alstDeals != null) {
if (alstDeals.size() > 0) {
if (alstDeals.get(position).getIsWallet().equalsIgnoreCase("0")) {
menu.addMenuItem(AddItem);
} else {
menu.addMenuItem(RemoveItem);
}
}
}
}
};
lstDeal.setMenuCreator(creator);
lstDeal.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
if (isSkipNow) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.you_are_not_register_user));
} else {
final DealsModle mModel = alstDeals.get(position);
Log.e(" ", "position:::::" + position);
Log.e(" ", "index::::" + index);
//Toast.makeText(DealsActivity.this, "Postion::" + position, Toast.LENGTH_SHORT).show();
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.internet_problem));
} else {
String customenr_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
String deal_id = mModel.getDeal_id();
if (mModel.getIsWallet().equalsIgnoreCase("0")) {
AddToWalletSevice(customenr_id, deal_id, mModel);
} else {
showDeleteDealDialog(DealsActivity.this, customenr_id, deal_id, mModel);
}
}
}
return false;
}
});
// lstDeal.setOnScrollListener(new AbsListView.OnScrollListener() {
// @Override
// public void onScrollStateChanged(AbsListView view, int scrollState) {
//
// }
//
// @Override
// public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// int lastInScreen = firstVisibleItem + visibleItemCount;
// // is the bottom item visible & not loading more already ? Load more !
// String nextStart ="0";
// if (isDeal) {
// if ((lastInScreen == totalItemCount) && mDealsAsynckTask == null) {
// if (alstDeals != null) {
// if (alstDeals.size() > 0) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
// DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
// } else if (sub_cat_id.equalsIgnoreCase("")) {
// DealsSevice("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
// } else {
// DealsSevice("home", cust_id, "0", "0", myLat, myLng,nextStart);
// }
// }
// }
// }
// }
// }
// }
// });
lstDeal.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {
@Override
public void onSwipeStart(int position) {
// Toast.makeText(DealsActivity.this, "Swip Start", Toast.LENGTH_SHORT).show();
}
@Override
public void onSwipeEnd(int position) {
// Toast.makeText(DealsActivity.this, "Swip End", Toast.LENGTH_SHORT).show();
}
});
lstDeal.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// Toast.makeText(DealsActivity.this.getApplicationContext(), position + " long click", Toast.LENGTH_LONG).show();
return false;
}
});
lstDeal.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(DealsActivity.this, DealDetailActivity.class);
intent.putExtra(Consts.DEAL_ID, alstDeals.get(i).getDeal_id());
// intent.putExtra("lat", myLat);
// intent.putExtra("long", myLng);
// MasMas.tracker().send(new HitBuilders.EventBuilder("D_" + alstDeals.get(i).getDeal_id(), "Deal_Click")
// .setLabel("CM_" + cust_id)
// .build());
MasMas.getInstance().trackEvent("D_" + alstDeals.get(i).getDeal_id(), "Deal Click", "CM_" + cust_id);
if (alstDeals.get(i).getAlstLocation() != null) {
if (alstDeals.get(i).getAlstLocation().size() > 0) {
//Log.e("", "LOCIDDDD:::::" + alstDeals.get(i).getAlstLocation().get(0).getLocation_id());
intent.putExtra(Consts.LOCATION_ID, alstDeals.get(i).getAlstLocation().get(0).getLocation_id());
}
}
startActivity(intent);
}
});
SwipeMenuCreator creatorFollow = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu, int position) {
SwipeMenuItem FollowItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
FollowItem.setIcon(R.drawable.follow);
FollowItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
FollowItem.setTitleColor(getResources().getColor(R.color.white));
FollowItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(WalletItem);
SwipeMenuItem UnFollowItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
UnFollowItem.setIcon(R.drawable.unfollow);
UnFollowItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
UnFollowItem.setTitleColor(getResources().getColor(R.color.white));
UnFollowItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(RemoveItem);
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
Log.e("Follow","Follow:::"+alstSearchLocationFilter.get(position).getLocation_name());
Log.e("Follow","Follow:::"+alstSearchLocationFilter.get(position).getIs_following());
if (alstSearchLocationFilter.get(position).getIs_following().equalsIgnoreCase("0")) {
menu.addMenuItem(FollowItem);
} else {
menu.addMenuItem(UnFollowItem);
}
}
}
}
};
lstLocation.setMenuCreator(creatorFollow);
lstLocation.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
if (isSkipNow) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.you_are_not_register_user));
} else {
final LocationModel mModel = alstSearchLocationFilter.get(position);
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
String customer_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "0");
String location_id = mModel.getLocation_id();
if (mModel.getIs_following().equalsIgnoreCase("0")) {
showUnFollowLocationDialog(customer_id, location_id, "1", mModel, type_location);
} else {
showUnFollowLocationDialog(customer_id, location_id, "0", mModel, type_location);
}
}
}
return false;
}
});
lstLocation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// MasMas.tracker().send(new HitBuilders.EventBuilder("L_"+alstSearchLocationFilter.get(i).getLocation_id(), "Location_Click")
// .setLabel("CM_" +cust_id)
// .build());
MasMas.getInstance().trackEvent("L_" + alstSearchLocationFilter.get(i).getLocation_id(), "Location Click", "CM_" + cust_id);
Intent mIntent = new Intent(DealsActivity.this, LocationDetailActivity.class);
Log.e("", "Location ID :::::" + alstSearchLocationFilter.get(i).getLocation_id());
mIntent.putExtra(Consts.LOCATION_ID, alstSearchLocationFilter.get(i).getLocation_id());
mIntent.putExtra("price_type", alstSearchLocationFilter.get(i).getPrice_type());
startActivity(mIntent);
}
});
}
@Override
protected void onResume() {
super.onResume();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
public void AddToWalletSevice(String customenr_id, String deal_id, final DealsModle mDealsModle) {
AddWalletAsynckTask mAddWalletAsynckTask = new AddWalletAsynckTask(DealsActivity.this);
mAddWalletAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "Add To wallet Response ::::::::" + result.toString());
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mDealsModle.getIsWallet().equalsIgnoreCase("0")) {
mDealsModle.setIsWallet("1");
} else {
mDealsModle.setIsWallet("0");
}
int pos = alstDeals.indexOf(mDealsModle);
alstDeals.set(pos, mDealsModle);
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.deals_success_msg), Toast.LENGTH_LONG).show();
// Utils.SimpleAlertMessage(mContext, mContext.getResources().getString(R.string.deals_success_msg));
}
mDealsAdapter.notifyDataSetChanged();
if (!Utils.checkInternetConnection(DealsActivity.this))
{
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
}
else {
if (type.equalsIgnoreCase(Consts.HOME)) {
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (alstNearBy.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstNearBy.size(); a++) {
alstSearchDealName.add(alstNearBy.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstNearBy, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
/// }
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// DealsLikeSevice("home", cust_id, cat_id, sub_cat_id,myLat,myLng);
// }
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
alstLike.clear();
for (int a = 0; a < alstDeals.size(); a++) {
if (alstDeals.get(a).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(a));
}
}
for (int a = 0; a < alstLike.size(); a++) {
alstSearchDealName.add(alstLike.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstLike, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
}
} else
{
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.deals_success_msg));
}
} catch (Exception e) {
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mAddWalletAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customenr_id, deal_id);
} else {
mAddWalletAsynckTask.execute(customenr_id, deal_id);
}
}
public void DeleteWalletSevice(Context mContext, String customenr_id, String deal_id, final DealsModle mDealsModle) {
DeleteWalletAsynckTask mDeleteWalletAsynckTask = new DeleteWalletAsynckTask(mContext);
mDeleteWalletAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mDealsModle.getIsWallet().equalsIgnoreCase("0")) {
mDealsModle.setIsWallet("1");
} else {
mDealsModle.setIsWallet("0");
}
int pos = alstDeals.indexOf(mDealsModle);
alstDeals.set(pos, mDealsModle);
}
mDealsAdapter.notifyDataSetChanged();
if (type.equalsIgnoreCase(Consts.HOME)) {
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (alstNearBy.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstNearBy.size(); a++) {
alstSearchDealName.add(alstNearBy.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
// }
} else if (type.equalsIgnoreCase("like")) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// DealsLikeSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng);
// }
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
alstLike.clear();
for (int a = 0; a < alstDeals.size(); a++) {
if (alstDeals.get(a).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(a));
}
}
for (int a = 0; a < alstLike.size(); a++) {
alstSearchDealName.add(alstLike.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstLike, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
}
} catch (Exception e) {
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDeleteWalletAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customenr_id, deal_id);
} else {
mDeleteWalletAsynckTask.execute(customenr_id, deal_id);
}
}
/**
* Function to show settings alert dialog.
* On pressing the Settings button it will launch Settings Options.
*/
public void showDeleteDealDialog(final Context mContext, final String customenr_id, final String deal_id, final DealsModle mDealsModle) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle(R.string.app_name);
alertDialog.setMessage(mContext.getResources().getString(R.string.are_u_sure_you_want_to_delete_deals));
alertDialog.setNegativeButton(mContext.getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton(mContext.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
DeleteWalletSevice(mContext, customenr_id, deal_id, mDealsModle);
}
});
alertDialog.show();
}
public void showUnFollowLocationDialog(final String customer_id, final String location_id, final String is_Following, final LocationModel mLocationModel, final String type) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle(R.string.app_name);
if (is_Following.equalsIgnoreCase("1")) {
alertDialog.setMessage(getResources().getString(R.string.are_u_sure_you_want_to_follow_this_location));
} else {
alertDialog.setMessage(getResources().getString(R.string.are_u_sure_you_want_to_unfollow_this_location));
}
alertDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
unFollow_Follow_Location(customer_id, location_id, is_Following, mLocationModel, type);
}
});
alertDialog.show();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.txtFilterbtn:
edt_search_deal.setText("");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Intent mFilterIntent = new Intent(this, FilterActivity.class);
startActivity(mFilterIntent);
finish();
} else {
Intent mFilterIntent = new Intent(this, FilterLocationActivity.class);
startActivity(mFilterIntent);
finish();
}
break;
case R.id.txtMapDeal:
edt_search_deal.setText("");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Intent mIntent = new Intent(DealsActivity.this, DealsMapActivity.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST", (Serializable) alstDeals);
mIntent.putExtra("BUNDLE", args);
startActivity(mIntent);
} else {
Intent mIntent = new Intent(DealsActivity.this, LocationMapActivity.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST_LOCATION", (Serializable) alstSearchLocationFilter);
// for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
// Log.e("Lat", "Lat:::" + alstSearchLocationFilter.get(i).getLatitude());
// Log.e("Lag", "Lag:::" + alstSearchLocationFilter.get(i).getLongitude());
// }
mIntent.putExtra("BUNDLE_LOCATION", args);
startActivity(mIntent);
}
break;
case R.id.imgDeals_menu:
edt_search_deal.setText("");
edt_search_deal.dismissDropDown();
drawerLayout.openDrawer(drawerView);
break;
case R.id.imgFilterClose:
Utils.storeString(Consts.SORT_FILTER, "deal_name");
lytFilter.setVisibility(View.GONE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
break;
case R.id.txtHome:
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.HOME);
islike = false;
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstDeals.clear();
alstDeals.addAll(alstHome);
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getDeal_name().compareTo(object2.getDeal_name());
}
});
alstSearchDealName.clear();
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
// Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
break;
case R.id.txtNearBy:
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.NEAR_BY);
islike = false;
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.header));
imgNearBy.setVisibility(View.VISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstDeals.clear();
alstDeals.addAll(alstNearBy);
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.NEAR_BY);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
lstLocation.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.header));
imgNearBy.setVisibility(View.VISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
// Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
break;
case R.id.txtLike:
if (isSkipNow) {
dialogSkipNow(this);
} else {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.LIKE);
islike = true;
edt_search_deal.setText("");
lytLocation.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.header));
imgLike.setVisibility(View.VISIBLE);
alstLike.clear();
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.FOLLOWING);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.header));
imgLike.setVisibility(View.VISIBLE);
alstSearchLocationName.clear();
alstLocatonFollowing.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("1")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
}
break;
case R.id.edt_search_deal:
if (islike) {
lytLocation.setVisibility(View.GONE);
} else {
lytLocation.setVisibility(View.VISIBLE);
}
break;
case R.id.btnDeals:
Utils.storeBoolean(Consts.IS_DEAL, true);
lytFilter.setVisibility(View.GONE);
txtLike.setText(getResources().getString(R.string.like));
dealVisible();
txtHeader_deals.setText(getResources().getString(R.string.deals));
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
break;
case R.id.btnLocation:
lytFilter.setVisibility(View.GONE);
Utils.storeBoolean(Consts.IS_DEAL, false);
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
txtHeader_deals.setText(getResources().getString(R.string.locations));
txtLike.setText(getResources().getString(R.string.profile_following_btn));
lstDeal.setVisibility(View.GONE);
locationVisible();
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
break;
case R.id.imgClose:
edt_search_deal.setText("");
lstDeal.setVisibility(View.VISIBLE);
if (edt_search_deal != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edt_search_deal.getWindowToken(), 0);
}
break;
default:
break;
}
}
private void locationVisible() {
lstDeal.setVisibility(View.GONE);
rlytLocation.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.VISIBLE);
edt_search_deal.setText("");
btnDeals.setBackgroundResource(R.drawable.ractangle_tab_left_normal);
btnDeals.setTextColor(getResources().getColor(R.color.black));
btnLocation.setBackgroundResource(R.drawable.ractangle_tab_right);
btnLocation.setTextColor(getResources().getColor(R.color.white));
rlytLocation.setVisibility(View.VISIBLE);
}
private void dealVisible() {
lstLocation.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
rlytLocation.setVisibility(View.GONE);
edt_search_deal.setText("");
btnDeals.setBackgroundResource(R.drawable.ractangle_tab_left);
btnDeals.setTextColor(getResources().getColor(R.color.white));
btnLocation.setBackgroundResource(R.drawable.ractangle_tab_right_normal);
btnLocation.setTextColor(getResources().getColor(R.color.black));
}
public void DealsSevice(final String deal_type, String cust_id, String cat_id, String sub_cat_id, String latitude, String longitude, String next_start) {
if (mDealsAsynckTask == null) {
mDealsAsynckTask = new DealsAsynckTask(this);
mDealsAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
mDealsAsynckTask = null;
if (result != null) {
try {
alstHome.clear();
alstNearBy.clear();
alstLike.clear();
alstDeals.clear();
alstLocation.clear();
alstLocationImages.clear();
// alstSearchLoaction.clear();
alstSearchDealName.clear();
alstSearchLocationName.clear();
alstSearchLocationFilter.clear();
DealsModle dealsModel = null;
LocationModel locationModel = null;
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
lstDeal.setVisibility(View.VISIBLE);
txtNoDeal.setVisibility(View.INVISIBLE);
alstDeals = new ArrayList<DealsModle>();
alstHome = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("home");
for (int i = 0; i < mJsonArray.length(); i++) {
dealsModel = new DealsModle();
JSONObject mData = mJsonArray.getJSONObject(i);
dealsModel.setDeal_id(mData.optString("deal_id"));
dealsModel.setM_fullname(mData.optString("m_fullname"));
dealsModel.setMerchant_id(mData.optString("merchant_id"));
dealsModel.setMaximum_redumption(mData.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mData.optString("merchant_user_id"));
dealsModel.setCategory_id(mData.optString("category_id"));
dealsModel.setDeal_name(mData.optString("deal_name"));
dealsModel.setDeal_desc(mData.optString("deal_desc"));
dealsModel.setStart_date(mData.optString("start_date"));
dealsModel.setEnd_date(mData.optString("end_date"));
dealsModel.setIs_active(mData.optString("is_active"));
dealsModel.setRate(mData.optString("rate"));
dealsModel.setComments(mData.optString("comments"));
dealsModel.setImage(mData.optString("image"));
dealsModel.setDeals_left(mData.optString("deals_left"));
dealsModel.setIsLike(mData.optString("is_liked"));
Log.e("", "LIKE::::::" + mData.optString("is_liked"));
dealsModel.setIsWallet(mData.optString("is_wallet"));
dealsModel.setPopularity_count(mData.optString("popularity_count"));
dealsModel.setDistanceKm(mData.optString("distance_in_km"));
JSONArray mLocationArray = mData.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
alstHome.add(dealsModel);
// alstNearBy.add(dealsModel);
}
alstNearBy = new ArrayList<DealsModle>();
JSONArray mJsonArrayNearBy = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayNearBy.length(); i++) {
dealsModel = new DealsModle();
JSONObject mDataNearBy = mJsonArrayNearBy.getJSONObject(i);
dealsModel.setDeal_id(mDataNearBy.optString("deal_id"));
dealsModel.setM_fullname(mDataNearBy.optString("m_fullname"));
dealsModel.setMerchant_id(mDataNearBy.optString("merchant_id"));
dealsModel.setMaximum_redumption(mDataNearBy.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mDataNearBy.optString("merchant_user_id"));
dealsModel.setCategory_id(mDataNearBy.optString("category_id"));
dealsModel.setDeal_name(mDataNearBy.optString("deal_name"));
dealsModel.setDeal_desc(mDataNearBy.optString("deal_desc"));
dealsModel.setStart_date(mDataNearBy.optString("start_date"));
dealsModel.setEnd_date(mDataNearBy.optString("end_date"));
dealsModel.setIs_active(mDataNearBy.optString("is_active"));
dealsModel.setRate(mDataNearBy.optString("rate"));
dealsModel.setComments(mDataNearBy.optString("comments"));
dealsModel.setImage(mDataNearBy.optString("image"));
dealsModel.setDeals_left(mDataNearBy.optString("deals_left"));
dealsModel.setIsLike(mDataNearBy.optString("is_liked"));
Log.e("", "LIKE::::::" + mDataNearBy.optString("is_liked"));
dealsModel.setIsWallet(mDataNearBy.optString("is_wallet"));
dealsModel.setPopularity_count(mDataNearBy.optString("popularity_count"));
dealsModel.setDistanceKm(mDataNearBy.optString("distance_in_km"));
JSONArray mLocationArray = mDataNearBy.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
// alstHome.add(dealsModel);
alstNearBy.add(dealsModel);
}
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
//sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else if (strStatus.equalsIgnoreCase("2")) {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDealsAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
} else {
mDealsAsynckTask.execute(deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
}
}
}
public void DealsSevice_loadmore(final String deal_type, String cust_id, String cat_id, String sub_cat_id, String latitude, String longitude, String next_start) {
mDealsAsynckTask_loadmore = new DealsAsynckTask_loadmore(this);
mDealsAsynckTask_loadmore.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
lstDeal.stopLoadMore();
lstDeal.stopRefresh();
if (result != null) {
try {
DealsModle dealsModel = null;
LocationModel locationModel = null;
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
// alstDeals = new ArrayList<DealsModle>();
//alstHome = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("home");
for (int i = 0; i < mJsonArray.length(); i++) {
dealsModel = new DealsModle();
JSONObject mData = mJsonArray.getJSONObject(i);
dealsModel.setDeal_id(mData.optString("deal_id"));
dealsModel.setM_fullname(mData.optString("m_fullname"));
dealsModel.setMerchant_id(mData.optString("merchant_id"));
dealsModel.setMaximum_redumption(mData.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mData.optString("merchant_user_id"));
dealsModel.setCategory_id(mData.optString("category_id"));
dealsModel.setDeal_name(mData.optString("deal_name"));
dealsModel.setDeal_desc(mData.optString("deal_desc"));
dealsModel.setStart_date(mData.optString("start_date"));
dealsModel.setEnd_date(mData.optString("end_date"));
dealsModel.setIs_active(mData.optString("is_active"));
dealsModel.setRate(mData.optString("rate"));
dealsModel.setComments(mData.optString("comments"));
dealsModel.setImage(mData.optString("image"));
dealsModel.setDeals_left(mData.optString("deals_left"));
dealsModel.setIsLike(mData.optString("is_liked"));
Log.e("", "LIKE::::::" + mData.optString("is_liked"));
dealsModel.setIsWallet(mData.optString("is_wallet"));
dealsModel.setPopularity_count(mData.optString("popularity_count"));
dealsModel.setDistanceKm(mData.optString("distance_in_km"));
JSONArray mLocationArray = mData.optJSONArray("locations");
// alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
alstHome.add(dealsModel);
// alstNearBy.add(dealsModel);
}
alstNearBy = new ArrayList<DealsModle>();
JSONArray mJsonArrayNearBy = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayNearBy.length(); i++) {
dealsModel = new DealsModle();
JSONObject mDataNearBy = mJsonArrayNearBy.getJSONObject(i);
dealsModel.setDeal_id(mDataNearBy.optString("deal_id"));
dealsModel.setM_fullname(mDataNearBy.optString("m_fullname"));
dealsModel.setMerchant_id(mDataNearBy.optString("merchant_id"));
dealsModel.setMaximum_redumption(mDataNearBy.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mDataNearBy.optString("merchant_user_id"));
dealsModel.setCategory_id(mDataNearBy.optString("category_id"));
dealsModel.setDeal_name(mDataNearBy.optString("deal_name"));
dealsModel.setDeal_desc(mDataNearBy.optString("deal_desc"));
dealsModel.setStart_date(mDataNearBy.optString("start_date"));
dealsModel.setEnd_date(mDataNearBy.optString("end_date"));
dealsModel.setIs_active(mDataNearBy.optString("is_active"));
dealsModel.setRate(mDataNearBy.optString("rate"));
dealsModel.setComments(mDataNearBy.optString("comments"));
dealsModel.setImage(mDataNearBy.optString("image"));
dealsModel.setDeals_left(mDataNearBy.optString("deals_left"));
dealsModel.setIsLike(mDataNearBy.optString("is_liked"));
Log.e("", "LIKE::::::" + mDataNearBy.optString("is_liked"));
dealsModel.setIsWallet(mDataNearBy.optString("is_wallet"));
dealsModel.setPopularity_count(mDataNearBy.optString("popularity_count"));
dealsModel.setDistanceKm(mDataNearBy.optString("distance_in_km"));
JSONArray mLocationArray = mDataNearBy.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
// alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
// alstHome.add(dealsModel);
alstNearBy.add(dealsModel);
}
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
//sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
//mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
mDealsAdapter.notifyDataSetChanged();
// lstDeal.setAdapter(mDealsAdapter);
}
}
else
{
lstDeal.hide_layout();
mDealsAdapter.notifyDataSetChanged();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDealsAsynckTask_loadmore.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
} else {
mDealsAsynckTask_loadmore.execute(deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
}
}
private boolean isDuplicate(LocationModel locationModel) {
if (locationModel != null) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (locationModel.getLocation_id().equalsIgnoreCase(alstSearchLocationFilter.get(i).getLocation_id())) {
return true;
}
}
}
return false;
}
public void GetAllLocation(String customer_id, String location_type,String cat_id,String sub_cat_id ,String c_latitude, String c_longitude, String next_start) {
if (mGetAllLocationAsynckTask == null) {
mGetAllLocationAsynckTask = new GetAllLocationAsynckTask(this);
mGetAllLocationAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
mGetAllLocationAsynckTask = null;
if (result != null) {
Log.e("result", "Location result::::::::" + result.toString());
try {
alstLocatonHome.clear();
alstLocatonNearBy.clear();
alstLocatonFollowing.clear();
locationModel = null;
alstSearchLocationFilter.clear();
alstLocationImages.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextLocationStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
JSONArray mLocationArray = mJsonResponse.getJSONArray("home");
txtNoDeal.setVisibility(View.GONE);
lstLocation.setVisibility(View.VISIBLE);
alstLocatonHome = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setCity(mLocationObj.optString("city"));
locationModel.setState(mLocationObj.optString("state"));
locationModel.setCountry(mLocationObj.optString("country"));
locationModel.setZipcode(mLocationObj.optString("zipcode"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setTags(mLocationObj.optString("tags"));
locationModel.setEmail(mLocationObj.optString("email"));
locationModel.setWebsite(mLocationObj.optString("website"));
locationModel.setDisp_attire(mLocationObj.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObj.optString("is_deleted"));
locationModel.setCreated(mLocationObj.optString("created"));
locationModel.setAvg_rate(mLocationObj.optString("avg_rate"));
locationModel.setCity_name(mLocationObj.optString("city_name"));
locationModel.setDistance_in_km(mLocationObj.optString("distance_in_km"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
locationModel.setIs_following(mLocationObj.optString("is_following"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
alstLocatonHome.add(locationModel);
//alstLocatonNearBy.add(locationModel);
}
JSONArray mLocationNearBy = mJsonResponse.getJSONArray("data");
if (mLocationNearBy != null) {
if (mLocationNearBy.length() > 0) {
alstLocatonNearBy = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationNearBy.length(); j++) {
JSONObject mLocationObjNearBy = mLocationNearBy.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObjNearBy.optString("location_id"));
locationModel.setLocation_name(mLocationObjNearBy.optString("location_name"));
locationModel.setLocation_desc(mLocationObjNearBy.optString("location_desc"));
locationModel.setLatitude(mLocationObjNearBy.optString("latitude"));
locationModel.setLongitude(mLocationObjNearBy.optString("longitude"));
locationModel.setContact(mLocationObjNearBy.optString("contact"));
locationModel.setAddress1(mLocationObjNearBy.optString("address1"));
locationModel.setAddress2(mLocationObjNearBy.optString("address2"));
locationModel.setLocation_timing(mLocationObjNearBy.optString("location_timing"));
locationModel.setCity(mLocationObjNearBy.optString("city"));
locationModel.setState(mLocationObjNearBy.optString("state"));
locationModel.setCountry(mLocationObjNearBy.optString("country"));
locationModel.setZipcode(mLocationObjNearBy.optString("zipcode"));
locationModel.setPrice_type(mLocationObjNearBy.optString("price_type"));
locationModel.setTags(mLocationObjNearBy.optString("tags"));
locationModel.setEmail(mLocationObjNearBy.optString("email"));
locationModel.setWebsite(mLocationObjNearBy.optString("website"));
locationModel.setDisp_attire(mLocationObjNearBy.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObjNearBy.optString("is_deleted"));
locationModel.setCreated(mLocationObjNearBy.optString("created"));
locationModel.setAvg_rate(mLocationObjNearBy.optString("avg_rate"));
locationModel.setCity_name(mLocationObjNearBy.optString("city_name"));
locationModel.setDistance_in_km(mLocationObjNearBy.optString("distance_in_km"));
locationModel.setRate(mLocationObjNearBy.optString("rate"));
locationModel.setComments(mLocationObjNearBy.optString("comments"));
locationModel.setIs_following(mLocationObjNearBy.optString("is_following"));
JSONArray locationImageNearBy = mLocationObjNearBy.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImageNearBy != null) {
if (locationImageNearBy.length() > 0) {
for (int k = 0; k < locationImageNearBy.length(); k++) {
JSONObject mlocationImageObj1 = locationImageNearBy.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj1.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// alstLocatonHome.add(locationModel);
alstLocatonNearBy.add(locationModel);
}
}
}
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
// if (alstSearchLocationFilter.size() > 0) {
// Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
// @Override
// public int compare(final LocationModel object1, final LocationModel object2) {
// return object1.getLocation_name().compareTo(object2.getLocation_name());
// }
// });
// }
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (!alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("0")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
lstLocation.setVisibility(View.GONE);
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
lstLocation.setVisibility(View.GONE);
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.no_location_found), Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.e("Lat", "Lat:::" + c_latitude);
Log.e("Long", "Long:::" + c_longitude);
mGetAllLocationAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customer_id, location_type, cat_id,sub_cat_id,c_latitude, c_longitude, next_start);
} else {
mGetAllLocationAsynckTask.execute(customer_id, location_type,cat_id,sub_cat_id,c_latitude, c_longitude, next_start);
}
}
}
public void GetAllLocation_loadmore(String customer_id, String location_type,String cat_id ,String sub_cat_id,String c_latitude, String c_longitude, String next_start) {
mGetAllLocationAsynckTask_loadmore = new GetAllLocationAsynckTask_loadMore(this);
mGetAllLocationAsynckTask_loadmore.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response)
{
}
@Override
public void onResponseReceived(String result) {
lstLocation.stopRefresh();
lstLocation.stopLoadMore();
if (result != null) {
try {
JSONObject mJsonResult = new JSONObject(result);
// lstLocation.hide_layout();
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextLocationStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
JSONArray mLocationArray = mJsonResponse.getJSONArray("home");
//alstLocatonHome = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setCity(mLocationObj.optString("city"));
locationModel.setState(mLocationObj.optString("state"));
locationModel.setCountry(mLocationObj.optString("country"));
locationModel.setZipcode(mLocationObj.optString("zipcode"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setTags(mLocationObj.optString("tags"));
locationModel.setEmail(mLocationObj.optString("email"));
locationModel.setWebsite(mLocationObj.optString("website"));
locationModel.setDisp_attire(mLocationObj.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObj.optString("is_deleted"));
locationModel.setCreated(mLocationObj.optString("created"));
locationModel.setAvg_rate(mLocationObj.optString("avg_rate"));
locationModel.setCity_name(mLocationObj.optString("city_name"));
locationModel.setDistance_in_km(mLocationObj.optString("distance_in_km"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
locationModel.setIs_following(mLocationObj.optString("is_following"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
alstLocatonHome.add(locationModel);
//alstLocatonNearBy.add(locationModel);
}
JSONArray mLocationNearBy = mJsonResponse.getJSONArray("data");
if (mLocationNearBy != null) {
if (mLocationNearBy.length() > 0) {
alstLocatonNearBy = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationNearBy.length(); j++) {
JSONObject mLocationObjNearBy = mLocationNearBy.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObjNearBy.optString("location_id"));
locationModel.setLocation_name(mLocationObjNearBy.optString("location_name"));
locationModel.setLocation_desc(mLocationObjNearBy.optString("location_desc"));
locationModel.setLatitude(mLocationObjNearBy.optString("latitude"));
locationModel.setLongitude(mLocationObjNearBy.optString("longitude"));
locationModel.setContact(mLocationObjNearBy.optString("contact"));
locationModel.setAddress1(mLocationObjNearBy.optString("address1"));
locationModel.setAddress2(mLocationObjNearBy.optString("address2"));
locationModel.setLocation_timing(mLocationObjNearBy.optString("location_timing"));
locationModel.setCity(mLocationObjNearBy.optString("city"));
locationModel.setState(mLocationObjNearBy.optString("state"));
locationModel.setCountry(mLocationObjNearBy.optString("country"));
locationModel.setZipcode(mLocationObjNearBy.optString("zipcode"));
locationModel.setPrice_type(mLocationObjNearBy.optString("price_type"));
locationModel.setTags(mLocationObjNearBy.optString("tags"));
locationModel.setEmail(mLocationObjNearBy.optString("email"));
locationModel.setWebsite(mLocationObjNearBy.optString("website"));
locationModel.setDisp_attire(mLocationObjNearBy.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObjNearBy.optString("is_deleted"));
locationModel.setCreated(mLocationObjNearBy.optString("created"));
locationModel.setAvg_rate(mLocationObjNearBy.optString("avg_rate"));
locationModel.setCity_name(mLocationObjNearBy.optString("city_name"));
locationModel.setDistance_in_km(mLocationObjNearBy.optString("distance_in_km"));
locationModel.setRate(mLocationObjNearBy.optString("rate"));
locationModel.setComments(mLocationObjNearBy.optString("comments"));
locationModel.setIs_following(mLocationObjNearBy.optString("is_following"));
JSONArray locationImageNearBy = mLocationObjNearBy.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImageNearBy != null) {
if (locationImageNearBy.length() > 0) {
for (int k = 0; k < locationImageNearBy.length(); k++) {
JSONObject mlocationImageObj1 = locationImageNearBy.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj1.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// alstLocatonHome.add(locationModel);
alstLocatonNearBy.add(locationModel);
}
}
}
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
// if (alstSearchLocationFilter.size() > 0) {
// Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
// @Override
// public int compare(final LocationModel object1, final LocationModel object2) {
// return object1.getLocation_name().compareTo(object2.getLocation_name());
// }
// });
// }
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++)
{
if (!alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("0")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
//mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
// lstLocation.setAdapter(mSearchLocationAdapter);
mSearchLocationAdapter.notifyDataSetChanged();
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
}
}
else
{
lstLocation.hide_layout();
mSearchLocationAdapter.notifyDataSetChanged();
}
}
} catch (JSONException e)
{
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.e("Lat", "Lat:::" + c_latitude);
Log.e("Long", "Long:::" + c_longitude);
mGetAllLocationAsynckTask_loadmore.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customer_id,cat_id,sub_cat_id,location_type, c_latitude, c_longitude, next_start);
} else {
mGetAllLocationAsynckTask_loadmore.execute(customer_id, location_type,cat_id,sub_cat_id, c_latitude, c_longitude, next_start);
}
}
public void unFollow_Follow_Location(final String cust_id, String location_id, final String is_following, final LocationModel mLocationModel, final String location_type) {
FollowUnFollowLocationAsyncTask mFollowUnFollowAsyncTask = new FollowUnFollowLocationAsyncTask(this);
mFollowUnFollowAsyncTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mLocationModel.getIs_following().equalsIgnoreCase("0")) {
// mLocationModel.setIs_following("1");
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.you_have_follow_this_location), Toast.LENGTH_LONG).show();
} else {
// mLocationModel.setIs_following("0");
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.you_have_unfollow_this_location), Toast.LENGTH_LONG).show();
}
// int pos = alstSearchLocationFilter.indexOf(mLocationModel);
// alstSearchLocationFilter.set(pos, mLocationModel);
// mSearchLocationAdapter.notifyDataSetChanged();
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (location_type.equalsIgnoreCase(Consts.HOME))
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
else if (location_type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
else if (location_type.equalsIgnoreCase(Consts.FOLLOWING)) {
mLocationModel.setIs_following("0");
// int follow_pos = alstSearchLocationFilter.indexOf(mLocationModel);
alstSearchLocationFilter.remove(mLocationModel);
mSearchLocationAdapter.notifyDataSetChanged();
if (alstSearchLocationFilter.size() <= 0) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
}
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
// Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.please_try_again), Toast.LENGTH_LONG).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mFollowUnFollowAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cust_id, location_id, is_following);
} else {
mFollowUnFollowAsyncTask.execute(cust_id, location_id, is_following);
}
}
public void FollowingLocation(String cust_id) {
LocationFollowingAsyncTask mFollowingsAsynckTask = new LocationFollowingAsyncTask(this);
mFollowingsAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
alstSearchLocationFilter.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
txtNoDeal.setVisibility(View.GONE);
alstSearchLocationFilter = new ArrayList<LocationModel>();
JSONArray mJsonArrayLocation = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayLocation.length(); i++) {
locationModel = new LocationModel();
JSONObject mLocationData = mJsonArrayLocation.getJSONObject(i);
locationModel.setLocation_id(mLocationData.optString("location_id"));
locationModel.setLocation_name(mLocationData.optString("location_name"));
locationModel.setLocation_desc(mLocationData.optString("mLocationData"));
locationModel.setAddress1(mLocationData.optString("address1"));
locationModel.setFollower_id(mLocationData.optString("follower_id"));
locationModel.setIs_following(mLocationData.optString("is_following"));
locationModel.setIs_block(mLocationData.optString("is_block"));
locationModel.setComments(mLocationData.optString("comments"));
locationModel.setRate(mLocationData.optString("rate"));
locationModel.setImage(mLocationData.optString("image"));
alstSearchLocationFilter.add(locationModel);
// strLocationCount = String.valueOf(mJsonArrayLocation.length());
}
// txtLocation.setText(getResources().getString(R.string.you_are_following) + " " + strLocationCount + " " + getResources().getString(R.string.locations));
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mFollowingsAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cust_id);
} else {
mFollowingsAsynckTask.execute(cust_id);
}
}
public void GetAllCategories() {
GetCategoriesAsynckTask mGetCategoriesAsynckTask = new GetCategoriesAsynckTask(this);
mGetCategoriesAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
CategoryModel mCategoryModel = null;
SubCategoriesModel mSubCategoriesModel = null;
alstCategory.clear();
alstMoreCategories.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
alstCategory = new ArrayList<CategoryModel>();
alstMoreCategories = new ArrayList<CategoryModel>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("data");
if (mJsonArray != null) {
for (int i = 0; i < mJsonArray.length() + 1; i++) {
if (i == 0) {
mCategoryModel = new CategoryModel();
//JSONObject mData = mJsonArray.optJSONObject(i);
mCategoryModel.setCatId("0");
mCategoryModel.setCatName(getResources().getString(R.string.all));
mCategoryModel.setCatImage("");
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstCategory.add(mCategoryModel);
alstMoreCategories.add(mCategoryModel);
alstSubCategory = new ArrayList<SubCategoriesModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
hashmapSubCategory.put("0", alstSubCategory);
hashmapMoreSubCategories.put("0", alstMoreSubCategories);
} else if (i < 5) {
mCategoryModel = new CategoryModel();
JSONObject mData = mJsonArray.optJSONObject(i - 1);
mCategoryModel.setCatId(mData.optString("category_id"));
mCategoryModel.setCatName(mData.optString("category_name"));
mCategoryModel.setCatImage(mData.optString("image"));
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstCategory.add(mCategoryModel);
alstMoreCategories.add(mCategoryModel);
JSONArray mSubArray = mData.optJSONArray("subcategories");
alstSubCategory = new ArrayList<SubCategoriesModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
if (mSubArray != null) {
if (mSubArray.length() > 0) {
for (int j = 0; j < mSubArray.length(); j++) {
mSubCategoriesModel = new SubCategoriesModel();
JSONObject mSubObj = mSubArray.optJSONObject(j);
mSubCategoriesModel.setStrSubCatId(mSubObj.optString("category_id"));
mSubCategoriesModel.setStrSubCatName(mSubObj.optString("category_name"));
mSubCategoriesModel.setStrSubCatImage(mSubObj.optString("image"));
mSubCategoriesModel.setIsChecked(false);
alstSubCategory.add(mSubCategoriesModel);
alstMoreSubCategories.add(mSubCategoriesModel);
}
// mCategoryModel.setAlstSubCat(alstSubCategory);
}
}
hashmapSubCategory.put(mData.optString("category_id"), alstSubCategory);
hashmapMoreSubCategories.put(mData.optString("category_id"), alstMoreSubCategories);
}
// else if (i == 5) {
// mCategoryModel = new CategoryModel();
// //JSONObject mData = mJsonArray.optJSONObject(i);
// mCategoryModel.setCatId("-1");
// mCategoryModel.setCatName(getResources().getString(R.string.more_categories));
// mCategoryModel.setCatImage("");
// mCategoryModel.setIsChecked(false);
// mCategoryModel.setIsChildChecked(false);
// alstCategory.add(mCategoryModel);
// alstSubCategory = new ArrayList<SubCategoriesModel>();
// hashmapSubCategory.put("-1", alstSubCategory);
else {
mCategoryModel = new CategoryModel();
JSONObject mData = mJsonArray.optJSONObject(i - 1);
mCategoryModel.setCatId(mData.optString("category_id"));
mCategoryModel.setCatName(mData.optString("category_name"));
mCategoryModel.setCatImage(mData.optString("image"));
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstMoreCategories.add(mCategoryModel);
JSONArray mSubArray = mData.optJSONArray("subcategories");
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
if (mSubArray != null) {
if (mSubArray.length() > 0) {
for (int j = 0; j < mSubArray.length(); j++) {
mSubCategoriesModel = new SubCategoriesModel();
JSONObject mSubObj = mSubArray.optJSONObject(j);
mSubCategoriesModel.setStrSubCatId(mSubObj.optString("category_id"));
mSubCategoriesModel.setStrSubCatName(mSubObj.optString("category_name"));
mSubCategoriesModel.setStrSubCatImage(mSubObj.optString("image"));
mSubCategoriesModel.setIsChecked(false);
alstMoreSubCategories.add(mSubCategoriesModel);
}
// mCategoryModel.setAlstSubCat(alstSubCategory);
}
}
hashmapMoreSubCategories.put(mData.optString("category_id"), alstMoreSubCategories);
}
}
//
// for (int i = 0; i < alstCategory.size(); i++) {
// Log.e("", "Category:::::" + alstCategory.get(i).getCatName());
// }
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setVisibility(View.VISIBLE);
drawerView = (ViewDrawer) findViewById(R.id.drawer);
drawerView.setVisibility(View.VISIBLE);
mOnUpdateListner = (onUpdateListner) drawerView;
mOnUpdateListner.onUpdate();
inItData();
}
}
else
{
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mGetCategoriesAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
mGetCategoriesAsynckTask.execute();
}
}
public void dialogSkipNow(Context context) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(getResources().getString(R.string.app_name));
alertDialogBuilder
.setMessage(getResources().getString(R.string.you_have_not_register_yet))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.register_now), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
Intent intent = new Intent(DealsActivity.this, RegistrationActivity.class);
startActivity(intent);
finish();
}
})
.setNegativeButton(getResources().getString(R.string.register_later), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
// Utils.storeString(Consts.USER_ID, "");
// Utils.storeString(Consts.CUSTOMER_ID, "");
// Utils.storeString(Consts.USER_NAME, "");
// Utils.storeString(Consts.USER_EMAIL, "");
// Utils.storeString(Consts.PROFILE_PIC_URL, "");
// Utils.storeString(Consts.COVER_PIC_URL, "");
Utils.storeBoolean(Consts.SKIP_NOW, true);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return false;
}
return super.onKeyDown(keyCode, event);
}
public void sortDealData(String strSort) {
if (Utils.validateString(strSort)) {
if (alstDeals.size() > 0) {
if (strSort.equalsIgnoreCase("deal_id")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getStart_date().compareTo(object2.getStart_date());
}
});
} else if (strSort.equalsIgnoreCase("deal_name")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getDeal_name().compareTo(object2.getDeal_name());
}
});
} else if (strSort.equalsIgnoreCase("comments")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getPopularity_count().compareTo(object2.getPopularity_count());
}
});
}
}
}
}
public void callLogin(String strUserEmail, String strUserPass) {
ReturnResult retrunResultObj = new ReturnResult() {
@Override
public void resultData(Object object, String tag) {
if (object != null) {
try {
JSONObject jObj = (JSONObject) object;
JSONObject response = jObj.getJSONObject("response");
String status = response.getString("status");
if (status != null) {
if (status.equalsIgnoreCase("1")) {
Utils.storeString(Consts.USER_ID, response.getString("user_id"));
Utils.storeString(Consts.CUSTOMER_ID, response.getString("customer_id"));
Utils.storeString(Consts.USER_NAME, response.getString("full_name"));
Utils.storeString(Consts.USER_EMAIL, response.getString("email"));
Utils.storeString(Consts.PROFILE_PIC_URL, response.getString("profile_image"));
Utils.storeString(Consts.COVER_PIC_URL, response.getString("cover_image"));
Utils.storeBoolean(Consts.SKIP_NOW, false);
Utils.storeBoolean(Consts.IS_LOGIN, true);
} else if (status.equalsIgnoreCase("2")) {
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.email_validation), Toast.LENGTH_SHORT).show();
} else if (status.equalsIgnoreCase("-4"))
AlertMessageLogin(getString(R.string.your_account_has_been_blocked_please_contact_masmas));
else if (status.equalsIgnoreCase("-5"))
AlertMessageLogin(getString(R.string.your_account_has_been_deleted_from_database));
}
//else
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.please_try_again), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
} else {
// Toast.makeText(DealsActivity.this, getString(R.string.please_try_again), Toast.LENGTH_LONG).show();
}
}
};
List<NameValuePair> nameValuePairsParams = new ArrayList<NameValuePair>();
nameValuePairsParams.add(new BasicNameValuePair("email", strUserEmail));
nameValuePairsParams.add(new BasicNameValuePair("password", strUserPass));
nameValuePairsParams.add(new BasicNameValuePair("device_token", "yrr"));
nameValuePairsParams.add(new BasicNameValuePair("ut_id", "2"));
if (new NetworkConnection().checkInternetConnection(this)) {
new PostDataAsync(DealsActivity.this, retrunResultObj, Consts.BASE_URL + "Customer/Login", nameValuePairsParams, "login").execute();
} else {
Toast.makeText(DealsActivity.this, getString(R.string.internet_problem), Toast.LENGTH_LONG).show();
}
}
public void AlertMessageLogin(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg);
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Utils.storeBoolean(Consts.IS_LOGIN, false);
Intent mIntent = new Intent(DealsActivity.this, LoginActivity.class);
startActivity(mIntent);
finish();
}
});
AlertDialog alert11 = builder.show();
alert11.show();
}
@Override
public void onRefresh()
{
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if(isDeal)
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice_loadmore("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
else
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation_loadmore(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
}
}, 2000);
}
@Override
public void onLoadMore() {
{
mHandler.postDelayed(new Runnable() {
@Override
public void run()
{
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if(isDeal)
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, sub_cat_id, myLat,myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice_loadmore("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
else
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation_loadmore(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
}
}, 2000);
}
}
}
package com.bluegreen.masmas.customer.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bluegreen.masmas.customer.AsyncTask.AddWalletAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.AsyncCallListener;
import com.bluegreen.masmas.customer.AsyncTask.DealsAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.DealsAsynckTask_loadmore;
import com.bluegreen.masmas.customer.AsyncTask.DeleteWalletAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.FollowUnFollowLocationAsyncTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllLocationAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllLocationAsynckTask_loadMore;
import com.bluegreen.masmas.customer.AsyncTask.GetCategoriesAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.LocationFollowingAsyncTask;
import com.bluegreen.masmas.customer.AsyncTask.PostDataAsync;
import com.bluegreen.masmas.customer.AsyncTask.ReturnResult;
import com.bluegreen.masmas.customer.R;
import com.bluegreen.masmas.customer.Utility.Consts;
import com.bluegreen.masmas.customer.Utility.GPSTracker;
import com.bluegreen.masmas.customer.Utility.LanguageChange;
import com.bluegreen.masmas.customer.Utility.MasMas;
import com.bluegreen.masmas.customer.Utility.NetworkConnection;
import com.bluegreen.masmas.customer.Utility.Utils;
import com.bluegreen.masmas.customer.adapter.DealsAdapter;
import com.bluegreen.masmas.customer.adapter.SearchLocationAdapter;
import com.bluegreen.masmas.customer.model.CategoryModel;
import com.bluegreen.masmas.customer.model.DealDetailImagesModel;
import com.bluegreen.masmas.customer.model.DealsModle;
import com.bluegreen.masmas.customer.model.LocationModel;
import com.bluegreen.masmas.customer.model.SubCategoriesModel;
import com.bluegreen.masmas.customer.navigation.ViewDrawer;
import com.bluegreen.masmas.customer.navigation.onUpdateListner;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenu;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuCreator;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuItem;
import com.bluegreen.masmas.customer.swipmenulistview.SwipeMenuListView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
/**
* Created by Manisha on 08/09/2015.
*/
public class DealsActivity extends Activity implements View.OnClickListener,SwipeMenuListView.IXListViewListener {
private ImageView imgDeals_menu;
private TextView txtHeader_deals, txtFilterbtn, txtMapDeal;
DrawerLayout drawerLayout;
ViewDrawer drawerView;
private SwipeMenuListView lstDeal;
private SwipeMenuListView lstLocation;
private DealsAdapter mDealsAdapter;
private String cust_id = "";
private boolean isFromMenu = false;
private TextView txtHome, txtNearBy, txtLike;
private ImageView imgHome, imgNearBy, imgLike, imgClose, imgFilterClose;
private String myLat = "", myLng = "";
private String type = Consts.HOME;
private String type_location = Consts.HOME;
private AutoCompleteTextView edt_search_deal;
private ArrayList<DealsModle> alstDeals;
private ArrayList<DealsModle> alstHome;
private ArrayList<DealsModle> alstNearBy;
private ArrayList<DealsModle> alstLike;
private ArrayList<LocationModel> alstLocation;
private ArrayList<LocationModel> alstLocatonHome;
private ArrayList<LocationModel> alstLocatonNearBy;
private ArrayList<LocationModel> alstLocatonFollowing;
private DealDetailImagesModel mDealDetailImagesModel;
private ArrayList<DealDetailImagesModel> alstLocationImages;
private SearchLocationAdapter mSearchLocationAdapter;
private TextView btnDeals, btnLocation;
private RelativeLayout rlytLocation;
public Boolean isDeal = false;
private ArrayList<LocationModel> alstSearchLocationFilter;
public boolean islike = false;
private TextView txtNoDeal, txtFilterText;
private ArrayAdapter<String> aadpDeal;
private ArrayList<String> alstSearchDealName;
private ArrayList<String> alstSearchLocationName;
private LinearLayout lytLocation, lytFilter;
private boolean isSkipNow = false;
private String cat_id = "0", sub_cat_id = "0";
private LocationModel locationModel;
public static HashMap<String, List<SubCategoriesModel>> hashmapSubCategory, hashmapMoreSubCategories;
public static ArrayList<CategoryModel> alstCategory, alstMoreCategories;
public static ArrayList<SubCategoriesModel> alstSubCategory, alstMoreSubCategories;
private onUpdateListner mOnUpdateListner;
private Boolean is_first = false;
private String strSort = "";
private String strUserEmail, strUserPass;
public DealsAsynckTask mDealsAsynckTask = null;
public DealsAsynckTask_loadmore mDealsAsynckTask_loadmore = null;
public GetAllLocationAsynckTask mGetAllLocationAsynckTask = null;
GetAllLocationAsynckTask_loadMore mGetAllLocationAsynckTask_loadmore=null;
private ArrayList<LocationModel> alstMapLocation;
EditText dummyEditTextFocus;
String nextLocationStart="0";
String nextStart="0";
private Handler mHandler;
//c creatorFollow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, Context.MODE_MULTI_PROCESS);
boolean is_login = Utils.sharedPreferences.getBoolean(Consts.IS_LOGIN, false);
String language = Utils.sharedPreferences.getString(Consts.LANGUAGE, Consts.SPANISH);
if (Utils.validateString(language)) {
LanguageChange.setlanguage(this, language);
}
setContentView(R.layout.activity_deals_dashboard);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.header));
}
// Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, MODE_PRIVATE);
is_first = Utils.sharedPreferences.getBoolean(Consts.IS_FIRST, false);
strUserEmail = Utils.sharedPreferences.getString(Consts.USER_EMAIL, "");
strUserPass = Utils.sharedPreferences.getString(Consts.PASSWORD, "");
alstMapLocation = new ArrayList<LocationModel>();
Utils.storeString(Consts.TYPE, Consts.HOME);
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
Log.e("", "is_first::::" + is_first);
if (is_login)
{
callLogin(strUserEmail, strUserPass);
}
if (is_first) {
inItData();
} else {
Utils.storeBoolean(Consts.IS_FIRST, true);
inItDrawerData();
GetAllCategories();
}
}
// msg : categories for locations are coming soon.
public void inItDrawerData() {
alstCategory = new ArrayList<CategoryModel>();
alstSubCategory = new ArrayList<SubCategoriesModel>();
hashmapSubCategory = new HashMap<String, List<SubCategoriesModel>>();
alstMoreCategories = new ArrayList<CategoryModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
hashmapMoreSubCategories = new HashMap<String, List<SubCategoriesModel>>();
}
public void inItData() {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
GPSTracker gps = new GPSTracker(this);
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
strSort = Utils.sharedPreferences.getString(Consts.SORT_FILTER, "");
isSkipNow = Utils.sharedPreferences.getBoolean(Consts.SKIP_NOW, false);
cust_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
imgDeals_menu = (ImageView) findViewById(R.id.imgDeals_menu);
imgDeals_menu.setOnClickListener(this);
txtHeader_deals = (TextView) findViewById(R.id.txtHeader_deals);
if (Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false)) {
txtHeader_deals.setText(getResources().getString(R.string.deals));
} else {
txtHeader_deals.setText(getResources().getString(R.string.locations));
}
dummyEditTextFocus = (EditText) findViewById(R.id.dummyEditTextFocus);
dummyEditTextFocus.requestFocus();
txtFilterbtn = (TextView) findViewById(R.id.txtFilterbtn);
txtFilterbtn.setOnClickListener(this);
txtNoDeal = (TextView) findViewById(R.id.txtNoDeal);
txtMapDeal = (TextView) findViewById(R.id.txtMapDeal);
txtMapDeal.setOnClickListener(this);
txtHome = (TextView) findViewById(R.id.txtHome);
txtHome.setOnClickListener(this);
txtNearBy = (TextView) findViewById(R.id.txtNearBy);
txtNearBy.setOnClickListener(this);
txtLike = (TextView) findViewById(R.id.txtLike);
txtLike.setOnClickListener(this);
lytLocation = (LinearLayout) findViewById(R.id.lytLocation);
lytLocation.setVisibility(View.VISIBLE);
lstLocation = (SwipeMenuListView) findViewById(R.id.lstLocation);
rlytLocation = (RelativeLayout) findViewById(R.id.rlytLocation);
rlytLocation.setVisibility(View.GONE);
btnDeals = (TextView) findViewById(R.id.btnDeals);
btnDeals.setOnClickListener(this);
btnLocation = (TextView) findViewById(R.id.btnLocation);
btnLocation.setOnClickListener(this);
imgHome = (ImageView) findViewById(R.id.imgHome);
imgNearBy = (ImageView) findViewById(R.id.imgNearBy);
imgLike = (ImageView) findViewById(R.id.imgLike);
imgClose = (ImageView) findViewById(R.id.imgClose);
imgClose.setOnClickListener(this);
lytFilter = (LinearLayout) findViewById(R.id.lytFilter);
imgFilterClose = (ImageView) findViewById(R.id.imgFilterClose);
imgFilterClose.setOnClickListener(this);
txtFilterText = (TextView) findViewById(R.id.txtFilterText);
alstDeals = new ArrayList<DealsModle>();
alstHome = new ArrayList<DealsModle>();
alstNearBy = new ArrayList<DealsModle>();
alstLike = new ArrayList<DealsModle>();
alstLocation = new ArrayList<LocationModel>();
alstLocatonHome = new ArrayList<LocationModel>();
alstLocatonNearBy = new ArrayList<LocationModel>();
alstLocatonFollowing = new ArrayList<LocationModel>();
alstLocationImages = new ArrayList<DealDetailImagesModel>();
alstSearchLocationFilter = new ArrayList<LocationModel>();
alstSearchDealName = new ArrayList<String>();
alstSearchLocationName = new ArrayList<String>();
edt_search_deal = (AutoCompleteTextView) findViewById(R.id.edt_search_deal);
edt_search_deal.setText("");
edt_search_deal.setThreshold(1);
edt_search_deal.setOnClickListener(this);
lstDeal = (SwipeMenuListView) findViewById(R.id.lstDeals);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setVisibility(View.VISIBLE);
drawerView = (ViewDrawer) findViewById(R.id.drawer);
drawerView.setVisibility(View.VISIBLE);
mHandler = new Handler();
lstLocation.setXListViewListener(this);
lstLocation.setPullLoadEnable(true);
lstDeal.setXListViewListener(this);
lstDeal.setPullLoadEnable(true);
// check if GPS enabled
if (gps.getIsGPSTrackingEnabled())
{
myLat = String.valueOf(gps.getLatitude());
myLng = String.valueOf(gps.getLongitude());
/* myLat = "-0.18287";
myLng = "-78.477663";*/
//self.STRLatitude = @"-0.182875";
//self.STRLongitude = @"-78.477663";
// myLat = "23.012658";
// myLng = "72.521739";
// Log.e("", "myLat:::" + myLat);
// Log.e("", "myLng:::" + myLng);
}
Intent intent = getIntent();
if (intent.getAction() != null) {
alstDeals.clear();
alstSearchDealName.clear();
alstSearchLocationName.clear();
alstHome.clear();
alstNearBy.clear();
if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_FILTER)) {
// isDeal = true;
Utils.storeBoolean(Consts.IS_DEAL, true);
Utils.storeBoolean(Consts.FILTER_RESULT, true);
lytFilter.setVisibility(View.VISIBLE);
txtFilterText.setText(Utils.sharedPreferences.getString(Consts.FILTER_TEXT, ""));
dealVisible();
Bundle mBundle = intent.getBundleExtra(Consts.FILTER_DEAL_BUNDLE);
if (mBundle != null) {
alstHome = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
alstNearBy = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
alstDeals = (ArrayList<DealsModle>) mBundle.getSerializable(Consts.FILTER_DEAL_ARRAY);
// sortDealData(strSort);
// Handle Deals sorting as per type
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
edt_search_deal.setAdapter(aadpDeal);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_MENU)) {
cat_id = Utils.sharedPreferences.getString(Consts.CATEGORY_ID, "0");
sub_cat_id = Utils.sharedPreferences.getString(Consts.SUB_CATEGORY_ID, "0");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, false);
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
strSort = Utils.sharedPreferences.getString(Consts.SORT_FILTER, "");
if (isDeal) {
dealVisible();
Log.e("", "cat_id::" + cat_id);
Log.e("", "sub_cat_id::" + sub_cat_id);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("0") && !sub_cat_id.equalsIgnoreCase("0")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("0")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
} else {
locationVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("0") && !sub_cat_id.equalsIgnoreCase("0")) {
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, "0");
}else if (sub_cat_id.equalsIgnoreCase("0"))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, "0");
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, "0");
}
}
}
} else if (intent.getAction().equalsIgnoreCase(Consts.IS_FROM_FILTER_LOCATION)) {
// isDeal = false;
Utils.storeBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, true);
locationVisible();
Bundle mBundle = intent.getBundleExtra(Consts.FILTER_LOCATION_BUNDLE);
txtFilterText.setText(Utils.sharedPreferences.getString(Consts.FILTER_TEXT, ""));
alstSearchLocationName.clear();
alstSearchLocationFilter.clear();
alstLocatonHome.clear();
alstLocatonNearBy.clear();
alstSearchLocationFilter = (ArrayList<LocationModel>) mBundle.getSerializable(Consts.FILTER_LOCATION_ARRAY);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
Log.e("", "Location Name:::" + alstSearchLocationFilter.get(i).getLocation_name());
Log.e("", "Price Type:::" + alstSearchLocationFilter.get(i).getPrice_type());
Log.e("", "Rate:::" + alstSearchLocationFilter.get(i).getRate());
}
alstLocatonHome.addAll(alstSearchLocationFilter);
alstLocatonNearBy.addAll(alstSearchLocationFilter);
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
if (alstSearchLocationFilter.size() > 0) {
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
}
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("1")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int x = 0; x < alstSearchLocationFilter.size(); x++) {
Log.e("", "Loc Name:::" + alstSearchLocationFilter.get(x).getLocation_name());
alstSearchLocationName.add(alstSearchLocationFilter.get(x).getLocation_name());
}
if (alstSearchLocationFilter.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
} else {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
Utils.storeBoolean(Consts.FILTER_RESULT, false);
if (isDeal) {
dealVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else {
locationVisible();
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, "0");
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, "0");
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, "0");
}
}
}
}
// edt_search_deal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
// public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_NEXT)) {
// Log.i("", "Enter pressed=>>>>");
// InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
// }
// return false;
// }
// });
edt_search_deal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
}
});
edt_search_deal.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
edt_search_deal.setAdapter(aadpDeal);
// edt_search_deal.showDropDown();
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
String text = edt_search_deal.getText().toString().toLowerCase(Locale.getDefault());
if (mDealsAdapter != null) {
mDealsAdapter.filter(text);
}
} else {
String text = edt_search_deal.getText().toString().toLowerCase(Locale.getDefault());
if (mSearchLocationAdapter != null) {
mSearchLocationAdapter.filter(text);
}
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
});
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu, int position) {
SwipeMenuItem AddItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
AddItem.setIcon(R.drawable.add_wallet);
AddItem.setTitle("");
AddItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
AddItem.setTitleColor(getResources().getColor(R.color.white));
AddItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(WalletItem);
SwipeMenuItem RemoveItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
RemoveItem.setIcon(R.drawable.remove_wallet);
RemoveItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
RemoveItem.setTitleColor(getResources().getColor(R.color.white));
RemoveItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(RemoveItem);
if (alstDeals != null) {
if (alstDeals.size() > 0) {
if (alstDeals.get(position).getIsWallet().equalsIgnoreCase("0")) {
menu.addMenuItem(AddItem);
} else {
menu.addMenuItem(RemoveItem);
}
}
}
}
};
lstDeal.setMenuCreator(creator);
lstDeal.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
if (isSkipNow) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.you_are_not_register_user));
} else {
final DealsModle mModel = alstDeals.get(position);
Log.e(" ", "position:::::" + position);
Log.e(" ", "index::::" + index);
//Toast.makeText(DealsActivity.this, "Postion::" + position, Toast.LENGTH_SHORT).show();
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.internet_problem));
} else {
String customenr_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
String deal_id = mModel.getDeal_id();
if (mModel.getIsWallet().equalsIgnoreCase("0")) {
AddToWalletSevice(customenr_id, deal_id, mModel);
} else {
showDeleteDealDialog(DealsActivity.this, customenr_id, deal_id, mModel);
}
}
}
return false;
}
});
// lstDeal.setOnScrollListener(new AbsListView.OnScrollListener() {
// @Override
// public void onScrollStateChanged(AbsListView view, int scrollState) {
//
// }
//
// @Override
// public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// int lastInScreen = firstVisibleItem + visibleItemCount;
// // is the bottom item visible & not loading more already ? Load more !
// String nextStart ="0";
// if (isDeal) {
// if ((lastInScreen == totalItemCount) && mDealsAsynckTask == null) {
// if (alstDeals != null) {
// if (alstDeals.size() > 0) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
// DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
// } else if (sub_cat_id.equalsIgnoreCase("")) {
// DealsSevice("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
// } else {
// DealsSevice("home", cust_id, "0", "0", myLat, myLng,nextStart);
// }
// }
// }
// }
// }
// }
// }
// });
lstDeal.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {
@Override
public void onSwipeStart(int position) {
// Toast.makeText(DealsActivity.this, "Swip Start", Toast.LENGTH_SHORT).show();
}
@Override
public void onSwipeEnd(int position) {
// Toast.makeText(DealsActivity.this, "Swip End", Toast.LENGTH_SHORT).show();
}
});
lstDeal.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// Toast.makeText(DealsActivity.this.getApplicationContext(), position + " long click", Toast.LENGTH_LONG).show();
return false;
}
});
lstDeal.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(DealsActivity.this, DealDetailActivity.class);
intent.putExtra(Consts.DEAL_ID, alstDeals.get(i).getDeal_id());
// intent.putExtra("lat", myLat);
// intent.putExtra("long", myLng);
// MasMas.tracker().send(new HitBuilders.EventBuilder("D_" + alstDeals.get(i).getDeal_id(), "Deal_Click")
// .setLabel("CM_" + cust_id)
// .build());
MasMas.getInstance().trackEvent("D_" + alstDeals.get(i).getDeal_id(), "Deal Click", "CM_" + cust_id);
if (alstDeals.get(i).getAlstLocation() != null) {
if (alstDeals.get(i).getAlstLocation().size() > 0) {
//Log.e("", "LOCIDDDD:::::" + alstDeals.get(i).getAlstLocation().get(0).getLocation_id());
intent.putExtra(Consts.LOCATION_ID, alstDeals.get(i).getAlstLocation().get(0).getLocation_id());
}
}
startActivity(intent);
}
});
SwipeMenuCreator creatorFollow = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu, int position) {
SwipeMenuItem FollowItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
FollowItem.setIcon(R.drawable.follow);
FollowItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
FollowItem.setTitleColor(getResources().getColor(R.color.white));
FollowItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(WalletItem);
SwipeMenuItem UnFollowItem = new SwipeMenuItem(DealsActivity.this.getApplicationContext());
UnFollowItem.setIcon(R.drawable.unfollow);
UnFollowItem.setBackground(new ColorDrawable(Color.rgb(0x01, 0xb1, 0xe3)));
UnFollowItem.setTitleColor(getResources().getColor(R.color.white));
UnFollowItem.setWidth(dp2px((int) getResources().getDimension(R.dimen.val_60)));
// menu.addMenuItem(RemoveItem);
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
Log.e("Follow","Follow:::"+alstSearchLocationFilter.get(position).getLocation_name());
Log.e("Follow","Follow:::"+alstSearchLocationFilter.get(position).getIs_following());
if (alstSearchLocationFilter.get(position).getIs_following().equalsIgnoreCase("0")) {
menu.addMenuItem(FollowItem);
} else {
menu.addMenuItem(UnFollowItem);
}
}
}
}
};
lstLocation.setMenuCreator(creatorFollow);
lstLocation.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
if (isSkipNow) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.you_are_not_register_user));
} else {
final LocationModel mModel = alstSearchLocationFilter.get(position);
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
String customer_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "0");
String location_id = mModel.getLocation_id();
if (mModel.getIs_following().equalsIgnoreCase("0")) {
showUnFollowLocationDialog(customer_id, location_id, "1", mModel, type_location);
} else {
showUnFollowLocationDialog(customer_id, location_id, "0", mModel, type_location);
}
}
}
return false;
}
});
lstLocation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// MasMas.tracker().send(new HitBuilders.EventBuilder("L_"+alstSearchLocationFilter.get(i).getLocation_id(), "Location_Click")
// .setLabel("CM_" +cust_id)
// .build());
MasMas.getInstance().trackEvent("L_" + alstSearchLocationFilter.get(i).getLocation_id(), "Location Click", "CM_" + cust_id);
Intent mIntent = new Intent(DealsActivity.this, LocationDetailActivity.class);
Log.e("", "Location ID :::::" + alstSearchLocationFilter.get(i).getLocation_id());
mIntent.putExtra(Consts.LOCATION_ID, alstSearchLocationFilter.get(i).getLocation_id());
mIntent.putExtra("price_type", alstSearchLocationFilter.get(i).getPrice_type());
startActivity(mIntent);
}
});
}
@Override
protected void onResume() {
super.onResume();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
public void AddToWalletSevice(String customenr_id, String deal_id, final DealsModle mDealsModle) {
AddWalletAsynckTask mAddWalletAsynckTask = new AddWalletAsynckTask(DealsActivity.this);
mAddWalletAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "Add To wallet Response ::::::::" + result.toString());
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mDealsModle.getIsWallet().equalsIgnoreCase("0")) {
mDealsModle.setIsWallet("1");
} else {
mDealsModle.setIsWallet("0");
}
int pos = alstDeals.indexOf(mDealsModle);
alstDeals.set(pos, mDealsModle);
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.deals_success_msg), Toast.LENGTH_LONG).show();
// Utils.SimpleAlertMessage(mContext, mContext.getResources().getString(R.string.deals_success_msg));
}
mDealsAdapter.notifyDataSetChanged();
if (!Utils.checkInternetConnection(DealsActivity.this))
{
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
}
else {
if (type.equalsIgnoreCase(Consts.HOME)) {
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (alstNearBy.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstNearBy.size(); a++) {
alstSearchDealName.add(alstNearBy.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstNearBy, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
/// }
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// DealsLikeSevice("home", cust_id, cat_id, sub_cat_id,myLat,myLng);
// }
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
alstLike.clear();
for (int a = 0; a < alstDeals.size(); a++) {
if (alstDeals.get(a).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(a));
}
}
for (int a = 0; a < alstLike.size(); a++) {
alstSearchDealName.add(alstLike.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstLike, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
}
} else
{
Utils.SimpleAlertMessage(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.deals_success_msg));
}
} catch (Exception e) {
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mAddWalletAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customenr_id, deal_id);
} else {
mAddWalletAsynckTask.execute(customenr_id, deal_id);
}
}
public void DeleteWalletSevice(Context mContext, String customenr_id, String deal_id, final DealsModle mDealsModle) {
DeleteWalletAsynckTask mDeleteWalletAsynckTask = new DeleteWalletAsynckTask(mContext);
mDeleteWalletAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mDealsModle.getIsWallet().equalsIgnoreCase("0")) {
mDealsModle.setIsWallet("1");
} else {
mDealsModle.setIsWallet("0");
}
int pos = alstDeals.indexOf(mDealsModle);
alstDeals.set(pos, mDealsModle);
}
mDealsAdapter.notifyDataSetChanged();
if (type.equalsIgnoreCase(Consts.HOME)) {
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (alstNearBy.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstNearBy.size(); a++) {
alstSearchDealName.add(alstNearBy.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
// }
} else if (type.equalsIgnoreCase("like")) {
// if (!Utils.checkInternetConnection(DealsActivity.this)) {
// Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
// } else {
// DealsLikeSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng);
// }
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
alstLike.clear();
for (int a = 0; a < alstDeals.size(); a++) {
if (alstDeals.get(a).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(a));
}
}
for (int a = 0; a < alstLike.size(); a++) {
alstSearchDealName.add(alstLike.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstLike, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
}
} catch (Exception e) {
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDeleteWalletAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customenr_id, deal_id);
} else {
mDeleteWalletAsynckTask.execute(customenr_id, deal_id);
}
}
/**
* Function to show settings alert dialog.
* On pressing the Settings button it will launch Settings Options.
*/
public void showDeleteDealDialog(final Context mContext, final String customenr_id, final String deal_id, final DealsModle mDealsModle) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle(R.string.app_name);
alertDialog.setMessage(mContext.getResources().getString(R.string.are_u_sure_you_want_to_delete_deals));
alertDialog.setNegativeButton(mContext.getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton(mContext.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
DeleteWalletSevice(mContext, customenr_id, deal_id, mDealsModle);
}
});
alertDialog.show();
}
public void showUnFollowLocationDialog(final String customer_id, final String location_id, final String is_Following, final LocationModel mLocationModel, final String type) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle(R.string.app_name);
if (is_Following.equalsIgnoreCase("1")) {
alertDialog.setMessage(getResources().getString(R.string.are_u_sure_you_want_to_follow_this_location));
} else {
alertDialog.setMessage(getResources().getString(R.string.are_u_sure_you_want_to_unfollow_this_location));
}
alertDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
}
});
alertDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
unFollow_Follow_Location(customer_id, location_id, is_Following, mLocationModel, type);
}
});
alertDialog.show();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.txtFilterbtn:
edt_search_deal.setText("");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Intent mFilterIntent = new Intent(this, FilterActivity.class);
startActivity(mFilterIntent);
finish();
} else {
Intent mFilterIntent = new Intent(this, FilterLocationActivity.class);
startActivity(mFilterIntent);
finish();
}
break;
case R.id.txtMapDeal:
edt_search_deal.setText("");
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Intent mIntent = new Intent(DealsActivity.this, DealsMapActivity.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST", (Serializable) alstDeals);
mIntent.putExtra("BUNDLE", args);
startActivity(mIntent);
} else {
Intent mIntent = new Intent(DealsActivity.this, LocationMapActivity.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST_LOCATION", (Serializable) alstSearchLocationFilter);
// for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
// Log.e("Lat", "Lat:::" + alstSearchLocationFilter.get(i).getLatitude());
// Log.e("Lag", "Lag:::" + alstSearchLocationFilter.get(i).getLongitude());
// }
mIntent.putExtra("BUNDLE_LOCATION", args);
startActivity(mIntent);
}
break;
case R.id.imgDeals_menu:
edt_search_deal.setText("");
edt_search_deal.dismissDropDown();
drawerLayout.openDrawer(drawerView);
break;
case R.id.imgFilterClose:
Utils.storeString(Consts.SORT_FILTER, "deal_name");
lytFilter.setVisibility(View.GONE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
break;
case R.id.txtHome:
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.HOME);
islike = false;
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstDeals.clear();
alstDeals.addAll(alstHome);
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getDeal_name().compareTo(object2.getDeal_name());
}
});
alstSearchDealName.clear();
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
// Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
break;
case R.id.txtNearBy:
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.NEAR_BY);
islike = false;
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.header));
imgNearBy.setVisibility(View.VISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstDeals.clear();
alstDeals.addAll(alstNearBy);
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
alstSearchDealName.clear();
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
}
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.NEAR_BY);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
lstLocation.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.header));
imgNearBy.setVisibility(View.VISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
// Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
break;
case R.id.txtLike:
if (isSkipNow) {
dialogSkipNow(this);
} else {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
Utils.storeString(Consts.TYPE, Consts.LIKE);
islike = true;
edt_search_deal.setText("");
lytLocation.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.header));
imgLike.setVisibility(View.VISIBLE);
alstLike.clear();
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else {
Utils.storeString(Consts.TYPE_LOCATION, Consts.FOLLOWING);
edt_search_deal.setText("");
lytLocation.setVisibility(View.VISIBLE);
lstDeal.setVisibility(View.GONE);
txtHome.setTextColor(getResources().getColor(R.color.gray_dark));
imgHome.setVisibility(View.INVISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.profile_following_btn));
txtLike.setTextColor(getResources().getColor(R.color.header));
imgLike.setVisibility(View.VISIBLE);
alstSearchLocationName.clear();
alstLocatonFollowing.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("1")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.GONE);
}
}
}
break;
case R.id.edt_search_deal:
if (islike) {
lytLocation.setVisibility(View.GONE);
} else {
lytLocation.setVisibility(View.VISIBLE);
}
break;
case R.id.btnDeals:
Utils.storeBoolean(Consts.IS_DEAL, true);
lytFilter.setVisibility(View.GONE);
txtLike.setText(getResources().getString(R.string.like));
dealVisible();
txtHeader_deals.setText(getResources().getString(R.string.deals));
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setText(getResources().getString(R.string.like));
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice("home", cust_id, cat_id, "0", myLat, myLng, nextStart);
} else {
DealsSevice("home", cust_id, "0", "0", myLat, myLng, nextStart);
}
}
break;
case R.id.btnLocation:
lytFilter.setVisibility(View.GONE);
Utils.storeBoolean(Consts.IS_DEAL, false);
Utils.storeString(Consts.TYPE_LOCATION, Consts.HOME);
txtHeader_deals.setText(getResources().getString(R.string.locations));
txtLike.setText(getResources().getString(R.string.profile_following_btn));
lstDeal.setVisibility(View.GONE);
locationVisible();
txtHome.setTextColor(getResources().getColor(R.color.header));
imgHome.setVisibility(View.VISIBLE);
txtNearBy.setTextColor(getResources().getColor(R.color.gray_dark));
imgNearBy.setVisibility(View.INVISIBLE);
txtLike.setTextColor(getResources().getColor(R.color.gray_dark));
imgLike.setVisibility(View.INVISIBLE);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
break;
case R.id.imgClose:
edt_search_deal.setText("");
lstDeal.setVisibility(View.VISIBLE);
if (edt_search_deal != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edt_search_deal.getWindowToken(), 0);
}
break;
default:
break;
}
}
private void locationVisible() {
lstDeal.setVisibility(View.GONE);
rlytLocation.setVisibility(View.VISIBLE);
lstLocation.setVisibility(View.VISIBLE);
edt_search_deal.setText("");
btnDeals.setBackgroundResource(R.drawable.ractangle_tab_left_normal);
btnDeals.setTextColor(getResources().getColor(R.color.black));
btnLocation.setBackgroundResource(R.drawable.ractangle_tab_right);
btnLocation.setTextColor(getResources().getColor(R.color.white));
rlytLocation.setVisibility(View.VISIBLE);
}
private void dealVisible() {
lstLocation.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
rlytLocation.setVisibility(View.GONE);
edt_search_deal.setText("");
btnDeals.setBackgroundResource(R.drawable.ractangle_tab_left);
btnDeals.setTextColor(getResources().getColor(R.color.white));
btnLocation.setBackgroundResource(R.drawable.ractangle_tab_right_normal);
btnLocation.setTextColor(getResources().getColor(R.color.black));
}
public void DealsSevice(final String deal_type, String cust_id, String cat_id, String sub_cat_id, String latitude, String longitude, String next_start) {
if (mDealsAsynckTask == null) {
mDealsAsynckTask = new DealsAsynckTask(this);
mDealsAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
mDealsAsynckTask = null;
if (result != null) {
try {
alstHome.clear();
alstNearBy.clear();
alstLike.clear();
alstDeals.clear();
alstLocation.clear();
alstLocationImages.clear();
// alstSearchLoaction.clear();
alstSearchDealName.clear();
alstSearchLocationName.clear();
alstSearchLocationFilter.clear();
DealsModle dealsModel = null;
LocationModel locationModel = null;
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
lstDeal.setVisibility(View.VISIBLE);
txtNoDeal.setVisibility(View.INVISIBLE);
alstDeals = new ArrayList<DealsModle>();
alstHome = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("home");
for (int i = 0; i < mJsonArray.length(); i++) {
dealsModel = new DealsModle();
JSONObject mData = mJsonArray.getJSONObject(i);
dealsModel.setDeal_id(mData.optString("deal_id"));
dealsModel.setM_fullname(mData.optString("m_fullname"));
dealsModel.setMerchant_id(mData.optString("merchant_id"));
dealsModel.setMaximum_redumption(mData.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mData.optString("merchant_user_id"));
dealsModel.setCategory_id(mData.optString("category_id"));
dealsModel.setDeal_name(mData.optString("deal_name"));
dealsModel.setDeal_desc(mData.optString("deal_desc"));
dealsModel.setStart_date(mData.optString("start_date"));
dealsModel.setEnd_date(mData.optString("end_date"));
dealsModel.setIs_active(mData.optString("is_active"));
dealsModel.setRate(mData.optString("rate"));
dealsModel.setComments(mData.optString("comments"));
dealsModel.setImage(mData.optString("image"));
dealsModel.setDeals_left(mData.optString("deals_left"));
dealsModel.setIsLike(mData.optString("is_liked"));
Log.e("", "LIKE::::::" + mData.optString("is_liked"));
dealsModel.setIsWallet(mData.optString("is_wallet"));
dealsModel.setPopularity_count(mData.optString("popularity_count"));
dealsModel.setDistanceKm(mData.optString("distance_in_km"));
JSONArray mLocationArray = mData.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
alstHome.add(dealsModel);
// alstNearBy.add(dealsModel);
}
alstNearBy = new ArrayList<DealsModle>();
JSONArray mJsonArrayNearBy = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayNearBy.length(); i++) {
dealsModel = new DealsModle();
JSONObject mDataNearBy = mJsonArrayNearBy.getJSONObject(i);
dealsModel.setDeal_id(mDataNearBy.optString("deal_id"));
dealsModel.setM_fullname(mDataNearBy.optString("m_fullname"));
dealsModel.setMerchant_id(mDataNearBy.optString("merchant_id"));
dealsModel.setMaximum_redumption(mDataNearBy.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mDataNearBy.optString("merchant_user_id"));
dealsModel.setCategory_id(mDataNearBy.optString("category_id"));
dealsModel.setDeal_name(mDataNearBy.optString("deal_name"));
dealsModel.setDeal_desc(mDataNearBy.optString("deal_desc"));
dealsModel.setStart_date(mDataNearBy.optString("start_date"));
dealsModel.setEnd_date(mDataNearBy.optString("end_date"));
dealsModel.setIs_active(mDataNearBy.optString("is_active"));
dealsModel.setRate(mDataNearBy.optString("rate"));
dealsModel.setComments(mDataNearBy.optString("comments"));
dealsModel.setImage(mDataNearBy.optString("image"));
dealsModel.setDeals_left(mDataNearBy.optString("deals_left"));
dealsModel.setIsLike(mDataNearBy.optString("is_liked"));
Log.e("", "LIKE::::::" + mDataNearBy.optString("is_liked"));
dealsModel.setIsWallet(mDataNearBy.optString("is_wallet"));
dealsModel.setPopularity_count(mDataNearBy.optString("popularity_count"));
dealsModel.setDistanceKm(mDataNearBy.optString("distance_in_km"));
JSONArray mLocationArray = mDataNearBy.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
// alstHome.add(dealsModel);
alstNearBy.add(dealsModel);
}
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
//sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
lstDeal.setAdapter(mDealsAdapter);
} else {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
} else if (strStatus.equalsIgnoreCase("2")) {
lstDeal.setVisibility(View.GONE);
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_deal_found));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDealsAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
} else {
mDealsAsynckTask.execute(deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
}
}
}
public void DealsSevice_loadmore(final String deal_type, String cust_id, String cat_id, String sub_cat_id, String latitude, String longitude, String next_start) {
mDealsAsynckTask_loadmore = new DealsAsynckTask_loadmore(this);
mDealsAsynckTask_loadmore.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
lstDeal.stopLoadMore();
lstDeal.stopRefresh();
if (result != null) {
try {
DealsModle dealsModel = null;
LocationModel locationModel = null;
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
// alstDeals = new ArrayList<DealsModle>();
//alstHome = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("home");
for (int i = 0; i < mJsonArray.length(); i++) {
dealsModel = new DealsModle();
JSONObject mData = mJsonArray.getJSONObject(i);
dealsModel.setDeal_id(mData.optString("deal_id"));
dealsModel.setM_fullname(mData.optString("m_fullname"));
dealsModel.setMerchant_id(mData.optString("merchant_id"));
dealsModel.setMaximum_redumption(mData.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mData.optString("merchant_user_id"));
dealsModel.setCategory_id(mData.optString("category_id"));
dealsModel.setDeal_name(mData.optString("deal_name"));
dealsModel.setDeal_desc(mData.optString("deal_desc"));
dealsModel.setStart_date(mData.optString("start_date"));
dealsModel.setEnd_date(mData.optString("end_date"));
dealsModel.setIs_active(mData.optString("is_active"));
dealsModel.setRate(mData.optString("rate"));
dealsModel.setComments(mData.optString("comments"));
dealsModel.setImage(mData.optString("image"));
dealsModel.setDeals_left(mData.optString("deals_left"));
dealsModel.setIsLike(mData.optString("is_liked"));
Log.e("", "LIKE::::::" + mData.optString("is_liked"));
dealsModel.setIsWallet(mData.optString("is_wallet"));
dealsModel.setPopularity_count(mData.optString("popularity_count"));
dealsModel.setDistanceKm(mData.optString("distance_in_km"));
JSONArray mLocationArray = mData.optJSONArray("locations");
// alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
alstHome.add(dealsModel);
// alstNearBy.add(dealsModel);
}
alstNearBy = new ArrayList<DealsModle>();
JSONArray mJsonArrayNearBy = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayNearBy.length(); i++) {
dealsModel = new DealsModle();
JSONObject mDataNearBy = mJsonArrayNearBy.getJSONObject(i);
dealsModel.setDeal_id(mDataNearBy.optString("deal_id"));
dealsModel.setM_fullname(mDataNearBy.optString("m_fullname"));
dealsModel.setMerchant_id(mDataNearBy.optString("merchant_id"));
dealsModel.setMaximum_redumption(mDataNearBy.optString("maximum_redumption"));
dealsModel.setMerchant_user_id(mDataNearBy.optString("merchant_user_id"));
dealsModel.setCategory_id(mDataNearBy.optString("category_id"));
dealsModel.setDeal_name(mDataNearBy.optString("deal_name"));
dealsModel.setDeal_desc(mDataNearBy.optString("deal_desc"));
dealsModel.setStart_date(mDataNearBy.optString("start_date"));
dealsModel.setEnd_date(mDataNearBy.optString("end_date"));
dealsModel.setIs_active(mDataNearBy.optString("is_active"));
dealsModel.setRate(mDataNearBy.optString("rate"));
dealsModel.setComments(mDataNearBy.optString("comments"));
dealsModel.setImage(mDataNearBy.optString("image"));
dealsModel.setDeals_left(mDataNearBy.optString("deals_left"));
dealsModel.setIsLike(mDataNearBy.optString("is_liked"));
Log.e("", "LIKE::::::" + mDataNearBy.optString("is_liked"));
dealsModel.setIsWallet(mDataNearBy.optString("is_wallet"));
dealsModel.setPopularity_count(mDataNearBy.optString("popularity_count"));
dealsModel.setDistanceKm(mDataNearBy.optString("distance_in_km"));
JSONArray mLocationArray = mDataNearBy.optJSONArray("locations");
alstLocation = new ArrayList<LocationModel>();
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
// alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// String loc_id = mLocationObj.optString("location_id");
// alstSearchLoaction.add(locationModel);
alstLocation.add(locationModel);
}
dealsModel.setAlstLocation(alstLocation);
}
// alstHome.add(dealsModel);
alstNearBy.add(dealsModel);
}
type = Utils.sharedPreferences.getString(Consts.TYPE, Consts.HOME);
if (type.equalsIgnoreCase(Consts.HOME)) {
alstDeals.clear();
alstDeals.addAll(alstHome);
//sortDealData(strSort);
} else if (type.equalsIgnoreCase(Consts.NEAR_BY)) {
alstDeals.clear();
alstDeals.addAll(alstNearBy);
} else if (type.equalsIgnoreCase(Consts.LIKE)) {
sortDealData(strSort);
for (int i = 0; i < alstDeals.size(); i++) {
if (alstDeals.get(i).getIsLike().equalsIgnoreCase("1")) {
alstLike.add(alstDeals.get(i));
}
}
alstDeals.clear();
alstDeals.addAll(alstLike);
}
if (alstDeals.size() > 0) {
txtNoDeal.setVisibility(View.GONE);
lstDeal.setVisibility(View.VISIBLE);
for (int a = 0; a < alstDeals.size(); a++) {
alstSearchDealName.add(alstDeals.get(a).getDeal_name());
}
Collections.sort(alstSearchDealName);
//Collections.sort(alstSearchLocationName);
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if (isDeal) {
aadpDeal = null;
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchDealName);
}
//mDealsAdapter = new DealsAdapter(DealsActivity.this, alstDeals, islike);
mDealsAdapter.notifyDataSetChanged();
// lstDeal.setAdapter(mDealsAdapter);
}
}
else
{
lstDeal.hide_layout();
mDealsAdapter.notifyDataSetChanged();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDealsAsynckTask_loadmore.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
} else {
mDealsAsynckTask_loadmore.execute(deal_type, cust_id, cat_id, sub_cat_id, latitude, longitude, next_start);
}
}
private boolean isDuplicate(LocationModel locationModel) {
if (locationModel != null) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (locationModel.getLocation_id().equalsIgnoreCase(alstSearchLocationFilter.get(i).getLocation_id())) {
return true;
}
}
}
return false;
}
public void GetAllLocation(String customer_id, String location_type,String cat_id,String sub_cat_id ,String c_latitude, String c_longitude, String next_start) {
if (mGetAllLocationAsynckTask == null) {
mGetAllLocationAsynckTask = new GetAllLocationAsynckTask(this);
mGetAllLocationAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
mGetAllLocationAsynckTask = null;
if (result != null) {
Log.e("result", "Location result::::::::" + result.toString());
try {
alstLocatonHome.clear();
alstLocatonNearBy.clear();
alstLocatonFollowing.clear();
locationModel = null;
alstSearchLocationFilter.clear();
alstLocationImages.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextLocationStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
JSONArray mLocationArray = mJsonResponse.getJSONArray("home");
txtNoDeal.setVisibility(View.GONE);
lstLocation.setVisibility(View.VISIBLE);
alstLocatonHome = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setCity(mLocationObj.optString("city"));
locationModel.setState(mLocationObj.optString("state"));
locationModel.setCountry(mLocationObj.optString("country"));
locationModel.setZipcode(mLocationObj.optString("zipcode"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setTags(mLocationObj.optString("tags"));
locationModel.setEmail(mLocationObj.optString("email"));
locationModel.setWebsite(mLocationObj.optString("website"));
locationModel.setDisp_attire(mLocationObj.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObj.optString("is_deleted"));
locationModel.setCreated(mLocationObj.optString("created"));
locationModel.setAvg_rate(mLocationObj.optString("avg_rate"));
locationModel.setCity_name(mLocationObj.optString("city_name"));
locationModel.setDistance_in_km(mLocationObj.optString("distance_in_km"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
locationModel.setIs_following(mLocationObj.optString("is_following"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
alstLocatonHome.add(locationModel);
//alstLocatonNearBy.add(locationModel);
}
JSONArray mLocationNearBy = mJsonResponse.getJSONArray("data");
if (mLocationNearBy != null) {
if (mLocationNearBy.length() > 0) {
alstLocatonNearBy = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationNearBy.length(); j++) {
JSONObject mLocationObjNearBy = mLocationNearBy.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObjNearBy.optString("location_id"));
locationModel.setLocation_name(mLocationObjNearBy.optString("location_name"));
locationModel.setLocation_desc(mLocationObjNearBy.optString("location_desc"));
locationModel.setLatitude(mLocationObjNearBy.optString("latitude"));
locationModel.setLongitude(mLocationObjNearBy.optString("longitude"));
locationModel.setContact(mLocationObjNearBy.optString("contact"));
locationModel.setAddress1(mLocationObjNearBy.optString("address1"));
locationModel.setAddress2(mLocationObjNearBy.optString("address2"));
locationModel.setLocation_timing(mLocationObjNearBy.optString("location_timing"));
locationModel.setCity(mLocationObjNearBy.optString("city"));
locationModel.setState(mLocationObjNearBy.optString("state"));
locationModel.setCountry(mLocationObjNearBy.optString("country"));
locationModel.setZipcode(mLocationObjNearBy.optString("zipcode"));
locationModel.setPrice_type(mLocationObjNearBy.optString("price_type"));
locationModel.setTags(mLocationObjNearBy.optString("tags"));
locationModel.setEmail(mLocationObjNearBy.optString("email"));
locationModel.setWebsite(mLocationObjNearBy.optString("website"));
locationModel.setDisp_attire(mLocationObjNearBy.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObjNearBy.optString("is_deleted"));
locationModel.setCreated(mLocationObjNearBy.optString("created"));
locationModel.setAvg_rate(mLocationObjNearBy.optString("avg_rate"));
locationModel.setCity_name(mLocationObjNearBy.optString("city_name"));
locationModel.setDistance_in_km(mLocationObjNearBy.optString("distance_in_km"));
locationModel.setRate(mLocationObjNearBy.optString("rate"));
locationModel.setComments(mLocationObjNearBy.optString("comments"));
locationModel.setIs_following(mLocationObjNearBy.optString("is_following"));
JSONArray locationImageNearBy = mLocationObjNearBy.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImageNearBy != null) {
if (locationImageNearBy.length() > 0) {
for (int k = 0; k < locationImageNearBy.length(); k++) {
JSONObject mlocationImageObj1 = locationImageNearBy.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj1.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// alstLocatonHome.add(locationModel);
alstLocatonNearBy.add(locationModel);
}
}
}
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
// if (alstSearchLocationFilter.size() > 0) {
// Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
// @Override
// public int compare(final LocationModel object1, final LocationModel object2) {
// return object1.getLocation_name().compareTo(object2.getLocation_name());
// }
// });
// }
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
if (!alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("0")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
} else {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
lstLocation.setVisibility(View.GONE);
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
lstLocation.setVisibility(View.GONE);
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.no_location_found), Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.e("Lat", "Lat:::" + c_latitude);
Log.e("Long", "Long:::" + c_longitude);
mGetAllLocationAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customer_id, location_type, cat_id,sub_cat_id,c_latitude, c_longitude, next_start);
} else {
mGetAllLocationAsynckTask.execute(customer_id, location_type,cat_id,sub_cat_id,c_latitude, c_longitude, next_start);
}
}
}
public void GetAllLocation_loadmore(String customer_id, String location_type,String cat_id ,String sub_cat_id,String c_latitude, String c_longitude, String next_start) {
mGetAllLocationAsynckTask_loadmore = new GetAllLocationAsynckTask_loadMore(this);
mGetAllLocationAsynckTask_loadmore.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response)
{
}
@Override
public void onResponseReceived(String result) {
lstLocation.stopRefresh();
lstLocation.stopLoadMore();
if (result != null) {
try {
JSONObject mJsonResult = new JSONObject(result);
// lstLocation.hide_layout();
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
nextLocationStart = mJsonResponse.getString("nextStart");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
JSONArray mLocationArray = mJsonResponse.getJSONArray("home");
//alstLocatonHome = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationArray.length(); j++) {
JSONObject mLocationObj = mLocationArray.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObj.optString("location_id"));
locationModel.setLocation_name(mLocationObj.optString("location_name"));
locationModel.setLocation_desc(mLocationObj.optString("location_desc"));
locationModel.setLatitude(mLocationObj.optString("latitude"));
locationModel.setLongitude(mLocationObj.optString("longitude"));
locationModel.setContact(mLocationObj.optString("contact"));
locationModel.setAddress1(mLocationObj.optString("address1"));
locationModel.setAddress2(mLocationObj.optString("address2"));
locationModel.setLocation_timing(mLocationObj.optString("location_timing"));
locationModel.setCity(mLocationObj.optString("city"));
locationModel.setState(mLocationObj.optString("state"));
locationModel.setCountry(mLocationObj.optString("country"));
locationModel.setZipcode(mLocationObj.optString("zipcode"));
locationModel.setPrice_type(mLocationObj.optString("price_type"));
locationModel.setTags(mLocationObj.optString("tags"));
locationModel.setEmail(mLocationObj.optString("email"));
locationModel.setWebsite(mLocationObj.optString("website"));
locationModel.setDisp_attire(mLocationObj.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObj.optString("is_deleted"));
locationModel.setCreated(mLocationObj.optString("created"));
locationModel.setAvg_rate(mLocationObj.optString("avg_rate"));
locationModel.setCity_name(mLocationObj.optString("city_name"));
locationModel.setDistance_in_km(mLocationObj.optString("distance_in_km"));
locationModel.setRate(mLocationObj.optString("rate"));
locationModel.setComments(mLocationObj.optString("comments"));
locationModel.setIs_following(mLocationObj.optString("is_following"));
JSONArray locationImage = mLocationObj.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImage != null) {
if (locationImage.length() > 0) {
for (int k = 0; k < locationImage.length(); k++) {
JSONObject mlocationImageObj = locationImage.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
alstLocatonHome.add(locationModel);
//alstLocatonNearBy.add(locationModel);
}
JSONArray mLocationNearBy = mJsonResponse.getJSONArray("data");
if (mLocationNearBy != null) {
if (mLocationNearBy.length() > 0) {
alstLocatonNearBy = new ArrayList<LocationModel>();
for (int j = 0; j < mLocationNearBy.length(); j++) {
JSONObject mLocationObjNearBy = mLocationNearBy.getJSONObject(j);
locationModel = new LocationModel();
locationModel.setLocation_id(mLocationObjNearBy.optString("location_id"));
locationModel.setLocation_name(mLocationObjNearBy.optString("location_name"));
locationModel.setLocation_desc(mLocationObjNearBy.optString("location_desc"));
locationModel.setLatitude(mLocationObjNearBy.optString("latitude"));
locationModel.setLongitude(mLocationObjNearBy.optString("longitude"));
locationModel.setContact(mLocationObjNearBy.optString("contact"));
locationModel.setAddress1(mLocationObjNearBy.optString("address1"));
locationModel.setAddress2(mLocationObjNearBy.optString("address2"));
locationModel.setLocation_timing(mLocationObjNearBy.optString("location_timing"));
locationModel.setCity(mLocationObjNearBy.optString("city"));
locationModel.setState(mLocationObjNearBy.optString("state"));
locationModel.setCountry(mLocationObjNearBy.optString("country"));
locationModel.setZipcode(mLocationObjNearBy.optString("zipcode"));
locationModel.setPrice_type(mLocationObjNearBy.optString("price_type"));
locationModel.setTags(mLocationObjNearBy.optString("tags"));
locationModel.setEmail(mLocationObjNearBy.optString("email"));
locationModel.setWebsite(mLocationObjNearBy.optString("website"));
locationModel.setDisp_attire(mLocationObjNearBy.optString("disp_attire"));
locationModel.setIs_deleted(mLocationObjNearBy.optString("is_deleted"));
locationModel.setCreated(mLocationObjNearBy.optString("created"));
locationModel.setAvg_rate(mLocationObjNearBy.optString("avg_rate"));
locationModel.setCity_name(mLocationObjNearBy.optString("city_name"));
locationModel.setDistance_in_km(mLocationObjNearBy.optString("distance_in_km"));
locationModel.setRate(mLocationObjNearBy.optString("rate"));
locationModel.setComments(mLocationObjNearBy.optString("comments"));
locationModel.setIs_following(mLocationObjNearBy.optString("is_following"));
JSONArray locationImageNearBy = mLocationObjNearBy.optJSONArray("location_images");
alstLocationImages = new ArrayList<DealDetailImagesModel>();
if (locationImageNearBy != null) {
if (locationImageNearBy.length() > 0) {
for (int k = 0; k < locationImageNearBy.length(); k++) {
JSONObject mlocationImageObj1 = locationImageNearBy.getJSONObject(k);
mDealDetailImagesModel = new DealDetailImagesModel();
mDealDetailImagesModel.setStrImage(mlocationImageObj1.optString("image"));
alstLocationImages.add(mDealDetailImagesModel);
}
locationModel.setAlstlocationImages(alstLocationImages);
}
}
// alstLocatonHome.add(locationModel);
alstLocatonNearBy.add(locationModel);
}
}
}
type_location = Utils.sharedPreferences.getString(Consts.TYPE_LOCATION, Consts.HOME);
if (type_location.equalsIgnoreCase(Consts.HOME)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonHome);
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
// if (alstSearchLocationFilter.size() > 0) {
// Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
// @Override
// public int compare(final LocationModel object1, final LocationModel object2) {
// return object1.getLocation_name().compareTo(object2.getLocation_name());
// }
// });
// }
} else if (type_location.equalsIgnoreCase(Consts.NEAR_BY)) {
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonNearBy);
} else if (type_location.equalsIgnoreCase(Consts.FOLLOWING)) {
alstLocatonFollowing.clear();
Collections.sort(alstSearchLocationFilter, new Comparator<LocationModel>() {
@Override
public int compare(final LocationModel object1, final LocationModel object2) {
return object1.getLocation_name().compareTo(object2.getLocation_name());
}
});
for (int i = 0; i < alstSearchLocationFilter.size(); i++)
{
if (!alstSearchLocationFilter.get(i).getIs_following().equalsIgnoreCase("0")) {
alstLocatonFollowing.add(alstSearchLocationFilter.get(i));
}
}
alstSearchLocationFilter.clear();
alstSearchLocationFilter.addAll(alstLocatonFollowing);
// lstLocation.setMenuCreator(creatorFollow);
}
// for(int i=0;i<alstSearchLocationFilter.size();i++){
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getLocation_name());
// Log.e("","Follow:::"+alstSearchLocationFilter.get(i).getIs_following());
// }
//mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
// lstLocation.setAdapter(mSearchLocationAdapter);
mSearchLocationAdapter.notifyDataSetChanged();
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
}
}
else
{
lstLocation.hide_layout();
mSearchLocationAdapter.notifyDataSetChanged();
}
}
} catch (JSONException e)
{
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.e("Lat", "Lat:::" + c_latitude);
Log.e("Long", "Long:::" + c_longitude);
mGetAllLocationAsynckTask_loadmore.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customer_id,cat_id,sub_cat_id,location_type, c_latitude, c_longitude, next_start);
} else {
mGetAllLocationAsynckTask_loadmore.execute(customer_id, location_type,cat_id,sub_cat_id, c_latitude, c_longitude, next_start);
}
}
public void unFollow_Follow_Location(final String cust_id, String location_id, final String is_following, final LocationModel mLocationModel, final String location_type) {
FollowUnFollowLocationAsyncTask mFollowUnFollowAsyncTask = new FollowUnFollowLocationAsyncTask(this);
mFollowUnFollowAsyncTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
if (mLocationModel.getIs_following().equalsIgnoreCase("0")) {
// mLocationModel.setIs_following("1");
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.you_have_follow_this_location), Toast.LENGTH_LONG).show();
} else {
// mLocationModel.setIs_following("0");
Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.you_have_unfollow_this_location), Toast.LENGTH_LONG).show();
}
// int pos = alstSearchLocationFilter.indexOf(mLocationModel);
// alstSearchLocationFilter.set(pos, mLocationModel);
// mSearchLocationAdapter.notifyDataSetChanged();
if (!Utils.checkInternetConnection(DealsActivity.this)) {
Utils.SimpleAlertMessage(DealsActivity.this, getResources().getString(R.string.internet_problem));
} else {
if (location_type.equalsIgnoreCase(Consts.HOME))
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
else if (location_type.equalsIgnoreCase(Consts.NEAR_BY)) {
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
else if (location_type.equalsIgnoreCase(Consts.FOLLOWING)) {
mLocationModel.setIs_following("0");
// int follow_pos = alstSearchLocationFilter.indexOf(mLocationModel);
alstSearchLocationFilter.remove(mLocationModel);
mSearchLocationAdapter.notifyDataSetChanged();
if (alstSearchLocationFilter.size() <= 0) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
}
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
// Toast.makeText(DealsActivity.this, DealsActivity.this.getResources().getString(R.string.please_try_again), Toast.LENGTH_LONG).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mFollowUnFollowAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cust_id, location_id, is_following);
} else {
mFollowUnFollowAsyncTask.execute(cust_id, location_id, is_following);
}
}
public void FollowingLocation(String cust_id) {
LocationFollowingAsyncTask mFollowingsAsynckTask = new LocationFollowingAsyncTask(this);
mFollowingsAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
alstSearchLocationFilter.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
txtNoDeal.setVisibility(View.GONE);
alstSearchLocationFilter = new ArrayList<LocationModel>();
JSONArray mJsonArrayLocation = mJsonResponse.getJSONArray("data");
for (int i = 0; i < mJsonArrayLocation.length(); i++) {
locationModel = new LocationModel();
JSONObject mLocationData = mJsonArrayLocation.getJSONObject(i);
locationModel.setLocation_id(mLocationData.optString("location_id"));
locationModel.setLocation_name(mLocationData.optString("location_name"));
locationModel.setLocation_desc(mLocationData.optString("mLocationData"));
locationModel.setAddress1(mLocationData.optString("address1"));
locationModel.setFollower_id(mLocationData.optString("follower_id"));
locationModel.setIs_following(mLocationData.optString("is_following"));
locationModel.setIs_block(mLocationData.optString("is_block"));
locationModel.setComments(mLocationData.optString("comments"));
locationModel.setRate(mLocationData.optString("rate"));
locationModel.setImage(mLocationData.optString("image"));
alstSearchLocationFilter.add(locationModel);
// strLocationCount = String.valueOf(mJsonArrayLocation.length());
}
// txtLocation.setText(getResources().getString(R.string.you_are_following) + " " + strLocationCount + " " + getResources().getString(R.string.locations));
mSearchLocationAdapter = new SearchLocationAdapter(DealsActivity.this, alstSearchLocationFilter);
lstLocation.setAdapter(mSearchLocationAdapter);
alstSearchLocationName.clear();
if (alstSearchLocationFilter != null) {
if (alstSearchLocationFilter.size() > 0) {
for (int i = 0; i < alstSearchLocationFilter.size(); i++) {
alstSearchLocationName.add(alstSearchLocationFilter.get(i).getLocation_name());
}
aadpDeal = null;
Collections.sort(alstSearchLocationName);
aadpDeal = new ArrayAdapter<String>(DealsActivity.this, R.layout.auto_list_item, alstSearchLocationName);
}
}
} else if (strStatus.equalsIgnoreCase("2")) {
txtNoDeal.setVisibility(View.VISIBLE);
txtNoDeal.setText(getResources().getString(R.string.no_location_found));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mFollowingsAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cust_id);
} else {
mFollowingsAsynckTask.execute(cust_id);
}
}
public void GetAllCategories() {
GetCategoriesAsynckTask mGetCategoriesAsynckTask = new GetCategoriesAsynckTask(this);
mGetCategoriesAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
CategoryModel mCategoryModel = null;
SubCategoriesModel mSubCategoriesModel = null;
alstCategory.clear();
alstMoreCategories.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
alstCategory = new ArrayList<CategoryModel>();
alstMoreCategories = new ArrayList<CategoryModel>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("data");
if (mJsonArray != null) {
for (int i = 0; i < mJsonArray.length() + 1; i++) {
if (i == 0) {
mCategoryModel = new CategoryModel();
//JSONObject mData = mJsonArray.optJSONObject(i);
mCategoryModel.setCatId("0");
mCategoryModel.setCatName(getResources().getString(R.string.all));
mCategoryModel.setCatImage("");
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstCategory.add(mCategoryModel);
alstMoreCategories.add(mCategoryModel);
alstSubCategory = new ArrayList<SubCategoriesModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
hashmapSubCategory.put("0", alstSubCategory);
hashmapMoreSubCategories.put("0", alstMoreSubCategories);
} else if (i < 5) {
mCategoryModel = new CategoryModel();
JSONObject mData = mJsonArray.optJSONObject(i - 1);
mCategoryModel.setCatId(mData.optString("category_id"));
mCategoryModel.setCatName(mData.optString("category_name"));
mCategoryModel.setCatImage(mData.optString("image"));
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstCategory.add(mCategoryModel);
alstMoreCategories.add(mCategoryModel);
JSONArray mSubArray = mData.optJSONArray("subcategories");
alstSubCategory = new ArrayList<SubCategoriesModel>();
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
if (mSubArray != null) {
if (mSubArray.length() > 0) {
for (int j = 0; j < mSubArray.length(); j++) {
mSubCategoriesModel = new SubCategoriesModel();
JSONObject mSubObj = mSubArray.optJSONObject(j);
mSubCategoriesModel.setStrSubCatId(mSubObj.optString("category_id"));
mSubCategoriesModel.setStrSubCatName(mSubObj.optString("category_name"));
mSubCategoriesModel.setStrSubCatImage(mSubObj.optString("image"));
mSubCategoriesModel.setIsChecked(false);
alstSubCategory.add(mSubCategoriesModel);
alstMoreSubCategories.add(mSubCategoriesModel);
}
// mCategoryModel.setAlstSubCat(alstSubCategory);
}
}
hashmapSubCategory.put(mData.optString("category_id"), alstSubCategory);
hashmapMoreSubCategories.put(mData.optString("category_id"), alstMoreSubCategories);
}
// else if (i == 5) {
// mCategoryModel = new CategoryModel();
// //JSONObject mData = mJsonArray.optJSONObject(i);
// mCategoryModel.setCatId("-1");
// mCategoryModel.setCatName(getResources().getString(R.string.more_categories));
// mCategoryModel.setCatImage("");
// mCategoryModel.setIsChecked(false);
// mCategoryModel.setIsChildChecked(false);
// alstCategory.add(mCategoryModel);
// alstSubCategory = new ArrayList<SubCategoriesModel>();
// hashmapSubCategory.put("-1", alstSubCategory);
else {
mCategoryModel = new CategoryModel();
JSONObject mData = mJsonArray.optJSONObject(i - 1);
mCategoryModel.setCatId(mData.optString("category_id"));
mCategoryModel.setCatName(mData.optString("category_name"));
mCategoryModel.setCatImage(mData.optString("image"));
mCategoryModel.setIsChecked(false);
mCategoryModel.setIsChildChecked(false);
alstMoreCategories.add(mCategoryModel);
JSONArray mSubArray = mData.optJSONArray("subcategories");
alstMoreSubCategories = new ArrayList<SubCategoriesModel>();
if (mSubArray != null) {
if (mSubArray.length() > 0) {
for (int j = 0; j < mSubArray.length(); j++) {
mSubCategoriesModel = new SubCategoriesModel();
JSONObject mSubObj = mSubArray.optJSONObject(j);
mSubCategoriesModel.setStrSubCatId(mSubObj.optString("category_id"));
mSubCategoriesModel.setStrSubCatName(mSubObj.optString("category_name"));
mSubCategoriesModel.setStrSubCatImage(mSubObj.optString("image"));
mSubCategoriesModel.setIsChecked(false);
alstMoreSubCategories.add(mSubCategoriesModel);
}
// mCategoryModel.setAlstSubCat(alstSubCategory);
}
}
hashmapMoreSubCategories.put(mData.optString("category_id"), alstMoreSubCategories);
}
}
//
// for (int i = 0; i < alstCategory.size(); i++) {
// Log.e("", "Category:::::" + alstCategory.get(i).getCatName());
// }
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setVisibility(View.VISIBLE);
drawerView = (ViewDrawer) findViewById(R.id.drawer);
drawerView.setVisibility(View.VISIBLE);
mOnUpdateListner = (onUpdateListner) drawerView;
mOnUpdateListner.onUpdate();
inItData();
}
}
else
{
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mGetCategoriesAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
mGetCategoriesAsynckTask.execute();
}
}
public void dialogSkipNow(Context context) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(getResources().getString(R.string.app_name));
alertDialogBuilder
.setMessage(getResources().getString(R.string.you_have_not_register_yet))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.register_now), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
Intent intent = new Intent(DealsActivity.this, RegistrationActivity.class);
startActivity(intent);
finish();
}
})
.setNegativeButton(getResources().getString(R.string.register_later), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
// Utils.storeString(Consts.USER_ID, "");
// Utils.storeString(Consts.CUSTOMER_ID, "");
// Utils.storeString(Consts.USER_NAME, "");
// Utils.storeString(Consts.USER_EMAIL, "");
// Utils.storeString(Consts.PROFILE_PIC_URL, "");
// Utils.storeString(Consts.COVER_PIC_URL, "");
Utils.storeBoolean(Consts.SKIP_NOW, true);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return false;
}
return super.onKeyDown(keyCode, event);
}
public void sortDealData(String strSort) {
if (Utils.validateString(strSort)) {
if (alstDeals.size() > 0) {
if (strSort.equalsIgnoreCase("deal_id")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getStart_date().compareTo(object2.getStart_date());
}
});
} else if (strSort.equalsIgnoreCase("deal_name")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getDeal_name().compareTo(object2.getDeal_name());
}
});
} else if (strSort.equalsIgnoreCase("comments")) {
Collections.sort(alstDeals, new Comparator<DealsModle>() {
@Override
public int compare(final DealsModle object1, final DealsModle object2) {
return object1.getPopularity_count().compareTo(object2.getPopularity_count());
}
});
}
}
}
}
public void callLogin(String strUserEmail, String strUserPass) {
ReturnResult retrunResultObj = new ReturnResult() {
@Override
public void resultData(Object object, String tag) {
if (object != null) {
try {
JSONObject jObj = (JSONObject) object;
JSONObject response = jObj.getJSONObject("response");
String status = response.getString("status");
if (status != null) {
if (status.equalsIgnoreCase("1")) {
Utils.storeString(Consts.USER_ID, response.getString("user_id"));
Utils.storeString(Consts.CUSTOMER_ID, response.getString("customer_id"));
Utils.storeString(Consts.USER_NAME, response.getString("full_name"));
Utils.storeString(Consts.USER_EMAIL, response.getString("email"));
Utils.storeString(Consts.PROFILE_PIC_URL, response.getString("profile_image"));
Utils.storeString(Consts.COVER_PIC_URL, response.getString("cover_image"));
Utils.storeBoolean(Consts.SKIP_NOW, false);
Utils.storeBoolean(Consts.IS_LOGIN, true);
} else if (status.equalsIgnoreCase("2")) {
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.email_validation), Toast.LENGTH_SHORT).show();
} else if (status.equalsIgnoreCase("-4"))
AlertMessageLogin(getString(R.string.your_account_has_been_blocked_please_contact_masmas));
else if (status.equalsIgnoreCase("-5"))
AlertMessageLogin(getString(R.string.your_account_has_been_deleted_from_database));
}
//else
// Toast.makeText(DealsActivity.this, getResources().getString(R.string.please_try_again), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
} else {
// Toast.makeText(DealsActivity.this, getString(R.string.please_try_again), Toast.LENGTH_LONG).show();
}
}
};
List<NameValuePair> nameValuePairsParams = new ArrayList<NameValuePair>();
nameValuePairsParams.add(new BasicNameValuePair("email", strUserEmail));
nameValuePairsParams.add(new BasicNameValuePair("password", strUserPass));
nameValuePairsParams.add(new BasicNameValuePair("device_token", "yrr"));
nameValuePairsParams.add(new BasicNameValuePair("ut_id", "2"));
if (new NetworkConnection().checkInternetConnection(this)) {
new PostDataAsync(DealsActivity.this, retrunResultObj, Consts.BASE_URL + "Customer/Login", nameValuePairsParams, "login").execute();
} else {
Toast.makeText(DealsActivity.this, getString(R.string.internet_problem), Toast.LENGTH_LONG).show();
}
}
public void AlertMessageLogin(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg);
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Utils.storeBoolean(Consts.IS_LOGIN, false);
Intent mIntent = new Intent(DealsActivity.this, LoginActivity.class);
startActivity(mIntent);
finish();
}
});
AlertDialog alert11 = builder.show();
alert11.show();
}
@Override
public void onRefresh()
{
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if(isDeal)
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, sub_cat_id, myLat, myLng, nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice_loadmore("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
else
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation_loadmore(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
}
}, 2000);
}
@Override
public void onLoadMore() {
{
mHandler.postDelayed(new Runnable() {
@Override
public void run()
{
isDeal = Utils.sharedPreferences.getBoolean(Consts.IS_DEAL, false);
if(isDeal)
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, sub_cat_id, myLat,myLng,nextStart);
} else if (sub_cat_id.equalsIgnoreCase("")) {
DealsSevice_loadmore("home", cust_id, cat_id, "0", myLat, myLng,nextStart);
} else {
DealsSevice_loadmore("home", cust_id, "0", "0", myLat, myLng,nextStart);
}
}
else
{
if (!cust_id.equalsIgnoreCase("") && !sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location,cat_id,sub_cat_id, myLat, myLng, nextLocationStart);
}
else if (sub_cat_id.equalsIgnoreCase(""))
{
GetAllLocation_loadmore(cust_id, type_location, cat_id, "0", myLat, myLng, nextLocationStart);
}
else
{
GetAllLocation_loadmore(cust_id, type_location, "0", "0", myLat, myLng, nextLocationStart);
}
}
}
}, 2000);
}
}
}
2)Deals Adapter.java
=================
package com.bluegreen.masmas.customer.adapter;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
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.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;
import com.bluegreen.masmas.customer.AsyncTask.AsyncCallListener;
import com.bluegreen.masmas.customer.AsyncTask.LikeAsynckTask;
import com.bluegreen.masmas.customer.R;
import com.bluegreen.masmas.customer.Utility.Consts;
import com.bluegreen.masmas.customer.Utility.Utils;
import com.bluegreen.masmas.customer.model.DealsModle;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import org.json.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* Created by Manisha on 15/10/2015.
*/
public class DealsAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private ArrayList<DealsModle> alstDealsModel;
private Context mContext;
private ArrayList<DealsModle> arraylist;
private boolean islike;
private boolean isSkipNow = false;
public DealsAdapter(Context mContext, ArrayList<DealsModle> alstDealsModel, boolean islike) {
this.mContext = mContext;
this.alstDealsModel = alstDealsModel;
mInflater = LayoutInflater.from(mContext);
this.arraylist = new ArrayList<DealsModle>();
this..addAll(alstDealsModel);
this.islike = islike;
Utils.sharedPreferences = mContext.getSharedPreferences(Utils.PREF_NAME, Context.MODE_MULTI_PROCESS);
isSkipNow = Utils.sharedPreferences.getBoolean(Consts.SKIP_NOW, false);
}
@Override
public int getCount() {
return alstDealsModel.size();
}
arraylist
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
final DealsModle mDealsModel = alstDealsModel.get(i);
final ViewHolder mViewHolder;
if (view == null) {
view = mInflater.inflate(R.layout.deal, null);
mViewHolder = new ViewHolder();
mViewHolder.imgShare = (ImageView) view.findViewById(R.id.imgShare);
mViewHolder.imgLike = (ImageView) view.findViewById(R.id.imgLike);
mViewHolder.imgDeals = (ImageView) view.findViewById(R.id.imgDeals);
mViewHolder.txtdaysLeft = (TextView) view.findViewById(R.id.txtdaysLeft);
mViewHolder.txtItemName = (TextView) view.findViewById(R.id.txtItemName);
mViewHolder.txtDesc = (TextView) view.findViewById(R.id.txtDesc);
mViewHolder.txtOffer = (TextView) view.findViewById(R.id.txtOffer);
mViewHolder.txtReview = (TextView) view.findViewById(R.id.txtReview);
mViewHolder.txtRedeemed = (TextView) view.findViewById(R.id.txtRedeemed);
mViewHolder.mProgressBar = (ProgressBar) view.findViewById(R.id.progressbar);
mViewHolder.ratingBar = (RatingBar) view.findViewById(R.id.rating);
mViewHolder.txtDist = (TextView) view.findViewById(R.id.txtDist);
view.setTag(mViewHolder);
} else {
mViewHolder = (ViewHolder) view.getTag();
}
if (!alstDealsModel.get(i).getDeals_left().equalsIgnoreCase("-1")) {
mViewHolder.txtRedeemed.setVisibility(View.VISIBLE);
if (Utils.validateString(alstDealsModel.get(i).getDeals_left()) && Utils.validateString(alstDealsModel.get(i).getMaximum_redumption())) {
int DealesLeft = ((Integer.parseInt(alstDealsModel.get(i).getMaximum_redumption())) - (Integer.parseInt(alstDealsModel.get(i).getDeals_left())));
mViewHolder.txtRedeemed.setText(DealesLeft +" "+mContext.getResources().getString(R.string.of) + alstDealsModel.get(i).getMaximum_redumption() + " "+mContext.getResources().getString(R.string.redeemed));
} else {
mViewHolder.txtRedeemed.setVisibility(View.INVISIBLE);
}
} else {
mViewHolder.txtRedeemed.setVisibility(View.INVISIBLE);
}
if (Utils.validateString(alstDealsModel.get(i).getDeal_name())) {
mViewHolder.txtItemName.setText(alstDealsModel.get(i).getDeal_name());
} else {
mViewHolder.txtItemName.setText("");
}
if (Utils.validateString(alstDealsModel.get(i).getDistanceKm())) {
mViewHolder.txtDist.setText(alstDealsModel.get(i).getDistanceKm()+" "+mContext.getResources().getString(R.string.km));
} else {
mViewHolder.txtDist.setText("");
}
if (Utils.validateString(alstDealsModel.get(i).getComments())) {
if (Integer.parseInt(alstDealsModel.get(i).getComments()) > 1) {
mViewHolder.txtReview.setText(alstDealsModel.get(i).getComments() +" "+ mContext.getResources().getString(R.string.reviews));
} else {
mViewHolder.txtReview.setText(alstDealsModel.get(i).getComments() + " "+mContext.getResources().getString(R.string.review));
}
} else {
mViewHolder.txtReview.setText("0" +" "+mContext.getResources().getString(R.string.review));
}
if (alstDealsModel.get(i).getAlstLocation() != null) {
if (alstDealsModel.get(i).getAlstLocation().size() > 0) {
if (Utils.validateString(alstDealsModel.get(i).getAlstLocation().get(0).getLocation_name())) {
Log.e("", "Size:::" + alstDealsModel.get(i).getAlstLocation().size());
if ((alstDealsModel.get(i).getAlstLocation().size() - 1) == 0) {
mViewHolder.txtDesc.setText(alstDealsModel.get(i).getAlstLocation().get(0).getLocation_name());
} else {
mViewHolder.txtDesc.setText(alstDealsModel.get(i).getAlstLocation().get(0).getLocation_name() + " +" + (alstDealsModel.get(i).getAlstLocation().size() - 1) + " " + mContext.getResources().getString(R.string.locations));
}
} else {
mViewHolder.txtDesc.setText("");
}
} else {
mViewHolder.txtDesc.setText("");
}
} else {
mViewHolder.txtDesc.setText("");
}
if (Utils.validateString(alstDealsModel.get(i).getRate())) {
int rating = Math.round(Float.parseFloat(alstDealsModel.get(i).getRate()));
String strRating = String.valueOf(rating);
mViewHolder.ratingBar.setRating(Float.parseFloat(strRating));
}
if (Utils.validateString(alstDealsModel.get(i).getDeal_desc())) {
mViewHolder.txtOffer.setText(alstDealsModel.get(i).getDeal_desc());
} else {
mViewHolder.txtOffer.setText("");
}
if(Utils.validateString(alstDealsModel.get(i).getImage())){
mViewHolder.mProgressBar.setVisibility(View.VISIBLE);
}else{
mViewHolder.mProgressBar.setVisibility(View.GONE);
}
if (Utils.validateString(alstDealsModel.get(i).getImage())) {
Picasso.with(mContext).load(alstDealsModel.get(i).getImage()).into(mViewHolder.imgDeals, new Callback() {
@Override
public void onSuccess() {
mViewHolder.mProgressBar.setVisibility(View.GONE);
}
@Override
public void onError() {
mViewHolder.mProgressBar.setVisibility(View.GONE);
}
});
} else {
mViewHolder.mProgressBar.setVisibility(View.GONE);
mViewHolder.imgDeals.setImageResource(R.drawable.list_noimg);
}
if (alstDealsModel.get(i).getIsLike().equalsIgnoreCase("0")) {
mViewHolder.imgLike.setImageResource(R.drawable.like_deselect);
} else {
mViewHolder.imgLike.setImageResource(R.drawable.like_selected);
}
long daysLeft = daycomapare(alstDealsModel.get(i).getEnd_date());
if (daysLeft > 1) {
mViewHolder.txtdaysLeft.setText(String.valueOf(daysLeft) + " "+mContext.getResources().getString(R.string.days_left));
} else {
mViewHolder.txtdaysLeft.setText(String.valueOf(daysLeft) + " "+mContext.getResources().getString(R.string.days_left));
}
mViewHolder.imgShare.setTag(mDealsModel);
mViewHolder.imgShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "http://masmas.org/deal-detail.html?deal_id=" + mDealsModel.getDeal_id());
// intent.putExtra(Intent.EXTRA_TEXT, "http://dev.credencys.com/masmas/deal-detail.html?deal_id=" + mDealsModel.getDeal_id());
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this site!");
mContext.startActivity(Intent.createChooser(intent, "Share"));
}
});
mViewHolder.imgLike.setTag(mDealsModel);
mViewHolder.imgLike.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isSkipNow) {
Utils.SimpleAlertMessage(mContext, mContext.getResources().getString(R.string.you_are_not_register_user));
} else {
DealsModle dealsModle = (DealsModle) view.getTag();
if (!Utils.checkInternetConnection(mContext)) {
Utils.SimpleAlertMessage(mContext, mContext.getResources().getString(R.string.internet_problem));
} else {
String customenr_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
String deal_id = dealsModle.getDeal_id();
String status = dealsModle.getIsLike();
if (status.equalsIgnoreCase("0")) {
status = "1";
} else {
status = "0";
}
LikeUnlikeSevice(customenr_id, deal_id, status, dealsModle, islike);
}
}
}
});
return view;
}
public class ViewHolder {
private ImageView imgShare;
private ImageView imgLike;
private ImageView imgDeals;
private TextView txtRedeemed;
private TextView txtItemName;
private TextView txtdaysLeft;
private TextView txtOffer;
private TextView txtReview;
private TextView txtDesc;
private ProgressBar mProgressBar;
private RatingBar ratingBar;
private TextView txtDist;
}
public static long daycomapare(String strDate) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long days = 0;
Date oldDate = null;
try {
oldDate = dateFormat.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(oldDate);
Date currentDate = new Date();
long diff = oldDate.getTime() - currentDate.getTime();
long seconds = diff / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
days = hours / 24;
return days;
}
public static long daysBetween(Date startDate, Date endDate) {
Calendar sDate = getDatePart(startDate);
Calendar eDate = getDatePart(endDate);
long daysBetween = 0;
while (sDate.before(eDate)) {
sDate.add(Calendar.DAY_OF_MONTH, 1);
daysBetween++;
}
return daysBetween;
}
public static Calendar getDatePart(Date date) {
Calendar cal = Calendar.getInstance(); // get calendar instance
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0); // set hour to midnight
cal.set(Calendar.MINUTE, 0); // set minute in hour
cal.set(Calendar.SECOND, 0); // set second in minute
cal.set(Calendar.MILLISECOND, 0); // set millisecond in second
return cal; // return the date part
}
public void LikeUnlikeSevice(String customenr_id, String deal_id, String status, final DealsModle mDealsModle, final boolean islike) {
LikeAsynckTask mLikeAsynckTask = new LikeAsynckTask(mContext);
mLikeAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
Log.e("result", "result::::::::" + result.toString());
if (result != null) {
try {
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
mDealsModle.setIsLike(mJsonResponse.getString("is_liked"));
int pos = alstDealsModel.indexOf(mDealsModle);
if (islike) {
if (mJsonResponse.getString("is_liked").equalsIgnoreCase("1")) {
alstDealsModel.set(pos, mDealsModle);
} else {
alstDealsModel.remove(mDealsModle);
}
} else {
alstDealsModel.set(pos, mDealsModle);
}
notifyDataSetChanged();
}
}
} catch (Exception e) {
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mLikeAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, customenr_id, deal_id, status);
} else {
mLikeAsynckTask.execute(customenr_id, deal_id, status);
}
}
// Filter Class
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
alstDealsModel.clear();
if (charText.length() == 0) {
alstDealsModel.addAll(arraylist);
} else {
for (DealsModle dm : arraylist) {
if (dm.getDeal_name().toLowerCase(Locale.getDefault()).contains(charText)) {
alstDealsModel.add(dm);
}
}
}
notifyDataSetChanged();
}
}
3)CityAdapter.java
=============
package com.bluegreen.masmas.customer.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bluegreen.masmas.customer.R;
import com.bluegreen.masmas.customer.activities.FilterLocationActivity;
import com.bluegreen.masmas.customer.model.GetCityModel;
import java.util.ArrayList;
/**
* Created by Manisha on 15/10/2015.
*/
public class CityAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater;
private ArrayList<GetCityModel> alstCity;
public CityAdapter(Context mContext, ArrayList<GetCityModel> alstCity) {
this.mContext = mContext;
this.mInflater = LayoutInflater.from(mContext);
this.alstCity = alstCity;
}
@Override
public int getCount() {
return alstCity.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(final int i, View convetView, ViewGroup viewGroup) {
final ViewHolder mViewHolder;
final GetCityModel mGetCityModel = alstCity.get(i);
if(convetView == null) {
convetView = mInflater.inflate(R.layout.merchant_item, null);
mViewHolder = new ViewHolder();
mViewHolder.txtBusiness = (TextView) convetView.findViewById(R.id.txtBisnessName);
mViewHolder.imgCheckBox = (ImageView) convetView.findViewById(R.id.imgCheckBox);
mViewHolder.imgCheckBox.setTag(mGetCityModel);
convetView.setTag(mViewHolder);
} else {
mViewHolder = (ViewHolder) convetView.getTag();
}
if (alstCity.get(i).ischecked() == true) {
mViewHolder.imgCheckBox.setImageResource(R.drawable.ic_checkbox);
} else {
mViewHolder.imgCheckBox.setImageResource(R.drawable.ic_uncheckbox);
}
mViewHolder.txtBusiness.setText(alstCity.get(i).getCity_name());
mViewHolder.imgCheckBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GetCityModel mGetCityModel = (GetCityModel) view.getTag();
if (mGetCityModel.ischecked()) {
FilterLocationActivity.imgCheckAllCity.setImageResource(R.drawable.ic_uncheckbox);
FilterLocationActivity.isCheckAllCity = false;
mGetCityModel.setIschecked(false);
} else {
mGetCityModel.setIschecked(true);
}
int pos = alstCity.indexOf(mGetCityModel);
alstCity.set(pos, mGetCityModel);
notifyDataSetChanged();
}
});
return convetView;
}
public class ViewHolder {
private TextView txtBusiness;
private ImageView imgCheckBox;
}
}
4)FilterActivity.java
=================
package com.bluegreen.masmas.customer.activities;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.bluegreen.masmas.customer.AsyncTask.AsyncCallListener;
import com.bluegreen.masmas.customer.AsyncTask.FilterAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllCityAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllLocationAsynckTask;
import com.bluegreen.masmas.customer.AsyncTask.GetAllMerchantsAsynckTask;
import com.bluegreen.masmas.customer.R;
import com.bluegreen.masmas.customer.Utility.Consts;
import com.bluegreen.masmas.customer.Utility.CustomFont;
import com.bluegreen.masmas.customer.Utility.CustomFontRegular;
import com.bluegreen.masmas.customer.Utility.GPSTracker;
import com.bluegreen.masmas.customer.Utility.LanguageChange;
import com.bluegreen.masmas.customer.Utility.Utils;
import com.bluegreen.masmas.customer.adapter.CityAdapter;
import com.bluegreen.masmas.customer.adapter.LocationAdapter;
import com.bluegreen.masmas.customer.adapter.MerchantAdapter;
import com.bluegreen.masmas.customer.model.DealsModle;
import com.bluegreen.masmas.customer.model.GetCityModel;
import com.bluegreen.masmas.customer.model.GetLocationModel;
import com.bluegreen.masmas.customer.model.LocationModel;
import com.bluegreen.masmas.customer.model.MerchantModel;
import com.bluegreen.masmas.customer.navigation.ViewDrawer;
import com.github.jjobes.slidedatetimepicker.SlideDateTimeListener;
import com.github.jjobes.slidedatetimepicker.SlideDateTimePicker;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
public class FilterActivity extends FragmentActivity implements OnClickListener {
DrawerLayout drawerLayout;
ViewDrawer drawerView;
private ImageView imgMenu;
public static ImageView imgCheckAllBrand, imgCheckAllCity, imgCheckAllLocation;
private TextView txtHeader_deals;
private TextView filterTextView, clearTextView, txtBrands, txtCheckBoxCount, txtPrice, txtStartDate, txtEndDate, txtDate, txtCheckBoxCountCity, txtCity,
txtCheckBoxCountLocation, txtLocation, txtSort;
private Context context;
private SeekBar distanceSeekBar;
private ImageView back, ratingArrowImageView, distanceArrowImageView, timeArrowImageView, imgArrowBrands, imgSortArrow, imgLocationArrow, imgCityArrow,
imgDateArrow, imgPriceArrow;
android.location.Location Location;
// mylocationlistener locationListener;
private RadioGroup timeGroup, radioGroupSort;
private ListView lstBrands, lstLocation, lstCity;
private RadioButton anyTimeRadioButton, past24RadioButton, pastweekRadioButton, rbtnByDate, rbtnByDealName, rbtnByPriority;
private int progressDistance, progressDuration;
private RatingBar ratingBar;
private Float ratings = 0.0f;
private LinearLayout distanceLL;
private LinearLayout ratingLLTitle, distanceLLTitle, timeLLTitle, lytBrands, lytBrandDetail, lytLocation, lytLocationDetail, lytCity, lytCityDetail, lytDate,
lytDateDetail, lytPrice, lytPriceDetail, lytSort;
private ImageView back_icon;
private TextView distancetv, timetv, ratingtv;
private TextView dis_pointer, startDis, end_dis;
float X, X_VALIDITY;
private String myLat = "0.0", myLng = "0.0";
private GPSTracker gps;
public static ArrayList<MerchantModel> alstMerchant = new ArrayList<>();
public static ArrayList<GetLocationModel> alstLocation = new ArrayList<>();
public static ArrayList<GetCityModel> alstCity = new ArrayList<>();
MerchantAdapter mMerchantAdapter;
LocationAdapter mLocationAdapter;
CityAdapter mCityAdapter;
public static Date startdate, enddate;
public static boolean isCheckAllBrands = false, isCheckAllCity = false, isCheckAllLocation;
private boolean is_filter_call = false;
private CheckBox chkLow, chkHigh, chkMedium;
ArrayList<String> priceList = new ArrayList<>();
private String strTime = "", cust_id = "", strstartdate = "", strEnddate = "", price = "", location_id = "", city_id = "", cat_id = "", sub_cat_id = "",
merchant_id = "", strSort = "", strRating = "";
ArrayList<String> alstSelected_price_id = new ArrayList<>();
private boolean isAllBrandCheck = true, isAllCityCheck = true, isAllLocationCheck = true;
private Date currentDate = new Date(System.currentTimeMillis());
private int intLocationCount = 0, intBrandCount = 0, intCityCount = 0;
private String strPrice = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, Context.MODE_MULTI_PROCESS);
String language = Utils.sharedPreferences.getString(Consts.LANGUAGE, Consts.SPANISH);
if (Utils.validateString(language)) {
LanguageChange.setlanguage(this, language);
}
setContentView(R.layout.activity_filter_deals);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.header));
}
inItData();
}
public void inItData() {
Utils.sharedPreferences = this.getSharedPreferences(Utils.PREF_NAME, Context.MODE_MULTI_PROCESS);
gps = new GPSTracker(this);
cust_id = Utils.sharedPreferences.getString(Consts.CUSTOMER_ID, "");
cat_id = Utils.sharedPreferences.getString(Consts.CATEGORY_ID, "0");
sub_cat_id = Utils.sharedPreferences.getString(Consts.SUB_CATEGORY_ID, "0");
is_filter_call = Utils.sharedPreferences.getBoolean(Consts.IS_FILTER_CALL_FIRST, false);
back_icon = (ImageView) findViewById(R.id.back_icon);
ratingArrowImageView = (ImageView) findViewById(R.id.rating_arrow);
distanceArrowImageView = (ImageView) findViewById(R.id.distance_arrow);
//durationArrowImageView = (ImageView) findViewById(R.id.validity_arrow);
timeArrowImageView = (ImageView) findViewById(R.id.time_arrow);
ratingLLTitle = (LinearLayout) findViewById(R.id.ratings_title_ll);
distanceLLTitle = (LinearLayout) findViewById(R.id.distance_title_ll);
// durationLLTitle = (LinearLayout) findViewById(R.id.validity_title_ll);
timeLLTitle = (LinearLayout) findViewById(R.id.time_title_ll);
lytBrands = (LinearLayout) findViewById(R.id.lytBrands);
imgArrowBrands = (ImageView) findViewById(R.id.img_brandArrow);
txtBrands = (TextView) findViewById(R.id.txtBrands);
distanceLL = (LinearLayout) findViewById(R.id.distance_ll);
// durationLL = (LinearLayout) findViewById(R.id.duration_ll);
ratingBar = (RatingBar) findViewById(R.id.ratings);
ratingBar.setStepSize(1);
timeGroup = (RadioGroup) findViewById(R.id.radio_scan);
radioGroupSort = (RadioGroup) findViewById(R.id.radioGroupSort);
filterTextView = (TextView) findViewById(R.id.filter_tv);
clearTextView = (TextView) findViewById(R.id.clear);
anyTimeRadioButton = (RadioButton) findViewById(R.id.any_time);
past24RadioButton = (RadioButton) findViewById(R.id.past_24);
pastweekRadioButton = (RadioButton) findViewById(R.id.past_week);
dis_pointer = (TextView) findViewById(R.id.distance_pointer_txt);
startDis = (TextView) findViewById(R.id.start_dis);
// startDutration = (CustomFont) findViewById(R.id.start_day);
end_dis = (TextView) findViewById(R.id.end_dis);
// end_duration = (CustomFont) findViewById(R.id.end_duration);
anyTimeRadioButton.setTag("0");
past24RadioButton.setTag("1");
pastweekRadioButton.setTag("2");
rbtnByDate = (RadioButton) findViewById(R.id.rbtnByDate);
rbtnByDealName = (RadioButton) findViewById(R.id.rbtnByDealName);
rbtnByPriority = (RadioButton) findViewById(R.id.rbtnByPriority);
rbtnByDate.setTag("0");
rbtnByDealName.setTag("1");
rbtnByPriority.setTag("2");
distanceSeekBar = (SeekBar) findViewById(R.id.distance_seekbar);
// durationSeekBar = (SeekBar) findViewById(R.id.duration_seekbar);
distancetv = (TextView) findViewById(R.id.distance);
ratingtv = (TextView) findViewById(R.id.ratings_txt);
timetv = (TextView) findViewById(R.id.time);
// validitytv = (CustomFont) findViewById(R.id.validity_txt);
// validity_pointer = (CustomFont) findViewById(R.id.validity_pointer);
lytBrandDetail = (LinearLayout) findViewById(R.id.lytBrandDetail);
txtCheckBoxCount = (TextView) findViewById(R.id.txtCheckBoxCount);
imgCheckAllBrand = (ImageView) findViewById(R.id.imgCheckAllBrand);
imgCheckAllBrand.setOnClickListener(this);
chkLow = (CheckBox) findViewById(R.id.chkLow);
chkMedium = (CheckBox) findViewById(R.id.chkMedium);
chkHigh = (CheckBox) findViewById(R.id.chkHigh);
txtPrice = (TextView) findViewById(R.id.txtPrice);
txtCity = (TextView) findViewById(R.id.txtCity);
txtStartDate = (TextView) findViewById(R.id.txtStartDate);
txtStartDate.setOnClickListener(this);
txtEndDate = (TextView) findViewById(R.id.txtEndDate);
txtEndDate.setOnClickListener(this);
txtDate = (TextView) findViewById(R.id.txtDate);
txtCheckBoxCountCity = (TextView) findViewById(R.id.txtCheckBoxCountCity);
txtCheckBoxCountLocation = (TextView) findViewById(R.id.txtCheckBoxCountLocation);
txtLocation = (TextView) findViewById(R.id.txtLocation);
txtSort = (TextView) findViewById(R.id.txtSort);
imgSortArrow = (ImageView) findViewById(R.id.imgSortArrow);
imgLocationArrow = (ImageView) findViewById(R.id.imgLocationArrow);
imgCityArrow = (ImageView) findViewById(R.id.imgCityArrow);
imgCheckAllCity = (ImageView) findViewById(R.id.imgCheckAllCity);
imgCheckAllCity.setOnClickListener(this);
imgCheckAllLocation = (ImageView) findViewById(R.id.imgCheckAllLocation);
imgCheckAllLocation.setOnClickListener(this);
imgDateArrow = (ImageView) findViewById(R.id.imgDateArrow);
imgPriceArrow = (ImageView) findViewById(R.id.imgPriceArrow);
lytLocation = (LinearLayout) findViewById(R.id.lytLocation);
lytLocationDetail = (LinearLayout) findViewById(R.id.lytLocationDetail);
lytCity = (LinearLayout) findViewById(R.id.lytCity);
lytCityDetail = (LinearLayout) findViewById(R.id.lytCityDetail);
lytDate = (LinearLayout) findViewById(R.id.lytDate);
lytDate.setOnClickListener(this);
lytDateDetail = (LinearLayout) findViewById(R.id.lytDateDetail);
lytPrice = (LinearLayout) findViewById(R.id.lytPrice);
lytPrice.setOnClickListener(this);
lytPriceDetail = (LinearLayout) findViewById(R.id.lytPriceDetail);
lytSort = (LinearLayout) findViewById(R.id.lytSort);
lytSort.setOnClickListener(this);
lstBrands = (ListView) findViewById(R.id.lstBrands);
mMerchantAdapter = new MerchantAdapter(FilterActivity.this, alstMerchant);
lstBrands.setAdapter(mMerchantAdapter);
lstLocation = (ListView) findViewById(R.id.lstLocation);
mLocationAdapter = new LocationAdapter(FilterActivity.this, alstLocation);
lstLocation.setAdapter(mLocationAdapter);
lstCity = (ListView) findViewById(R.id.lstCity);
mCityAdapter = new CityAdapter(FilterActivity.this, alstCity);
lstCity.setAdapter(mCityAdapter);
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
ratings = rating;
Log.v("rating", "rating" + rating);
}
});
// price = "";
// if (price != null) {
// priceList = new ArrayList<String>(Arrays.asList(price.split(",")));
// if (priceList.contains("1")) {
// chkLow.setChecked(true);
// }
// if (priceList.contains("2")) {
// chkMedium.setChecked(true);
// }
// if (priceList.contains("3")) {
// chkHigh.setChecked(true);
// }
// }
distanceSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
progressDistance = progresValue;
int val = (progresValue * (seekBar.getWidth() - 2 * seekBar.getThumbOffset())) / seekBar.getMax();
Log.v("chng", "chng" + seekBar.getThumbOffset() + " " + seekBar.getX() + val + seekBar.getThumbOffset() / 2);
positionThumbLabel(distanceSeekBar, dis_pointer, progresValue);
// distanceSeekBar.setThumb(writeOnDrawable(R.drawable.btn_radio, progressDistance+""));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.v("seek", "seek" + progressDistance + "/" + seekBar.getMax());
}
});
// durationSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
// int progress = 0;
// @Override
// public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
// progressDuration = progresValue;
// positionValidityThumbLabel(durationSeekBar, validity_pointer, progresValue);
// }
// @Override
// public void onStartTrackingTouch(SeekBar seekBar) {
// }
//
// @Override
// public void onStopTrackingTouch(SeekBar seekBar) {
// Log.v("seek", "duration SeekBar" + progressDuration + "/" + seekBar.getMax());
// }
// });
filterTextView.setOnClickListener(this);
clearTextView.setOnClickListener(this);
ratingLLTitle.setOnClickListener(this);
// durationLLTitle.setOnClickListener(this);
distanceLLTitle.setOnClickListener(this);
timeLLTitle.setOnClickListener(this);
lytBrands.setOnClickListener(this);
lytLocation.setOnClickListener(this);
lytCity.setOnClickListener(this);
back_icon.setOnClickListener(this);
// gps = new GPSTracker(this);
// if (gps.getIsGPSTrackingEnabled()) {
// myLat = String.valueOf(gps.getLatitude());
// myLng = String.valueOf(gps.getLongitude());
// }
// GPSTracker gps = new GPSTracker(FilterActivity.this);
if (gps.getIsGPSTrackingEnabled()) {
myLat = String.valueOf(gps.getLatitude());
myLng = String.valueOf(gps.getLongitude());
// myLat = "23.012658";
// myLng = "72.521739";
// Log.e("", "Filter myLat:::" + myLat);
// Log.e("", "Filter myLng:::" + myLng);
}
is_filter_call = Utils.sharedPreferences.getBoolean(Consts.IS_FILTER_CALL_FIRST, false);
if (!is_filter_call) {
GetAllMerchants();
GetAllCity();
GetAllLocation("0", "home", "", "","-1");
Utils.storeBoolean(Consts.IS_FILTER_CALL_FIRST, true);
}
getdatafrompref();
}
//Getdata from preferences
public void getdatafrompref() {
strSort = Utils.sharedPreferences.getString(Consts.SORT_FILTER, "");
strRating = Utils.sharedPreferences.getString(Consts.RATING_FILTER, "");
strTime = Utils.sharedPreferences.getString(Consts.TIME_FILTER, "");
if (Utils.validateString(Utils.sharedPreferences.getString(Consts.DISTANCE_FILTER, ""))) {
progressDistance = Integer.parseInt(Utils.sharedPreferences.getString(Consts.DISTANCE_FILTER, ""));
} else {
progressDistance = 0;
}
if (Utils.validateString(Utils.sharedPreferences.getString(Consts.RATING_FILTER, ""))) {
float rating = Float.parseFloat(Utils.sharedPreferences.getString(Consts.RATING_FILTER, ""));
if (rating > 0.0) {
ratingBar.setRating(rating);
ratingLLTitle.setVisibility(View.VISIBLE);
onRatingLlClicked();
}
} else {
ratingBar.setRating(0);
}
merchant_id = Utils.sharedPreferences.getString(Consts.MERCHANT_ID_FILTER, "");
city_id = Utils.sharedPreferences.getString(Consts.CITY_ID_FILTER, "");
location_id = Utils.sharedPreferences.getString(Consts.LOCATION_ID_FILTER, "");
strstartdate = Utils.sharedPreferences.getString(Consts.START_DATE_FILTER, "");
strEnddate = Utils.sharedPreferences.getString(Consts.END_DATE_FILTER, "");
price = "";
price = Utils.sharedPreferences.getString(Consts.PRICE_FILTER, "");
isAllBrandCheck = Utils.sharedPreferences.getBoolean(Consts.IS_ALL_BRANDS_CHECK, false);
isAllCityCheck = Utils.sharedPreferences.getBoolean(Consts.IS_ALL_CITY_CHECK, false);
isAllLocationCheck = Utils.sharedPreferences.getBoolean(Consts.IS_ALL_LOCATION_CHECK, false);
if (Utils.validateString(strSort)) {
lytSort.setVisibility(View.VISIBLE);
onSortLlClciked();
if (strSort.equalsIgnoreCase("deal_id")) {
rbtnByDate.setChecked(true);
} else if (strSort.equalsIgnoreCase("deal_name")) {
rbtnByDealName.setChecked(true);
} else if (strSort.equalsIgnoreCase("comments")) {
rbtnByPriority.setChecked(true);
}
}
if (Utils.validateString(strTime)) {
timeLLTitle.setVisibility(View.VISIBLE);
onTimeLlClciked();
if (strTime.equalsIgnoreCase("0")) {
anyTimeRadioButton.setChecked(true);
} else if (strTime.equalsIgnoreCase("1")) {
past24RadioButton.setChecked(true);
} else if (strTime.equalsIgnoreCase("2")) {
pastweekRadioButton.setChecked(true);
}
}
if (Utils.validateString(String.valueOf(progressDistance))) {
distanceLL.setVisibility(View.VISIBLE);
onDistanceLLClicked();
distanceSeekBar.setProgress(progressDistance);
}
if (Utils.validateString(merchant_id)) {
lytBrandDetail.setVisibility(View.GONE);
onBrandLLClciked();
}
if (Utils.validateString(city_id)) {
lytCityDetail.setVisibility(View.GONE);
onCityClciked();
}
if (Utils.validateString(location_id)) {
lytLocationDetail.setVisibility(View.GONE);
onLocationClciked();
}
if (Utils.validateString(strstartdate) && Utils.validateString(strEnddate)) {
lytDateDetail.setVisibility(View.GONE);
ondateClciked();
}
if (Utils.validateString(price)) {
Log.e("", "price:::" + price);
lytPriceDetail.setVisibility(View.GONE);
onPriceClciked();
priceList.clear();
priceList = new ArrayList<String>(Arrays.asList(price.split(",")));
if (priceList.contains("1")) {
chkLow.setChecked(true);
}
if (priceList.contains("2")) {
chkMedium.setChecked(true);
}
if (priceList.contains("3")) {
chkHigh.setChecked(true);
}
}
chkLow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
if (!priceList.contains("1"))
priceList.add("1");
} else {
priceList.remove("1");
}
}
});
chkMedium.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
if (!priceList.contains("2"))
priceList.add("2");
} else {
// if (!priceList.contains("1"))
priceList.remove("2");
}
}
});
chkHigh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
if (!priceList.contains("3"))
priceList.add("3");
} else {
priceList.remove("3");
}
}
});
if (isCheckAllBrands) {
imgCheckAllBrand.setImageResource(R.drawable.ic_checkbox);
} else {
imgCheckAllBrand.setImageResource(R.drawable.ic_uncheckbox);
}
if (isCheckAllCity) {
imgCheckAllCity.setImageResource(R.drawable.ic_checkbox);
} else {
imgCheckAllCity.setImageResource(R.drawable.ic_uncheckbox);
}
if (isCheckAllLocation) {
imgCheckAllLocation.setImageResource(R.drawable.ic_checkbox);
} else {
imgCheckAllLocation.setImageResource(R.drawable.ic_uncheckbox);
}
}
@Override
public void onClick(View v) {
if (v == filterTextView) {
int selectedId = timeGroup.getCheckedRadioButtonId();
RadioButton radioTimeButton = (RadioButton) findViewById(selectedId);
int intSelectedSort = radioGroupSort.getCheckedRadioButtonId();
RadioButton radioSort = (RadioButton) findViewById(intSelectedSort);
price = "";
strPrice = "";
if (priceList != null) {
if (priceList.size() > 0) {
for (int i = 0; i < priceList.size(); i++) {
if (price.equalsIgnoreCase("")) {
price = priceList.get(i).toString();
if (priceList.get(i).toString().equalsIgnoreCase("1")) {
strPrice = getResources().getString(R.string.low);
} else if (priceList.get(i).toString().equalsIgnoreCase("2")) {
strPrice = getResources().getString(R.string.medium);
} else if (priceList.get(i).toString().equalsIgnoreCase("3")) {
strPrice = getResources().getString(R.string.high);
}
} else {
price = price + "," + priceList.get(i).toString();
if (priceList.get(i).toString().equalsIgnoreCase("1")) {
strPrice = strPrice + "," + getResources().getString(R.string.low);
} else if (priceList.get(i).toString().equalsIgnoreCase("2")) {
strPrice = strPrice + "," + getResources().getString(R.string.medium);
} else if (priceList.get(i).toString().equalsIgnoreCase("3")) {
strPrice = strPrice + "," + getResources().getString(R.string.high);
}
}
}
}
}
merchant_id = "";
if (alstMerchant != null) {
if (alstMerchant.size() > 0) {
intBrandCount=0;
for (int i = 0; i < alstMerchant.size(); i++) {
if (alstMerchant.get(i).isChecked() == true) {
intBrandCount++;
if (merchant_id.equalsIgnoreCase("")) {
merchant_id = alstMerchant.get(i).getM_id();
} else {
merchant_id = merchant_id + "," + alstMerchant.get(i).getM_id();
}
}
}
}
}
location_id = "";
if (alstLocation != null) {
if (alstLocation.size() > 0) {
intLocationCount=0;
for (int i = 0; i < alstLocation.size(); i++) {
if (alstLocation.get(i).ischecked() == true) {
intLocationCount++;
if (location_id.equalsIgnoreCase("")) {
location_id = alstLocation.get(i).getLocation_id();
} else {
location_id = location_id + "," + alstLocation.get(i).getLocation_id();
}
}
}
}
}
Log.e("", "Location ID::: " + location_id);
city_id = "";
if (alstCity != null) {
if (alstCity.size() > 0) {
intCityCount=0;
for (int i = 0; i < alstCity.size(); i++) {
if (alstCity.get(i).ischecked() == true) {
intCityCount++;
if (city_id.equalsIgnoreCase("")) {
city_id = alstCity.get(i).getCity_id();
} else {
city_id = city_id + "," + alstCity.get(i).getCity_id();
}
}
}
}
}
Log.e("", "city::: " + city_id);
strstartdate = txtStartDate.getText().toString().trim();
if (strstartdate.equalsIgnoreCase(getResources().getString(R.string.start_date))) {
strstartdate = "";
}
strEnddate = txtEndDate.getText().toString().trim();
if (strEnddate.equalsIgnoreCase(getResources().getString(R.string.end_date))) {
strEnddate = "";
}
if (radioSort.getTag().toString().equalsIgnoreCase("0")) {
strSort = "deal_id";
} else if (radioSort.getTag().toString().equalsIgnoreCase("1")) {
strSort = "deal_name";
} else if (radioSort.getTag().toString().equalsIgnoreCase("2")) {
strSort = "comments";
} else {
strSort = "";
}
if (!checkIfAnyFieldApplied()) {
Intent intent = new Intent(FilterActivity.this, DealsActivity.class);
startActivity(intent);
finish();
} else {
Utils.storeString(Consts.SORT_FILTER, strSort);
Utils.storeString(Consts.RATING_FILTER, String.valueOf(ratings));
Utils.storeString(Consts.TIME_FILTER, radioTimeButton.getTag().toString());
Utils.storeString(Consts.DISTANCE_FILTER, String.valueOf(progressDistance));
Utils.storeString(Consts.MERCHANT_ID_FILTER, merchant_id);
Utils.storeString(Consts.CITY_ID_FILTER, city_id);
Utils.storeString(Consts.LOCATION_ID_FILTER, location_id);
Utils.storeString(Consts.START_DATE_FILTER, strstartdate);
Utils.storeString(Consts.END_DATE_FILTER, strEnddate);
Utils.storeString(Consts.PRICE_FILTER, price);
if (isAllBrandCheck) {
Utils.storeBoolean(Consts.IS_ALL_BRANDS_CHECK, false);
} else {
Utils.storeBoolean(Consts.IS_ALL_BRANDS_CHECK, true);
}
if (isAllCityCheck) {
Utils.storeBoolean(Consts.IS_ALL_CITY_CHECK, false);
} else {
Utils.storeBoolean(Consts.IS_ALL_CITY_CHECK, true);
}
if (isAllLocationCheck) {
Utils.storeBoolean(Consts.IS_ALL_LOCATION_CHECK, false);
} else {
Utils.storeBoolean(Consts.IS_ALL_LOCATION_CHECK, true);
}
Log.e("", "strSort ::: " + strSort);
Log.e("", "ratings:::;" + String.valueOf(ratings));
Log.e("", "time:::" + radioTimeButton.getTag().toString());
Log.e("", "Lat:::" + myLat);
Log.e("", "Lng:::" + myLng);
Log.e("", "Distance:::" + String.valueOf(progressDistance));
Log.e("", "cust_id:::" + cust_id);
Log.e("", "merchant_id:::" + merchant_id);
Log.e("", "location_id:::" + location_id);
Log.e("", "city_id" + city_id);
Log.e("", "strstartdate::;" + strstartdate);
Log.e("", "strEnddate:::" + strEnddate);
Log.e("", "cat_id::;" + cat_id);
Log.e("", "sub_cat_id:::" + sub_cat_id);
Log.e("", "price ::: " + price);
//FilterSevice(String.valueOf(ratings), radioTimeButton.getTag().toString(), String.valueOf(progressDuration), "-0.139373", "-78.488532", "100", cust_id, merchant_id);
if (!Utils.checkInternetConnection(this)) {
Utils.SimpleAlertMessage(this, getResources().getString(R.string.internet_problem));
} else {
FilterSevice(String.valueOf(ratings), radioTimeButton.getTag().toString(), myLat, myLng, String.valueOf(progressDistance), cust_id,
merchant_id, location_id, city_id, strstartdate, strEnddate, strSort, cat_id, sub_cat_id, price);
}
}
} else if (v == back_icon) {
Intent intent = new Intent(FilterActivity.this, DealsActivity.class);
startActivity(intent);
finish();
} else if (v == clearTextView) {
priceList.clear();
ratingBar.setRating(0);
distanceSeekBar.setProgress(0);
rbtnByDate.setChecked(true);
anyTimeRadioButton.setChecked(true);
//durationSeekBar.setProgress(0);
((RadioButton) timeGroup.getChildAt(0)).setChecked(true);
((RadioButton) radioGroupSort.getChildAt(0)).setChecked(true);
closeView();
imgCheckAllBrand.setImageResource(R.drawable.ic_uncheckbox);
for (int i = 0; i < alstMerchant.size(); i++) {
alstMerchant.get(i).setIsChecked(false);
}
isCheckAllBrands = false;
mMerchantAdapter.notifyDataSetChanged();
imgCheckAllLocation.setImageResource(R.drawable.ic_uncheckbox);
for (int i = 0; i < alstLocation.size(); i++) {
alstLocation.get(i).setIschecked(false);
}
isCheckAllLocation = false;
mLocationAdapter.notifyDataSetChanged();
imgCheckAllCity.setImageResource(R.drawable.ic_uncheckbox);
for (int i = 0; i < alstCity.size(); i++) {
alstCity.get(i).setIschecked(false);
}
isCheckAllCity = false;
mCityAdapter.notifyDataSetChanged();
txtStartDate.setText(getResources().getString(R.string.start_date_time));
txtEndDate.setText(getResources().getString(R.string.end_date_time));
// alstLocation.clear();
// alstCity.clear();
// priceList.clear();
price = "";
city_id = "";
merchant_id = "";
location_id = "";
city_id = "";
progressDistance = 0;
Utils.storeBoolean(Consts.IS_ALL_CITY_CHECK, false);
Utils.storeString(Consts.RATING_FILTER, String.valueOf(0.0));
Utils.storeString(Consts.DISTANCE_FILTER, String.valueOf(progressDistance));
Utils.storeString(Consts.PRICE_FILTER, price);
Utils.storeString(Consts.START_DATE_FILTER, "");
Utils.storeString(Consts.END_DATE_FILTER, "");
Utils.storeString(Consts.MERCHANT_ID_FILTER, merchant_id);
Utils.storeString(Consts.CITY_ID_FILTER, city_id);
Utils.storeString(Consts.LOCATION_ID_FILTER, location_id);
chkHigh.setChecked(false);
chkMedium.setChecked(false);
chkLow.setChecked(false);
// sessionManager.clearFilter();
} else if (v == ratingLLTitle) {
onRatingLlClicked();
// } else if (v == durationLLTitle) {
// onDurationLLClicked();
} else if (v == distanceLLTitle) {
onDistanceLLClicked();
} else if (v == timeLLTitle) {
onTimeLlClciked();
} else if (v == lytBrands) {
onBrandLLClciked();
} else if (v == imgCheckAllBrand) {
if (isCheckAllBrands) {
imgCheckAllBrand.setImageResource(R.drawable.ic_uncheckbox);
for (int i = 0; i < alstMerchant.size(); i++) {
alstMerchant.get(i).setIsChecked(false);
}
isCheckAllBrands = false;
} else {
imgCheckAllBrand.setImageResource(R.drawable.ic_checkbox);
for (int i = 0; i < alstMerchant.size(); i++) {
alstMerchant.get(i).setIsChecked(true);
}
isCheckAllBrands = true;
}
mMerchantAdapter.notifyDataSetChanged();
} else if (v == imgCheckAllLocation) {
if (isCheckAllLocation) {
imgCheckAllLocation.setImageResource(R.drawable.ic_uncheckbox);
for (int i = 0; i < alstLocation.size(); i++) {
alstLocation.get(i).setIschecked(false);
}
isCheckAllLocation = false;
} else {
imgCheckAllLocation.setImageResource(R.drawable.ic_checkbox);
for (int i = 0; i < alstLocation.size(); i++) {
alstLocation.get(i).setIschecked(true);
}
isCheckAllLocation = true;
}
mLocationAdapter.notifyDataSetChanged();
} else if (v == imgCheckAllCity) {
if (isCheckAllCity) {
imgCheckAllCity.setImageResource(R.drawable.ic_uncheckbox);
for (int i = 0; i < alstCity.size(); i++) {
alstCity.get(i).setIschecked(false);
}
isCheckAllCity = false;
} else {
imgCheckAllCity.setImageResource(R.drawable.ic_checkbox);
for (int i = 0; i < alstCity.size(); i++) {
alstCity.get(i).setIschecked(true);
}
isCheckAllCity = true;
}
mCityAdapter.notifyDataSetChanged();
} else if (v == lytSort) {
onSortLlClciked();
} else if (v == lytLocation) {
onLocationClciked();
} else if (v == lytCity) {
onCityClciked();
} else if (v == lytDate) {
ondateClciked();
} else if (v == txtStartDate) {
new SlideDateTimePicker.Builder(this.getSupportFragmentManager())
.setListener(Datelistener)
.setInitialDate(new Date())
.setMaxDate(currentDate)
.build()
.show();
} else if (v == txtEndDate) {
new SlideDateTimePicker.Builder(this.getSupportFragmentManager())
.setListener(EndDatelistener)
// .setMaxDate(4-4-16);
.setMinDate(currentDate)
.setInitialDate(new Date())
.build()
.show();
} else if (v == lytPrice) {
onPriceClciked();
}
}
SlideDateTimeListener Datelistener = new SlideDateTimeListener() {
@Override
public void onDateTimeSet(Date date) {
// Do something with the date. This Date object contains
// the date and time that the user has selected.
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
strstartdate = formatter.format(date);
System.out.println(".....Date..." + strstartdate);
txtStartDate.setText(strstartdate);
startdate = date;
// strstartdate = txtStartDate.getText().toString();
Log.v("date", "date" + date);
}
@Override
public void onDateTimeCancel() {
// Overriding onDateTimeCancel() is optional.
}
};
SlideDateTimeListener EndDatelistener = new SlideDateTimeListener() {
@Override
public void onDateTimeSet(Date date) {
// Do something with the date. This Date object contains
// the date and time that the user has selected.
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
strEnddate = formatter.format(date);
if (isDateAfter(strstartdate, strEnddate)) {
txtEndDate.setText(strEnddate);
} else {
Toast.makeText(FilterActivity.this, getResources().getString(R.string.start_date_should_not_greater_then_end_date), Toast.LENGTH_SHORT).show();
txtEndDate.setText(getResources().getString(R.string.end_date_time));
}
enddate = date;
}
@Override
public void onDateTimeCancel() {
// Overriding onDateTimeCancel() is optional.
}
};
public static boolean isDateAfter(String startDate, String endDate) {
try {
String myFormatString = "yyyy-MM-dd HH:mm";
SimpleDateFormat df = new SimpleDateFormat(myFormatString);
Date date1 = df.parse(endDate);
Date startingDate = df.parse(startDate);
if (date1.after(startingDate))
return true;
else
return false;
} catch (Exception e) {
return false;
}
}
private Boolean checkIfAnyFieldApplied() {
int selectedId = timeGroup.getCheckedRadioButtonId();
boolean isUpdatedBrand = false;
// if (alstMerchant.size() > 0) {
// for (int i = 0; i < alstMerchant.size(); i++) {
// if (alstMerchant.get(i).isChecked()) {
// isUpdatedBrand = true;
// break;
// }
// }
// }
RadioButton radioSexButton = (RadioButton) findViewById(selectedId);
Log.v("##", "ratings" + ratings + " " + progressDistance + " " + progressDuration + " " + Integer.parseInt(radioSexButton.getTag().toString()));
if (ratings > 0.0)
return true;
if (progressDistance > 0)
return true;
// if (progressDuration > 0)
// return true;
if (Integer.parseInt(radioSexButton.getTag().toString()) > 0)
return true;
if (merchant_id.length() > 0)
return true;
if (location_id.length() > 0)
return true;
if (city_id.length() > 0)
return true;
if (strSort.length() > 0)
return true;
if (price.length() > 0)
return true;
if (txtStartDate.length() > 0)
return true;
if (txtEndDate.length() > 0)
return true;
if (Integer.parseInt(radioSexButton.getTag().toString()) > 0)
return true;
else
return false;
}
void onSortLlClciked() {
if (radioGroupSort.getVisibility() == View.GONE) {
radioGroupSort.setVisibility(View.VISIBLE);
imgSortArrow.setImageResource(R.drawable.filt_down);
lytSort.setBackgroundColor(Color.parseColor("#555555"));
txtSort.setTextColor(Color.parseColor("#ffffff"));
} else {
radioGroupSort.setVisibility(View.GONE);
timeArrowImageView.setImageResource(R.drawable.filt_right);
lytSort.setBackgroundColor(Color.parseColor("#ffffff"));
txtSort.setTextColor(Color.parseColor("#000000"));
}
}
void onRatingLlClicked() {
if (ratingBar.getVisibility() == View.GONE) {
ratingBar.setVisibility(View.VISIBLE);
ratingArrowImageView.setImageResource(R.drawable.filt_down);
ratingLLTitle.setBackgroundColor(Color.parseColor("#555555"));
ratingtv.setTextColor(Color.parseColor("#ffffff"));
} else {
ratingBar.setVisibility(View.GONE);
ratingArrowImageView.setImageResource(R.drawable.filt_right);
ratingLLTitle.setBackgroundColor(Color.parseColor("#ffffff"));
ratingtv.setTextColor(Color.parseColor("#000000"));
}
}
void onDistanceLLClicked() {
if (distanceLL.getVisibility() == View.GONE) {
distanceLL.setVisibility(View.VISIBLE);
distanceArrowImageView.setImageResource(R.drawable.filt_down);
distanceLLTitle.setBackgroundColor(Color.parseColor("#555555"));
distancetv.setTextColor(Color.parseColor("#ffffff"));
} else {
distanceLL.setVisibility(View.GONE);
distanceArrowImageView.setImageResource(R.drawable.filt_right);
distanceLLTitle.setBackgroundColor(Color.parseColor("#ffffff"));
distancetv.setTextColor(Color.parseColor("#000000"));
}
}
void onTimeLlClciked() {
if (timeGroup.getVisibility() == View.GONE) {
timeGroup.setVisibility(View.VISIBLE);
timeArrowImageView.setImageResource(R.drawable.filt_down);
timeLLTitle.setBackgroundColor(Color.parseColor("#555555"));
timetv.setTextColor(Color.parseColor("#ffffff"));
} else {
timeGroup.setVisibility(View.GONE);
timeArrowImageView.setImageResource(R.drawable.filt_right);
timeLLTitle.setBackgroundColor(Color.parseColor("#ffffff"));
timetv.setTextColor(Color.parseColor("#000000"));
}
}
void onBrandLLClciked() {
if (lytBrandDetail.getVisibility() == View.GONE) {
lytBrandDetail.setVisibility(View.VISIBLE);
imgArrowBrands.setImageResource(R.drawable.filt_down);
lytBrands.setBackgroundColor(Color.parseColor("#555555"));
txtBrands.setTextColor(Color.parseColor("#ffffff"));
// GetAllMerchants();
} else {
lytBrandDetail.setVisibility(View.GONE);
imgArrowBrands.setImageResource(R.drawable.filt_right);
lytBrands.setBackgroundColor(Color.parseColor("#ffffff"));
txtBrands.setTextColor(Color.parseColor("#000000"));
}
}
void onLocationClciked() {
if (lytLocationDetail.getVisibility() == View.GONE) {
lytLocationDetail.setVisibility(View.VISIBLE);
imgLocationArrow.setImageResource(R.drawable.filt_down);
lytLocation.setBackgroundColor(Color.parseColor("#555555"));
txtLocation.setTextColor(Color.parseColor("#ffffff"));
// GetAllLocation("0","home","","");
} else {
lytLocationDetail.setVisibility(View.GONE);
imgLocationArrow.setImageResource(R.drawable.filt_right);
lytLocation.setBackgroundColor(Color.parseColor("#ffffff"));
txtLocation.setTextColor(Color.parseColor("#000000"));
}
}
void onCityClciked() {
if (lytCityDetail.getVisibility() == View.GONE) {
lytCityDetail.setVisibility(View.VISIBLE);
imgCityArrow.setImageResource(R.drawable.filt_down);
lytCity.setBackgroundColor(Color.parseColor("#555555"));
txtCity.setTextColor(Color.parseColor("#ffffff"));
// GetAllCity();
} else {
lytCityDetail.setVisibility(View.GONE);
imgCityArrow.setImageResource(R.drawable.filt_right);
lytCity.setBackgroundColor(Color.parseColor("#ffffff"));
txtCity.setTextColor(Color.parseColor("#000000"));
}
}
void ondateClciked() {
if (lytDateDetail.getVisibility() == View.GONE) {
lytDateDetail.setVisibility(View.VISIBLE);
imgDateArrow.setImageResource(R.drawable.filt_down);
lytDate.setBackgroundColor(Color.parseColor("#555555"));
txtDate.setTextColor(Color.parseColor("#ffffff"));
} else {
lytDateDetail.setVisibility(View.GONE);
imgDateArrow.setImageResource(R.drawable.filt_right);
lytDate.setBackgroundColor(Color.parseColor("#ffffff"));
txtDate.setTextColor(Color.parseColor("#000000"));
}
}
void onPriceClciked() {
if (lytPriceDetail.getVisibility() == View.GONE) {
lytPriceDetail.setVisibility(View.VISIBLE);
imgPriceArrow.setImageResource(R.drawable.filt_down);
lytPrice.setBackgroundColor(Color.parseColor("#555555"));
txtPrice.setTextColor(Color.parseColor("#ffffff"));
} else {
lytPriceDetail.setVisibility(View.GONE);
imgPriceArrow.setImageResource(R.drawable.filt_right);
lytPrice.setBackgroundColor(Color.parseColor("#ffffff"));
txtPrice.setTextColor(Color.parseColor("#000000"));
}
}
String strFilter = "";
public void FilterSevice(final String rate, String time,
String latitude, String longitude, String distance,
String customer_id, String merchant_id, String location_id, String city_id, String start_date, String end_date, String sort,
String category_id, String sub_cat_id, String price_type) {
FilterAsynckTask mFilterAsynckTask = new FilterAsynckTask(this);
mFilterAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("filter", "Filter::::::::" + result.toString());
try {
DealsModle dealsModle = null;
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
String strFilter = "";
if (Utils.validateString(strSort)) {
String strSorted = "";
if (strSort.equalsIgnoreCase("deal_id")) {
strSorted = getResources().getString(R.string.by_date);
} else if (strSort.equalsIgnoreCase("deal_name")) {
strSorted = getResources().getString(R.string.by_deal_name);
} else if (strSort.equalsIgnoreCase("comments")) {
strSorted = getResources().getString(R.string.by_popularity);
}
strFilter = "Sort:" + strSorted;
}
if (ratings > 0.0) {
if (Utils.validateString(strFilter)) {
strFilter = strFilter + "," +"Rate:" + String.valueOf(ratings);
} else {
strFilter = "Rate:" + String.valueOf(ratings);
}
}
int selectedId = timeGroup.getCheckedRadioButtonId();
RadioButton radioTimeButton = (RadioButton) findViewById(selectedId);
if (Utils.validateString(strFilter)) {
strFilter = strFilter+"," + "Time:" + radioTimeButton.getText().toString();
} else {
strFilter = "Time:" + radioTimeButton.getText().toString();
}
if(progressDistance > 0) {
if (Utils.validateString(strFilter)) {
strFilter = strFilter+"," +"Duration:" + String.valueOf(progressDistance);
} else {
strFilter = "Duration:" + String.valueOf(progressDistance);
}
}
if(intBrandCount > 0) {
if (Utils.validateString(strFilter)) {
strFilter = strFilter+"," +"Brand:" + intBrandCount;
} else {
strFilter = "Brand:" + intBrandCount;
}
}
if(intLocationCount > 0) {
if (Utils.validateString(strFilter)) {
strFilter = strFilter+"," +"Location:" + intLocationCount;
} else {
strFilter = "Location:" + intLocationCount;
}
}
if(intCityCount > 0) {
if (Utils.validateString(strFilter)) {
strFilter = strFilter+"," +"City:" + intCityCount;
} else {
strFilter = "City:" + intCityCount;
}
}
if(Utils.validateString(strstartdate) && Utils.validateString(strEnddate)){
if (Utils.validateString(strFilter)) {
strFilter = strFilter+"," + "Start Date:" + strstartdate+"-"+"End Date:"+strEnddate;
} else {
strFilter = "Start Date:" + strstartdate+"-"+"End Date:"+strEnddate;
}
}
if(Utils.validateString(price)) {
if (Utils.validateString(strFilter)) {
strFilter = strFilter+"," + "Price:" + strPrice;
} else {
strFilter ="Price:" + strPrice;
}
}
Log.e("Filter String :::","Filter String :::"+strFilter);
Log.e("Filter String :::","Filter String :::"+strFilter);
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
ArrayList<DealsModle> alstDeals = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse
.getJSONArray("data");
for (int i = 0; i < mJsonArray.length(); i++) {
dealsModle = new DealsModle();
JSONObject mData = mJsonArray.getJSONObject(i);
dealsModle.setDeal_id(mData.optString("deal_id"));
dealsModle.setM_fullname(mData
.optString("m_fullname"));
dealsModle.setMerchant_id(mData
.optString("merchant_id"));
dealsModle.setMaximum_redumption(mData
.optString("maximum_redumption"));
dealsModle.setMerchant_user_id(mData
.optString("merchant_user_id"));
dealsModle.setCategory_id(mData
.optString("category_id"));
dealsModle.setDeal_name(mData
.optString("deal_name"));
dealsModle.setDeal_desc(mData
.optString("deal_desc"));
dealsModle.setStart_date(mData
.optString("start_date"));
dealsModle.setEnd_date(mData
.optString("end_date"));
dealsModle.setIs_active(mData
.optString("is_active"));
dealsModle.setRate(mData.optString("rate"));
dealsModle.setComments(mData
.optString("comments"));
dealsModle.setImage(mData
.optString("image"));
dealsModle.setDeals_left(mData
.optString("deals_left"));
dealsModle.setIsLike(mData
.optString("is_liked"));
dealsModle.setIsWallet(mData
.optString("is_wallet"));
JSONArray mLocationArray = mData
.optJSONArray("locations");
ArrayList<LocationModel> alstLocationModel = new ArrayList<LocationModel>();
LocationModel locationModel = null;
if (mLocationArray != null) {
for (int j = 0; j < mLocationArray
.length(); j++) {
JSONObject mLocationObj = mLocationArray
.getJSONObject(j);
locationModel = new LocationModel();
locationModel
.setLocation_id(mLocationObj
.optString("location_id"));
locationModel
.setLocation_name(mLocationObj
.optString("location_name"));
locationModel
.setLocation_desc(mLocationObj
.optString("location_desc"));
locationModel.setLatitude(mLocationObj
.optString("latitude"));
locationModel.setLongitude(mLocationObj
.optString("longitude"));
locationModel.setContact(mLocationObj
.optString("contact"));
locationModel.setAddress1(mLocationObj
.optString("address1"));
locationModel.setAddress1(mLocationObj
.optString("address2"));
locationModel
.setLocation_timing(mLocationObj
.optString("location_timing"));
alstLocationModel
.add(locationModel);
}
dealsModle
.setAlstLocation(alstLocationModel);
}
alstDeals.add(dealsModle);
}
/// FilterSevice(String.valueOf(ratings), radioTimeButton.getTag().toString(), myLat, myLng, String.valueOf(progressDistance), cust_id,
// merchant_id, location_id, city_id, strstartdate, strEnddate, strSort, cat_id, sub_cat_id, price);
Intent mIntent = new Intent(FilterActivity.this, DealsActivity.class);
Utils.storeString(Consts.FILTER_TEXT,strFilter);
mIntent.setAction(Consts.IS_FROM_FILTER);
Bundle args = new Bundle();
args.putSerializable(Consts.FILTER_DEAL_ARRAY, (Serializable) alstDeals);
mIntent.putExtra(Consts.FILTER_DEAL_BUNDLE, args);
startActivity(mIntent);
} else if (strStatus.equalsIgnoreCase("2")) {
Toast.makeText(FilterActivity.this, getResources().getString(R.string.no_deal_found), Toast.LENGTH_SHORT).show();
// ratingBar.setRating(0);
//distanceSeekBar.setProgress(0);
// durationSeekBar.setProgress(0);
// positionValidityThumbLabel(durationSeekBar, validity_pointer, 0);
// positionThumbLabel(distanceSeekBar, dis_pointer, 0);
// //((RadioButton) timeGroup.getChildAt(0)).setChecked(true);
// imgCheckAllBrand.setImageResource(R.drawable.ic_uncheckbox);
// for (int i = 0; i < alstMerchant.size(); i++) {
// alstMerchant.get(i).setIsChecked(false);
// }
isCheckAllBrands = false;
// price = "";
}else{
Toast.makeText(FilterActivity.this, getResources().getString(R.string.no_deal_found), Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mFilterAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
rate, time, latitude, longitude, distance,
customer_id, merchant_id, location_id, city_id, start_date, end_date, sort, category_id, sub_cat_id, price_type);
} else {
mFilterAsynckTask.execute(rate, time, latitude, longitude, distance,
customer_id, merchant_id, location_id, city_id, start_date, end_date, sort, category_id, sub_cat_id, price_type);
}
}
public void GetAllMerchants() {
GetAllMerchantsAsynckTask mGetAllMerchantsAsynckTask = new GetAllMerchantsAsynckTask(this);
mGetAllMerchantsAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
Log.e("result", "result::::::::" + result.toString());
if (result != null) {
try {
MerchantModel mMerchantModel = null;
alstMerchant.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
// ArrayList<DealsModle> alstDeals = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("data");
if (mJsonArray != null) {
for (int i = 0; i < mJsonArray.length(); i++) {
mMerchantModel = new MerchantModel();
JSONObject mData = mJsonArray.getJSONObject(i);
mMerchantModel.setM_id(mData.getString("m_id"));
mMerchantModel.setBusiness_name(mData.getString("business_name"));
mMerchantModel.setDeals_count(mData.getString("deals_count"));
mMerchantModel.setIsChecked(false);
alstMerchant.add(mMerchantModel);
Log.e("", "Merchant :::" + mData.getString("business_name"));
}
txtCheckBoxCount.setText(getResources().getString(R.string.all) + "(" + (alstMerchant.size() - 1) + ")");
mMerchantAdapter.notifyDataSetChanged();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mGetAllMerchantsAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
mGetAllMerchantsAsynckTask.execute();
}
}
public void GetAllLocation(String cust_id, String type, String lat, String lng,String nextStart) {
GetAllLocationAsynckTask mGetAllLocationAsynckTask = new GetAllLocationAsynckTask(this);
mGetAllLocationAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
GetLocationModel mGetLocationModel = null;
alstLocation.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
// ArrayList<DealsModle> alstDeals = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("data");
if (mJsonArray != null) {
for (int i = 0; i < mJsonArray.length(); i++) {
mGetLocationModel = new GetLocationModel();
JSONObject mData = mJsonArray.getJSONObject(i);
mGetLocationModel.setLocation_id(mData.getString("location_id"));
mGetLocationModel.setLocation_name(mData.getString("location_name"));
mGetLocationModel.setIschecked(false);
alstLocation.add(mGetLocationModel);
Log.e("", "Location :::" + mData.getString("location_name"));
}
txtCheckBoxCountLocation.setText(getResources().getString(R.string.all) + "(" + (alstLocation.size() - 1) + ")");
mLocationAdapter.notifyDataSetChanged();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mGetAllLocationAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, cust_id, type, lat, lng, nextStart);
} else {
mGetAllLocationAsynckTask.execute(cust_id, type, lat, lng, nextStart);
}
}
public void GetAllCity() {
GetAllCityAsynckTask mGetAllCityAsynckTask = new GetAllCityAsynckTask(this);
mGetAllCityAsynckTask.setAsyncCallListener(new AsyncCallListener() {
@Override
public void onResponseReceived(Object response) {
}
@Override
public void onResponseReceived(String result) {
if (result != null) {
Log.e("result", "result::::::::" + result.toString());
try {
GetCityModel mGetCityModel = null;
alstCity.clear();
JSONObject mJsonResult = new JSONObject(result);
JSONObject mJsonResponse = mJsonResult.getJSONObject("response");
String strStatus = mJsonResponse.getString("status");
if (Utils.validateString(strStatus)) {
if (strStatus.equalsIgnoreCase("1")) {
// ArrayList<DealsModle> alstDeals = new ArrayList<DealsModle>();
JSONArray mJsonArray = mJsonResponse.getJSONArray("data");
if (mJsonArray != null) {
for (int i = 0; i < mJsonArray.length(); i++) {
mGetCityModel = new GetCityModel();
JSONObject mData = mJsonArray.getJSONObject(i);
mGetCityModel.setCity_id(mData.getString("city_id"));
mGetCityModel.setCity_name(mData.getString("city_name"));
mGetCityModel.setIschecked(false);
alstCity.add(mGetCityModel);
Log.e("", "City :::" + mData.getString("city_name"));
}
txtCheckBoxCountCity.setText(getResources().getString(R.string.all) + "(" + (alstCity.size() - 1) + ")");
mCityAdapter.notifyDataSetChanged();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
public void onErrorReceived(String error) {
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mGetAllCityAsynckTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
mGetAllCityAsynckTask.execute();
}
}
//40 km 22 days
protected void positionThumbLabel(SeekBar seekBar, TextView label, int progress) {
Rect tr = seekBar.getThumb().getBounds();
Log.v("progress", "km" + progress + " " + seekBar.getProgress() + " " + tr.left + " ");
label.setX(tr.left);
if (progress == 0) {
label.setText(0 + " KM");
}
if (progress < 6)
startDis.setVisibility(View.GONE);
else
startDis.setVisibility(View.VISIBLE);
if (progress > 40) {
end_dis.setVisibility(View.GONE);
} else {
end_dis.setVisibility(View.VISIBLE);
}
if (progress > 0 && progress < 51) {
label.setText(progress + " KM");
label.setVisibility(View.VISIBLE);
}
X = label.getX();
}
public void closeView(){
//Close sort view
timeGroup.setVisibility(View.GONE);
timeArrowImageView.setImageResource(R.drawable.filt_right);
timeLLTitle.setBackgroundColor(Color.parseColor("#ffffff"));
timetv.setTextColor(Color.parseColor("#000000"));
//Close Time view
radioGroupSort.setVisibility(View.GONE);
timeArrowImageView.setImageResource(R.drawable.filt_right);
lytSort.setBackgroundColor(Color.parseColor("#ffffff"));
txtSort.setTextColor(Color.parseColor("#000000"));
// Rating bar view close
ratingBar.setVisibility(View.GONE);
ratingArrowImageView.setImageResource(R.drawable.filt_right);
ratingLLTitle.setBackgroundColor(Color.parseColor("#ffffff"));
ratingtv.setTextColor(Color.parseColor("#000000"));
//distance view close
distanceLL.setVisibility(View.GONE);
distanceArrowImageView.setImageResource(R.drawable.filt_right);
distanceLLTitle.setBackgroundColor(Color.parseColor("#ffffff"));
distancetv.setTextColor(Color.parseColor("#000000"));
//Brand view close
lytBrandDetail.setVisibility(View.GONE);
imgArrowBrands.setImageResource(R.drawable.filt_right);
lytBrands.setBackgroundColor(Color.parseColor("#ffffff"));
txtBrands.setTextColor(Color.parseColor("#000000"));
// Location view close
lytLocationDetail.setVisibility(View.GONE);
imgLocationArrow.setImageResource(R.drawable.filt_right);
lytLocation.setBackgroundColor(Color.parseColor("#ffffff"));
txtLocation.setTextColor(Color.parseColor("#000000"));
// city view close
lytCityDetail.setVisibility(View.GONE);
imgCityArrow.setImageResource(R.drawable.filt_right);
lytCity.setBackgroundColor(Color.parseColor("#ffffff"));
txtCity.setTextColor(Color.parseColor("#000000"));
//Date view close
lytDateDetail.setVisibility(View.GONE);
imgDateArrow.setImageResource(R.drawable.filt_right);
lytDate.setBackgroundColor(Color.parseColor("#ffffff"));
txtDate.setTextColor(Color.parseColor("#000000"));
//price view close
lytPriceDetail.setVisibility(View.GONE);
imgPriceArrow.setImageResource(R.drawable.filt_right);
lytPrice.setBackgroundColor(Color.parseColor("#ffffff"));
txtPrice.setTextColor(Color.parseColor("#000000"));
}
// protected void positionValidityThumbLabel(SeekBar seekBar, TextView label, int progress) {
// Rect tr = seekBar.getThumb().getBounds();
// label.setX(tr.left);
// Log.v("progress", "val" + progress + " " + seekBar.getProgress() + " " + tr.left);
// if (progress == 0) {
// label.setText(0 + " Day");
// }
// if (progress < 3)
// startDutration.setVisibility(View.GONE);
// else
// startDutration.setVisibility(View.VISIBLE);
//
// if (progress > 22) {
// end_duration.setVisibility(View.GONE);
// } else {
// end_duration.setVisibility(View.VISIBLE);
// }
// if (progress > 0 && progress < 31) {
// if (progress == 1) {
// label.setText(progress + " Day");
// } else
// label.setText(progress + " Days");
// label.setVisibility(View.VISIBLE);
// }
// X_VALIDITY = label.getX();
// }
}
No comments:
Post a Comment