Editing flair is now available.

This commit is contained in:
Alex Ning 2019-08-14 13:53:08 +08:00
parent a62f47aacb
commit eaef58037c
15 changed files with 149 additions and 48 deletions

View File

@ -35,9 +35,9 @@
<map>
<entry key="assetSourceType" value="FILE" />
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_outline_more_vert_24px" />
<entry key="outputName" value="ic_outline_edit_24px" />
<entry key="overrideSize" value="true" />
<entry key="sourceFile" value="$USER_HOME$/Downloads/outline-more_vert-24px.svg" />
<entry key="sourceFile" value="$USER_HOME$/Downloads/outline-edit-24px.svg" />
</map>
</option>
</PersistentState>

Binary file not shown.

View File

@ -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'

View File

@ -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();
});

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M14.06,9.02l0.92,0.92L5.92,19L5,19v-0.92l9.06,-9.06M17.66,3c-0.25,0 -0.51,0.1 -0.7,0.29l-1.83,1.83 3.75,3.75 1.83,-1.83c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.2,-0.2 -0.45,-0.29 -0.71,-0.29zM14.06,6.19L3,17.25L3,21h3.75L17.81,9.94l-3.75,-3.75z"/>
</vector>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/flair_edit_text_edit_flair_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:background="#00000000"
android:textColor="@color/primaryTextColor"
android:hint="@string/flair"
android:maxLength="64" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="@string/only_allow_64_chars"
android:textColor="@color/colorAccent"/>
</LinearLayout>

View File

@ -1,16 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/flair_text_view_item_flair"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:textColor="@color/primaryTextColor"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
android:textColor="@color/primaryTextColor" />
<ImageView
android:id="@+id/edit_flair_image_view_item_flair"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical|end"
android:layout_marginStart="32dp"
android:src="@drawable/ic_outline_edit_24px"
android:visibility="gone"
android:tint="@color/primaryTextColor"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true" />
</LinearLayout>

View File

@ -194,6 +194,7 @@
<string name="edit">Edit</string>
<string name="delete">Delete</string>
<string name="cancel">Cancel</string>
<string name="ok">OK</string>
<string name="edit_success">Edit successful</string>
<string name="delete_post_success">Delete successfully</string>
<string name="delete_post_failed">Delete failed</string>
@ -207,4 +208,7 @@
<string name="unmark_spoiler_failed">Unmark spoiler failed</string>
<string name="update_flair_success">Update flair successful</string>
<string name="update_flair_failed">Update flair failed</string>
<string name="edit_flair">Edit Flair</string>
<string name="only_allow_64_chars">Only allow less than 64 characters</string>
</resources>

View File

@ -31,6 +31,6 @@ task clean(type: Delete) {
}
ext {
roomVersion = '2.2.0-alpha01'
archLifecycleVersion = '2.2.0-alpha02'
roomVersion = '2.2.0-alpha02'
archLifecycleVersion = '2.2.0-alpha03'
}