Android Open Source - TuentiTV Detail Fragment






From Project

Back to project page TuentiTV.

License

The source code is released under:

Apache License

If you think the Android project TuentiTV listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Pedro Vicente Gmez Snchez.
 */*from w  w  w. j  a va2s  .  co m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.pedrovgs.tuentitv.ui.fragment;

import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v17.leanback.app.BackgroundManager;
import android.support.v17.leanback.widget.Action;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.ClassPresenterSelector;
import android.support.v17.leanback.widget.DetailsOverviewRow;
import android.support.v17.leanback.widget.DetailsOverviewRowPresenter;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.util.DisplayMetrics;
import com.github.pedrovgs.tuentitv.R;
import com.github.pedrovgs.tuentitv.presenter.DetailPresenter;
import com.github.pedrovgs.tuentitv.ui.data.CardInfo;
import com.github.pedrovgs.tuentitv.ui.picasso.PicassoBackgroundManagerTarget;
import com.github.pedrovgs.tuentitv.ui.util.Util;
import com.github.pedrovgs.tuentitv.ui.viewpresenter.DetailsDescriptionPresenter;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import javax.inject.Inject;

/**
 * DetailBaseFragment extension created to show detailed information of Contacts or
 * ConversationSummary given an identifier passed as extra to the container activity.
 *
 * @author Pedro Vicente Gmez Snchez.
 */
public class DetailFragment extends DetailBaseFragment implements DetailPresenter.View {

  public static final String ID_EXTRA = "id_extra";

  private static final long VD_CALL_ACTION_ID = 1;
  private static final long CALL_ACTION_ID = 2;
  private static final long CHAT_ACTION_ID = 3;
  private static final long EDIT_ACTION_ID = 4;
  private static final int DETAIL_THUMB_WIDTH = 274;
  private static final int DETAIL_THUMB_HEIGHT = 274;

  @Inject DetailPresenter presenter;

  private PicassoBackgroundManagerTarget backgroundTarget;
  private DisplayMetrics metrics;
  private ArrayObjectAdapter adapter;

  @Override public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    configureBackground();
    configureDetailPresenter();
  }

  @Override public void showBackground(String backgroundUrl) {
    Picasso.with(getActivity())
        .load(backgroundUrl)
        .resize(metrics.widthPixels, metrics.heightPixels)
        .error(R.drawable.fragment_default_background)
        .centerCrop()
        .into(backgroundTarget);
  }

  @Override public void showCardInfo(final CardInfo cardInfo) {
    new AsyncTask<Void, Void, Bitmap>() {

      @Override protected Bitmap doInBackground(Void... params) {
        Bitmap detailImage = null;
        try {
          detailImage = Picasso.with(getActivity())
              .load(cardInfo.getCardImageUrl())
              .placeholder(R.drawable.icn_wink)
              .error(R.drawable.icn_wink)
              .resize(Util.convertDpToPixel(getActivity(), DETAIL_THUMB_WIDTH),
                  Util.convertDpToPixel(getActivity(), DETAIL_THUMB_HEIGHT))
              .centerCrop()
              .get();
        } catch (IOException e) {
          //Empty
        }
        return detailImage;
      }

      @Override protected void onPostExecute(Bitmap bitmap) {
        DetailsOverviewRow detailRow = configureDetailsOverviewRow(cardInfo, bitmap);
        ClassPresenterSelector presenterSelector = new ClassPresenterSelector();
        DetailsOverviewRowPresenter dorPresenter =
            new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
        dorPresenter.setBackgroundColor(getResources().getColor(R.color.primary_color));
        dorPresenter.setStyleLarge(false);
        presenterSelector.addClassPresenter(DetailsOverviewRow.class, dorPresenter);
        presenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter());
        adapter = new ArrayObjectAdapter(presenterSelector);
        adapter.add(detailRow);
        setAdapter(adapter);
      }
    }.execute();
  }

  private DetailsOverviewRow configureDetailsOverviewRow(CardInfo cardInfo, Bitmap bitmap) {
    final DetailsOverviewRow row = new DetailsOverviewRow(cardInfo);
    row.setImageBitmap(getActivity(), bitmap);
    row.addAction(new Action(VD_CALL_ACTION_ID, getString(R.string.vd_call_action_title)));
    row.addAction(new Action(CALL_ACTION_ID, getString(R.string.call_action_title)));
    row.addAction(new Action(CHAT_ACTION_ID, getString(R.string.chat_action_title)));
    row.addAction(new Action(EDIT_ACTION_ID, getString(R.string.edit_action_title)));
    return row;
  }

  private void configureBackground() {
    metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    BackgroundManager backgroundManager = BackgroundManager.getInstance(getActivity());
    backgroundManager.attach(getActivity().getWindow());
    backgroundTarget = new PicassoBackgroundManagerTarget(backgroundManager);
  }

  private void configureDetailPresenter() {
    presenter.setView(this);
    String contentId = getContentId();
    presenter.loadContent(contentId);
  }

  private String getContentId() {
    return getActivity().getIntent().getExtras().getString(ID_EXTRA);
  }
}




