Skip to content

Commit 067d83c

Browse files
committed
Moving carousel into a fragment. Therefore making this a fragment which manages other fragments.
1 parent ddf8822 commit 067d83c

File tree

9 files changed

+114
-53
lines changed

9 files changed

+114
-53
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
android:debuggable="true">
2424

2525
<activity
26-
android:name=".ui.CarouselActivity"
26+
android:name=".ui.HomeActivity"
2727
android:configChanges="orientation|keyboardHidden|screenSize"
2828
android:label="@string/app_name">
2929
<intent-filter>

app/src/main/java/com/donnfelker/android/bootstrap/BootstrapModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.donnfelker.android.bootstrap.authenticator.LogoutService;
88
import com.donnfelker.android.bootstrap.core.TimerService;
99
import com.donnfelker.android.bootstrap.ui.BootstrapTimerActivity;
10-
import com.donnfelker.android.bootstrap.ui.CarouselActivity;
10+
import com.donnfelker.android.bootstrap.ui.HomeActivity;
1111
import com.donnfelker.android.bootstrap.ui.CheckInsListFragment;
1212
import com.donnfelker.android.bootstrap.ui.NewsActivity;
1313
import com.donnfelker.android.bootstrap.ui.NewsListFragment;
@@ -30,7 +30,7 @@
3030
injects = {
3131
BootstrapApplication.class,
3232
BootstrapAuthenticatorActivity.class,
33-
CarouselActivity.class,
33+
HomeActivity.class,
3434
BootstrapTimerActivity.class,
3535
CheckInsListFragment.class,
3636
NewsActivity.class,

app/src/main/java/com/donnfelker/android/bootstrap/authenticator/ApiKeyProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ public class ApiKeyProvider {
2525

2626
/**
2727
* This call blocks, so shouldn't be called on the UI thread.
28+
* This call is what makes the login screen pop up. If the user has
29+
* not logged in there will no accounts in the {@link android.accounts.AccountManager}
30+
* and therefore the Activity that is referenced in the
31+
* {@link com.donnfelker.android.bootstrap.authenticator.BootstrapAccountAuthenticator} will get started.
32+
* If you want to remove the authentication then you can comment out the code below and return a string such as
33+
* "foo" and the authentication process will not be kicked off. Alternatively, you can remove this class
34+
* completely and clean up any referecnes to the authenticator.
35+
*
36+
* @see com.donnfelker.android.bootstrap.authenticator.BootstrapAccountAuthenticator
37+
* @see com.donnfelker.android.bootstrap.authenticator.BootstrapAuthenticatorActivity
38+
* @see com.donnfelker.android.bootstrap.authenticator.AccountAuthenticatorService
39+
* @see com.donnfelker.android.bootstrap.authenticator.ApiKeyProvider
2840
*
2941
* @return API key to be used for authorization with a
3042
* {@link com.donnfelker.android.bootstrap.core.BootstrapService} instance

app/src/main/java/com/donnfelker/android/bootstrap/ui/BootstrapActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
3939
case android.R.id.home:
4040
// Don't call finish! Because activity could have been started by an
4141
// outside activity and the home button would not operated as expected!
42-
final Intent homeIntent = new Intent(this, CarouselActivity.class);
42+
final Intent homeIntent = new Intent(this, HomeActivity.class);
4343
homeIntent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
4444
startActivity(homeIntent);
4545
return true;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.donnfelker.android.bootstrap.ui;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.Fragment;
5+
import android.support.v4.view.ViewPager;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import com.donnfelker.android.bootstrap.R;
11+
import com.viewpagerindicator.TitlePageIndicator;
12+
13+
import butterknife.InjectView;
14+
import butterknife.Views;
15+
16+
/**
17+
* Fragment which houses the View pager.
18+
*/
19+
public class CarouselFragment extends Fragment {
20+
21+
@InjectView(R.id.tpi_header)
22+
protected TitlePageIndicator indicator;
23+
24+
@InjectView(R.id.vp_pages)
25+
protected ViewPager pager;
26+
27+
@Override
28+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
29+
return inflater.inflate(R.layout.fragment_carousel, container, false);
30+
}
31+
32+
@Override
33+
public void onActivityCreated(Bundle savedInstanceState) {
34+
super.onActivityCreated(savedInstanceState);
35+
36+
Views.inject(this, getView());
37+
38+
pager.setAdapter(new BootstrapPagerAdapter(getResources(), getChildFragmentManager()));
39+
indicator.setViewPager(pager);
40+
pager.setCurrentItem(1);
41+
42+
}
43+
}

app/src/main/java/com/donnfelker/android/bootstrap/ui/CarouselActivity.java renamed to app/src/main/java/com/donnfelker/android/bootstrap/ui/HomeActivity.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import android.content.res.Configuration;
88
import android.os.Bundle;
99
import android.support.v4.app.ActionBarDrawerToggle;
10-
import android.support.v4.view.ViewPager;
10+
import android.support.v4.app.FragmentManager;
1111
import android.support.v4.widget.DrawerLayout;
1212
import android.view.MenuItem;
1313
import android.view.View;
@@ -16,22 +16,21 @@
1616
import com.donnfelker.android.bootstrap.BootstrapServiceProvider;
1717
import com.donnfelker.android.bootstrap.R;
1818
import com.donnfelker.android.bootstrap.core.BootstrapService;
19+
import com.donnfelker.android.bootstrap.util.Ln;
1920
import com.donnfelker.android.bootstrap.util.SafeAsyncTask;
20-
import com.viewpagerindicator.TitlePageIndicator;
2121

2222
import javax.inject.Inject;
2323

24-
import butterknife.InjectView;
2524
import butterknife.Views;
2625

2726

2827
/**
29-
* Activity to view the carousel and view pager indicator with fragments.
28+
* Initial activity for the application.
29+
*
30+
* If you need to remove the authentication from the application please see
31+
* {@link com.donnfelker.android.bootstrap.authenticator.ApiKeyProvider#getAuthKey(android.app.Activity)}
3032
*/
31-
public class CarouselActivity extends BootstrapFragmentActivity {
32-
33-
@InjectView(R.id.tpi_header) protected TitlePageIndicator indicator;
34-
@InjectView(R.id.vp_pages) protected ViewPager pager;
33+
public class HomeActivity extends BootstrapFragmentActivity {
3534

3635
@Inject protected BootstrapServiceProvider serviceProvider;
3736

@@ -49,7 +48,7 @@ protected void onCreate(final Bundle savedInstanceState) {
4948

5049
super.onCreate(savedInstanceState);
5150

52-
setContentView(R.layout.carousel_view);
51+
setContentView(R.layout.home_activity);
5352

5453
// View injection with Butterknife
5554
Views.inject(this);
@@ -103,11 +102,12 @@ public void onConfigurationChanged(final Configuration newConfig) {
103102

104103
private void initScreen() {
105104
if (userHasAuthenticated) {
106-
pager.setAdapter(new BootstrapPagerAdapter(getResources(),
107-
getSupportFragmentManager()));
108105

109-
indicator.setViewPager(pager);
110-
pager.setCurrentItem(1);
106+
Ln.d("Foo");
107+
final FragmentManager fragmentManager = getSupportFragmentManager();
108+
fragmentManager.beginTransaction()
109+
.replace(R.id.container, new CarouselFragment())
110+
.commit();
111111
}
112112

113113
setNavListeners();
@@ -118,7 +118,7 @@ private void checkAuth() {
118118

119119
@Override
120120
public Boolean call() throws Exception {
121-
final BootstrapService svc = serviceProvider.getService(CarouselActivity.this);
121+
final BootstrapService svc = serviceProvider.getService(HomeActivity.this);
122122
return svc != null;
123123
}
124124

app/src/main/res/layout/carousel_view.xml

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:orientation="vertical"
5+
android:layout_width="match_parent"
6+
android:background="@color/pager_background"
7+
android:layout_height="match_parent">
8+
9+
<com.viewpagerindicator.TitlePageIndicator
10+
android:id="@+id/tpi_header"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
textColor="@color/text_light"
14+
android:background="@drawable/stripe_repeat"
15+
/>
16+
17+
<android.support.v4.view.ViewPager
18+
android:id="@+id/vp_pages"
19+
android:layout_width="match_parent"
20+
android:layout_height="0dp"
21+
android:layout_weight="1" />
22+
23+
</LinearLayout>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<android.support.v4.widget.DrawerLayout
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:id="@+id/drawer_layout"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent">
8+
9+
<!-- The main content view -->
10+
<FrameLayout
11+
android:id="@+id/container"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent" />
14+
15+
<!-- The navigation drawer -->
16+
<include layout="@layout/navigation_drawer" />
17+
18+
</android.support.v4.widget.DrawerLayout>

0 commit comments

Comments
 (0)