Creating the MainView

Before we proceed with creating the main view, it is imperative that we have a clear understanding of the user interface that we want to implement. A good place to start is to clearly write out sentences that describe how we want the MainView to function. Let's go ahead and do that:

  • The main view should display the active conversations of the currently logged-in user upon launch
  • The main view should allow a logged-in user to create a new conversation
  • The main view should be able to show the contacts of a currently logged-in user (in the case of this application, this is a list of all the registered users on the Messenger platform)
  • A user must be able to access the settings screen directly from the MainView
  • A user should be able to log out of the application directly from the MainView

All right, great! We have our list of brief statements describing what the MainView can do. With this list, it is possible to get on with creating the MainView (in terms of programming, that is). We are not going to do this yet. Let's create a few visual sketches of MainView to give us a clearer idea of how it will look:

As can be seen from the preceding diagram, MainActivity can render two completely separate views to a user. The first view is the Conversations Screen and the second the Contacts Screen. A perfect way to implement this is to employ two use fragments within the MainActivity. In this case, we will require two distinct fragments. These are the conversations fragment and the contacts fragment.

Now that we have a clear idea of what the MainView is going to contain, we need to implement a proper interface to declare the behaviors of the MainView. The following is the MainView interface:

package com.example.messenger.ui.main
import com.example.messenger.ui.base.BaseView

interface MainView : BaseView {
fun showConversationsLoadError()
fun showContactsLoadError()
fun showConversationsScreen()
fun showContactsScreen()
fun getContactsFragment(): MainActivity.ContactsFragment
fun getConversationsFragment(): MainActivity.ConversationsFragment
fun showNoConversations()
fun navigateToLogin()
fun navigateToSettings()
}

Great work! We will save the implementation of the MainView by MainActivity for later. For now, we will work on the MainInteractor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.249.252