Java Source Code List

com.github.pedrovgs.tuentitv.TuentiTvApplication.java
com.github.pedrovgs.tuentitv.di.ActivityContext.java
com.github.pedrovgs.tuentitv.di.ActivityModule.java
com.github.pedrovgs.tuentitv.di.ApplicationContext.java
com.github.pedrovgs.tuentitv.di.RootModule.java
com.github.pedrovgs.tuentitv.di.TuentiTvApplicationModule.java
com.github.pedrovgs.tuentitv.model.Account.java
com.github.pedrovgs.tuentitv.model.Accounts.java
com.github.pedrovgs.tuentitv.model.Agenda.java
com.github.pedrovgs.tuentitv.model.Chat.java
com.github.pedrovgs.tuentitv.model.Contact.java
com.github.pedrovgs.tuentitv.model.ConversationSummary.java
com.github.pedrovgs.tuentitv.model.MediaElement.java
com.github.pedrovgs.tuentitv.model.MediaGallery.java
com.github.pedrovgs.tuentitv.presenter.DetailPresenter.java
com.github.pedrovgs.tuentitv.presenter.EnterPasswordPresenter.java
com.github.pedrovgs.tuentitv.presenter.LoginPresenter.java
com.github.pedrovgs.tuentitv.presenter.MainPresenter.java
com.github.pedrovgs.tuentitv.presenter.SearchPresenter.java
com.github.pedrovgs.tuentitv.recommendation.builder.RecommendationBuilder.java
com.github.pedrovgs.tuentitv.recommendation.service.BaseIntentService.java
com.github.pedrovgs.tuentitv.recommendation.service.RecommendationService.java
com.github.pedrovgs.tuentitv.ui.activity.BaseActivity.java
com.github.pedrovgs.tuentitv.ui.activity.DetailActivity.java
com.github.pedrovgs.tuentitv.ui.activity.EnterPasswordActivity.java
com.github.pedrovgs.tuentitv.ui.activity.LoadingActivity.java
com.github.pedrovgs.tuentitv.ui.activity.LoginActivity.java
com.github.pedrovgs.tuentitv.ui.activity.MainActivity.java
com.github.pedrovgs.tuentitv.ui.activity.SearchActivity.java
com.github.pedrovgs.tuentitv.ui.activity.ShowImageActivity.java
com.github.pedrovgs.tuentitv.ui.data.CardInfo.java
com.github.pedrovgs.tuentitv.ui.data.IconInfo.java
com.github.pedrovgs.tuentitv.ui.data.ImageInfo.java
com.github.pedrovgs.tuentitv.ui.fragment.BrowseBaseFragment.java
com.github.pedrovgs.tuentitv.ui.fragment.DetailBaseFragment.java
com.github.pedrovgs.tuentitv.ui.fragment.DetailFragment.java
com.github.pedrovgs.tuentitv.ui.fragment.MainFragment.java
com.github.pedrovgs.tuentitv.ui.fragment.SearchBaseFragment.java
com.github.pedrovgs.tuentitv.ui.fragment.SearchFragment.java
com.github.pedrovgs.tuentitv.ui.navigator.Navigator.java
com.github.pedrovgs.tuentitv.ui.picasso.PicassoBackgroundManagerTarget.java
com.github.pedrovgs.tuentitv.ui.picasso.PicassoImageCardViewTarget.java
com.github.pedrovgs.tuentitv.ui.picasso.transformation.BlurTransformation.java
com.github.pedrovgs.tuentitv.ui.picasso.transformation.CircleTransform.java
com.github.pedrovgs.tuentitv.ui.picasso.transformation.GrayScaleTransformation.java
com.github.pedrovgs.tuentitv.ui.util.Util.java
com.github.pedrovgs.tuentitv.ui.viewpresenter.CardPresenter.java
com.github.pedrovgs.tuentitv.ui.viewpresenter.DetailsDescriptionPresenter.java
com.github.pedrovgs.tuentitv.ui.viewpresenter.IconPresenter.java
com.github.pedrovgs.tuentitv.ui.viewpresenter.ImagePresenter.java