Search in sources :

Example 26 with ToolbarListener

use of net.iGap.observers.interfaces.ToolbarListener in project iGap-Android by KianIranian-STDG.

the class FragmentPaymentInquiryTelephone method onViewCreated.

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    binding.toolbar.addView(HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLogoShown(true).setDefaultTitle(getString(R.string.bills_inquiry_telecom)).setLeftIcon(R.string.icon_back).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            popBackStackFragment();
        }
    }).getView());
    viewModel.getHideKeyword().observe(getViewLifecycleOwner(), isHide -> {
        if (isHide != null && isHide) {
            hideKeyboard();
        }
    });
    viewModel.getShowErrorMessage().observe(getViewLifecycleOwner(), messageResId -> {
        if (messageResId != null) {
            HelperError.showSnackMessage(getString(messageResId), false);
        }
    });
    viewModel.getGoToShowInquiryBillPage().observe(getViewLifecycleOwner(), data -> {
        if (getActivity() != null && data != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), ShowBillInquiryFragment.getInstance(data, R.string.bills_inquiry_telecom)).setReplace(false).load(true);
        }
    });
}
Also used : ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) HelperFragment(net.iGap.helper.HelperFragment) View(android.view.View)

Example 27 with ToolbarListener

use of net.iGap.observers.interfaces.ToolbarListener in project iGap-Android by KianIranian-STDG.

the class PaymentInternetFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setupRecyclerViews();
    toolbar.addView(HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setDefaultTitle(getString(R.string.buy_internet_package_title)).setLogoShown(true).setLeftIcon(R.string.icon_back).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            if (getActivity() != null) {
                getActivity().onBackPressed();
            }
        }
    }).getView());
    viewModel.getTimeFilterListObservable().observe(getViewLifecycleOwner(), timeFilterList -> {
        hideKeyboard();
        if (timeFilterList != null) {
            spinnerTime.setAdapter(new MySpinnerAdapter(timeFilterList));
        } else {
            spinnerTime.setSelection(0);
        }
    });
    viewModel.getTrafficFilterListObservable().observe(getViewLifecycleOwner(), trafficFilter -> {
        hideKeyboard();
        if (trafficFilter != null) {
            spinnerTraffic.setAdapter(new MySpinnerAdapter(trafficFilter));
        } else {
            spinnerTraffic.setSelection(0);
        }
    });
    viewModel.getPackageListSuggestedObservable().observe(getViewLifecycleOwner(), internetPackages -> {
        if (internetPackages == null || internetPackages.size() == 0) {
            suggestedRecyclerView.setVisibility(View.GONE);
            suggestedTextView.setVisibility(View.GONE);
            return;
        }
        suggestedRecyclerView.setVisibility(View.VISIBLE);
        suggestedTextView.setVisibility(View.VISIBLE);
        suggestedAdapter.setData(internetPackages, packageType);
    });
    viewModel.getPackageListOthersObservable().observe(getViewLifecycleOwner(), internetPackages -> {
        if (internetPackages == null || internetPackages.size() == 0) {
            otherPackagesRecyclerView.setVisibility(View.GONE);
            othersTextView.setVisibility(View.GONE);
            return;
        }
        otherPackagesRecyclerView.setVisibility(View.VISIBLE);
        othersTextView.setVisibility(View.VISIBLE);
        othersAdapter.setData(internetPackages, packageType);
        dataDidLoad();
    });
    viewModel.getGoToPaymentPage().observe(getViewLifecycleOwner(), token -> {
        if (getActivity() != null && token != null) {
            new HelperFragment(getActivity().getSupportFragmentManager()).loadPayment(getString(R.string.buy_internet_package_title), true, token, result -> {
                if (result.isSuccess()) {
                    if (currentInternetPackage != null) {
                        savePayment();
                    }
                    if (getActivity() != null)
                        getActivity().onBackPressed();
                }
            });
        }
    });
    viewModel.getShowErrorMessage().observe(getViewLifecycleOwner(), errorRes -> {
        showError(getResources().getString(errorRes));
    });
    viewModel.getShowRequestErrorMessage().observe(getViewLifecycleOwner(), this::showError);
    viewModel.getLoadingVisibility().observe(getViewLifecycleOwner(), showLoading -> {
        if (showLoading == null)
            return;
        if (showLoading) {
            loadingView.setVisibility(View.VISIBLE);
            payBtn.setEnabled(false);
        } else {
            loadingView.setVisibility(View.GONE);
            payBtn.setEnabled(true);
        }
    });
    viewModel.getIsDataLoaded().observe(getViewLifecycleOwner(), isDataLoaded -> {
        if (isDataLoaded != null && isDataLoaded) {
            loadingView.setVisibility(View.GONE);
            scrollView.setVisibility(View.VISIBLE);
            payBtn.setVisibility(View.VISIBLE);
        }
    });
    spinnerTime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            timeFilterPosition = position - 1;
            viewModel.updateInternetPackager(timeFilterPosition, trafficFilterPosition);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerTraffic.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            trafficFilterPosition = position - 1;
            viewModel.updateInternetPackager(timeFilterPosition, trafficFilterPosition);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    payBtn.setOnClickListener(v -> viewModel.requestPayment());
}
Also used : ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) MySpinnerAdapter(net.iGap.adapter.MySpinnerAdapter) AdapterView(android.widget.AdapterView) HelperFragment(net.iGap.helper.HelperFragment) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) NestedScrollView(androidx.core.widget.NestedScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) RecyclerListView(net.iGap.module.customView.RecyclerListView)

