mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Add follow request support for locked accounts
This commit is contained in:
parent
a00476c168
commit
813a2f4e12
9 changed files with 320 additions and 10 deletions
|
@ -55,8 +55,8 @@
|
|||
android:name=".activities.ContextActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".activities.DraftActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
android:name=".activities.DraftActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".activities.ComposeActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
|
@ -65,6 +65,9 @@
|
|||
<activity
|
||||
android:name=".activities.StatusInfoActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".activities.FollowRequestActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".activities.WebviewActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
|
|
|
@ -83,6 +83,7 @@ import app.fedilab.android.activities.ComposeActivity;
|
|||
import app.fedilab.android.activities.ContextActivity;
|
||||
import app.fedilab.android.activities.DraftActivity;
|
||||
import app.fedilab.android.activities.FilterActivity;
|
||||
import app.fedilab.android.activities.FollowRequestActivity;
|
||||
import app.fedilab.android.activities.InstanceActivity;
|
||||
import app.fedilab.android.activities.InstanceHealthActivity;
|
||||
import app.fedilab.android.activities.LoginActivity;
|
||||
|
@ -333,6 +334,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
} else if (id == R.id.nav_scheduled) {
|
||||
Intent intent = new Intent(this, ScheduledActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.nav_follow_requests) {
|
||||
Intent intent = new Intent(this, FollowRequestActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
binding.drawerLayout.close();
|
||||
return false;
|
||||
|
@ -564,7 +568,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
return;
|
||||
}
|
||||
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(account, binding.bottomNavView);
|
||||
|
||||
if (account.mastodon_account.locked) {
|
||||
binding.navView.getMenu().findItem(R.id.nav_follow_requests).setVisible(true);
|
||||
}
|
||||
if (bottomMenu != null) {
|
||||
//ManageClick on bottom menu items
|
||||
if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -373,7 +373,8 @@ public interface MastodonAccountsService {
|
|||
@GET("follow_requests")
|
||||
Call<List<Account>> getFollowRequests(
|
||||
@Header("Authorization") String token,
|
||||
@Path("limit") String limit);
|
||||
@Query("max_id") String max_id,
|
||||
@Query("limit") int limit);
|
||||
|
||||
//Accept follow request
|
||||
@POST("follow_requests/{id}/authorize")
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1288,28 +1288,30 @@ public class AccountsVM extends AndroidViewModel {
|
|||
* @param limit Maximum number of results to return. Defaults to 40.
|
||||
* @return {@link LiveData} containing a {@link List} of {@link Account}s
|
||||
*/
|
||||
public LiveData<List<Account>> getFollowRequests(@NonNull String instance, String token, String limit) {
|
||||
accountListMutableLiveData = new MutableLiveData<>();
|
||||
public LiveData<Accounts> getFollowRequests(@NonNull String instance, String token, String max_id, int limit) {
|
||||
accountsMutableLiveData = new MutableLiveData<>();
|
||||
MastodonAccountsService mastodonAccountsService = init(instance);
|
||||
new Thread(() -> {
|
||||
List<Account> accountList = null;
|
||||
Call<List<Account>> followRequestsCall = mastodonAccountsService.getFollowRequests(token, limit);
|
||||
Accounts accounts = new Accounts();
|
||||
Call<List<Account>> followRequestsCall = mastodonAccountsService.getFollowRequests(token, max_id, limit);
|
||||
if (followRequestsCall != null) {
|
||||
try {
|
||||
Response<List<Account>> followRequestsResponse = followRequestsCall.execute();
|
||||
if (followRequestsResponse.isSuccessful()) {
|
||||
accountList = followRequestsResponse.body();
|
||||
accounts.accounts = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), accountList);
|
||||
accounts.pagination = MastodonHelper.getPagination(followRequestsResponse.headers());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
List<Account> finalAccountList = accountList;
|
||||
Runnable myRunnable = () -> accountListMutableLiveData.setValue(finalAccountList);
|
||||
Runnable myRunnable = () -> accountsMutableLiveData.setValue(accounts);
|
||||
mainHandler.post(myRunnable);
|
||||
}
|
||||
}).start();
|
||||
return accountListMutableLiveData;
|
||||
return accountsMutableLiveData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
22
app/src/main/res/drawable/ic_baseline_group_add_24.xml
Normal file
22
app/src/main/res/drawable/ic_baseline_group_add_24.xml
Normal file
|
@ -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>
|
|
@ -40,6 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/title"
|
||||
style="@style/TextAppearance.AppCompat.Title"
|
||||
|
@ -49,6 +50,25 @@
|
|||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/no_action"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/no_action_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:padding="10dp"
|
||||
android:textSize="20sp"
|
||||
android:typeface="serif" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_marginTop="?actionBarSize"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
android:id="@+id/nav_scheduled"
|
||||
android:icon="@drawable/ic_baseline_schedule_24"
|
||||
android:title="@string/scheduled" />
|
||||
<item
|
||||
android:id="@+id/nav_follow_requests"
|
||||
android:icon="@drawable/ic_baseline_group_add_24"
|
||||
android:title="@string/follow_request"
|
||||
android:visible="false" />
|
||||
<item
|
||||
android:id="@+id/nav_settings"
|
||||
android:icon="@drawable/ic_baseline_settings_24"
|
||||
|
|
Loading…
Reference in a new issue