Add char counter

captchafix
Floens 11 years ago
parent 1f8b0a5cbe
commit bb0a2fbf92
  1. 78
      Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java
  2. 76
      Clover/app/src/main/res/layout/reply_input.xml
  3. 5
      Clover/app/src/main/res/values/strings.xml

@ -23,8 +23,10 @@ import android.app.DialogFragment;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.Selection; import android.text.Selection;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -81,6 +83,9 @@ public class ReplyFragment extends DialogFragment {
private boolean gettingCaptcha = false; private boolean gettingCaptcha = false;
private String captchaChallenge = ""; private String captchaChallenge = "";
private int defaultTextColor;
private int maxCommentCount;
// Views // Views
private View container; private View container;
private ViewFlipper flipper; private ViewFlipper flipper;
@ -97,6 +102,10 @@ public class ReplyFragment extends DialogFragment {
private LoadView captchaContainer; private LoadView captchaContainer;
private TextView captchaInput; private TextView captchaInput;
private LoadView responseContainer; private LoadView responseContainer;
private Button insertInline;
private Button insertSpoiler;
private Button insertCode;
private TextView commentCountView;
private Activity context; private Activity context;
@ -180,6 +189,31 @@ public class ReplyFragment extends DialogFragment {
subjectView.setVisibility(View.GONE); subjectView.setVisibility(View.GONE);
} }
defaultTextColor = commentView.getCurrentTextColor();
Board b = ChanApplication.getBoardManager().getBoardByValue(loadable.board);
if (b != null) {
insertSpoiler.setVisibility(b.spoilers ? View.VISIBLE : View.GONE);
insertCode.setVisibility(b.codeTags ? View.VISIBLE : View.GONE);
maxCommentCount = b.maxCommentChars;
}
commentView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
showCommentCount();
}
});
showCommentCount();
getCaptcha(); getCaptcha();
} else { } else {
Logger.e(TAG, "Loadable in ReplyFragment was null"); Logger.e(TAG, "Loadable in ReplyFragment was null");
@ -297,6 +331,32 @@ public class ReplyFragment extends DialogFragment {
} }
}); });
insertInline = (Button) container.findViewById(R.id.insert_inline);
insertInline.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insertAtCursor(">", "");
}
});
insertSpoiler = (Button) container.findViewById(R.id.insert_spoiler);
insertSpoiler.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insertAtCursor("[spoiler]", "[/spoiler]");
}
});
insertCode = (Button) container.findViewById(R.id.insert_code);
insertCode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insertAtCursor("[code]", "[/code]");
}
});
commentCountView = (TextView) container.findViewById(R.id.reply_comment_counter);
return container; return container;
} }
@ -311,6 +371,24 @@ public class ReplyFragment extends DialogFragment {
} }
} }
private void insertAtCursor(String before, String after) {
int pos = commentView.getSelectionStart();
String text = commentView.getText().toString();
text = new StringBuilder(text).insert(pos, before + after).toString();
commentView.setText(text);
commentView.setSelection(pos + before.length());
}
private void showCommentCount() {
int count = commentView.getText().length();
commentCountView.setText(count + "/" + maxCommentCount);
if (count > maxCommentCount) {
commentCountView.setTextColor(0xffff0000);
} else {
commentCountView.setTextColor(defaultTextColor);
}
}
private void closeReply() { private void closeReply() {
if (getDialog() != null) { if (getDialog() != null) {
dismiss(); dismiss();

@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/reply_name" android:hint="@string/reply_name"
android:minHeight="48dp" android:minHeight="48dp"
android:textSize="16sp" /> android:textSize="14sp" />
<EditText <EditText
android:id="@+id/reply_subject" android:id="@+id/reply_subject"
@ -38,7 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/reply_subject" android:hint="@string/reply_subject"
android:minHeight="48dp" android:minHeight="48dp"
android:textSize="16sp" /> android:textSize="14sp" />
<EditText <EditText
android:id="@+id/reply_email" android:id="@+id/reply_email"
@ -46,17 +46,71 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/reply_email" android:hint="@string/reply_email"
android:minHeight="48dp" android:minHeight="48dp"
android:textSize="16sp" /> android:textSize="14sp" />
<EditText <RelativeLayout
android:id="@+id/reply_comment" android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/reply_comment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:hint="@string/reply_comment"
android:imeActionLabel="@string/reply_submit"
android:inputType="textMultiLine|textCapSentences|textAutoCorrect"
android:minLines="4"
android:textSize="14sp" />
<TextView
android:id="@+id/reply_comment_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="8dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<LinearLayout
style="?android:buttonBarStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/reply_comment" android:orientation="horizontal">
android:imeActionLabel="@string/reply_submit"
android:inputType="textMultiLine|textCapSentences|textAutoCorrect" <Button
android:minLines="4" android:id="@+id/insert_inline"
android:textSize="16sp" /> style="?android:buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:minWidth="48dp"
android:text="@string/reply_insert_inline"
android:textSize="14sp" />
<Button
android:id="@+id/insert_spoiler"
style="?android:buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:minWidth="48dp"
android:text="@string/reply_insert_spoiler"
android:textSize="14sp" />
<Button
android:id="@+id/insert_code"
style="?android:buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:minWidth="48dp"
android:text="@string/reply_insert_code"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -70,7 +124,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:layout_weight="1" android:layout_weight="1"
android:hint="@string/reply_file_name" android:hint="@string/reply_file_name"
android:minHeight="48dp" android:minHeight="48dp"
android:textSize="16sp" /> android:textSize="14sp" />
<ImageButton <ImageButton
android:id="@+id/reply_file" android:id="@+id/reply_file"

@ -117,6 +117,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="reply_file_name">File name</string> <string name="reply_file_name">File name</string>
<string name="reply_spoiler_image">Spoiler image</string> <string name="reply_spoiler_image">Spoiler image</string>
<string name="reply_no_preview">No preview available</string> <string name="reply_no_preview">No preview available</string>
<string name="reply_insert_inline">&gt;</string>
<string name="reply_insert_spoiler">[spoiler]</string>
<string name="reply_insert_code">[code]</string>
<string name="reply_submit">Submit</string> <string name="reply_submit">Submit</string>
<string name="reply_captcha">Enter the text</string> <string name="reply_captcha">Enter the text</string>
<string name="reply_error">Error sending reply</string> <string name="reply_error">Error sending reply</string>

Loading…
Cancel
Save