-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from vjs3/client_list
Client List with navigation drawer added
- Loading branch information
Showing
14 changed files
with
368 additions
and
14 deletions.
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
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().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)); | ||
} | ||
}); | ||
} | ||
} |
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
131 changes: 131 additions & 0 deletions
131
app/src/main/java/org/mifos/selfserviceapp/ui/activities/ClientListActivity.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,131 @@ | ||
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 progressDialog; | ||
|
||
@BindView(R.id.rv_clients) | ||
RecyclerView rvClients; | ||
@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); | ||
rvClients.setLayoutManager(layoutManager); | ||
rvClients.addOnItemTouchListener(new RecyclerItemClickListener(this, this)); | ||
rvClients.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 (progressDialog == null) { | ||
progressDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER); | ||
progressDialog.setCancelable(false); | ||
} | ||
progressDialog.setMessage(getResources().getText(R.string.progress_message_loading)); | ||
progressDialog.show(); | ||
} | ||
|
||
@Override | ||
public void hideProgress() { | ||
if (progressDialog != null && progressDialog.isShowing()) | ||
progressDialog.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); | ||
rvClients.setAdapter(clientListAdapter); | ||
} | ||
|
||
@Override | ||
public void showErrorFetchingClients(String message) { | ||
Toast.makeText(this, message, Toast.LENGTH_LONG).show(); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
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,104 @@ | ||
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 { | ||
|
||
@BindView(R.id.toolbar) | ||
Toolbar toolbar; | ||
@BindView(R.id.navigation_view) | ||
NavigationView mNavigationView; | ||
@BindView(R.id.drawer) | ||
DrawerLayout mDrawerLayout; | ||
|
||
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() { | ||
|
||
mNavigationView.setNavigationItemSelectedListener(this); | ||
|
||
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.