Skip to content

Commit

Permalink
Android:APIJSONApp 引入 Kotlin;新增测试自动生成代码的 TestRequestAndResponse 的 Jav…
Browse files Browse the repository at this point in the history
…a 和 Kotlin 的工具类
  • Loading branch information
TommyLemon committed May 4, 2019
1 parent 656ece9 commit b697c0e
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 16 deletions.
1 change: 1 addition & 0 deletions APIJSON-Android/APIJSONApp/APIJSONLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile files('libs/fastjson-1.2.24.jar')

}
5 changes: 5 additions & 0 deletions APIJSON-Android/APIJSONApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
Expand All @@ -23,6 +27,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compile project(':QRCodeLibrary')
compile project(':ZBLibrary')
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@

package apijson.demo.client.activity_fragment;

import zuo.biao.apijson.JSONResponse;
import zuo.biao.library.base.BaseBroadcastReceiver;
import zuo.biao.library.interfaces.OnBottomDragListener;
import zuo.biao.library.manager.HttpManager.OnHttpResponseListener;
import zuo.biao.library.ui.EditTextInfoWindow;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.SettingUtil;
import zuo.biao.library.util.StringUtil;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand All @@ -31,13 +23,23 @@
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;

import apijson.demo.client.R;
import apijson.demo.client.application.APIJSONApplication;
import apijson.demo.client.base.BaseBottomTabActivity;
import apijson.demo.client.interfaces.TopBarMenuCallback;
import apijson.demo.client.model.User;
import apijson.demo.client.util.ActionUtil;
import apijson.demo.client.util.HttpRequest;
import zuo.biao.apijson.JSON;
import zuo.biao.apijson.JSONResponse;
import zuo.biao.library.base.BaseBroadcastReceiver;
import zuo.biao.library.interfaces.OnBottomDragListener;
import zuo.biao.library.manager.HttpManager.OnHttpResponseListener;
import zuo.biao.library.ui.EditTextInfoWindow;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.SettingUtil;
import zuo.biao.library.util.StringUtil;

