Commit 916c2032 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#201: [WIP] New acvitivty and classes created

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent bbb2f298
......@@ -36,6 +36,7 @@
<activity android:name=".SignupActivity"></activity>
<activity android:name=".AccountActivity"></activity>
<activity android:name=".ForgotPasswordActivity"></activity>
<activity android:name=".DependentsActivity"></activity>
<service
android:name=".services.ImageUpdateService"
......
......@@ -10,16 +10,15 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.CitizensArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.CitizensItemListener;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.CitizensArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.RecyclerViewItemListener;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.CitizensPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
......@@ -70,8 +69,8 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
rv_citizens.setVisibility(View.INVISIBLE);
rv_citizens.addOnItemTouchListener(new CitizensItemListener(getApplicationContext(), rv_citizens,
new CitizensItemListener.RecyclerTouchListener() {
rv_citizens.addOnItemTouchListener(new RecyclerViewItemListener(getApplicationContext(), rv_citizens,
new RecyclerViewItemListener.RecyclerTouchListener() {
public void onClickItem(View v, int position) {
Intent intent = new Intent(CitizenActivity.this, TermActivity.class);
Bundle bundle = new Bundle();
......@@ -112,8 +111,10 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
}
public void showLayout(boolean enabled) {
rv_citizens.setAdapter(new CitizensArrayAdapter(this, citizens));
rv_citizens.setVisibility(View.VISIBLE);
if(enabled){
rv_citizens.setAdapter(new CitizensArrayAdapter(this, citizens));
rv_citizens.setVisibility(View.VISIBLE);
}
}
public void successfulCitizens(List<UserOutput> citizens) {
......
package br.ufpr.c3sl.agendador.agendador;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.CitizensArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.RecyclerViewItemListener;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.DependentsPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.DependentsView;
/**
* Created by Lucas B. Cunha on 08/08/17.
*/
public class DependentsActivity extends AppCompatActivity implements DependentsView{
private DependentsPresenter presenter;
private ProgressBar pb_dependents;
private RecyclerView rv_dependents;
private ConnectionFailureDialog dg_connection_failure;
private List<UserOutput> dependents;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
presenter = new DependentsPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new DependentsPresenter(this);
}
setContentView(R.layout.activity_dependents);
pb_dependents = (ProgressBar) findViewById(R.id.pb_dependentact);
rv_dependents = (RecyclerView) findViewById(R.id.rv_dependents);
RecyclerView.LayoutManager layout = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL, false);
rv_dependents.setLayoutManager(layout);
rv_dependents.setVisibility(View.INVISIBLE);
rv_dependents.addOnItemTouchListener(new RecyclerViewItemListener(getApplicationContext(), rv_dependents,
new RecyclerViewItemListener.RecyclerTouchListener() {
public void onClickItem(View v, int position) {
/*Intent intent = new Intent(DependentsActivity.this, );
Bundle bundle = new Bundle();
bundle.putParcelable(Utils.CITIZEN, citizens.get(position));
intent.putExtra(Utils.CITIZEN_BUNDLE, bundle);
startActivity(intent);
finish();*/
Toast.makeText(getBaseContext(), "Selecionou algum", Toast.LENGTH_SHORT).show();
}
public void onLongClickItem(View v, int position) {
//do nothing.
}
}));
}
/*public void successfulCitizens(List<UserOutput> citizens) {
this.citizens = citizens;
}
*/
public void onRequestFailure(){
Bundle bundle = new Bundle();
if(dg_connection_failure == null){
dg_connection_failure = new ConnectionFailureDialog();
}
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE, getString(R.string.dialog_term_error));
dg_connection_failure.setArguments(bundle);
dg_connection_failure.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
if(dependents == null)
presenter.requestDependents();
}
@Override
protected void onPause() {
super.onPause();
presenter.unbindView();
}
@Override
public void onSaveInstanceState(Bundle outState) {
PresenterManager.getInstance().savePresenter(presenter, outState);
super.onSaveInstanceState(outState);
}
public void showLayout(boolean enabled) {
if(enabled){
rv_dependents.setAdapter(new CitizensArrayAdapter(this, dependents));
rv_dependents.setVisibility(View.VISIBLE);
}
}
public void setProgressBar(boolean enabled) {
if (enabled) {
pb_dependents.setVisibility(View.VISIBLE);
rv_dependents.setVisibility(View.INVISIBLE);
} else {
pb_dependents.setVisibility(View.INVISIBLE);
}
}
public static class ConnectionFailureDialog extends DialogFragment {
public static final String DIALOG_MESSAGE_KEY = "message";
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getArguments().getString(DIALOG_MESSAGE_KEY))
.setTitle(getString(R.string.warningDialog_title))
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Activity activity = getActivity();
activity.onBackPressed();
}
});
return builder.create();
}
}
}
......@@ -226,6 +226,10 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
intent = new Intent(this, CitizenActivity.class);
startActivity(intent);
break;
case R.id.nav_dependants:
intent = new Intent(this, DependentsActivity.class);
startActivity(intent);
break;
default:
break;
}
......
......@@ -14,7 +14,7 @@ import android.view.View;
public class CitizensItemListener implements RecyclerView.OnItemTouchListener{
public class RecyclerViewItemListener implements RecyclerView.OnItemTouchListener{
private RecyclerTouchListener listener;
......@@ -25,8 +25,8 @@ public class CitizensItemListener implements RecyclerView.OnItemTouchListener{
void onLongClickItem(View v, int position);
}
public CitizensItemListener(Context ctx, final RecyclerView rv,
final RecyclerTouchListener listener) {
public RecyclerViewItemListener(Context ctx, final RecyclerView rv,
final RecyclerTouchListener listener) {
this.listener = listener;
gd = new GestureDetector(ctx,
new GestureDetector.SimpleOnGestureListener() {
......
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.util.Log;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.DependentsActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import okhttp3.Headers;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by Lucas B. Cunha on 08/08/17.
*/
public class DependentsPresenter extends BasePresenter<DependentsActivity> {
private Context context;
private ObscuredSharedPreferences osb;
private DependentsPresenter presenter;
public DependentsPresenter(Context context){
this.context = context;
presenter = this;
osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", Context.MODE_PRIVATE);
}
private void updateToken(Headers headers) {
if(headers.get("access-token") != null)
osb.edit().putString("access-token", headers.get("access-token")).apply();
if(headers.get("client") != null)
osb.edit().putString("client", headers.get("client")).apply();
}
public void requestDependents(){
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
header.put("access-token", osb.getString("access-token", null));
header.put("client", osb.getString("client", null));
header.put("uid", osb.getString("uid", null));
final ApiEndpoints service = ApiUtils.request(header);
//Call<List<UserOutput>> listCall = service.requestDependents();
presenter.view().setProgressBar(true);
/*listCall.enqueue(new Callback<List<UserOutput>>() {
@Override
public void onResponse(Call<List<UserOutput>> call, Response<List<UserOutput>> response) {
Headers headers = response.headers();
int status = response.code();
List<UserOutput> citizens = response.body();
switch (status) {
case 200:
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
updateToken(headers);
//has to be done before showing layout
presenter.view().successfulCitizens(citizens);
presenter.view().showLayout(true);
presenter.view().setProgressBar(false);
break;
default:
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
presenter.view().onRequestFailure();
break;
}
}
@Override
public void onFailure(Call<List<UserOutput>> call, Throwable t) {
Log.e("Server response", getClass().getName() + ": Requisição falhou!!");
presenter.view().setProgressBar(false);
presenter.view().onRequestFailure();
}
});*/
}
@Override
protected void updateView() {
}
}
......@@ -27,7 +27,9 @@ import retrofit2.Response;
public class HomePresenter extends BasePresenter<HomeView> {
private Context context;
private HomePresenter homePresenter;
private ObscuredSharedPreferences osb;
public HomePresenter(Context context) {
......
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.os.Bundle;
import android.support.test.espresso.core.deps.guava.cache.Cache;
import android.support.test.espresso.core.deps.guava.cache.CacheBuilder;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
/**
* Created by Bruno Freitas Tissei on 2/2/17.
*/
public class PresenterManager {
private static final String SIS_KEY_PRESENTER_ID = "presenter_id";
private static PresenterManager instance;
private final AtomicLong currentId;
private final Cache<Long, BasePresenter<?>> presenters;
public PresenterManager(long maxSize, long expirationValue, TimeUnit expirationUnit) {
currentId = new AtomicLong();
presenters = CacheBuilder.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(expirationValue, expirationUnit)
.build();
}
public static PresenterManager getInstance() {
if (instance == null) {
instance = new PresenterManager(10, 30, TimeUnit.SECONDS);
}
return instance;
}
public <P extends BasePresenter<?>> P restorePresenter(Bundle savedInstanceState) {
Long presenterId = savedInstanceState.getLong(SIS_KEY_PRESENTER_ID);
P presenter = (P) presenters.getIfPresent(presenterId);
presenters.invalidate(presenterId);
return presenter;
}
public void savePresenter(BasePresenter<?> presenter, Bundle outState) {
long presenterId = currentId.incrementAndGet();
presenters.put(presenterId, presenter);
outState.putLong(SIS_KEY_PRESENTER_ID, presenterId);
}
}
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador.views;
/**
* Created by Lucas B. Cunha on 08/08/17.
*/
public interface DependentsView {
void showLayout(boolean enabled);
void setProgressBar(boolean enabled);
void onRequestFailure();
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/dependents_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dependents_description"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_dependents"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="br.ufpr.c3sl.agendador.agendador.CitizenActivity"
android:layout_below="@+id/dependents_description"
android:layout_alignParentStart="true" />
<ProgressBar
android:id="@+id/pb_dependentact"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment