Search in sources :

Example 1 with StaticFragmentPagerAdapter

use of org.edx.mobile.view.adapters.StaticFragmentPagerAdapter in project edx-app-android by edx.

the class UserProfileFragment method createView.

@NonNull
@Override
protected UserProfilePresenter.ViewInterface createView() {
    viewHolder = DataBindingUtil.getBinding(getView());
    snackbarErrorNotification = new SnackbarErrorNotification(viewHolder.getRoot());
    viewHolder.profileSectionPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            onChildScrollingPreferenceChanged();
        }
    });
    final StaticFragmentPagerAdapter adapter = createTabAdapter();
    viewHolder.profileSectionPager.setAdapter(adapter);
    viewHolder.profileSectionTabs.setupWithViewPager(viewHolder.profileSectionPager);
    return new UserProfilePresenter.ViewInterface() {

        @Override
        public void setEditProfileMenuButtonVisible(boolean visible) {
            setHasOptionsMenu(visible);
        }

        @Override
        public void showProfile(@NonNull UserProfileViewModel profile) {
            if (profile.limitedProfileMessage == UserProfileViewModel.LimitedProfileMessage.NONE) {
                viewHolder.sharingLimited.setVisibility(View.GONE);
            } else {
                viewHolder.sharingLimited.setVisibility(View.VISIBLE);
                viewHolder.sharingLimited.setText(profile.limitedProfileMessage == UserProfileViewModel.LimitedProfileMessage.OWN_PROFILE ? R.string.profile_sharing_limited_by_you : R.string.profile_sharing_limited_by_other_user);
            }
            if (TextUtils.isEmpty(profile.language)) {
                viewHolder.languageContainer.setVisibility(View.GONE);
            } else {
                viewHolder.languageText.setText(profile.language);
                viewHolder.languageText.setContentDescription(ResourceUtil.getFormattedString(getResources(), R.string.profile_language_description, "language", profile.language));
                viewHolder.languageContainer.setVisibility(View.VISIBLE);
            }
            if (TextUtils.isEmpty(profile.location)) {
                viewHolder.locationContainer.setVisibility(View.GONE);
            } else {
                viewHolder.locationText.setText(profile.location);
                viewHolder.locationText.setContentDescription(ResourceUtil.getFormattedString(getResources(), R.string.profile_location_description, "location", profile.location));
                viewHolder.locationContainer.setVisibility(View.VISIBLE);
            }
            viewHolder.contentLoadingIndicator.getRoot().setVisibility(View.GONE);
            viewHolder.contentError.getRoot().setVisibility(View.GONE);
            viewHolder.profileBodyContent.setVisibility(View.VISIBLE);
            viewHolder.profileHeader.setVisibility(View.VISIBLE);
            onFinish();
        }

        @Override
        public void showLoading() {
            ((AppBarLayout.LayoutParams) viewHolder.profileHeader.getLayoutParams()).setScrollFlags(0);
            viewHolder.profileBody.setBackgroundColor(getResources().getColor(R.color.edx_brand_gray_x_back));
            viewHolder.profileSectionTabs.setVisibility(View.GONE);
            viewHolder.contentError.getRoot().setVisibility(View.GONE);
            viewHolder.profileBodyContent.setVisibility(View.GONE);
            viewHolder.contentLoadingIndicator.getRoot().setVisibility(View.VISIBLE);
            viewHolder.profileHeader.setVisibility(View.GONE);
        }

        @Override
        public void showError(@NonNull Throwable error) {
            ((AppBarLayout.LayoutParams) viewHolder.profileHeader.getLayoutParams()).setScrollFlags(0);
            viewHolder.profileBody.setBackgroundColor(getResources().getColor(R.color.edx_brand_gray_x_back));
            viewHolder.profileSectionTabs.setVisibility(View.GONE);
            viewHolder.contentLoadingIndicator.getRoot().setVisibility(View.GONE);
            viewHolder.profileBodyContent.setVisibility(View.GONE);
            final Icon errorIcon = ErrorUtils.getErrorIcon(error);
            viewHolder.contentError.getRoot().setVisibility(View.VISIBLE);
            if (errorIcon != null) {
                viewHolder.contentError.contentErrorIcon.setIcon(errorIcon);
            }
            viewHolder.contentError.contentErrorText.setText(ErrorUtils.getErrorMessage(error, getContext()));
            viewHolder.contentError.contentErrorAction.setText(R.string.lbl_reload);
            viewHolder.contentError.contentErrorAction.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (NetworkUtil.isConnected(getContext())) {
                        onRefresh();
                    }
                }
            });
            viewHolder.contentError.contentErrorAction.setVisibility(View.VISIBLE);
            viewHolder.profileHeader.setVisibility(View.GONE);
            onFinish();
        }

        @Override
        public void showTabs(@NonNull List<UserProfileTab> tabs) {
            adapter.setItems(pagerItemsFromProfileTabs(tabs, getResources()));
            viewHolder.profileSectionTabs.setVisibility(tabs.size() < 2 ? View.GONE : View.VISIBLE);
        }

        @Override
        public void setPhotoImage(@NonNull UserProfileImageViewModel model) {
            if (null == model.uri) {
                Glide.with(UserProfileFragment.this).load(R.drawable.profile_photo_placeholder).into(viewHolder.profileImage);
            } else if (model.shouldReadFromCache) {
                Glide.with(UserProfileFragment.this).load(model.uri).into(viewHolder.profileImage);
            } else {
                Glide.with(UserProfileFragment.this).load(model.uri).skipMemoryCache(// URI is re-used in subsequent events; disable caching
                true).diskCacheStrategy(DiskCacheStrategy.NONE).into(viewHolder.profileImage);
            }
        }

        @Override
        public void setUsername(@NonNull String username) {
            viewHolder.nameText.setText(username);
            viewHolder.nameText.setContentDescription(ResourceUtil.getFormattedString(getResources(), R.string.profile_username_description, "username", username));
        }

        @Override
        public void navigateToProfileEditor(@NonNull String username) {
            router.showUserProfileEditor(getActivity(), username);
        }

        private void onFinish() {
            if (!EventBus.getDefault().isRegistered(UserProfileFragment.this)) {
                EventBus.getDefault().registerSticky(UserProfileFragment.this);
            }
        }
    };
}
Also used : StaticFragmentPagerAdapter(org.edx.mobile.view.adapters.StaticFragmentPagerAdapter) ViewPager(android.support.v4.view.ViewPager) View(android.view.View) SnackbarErrorNotification(org.edx.mobile.http.notifications.SnackbarErrorNotification) NonNull(android.support.annotation.NonNull) LinkedList(java.util.LinkedList) List(java.util.List) Icon(com.joanzapata.iconify.Icon) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 Icon (com.joanzapata.iconify.Icon)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 SnackbarErrorNotification (org.edx.mobile.http.notifications.SnackbarErrorNotification)1 StaticFragmentPagerAdapter (org.edx.mobile.view.adapters.StaticFragmentPagerAdapter)1