1
1
package com.windscribe.mobile.ui.preferences.debug
2
2
3
3
import PreferencesNavBar
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import android.net.Uri
7
+ import androidx.compose.foundation.combinedClickable
4
8
import androidx.compose.foundation.layout.Column
5
9
import androidx.compose.foundation.layout.Spacer
6
10
import androidx.compose.foundation.layout.height
@@ -16,9 +20,12 @@ import androidx.compose.runtime.getValue
16
20
import androidx.compose.runtime.mutableStateOf
17
21
import androidx.compose.runtime.remember
18
22
import androidx.compose.ui.Modifier
23
+ import androidx.compose.ui.platform.LocalContext
19
24
import androidx.compose.ui.res.stringResource
20
25
import androidx.compose.ui.text.style.TextAlign
21
26
import androidx.compose.ui.unit.dp
27
+ import androidx.core.content.FileProvider
28
+ import androidx.navigation.NavController
22
29
import com.windscribe.mobile.ui.common.PreferenceBackground
23
30
import com.windscribe.mobile.ui.common.PreferenceProgressBar
24
31
import com.windscribe.mobile.ui.helper.MultiDevicePreview
@@ -27,10 +34,14 @@ import com.windscribe.mobile.ui.nav.LocalNavController
27
34
import com.windscribe.mobile.ui.theme.font12
28
35
import com.windscribe.mobile.ui.theme.primaryTextColor
29
36
import com.windscribe.vpn.R
37
+ import com.windscribe.vpn.Windscribe.Companion.appContext
38
+ import com.windscribe.vpn.constants.PreferencesKeyConstants
39
+ import java.io.File
30
40
31
41
@Composable
32
42
fun DebugScreen (viewModel : DebugViewModel ? = null) {
33
43
val navController = LocalNavController .current
44
+ val context = LocalContext .current
34
45
val debugLog by viewModel?.debugLog?.collectAsState()
35
46
? : remember { mutableStateOf(emptyList()) }
36
47
val showProgress by viewModel?.showProgress?.collectAsState()
@@ -48,7 +59,12 @@ fun DebugScreen(viewModel: DebugViewModel? = null) {
48
59
listState.scrollToItem(debugLog.size - 1 )
49
60
}
50
61
}
51
- LazyColumn (state = listState) {
62
+ LazyColumn (state = listState, modifier = Modifier .combinedClickable(
63
+ onClick = {},
64
+ onLongClick = {
65
+ exportLog(context)
66
+ }
67
+ )) {
52
68
items(debugLog.size) {
53
69
Text (
54
70
debugLog[it],
@@ -63,6 +79,26 @@ fun DebugScreen(viewModel: DebugViewModel? = null) {
63
79
}
64
80
}
65
81
82
+ private fun exportLog (context : Context ) {
83
+ val logFile = File (appContext.cacheDir.path + PreferencesKeyConstants .DEBUG_LOG_FILE_NAME )
84
+ if (logFile.exists()) {
85
+ val fileUri: Uri = FileProvider .getUriForFile(
86
+ context,
87
+ " com.windscribe.vpn.provider" ,
88
+ logFile
89
+ )
90
+ val shareIntent = Intent (Intent .ACTION_SEND ).apply {
91
+ type = " text/plain"
92
+ putExtra(Intent .EXTRA_STREAM , fileUri)
93
+ addFlags(Intent .FLAG_GRANT_READ_URI_PERMISSION )
94
+ }
95
+ val chooser = Intent .createChooser(shareIntent, " Export Log File" )
96
+ if (shareIntent.resolveActivity(context.packageManager) != null ) {
97
+ context.startActivity(chooser)
98
+ }
99
+ }
100
+ }
101
+
66
102
@Composable
67
103
@MultiDevicePreview
68
104
private fun DebugScreenPreview () {
0 commit comments