|
@@ -21,8 +21,13 @@ import androidx.activity.result.ActivityResultLauncher
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
|
import androidx.core.app.ActivityCompat
|
|
import androidx.core.app.ActivityCompat
|
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.core.content.ContextCompat
|
|
|
|
|
+import androidx.datastore.core.DataStore
|
|
|
|
|
+import androidx.datastore.preferences.core.Preferences
|
|
|
|
|
+import androidx.datastore.preferences.core.stringPreferencesKey
|
|
|
|
|
+import androidx.datastore.preferences.preferencesDataStore
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.Fragment
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
|
+import com.example.modifier.BuildConfig
|
|
|
import com.example.modifier.Global
|
|
import com.example.modifier.Global
|
|
|
import com.example.modifier.Global.save
|
|
import com.example.modifier.Global.save
|
|
|
import com.example.modifier.Global.saveServer
|
|
import com.example.modifier.Global.saveServer
|
|
@@ -50,6 +55,9 @@ import io.ktor.http.contentType
|
|
|
import io.ktor.http.isSuccess
|
|
import io.ktor.http.isSuccess
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.delay
|
|
|
|
|
+import kotlinx.coroutines.flow.first
|
|
|
|
|
+import kotlinx.coroutines.flow.last
|
|
|
|
|
+import kotlinx.coroutines.flow.map
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withContext
|
|
|
import kotlinx.coroutines.withTimeout
|
|
import kotlinx.coroutines.withTimeout
|
|
@@ -65,10 +73,8 @@ class SettingsFragment : Fragment() {
|
|
|
private val TAG = "SettingsFragment"
|
|
private val TAG = "SettingsFragment"
|
|
|
|
|
|
|
|
private lateinit var binding: FragmentSettingsBinding
|
|
private lateinit var binding: FragmentSettingsBinding
|
|
|
-
|
|
|
|
|
- var handler: Handler = Handler(Looper.getMainLooper())
|
|
|
|
|
-
|
|
|
|
|
- lateinit var requestPermissionLauncher: ActivityResultLauncher<String>
|
|
|
|
|
|
|
+ private lateinit var requestPermissionLauncher: ActivityResultLauncher<String>
|
|
|
|
|
+ private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = BuildConfig.APPLICATION_ID)
|
|
|
|
|
|
|
|
init {
|
|
init {
|
|
|
Log.i("SettingsFragment", "SettingsFragment")
|
|
Log.i("SettingsFragment", "SettingsFragment")
|
|
@@ -322,6 +328,12 @@ class SettingsFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
lifecycleScope.launch {
|
|
lifecycleScope.launch {
|
|
|
loadConfigs()
|
|
loadConfigs()
|
|
|
|
|
+
|
|
|
|
|
+ val server = requireContext().dataStore.data.map {
|
|
|
|
|
+ it[stringPreferencesKey("server")]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Log.i("xxxxxxserver", "server: ${server.first()}")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return binding.root
|
|
return binding.root
|