mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-23 17:20:04 +02:00
Add some endpoints + ui
This commit is contained in:
parent
f96de62fef
commit
b5a304be56
17 changed files with 517 additions and 26 deletions
|
@ -201,7 +201,7 @@
|
|||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/account" />
|
||||
<activity
|
||||
android:name=".activities.AdminAccountActivity"
|
||||
android:name=".activities.admin.AdminAccountActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/account" />
|
||||
<activity
|
||||
|
@ -210,7 +210,7 @@
|
|||
android:label="@string/account"
|
||||
android:theme="@style/AppThemeBar" />
|
||||
<activity
|
||||
android:name=".activities.AdminReportActivity"
|
||||
android:name=".activities.admin.AdminReportActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/report"
|
||||
android:theme="@style/AppThemeBar" />
|
||||
|
@ -259,7 +259,7 @@
|
|||
android:label="@string/interactions"
|
||||
android:theme="@style/AppThemeBar" />
|
||||
<activity
|
||||
android:name=".activities.AdminActionActivity"
|
||||
android:name=".activities.admin.AdminActionActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/administration"
|
||||
android:theme="@style/AppThemeBar" />
|
||||
|
|
|
@ -95,7 +95,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import app.fedilab.android.activities.AboutActivity;
|
||||
import app.fedilab.android.activities.ActionActivity;
|
||||
import app.fedilab.android.activities.AdminActionActivity;
|
||||
import app.fedilab.android.activities.AnnouncementActivity;
|
||||
import app.fedilab.android.activities.BaseActivity;
|
||||
import app.fedilab.android.activities.CacheActivity;
|
||||
|
@ -119,6 +118,7 @@ import app.fedilab.android.activities.SearchResultTabActivity;
|
|||
import app.fedilab.android.activities.SettingsActivity;
|
||||
import app.fedilab.android.activities.SuggestionActivity;
|
||||
import app.fedilab.android.activities.TrendsActivity;
|
||||
import app.fedilab.android.activities.admin.AdminActionActivity;
|
||||
import app.fedilab.android.broadcastreceiver.NetworkStateReceiver;
|
||||
import app.fedilab.android.client.entities.api.Emoji;
|
||||
import app.fedilab.android.client.entities.api.EmojiInstance;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package app.fedilab.android.activities;
|
||||
package app.fedilab.android.activities.admin;
|
||||
/* Copyright 2022 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
|
@ -54,8 +54,13 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.BaseActivity;
|
||||
import app.fedilab.android.activities.InstanceProfileActivity;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.activities.MediaActivity;
|
||||
import app.fedilab.android.client.entities.api.Attachment;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminAccount;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminIp;
|
||||
import app.fedilab.android.databinding.ActivityAdminAccountBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.MastodonHelper;
|
||||
|
@ -204,7 +209,7 @@ public class AdminAccountActivity extends BaseActivity {
|
|||
StringBuilder lastActive = new StringBuilder();
|
||||
if (adminAccount.ips != null) {
|
||||
int count = 0;
|
||||
for (AdminAccount.IP ip : adminAccount.ips) {
|
||||
for (AdminIp ip : adminAccount.ips) {
|
||||
lastActive.append(Helper.shortDateToString(ip.used_at)).append(" - ").append(ip.ip).append("\r\n");
|
||||
count++;
|
||||
if (count > 4) {
|
|
@ -1,4 +1,4 @@
|
|||
package app.fedilab.android.activities;
|
||||
package app.fedilab.android.activities.admin;
|
||||
/* Copyright 2022 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
|
@ -14,7 +14,9 @@ package app.fedilab.android.activities;
|
|||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import static app.fedilab.android.activities.AdminActionActivity.AdminEnum.REPORT;
|
||||
import static app.fedilab.android.activities.admin.AdminActionActivity.AdminEnum.ACCOUNT;
|
||||
import static app.fedilab.android.activities.admin.AdminActionActivity.AdminEnum.DOMAIN;
|
||||
import static app.fedilab.android.activities.admin.AdminActionActivity.AdminEnum.REPORT;
|
||||
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
|
@ -31,12 +33,14 @@ import androidx.fragment.app.FragmentTransaction;
|
|||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.BaseActivity;
|
||||
import app.fedilab.android.databinding.ActivityAdminActionsBinding;
|
||||
import app.fedilab.android.databinding.PopupAdminFilterAccountsBinding;
|
||||
import app.fedilab.android.databinding.PopupAdminFilterReportsBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.ThemeHelper;
|
||||
import app.fedilab.android.ui.fragment.admin.FragmentAdminAccount;
|
||||
import app.fedilab.android.ui.fragment.admin.FragmentAdminDomain;
|
||||
import app.fedilab.android.ui.fragment.admin.FragmentAdminReport;
|
||||
|
||||
public class AdminActionActivity extends BaseActivity {
|
||||
|
@ -47,6 +51,7 @@ public class AdminActionActivity extends BaseActivity {
|
|||
private boolean canGoBack;
|
||||
private FragmentAdminReport fragmentAdminReport;
|
||||
private FragmentAdminAccount fragmentAdminAccount;
|
||||
private FragmentAdminDomain fragmentAdminDomain;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -61,13 +66,13 @@ public class AdminActionActivity extends BaseActivity {
|
|||
}
|
||||
canGoBack = false;
|
||||
binding.reports.setOnClickListener(v -> displayTimeline(REPORT));
|
||||
binding.accounts.setOnClickListener(v -> displayTimeline(AdminEnum.ACCOUNT));
|
||||
binding.accounts.setOnClickListener(v -> displayTimeline(ACCOUNT));
|
||||
binding.domains.setOnClickListener(v -> displayTimeline(DOMAIN));
|
||||
}
|
||||
|
||||
private void displayTimeline(AdminEnum type) {
|
||||
canGoBack = true;
|
||||
if (type == REPORT) {
|
||||
|
||||
ThemeHelper.slideViewsToLeft(binding.buttonContainer, binding.fragmentContainer, () -> {
|
||||
fragmentAdminReport = new FragmentAdminReport();
|
||||
Bundle bundle = new Bundle();
|
||||
|
@ -80,9 +85,7 @@ public class AdminActionActivity extends BaseActivity {
|
|||
fragmentTransaction.replace(R.id.fragment_container, fragmentAdminReport);
|
||||
fragmentTransaction.commit();
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
} else if (type == ACCOUNT) {
|
||||
ThemeHelper.slideViewsToLeft(binding.buttonContainer, binding.fragmentContainer, () -> {
|
||||
fragmentAdminAccount = new FragmentAdminAccount();
|
||||
Bundle bundle = new Bundle();
|
||||
|
@ -95,7 +98,19 @@ public class AdminActionActivity extends BaseActivity {
|
|||
fragmentTransaction.replace(R.id.fragment_container, fragmentAdminAccount);
|
||||
fragmentTransaction.commit();
|
||||
});
|
||||
|
||||
} else if (type == DOMAIN) {
|
||||
ThemeHelper.slideViewsToLeft(binding.buttonContainer, binding.fragmentContainer, () -> {
|
||||
fragmentAdminDomain = new FragmentAdminDomain();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, type);
|
||||
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + type.getValue());
|
||||
fragmentAdminDomain.setArguments(bundle);
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
FragmentTransaction fragmentTransaction =
|
||||
fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragmentAdminDomain);
|
||||
fragmentTransaction.commit();
|
||||
});
|
||||
}
|
||||
switch (type) {
|
||||
case REPORT:
|
||||
|
@ -104,6 +119,9 @@ public class AdminActionActivity extends BaseActivity {
|
|||
case ACCOUNT:
|
||||
setTitle(R.string.accounts);
|
||||
break;
|
||||
case DOMAIN:
|
||||
setTitle(R.string.domains);
|
||||
break;
|
||||
}
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
@ -283,6 +301,9 @@ public class AdminActionActivity extends BaseActivity {
|
|||
if (fragmentAdminAccount != null) {
|
||||
fragmentAdminAccount.onDestroyView();
|
||||
}
|
||||
if (fragmentAdminDomain != null) {
|
||||
fragmentAdminDomain.onDestroyView();
|
||||
}
|
||||
setTitle(R.string.administration);
|
||||
invalidateOptionsMenu();
|
||||
});
|
||||
|
@ -296,8 +317,9 @@ public class AdminActionActivity extends BaseActivity {
|
|||
@SerializedName("REPORT")
|
||||
REPORT("REPORT"),
|
||||
@SerializedName("ACCOUNT")
|
||||
ACCOUNT("ACCOUNT");
|
||||
|
||||
ACCOUNT("ACCOUNT"),
|
||||
@SerializedName("DOMAIN")
|
||||
DOMAIN("DOMAIN");
|
||||
private final String value;
|
||||
|
||||
AdminEnum(String value) {
|
|
@ -1,4 +1,4 @@
|
|||
package app.fedilab.android.activities;
|
||||
package app.fedilab.android.activities.admin;
|
||||
/* Copyright 2022 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
|
@ -55,9 +55,13 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.BaseActivity;
|
||||
import app.fedilab.android.activities.InstanceProfileActivity;
|
||||
import app.fedilab.android.activities.MediaActivity;
|
||||
import app.fedilab.android.client.entities.api.Account;
|
||||
import app.fedilab.android.client.entities.api.Attachment;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminAccount;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminIp;
|
||||
import app.fedilab.android.databinding.ActivityAdminAccountBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.MastodonHelper;
|
||||
|
@ -141,7 +145,7 @@ public class AdminReportActivity extends BaseActivity {
|
|||
binding.email.setText(adminAccount.email);
|
||||
StringBuilder lastActive = new StringBuilder();
|
||||
if (adminAccount.ips != null) {
|
||||
for (AdminAccount.IP ip : adminAccount.ips) {
|
||||
for (AdminIp ip : adminAccount.ips) {
|
||||
lastActive.append(Helper.shortDateToString(ip.used_at)).append(" - ").append(ip.ip).append("\r\n");
|
||||
}
|
||||
}
|
|
@ -164,12 +164,25 @@ public interface MastodonAdminService {
|
|||
@Query("limit") int limit
|
||||
);
|
||||
|
||||
@GET("admin/domain_allows")
|
||||
Call<List<AdminDomainBlock>> getDomainAllows(
|
||||
@Header("Authorization") String token,
|
||||
@Query("max_id") String max_id,
|
||||
@Query("limit") int limit
|
||||
);
|
||||
|
||||
@GET("admin/domain_blocks/{id}")
|
||||
Call<AdminDomainBlock> getDomainBlock(
|
||||
@Header("Authorization") String token,
|
||||
@Path("id") String id
|
||||
);
|
||||
|
||||
@GET("admin/domain_allows/{id}")
|
||||
Call<AdminDomainBlock> getDomainAllow(
|
||||
@Header("Authorization") String token,
|
||||
@Path("id") String id
|
||||
);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("admin/domain_blocks")
|
||||
|
@ -184,6 +197,13 @@ public interface MastodonAdminService {
|
|||
@Field("obfuscate") Boolean obfuscate
|
||||
);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("admin/domain_allows")
|
||||
Call<AdminDomainBlock> allowDomain(
|
||||
@Header("Authorization") String app_token,
|
||||
@Path("domain") String domain
|
||||
);
|
||||
|
||||
@FormUrlEncoded
|
||||
@PUT("admin/domain_blocks")
|
||||
Call<AdminDomainBlock> updateBlockDomain(
|
||||
|
@ -202,4 +222,11 @@ public interface MastodonAdminService {
|
|||
@Header("Authorization") String app_token,
|
||||
@Path("id") String id
|
||||
);
|
||||
|
||||
|
||||
@DELETE("admin/domain_allows/{id}")
|
||||
Call<Void> deleteAllowDomain(
|
||||
@Header("Authorization") String app_token,
|
||||
@Path("id") String id
|
||||
);
|
||||
}
|
||||
|
|
|
@ -100,7 +100,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.AdminAccountActivity;
|
||||
import app.fedilab.android.activities.ComposeActivity;
|
||||
import app.fedilab.android.activities.ContextActivity;
|
||||
import app.fedilab.android.activities.CustomSharingActivity;
|
||||
|
@ -109,6 +108,7 @@ import app.fedilab.android.activities.ProfileActivity;
|
|||
import app.fedilab.android.activities.ReportActivity;
|
||||
import app.fedilab.android.activities.StatusHistoryActivity;
|
||||
import app.fedilab.android.activities.StatusInfoActivity;
|
||||
import app.fedilab.android.activities.admin.AdminAccountActivity;
|
||||
import app.fedilab.android.client.entities.api.Attachment;
|
||||
import app.fedilab.android.client.entities.api.Poll;
|
||||
import app.fedilab.android.client.entities.api.Reaction;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package app.fedilab.android.ui.drawer;
|
||||
package app.fedilab.android.ui.drawer.admin;
|
||||
/* Copyright 2022 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
|
@ -27,7 +27,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import app.fedilab.android.activities.AdminAccountActivity;
|
||||
import app.fedilab.android.activities.admin.AdminAccountActivity;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminAccount;
|
||||
import app.fedilab.android.databinding.DrawerAdminAccountBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
|
@ -0,0 +1,90 @@
|
|||
package app.fedilab.android.ui.drawer.admin;
|
||||
/* 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.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.fedilab.android.client.entities.api.admin.AdminDomainBlock;
|
||||
import app.fedilab.android.databinding.DrawerAdminDomainBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
|
||||
|
||||
public class AdminDomainAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final List<AdminDomainBlock> adminDomainBlockList;
|
||||
private Context context;
|
||||
|
||||
|
||||
public AdminDomainAdapter(List<AdminDomainBlock> adminDomainBlocks) {
|
||||
this.adminDomainBlockList = adminDomainBlocks;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
|
||||
context = parent.getContext();
|
||||
DrawerAdminDomainBinding itemBinding = DrawerAdminDomainBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||
return new DomainViewHolder(itemBinding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||
DomainViewHolder holder = (DomainViewHolder) viewHolder;
|
||||
AdminDomainBlock adminDomainBlock = adminDomainBlockList.get(position);
|
||||
|
||||
holder.binding.date.setText(Helper.shortDateToString(adminDomainBlock.created_at));
|
||||
holder.binding.title.setText(adminDomainBlock.domain);
|
||||
holder.binding.severity.setText(adminDomainBlock.severity);
|
||||
/*holder.binding.mainContainer.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(context, AccountReportActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putSerializable(Helper.ARG_REPORT, report);
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
});*/
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return adminDomainBlockList.size();
|
||||
}
|
||||
|
||||
|
||||
public static class DomainViewHolder extends RecyclerView.ViewHolder {
|
||||
DrawerAdminDomainBinding binding;
|
||||
|
||||
DomainViewHolder(DrawerAdminDomainBinding itemView) {
|
||||
super(itemView.getRoot());
|
||||
binding = itemView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package app.fedilab.android.ui.drawer;
|
||||
package app.fedilab.android.ui.drawer.admin;
|
||||
/* Copyright 2022 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
|
@ -33,14 +33,14 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.AdminActionActivity;
|
||||
import app.fedilab.android.activities.admin.AdminActionActivity;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminAccount;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminAccounts;
|
||||
import app.fedilab.android.databinding.FragmentPaginationBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.MastodonHelper;
|
||||
import app.fedilab.android.helper.ThemeHelper;
|
||||
import app.fedilab.android.ui.drawer.AdminAccountAdapter;
|
||||
import app.fedilab.android.ui.drawer.admin.AdminAccountAdapter;
|
||||
import app.fedilab.android.viewmodel.mastodon.AdminVM;
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
package app.fedilab.android.ui.fragment.admin;
|
||||
/* 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.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
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.admin.AdminDomainBlock;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminDomainBlocks;
|
||||
import app.fedilab.android.databinding.FragmentPaginationBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.ThemeHelper;
|
||||
import app.fedilab.android.ui.drawer.admin.AdminDomainAdapter;
|
||||
import app.fedilab.android.viewmodel.mastodon.AdminVM;
|
||||
|
||||
|
||||
public class FragmentAdminDomain extends Fragment {
|
||||
|
||||
|
||||
private FragmentPaginationBinding binding;
|
||||
private AdminVM adminVM;
|
||||
private boolean flagLoading;
|
||||
private List<AdminDomainBlock> adminDomainBlocks;
|
||||
private String max_id, min_id;
|
||||
private AdminDomainAdapter adminDomainAdapter;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private String viewModelKey;
|
||||
|
||||
public void scrollToTop() {
|
||||
if (binding != null) {
|
||||
binding.recyclerView.scrollToPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
if (getArguments() != null) {
|
||||
viewModelKey = getArguments().getString(Helper.ARG_VIEW_MODEL_KEY, "");
|
||||
}
|
||||
|
||||
binding = FragmentPaginationBinding.inflate(inflater, container, false);
|
||||
binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity()));
|
||||
|
||||
int c1 = getResources().getColor(R.color.cyanea_accent_reference);
|
||||
binding.swipeContainer.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.cyanea_primary_reference));
|
||||
binding.swipeContainer.setColorSchemeColors(
|
||||
c1, c1, c1
|
||||
);
|
||||
|
||||
adminVM = new ViewModelProvider(FragmentAdminDomain.this).get(viewModelKey, AdminVM.class);
|
||||
|
||||
binding.loader.setVisibility(View.VISIBLE);
|
||||
binding.recyclerView.setVisibility(View.GONE);
|
||||
flagLoading = false;
|
||||
adminVM.getDomainBlocks(
|
||||
BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null)
|
||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intialize the common view for domain block on different timelines
|
||||
*
|
||||
* @param adminDomainBlocks {@link AdminDomainBlocks}
|
||||
*/
|
||||
private void initializeStatusesCommonView(final AdminDomainBlocks adminDomainBlocks) {
|
||||
if (binding == null || !isAdded() || getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
binding.loader.setVisibility(View.GONE);
|
||||
binding.noAction.setVisibility(View.GONE);
|
||||
binding.swipeContainer.setRefreshing(false);
|
||||
binding.swipeContainer.setOnRefreshListener(() -> {
|
||||
binding.swipeContainer.setRefreshing(true);
|
||||
max_id = null;
|
||||
flagLoading = false;
|
||||
adminVM.getDomainBlocks(
|
||||
BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null)
|
||||
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
|
||||
});
|
||||
|
||||
if (adminDomainBlocks == null || adminDomainBlocks.adminDomainBlocks == null || adminDomainBlocks.adminDomainBlocks.size() == 0) {
|
||||
binding.noAction.setVisibility(View.VISIBLE);
|
||||
return;
|
||||
}
|
||||
flagLoading = adminDomainBlocks.pagination.max_id == null;
|
||||
binding.recyclerView.setVisibility(View.VISIBLE);
|
||||
if (adminDomainAdapter != null && this.adminDomainBlocks != null) {
|
||||
int size = this.adminDomainBlocks.size();
|
||||
this.adminDomainBlocks.clear();
|
||||
this.adminDomainBlocks = new ArrayList<>();
|
||||
adminDomainAdapter.notifyItemRangeRemoved(0, size);
|
||||
}
|
||||
if (this.adminDomainBlocks == null) {
|
||||
this.adminDomainBlocks = new ArrayList<>();
|
||||
}
|
||||
this.adminDomainBlocks.addAll(adminDomainBlocks.adminDomainBlocks);
|
||||
|
||||
if (max_id == null || (adminDomainBlocks.pagination.max_id != null && Helper.compareTo(adminDomainBlocks.pagination.max_id, max_id) < 0)) {
|
||||
max_id = adminDomainBlocks.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (adminDomainBlocks.pagination.max_id != null && Helper.compareTo(adminDomainBlocks.pagination.min_id, min_id) > 0)) {
|
||||
min_id = adminDomainBlocks.pagination.min_id;
|
||||
}
|
||||
|
||||
adminDomainAdapter = new AdminDomainAdapter(adminDomainBlocks.adminDomainBlocks);
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(requireActivity());
|
||||
binding.recyclerView.setLayoutManager(mLayoutManager);
|
||||
binding.recyclerView.setAdapter(adminDomainAdapter);
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(binding.recyclerView.getContext(),
|
||||
mLayoutManager.getOrientation());
|
||||
binding.recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
if (requireActivity() instanceof BaseMainActivity) {
|
||||
if (dy < 0 && !((BaseMainActivity) requireActivity()).getFloatingVisibility())
|
||||
((BaseMainActivity) requireActivity()).manageFloatingButton(true);
|
||||
if (dy > 0 && ((BaseMainActivity) requireActivity()).getFloatingVisibility())
|
||||
((BaseMainActivity) requireActivity()).manageFloatingButton(false);
|
||||
}
|
||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||
if (dy > 0) {
|
||||
int visibleItemCount = mLayoutManager.getChildCount();
|
||||
int totalItemCount = mLayoutManager.getItemCount();
|
||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||
if (!flagLoading) {
|
||||
flagLoading = true;
|
||||
binding.loadingNextElements.setVisibility(View.VISIBLE);
|
||||
adminVM.getDomainAllows(
|
||||
BaseMainActivity.currentInstance, BaseMainActivity.currentToken, max_id)
|
||||
.observe(getViewLifecycleOwner(), adminDomainBlocks1 -> dealWithPagination(adminDomainBlocks1));
|
||||
}
|
||||
} else {
|
||||
binding.loadingNextElements.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update view and pagination when scrolling down
|
||||
*
|
||||
* @param admDomainBlocks AdminDomainBlocks
|
||||
*/
|
||||
private void dealWithPagination(AdminDomainBlocks admDomainBlocks) {
|
||||
|
||||
if (binding == null || !isAdded() || getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
binding.loadingNextElements.setVisibility(View.GONE);
|
||||
if (this.adminDomainBlocks != null && admDomainBlocks != null && admDomainBlocks.adminDomainBlocks != null && admDomainBlocks.adminDomainBlocks.size() > 0) {
|
||||
flagLoading = admDomainBlocks.pagination.max_id == null;
|
||||
//There are some adminDomainBlocks present in the timeline
|
||||
int startId = this.adminDomainBlocks.size();
|
||||
this.adminDomainBlocks.addAll(admDomainBlocks.adminDomainBlocks);
|
||||
adminDomainAdapter.notifyItemRangeInserted(startId, admDomainBlocks.adminDomainBlocks.size());
|
||||
if (max_id == null || (admDomainBlocks.pagination.max_id != null && Helper.compareTo(admDomainBlocks.pagination.max_id, max_id) < 0)) {
|
||||
max_id = admDomainBlocks.pagination.max_id;
|
||||
}
|
||||
if (min_id == null || (admDomainBlocks.pagination.min_id != null && Helper.compareTo(admDomainBlocks.pagination.min_id, min_id) > 0)) {
|
||||
min_id = admDomainBlocks.pagination.min_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -33,13 +33,13 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.AdminActionActivity;
|
||||
import app.fedilab.android.activities.admin.AdminActionActivity;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminReport;
|
||||
import app.fedilab.android.client.entities.api.admin.AdminReports;
|
||||
import app.fedilab.android.databinding.FragmentPaginationBinding;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.ThemeHelper;
|
||||
import app.fedilab.android.ui.drawer.ReportAdapter;
|
||||
import app.fedilab.android.ui.drawer.admin.ReportAdapter;
|
||||
import app.fedilab.android.viewmodel.mastodon.AdminVM;
|
||||
|
||||
|
||||
|
|
|
@ -630,4 +630,72 @@ public class AdminVM extends AndroidViewModel {
|
|||
}).start();
|
||||
return adminDomainBlockMutableLiveData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* View all allowed domains.
|
||||
*
|
||||
* @param instance Instance domain of the active account
|
||||
* @param token Access token of the active account
|
||||
* @return {@link LiveData} containing a {@link List} of {@link AdminDomainBlocks}s
|
||||
*/
|
||||
public LiveData<AdminDomainBlocks> getDomainAllows(@NonNull String instance,
|
||||
String token,
|
||||
String max_id) {
|
||||
MastodonAdminService mastodonAdminService = init(instance);
|
||||
adminDomainBlockListMutableLiveData = new MutableLiveData<>();
|
||||
new Thread(() -> {
|
||||
List<AdminDomainBlock> adminDomainBlockList;
|
||||
Call<List<AdminDomainBlock>> getDomainBlocks = mastodonAdminService.getDomainAllows(token, max_id, MastodonHelper.statusesPerCall(getApplication()));
|
||||
AdminDomainBlocks adminDomainBlocks = new AdminDomainBlocks();
|
||||
if (getDomainBlocks != null) {
|
||||
try {
|
||||
Response<List<AdminDomainBlock>> getDomainBlocksResponse = getDomainBlocks.execute();
|
||||
if (getDomainBlocksResponse.isSuccessful()) {
|
||||
adminDomainBlocks.adminDomainBlocks = getDomainBlocksResponse.body();
|
||||
adminDomainBlocks.pagination = MastodonHelper.getPagination(getDomainBlocksResponse.headers());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> adminDomainBlockListMutableLiveData.setValue(adminDomainBlocks);
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
return adminDomainBlockListMutableLiveData;
|
||||
}
|
||||
|
||||
/**
|
||||
* View a single allowed domain
|
||||
*
|
||||
* @param instance Instance domain of the active account
|
||||
* @param token Access token of the active account
|
||||
* @return {@link LiveData} containing a {@link List} of {@link AdminDomainBlocks}s
|
||||
*/
|
||||
public LiveData<AdminDomainBlock> getDomainAllow(@NonNull String instance,
|
||||
String token,
|
||||
String id) {
|
||||
MastodonAdminService mastodonAdminService = init(instance);
|
||||
adminDomainBlockMutableLiveData = new MutableLiveData<>();
|
||||
new Thread(() -> {
|
||||
AdminDomainBlock adminDomainBlock = null;
|
||||
Call<AdminDomainBlock> getDomainBlock = mastodonAdminService.getDomainAllow(token, id);
|
||||
if (getDomainBlock != null) {
|
||||
try {
|
||||
Response<AdminDomainBlock> getDomainBlocksResponse = getDomainBlock.execute();
|
||||
if (getDomainBlocksResponse.isSuccessful()) {
|
||||
adminDomainBlock = getDomainBlocksResponse.body();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
AdminDomainBlock finalAdminDomainBlock = adminDomainBlock;
|
||||
Runnable myRunnable = () -> adminDomainBlockMutableLiveData.setValue(finalAdminDomainBlock);
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
return adminDomainBlockMutableLiveData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,20 @@
|
|||
app:iconTint="@color/cyanea_accent_dark_reference"
|
||||
app:strokeColor="@color/cyanea_accent_dark_reference" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/domains"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:text="@string/blocked_domains"
|
||||
android:textAlignment="textStart"
|
||||
android:textColor="@color/cyanea_accent_dark_reference"
|
||||
app:icon="@drawable/ic_baseline_navigate_next_24"
|
||||
app:iconGravity="end"
|
||||
app:iconTint="@color/cyanea_accent_dark_reference"
|
||||
app:strokeColor="@color/cyanea_accent_dark_reference" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
|
|
56
app/src/main/res/layout/drawer_admin_domain.xml
Normal file
56
app/src/main/res/layout/drawer_admin_domain.xml
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
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>.
|
||||
-->
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/title"
|
||||
style="@style/TextAppearance.AppCompat.Title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="example.net" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/severity"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="16sp"
|
||||
tools:text="stable" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textSize="16sp"
|
||||
tools:text="@tools:sample/date/ddmmyy" />
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
|
@ -1914,4 +1914,5 @@
|
|||
<string name="unpin_timeline">Remove pinned timeline?</string>
|
||||
<string name="unpin_timeline_description">Are you sure to unpin that timeline?</string>
|
||||
<string name="action_pinned_delete">Delete the pinned timelines?</string>
|
||||
<string name="domains">Domains</string>
|
||||
</resources>
|
Loading…
Reference in a new issue