Skip to content

Instantly share code, notes, and snippets.

@yfli
Created April 11, 2012 09:25
Show Gist options
  • Save yfli/2358220 to your computer and use it in GitHub Desktop.
Save yfli/2358220 to your computer and use it in GitHub Desktop.
aSM patch
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8b66adf..ead431f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -54,6 +54,8 @@
<string name="post_query_author">查看作者信息</string>
<string name="post_copy_content">复制帖子内容</string>
<string name="post_foward_self">转寄到自己信箱</string>
+ <string name="post_foward_external">转寄到外部邮箱</string>
+ <string name="post_group_foward_external">合集转寄到外部邮箱</string>
<string name="post_edit_post">修改文章</string>
<string name="write_label_post">发表</string>
<string name="post_attach">附件</string>
@@ -109,6 +111,8 @@
<string name="setting_force_screen_portrait_details">选中后不显示横屏界面</string>
<string name="setting_black_list">黑名单</string>
<string name="setting_black_list_details">请以空格隔开ID</string>
+ <string name="setting_forward_email">外部邮箱地址</string>
+ <string name="setting_forward_email_details">请输入转寄的外部邮箱地址</string>
<string name="setting_promotion_show">发帖显示宣传语</string>
<string name="setting_promotion_show_details">选中后发帖时结尾添加宣传语</string>
<!-- 下拉刷新 -->
diff --git a/res/xml/preference.xml b/res/xml/preference.xml
index f52c1eb..bf825bd 100644
--- a/res/xml/preference.xml
+++ b/res/xml/preference.xml
@@ -53,6 +53,9 @@
android:summary="@string/setting_force_screen_portrait_details" android:title="@string/setting_force_screen_portrait"/> -->
<CheckBoxPreference android:key="promotion_show"
android:summary="@string/setting_promotion_show_details" android:title="@string/setting_promotion_show" />
+ <EditTextPreference android:key="forward_email"
+ android:title="@string/setting_forward_email" android:summary="@string/setting_forward_email_details"
+ android:dialogTitle="请输入Email" android:defaultValue="" />
<EditTextPreference android:key="black_list"
android:title="@string/setting_black_list" android:summary="@string/setting_black_list_details"
android:dialogTitle="请输入ID" android:defaultValue="" />
diff --git a/src/com/athena/asm/PostListActivity.java b/src/com/athena/asm/PostListActivity.java
index dd77a34..6b8364a 100644
--- a/src/com/athena/asm/PostListActivity.java
+++ b/src/com/athena/asm/PostListActivity.java
@@ -11,6 +11,7 @@ import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.ClipboardManager;
+import android.text.Editable;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
@@ -320,6 +321,7 @@ public class PostListActivity extends Activity implements OnClickListener,
final String authorID = (String) ((TextView) relativeLayout
.findViewById(R.id.AuthorID)).getText();
final Post post = (Post) relativeLayout.getTag();
+ final Post firstPost = postList.get(0);
List<String> itemList = new ArrayList<String>();
itemList.add(getString(R.string.post_reply_post));
itemList.add(getString(R.string.post_reply_mail));
@@ -327,6 +329,8 @@ public class PostListActivity extends Activity implements OnClickListener,
itemList.add(getString(R.string.post_copy_author));
itemList.add(getString(R.string.post_copy_content));
itemList.add(getString(R.string.post_foward_self));
+ itemList.add(getString(R.string.post_foward_external));
+ itemList.add(getString(R.string.post_group_foward_external));
if (post.getAuthor().equals(smthSupport.userid)) {
itemList.add(getString(R.string.post_edit_post));
}
@@ -395,6 +399,12 @@ public class PostListActivity extends Activity implements OnClickListener,
}
break;
case 6:
+ forwardToEmail(post, false);
+ break;
+ case 7:
+ forwardToEmail(firstPost, true);
+ break;
+ case 8:
intent = new Intent();
intent.setClassName("com.athena.asm",
"com.athena.asm.WritePostActivity");
@@ -418,6 +428,61 @@ public class PostListActivity extends Activity implements OnClickListener,
return true;
}
+ private void forwardToEmail(final Post post, final boolean group)
+ {
+ String email = HomeActivity.application.getForwardEmailAddr();
+
+ if (email == "") {
+ final EditText input = new EditText(this);
+
+ new AlertDialog.Builder(this)
+ .setTitle("设置转寄邮箱")
+ .setMessage("您还没有设置转寄邮箱,请先设置。如需更改,请至设置页面")
+ .setView(input)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ Editable value = input.getText();
+ HomeActivity.application.updateForwardEmailAddr(value.toString());
+
+ String msg = null;
+ boolean result;
+
+ if (group)
+ result = smthSupport.forwardGroupPostToExternalMail(post, value.toString()) ;
+ else
+ result = smthSupport.forwardPostToExternalMail(post, value.toString()) ;
+ if ( result )
+ msg = "已转寄往信箱"+value.toString();
+ else
+ msg = "可耻滴失败鸟";
+ Toast.makeText(getApplicationContext(),
+ msg, Toast.LENGTH_SHORT).show();
+ }
+ }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ // Do nothing.
+ }
+ }).show();
+ } else {
+ String msg = null;
+ boolean result;
+
+ if (group)
+ result = smthSupport.forwardGroupPostToExternalMail(post, email) ;
+ else
+ result = smthSupport.forwardPostToExternalMail(post, email) ;
+ if ( result )
+ msg = "已转寄往信箱"+email;
+ else
+ msg = "可耻滴失败鸟";
+ Toast.makeText(getApplicationContext(),
+ msg, Toast.LENGTH_SHORT).show();
+
+ }
+
+ return ;
+ }
+
@Override
public boolean onDown(MotionEvent e) {
return false;
diff --git a/src/com/athena/asm/aSMApplication.java b/src/com/athena/asm/aSMApplication.java
index f215757..f680858 100644
--- a/src/com/athena/asm/aSMApplication.java
+++ b/src/com/athena/asm/aSMApplication.java
@@ -59,6 +59,7 @@ public class aSMApplication extends Application {
private boolean isForceScreenPortrait = false;
private boolean isPromotionShow = true;
private ArrayList<String> blackList = new ArrayList<String>();
+ private String forwardEmailAddr = "";
public void syncPreferences() {
try {
@@ -223,6 +224,11 @@ public class aSMApplication extends Application {
}
}
}
+ if (!settings.contains(Preferences.FORWARD_EMAIL)) {
+ editor.putString(Preferences.FORWARD_EMAIL, "");
+ } else {
+ setForwardEmailAddr(settings.getString(Preferences.FORWARD_EMAIL,""));;
+ }
PackageManager pm = getPackageManager();
try {
@@ -487,4 +493,23 @@ public class aSMApplication extends Application {
public void setNightTheme(boolean isNightTheme) {
this.isNightTheme = isNightTheme;
}
+
+ public String getForwardEmailAddr() {
+ return forwardEmailAddr;
+ }
+
+ public void setForwardEmailAddr(String forwardEmailAddr) {
+ this.forwardEmailAddr = forwardEmailAddr;
+ }
+
+ public void updateForwardEmailAddr(String email) {
+ this.forwardEmailAddr = email;
+ SharedPreferences settings = PreferenceManager
+ .getDefaultSharedPreferences(this);
+ SharedPreferences.Editor editor = settings.edit();
+ editor.putString(Preferences.FORWARD_EMAIL, email);
+ editor.commit();
+
+ }
+
}
diff --git a/src/com/athena/asm/data/Preferences.java b/src/com/athena/asm/data/Preferences.java
index 546d3c2..9dc54dd 100644
--- a/src/com/athena/asm/data/Preferences.java
+++ b/src/com/athena/asm/data/Preferences.java
@@ -23,6 +23,7 @@ public class Preferences {
public static final String NIGHT_THEME = "night_theme";
public static final String PROMOTION_SHOW = "promotion_show";
+ public static final String FORWARD_EMAIL= "forward_email";
public static final String BLACK_LIST = "black_list";
public static final String LAST_LAUNCH_VERSION = "last_launch_version";
diff --git a/src/com/athena/asm/util/SmthSupport.java b/src/com/athena/asm/util/SmthSupport.java
index 935a68a..b4242b5 100644
--- a/src/com/athena/asm/util/SmthSupport.java
+++ b/src/com/athena/asm/util/SmthSupport.java
@@ -954,13 +954,29 @@ public class SmthSupport {
return postList;
}
- public Boolean forwardPostToMailBox(Post post) {
+ private Boolean forwardGroupPostTo(Post post, String to) {
+ String url = "http://www.newsmth.net/bbstfwd.php?do";
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("board", post.getBoard()));
+ params.add(new BasicNameValuePair("gid", post.getSubjectID()));
+ params.add(new BasicNameValuePair("start", post.getSubjectID()));
+ params.add(new BasicNameValuePair("noansi", "1"));
+ params.add(new BasicNameValuePair("target", to));
+ String content = crawler.getPostRequestResult(url, params);
+ if (content.contains("操作成功")) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ private Boolean forwardPostTo(Post post, String to) {
String url = "http://www.newsmth.net/bbsfwd.php?do";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("board", post.getBoard()));
params.add(new BasicNameValuePair("id", post.getSubjectID()));
params.add(new BasicNameValuePair("noansi", "1"));
- params.add(new BasicNameValuePair("target", userid));
+ params.add(new BasicNameValuePair("target", to));
String content = crawler.getPostRequestResult(url, params);
if (content.contains("操作成功")) {
return true;
@@ -969,6 +985,21 @@ public class SmthSupport {
return false;
}
}
+ public Boolean forwardGroupPostToExternalMail(Post post, String emailAddress) {
+ return forwardGroupPostTo(post, emailAddress);
+ }
+
+ public Boolean forwardGroupPostToMailBox(Post post) {
+ return forwardPostTo(post, userid);
+ }
+
+ public Boolean forwardPostToExternalMail(Post post, String emailAddress) {
+ return forwardPostTo(post, emailAddress);
+ }
+
+ public Boolean forwardPostToMailBox(Post post) {
+ return forwardPostTo(post, userid);
+ }
/**
* 获得个人信息
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment