Verified Commit 1102b25c authored by HashikD's avatar HashikD
Browse files

Removed onDestroy MainActivityModel

parent e80fd014
......@@ -27,9 +27,9 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
private static final String TAG = "MainActivity";
int currentFragment;
MainActivityPresenter presenter;
private Button settingsButton;
//Indicates if model finished checking the date and reset served count if need be.
boolean isCheckDateFinished;
private Button settingsButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -136,7 +136,7 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
@Override
protected void onDestroy() {
//Detach
presenter.onDestroy();
presenter.detach();
super.onDestroy();
}
......@@ -164,7 +164,7 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
@Override
public int getServed() {
if(isCheckDateFinished)
if (isCheckDateFinished)
return presenter.getServedCount();
else
return 0;
......
......@@ -25,7 +25,6 @@ public class MainActivityModel {
private SharedPreferences sharedPreferences;
private MainActivityPresenter presenter;
private int servedCount;
private Disposable disposable;
private SharedPreferences.OnSharedPreferenceChangeListener listener;
......@@ -82,16 +81,6 @@ public class MainActivityModel {
sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}
public void onDestroy() {
Log.d(TAG, "onDestroy: ");
//Unregistering the listener.
sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener);
//Disposing off call
disposable.dispose();
//Detaching presenter
presenter = null;
}
public String getDate(String dateKey) {
return sharedPreferences.getString(dateKey, "");
}
......@@ -151,7 +140,8 @@ public class MainActivityModel {
public void checkDateAsync() {
//Launching another thread to check, reset served date if need be.
if (presenter != null) {
disposable = Single.fromCallable(this::checkServedDate)
//By this point the servedCount must be reset or left as is after checking the dates.
Single.fromCallable(this::checkServedDate)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((status) -> { //Runs on main thread
......
......@@ -23,10 +23,8 @@ public class MainActivityPresenter {
/**
* Cleaning
*/
public void onDestroy() {
Log.d(TAG, "onDestroy: ");
//Calling on Destroy on model
model.onDestroy();
public void detach() {
Log.d(TAG, "detach: ");
//Detaching
view = null;
}
......@@ -83,16 +81,13 @@ public class MainActivityPresenter {
* Getting the served date.
*/
public String getDate() {
return model.getDate(((MainActivity) view).getString(R.string.served_date_key));
return model.getDate("date");
}
public void checkDate() {
model.checkDateAsync();
}
public void setListenerForCount() {
}
/**
* View for the MainActivity
*/
......
Supports Markdown
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