Advertisement
dmfrey

Untitled

Nov 22nd, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.99 KB | None | 0 0
  1. package org.mythtv.android.presentation.view.activity;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.design.widget.TabLayout;
  7. import android.support.v4.app.Fragment;
  8. import android.support.v4.app.FragmentManager;
  9. import android.support.v4.app.FragmentStatePagerAdapter;
  10. import android.support.v4.view.ViewPager;
  11. import android.util.Log;
  12. import android.view.Window;
  13.  
  14. import org.mythtv.android.R;
  15. import org.mythtv.android.domain.ContentType;
  16. import org.mythtv.android.presentation.internal.di.HasComponent;
  17. import org.mythtv.android.presentation.internal.di.components.DaggerVideoComponent;
  18. import org.mythtv.android.presentation.internal.di.components.VideoComponent;
  19. import org.mythtv.android.presentation.internal.di.modules.VideosModule;
  20. import org.mythtv.android.presentation.view.fragment.VideoMetadataInfoListFragment;
  21.  
  22. import java.util.ArrayList;
  23. import java.util.List;
  24.  
  25. import butterknife.Bind;
  26.  
  27. /**
  28.  * Created by dmfrey on 11/13/15.
  29.  */
  30. public class VideoMetadataInfoListActivity extends BaseActivity implements HasComponent<VideoComponent> {
  31.  
  32.     private static final String TAG = VideoMetadataInfoListActivity.class.getSimpleName();
  33.  
  34.     public static Intent getCallingIntent( Context context ) {
  35.  
  36.         return new Intent( context, VideoMetadataInfoListActivity.class );
  37.     }
  38.  
  39.     private VideoComponent videoComponent;
  40.  
  41.     @Bind( R.id.tabs )
  42.     TabLayout mTabLayout;
  43.  
  44.     @Bind( R.id.pager )
  45.     ViewPager mPager;
  46.  
  47.     @Override
  48.     public int getLayoutResource() {
  49.  
  50.         return R.layout.activity_video_metadata_info_list;
  51.     }
  52.  
  53.     @Override
  54.     protected void onCreate( Bundle savedInstanceState ) {
  55.         Log.d( TAG, "onCreate : enter" );
  56.  
  57.         requestWindowFeature( Window.FEATURE_INDETERMINATE_PROGRESS );
  58.         super.onCreate( savedInstanceState );
  59.  
  60.         this.initializeInjector();
  61.  
  62.         setNavigationMenuItemChecked( 1 );
  63.  
  64.         mTabLayout.setTabMode( TabLayout.MODE_SCROLLABLE );
  65.         mPager.setAdapter( new VideosFragmentPagerAdapter( getSupportFragmentManager() ) );
  66.         mTabLayout.setupWithViewPager( mPager );
  67.         mPager.addOnPageChangeListener( new TabLayout.TabLayoutOnPageChangeListener( mTabLayout ) );
  68.  
  69.         Log.d( TAG, "onCreate : exit" );
  70.     }
  71.  
  72.     @Override
  73.     public void onBackPressed() {
  74.  
  75.         if( mPager.getCurrentItem() == 0 ) {
  76.  
  77.             // If the user is currently looking at the first step, allow the system to handle the
  78.             // Back button. This calls finish() on this activity and pops the back stack.
  79.             super.onBackPressed();
  80.  
  81.         } else {
  82.  
  83.             // Otherwise, select the previous step.
  84.             mPager.setCurrentItem( mPager.getCurrentItem() - 1 );
  85.  
  86.         }
  87.  
  88.     }
  89.  
  90.     private void initializeInjector() {
  91.         Log.d(TAG, "initializeInjector : enter");
  92.  
  93.         this.videoComponent = DaggerVideoComponent.builder()
  94.                 .applicationComponent( getApplicationComponent() )
  95.                 .activityModule( getActivityModule() )
  96.                 .build();
  97.  
  98.         Log.d( TAG, "initializeInjector : exit" );
  99.     }
  100.  
  101.     @Override
  102.     public VideoComponent getComponent() {
  103.         Log.d( TAG, "getComponent : enter" );
  104.  
  105.         Log.d( TAG, "getComponent : exit" );
  106.         return videoComponent;
  107.     }
  108.  
  109.     class VideosFragmentPagerAdapter extends FragmentStatePagerAdapter {
  110.  
  111.         String[] tabs;
  112.         List<Fragment> fragments = new ArrayList<>();
  113.  
  114.         boolean showAdultTab = false;
  115.  
  116.         public VideosFragmentPagerAdapter( FragmentManager fm ) {
  117.             super( fm );
  118.  
  119. //            showAdultTab = MainApplication.getInstance().showAdultTab();
  120.  
  121.             tabs = getResources().getStringArray( R.array.watch_videos_tabs );
  122.             fragments.add(VideoMetadataInfoListFragment.newInstance( ContentType.MOVIE ) );
  123. //            fragments.add( Fragment.instantiate( VideoMetadataInfoListActivity.this, TelevisionFragment.class.getName(), null ) );
  124. //            fragments.add( Fragment.instantiate( VideoMetadataInfoListActivity.this, HomeMoviesFragment.class.getName(), null ) );
  125. //            fragments.add( Fragment.instantiate( VideoMetadataInfoListActivity.this, MusicVideosFragment.class.getName(), null ) );
  126.  
  127.             if( showAdultTab ) {
  128.  
  129. //                fragments.add( Fragment.instantiate( VideoMetadataInfoListActivity.this, AdultFragment.class.getName(), null ) );
  130.  
  131.             }
  132.  
  133.             notifyDataSetChanged();
  134.         }
  135.  
  136.         @Override
  137.         public Fragment getItem( int position ) {
  138.             Log.v( TAG, "getItem : position=" + position );
  139.  
  140.             return fragments.get( position );
  141.         }
  142.  
  143.         @Override
  144.         public CharSequence getPageTitle( int position ) {
  145.  
  146.             return tabs[ position ];
  147.         }
  148.  
  149.         @Override
  150.         public int getCount() {
  151.  
  152.             if( showAdultTab ) {
  153.  
  154.                 return 5;
  155.             }
  156.  
  157.             return 1; //4;
  158.         }
  159.  
  160.     }
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement