From eaef58037c9df2cb7938c4a34f2ee5bcaf6b0d17 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 14 Aug 2019 13:53:08 +0800 Subject: Editing flair is now available. --- app/build.gradle | 2 +- .../FlairBottomSheetFragment.java | 16 +++---- .../FlairBottomSheetRecyclerViewAdapter.java | 52 ++++++++++++++++++++-- .../infinityforreddit/PostImageActivity.java | 18 ++++---- .../infinityforreddit/PostLinkActivity.java | 2 + .../infinityforreddit/PostTextActivity.java | 18 ++++---- .../infinityforreddit/PostVideoActivity.java | 18 ++++---- app/src/main/res/drawable/ic_outline_edit_24px.xml | 9 ++++ app/src/main/res/layout/dialog_edit_flair.xml | 24 ++++++++++ app/src/main/res/layout/item_flair.xml | 26 ++++++++--- app/src/main/res/values/strings.xml | 4 ++ 11 files changed, 145 insertions(+), 44 deletions(-) create mode 100644 app/src/main/res/drawable/ic_outline_edit_24px.xml create mode 100644 app/src/main/res/layout/dialog_edit_flair.xml (limited to 'app') diff --git a/app/build.gradle b/app/build.gradle index b172df20..6cfa4e13 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,7 +34,7 @@ repositories { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.1.0-rc01' - implementation 'com.google.android.material:material:1.1.0-alpha08' + implementation 'com.google.android.material:material:1.1.0-alpha09' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' 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 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 { + 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 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); diff --git a/app/src/main/res/drawable/ic_outline_edit_24px.xml b/app/src/main/res/drawable/ic_outline_edit_24px.xml new file mode 100644 index 00000000..17a2a81f --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_edit_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/dialog_edit_flair.xml b/app/src/main/res/layout/dialog_edit_flair.xml new file mode 100644 index 00000000..7893cf66 --- /dev/null +++ b/app/src/main/res/layout/dialog_edit_flair.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_flair.xml b/app/src/main/res/layout/item_flair.xml index c6006358..7cce337f 100644 --- a/app/src/main/res/layout/item_flair.xml +++ b/app/src/main/res/layout/item_flair.xml @@ -1,16 +1,28 @@ + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:clickable="true" + android:focusable="true" + android:background="?attr/selectableItemBackground"> + android:textColor="@color/primaryTextColor" /> + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c7b64362..86af0755 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -194,6 +194,7 @@ Edit Delete Cancel + OK Edit successful Delete successfully Delete failed @@ -207,4 +208,7 @@ Unmark spoiler failed Update flair successful Update flair failed + + Edit Flair + Only allow less than 64 characters -- cgit v1.2.3