Fixes reorienting creating a visual duplicate of the thread. Closes #237

main
Vavassor 8 years ago
parent 144b4d6474
commit 9f78d7a9b8
  1. 11
      app/src/main/AndroidManifest.xml
  2. 7
      app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java
  3. 8
      app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java
  4. 35
      app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java

@ -38,7 +38,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".MainActivity" android:configChanges="orientation|screenSize|keyboardHidden"> android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden">
</activity> </activity>
<activity <activity
android:name=".ComposeActivity" android:name=".ComposeActivity"
@ -59,8 +60,12 @@
<data android:mimeType="image/*" /> <data android:mimeType="image/*" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".ViewVideoActivity" android:configChanges="orientation|keyboardHidden|screenSize" /> <activity
<activity android:name=".ViewThreadActivity" /> android:name=".ViewVideoActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name=".ViewThreadActivity"
android:configChanges="orientation|screenSize" />
<activity android:name=".ViewTagActivity" /> <activity android:name=".ViewTagActivity" />
<activity android:name=".AccountActivity" /> <activity android:name=".AccountActivity" />
<activity android:name=".EditProfileActivity" /> <activity android:name=".EditProfileActivity" />

@ -15,7 +15,6 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; 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, // 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 // as we have no guarantee on their order to be the same as before
int old_size = statuses.size(); int oldSize = statuses.size();
if (old_size > 0) { if (oldSize > 0) {
mainStatus = statuses.get(statusIndex); mainStatus = statuses.get(statusIndex);
statuses.clear(); statuses.clear();
notifyItemRangeRemoved(0, old_size); notifyItemRangeRemoved(0, oldSize);
} }
// Insert newly fetched ancestors // Insert newly fetched ancestors

@ -15,6 +15,7 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -74,4 +75,11 @@ public class ViewThreadActivity extends BaseActivity implements SFragment.OnUser
listener.removePostsByUser(accountId); 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. */
}
} }

@ -34,6 +34,7 @@ import com.keylesspalace.tusky.entity.StatusContext;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response;
public class ViewThreadFragment extends SFragment implements public class ViewThreadFragment extends SFragment implements
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener { SwipeRefreshLayout.OnRefreshListener, StatusActionListener, StatusRemoveListener {
@ -42,6 +43,7 @@ public class ViewThreadFragment extends SFragment implements
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
private RecyclerView recyclerView; private RecyclerView recyclerView;
private ThreadAdapter adapter; private ThreadAdapter adapter;
private MastodonAPI mastodonApi;
private String thisThreadsStatusId; private String thisThreadsStatusId;
public static ViewThreadFragment newInstance(String id) { public static ViewThreadFragment newInstance(String id) {
@ -72,25 +74,34 @@ public class ViewThreadFragment extends SFragment implements
R.drawable.status_divider_dark); R.drawable.status_divider_dark);
divider.setDrawable(drawable); divider.setDrawable(drawable);
recyclerView.addItemDecoration(divider); 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); adapter = new ThreadAdapter(this);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
String id = getArguments().getString("id"); mastodonApi = null;
sendStatusRequest(id); thisThreadsStatusId = null;
sendThreadRequest(id);
thisThreadsStatusId = id;
return rootView; return rootView;
} }
private void sendStatusRequest(final String id) { @Override
MastodonAPI api = ((BaseActivity) getActivity()).mastodonAPI; 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;
Call<Status> call = api.status(id); thisThreadsStatusId = getArguments().getString("id");
onRefresh();
}
private void sendStatusRequest(final String id) {
Call<Status> call = mastodonApi.status(id);
call.enqueue(new Callback<Status>() { call.enqueue(new Callback<Status>() {
@Override @Override
public void onResponse(Call<Status> call, retrofit2.Response<Status> response) { public void onResponse(Call<Status> call, Response<Status> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
int position = adapter.setStatus(response.body()); int position = adapter.setStatus(response.body());
recyclerView.scrollToPosition(position); recyclerView.scrollToPosition(position);
@ -108,12 +119,10 @@ public class ViewThreadFragment extends SFragment implements
} }
private void sendThreadRequest(final String id) { private void sendThreadRequest(final String id) {
MastodonAPI api = ((BaseActivity) getActivity()).mastodonAPI; Call<StatusContext> call = mastodonApi.statusContext(id);
Call<StatusContext> call = api.statusContext(id);
call.enqueue(new Callback<StatusContext>() { call.enqueue(new Callback<StatusContext>() {
@Override @Override
public void onResponse(Call<StatusContext> call, retrofit2.Response<StatusContext> response) { public void onResponse(Call<StatusContext> call, Response<StatusContext> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
StatusContext context = response.body(); StatusContext context = response.body();

Loading…
Cancel
Save