aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java35
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java33
3 files changed, 53 insertions, 25 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java
index e2607976..bb4b13b5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java
@@ -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()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java
index 244fe14c..9f875d70 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java
@@ -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();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java
index 5eec9c24..3f88fe19 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java
@@ -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);
});
}
}