Untitled
raw download clone
TEXT
views 40
,
size 54170 b
package com.mixxi.appcea.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.andremion.counterfab.CounterFab;
import com.crashlytics.android.Crashlytics;
import com.google.android.material.appbar.AppBarLayout;
import com.mixxi.appcea.R;
import com.mixxi.appcea.domian.controller.MenuController;
import com.mixxi.appcea.domian.controller.OrderController;
import com.mixxi.appcea.domian.controller.WishlistController;
import com.mixxi.appcea.domian.model.CategoryViewModel;
import com.mixxi.appcea.domian.model.DepartmentViewModel;
import com.mixxi.appcea.domian.model.HomeBanner;
import com.mixxi.appcea.domian.model.OrderGroupViewModel;
import com.mixxi.appcea.domian.model.ProductsViewModel;
import com.mixxi.appcea.domian.model.home.Bubble;
import com.mixxi.appcea.domian.model.home.BubbleResult;
import com.mixxi.appcea.domian.model.wishlist.Wishlist;
import com.mixxi.appcea.restruct.ui.qrcode.steps.map.mapActivity.QrMapBaseActivity;
import com.mixxi.appcea.ui.activity.BarcodeScannerActivity;
import com.mixxi.appcea.ui.activity.CAActivity;
import com.mixxi.appcea.ui.activity.CAActivityKt;
import com.mixxi.appcea.ui.activity.Orders.MyOrders;
import com.mixxi.appcea.ui.activity.Orders.OrderDetail;
import com.mixxi.appcea.ui.activity.account.Login;
import com.mixxi.appcea.ui.activity.detailProduct.detail.DetailProductActivity;
import com.mixxi.appcea.ui.activity.showcase.ShowcaseActivity;
import com.mixxi.appcea.ui.activity.showcase.ShowcaseNeemuActivity;
import com.mixxi.appcea.ui.activity.wishlist.WishlistActivity;
import com.mixxi.appcea.ui.adapter.MyOrderSimpleAdapter;
import com.mixxi.appcea.ui.adapter.home.BubbleAdapter;
import com.mixxi.appcea.ui.adapter.showcase.ProductSimpleListAdapter;
import com.mixxi.appcea.ui.view.BannerLinearLayout;
import com.mixxi.appcea.util.GeneralUtils;
import com.mixxi.appcea.util.IntentUtils;
import com.mixxi.appcea.util.ServerCallback;
import com.mixxi.appcea.util.SessionFirebaseManager;
import com.mixxi.appcea.util.SessionManager;
import com.mixxi.appcea.util.tracking.TrackingUtils;

import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by tainaraspecht on 7/24/17.
 */
public class HomeFragment extends CAFragment implements BannerLinearLayout.BannerViewListener {
    @BindView(R.id.banner_layout_top) LinearLayout bannerLayoutTop;
    @BindView(R.id.banner_layout) LinearLayout bannerLayout;
    @BindView(R.id.temp_progress_bar) ProgressBar tempProgressBar;

    @BindView(R.id.v_homeBubbles) View v_homeBubbles;
    @BindView(R.id.tv_homeBubblesTitle) TextView tv_homeBubbles;
    @BindView(R.id.rv_homeBubbles) RecyclerView rv_homeBubbles;
    @BindView(R.id.v_homeOrders) View v_homeOrders;
    @BindView(R.id.rv_homeOrders) RecyclerView rv_homeOrders;
    @BindView(R.id.hsv_homeWishlist) HorizontalScrollView hsv_homeWishlist;
    @BindView(R.id.v_homeWishlist) View v_homeWishlist;
    @BindView(R.id.rv_homeWishlist) RecyclerView rv_homeWishlist;
    @BindView(R.id.tv_homeWishlistTitle) TextView tv_homeWishlistTitle;
    @BindView(R.id.v_homeWishlistSeeMore) View v_homeWishlistSeeMore;
    @BindView(R.id.v_homeWishlistLogin) View v_homeWishlistLogin;
    @BindView(R.id.tv_homeWishlistLogin) TextView tv_homeWishlistLogin;
    @BindView(R.id.iv_homeWishlistIcon) ImageView iv_homeWishlistIcon;
    @BindView(R.id.iv_homeWishlistArrow) ImageView iv_homeWishlistArrow;

    private View bannerEVC;
    private Toolbar toolbar;
    private AppBarLayout appBarLayout;
    private RelativeLayout relativeLayout;
    private ImageView CALogo;
    private Window window;
    private CounterFab btnOpenCart;
    private SearchView searchView;
    private MenuController menuController;
    private ImageView ivBlock;
    private NestedScrollView scrollView_home;
    public List<HomeBanner> banners;
    private List<BannerLinearLayout> bannerViews;
    private boolean bannerLoaded;

    private ProductSimpleListAdapter wishlistAdapter;

