mirror of https://codeberg.org/tom79/Fedilab
parent
f96de62fef
commit
b5a304be56
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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>
|
Loading…
Reference in new issue