Android Open Source - EffectiveAndroidUI Tv Show Activity






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.
 */*www .  ja  v  a  2  s  . c  om*/
 * 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.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.github.pedrovgs.effectiveandroidui.R;
import com.github.pedrovgs.effectiveandroidui.ui.fragment.TvShowFragment;
import com.github.pedrovgs.effectiveandroidui.ui.presenter.TvShowUIModule;
import com.github.pedrovgs.effectiveandroidui.util.StringUtils;
import java.util.LinkedList;
import java.util.List;

/**
 * Activity created to show a TvShow using TvShowFragment. This activity is going to be launched
 * only in Android 2.X versions.
 *
 * This activity has to be launched using a tv show id as extra or will throw an exception.
 *
 * This Activity will implement two good practices:
 *
 * - Implement a method to create the intent needed to start this activity.
 * - This activity will be thrown from Navigator class used in TvShowCatalogPresenter instead of
 * start the activity from other activity.
 *
 * @author Pedro Vicente Gmez Snchez
 */
public class TvShowActivity extends BaseActivity {

  private static final String EXTRA_TV_SHOW_ID = "extra_tv_show_id";

  private String tvShowId;

  /**
   * Generates the intent neede by the client code to launch this activity. This method is a sample
   * of who to avoid duplicate this code by all the application.
   */
  public static Intent getLaunchIntent(final Context context, final String tvShowId) {
    if (StringUtils.isNullOrEmpty(tvShowId)) {
      throwIllegalArgumentException();
    }
    Intent intent = new Intent(context, TvShowActivity.class);
    return intent.putExtra(EXTRA_TV_SHOW_ID, tvShowId);
  }

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tv_show);
    mapExtras();
    initializeFragment();
  }

  @Override protected List<Object> getModules() {
    List<Object> modules = new LinkedList<Object>();
    modules.add(new TvShowUIModule());
    return modules;
  }

  /**
   * As TvShowId is mandatory if there is no an extra inside the bundle that launches this activity
   * we are going to throw a new IllegalArgumentException.
   */
  private void mapExtras() {
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
      throwIllegalArgumentException();
    }
    tvShowId = extras.getString(EXTRA_TV_SHOW_ID);
    if (StringUtils.isNullOrEmpty(tvShowId)) {
      throwIllegalArgumentException();
    }
  }

  /**
   * Propagates the tv show identifier to the fragment.
   */
  private void initializeFragment() {
    TvShowFragment tvShowFragment =
        (TvShowFragment) getSupportFragmentManager().findFragmentById(R.id.f_tv_show);
    tvShowFragment.showTvShow(tvShowId);
  }

  private static void throwIllegalArgumentException() {
    throw new IllegalArgumentException(
        "TvShowActivity has to be launched using a TvShow identifier as extra");
  }
}




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