Closed JayBrizle closed 9 years ago
Awesome! I'll locally clone and do some tests.
One thing I realized I didn't do was use setRetainInstanceState method in QuestionsFragment. The app is currently fixed to portrait but that of course will change later. I think android automatically tracks the basic things in there now though (like a checked checkbox will stay checked after configuration change). We can deal with the reconfiguration stuff later, just making note now.
Yes, with the reconfiguration (screen rotation) it resets to the first question. Orientation is fixed for activity and it's no longer exists. But it's not a really big deal for now. Thinking about all pros and cons of the fragments. Started a new thread https://class.coursera.org/androidpart1-010/forum/thread?thread_id=172
You did a lot of work, I like the idea of callback (decoupling) and comments are good.
By the way, I can do grammar mistakes, feel free to correct me =)
At that moment a user can do 2 focused actions:
So it feels like two activities are ok. First one do not need fragments (at least for now). But the second is a good candidate for two fragments.
From reading through the documentation and training on the Android developer site I think you build the fragment capabilities in from the start so that you can reuse them throughout the entire application from small to large devices with all configurations. Maybe I am understanding it wrong though. After doing all that coding it would seem though that if you know you are going to want to support different devices then you should build with fragments from the start. I believe it may save a crap ton of refactoring and build flexibility in from the start. Now that the base is laid in fragments it's a simple thing that while on a small device the app works the same as with Activities but it should be much easier to extend the application now going forward without having to do another large refactoring later to support different devices beyond a simple small phone.
And I understand your grammar just fine by the way lol
Later tonight I will work a bit more on this to implement the layout orientations using fragments for small to medium devices as a test to show. I'll also add in what's needed to save state so the current question stays after reconfiguration
More interesting articles
https://corner.squareup.com/2014/10/advocating-against-android-fragments.html
Those are good links. I would think that the way shown by Google on the Android dev site should be the standard way but it appears people have modified things to meet their specific needs. Its nice to know we can do that when needed, although it requires a bit of extra learning beyond the fundamentals. I especially like the accepted answer in the stackoverflow link.
Did some refactoring and added state saving https://github.com/mgolokhov/dodroid/commit/ae70b0d826de64eb7392f9b393cc9ced4fb34670
Looks good. I like the implementing of click listener interface and using onClick with the switch statement. That cleans things up nicely.
I added the needed code and refactored the code base to work with Fragments now (was quite the learning experience and required a number of changes). I had to move things around a bit to make it all work, so some of the code is in new places and classes now(as well as layout files). I tested on my Galaxy S6 phone and all works the same as before, just built on top of fragments now, only Activity is main hosting Activity, so we can start using that flexibility when we start to develop for different device sizes and orientations. Comments have been added in places to help describe things where maybe needed. Let me know if there are any problems or something I overlooked.