city and zones

This commit is contained in:
cimenmus
2017-10-23 23:59:04 +03:00
parent 61fb410abe
commit d7395683a5
11 changed files with 548 additions and 13 deletions

View File

@@ -4,9 +4,14 @@ import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import com.afollestad.materialdialogs.MaterialDialog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import butterknife.BindString;
import butterknife.BindView;
@@ -16,11 +21,15 @@ import butterknife.OnClick;
import ch.pizzalink.android.R;
import ch.pizzalink.android.api.ApiErrorUtils;
import ch.pizzalink.android.api.ApiService;
import ch.pizzalink.android.api.ResponseArray;
import ch.pizzalink.android.api.ResponseObject;
import ch.pizzalink.android.helper.DialogHelper;
import ch.pizzalink.android.helper.SharedPrefsHelper;
import ch.pizzalink.android.helper.ViewHelper;
import ch.pizzalink.android.model.ZoneModel;
import ch.pizzalink.android.model.CountryModel;
import ch.pizzalink.android.model.UserModel;
import ch.pizzalink.android.view.PizzalinkDropdown;
import ch.pizzalink.android.view.PizzalinkEditText;
import ch.pizzalink.android.view.PizzalinkToolbar;
import retrofit2.Call;
@@ -34,21 +43,34 @@ public class RegisterActivity extends BaseActivity {
@BindViews({ R.id.firstnamePizzalinkEditText, R.id.lasstnamePizzalinkEditText,
R.id.telephonePizzalinkEditText, R.id.emailPizzalinkEditText,
R.id.passwordPizzalinkEditText, R.id.passwordAgainPizzalinkEditText,
R.id.address1PizzalinkEditText, R.id.cityPizzalinkEditText,
R.id.postcodePizzalinkEditText})
R.id.address1PizzalinkEditText, R.id.cityPizzalinkEditText})
List<PizzalinkEditText> pizzalinkEditTextList;
@BindView(R.id.zonePizzalinkDropdown) PizzalinkDropdown zonePizzalinkDropdown;
@BindView(R.id.postcodePizzalinkDrowpdown) PizzalinkDropdown postcodePizzalinkDrowpdown;
@BindView(R.id.countryPizzalinkDropdown) PizzalinkDropdown countryPizzalinkDropdown;
@BindString(R.string.alert_fill_all_fields) String fillAllFieldsText;
@BindString(R.string.alert_invalid_email) String validEmailText;
@BindString(R.string.alert_passwords_not_matched) String passwordsNotMatchedText;
@BindString(R.string.alert_invalid_post_code) String invalidPostCodeText;
private ArrayList<ZoneModel> zoneList = new ArrayList<>();
private ArrayList<CountryModel> countryList = new ArrayList<>();
private ZoneModel selectedZoneModel;
private CountryModel selectedCountryModel;
private int activeRequestCount = 0;
private ReentrantLock lock = new ReentrantLock();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
ButterKnife.bind(this);
initViews();
getZoneList();
getCountryList();
//setTestFields();
}
@@ -66,6 +88,18 @@ public class RegisterActivity extends BaseActivity {
onBackPressed();
}
});
zonePizzalinkDropdown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showZoneDialog();
}
});
countryPizzalinkDropdown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCountryDialog();
}
});
}
private boolean checkFields(){
@@ -95,14 +129,105 @@ public class RegisterActivity extends BaseActivity {
return false;
}
if(pizzalinkEditTextList.get(8).getText().length() != 4){
DialogHelper.showAlertDialog(this, invalidPostCodeText);
if(zonePizzalinkDropdown.isEmpty() ||
postcodePizzalinkDrowpdown.isEmpty() ||
countryPizzalinkDropdown.isEmpty()){
DialogHelper.showAlertDialog(this, fillAllFieldsText);
return false;
}
return true;
}
private void getZoneList(){
if(activeRequestCount == 0)
DialogHelper.showLoadingDialog();
Call<ResponseArray<ZoneModel>> call = ApiService.apiInterface.getZoneList();
call.enqueue(new Callback<ResponseArray<ZoneModel>>() {
@Override
public void onResponse(Call<ResponseArray<ZoneModel>> call, Response<ResponseArray<ZoneModel>> response) {
decreaseActiveRequestCount();
if(activeRequestCount == 0)
DialogHelper.hideLoadingDialog();
if(response.isSuccessful() &&
response.body().getData() != null &&
response.body().isSuccess()){
fillAndNotifyZoneList(response.body().getData());
}
else if(activeRequestCount == 0){
ApiErrorUtils.parseError(response);
}
}
@Override
public void onFailure(Call<ResponseArray<ZoneModel>> call, Throwable t) {
decreaseActiveRequestCount();
if(activeRequestCount == 0){
DialogHelper.hideLoadingDialog();
DialogHelper.showFailedDialog();
}
}
});
increaseActiveRequestCount();
}
private void getCountryList(){
if(activeRequestCount == 0)
DialogHelper.showLoadingDialog();
increaseActiveRequestCount();
Call<ResponseArray<CountryModel>> call = ApiService.apiInterface.getCountryList();
call.enqueue(new Callback<ResponseArray<CountryModel>>() {
@Override
public void onResponse(Call<ResponseArray<CountryModel>> call, Response<ResponseArray<CountryModel>> response) {
decreaseActiveRequestCount();
if(activeRequestCount == 0)
DialogHelper.hideLoadingDialog();
if(response.isSuccessful() &&
response.body().getData() != null &&
response.body().isSuccess()){
fillAndNotifyCountryList(response.body().getData());
}
else if(activeRequestCount == 0){
ApiErrorUtils.parseError(response);
}
}
@Override
public void onFailure(Call<ResponseArray<CountryModel>> call, Throwable t) {
decreaseActiveRequestCount();
if(activeRequestCount == 0){
DialogHelper.hideLoadingDialog();
DialogHelper.showFailedDialog();
}
}
});
}
private void fillAndNotifyZoneList(ArrayList<ZoneModel> zones){
ZoneModel.checkNull(zones);
zoneList.clear();
zoneList.addAll(zones);
}
private void fillAndNotifyCountryList(ArrayList<CountryModel> countries){
CountryModel.checkNull(countries);
countryList.clear();
countryList.addAll(countries);
}
private void registerUser(){
DialogHelper.showLoadingDialog();
Call<ResponseObject<UserModel>> call = ApiService.apiInterface.register(getRegisterParams());
@@ -143,12 +268,45 @@ public class RegisterActivity extends BaseActivity {
params.put("address_1", pizzalinkEditTextList.get(6).getText());
params.put("address_2", "");
params.put("city", pizzalinkEditTextList.get(7).getText());
params.put("postcode", pizzalinkEditTextList.get(8).getText());
params.put("country_id", "1");
params.put("postcode", postcodePizzalinkDrowpdown.getText());
params.put("zone_id", "1");
params.put("country_id", "1");
return params;
}
private void showZoneDialog(){
final ArrayList<String> zoneNameList = new ArrayList<>();
for(ZoneModel zone : zoneList){
zoneNameList.add(zone.getCity());
}
DialogHelper.showListDialog(zoneNameList, new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
selectedZoneModel = zoneList.get(position);
zonePizzalinkDropdown.setText(selectedZoneModel.getCity());
postcodePizzalinkDrowpdown.setText(selectedZoneModel.getPostcode());
}
});
}
private void showCountryDialog(){
final ArrayList<String> countryNameList = new ArrayList<>();
for(CountryModel country : countryList){
countryNameList.add(country.getName());
}
DialogHelper.showListDialog(countryNameList, new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
selectedCountryModel = countryList.get(position);
countryPizzalinkDropdown.setText(selectedCountryModel.getName());
}
});
}
private void setTestFields(){
pizzalinkEditTextList.get(0).getEditText().setText("testname");
pizzalinkEditTextList.get(1).getEditText().setText("testsurname");
@@ -158,6 +316,26 @@ public class RegisterActivity extends BaseActivity {
pizzalinkEditTextList.get(5).getEditText().setText("test");
pizzalinkEditTextList.get(6).getEditText().setText("test address 1");
pizzalinkEditTextList.get(7).getEditText().setText("test");
pizzalinkEditTextList.get(8).getEditText().setText("1234");
postcodePizzalinkDrowpdown.setText("1234");
}
private synchronized void increaseActiveRequestCount(){
lock.lock();
try {
activeRequestCount++;
}finally {
lock.unlock();
}
}
private synchronized void decreaseActiveRequestCount(){
lock.lock();
try {
activeRequestCount--;
}finally {
lock.unlock();
}
}
}

