Commit 6cf45268 by Jemsheer K D

Order Info Page

parent 1df5b1b9
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
package in.techware.carrefour.activity.info; package in.techware.carrefour.activity.info;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -11,22 +12,14 @@ import android.view.inputmethod.InputMethodManager; ...@@ -11,22 +12,14 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;
import in.techware.carrefour.R; import in.techware.carrefour.R;
import in.techware.carrefour.activity.BaseAppCompatNoDrawerActivity; import in.techware.carrefour.activity.BaseAppCompatNoDrawerActivity;
import in.techware.carrefour.app.App;
import in.techware.carrefour.config.Config;
import in.techware.carrefour.dialogs.PopupMessage; import in.techware.carrefour.dialogs.PopupMessage;
import in.techware.carrefour.dialogs.ProductInfoUnitDialog; import in.techware.carrefour.dialogs.ProductInfoUnitDialog;
import in.techware.carrefour.listeners.BarcodeUpdateListener; import in.techware.carrefour.listeners.BarcodeUpdateListener;
import in.techware.carrefour.listeners.ProductInfoListener;
import in.techware.carrefour.model.FamilyBean; import in.techware.carrefour.model.FamilyBean;
import in.techware.carrefour.model.MenuBean; import in.techware.carrefour.model.MenuBean;
import in.techware.carrefour.model.ProductInfoBean;
import in.techware.carrefour.net.DataManager;
import in.techware.carrefour.util.AppConstants; import in.techware.carrefour.util.AppConstants;
import in.techware.carrefour.util.BarcodeUtil; import in.techware.carrefour.util.BarcodeUtil;
import in.techware.carrefour.util.TimeUtil; import in.techware.carrefour.util.TimeUtil;
...@@ -81,6 +74,8 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -81,6 +74,8 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
initToolbar(); initToolbar();
initViews(); initViews();
initViewModelCallbacks();
handleKeyboard(); handleKeyboard();
// populateViewModel(); // populateViewModel();
...@@ -140,6 +135,8 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -140,6 +135,8 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
etxtBarcode.requestFocus(); etxtBarcode.requestFocus();
} }
clearViews();
btnUnit.setOnClickListener(new View.OnClickListener() { btnUnit.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -185,11 +182,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -185,11 +182,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
viewModel.setBarcode(BarcodeUtil.getFormattedBarcode(barcode)); viewModel.setBarcode(BarcodeUtil.getFormattedBarcode(barcode));
setProgressScreenVisibility(true, true); setProgressScreenVisibility(true, true);
if (App.isNetworkAvailable()) { viewModel.fetchProductInfo();
fetchProductInfoFromWS();
} else {
fetchProductInfoFromFile();
}
} }
return true; return true;
...@@ -209,15 +202,25 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -209,15 +202,25 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
viewModel.setBarcode(barcode); viewModel.setBarcode(barcode);
setProgressScreenVisibility(true, true); setProgressScreenVisibility(true, true);
if (App.isNetworkAvailable()) { viewModel.fetchProductInfo();
fetchProductInfoFromWS();
} else {
fetchProductInfoFromFile();
}
} }
}; };
addBarcodeUpdateListener(barcodeUpdateListener); addBarcodeUpdateListener(barcodeUpdateListener);
}
private void initViewModelCallbacks() {
viewModel.isFetchingFinished().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean isFetchingFinished) {
if (isFetchingFinished) {
populateProductInfo();
}
}
});
} }
...@@ -379,54 +382,16 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -379,54 +382,16 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
} }
} }
private void fetchProductInfoFromWS() {
HashMap<String, String> urlParams = new HashMap<>(); private void populateProductInfo() {
urlParams.put("StoreID", Config.getInstance().getAppSettingsBean().getStoreID()); if (viewModel.getProductInfoBean() != null) {
setData();
int type = AppConstants.PRODUCT_INFO_TYPE_NORMAL;
if (viewModel.getBarcode().startsWith("21")) {
urlParams.put("BarCode", viewModel.getBarcode().substring(0, 7));
type = AppConstants.PRODUCT_INFO_TYPE_MARKET;
} else { } else {
urlParams.put("BarCode", viewModel.getBarcode()); PopupMessage popupMessage = new PopupMessage(this);
} popupMessage.show(getString(R.string.message_item_not_found), 0, getString(R.string.btn_ok));
clearViews();
DataManager.fetchProductInfo(urlParams, type, new ProductInfoListener() {
@Override
public void onLoadCompleted(ProductInfoBean productInfoBean) {
viewModel.setProductInfoBean(ProductInfoUtil.parseProductInfo(productInfoBean));
if (viewModel.getProductInfoBean() != null) {
setData();
} else {
PopupMessage popupMessage = new PopupMessage(ProductInfoActivity.this);
popupMessage.show(getString(R.string.message_item_not_found), 0, getString(R.string.btn_ok));
clearViews();
}
setProgressScreenVisibility(false, false);
}
@Override
public void onLoadFailed(String error) {
Toast.makeText(ProductInfoActivity.this, error, Toast.LENGTH_SHORT).show();
clearViews();
setProgressScreenVisibility(false, false);
}
});
}
private void fetchProductInfoFromFile() {
if (Config.getInstance().getProductInfoList() != null && !Config.getInstance().getProductInfoList().isEmpty()) {
viewModel.setProductInfoBean(Config.getInstance().searchProductInfo(viewModel.getBarcode()));
if (viewModel.getProductInfoBean() != null) {
setData();
} else {
PopupMessage popupMessage = new PopupMessage(this);
popupMessage.show(getString(R.string.message_item_not_found), 0, getString(R.string.btn_ok));
clearViews();
}
setProgressScreenVisibility(false, false);
} }
setProgressScreenVisibility(false, false);
} }
private void onProductInfoUnitClick(View view) { private void onProductInfoUnitClick(View view) {
...@@ -461,6 +426,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -461,6 +426,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
//mVibrator.vibrate(25); //mVibrator.vibrate(25);
startActivity(new Intent(getApplicationContext(), LabelActivity.class) startActivity(new Intent(getApplicationContext(), LabelActivity.class)
.putExtra("menuBean", viewModel.getSelectedMenuBean())
.putExtra("bean", viewModel.getProductInfoBean()) .putExtra("bean", viewModel.getProductInfoBean())
.putExtra("barcode", viewModel.getBarcode())); .putExtra("barcode", viewModel.getBarcode()));
finish(); finish();
...@@ -471,6 +437,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -471,6 +437,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
//mVibrator.vibrate(25); //mVibrator.vibrate(25);
startActivity(new Intent(getApplicationContext(), OrderInfoActivity.class) startActivity(new Intent(getApplicationContext(), OrderInfoActivity.class)
.putExtra("menuBean", viewModel.getSelectedMenuBean())
.putExtra("bean", viewModel.getProductInfoBean()) .putExtra("bean", viewModel.getProductInfoBean())
.putExtra("barcode", viewModel.getBarcode())); .putExtra("barcode", viewModel.getBarcode()));
finish(); finish();
...@@ -481,6 +448,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity { ...@@ -481,6 +448,7 @@ public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {
//mVibrator.vibrate(25); //mVibrator.vibrate(25);
startActivity(new Intent(getApplicationContext(), WeekMovementActivity.class) startActivity(new Intent(getApplicationContext(), WeekMovementActivity.class)
.putExtra("menuBean", viewModel.getSelectedMenuBean())
.putExtra("bean", viewModel.getProductInfoBean()) .putExtra("bean", viewModel.getProductInfoBean())
.putExtra("barcode", viewModel.getBarcode())); .putExtra("barcode", viewModel.getBarcode()));
finish(); finish();
......
package `in`.techware.carrefour.viewModels package `in`.techware.carrefour.viewModels
import `in`.techware.carrefour.app.App
import `in`.techware.carrefour.config.Config
import `in`.techware.carrefour.listeners.ProductInfoListener
import `in`.techware.carrefour.model.MenuBean import `in`.techware.carrefour.model.MenuBean
import `in`.techware.carrefour.model.ProductInfoBean import `in`.techware.carrefour.model.ProductInfoBean
import `in`.techware.carrefour.net.DataManager
import `in`.techware.carrefour.util.AppConstants
import `in`.techware.carrefour.util.menuUtils.ProductInfoUtil
import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel import android.arch.lifecycle.ViewModel
import android.widget.Toast
import java.util.*
import kotlin.collections.set
/** /**
* Created by Jemsheer K D on 27 July, 2018. * Created by Jemsheer K D on 27 July, 2018.
...@@ -17,7 +27,8 @@ class ProductInfoViewModel : ViewModel() { ...@@ -17,7 +27,8 @@ class ProductInfoViewModel : ViewModel() {
var selectedMenuBean: MenuBean? = null var selectedMenuBean: MenuBean? = null
var productInfoList: ArrayList<ProductInfoBean> = ArrayList() var isFetchingFinished: MutableLiveData<Boolean> = MutableLiveData()
fun setData(bean: ProductInfoBean) { fun setData(bean: ProductInfoBean) {
...@@ -29,25 +40,51 @@ class ProductInfoViewModel : ViewModel() { ...@@ -29,25 +40,51 @@ class ProductInfoViewModel : ViewModel() {
productInfoBean = null productInfoBean = null
} }
fun indexOf(productInfoBean: ProductInfoBean): Int { fun fetchProductInfo() {
for (bean in productInfoList) { isFetchingFinished.value = false
if (bean.barcode == productInfoBean.barcode) { if (App.isNetworkAvailable()) {
return productInfoList.indexOf(bean) fetchProductInfoFromWS()
} } else {
fetchProductInfoFromFile()
} }
return -1
} }
fun lastIndex(): Int { private fun fetchProductInfoFromWS() {
return productInfoList.size - 1
} val urlParams = HashMap<String, String>()
urlParams["StoreID"] = Config.getInstance().appSettingsBean.storeID
var type = AppConstants.PRODUCT_INFO_TYPE_NORMAL
if (barcode.startsWith("21")) {
urlParams["BarCode"] = barcode.substring(0, 7)
type = AppConstants.PRODUCT_INFO_TYPE_MARKET
} else {
urlParams["BarCode"] = barcode
}
fun indexOf(barcode: String): Int { DataManager.fetchProductInfo(urlParams, type, object : ProductInfoListener {
for (bean in productInfoList) { override fun onLoadCompleted(productInfoBeanWS: ProductInfoBean) {
if (bean.barcode == barcode) { productInfoBean = ProductInfoUtil.parseProductInfo(productInfoBeanWS)
return productInfoList.indexOf(bean) isFetchingFinished.value = true
} }
override fun onLoadFailed(error: String) {
Toast.makeText(App.getInstance(), error, Toast.LENGTH_SHORT).show()
productInfoBean = null
isFetchingFinished.value = true
}
})
}
private fun fetchProductInfoFromFile() {
if (Config.getInstance().productInfoList != null && !Config.getInstance().productInfoList.isEmpty()) {
productInfoBean = Config.getInstance().searchProductInfo(barcode)
isFetchingFinished.value = true
} else {
productInfoBean = null
isFetchingFinished.value = true
} }
return -1
} }
} }
\ No newline at end of file
...@@ -136,19 +136,19 @@ ...@@ -136,19 +136,19 @@
<string name="label_survey_placeholder">Label Survey</string> <string name="label_survey_placeholder">Label Survey</string>
<string name="label_today_selling_price">Today Selling Price</string> <string name="label_today_selling_price">Today Selling Price</string>
<string name="label_zone">Zone</string> <string name="label_zone">Zone</string>
<string name="last_recept_date_value">Last reception date</string> <string name="label_last_reception_date">Last reception date</string>
<string name="lpo_type_value">Supplier LPO Type</string> <string name="label_supplier_lpo_type">Supplier LPO Type</string>
<string name="main_menu_placeholder">Main Menu</string> <string name="main_menu_placeholder">Main Menu</string>
<string name="main_page_placeholder">Main Page</string> <string name="main_page_placeholder">Main Page</string>
<string name="next_delivery_value">Next delivery date</string> <string name="label_next_delivery_date">Next delivery date</string>
<string name="next_ordering_value">Next ordering date</string> <string name="label_next_ordering_date">Next ordering date</string>
<string name="offsite_storage_in_label">Off-Site Storage IN</string> <string name="offsite_storage_in_label">Off-Site Storage IN</string>
<string name="offsite_storage_out_label">Off-Site Storage OUT</string> <string name="offsite_storage_out_label">Off-Site Storage OUT</string>
<string name="order_info_label">Order Info</string> <string name="order_info_label">Order Info</string>
<string name="order_placeholder">Order</string> <string name="order_placeholder">Order</string>
<string name="password_label">Password</string> <string name="password_label">Password</string>
<string name="pcb_value">PCB</string> <string name="label_pcb">PCB</string>
<string name="pending_orders_value">Pending Orders</string> <string name="label_pending_orders">Pending Orders</string>
<string name="percentage_progress_label">46%</string> <string name="percentage_progress_label">46%</string>
<string name="pit_number_placeholder">PIT Number</string> <string name="pit_number_placeholder">PIT Number</string>
<string name="price_label">Price</string> <string name="price_label">Price</string>
...@@ -161,11 +161,11 @@ ...@@ -161,11 +161,11 @@
<string name="shelf_print_label">Print Shelf Label</string> <string name="shelf_print_label">Print Shelf Label</string>
<string name="spinner_arrow">\u02C5</string> <string name="spinner_arrow">\u02C5</string>
<string name="spinner_prompt">1-Freshness, Quality</string> <string name="spinner_prompt">1-Freshness, Quality</string>
<string name="stock_min_value">Stock minimum</string> <string name="label_stock_minimum">Stock minimum</string>
<string name="stock_take_placeholder">Stock Take</string> <string name="stock_take_placeholder">Stock Take</string>
<string name="store_placeholder">456</string> <string name="store_placeholder">456</string>
<string name="supplier_dc_value">SUPPLIER or DC</string> <string name="label_supplier_or_dc">SUPPLIER or DC</string>
<string name="supplier_lead_time_value">Supplier Lead Time</string> <string name="label_supplier_lead_time">Supplier Lead Time</string>
<string name="title_expiry_action">Expiry Action</string> <string name="title_expiry_action">Expiry Action</string>
<string name="title_file_transfer">File Transfer</string> <string name="title_file_transfer">File Transfer</string>
<string name="title_get_orders">Get Orders</string> <string name="title_get_orders">Get Orders</string>
...@@ -867,6 +867,8 @@ ...@@ -867,6 +867,8 @@
<string name="sample_unit">Composed/Pack</string> <string name="sample_unit">Composed/Pack</string>
<string name="label_updated_on">Updated On-</string> <string name="label_updated_on">Updated On-</string>
<string name="message_item_not_found">Item not found</string> <string name="message_item_not_found">Item not found</string>
<string name="btn_main_page">Main Page</string>
<string name="title_order_info">Order Info</string>
<string-array name="menu_home"> <string-array name="menu_home">
......
...@@ -11,7 +11,7 @@ buildscript { ...@@ -11,7 +11,7 @@ buildscript {
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha11' classpath 'com.android.tools.build:gradle:3.3.0-alpha12'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'io.fabric.tools:gradle:1+' classpath 'io.fabric.tools:gradle:1+'
......
#Fri Sep 14 10:22:14 IST 2018 #Thu Sep 27 11:09:58 IST 2018
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment