Commit bbb2f298 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Bug fix: App used to crash if opened from 'recents' list - now [really] fixed

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 23bd3e45
......@@ -52,6 +52,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.adapters.PhotoSelectionAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.presenters.AccountPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.AccountView;
/**
......@@ -105,6 +106,8 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
presenter = new AccountPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new AccountPresenter(this);
}
/*TODO: Check performance of acvitity
......
......@@ -13,6 +13,7 @@ import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.presenters.CepPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.CepView;
/**
......@@ -34,6 +35,8 @@ public class CepActivity extends AppCompatActivity implements CepView {
presenter = new CepPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new CepPresenter(this);
}
setContentView(R.layout.activity_cep);
......
......@@ -8,6 +8,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.presenters.CepNotFoundPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.CepNotFoundView;
/**
......@@ -27,6 +28,8 @@ public class CepNotFoundActivity extends AppCompatActivity implements CepNotFoun
presenter = new CepNotFoundPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new CepNotFoundPresenter(this);
}
setContentView(R.layout.activity_cep_not_found);
......
......@@ -10,6 +10,7 @@ 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;
......@@ -21,6 +22,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.CitizensItemListener;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.CitizensPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.CitizenView;
......@@ -44,14 +46,17 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_citizen);
if (savedInstanceState == null) {
citizensPresenter = new CitizensPresenter(this);
} else {
}
else{
citizensPresenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(citizensPresenter == null){
citizensPresenter = new CitizensPresenter(this);
}
}
setContentView(R.layout.activity_citizen);
pb_citizen = (ProgressBar) findViewById(R.id.pb_citizenact);
......@@ -81,14 +86,17 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
}
}));
}
@Override
protected void onResume() {
super.onResume();
citizensPresenter.bindView(this);
citizensPresenter.requestCitizens();
if(citizens == null)
citizensPresenter.requestCitizens();
}
@Override
......@@ -104,7 +112,6 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
}
public void showLayout(boolean enabled) {
rv_citizens.setAdapter(new CitizensArrayAdapter(this, citizens));
rv_citizens.setVisibility(View.VISIBLE);
}
......@@ -157,5 +164,4 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
}
}
......@@ -9,6 +9,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.presenters.ForgotPasswordPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.ForgotPasswordView;
/**
......@@ -32,6 +33,8 @@ public class ForgotPasswordActivity extends AppCompatActivity implements ForgotP
presenter = new ForgotPasswordPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new ForgotPasswordPresenter(this);
}
setContentView(R.layout.activity_login);
......
......@@ -33,6 +33,7 @@ import android.widget.Toast;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.presenters.HomePresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.HomeView;
/**
......@@ -61,6 +62,8 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
presenter = new HomePresenter(this);
}else{
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new HomePresenter(this);
}
setContentView(R.layout.activity_home);
......
......@@ -25,6 +25,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.presenters.LoginPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.LoginView;
/**
......@@ -50,6 +51,8 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
presenter = new LoginPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new LoginPresenter(this);
}
setContentView(R.layout.activity_login);
......
......@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import br.ufpr.c3sl.agendador.agendador.presenters.MainPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.MainView;
public class MainActivity extends AppCompatActivity implements MainView {
......@@ -17,6 +18,8 @@ public class MainActivity extends AppCompatActivity implements MainView {
presenter = new MainPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new MainPresenter(this);
}
setContentView(R.layout.activity_main);
......
package br.ufpr.c3sl.agendador.agendador;
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;
import br.ufpr.c3sl.agendador.agendador.presenters.BasePresenter;
/**
* 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
......@@ -15,7 +15,6 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
......@@ -35,6 +34,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.presenters.ScheduleConfirmationPresenter;
import br.ufpr.c3sl.agendador.agendador.views.ScheduleConfirmationView;
......@@ -68,6 +68,8 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
scheduleConfirmationPresenter = new ScheduleConfirmationPresenter(getBaseContext());
}else{
scheduleConfirmationPresenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(scheduleConfirmationPresenter == null)
scheduleConfirmationPresenter = new ScheduleConfirmationPresenter(this);
}
setContentView(R.layout.activity_schedule_confirmation);
......
......@@ -56,6 +56,7 @@ import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
import br.ufpr.c3sl.agendador.agendador.models.ServiceSchedule;
import br.ufpr.c3sl.agendador.agendador.models.ServiceType;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
import br.ufpr.c3sl.agendador.agendador.views.SchedulingView;
......@@ -88,7 +89,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private String[] days_short;
private SchedulingPresenter schedulingPresenter;
private SchedulingPresenter presenter;
private UserOutput citizen;
......@@ -142,10 +143,11 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
schedulingPresenter = new SchedulingPresenter(this);
presenter = new SchedulingPresenter(this);
} else {
schedulingPresenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new SchedulingPresenter(this);
}
setContentView(R.layout.activity_scheduling);
......@@ -291,12 +293,12 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
tv_day_month.setText(days_short[calendar.get(Calendar.DAY_OF_WEEK) - 1] + ", " +
months_short[calendar.get(Calendar.MONTH)] + " " + calendar.get(Calendar.DAY_OF_MONTH));
sectorSpinnerListener = new SectorSpinnerListener(schedulingPresenter, sectors, mcv, tv_year, tv_day_month, days_short, months_short);
sectorSpinnerListener = new SectorSpinnerListener(presenter, sectors, mcv, tv_year, tv_day_month, days_short, months_short);
spnr_sector.setOnItemSelectedListener(sectorSpinnerListener);
spnr_sector.setOnTouchListener(sectorSpinnerListener);
serviceTypeSpinnerListener = new ServiceTypeSpinnerListener(schedulingPresenter, mcv, tv_year, tv_day_month, days_short, months_short);
serviceTypeSpinnerListener = new ServiceTypeSpinnerListener(presenter, mcv, tv_year, tv_day_month, days_short, months_short);
spnr_type.setOnItemSelectedListener(serviceTypeSpinnerListener);
spnr_type.setOnTouchListener(serviceTypeSpinnerListener);
......@@ -320,7 +322,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
btn_confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
schedulingPresenter.onScheduleButtonClicked(selectedSchedule, citizen);
presenter.onScheduleButtonClicked(selectedSchedule, citizen);
}
});
}
......@@ -328,20 +330,20 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
@Override
protected void onResume() {
super.onResume();
schedulingPresenter.bindView(this);
presenter.bindView(this);
}
@Override
protected void onPause() {
super.onPause();
schedulingPresenter.unbindView();
presenter.unbindView();
}
@Override
public void onSaveInstanceState(Bundle outState) {
PresenterManager.getInstance().savePresenter(schedulingPresenter, outState);
PresenterManager.getInstance().savePresenter(presenter, outState);
super.onSaveInstanceState(outState);
}
......@@ -719,7 +721,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SchedulingActivity activity = (SchedulingActivity) getActivity();
activity.schedulingPresenter.onSignOutClicked();
activity.presenter.onSignOutClicked();
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
......
......@@ -20,6 +20,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionChecker;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.DateValidator;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.presenters.SignupPresenter;
import br.ufpr.c3sl.agendador.agendador.views.SignupView;
......@@ -48,6 +49,8 @@ public class SignupActivity extends AppCompatActivity implements SignupView {
presenter = new SignupPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new SignupPresenter(this);
}
setContentView(R.layout.activity_signup);
......
......@@ -27,12 +27,13 @@ import br.ufpr.c3sl.agendador.agendador.helpers.adapters.SectorArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.presenters.TermPresenter;
import br.ufpr.c3sl.agendador.agendador.views.TermView;
public class TermActivity extends AppCompatActivity implements TermView {
private TermPresenter termPresenter;
private TermPresenter presenter;
private List<SectorInput> sectors;
......@@ -50,9 +51,11 @@ public class TermActivity extends AppCompatActivity implements TermView {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
termPresenter = new TermPresenter(this);
presenter = new TermPresenter(this);
} else {
termPresenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new TermPresenter(this);
}
setContentView(R.layout.activity_term);
......@@ -103,27 +106,27 @@ public class TermActivity extends AppCompatActivity implements TermView {
R.drawable.item_divider)));
termPresenter.bindView(this);
termPresenter.requestSectors(citizen);
presenter.bindView(this);
presenter.requestSectors(citizen);
}
@Override
protected void onResume() {
super.onResume();
termPresenter.bindView(this);
presenter.bindView(this);
}
@Override
protected void onPause() {
super.onPause();
termPresenter.unbindView();
presenter.unbindView();
}
@Override
public void onSaveInstanceState(Bundle outState) {
PresenterManager.getInstance().savePresenter(termPresenter, outState);
PresenterManager.getInstance().savePresenter(presenter, outState);
super.onSaveInstanceState(outState);
}
......
......@@ -7,7 +7,7 @@
android:layout_height="match_parent">
<TextView
android:id="@+id/citizen_description"
android:id="@+id/dependents_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/citizen_description"
......@@ -24,7 +24,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="br.ufpr.c3sl.agendador.agendador.CitizenActivity"
android:layout_below="@+id/citizen_description"
android:layout_below="@+id/dependents_description"
android:layout_alignParentStart="true" />
......
......@@ -170,4 +170,5 @@
<string name="snackbar_home_description">Agendamento realizado</string>
<string name="scheduling_conflict">Você já possui um agendamento nesse horário.</string>
<string name="attention">Atenção!</string>
<string name="dependents_description">Selecione o dependente:</string>
</resources>
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