Example 28 with ToolbarListener

use of net.iGap.observers.interfaces.ToolbarListener in project iGap-Android by KianIranian-STDG.

the class ChartFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    toolbar = view.findViewById(R.id.chart_toolbar);
    emptyRecycle = view.findViewById(R.id.emptyRecycle_chart);
    swipeRefresh = view.findViewById(R.id.sweep);
    chart = view.findViewById(R.id.type8_chart0);
    if (getArguments() != null) {
        pollId = getArguments().getInt("pollId");
    } else {
        if (getActivity() != null)
            getActivity().onBackPressed();
    }
    helperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setLogoShown(true).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            popBackStackFragment();
        }
    });
    toolbar.addView(helperToolbar.getView());
    XAxis xAxis = chart.getXAxis();
    xAxis.setTextColor(new Theme().getTitleTextColor(chart.getContext()));
    xAxis.setTypeface(ResourcesCompat.getFont(chart.getContext(), R.font.main_font));
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextSize(ViewMaker.dpToPixel(4));
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);
    xAxis.setGranularityEnabled(true);
    tryToUpdateOrFetchRecycleViewData(0);
    chart.setMaxVisibleValueCount(100);
    chart.setNoDataText(getString(R.string.Submitـomment));
    chart.setPinchZoom(false);
    chart.setHighlightPerTapEnabled(false);
    chart.setDrawValueAboveBar(true);
    chart.setDrawBarShadow(false);
    chart.setDrawGridBackground(false);
    chart.getDescription().setEnabled(false);
    chart.setDrawGridBackground(false);
    chart.setTouchEnabled(true);
    chart.setDoubleTapToZoomEnabled(false);
    chart.getAxisLeft().setAxisMinimum(0);
    chart.getAxisRight().setEnabled(false);
    chart.getAxisLeft().setEnabled(false);
    chart.getAxisLeft().setDrawGridLines(false);
    chart.animateY(1000);
    chart.getLegend().setEnabled(false);
    chart.getAxisLeft().setValueFormatter(new ValueFormatter() {

        @Override
        public String getFormattedValue(float value) {
            return String.valueOf((int) Math.floor(value));
        }
    });
    emptyRecycle.setOnClickListener(v -> {
        boolean isSend = updateOrFetchRecycleViewData();
        if (!isSend) {
            HelperError.showSnackMessage(getString(R.string.wallet_error_server), false);
        } else {
            emptyRecycle.setVisibility(View.GONE);
        }
    });
    swipeRefresh.setOnRefreshListener(() -> {
        swipeRefresh.setRefreshing(true);
        boolean isSend = updateOrFetchRecycleViewData();
        if (!isSend) {
            swipeRefresh.setRefreshing(false);
            HelperError.showSnackMessage(getString(R.string.wallet_error_server), false);
        } else {
            emptyRecycle.setVisibility(View.GONE);
        }
    });
}
Also used : ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) Theme(net.iGap.module.Theme) IndexAxisValueFormatter(com.github.mikephil.charting.formatter.IndexAxisValueFormatter) ValueFormatter(com.github.mikephil.charting.formatter.ValueFormatter) View(android.view.View) TextView(android.widget.TextView) XAxis(com.github.mikephil.charting.components.XAxis)

