diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 830c6695..a286e60e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,7 +38,8 @@ + android:name=".MainActivity" + android:configChanges="orientation|screenSize|keyboardHidden"> - - + + diff --git a/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java b/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java index afa407f8..97dfc941 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java @@ -15,7 +15,6 @@ package com.keylesspalace.tusky; -import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -94,11 +93,11 @@ class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRemover { // In case of refresh, remove old ancestors and descendants first. We'll remove all blindly, // as we have no guarantee on their order to be the same as before - int old_size = statuses.size(); - if (old_size > 0) { + int oldSize = statuses.size(); + if (oldSize > 0) { mainStatus = statuses.get(statusIndex); statuses.clear(); - notifyItemRangeRemoved(0, old_size); + notifyItemRangeRemoved(0, oldSize); } // Insert newly fetched ancestors diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java index 9dcd5efa..160e438f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java @@ -15,6 +15,7 @@ package com.keylesspalace.tusky; +import android.content.res.Configuration; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -74,4 +75,11 @@ public class ViewThreadActivity extends BaseActivity implements SFragment.OnUser listener.removePostsByUser(accountId); } } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + /* Provide a stub to ignore configuration changes so the thread isn't reloaded when the + * the activity is reoriented or resized. */ + } } diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index 0cf47600..ef1fc0a7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -34,6 +34,7 @@ import com.keylesspalace.tusky.entity.StatusContext; import retrofit2.Call; import retrofit2.Callback; +import retrofit2.Response; public class ViewThreadFragment extends SFragment implements SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener { @@ -42,6 +43,7 @@ public class ViewThreadFragment extends SFragment implements private SwipeRefreshLayout swipeRefreshLayout; private RecyclerView recyclerView; private ThreadAdapter adapter; + private MastodonAPI mastodonApi; private String thisThreadsStatusId; public static ViewThreadFragment newInstance(String id) { @@ -72,25 +74,34 @@ public class ViewThreadFragment extends SFragment implements R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); - recyclerView.addItemDecoration(new ConversationLineItemDecoration(context, ContextCompat.getDrawable(context, R.drawable.conversation_divider_dark))); + recyclerView.addItemDecoration(new ConversationLineItemDecoration(context, + ContextCompat.getDrawable(context, R.drawable.conversation_divider_dark))); adapter = new ThreadAdapter(this); recyclerView.setAdapter(adapter); - String id = getArguments().getString("id"); - sendStatusRequest(id); - sendThreadRequest(id); - thisThreadsStatusId = id; + mastodonApi = null; + thisThreadsStatusId = null; return rootView; } - private void sendStatusRequest(final String id) { - MastodonAPI api = ((BaseActivity) getActivity()).mastodonAPI; + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + /* BaseActivity's MastodonAPI object isn't guaranteed to be valid until after its onCreate + * is run, so all calls that need it can't be done until here. */ + mastodonApi = ((BaseActivity) getActivity()).mastodonAPI; + + thisThreadsStatusId = getArguments().getString("id"); + onRefresh(); + } - Call call = api.status(id); + private void sendStatusRequest(final String id) { + Call call = mastodonApi.status(id); call.enqueue(new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { int position = adapter.setStatus(response.body()); recyclerView.scrollToPosition(position); @@ -108,12 +119,10 @@ public class ViewThreadFragment extends SFragment implements } private void sendThreadRequest(final String id) { - MastodonAPI api = ((BaseActivity) getActivity()).mastodonAPI; - - Call call = api.statusContext(id); + Call call = mastodonApi.statusContext(id); call.enqueue(new Callback() { @Override - public void onResponse(Call call, retrofit2.Response response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { swipeRefreshLayout.setRefreshing(false); StatusContext context = response.body();