Skip to content

Commit

Permalink
add stopping step
Browse files Browse the repository at this point in the history
  • Loading branch information
rkonfj committed May 12, 2023
1 parent c612407 commit 89e9708
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/src/main/java/sh/toh/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Paths;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -197,11 +198,11 @@ private void showLogComponent() {
if (logComponent.getVisibility() == VISIBLE) {
logComponent.animate()
.translationY(logComponentHeight)
.setDuration(800)
.setDuration(1500)
.withEndAction(() -> logComponent.setVisibility(GONE))
.start();
btnComponent.animate().translationY((int) (logComponentHeight / 2))
.setDuration(800)
btnComponent.animate().translationY(logComponentHeight / 2F)
.setDuration(1500)
.withEndAction(() -> btnComponent.setTranslationY(0))
.start();
return;
Expand All @@ -212,15 +213,27 @@ private void showLogComponent() {
.translationY(0) // 将组件的 Y 轴偏移量设置为 0,向上移动到原始位置
.setDuration(300) // 设置动画持续时间为 1000 毫秒
.start(); // 启动动画
btnComponent.setTranslationY((int) (logComponentHeight / 2));
btnComponent.setTranslationY(logComponentHeight / 2F);
btnComponent.animate().translationY(0).setDuration(300).start();
}

private void disconnect(View v) {
msgBus.pub(R.string.stopVpn);
stopService(vpnService);
stopService(tohService);
connectButton.setText(R.string.connect);
connectButton.setText(R.string.stopping);
connectButton.setEnabled(false);
executors.submit(() -> {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
runOnUiThread(() -> {
connectButton.setText(R.string.connect);
connectButton.setEnabled(true);
});
});
connectButton.setOnClickListener(this::connect);
showLogComponent();
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/sh/toh/app/srv/Socks5VpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void onCreate() {
log.show("tun2socks", e);
}
}
stopSelf();
});

try {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<string name="app_name">Tohdroid</string>
<string name="connect">Connect</string>
<string name="connecting">Connecting</string>
<string name="stopping">Stopping</string>
<string name="connected">Connected</string>
<string name="scanQR">Scan QR</string>
<string name="clearLog">Clear Log</string>
Expand Down

0 comments on commit 89e9708

Please sign in to comment.