    public HomeFragment() {
        menuController = new MenuController();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        setHasOptionsMenu(true);
        findViews(view);
        ButterKnife.bind(this, view);
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics metrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metrics);
        ViewGroup.LayoutParams layoutParams = bannerLayout.getLayoutParams();
        layoutParams.height = metrics.heightPixels;
        ivBlock = view.findViewById(R.id.ivBlock);
        ivBlock.setOnClickListener(v -> {
            searchView.onActionViewCollapsed();
            searchView.setIconified(true);
        });
        tempProgressBar.getIndeterminateDrawable()
                .setColorFilter(ContextCompat.getColor(getContext(), R.color.white), PorterDuff.Mode.SRC_IN);
        bannerViews = new ArrayList<>();

        return view;
    }

    @Override
    public void onActivityCreated(@androidx.annotation.Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if(getActivity() instanceof CAActivityKt) {
            ((CAActivityKt)getActivity()).showLoading(true);
        }
        menuController.getHomeBanners(getContext(), new ServerCallback.BackHomeBanner() {
            @Override
            public void onSuccess(List<HomeBanner> homeBanners) {
                loadLinearBanners(homeBanners);
                if(getActivity() instanceof CAActivityKt) {
                    ((CAActivityKt)getActivity()).hideLoading(true);
                }
            }

            @Override
            public void onFailure(String message) {
                List<HomeBanner> bannersList = new ArrayList<>();
                HomeBanner topBanner = new HomeBanner();
                topBanner.setType(HomeBanner.TYPE_TOP);
                bannersList.add(topBanner);
                HomeBanner pairBanner1 = new HomeBanner();
                pairBanner1.setType(HomeBanner.TYPE_PAIR);
                bannersList.add(pairBanner1);
                HomeBanner pairBanner2 = new HomeBanner();
                pairBanner2.setType(HomeBanner.TYPE_PAIR);
                bannersList.add(pairBanner2);
                HomeBanner bottomBanner = new HomeBanner();
                bottomBanner.setType(HomeBanner.TYPE_WIDE);
                bannersList.add(bottomBanner);
                loadLinearBanners(bannersList);
                if(getActivity() instanceof CAActivityKt) {
                    ((CAActivityKt)getActivity()).hideLoading(true);
                }
            }
        });

        SessionFirebaseManager firebaseManager = SessionFirebaseManager.getInstance(getContext());
        if(firebaseManager.isFeatureHomeBubbleEnabled())
            loadBubbles();
        if(firebaseManager.isFeatureHomeOrderEnabled())
            loadOrders();
        if(firebaseManager.isFeatureHomeWishlistEnabled())
            loadWishlist();
    }

    private void findViews(View view) {
        if (getActivity() != null) {
            toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
            appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.app_bar_layout);
            relativeLayout = (RelativeLayout) getActivity().findViewById(R.id.rl_content_main);
            CALogo = (ImageView) getActivity().findViewById(R.id.c_a_logo);
            window = getActivity().getWindow();
            scrollView_home = view.findViewById(R.id.scrollview_home);
            bannerEVC = view.findViewById(R.id.banner_evc);
            btnOpenCart = (CounterFab) view.findViewById(R.id.btnOpenCart);
            btnOpenCart.setOnClickListener(v -> IntentUtils.openCart(getContext()));
            window = Objects.requireNonNull(getActivity()).getWindow();
            TextView tv_footer = view.findViewById(R.id.home_text_footer);
            tv_footer.setText(Html.fromHtml(getString(R.string.home_footer)));
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == BarcodeScannerActivity.REQUEST_CODE) {
            if (resultCode == BarcodeScannerActivity.RESULT_PERMISSION_DENIED) {
                ((CAActivity) Objects.requireNonNull(getActivity()))
                        .showErrorMessage(searchView, R.string.barcode_camera_permission_error);
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            appBarLayout.setElevation(0);
            window.setStatusBarColor(ContextCompat.getColor(getContext(), R.color.black));
        }
        getActivity().setTitle("");
        CALogo.setVisibility(View.VISIBLE);
        //set it to transparent
        toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));
        //set app bar scrolling behavior to false
        CoordinatorLayout.LayoutParams params =
                (CoordinatorLayout.LayoutParams) relativeLayout.getLayoutParams();
        params.setBehavior(null);
        relativeLayout.requestLayout();
        if (searchView != null) {
            searchView.setQuery("", false);
            searchView.setIconified(true);
            searchView.requestFocusFromTouch();
        }
        for (BannerLinearLayout banner : bannerViews) {
            if (banner.fetch()) {
                banner.setBanners(banner.getBanners());
            }
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        for (BannerLinearLayout bannerLL : bannerViews) {
            bannerLL.setTracked(false);
        }
    }

    private void loadLinearBanners(List<HomeBanner> homeBanners) {
        bannerLayoutTop.removeAllViews();
        bannerLayout.removeAllViews();
        banners = homeBanners;
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics metrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metrics);
        Iterator<HomeBanner> iterator = banners.iterator();
        int bannerIndex = 0;
        while (iterator.hasNext()) {
            HomeBanner homeBanner = iterator.next();
            BannerLinearLayout linearBanner = new BannerLinearLayout(getContext());
            linearBanner.setLayoutParams(new LinearLayout.LayoutParams(metrics.widthPixels, (int) (metrics.widthPixels * homeBanner.getRatio())));
            linearBanner.setListener(HomeFragment.this);
            List<HomeBanner> list = new ArrayList<>();
            bannersContainsCeAeVC(homeBanner);
            list.add(homeBanner);
            if (homeBanner.getType().equalsIgnoreCase(HomeBanner.TYPE_PAIR)) {
                list.add(iterator.next());
            }
            linearBanner.setBanners(list);
            if(bannerIndex == 0)
                bannerLayoutTop.addView(linearBanner);
            else
                bannerLayout.addView(linearBanner);
            bannerViews.add(linearBanner);
            bannerIndex++;
        }
        ViewGroup.LayoutParams layoutParams = bannerLayoutTop.getLayoutParams();
        layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
        ViewGroup.LayoutParams lp = bannerLayout.getLayoutParams();
        lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;

        bannerLoaded = true;
        scrollView_home.postDelayed(this::trackBanners, 1000);
        scrollView_home.getViewTreeObserver().addOnScrollChangedListener(this::trackBanners);
    }

    private void bannersContainsCeAeVC(HomeBanner homeBanner) {
        if (homeBanner != null
                && homeBanner.getBannerName() != null
                && HomeBanner.BANNER_EVC.equals(homeBanner.getBannerName().toLowerCase())) {
            bannerEVC.setVisibility(View.GONE);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (SessionManager.getInstance(getContext()).isBagVisible()) {
            btnOpenCart.show();
            btnOpenCart.setCount(SessionManager.getInstance(getContext()).getBagProducts());
        } else {
            btnOpenCart.hide();
        }
    }

    @Override
    public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) {
        // Inflate the menu; this adds items to the action bar if it is present.
        inflater.inflate(R.menu.main, menu);
        searchView =
                (SearchView) menu.findItem(R.id.action_search).getActionView();
//        searchView.setSearchableInfo(
//                searchManager.getSearchableInfo(getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                TrackingUtils.Companion.newInstance(getActivity(), mFirebaseAnalytics).search(query);
                DepartmentViewModel departmentViewModel = new DepartmentViewModel();
                departmentViewModel.setName(query);
                departmentViewModel.setDepartmentName(query);
                departmentViewModel.setQuerySearchItem(query);
                departmentViewModel.setColorStart("#0097b8");
                departmentViewModel.setColorEnd("#00748d");
                departmentViewModel.setQuerySearchItem("");

                Intent i;
                if (SessionFirebaseManager.getInstance(getContext()).isSearchNeemuEnabled()) {
                    i = ShowcaseNeemuActivity.Companion.createIntent(getContext(), query, departmentViewModel);
                } else
                    i = ShowcaseActivity.Companion.createIntent(getContext(), query, departmentViewModel);

                startActivity(i);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
        searchView.setOnSearchClickListener(v -> {
            menu.findItem(R.id.action_heart).setVisible(false);
            CALogo.setVisibility(View.GONE);
            searchView.requestFocusFromTouch();
            ivBlock.setVisibility(View.VISIBLE);
        });
        searchView.setOnCloseListener(() -> {
            menu.findItem(R.id.action_heart).setVisible(true);
            CALogo.setVisibility(View.VISIBLE);
            ivBlock.setVisibility(View.GONE);
            return false;
        });
    }

    @Override
    public void onDetach() {
        super.onDetach();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            appBarLayout.setElevation(15);
            window.setStatusBarColor(ContextCompat.getColor(Objects.requireNonNull(getContext()), R.color.colorPrimaryDark));
        }
        CALogo.setVisibility(View.GONE);
        toolbar.setBackgroundColor(ContextCompat.getColor(Objects.requireNonNull(getContext()), R.color.colorPrimary));
        //set app bar scrolling behavior to true
        CoordinatorLayout.LayoutParams params =
                (CoordinatorLayout.LayoutParams) relativeLayout.getLayoutParams();
        params.setBehavior(new AppBarLayout.ScrollingViewBehavior());
        relativeLayout.requestLayout();
        appBarLayout.setExpanded(true, true);
        menuController.cancelAllRequests();
    }

    private void trackBanners() {
        try {
            if (bannerLoaded) {
                for (BannerLinearLayout bannerLL : bannerViews) {
                    if (!bannerLL.isTracked() && GeneralUtils.isViewVisible(scrollView_home, bannerLL)) {
                        TrackingUtils.Companion.newInstance(getActivity(), mFirebaseAnalytics).bannerImpressions(bannerLL.getBanners().toArray(new HomeBanner[bannerLL.getBanners().size()]));
                        bannerLL.setTracked(true);
                    }
                }
            }
        } catch (Exception e) {
        }
    }

    public void onBannerClicked(HomeBanner banner) {
        if (banner == null) return;

        if (HomeBanner.BANNER_EVC.toLowerCase().equals(banner.getBannerName().toLowerCase())) {
            goToCeAeVC();
            return;
        }

        if (banner.getQuery() == null) {
            return;
        }

        DepartmentViewModel departmentViewModel = DepartmentViewModel.defaultDepartment();
        departmentViewModel.setName("");
        departmentViewModel.setDepartmentName("");
        Intent intent = ShowcaseActivity.Companion
                .createIntent(getContext(), CategoryViewModel.fromHomeBanner(banner), departmentViewModel);
        startActivity(intent);

        TrackingUtils.Companion.newInstance(getActivity(), mFirebaseAnalytics).bannerClick(banner.getBannerName());
    }

    private void loadBubbles() {
        Set<Bubble> bubblesTracked = new HashSet<>();
        LinearLayoutManager lm = new LinearLayoutManager(getActivity(), RecyclerView.HORIZONTAL, false);
        rv_homeBubbles.setLayoutManager(lm);
        BubbleAdapter bubbleAdapter = new BubbleAdapter(getActivity());
        bubbleAdapter.setListener((v, bubble) -> {
            TrackingUtils.Companion.newInstance(getContext(), mFirebaseAnalytics)
                    .bannerClick(bubble.getName());
            Intent intent = ShowcaseActivity.Companion.createIntent(getActivity(), null, bubble.getQuery());
            startActivity(intent, ((CAActivityKt) getActivity()).revealBundle(v));
        });
        rv_homeBubbles.setAdapter(bubbleAdapter);

        menuController.getBubbles(getContext(), new ServerCallback.BackBubbles() {
            @Override
            public void onSuccess(BubbleResult bubble) {
                v_homeBubbles.setVisibility(View.VISIBLE);
                tv_homeBubbles.setText(bubble.getTitle());
                bubbleAdapter.setList(bubble.getBubbles());
            }

            @Override
            public void onFailure(String message) {}
        });

        rv_homeBubbles.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                List<Bubble> bubbles = bubbleAdapter.getList();
                if(bubbles.size() > 0) {
                    int firstItem = lm.findFirstCompletelyVisibleItemPosition();
                    int lastItem = lm.findLastCompletelyVisibleItemPosition();
                    for (int i = firstItem; i <= lastItem; i++) {
                        Bubble bubble = bubbles.get(i);
                        if (!bubblesTracked.contains(bubble)) {
                            TrackingUtils.Companion.newInstance(getContext(), mFirebaseAnalytics)
                                    .bannerImpressions(bubble.getName());
                            bubblesTracked.add(bubble);
                        }
                    }
                }
            }
        });
    }

    private void loadOrders() {
        if(SessionManager.getInstance(getContext()).isLoggedIn()) {
            rv_homeOrders.setLayoutManager(new LinearLayoutManager(getActivity()));
            MyOrderSimpleAdapter ordersAdapter = new MyOrderSimpleAdapter(getContext());
            rv_homeOrders.setAdapter(ordersAdapter);
            ordersAdapter.setListener(myOrderViewModel -> {
                Intent i = new Intent(getActivity(), OrderDetail.class);
                i.putExtra(OrderDetail.EXTRA_ORDER_VIEW_MODEL, myOrderViewModel);
                startActivity(i);
            });
            new OrderController().getMyOrders(getContext(), new ServerCallback.BackListOrder() {
                @Override
                public void onSuccess(List<OrderGroupViewModel> result) {
                    try {
                        if(result.size() > 0) {
                            for (OrderGroupViewModel order : result) {
                                Date dateUpdate = order.getStatusLastUpdateParsed();
                                if(GeneralUtils.daysBetween(dateUpdate, new Date()) <= 3) {
                                    v_homeOrders.setVisibility(View.VISIBLE);
                                    ordersAdapter.setList(Collections.singletonList(order));
                                    return;
                                }
                            }
                        }
                    } catch (Exception e) {
                        Crashlytics.logException(e);
                    }
                }

                @Override
                public void onFailure(String result) {}
            });
        }
    }

    private void loadWishlist() {
        int padding = getResources().getDimensionPixelOffset(R.dimen.ela_scale_s4);
        if(SessionManager.getInstance(getContext()).isLoggedIn()) {
            rv_homeWishlist.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.HORIZONTAL, false));
            wishlistAdapter = new ProductSimpleListAdapter(getContext());
            rv_homeWishlist.setAdapter(wishlistAdapter);
            wishlistAdapter.setOnSelectProductListener((position, product) ->
                    startActivity(DetailProductActivity.Companion.CreateIntent(getContext(),
                    product.getProductId(), null)));

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                hsv_homeWishlist.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
                    iv_homeWishlistArrow.setVisibility(View.GONE);
                    SessionManager.getInstance(getContext()).setFirstTimeWishlistScrollHome(false);
                });
            }
            new WishlistController(getContext()).getWishlist(new ServerCallback.BackWishlist() {
                @Override
                public void onSuccess(@Nullable Wishlist wishlist) {
                    try {
                        List<ProductsViewModel> products = new ArrayList<>();
                        if(wishlist != null) {
                            for (ProductsViewModel product : wishlist.getProducts()) {
                                if (product.getPrice() > 0.0) {
                                    products.add(product);
                                }
                            }
                            if (products.size() > 1) {
                                tv_homeWishlistTitle.setText(SessionManager.getInstance(getContext())
                                        .getUser().getFirstName() + ",\naproveite sua lista de desejos");
                                if (products.size() >= 8) {
                                    v_homeWishlistSeeMore.setVisibility(View.VISIBLE);
                                } else {
                                    v_homeWishlistSeeMore.setVisibility(View.GONE);
                                }
                                if (products.size() > 2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                                        && SessionManager.getInstance(getContext()).isFirstTimeWishlistScrollHome()) {
                                    iv_homeWishlistArrow.setVisibility(View.VISIBLE);
                                }

                                v_homeWishlist.setVisibility(View.VISIBLE);
                                wishlistAdapter.setList(products.subList(0, products.size() >= 8 ? 7 : products.size()));
                                wishlistAdapter.notifyDataSetChanged();
                            } else {
                                v_homeWishlist.setVisibility(View.GONE);
                            }
                        }
                    } catch (Exception e) {
                        v_homeWishlist.setVisibility(View.GONE);
                        Crashlytics.logException(e);
                    }
                }

                @Override
                public void onFailure(String message) {
                    v_homeWishlist.setVisibility(View.GONE);
                }
            });
            v_homeWishlist.setPadding(0, padding, 0, padding);
        }
        else {
            v_homeWishlist.setVisibility(View.VISIBLE);
            v_homeWishlistLogin.setVisibility(View.VISIBLE);
            hsv_homeWishlist.setVisibility(View.GONE);
            iv_homeWishlistIcon.setVisibility(View.GONE);
            iv_homeWishlistArrow.setVisibility(View.GONE);
            v_homeWishlist.setBackgroundColor(Color.WHITE);
            v_homeWishlist.setPadding(0, 0, 0, 0);
            tv_homeWishlistTitle.setText(getString(R.string.improve_your_experience));
            tv_homeWishlistLogin.setText(Html.fromHtml(getString(R.string.call_to_login_generic)));
        }
    }

    @OnClick(R.id.imageview_cc_button_CeAeVc)
    void goToCeAeVC() {
        IntentUtils.checkLoyaltyAndStart((CAActivity) getActivity(), null);
        TrackingUtils.Companion.newInstance(getActivity(), mFirebaseAnalytics).bannerClick(HomeBanner.BANNER_EVC);
    }

    @OnClick(R.id.home_info_layout)
    public void onInfoClick() {
        IntentUtils.startConditions(getContext());
    }

    @OnClick(R.id.v_homeWishlistSeeMore)
    public void onSeeMoreWishlistClick() {
        startActivity(new Intent(getActivity(), WishlistActivity.class));
    }

    @OnClick(R.id.v_homeOrders)
    public void onOrderClick() {
        startActivity(new Intent(getContext(), MyOrders.class));
    }

    @OnClick(R.id.tv_homeOrdersSeeAll)
    public void onSeeMoreOrdersClick() {
        startActivity(new Intent(getActivity(), MyOrders.class));
    }

    @OnClick(R.id.v_homeWishlistLogin)
    public void onLoginClick() {
        startActivity(new Intent(getActivity(), Login.class));
    }

    @OnClick(R.id.iv_homeWishlistArrow)
    public void onScrollWishlistClick() {
        hsv_homeWishlist.smoothScrollTo(getResources().getDimensionPixelOffset(R.dimen.simple_card_product_width) * 2, 0);
    }

    @OnClick(R.id.v_homeWishlist)
    public void onWishlistClick() {
        if(SessionManager.getInstance(getContext()).isLoggedIn()) {
            if(wishlistAdapter != null && wishlistAdapter.getList().size() > 2)
                startActivity(new Intent(getContext(), WishlistActivity.class));
        }
        else {
            startActivity(new Intent(getContext(), Login.class));
        }
    }

}


