Android Open Source - EffectiveAndroidUI Tv Show Draggable Fragment






From Project

Back to project page EffectiveAndroidUI.

License

The source code is released under:

Apache License

If you think the Android project EffectiveAndroidUI 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   www . java  2  s  . c  o  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.effectiveandroidui.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import butterknife.InjectView;
import com.github.pedrovgs.DraggableListener;
import com.github.pedrovgs.DraggableView;
import com.github.pedrovgs.effectiveandroidui.R;
import com.github.pedrovgs.effectiveandroidui.domain.tvshow.ChapterCollection;
import com.github.pedrovgs.effectiveandroidui.domain.tvshow.TvShow;
import com.github.pedrovgs.effectiveandroidui.ui.presenter.TvShowPresenter;
import com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterAdapteeCollection;
import com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterRendererAdapter;
import com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterRendererAdapterFactory;
import com.github.pedrovgs.effectiveandroidui.util.ToastUtils;
import com.squareup.picasso.Picasso;
import javax.inject.Inject;

/**
 * Fragment created to show a TvShows using DraggablePanel library.
 *
 * This Fragment uses a Model View Presenter implementation to implement all the presentation
 * logic. Review TvShowPresenter to get more info about the implementation.
 *
 * @author Pedro Vicente Gmez Snchez
 */
public class TvShowDraggableFragment extends BaseFragment implements TvShowPresenter.View {

  private static final String EXTRA_TV_SHOW = "extra_tv_show";

  @Inject TvShowPresenter tvShowPresenter;
  @Inject ChapterRendererAdapterFactory chapterRendererAdapterFactory;

  private ChapterRendererAdapter adapter;
  private ChapterAdapteeCollection chapterAdapteeCollection = new ChapterAdapteeCollection();

  private boolean useSaveInstanceState = true;

  @InjectView(R.id.draggable_view) DraggableView draggable_view;
  @InjectView(R.id.iv_fan_art) ImageView iv_fan_art;
  @InjectView(R.id.lv_chapters) ListView lv_chapters;
  @InjectView(R.id.pb_loading) ProgressBar pb_loading;

  private TextView header_tv_show_chapters;

  @Override public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    tvShowPresenter.setView(this);
    initializeDraggableView();
    initializeListView();
  }

  public void disableSaveInstanceState() {
    useSaveInstanceState = false;
  }

  private void initializeListView() {
    header_tv_show_chapters = (TextView) LayoutInflater.from(getActivity())
        .inflate(R.layout.header_tv_show_chapters, null);
    lv_chapters.addHeaderView(header_tv_show_chapters);
    adapter = (ChapterRendererAdapter) chapterRendererAdapterFactory.getChapterRendererAdapter(
        chapterAdapteeCollection);
    lv_chapters.setAdapter(adapter);
  }

  public void showTvShow(final String tvShowId) {
    if (isAdded()) {
      tvShowPresenter.loadTvShow(tvShowId);
    }
  }

  @Override public void showLoading() {
    pb_loading.setVisibility(View.VISIBLE);
  }

  @Override public void showFanArt(final String tvShowFanArtUrl) {
    iv_fan_art.setVisibility(View.VISIBLE);
    Picasso.with(getActivity())
        .load(tvShowFanArtUrl)
        .placeholder(R.color.main_color)
        .into(iv_fan_art);
  }

  @Override public void showTvShowTitle(final String tvShowTitle) {
    String tvShowHeaderTitle = getString(R.string.tv_show_title, tvShowTitle);
    header_tv_show_chapters.setText(tvShowHeaderTitle);
  }

  @Override public boolean isReady() {
    return isAdded();
  }

  @Override public boolean isAlreadyLoaded() {
    return adapter.getCount() > 0;
  }

  @Override public void showChapters(ChapterCollection chapters) {
    chapterAdapteeCollection.clear();
    chapterAdapteeCollection.addAll(chapters.getChapters());
    adapter.notifyDataSetChanged();
  }

  @Override public void hideLoading() {
    pb_loading.setVisibility(View.GONE);
  }

  @Override public void showTvShowNotFoundMessage() {
    String tvShowNotFoundMessage = getString(R.string.tv_show_not_found);
    ToastUtils.showShortMessage(tvShowNotFoundMessage, getActivity());
  }

  @Override public void showConnectionErrorMessage() {
    String connectionErrorMessage = getString(R.string.connection_error_message);
    ToastUtils.showError(connectionErrorMessage, getActivity());
  }

  @Override public void showTvShow() {
    draggable_view.setVisibility(View.VISIBLE);
    draggable_view.maximize();
  }

  @Override public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (useSaveInstanceState) {
      outState.putSerializable(EXTRA_TV_SHOW, tvShowPresenter.getCurrentTvShow());
    }
  }

  @Override public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    if (savedInstanceState != null) {
      final TvShow tvShow = (TvShow) savedInstanceState.getSerializable(EXTRA_TV_SHOW);
      updatePresenterWithSavedTvShow(tvShow);
    }
  }

  private void updatePresenterWithSavedTvShow(final TvShow tvShow) {
    if (tvShow != null) {
      draggable_view.post(new Runnable() {
        @Override public void run() {
          tvShowPresenter.loadTvShow(tvShow);
        }
      });
    }
  }

  @Override protected int getFragmentLayout() {
    return R.layout.fragment_draggable_tv_show;
  }

  private void initializeDraggableView() {
    draggable_view.post(new Runnable() {
      @Override
      public void run() {
        draggable_view.closeToRight();
      }
    });
    draggable_view.setDraggableListener(new DraggableListener() {
      @Override public void onMaximized() {
        //Empty
      }

      @Override public void onMinimized() {
        //Empty
      }

      @Override public void onClosedToLeft() {
        tvShowPresenter.tvShowClosed();
      }

      @Override public void onClosedToRight() {
        tvShowPresenter.tvShowClosed();
      }
    });
  }
}




