Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement swiping between tabs #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/res/layout-large-land/activity_choose_photos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
android:orientation="horizontal" >

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frag_primary"
android:layout_width="0px"
android:layout_height="fill_parent"
Expand Down
11 changes: 9 additions & 2 deletions client/res/layout/activity_choose_photos.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vp_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>

<!-- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frag_primary"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

</FrameLayout>
</FrameLayout> -->
20 changes: 18 additions & 2 deletions client/src/uk/co/senab/photup/PhotoSelectionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*******************************************************************************/
package uk.co.senab.photup;

import uk.co.senab.photup.adapters.FragmentsViewPagerAdapter;
import uk.co.senab.photup.events.PhotoSelectionAddedEvent;
import uk.co.senab.photup.events.PhotoSelectionRemovedEvent;
import uk.co.senab.photup.events.UploadsModifiedEvent;
Expand All @@ -29,6 +30,7 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
Expand All @@ -49,6 +51,8 @@ public class PhotoSelectionActivity extends AbstractPhotoUploadActivity implemen

private UploadActionBarView mUploadActionView;
private UploadsActionBarView mUploadsActionView;

private ViewPager mViewPager;

private boolean mSinglePane;

Expand Down Expand Up @@ -79,6 +83,15 @@ public void onCreate(Bundle savedInstanceState) {
ab.addTab(ab.newTab().setText(R.string.tab_photos).setTag(TAB_PHOTOS).setTabListener(this));

if (mSinglePane) {
mViewPager = (ViewPager) findViewById(R.id.vp_fragments);
FragmentsViewPagerAdapter viewPagerAdapter = new FragmentsViewPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(viewPagerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
@Override
public void onPageSelected(int position) {
getSupportActionBar().setSelectedNavigationItem(position);
}
});
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ab.addTab(ab.newTab().setTag(TAB_SELECTED).setTabListener(this));
ab.addTab(ab.newTab().setText(R.string.tab_uploads).setTag(TAB_UPLOADS).setTabListener(this));
Expand Down Expand Up @@ -207,8 +220,11 @@ public void onTabReselected(Tab tab, FragmentTransaction ft) {
}

public void onTabSelected(Tab tab, FragmentTransaction ft) {
final int id = (Integer) tab.getTag();
replacePrimaryFragment(id, ft);
if (mViewPager != null) {
// When the tab is selected, switch to the
// corresponding page in the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}

// Refresh Action Bar so correct Menu is displayed
supportInvalidateOptionsMenu();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright 2013 Chris Banes.
*
* 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 uk.co.senab.photup.adapters;

import uk.co.senab.photup.fragments.SelectedPhotosFragment;
import uk.co.senab.photup.fragments.UploadsFragment;
import uk.co.senab.photup.fragments.UserPhotosFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class FragmentsViewPagerAdapter extends FragmentPagerAdapter {

public FragmentsViewPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}

@Override
public Fragment getItem(int position) {
Fragment fragment;
switch (position) {
case 0:
fragment = new UserPhotosFragment();
return fragment;
case 1:
fragment = new SelectedPhotosFragment();
return fragment;
case 2:
fragment = new UploadsFragment();
return fragment;
default:
return null;
}
}

@Override
public int getCount() {
return 3;
}

}