Allows to lock/unlock the account in the profile activity
This commit is contained in:
parent
31f6baf44c
commit
a641212762
|
@ -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<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> 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() {
|
||||
|
|
|
@ -32,22 +32,24 @@ import fr.gouv.etalab.mastodon.interfaces.OnUpdateCredentialInterface;
|
|||
public class UpdateCredentialAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private String display_name, note, avatar, header;
|
||||
private API.accountPrivacy privacy;
|
||||
private APIResponse apiResponse;
|
||||
private OnUpdateCredentialInterface listener;
|
||||
private WeakReference<Context> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, String> 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"));
|
||||
|
|
|
@ -111,6 +111,13 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
<!-- Lock the account -->
|
||||
<CheckBox
|
||||
android:layout_marginTop="10dp"
|
||||
android:id="@+id/set_lock_account"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/set_lock_account"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:layout_marginTop="5dp"
|
||||
|
|
|
@ -314,6 +314,7 @@
|
|||
<string name="set_nsfw_timeout">NSFW view timeout (seconds, 0 means off)</string>
|
||||
<string name="settings_title_profile">Edit profile</string>
|
||||
<string name="set_profile_description">Bio…</string>
|
||||
<string name="set_lock_account">Lock account</string>
|
||||
<string name="set_save_changes">Save changes</string>
|
||||
<string name="set_header_picture_overlay">Choose a header picture</string>
|
||||
<string name="set_preview_reply">Display the number of replies in home timeline</string>
|
||||
|
|
Loading…
Reference in New Issue