MoneyBack – 3 weeks before the end of DSP

In today’s post I’d like to present what’s the current status of works on MoneyBack application, 3 weeks before the end of DSP competition.

In general, the project hasn’t been going as well as I expected and is currently not as advanced as I’d expect it to be at this stage. There are many reasons behind that, including lack of time recently and many issues met during development, however, as I already wrote in my DSP introducing post, the most important is to survive with the project to the end of the competition and meet all requirements. The end of DSP doesn’t equal the end of MoneyBack 🙂

That’s why in this post I’d like to show you how the project looks currently and what’s still to be done. Moreover, as I promised before, I’m publishing my Trello board with tasks still to be done within the project.

UI changes

For the last days working on the project I’ve been trying to make the UI of MoneyBack some kind of “final” version, so I can easily extend it adding new functionalities and focus on development instead of spending time on interface design, which is not important for me at the moment. I met many issues with that, which I think came from using some deprecated UI elements I used (e.g. ListView and Adapters) that are not fully-supported in the newest versions of Android. Tutorials are also not really up-to-date for those components. Maybe that’s also because when I wanted to implement displaying a list of entities I looked in Google for something like “xamarin android list of elements” which lead me to this ListView and Adapters tutorial. Instead of firstly reading the whole User Interface tutorial, I wanted to implement displaying the list quickly, so I used those deprecated elements instead of implementing for instance newer and recommended RecyclerView from the beginning, which would be easier extensible now. That definitely teaches me that I should get to know a particular topic/area better and wider before deciding to use one of the possible solutions to solve a problem. Sometimes we want to implement something particular quickly, but later it produces more issues than benefits.

Finally I added tabs (only one tab for People for now, but it will be easy to add new ones now) and ActionBar menu on the main Activity of the app:

MoneyBack – tabs

On the screenshot above, in the right-upper corner there is “Add” button visible when clicking on ActionBar menu. It opens a new person’s adding screen, on which I made name and email fields mandatory:

MoneyBack – adding Person

People added are then displayed on the main screen of the app in “People” tab:

MoneyBack – list of people

Code – interesting parts

Using tabs layout in an Activity

It turned out that using tabs-like layout in the Activity is pretty easy. In the AXML layout file for MainActivity I just added a FrameLayout container, within which the tabs and their contents are to be displayed:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<FrameLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabFragmentsContainer" />
</LinearLayout>

view raw

Main.axml

hosted with ❤ by GitHub

I called it tabFragmentsContainer, because within each tab we will display a Fragment. Fragment represents a part of UI and/or behavior, which is displayed within an Activity. You can think of Fragments as smaller pieces, that can be placed onto (inside) Activities.

Basically, I changed PeopleListActivity to PeopleListFragment, which in fact only required changing inheritance from being a child of Activity to inheriting from ListFragment (which is a special kind of Fragment used for displaying lists of elements). The complete code of PeopleListFragment can be found in this public Gist.

In the end, making MainActivity displaying tabs requires setting its ActionBar’s navigation mode to ActionBarNavigationMode.Tabs:

this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;

and adding as many tabs as you wish, using for instance code similar to the following one:


void AddTab(string tabText, Fragment view)
{
var tab = this.ActionBar.NewTab();
tab.SetText(tabText);
tab.TabSelected += delegate (object sender, ActionBar.TabEventArgs e)
{
var fragment = this.FragmentManager.FindFragmentById(Resource.Id.tabFragmentsContainer);
if (fragment != null)
e.FragmentTransaction.Remove(fragment);
e.FragmentTransaction.Add(Resource.Id.tabFragmentsContainer, view);
};
tab.TabUnselected += delegate (object sender, ActionBar.TabEventArgs e) {
e.FragmentTransaction.Remove(view);
};
this.ActionBar.AddTab(tab);
}

The arguments are name of the tab and an instance of a Fragment we want to have displayed in this tab (PeopleListFragment‘s instance in our case).

Lines 6-12 present what happens when the tab is selected by the user – Fragment‘s instance is added to previously defined tabFragmentsContainer.

Lines 13-15 define callback method on tab deselection – Fragment is removed from the container.

Adding ActionBar with menu to the Activity

Addition of ActionBar with menu button in right-upper corner of the Activity requires creating an XML view in Resources/menu folder first (with one button in our case):


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menuAdd"
android:title="@string/menuAddTitle"/>
</menu>

and then in the Activity considered overriding OnCreateOptionsMenu method inflating ActionBar’s menu using created view:


public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.ActionBarMenu, menu);
return base.OnPrepareOptionsMenu(menu);
}

We also need to define what happens when a menu option is selected. For that purpose, override OnOptionsItemSelected method:


public override bool OnOptionsItemSelected(IMenuItem item)
{
if (item.ItemId == Resource.Id.menuAdd)
{
OpenAddingNewPerson();
return true;
}
return base.OnOptionsItemSelected(item);
}

Next coding tasks

From now on you can watch my public Trello board, where I have all tasks to be done in the nearest future in MoneyBack defined. I will try to define deadlines for those tasks as well.

At the moment of writing this post, I’ve started adding a possibility to create Events. I will need to keep many-to-many relationship between Person and Event entities and I will probably use SQLite-Net Extensions library for that. You can expect a separate post about defining relationships using this library soon 😉

Other tasks left to be done

Apart from coding and developing the project, I still need to fulfill the DSP competition’s requirements. This is my 14th post within DajSiePoznac2017, so 6 posts still to be written. I have the ideas in my mind already and few next posts planned. There are only 3 weeks left to the end of the competition, so those days will need to be more intensive that it recently was, but that’s good, it means that you should be receiving more content here in the coming days and I will be spending more time on developing MoneyBack. Only positive changes, I hope 🙂

Summary

We saw the status of MoneyBack project today. There are still many things to be done in the app to at least fulfill the minimal requirements I assumed in the beginning of the competition. but as I mentioned, the end of DSP is not the end of MoneyBack 🙂 On the other hand, DSP is a very good motivator, so I’ll try to make coming days and weeks more intensive. The most important goal for now is to fulfill the competition’s requirements for having 20 posts written until the end of May, which shouldn’t be problematic at all 🙂

I’ve also published my Trello dashboard. You can find a link to it here.

Using this opportunity, I’d like to wish all DSP’17 participants good luck in the last weeks of the competition. I’m constantly reading the others’ blogs and I see a lot of very nice and decent quality stuff appearing in Polish programming community on your blogs and repositories – great job!

Keep your fingers crossed! 🙂

.NET full stack web developer & digital nomad
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments