Search in sources :

Example 1 with PopularChannelHomeAdapter

use of net.iGap.adapter.items.popularChannel.PopularChannelHomeAdapter in project iGap-Android by KianIranian-STDG.

the class PopularChannelHomeFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    RecyclerView recyclerView = view.findViewById(R.id.rv_popularChannel_home);
    swipeRefreshLayout = view.findViewById(R.id.sr_popularChannel_home);
    epmtyView = view.findViewById(R.id.emptyRecycle);
    Toolbar popularChannelsToolbar = new Toolbar(getContext());
    popularChannelsToolbar.setBackIcon(new BackDrawable(false));
    popularChannelsToolbar.setTitle(getString(R.string.popular_channel));
    popularChannelsToolbar.setListener(i -> {
        if (i == -1) {
            if (getActivity() != null)
                getActivity().onBackPressed();
        }
    });
    recyclerView.setAdapter(new PopularChannelHomeAdapter(viewModel.getRecyclerItemClick()));
    ((ViewGroup) view.findViewById(R.id.ll_popularChannel_toolBar)).addView(popularChannelsToolbar);
    viewModel.getFirstPageMutableLiveData().observe(getViewLifecycleOwner(), parentChannel -> {
        if (recyclerView.getAdapter() instanceof PopularChannelHomeAdapter && parentChannel != null) {
            ((PopularChannelHomeAdapter) recyclerView.getAdapter()).setData(parentChannel.getData());
        }
    });
    viewModel.getProgressMutableLiveData().observe(getViewLifecycleOwner(), progress -> {
        if (progress != null && progress)
            swipeRefreshLayout.setRefreshing(true);
        else
            swipeRefreshLayout.setRefreshing(false);
    });
    swipeRefreshLayout.setOnRefreshListener(() -> {
        viewModel.getFirstPage();
    });
    viewModel.getEmptyViewMutableLiveData().observe(getViewLifecycleOwner(), visibility -> {
        if (visibility != null)
            epmtyView.setVisibility(visibility);
    });
    viewModel.getGoToMorePage().observe(getViewLifecycleOwner(), data -> {
        if (getActivity() != null && data != null) {
            PopularMoreChannelFragment moreChannelFragment = new PopularMoreChannelFragment();
            Bundle bundle = new Bundle();
            bundle.putString("id", data.getId());
            bundle.putString("title", G.isAppRtl ? data.getTitle() : data.getTitleEn());
            moreChannelFragment.setArguments(bundle);
            new HelperFragment(getActivity().getSupportFragmentManager(), moreChannelFragment).setReplace(false).load(true);
        }
    });
    viewModel.getGoToRoom().observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            HelperUrl.checkUsernameAndGoToRoom(getActivity(), link, HelperUrl.ChatEntry.chat);
        }
    });
    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.getGoToWebViewPage().observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentWebView.newInstance(link, false, null)).setReplace(false).load();
        }
    });
    viewModel.getOpenBrowser().observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            SharedPreferences sharedPreferences = getActivity().getSharedPreferences(SHP_SETTING.FILE_NAME, Context.MODE_PRIVATE);
            int checkedInAppBrowser = sharedPreferences.getInt(SHP_SETTING.KEY_IN_APP_BROWSER, 1);
            if (checkedInAppBrowser == 1 && !HelperUrl.isNeedOpenWithoutBrowser(link)) {
                HelperUrl.openBrowser(link);
            } else {
                HelperUrl.openWithoutBrowser(link);
            }
        }
    });
    epmtyView.setOnClickListener(v -> viewModel.getFirstPage());
}
Also used : PopularChannelHomeAdapter(net.iGap.adapter.items.popularChannel.PopularChannelHomeAdapter) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Bundle(android.os.Bundle) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) HelperToolbar(net.iGap.helper.HelperToolbar)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 ViewGroup (android.view.ViewGroup)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 PopularChannelHomeAdapter (net.iGap.adapter.items.popularChannel.PopularChannelHomeAdapter)1 HelperFragment (net.iGap.helper.HelperFragment)1 HelperToolbar (net.iGap.helper.HelperToolbar)1 BackDrawable (net.iGap.messenger.ui.toolBar.BackDrawable)1 Toolbar (net.iGap.messenger.ui.toolBar.Toolbar)1