Display users

This commit is contained in:
tom79 2019-06-21 18:42:00 +02:00
parent fb8297ea14
commit 36fac88338
6 changed files with 429 additions and 4 deletions

View File

@ -237,6 +237,11 @@
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.AccountReportActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
<activity android:name="app.fedilab.android.activities.ReorderTimelinesActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"

View File

@ -0,0 +1,160 @@
package app.fedilab.android.activities;
/* 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>. */
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import app.fedilab.android.R;
import app.fedilab.android.asynctasks.PostAdminActionAsyncTask;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.AccountAdmin;
import app.fedilab.android.client.Entities.Report;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.interfaces.OnAdminActionInterface;
import es.dmoral.toasty.Toasty;
public class AccountReportActivity extends BaseActivity implements OnAdminActionInterface {
TextView permissions, email, email_status, login_status, joined, recent_ip;
Button warn, disable, silence;
private String account_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
setTheme(R.style.AppAdminTheme);
Report report = null;
AccountAdmin targeted_account = null;
Bundle b = getIntent().getExtras();
if (b != null) {
account_id = b.getString("account_id", null);
targeted_account = b.getParcelable("targeted_account");
report = b.getParcelable("report");
}
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
assert inflater != null;
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, null);
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();
}
});
toolbar_title.setText(String.format(getString(R.string.administration) + " %s", Helper.getLiveInstance(getApplicationContext())));
}
setContentView(R.layout.activity_admin_report);
warn = findViewById(R.id.warn);
disable = findViewById(R.id.disable);
silence = findViewById(R.id.silence);
permissions = findViewById(R.id.permissions);
email = findViewById(R.id.email);
email_status = findViewById(R.id.email_status);
login_status = findViewById(R.id.login_status);
joined = findViewById(R.id.joined);
recent_ip = findViewById(R.id.recent_ip);
CheckBox email_user = findViewById(R.id.email_user);
EditText comment = findViewById(R.id.comment);
if( account_id == null && report == null && targeted_account == null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
finish();
}
if( account_id != null){
new PostAdminActionAsyncTask(getApplicationContext(), API.adminAction.GET_ONE_ACCOUNT, account_id, null, AccountReportActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return;
}
if( report != null) {
targeted_account = report.getAccount();
}
fillReport(targeted_account);
}
@Override
public void onAdminAction(APIResponse apiResponse) {
if( apiResponse == null || apiResponse.getError() != null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
return;
}
if( apiResponse.getAccountAdmins() != null && apiResponse.getAccountAdmins().size() > 0) {
fillReport(apiResponse.getAccountAdmins().get(0));
}
}
private void fillReport(AccountAdmin accountAdmin){
if( accountAdmin == null){
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
return;
}
switch (accountAdmin.getRole()){
case "user":
permissions.setText(getString(R.string.user));
break;
case "mod":
permissions.setText(getString(R.string.moderator));
break;
case "admin":
permissions.setText(getString(R.string.administrator));
break;
}
email.setText(accountAdmin.getEmail());
email_status.setText(accountAdmin.isConfirmed()?getString(R.string.confirmed):getString(R.string.unconfirmed));
if( accountAdmin.isDisabled()){
login_status.setText(getString(R.string.disabled));
}else if( accountAdmin.isSilenced()){
login_status.setText(getString(R.string.silenced));
}else if( accountAdmin.isSuspended()){
login_status.setText(getString(R.string.suspended));
}else{
login_status.setText(getString(R.string.active));
}
joined.setText(Helper.dateToString(accountAdmin.getCreated_at()));
recent_ip.setText(accountAdmin.getIp());
}
}

View File

@ -15,6 +15,8 @@ package app.fedilab.android.drawers;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -28,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.activities.AccountReportActivity;
import app.fedilab.android.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.AccountAdmin;
@ -97,6 +100,15 @@ public class AccountsAdminListAdapter extends RecyclerView.Adapter implements On
holder.report_action_taken.setText(accountAdmin.getIp());
Helper.loadGiF(context, account.getAvatar(), holder.account_pp);
holder.main_container.setOnClickListener(view ->{
Intent intent = new Intent(context, AccountReportActivity.class);
Bundle b = new Bundle();
b.putParcelable("targeted_account", accountAdmin);
intent.putExtras(b);
context.startActivity(intent);
});
}
@Override
@ -141,7 +153,7 @@ public class AccountsAdminListAdapter extends RecyclerView.Adapter implements On
TextView account_un;
TextView report_action_taken;
LinearLayout account_container;
LinearLayout main_container;
ViewHolder(View itemView) {
super(itemView);
@ -150,7 +162,7 @@ public class AccountsAdminListAdapter extends RecyclerView.Adapter implements On
account_ac = itemView.findViewById(R.id.account_ac);
account_un = itemView.findViewById(R.id.account_un);
report_action_taken = itemView.findViewById(R.id.report_action_taken);
account_container = itemView.findViewById(R.id.account_container);
main_container = itemView.findViewById(R.id.main_container);
}
}

