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

View file

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

View file

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

View file

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