-
Notifications
You must be signed in to change notification settings - Fork 717
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/src/main/java/org/mifos/selfserviceapp/presenters/ClientListPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
app/src/main/java/org/mifos/selfserviceapp/ui/activities/HomeActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.