Skip to content

Commit

Permalink
ui optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
youlookwhat committed Apr 23, 2021
1 parent 45e6c9d commit 7208724
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 27 deletions.
47 changes: 26 additions & 21 deletions app/src/main/java/me/jingbin/smb/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ class MainActivity : AppCompatActivity() {
val activity = mWeakReference?.get()
activity?.let {
activity.progressDialog?.hide()
if (msg.what == 1) {
// 读取文件列表成功
val msgContent = msg.obj
val list = msgContent as List<*>
activity.tv_file_list.text = list.toString()
} else {
val msgContent = msg.obj
Log.e("handleMessage", msgContent.toString())
activity.tv_log.text = msgContent.toString()
Toast.makeText(activity.instance, msgContent.toString(), Toast.LENGTH_SHORT).show()
if (msg.what == 2) {
when (msg.what) {
1 -> {
// 读取文件列表成功
val list = msg.obj as List<*>
activity.tv_file_list.text = list.toString()
}
2 -> {
// 写入或删除成功后再次读取
activity.tv_log.text = msg.obj.toString()
activity.operation(2)
}
else -> {
// 失败
val msgContent = msg.obj
activity.tv_log.text = msgContent.toString()
Toast.makeText(activity.instance, msgContent.toString(), Toast.LENGTH_SHORT).show()
}
}
}
}
Expand All @@ -63,9 +67,9 @@ class MainActivity : AppCompatActivity() {
et_fileName.setText(SpUtil.getString("contentFileName"))

handle = MyHandle(this)
tv_send.setOnClickListener { operation(1) }
tv_read.setOnClickListener { operation(2) }
tv_delete.setOnClickListener { operation(3) }
tv_send.setOnClickListener { operation(1); saveEditValue() }
tv_read.setOnClickListener { operation(2); saveEditValue() }
tv_delete.setOnClickListener { operation(3); saveEditValue() }

}

Expand Down Expand Up @@ -103,19 +107,18 @@ class MainActivity : AppCompatActivity() {
et_content.text.toString(),
et_fileName.text.toString()
)

// 写入
bySmb.writeToFile(writeStringToFile, object : OnOperationFileCallback {

override fun onSuccess() {
// 成功
val msg = Message.obtain()
msg.obj = "成功"
msg.obj = "写入成功"
msg.what = 2
handle.sendMessage(msg)
}

override fun onFailure(message: String) {
Log.e("onFailure", message)
val msg = Message.obtain()
msg.obj = message
handle.sendMessage(msg)
Expand All @@ -124,8 +127,8 @@ class MainActivity : AppCompatActivity() {
})
}
2 -> {
// 读取 ("", "*.txt", callback)
bySmb.listShareFileName(object : OnReadFileListNameCallback {
// bySmb?.listShareFileName("", "*.txt", object : OnReadFileListNameCallback {
override fun onSuccess(fileNameList: List<String>) {
// 成功
val msg = Message.obtain()
Expand All @@ -135,25 +138,23 @@ class MainActivity : AppCompatActivity() {
}

override fun onFailure(message: String) {
Log.e("onFailure", message)
val msg = Message.obtain()
msg.obj = message
handle.sendMessage(msg)
}
})
}
3 -> {
// 删除
bySmb.deleteFile(et_fileName.text.toString(), object : OnOperationFileCallback {
override fun onSuccess() {
// 成功 只有在杀掉进程时才生效
val msg = Message.obtain()
msg.obj = "删除成功"
msg.what = 2
handle.sendMessage(msg)
}

override fun onFailure(message: String) {
Log.e("onFailure", message)
val msg = Message.obtain()
msg.obj = message
handle.sendMessage(msg)
Expand Down Expand Up @@ -190,6 +191,10 @@ class MainActivity : AppCompatActivity() {

override fun onBackPressed() {
super.onBackPressed()
saveEditValue()
}

private fun saveEditValue() {
SpUtil.putString("ip", et_ip.text.toString())
SpUtil.putString("username", et_username.text.toString())
SpUtil.putString("password", et_password.text.toString())
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/share_button_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 填充的颜色 -->
<solid android:color="@color/purple_500" />

<!-- 圆角的半径 -->
<corners android:radius="27dp" />
</shape>
25 changes: 19 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="ip"
android:imeOptions="actionNext"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -22,6 +24,8 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="用户名"
android:imeOptions="actionNext"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_ip" />
Expand All @@ -32,6 +36,8 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="密码"
android:imeOptions="actionNext"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_username" />
Expand All @@ -42,6 +48,8 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="文件夹名称"
android:imeOptions="actionNext"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_password" />
Expand All @@ -52,6 +60,7 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="需要保存的内容"
android:imeOptions="actionNext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_foldName" />
Expand All @@ -62,16 +71,18 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="保存的文件名"
android:imeOptions="actionDone"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_content" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/tv_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:background="@color/purple_500"
android:background="@drawable/share_button_bg"
android:text="写入"
android:textColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -94,8 +105,10 @@
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/tv_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/purple_500"
android:layout_height="40dp"
android:background="@drawable/share_button_bg"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="查看文件列表"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
Expand Down Expand Up @@ -130,9 +143,9 @@
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/tv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="40dp"
android:layout_marginRight="10dp"
android:background="@color/purple_500"
android:background="@drawable/share_button_bg"
android:text="删除文件"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF2483D9</color>
<color name="purple_700">#FF2483D9</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="bg_text_log">#22F9F9F9</color>
</resources>

0 comments on commit 7208724

Please sign in to comment.