2019-06-19 14:58:57 +02:00
|
|
|
/* Copyright 2019 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>. */
|
|
|
|
package app.fedilab.android.activities;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
2019-11-13 12:54:01 +01:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2019-06-19 14:58:57 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
2019-06-20 16:33:29 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2019-06-19 14:58:57 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
2019-06-20 16:33:29 +02:00
|
|
|
import android.widget.LinearLayout;
|
2019-06-19 14:58:57 +02:00
|
|
|
import android.widget.TextView;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-11-27 15:35:14 +01:00
|
|
|
import androidx.annotation.NonNull;
|
2019-06-19 14:58:57 +02:00
|
|
|
import androidx.appcompat.app.ActionBar;
|
2019-06-20 16:33:29 +02:00
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
2019-11-13 12:54:01 +01:00
|
|
|
import androidx.core.content.ContextCompat;
|
2019-06-19 14:58:57 +02:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
2019-06-20 18:48:46 +02:00
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
2019-06-19 14:58:57 +02:00
|
|
|
import androidx.viewpager.widget.PagerAdapter;
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-06-19 14:58:57 +02:00
|
|
|
import com.google.android.material.tabs.TabLayout;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-06-19 14:58:57 +02:00
|
|
|
import app.fedilab.android.R;
|
2019-06-30 15:30:45 +02:00
|
|
|
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
2019-06-19 14:58:57 +02:00
|
|
|
import app.fedilab.android.fragments.DisplayAdminAccountsFragment;
|
|
|
|
import app.fedilab.android.fragments.DisplayAdminReportsFragment;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 19/06/2019.
|
|
|
|
* Admin activity
|
|
|
|
*/
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
public class AdminActivity extends BaseActivity {
|
2019-06-19 14:58:57 +02:00
|
|
|
|
|
|
|
|
2019-06-20 16:33:29 +02:00
|
|
|
private boolean unresolved;
|
|
|
|
private boolean local, remote, active, pending, disabled, silenced, suspended;
|
|
|
|
private DisplayAdminReportsFragment displayAdminReportsFragment;
|
2019-06-20 18:48:46 +02:00
|
|
|
private DisplayAdminAccountsFragment displayAdminAccountsFragment;
|
|
|
|
|
2019-06-19 14:58:57 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
|
|
|
|
setTheme(R.style.AppAdminTheme);
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
if (getSupportActionBar() != null)
|
2019-06-19 14:58:57 +02:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
2019-09-06 17:55:14 +02:00
|
|
|
if (actionBar != null) {
|
2019-06-19 14:58:57 +02:00
|
|
|
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
|
|
|
|
assert inflater != null;
|
2019-08-18 17:41:10 +02:00
|
|
|
View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(getApplicationContext()), false);
|
2019-11-15 19:36:39 +01:00
|
|
|
view.setBackground(new ColorDrawable(ContextCompat.getColor(AdminActivity.this, R.color.cyanea_primary)));
|
2019-06-19 14:58:57 +02:00
|
|
|
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
|
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
|
|
|
|
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
|
|
|
toolbar_close.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
2019-09-06 17:55:14 +02:00
|
|
|
toolbar_title.setText(String.format(getString(R.string.administration) + " %s", Helper.getLiveInstance(getApplicationContext())));
|
2019-06-19 14:58:57 +02:00
|
|
|
}
|
|
|
|
setContentView(R.layout.activity_admin);
|
2019-06-20 18:48:46 +02:00
|
|
|
unresolved = local = active = true;
|
|
|
|
remote = pending = disabled = silenced = suspended = false;
|
2019-06-19 14:58:57 +02:00
|
|
|
ViewPager admin_viewpager = findViewById(R.id.admin_viewpager);
|
|
|
|
|
|
|
|
TabLayout admin_tablayout = findViewById(R.id.admin_tablayout);
|
2019-11-13 12:54:01 +01:00
|
|
|
admin_tablayout.setBackgroundColor(ContextCompat.getColor(AdminActivity.this, R.color.cyanea_primary));
|
2019-06-19 14:58:57 +02:00
|
|
|
admin_tablayout.addTab(admin_tablayout.newTab().setText(getString(R.string.reports)));
|
|
|
|
admin_tablayout.addTab(admin_tablayout.newTab().setText(getString(R.string.accounts)));
|
|
|
|
|
|
|
|
|
2019-06-20 16:33:29 +02:00
|
|
|
final LinearLayout tabStrip = (LinearLayout) admin_tablayout.getChildAt(0);
|
|
|
|
tabStrip.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
PopupMenu popup = new PopupMenu(AdminActivity.this, tabStrip.getChildAt(0));
|
|
|
|
popup.getMenuInflater()
|
|
|
|
.inflate(R.menu.option_filter_admin_reports, popup.getMenu());
|
|
|
|
Menu menu = popup.getMenu();
|
|
|
|
final MenuItem itemUnresolved = menu.findItem(R.id.action_unresolved_reports);
|
|
|
|
|
|
|
|
|
|
|
|
itemUnresolved.setChecked(unresolved);
|
|
|
|
|
|
|
|
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss(PopupMenu menu) {
|
2019-06-20 18:48:46 +02:00
|
|
|
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
|
fragTransaction.detach(displayAdminReportsFragment);
|
|
|
|
Bundle bundle = new Bundle();
|
2019-09-06 17:55:14 +02:00
|
|
|
bundle.putBoolean("unresolved", unresolved);
|
2019-06-20 18:48:46 +02:00
|
|
|
displayAdminReportsFragment.setArguments(bundle);
|
|
|
|
fragTransaction.attach(displayAdminReportsFragment);
|
|
|
|
fragTransaction.commit();
|
2019-06-20 16:33:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
|
|
|
item.setActionView(new View(getApplicationContext()));
|
|
|
|
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (item.getItemId() == R.id.action_unresolved_reports) {
|
|
|
|
unresolved = !unresolved;
|
|
|
|
}
|
2019-06-20 18:51:54 +02:00
|
|
|
itemUnresolved.setChecked(unresolved);
|
2019-06-20 18:48:46 +02:00
|
|
|
return false;
|
2019-06-20 16:33:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
popup.show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-06-20 18:48:46 +02:00
|
|
|
tabStrip.getChildAt(1).setOnLongClickListener(new View.OnLongClickListener() {
|
2019-06-19 14:58:57 +02:00
|
|
|
@Override
|
2019-06-20 18:48:46 +02:00
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
PopupMenu popup = new PopupMenu(AdminActivity.this, tabStrip.getChildAt(1));
|
|
|
|
popup.getMenuInflater()
|
|
|
|
.inflate(R.menu.option_filter_admin_accounts, popup.getMenu());
|
|
|
|
Menu menu = popup.getMenu();
|
|
|
|
final MenuItem itemLocal = menu.findItem(R.id.action_local);
|
|
|
|
final MenuItem itemRemote = menu.findItem(R.id.action_remote);
|
|
|
|
final MenuItem itemActive = menu.findItem(R.id.action_active);
|
|
|
|
final MenuItem itemPending = menu.findItem(R.id.action_pending);
|
|
|
|
final MenuItem itemDisabled = menu.findItem(R.id.action_disabled);
|
|
|
|
final MenuItem itemSilenced = menu.findItem(R.id.action_silenced);
|
|
|
|
final MenuItem itemSuspended = menu.findItem(R.id.action_suspended);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
2019-06-30 15:30:45 +02:00
|
|
|
itemSilenced.setVisible(false);
|
|
|
|
itemPending.setVisible(false);
|
|
|
|
itemSuspended.setVisible(false);
|
|
|
|
}
|
2019-06-20 18:48:46 +02:00
|
|
|
|
|
|
|
itemLocal.setChecked(local);
|
|
|
|
itemRemote.setChecked(remote);
|
|
|
|
itemActive.setChecked(active);
|
|
|
|
itemPending.setChecked(pending);
|
|
|
|
itemDisabled.setChecked(disabled);
|
|
|
|
itemSilenced.setChecked(silenced);
|
|
|
|
itemSuspended.setChecked(suspended);
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-20 18:48:46 +02:00
|
|
|
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss(PopupMenu menu) {
|
|
|
|
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
|
fragTransaction.detach(displayAdminAccountsFragment);
|
|
|
|
Bundle bundle = new Bundle();
|
2019-09-06 17:55:14 +02:00
|
|
|
bundle.putBoolean("local", local);
|
|
|
|
bundle.putBoolean("remote", remote);
|
|
|
|
bundle.putBoolean("active", active);
|
|
|
|
bundle.putBoolean("pending", pending);
|
|
|
|
bundle.putBoolean("disabled", disabled);
|
|
|
|
bundle.putBoolean("silenced", silenced);
|
|
|
|
bundle.putBoolean("suspended", suspended);
|
2019-06-20 18:48:46 +02:00
|
|
|
displayAdminAccountsFragment.setArguments(bundle);
|
|
|
|
fragTransaction.attach(displayAdminAccountsFragment);
|
|
|
|
fragTransaction.commit();
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-20 18:48:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
2019-06-30 15:30:45 +02:00
|
|
|
|
2019-06-20 18:48:46 +02:00
|
|
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
|
|
|
item.setActionView(new View(getApplicationContext()));
|
|
|
|
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-20 18:48:46 +02:00
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2019-09-06 17:55:14 +02:00
|
|
|
switch (item.getItemId()) {
|
2019-06-20 18:48:46 +02:00
|
|
|
case R.id.action_local:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!local) {
|
2019-06-20 18:48:46 +02:00
|
|
|
remote = false;
|
|
|
|
local = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_remote:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!remote) {
|
2019-06-20 18:48:46 +02:00
|
|
|
remote = true;
|
|
|
|
local = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_active:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!active) {
|
2019-06-20 18:48:46 +02:00
|
|
|
active = true;
|
|
|
|
pending = false;
|
|
|
|
disabled = false;
|
|
|
|
silenced = false;
|
|
|
|
suspended = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_pending:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!pending) {
|
2019-06-20 18:48:46 +02:00
|
|
|
pending = true;
|
|
|
|
active = false;
|
|
|
|
disabled = false;
|
|
|
|
silenced = false;
|
|
|
|
suspended = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_disabled:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!disabled) {
|
2019-06-20 18:48:46 +02:00
|
|
|
disabled = true;
|
|
|
|
active = false;
|
|
|
|
pending = false;
|
|
|
|
silenced = false;
|
|
|
|
suspended = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_silenced:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!silenced) {
|
2019-06-20 18:48:46 +02:00
|
|
|
silenced = true;
|
|
|
|
active = false;
|
|
|
|
pending = false;
|
|
|
|
disabled = false;
|
|
|
|
suspended = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_suspended:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (!suspended) {
|
2019-06-20 18:48:46 +02:00
|
|
|
suspended = true;
|
|
|
|
active = false;
|
|
|
|
pending = false;
|
|
|
|
disabled = false;
|
|
|
|
silenced = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-06-20 18:48:46 +02:00
|
|
|
itemLocal.setChecked(local);
|
|
|
|
itemRemote.setChecked(remote);
|
|
|
|
itemActive.setChecked(active);
|
|
|
|
itemPending.setChecked(pending);
|
|
|
|
itemDisabled.setChecked(disabled);
|
|
|
|
itemSilenced.setChecked(silenced);
|
|
|
|
itemSuspended.setChecked(suspended);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
popup.show();
|
|
|
|
return true;
|
2019-06-19 14:58:57 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-20 18:48:46 +02:00
|
|
|
|
|
|
|
PagerAdapter mPagerAdapter = new AdminPagerAdapter(getSupportFragmentManager());
|
|
|
|
admin_viewpager.setAdapter(mPagerAdapter);
|
|
|
|
admin_viewpager.setOffscreenPageLimit(2);
|
|
|
|
admin_viewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(admin_tablayout));
|
2019-06-19 14:58:57 +02:00
|
|
|
admin_tablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
|
admin_viewpager.setCurrentItem(tab.getPosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabReselected(TabLayout.Tab tab) {
|
|
|
|
Fragment fragment = null;
|
2019-09-06 17:55:14 +02:00
|
|
|
if (admin_viewpager.getAdapter() != null)
|
2019-06-19 14:58:57 +02:00
|
|
|
fragment = (Fragment) admin_viewpager.getAdapter().instantiateItem(admin_viewpager, tab.getPosition());
|
2019-09-06 17:55:14 +02:00
|
|
|
switch (tab.getPosition()) {
|
2019-06-19 14:58:57 +02:00
|
|
|
case 0:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (fragment != null) {
|
2019-06-20 16:33:29 +02:00
|
|
|
displayAdminReportsFragment = ((DisplayAdminReportsFragment) fragment);
|
2019-06-19 14:58:57 +02:00
|
|
|
displayAdminReportsFragment.scrollToTop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-09-06 17:55:14 +02:00
|
|
|
if (fragment != null) {
|
2019-06-20 18:48:46 +02:00
|
|
|
displayAdminAccountsFragment = ((DisplayAdminAccountsFragment) fragment);
|
2019-06-19 14:58:57 +02:00
|
|
|
displayAdminAccountsFragment.scrollToTop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class AdminPagerAdapter extends FragmentStatePagerAdapter {
|
|
|
|
|
|
|
|
AdminPagerAdapter(FragmentManager fm) {
|
|
|
|
super(fm);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Fragment getItem(int position) {
|
|
|
|
Bundle bundle = new Bundle();
|
2019-09-06 17:55:14 +02:00
|
|
|
switch (position) {
|
2019-06-19 14:58:57 +02:00
|
|
|
case 0:
|
2019-06-20 18:48:46 +02:00
|
|
|
displayAdminReportsFragment = new DisplayAdminReportsFragment();
|
2019-06-20 16:33:29 +02:00
|
|
|
bundle = new Bundle();
|
2019-09-06 17:55:14 +02:00
|
|
|
bundle.putBoolean("unresolved", unresolved);
|
2019-06-20 16:33:29 +02:00
|
|
|
displayAdminReportsFragment.setArguments(bundle);
|
2019-06-19 14:58:57 +02:00
|
|
|
return displayAdminReportsFragment;
|
|
|
|
case 1:
|
2019-06-20 18:48:46 +02:00
|
|
|
displayAdminAccountsFragment = new DisplayAdminAccountsFragment();
|
|
|
|
bundle = new Bundle();
|
2019-09-06 17:55:14 +02:00
|
|
|
bundle.putBoolean("local", local);
|
|
|
|
bundle.putBoolean("remote", remote);
|
|
|
|
bundle.putBoolean("active", active);
|
|
|
|
bundle.putBoolean("pending", pending);
|
|
|
|
bundle.putBoolean("disabled", disabled);
|
|
|
|
bundle.putBoolean("silenced", silenced);
|
|
|
|
bundle.putBoolean("suspended", suspended);
|
2019-06-20 18:48:46 +02:00
|
|
|
displayAdminAccountsFragment.setArguments(bundle);
|
2019-06-19 14:58:57 +02:00
|
|
|
return displayAdminAccountsFragment;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-11-27 15:35:14 +01:00
|
|
|
@Override
|
|
|
|
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
2019-06-19 14:58:57 +02:00
|
|
|
|
2019-11-27 15:35:14 +01:00
|
|
|
}
|
2019-06-19 14:58:57 +02:00
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|