Skip to content

Commit

Permalink
修改TCP/UDP库接口;
Browse files Browse the repository at this point in the history
  • Loading branch information
D10NGYANG committed Aug 12, 2020
1 parent 49a2c9f commit 09ac3c8
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 138 deletions.
21 changes: 12 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 4
versionName "0.1.3"
versionName "0.1.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down Expand Up @@ -63,14 +63,14 @@ static def releaseTime() {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.2.0'

// Room components
implementation "androidx.room:room-runtime:2.2.5"
Expand All @@ -79,22 +79,25 @@ dependencies {
androidTestImplementation "androidx.room:room-testing:2.2.5"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
kapt "androidx.lifecycle:lifecycle-compiler:2.3.0-alpha05"
kapt "androidx.lifecycle:lifecycle-compiler:2.3.0-alpha06"
androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
// ViewModel Kotlin support
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-alpha05"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-alpha06"
// Coroutines
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6"

// 弹窗工具
implementation 'com.github.D10NGYANG:DL10Dialog:1.4'
implementation 'com.github.D10NGYANG:DL10Dialog:1.5'

// 实体转换工具
implementation 'com.github.D10NGYANG:JsonEntityManager:1.4'

// 调试工具
debugImplementation 'com.simple:spiderman:1.1.0'
releaseImplementation 'com.simple:spiderman-no-op:1.1.0'

// UPD/TCP工具
//implementation 'com.github.D10NGYANG:NetworkDebugAssistant:0.1.3'
implementation project(path: ':dl10netassistant')
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,17 @@ open class BaseSendReceiveActivity : BaseActivity() {
// 弹窗
connectDialog = ButtonDialog(this).setTittle(resources.getString(R.string.prompt))
.setMsg(resources.getString(R.string.connect_ing))
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, object :
OnBtnClick {
override fun click(d0: BaseDialog<*>, text: String) {
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL) {
onClick { dialog, _ ->
thread = null
showConnect(false)
showToast(resources.getString(R.string.connect_cancel))
d0.dismiss()
dialog.dismiss()
}
})
}
.create()
connectDialog?.startLoad(true, 0, 1)
connectDialog?.show()
.startLoad(true, 0, 1)
.show()
}

