Cleaned up ReplyFragment

captchafix
Florens Douwes 11 years ago
parent 8b3d6c3ef4
commit 998a774efa
  1. 27
      Chan/res/layout/reply_captcha.xml
  2. 88
      Chan/res/layout/reply_input.xml
  3. 143
      Chan/res/layout/reply_view.xml
  4. 51
      Chan/src/org/floens/chan/ui/fragment/ReplyFragment.java

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/reply_captcha_tap_to_reload"
android:textSize="16sp" />
<org.floens.chan.ui.view.LoadView
android:id="@+id/reply_captcha_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center" />
<EditText
android:id="@+id/reply_captcha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reply_captcha"
android:inputType="textNoSuggestions" />
</LinearLayout>

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:floatlabel="http://schemas.android.com/apk/res-auto"
android:id="@+id/reply_data"
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
floatlabel:fitScreenWidth="full"
floatlabel:hint="@string/reply_name"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray"
floatlabel:textSize="16sp" />
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
floatlabel:fitScreenWidth="full"
floatlabel:hint="@string/reply_email"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray"
floatlabel:textSize="16sp" />
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
floatlabel:fitScreenWidth="full"
floatlabel:hint="@string/reply_subject"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray"
floatlabel:textSize="16sp" />
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeActionLabel="@string/reply_submit"
android:inputType="textMultiLine|textCapSentences|textAutoCorrect"
android:minLines="5"
floatlabel:fitScreenWidth="full"
floatlabel:hint="@string/reply_comment"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray"
floatlabel:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/reply_file"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/reply_file" />
<Button
android:id="@+id/reply_file_delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/reply_file_delete" />
</LinearLayout>
<org.floens.chan.ui.view.LoadView
android:id="@+id/reply_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:minHeight="200dp"
android:scaleType="centerCrop" />
</LinearLayout>
</LinearLayout>

