|
|
@ -12,6 +12,7 @@ import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
|
|
|
|
import android.support.design.widget.Snackbar; |
|
|
|
import android.support.v4.app.ActivityCompat; |
|
|
|
import android.support.v4.app.ActivityCompat; |
|
|
|
import android.support.v4.content.ContextCompat; |
|
|
|
import android.support.v4.content.ContextCompat; |
|
|
|
import android.support.v7.app.ActionBar; |
|
|
|
import android.support.v7.app.ActionBar; |
|
|
@ -24,7 +25,6 @@ import android.widget.Button; |
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.ProgressBar; |
|
|
|
import android.widget.ProgressBar; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.keylesspalace.tusky.entity.Account; |
|
|
|
import com.keylesspalace.tusky.entity.Account; |
|
|
|
import com.keylesspalace.tusky.entity.Profile; |
|
|
|
import com.keylesspalace.tusky.entity.Profile; |
|
|
@ -66,7 +66,7 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
@BindView(R.id.edit_profile_header) Button headerButton; |
|
|
|
@BindView(R.id.edit_profile_header) Button headerButton; |
|
|
|
@BindView(R.id.edit_profile_header_preview) ImageView headerPreview; |
|
|
|
@BindView(R.id.edit_profile_header_preview) ImageView headerPreview; |
|
|
|
@BindView(R.id.edit_profile_header_progress) ProgressBar headerProgress; |
|
|
|
@BindView(R.id.edit_profile_header_progress) ProgressBar headerProgress; |
|
|
|
@BindView(R.id.edit_profile_error) TextView errorText; |
|
|
|
@BindView(R.id.edit_profile_save_progress) ProgressBar saveProgress; |
|
|
|
|
|
|
|
|
|
|
|
private String priorDisplayName; |
|
|
|
private String priorDisplayName; |
|
|
|
private String priorNote; |
|
|
|
private String priorNote; |
|
|
@ -131,7 +131,7 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
public void onClick(View v) { |
|
|
|
headerPreview.setImageBitmap(null); |
|
|
|
headerPreview.setImageBitmap(null); |
|
|
|
avatarPreview.setVisibility(View.GONE); |
|
|
|
headerPreview.setVisibility(View.GONE); |
|
|
|
headerBase64 = null; |
|
|
|
headerBase64 = null; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -173,7 +173,11 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onMediaPick(PickType pickType) { |
|
|
|
private void onMediaPick(PickType pickType) { |
|
|
|
beginMediaPicking(pickType); |
|
|
|
if (currentlyPicking != PickType.NOTHING) { |
|
|
|
|
|
|
|
// Ignore inputs if another pick operation is still occurring.
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
currentlyPicking = pickType; |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && |
|
|
|
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) |
|
|
|
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) |
|
|
|
!= PackageManager.PERMISSION_GRANTED) { |
|
|
|
!= PackageManager.PERMISSION_GRANTED) { |
|
|
@ -195,7 +199,8 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
initiateMediaPicking(); |
|
|
|
initiateMediaPicking(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
endMediaPicking(); |
|
|
|
endMediaPicking(); |
|
|
|
errorText.setText(R.string.error_media_upload_permission); |
|
|
|
Snackbar.make(avatarButton, R.string.error_media_upload_permission, |
|
|
|
|
|
|
|
Snackbar.LENGTH_LONG).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -205,20 +210,13 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
private void initiateMediaPicking() { |
|
|
|
private void initiateMediaPicking() { |
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE); |
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE); |
|
|
|
intent.setType("*/*"); |
|
|
|
intent.setType("image/*"); |
|
|
|
switch (currentlyPicking) { |
|
|
|
switch (currentlyPicking) { |
|
|
|
case AVATAR: { |
|
|
|
case AVATAR: { startActivityForResult(intent, AVATAR_PICK_RESULT); break; } |
|
|
|
startActivityForResult(intent, AVATAR_PICK_RESULT); |
|
|
|
case HEADER: { startActivityForResult(intent, HEADER_PICK_RESULT); break; } |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case HEADER: { |
|
|
|
|
|
|
|
startActivityForResult(intent, HEADER_PICK_RESULT); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
getMenuInflater().inflate(R.menu.edit_profile_toolbar, menu); |
|
|
|
getMenuInflater().inflate(R.menu.edit_profile_toolbar, menu); |
|
|
@ -263,10 +261,15 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
// If it's not any different, don't patch it.
|
|
|
|
// If it's not any different, don't patch it.
|
|
|
|
newNote = null; |
|
|
|
newNote = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (newDisplayName == null && newNote == null && avatarBase64 == null |
|
|
|
|
|
|
|
&& headerBase64 == null) { |
|
|
|
|
|
|
|
// If nothing is changed, then there's nothing to save.
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isAlreadySaving = true; |
|
|
|
saveProgress.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "avatar " + avatarBase64); |
|
|
|
isAlreadySaving = true; |
|
|
|
|
|
|
|
|
|
|
|
Profile profile = new Profile(); |
|
|
|
Profile profile = new Profile(); |
|
|
|
profile.displayName = newDisplayName; |
|
|
|
profile.displayName = newDisplayName; |
|
|
@ -280,6 +283,9 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
onSaveFailure(); |
|
|
|
onSaveFailure(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getPrivatePreferences().edit() |
|
|
|
|
|
|
|
.putBoolean("refreshProfileHeader", true) |
|
|
|
|
|
|
|
.apply(); |
|
|
|
finish(); |
|
|
|
finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -292,21 +298,38 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
|
|
|
private void onSaveFailure() { |
|
|
|
private void onSaveFailure() { |
|
|
|
isAlreadySaving = false; |
|
|
|
isAlreadySaving = false; |
|
|
|
errorText.setText(getString(R.string.error_media_upload_sending)); |
|
|
|
Snackbar.make(avatarButton, R.string.error_media_upload_sending, Snackbar.LENGTH_LONG) |
|
|
|
|
|
|
|
.show(); |
|
|
|
|
|
|
|
saveProgress.setVisibility(View.GONE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void beginMediaPicking(PickType pickType) { |
|
|
|
private void beginMediaPicking() { |
|
|
|
currentlyPicking = pickType; |
|
|
|
|
|
|
|
switch (currentlyPicking) { |
|
|
|
switch (currentlyPicking) { |
|
|
|
case AVATAR: { avatarProgress.setVisibility(View.VISIBLE); break; } |
|
|
|
case AVATAR: { |
|
|
|
case HEADER: { headerProgress.setVisibility(View.VISIBLE); break; } |
|
|
|
avatarProgress.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
avatarPreview.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case HEADER: { |
|
|
|
|
|
|
|
headerProgress.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
headerPreview.setVisibility(View.INVISIBLE); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void endMediaPicking() { |
|
|
|
private void endMediaPicking() { |
|
|
|
switch (currentlyPicking) { |
|
|
|
switch (currentlyPicking) { |
|
|
|
case AVATAR: { avatarProgress.setVisibility(View.GONE); break; } |
|
|
|
case AVATAR: { |
|
|
|
case HEADER: { headerProgress.setVisibility(View.GONE); break; } |
|
|
|
avatarProgress.setVisibility(View.GONE); |
|
|
|
|
|
|
|
avatarPreview.setVisibility(View.GONE); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case HEADER: { |
|
|
|
|
|
|
|
headerProgress.setVisibility(View.GONE); |
|
|
|
|
|
|
|
headerPreview.setVisibility(View.GONE); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
currentlyPicking = PickType.NOTHING; |
|
|
|
currentlyPicking = PickType.NOTHING; |
|
|
|
} |
|
|
|
} |
|
|
@ -321,6 +344,8 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
.setInitialCropWindowPaddingRatio(0) |
|
|
|
.setInitialCropWindowPaddingRatio(0) |
|
|
|
.setAspectRatio(AVATAR_WIDTH, AVATAR_HEIGHT) |
|
|
|
.setAspectRatio(AVATAR_WIDTH, AVATAR_HEIGHT) |
|
|
|
.start(this); |
|
|
|
.start(this); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
endMediaPicking(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -330,6 +355,8 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
.setInitialCropWindowPaddingRatio(0) |
|
|
|
.setInitialCropWindowPaddingRatio(0) |
|
|
|
.setAspectRatio(HEADER_WIDTH, HEADER_HEIGHT) |
|
|
|
.setAspectRatio(HEADER_WIDTH, HEADER_HEIGHT) |
|
|
|
.start(this); |
|
|
|
.start(this); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
endMediaPicking(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -346,6 +373,7 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void beginResize(Uri uri) { |
|
|
|
private void beginResize(Uri uri) { |
|
|
|
|
|
|
|
beginMediaPicking(); |
|
|
|
int width, height; |
|
|
|
int width, height; |
|
|
|
switch (currentlyPicking) { |
|
|
|
switch (currentlyPicking) { |
|
|
|
default: { |
|
|
|
default: { |
|
|
@ -366,7 +394,9 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onSuccess(List<Bitmap> contentList) { |
|
|
|
public void onSuccess(List<Bitmap> contentList) { |
|
|
|
Bitmap bitmap = contentList.get(0); |
|
|
|
Bitmap bitmap = contentList.get(0); |
|
|
|
switch (currentlyPicking) { |
|
|
|
PickType pickType = currentlyPicking; |
|
|
|
|
|
|
|
endMediaPicking(); |
|
|
|
|
|
|
|
switch (pickType) { |
|
|
|
case AVATAR: { |
|
|
|
case AVATAR: { |
|
|
|
avatarPreview.setImageBitmap(bitmap); |
|
|
|
avatarPreview.setImageBitmap(bitmap); |
|
|
|
avatarPreview.setVisibility(View.VISIBLE); |
|
|
|
avatarPreview.setVisibility(View.VISIBLE); |
|
|
@ -380,7 +410,6 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
endMediaPicking(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -391,7 +420,8 @@ public class EditProfileActivity extends BaseActivity { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onResizeFailure() { |
|
|
|
private void onResizeFailure() { |
|
|
|
errorText.setText(getString(R.string.error_media_upload_sending)); |
|
|
|
Snackbar.make(avatarButton, R.string.error_media_upload_sending, Snackbar.LENGTH_LONG) |
|
|
|
|
|
|
|
.show(); |
|
|
|
endMediaPicking(); |
|
|
|
endMediaPicking(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|