From 19e272582463e86c2eba6d7624de6d91572e679a Mon Sep 17 00:00:00 2001 From: Vavassor Date: Wed, 15 Mar 2017 15:27:49 -0400 Subject: [PATCH] Fixes intermittent crashes when clicking the reply button and opening a thread. Closes #26 --- .../keylesspalace/tusky/LoginActivity.java | 3 ++- .../com/keylesspalace/tusky/SFragment.java | 3 +-- .../tusky/ViewThreadFragment.java | 21 +++++++++++-------- .../keylesspalace/tusky/entity/Status.java | 4 ++++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 91b05a32..0dbfdf13 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; @@ -41,7 +42,7 @@ import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; -public class LoginActivity extends BaseActivity { +public class LoginActivity extends AppCompatActivity { private static final String TAG = "LoginActivity"; // logging tag private static String OAUTH_SCOPES = "read write follow"; diff --git a/app/src/main/java/com/keylesspalace/tusky/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/SFragment.java index 967a0e03..3dacaeba 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/SFragment.java @@ -19,7 +19,6 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import android.provider.ContactsContract; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentTransaction; @@ -74,7 +73,7 @@ public class SFragment extends BaseFragment { mentionedUsernames.remove(loggedInUsername); Intent intent = new Intent(getContext(), ComposeActivity.class); intent.putExtra("in_reply_to_id", inReplyToId); - intent.putExtra("reply_visibility", status.visibility.toString().toLowerCase()); + intent.putExtra("reply_visibility", status.getVisibility().toString().toLowerCase()); intent.putExtra("mentioned_usernames", mentionedUsernames.toArray(new String[0])); startActivity(intent); } diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index 11120541..df35e88f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -125,15 +125,18 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene } private void onThreadRequestFailure(final String id) { - Snackbar.make(recyclerView, R.string.error_view_thread, Snackbar.LENGTH_LONG) - .setAction(R.string.action_retry, new View.OnClickListener() { - @Override - public void onClick(View v) { - sendThreadRequest(id); - sendStatusRequest(id); - } - }) - .show(); + View view = getView(); + if (view != null) { + Snackbar.make(view, R.string.error_view_thread, Snackbar.LENGTH_LONG) + .setAction(R.string.action_retry, new View.OnClickListener() { + @Override + public void onClick(View v) { + sendThreadRequest(id); + sendStatusRequest(id); + } + }) + .show(); + } } public void onReply(int position) { diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Status.java b/app/src/main/java/com/keylesspalace/tusky/entity/Status.java index 39378ee9..2e354da6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Status.java +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Status.java @@ -77,6 +77,10 @@ public class Status { public Visibility visibility; + public Visibility getVisibility() { + return visibility == null ? Visibility.UNLISTED : visibility; + } + @SerializedName("media_attachments") public MediaAttachment[] attachments;