Skip to content

Commit

Permalink
#35 Added post reply function!
Browse files Browse the repository at this point in the history
  • Loading branch information
MewX committed Jul 5, 2020
1 parent 11adb22 commit 1aad1f0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mewx.wenku8.activity;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
Expand All @@ -21,6 +22,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -132,25 +134,22 @@ protected void onCreate(Bundle savedInstanceState) {
mSwipeRefreshLayout.setOnRefreshListener(this::refreshReviewReplyList);

llReplyButton.setOnClickListener(ignored -> {
// FIXME: enable these
Toast.makeText(getApplication(), getResources().getString(R.string.system_api_error), Toast.LENGTH_SHORT).show();

// String temp = etReplyText.getText().toString();
// String badWord = Wenku8API.searchBadWords(temp);
// if (badWord != null) {
// Toast.makeText(getApplication(), String.format(getResources().getString(R.string.system_containing_bad_word), badWord), Toast.LENGTH_SHORT).show();
// } else if (temp.length() < Wenku8API.MIN_REPLY_TEXT) {
// Toast.makeText(getApplication(), getResources().getString(R.string.system_review_too_short), Toast.LENGTH_SHORT).show();
// } else {
// // hide ime
// InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
// View view = getCurrentFocus();
// if (view == null) view = new View(this);
// if (imm != null) imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
//
// // submit
// new AsyncPublishReply(etReplyText, this, rid, temp).execute();
// }
String temp = etReplyText.getText().toString();
String badWord = Wenku8API.searchBadWords(temp);
if (badWord != null) {
Toast.makeText(getApplication(), String.format(getResources().getString(R.string.system_containing_bad_word), badWord), Toast.LENGTH_SHORT).show();
} else if (temp.length() < Wenku8API.MIN_REPLY_TEXT) {
Toast.makeText(getApplication(), getResources().getString(R.string.system_review_too_short), Toast.LENGTH_SHORT).show();
} else {
// hide ime
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = getCurrentFocus();
if (view == null) view = new View(this);
if (imm != null) imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

// submit
new AsyncPublishReply(etReplyText, this, rid, temp).execute();
}
});

// load initial content
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.mewx.wenku8.global.api;

import android.content.ContentValues;

import androidx.annotation.Nullable;

import org.mewx.wenku8.BuildConfig;
import org.mewx.wenku8.R;
import org.mewx.wenku8.global.GlobalConfig;
import org.mewx.wenku8.util.LightBase64;
import org.mewx.wenku8.util.LightNetwork;
import org.mewx.wenku8.R;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -44,7 +46,10 @@ public static String getCoverURL(int aid) {
"李克強", "臺獨", "藏獨", "反日", "反共", "反中", "達賴", "劉曉波", "毛主席", "憤青",
"反華", "右翼", "遊行", "示威", "靜坐", "公安", "李洪誌", "法輪功", "刷分", "路過路過",
".......", "。。。。", "色情", "吃屎", "你媽", "他媽", "她媽", "操你", "垃圾", "去死",
"迷魂藥", "催情藥", "毒品"
"迷魂藥", "催情藥", "毒品",

// Testing
"blablabla",
};


Expand Down Expand Up @@ -258,9 +263,11 @@ public static int getErrorInfo_ResId(int errNo) {
* This part are the old API writing ways.
* It's not efficient enough, and maybe bug-hidden.
*/
static Map<String,String> getEncryptedMAP(String str) {
static Map<String, String> getEncryptedMAP(String str) {
Map<String, String> params = new HashMap<>();
params.put("request", LightBase64.EncodeBase64(str+"&timetoken="+System.currentTimeMillis()));
params.put("appver=" + BuildConfig.VERSION_NAME
+ "&request", LightBase64.EncodeBase64(str)
+ "&timetoken=" + System.currentTimeMillis());
return params;
}

Expand Down Expand Up @@ -676,8 +683,9 @@ public static ContentValues getCommentNewThreadParams(int aid, String title, Str

// 需要敏感词过滤,特殊符号处理

return getEncryptedCV("action=review&do=post&aid=" + aid + "&title="+ LightBase64.EncodeBase64(title)
+"&content=" + LightBase64.EncodeBase64(content));
return getEncryptedCV("action=review&do=post&aid=" + aid
+ "&title=" + LightBase64.EncodeBase64(LightNetwork.encodeToHttp(title, "GBK"))
+ "&content=" + LightBase64.EncodeBase64(LightNetwork.encodeToHttp(content, "GBK")));
}

public static ContentValues getCommentReplyParams(int rid, String content) {
Expand All @@ -687,7 +695,9 @@ public static ContentValues getCommentReplyParams(int rid, String content) {

// 需要敏感词过滤,特殊符号处理

return getEncryptedCV("action=review&do=reply&rid=" + rid + "&content=" + LightBase64.EncodeBase64(content));
// Server-side bug, only GBK worked.
return getEncryptedCV("action=review&do=reply&rid=" + rid
+ "&content=" + LightBase64.EncodeBase64(LightNetwork.encodeToHttp(content, "GBK")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Objects;
import java.util.zip.GZIPInputStream;

/**
Expand All @@ -24,22 +25,27 @@
public class LightNetwork {

/**
* encodeToHttp:
*
* Encode UTF-8 character to http postable style. For example: "妹" =
* "%E5%A6%B9"
*
* @param str
* : input string
* Encode UTF-8 character to http postable style. For example: "妹" = "%E5%A6%B9"
* @param str input string
* @return result encoded string or empty string
*/
public static String encodeToHttp(String str) {
return encodeToHttp(str, "UTF-8");
}

/**
* Universal encoding to percent-encoding.
* @param str the string to be encoded.
* @param encoding the encoding in text form.
* @return the percent-encoded text.
*/
public static String encodeToHttp(String str, String encoding) {
String enc;
try {
enc = URLEncoder.encode(str, "UTF-8");
enc = URLEncoder.encode(str, encoding);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
Log.v("MewX-Net", e.getMessage());
Log.v("MewX-Net", Objects.requireNonNull(e.getMessage()));
enc = ""; // prevent crash
}
return enc;
Expand Down Expand Up @@ -74,7 +80,7 @@ public static byte[] LightHttpPostConnection(String u, ContentValues values) {
}

// make request args
StringBuilder params = new StringBuilder("");
StringBuilder params = new StringBuilder();
for( String key : values.keySet() ) {
if( !(values.get(key) instanceof String)) continue;
params.append("&").append(key).append("=").append(values.get(key)); // now, like "&a=1&b=1&c=1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
android:background="@color/default_mask_background_white"
android:visibility="visible">

<!--FIXME: enable me-->
<EditText
android:id="@+id/review_reply_edit_text"
android:layout_width="wrap_content"
Expand All @@ -42,7 +41,6 @@
android:layout_alignParentStart="true"
android:layout_toLeftOf="@id/review_reply_send"
android:layout_toStartOf="@id/review_reply_send"
android:enabled="false"
android:hint="@string/action_review_reply"
android:inputType="textMultiLine"
android:padding="16dp"
Expand Down

0 comments on commit 1aad1f0

Please sign in to comment.