Java Source Code List

com.github.pedrovgs.effectiveandroidui.TvShowsApplication.java
com.github.pedrovgs.effectiveandroidui.di.ActivityContext.java
com.github.pedrovgs.effectiveandroidui.di.ActivityModule.java
com.github.pedrovgs.effectiveandroidui.di.RootModule.java
com.github.pedrovgs.effectiveandroidui.domain.GetTvShowByIdInteractor.java
com.github.pedrovgs.effectiveandroidui.domain.GetTvShowById.java
com.github.pedrovgs.effectiveandroidui.domain.GetTvShowsInteractor.java
com.github.pedrovgs.effectiveandroidui.domain.GetTvShows.java
com.github.pedrovgs.effectiveandroidui.domain.TvShowsModule.java
com.github.pedrovgs.effectiveandroidui.domain.exception.TvShowNotFoundException.java
com.github.pedrovgs.effectiveandroidui.domain.tvshow.Catalog.java
com.github.pedrovgs.effectiveandroidui.domain.tvshow.ChapterCollection.java
com.github.pedrovgs.effectiveandroidui.domain.tvshow.Chapter.java
com.github.pedrovgs.effectiveandroidui.domain.tvshow.TvShow.java
com.github.pedrovgs.effectiveandroidui.executor.ExecutorModule.java
com.github.pedrovgs.effectiveandroidui.executor.Executor.java
com.github.pedrovgs.effectiveandroidui.executor.Interactor.java
com.github.pedrovgs.effectiveandroidui.executor.MainThreadImpl.java
com.github.pedrovgs.effectiveandroidui.executor.MainThread.java
com.github.pedrovgs.effectiveandroidui.executor.ThreadExecutor.java
com.github.pedrovgs.effectiveandroidui.ui.activity.BaseActivity.java
com.github.pedrovgs.effectiveandroidui.ui.activity.MainActivity.java
com.github.pedrovgs.effectiveandroidui.ui.activity.Navigator.java
com.github.pedrovgs.effectiveandroidui.ui.activity.TvShowActivity.java
com.github.pedrovgs.effectiveandroidui.ui.fragment.BaseFragment.java
com.github.pedrovgs.effectiveandroidui.ui.fragment.TvShowCatalogFragment.java
com.github.pedrovgs.effectiveandroidui.ui.fragment.TvShowDraggableFragment.java
com.github.pedrovgs.effectiveandroidui.ui.fragment.TvShowFragment.java
com.github.pedrovgs.effectiveandroidui.ui.presenter.Presenter.java
com.github.pedrovgs.effectiveandroidui.ui.presenter.TvShowCatalogPresenter.java
com.github.pedrovgs.effectiveandroidui.ui.presenter.TvShowPresenter.java
com.github.pedrovgs.effectiveandroidui.ui.presenter.TvShowUIModule.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterAdapteeCollection.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterRendererAdapterFactory.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterRendererAdapter.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterRendererBuilder.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapter.ChapterRenderer.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapterviewmodel.ChapterViewModelCollection.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapterviewmodel.ChapterViewModelRendererAdapterFactory.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapterviewmodel.ChapterViewModelRendererAdapter.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapterviewmodel.ChapterViewModelRendererBuilder.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.chapterviewmodel.ChapterViewModelRenderer.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.tvshow.TvShowCollection.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.tvshow.TvShowRendererAdapterFactory.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.tvshow.TvShowRendererBuilder.java
com.github.pedrovgs.effectiveandroidui.ui.renderer.tvshow.TvShowRenderer.java
com.github.pedrovgs.effectiveandroidui.ui.viewmodel.ChapterViewModel.java
com.github.pedrovgs.effectiveandroidui.ui.viewmodel.TvShowViewModel.java
com.github.pedrovgs.effectiveandroidui.ui.viewmodel.action.ActionCommand.java
com.github.pedrovgs.effectiveandroidui.ui.viewmodel.action.ShowTvShowOnBrowserActionCommand.java
com.github.pedrovgs.effectiveandroidui.util.RandomUtils.java
com.github.pedrovgs.effectiveandroidui.util.StringUtils.java
com.github.pedrovgs.effectiveandroidui.util.TimeMachine.java
com.github.pedrovgs.effectiveandroidui.util.ToastUtils.java