Lean Mobile App Development by Mike van Drongelen

Lean Mobile App Development by Mike van Drongelen

Author:Mike van Drongelen
Language: eng
Format: epub, mobi
Tags: COM051460 - COMPUTERS / Programming / Mobile Devices, COM051230 - COMPUTERS / Software Development and Engineering / General, COM051440 - COMPUTERS / Software Development and Engineering / Tools
Publisher: Packt Publishing
Published: 2017-11-27T09:06:22+00:00


Everybody likes stories, so the first action probably will be that the user clicks on a story of which the summary looks appealing. (Again this is a hypothesis that needs to be proven.) If the user clicks on the floating action button (the one with the plus sign on it), he will create a new story:

class StoriesFragment : Fragment(), OnCardViewClicked, OnRepositoryResult { private var recyclerView: RecyclerView? = null private var adapter: StoryAdapter? = null private var viewModel = mutableListOf<Story>() ...

If you take a look inside StoriesFragment, you will see that a RecyclerView widget and a StoryAdapter will be used to display the data shown here. In the onCreateView method, the loadData method will be called, which in turn calls the getStories method of the Repository class, passing the fragment itself as the handler of the results:

override fun onResult(result: List<Story>) { viewModel = result.toMutableList() adapter = StoryAdapter(viewModel) adapter?.setOnCardViewClicked(this) recyclerView?.adapter = adapter }

When the results come in, an instance of the StoryAdapter class will be created and attached to the RecyclerView instance. The StoryAdapter binds the data for each story to a row in the list:

override fun onCardClicked(view: View, position: Int) { (activity as MainActivity).onReadStory(viewModel[position]) }

If the user clicks on any of the rows the OnCardViewClick event will be triggered, which will call the onReadStory method from MainActivity, passing the selected story as the parameter. This will bring us to the StoryDetailFragment implementation.

This fragment displays the full story to the user, including the name of the contributors. Here, the user can contribute to the story by clicking on the CONTRIBUTE (as shown in the example image):

class StoryDetailFragment : Fragment() { private var mStory: Story? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mStory = getArguments().getParcelable(ARG_STORY) }

In the onCreate method, the selected story will receive through the bundle. It is here where the Parcelable implementation comes in handy. In the onCreateView method, the content of the story will be set as text for textView using the getFullStory method of the story object:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.