campaign banners on splash
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
@@ -5,6 +5,8 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -22,6 +24,7 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import ch.pizzaleu.android.R;
|
import ch.pizzaleu.android.R;
|
||||||
|
import ch.pizzaleu.android.adapter.recycler.CampaignBannerRecyclerAdapter;
|
||||||
import ch.pizzaleu.android.api.ApiConstants;
|
import ch.pizzaleu.android.api.ApiConstants;
|
||||||
import ch.pizzaleu.android.api.ApiEndPoints;
|
import ch.pizzaleu.android.api.ApiEndPoints;
|
||||||
import ch.pizzaleu.android.api.ApiErrorUtils;
|
import ch.pizzaleu.android.api.ApiErrorUtils;
|
||||||
@@ -34,6 +37,7 @@ import ch.pizzaleu.android.helper.PriceHelper;
|
|||||||
import ch.pizzaleu.android.helper.SessionHelper;
|
import ch.pizzaleu.android.helper.SessionHelper;
|
||||||
import ch.pizzaleu.android.helper.SharedPrefsHelper;
|
import ch.pizzaleu.android.helper.SharedPrefsHelper;
|
||||||
import ch.pizzaleu.android.model.AppVersionModel;
|
import ch.pizzaleu.android.model.AppVersionModel;
|
||||||
|
import ch.pizzaleu.android.model.CampaignBannerModel;
|
||||||
import ch.pizzaleu.android.model.CategoryModel;
|
import ch.pizzaleu.android.model.CategoryModel;
|
||||||
import ch.pizzaleu.android.model.StoreModel;
|
import ch.pizzaleu.android.model.StoreModel;
|
||||||
import ch.pizzaleu.android.model.cart.CartInfoModel;
|
import ch.pizzaleu.android.model.cart.CartInfoModel;
|
||||||
@@ -44,12 +48,15 @@ import retrofit2.Response;
|
|||||||
public class SplashActivity extends BaseActivity {
|
public class SplashActivity extends BaseActivity {
|
||||||
|
|
||||||
@BindView(R.id.pizzappSplashLogoImageView) ImageView pizzappSplashLogoImageView;
|
@BindView(R.id.pizzappSplashLogoImageView) ImageView pizzappSplashLogoImageView;
|
||||||
|
@BindView(R.id.campaignBannerRecyclerView) RecyclerView campaignBannerRecyclerView;
|
||||||
@BindView(R.id.postCodeTextView) TextView postCodeTextView;
|
@BindView(R.id.postCodeTextView) TextView postCodeTextView;
|
||||||
|
|
||||||
@BindString(R.string.alert_invalid_post_code) String choosePostCodeAlert;
|
@BindString(R.string.alert_invalid_post_code) String choosePostCodeAlert;
|
||||||
|
|
||||||
private ArrayList<StoreModel> storeList = new ArrayList<>();
|
private ArrayList<StoreModel> storeList = new ArrayList<>();
|
||||||
|
private ArrayList<CampaignBannerModel> campaignBannerList = new ArrayList<>();
|
||||||
private StoreModel selectedStoreModel;
|
private StoreModel selectedStoreModel;
|
||||||
|
private CampaignBannerRecyclerAdapter campaignBannerRecyclerAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -57,6 +64,7 @@ public class SplashActivity extends BaseActivity {
|
|||||||
setContentView(R.layout.activity_splash);
|
setContentView(R.layout.activity_splash);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
//DisplayHelper.changeStatusColor();
|
//DisplayHelper.changeStatusColor();
|
||||||
|
initCampaignBannerRecyclerView();
|
||||||
if(NetworkHelper.isNetworkAvailable()){
|
if(NetworkHelper.isNetworkAvailable()){
|
||||||
registerNotificationTag();
|
registerNotificationTag();
|
||||||
getStoreList();
|
getStoreList();
|
||||||
@@ -66,6 +74,13 @@ public class SplashActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initCampaignBannerRecyclerView(){
|
||||||
|
campaignBannerRecyclerAdapter = new CampaignBannerRecyclerAdapter(campaignBannerList);
|
||||||
|
campaignBannerRecyclerView.setAdapter(campaignBannerRecyclerAdapter);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(BaseActivity.currentActivity);
|
||||||
|
campaignBannerRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick({R.id.choosePostCodeLayout, R.id.choosePostCodeButton})
|
@OnClick({R.id.choosePostCodeLayout, R.id.choosePostCodeButton})
|
||||||
protected void onClick(View view){
|
protected void onClick(View view){
|
||||||
switch (view.getId()){
|
switch (view.getId()){
|
||||||
@@ -98,11 +113,47 @@ public class SplashActivity extends BaseActivity {
|
|||||||
call.enqueue(new Callback<ResponseArray<StoreModel>>() {
|
call.enqueue(new Callback<ResponseArray<StoreModel>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<ResponseArray<StoreModel>> call, Response<ResponseArray<StoreModel>> response) {
|
public void onResponse(Call<ResponseArray<StoreModel>> call, Response<ResponseArray<StoreModel>> response) {
|
||||||
DialogHelper.hideLoadingDialog();
|
|
||||||
if(response.isSuccessful() &&
|
if(response.isSuccessful() &&
|
||||||
response.body().getData() != null &&
|
response.body().getData() != null &&
|
||||||
response.body().isSuccess() && !response.body().getData().isEmpty()){
|
response.body().isSuccess() && !response.body().getData().isEmpty()){
|
||||||
storeList.addAll(response.body().getData());
|
storeList.addAll(response.body().getData());
|
||||||
|
getCampaignBanners();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DialogHelper.hideLoadingDialog();
|
||||||
|
ApiErrorUtils.parseError(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<ResponseArray<StoreModel>> call, Throwable t) {
|
||||||
|
DialogHelper.hideLoadingDialog();
|
||||||
|
DialogHelper.showFailedDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCampaignBanners(){
|
||||||
|
Call<ResponseArray<CampaignBannerModel>> call = ApiService.apiInterface.getCampaignBanners();
|
||||||
|
call.enqueue(new Callback<ResponseArray<CampaignBannerModel>>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<ResponseArray<CampaignBannerModel>> call, Response<ResponseArray<CampaignBannerModel>> response) {
|
||||||
|
DialogHelper.hideLoadingDialog();
|
||||||
|
if(response.isSuccessful() &&
|
||||||
|
response.body().getData() != null &&
|
||||||
|
response.body().isSuccess() && !response.body().getData().isEmpty()){
|
||||||
|
campaignBannerList.clear();
|
||||||
|
campaignBannerList.addAll(response.body().getData());
|
||||||
|
sortCampaignBannerList();
|
||||||
|
campaignBannerRecyclerAdapter.notifyDataSetChanged();
|
||||||
|
if(campaignBannerList.isEmpty()){
|
||||||
|
pizzappSplashLogoImageView.setVisibility(View.VISIBLE);
|
||||||
|
campaignBannerRecyclerView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pizzappSplashLogoImageView.setVisibility(View.GONE);
|
||||||
|
campaignBannerRecyclerView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ApiErrorUtils.parseError(response);
|
ApiErrorUtils.parseError(response);
|
||||||
@@ -110,7 +161,7 @@ public class SplashActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<ResponseArray<StoreModel>> call, Throwable t) {
|
public void onFailure(Call<ResponseArray<CampaignBannerModel>> call, Throwable t) {
|
||||||
DialogHelper.hideLoadingDialog();
|
DialogHelper.hideLoadingDialog();
|
||||||
DialogHelper.showFailedDialog();
|
DialogHelper.showFailedDialog();
|
||||||
}
|
}
|
||||||
@@ -376,6 +427,23 @@ public class SplashActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void sortCampaignBannerList(){
|
||||||
|
ArrayList<CampaignBannerModel> tempList = new ArrayList<>();
|
||||||
|
for(CampaignBannerModel campaignBannerModel : campaignBannerList){
|
||||||
|
if(campaignBannerModel.isActive()){
|
||||||
|
tempList.add(campaignBannerModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
campaignBannerList.clear();
|
||||||
|
campaignBannerList.addAll(tempList);
|
||||||
|
tempList.clear();
|
||||||
|
Collections.sort(campaignBannerList, new Comparator<CampaignBannerModel>() {
|
||||||
|
@Override
|
||||||
|
public int compare(CampaignBannerModel b1, CampaignBannerModel b2) {
|
||||||
|
return b1.getOrder().compareTo(b2.getOrder());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package ch.pizzaleu.android.adapter.recycler;
|
||||||
|
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import ch.pizzaleu.android.R;
|
||||||
|
import ch.pizzaleu.android.helper.ImageLoadHelper;
|
||||||
|
import ch.pizzaleu.android.model.CampaignBannerModel;
|
||||||
|
|
||||||
|
public class CampaignBannerRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
|
||||||
|
|
||||||
|
private final int HOLDER_CAMPAIGN_BANNER = 0;
|
||||||
|
private final int HOLDER_SPACE = 1;
|
||||||
|
|
||||||
|
private ArrayList<CampaignBannerModel> bannerList = new ArrayList<>();
|
||||||
|
|
||||||
|
public static class CampaignBannerHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
@BindView(R.id.campaignBannerImageView)
|
||||||
|
ImageView campaignBannerImageView;
|
||||||
|
|
||||||
|
public CampaignBannerHolder(final View view) {
|
||||||
|
super(view);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SpaceViewHolder extends RecyclerView.ViewHolder{
|
||||||
|
public SpaceViewHolder(final View view) {
|
||||||
|
super(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
|
||||||
|
if(position == bannerList.size())
|
||||||
|
return HOLDER_SPACE;
|
||||||
|
|
||||||
|
return HOLDER_CAMPAIGN_BANNER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CampaignBannerRecyclerAdapter(ArrayList<CampaignBannerModel> bannerList){
|
||||||
|
this.bannerList = bannerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
|
||||||
|
RecyclerView.ViewHolder viewHolder;
|
||||||
|
View view;
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
|
||||||
|
|
||||||
|
switch (viewType){
|
||||||
|
|
||||||
|
case HOLDER_SPACE:
|
||||||
|
view = inflater.inflate(R.layout.row_space, viewGroup, false);
|
||||||
|
viewHolder = new SpaceViewHolder(view);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// HOLDER_CAMPAIGN_BANNER
|
||||||
|
default:
|
||||||
|
view = inflater.inflate(R.layout.row_campaign_banner, viewGroup, false);
|
||||||
|
viewHolder = new CampaignBannerHolder(view);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return viewHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||||
|
switch (holder.getItemViewType()){
|
||||||
|
case HOLDER_CAMPAIGN_BANNER :
|
||||||
|
CampaignBannerHolder campaignBannerHolder = (CampaignBannerHolder) holder;
|
||||||
|
ImageLoadHelper.loadImage(campaignBannerHolder.campaignBannerImageView, bannerList.get(position).getImageUrl());
|
||||||
|
//ImageLoadHelper.loadImage(campaignBannerHolder.campaignBannerImageView, getSampleImageUrl(position));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HOLDER_SPACE :
|
||||||
|
SpaceViewHolder spaceViewHolder = (SpaceViewHolder) holder;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return bannerList.size() + 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSampleImageUrl(int position){
|
||||||
|
if(position % 2 == 0){
|
||||||
|
return "http://pizzaleu.ddns.net/pizza/images/angebot3.png";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "http://pizzaleu.ddns.net/pizza/images/Pizza_Leu-Pizzapass.png";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ public class ApiEndPoints {
|
|||||||
private static final String SUFFIX = "&is_mobile=1";
|
private static final String SUFFIX = "&is_mobile=1";
|
||||||
|
|
||||||
public static final String API_GET_STORE_LIST = "pizza/servicemagazabelirle.php";
|
public static final String API_GET_STORE_LIST = "pizza/servicemagazabelirle.php";
|
||||||
|
public static final String API_GET_CAMPAIGN_BANNERS = "pizzaleu/" + PREFIX + "getCampaignBanners" + SUFFIX;
|
||||||
|
|
||||||
public static final String API_GET_ALL_CATEGORIES = PREFIX + "getAllCategories" + SUFFIX;
|
public static final String API_GET_ALL_CATEGORIES = PREFIX + "getAllCategories" + SUFFIX;
|
||||||
public static final String API_GET_IGNORED_CATEGORY_IDS= PREFIX + "getIgnoredCategory" + SUFFIX;
|
public static final String API_GET_IGNORED_CATEGORY_IDS= PREFIX + "getIgnoredCategory" + SUFFIX;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import ch.pizzaleu.android.model.AddNewAddressResponseModel;
|
|||||||
import ch.pizzaleu.android.model.AddProductToBasketResponseModel;
|
import ch.pizzaleu.android.model.AddProductToBasketResponseModel;
|
||||||
import ch.pizzaleu.android.model.AddressModel;
|
import ch.pizzaleu.android.model.AddressModel;
|
||||||
import ch.pizzaleu.android.model.AppVersionModel;
|
import ch.pizzaleu.android.model.AppVersionModel;
|
||||||
|
import ch.pizzaleu.android.model.CampaignBannerModel;
|
||||||
import ch.pizzaleu.android.model.CampaignModel;
|
import ch.pizzaleu.android.model.CampaignModel;
|
||||||
import ch.pizzaleu.android.model.CheckCouponModel;
|
import ch.pizzaleu.android.model.CheckCouponModel;
|
||||||
import ch.pizzaleu.android.model.CountryModel;
|
import ch.pizzaleu.android.model.CountryModel;
|
||||||
@@ -233,6 +234,9 @@ public interface ApiInterface {
|
|||||||
@GET
|
@GET
|
||||||
Call<ResponseObject<PaymentTokenModel>> createPaymentToken(@Url String url);
|
Call<ResponseObject<PaymentTokenModel>> createPaymentToken(@Url String url);
|
||||||
|
|
||||||
|
@GET(ApiEndPoints.API_GET_CAMPAIGN_BANNERS)
|
||||||
|
Call<ResponseArray<CampaignBannerModel>> getCampaignBanners();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package ch.pizzaleu.android.model;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class CampaignBannerModel {
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
@SerializedName("title")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
@SerializedName("image")
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
@SerializedName("order")
|
||||||
|
private String order;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
@SerializedName("status")
|
||||||
|
private boolean active;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
if(imageUrl == null){
|
||||||
|
imageUrl = "";
|
||||||
|
}
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrder() {
|
||||||
|
if(order == null){
|
||||||
|
order = "0";
|
||||||
|
}
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,14 +23,23 @@
|
|||||||
android:src="@drawable/pizzaleu_splash_logo"
|
android:src="@drawable/pizzaleu_splash_logo"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
android:scaleType="fitXY" />
|
android:scaleType="fitXY"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/campaignBannerRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_above="@+id/splashButtonsLayout"
|
||||||
|
tools:listitem="@layout/row_campaign_banner"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/splashButtonsLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_margin="8dp"
|
android:layout_margin="8dp"
|
||||||
android:layout_centerInParent="true">
|
android:layout_alignParentBottom="true">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/choosePostCodeLayout"
|
android:id="@+id/choosePostCodeLayout"
|
||||||
|
|||||||
13
app/src/main/res/layout/row_campaign_banner.xml
Normal file
13
app/src/main/res/layout/row_campaign_banner.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ImageView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/campaignBannerImageView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
tools:src="@drawable/pizzaleu_splash_logo"/>
|
||||||
Reference in New Issue
Block a user