<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mixxi.appcea.ui.fragment.HomeFragment">

    <RelativeLayout
        android:id="@+id/home_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.mixxi.appcea.ui.fragment.HomeFragment">

        <androidx.core.widget.NestedScrollView
            android:id="@+id/scrollview_home"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/background_home"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                android:id="@+id/v_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <LinearLayout
                    android:id="@+id/banner_layout_top"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <ProgressBar
                        android:id="@+id/temp_progress_bar"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_gravity="center" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/v_homeBubbles"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone"
                    tools:visibility="visible">

                    <ela.cea.sdk.components.ElaTextView
                        android:id="@+id/tv_homeBubblesTitle"
                        android:fontFamily="@font/greycliff"
                        style="@style/ElaTextView.F5.Black.Bold"
                        android:gravity="center"
                        android:layout_marginTop="@dimen/ela_scale_s4"
                        android:layout_marginStart="@dimen/ela_scale_s7"
                        android:text="navegue por departamento"/>

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/rv_homeBubbles"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/ela_scale_s5"
                        android:clipToPadding="false"
                        android:paddingStart="@dimen/ela_scale_s7"
                        android:paddingEnd="@dimen/ela_scale_s7" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/v_homeOrders"
                    android:visibility="gone"
                    android:layout_width="match_parent"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginTop="@dimen/ela_scale_s4"
                    android:padding="@dimen/ela_scale_s7"
                    tools:visibility="visible">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ela.cea.sdk.components.ElaTextView
                            android:fontFamily="@font/greycliff"
                            android:gravity="center"
                            style="@style/ElaTextView.F5.Black.Bold"
                            android:text="acompanhe seu pedido"/>

                        <ela.cea.sdk.components.ElaTextView
                            android:id="@+id/tv_homeOrdersSeeAll"
                            android:gravity="center"
                            android:textColor="#1C73C6"
                            android:background="?attr/selectableItemBackgroundBorderless"
                            style="@style/ElaTextView.F7.Black"
                            android:layout_alignParentEnd="true"
                            android:text="meus pedidos"/>
                    </RelativeLayout>

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/rv_homeOrders"
                        android:layout_width="match_parent"
                        android:layout_marginTop="@dimen/ela_scale_s5"
                        android:layout_height="wrap_content" />
                </LinearLayout>


                <ela.cea.sdk.components.ElaTextView
                    style="@style/ElaTextView.F5.Black.Bold"
                    android:fontFamily="@font/greycliff"
                    android:gravity="center"
                    android:layout_marginStart="@dimen/ela_scale_s7"
                    android:layout_marginTop="@dimen/ela_scale_s4"
                    android:text="aproveite as promoções"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:orientation="vertical"
                    android:paddingBottom="@dimen/ela_scale_s6"
                    android:layout_height="wrap_content">

                    <LinearLayout
                        android:id="@+id/banner_layout"
                        android:layout_marginTop="10dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <ProgressBar
                            android:id="@+id/temp_progress_bar_2"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_gravity="center" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/banner_evc"
                        android:layout_marginTop="6dp"
                        android:layout_width="match_parent"
                        android:layout_marginStart="6dp"
                        android:layout_marginEnd="6dp"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:id="@+id/imageview_cc_button_CeAeVc"
                            android:layout_width="match_parent"
                            android:layout_height="180dp"
                            android:scaleType="centerCrop"
                            android:src="@drawable/banner_ceaevc" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:id="@+id/v_homeWishlist"
                    android:layout_width="match_parent"
                    android:gravity="center"
                    android:background="@color/ela_grey_smokelighter"
                    android:foreground="?attr/selectableItemBackgroundBorderless"
                    android:layout_marginTop="@dimen/ela_scale_s6"
                    android:layout_marginBottom="@dimen/ela_scale_s4"
                    android:visibility="gone"
                    tools:visibility="visible"
                    android:paddingBottom="@dimen/ela_scale_s4"
                    android:paddingTop="@dimen/ela_scale_s4"
                    android:layout_height="wrap_content">

                    <LinearLayout
                        android:paddingStart="@dimen/ela_scale_s7"
                        android:paddingEnd="@dimen/ela_scale_s7"
                        android:layout_width="match_parent"
                        android:gravity="center_vertical"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:id="@+id/iv_homeWishlistIcon"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="@dimen/ela_scale_s7"
                            android:src="@drawable/ic_heart_bicolor"/>

                        <ela.cea.sdk.components.ElaTextView
                            android:id="@+id/tv_homeWishlistTitle"
                            android:fontFamily="@font/greycliff"
                            android:layout_marginEnd="@dimen/ela_scale_s7"
                            style="@style/ElaTextView.F5.Black.Bold"
                            android:text="Denise, \naproveite sua lista de desejos "/>
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/v_homeWishlistLogin"
                        android:visibility="gone"
                        tools:visibility="visible"
                        android:layout_width="match_parent"
                        android:background="@drawable/shape_rectangle_rouded_corner"
                        android:layout_marginTop="@dimen/ela_scale_s5"
                        android:layout_marginStart="@dimen/ela_scale_s7"
                        android:layout_marginEnd="@dimen/ela_scale_s7"
                        android:paddingTop="@dimen/ela_scale_s5"
                        android:paddingStart="@dimen/ela_scale_s7"
                        android:paddingEnd="@dimen/ela_scale_s7"
                        android:paddingBottom="@dimen/ela_scale_s5"
                        android:foreground="?attr/selectableItemBackground"
                        android:gravity="center_vertical"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/ic_heart_bicolor"/>

                        <TextView
                            android:id="@+id/tv_homeWishlistLogin"
                            android:fontFamily="@font/greycliff"
                            android:layout_marginStart="@dimen/ela_scale_s7"
                            android:layout_marginEnd="@dimen/ela_scale_s7"
                            style="@style/ElaTextView.F6"
                            tools:text="entre ou cadastre-se para receber status do seu pedido, promoções e muito mais"/>

                    </LinearLayout>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <HorizontalScrollView
                            android:id="@+id/hsv_homeWishlist"
                            android:layout_width="match_parent"
                            android:fillViewport="true"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/ela_scale_s5"
                            android:nestedScrollingEnabled="true"
                            android:scrollbars="horizontal">

                            <RelativeLayout
                                android:layout_marginBottom="@dimen/ela_scale_s5"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content">

                                <androidx.recyclerview.widget.RecyclerView
                                    android:id="@+id/rv_homeWishlist"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content" />

                                <LinearLayout
                                    android:layout_toEndOf="@+id/rv_homeWishlist"
                                    android:id="@+id/v_homeWishlistSeeMore"
                                    android:layout_width="@dimen/card_product_width"
                                    android:gravity="center"
                                    android:orientation="vertical"
                                    android:layout_alignTop="@+id/rv_homeWishlist"
                                    android:layout_alignBottom="@+id/rv_homeWishlist"
                                    android:background="?attr/selectableItemBackground"
                                    android:layout_height="match_parent" >

                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:src="@drawable/btn_last"/>

                                    <ela.cea.sdk.components.ElaTextView
                                        style="@style/ElaTextView.F6.Black.Bold"
                                        android:textColor="#1C73C6"
                                        android:gravity="center"
                                        android:fontFamily="@font/greycliff"
                                        android:text="mostrar todos\nos produtos" />
                                </LinearLayout>

                            </RelativeLayout>
                        </HorizontalScrollView>

                        <ImageView
                            android:id="@+id/iv_homeWishlistArrow"
                            android:layout_centerVertical="true"
                            android:layout_width="wrap_content"
                            android:layout_alignParentEnd="true"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="@dimen/ela_scale_s5"
                            android:visibility="gone"
                            tools:visibility="visible"
                            android:src="@drawable/btn_next"/>
                    </RelativeLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/home_info_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/white"
                    android:foreground="?attr/selectableItemBackground"
                    android:orientation="vertical"
                    android:paddingBottom="@dimen/ela_scale_s4"
                    android:paddingStart="@dimen/ela_scale_s7"
                    android:paddingEnd="@dimen/ela_scale_s7">

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#DFE4EF"/>

                    <TextView
                        style="@style/ElaTextView.Greycliff.F7.Black.Bold"
                        android:layout_marginTop="@dimen/ela_scale_s6"
                        android:text="ofertas e promoções"
                        android:textColor="@color/black"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/home_text_footer"
                        style="@style/ElaTextView.Greycliff.F7.Grey.Bold"
                        android:text="@string/home_footer"
                        android:textSize="10sp"
                        tools:ignore="MissingPrefix" />

                </LinearLayout>
            </LinearLayout>
        </androidx.core.widget.NestedScrollView>

        <include
            android:id="@+id/v_shimmer"
            layout="@layout/fragment_home_shimmer"
            android:visibility="gone" />

        <ImageView
            android:id="@+id/ivBlock"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:clickable="true"
            android:visibility="gone" />


    </RelativeLayout>

    <com.andremion.counterfab.CounterFab
        android:id="@+id/btnOpenCart"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_gravity="end|bottom"
        android:layout_margin="16dp"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:visibility="visible"
        app:fabSize="normal"
        app:srcCompat="@drawable/ic_sacola_btn" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>