View File

@ -15,6 +15,8 @@ package app.fedilab.android.drawers;
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -28,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.activities.AccountReportActivity;
import app.fedilab.android.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Report;
@ -104,6 +107,14 @@ public class ReportsListAdapter extends RecyclerView.Adapter implements OnRetrie
holder.report_number_status.setText("0");
}
holder.main_container.setOnClickListener(view ->{
Intent intent = new Intent(context, AccountReportActivity.class);
Bundle b = new Bundle();
b.putParcelable("report", report);
intent.putExtras(b);
context.startActivity(intent);
});
}
@Override
@ -147,7 +158,7 @@ public class ReportsListAdapter extends RecyclerView.Adapter implements OnRetrie
TextView account_dn, account_dn_reporter;
TextView report_comment, report_number_status;
LinearLayout account_container;
LinearLayout main_container;
ViewHolder(View itemView) {
super(itemView);
@ -157,7 +168,7 @@ public class ReportsListAdapter extends RecyclerView.Adapter implements OnRetrie
account_dn_reporter = itemView.findViewById(R.id.account_dn_reporter);
account_ac = itemView.findViewById(R.id.account_ac);
report_comment = itemView.findViewById(R.id.report_comment);
account_container = itemView.findViewById(R.id.account_container);
main_container = itemView.findViewById(R.id.main_container);
report_number_status = itemView.findViewById(R.id.report_number_status);
}
}

View File

@ -0,0 +1,221 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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>.
-->
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
tools:context="app.fedilab.android.activities.AdminActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="@string/permissions"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/permissions"
android:layout_width="wrap_content"
android:layout_weight="3"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="@string/email"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_weight="3"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="@string/email_status"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/email_status"
android:layout_width="wrap_content"
android:layout_weight="3"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="@string/login_status"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/login_status"
android:layout_width="wrap_content"
android:layout_weight="3"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="@string/joined"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/joined"
android:layout_width="wrap_content"
android:layout_weight="3"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="@string/recent_ip"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/recent_ip"
android:layout_width="wrap_content"
android:layout_weight="3"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<Button
android:id="@+id/warn"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/warn"
android:textSize="16sp" />
<Button
android:id="@+id/disable"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/disable"
android:textSize="16sp" />
<Button
android:id="@+id/silence"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/silence"
android:textSize="16sp" />
</LinearLayout>
<CheckBox
android:layout_marginTop="20dp"
android:checked="true"
android:id="@+id/email_user"
android:text="@string/email_user"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:labelFor="@+id/comment"
android:text="@string/custom_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:minLines="3"
android:id="@+id/comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!--
<Button
android:id="@+id/action"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/perform_action"
android:textSize="18sp" />
-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_statuses"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:divider="@null"
/>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1041,6 +1041,22 @@
<string name="disabled">Disabled</string>
<string name="silenced">Silenced</string>
<string name="suspended">Suspended</string>
<string name="permissions">Permissions</string>
<string name="email_status">Email status</string>
<string name="login_status">Login status</string>
<string name="joined">Joined</string>
<string name="recent_ip">Most recent IP</string>
<string name="warn">Warn</string>
<string name="disable">Disable</string>
<string name="silence">Silence</string>
<string name="email_user">Notify the user per e-mail</string>
<string name="perform_action">Perform action</string>
<string name="custom_warning">Custom warning</string>
<string name="user">User</string>
<string name="moderator">Moderator</string>
<string name="administrator">Administrator</string>
<string name="confirmed">Confirmed</string>
<string name="unconfirmed">Not confirmed</string>
<plurals name="number_of_vote">
<item quantity="one">%d vote</item>
<item quantity="other">%d votes</item>