remote info

This commit is contained in:
Thomas 2023-03-14 16:15:22 +01:00
parent 569e4c680e
commit 20c797520e
4 changed files with 58 additions and 57 deletions

View file

@ -15,6 +15,9 @@ package app.fedilab.android.mastodon.activities;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.currentToken;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
@ -24,10 +27,11 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityStatusInfoBinding;
import app.fedilab.android.mastodon.client.entities.api.Account;
@ -50,6 +54,9 @@ public class StatusInfoActivity extends BaseActivity {
private boolean flagLoading;
private Status status;
private boolean checkRemotely;
private String instance, token;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -62,20 +69,41 @@ public class StatusInfoActivity extends BaseActivity {
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
accountList = new ArrayList<>();
checkRemotely = false;
Bundle b = getIntent().getExtras();
if (b != null) {
type = (typeOfInfo) b.getSerializable(Helper.ARG_TYPE_OF_INFO);
status = (Status) b.getSerializable(Helper.ARG_STATUS);
checkRemotely = b.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
}
if (type == null || status == null) {
finish();
return;
}
token = currentToken;
instance = currentInstance;
if (checkRemotely) {
try {
URL url = new URL(status.uri);
instance = url.getHost();
} catch (MalformedURLException e) {
e.printStackTrace();
}
token = null;
if (instance != null && instance.equalsIgnoreCase(currentInstance)) {
checkRemotely = false;
instance = currentInstance;
token = currentToken;
}
}
flagLoading = false;
max_id = null;
setTitle("");
binding.title.setText(type == typeOfInfo.BOOSTED_BY ? R.string.boosted_by : R.string.favourited_by);
StatusesVM statusesVM = new ViewModelProvider(StatusInfoActivity.this).get(StatusesVM.class);
accountAdapter = new AccountAdapter(accountList);
accountAdapter = new AccountAdapter(accountList, false, checkRemotely ? instance : null);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(StatusInfoActivity.this);
binding.lvAccounts.setLayoutManager(mLayoutManager);
binding.lvAccounts.setAdapter(accountAdapter);
@ -92,9 +120,9 @@ public class StatusInfoActivity extends BaseActivity {
flagLoading = true;
binding.loadingNextAccounts.setVisibility(View.VISIBLE);
if (type == typeOfInfo.BOOSTED_BY) {
statusesVM.rebloggedBy(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, max_id, null, null).observe(StatusInfoActivity.this, accounts -> manageView(accounts));
statusesVM.rebloggedBy(instance, token, status.id, max_id, null, null).observe(StatusInfoActivity.this, accounts -> manageView(accounts));
} else if (type == typeOfInfo.LIKED_BY) {
statusesVM.favouritedBy(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, max_id, null, null).observe(StatusInfoActivity.this, accounts -> manageView(accounts));
statusesVM.favouritedBy(instance, token, status.id, max_id, null, null).observe(StatusInfoActivity.this, accounts -> manageView(accounts));
}
}
} else {
@ -104,9 +132,9 @@ public class StatusInfoActivity extends BaseActivity {
}
});
if (type == typeOfInfo.BOOSTED_BY) {
statusesVM.rebloggedBy(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null, null, null).observe(StatusInfoActivity.this, this::manageView);
statusesVM.rebloggedBy(instance, token, status.id, null, null, null).observe(StatusInfoActivity.this, this::manageView);
} else if (type == typeOfInfo.LIKED_BY) {
statusesVM.favouritedBy(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null, null, null).observe(StatusInfoActivity.this, this::manageView);
statusesVM.favouritedBy(instance, token, status.id, null, null, null).observe(StatusInfoActivity.this, this::manageView);
}
}
@ -114,7 +142,9 @@ public class StatusInfoActivity extends BaseActivity {
binding.loadingNextAccounts.setVisibility(View.GONE);
if (accountList != null && accounts != null && accounts.accounts != null) {
int position = this.accountList.size();
if (!checkRemotely) {
fetchRelationShip(accounts.accounts, position);
}
int startId = 0;
//There are some statuses present in the timeline
if (accountList.size() > 0) {
@ -133,7 +163,7 @@ public class StatusInfoActivity extends BaseActivity {
ids.add(account.id);
}
AccountsVM accountsVM = new ViewModelProvider(StatusInfoActivity.this).get(AccountsVM.class);
accountsVM.getRelationships(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, ids)
accountsVM.getRelationships(instance, token, ids)
.observe(StatusInfoActivity.this, relationShips -> {
if (relationShips != null) {
for (RelationShip relationShip : relationShips) {

View file

@ -1758,57 +1758,23 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance());
holder.binding.reblogInfo.setOnClickListener(v -> {
if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
if (fetchedStatus.reblogs_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY);
intent.putExtra(Helper.ARG_STATUS, fetchedStatus);
context.startActivity(intent);
}
} else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
}
});
} else {
if (statusToDeal.reblogs_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY);
intent.putExtra(Helper.ARG_STATUS, statusToDeal);
intent.putExtra(Helper.ARG_CHECK_REMOTELY, remote);
context.startActivity(intent);
}
}
});
holder.binding.favouriteInfo.setOnClickListener(v -> {
if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
if (fetchedStatus.favourites_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY);
intent.putExtra(Helper.ARG_STATUS, fetchedStatus);
context.startActivity(intent);
}
} else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
}
});
} else {
if (statusToDeal.favourites_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY);
intent.putExtra(Helper.ARG_STATUS, statusToDeal);
intent.putExtra(Helper.ARG_CHECK_REMOTELY, remote);
context.startActivity(intent);
}
}
});
// --- POLL ---

View file

@ -19,6 +19,7 @@ import android.app.Application;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
@ -474,14 +475,19 @@ public class StatusesVM extends AndroidViewModel {
List<Account> accounts = null;
Headers headers = null;
if (accountsCall != null) {
Log.v(Helper.TAG, "accountsCall: " + accountsCall.request());
try {
Response<List<Account>> accountsResponse = accountsCall.execute();
if (accountsResponse.isSuccessful()) {
accounts = accountsResponse.body();
Log.v(Helper.TAG, "accounts: " + accounts);
} else {
Log.v(Helper.TAG, "err: " + accountsResponse.errorBody().string());
}
headers = accountsResponse.headers();
} catch (Exception e) {
e.printStackTrace();
Log.v(Helper.TAG, "er: " + e.getMessage());
}
}
Accounts accountsPagination = new Accounts();

View file

@ -1,7 +1,6 @@
Added:
- Check remotely following/followers from profiles
Changed:
- Display all following/followers lists from remote profiles
- Display all accounts that boosted/fav from a remote message
Fixed:
- Fix a crash with auto-fetch messages