fun clean(view: View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ open class BaseSettingActivity : BaseActivity(), CompoundButton.OnCheckedChangeL
.setMsg(resources.getString(R.string.setting_auto_send_loop_time))
.addEdit(tag, "${contentBind.config?.autoSendTime?: 1000}", resources.getString(R.string.please_input_loop_time))
.setInputType(tag, InputType.TYPE_CLASS_NUMBER)
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick {
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
if (value.isEmpty()) {
dialog.setError(tag, resources.getString(R.string.input_loop_time_can_not_empty))
Expand All @@ -133,7 +132,7 @@ open class BaseSettingActivity : BaseActivity(), CompoundButton.OnCheckedChangeL
}
}
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class HistoryActivity : BaseActivity() {
if (info.text.length > length) tips = "$tips..."
ButtonDialog(this).setTittle(resources.getString(R.string.prompt))
.setMsg(tips)
.addAction(resources.getString(R.string.delete), ButtonStyle.ERROR, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
.addAction(resources.getString(R.string.delete), ButtonStyle.ERROR) {
onClick { dialog, _ ->
viewModel.deleteHistory(info)
d0.dismiss()
dialog.dismiss()
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ class SelectFolderActivity : BaseActivity() {
tips = tips.replace("**", info.name)
ButtonDialog(this).setTittle(resources.getString(R.string.prompt))
.setMsg(tips)
.addAction(resources.getString(R.string.folder_edit_name), ButtonStyle.THEME, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
.addAction(resources.getString(R.string.folder_edit_name), ButtonStyle.THEME) {
onClick { dialog, _ ->
// 重命名
renameFolder(info)
d0.dismiss()
dialog.dismiss()
}
})
.addAction(resources.getString(R.string.delete), ButtonStyle.ERROR, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
}
.addAction(resources.getString(R.string.delete), ButtonStyle.ERROR) {
onClick { dialog, _ ->
// 删除
deleteFolder(info)
d0.dismiss()
dialog.dismiss()
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand Down Expand Up @@ -134,9 +134,8 @@ class SelectFolderActivity : BaseActivity() {
EditDialog(this).setTittle(resources.getString(R.string.prompt))
.setMsg(resources.getString(R.string.folder_create_new_folder))
.addEdit(tag, "", resources.getString(R.string.please_input_new_folder_name))
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
when {
value.isEmpty() -> {
Expand All @@ -158,7 +157,7 @@ class SelectFolderActivity : BaseActivity() {
}
}
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand All @@ -178,9 +177,8 @@ class SelectFolderActivity : BaseActivity() {
EditDialog(this).setTittle(resources.getString(R.string.prompt))
.setMsg(tips)
.addEdit(tag, folder.name, resources.getString(R.string.please_input_new_folder_name))
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
when {
value.isEmpty() -> {
Expand All @@ -202,7 +200,7 @@ class SelectFolderActivity : BaseActivity() {
}
}
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand All @@ -215,16 +213,16 @@ class SelectFolderActivity : BaseActivity() {
tips = tips.replace("**", folder.name)
ButtonDialog(this).setTittle(resources.getString(R.string.prompt))
.setMsg(tips)
.addAction(resources.getString(R.string.delete), ButtonStyle.ERROR, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
.addAction(resources.getString(R.string.delete), ButtonStyle.ERROR) {
onClick { dialog, _ ->
// 删除
val file = File(folder.path)
file.delete()
// 更新文件夹列表
updateArray()
d0.dismiss()
dialog.dismiss()
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,36 @@ class TcpClientSettingActivity : BaseSettingActivity() {
.setMsg(resources.getString(R.string.target_ip_address))
.addEdit(tag, cc.serverIpAddress, resources.getString(R.string.please_input_ip_address))
.setInputType(tag, InputType.TYPE_NUMBER_FLAG_DECIMAL)
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick {
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
if (value.isEmpty()) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
val items = value.split(".")
if (items.size != 4) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
val builder = StringBuilder()
for (str in items.iterator()) {
if (!StringUtils.isNumeric(str)) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
val num = str.toIntOrNull()?: -1
if (num < 0 || num > 255) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
builder.append(num).append(".")
}
cc.serverIpAddress = builder.substring(0, builder.length -1)
updateConfigShow()
dialog.dismiss()
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand All @@ -99,9 +98,8 @@ class TcpClientSettingActivity : BaseSettingActivity() {
.setMsg(resources.getString(R.string.target_port))
.addEdit(tag, "${cc.serverPort}", resources.getString(R.string.please_input_port))
.setInputType(tag, InputType.TYPE_CLASS_NUMBER)
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick {
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
if (value.isEmpty()) {
dialog.setError(tag, resources.getString(R.string.input_port_can_not_empty))
Expand All @@ -116,7 +114,7 @@ class TcpClientSettingActivity : BaseSettingActivity() {
}
}
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class TcpServerSettingActivity : BaseSettingActivity() {
.setMsg(resources.getString(R.string.local_port))
.addEdit(tag, "${cc.localPort}", resources.getString(R.string.please_input_port))
.setInputType(tag, InputType.TYPE_CLASS_NUMBER)
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick {
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
if (value.isEmpty()) {
dialog.setError(tag, resources.getString(R.string.input_port_can_not_empty))
Expand All @@ -69,7 +68,7 @@ class TcpServerSettingActivity : BaseSettingActivity() {
}
}
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ class UdpBroadSettingActivity : BaseSettingActivity() {
.setMsg(resources.getString(R.string.local_port))
.addEdit(tag, "${cc.localPort}", resources.getString(R.string.please_input_port))
.setInputType(tag, InputType.TYPE_CLASS_NUMBER)
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
if (value.isEmpty()) {
dialog.setError(tag, resources.getString(R.string.input_port_can_not_empty))
Expand All @@ -73,7 +72,7 @@ class UdpBroadSettingActivity : BaseSettingActivity() {
}
}
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand All @@ -86,37 +85,36 @@ class UdpBroadSettingActivity : BaseSettingActivity() {
.setMsg(resources.getString(R.string.target_ip_address))
.addEdit(tag, cc.targetIpAddress, resources.getString(R.string.please_input_ip_address))
.setInputType(tag, InputType.TYPE_NUMBER_FLAG_DECIMAL)
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
if (value.isEmpty()) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
val items = value.split(".")
if (items.size != 4) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
val builder = StringBuilder()
for (str in items.iterator()) {
if (!StringUtils.isNumeric(str)) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
val num = str.toIntOrNull()?: -1
if (num < 0 || num > 255) {
dialog.setError(tag, resources.getString(R.string.input_ip_address_wrong_format))
return
return@onClick
}
builder.append(num).append(".")
}
cc.targetIpAddress = builder.substring(0, builder.length -1)
updateConfigShow()
dialog.dismiss()
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand All @@ -129,9 +127,8 @@ class UdpBroadSettingActivity : BaseSettingActivity() {
.setMsg(resources.getString(R.string.target_port))
.addEdit(tag, "${cc.targetPort}", resources.getString(R.string.please_input_port))
.setInputType(tag, InputType.TYPE_CLASS_NUMBER)
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME, object : OnBtnClick{
override fun click(d0: BaseDialog<*>, text: String) {
val dialog = d0 as EditDialog
.addAction(resources.getString(R.string.sure), ButtonStyle.THEME) {
onClick { dialog, _ ->
val value = dialog.getInputText(tag)
if (value.isEmpty()) {
dialog.setError(tag, resources.getString(R.string.input_port_can_not_empty))
Expand All @@ -146,7 +143,7 @@ class UdpBroadSettingActivity : BaseSettingActivity() {
}
}
}
})
}
.addAction(resources.getString(R.string.cancel), ButtonStyle.NORMAL, null)
.create().show()
}
Expand Down
Loading

0 comments on commit 09ac3c8

Please sign in to comment.