add possibility to un/lock accounts

main
Conny Duck 7 years ago
parent ee65dbeff0
commit 06d44c949e
  1. 19
      app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.kt
  2. 4
      app/src/main/java/com/keylesspalace/tusky/MainActivity.java
  3. 1
      app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.java
  4. 21
      app/src/main/res/layout/activity_edit_profile.xml
  5. 2
      app/src/main/res/values/strings.xml

@ -57,6 +57,7 @@ private const val AVATAR_FILE_NAME = "avatar.png"
private const val KEY_OLD_DISPLAY_NAME = "OLD_DISPLAY_NAME" private const val KEY_OLD_DISPLAY_NAME = "OLD_DISPLAY_NAME"
private const val KEY_OLD_NOTE = "OLD_NOTE" private const val KEY_OLD_NOTE = "OLD_NOTE"
private const val KEY_OLD_LOCKED = "OLD_LOCKED"
private const val KEY_IS_SAVING = "IS_SAVING" private const val KEY_IS_SAVING = "IS_SAVING"
private const val KEY_CURRENTLY_PICKING = "CURRENTLY_PICKING" private const val KEY_CURRENTLY_PICKING = "CURRENTLY_PICKING"
private const val KEY_AVATAR_CHANGED = "AVATAR_CHANGED" private const val KEY_AVATAR_CHANGED = "AVATAR_CHANGED"
@ -73,6 +74,7 @@ class EditProfileActivity : BaseActivity(), Injectable {
private var oldDisplayName: String? = null private var oldDisplayName: String? = null
private var oldNote: String? = null private var oldNote: String? = null
private var oldLocked: Boolean = false
private var isSaving: Boolean = false private var isSaving: Boolean = false
private var currentlyPicking: PickType = PickType.NOTHING private var currentlyPicking: PickType = PickType.NOTHING
private var avatarChanged: Boolean = false private var avatarChanged: Boolean = false
@ -101,6 +103,7 @@ class EditProfileActivity : BaseActivity(), Injectable {
savedInstanceState?.let { savedInstanceState?.let {
oldDisplayName = it.getString(KEY_OLD_DISPLAY_NAME) oldDisplayName = it.getString(KEY_OLD_DISPLAY_NAME)
oldNote = it.getString(KEY_OLD_NOTE) oldNote = it.getString(KEY_OLD_NOTE)
oldLocked = it.getBoolean(KEY_OLD_LOCKED)
isSaving = it.getBoolean(KEY_IS_SAVING) isSaving = it.getBoolean(KEY_IS_SAVING)
currentlyPicking = it.getSerializable(KEY_CURRENTLY_PICKING) as PickType currentlyPicking = it.getSerializable(KEY_CURRENTLY_PICKING) as PickType
avatarChanged = it.getBoolean(KEY_AVATAR_CHANGED) avatarChanged = it.getBoolean(KEY_AVATAR_CHANGED)
@ -137,10 +140,12 @@ class EditProfileActivity : BaseActivity(), Injectable {
val me = response.body() val me = response.body()
oldDisplayName = me!!.displayName oldDisplayName = me!!.displayName
oldNote = me.note.toString() oldNote = me.note.toString()
oldLocked = me.locked
displayNameEditText.setText(oldDisplayName) displayNameEditText.setText(oldDisplayName)
noteEditText.setText(oldNote) noteEditText.setText(oldNote)
lockedCheckBox.isChecked = oldLocked
if (!avatarChanged) { if (!avatarChanged) {
Picasso.with(avatarPreview.context) Picasso.with(avatarPreview.context)
.load(me.avatar) .load(me.avatar)
@ -165,6 +170,7 @@ class EditProfileActivity : BaseActivity(), Injectable {
outState.run { outState.run {
putString(KEY_OLD_DISPLAY_NAME, oldDisplayName) putString(KEY_OLD_DISPLAY_NAME, oldDisplayName)
putString(KEY_OLD_NOTE, oldNote) putString(KEY_OLD_NOTE, oldNote)
putBoolean(KEY_OLD_LOCKED, oldLocked)
putBoolean(KEY_IS_SAVING, isSaving) putBoolean(KEY_IS_SAVING, isSaving)
putSerializable(KEY_CURRENTLY_PICKING, currentlyPicking) putSerializable(KEY_CURRENTLY_PICKING, currentlyPicking)
putBoolean(KEY_AVATAR_CHANGED, avatarChanged) putBoolean(KEY_AVATAR_CHANGED, avatarChanged)
@ -259,6 +265,13 @@ class EditProfileActivity : BaseActivity(), Injectable {
RequestBody.create(MultipartBody.FORM, newNote) RequestBody.create(MultipartBody.FORM, newNote)
} }
val newLocked = lockedCheckBox.isChecked
val locked = if (oldLocked == newLocked) {
null
} else {
RequestBody.create(MultipartBody.FORM, newLocked.toString())
}
val avatar = if (avatarChanged) { val avatar = if (avatarChanged) {
val avatarBody = RequestBody.create(MediaType.parse("image/png"), getCacheFileForName(AVATAR_FILE_NAME)) val avatarBody = RequestBody.create(MediaType.parse("image/png"), getCacheFileForName(AVATAR_FILE_NAME))
MultipartBody.Part.createFormData("avatar", getFileName(), avatarBody) MultipartBody.Part.createFormData("avatar", getFileName(), avatarBody)
@ -273,13 +286,13 @@ class EditProfileActivity : BaseActivity(), Injectable {
null null
} }
if (displayName == null && note == null && avatar == null && header == null) { if (displayName == null && note == null && locked == null && avatar == null && header == null) {
/** if nothing has changed, there is no need to make a network request */ /** if nothing has changed, there is no need to make a network request */
finish() finish()
return return
} }
mastodonApi.accountUpdateCredentials(displayName, note, avatar, header).enqueue(object : Callback<Account> { mastodonApi.accountUpdateCredentials(displayName, note, locked, avatar, header).enqueue(object : Callback<Account> {
override fun onResponse(call: Call<Account>, response: Response<Account>) { override fun onResponse(call: Call<Account>, response: Response<Account>) {
if (!response.isSuccessful) { if (!response.isSuccessful) {
onSaveFailure() onSaveFailure()

@ -69,7 +69,6 @@ import javax.inject.Inject;
import dagger.android.AndroidInjector; import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector; import dagger.android.DispatchingAndroidInjector;
import dagger.android.support.AndroidSupportInjection;
import dagger.android.support.HasSupportFragmentInjector; import dagger.android.support.HasSupportFragmentInjector;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
@ -457,7 +456,6 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity,
.setTitle(R.string.action_logout) .setTitle(R.string.action_logout)
.setMessage(getString(R.string.action_logout_confirm, activeAccount.getFullName())) .setMessage(getString(R.string.action_logout_confirm, activeAccount.getFullName()))
.setPositiveButton(android.R.string.yes, (dialog, which) -> { .setPositiveButton(android.R.string.yes, (dialog, which) -> {
;
NotificationHelper.deleteNotificationChannelsForAccount(accountManager.getActiveAccount(), MainActivity.this); NotificationHelper.deleteNotificationChannelsForAccount(accountManager.getActiveAccount(), MainActivity.this);
@ -521,6 +519,8 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity,
.withSelectable(false) .withSelectable(false)
.withIcon(GoogleMaterial.Icon.gmd_person_add); .withIcon(GoogleMaterial.Icon.gmd_person_add);
drawer.addItemAtPosition(followRequestsItem, 3); drawer.addItemAtPosition(followRequestsItem, 3);
} else {
drawer.removeItem(DRAWER_ITEM_FOLLOW_REQUESTS);
} }
updateProfiles(); updateProfiles();

@ -142,6 +142,7 @@ public interface MastodonApi {
Call<Account> accountUpdateCredentials( Call<Account> accountUpdateCredentials(
@Nullable @Part(value="display_name") RequestBody displayName, @Nullable @Part(value="display_name") RequestBody displayName,
@Nullable @Part(value="note") RequestBody note, @Nullable @Part(value="note") RequestBody note,
@Nullable @Part(value="locked") RequestBody locked,
@Nullable @Part MultipartBody.Part avatar, @Nullable @Part MultipartBody.Part avatar,
@Nullable @Part MultipartBody.Part header); @Nullable @Part MultipartBody.Part header);

@ -112,6 +112,27 @@
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/lockedCheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="30dp"
android:paddingStart="8dp"
android:text="@string/lock_account_label"
android:textSize="?attr/status_text_medium" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:paddingStart="40dp"
android:text="@string/lock_account_label_description"
android:textSize="?attr/status_text_small" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

@ -286,5 +286,7 @@
<string name="hint_describe_for_visually_impaired">Describe for visually impaired</string> <string name="hint_describe_for_visually_impaired">Describe for visually impaired</string>
<string name="action_set_caption">Set caption</string> <string name="action_set_caption">Set caption</string>
<string name="action_remove_media">Remove</string> <string name="action_remove_media">Remove</string>
<string name="lock_account_label">Lock account</string>
<string name="lock_account_label_description">Requires you to manually approve followers</string>
</resources> </resources>

Loading…
Cancel
Save