Example 29 with ToolbarListener

use of net.iGap.observers.interfaces.ToolbarListener in project iGap-Android by KianIranian-STDG.

the class PopularMoreChannelFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    helperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            viewModel.toolbarBackClick();
        }
    }).setLogoShown(true).setDefaultTitle("").setLeftIcon(R.string.icon_back);
    ((LinearLayout) view.findViewById(R.id.ll_moreChannel_toolBar)).addView(helperToolbar.getView());
    RecyclerView recyclerView = view.findViewById(R.id.rv_moreChannel);
    swipeRefreshLayout = view.findViewById(R.id.sr_popularChannel_moreChannel);
    emptyTextView = view.findViewById(R.id.tv_popularChannel_emptyText);
    sliderCv = view.findViewById(R.id.cv_popularChannel_more);
    slider = view.findViewById(R.id.bs_popularChannel_more);
    recyclerView.setAdapter(new PopularMoreChannelAdapter(new PopularMoreChannelAdapter.OnMoreChannelCallBack() {

        @Override
        public void onChannelClick(Channel channel) {
            viewModel.onChannelClick(channel);
        }

        @Override
        public void onLoadMore() {
            viewModel.loadMoreData();
        }
    }));
    recyclerView.setNestedScrollingEnabled(false);
    swipeRefreshLayout.setOnRefreshListener(() -> viewModel.onSwipeRefresh());
    view.findViewById(R.id.retryView).setOnClickListener(v -> viewModel.onSwipeRefresh());
    viewModel.getGoBack().observe(getViewLifecycleOwner(), isGoBack -> {
        if (getActivity() != null && isGoBack != null && isGoBack) {
            getActivity().onBackPressed();
        }
    });
    viewModel.getToolbarTitle().observe(getViewLifecycleOwner(), toolbarTitle -> {
        if (toolbarTitle != null) {
            helperToolbar.setDefaultTitle(toolbarTitle);
        }
    });
    viewModel.getShowAdvertisement().observe(getViewLifecycleOwner(), adv -> {
        if (adv != null) {
            sliderCv.setVisibility(View.VISIBLE);
            String scale = adv.getmScale();
            slider.postDelayed(() -> {
                slider.setAdapter(new PopularChannelMoreSliderAdapter(adv.getSlides(), scale));
                slider.setSelectedSlide(0);
                slider.setLoopSlides(true);
                slider.setInterval(adv.getmPlaybackTime());
                slider.setOnSlideClickListener(position -> {
                    viewModel.onSlideClick(adv.getSlides().get(position));
                });
            }, 200);
        } else {
            sliderCv.setVisibility(View.GONE);
        }
    });
    viewModel.getGoToChannel().observe(getViewLifecycleOwner(), data -> {
        if (getActivity() != null && data != null) {
            if (data.isPrivate()) {
                HelperUrl.checkAndJoinToRoom(getActivity(), data.getSlug());
            } else {
                HelperUrl.checkUsernameAndGoToRoom(getActivity(), data.getSlug(), HelperUrl.ChatEntry.chat);
            }
        }
    });
    viewModel.getMoreChannelMutableLiveData().observe(getViewLifecycleOwner(), childChannel -> {
        Log.wtf(this.getClass().getName(), "getMoreChannelMutableLiveData");
        if (childChannel != null && recyclerView.getAdapter() instanceof PopularMoreChannelAdapter) {
            Log.wtf(this.getClass().getName(), "getMoreChannelMutableLiveData");
            ((PopularMoreChannelAdapter) recyclerView.getAdapter()).setChannels(childChannel);
        }
    });
    viewModel.getShowRetryView().observe(getViewLifecycleOwner(), isShow -> {
        if (isShow != null) {
            view.findViewById(R.id.retryView).setVisibility(isShow ? View.VISIBLE : View.GONE);
        }
    });
    viewModel.getProgressMutableLiveData().observe(getViewLifecycleOwner(), progress -> {
        if (progress != null && progress)
            swipeRefreshLayout.setRefreshing(true);
        else
            swipeRefreshLayout.setRefreshing(false);
    });
    viewModel.getEmptyViewMutableLiveData().observe(getViewLifecycleOwner(), haveEmptyView -> {
        if (haveEmptyView != null && haveEmptyView)
            emptyTextView.setVisibility(View.VISIBLE);
        else
            emptyTextView.setVisibility(View.GONE);
    });
}
Also used : PopularMoreChannelAdapter(net.iGap.adapter.items.popularChannel.PopularMoreChannelAdapter) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) PopularChannelMoreSliderAdapter(net.iGap.adapter.items.popularChannel.PopularChannelMoreSliderAdapter) Channel(net.iGap.model.popularChannel.Channel) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 30 with ToolbarListener