package com.mixxi.appcea.domian.model;

import android.content.Context;

import com.mixxi.appcea.util.GeneralUtils;

/**
 * Created by aleciogomes on 18/08/17.
 */

public class HomeBanner {


    String bannerName;
    String name;
    String imageUrl;
    String query;
    String filter;
    String filterMap;
    String webViewUrl;
    String type;

    public static final String TYPE_TOP = "top";
    public static final String TYPE_PAIR = "pair";
    public static final String TYPE_WIDE = "wide";

    public static final String BANNER_EVC = "cea_gamification";

    public String getImageUrl(Context context) {
        return imageUrl.replace("{os}", "android").replace("{resolution}", GeneralUtils.getImageResolutionName(context));
    }

    public Boolean hasImageUrl() {
        return imageUrl != null;
    }

    public void setBannerName(String bannerName) {
        this.bannerName = bannerName;
    }

    public String getName() {
        return name;
    }

    public String getQuery() {
        return query;
    }

    public String getFilter() {
        return filter;
    }

    public String getFilterMap() {
        return filterMap;
    }

    public String getType() {
        return type;
    }

    public float getRatio() {
        if (type.equalsIgnoreCase("top")) {
            return 1.000f;
        }

        return  0.5f;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getWebviewUrl() {
        return webViewUrl;
    }

    public void setWebviewUrl(String webViewUrl) {
        this.webViewUrl = webViewUrl;
    }

    public String getBannerName() {
        return bannerName == null ? "" : bannerName;
    }

    @Override
    public String toString() {
        if(bannerName != null && !bannerName.isEmpty()) {
            return bannerName;
        }
        return super.toString();
    }
}


package com.mixxi.appcea.restruct.ui.qrcode.steps.info.action

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.mixxi.appcea.R
import com.mixxi.appcea.databinding.FragmentStepInfoActionBinding
import com.mixxi.appcea.restruct.ui.base.BaseViewModel
import com.mixxi.appcea.restruct.ui.qrcode.BaseQrFragment
import com.mixxi.appcea.restruct.ui.qrcode.steps.map.mapActivity.QrMapBaseActivity
import com.mixxi.appcea.restruct.util.extensions.bind
import com.mixxi.appcea.restruct.util.extensions.view.configureToolbarForGamification
import com.mixxi.appcea.restruct.util.extensions.view.snackErrorMessage
import com.mixxi.appcea.ui.activity.ImageFullScreenDynamic
import com.mixxi.appcea.ui.activity.gamification.base.BaseFragment
import com.mixxi.domain.entity.qrcode.QrCodeResult
import org.koin.androidx.viewmodel.ext.android.viewModel
import java.io.Serializable


class StepQrInfoActionFragment : BaseQrFragment() {

