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;
|
2017-08-16 15:25:42 +02:00
|
|
|
import android.widget.ImageView;
|
2019-08-18 17:41:10 +02:00
|
|
|
import android.widget.LinearLayout;
|
2017-08-16 15:25:42 +02:00
|
|
|
import android.widget.TextView;
|
2017-05-30 19:31:44 +02:00
|
|
|
import android.widget.Toast;
|
2017-05-05 16:36:04 +02:00
|
|
|
|
2019-11-15 19:36:39 +01:00
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
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.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
|
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;
|
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;
|
2018-05-11 13:53:08 +02:00
|
|
|
|
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;
|
2017-06-30 19:14:25 +02:00
|
|
|
private SwipeRefreshLayout swipeRefreshLayout;
|
2017-10-14 14:36:48 +02:00
|
|
|
private RecyclerView lv_status;
|
2017-10-29 08:13:21 +01:00
|
|
|
private List<Status> statuses;
|
2017-12-20 13:57:28 +01:00
|
|
|
private StatusListAdapter statusListAdapter;
|
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;
|
2019-10-20 10:59:53 +02:00
|
|
|
private LinearLayout loader;
|
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);
|
2017-06-30 17:09:07 +02:00
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
2017-07-04 21:15:11 +02:00
|
|
|
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
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
setContentView(R.layout.activity_show_conversation);
|
2018-10-25 14:09:41 +02:00
|
|
|
lv_status = findViewById(R.id.lv_status);
|
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();
|
|
|
|
|
2019-10-20 10:59:53 +02:00
|
|
|
loader = findViewById(R.id.loader);
|
|
|
|
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);
|
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
|
|
|
}
|
2019-11-15 19:36:39 +01:00
|
|
|
Toolbar actionBar = findViewById(R.id.toolbar);
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setBackground(new ColorDrawable(ContextCompat.getColor(ShowConversationActivity.this, R.color.cyanea_primary)));
|
|
|
|
}
|
2019-11-07 19:51:53 +01:00
|
|
|
TextView title = findViewById(R.id.toolbar_title);
|
|
|
|
ImageView pp_actionBar = findViewById(R.id.pp_actionBar);
|
|
|
|
ImageView action_refresh = findViewById(R.id.action_refresh);
|
|
|
|
ImageView action_expand = findViewById(R.id.action_expand);
|
|
|
|
title.setText(R.string.conversation);
|
|
|
|
ImageView close_conversation = findViewById(R.id.close_conversation);
|
|
|
|
ImageView action_unhide = findViewById(R.id.action_unhide);
|
|
|
|
if (expanded)
|
|
|
|
action_expand.setImageResource(R.drawable.ic_expand_less);
|
|
|
|
else
|
|
|
|
action_expand.setImageResource(R.drawable.ic_expand_more);
|
2020-04-08 17:42:28 +02:00
|
|
|
title.setOnClickListener(view -> {
|
|
|
|
if (lv_status != null) {
|
|
|
|
lv_status.setAdapter(statusListAdapter);
|
2017-08-16 15:25:42 +02:00
|
|
|
}
|
2019-11-07 19:51:53 +01:00
|
|
|
});
|
|
|
|
if (close_conversation != null) {
|
2020-04-08 17:42:28 +02:00
|
|
|
close_conversation.setOnClickListener(v -> finish());
|
2019-11-07 19:51:53 +01:00
|
|
|
}
|
2020-04-08 17:42:28 +02:00
|
|
|
action_refresh.setOnClickListener(view -> {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2020-04-08 17:42:28 +02:00
|
|
|
action_unhide.setOnClickListener(v -> {
|
|
|
|
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
|
|
|
}
|
2020-04-08 17:42:28 +02:00
|
|
|
statusListAdapter.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
|
|
|
});
|
2020-04-08 17:42:28 +02:00
|
|
|
action_expand.setOnClickListener(v -> {
|
|
|
|
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();
|
2018-09-03 08:20:02 +02:00
|
|
|
finish();
|
|
|
|
}
|
2020-04-08 12:42:15 +02:00
|
|
|
Helper.loadGiF(ShowConversationActivity.this, account, pp_actionBar);
|
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);
|
2020-03-07 08:46:48 +01:00
|
|
|
statusListAdapter = new StatusListAdapter(statusDrawerParams);
|
2017-06-30 19:14:25 +02:00
|
|
|
|
2018-11-15 19:09:44 +01:00
|
|
|
final LinearLayoutManager mLayoutManager;
|
|
|
|
mLayoutManager = new LinearLayoutManager(this);
|
|
|
|
lv_status.setLayoutManager(mLayoutManager);
|
|
|
|
lv_status.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;
|
2019-02-27 10:27:01 +01:00
|
|
|
|
2021-01-19 17:43:51 +01:00
|
|
|
new RetrieveContextAsyncTask(ShowConversationActivity.this, expanded, detailsStatus.getVisibility().equals("direct"), 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);
|
2017-06-30 19:14:25 +02:00
|
|
|
});
|
2018-10-25 14:09:41 +02:00
|
|
|
|
2017-10-29 08:13:21 +01:00
|
|
|
|
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) {
|
2019-07-07 11:24:21 +02:00
|
|
|
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);
|
|
|
|
statusListAdapter.notifyItemInserted(position + 1);
|
2019-07-14 16:26:46 +02:00
|
|
|
break;
|
2019-07-07 11:24:21 +02:00
|
|
|
}
|
|
|
|
position++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-29 08:13:21 +01:00
|
|
|
|
2019-09-06 18:42:41 +02:00
|
|
|
@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) {
|
2017-06-30 19:14:25 +02:00
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
2019-10-20 10:59:53 +02:00
|
|
|
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
|
|
|
}
|
2017-05-30 19:31:44 +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) {
|
2019-09-28 18:08:07 +02:00
|
|
|
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) {
|
|
|
|
statuses.addAll(0, apiResponse.getContext().getAncestors());
|
|
|
|
statusListAdapter.notifyItemRangeInserted(0, 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());
|
|
|
|
statusListAdapter.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())) {
|
2019-02-21 19:06:04 +01:00
|
|
|
statusListAdapter.setConversationPosition(i);
|
|
|
|
detailsStatus = status;
|
|
|
|
position = i;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2019-10-31 09:58:05 +01:00
|
|
|
decorate(position);
|
2019-09-28 18:08:07 +02:00
|
|
|
statusListAdapter.notifyItemRangeChanged(1, apiResponse.getContext().getDescendants().size());
|
2019-02-21 19:06:04 +01:00
|
|
|
lv_status.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);
|
|
|
|
lv_status.setLayoutManager(mLayoutManager);
|
|
|
|
|
|
|
|
lv_status.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
|
|
|
|
2019-10-31 09:58:05 +01:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 16:32:25 +01:00
|
|
|
statusListAdapter.notifyItemRangeChanged(0, statuses.size());
|
2019-10-31 09:58:05 +01:00
|
|
|
}
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|