use of net.iGap.observers.interfaces.ToolbarListener in project iGap-Android by KianIranian-STDG.

the class NewsDetailFrag method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Bundle arg = getArguments();
    HelperToolbar mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            popBackStackFragment();
        }
    }).setLogoShown(true);
    LinearLayout toolbarLayout = binding.Toolbar;
    toolbarLayout.addView(mHelperToolbar.getView());
    binding.shareNews.setOnClickListener(v -> Toast.makeText(getContext(), "share", Toast.LENGTH_SHORT).show());
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false);
    binding.relatedNewsList.setLayoutManager(layoutManager);
    LinearLayoutManager layoutManager2 = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false);
    binding.commentList.setLayoutManager(layoutManager2);
    binding.shareNewsBTN.setOnClickListener(v -> {
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, viewModel.getData().getValue().getTitle() + "\n" + viewModel.getData().getValue().getLead() + "\n" + "تاریخ انتشار: " + viewModel.getData().getValue().getDate() + "\n" + "قدرت گرفته از آیگپ" + "\n" + "این خبر را در آیگپ بخوانید: " + "igap://news/showDetail/" + arg.getString("NewsID") + "\n" + "لینک خبر: " + viewModel.getData().getValue().getLink());
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, "Share via"));
    });
    binding.writeComment.setOnClickListener(v -> {
        NewsAddCommentBottomSheetFrag bottomSheetFragment = new NewsAddCommentBottomSheetFrag().setData(arg.getString("NewsID"), result -> {
            if (result)
                Toast.makeText(getContext(), R.string.news_add_comment_successToast, Toast.LENGTH_SHORT).show();
            else
                Toast.makeText(getContext(), R.string.news_add_comment_failToast, Toast.LENGTH_SHORT).show();
        });
        bottomSheetFragment.show(getFragmentManager(), "AddCommentBottomSheet");
    });
    viewModel.getDataFromServer(arg.getString("NewsID"));
    onErrorObserver();
    onDataChanged();
    onProgress();
}
Also used : ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) Bundle(android.os.Bundle) Intent(android.content.Intent) HelperToolbar(net.iGap.helper.HelperToolbar) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)35 ToolbarListener (net.iGap.observers.interfaces.ToolbarListener)35 HelperToolbar (net.iGap.helper.HelperToolbar)18 HelperFragment (net.iGap.helper.HelperFragment)13 LinearLayout (android.widget.LinearLayout)9 TextView (android.widget.TextView)9 Bundle (android.os.Bundle)8 ViewGroup (android.view.ViewGroup)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 Fragment (androidx.fragment.app.Fragment)5 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)5 LayoutInflater (android.view.LayoutInflater)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 DataBindingUtil (androidx.databinding.DataBindingUtil)4 ViewModelProviders (androidx.lifecycle.ViewModelProviders)4 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 R (net.iGap.R)4 ActivityMain (net.iGap.activities.ActivityMain)4 AdapterView (android.widget.AdapterView)3