    private lateinit var binding: FragmentStepInfoActionBinding

    override val baseViewModel: BaseViewModel get() = qrInfoViewModel
    private val qrInfoViewModel: QrInfoActionViewModel by viewModel()
    private lateinit var data: QrCodeResult


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        qrInfoViewModel.start(data)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        binding = FragmentStepInfoActionBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        configureData()
    }

    override fun configureData() {
        configureComponents()
        subscribeUi()
    }

    override fun configureComponents() {
        configureToolbar()
        binding.infoNext.setOnClickListener {
            qrInfoViewModel.nextClick()
        }
    }

    override fun configureToolbar() {
        binding.toolbar.configureToolbarForGamification()
    }

    override fun showSnackError(message: String) {
        binding.snackErrorMessage(message)
    }

    override fun subscribeUi() {
        super.subscribeUi()
        bind(qrInfoViewModel.currentFragment, ::onFragmentChange)
        bind(baseViewModel.loading, ::onLoadingChange)
        bind(qrInfoViewModel.position, ::configureBinding)
        bind(qrInfoViewModel.position, ::configClick)
        bind(qrInfoViewModel.position, ::createIndicatorsView)
    }

    private fun configureBinding(position: Int) {
        binding.dataValue = data.steps[position]
    }

    private fun configClick(position: Int) {
        when (data.steps[position].linkType) {
            "mapa" -> {
                binding.infoAction.setOnClickListener {
                    val permissionCheck: Int = ContextCompat.checkSelfPermission(activity!!.applicationContext, Manifest.permission.ACCESS_FINE_LOCATION)

                    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
                        ActivityCompat.requestPermissions(activity!!, arrayOf<String>(Manifest.permission.ACCESS_FINE_LOCATION), REQUEST_PERMISSION)
                    } else { //Do your work
                        startActivity(Intent(activity!!.applicationContext, QrMapBaseActivity()::class.java))
                    }
                }
            }
            "showImages" -> {
                val imagens = data.steps[position].details?.toList()
                binding.infoAction.setOnClickListener {
                    startActivity(Intent(activity?.applicationContext, ImageFullScreenDynamic::class.java).apply {
                        putExtra("photos_drawable", imagens as Serializable)
                    })
                }
            }
        }
        binding.infoPrevious.setOnClickListener { qrInfoViewModel.previousClick() }

    }

    private fun createIndicatorsView(position: Int) {

        val indicatorsList = mutableListOf<View>()
        var a = 1
        while (a <= position) {
            val indicatorView = View(context)
            indicatorView.apply {
                tag = a.plus(10)
                background = resources.getDrawable(R.drawable.shape_gamification_indicator_selected)
            }

            constructLayoutParam(indicatorView)
            indicatorsList.add(indicatorView)
            a++
        }

        while (a <= 5) {
            val indicatorView = View(context)
            indicatorView.apply {
                tag = a.plus(10)
                background = resources.getDrawable(R.drawable.shape_gamification_indicator)
            }

            constructLayoutParam(indicatorView)
            indicatorsList.add(indicatorView)
            a++
        }

        indicatorView(indicatorsList)
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        when (requestCode) {
            REQUEST_PERMISSION -> if (grantResults.size > 0 && grantResults[0] === PackageManager.PERMISSION_GRANTED) {
                startActivity(Intent(activity!!.applicationContext, QrMapBaseActivity()::class.java))
            } else {
                Toast.makeText(activity!!.applicationContext, PERMISSION_DENID, Toast.LENGTH_SHORT).show()
            }
            else -> {}
        }
    }

    override fun indicatorView(indicators: List<View>) {
        binding.infoIndicators.removeAllViews()
        indicators.forEach { indicator ->
            binding.infoIndicators.addView(indicator)
        }
    }

    companion object {
        const val PERMISSION_DENID = "Permissão negada!"
        const val REQUEST_PERMISSION = 11
        fun newInstance(data: QrCodeResult): BaseFragment {
            val frag = StepQrInfoActionFragment()
            frag.data = data
            return frag
        }
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.