File name in ReplyFragment now auto fills

captchafix
Florens Douwes 11 years ago
parent e95a45ca90
commit b8cfc4f9d0
  1. 2
      Chan/res/values/strings.xml
  2. 12
      Chan/src/org/floens/chan/core/manager/ReplyManager.java
  3. 16
      Chan/src/org/floens/chan/ui/activity/ImagePickActivity.java
  4. 18
      Chan/src/org/floens/chan/ui/fragment/ReplyFragment.java

@ -73,7 +73,7 @@
<string name="reply_comment">Comment</string> <string name="reply_comment">Comment</string>
<string name="reply_file">Pick file</string> <string name="reply_file">Pick file</string>
<string name="reply_file_delete">Remove file</string> <string name="reply_file_delete">Remove file</string>
<string name="reply_file_name">File name (not required)</string> <string name="reply_file_name">File name</string>
<string name="reply_submit">Submit</string> <string name="reply_submit">Submit</string>
<string name="reply_captcha">Enter captcha</string> <string name="reply_captcha">Enter captcha</string>
<string name="reply_error">Error sending reply</string> <string name="reply_error">Error sending reply</string>

@ -113,9 +113,9 @@ public class ReplyManager {
* Called from ImagePickActivity. Sends the file to the listening * Called from ImagePickActivity. Sends the file to the listening
* fileListener, and deletes the fileListener. * fileListener, and deletes the fileListener.
*/ */
public void _onPickedFile(File file) { public void _onPickedFile(String name, File file) {
if (fileListener != null) { if (fileListener != null) {
fileListener.onFile(file); fileListener.onFile(name, file);
} }
fileListener = null; fileListener = null;
} }
@ -346,12 +346,12 @@ public class ReplyManager {
public static abstract class FileListener { public static abstract class FileListener {
/** /**
* When a file is picked. * When the file was picked
* *
* @param the * @param name
* picked file * @param file
*/ */
public abstract void onFile(File file); public abstract void onFile(String name, File file);
/** /**
* When the file has started loading. * When the file has started loading.

@ -12,8 +12,10 @@ import org.floens.chan.utils.IOUtils;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.OpenableColumns;
import android.widget.Toast; import android.widget.Toast;
public class ImagePickActivity extends Activity { public class ImagePickActivity extends Activity {
@ -43,6 +45,18 @@ public class ImagePickActivity extends Activity {
if (data != null) { if (data != null) {
final Uri uri = data.getData(); final Uri uri = data.getData();
Cursor returnCursor = getContentResolver().query(uri, null, null, null, null);
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
returnCursor.moveToFirst();
String name = "image";
if (nameIndex > -1) {
name = returnCursor.getString(nameIndex);
}
returnCursor.close();
final String finalName = name;
ChanApplication.getReplyManager()._onPickedFileLoading(); ChanApplication.getReplyManager()._onPickedFileLoading();
// Async load the stream into "pickedFileCache", an file in the cache root // Async load the stream into "pickedFileCache", an file in the cache root
@ -64,7 +78,7 @@ public class ImagePickActivity extends Activity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
ChanApplication.getReplyManager()._onPickedFile(cacheFile); ChanApplication.getReplyManager()._onPickedFile(finalName, cacheFile);
} }
}); });

@ -146,7 +146,7 @@ public class ReplyFragment extends DialogFragment {
emailView.getEditText().setText(draft.email); emailView.getEditText().setText(draft.email);
subjectView.getEditText().setText(draft.subject); subjectView.getEditText().setText(draft.subject);
commentView.getEditText().setText(draft.comment); commentView.getEditText().setText(draft.comment);
setFile(draft.file); setFile(draft.fileName, draft.file);
getCaptcha(); getCaptcha();
} else { } else {
@ -167,10 +167,14 @@ public class ReplyFragment extends DialogFragment {
draft.subject = subjectView.getText().toString(); draft.subject = subjectView.getText().toString();
draft.comment = commentView.getText().toString(); draft.comment = commentView.getText().toString();
if (fileNameView != null) {
draft.fileName = fileNameView.getText().toString();
}
replyManager.setReplyDraft(draft); replyManager.setReplyDraft(draft);
} else { } else {
replyManager.removeReplyDraft(); replyManager.removeReplyDraft();
setFile(null); setFile(null, null);
} }
} }
@ -223,8 +227,8 @@ public class ReplyFragment extends DialogFragment {
public void onClick(View view) { public void onClick(View view) {
ChanApplication.getReplyManager().pickFile(new ReplyManager.FileListener() { ChanApplication.getReplyManager().pickFile(new ReplyManager.FileListener() {
@Override @Override
public void onFile(File file) { public void onFile(String name, File file) {
setFile(file); setFile(name, file);
} }
@Override @Override
@ -239,7 +243,7 @@ public class ReplyFragment extends DialogFragment {
fileDeleteButton.setOnClickListener(new OnClickListener() { fileDeleteButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
setFile(null); setFile(null, null);
} }
}); });
@ -317,8 +321,9 @@ public class ReplyFragment extends DialogFragment {
* @param imagePath * @param imagePath
* file to image to send or null to clear * file to image to send or null to clear
*/ */
private void setFile(final File file) { private void setFile(final String name, final File file) {
draft.file = file; draft.file = file;
draft.fileName = name;
if (file == null) { if (file == null) {
fileDeleteButton.setEnabled(false); fileDeleteButton.setEnabled(false);
@ -352,6 +357,7 @@ public class ReplyFragment extends DialogFragment {
fileNameView.setSingleLine(); fileNameView.setSingleLine();
fileNameView.setHint(R.string.reply_file_name); fileNameView.setHint(R.string.reply_file_name);
fileNameView.setTextSize(16f); fileNameView.setTextSize(16f);
fileNameView.setText(name);
wrapper.addView(fileNameView); wrapper.addView(fileNameView);
ImageView imageView = new ImageView(context); ImageView imageView = new ImageView(context);

Loading…
Cancel
Save