diff options
Diffstat (limited to 'app/src/main/java/ml')
6 files changed, 88 insertions, 36 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java index 6a9987cf..6087e350 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java @@ -2,8 +2,6 @@ package ml.docilealligator.infinityforreddit; import android.app.Activity; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -47,7 +45,7 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment { private String mAccessToken; private String mSubredditName; - private Activity mAcitivity; + private Activity mActivity; private FlairBottomSheetRecyclerViewAdapter mAdapter; @Inject @@ -70,17 +68,17 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment { ButterKnife.bind(this, rootView); - mAcitivity = getActivity(); + mActivity = getActivity(); - ((Infinity) mAcitivity.getApplication()).getAppComponent().inject(this); + ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + /*if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } + }*/ - mAdapter = new FlairBottomSheetRecyclerViewAdapter(flair -> { - ((FlairSelectionCallback) mAcitivity).flairSelected(flair); + mAdapter = new FlairBottomSheetRecyclerViewAdapter(mActivity, flair -> { + ((FlairSelectionCallback) mActivity).flairSelected(flair); dismiss(); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java index f3cf3328..d1eecf20 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java @@ -1,13 +1,20 @@ package ml.docilealligator.infinityforreddit; +import android.app.Activity; +import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import java.util.ArrayList; import butterknife.BindView; @@ -18,10 +25,12 @@ class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<FlairBott void onClick(Flair flair); } + private Context context; private ArrayList<Flair> flairs; private ItemClickListener itemClickListener; - FlairBottomSheetRecyclerViewAdapter(ItemClickListener itemClickListener) { + FlairBottomSheetRecyclerViewAdapter(Context context, ItemClickListener itemClickListener) { + this.context = context; this.itemClickListener = itemClickListener; } @@ -33,6 +42,36 @@ class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<FlairBott @Override public void onBindViewHolder(@NonNull FlairViewHolder holder, int position) { + if(flairs.get(holder.getAdapterPosition()).isEditable()) { + holder.editFlairImageView.setVisibility(View.VISIBLE); + holder.editFlairImageView.setOnClickListener(view -> { + View dialogView = ((Activity) context).getLayoutInflater().inflate(R.layout.dialog_edit_flair, null); + EditText flairEditText = dialogView.findViewById(R.id.flair_edit_text_edit_flair_dialog); + flairEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + if(imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(context, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.edit_flair) + .setView(dialogView) + .setPositiveButton(R.string.ok, (dialogInterface, i) + -> { + Flair flair = flairs.get(holder.getAdapterPosition()); + flair.setText(flairEditText.getText().toString()); + itemClickListener.onClick(flair); + }) + .setNegativeButton(R.string.cancel, null) + .show(); + }); + } + + if(flairs.get(holder.getAdapterPosition()).isEditable() && flairs.get(holder.getAdapterPosition()).getText().equals("")) { + holder.itemView.setOnClickListener(view -> holder.editFlairImageView.performClick()); + } else { + holder.itemView.setOnClickListener(view -> itemClickListener.onClick(flairs.get(holder.getAdapterPosition()))); + } + holder.flairTextView.setText(flairs.get(holder.getAdapterPosition()).getText()); } @@ -41,19 +80,26 @@ class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<FlairBott return flairs == null ? 0 : flairs.size(); } + @Override + public void onViewRecycled(@NonNull FlairViewHolder holder) { + super.onViewRecycled(holder); + holder.editFlairImageView.setVisibility(View.GONE); + } + void changeDataset(ArrayList<Flair> flairs) { this.flairs = flairs; notifyDataSetChanged(); } class FlairViewHolder extends RecyclerView.ViewHolder { + View itemView; @BindView(R.id.flair_text_view_item_flair) TextView flairTextView; + @BindView(R.id.edit_flair_image_view_item_flair) ImageView editFlairImageView; FlairViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); - - flairTextView.setOnClickListener(view -> itemClickListener.onClick(flairs.get(getAdapterPosition()))); + this.itemView = itemView; } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java index 7d2a999b..67bcd4ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java @@ -72,7 +72,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS @BindView(R.id.coordinator_layout_post_image_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.toolbar_post_image_activity) Toolbar toolbar; @BindView(R.id.subreddit_icon_gif_image_view_post_image_activity) GifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_post_image_activity) TextView subreditNameTextView; + @BindView(R.id.subreddit_name_text_view_post_image_activity) TextView subredditNameTextView; @BindView(R.id.rules_button_post_image_activity) Button rulesButton; @BindView(R.id.flair_custom_text_view_post_image_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_image_activity) CustomTextView spoilerTextView; @@ -168,7 +168,8 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS } if(subredditName != null) { - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { loadSubredditIcon(); @@ -198,7 +199,8 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); loadSubredditIcon(); } else { mGlide.load(R.drawable.subreddit_default_icon) @@ -212,7 +214,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); - subreditNameTextView.setOnClickListener(view -> { + subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -376,9 +378,9 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS String subredditName; if(subredditIsUser) { - subredditName = "u_" + subreditNameTextView.getText().toString(); + subredditName = "u_" + subredditNameTextView.getText().toString(); } else { - subredditName = subreditNameTextView.getText().toString(); + subredditName = subredditNameTextView.getText().toString(); } Intent intent = new Intent(this, SubmitPostService.class); @@ -433,8 +435,8 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); displaySubredditIcon(); flairTextView.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java index 15b47cce..7643ec07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java @@ -138,6 +138,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if(subredditName != null) { + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { @@ -168,6 +169,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java index 7d401c90..105da07f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java @@ -58,7 +58,7 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh @BindView(R.id.coordinator_layout_post_text_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.toolbar_post_text_activity) Toolbar toolbar; @BindView(R.id.subreddit_icon_gif_image_view_search_activity) GifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_search_activity) TextView subreditNameTextView; + @BindView(R.id.subreddit_name_text_view_search_activity) TextView subredditNameTextView; @BindView(R.id.rules_button_post_text_activity) Button rulesButton; @BindView(R.id.flair_custom_text_view_post_text_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_text_activity) CustomTextView spoilerTextView; @@ -131,7 +131,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if(subredditName != null) { - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { loadSubredditIcon(); @@ -160,7 +161,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); } else { @@ -175,7 +177,7 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); - subreditNameTextView.setOnClickListener(view -> { + subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -299,9 +301,9 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh String subredditName; if(subredditIsUser) { - subredditName = "u_" + subreditNameTextView.getText().toString(); + subredditName = "u_" + subredditNameTextView.getText().toString(); } else { - subredditName = subreditNameTextView.getText().toString(); + subredditName = subredditNameTextView.getText().toString(); } Intent intent = new Intent(this, SubmitPostService.class); @@ -348,8 +350,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); displaySubredditIcon(); flairTextView.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java index b0ab91bb..fcf3a5d4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java @@ -67,7 +67,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS @BindView(R.id.coordinator_layout_post_video_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.toolbar_post_video_activity) Toolbar toolbar; @BindView(R.id.subreddit_icon_gif_image_view_post_video_activity) GifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_post_video_activity) TextView subreditNameTextView; + @BindView(R.id.subreddit_name_text_view_post_video_activity) TextView subredditNameTextView; @BindView(R.id.rules_button_post_video_activity) Button rulesButton; @BindView(R.id.flair_custom_text_view_post_video_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_video_activity) CustomTextView spoilerTextView; @@ -166,7 +166,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS } if(subredditName != null) { - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { loadSubredditIcon(); @@ -196,7 +197,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); loadSubredditIcon(); } else { mGlide.load(R.drawable.subreddit_default_icon) @@ -210,7 +212,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); - subreditNameTextView.setOnClickListener(view -> { + subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -371,9 +373,9 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS String subredditName; if(subredditIsUser) { - subredditName = "u_" + subreditNameTextView.getText().toString(); + subredditName = "u_" + subredditNameTextView.getText().toString(); } else { - subredditName = subreditNameTextView.getText().toString(); + subredditName = subredditNameTextView.getText().toString(); } Intent intent = new Intent(this, SubmitPostService.class); @@ -434,8 +436,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); - subreditNameTextView.setText(subredditName); + subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setText(subredditName); displaySubredditIcon(); flairTextView.setVisibility(View.VISIBLE); |