2020-09-22 13:11:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2020 WireGuard LLC. All Rights Reserved.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.wireguard.android.activity
|
|
|
|
|
|
|
|
import android.os.Bundle
|
2020-09-22 13:51:57 +02:00
|
|
|
import android.widget.Toast
|
2020-09-22 13:11:08 +02:00
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
2020-09-22 14:33:04 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2020-09-22 13:11:08 +02:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2020-09-22 14:33:04 +02:00
|
|
|
import com.wireguard.android.Application
|
|
|
|
import com.wireguard.android.databinding.TvActivityBinding
|
2020-09-22 13:51:57 +02:00
|
|
|
import com.wireguard.android.util.TunnelImporter
|
2020-09-22 13:11:08 +02:00
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
2020-09-22 14:33:04 +02:00
|
|
|
class TvMainActivity : AppCompatActivity() {
|
2020-09-22 13:11:08 +02:00
|
|
|
private val tunnelFileImportResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { data ->
|
2020-09-22 13:51:57 +02:00
|
|
|
lifecycleScope.launch {
|
|
|
|
TunnelImporter.importTunnel(contentResolver, data) {
|
|
|
|
Toast.makeText(this@TvMainActivity, it, Toast.LENGTH_LONG).show()
|
|
|
|
}
|
|
|
|
}
|
2020-09-22 13:11:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2020-09-22 14:33:04 +02:00
|
|
|
val binding = TvActivityBinding.inflate(layoutInflater)
|
|
|
|
lifecycleScope.launch { binding.tunnels = Application.getTunnelManager().getTunnels() }
|
|
|
|
binding.importButton.setOnClickListener {
|
2020-09-22 13:11:08 +02:00
|
|
|
tunnelFileImportResultLauncher.launch("*/*")
|
|
|
|
}
|
2020-09-22 14:33:04 +02:00
|
|
|
binding.executePendingBindings()
|
|
|
|
setContentView(binding.root)
|
2020-09-22 13:11:08 +02:00
|
|
|
}
|
|
|
|
}
|