View File

@@ -21,6 +21,7 @@ public class ApiEndPoints {
public static final String API_CREATE_ORDER = PREFIX + "addOrder2" + SUFFIX + "&token=";
public static final String API_CHECK_UPDATE = PREFIX + "checkUpdate" + SUFFIX;
public static final String API_FORGOT_PASSWORD = PREFIX + "forgotPassword" + SUFFIX;
public static final String API_GET_ZONE_LIST = PREFIX + "getCities" + SUFFIX;
public static final String API_GET_COUNTRY_LIST = PREFIX + "getCountries" + SUFFIX;
}

View File

@@ -5,10 +5,12 @@ import java.util.HashMap;
import ch.pizzalink.android.model.AddProductToBasketResponseModel;
import ch.pizzalink.android.model.AddressModel;
import ch.pizzalink.android.model.AppVersionModel;
import ch.pizzalink.android.model.CountryModel;
import ch.pizzalink.android.model.PaymentMethodModel;
import ch.pizzalink.android.model.PaymentMethodsResponseModel;
import ch.pizzalink.android.model.ShippingMethodModel;
import ch.pizzalink.android.model.ShippingMethodsResponseModel;
import ch.pizzalink.android.model.ZoneModel;
import ch.pizzalink.android.model.cart.CartInfoModel;
import ch.pizzalink.android.model.CategoryModel;
import ch.pizzalink.android.model.OrderModel;
@@ -104,5 +106,11 @@ public interface ApiInterface {
@POST(ApiEndPoints.API_FORGOT_PASSWORD)
Call<ResponseObject> forgotPassword(@Field("email") String emailAddress);
@GET(ApiEndPoints.API_GET_ZONE_LIST)
Call<ResponseArray<ZoneModel>> getZoneList();
@GET(ApiEndPoints.API_GET_COUNTRY_LIST)
Call<ResponseArray<CountryModel>> getCountryList();
}

