commit 1102b25cb49dccff46aca5ed66c760375ec3607c Author: Hashik Donthineni HashikDonthineni@gmail.com Date: Sat Jul 25 18:17:03 2020 +0530
Removed onDestroy MainActivityModel --- .../main/java/org/torproject/snowflake/MainActivity.java | 6 +++--- .../org/torproject/snowflake/models/MainActivityModel.java | 14 ++------------ .../snowflake/presenters/MainActivityPresenter.java | 11 +++-------- 3 files changed, 8 insertions(+), 23 deletions(-)
diff --git a/app/src/main/java/org/torproject/snowflake/MainActivity.java b/app/src/main/java/org/torproject/snowflake/MainActivity.java index 8610b44..96b27da 100644 --- a/app/src/main/java/org/torproject/snowflake/MainActivity.java +++ b/app/src/main/java/org/torproject/snowflake/MainActivity.java @@ -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; diff --git a/app/src/main/java/org/torproject/snowflake/models/MainActivityModel.java b/app/src/main/java/org/torproject/snowflake/models/MainActivityModel.java index 8510b9e..7aaf0e5 100644 --- a/app/src/main/java/org/torproject/snowflake/models/MainActivityModel.java +++ b/app/src/main/java/org/torproject/snowflake/models/MainActivityModel.java @@ -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 diff --git a/app/src/main/java/org/torproject/snowflake/presenters/MainActivityPresenter.java b/app/src/main/java/org/torproject/snowflake/presenters/MainActivityPresenter.java index 7878f56..1958622 100644 --- a/app/src/main/java/org/torproject/snowflake/presenters/MainActivityPresenter.java +++ b/app/src/main/java/org/torproject/snowflake/presenters/MainActivityPresenter.java @@ -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 */
tor-commits@lists.torproject.org