Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation drawer with client list added #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
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.HomeActivity"
android:label="@string/home"
android:screenOrientation="portrait" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
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.HomeActivity;
import org.mifos.selfserviceapp.ui.activities.LoginActivity;
import org.mifos.selfserviceapp.ui.fragments.ClientListFragment;

import dagger.Component;

Expand All @@ -17,4 +19,8 @@ public interface ActivityComponent {

void inject(LoginActivity loginActivity);

void inject(HomeActivity homeActivity);

void inject(ClientListFragment clientListFragment);

}
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().showInternalServerError(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,138 @@
package org.mifos.selfserviceapp.ui.activities;


import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
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 org.mifos.selfserviceapp.ui.fragments.ClientListFragment;

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));
}

replaceFragment(new ClientListFragment(), false, R.id.container);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't create fragments like this.
Use getInstance() method to create Fragments.


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_client_list:
replaceFragment(new ClientListFragment(), false, R.id.container);
break;
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_client_list);
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();
}

/**
*Replace the Activity with desired fragment depending upon what user is
* selecting in navigation drawer.
*
* @param fragment Name of the fragment which is to be replaced
* @param addToBackStack boolean value to decide weather to store fragment in backstack
* @param containerId id of container where fragment has to be hold
*/
private void replaceFragment(Fragment fragment, boolean addToBackStack, int containerId) {
invalidateOptionsMenu();
String backStateName = fragment.getClass().getName();
boolean fragmentPopped = getSupportFragmentManager().popBackStackImmediate(backStateName,
0);

if (!fragmentPopped && getSupportFragmentManager().findFragmentByTag(backStateName) ==
null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(containerId, fragment, backStateName);
if (addToBackStack) {
transaction.addToBackStack(backStateName);
}
transaction.commit();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mifos.selfserviceapp.ui.activities;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.widget.EditText;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void onLoginSuccess(String userName) {
getString(R.string.toast_welcome, userName);
showToast(toastMessage);

// TODO : Handle the flow from here
startActivity(new Intent(this, HomeActivity.class));
}

@Override
Expand Down
Loading