fedilab-Android-App/app/src/main/java/app/fedilab/android/activities/ShowConversationActivity.java

443 lines
20 KiB
Java
Raw Normal View History

2017-05-05 16:36:04 +02:00
/* Copyright 2017 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* This file is a part of Fedilab
2017-05-05 16:36:04 +02:00
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
2019-05-18 11:10:30 +02:00
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2017-05-05 16:36:04 +02:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
2017-05-05 16:36:04 +02:00
* see <http://www.gnu.org/licenses>. */
2019-05-18 11:10:30 +02:00
package app.fedilab.android.activities;
2017-05-05 16:36:04 +02:00
2019-01-11 17:57:01 +01:00
import android.content.BroadcastReceiver;
2018-11-16 15:39:53 +01:00
import android.content.Intent;
2019-01-11 17:57:01 +01:00
import android.content.IntentFilter;
2017-05-05 16:36:04 +02:00
import android.content.SharedPreferences;
2017-08-16 15:25:42 +02:00
import android.database.sqlite.SQLiteDatabase;
2019-11-15 19:36:39 +01:00
import android.graphics.drawable.ColorDrawable;
2017-05-05 16:36:04 +02:00
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
2017-05-05 16:36:04 +02:00
2019-11-15 19:36:39 +01:00
import androidx.core.content.ContextCompat;
2019-11-15 16:32:25 +01:00
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
2021-01-29 18:02:32 +01:00
import org.json.JSONException;
import org.json.JSONObject;
2020-04-25 19:20:42 +02:00
import java.lang.ref.WeakReference;
2017-05-05 16:36:04 +02:00
import java.util.ArrayList;
import java.util.List;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.R;
import app.fedilab.android.asynctasks.RetrieveContextAsyncTask;
2020-03-07 12:27:46 +01:00
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
2019-09-28 18:08:07 +02:00
import app.fedilab.android.client.APIResponse;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Status;
2020-03-07 08:46:48 +01:00
import app.fedilab.android.client.Entities.StatusDrawerParams;
2021-01-29 18:02:32 +01:00
import app.fedilab.android.client.PixelfedAPI;
import app.fedilab.android.databinding.ActivityShowConversationBinding;
import app.fedilab.android.drawers.PixelfedListAdapter;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.drawers.StatusListAdapter;
import app.fedilab.android.helper.Helper;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.interfaces.OnRetrieveContextInterface;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite;
2018-11-25 10:45:16 +01:00
import es.dmoral.toasty.Toasty;
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 04/05/2017.
* Show conversation activity class
*/
2019-09-06 17:55:14 +02:00
public class ShowConversationActivity extends BaseActivity implements OnRetrieveContextInterface {
2017-05-05 16:36:04 +02:00
private Status initialStatus;
2018-11-15 19:09:44 +01:00
private Status detailsStatus;
private SwipeRefreshLayout swipeRefreshLayout;
private List<Status> statuses;
2017-12-20 13:57:28 +01:00
private StatusListAdapter statusListAdapter;
2021-01-29 18:02:32 +01:00
private PixelfedListAdapter pixelfedListAdapter;
2018-03-15 18:28:12 +01:00
private boolean expanded;
2019-01-11 17:57:01 +01:00
private BroadcastReceiver receive_action;
2019-02-21 19:06:04 +01:00
private String conversationId;
2019-06-06 14:16:33 +02:00
private boolean spoilerShown, spoilerBehaviour;
2021-01-29 18:02:32 +01:00
private ActivityShowConversationBinding binding;
2018-03-15 18:28:12 +01:00
2017-05-05 16:36:04 +02:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
2019-05-18 11:10:30 +02:00
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
2019-11-09 17:11:55 +01:00
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack_NoActionBar);
break;
default:
setTheme(R.style.AppThemeDark_NoActionBar);
2017-06-30 17:09:07 +02:00
}
2021-01-29 18:02:32 +01:00
binding = ActivityShowConversationBinding.inflate(getLayoutInflater());
View viewRoot = binding.getRoot();
setContentView(viewRoot);
2019-09-06 17:55:14 +02:00
spoilerShown = spoilerBehaviour = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
2018-03-15 18:28:12 +01:00
Bundle b = getIntent().getExtras();
2018-11-15 19:09:44 +01:00
statuses = new ArrayList<>();
2019-09-06 17:55:14 +02:00
if (b != null) {
2018-11-15 19:09:44 +01:00
detailsStatus = b.getParcelable("status");
2019-09-06 17:55:14 +02:00
expanded = b.getBoolean("expanded", false);
2018-11-16 15:39:53 +01:00
initialStatus = b.getParcelable("initialStatus");
2019-09-06 17:55:14 +02:00
conversationId = b.getString("conversationId", null);
2018-11-16 15:39:53 +01:00
}
2019-09-06 17:55:14 +02:00
if (detailsStatus == null || detailsStatus.getId() == null)
2018-03-15 18:28:12 +01:00
finish();
2021-01-29 18:02:32 +01:00
binding.loader.setVisibility(View.VISIBLE);
2019-08-18 17:53:56 +02:00
detailsStatus.setFocused(true);
2020-04-08 17:56:59 +02:00
//Some spannable
2020-04-25 19:20:42 +02:00
Status.fillSpan(new WeakReference<>(ShowConversationActivity.this), detailsStatus);
2019-08-18 17:53:56 +02:00
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
2019-01-11 17:57:01 +01:00
2019-09-06 17:55:14 +02:00
if (receive_action != null)
2020-04-08 12:42:15 +02:00
LocalBroadcastManager.getInstance(ShowConversationActivity.this).unregisterReceiver(receive_action);
2019-01-11 17:57:01 +01:00
receive_action = new BroadcastReceiver() {
@Override
public void onReceive(android.content.Context context, Intent intent) {
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
2019-09-06 17:55:14 +02:00
if (status != null && statusListAdapter != null) {
2019-11-22 19:33:32 +01:00
statusListAdapter.notifyStatusChanged(status);
2021-01-29 18:02:32 +01:00
} else if (status != null && pixelfedListAdapter != null) {
pixelfedListAdapter.notifyStatusChanged(status);
2019-01-11 17:57:01 +01:00
}
}
};
2020-04-08 12:42:15 +02:00
LocalBroadcastManager.getInstance(ShowConversationActivity.this).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_ACTION));
2019-01-11 17:57:01 +01:00
}
2021-01-29 18:02:32 +01:00
binding.incToolbar.toolbar.setBackground(new ColorDrawable(ContextCompat.getColor(ShowConversationActivity.this, R.color.cyanea_primary)));
binding.incToolbar.toolbarTitle.setText(R.string.conversation);
2019-11-07 19:51:53 +01:00
if (expanded)
2021-01-29 18:02:32 +01:00
binding.incToolbar.actionExpand.setImageResource(R.drawable.ic_expand_less);
2019-11-07 19:51:53 +01:00
else
2021-01-29 18:02:32 +01:00
binding.incToolbar.actionExpand.setImageResource(R.drawable.ic_expand_more);
//Scroll to top
binding.incToolbar.toolbarTitle.setOnClickListener(view -> {
if (statusListAdapter != null) {
binding.lvStatus.setAdapter(statusListAdapter);
} else if (pixelfedListAdapter != null) {
binding.lvStatus.setAdapter(pixelfedListAdapter);
2017-08-16 15:25:42 +02:00
}
2019-11-07 19:51:53 +01:00
});
2021-01-29 18:02:32 +01:00
binding.incToolbar.closeConversation.setOnClickListener(v -> finish());
binding.incToolbar.actionRefresh.setOnClickListener(view -> {
2020-04-08 17:42:28 +02:00
Intent intent = new Intent(ShowConversationActivity.this, ShowConversationActivity.class);
Bundle b1 = new Bundle();
b1.putParcelable("status", detailsStatus);
b1.putBoolean("expanded", expanded);
if (expanded && statuses != null && statuses.size() > 0)
b1.putParcelable("initialStatus", statuses.get(0));
intent.putExtras(b1);
finish();
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
2019-11-07 19:51:53 +01:00
});
2021-01-29 18:02:32 +01:00
binding.incToolbar.actionUnhide.setOnClickListener(v -> {
2020-04-08 17:42:28 +02:00
if (statuses != null && statuses.size() > 0) {
spoilerShown = !spoilerShown;
for (Status status : statuses) {
2021-01-10 18:41:50 +01:00
status.setAutoHiddenCW(spoilerBehaviour && !status.isSpoilerShown());
2020-04-08 17:42:28 +02:00
status.setSpoilerShown(spoilerShown);
status.setShowSpoiler(spoilerShown);
2019-01-31 18:01:08 +01:00
}
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statusListAdapter.notifyItemRangeChanged(0, statuses.size());
} else if (pixelfedListAdapter != null) {
pixelfedListAdapter.notifyItemRangeChanged(0, statuses.size());
}
2019-11-07 19:51:53 +01:00
}
2020-04-08 17:42:28 +02:00
2019-11-07 19:51:53 +01:00
});
2021-01-29 18:02:32 +01:00
binding.incToolbar.actionExpand.setOnClickListener(v -> {
2020-04-08 17:42:28 +02:00
expanded = !expanded;
Intent intent = new Intent(ShowConversationActivity.this, ShowConversationActivity.class);
Bundle b12 = new Bundle();
b12.putParcelable("status", detailsStatus);
b12.putBoolean("expanded", expanded);
if (expanded && statuses != null && statuses.size() > 0)
b12.putParcelable("initialStatus", statuses.get(0));
intent.putExtras(b12);
finish();
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
2018-03-15 18:28:12 +01:00
2019-11-07 19:51:53 +01:00
});
2017-12-26 10:06:22 +01:00
2020-04-09 18:57:12 +02:00
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
2017-08-16 15:25:42 +02:00
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
2019-06-05 14:35:42 +02:00
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null);
2020-04-08 12:42:15 +02:00
Account account = new AccountDAO(ShowConversationActivity.this, db).getUniqAccount(userId, instance);
2019-09-06 17:55:14 +02:00
if (account.getAvatar() == null) {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowConversationActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
finish();
}
2021-01-29 18:02:32 +01:00
Helper.loadGiF(ShowConversationActivity.this, account, binding.incToolbar.ppActionBar);
2018-03-15 18:28:12 +01:00
2017-08-16 15:25:42 +02:00
2017-10-21 12:32:27 +02:00
swipeRefreshLayout = findViewById(R.id.swipeContainer);
2019-11-12 19:22:14 +01:00
int c1 = getResources().getColor(R.color.cyanea_accent);
int c2 = getResources().getColor(R.color.cyanea_primary_dark);
int c3 = getResources().getColor(R.color.cyanea_primary);
2019-11-12 19:08:05 +01:00
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(c3);
swipeRefreshLayout.setColorSchemeColors(
c1, c2, c1
);
2020-04-08 12:42:15 +02:00
boolean isOnWifi = Helper.isOnWIFI(ShowConversationActivity.this);
2019-09-06 17:55:14 +02:00
if (initialStatus != null)
2018-11-16 15:39:53 +01:00
statuses.add(initialStatus);
else
statuses.add(detailsStatus);
2020-03-07 08:46:48 +01:00
StatusDrawerParams statusDrawerParams = new StatusDrawerParams();
statusDrawerParams.setPosition(0);
statusDrawerParams.setTargetedId(null);
statusDrawerParams.setOnWifi(isOnWifi);
statusDrawerParams.setStatuses(statuses);
2020-03-07 12:27:46 +01:00
statusDrawerParams.setType(RetrieveFeedsAsyncTask.Type.CONTEXT);
2018-11-15 19:09:44 +01:00
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(this);
2021-01-29 18:02:32 +01:00
binding.lvStatus.setLayoutManager(mLayoutManager);
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
pixelfedListAdapter = new PixelfedListAdapter(statusDrawerParams);
binding.lvStatus.setAdapter(pixelfedListAdapter);
} else {
statusListAdapter = new StatusListAdapter(statusDrawerParams);
binding.lvStatus.setAdapter(statusListAdapter);
}
2018-11-16 16:35:25 +01:00
String statusIdToFetch = null;
2019-09-06 17:55:14 +02:00
if (initialStatus != null)
2018-11-16 15:39:53 +01:00
statusIdToFetch = initialStatus.getId();
2019-09-06 17:55:14 +02:00
else if (detailsStatus != null)
2018-11-16 15:39:53 +01:00
statusIdToFetch = detailsStatus.getId();
2019-09-06 17:55:14 +02:00
if (statusIdToFetch == null)
2018-11-16 16:35:25 +01:00
finish();
2019-09-06 17:55:14 +02:00
if (conversationId != null)
2019-02-21 19:06:04 +01:00
statusIdToFetch = conversationId;
2021-01-29 18:02:32 +01:00
new RetrieveContextAsyncTask(ShowConversationActivity.this, expanded, detailsStatus.getVisibility().equals("direct"), detailsStatus.getAccount().getId(), statusIdToFetch, ShowConversationActivity.this);
2019-07-07 18:08:52 +02:00
swipeRefreshLayout.setDistanceToTriggerSync(500);
2020-04-08 17:42:28 +02:00
swipeRefreshLayout.setOnRefreshListener(() -> {
Intent intent = new Intent(ShowConversationActivity.this, ShowConversationActivity.class);
Bundle b13 = new Bundle();
b13.putParcelable("status", detailsStatus);
b13.putBoolean("expanded", expanded);
if (expanded && statuses != null && statuses.size() > 0)
b13.putParcelable("initialStatus", statuses.get(0));
b13.putParcelable("status", detailsStatus);
intent.putExtras(b13);
finish();
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
});
2018-10-25 14:09:41 +02:00
2021-01-29 18:02:32 +01:00
//Searching some pixelfed info (bookmarked?)
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
new Thread(() -> {
JSONObject result = new PixelfedAPI(ShowConversationActivity.this).getPostDetails(detailsStatus.getAccount().getUsername(), detailsStatus.getId());
if (result != null && result.has("bookmarked")) {
try {
boolean bookmarked = result.getBoolean("bookmarked");
statuses.get(0).setBookmarked(bookmarked);
runOnUiThread(() -> {
pixelfedListAdapter.notifyItemChanged(0);
});
} catch (JSONException e) {
e.printStackTrace();
}
}
}).start();
}
2017-05-05 16:36:04 +02:00
}
2019-09-06 17:55:14 +02:00
public void addStatuses(Status status) {
if (status != null && status.getIn_reply_to_id() != null && this.statuses != null) {
int position = 0;
2019-09-06 17:55:14 +02:00
for (Status s : this.statuses) {
if (status.getIn_reply_to_id().equals(s.getId())) {
this.statuses.add(position + 1, status);
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statusListAdapter.notifyItemInserted(position + 1);
} else if (pixelfedListAdapter != null) {
pixelfedListAdapter.notifyItemInserted(position + 1);
}
break;
}
position++;
}
}
}
@Override
public void onStop() {
super.onStop();
if (statusListAdapter != null) {
statusListAdapter.storeToot();
}
}
2017-05-05 16:36:04 +02:00
2019-01-11 17:57:01 +01:00
@Override
public void onDestroy() {
super.onDestroy();
2019-09-06 17:55:14 +02:00
if (receive_action != null)
2020-04-08 12:42:15 +02:00
LocalBroadcastManager.getInstance(ShowConversationActivity.this).unregisterReceiver(receive_action);
2020-04-11 19:18:08 +02:00
detailsStatus = null;
2019-01-11 17:57:01 +01:00
}
2017-05-05 16:36:04 +02:00
@Override
2019-09-28 18:08:07 +02:00
public void onRetrieveContext(APIResponse apiResponse) {
swipeRefreshLayout.setRefreshing(false);
2021-01-29 18:02:32 +01:00
binding.loader.setVisibility(View.GONE);
2019-09-28 18:08:07 +02:00
if (apiResponse.getError() != null) {
2019-11-15 16:32:25 +01:00
if (apiResponse.getError().getError() != null) {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowConversationActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
2019-11-15 16:32:25 +01:00
} else {
2020-04-08 12:42:15 +02:00
Toasty.error(ShowConversationActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
2019-09-28 18:08:07 +02:00
}
return;
}
2019-09-28 18:08:07 +02:00
if (apiResponse.getContext() == null || apiResponse.getContext().getAncestors() == null) {
2018-11-17 14:31:03 +01:00
return;
}
2019-10-31 09:58:05 +01:00
if (BaseMainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && BaseMainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statusListAdapter.setConversationPosition(apiResponse.getContext().getAncestors().size());
}
2019-09-06 17:55:14 +02:00
if (!expanded) {
2019-09-28 18:08:07 +02:00
if (apiResponse.getContext().getAncestors() != null && apiResponse.getContext().getAncestors().size() > 0) {
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statuses.addAll(0, apiResponse.getContext().getAncestors());
statusListAdapter.notifyItemRangeInserted(0, apiResponse.getContext().getAncestors().size());
} else if (pixelfedListAdapter != null) {
statuses.addAll(1, apiResponse.getContext().getAncestors());
pixelfedListAdapter.notifyItemRangeInserted(1, apiResponse.getContext().getAncestors().size());
}
2019-02-21 19:06:04 +01:00
}
2019-11-15 16:32:25 +01:00
int targetedPosition = statuses.size() - 1;
2019-09-28 18:08:07 +02:00
if (apiResponse.getContext().getDescendants() != null && apiResponse.getContext().getDescendants().size() > 0) {
statuses.addAll(apiResponse.getContext().getAncestors().size() + 1, apiResponse.getContext().getDescendants());
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statusListAdapter.notifyItemRangeChanged(apiResponse.getContext().getAncestors().size() + 1, apiResponse.getContext().getDescendants().size());
} else if (pixelfedListAdapter != null) {
pixelfedListAdapter.notifyItemRangeChanged(apiResponse.getContext().getAncestors().size() + 1, apiResponse.getContext().getDescendants().size());
}
2019-02-21 19:06:04 +01:00
}
2019-10-31 09:58:05 +01:00
decorate(targetedPosition);
2019-09-06 17:55:14 +02:00
} else {
2019-09-28 18:08:07 +02:00
List<Status> statusesTemp = apiResponse.getContext().getDescendants();
2019-02-21 19:06:04 +01:00
int i = 1;
int position = 0;
2019-09-06 17:55:14 +02:00
for (Status status : statusesTemp) {
2019-02-21 19:06:04 +01:00
statuses.add(status);
2019-09-06 17:55:14 +02:00
if (status.getId().equals(detailsStatus.getId())) {
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statusListAdapter.setConversationPosition(i);
}
2019-02-21 19:06:04 +01:00
detailsStatus = status;
position = i;
}
i++;
}
2019-10-31 09:58:05 +01:00
decorate(position);
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statusListAdapter.notifyItemRangeChanged(1, apiResponse.getContext().getDescendants().size());
} else if (pixelfedListAdapter != null) {
pixelfedListAdapter.notifyItemRangeChanged(1, apiResponse.getContext().getDescendants().size());
}
binding.lvStatus.scrollToPosition(position);
2017-05-05 16:36:04 +02:00
}
2019-09-06 17:55:14 +02:00
} else {
2019-02-21 19:06:04 +01:00
int i = 0;
2019-09-28 18:08:07 +02:00
if (apiResponse.getContext().getAncestors() != null && apiResponse.getContext().getAncestors().size() > 1) {
2019-02-21 19:06:04 +01:00
statuses = new ArrayList<>();
statuses.clear();
2019-09-28 18:08:07 +02:00
for (Status status : apiResponse.getContext().getAncestors()) {
2020-07-24 19:52:36 +02:00
if (detailsStatus != null && detailsStatus.equals(status)) {
2019-02-21 19:06:04 +01:00
break;
}
i++;
}
2020-04-08 12:42:15 +02:00
boolean isOnWifi = Helper.isOnWIFI(ShowConversationActivity.this);
2019-09-28 18:08:07 +02:00
for (Status status : apiResponse.getContext().getAncestors()) {
2019-09-06 17:55:14 +02:00
statuses.add(0, status);
2019-02-21 19:06:04 +01:00
}
2020-03-07 08:46:48 +01:00
StatusDrawerParams statusDrawerParams = new StatusDrawerParams();
statusDrawerParams.setPosition((statuses.size() - 1 - i));
statusDrawerParams.setTargetedId(null);
statusDrawerParams.setOnWifi(isOnWifi);
statusDrawerParams.setStatuses(statuses);
2020-03-07 12:27:46 +01:00
statusDrawerParams.setType(RetrieveFeedsAsyncTask.Type.CONTEXT);
2020-03-07 08:46:48 +01:00
statusListAdapter = new StatusListAdapter(statusDrawerParams);
2019-09-06 17:55:14 +02:00
statusListAdapter.setConversationPosition((statuses.size() - 1 - i));
2019-10-31 09:58:05 +01:00
decorate(0);
2019-02-21 19:06:04 +01:00
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(this);
2021-01-29 18:02:32 +01:00
binding.lvStatus.setLayoutManager(mLayoutManager);
2019-02-21 19:06:04 +01:00
2021-01-29 18:02:32 +01:00
binding.lvStatus.setAdapter(statusListAdapter);
2017-12-20 13:57:28 +01:00
}
}
2019-02-21 19:06:04 +01:00
2017-12-20 13:57:28 +01:00
}
2018-11-16 15:39:53 +01:00
2021-01-29 18:02:32 +01:00
//Add lines and offset to messages
2019-11-15 16:32:25 +01:00
private void decorate(int targetedPosition) {
for (int i = 0; i < statuses.size(); i++) {
2019-10-31 09:58:05 +01:00
if (i == targetedPosition) {
2019-11-15 16:32:25 +01:00
if (targetedPosition < statuses.size() - 1)
2019-10-31 09:58:05 +01:00
statuses.get(targetedPosition).setShowBottomLine(true);
2020-03-28 17:18:23 +01:00
if (targetedPosition > 0 && statuses.get(targetedPosition).getIn_reply_to_id() != null && statuses.get(targetedPosition).getIn_reply_to_id().compareTo(statuses.get(targetedPosition - 1).getId()) == 0) {
2019-11-15 16:32:25 +01:00
statuses.get(targetedPosition - 1).setShowBottomLine(true);
2019-10-31 09:58:05 +01:00
statuses.get(targetedPosition).setShowTopLine(true);
}
} else if (0 < i && i <= statuses.size() - 1) {
2020-03-28 17:18:23 +01:00
if (statuses.get(i).getIn_reply_to_id() != null && statuses.get(i - 1).getId().compareTo(statuses.get(i).getIn_reply_to_id()) == 0) {
2019-11-15 16:32:25 +01:00
statuses.get(i - 1).setShowBottomLine(true);
2019-10-31 09:58:05 +01:00
statuses.get(i).setShowTopLine(true);
}
}
}
2021-01-29 18:02:32 +01:00
if (statusListAdapter != null) {
statusListAdapter.notifyItemRangeChanged(0, statuses.size());
} else if (pixelfedListAdapter != null) {
pixelfedListAdapter.notifyItemRangeChanged(0, statuses.size());
}
2019-10-31 09:58:05 +01:00
}
2017-05-05 16:36:04 +02:00
}