/**应用主页
* @author Lemon
Expand Down Expand Up @@ -77,14 +79,32 @@ protected void onCreate(Bundle savedInstanceState) {
initEvent();
//功能归类分区方法,必须调用>>>>>>>>>>


BaseBroadcastReceiver.register(context, receiver
, new String[]{ACTION_EXIT_APP, ActionUtil.ACTION_RELOAD_CURRENT_USER});


if (SettingUtil.isOnTestMode) {
showShortToast("测试服务器\n" + HttpRequest.URL_BASE);
}


HttpRequest.get(JSON.parseObject(JSON.toJSONString(TestRequestAndResponseJava.request()), zuo.biao.apijson.JSONObject.class), 0, new OnHttpResponseListener() {
@Override
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
TestRequestAndResponseJava.response(resultJson);
}
});


HttpRequest.get(JSON.parseObject(JSON.toJSONString(TestRequestAndResponseKt.request()), zuo.biao.apijson.JSONObject.class), 0, new OnHttpResponseListener() {
@Override
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
TestRequestAndResponseKt.response(resultJson);
}
});


}


Expand Down Expand Up @@ -156,7 +176,7 @@ protected void selectTab(int position) {
llMainTabRightContainer.addView(right);
}


verifyLogin();
}

Expand All @@ -180,12 +200,12 @@ protected void selectTab(int position) {
@Override
public void initData() {// 必须调用
super.initData();

if (isCurrentUserCorrect() == false) {
reloadAll();
}
}


@Override
protected void reloadAll() {
Expand Down Expand Up @@ -232,7 +252,7 @@ public void initEvent() {// 必须调用
public void onDragBottom(boolean rightToLeft) {
if (fragments[currentPosition] instanceof OnBottomDragListener) {
((OnBottomDragListener) fragments[currentPosition]).onDragBottom(rightToLeft);
}
}
}


Expand Down Expand Up @@ -299,9 +319,9 @@ public void onReceive(Context context, Intent intent) {
finish();
return;
}

if (ActionUtil.ACTION_RELOAD_CURRENT_USER.equals(action)) {
reloadAll();// fragmentManager show remove等都会崩溃
reloadAll();// fragmentManager show remove等都会崩溃
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
package apijson.demo.client.activity_fragment

import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import zuo.biao.apijson.JSON
import java.util.*

fun request(): Map<String, Any> {
return mapOf(
"emptyList" to ArrayList<Any>(),
"[]" to mapOf(
"count" to 5,
"page" to 0,
"join" to "&/User:owner/id@",
"Moment" to HashMap<String, Any>(),
"User:owner" to mapOf(
"id{}" to listOf(82001, 82002),
"id@" to "/Moment/userId",
"@column" to "id,name,head"
),
"User:praiseUser[]" to mapOf(
"count" to 10,
"User" to mapOf(
"id{}@" to "[]/Moment/praiseUserIdList",
"@column" to "id,name"
)
),
"CommentItem[]" to mapOf(
"count" to 6,
"join" to "</User:publisher/id@",
"Comment" to mapOf(
"@order" to "date+",
"momentId@" to "[]/Moment/id"
),
"User:publisher" to mapOf(
"id@" to "/Comment/userId",
"@column" to "id,name"
)
)
)
)
}

fun response(resultJson: String?) {

var response: JSONObject = JSON.parseObject(resultJson)


//[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var list: JSONArray? = response.getJSONArray("[]")
if (list == null) {
list = JSONArray()
}

var item: JSONObject?
for (i in 0..list.size - 1) {
item = list.getJSONObject(i)
if (item == null) {
continue
}
println("\nitem = list[" + i + "] = \n" + item + "\n\n")
//TODO 你的代码


//Moment<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var moment: JSONObject? = item.getJSONObject("Moment")
if (moment == null) {
moment = JSONObject()
}

var id = moment.getLongValue("id")
println("moment.id = " + id);
var userId = moment.getLongValue("userId")
println("moment.userId = " + userId);
var date = moment.getString("date")
println("moment.date = " + date);
var content = moment.getString("content")
println("moment.content = " + content);

//praiseUserIdList<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var praiseUserIdList1: JSONArray? = moment.getJSONArray("praiseUserIdList")
if (praiseUserIdList1 == null) {
praiseUserIdList1 = JSONArray()
}

var item1: Int?
for (i1 in 0..praiseUserIdList1.size - 1) {
item1 = praiseUserIdList1.getInteger(i1)
if (item1 == null) {
continue
}
println("\nitem1 = praiseUserIdList1[" + i1 + "] = \n" + item1 + "\n\n")
//TODO 你的代码

}//praiseUserIdList>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//pictureList<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var pictureList1: JSONArray? = moment.getJSONArray("pictureList")
if (pictureList1 == null) {
pictureList1 = JSONArray()
}

var item2: String?
for (i1 in 0..pictureList1.size - 1) {
item2 = pictureList1.getString(i1)
if (item2 == null) {
continue
}
println("\nitem1 = pictureList1[" + i1 + "] = \n" + item2 + "\n\n")
//TODO 你的代码

}//pictureList>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//Moment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//User:owner<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var owner: JSONObject? = item.getJSONObject("User:owner")
if (owner == null) {
owner = JSONObject()
}

var id2 = owner.getLongValue("id")
println("owner.id = " + id);
var name = owner.getString("name")
println("owner.name = " + name);
var head = owner.getString("head")
println("owner.head = " + head);
//User:owner>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//User:praiseUser[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var praiseUserList1: JSONArray? = item.getJSONArray("User:praiseUser[]")
if (praiseUserList1 == null) {
praiseUserList1 = JSONArray()
}

var item3: JSONObject?
for (i1 in 0..praiseUserList1.size - 1) {
item3 = praiseUserList1.getJSONObject(i1)
if (item3 == null) {
continue
}
println("\nitem3 = praiseUserList1[" + i1 + "] = \n" + item3 + "\n\n")
//TODO 你的代码

var id = item3.getLongValue("id")
println("item3.id = " + id);
var name = item3.getString("name")
println("item3.name = " + name);
}//User:praiseUser[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//CommentItem[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var commentItemList1: JSONArray? = item.getJSONArray("CommentItem[]")
if (commentItemList1 == null) {
commentItemList1 = JSONArray()
}

var item4: JSONObject?
for (i1 in 0..commentItemList1.size - 1) {
item4 = commentItemList1.getJSONObject(i1)
if (item4 == null) {
continue
}
println("\nitem4 = commentItemList1[" + i1 + "] = \n" + item4 + "\n\n")
//TODO 你的代码


//Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var comment: JSONObject? = item4.getJSONObject("Comment")
if (comment == null) {
comment = JSONObject()
}

var id3 = comment.getLongValue("id")
println("comment.id3 = " + id3);
var toId = comment.getLongValue("toId")
println("comment.toId = " + toId);
var userId = comment.getLongValue("userId")
println("comment.userId = " + userId);
var momentId = comment.getLongValue("momentId")
println("comment.momentId = " + momentId);
var date = comment.getString("date")
println("comment.date = " + date);
var content = comment.getString("content")
println("comment.content = " + content);
//Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//User:publisher<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var publisher: JSONObject? = item4.getJSONObject("User:publisher")
if (publisher == null) {
publisher = JSONObject()
}

var id4 = publisher.getLongValue("id")
println("publisher.id4 = " + id4);
var name = publisher.getString("name")
println("publisher.name = " + name);
//User:publisher>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

}//CommentItem[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

}//[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//emptyList<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
var emptyList: JSONArray? = response.getJSONArray("emptyList")
if (emptyList == null) {
emptyList = JSONArray()
}

var item5: Any?
for (i in 0..emptyList.size - 1) {
item5 = emptyList.get(i)
if (item5 == null) {
continue
}
println("\nitem5 = emptyList[" + i + "] = \n" + item5 + "\n\n")
//TODO 你的代码

}//emptyList>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

var code = response.getIntValue("code")
println("response.code = " + code);
var msg = response.getString("msg")
println("response.msg = " + msg);

}
Loading

0 comments on commit b697c0e

Please sign in to comment.