View File

@@ -8,6 +8,8 @@ import android.support.v4.content.ContextCompat;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import java.util.ArrayList;
import ch.pizzalink.android.R;
import ch.pizzalink.android.activity.BaseActivity;
import ch.pizzalink.android.activity.LoginActivity;
@@ -153,4 +155,12 @@ public class DialogHelper {
}
public static void showListDialog(ArrayList<String> itemList, MaterialDialog.ListCallback listCallback){
new MaterialDialog.Builder(BaseActivity.currentActivity)
.title(R.string.choose)
.items(itemList)
.itemsCallback(listCallback)
.show();
}
}

View File

@@ -0,0 +1,80 @@
package ch.pizzalink.android.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
/**
* Created by cimenmus on 23.10.2017.
*/
public class CountryModel {
@Expose @SerializedName("country_id") private String id;
@Expose @SerializedName("iso_code_2") private String isoCode2;
@Expose @SerializedName("iso_code_3") private String isoCode3;
@Expose @SerializedName("address_format") private String addressFormat;
@Expose @SerializedName("postcode_required") private String postcodeRequired;
private String name;
private String status;
private void checkNull(){
if(id == null)
id = "";
if(isoCode2 == null)
isoCode2 = "";
if(isoCode3 == null)
isoCode3 = "";
if(addressFormat == null)
addressFormat = "";
if(postcodeRequired == null)
postcodeRequired = "";
if(name == null)
name = "";
if(status == null)
status = "";
}
public static void checkNull(ArrayList<CountryModel> countryList){
for(CountryModel countryModel : countryList){
countryModel.checkNull();
}
}
public String getId() {
return id;
}
public String getIsoCode2() {
return isoCode2;
}
public String getIsoCode3() {
return isoCode3;
}
public String getAddressFormat() {
return addressFormat;
}
public String getPostcodeRequired() {
return postcodeRequired;
}
public String getName() {
return name;
}
public String getStatus() {
return status;
}
}

View File

@@ -0,0 +1,79 @@
package ch.pizzalink.android.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
/**
* Created by cimenmus on 23.10.2017.
*/
public class ZoneModel {
@Expose @SerializedName("shipping_point_id") private String shippingPointId;
@Expose @SerializedName("store_id") private String storeId;
@Expose @SerializedName("postcode") private String postcode;
@Expose @SerializedName("minimum_price") private String minimumPrice;
private String city;
private String canton;
private void checkNull(){
if(shippingPointId == null){
shippingPointId = "";
}
if(storeId == null){
storeId = "";
}
if(postcode == null){
postcode = "";
}
if(minimumPrice == null){
minimumPrice = "";
}
if(city == null){
city = "";
}
if(canton == null){
canton = "";
}
}
public static void checkNull(ArrayList<ZoneModel> cityList){
for (ZoneModel zoneModel : cityList){
zoneModel.checkNull();
}
}
public String getShippingPointId() {
return shippingPointId;
}
public String getStoreId() {
return storeId;
}
public String getPostcode() {
return postcode;
}
public String getMinimumPrice() {
return minimumPrice;
}
public String getCity() {
return city;
}
public String getCanton() {
return canton;
}
}

