This commit is contained in:
Gagan290
2017-01-09 12:30:14 +05:30
parent e6b6c607b5
commit 0c30da48e7
7 changed files with 813 additions and 626 deletions
@@ -1457,8 +1457,9 @@ public class GSKOrangeDB extends SQLiteOpenHelper {
} }
public void InsertAdditionalPromoData(Promo_Compliance_DataGetterSetter data) { public void InsertAdditionalPromoData(Promo_Compliance_DataGetterSetter data) {
ContentValues values = new ContentValues();
try { try {
ContentValues values = new ContentValues();
values.put("STORE_ID", Integer.parseInt(data.getStore_id())); values.put("STORE_ID", Integer.parseInt(data.getStore_id()));
values.put("PROMO_ID", Integer.parseInt(data.getPromo_id())); values.put("PROMO_ID", Integer.parseInt(data.getPromo_id()));
values.put("PROMO", data.getPromo()); values.put("PROMO", data.getPromo());
@@ -1504,14 +1505,16 @@ public class GSKOrangeDB extends SQLiteOpenHelper {
return list; return list;
} }
public void InsertPromoSkuData(ArrayList<Promo_Compliance_DataGetterSetter> promoSkuListData) { public void InsertPromoSkuData(ArrayList<Promo_Compliance_DataGetterSetter> promoSkuListData, String category_id) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
try { try {
db.beginTransaction(); db.beginTransaction();
for (int i = 0; i < promoSkuListData.size(); i++) { for (int i = 0; i < promoSkuListData.size(); i++) {
Promo_Compliance_DataGetterSetter data = promoSkuListData.get(i); Promo_Compliance_DataGetterSetter data = promoSkuListData.get(i);
values.put("STORE_ID", Integer.parseInt(data.getStore_id())); values.put("STORE_ID", Integer.parseInt(data.getStore_id()));
values.put("CATEGORY_ID", Integer.parseInt(category_id));
values.put("SKU_ID", Integer.parseInt(data.getSku_id())); values.put("SKU_ID", Integer.parseInt(data.getSku_id()));
values.put("SKU", data.getSku()); values.put("SKU", data.getSku());
values.put("PROMO_ID", Integer.parseInt(data.getPromo_id())); values.put("PROMO_ID", Integer.parseInt(data.getPromo_id()));
@@ -1529,6 +1532,41 @@ public class GSKOrangeDB extends SQLiteOpenHelper {
} }
} }
public boolean checkPromoComplianceData(String store_id, String category_id) {
Log.d("PromoCompliance ", "PromoCompliance data--------------->Start<------------");
ArrayList<Promo_Compliance_DataGetterSetter> list = new ArrayList<>();
Cursor dbcursor = null;
try {
dbcursor = db.rawQuery("Select * from Promo_SKU_Data " +
"where CATEGORY_ID='" + category_id + "' and STORE_ID='" + store_id + "'", null);
if (dbcursor != null) {
if (dbcursor.moveToFirst()) {
do {
Promo_Compliance_DataGetterSetter sb = new Promo_Compliance_DataGetterSetter();
sb.setSku_id(dbcursor.getString(dbcursor.getColumnIndexOrThrow("SKU_ID")));
list.add(sb);
} while (dbcursor.moveToNext());
}
dbcursor.close();
if (list.size() > 0) {
return true;
} else {
return false;
}
}
} catch (Exception e) {
Log.d("Exception ", "when fetching Records!!!!!!!!!!!!!!!!!!!!!" + e.toString());
return false;
}
Log.d("Stock_Facing ", "midday---------------------->Stop<-----------");
return false;
}
//Gagan End Method //Gagan End Method
//Non Working data //Non Working data
@@ -1610,34 +1648,22 @@ public class GSKOrangeDB extends SQLiteOpenHelper {
//Gagan start new code 1 //Gagan start new code 1
public void updatePromoComplianceSKU(String storeId, String categoryId, List<Stock_FacingGetterSetter> hashMapListHeaderData, public void updatePromoComplianceSKU(ArrayList<Promo_Compliance_DataGetterSetter> promoSkuListData,
HashMap<Stock_FacingGetterSetter, List<Stock_FacingGetterSetter>> hashMapListChildData) { String categoryId, String storeId) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
ContentValues values1 = new ContentValues();
try { try {
db.beginTransaction(); db.beginTransaction();
for (int i = 0; i < hashMapListHeaderData.size(); i++) { for (int i = 0; i < promoSkuListData.size(); i++) {
Stock_FacingGetterSetter data1 = hashMapListHeaderData.get(i); Promo_Compliance_DataGetterSetter data = promoSkuListData.get(i);
values1.put("IMAGE1", data1.getImage1()); values.put("IN_STOCK_VALUE", Integer.parseInt(data.getIn_stock()));
values1.put("IMAGE2", data1.getImage2()); values.put("PROMO_ANNOUNCER_VALUE", Integer.parseInt(data.getPromo_announcer()));
values.put("RUNNING_POS_VALUE", Integer.parseInt(data.getRunning_pos()));
//db.insert(CommonString.TABLE_INSERT_STOCK_FACING_HEADER, null, values1); db.update(CommonString.TABLE_INSERT_PROMO_SKU, values,
db.update(CommonString.TABLE_INSERT_STOCK_FACING_HEADER, values1, "CATEGORY_ID='" + categoryId + "' AND STORE_ID='" + storeId +
"Category_Id='" + categoryId + "' AND Store_Id='" + storeId + "' ", null); "' AND SKU_ID='" + data.getSku_id() + "' AND PROMO_ID='" + data.getPromo_id() + "'", null);
for (int j = 0; j < hashMapListChildData.get(hashMapListHeaderData.get(i)).size(); j++) {
Stock_FacingGetterSetter data = hashMapListChildData.get(hashMapListHeaderData.get(i)).get(j);
values.put("STOCK_VALUE", data.getStock());
values.put("FACEUP_VALUE", data.getFacing());
//db.insert(CommonString.TABLE_INSERT_STOCK_FACING_CHILD, null, values);
db.update(CommonString.TABLE_INSERT_STOCK_FACING_CHILD, values,
"Brand_Id ='" + hashMapListHeaderData.get(i).getBrand_id() + "' AND SKU_ID ='" + data.getSku_id() +
"' AND Category_Id='" + categoryId + "' AND Store_Id='" + storeId + "'", null);
}
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
db.endTransaction(); db.endTransaction();
@@ -1647,5 +1673,39 @@ public class GSKOrangeDB extends SQLiteOpenHelper {
} }
public ArrayList<Promo_Compliance_DataGetterSetter> getPromoComplianceSkuAfterData(String store_id, String category_id) {
ArrayList<Promo_Compliance_DataGetterSetter> list = new ArrayList<>();
Cursor dbcursor = null;
try {
dbcursor = db.rawQuery("Select * from Promo_SKU_Data " +
"where STORE_ID='" + store_id + "' AND CATEGORY_ID='" + category_id + "'", null);
if (dbcursor != null) {
dbcursor.moveToFirst();
while (!dbcursor.isAfterLast()) {
Promo_Compliance_DataGetterSetter cd = new Promo_Compliance_DataGetterSetter();
cd.setStore_id(dbcursor.getString(dbcursor.getColumnIndexOrThrow("STORE_ID")));
cd.setSku_id(dbcursor.getString(dbcursor.getColumnIndexOrThrow("SKU_ID")));
cd.setSku(dbcursor.getString(dbcursor.getColumnIndexOrThrow("SKU")));
cd.setPromo_id(dbcursor.getString(dbcursor.getColumnIndexOrThrow("PROMO_ID")));
cd.setPromo(dbcursor.getString(dbcursor.getColumnIndexOrThrow("PROMO")));
cd.setIn_stock(dbcursor.getString(dbcursor.getColumnIndexOrThrow("IN_STOCK_VALUE")));
cd.setPromo_announcer(dbcursor.getString(dbcursor.getColumnIndexOrThrow("PROMO_ANNOUNCER_VALUE")));
cd.setRunning_pos(dbcursor.getString(dbcursor.getColumnIndexOrThrow("RUNNING_POS_VALUE")));
list.add(cd);
dbcursor.moveToNext();
}
dbcursor.close();
return list;
}
} catch (Exception e) {
Log.d("Exception ", "getPromoComplianceSkuAfterData!" + e.toString());
return list;
}
return list;
}
//Gagan end new code 1 //Gagan end new code 1
} }
@@ -303,6 +303,9 @@ public class CommonString {
+ "STORE_ID" + "STORE_ID"
+ " INTEGER," + " INTEGER,"
+ "CATEGORY_ID"
+ " INTEGER,"
+ "SKU_ID" + "SKU_ID"
+ " INTEGER," + " INTEGER,"
@@ -2,7 +2,10 @@ package cpm.com.gskmtorange.gsk_dailyentry;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@@ -20,7 +23,9 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import cpm.com.gskmtorange.Database.GSKOrangeDB;
import cpm.com.gskmtorange.R; import cpm.com.gskmtorange.R;
import cpm.com.gskmtorange.constant.CommonString;
import cpm.com.gskmtorange.dailyentry.T2PComplianceActivity; import cpm.com.gskmtorange.dailyentry.T2PComplianceActivity;
import cpm.com.gskmtorange.xmlGetterSetter.DailyDataMenuGetterSetter; import cpm.com.gskmtorange.xmlGetterSetter.DailyDataMenuGetterSetter;
@@ -29,26 +34,47 @@ public class DailyDataMenuActivity extends AppCompatActivity {
ArrayList<DailyDataMenuGetterSetter> categoryList; ArrayList<DailyDataMenuGetterSetter> categoryList;
DailyDataMenuAdapter adapter; DailyDataMenuAdapter adapter;
TextView txt_categoryName; TextView txt_categoryName;
GSKOrangeDB db;
String categoryName = "", categoryId; String categoryName = "", categoryId;
private SharedPreferences preferences;
String store_id, visit_date, username, intime, date, keyAccount_id, class_id, storeType_id;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_data_menu); try {
setContentView(R.layout.activity_daily_data_menu);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
txt_categoryName = (TextView) findViewById(R.id.txt_categoryName); txt_categoryName = (TextView) findViewById(R.id.txt_categoryName);
categoryName = getIntent().getStringExtra("categoryName"); db = new GSKOrangeDB(this);
categoryId = getIntent().getStringExtra("categoryId"); db.open();
//txt_categoryName.setText("Daily Data Menu - " + categoryName); //preference data
txt_categoryName.setText(getResources().getString(R.string.title_activity_daily_main_menu) + " - " + categoryName); preferences = PreferenceManager.getDefaultSharedPreferences(this);
store_id = preferences.getString(CommonString.KEY_STORE_ID, null);
visit_date = preferences.getString(CommonString.KEY_DATE, null);
date = preferences.getString(CommonString.KEY_DATE, null);
username = preferences.getString(CommonString.KEY_USERNAME, null);
intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, "");
keyAccount_id = preferences.getString(CommonString.KEY_KEYACCOUNT_ID, "");
class_id = preferences.getString(CommonString.KEY_CLASS_ID, "");
storeType_id = preferences.getString(CommonString.KEY_STORETYPE_ID, "");
//Intent data
categoryName = getIntent().getStringExtra("categoryName");
categoryId = getIntent().getStringExtra("categoryId");
//txt_categoryName.setText("Daily Data Menu - " + categoryName);
txt_categoryName.setText(getResources().getString(R.string.title_activity_daily_main_menu) + " - " + categoryName);
/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@@ -58,59 +84,79 @@ public class DailyDataMenuActivity extends AppCompatActivity {
.setAction("Action", null).show(); .setAction("Action", null).show();
} }
});*/ });*/
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
categoryList = new ArrayList<>(); try {
categoryList = new ArrayList<>();
DailyDataMenuGetterSetter data = new DailyDataMenuGetterSetter(); DailyDataMenuGetterSetter data = new DailyDataMenuGetterSetter();
//data.setCategory_name("MSL Availability"); //data.setCategory_name("MSL Availability");
data.setCategory_name(getResources().getString(R.string.daily_data_menu_msl_availability)); data.setCategory_name(getResources().getString(R.string.daily_data_menu_msl_availability));
data.setCategory_img(R.mipmap.msl_availability); if (db.checkMsl_AvailabilityData(store_id, categoryId)) {
categoryList.add(data); data.setCategory_img(R.mipmap.msl_availability_done);
} else {
data.setCategory_img(R.mipmap.msl_availability);
}
categoryList.add(data);
data = new DailyDataMenuGetterSetter(); data = new DailyDataMenuGetterSetter();
data.setCategory_name(getResources().getString(R.string.daily_data_menu_stock_facing)); //data.setCategory_name("Stock & Facing");
//data.setCategory_name("Stock & Facing"); data.setCategory_name(getResources().getString(R.string.daily_data_menu_stock_facing));
data.setCategory_img(R.mipmap.stock_and_facing); if (db.checkStockAndFacingData(store_id, categoryId)) {
categoryList.add(data); data.setCategory_img(R.mipmap.stock_and_facing_done);
} else {
data.setCategory_img(R.mipmap.stock_and_facing);
}
categoryList.add(data);
data = new DailyDataMenuGetterSetter(); data = new DailyDataMenuGetterSetter();
data.setCategory_name(getResources().getString(R.string.daily_data_menu_t2p)); //data.setCategory_name("T2P Compliance");
//data.setCategory_name("T2P Compliance"); data.setCategory_name(getResources().getString(R.string.daily_data_menu_t2p));
data.setCategory_img(R.mipmap.t2p_compliance); data.setCategory_img(R.mipmap.t2p_compliance);
categoryList.add(data); categoryList.add(data);
data = new DailyDataMenuGetterSetter(); data = new DailyDataMenuGetterSetter();
data.setCategory_name(getResources().getString(R.string.daily_data_menu_additional_visibility)); //data.setCategory_name("Additional Visibility");
//data.setCategory_name("Additional Visibility"); data.setCategory_name(getResources().getString(R.string.daily_data_menu_additional_visibility));
data.setCategory_img(R.mipmap.additional_visibility); data.setCategory_img(R.mipmap.additional_visibility);
categoryList.add(data); categoryList.add(data);
data = new DailyDataMenuGetterSetter(); data = new DailyDataMenuGetterSetter();
data.setCategory_name(getResources().getString(R.string.daily_data_menu_promo_compliance)); //data.setCategory_name("Promo Compliance");
//data.setCategory_name("Promo Compliance"); data.setCategory_name(getResources().getString(R.string.daily_data_menu_promo_compliance));
data.setCategory_img(R.mipmap.promo_compliance); if (db.checkPromoComplianceData(store_id, categoryId)) {
categoryList.add(data); data.setCategory_img(R.mipmap.promo_compliance_done);
} else {
data.setCategory_img(R.mipmap.promo_compliance);
}
categoryList.add(data);
/*data = new DailyDataMenuGetterSetter(); /*data = new DailyDataMenuGetterSetter();
data.setCategory_name(getResources().getString(R.string.daily_data_menu_competition_tracking)); data.setCategory_name(getResources().getString(R.string.daily_data_menu_competition_tracking));
//data.setCategory_name("Competition Tracking"); //data.setCategory_name("Competition Tracking");
data.setCategory_img(R.drawable.category); data.setCategory_img(R.drawable.category);
categoryList.add(data); categoryList.add(data);
data = new DailyDataMenuGetterSetter(); data = new DailyDataMenuGetterSetter();
data.setCategory_name(getResources().getString(R.string.daily_data_menu_additional_promotions)); data.setCategory_name(getResources().getString(R.string.daily_data_menu_additional_promotions));
//data.setCategory_name("Competition Promo"); //data.setCategory_name("Competition Promo");
data.setCategory_img(R.drawable.category); data.setCategory_img(R.drawable.category);
categoryList.add(data);*/ categoryList.add(data);*/
adapter = new DailyDataMenuAdapter(DailyDataMenuActivity.this, categoryList); adapter = new DailyDataMenuAdapter(DailyDataMenuActivity.this, categoryList);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new GridLayoutManager(getApplicationContext(), 2)); recyclerView.setLayoutManager(new GridLayoutManager(getApplicationContext(), 2));
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
} }
public class DailyDataMenuAdapter extends RecyclerView.Adapter<DailyDataMenuAdapter.MyViewHolder> { public class DailyDataMenuAdapter extends RecyclerView.Adapter<DailyDataMenuAdapter.MyViewHolder> {
@@ -4,6 +4,7 @@ import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@@ -60,182 +61,192 @@ public class MSL_AvailabilityActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_msl__availability); try {
setContentView(R.layout.activity_msl__availability);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView); expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
txt_mslAvailabilityName = (TextView) findViewById(R.id.txt_mslAvailabilityName); txt_mslAvailabilityName = (TextView) findViewById(R.id.txt_mslAvailabilityName);
db = new GSKOrangeDB(this); db = new GSKOrangeDB(this);
db.open(); db.open();
//preference data //preference data
preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences = PreferenceManager.getDefaultSharedPreferences(this);
store_id = preferences.getString(CommonString.KEY_STORE_ID, null); store_id = preferences.getString(CommonString.KEY_STORE_ID, null);
visit_date = preferences.getString(CommonString.KEY_DATE, null); visit_date = preferences.getString(CommonString.KEY_DATE, null);
date = preferences.getString(CommonString.KEY_DATE, null); date = preferences.getString(CommonString.KEY_DATE, null);
username = preferences.getString(CommonString.KEY_USERNAME, null); username = preferences.getString(CommonString.KEY_USERNAME, null);
intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, ""); intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, "");
keyAccount_id = preferences.getString(CommonString.KEY_KEYACCOUNT_ID, ""); keyAccount_id = preferences.getString(CommonString.KEY_KEYACCOUNT_ID, "");
class_id = preferences.getString(CommonString.KEY_CLASS_ID, ""); class_id = preferences.getString(CommonString.KEY_CLASS_ID, "");
storeType_id = preferences.getString(CommonString.KEY_STORETYPE_ID, ""); storeType_id = preferences.getString(CommonString.KEY_STORETYPE_ID, "");
//Intent data //Intent data
categoryName = getIntent().getStringExtra("categoryName"); categoryName = getIntent().getStringExtra("categoryName");
categoryId = getIntent().getStringExtra("categoryId"); categoryId = getIntent().getStringExtra("categoryId");
//txt_mslAvailabilityName.setText(categoryName); //txt_mslAvailabilityName.setText(categoryName);
txt_mslAvailabilityName.setText(getResources().getString(R.string.title_activity_msl__availability)); txt_mslAvailabilityName.setText(getResources().getString(R.string.title_activity_msl__availability));
prepareList(); prepareList();
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(final View view) {
//if (validateData(listDataHeader, listDataChild)) { //if (validateData(listDataHeader, listDataChild)) {
AlertDialog.Builder builder = new AlertDialog.Builder(MSL_AvailabilityActivity.this);
builder.setMessage("Are you sure you want to save")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
db.open();
if (db.checkMsl_AvailabilityData(store_id, categoryId)) {
db.updateMSL_Availability(store_id, categoryId, hashMapListHeaderData, hashMapListChildData);
} else {
db.InsertMSL_Availability(store_id, categoryId, hashMapListHeaderData, hashMapListChildData);
}
Toast.makeText(getApplicationContext(), "Data has been saved", Toast.LENGTH_LONG).show();
finish();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
/*} else {
AlertDialog.Builder builder = new AlertDialog.Builder(MSL_AvailabilityActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(MSL_AvailabilityActivity.this);
builder.setMessage("Fill the value or fill 0 ") builder.setMessage("Are you sure you want to save")
.setCancelable(false) .setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() { .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
dialog.dismiss(); db.open();
if (db.checkMsl_AvailabilityData(store_id, categoryId)) {
db.updateMSL_Availability(store_id, categoryId, hashMapListHeaderData, hashMapListChildData);
Snackbar.make(view, "Data has been updated", Snackbar.LENGTH_LONG).setAction("Action", null).show();
} else {
db.InsertMSL_Availability(store_id, categoryId, hashMapListHeaderData, hashMapListChildData);
Snackbar.make(view, "Data has been saved", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
//Toast.makeText(getApplicationContext(), "Data has been saved", Toast.LENGTH_LONG).show();
finish();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
} }
}); });
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
}*/
} /*} else {
}); AlertDialog.Builder builder = new AlertDialog.Builder(MSL_AvailabilityActivity.this);
builder.setMessage("Fill the value or fill 0 ")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}*/
expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int lastItem = firstVisibleItem + visibleItemCount;
if (firstVisibleItem == 0) {
fab.setVisibility(View.VISIBLE);
} else if (lastItem == totalItemCount) {
fab.setVisibility(View.INVISIBLE);
} else {
fab.setVisibility(View.VISIBLE);
} }
} });
@Override expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() {
public void onScrollStateChanged(AbsListView arg0, int arg1) { @Override
InputMethodManager inputManager = (InputMethodManager) getApplicationContext() public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
.getSystemService(Context.INPUT_METHOD_SERVICE); int lastItem = firstVisibleItem + visibleItemCount;
if (getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); if (firstVisibleItem == 0) {
getCurrentFocus().clearFocus(); fab.setVisibility(View.VISIBLE);
} else if (lastItem == totalItemCount) {
fab.setVisibility(View.INVISIBLE);
} else {
fab.setVisibility(View.VISIBLE);
}
} }
//expandableListView.invalidateViews(); @Override
} public void onScrollStateChanged(AbsListView arg0, int arg1) {
}); InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
}
// Listview Group click listener //expandableListView.invalidateViews();
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
return false;
}
});
// Listview Group expanded listener
expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getWindow().getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
} }
} });
});
// Listview Group collasped listener // Listview Group click listener
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() { expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override @Override
public void onGroupCollapse(int groupPosition) { public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext() return false;
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getWindow().getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
} }
} });
});
// Listview on child click listener // Listview Group expanded listener
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, public void onGroupExpand(int groupPosition) {
int childPosition, long id) { InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
return false; .getSystemService(Context.INPUT_METHOD_SERVICE);
} if (getWindow().getCurrentFocus() != null) {
}); inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
}
}
});
// Listview Group collasped listener
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getWindow().getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
}
}
});
// Listview on child click listener
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
return false;
}
});
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
} }
private void prepareList() { private void prepareList() {
hashMapListHeaderData = new ArrayList<>(); try {
hashMapListChildData = new HashMap<>(); hashMapListHeaderData = new ArrayList<>();
hashMapListChildData = new HashMap<>();
//Header //Header
headerDataList = db.getMSL_AvailabilityHeaderData(categoryId); headerDataList = db.getMSL_AvailabilityHeaderData(categoryId);
if (headerDataList.size() > 0) { if (headerDataList.size() > 0) {
for (int i = 0; i < headerDataList.size(); i++) { for (int i = 0; i < headerDataList.size(); i++) {
hashMapListHeaderData.add(headerDataList.get(i)); hashMapListHeaderData.add(headerDataList.get(i));
//childDataList = new ArrayList<>(); //childDataList = new ArrayList<>();
childDataList = db.getMSL_AvailabilitySKU_AfterSaveData(categoryId, headerDataList.get(i).getBrand_id()); childDataList = db.getMSL_AvailabilitySKU_AfterSaveData(categoryId, headerDataList.get(i).getBrand_id());
if (!(childDataList.size() > 0)) { if (!(childDataList.size() > 0)) {
childDataList = db.getMSL_AvailabilitySKUData(categoryId, headerDataList.get(i).getBrand_id()); childDataList = db.getMSL_AvailabilitySKUData(categoryId, headerDataList.get(i).getBrand_id());
}
hashMapListChildData.put(hashMapListHeaderData.get(i), childDataList);
} }
hashMapListChildData.put(hashMapListHeaderData.get(i), childDataList);
} }
}
adapter = new ExpandableListAdapter(this, hashMapListHeaderData, hashMapListChildData); adapter = new ExpandableListAdapter(this, hashMapListHeaderData, hashMapListChildData);
expandableListView.setAdapter(adapter); expandableListView.setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
} }
public class ExpandableListAdapter extends BaseExpandableListAdapter { public class ExpandableListAdapter extends BaseExpandableListAdapter {
@@ -9,6 +9,8 @@ import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@@ -33,7 +35,7 @@ public class PromoComplianceActivity extends AppCompatActivity {
ToggleButton toggle_add_InStock, toggle_add_promoAnnouncer, toggle_add_runningPos; ToggleButton toggle_add_InStock, toggle_add_promoAnnouncer, toggle_add_runningPos;
Button btn_add; Button btn_add;
ArrayList<Promo_Compliance_DataGetterSetter> promoSkuListData; ArrayList<Promo_Compliance_DataGetterSetter> promoSkuListData, promoSkuListAfterData;
ArrayList<Promo_Compliance_DataGetterSetter> promoSpinnerListData; ArrayList<Promo_Compliance_DataGetterSetter> promoSpinnerListData;
ArrayList<Promo_Compliance_DataGetterSetter> additionalPromoListData; ArrayList<Promo_Compliance_DataGetterSetter> additionalPromoListData;
@@ -46,189 +48,199 @@ public class PromoComplianceActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_promo_compliance); try {
setContentView(R.layout.activity_promo_compliance);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
lin_promo_sku = (LinearLayout) findViewById(R.id.lin_promo_sku); lin_promo_sku = (LinearLayout) findViewById(R.id.lin_promo_sku);
lin_addtional_promo = (LinearLayout) findViewById(R.id.lin_addtional_promo); lin_addtional_promo = (LinearLayout) findViewById(R.id.lin_addtional_promo);
view_promo_sku = findViewById(R.id.view_promo_sku); view_promo_sku = findViewById(R.id.view_promo_sku);
view_additional_promo = findViewById(R.id.view_additional_promo); view_additional_promo = findViewById(R.id.view_additional_promo);
sp_promo = (Spinner) findViewById(R.id.sp_promo); sp_promo = (Spinner) findViewById(R.id.sp_promo);
toggle_add_InStock = (ToggleButton) findViewById(R.id.toggle_add_InStock); toggle_add_InStock = (ToggleButton) findViewById(R.id.toggle_add_InStock);
toggle_add_promoAnnouncer = (ToggleButton) findViewById(R.id.toggle_add_promoAnnouncer); toggle_add_promoAnnouncer = (ToggleButton) findViewById(R.id.toggle_add_promoAnnouncer);
toggle_add_runningPos = (ToggleButton) findViewById(R.id.toggle_add_runningPos); toggle_add_runningPos = (ToggleButton) findViewById(R.id.toggle_add_runningPos);
btn_add = (Button) findViewById(R.id.btn_add); btn_add = (Button) findViewById(R.id.btn_add);
db = new GSKOrangeDB(this); db = new GSKOrangeDB(this);
db.open(); db.open();
//preference data //preference data
preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences = PreferenceManager.getDefaultSharedPreferences(this);
store_id = preferences.getString(CommonString.KEY_STORE_ID, null); store_id = preferences.getString(CommonString.KEY_STORE_ID, null);
visit_date = preferences.getString(CommonString.KEY_DATE, null); visit_date = preferences.getString(CommonString.KEY_DATE, null);
date = preferences.getString(CommonString.KEY_DATE, null); date = preferences.getString(CommonString.KEY_DATE, null);
username = preferences.getString(CommonString.KEY_USERNAME, null); username = preferences.getString(CommonString.KEY_USERNAME, null);
intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, ""); intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, "");
keyAccount_id = preferences.getString(CommonString.KEY_KEYACCOUNT_ID, ""); keyAccount_id = preferences.getString(CommonString.KEY_KEYACCOUNT_ID, "");
class_id = preferences.getString(CommonString.KEY_CLASS_ID, ""); class_id = preferences.getString(CommonString.KEY_CLASS_ID, "");
storeType_id = preferences.getString(CommonString.KEY_STORETYPE_ID, ""); storeType_id = preferences.getString(CommonString.KEY_STORETYPE_ID, "");
//Intent data //Intent data
categoryName = getIntent().getStringExtra("categoryName"); categoryName = getIntent().getStringExtra("categoryName");
categoryId = getIntent().getStringExtra("categoryId"); categoryId = getIntent().getStringExtra("categoryId");
prepareList(); prepareList();
promoSkuListView(); promoSkuListView();
additionalPromoListData = new ArrayList<>(); additionalPromoListData = new ArrayList<>();
//AdditionalPromoListView(); AdditionalPromoListView();
final Promo_Compliance_DataGetterSetter cd = new Promo_Compliance_DataGetterSetter(); final Promo_Compliance_DataGetterSetter cd = new Promo_Compliance_DataGetterSetter();
cd.setStore_id(store_id); cd.setStore_id(store_id);
cd.setPromo_id(""); cd.setPromo_id("");
cd.setPromo(""); cd.setPromo("");
cd.setIn_stock("1"); cd.setIn_stock("1");
cd.setPromo_announcer("1"); cd.setPromo_announcer("1");
cd.setRunning_pos("1"); cd.setRunning_pos("1");
cd.setSp_promo("0"); cd.setSp_promo("0");
toggle_add_InStock.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { toggle_add_InStock.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) { if (isChecked) {
cd.setIn_stock("1"); cd.setIn_stock("1");
} else { } else {
cd.setIn_stock("0"); cd.setIn_stock("0");
}
}
});
if (cd.getIn_stock().equals("1")) {
toggle_add_InStock.setChecked(true);
} else {
toggle_add_InStock.setChecked(false);
}
toggle_add_promoAnnouncer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cd.setPromo_announcer("1");
} else {
cd.setPromo_announcer("0");
}
}
});
if (cd.getPromo_announcer().equals("1")) {
toggle_add_promoAnnouncer.setChecked(true);
} else {
toggle_add_promoAnnouncer.setChecked(false);
}
toggle_add_runningPos.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cd.setRunning_pos("1");
} else {
cd.setRunning_pos("0");
}
}
});
if (cd.getRunning_pos().equals("1")) {
toggle_add_runningPos.setChecked(true);
} else {
toggle_add_runningPos.setChecked(false);
}
sp_promo.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
// childData.setSp_condition(position);
// childData.setConditionName(item);
for (int i = 0; i < promoSpinnerListData.size(); i++) {
if (position == i) {
cd.setSp_promo(promoSpinnerListData.get(i).getPromo_id());
cd.setPromo(promoSpinnerListData.get(i).getPromo());
cd.setPromo_id(promoSpinnerListData.get(i).getPromo_id());
} }
} }
});
if (cd.getIn_stock().equals("1")) {
toggle_add_InStock.setChecked(true);
} else {
toggle_add_InStock.setChecked(false);
} }
@Override toggle_add_promoAnnouncer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onNothingSelected(AdapterView<?> parent) { @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cd.setPromo_announcer("1");
} else {
cd.setPromo_announcer("0");
}
}
});
if (cd.getPromo_announcer().equals("1")) {
toggle_add_promoAnnouncer.setChecked(true);
} else {
toggle_add_promoAnnouncer.setChecked(false);
} }
});
for (int i = 0; i < promoSpinnerListData.size(); i++) { toggle_add_runningPos.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
if (cd.getSp_promo() == promoSpinnerListData.get(i).getPromo_id()) { @Override
sp_promo.setSelection(i); public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cd.setRunning_pos("1");
} else {
cd.setRunning_pos("0");
}
}
});
if (cd.getRunning_pos().equals("1")) {
toggle_add_runningPos.setChecked(true);
} else {
toggle_add_runningPos.setChecked(false);
} }
}
btn_add.setOnClickListener(new View.OnClickListener() { sp_promo.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onClick(final View v) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
AlertDialog.Builder builder = new AlertDialog.Builder(PromoComplianceActivity.this); String item = parent.getItemAtPosition(position).toString();
builder.setMessage("Are you sure you want to add") // childData.setSp_condition(position);
.setCancelable(false) // childData.setConditionName(item);
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
db.InsertAdditionalPromoData(cd); for (int i = 0; i < promoSpinnerListData.size(); i++) {
AdditionalPromoListView(); if (position == i) {
cd.setSp_promo(promoSpinnerListData.get(i).getPromo_id());
cd.setPromo(promoSpinnerListData.get(i).getPromo());
cd.setPromo_id(promoSpinnerListData.get(i).getPromo_id());
}
}
}
Snackbar.make(v, "promo is add", Snackbar.LENGTH_LONG).setAction("Action", null).show(); @Override
//Toast.makeText(getApplicationContext(), "promo is add", Toast.LENGTH_LONG).show(); public void onNothingSelected(AdapterView<?> parent) {
}
}) }
.setNegativeButton("No", new DialogInterface.OnClickListener() { });
public void onClick(DialogInterface dialog, int id) {
dialog.cancel(); for (int i = 0; i < promoSpinnerListData.size(); i++) {
} if (cd.getSp_promo() == promoSpinnerListData.get(i).getPromo_id()) {
}); sp_promo.setSelection(i);
AlertDialog alert = builder.create(); }
alert.show();
} }
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); btn_add.setOnClickListener(new View.OnClickListener() {
fab.setOnClickListener(new View.OnClickListener() { @Override
@Override public void onClick(final View v) {
public void onClick(final View view) { AlertDialog.Builder builder = new AlertDialog.Builder(PromoComplianceActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(PromoComplianceActivity.this); builder.setMessage("Are you sure you want to add")
builder.setMessage("Are you sure you want to save") .setCancelable(false)
.setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) {
public void onClick(DialogInterface dialog, int id) {
db.InsertPromoSkuData(promoSkuListData); db.InsertAdditionalPromoData(cd);
AdditionalPromoListView();
Snackbar.make(view, "Data has been saved", Snackbar.LENGTH_LONG).setAction("Action", null).show(); sp_promo.setSelection(0);
//Toast.makeText(getApplicationContext(), "Data has been saved", Toast.LENGTH_LONG).show(); toggle_add_InStock.setChecked(true);
finish(); toggle_add_promoAnnouncer.setChecked(true);
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out); toggle_add_runningPos.setChecked(true);
}
}) Snackbar.make(v, "promo is add", Snackbar.LENGTH_LONG).setAction("Action", null).show();
.setNegativeButton("No", new DialogInterface.OnClickListener() { //Toast.makeText(getApplicationContext(), "promo is add", Toast.LENGTH_LONG).show();
public void onClick(DialogInterface dialog, int id) { }
dialog.cancel(); })
} .setNegativeButton("No", new DialogInterface.OnClickListener() {
}); public void onClick(DialogInterface dialog, int id) {
AlertDialog alert = builder.create(); dialog.cancel();
alert.show(); }
} });
}); AlertDialog alert = builder.create();
alert.show();
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(PromoComplianceActivity.this);
builder.setMessage("Are you sure you want to save")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (db.checkPromoComplianceData(store_id, categoryId)) {
db.updatePromoComplianceSKU(promoSkuListData, categoryId, store_id);
Snackbar.make(view, "Data has been updated", Snackbar.LENGTH_LONG).setAction("Action", null).show();
} else {
db.InsertPromoSkuData(promoSkuListData, categoryId);
Snackbar.make(view, "Data has been saved", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
finish();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
/*ViewTreeObserver.OnScrollChangedListener onScrollChangedListener /*ViewTreeObserver.OnScrollChangedListener onScrollChangedListener
@@ -238,138 +250,182 @@ public class PromoComplianceActivity extends AppCompatActivity {
} }
};*/ };*/
} catch (Exception e) {
e.printStackTrace();
}
} }
private void prepareList() { private void prepareList() {
//Promo SKU List try {
promoSkuListData = db.getPromoComplianceSkuData(store_id); //Promo SKU List
promoSkuListData = db.getPromoComplianceSkuAfterData(store_id, categoryId);
if (!(promoSkuListData.size() > 0)) {
promoSkuListData = db.getPromoComplianceSkuData(store_id);
}
//Promo Spinner List //Promo Spinner List
promoSpinnerListData = db.getPromoSpinnerData(store_id); promoSpinnerListData = db.getPromoSpinnerData(store_id);
ArrayAdapter<String> sp_promo_adapter = new ArrayAdapter<>(PromoComplianceActivity.this, android.R.layout.simple_list_item_1); ArrayAdapter<String> sp_promo_adapter = new ArrayAdapter<>(PromoComplianceActivity.this, android.R.layout.simple_list_item_1);
for (int i = 0; i < promoSpinnerListData.size(); i++) { for (int i = 0; i < promoSpinnerListData.size(); i++) {
sp_promo_adapter.add(promoSpinnerListData.get(i).getPromo()); sp_promo_adapter.add(promoSpinnerListData.get(i).getPromo());
}
sp_promo.setAdapter(sp_promo_adapter);
} catch (Exception e) {
e.printStackTrace();
} }
sp_promo.setAdapter(sp_promo_adapter);
} }
private void promoSkuListView() { private void promoSkuListView() {
View view; try {
View view;
for (int i = 0; i < promoSkuListData.size(); i++) { for (int i = 0; i < promoSkuListData.size(); i++) {
view = getLayoutInflater().inflate(R.layout.item_promo_sku_list, null, false); view = getLayoutInflater().inflate(R.layout.item_promo_sku_list, null, false);
final Promo_Compliance_DataGetterSetter data = promoSkuListData.get(i); final Promo_Compliance_DataGetterSetter data = promoSkuListData.get(i);
TextView txt_promoSkuName = (TextView) view.findViewById(R.id.txt_promoSkuName); TextView txt_promoSkuName = (TextView) view.findViewById(R.id.txt_promoSkuName);
ToggleButton toggle_inStock = (ToggleButton) view.findViewById(R.id.toggle_inStock); ToggleButton toggle_inStock = (ToggleButton) view.findViewById(R.id.toggle_inStock);
ToggleButton toggle_promoAnnouncer = (ToggleButton) view.findViewById(R.id.toggle_promoAnnouncer); ToggleButton toggle_promoAnnouncer = (ToggleButton) view.findViewById(R.id.toggle_promoAnnouncer);
ToggleButton toggle_runningPos = (ToggleButton) view.findViewById(R.id.toggle_runningPos); ToggleButton toggle_runningPos = (ToggleButton) view.findViewById(R.id.toggle_runningPos);
txt_promoSkuName.setText(data.getPromo()); txt_promoSkuName.setText(data.getPromo());
//In Stock //In Stock
toggle_inStock.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { toggle_inStock.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) { if (isChecked) {
data.setIn_stock("1"); data.setIn_stock("1");
} else { } else {
data.setIn_stock("0"); data.setIn_stock("0");
}
} }
});
if (data.getIn_stock().equals("1")) {
toggle_inStock.setChecked(true);
} else {
toggle_inStock.setChecked(false);
} }
});
if (data.getIn_stock().equals("1")) { //Promo Announcer
toggle_inStock.setChecked(true); toggle_promoAnnouncer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
} else { @Override
toggle_inStock.setChecked(false); public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
} if (isChecked) {
data.setPromo_announcer("1");
//Promo Announcer } else {
toggle_promoAnnouncer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { data.setPromo_announcer("0");
@Override }
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
data.setPromo_announcer("1");
} else {
data.setPromo_announcer("0");
} }
});
if (data.getPromo_announcer().equals("1")) {
toggle_promoAnnouncer.setChecked(true);
} else {
toggle_promoAnnouncer.setChecked(false);
} }
});
if (data.getPromo_announcer().equals("1")) { //Running on POS
toggle_promoAnnouncer.setChecked(true); toggle_runningPos.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
} else { @Override
toggle_promoAnnouncer.setChecked(false); public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
} if (isChecked) {
data.setRunning_pos("1");
//Running on POS } else {
toggle_runningPos.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { data.setRunning_pos("0");
@Override }
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
data.setRunning_pos("1");
} else {
data.setRunning_pos("0");
} }
});
if (data.getRunning_pos().equals("1")) {
toggle_runningPos.setChecked(true);
} else {
toggle_runningPos.setChecked(false);
} }
});
if (data.getRunning_pos().equals("1")) { lin_promo_sku.addView(view);
toggle_runningPos.setChecked(true);
} else {
toggle_runningPos.setChecked(false);
} }
} catch (Exception e) {
lin_promo_sku.addView(view); e.printStackTrace();
} }
} }
private void AdditionalPromoListView() { private void AdditionalPromoListView() {
additionalPromoListData.clear(); try {
lin_addtional_promo.removeAllViews(); additionalPromoListData.clear();
lin_addtional_promo.removeAllViews();
//Additional Promo List //Additional Promo List
additionalPromoListData = db.getAdditionalPromoData(); additionalPromoListData = db.getAdditionalPromoData();
View view; View view;
for (int i = 0; i < additionalPromoListData.size(); i++) { for (int i = 0; i < additionalPromoListData.size(); i++) {
view = getLayoutInflater().inflate(R.layout.item_additional_promo_list, null, false); view = getLayoutInflater().inflate(R.layout.item_additional_promo_list, null, false);
final Promo_Compliance_DataGetterSetter data = additionalPromoListData.get(i); final Promo_Compliance_DataGetterSetter data = additionalPromoListData.get(i);
TextView txt_promoName = (TextView) view.findViewById(R.id.txt_promoName); TextView txt_promoName = (TextView) view.findViewById(R.id.txt_promoName);
TextView txt_inStock = (TextView) view.findViewById(R.id.txt_inStock); TextView txt_inStock = (TextView) view.findViewById(R.id.txt_inStock);
TextView txt_promoAnnouncer = (TextView) view.findViewById(R.id.txt_promoAnnouncer); TextView txt_promoAnnouncer = (TextView) view.findViewById(R.id.txt_promoAnnouncer);
TextView txt_runningPos = (TextView) view.findViewById(R.id.txt_runningPos); TextView txt_runningPos = (TextView) view.findViewById(R.id.txt_runningPos);
txt_promoName.setText(data.getPromo()); txt_promoName.setText(data.getPromo());
//In Stock //In Stock
if (data.getIn_stock().equals("1")) { if (data.getIn_stock().equals("1")) {
txt_inStock.setText("Yes"); txt_inStock.setText("Yes");
} else { } else {
txt_inStock.setText("No"); txt_inStock.setText("No");
}
//Promo Announcer
if (data.getPromo_announcer().equals("1")) {
txt_promoAnnouncer.setText("Yes");
} else {
txt_promoAnnouncer.setText("No");
}
//Running on POS
if (data.getRunning_pos().equals("1")) {
txt_runningPos.setText("Yes");
} else {
txt_runningPos.setText("No");
}
lin_addtional_promo.addView(view);
} }
} catch (Exception e) {
//Promo Announcer e.printStackTrace();
if (data.getPromo_announcer().equals("1")) {
txt_promoAnnouncer.setText("Yes");
} else {
txt_promoAnnouncer.setText("No");
}
//Running on POS
if (data.getRunning_pos().equals("1")) {
txt_runningPos.setText("Yes");
} else {
txt_runningPos.setText("No");
}
lin_addtional_promo.addView(view);
} }
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
}
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
} }
@@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@@ -76,186 +77,196 @@ public class Stock_FacingActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stock_facing); try {
setContentView(R.layout.activity_stock_facing);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
db = new GSKOrangeDB(this); db = new GSKOrangeDB(this);
db.open(); db.open();
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView); expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
txt_stockFacingName = (TextView) findViewById(R.id.txt_stockFacingName); txt_stockFacingName = (TextView) findViewById(R.id.txt_stockFacingName);
//preference data //preference data
preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences = PreferenceManager.getDefaultSharedPreferences(this);
store_id = preferences.getString(CommonString.KEY_STORE_ID, null); store_id = preferences.getString(CommonString.KEY_STORE_ID, null);
visit_date = preferences.getString(CommonString.KEY_DATE, null); visit_date = preferences.getString(CommonString.KEY_DATE, null);
date = preferences.getString(CommonString.KEY_DATE, null); date = preferences.getString(CommonString.KEY_DATE, null);
username = preferences.getString(CommonString.KEY_USERNAME, null); username = preferences.getString(CommonString.KEY_USERNAME, null);
intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, ""); intime = preferences.getString(CommonString.KEY_STORE_IN_TIME, "");
keyAccount_id = preferences.getString(CommonString.KEY_KEYACCOUNT_ID, ""); keyAccount_id = preferences.getString(CommonString.KEY_KEYACCOUNT_ID, "");
class_id = preferences.getString(CommonString.KEY_CLASS_ID, ""); class_id = preferences.getString(CommonString.KEY_CLASS_ID, "");
storeType_id = preferences.getString(CommonString.KEY_STORETYPE_ID, ""); storeType_id = preferences.getString(CommonString.KEY_STORETYPE_ID, "");
categoryName = getIntent().getStringExtra("categoryName"); categoryName = getIntent().getStringExtra("categoryName");
categoryId = getIntent().getStringExtra("categoryId"); categoryId = getIntent().getStringExtra("categoryId");
//txt_stockFacingName.setText(categoryName); //txt_stockFacingName.setText(categoryName);
txt_stockFacingName.setText(getResources().getString(R.string.title_activity_stock_facing)); txt_stockFacingName.setText(getResources().getString(R.string.title_activity_stock_facing));
prepareList(); prepareList();
str = CommonString.FILE_PATH + _pathforcheck; str = CommonString.FILE_PATH + _pathforcheck;
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(final View view) {
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) /*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/ .setAction("Action", null).show();*/
if (validateData(hashMapListHeaderData, hashMapListChildData)) { if (validateData(hashMapListHeaderData, hashMapListChildData)) {
AlertDialog.Builder builder = new AlertDialog.Builder(Stock_FacingActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(Stock_FacingActivity.this);
builder.setMessage("Are you sure you want to save") builder.setMessage("Are you sure you want to save")
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() { .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
db.open(); db.open();
if (db.checkStockAndFacingData(store_id, categoryId)) { if (db.checkStockAndFacingData(store_id, categoryId)) {
db.updateStockAndFacing(store_id, categoryId, hashMapListHeaderData, hashMapListChildData); db.updateStockAndFacing(store_id, categoryId, hashMapListHeaderData, hashMapListChildData);
} else { Snackbar.make(view, "Data has been updated", Snackbar.LENGTH_LONG).setAction("Action", null).show();
db.InsertStock_Facing(store_id, categoryId, hashMapListHeaderData, hashMapListChildData); } else {
db.InsertStock_Facing(store_id, categoryId, hashMapListHeaderData, hashMapListChildData);
Snackbar.make(view, "Data has been saved", Snackbar.LENGTH_LONG).setAction("Action", null).show();
//Toast.makeText(getApplicationContext(), "Data has been saved", Toast.LENGTH_LONG).show();
}
finish();
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
} }
})
Toast.makeText(getApplicationContext(), "Data has been saved", Toast.LENGTH_LONG).show(); .setNegativeButton("No", new DialogInterface.OnClickListener() {
finish(); public void onClick(DialogInterface dialog, int id) {
overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out); dialog.cancel();
} }
}) });
.setNegativeButton("No", new DialogInterface.OnClickListener() { AlertDialog alert = builder.create();
public void onClick(DialogInterface dialog, int id) { alert.show();
dialog.cancel(); } else {
} AlertDialog.Builder builder = new AlertDialog.Builder(Stock_FacingActivity.this);
}); builder.setMessage("Fill the value or fill 0 ")
AlertDialog alert = builder.create(); .setCancelable(false)
alert.show(); .setPositiveButton("OK", new DialogInterface.OnClickListener() {
} else { public void onClick(DialogInterface dialog, int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(Stock_FacingActivity.this); dialog.dismiss();
builder.setMessage("Fill the value or fill 0 ") }
.setCancelable(false) });
.setPositiveButton("OK", new DialogInterface.OnClickListener() { AlertDialog alert = builder.create();
public void onClick(DialogInterface dialog, int id) { alert.show();
dialog.dismiss(); }
}
});
AlertDialog alert = builder.create();
alert.show();
} }
} });
});
expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() { expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override @Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int lastItem = firstVisibleItem + visibleItemCount; int lastItem = firstVisibleItem + visibleItemCount;
if (firstVisibleItem == 0) { if (firstVisibleItem == 0) {
fab.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE);
} else if (lastItem == totalItemCount) { } else if (lastItem == totalItemCount) {
fab.setVisibility(View.INVISIBLE); fab.setVisibility(View.INVISIBLE);
} else { } else {
fab.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE);
} }
}
@Override
public void onScrollStateChanged(AbsListView arg0, int arg1) {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
} }
expandableListView.invalidateViews(); @Override
} public void onScrollStateChanged(AbsListView arg0, int arg1) {
}); InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
}
// Listview Group click listener expandableListView.invalidateViews();
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
return false;
}
});
// Listview Group expanded listener
expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getWindow().getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
} }
} });
});
// Listview Group collasped listener // Listview Group click listener
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() { expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override @Override
public void onGroupCollapse(int groupPosition) { public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext() return false;
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getWindow().getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
} }
} });
});
// Listview on child click listener // Listview Group expanded listener
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, public void onGroupExpand(int groupPosition) {
int childPosition, long id) { InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
return false; .getSystemService(Context.INPUT_METHOD_SERVICE);
} if (getWindow().getCurrentFocus() != null) {
}); inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
}
}
});
// Listview Group collasped listener
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (getWindow().getCurrentFocus() != null) {
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
getCurrentFocus().clearFocus();
}
}
});
// Listview on child click listener
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
return false;
}
});
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
} }
private void prepareList() { private void prepareList() {
hashMapListHeaderData = new ArrayList<>(); try {
hashMapListChildData = new HashMap<>(); hashMapListHeaderData = new ArrayList<>();
hashMapListChildData = new HashMap<>();
//Header Data //Header Data
headerDataList = db.getStockAndFacingHeader_AfterSaveData(categoryId); headerDataList = db.getStockAndFacingHeader_AfterSaveData(categoryId);
if (!(headerDataList.size() > 0)) { if (!(headerDataList.size() > 0)) {
headerDataList = db.getStockAndFacingHeaderData(categoryId); headerDataList = db.getStockAndFacingHeaderData(categoryId);
}
if (headerDataList.size() > 0) {
for (int i = 0; i < headerDataList.size(); i++) {
hashMapListHeaderData.add(headerDataList.get(i));
//Child Data
childDataList = db.getStockAndFacingSKU_AfterSaveData(categoryId, headerDataList.get(i).getBrand_id());
if (!(childDataList.size() > 0)) {
childDataList = db.getStockAndFacingSKUData(categoryId, headerDataList.get(i).getBrand_id());
}
hashMapListChildData.put(hashMapListHeaderData.get(i), childDataList);
} }
}
adapter = new ExpandableListAdapter(this, hashMapListHeaderData, hashMapListChildData); if (headerDataList.size() > 0) {
expandableListView.setAdapter(adapter);
for (int i = 0; i < headerDataList.size(); i++) {
hashMapListHeaderData.add(headerDataList.get(i));
//Child Data
childDataList = db.getStockAndFacingSKU_AfterSaveData(categoryId, headerDataList.get(i).getBrand_id());
if (!(childDataList.size() > 0)) {
childDataList = db.getStockAndFacingSKUData(categoryId, headerDataList.get(i).getBrand_id());
}
hashMapListChildData.put(hashMapListHeaderData.get(i), childDataList);
}
}
adapter = new ExpandableListAdapter(this, hashMapListHeaderData, hashMapListChildData);
expandableListView.setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
} }
public class ExpandableListAdapter extends BaseExpandableListAdapter { public class ExpandableListAdapter extends BaseExpandableListAdapter {
@@ -326,9 +337,9 @@ public class Stock_FacingActivity extends AppCompatActivity {
} }
if (headerTitle.getImage1().equals("")) { if (headerTitle.getImage1().equals("")) {
img_camera1.setBackgroundResource(R.drawable.ic_menu_camera); img_camera1.setBackgroundResource(R.mipmap.camera);
} else { } else {
img_camera1.setBackgroundResource(R.drawable.ic_menu_gallery); img_camera1.setBackgroundResource(R.mipmap.camera_done);
} }
@@ -354,9 +365,9 @@ public class Stock_FacingActivity extends AppCompatActivity {
} }
if (headerTitle.getImage2().equals("")) { if (headerTitle.getImage2().equals("")) {
img_camera2.setBackgroundResource(R.drawable.ic_menu_camera); img_camera2.setBackgroundResource(R.mipmap.camera);
} else { } else {
img_camera2.setBackgroundResource(R.drawable.ic_menu_gallery); img_camera2.setBackgroundResource(R.mipmap.camera_done);
} }
@@ -51,7 +51,7 @@
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:src="@android:drawable/btn_star_big_off" /> android:src="@mipmap/star" />
<ImageView <ImageView
android:id="@+id/img_camera1" android:id="@+id/img_camera1"
@@ -72,7 +72,7 @@
android:layout_width="25dp" android:layout_width="25dp"
android:layout_height="25dp" android:layout_height="25dp"
android:layout_marginRight="20dp" android:layout_marginRight="20dp"
android:src="@android:drawable/ic_menu_edit" /> android:src="@mipmap/no_camera" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>