Search in sources :

Example 1 with BodyHeadCard

use of app.insti.utils.BodyHeadCard in project IITB-App by wncc.

the class BodyFragment method displayBody.

private void displayBody() {
    /* Skip if we're already destroyed */
    if (getActivity() == null || getView() == null)
        return;
    if (body != min_body)
        bodyDisplayed = true;
    bodyPicture = (ImageView) getActivity().findViewById(R.id.body_picture);
    /* Load only low res image if transition is not completed */
    if (transitionEnded) {
        Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL());
    } else {
        Picasso.get().load(Utils.resizeImageUrl(body.getBodyImageURL())).into(bodyPicture);
    }
    /* Skip for min body */
    if (body == min_body) {
        return;
    }
    bodyPicture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            zoomImageFromThumb(bodyPicture);
            final FloatingActionButton fab = getView().findViewById(R.id.edit_fab);
            fab.hide();
        }
    });
    mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    final List<Role> roles = body.getBodyRoles();
    final List<User> users = new ArrayList<>();
    for (Role role : roles) {
        if (role.getRoleUsersDetail() != null) {
            for (User user : role.getRoleUsersDetail()) {
                user.setCurrentRole(role.getRoleName());
                users.add(user);
            }
        }
    }
    final List<CardInterface> cards = new ArrayList<>();
    cards.add(new BodyHeadCard(body));
    addWithTitleCard(cards, body.getBodyEvents(), "Events");
    addWithTitleCard(cards, users, "People");
    addWithTitleCard(cards, body.getBodyChildren(), "Organizations");
    addWithTitleCard(cards, body.getBodyParents(), "Part of");
    final RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.body_recycler_view);
    GenericAdapter genericAdapter = new GenericAdapter(cards, this);
    recyclerView.setAdapter(genericAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
    /* Show update button if role */
    if (((MainActivity) getActivity()).editBodyAccess(body)) {
        final FloatingActionButton fab = getView().findViewById(R.id.edit_fab);
        fab.show();
        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy > 0)
                    fab.hide();
                else
                    fab.show();
            }
        });
        fab.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                WebViewFragment webViewFragment = new WebViewFragment();
                Bundle bundle = new Bundle();
                bundle.putString(Constants.WV_TYPE, Constants.WV_TYPE_UPDATE_BODY);
                bundle.putString(Constants.WV_ID, body.getBodyID());
                webViewFragment.setArguments(bundle);
                ((MainActivity) getActivity()).updateFragment(webViewFragment);
            }
        });
    }
}
Also used : CardInterface(app.insti.interfaces.CardInterface) User(app.insti.api.model.User) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MainActivity(app.insti.activity.MainActivity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Point(android.graphics.Point) Role(app.insti.api.model.Role) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) RecyclerView(androidx.recyclerview.widget.RecyclerView) GenericAdapter(app.insti.adapter.GenericAdapter) BodyHeadCard(app.insti.utils.BodyHeadCard)

Example 2 with BodyHeadCard

use of app.insti.utils.BodyHeadCard in project IITB-App by wncc.

the class CardAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) {
    switch(holder.getItemViewType()) {
        case 0:
            CardViewHolder viewHolder = (CardViewHolder) holder;
            T t = tList.get(i);
            viewHolder.title.setText(t.getTitle());
            viewHolder.subtitle.setText(t.getSubtitle());
            // Set transition names
            viewHolder.avatar.setTransitionName(uid + Integer.toString((int) t.getId()) + "_sharedAvatar");
            // Set badge if wanted
            if (t.getBadge() != 0) {
                Picasso.get().load(t.getBadge()).into(viewHolder.badge);
                viewHolder.badge.setVisibility(View.VISIBLE);
            } else {
                viewHolder.badge.setVisibility(View.GONE);
            }
            if (getBigImageUrl(t) != null) {
                // Show big image, hide avatar
                viewHolder.bigPicture.setVisibility(View.VISIBLE);
                viewHolder.bigPicture.setTransitionName(uid + Integer.toString((int) t.getId()) + "_sharedBigPicture");
                viewHolder.avatar.setVisibility(View.GONE);
                // Load big image with low resolution as avatar
                Utils.loadImageWithPlaceholder(viewHolder.bigPicture, getBigImageUrl(t));
            } else {
                // Make sure avatar is visible for recycled views
                viewHolder.bigPicture.setVisibility(View.GONE);
                viewHolder.avatar.setVisibility(View.VISIBLE);
                // Build basic request
                RequestCreator requestCreator;
                if (t.getAvatarUrl() != null && !t.getAvatarUrl().equals(""))
                    requestCreator = Picasso.get().load(Utils.resizeImageUrl(t.getAvatarUrl()));
                else if (getAvatarPlaceholder(t) != 0) {
                    requestCreator = Picasso.get().load(getAvatarPlaceholder(t));
                } else {
                    return;
                }
                // Check if we have a placeholder
                if (getAvatarPlaceholder(t) != 0) {
                    requestCreator.placeholder(getAvatarPlaceholder(t));
                }
                // Load the image
                requestCreator.into(viewHolder.avatar);
            }
            return;
        case 2:
            TitleViewHolder titleViewHolder = (TitleViewHolder) holder;
            titleViewHolder.title.setText(tList.get(i).getTitle());
            return;
        case 4:
            ((BodyHeadCard) tList.get(i)).bindView((BodyHeadViewHolder) holder, mFragment);
            return;
        default:
            return;
    }
}
Also used : BodyHeadCard(app.insti.utils.BodyHeadCard) RequestCreator(com.squareup.picasso.RequestCreator)

Aggregations

BodyHeadCard (app.insti.utils.BodyHeadCard)2 Point (android.graphics.Point)1 Bundle (android.os.Bundle)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MainActivity (app.insti.activity.MainActivity)1 GenericAdapter (app.insti.adapter.GenericAdapter)1 Role (app.insti.api.model.Role)1 User (app.insti.api.model.User)1 CardInterface (app.insti.interfaces.CardInterface)1 FloatingActionButton (com.google.android.material.floatingactionbutton.FloatingActionButton)1 RequestCreator (com.squareup.picasso.RequestCreator)1 ArrayList (java.util.ArrayList)1