View File

@@ -0,0 +1,112 @@
package ch.pizzalink.android.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import ch.pizzalink.android.R;
import ch.pizzalink.android.activity.BaseActivity;
import ch.pizzalink.android.helper.PasswordHelper;
/**
* Created by cimenmus on 23.10.2017.
*/
public class PizzalinkDropdown extends LinearLayout implements View.OnClickListener {
private View rootView;
private TextView hintTextView;
private EditText editText;
private Typeface typeFace;
private String hint;
private OnClickListener onClickListener;
/*
public PizzalinkDropdown(LinearLayout rootView, boolean isLeftIconVisible, int leftIconId,
int editTextHintId, int inputType, boolean isPasswordIconVisible){
initViews(rootView);
setLeftIcon(isLeftIconVisible, leftIconId);
setPasswordIcon(isPasswordIconVisible);
setEditTextt(editTextHintId, inputType);
}
*/
public PizzalinkDropdown(Context context) {
super(context);
init(context);
}
public PizzalinkDropdown(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PizzalinkDropdown, 0, 0);
try {
hint = a.getString(R.styleable.PizzalinkDropdown_dropdownHint);
} finally {
a.recycle();
}
init(context);
}
private void init(Context context) {
rootView = (View) inflate(context, R.layout.layout_pizzalink_dropdown, this);
hintTextView = (TextView) rootView.findViewById(R.id.hintTextView);
editText = (EditText) rootView.findViewById(R.id.editText);
rootView.setClickable(true);
hintTextView.setText(hint);
rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(onClickListener != null){
onClickListener.onClick(rootView);
}
}
});
this.setClickable(true);
this.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(onClickListener != null){
onClickListener.onClick(rootView);
}
}
});
}
public void setOnClickListener(OnClickListener onClickListener){
this.onClickListener = onClickListener;
}
public boolean isEmpty(){
return hintTextView.getText().toString().isEmpty();
}
public String getText(){
return hintTextView.getText().toString();
}
public void setText(String text){
editText.setText(text);
}
@Override
public void onClick(View v) {
if(onClickListener != null){
onClickListener.onClick(rootView);
}
}
}

View File

@@ -89,12 +89,23 @@
app:inputType="address"
app:hint="@string/city"/>
<ch.pizzalink.android.view.PizzalinkEditText
android:id="@+id/postcodePizzalinkEditText"
<ch.pizzalink.android.view.PizzalinkDropdown
android:id="@+id/zonePizzalinkDropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:inputType="number"
app:hint="@string/postcode"/>
app:dropdownHint="@string/zone"/>
<ch.pizzalink.android.view.PizzalinkDropdown
android:id="@+id/postcodePizzalinkDrowpdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dropdownHint="@string/postcode"/>
<ch.pizzalink.android.view.PizzalinkDropdown
android:id="@+id/countryPizzalinkDropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dropdownHint="@string/country"/>
<android.support.v4.widget.Space
android:layout_width="match_parent"

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingStart="24dp"
android:paddingRight="24dp"
android:paddingEnd="24dp"
android:clickable="true">
<TextView
android:id="@+id/hintTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/venus"
android:layout_marginTop="12dp"
android:layout_marginBottom="4dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:textColorHint="@color/row_product_ingredients_background"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:layout_marginBottom="12dp"
android:clickable="false"
android:cursorVisible="false"
android:editable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/row_product_ingredients_background"
android:layout_marginTop="2dp"/>
</LinearLayout>

View File

@@ -19,4 +19,8 @@
<attr name="text" format="string" />
</declare-styleable>
<declare-styleable name="PizzalinkDropdown">
<attr name="dropdownHint" format="string" />
</declare-styleable>
</resources>

View File

@@ -56,8 +56,8 @@
<string name="addres_line_2">Adres 2</string>
<string name="city">Şehir</string>
<string name="postcode">Posta Kodu</string>
<string name="county">Ülke</string>
<string name="zone">Bölge</string>
<string name="country">Ülke</string>
<string name="alert_fill_all_fields">Lütfen istenen tüm bigileri doldurunuz.</string>
<string name="alert_invalid_email">Lütfen geçerli bir mail adresi giriniz.</string>
<string name="alert_passwords_not_matched">Şifreler uyuşmuyor..</string>
@@ -143,6 +143,8 @@
<string name="confirm_order">APPROVE</string>
<string name="done_order">DONE</string>
<string name="choose">Seçiniz</string>
<!-- OrderSummaryFragment-->
<string name="order_person_fullname">TO</string>
<string name="order_shipping_method">SHIPPING METHOD</string>