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());
}
Aggregations