mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 19:38:22 +01:00
Clear user flair.
This commit is contained in:
parent
767bfb5af6
commit
3c0e2ab2d6
@ -26,15 +26,17 @@ public class SelectUserFlair {
|
||||
void failed(String errorMessage);
|
||||
}
|
||||
|
||||
public static void selectUserFlair(Retrofit oauthRetrofit, String accessToken, UserFlair userFlair,
|
||||
public static void selectUserFlair(Retrofit oauthRetrofit, String accessToken, @Nullable UserFlair userFlair,
|
||||
String subredditName, String accountName, SelectUserFlairListener selectUserFlairListener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON);
|
||||
params.put(APIUtils.FLAIR_TEMPLATE_ID_KEY, userFlair.getId());
|
||||
if (userFlair != null) {
|
||||
params.put(APIUtils.FLAIR_TEMPLATE_ID_KEY, userFlair.getId());
|
||||
params.put(APIUtils.TEXT_KEY, userFlair.getText());
|
||||
}
|
||||
params.put(APIUtils.NAME_KEY, accountName);
|
||||
params.put(APIUtils.TEXT_KEY, userFlair.getText());
|
||||
oauthRetrofit.create(RedditAPI.class).selectUserFlair(APIUtils.getOAuthHeader(accessToken), params, subredditName)
|
||||
.enqueue(new Callback<String>() {
|
||||
.enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
|
@ -11,6 +11,7 @@ import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -162,12 +163,20 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.select_this_user_flair)
|
||||
.setMessage(userFlair.getText())
|
||||
.setPositiveButton(R.string.yes, (dialogInterface, i) -> selectUserFlair(userFlair))
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.show();
|
||||
if (userFlair == null) {
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.clear_user_flair)
|
||||
.setPositiveButton(R.string.yes, (dialogInterface, i) -> selectUserFlair(userFlair))
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.show();
|
||||
} else {
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.select_this_user_flair)
|
||||
.setMessage(userFlair.getText())
|
||||
.setPositiveButton(R.string.yes, (dialogInterface, i) -> selectUserFlair(userFlair))
|
||||
.setNegativeButton(R.string.no, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
mLinearLayoutManager = new LinearLayoutManagerBugFixed(SelectUserFlairActivity.this);
|
||||
@ -175,19 +184,27 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
private void selectUserFlair(UserFlair userFlair) {
|
||||
private void selectUserFlair(@Nullable UserFlair userFlair) {
|
||||
SelectUserFlair.selectUserFlair(mOauthRetrofit, mAccessToken, userFlair, mSubredditName, mAccountName,
|
||||
new SelectUserFlair.SelectUserFlairListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
Toast.makeText(SelectUserFlairActivity.this, R.string.select_user_flair_success, Toast.LENGTH_SHORT).show();
|
||||
if (userFlair == null) {
|
||||
Toast.makeText(SelectUserFlairActivity.this, R.string.clear_user_flair_success, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(SelectUserFlairActivity.this, R.string.select_user_flair_success, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(String errorMessage) {
|
||||
if (errorMessage == null || errorMessage.equals("")) {
|
||||
Snackbar.make(coordinatorLayout, R.string.select_user_flair_success, Snackbar.LENGTH_SHORT).show();
|
||||
if (userFlair == null) {
|
||||
Snackbar.make(coordinatorLayout, R.string.clear_user_flair_success, Snackbar.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Snackbar.make(coordinatorLayout, R.string.select_user_flair_success, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -46,23 +46,28 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof UserFlairViewHolder) {
|
||||
UserFlair userFlair = userFlairs.get(holder.getBindingAdapterPosition());
|
||||
if (userFlair.getHtmlText() == null || userFlair.getHtmlText().equals("")) {
|
||||
((UserFlairViewHolder) holder).userFlairHtmlTextView.setText(userFlair.getText());
|
||||
} else {
|
||||
Utils.setHTMLWithImageToTextView(((UserFlairViewHolder) holder).userFlairHtmlTextView, userFlair.getHtmlText(), true);
|
||||
}
|
||||
if (userFlair.isEditable()) {
|
||||
((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if (position == 0) {
|
||||
((UserFlairViewHolder) holder).userFlairHtmlTextView.setText(R.string.clear_user_flair);
|
||||
((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.GONE);
|
||||
} else {
|
||||
UserFlair userFlair = userFlairs.get(holder.getBindingAdapterPosition() - 1);
|
||||
if (userFlair.getHtmlText() == null || userFlair.getHtmlText().equals("")) {
|
||||
((UserFlairViewHolder) holder).userFlairHtmlTextView.setText(userFlair.getText());
|
||||
} else {
|
||||
Utils.setHTMLWithImageToTextView(((UserFlairViewHolder) holder).userFlairHtmlTextView, userFlair.getHtmlText(), true);
|
||||
}
|
||||
if (userFlair.isEditable()) {
|
||||
((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return userFlairs == null ? 0 : userFlairs.size();
|
||||
return userFlairs == null ? 1 : userFlairs.size() + 1;
|
||||
}
|
||||
|
||||
class UserFlairViewHolder extends RecyclerView.ViewHolder {
|
||||
@ -84,11 +89,15 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV
|
||||
}
|
||||
|
||||
itemView.setOnClickListener(view -> {
|
||||
itemClickListener.onClick(userFlairs.get(getBindingAdapterPosition()), false);
|
||||
if (getBindingAdapterPosition() == 0) {
|
||||
itemClickListener.onClick(null, false);
|
||||
} else {
|
||||
itemClickListener.onClick(userFlairs.get(getBindingAdapterPosition() - 1), false);
|
||||
}
|
||||
});
|
||||
|
||||
editUserFlairImageView.setOnClickListener(view -> {
|
||||
itemClickListener.onClick(userFlairs.get(getBindingAdapterPosition()), true);
|
||||
itemClickListener.onClick(userFlairs.get(getBindingAdapterPosition() - 1), true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1053,6 +1053,8 @@
|
||||
|
||||
<string name="select_user_flair_success">User flair selected</string>
|
||||
<string name="select_this_user_flair">Select this user flair?</string>
|
||||
<string name="clear_user_flair">Clear Flair</string>
|
||||
<string name="clear_user_flair_success">User flair cleared</string>
|
||||
|
||||
<string name="select_header_size">Select Header Size</string>
|
||||
<string name="large">Large</string>
|
||||
|
Loading…
Reference in New Issue
Block a user