@ -1,154 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:floatlabel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="600dp"
android:divider="?android:attr/dividerHorizontal"
android:minHeight="500dp"
android:minWidth="600dp"
android:orientation="vertical"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle" >
<!-- global viewflipper -->
<ViewFlipper
android:id="@+id/reply_flipper"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/reply_data"
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
floatlabel:fitScreenWidth="full"
floatlabel:textSize="16sp"
floatlabel:hint="@string/reply_name"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray" />
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
floatlabel:fitScreenWidth="full"
floatlabel:textSize="16sp"
floatlabel:hint="@string/reply_email"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray" />
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
floatlabel:fitScreenWidth="full"
floatlabel:textSize="16sp"
floatlabel:hint="@string/reply_subject"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray" />
<com.micromobs.android.floatlabel.FloatLabelEditText
android:id="@+id/reply_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapSentences|textAutoCorrect"
android:minLines="5"
android:imeActionLabel="@string/reply_submit"
floatlabel:fitScreenWidth="full"
floatlabel:textSize="16sp"
floatlabel:hint="@string/reply_comment"
floatlabel:textColorHintFocused="@color/holo_blue_dark"
floatlabel:textColorHintUnFocused="@android:color/darker_gray" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/reply_file"
android:text="@string/reply_file" />
<Button
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/reply_file_delete"
android:text="@string/reply_file_delete" />
</LinearLayout>
android:orientation="horizontal" >
<!-- input view: -->
<org.floens.chan.ui.view.LoadView
android:id="@+id/reply_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical" >
<org.floens.chan.ui.view.LoadView
android:id="@+id/reply_captcha_container"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center" />
<include layout="@layout/reply_input" />
</ScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/reply_captcha_tap_to_reload" />
<!-- captcha view: -->
<EditText
android:id="@+id/reply_captcha"
android:hint="@string/reply_captcha"
android:inputType="textNoSuggestions"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent" >
</LinearLayout>
<include layout="@layout/reply_captcha" />
</ScrollView>
<!-- response view: -->
<org.floens.chan.ui.view.LoadView
android:id="@+id/reply_response"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</org.floens.chan.ui.view.LoadView>
</ViewFlipper>
<LinearLayout
android:orientation="horizontal"
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/buttonBarStyle" >
android:orientation="horizontal" >
<Button
android:id="@+id/reply_cancel"
@ -166,7 +67,5 @@
android:layout_weight="1"
android:text="@string/reply_submit" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -15,9 +15,9 @@ import org.floens.chan.ui.view.LoadView;
import org.floens.chan.utils.ImageDecoder;
import org.floens.chan.utils.Logger;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
@ -73,6 +73,8 @@ public class ReplyFragment extends DialogFragment {
private TextView captchaText;
private LoadView responseContainer;
private Activity context;
public static ReplyFragment newInstance(Loadable loadable) {
ReplyFragment reply = new ReplyFragment();
reply.loadable = loadable;
@ -83,28 +85,29 @@ public class ReplyFragment extends DialogFragment {
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
loadable.writeToBundle(getActivity(), outState);
loadable.writeToBundle(context, outState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
context = getActivity();
if (loadable == null && savedInstanceState != null) {
loadable = new Loadable();
loadable.readFromBundle(getActivity(), savedInstanceState);
loadable.readFromBundle(context, savedInstanceState);
}
if (loadable != null) {
setClosable(true);
Dialog dialog = getDialog();
Context context = getActivity();
String title = loadable.isThreadMode() ? context.getString(R.string.reply) + " /" + loadable.board + "/"
+ loadable.no : context.getString(R.string.reply_to_board) + " /" + loadable.board + "/";
if (dialog == null) {
getActivity().getActionBar().setTitle(title);
context.getActionBar().setTitle(title);
} else {
dialog.setTitle(title);
}
@ -173,6 +176,8 @@ public class ReplyFragment extends DialogFragment {
ReplyManager replyManager = ChanApplication.getReplyManager();
replyManager.removeFileListener();
context = null;
}
@Override
@ -255,7 +260,7 @@ public class ReplyFragment extends DialogFragment {
if (getDialog() != null) {
dismiss();
} else {
getActivity().finish();
context.finish();
}
}
@ -318,20 +323,26 @@ public class ReplyFragment extends DialogFragment {
fileDeleteButton.setEnabled(true);
// UI Thread
final ImageView imageView = new ImageView(getActivity());
final ImageView imageView = new ImageView(context);
new Thread(new Runnable() {
@Override
public void run() {
if (context == null)
return;
// Other thread
final Bitmap bitmap = ImageDecoder.decodeFile(file, imageViewContainer.getWidth(), 3000);
getActivity().runOnUiThread(new Runnable() {
context.runOnUiThread(new Runnable() {
@Override
public void run() {
if (context == null)
return;
// UI Thread
if (bitmap == null) {
Toast.makeText(getActivity(), R.string.image_preview_failed, Toast.LENGTH_LONG).show();
Toast.makeText(context, R.string.image_preview_failed, Toast.LENGTH_LONG).show();
} else {
imageView.setScaleType(ScaleType.CENTER_CROP);
imageView.setImageBitmap(bitmap);
@ -357,31 +368,33 @@ public class ReplyFragment extends DialogFragment {
ChanApplication.getVolleyRequestQueue().add(new StringRequest(Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String result) {
if (!isVisible())
return;
if (context != null) {
String challenge = ReplyManager.getChallenge(result);
if (challenge != null) {
captchaChallenge = challenge;
String imageUrl = ChanUrls.getCaptchaImageUrl(challenge);
NetworkImageView captchaImage = new NetworkImageView(getActivity());
NetworkImageView captchaImage = new NetworkImageView(context);
captchaImage.setImageUrl(imageUrl, ChanApplication.getImageLoader());
captchaContainer.setView(captchaImage);
gettingCaptcha = false;
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
gettingCaptcha = false;
TextView text = new TextView(getActivity());
if (context != null) {
TextView text = new TextView(context);
text.setGravity(Gravity.CENTER);
text.setText(R.string.reply_captcha_load_error);
captchaContainer.setView(text);
}
}
}));
}
@ -420,13 +433,13 @@ public class ReplyFragment extends DialogFragment {
* @param response
*/
private void handleSubmitResponse(ReplyResponse response) {
if (getActivity() == null)
if (context == null)
return;
if (response.isNetworkError || response.isUserError) {
int resId = response.isCaptchaError ? R.string.reply_error_captcha
: (response.isFileError ? R.string.reply_error_file : R.string.reply_error);
Toast.makeText(getActivity(), resId, Toast.LENGTH_LONG).show();
Toast.makeText(context, resId, Toast.LENGTH_LONG).show();
submitButton.setEnabled(true);
cancelButton.setEnabled(true);
setClosable(true);
@ -435,15 +448,14 @@ public class ReplyFragment extends DialogFragment {
captchaText.setText("");
} else if (response.isSuccessful) {
shouldSaveDraft = false;
Toast.makeText(getActivity(), R.string.reply_success, Toast.LENGTH_SHORT).show();
Toast.makeText(context, R.string.reply_success, Toast.LENGTH_SHORT).show();
// threadFragment.reload(); // won't work: it takes 4chan a variable time to process the reply
closeReply();
} else {
if (isVisible()) {
cancelButton.setEnabled(true);
setClosable(true);
WebView webView = new WebView(getActivity());
WebView webView = new WebView(context);
WebSettings settings = webView.getSettings();
settings.setSupportZoom(true);
@ -452,5 +464,4 @@ public class ReplyFragment extends DialogFragment {
responseContainer.setView(webView);
}
}
}
}

Loading…
Cancel
Save