コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top_apps);
    toolbar = (Toolbar) findViewById(R.id.toolbarList);
    setSupportActionBar(toolbar);

    // Get a reference to the AppsListFragment
    appsListFragment =
        (AppsListFragment) getFragmentManager().findFragmentById(R.id.apps_list_fragment);

    // Get a reference to the appsDetailFragment
    appsDetailFragment =
        (AppsDetailFragment)
            getSupportFragmentManager().findFragmentById(R.id.apps_detail_fragment);

    preferences =
        this.getSharedPreferences(PreferencesManager.PREFERENCES_FILE, Context.MODE_PRIVATE);
    mngrPreferences = new PreferencesManager(preferences);

    // ToolBar Config
    toolbar.setLogo(R.mipmap.ic_launcher);
    toolbar.setTitle("iTunes - Top Apps");
    toolbar.setSubtitle("Last Update: " + mngrPreferences.getRssUpdate().substring(0, 10));

    if (appsDetailFragment != null) {

      if (appsDetailFragment.getLastSelectedIndex() != -1) {

        appsDetailFragment.showAppDetail(appsDetailFragment.getLastSelectedIndex());

      } else {

        appsDetailFragment.showAppDetail(0);
      }
    }
  }
コード例 #2
0
  @Override
  public void onListSelection(int index) {

    // Detect device (smartphone or tablet) according to the layout config
    boolean existAppDetail = (appsDetailFragment != null);

    // Log.i(TAG, "Hay Detalle = " + existAppDetail);

    if (existAppDetail && index != appsDetailFragment.getLastSelectedIndex()) {

      appsDetailFragment.showAppDetail(index);

    } else {

      Intent detailIntent = new Intent(this, AppsDetailActivity.class);
      detailIntent.putExtra(AppsDetailActivity.ID_ITUNES_ENTRY, index);
      startActivity(detailIntent);
      overridePendingTransition(R.anim.left_in, R.anim.left_out);
    }
  }