From 57c75dd216cbbd93a2123b14e4710cb9c1789d68 Mon Sep 17 00:00:00 2001 From: cimenmus Date: Thu, 12 Jul 2018 00:13:46 +0300 Subject: [PATCH] repeat order --- .idea/caches/build_file_checksums.ser | Bin 538 -> 538 bytes app/build.gradle | 4 +- app/release/output.json | 2 +- .../android/activity/MainActivity.java | 49 +++++--- .../activity/OrderHistoryDetailsActivity.java | 102 +++++++++++++--- .../recycler/OrderHistoryRecyclerAdapter.java | 9 ++ .../ch/pizzapp/android/api/ApiEndPoints.java | 1 + .../ch/pizzapp/android/api/ApiInterface.java | 4 + .../android/fragment/CartFragment.java | 5 + .../fragment/OrderHistoryFragment.java | 85 ++++++++++++- .../layout/activity_order_history_details.xml | 10 ++ app/src/main/res/layout/row_order_history.xml | 113 ++++++++++++------ app/src/main/res/values/strings.xml | 2 + 13 files changed, 315 insertions(+), 71 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 073a6256307dffa998d23ae8ca039d7e0a84bd94..053ac8dda321d716d5f169ad37d427bd236b53f3 100644 GIT binary patch delta 33 rcmV++0N($a1eyepm;{S3m>#j5Z2=MB&(1NbMLXd_-$1i|&SN5Y>ktmS delta 33 pcmbQmGK*!x43@O-A=fv~$z>EgZ&gzfQk>+#b$yoDy&LC4Dgg5g4+Q`K diff --git a/app/build.gradle b/app/build.gradle index 687196b..1f91ecd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "ch.pizzapp.capri" minSdkVersion 16 targetSdkVersion 27 - versionCode 9 // play store'daki version --> canlı : 8 dahili test: 6 - versionName "2.11" // play store'daki version : 2.1 + versionCode 10 // play store'daki version --> canlı: 8 - dahili test: 6 + versionName "2.12" // play store'daki version --> canlı: 2.1 - dahili test: 2.11 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/release/output.json b/app/release/output.json index 430a4e9..682ceae 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":8,"versionName":"2.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":9,"versionName":"2.11","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/java/ch/pizzapp/android/activity/MainActivity.java b/app/src/main/java/ch/pizzapp/android/activity/MainActivity.java index abb636f..58668f5 100644 --- a/app/src/main/java/ch/pizzapp/android/activity/MainActivity.java +++ b/app/src/main/java/ch/pizzapp/android/activity/MainActivity.java @@ -71,7 +71,7 @@ public class MainActivity extends BaseActivity { private FragmentManager fragmentManager; private String currentFragmentName = ""; private int currentCategoryId = -1; - private boolean isStartWithOrderHistory; + private boolean isStartWithOrderHistory, isStartWithCart; private ArrayList categoryList = new ArrayList<>(); private NavigationMenuRecyclerAdapter navigationMenuRecyclerAdapter; //private Badge badge; @@ -101,6 +101,7 @@ public class MainActivity extends BaseActivity { private void getDataFromIntent(){ isStartWithOrderHistory = getIntent().getBooleanExtra("isStartWithOrderHistory", false); + isStartWithCart = getIntent().getBooleanExtra("isStartWithCart", false); } private void initViews(){ @@ -161,6 +162,9 @@ public class MainActivity extends BaseActivity { if(isStartWithOrderHistory){ bottomNavigationView.setCurrentItem(1); } + else if(isStartWithCart){ + bottomNavigationView.setCurrentItem(2); + } else { openProductsScreen(categoryList.get(3)); } @@ -445,7 +449,8 @@ public class MainActivity extends BaseActivity { } public void setCartItemCount(){ - addBadgeAt(2, SharedPrefsHelper.getCartItemCount()); + updateBadge(); + updateCartTotalRelativeLayout(); } public void reopenCartFragment(){ @@ -454,23 +459,13 @@ public class MainActivity extends BaseActivity { } /* - private void addBadgeAt(int position, int number) { + private void addBadge(int position, int number) { badge.setBadgeNumber(number); badge.bindTarget(bottomNavigationView.getBottomNavigationItemView(position)); } */ - private void addBadgeAt(int position, int number) { - - badgeTextView.setText(String.valueOf(number)); - - if(number <= 0){ - badgeLayout.setVisibility(View.GONE); - } - else { - badgeLayout.setVisibility(View.VISIBLE); - } - + private void updateCartTotalRelativeLayout() { if(SharedPrefsHelper.getCartTotalPrice().equals("0") || SharedPrefsHelper.getCartTotalPrice().equals("0.0") || SharedPrefsHelper.getCartTotalPrice().equals("0.00")){ @@ -483,4 +478,30 @@ public class MainActivity extends BaseActivity { } + public void updateBadge(){ + int count = SharedPrefsHelper.getCartItemCount(); + badgeTextView.setText(String.valueOf(count)); + + if(count <= 0){ + badgeLayout.setVisibility(View.GONE); + } + else { + badgeLayout.setVisibility(View.VISIBLE); + } + } + + public void openFragmentAt(int position){ + currentFragmentName = ""; + bottomNavigationView.setCurrentItem(position); + } + + public void setCartTotalLayoutVisibility(boolean isVisible){ + if(isVisible){ + cartTotalRelativeLayout.setVisibility(View.VISIBLE); + } + else { + cartTotalRelativeLayout.setVisibility(View.GONE); + } + } + } diff --git a/app/src/main/java/ch/pizzapp/android/activity/OrderHistoryDetailsActivity.java b/app/src/main/java/ch/pizzapp/android/activity/OrderHistoryDetailsActivity.java index 8ff36bd..136ba34 100644 --- a/app/src/main/java/ch/pizzapp/android/activity/OrderHistoryDetailsActivity.java +++ b/app/src/main/java/ch/pizzapp/android/activity/OrderHistoryDetailsActivity.java @@ -1,18 +1,22 @@ package ch.pizzapp.android.activity; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TextView; import java.util.ArrayList; +import java.util.HashMap; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; import ch.pizzapp.android.R; import ch.pizzapp.android.api.ApiEndPoints; import ch.pizzapp.android.api.ApiErrorUtils; import ch.pizzapp.android.api.ApiService; import ch.pizzapp.android.api.ResponseArray; +import ch.pizzapp.android.api.ResponseObject; import ch.pizzapp.android.helper.DialogHelper; import ch.pizzapp.android.helper.PriceHelper; import ch.pizzapp.android.helper.SessionHelper; @@ -27,24 +31,16 @@ import retrofit2.Response; public class OrderHistoryDetailsActivity extends BaseActivity { - @BindView(R.id.orderDatePizzalinkInfoLayout) - AppInfoView orderDatePizzalinkInfoLayout; + @BindView(R.id.orderDatePizzalinkInfoLayout) AppInfoView orderDatePizzalinkInfoLayout; //@BindView(R.id.orderStatusPizzalinkInfoLayout) PizzalinkInfoView orderStatusPizzalinkInfoLayout; - @BindView(R.id.orderShippingTimePizzalinkInfoLayout) - AppInfoView orderShippingTimePizzalinkInfoLayout; - @BindView(R.id.orderTotalPizzalinkInfoLayout) - AppInfoView orderTotalPizzalinkInfoLayout; - @BindView(R.id.orderPaymentMethodPizzalinkInfoLayout) - AppInfoView orderPaymentMethodPizzalinkInfoLayout; + @BindView(R.id.orderShippingTimePizzalinkInfoLayout) AppInfoView orderShippingTimePizzalinkInfoLayout; + @BindView(R.id.orderTotalPizzalinkInfoLayout) AppInfoView orderTotalPizzalinkInfoLayout; + @BindView(R.id.orderPaymentMethodPizzalinkInfoLayout) AppInfoView orderPaymentMethodPizzalinkInfoLayout; @BindView(R.id.orderProductsTextView) TextView orderProductsTextView; - @BindView(R.id.orderFullnamePizzalinkInfoLayout) - AppInfoView orderFullnamePizzalinkInfoLayout; - @BindView(R.id.orderShippingMethodPizzalinkInfoLayout) - AppInfoView orderShippingMethodPizzalinkInfoLayout; - @BindView(R.id.orderShippingAddressPizzalinkInfoLayout) - AppInfoView orderShippingAddressPizzalinkInfoLayout; - @BindView(R.id.orderNotePizzalinkInfoLayout) - AppInfoView orderNotePizzalinkInfoLayout; + @BindView(R.id.orderFullnamePizzalinkInfoLayout) AppInfoView orderFullnamePizzalinkInfoLayout; + @BindView(R.id.orderShippingMethodPizzalinkInfoLayout) AppInfoView orderShippingMethodPizzalinkInfoLayout; + @BindView(R.id.orderShippingAddressPizzalinkInfoLayout) AppInfoView orderShippingAddressPizzalinkInfoLayout; + @BindView(R.id.orderNotePizzalinkInfoLayout) AppInfoView orderNotePizzalinkInfoLayout; private OrderHistoryModel orderHistoryModel; private ArrayList productList = new ArrayList<>(); @@ -59,6 +55,11 @@ public class OrderHistoryDetailsActivity extends BaseActivity { initViews(); } + @OnClick(R.id.repeatOrderButton) + public void onClick(){ + clearCart(); + } + private void getDataFromIntent(){ orderHistoryModel = (OrderHistoryModel) getIntent().getSerializableExtra("orderHistoryModel"); } @@ -192,6 +193,75 @@ public class OrderHistoryDetailsActivity extends BaseActivity { return stringBuilder.toString().trim(); } + private void clearCart(){ + DialogHelper.showLoadingDialog(); + Call call = ApiService.apiInterface.clearCart( + SessionHelper.getCustomerToken().getToken()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if(response.isSuccessful() && response.body().isSuccess()){ + /* + cartProductList.clear(); + cartRecyclerAdapter.notifyDataSetChanged(); + setCartLayoutsVisibility(); + SharedPrefsHelper.setCartItemCount(0); + SharedPrefsHelper.setCartTotalPrice("0"); + SharedPrefsHelper.setUserUsedPizzapassCampaign(false); + SharedPrefsHelper.setUserUsedChampagneCampaign(false); + MainActivity mainActivity = (MainActivity) getActivity(); + mainActivity.setCartItemCount(); + */ + repeatOrder(); + } + + else { + DialogHelper.hideLoadingDialog(); + ApiErrorUtils.parseError(response); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + DialogHelper.hideLoadingDialog(); + DialogHelper.showFailedDialog(); + } + }); + } + + private void repeatOrder(){ + + HashMap params = new HashMap<>(); + params.put("order_id", orderHistoryModel.getId()); + + Call call = ApiService.apiInterface.repeatOrder( + ApiEndPoints.API_REPEAT_ORDER + SessionHelper.getCustomerToken().getToken(), + params); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, final Response response) { + DialogHelper.hideLoadingDialog(); + if(response.isSuccessful() && + response.body().getData() != null && + response.body().isSuccess()){ + Intent basketIntent = new Intent(OrderHistoryDetailsActivity.this, MainActivity.class); + basketIntent.putExtra("isStartWithCart", true); + startActivity(basketIntent); + finishAffinity(); + } + else { + ApiErrorUtils.parseError(response); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + DialogHelper.hideLoadingDialog(); + DialogHelper.showFailedDialog(); + } + }); + } + /* private String getCartInfoText(CartProductModel cartProductModel){ diff --git a/app/src/main/java/ch/pizzapp/android/adapter/recycler/OrderHistoryRecyclerAdapter.java b/app/src/main/java/ch/pizzapp/android/adapter/recycler/OrderHistoryRecyclerAdapter.java index f8227ac..c8aa9a0 100644 --- a/app/src/main/java/ch/pizzapp/android/adapter/recycler/OrderHistoryRecyclerAdapter.java +++ b/app/src/main/java/ch/pizzapp/android/adapter/recycler/OrderHistoryRecyclerAdapter.java @@ -31,6 +31,7 @@ public class OrderHistoryRecyclerAdapter extends RecyclerView.Adapter call = ApiService.apiInterface.clearCart( + SessionHelper.getCustomerToken().getToken()); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if(response.isSuccessful() && response.body().isSuccess()){ + /* + cartProductList.clear(); + cartRecyclerAdapter.notifyDataSetChanged(); + setCartLayoutsVisibility(); + SharedPrefsHelper.setCartItemCount(0); + SharedPrefsHelper.setCartTotalPrice("0"); + SharedPrefsHelper.setUserUsedPizzapassCampaign(false); + SharedPrefsHelper.setUserUsedChampagneCampaign(false); + MainActivity mainActivity = (MainActivity) getActivity(); + mainActivity.setCartItemCount(); + */ + repeatOrder(orderId); + } + + else { + DialogHelper.hideLoadingDialog(); + ApiErrorUtils.parseError(response); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + DialogHelper.hideLoadingDialog(); + DialogHelper.showFailedDialog(); + } + }); + } + + private void repeatOrder(String orderId){ + + HashMap params = new HashMap<>(); + params.put("order_id", orderId); + + Call call = ApiService.apiInterface.repeatOrder( + ApiEndPoints.API_REPEAT_ORDER + SessionHelper.getCustomerToken().getToken(), + params); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, final Response response) { + DialogHelper.hideLoadingDialog(); + if(response.isSuccessful() && + response.body().getData() != null && + response.body().isSuccess()){ + MainActivity mainActivity = (MainActivity) getActivity(); + mainActivity.openFragmentAt(2); + } + else { + ApiErrorUtils.parseError(response); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + DialogHelper.hideLoadingDialog(); + DialogHelper.showFailedDialog(); + } + }); + } + } diff --git a/app/src/main/res/layout/activity_order_history_details.xml b/app/src/main/res/layout/activity_order_history_details.xml index 6a4b7bd..3c27350 100644 --- a/app/src/main/res/layout/activity_order_history_details.xml +++ b/app/src/main/res/layout/activity_order_history_details.xml @@ -130,6 +130,16 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:description="@string/order_history_order_note" /> + +