Convert VoteTagParser to kotlin

This commit is contained in:
FooIbar authored and tarsin committed 2023-04-03 00:06:40 +08:00
1 parent 21b3b66bcd
commit 3b04624b88
3 files changed
+10 -21

No files matched your search

@@ -617,7 +617,7 @@ object EhEngine {
token: String?,
tags: String?,
vote: Int,
): VoteTagParser.Result {
): String {
val json = JSONObject()
json.put("method", "taggallery")
json.put("apiuid", apiUid)
@@ -15,23 +15,13 @@
* You should have received a copy of the GNU General Public License along with EhViewer.
* If not, see <https://www.gnu.org/licenses/>.
*/
package com.hippo.ehviewer.client.parser
package com.hippo.ehviewer.client.parser;
import org.json.JSONException;
import org.json.JSONObject;
public class VoteTagParser {
import org.json.JSONObject
object VoteTagParser {
// {"error":"The tag \"neko\" is not allowed. Use character:neko or artist:neko"}
public static VoteTagParser.Result parse(String body) throws JSONException {
VoteTagParser.Result result = new VoteTagParser.Result();
JSONObject jo = new JSONObject(body);
if (jo.has("error")) result.error = jo.getString("error");
return result;
}
public static class Result {
public String error;
fun parse(body: String): String {
return JSONObject(body).optString("error")
}
}
@@ -144,7 +144,6 @@ import com.hippo.ehviewer.client.parser.HomeParser
import com.hippo.ehviewer.client.parser.ParserUtils
import com.hippo.ehviewer.client.parser.RateGalleryParser
import com.hippo.ehviewer.client.parser.TorrentParser
import com.hippo.ehviewer.client.parser.VoteTagParser
import com.hippo.ehviewer.coil.ehUrl
import com.hippo.ehviewer.dao.DownloadInfo
import com.hippo.ehviewer.dao.Filter
@@ -1527,10 +1526,10 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
}
private class VoteTagListener(context: Context) :
EhCallback<GalleryDetailScene?, VoteTagParser.Result>(context) {
override fun onSuccess(result: VoteTagParser.Result) {
if (!result.error.isNullOrEmpty()) {
showTip(result.error, LENGTH_SHORT)
EhCallback<GalleryDetailScene?, String>(context) {
override fun onSuccess(result: String) {
if (result.isNotEmpty()) {
showTip(result, LENGTH_SHORT)
} else {
showTip(R.string.tag_vote_successfully, LENGTH_SHORT)
}