|
|
@ -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(); |
|
|
|