Skip to content

Commit

Permalink
Merge pull request gdg-x#707 from gdg-x/fix/settings-crash
Browse files Browse the repository at this point in the history
Fix crash in settings
  • Loading branch information
tasomaniac committed Oct 30, 2016
2 parents 3750ffb + d91aeda commit 747a08a
Show file tree
Hide file tree
Showing 27 changed files with 169 additions and 259 deletions.
13 changes: 8 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@
android:theme="@style/Theme.GDG.Main" />
<activity
android:name=".gde.GdeActivity"
android:label="@string/gde"
android:theme="@style/Theme.GDG.WithNavDrawer" />
<activity
android:name=".about.AboutActivity"
android:label="@string/about"
android:theme="@style/Theme.GDG" />
<activity
android:name=".eventseries.TaggedEventSeriesActivity"
android:theme="@style/Theme.GDG.Special" />
<activity
android:name=".activity.SettingsActivity"
android:label="@string/settings"
android:theme="@style/Theme.GDG" />
<activity android:name=".onboarding.FirstStartActivity"
android:theme="@style/Theme.GDG.Onboarding"
/>
android:theme="@style/Theme.GDG"
android:parentActivityName=".chapter.MainActivity" />
<activity
android:name=".onboarding.FirstStartActivity"
android:theme="@style/Theme.GDG.Onboarding" />
<activity
android:name=".chapter.YoutubeActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
Expand Down Expand Up @@ -163,7 +166,7 @@
</activity>
<activity
android:name=".event.EventActivity"
android:parentActivityName=".chapter.MainActivity"
android:label="@string/event"
android:theme="@style/Theme.GDG" />

<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ public class AboutActivity extends GdgActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_about);

getActionBarToolbar().setTitle(R.string.about);
getActionBarToolbar().setNavigationIcon(R.drawable.ic_up);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

