Fixes reorienting creating a visual duplicate of the thread. Closes #237
This commit is contained in:
parent
7749c7f70b
commit
24b7e4db4c
|
@ -38,7 +38,8 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".MainActivity" android:configChanges="orientation|screenSize|keyboardHidden">
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ComposeActivity"
|
||||
|
@ -59,8 +60,12 @@
|
|||
<data android:mimeType="image/*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ViewVideoActivity" android:configChanges="orientation|keyboardHidden|screenSize" />
|
||||
<activity android:name=".ViewThreadActivity" />
|
||||
<activity
|
||||
android:name=".ViewVideoActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize" />
|
||||
<activity
|
||||
android:name=".ViewThreadActivity"
|
||||
android:configChanges="orientation|screenSize" />
|
||||
<activity android:name=".ViewTagActivity" />
|
||||
<activity android:name=".AccountActivity" />
|
||||
<activity android:name=".EditProfileActivity" />
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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. */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
Call<Status> call = api.status(id);
|
||||
/* 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();
|
||||
}
|
||||
|
||||
private void sendStatusRequest(final String id) {
|
||||
Call<Status> call = mastodonApi.status(id);
|
||||
call.enqueue(new Callback<Status>() {
|
||||
@Override
|
||||
public void onResponse(Call<Status> call, retrofit2.Response<Status> response) {
|
||||
public void onResponse(Call<Status> call, Response<Status> 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<StatusContext> call = api.statusContext(id);
|
||||
Call<StatusContext> call = mastodonApi.statusContext(id);
|
||||
call.enqueue(new Callback<StatusContext>() {
|
||||
@Override
|
||||
public void onResponse(Call<StatusContext> call, retrofit2.Response<StatusContext> response) {
|
||||
public void onResponse(Call<StatusContext> call, Response<StatusContext> response) {
|
||||
if (response.isSuccessful()) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
StatusContext context = response.body();
|
||||
|
|
Loading…
Reference in New Issue