Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

compose message: HACK Part 2: ProfileActivity

  • Loading branch information...
commit 68b739f7fdca1d0a9c5537390c91d06978e7af4e 1 parent 34056c3
@talklittle authored
View
12 src/com/andrewshu/android/reddit/common/Common.java
@@ -42,6 +42,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.Resources;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -181,6 +182,17 @@ public static void updateNextPreviousButtons(ListActivity act, View nextPrevious
}
}
+ public static void setTextColorFromTheme(int theme, Resources resources, TextView... textViews) {
+ int color;
+ if (Util.isLightTheme(theme))
+ color = resources.getColor(R.color.reddit_light_dialog_text_color);
+ else
+ color = resources.getColor(R.color.reddit_dark_dialog_text_color);
+ for (TextView textView : textViews)
+ textView.setTextColor(color);
+ }
+
+
static void clearCookies(RedditSettings settings, HttpClient client, Context context) {
settings.setRedditSessionCookie(null);
View
38 src/com/andrewshu/android/reddit/common/FormValidation.java
@@ -0,0 +1,38 @@
+package com.andrewshu.android.reddit.common;
+
+import android.content.Context;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.Toast;
+
+public class FormValidation {
+
+ public static boolean validateComposeMessageInputFields(
+ Context context,
+ final EditText composeDestination,
+ final EditText composeSubject,
+ final EditText composeText,
+ final EditText composeCaptcha
+ ) {
+ // reddit.com performs these sanity checks too.
+ if ("".equals(composeDestination.getText().toString().trim())) {
+ Toast.makeText(context, "please enter a username", Toast.LENGTH_LONG).show();
+ return false;
+ }
+ if ("".equals(composeSubject.getText().toString().trim())) {
+ Toast.makeText(context, "please enter a subject", Toast.LENGTH_LONG).show();
+ return false;
+ }
+ if ("".equals(composeText.getText().toString().trim())) {
+ Toast.makeText(context, "you need to enter a message", Toast.LENGTH_LONG).show();
+ return false;
+ }
+ if (composeCaptcha.getVisibility() == View.VISIBLE && "".equals(composeCaptcha.getText().toString().trim())) {
+ Toast.makeText(context, "", Toast.LENGTH_LONG).show();
+ return false;
+ }
+ return true;
+ }
+
+
+}
View
44 src/com/andrewshu/android/reddit/mail/InboxActivity.java
@@ -48,8 +48,8 @@
import com.andrewshu.android.reddit.captcha.CaptchaDownloadTask;
import com.andrewshu.android.reddit.common.Common;
import com.andrewshu.android.reddit.common.Constants;
+import com.andrewshu.android.reddit.common.FormValidation;
import com.andrewshu.android.reddit.common.RedditIsFunHttpClientFactory;
-import com.andrewshu.android.reddit.common.util.Util;
import com.andrewshu.android.reddit.settings.RedditSettings;
import com.andrewshu.android.reddit.things.ThingInfo;
@@ -157,7 +157,9 @@ protected Dialog onCreateDialog(int id) {
dialog = builder.setView(layout).create();
final Dialog composeDialog = dialog;
- setTextColorFromTheme(
+ Common.setTextColorFromTheme(
+ mSettings.getTheme(),
+ getResources(),
(TextView) layout.findViewById(R.id.compose_destination_textview),
(TextView) layout.findViewById(R.id.compose_subject_textview),
(TextView) layout.findViewById(R.id.compose_message_textview),
@@ -175,7 +177,7 @@ protected Dialog onCreateDialog(int id) {
public void onClick(View v) {
ThingInfo thingInfo = new ThingInfo();
- if (!validateInputFields(composeDestination, composeSubject, composeText, composeCaptcha))
+ if (!FormValidation.validateComposeMessageInputFields(InboxActivity.this, composeDestination, composeSubject, composeText, composeCaptcha))
return;
thingInfo.setDest(composeDestination.getText().toString().trim());
@@ -221,42 +223,6 @@ protected void onPrepareDialog(int id, Dialog dialog) {
}
}
- private void setTextColorFromTheme(TextView... textViews) {
- int color;
- if (Util.isLightTheme(mSettings.getTheme()))
- color = getResources().getColor(R.color.reddit_light_dialog_text_color);
- else
- color = getResources().getColor(R.color.reddit_dark_dialog_text_color);
- for (TextView textView : textViews)
- textView.setTextColor(color);
- }
-
- private boolean validateInputFields(
- final EditText composeDestination,
- final EditText composeSubject,
- final EditText composeText,
- final EditText composeCaptcha
- ) {
- // reddit.com performs these sanity checks too.
- if ("".equals(composeDestination.getText().toString().trim())) {
- Toast.makeText(InboxActivity.this, "please enter a username", Toast.LENGTH_LONG).show();
- return false;
- }
- if ("".equals(composeSubject.getText().toString().trim())) {
- Toast.makeText(InboxActivity.this, "please enter a subject", Toast.LENGTH_LONG).show();
- return false;
- }
- if ("".equals(composeText.getText().toString().trim())) {
- Toast.makeText(InboxActivity.this, "you need to enter a message", Toast.LENGTH_LONG).show();
- return false;
- }
- if (composeCaptcha.getVisibility() == View.VISIBLE && "".equals(composeCaptcha.getText().toString().trim())) {
- Toast.makeText(InboxActivity.this, "", Toast.LENGTH_LONG).show();
- return false;
- }
- return true;
- }
-
private class MyMessageComposeTask extends MessageComposeTask {
public MyMessageComposeTask(Dialog dialog,
View
31 src/com/andrewshu/android/reddit/user/ProfileActivity.java
@@ -79,6 +79,7 @@
import com.andrewshu.android.reddit.common.CacheInfo;
import com.andrewshu.android.reddit.common.Common;
import com.andrewshu.android.reddit.common.Constants;
+import com.andrewshu.android.reddit.common.FormValidation;
import com.andrewshu.android.reddit.common.ProgressInputStream;
import com.andrewshu.android.reddit.common.RedditIsFunHttpClientFactory;
import com.andrewshu.android.reddit.common.tasks.VoteTask;
@@ -1053,6 +1054,17 @@ public void onLoginChosen(String user, String password) {
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
layout = inflater.inflate(R.layout.compose_dialog, null);
+
+ Common.setTextColorFromTheme(
+ mSettings.getTheme(),
+ getResources(),
+ (TextView) layout.findViewById(R.id.compose_destination_textview),
+ (TextView) layout.findViewById(R.id.compose_subject_textview),
+ (TextView) layout.findViewById(R.id.compose_message_textview),
+ (TextView) layout.findViewById(R.id.compose_captcha_textview),
+ (TextView) layout.findViewById(R.id.compose_captcha_loading)
+ );
+
final EditText composeDestination = (EditText) layout.findViewById(R.id.compose_destination_input);
final EditText composeSubject = (EditText) layout.findViewById(R.id.compose_subject_input);
final EditText composeText = (EditText) layout.findViewById(R.id.compose_text_input);
@@ -1066,23 +1078,10 @@ public void onLoginChosen(String user, String password) {
composeSendButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ThingInfo hi = new ThingInfo();
- // reddit.com performs these sanity checks too.
- if ("".equals(composeDestination.getText().toString().trim())) {
- Toast.makeText(ProfileActivity.this, "please enter a username", Toast.LENGTH_LONG).show();
- return;
- }
- if ("".equals(composeSubject.getText().toString().trim())) {
- Toast.makeText(ProfileActivity.this, "please enter a subject", Toast.LENGTH_LONG).show();
+
+ if (!FormValidation.validateComposeMessageInputFields(ProfileActivity.this, composeDestination, composeSubject, composeText, composeCaptcha))
return;
- }
- if ("".equals(composeText.getText().toString().trim())) {
- Toast.makeText(ProfileActivity.this, "you need to enter a message", Toast.LENGTH_LONG).show();
- return;
- }
- if (composeCaptcha.getVisibility() == View.VISIBLE && "".equals(composeCaptcha.getText().toString().trim())) {
- Toast.makeText(ProfileActivity.this, "", Toast.LENGTH_LONG).show();
- return;
- }
+
hi.setDest(composeDestination.getText().toString().trim());
hi.setSubject(composeSubject.getText().toString().trim());
new MyMessageComposeTask(composeDialog, hi, composeCaptcha.getText().toString().trim())
Please sign in to comment.
Something went wrong with that request. Please try again.