mirror of https://codeberg.org/tom79/Fedilab
parent
a00476c168
commit
813a2f4e12
@ -0,0 +1,127 @@
|
|||||||
|
package app.fedilab.android.activities;
|
||||||
|
/* Copyright 2022 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.BaseMainActivity;
|
||||||
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.client.entities.api.Account;
|
||||||
|
import app.fedilab.android.client.entities.api.Accounts;
|
||||||
|
import app.fedilab.android.databinding.ActivityStatusInfoBinding;
|
||||||
|
import app.fedilab.android.helper.MastodonHelper;
|
||||||
|
import app.fedilab.android.helper.ThemeHelper;
|
||||||
|
import app.fedilab.android.ui.drawer.AccountFollowRequestAdapter;
|
||||||
|
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
|
||||||
|
|
||||||
|
|
||||||
|
public class FollowRequestActivity extends BaseActivity {
|
||||||
|
|
||||||
|
private ActivityStatusInfoBinding binding;
|
||||||
|
private List<Account> accountList;
|
||||||
|
private AccountFollowRequestAdapter accountAdapter;
|
||||||
|
private String max_id;
|
||||||
|
private boolean flagLoading;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
ThemeHelper.applyTheme(this);
|
||||||
|
binding = ActivityStatusInfoBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
|
setSupportActionBar(binding.toolbar);
|
||||||
|
if (getSupportActionBar() != null) {
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||||
|
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary)));
|
||||||
|
}
|
||||||
|
accountList = new ArrayList<>();
|
||||||
|
flagLoading = false;
|
||||||
|
max_id = null;
|
||||||
|
binding.title.setText(R.string.follow_request);
|
||||||
|
AccountsVM accountsVM = new ViewModelProvider(FollowRequestActivity.this).get(AccountsVM.class);
|
||||||
|
accountAdapter = new AccountFollowRequestAdapter(accountList);
|
||||||
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(FollowRequestActivity.this);
|
||||||
|
binding.lvAccounts.setLayoutManager(mLayoutManager);
|
||||||
|
binding.lvAccounts.setAdapter(accountAdapter);
|
||||||
|
|
||||||
|
binding.lvAccounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||||
|
if (dy > 0) {
|
||||||
|
int visibleItemCount = mLayoutManager.getChildCount();
|
||||||
|
int totalItemCount = mLayoutManager.getItemCount();
|
||||||
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||||
|
if (!flagLoading) {
|
||||||
|
flagLoading = true;
|
||||||
|
binding.loadingNextAccounts.setVisibility(View.VISIBLE);
|
||||||
|
accountsVM.getFollowRequests(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, max_id, MastodonHelper.accountsPerCall(FollowRequestActivity.this))
|
||||||
|
.observe(FollowRequestActivity.this, accounts -> manageView(accounts));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binding.loadingNextAccounts.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
accountsVM.getFollowRequests(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, MastodonHelper.accountsPerCall(FollowRequestActivity.this))
|
||||||
|
.observe(FollowRequestActivity.this, this::manageView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void manageView(Accounts accounts) {
|
||||||
|
flagLoading = false;
|
||||||
|
binding.loadingNextAccounts.setVisibility(View.GONE);
|
||||||
|
if (accountList != null && accounts != null && accounts.accounts != null && accounts.accounts.size() > 0) {
|
||||||
|
int startId = 0;
|
||||||
|
//There are some statuses present in the timeline
|
||||||
|
if (accountList.size() > 0) {
|
||||||
|
startId = accountList.size();
|
||||||
|
}
|
||||||
|
accountList.addAll(accounts.accounts);
|
||||||
|
max_id = accounts.pagination.max_id;
|
||||||
|
accountAdapter.notifyItemRangeInserted(startId, accounts.accounts.size());
|
||||||
|
binding.noAction.setVisibility(View.GONE);
|
||||||
|
binding.lvAccounts.setVisibility(View.VISIBLE);
|
||||||
|
} else if (accountList == null || accountList.size() == 0) {
|
||||||
|
binding.noActionText.setText(R.string.no_follow_request);
|
||||||
|
binding.noAction.setVisibility(View.VISIBLE);
|
||||||
|
binding.lvAccounts.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,124 @@
|
|||||||
|
package app.fedilab.android.ui.drawer;
|
||||||
|
/* Copyright 2022 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.app.ActivityOptionsCompat;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.lifecycle.ViewModelStoreOwner;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.R;
|
||||||
|
import app.fedilab.android.activities.MainActivity;
|
||||||
|
import app.fedilab.android.activities.ProfileActivity;
|
||||||
|
import app.fedilab.android.client.entities.api.Account;
|
||||||
|
import app.fedilab.android.databinding.DrawerFollowBinding;
|
||||||
|
import app.fedilab.android.helper.Helper;
|
||||||
|
import app.fedilab.android.helper.MastodonHelper;
|
||||||
|
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
|
||||||
|
|
||||||
|
|
||||||
|
public class AccountFollowRequestAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private final List<Account> accountList;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public AccountFollowRequestAdapter(List<Account> accountList) {
|
||||||
|
this.accountList = accountList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return accountList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Account getItem(int position) {
|
||||||
|
return accountList.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
context = parent.getContext();
|
||||||
|
DrawerFollowBinding itemBinding = DrawerFollowBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||||
|
return new ViewHolderFollow(itemBinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
Account account = accountList.get(position);
|
||||||
|
ViewHolderFollow holderFollow = (ViewHolderFollow) viewHolder;
|
||||||
|
MastodonHelper.loadPPMastodon(holderFollow.binding.avatar, account);
|
||||||
|
holderFollow.binding.displayName.setText(account.display_name);
|
||||||
|
holderFollow.binding.username.setText(String.format("@%s", account.acct));
|
||||||
|
holderFollow.binding.rejectButton.setVisibility(View.VISIBLE);
|
||||||
|
holderFollow.binding.acceptButton.setVisibility(View.VISIBLE);
|
||||||
|
holderFollow.binding.title.setText(R.string.follow_request);
|
||||||
|
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
|
||||||
|
holderFollow.binding.acceptButton.setOnClickListener(v -> {
|
||||||
|
accountsVM.acceptFollow(MainActivity.currentInstance, MainActivity.currentToken, account.id)
|
||||||
|
.observe((LifecycleOwner) context, relationShip -> {
|
||||||
|
accountList.remove(position);
|
||||||
|
notifyItemRemoved(position);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
holderFollow.binding.rejectButton.setOnClickListener(v -> {
|
||||||
|
accountsVM.rejectFollow(MainActivity.currentInstance, MainActivity.currentToken, account.id)
|
||||||
|
.observe((LifecycleOwner) context, relationShip -> {
|
||||||
|
accountList.remove(position);
|
||||||
|
notifyItemRemoved(position);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
holderFollow.binding.avatar.setOnClickListener(v -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putSerializable(Helper.ARG_ACCOUNT, account);
|
||||||
|
intent.putExtras(b);
|
||||||
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||||
|
.makeSceneTransitionAnimation((Activity) context, holderFollow.binding.avatar, context.getString(R.string.activity_porfile_pp));
|
||||||
|
// start the new activity
|
||||||
|
context.startActivity(intent, options.toBundle());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return accountList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static class ViewHolderFollow extends RecyclerView.ViewHolder {
|
||||||
|
DrawerFollowBinding binding;
|
||||||
|
|
||||||
|
ViewHolderFollow(DrawerFollowBinding itemView) {
|
||||||
|
super(itemView.getRoot());
|
||||||
|
binding = itemView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M22,9l0,-2l-2,0l0,2l-2,0l0,2l2,0l0,2l2,0l0,-2l2,0l0,-2z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M8,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4S4,5.79 4,8S5.79,12 8,12z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M8,13c-2.67,0 -8,1.34 -8,4v3h16v-3C16,14.34 10.67,13 8,13z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M12.51,4.05C13.43,5.11 14,6.49 14,8s-0.57,2.89 -1.49,3.95C14.47,11.7 16,10.04 16,8S14.47,4.3 12.51,4.05z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M16.53,13.83C17.42,14.66 18,15.7 18,17v3h2v-3C20,15.55 18.41,14.49 16.53,13.83z" />
|
||||||
|
</vector>
|
Loading…
Reference in new issue