Blocked domains - 2
This commit is contained in:
parent
01e53f8e48
commit
045e5a80ed
|
@ -0,0 +1,57 @@
|
|||
/* Copyright 2018 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastalab 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 Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.asynctasks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveDomainsInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 26/09/2018.
|
||||
* Delete a blocked instance
|
||||
*/
|
||||
|
||||
public class DeleteDomainsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private OnRetrieveDomainsInterface listener;
|
||||
private WeakReference<Context> contextReference;
|
||||
private int response;
|
||||
private String domainName;
|
||||
|
||||
public DeleteDomainsAsyncTask(Context context, String domainName, OnRetrieveDomainsInterface onRetrieveDomainsInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.listener = onRetrieveDomainsInterface;
|
||||
this.domainName = domainName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(this.contextReference.get());
|
||||
response = api.deleteBlockedDomain(domainName);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveDomainsDeleted(response);
|
||||
}
|
||||
|
||||
}
|
|
@ -89,7 +89,8 @@ public class API {
|
|||
ENDORSE,
|
||||
UNENDORSE,
|
||||
SHOW_BOOST,
|
||||
HIDE_BOOST
|
||||
HIDE_BOOST,
|
||||
BLOCK_DOMAIN
|
||||
|
||||
}
|
||||
public enum accountPrivacy {
|
||||
|
@ -811,32 +812,6 @@ public class API {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a blocked domains for the authenticated account *synchronously*
|
||||
* @param domain String domain name
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
public int addBlockedDomain(String domain){
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("domain",domain);
|
||||
domains = new ArrayList<>();
|
||||
HttpsConnection httpsConnection;
|
||||
try {
|
||||
httpsConnection = new HttpsConnection(context);
|
||||
httpsConnection.post(getAbsoluteUrl("/domain_blocks"), 60, params, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return actionCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a blocked domains for the authenticated account *synchronously*
|
||||
|
@ -1053,6 +1028,9 @@ public class API {
|
|||
case BLOCK:
|
||||
action = String.format("/accounts/%s/block", targetedId);
|
||||
break;
|
||||
case BLOCK_DOMAIN:
|
||||
action = String.format("/domain_blocks/%s", targetedId);
|
||||
break;
|
||||
case UNBLOCK:
|
||||
action = String.format("/accounts/%s/unblock", targetedId);
|
||||
break;
|
||||
|
|
|
@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.drawers;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -28,6 +29,7 @@ import android.widget.TextView;
|
|||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.DeleteDomainsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveDomainsInterface;
|
||||
|
||||
|
@ -77,6 +79,7 @@ public class DomainsListAdapter extends RecyclerView.Adapter implements OnRetrie
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
domains.remove(domain);
|
||||
domainsListAdapter.notifyItemRemoved(holder.getAdapterPosition());
|
||||
new DeleteDomainsAsyncTask(context, domain, DomainsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( domains.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
dialog.dismiss();
|
||||
|
@ -112,6 +115,11 @@ public class DomainsListAdapter extends RecyclerView.Adapter implements OnRetrie
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveDomainsDeleted(int response) {
|
||||
|
||||
}
|
||||
|
||||
private class ViewHolder extends RecyclerView.ViewHolder{
|
||||
TextView domain_name;
|
||||
ImageView domain_delete;
|
||||
|
|
|
@ -1187,10 +1187,14 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
|
||||
popup.getMenu().findItem(R.id.action_report).setVisible(false);
|
||||
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
|
||||
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
|
||||
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
|
||||
}else {
|
||||
popup.getMenu().findItem(R.id.action_redraft).setVisible(false);
|
||||
popup.getMenu().findItem(R.id.action_remove).setVisible(false);
|
||||
//Same instance
|
||||
if(status.getAccount().getAcct().split("#").length <2 )
|
||||
popup.getMenu().findItem(R.id.action_block_domain).setVisible(false);
|
||||
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
|
||||
if( type != RetrieveFeedsAsyncTask.Type.HOME){
|
||||
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
|
||||
|
@ -1225,6 +1229,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
//noinspection deprecation
|
||||
builderInner.setMessage(Html.fromHtml(status.getContent()));
|
||||
break;
|
||||
case R.id.action_block_domain:
|
||||
builderInner = new AlertDialog.Builder(context);
|
||||
builderInner.setTitle(stringArrayConf[3]);
|
||||
doAction = API.StatusAction.BLOCK_DOMAIN;
|
||||
String domain = status.getAccount().getAcct().split("@")[1];
|
||||
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
|
||||
break;
|
||||
case R.id.action_mute:
|
||||
builderInner = new AlertDialog.Builder(context);
|
||||
builderInner.setTitle(stringArrayConf[0]);
|
||||
|
@ -1507,7 +1518,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
comment = finalInput.getText().toString();
|
||||
new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else{
|
||||
String targetedId = status.getAccount().getId();
|
||||
String targetedId;
|
||||
if( item.getItemId() == R.id.action_block_domain){
|
||||
targetedId = status.getAccount().getAcct().split("@")[1];
|
||||
}else {
|
||||
targetedId = status.getAccount().getId();
|
||||
}
|
||||
new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
dialog.dismiss();
|
||||
|
|
|
@ -200,6 +200,10 @@ public class DisplayMutedInstanceFragment extends Fragment implements OnRetrieve
|
|||
firstLoad = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveDomainsDeleted(int response) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,4 +23,5 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
|
|||
*/
|
||||
public interface OnRetrieveDomainsInterface {
|
||||
void onRetrieveDomains(APIResponse apiResponse);
|
||||
void onRetrieveDomainsDeleted(int response);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
android:id="@+id/action_report"
|
||||
android:title="@string/more_action_3"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_block_domain"
|
||||
android:title="@string/block_domain"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_redraft"
|
||||
android:title="@string/more_action_9"
|
||||
|
|
|
@ -129,6 +129,7 @@
|
|||
<item>Mute this account?</item>
|
||||
<item>Block this account?</item>
|
||||
<item>Report this toot?</item>
|
||||
<item>Block this domain?</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="more_action_owner_confirm">
|
||||
|
@ -625,7 +626,9 @@
|
|||
<string name="no_blocked_domain">No blocked domains!</string>
|
||||
<string name="unblock_domain_confirm">Unblock domain</string>
|
||||
<string name="unblock_domain_confirm_message">Are you sure to unblock %s?</string>
|
||||
<string name="block_domain_confirm_message">Are you sure to block %s?</string>
|
||||
<string name="blocked_domains">Blocked domains</string>
|
||||
<string name="block_domain">Block domain</string>
|
||||
|
||||
<string-array name="filter_expire">
|
||||
<item>Never</item>
|
||||
|
|
Loading…
Reference in New Issue