|
@@ -5,6 +5,7 @@ import android.content.Intent
|
|
|
import android.content.res.Configuration
|
|
|
import android.os.Handler
|
|
|
import android.util.Log
|
|
|
+import android.widget.Toast
|
|
|
import androidx.activity.ComponentActivity
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
@@ -112,6 +113,9 @@ lateinit var vpnConnectionsUtil: VPNConnectionsUtil
|
|
|
onClick: () -> Unit, isServerDialogShown: Boolean, server: Server) {
|
|
|
val wg = VPNConnectionsUtil(context, act ,homeViewModel)
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
+ val serverListViewModel: ServerListViewModel = viewModel{
|
|
|
+ ServerListViewModel(context)
|
|
|
+ }
|
|
|
|
|
|
Log.d("ServerCallbacks", "onServerSelected called!")
|
|
|
|
|
@@ -130,14 +134,26 @@ lateinit var vpnConnectionsUtil: VPNConnectionsUtil
|
|
|
basePreferenceHelper.setServerObject(server)
|
|
|
}
|
|
|
} else {
|
|
|
- val recentList = basePreferenceHelper.getRecentlyList()
|
|
|
- val tempList = ArrayList<Server>()
|
|
|
- recentList?.forEachIndexed { index, server1 ->
|
|
|
- tempList.add(server1)
|
|
|
- }
|
|
|
- tempList.add(server)
|
|
|
+ serverListViewModel.setRecentlyConnectedServer(server)
|
|
|
|
|
|
- basePreferenceHelper.setRecentlyList(tempList)
|
|
|
+// val recentList = basePreferenceHelper.getRecentlyList()
|
|
|
+// val tempList = ArrayList<Server>()
|
|
|
+// recentList?.let { tempList.addAll(it) }
|
|
|
+//
|
|
|
+// if (tempList.size == 0) {
|
|
|
+// tempList.add(server)
|
|
|
+// }
|
|
|
+// else {
|
|
|
+// if (!tempList.any {
|
|
|
+// it.id == server.id
|
|
|
+// }) {
|
|
|
+// if (tempList.size != 5 && tempList.size < 5) {
|
|
|
+// tempList.add(0, server)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// basePreferenceHelper.setRecentlyList(tempList)
|
|
|
|
|
|
basePreferenceHelper.setConnectedServer(server)
|
|
|
basePreferenceHelper.setServerObject(server)
|
|
@@ -372,7 +388,8 @@ fun Home(
|
|
|
)
|
|
|
|
|
|
Column(
|
|
|
- modifier = Modifier.fillMaxWidth()
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
.fillMaxHeight()
|
|
|
.padding(bottom = 115.dp)
|
|
|
// .offset(y = -(118).dp)
|
|
@@ -640,6 +657,9 @@ fun Home(
|
|
|
else if (isConnect == App.DISCONNECTED) {
|
|
|
Log.d("isConnect_State_vpn", "startVPN")
|
|
|
basePreferenceHelper.setConnectedServer(smartServer)
|
|
|
+ if (smartServer != null) {
|
|
|
+ serverListViewModel.setRecentlyConnectedServer(smartServer)
|
|
|
+ }
|
|
|
vpnConnectionsUtil.startVpn()
|
|
|
}
|
|
|
|
|
@@ -713,6 +733,10 @@ fun ColumnScope.ShowServerDialog(
|
|
|
.wrapContentHeight()
|
|
|
) {
|
|
|
val lastServer = prefHelper.getConnectedServer()
|
|
|
+ val context = LocalContext.current
|
|
|
+ val serverListViewModel: ServerListViewModel = viewModel {
|
|
|
+ ServerListViewModel(context)
|
|
|
+ }
|
|
|
Surface(
|
|
|
color = colorResource(id = R.color.white),
|
|
|
modifier = Modifier
|
|
@@ -778,6 +802,7 @@ fun ColumnScope.ShowServerDialog(
|
|
|
isServerDialog.value = false
|
|
|
prefHelper.setServerObject(serverObj.value)
|
|
|
prefHelper.setConnectedServer(serverObj.value)
|
|
|
+ serverListViewModel.setRecentlyConnectedServer(serverObj.value)
|
|
|
wg.stopVpn()
|
|
|
Handler().postDelayed(Runnable {
|
|
|
wg.startVpn()
|