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

Add pull to refresh. Also add Butterknife. #18

Merged
merged 3 commits into from
Feb 3, 2017

Conversation

Gregliest
Copy link
Collaborator

@dektar

Adds pull to refresh to the MainActivity's RecyclerView. The spinner will show A) when the user enters the activity (in onResume) and B) when the user pulls to refresh. I removed the refresh button in the menu, let me know if you'd like me to add it back.

I also added Butterknife for convenience, so that we don't need to do a typecast + findbyId every time we want a view. I did some minor refactoring, splitting the api listener logic in onCreateView into a helper.

Copy link
Collaborator

@dektar dektar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This will be great.

Let's keep the Refresh button in the menu for accessibility - but you can hide it in overflow instead of showing the icon in the appbarlayout. Ref: https://developer.android.com/training/swipe/add-swipe-interface.html#AddRefreshAction.

} else if (!TextUtils.isEmpty(mZip)) {
AppSingleton.getInstance(getApplicationContext()).getJsonController()
.getIssuesForLocation(mZip);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a TODO for a "location error" else block, if we've got neither zip nor lat/long? It shouldn't happen but...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to just add it? What should we do in that case? Toast the user and log an error to the backend?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, ultimately I guess we'd want to redirect them to the Location screen to try to reset it, but a snackbar error sounds good for now.

(I prefer Snackbar to Toast as Snackbar meets accessibility standards.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok cool, sounds good

/**
* The activity which handles zip code lookup and showing the issues list.
*
* TODO: Add loading spinners when making Volley requests.
*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a TODO to use Butterknife across the app for consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! I can do that in the next PR.

@Gregliest
Copy link
Collaborator Author

@dektar Addressed your comments.

I also fixed a crash I encountered multiple times, when returning to the LocationActivity from a permissions request. When onBackPressed() was called, I was getting an IllegalStateException because onSaveInstanceState() had already been called. It's kind of awkward, since we're not doing FragmentTransaction, which is the normal reason this crash happens. Instead, AppCompatActivity inherits from FragmentActivity, which accesses the fragment manager in onBackPressed(), in case there's a fragment showing. So, the normal fixes don't work. I looked for an elegant solution for a while and couldn't find one, so I brute forced the solution by getting rid of the optimization to call onBackPressed(). I think this is fine because, with the current UX, we wouldn't expect people to be going back and forth between the MainActivity and LocationActivity frequently.

startActivity(intent);
finish();
}
Intent intent = new Intent(this, MainActivity.class);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think that if you return always with an intent, we end up with a big stack of activities (Location / Main / Location / Main). Even if you finish(), you end up with a stack of Main activities.

Curious why you changed this from the if (mFromMain) { onBackPressed() }?

Copy link
Collaborator

@dektar dektar Feb 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see your explanation above. Can we move this into a different PR to keep it separate from all this functionality? I'd like to experiment and see if there's a way to make it work without multiple layers of activities.

One option may be that we "startActivityForResult" from MainActivity when the Location menu option is clicked, and then we can "onActivityResult" instead of "onBackPressed". I'd need to look into it more, though.

Or, I do want to consider refactoring to using Fragments at some point... maybe starting with this class would make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll pull that out.

tools:context="org.a5calls.android.a5calls.controller.MainActivity">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been doing XML IDs like swipe_container instead of swipeContainer. Does this way work better with butterknife? Or can we stick with the other convention?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh we can stick to the other convention. Doesn't matter to me.

@Gregliest
Copy link
Collaborator Author

@dektar Done. I'm just going to make an issue for the crash, since the brute force fix was trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants