diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java index 9b0a422cf..9feb4c2af 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/EditProfileActivity.java @@ -46,6 +46,7 @@ import android.view.MenuItem; 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; @@ -64,6 +65,7 @@ import java.io.InputStream; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountInfoAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateCredentialAsyncTask; +import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Error; @@ -90,9 +92,11 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou private ImageView set_profile_picture, set_header_picture; private Button set_change_profile_picture, set_change_header_picture, set_profile_save; private TextView set_header_picture_overlay; + private CheckBox set_lock_account; private static final int PICK_IMAGE_HEADER = 4565; private static final int PICK_IMAGE_PROFILE = 6545; private String profile_picture, header_picture, profile_username, profile_note; + private API.accountPrivacy profile_privacy; private Bitmap profile_picture_bmp, profile_header_bmp; private ImageView pp_actionBar; private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE_HEADER = 754; @@ -147,7 +151,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou .load(url) .into(new SimpleTarget() { @Override - public void onResourceReady(Bitmap resource, Transition transition) { + public void onResourceReady(@NonNull Bitmap resource, Transition transition) { BitmapDrawable ppDrawable = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(25, getApplicationContext()), (int) Helper.convertDpToPixel(25, getApplicationContext()), true)); if( pp_actionBar != null){ pp_actionBar.setImageDrawable(ppDrawable); @@ -168,12 +172,14 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou set_change_header_picture = findViewById(R.id.set_change_header_picture); set_profile_save = findViewById(R.id.set_profile_save); set_header_picture_overlay = findViewById(R.id.set_header_picture_overlay); + set_lock_account = findViewById(R.id.set_lock_account); set_profile_save.setEnabled(false); set_change_header_picture.setEnabled(false); set_change_profile_picture.setEnabled(false); set_profile_name.setEnabled(false); set_profile_description.setEnabled(false); + set_lock_account.setEnabled(false); new RetrieveAccountInfoAsyncTask(getApplicationContext(), EditProfileActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); if( theme == Helper.THEME_LIGHT) { @@ -215,7 +221,11 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou set_change_profile_picture.setEnabled(true); set_profile_name.setEnabled(true); set_profile_description.setEnabled(true); - + set_lock_account.setEnabled(true); + if( account.isLocked()) + set_lock_account.setChecked(true); + else + set_lock_account.setChecked(false); set_profile_description.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @@ -368,6 +378,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou dialog_profile_picture.setBackground(set_profile_picture.getDrawable()); } } + profile_privacy = set_lock_account.isChecked()?API.accountPrivacy.LOCKED:API.accountPrivacy.PUBLIC; dialogBuilder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { @@ -379,7 +390,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou } }).start(); GlideApp.get(getApplicationContext()).clearMemory(); - new UpdateCredentialAsyncTask(getApplicationContext(), profile_username, profile_note, profile_picture, header_picture, EditProfileActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new UpdateCredentialAsyncTask(getApplicationContext(), profile_username, profile_note, profile_picture, header_picture, profile_privacy, EditProfileActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateCredentialAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateCredentialAsyncTask.java index 2b4a5defb..d39a9079a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateCredentialAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateCredentialAsyncTask.java @@ -32,22 +32,24 @@ import fr.gouv.etalab.mastodon.interfaces.OnUpdateCredentialInterface; public class UpdateCredentialAsyncTask extends AsyncTask { private String display_name, note, avatar, header; + private API.accountPrivacy privacy; private APIResponse apiResponse; private OnUpdateCredentialInterface listener; private WeakReference contextReference; - public UpdateCredentialAsyncTask(Context context, String display_name, String note, String avatar, String header, OnUpdateCredentialInterface onUpdateCredentialInterface){ + public UpdateCredentialAsyncTask(Context context, String display_name, String note, String avatar, String header, API.accountPrivacy privacy, OnUpdateCredentialInterface onUpdateCredentialInterface){ this.contextReference = new WeakReference<>(context); this.display_name = display_name; this.note = note; this.avatar = avatar; this.header = header; this.listener = onUpdateCredentialInterface; + this.privacy = privacy; } @Override protected Void doInBackground(Void... params) { - apiResponse = new API(this.contextReference.get()).updateCredential(display_name, note, avatar, header); + apiResponse = new API(this.contextReference.get()).updateCredential(display_name, note, avatar, header, privacy); return null; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 8a405be80..52c353061 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -78,7 +78,10 @@ public class API { PIN, UNPIN } - + public enum accountPrivacy { + PUBLIC, + LOCKED + } public API(Context context) { this.context = context; SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); @@ -137,7 +140,7 @@ public class API { * Update credential of the authenticated user *synchronously* * @return APIResponse */ - public APIResponse updateCredential(String display_name, String note, String avatar, String header) { + public APIResponse updateCredential(String display_name, String note, String avatar, String header, accountPrivacy privacy) { HashMap requestParams = new HashMap<>(); if( display_name != null) @@ -158,6 +161,8 @@ public class API { } catch (UnsupportedEncodingException e) { requestParams.put("avatar",avatar); } + if( privacy != null) + requestParams.put("locked",privacy==accountPrivacy.LOCKED?"true":"false"); if( header != null) try { requestParams.put("header",URLEncoder.encode(header, "UTF-8")); diff --git a/app/src/main/res/layout/activity_edit_profile.xml b/app/src/main/res/layout/activity_edit_profile.xml index e26b56698..a759f56ab 100644 --- a/app/src/main/res/layout/activity_edit_profile.xml +++ b/app/src/main/res/layout/activity_edit_profile.xml @@ -111,6 +111,13 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> + +