From 90564d9b2d164d50a68c62df5d19f35e7173a291 Mon Sep 17 00:00:00 2001 From: tom79 Date: Mon, 11 Sep 2017 07:01:59 +0200 Subject: [PATCH 1/4] Fixes potential crashes --- .../fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java | 2 +- app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 57fb935bb..cca007b66 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -465,7 +465,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf //Redraws top icons (boost/reply) final float scale = context.getResources().getDisplayMetrics().density; - if( !status.getIn_reply_to_account_id().equals("null") || !status.getIn_reply_to_id().equals("null") ){ + if( (status.getIn_reply_to_account_id()!= null && !status.getIn_reply_to_account_id().equals("null")) || (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null")) ){ Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply); img.setBounds(0,0,(int) (20 * iconSizePercent/100 * scale + 0.5f),(int) (15 * iconSizePercent/100 * scale + 0.5f)); holder.status_account_displayname.setCompoundDrawables( img, null, null, null); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 7f684d329..92f295f49 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -1665,7 +1665,8 @@ public class Helper { Gson gson = new Gson(); String json = sharedpreferences.getString(Helper.SET_TEMP_STATUS + userId, null); Type type = new TypeToken>() {}.getType(); - return gson.fromJson(json, type); + ArrayList statuses = gson.fromJson(json, type); + return (statuses != null)?statuses:new ArrayList(); } From 5b6f6e928bfb058418f709530ec51084bc92ec78 Mon Sep 17 00:00:00 2001 From: tom79 Date: Mon, 11 Sep 2017 07:04:01 +0200 Subject: [PATCH 2/4] Avoids to return a null value for notifications. --- app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 92f295f49..1d9d64a5b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -1714,7 +1714,8 @@ public class Helper { Gson gson = new Gson(); String json = sharedpreferences.getString(Helper.SET_TEMP_NOTIFICATIONS + userId, null); Type type = new TypeToken>() {}.getType(); - return gson.fromJson(json, type); + ArrayList notifications = gson.fromJson(json, type); + return (notifications != null)?notifications:new ArrayList(); } } From 364b4ca7385b506482a6435a6abfd17048c0bc76 Mon Sep 17 00:00:00 2001 From: tom79 Date: Mon, 11 Sep 2017 07:11:59 +0200 Subject: [PATCH 3/4] Should fix the crash when onResume is called before data have been retrieved --- .../fr/gouv/etalab/mastodon/activities/AboutActivity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java index d5ea7e75a..1762fe4ee 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java @@ -23,7 +23,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.Button; @@ -58,8 +57,9 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveRemote private List contributors = new ArrayList<>(); private AccountSearchDevAdapter accountSearchWebAdapterDeveloper; private AccountSearchDevAdapter accountSearchWebAdapterContributors; + @SuppressWarnings("FieldCanBeLocal") + private int DEV_COUNT = 1, CONTRIBUTOR_COUNT = 2; - @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -226,12 +226,12 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveRemote @Override public void onResume(){ super.onResume(); - if( developers != null && developers.size() > 0){ + if( developers != null && developers.size() == DEV_COUNT){ for(Account account: developers){ new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } - if( contributors != null && contributors.size() > 0){ + if( contributors != null && contributors.size() == CONTRIBUTOR_COUNT){ for(Account account: contributors){ new RetrieveRelationshipAsyncTask(getApplicationContext(), account.getId(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } From 48fead3b556f9895cb7b2c6c4d107e155794ae06 Mon Sep 17 00:00:00 2001 From: tom79 Date: Mon, 11 Sep 2017 19:04:40 +0200 Subject: [PATCH 4/4] Fixes issue when adding an account --- app/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 838a98a6c..f5475c694 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,7 +46,7 @@