Skip to content

Project architecture overview

Olya Fomenko edited this page Mar 15, 2016 · 3 revisions

1. Activities

MifosBaseActivity - base class for all activities. It contains a bunch of helpful methods for your implementation:

protected void showBackButton()
protected void setActionBarTitle(String title)
protected void setActionBarTitle(int title)
protected void showProgress(String message)
protected void hideProgress()
protected void logout()
protected void replaceFragment(Fragment fragment, boolean addToBackStack, int containerId)

replaceFragment - method handles fragment manipulations, and stack storage. BaseActivityCallback - this interface is implemented by MifosBaseActivity by default. This allows to make a single communication link Fragment <-> Activity and remove duplicating functionality.

2. Fragments

MifosBaseFragment - base component for fragments. Using BaseActivityCallback it can communicate with parent activity anytime. Through this link, have almost the same functionality as MifosBaseActivity.

3. Adapters

MifosBaseListAdapter - It is a generic adapter, that should be subclassed for all adapters in the project.

    public MifosBaseListAdapter(Context context, List<T> list, int layoutId) {
        ...
    }

It incapsulates the most of calculations, elements additions, inflater creation. Implementation sample:

public class ClientSearchAdapter extends MifosBaseListAdapter<SearchedEntity> {

    // layoutId - your layout identifier
    public ClientSearchAdapter(Context context, List<SearchedEntity> list, int layoutId) {
        super(context, list, layoutId);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        final SearchedEntity item;

        if (convertView == null) {
            convertView = getLayout();
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        item = getItem(position);
        holder.name.setText(item.getDescription());
        return convertView;
    }
     
    // Don't forget to use ViewHolder to prevent performance issues
    class ViewHolder {
        private TextView name;

        public ViewHolder(View view) {
            name = (TextView) view.findViewById(R.id.name);
        }
    }
}

4. API requests

ApiManager - base class for implementing server requests, it's located in package com.mifos.api. BaseApiManager - superclass for ApiManager, and it handles interface (API services) creation, request interception, logging, etc.

To add new request you should modify corresponding service interface, and then call it from ApiManager. Consider not using direct Callback into your UI controller.

ApiManager instance can be accessed from App class.

Example:

App.apiManager.login(username, password, this);

5. Preferences

PrefManager - preferences management utility. It allows to reduce boilerplate code with creating SharedPreferences instance.

5. Toaster

simple helper utility, that allows showing Toast (short notification message)