Skip to content

Commit

Permalink
Client List with navigation drawer added
Browse files Browse the repository at this point in the history
Added client list with home screen and nav drawer with change User interaction

Client list with navigation drawer added
  • Loading branch information
vjs3 committed Jul 27, 2016
1 parent e00a468 commit 28307ae
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 14 deletions.
11 changes: 10 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@
android:theme="@style/MaterialAppTheme">
<activity
android:name=".ui.activities.LoginActivity"
android:label="@string/login"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activities.ClientListActivity"
android:label="@string/clients_list"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activities.HomeActivity"
android:label="@string/home"
android:screenOrientation="portrait" />

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import retrofit2.http.Path;

/**
* Created by vjs3 on 23/6/16.
* @author Vishwajeet
* @since 23/6/16.
*/

public interface LoanAccountsListService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import retrofit2.http.Path;

/**
* Created by vjs3 on 21/6/16.
* @author Vishwajeet
* @since 21/6/16.
*/
public interface SavingAccountsListService {
@GET(ApiEndPoints.CLIENTS + "/{clientId}/accounts?fields=savingsAccounts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.mifos.selfserviceapp.injection.PerActivity;
import org.mifos.selfserviceapp.injection.module.ActivityDataModule;
import org.mifos.selfserviceapp.injection.module.ActivityModule;
import org.mifos.selfserviceapp.ui.activities.ClientListActivity;
import org.mifos.selfserviceapp.ui.activities.HomeActivity;
import org.mifos.selfserviceapp.ui.activities.LoginActivity;

import dagger.Component;
Expand All @@ -17,4 +19,8 @@ public interface ActivityComponent {

void inject(LoginActivity loginActivity);

void inject(ClientListActivity clientListActivity);

void inject(HomeActivity homeActivity);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.mifos.selfserviceapp.presenters;

import android.content.Context;

import org.mifos.selfserviceapp.R;
import org.mifos.selfserviceapp.api.DataManager;
import org.mifos.selfserviceapp.data.Client;
import org.mifos.selfserviceapp.injection.ActivityContext;
import org.mifos.selfserviceapp.presenters.base.BasePresenter;
import org.mifos.selfserviceapp.ui.views.ClientListView;

import java.util.List;

import javax.inject.Inject;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
* @author Vishwajeet
* @since 14/07/16
*/

public class ClientListPresenter extends BasePresenter<ClientListView> {
private DataManager dataManager;

/**
* Initialises the ClientListPresenter by automatically injecting an instance of
* {@link DataManager} and {@link Context}.
*
* @param dataManager DataManager class that provides access to the data
* via the API.
* @param context Context of the view attached to the presenter. In this case
* it is that of an {@link android.support.v7.app.AppCompatActivity}
*/
@Inject
public ClientListPresenter(DataManager dataManager, @ActivityContext Context context) {
super(context);
this.dataManager = dataManager;
}

/**
* Load list of client id's attached to particular self-service user from the server
* and notify the view to display it. Notify the view, in case there is any error in fetching
* the list from server.
*/
public void loadClients() {
Call<Client> call = dataManager.getClients();
getMvpView().showProgress();
call.enqueue(new Callback<Client>() {
@Override
public void onResponse(Response<Client> response) {
getMvpView().hideProgress();

if (response.code() == 200) {
final Client client = response.body();
List<Client> clientList = response.body().getPageItems();
if (client != null) {
getMvpView().showClients(clientList);
}
} else if (response.code() >= 400 && response.code() < 500) {
getMvpView().showErrorFetchingClients(context.getString(R.string.error_client_loading));
} else if (response.code() == 500) {
getMvpView().showErrorFetchingClients(context.getString(R.string.error_internal_server));
}
}

@Override
public void onFailure(Throwable t) {
getMvpView().hideProgress();
getMvpView().showErrorFetchingClients(context.getString(R.string.error_message_server));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onResponse(Response<User> response) {
getMvpView().onLoginSuccess(userName);

final int userID = user.getUserId();
final String authToken =
final String authToken = "Basic " +
user.getBase64EncodedAuthenticationKey();
saveAuthenticationTokenForSession(userID,authToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package org.mifos.selfserviceapp.ui.activities;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import org.mifos.selfserviceapp.R;
import org.mifos.selfserviceapp.data.Client;
import org.mifos.selfserviceapp.presenters.ClientListPresenter;
import org.mifos.selfserviceapp.ui.adapters.ClientListAdapter;
import org.mifos.selfserviceapp.ui.views.ClientListView;
import org.mifos.selfserviceapp.utils.Constants;
import org.mifos.selfserviceapp.utils.RecyclerItemClickListener;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
* @author Vishwajeet
* @since 14/07/16
*/
public class ClientListActivity extends BaseActivity implements RecyclerItemClickListener.OnItemClickListener, ClientListView {

@Inject
ClientListPresenter mClientListPresenter;

private ClientListAdapter clientListAdapter;
private List<Client> clientList = new ArrayList<>();
private LinearLayoutManager layoutManager;
private ProgressDialog progress;

@BindView(R.id.rv_clients)
RecyclerView rv_clients;
@BindView(R.id.swipe_container)
SwipeRefreshLayout swipeRefreshLayout;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);

setContentView(R.layout.activity_client_list);

ButterKnife.bind(this);

mClientListPresenter.attachView(this);

layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rv_clients.setLayoutManager(layoutManager);
rv_clients.addOnItemTouchListener(new RecyclerItemClickListener(this, this));
rv_clients.setHasFixedSize(true);

swipeRefreshLayout.setColorSchemeResources(R.color.blue_light, R.color.green_light, R
.color.orange_light, R.color.red_light);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mClientListPresenter.loadClients();
}
});

mClientListPresenter.loadClients();
}

@Override
public void onDestroy() {
mClientListPresenter.detachView();
super.onDestroy();
}

@Override
public void onItemClick(View childView, int position) {
Intent clientAccountIntent = new Intent(this, HomeActivity.class);
clientAccountIntent.putExtra(Constants.CLIENT_ID, clientList.get(position).getId());
startActivity(clientAccountIntent);
}

@Override
public void onItemLongPress(View childView, int position) {

}

@Override
public void showProgress() {
if (progress == null) {
progress = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
progress.setCancelable(false);
}
progress.setMessage(getResources().getText(R.string.progress_message_loading));
progress.show();
}

@Override
public void hideProgress() {
if (progress != null && progress.isShowing())
progress.dismiss();
}

@Override
public void showClients(List<Client> clientList) {
this.clientList = clientList;
inflateClientList();
if (swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setRefreshing(false);
}

/**
* setting adapter to display list of clients on the client list screen
*/
private void inflateClientList() {
clientListAdapter = new ClientListAdapter(this, clientList);
rv_clients.setAdapter(clientListAdapter);
}

@Override
public void showErrorFetchingClients(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.mifos.selfserviceapp.ui.activities;


import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;

import android.view.MenuItem;
import android.view.View;
import android.support.v7.widget.Toolbar;

import org.mifos.selfserviceapp.R;


import butterknife.BindView;
import butterknife.ButterKnife;

/**
* @author Vishwajeet
* @since 14/07/2016
*/

public class HomeActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {

private NavigationView mNavigationView;
private DrawerLayout mDrawerLayout;

@BindView(R.id.toolbar)
Toolbar toolbar;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getActivityComponent().inject(this);

setContentView(R.layout.activity_home);

ButterKnife.bind(this);

if (toolbar != null) {
setSupportActionBar(toolbar);
toolbar.setTitle(getString(R.string.home));
}

setupNavigationBar();
}

@Override
public boolean onNavigationItemSelected(MenuItem item) {
// ignore the current selected item
if (item.isChecked()) {
mDrawerLayout.closeDrawer(GravityCompat.START);
return false;
}

// select which item to open
switch (item.getItemId()) {
case R.id.item_accounts:
break;
case R.id.item_funds_transfer:
break;
case R.id.item_recent_transactions:
break;
case R.id.item_questionnaire:
break;
case R.id.item_about_us:
break;
}

// close the drawer
mDrawerLayout.closeDrawer(GravityCompat.START);
mNavigationView.setCheckedItem(R.id.item_accounts);
return true;
}

/**
*This method is used to set up the navigation drawer for
* self-service application
*/
private void setupNavigationBar() {

// setup navigation view
mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
mNavigationView.setNavigationItemSelectedListener(this);

// setup drawer layout and sync to toolbar
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer) {

@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}

@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
mDrawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
}

}
Loading

0 comments on commit 28307ae

Please sign in to comment.