mViewPager.setAdapter(new AboutPagerAdapter(getSupportFragmentManager(), getResources()));
mTabLayout.setupWithViewPager(mViewPager);
Expand All @@ -61,15 +58,13 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {

if (android.R.id.home == item.getItemId()) {
finish();
return true;
} else if (R.id.action_app_invite == item.getItemId()) {
AppInviteLinkGenerator.shareAppInviteLink(this);
return true;
}

return super.onOptionsItemSelected(item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import org.gdg.frisbee.android.R;
import org.gdg.frisbee.android.api.model.Chapter;
import org.gdg.frisbee.android.appwidget.UpcomingEventWidgetProvider;
import org.gdg.frisbee.android.chapter.ChapterSelectDialog;
import org.gdg.frisbee.android.common.GdgActivity;
import org.gdg.frisbee.android.common.TrackableActivity;
import org.gdg.frisbee.android.fragment.SettingsFragment;
import org.gdg.frisbee.android.utils.PrefUtils;

public class SettingsActivity extends GdgActivity implements ChapterSelectDialog.Listener {
public class SettingsActivity extends TrackableActivity implements ChapterSelectDialog.Listener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);

getActionBarToolbar().setTitle(R.string.settings);
getActionBarToolbar().setNavigationIcon(R.drawable.ic_up);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
Expand All @@ -52,12 +53,10 @@ protected String getTrackedViewName() {

@Override
public boolean onOptionsItemSelected(MenuItem item) {

if (item.getItemId() == android.R.id.home) {
finish();
return true;
}

return super.onOptionsItemSelected(item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class MainActivity extends GdgNavDrawerActivity implements ChapterSelectD
ViewPager viewPager;
@BindView(R.id.tabs)
TabLayout tabLayout;
@BindView(R.id.toolbar_actionbar)
Toolbar toolbar;
private TextView chapterSwitcher;

private ChapterComparator locationComparator;
Expand Down Expand Up @@ -335,7 +337,7 @@ protected void onSaveInstanceState(Bundle outState) {
}

private void setupChapterSwitcher() {
Toolbar toolbar = getActionBarToolbar();
getSupportActionBar().setDisplayShowTitleEnabled(false);
View container = LayoutInflater.from(this).inflate(R.layout.actionbar_chapter_selector, toolbar);
chapterSwitcher = (TextView) container.findViewById(android.R.id.text1);
chapterSwitcher.setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public static class ViewHolder extends RecyclerView.ViewHolder {
ImageView pic3;
String url;

private ViewHolder(View itemView) {
ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
Expand Down
31 changes: 12 additions & 19 deletions app/src/main/java/org/gdg/frisbee/android/common/GdgActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.FrameLayout;
import android.widget.Toast;
Expand Down Expand Up @@ -58,24 +58,26 @@
import timber.log.Timber;

public abstract class GdgActivity extends TrackableActivity implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {

private static final int RC_SIGN_IN = 101;

@Nullable
@BindView(R.id.content_frame)
FrameLayout mContentLayout;
@Nullable
@BindView(R.id.toolbar_actionbar)
Toolbar toolbar;

private GoogleApiClient mGoogleApiClient;
private GoogleApiClient signInClient;

private Toolbar mActionBarToolbar;

@Override
public void setContentView(int layoutResId) {
super.setContentView(layoutResId);
ButterKnife.bind(this);
getActionBarToolbar();
setSupportActionBar(toolbar);
}

@Override
Expand Down Expand Up @@ -166,16 +168,11 @@ protected void onSuccessfulSignIn(GoogleSignInAccount signInAccount) {
PrefUtils.setSignedIn(this);
}

protected Toolbar getActionBarToolbar() {
if (mActionBarToolbar == null) {
mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
if (mActionBarToolbar != null) {
setSupportActionBar(mActionBarToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mActionBarToolbar.setNavigationIcon(new DrawerArrowDrawable(getSupportActionBar().getThemedContext()));
}
}
return mActionBarToolbar;
@NonNull
@Override
public ActionBar getSupportActionBar() {
//noinspection ConstantConditions
return super.getSupportActionBar();
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Expand Down Expand Up @@ -224,10 +221,6 @@ private void showFatalPlayServiceMessage(@NonNull ConnectionResult result) {
PrefUtils.setFatalPlayServiceMessageShown(this);
}

public void setToolbarTitle(final String title) {
getActionBarToolbar().setTitle(title);
}

protected void recordEndPageView(Action viewAction) {
PendingResult<Status> result = AppIndex.AppIndexApi.end(getGoogleApiClient(), viewAction);
result.setResultCallback(appIndexApiCallback("end " + viewAction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.gdg.frisbee.android.common;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
Expand All @@ -24,6 +25,7 @@
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -84,6 +86,10 @@ public abstract class GdgNavDrawerActivity extends GdgActivity {
@Override
public void setContentView(int layoutResId) {
super.setContentView(layoutResId);
if (toolbar != null) {
DrawerArrowDrawable drawerIcon = new DrawerArrowDrawable(getSupportActionBar().getThemedContext());
toolbar.setNavigationIcon(drawerIcon);
}
setupDrawerContent(mNavigationView);
}

Expand Down Expand Up @@ -227,7 +233,7 @@ private void displayFeedbackDialog() {
new FeedbackFragment().show(getSupportFragmentManager(), "FeedbackFragment");
}

private void navigateTo(Class<? extends GdgActivity> activityClass, @Nullable Bundle additional) {
private void navigateTo(Class<? extends Activity> activityClass, @Nullable Bundle additional) {
if (this.getClass().equals(activityClass)
&& !(this instanceof TaggedEventSeriesActivity)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class EventActivity extends GdgActivity implements EventOverviewFragment.

@BindView(R.id.pager)
ViewPager mViewPager;

@BindView(R.id.tabs)
TabLayout mTabLayout;

Expand All @@ -53,10 +52,8 @@ public class EventActivity extends GdgActivity implements EventOverviewFragment.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_event);
getActionBarToolbar().setTitle(R.string.event);
getActionBarToolbar().setNavigationIcon(R.drawable.ic_up);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

final EventPagerAdapter mViewPagerAdapter = new EventPagerAdapter(this, getSupportFragmentManager());
mViewPager.setAdapter(mViewPagerAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ShareActionProvider;
import android.text.Html;
import android.view.LayoutInflater;
Expand All @@ -46,7 +47,6 @@
import org.gdg.frisbee.android.app.App;
import org.gdg.frisbee.android.cache.ModelCache;
import org.gdg.frisbee.android.common.BaseFragment;
import org.gdg.frisbee.android.common.GdgActivity;
import org.gdg.frisbee.android.utils.Utils;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -209,10 +209,8 @@ private void updateGroupDetails(Chapter group) {
if (getActivity() == null) {
return;
}

loadChapterImage(group.getGplusId());

((GdgActivity) getActivity()).setToolbarTitle(group.getShortName());
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(group.getShortName());
}

private void loadChapterImage(String gplusId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;
Expand Down Expand Up @@ -63,9 +62,7 @@ public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_special);

Toolbar toolbar = getActionBarToolbar();

toolbar.setTitle(mTaggedEventSeries.getTitleResId());
getSupportActionBar().setTitle(mTaggedEventSeries.getTitleResId());
if (mDescription != null) {
mDescription.setText(mTaggedEventSeries.getDescriptionResId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import org.gdg.frisbee.android.R;
import org.gdg.frisbee.android.api.Callback;
Expand All @@ -26,7 +25,6 @@ public class GdeActivity extends GdgNavDrawerActivity implements ViewPager.OnPag

@BindView(R.id.pager)
ViewPager mViewPager;

@BindView(R.id.tabs)
TabLayout mTabLayout;

Expand All @@ -37,9 +35,6 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gde);

Toolbar toolbar = getActionBarToolbar();
toolbar.setTitle(R.string.gde);

App.from(this).getModelCache().getAsync(ModelCache.KEY_GDE_LIST, new ModelCache.CacheListener() {
@Override
public void onGet(Object item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
return;
}

mViewPagerAdapter.getItem(mViewPager.getCurrentItem()).onActivityResult(requestCode, resultCode, data);
}

Expand Down
Loading

0 comments on commit 747a08a

Please sign in to comment.