1
1
package com.sakethh.linkora.ui.screens.settings.specific.data
2
2
3
3
import androidx.compose.animation.animateContentSize
4
+ import androidx.compose.foundation.BorderStroke
4
5
import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.layout.Box
5
7
import androidx.compose.foundation.layout.Column
8
+ import androidx.compose.foundation.layout.Row
9
+ import androidx.compose.foundation.layout.Spacer
10
+ import androidx.compose.foundation.layout.fillMaxSize
6
11
import androidx.compose.foundation.layout.fillMaxWidth
12
+ import androidx.compose.foundation.layout.height
13
+ import androidx.compose.foundation.layout.navigationBarsPadding
7
14
import androidx.compose.foundation.layout.padding
15
+ import androidx.compose.foundation.layout.wrapContentHeight
8
16
import androidx.compose.foundation.rememberScrollState
9
17
import androidx.compose.foundation.shape.RoundedCornerShape
10
18
import androidx.compose.foundation.verticalScroll
19
+ import androidx.compose.material.icons.Icons
20
+ import androidx.compose.material.icons.outlined.Info
11
21
import androidx.compose.material3.AlertDialogDefaults
12
22
import androidx.compose.material3.BasicAlertDialog
23
+ import androidx.compose.material3.Card
24
+ import androidx.compose.material3.CardDefaults
13
25
import androidx.compose.material3.ExperimentalMaterial3Api
26
+ import androidx.compose.material3.Icon
14
27
import androidx.compose.material3.LinearProgressIndicator
15
28
import androidx.compose.material3.MaterialTheme
16
29
import androidx.compose.material3.Text
30
+ import androidx.compose.material3.contentColorFor
17
31
import androidx.compose.runtime.Composable
18
32
import androidx.compose.runtime.LaunchedEffect
33
+ import androidx.compose.runtime.mutableLongStateOf
19
34
import androidx.compose.runtime.mutableStateOf
20
35
import androidx.compose.runtime.saveable.rememberSaveable
36
+ import androidx.compose.ui.Alignment
21
37
import androidx.compose.ui.Modifier
22
38
import androidx.compose.ui.draw.clip
39
+ import androidx.compose.ui.text.style.TextAlign
23
40
import androidx.compose.ui.unit.dp
24
41
import androidx.compose.ui.unit.sp
25
42
import androidx.compose.ui.window.DialogProperties
43
+ import androidx.lifecycle.ViewModel
26
44
import androidx.lifecycle.compose.collectAsStateWithLifecycle
45
+ import androidx.lifecycle.viewmodel.compose.viewModel
27
46
import com.sakethh.linkora.data.local.export.ExportRequestInfo
28
47
import com.sakethh.linkora.data.local.export.ExportRequestState
29
48
import com.sakethh.linkora.ui.theme.LinkoraTheme
@@ -46,36 +65,151 @@ fun DataExportDialogBox() {
46
65
LinkoraTheme {
47
66
BasicAlertDialog (
48
67
modifier = Modifier
49
- .animateContentSize(),
68
+ .animateContentSize()
69
+ .then(if (ExportRequestInfo .isHTMLBasedRequest.value) Modifier .fillMaxSize() else Modifier ),
50
70
onDismissRequest = {},
51
71
properties = DialogProperties (
72
+ dismissOnClickOutside = false ,
52
73
dismissOnBackPress = false ,
53
- usePlatformDefaultWidth = false
74
+ usePlatformDefaultWidth = ! ExportRequestInfo .isHTMLBasedRequest.value
54
75
)
55
76
) {
56
77
Column (
57
78
modifier = Modifier
58
- .fillMaxWidth()
59
- .padding( 20 .dp)
60
- .clip(
61
- RoundedCornerShape ( 15 .dp )
79
+ .then(
80
+ if ( ExportRequestInfo .isHTMLBasedRequest.value) Modifier .fillMaxSize() else Modifier .clip(
81
+ RoundedCornerShape ( 15 .dp)
82
+ )
62
83
)
84
+ .fillMaxWidth()
63
85
.background(AlertDialogDefaults .containerColor)
64
86
.padding(20 .dp)
65
87
.verticalScroll(rememberScrollState())
88
+ .animateContentSize()
66
89
) {
67
- Text (
68
- text = exportRequestResult.value.name,
69
- style = MaterialTheme .typography.titleMedium,
70
- fontSize = 20 .sp
71
- )
72
- LinearProgressIndicator (
73
- modifier = Modifier
74
- .fillMaxWidth()
75
- .padding(top = 15 .dp)
76
- )
90
+ if (! ExportRequestInfo .isHTMLBasedRequest.value) {
91
+ Text (
92
+ text = exportRequestResult.value.name,
93
+ style = MaterialTheme .typography.titleMedium,
94
+ fontSize = 20 .sp
95
+ )
96
+ LinearProgressIndicator (
97
+ modifier = Modifier
98
+ .fillMaxWidth()
99
+ .padding(top = 15 .dp)
100
+ )
101
+ } else {
102
+ Text (
103
+ text = " Collecting the data for exporting..." ,
104
+ style = MaterialTheme .typography.titleMedium,
105
+ fontSize = 20 .sp
106
+ )
107
+ val dataExportDialogBoxVM: DataExportDialogBoxVM = viewModel()
108
+ dataExportDialogBoxVM.dataExportSection().forEach {
109
+ if (it.totalDetectedSize <= 0 ) return @forEach
110
+ Spacer (Modifier .height(10 .dp))
111
+ Text (
112
+ it.itemType,
113
+ style = MaterialTheme .typography.titleMedium
114
+ )
115
+ Spacer (Modifier .height(10 .dp))
116
+ LinearProgressIndicator (modifier = Modifier .fillMaxWidth(), progress = {
117
+ if (it.currentIterationCount.value.toInt() != 0 && it.totalDetectedSize.toInt() != 0
118
+ ) {
119
+ it.currentIterationCount.value.toFloat() / it.totalDetectedSize
120
+ } else {
121
+ 0f
122
+ }
123
+ })
124
+ Spacer (Modifier .height(10 .dp))
125
+ Text (
126
+ " ${it.currentIterationCount.value} /${it.totalDetectedSize} " ,
127
+ style = MaterialTheme .typography.titleMedium
128
+ )
129
+ Spacer (Modifier .height(10 .dp))
130
+ Spacer (Modifier .height(10 .dp))
131
+ }
132
+ Card (
133
+ border = BorderStroke (
134
+ 1 .dp,
135
+ contentColorFor(MaterialTheme .colorScheme.surface)
136
+ ),
137
+ colors = CardDefaults .cardColors(containerColor = AlertDialogDefaults .containerColor),
138
+ modifier = Modifier
139
+ .fillMaxWidth()
140
+ .navigationBarsPadding()
141
+ ) {
142
+ Row (
143
+ modifier = Modifier
144
+ .fillMaxWidth()
145
+ .wrapContentHeight()
146
+ .padding(
147
+ top = 10 .dp, bottom = 10 .dp
148
+ ),
149
+ verticalAlignment = Alignment .CenterVertically
150
+ ) {
151
+ Box (
152
+ contentAlignment = Alignment .CenterStart
153
+ ) {
154
+ Icon (
155
+ imageVector = Icons .Outlined .Info ,
156
+ contentDescription = null ,
157
+ modifier = Modifier
158
+ .padding(
159
+ start = 10 .dp, end = 10 .dp
160
+ )
161
+ )
162
+ }
163
+ Text (
164
+ text = " Please keep the app open. Data is still being processed. Linkora will save it once the modification is complete. Closing the app or removing it from the background will cancel this operation." ,
165
+ style = MaterialTheme .typography.titleSmall,
166
+ fontSize = 14 .sp,
167
+ lineHeight = 18 .sp,
168
+ textAlign = TextAlign .Start ,
169
+ modifier = Modifier
170
+ .padding(end = 10 .dp)
171
+ )
172
+ }
173
+ }
174
+ }
77
175
}
78
176
}
79
177
}
80
178
}
179
+ }
180
+
181
+ class DataExportDialogBoxVM : ViewModel () {
182
+
183
+ fun dataExportSection () = listOf (
184
+ DataImportDialogBox (
185
+ itemType = " READING_SAVED_LINKS" ,
186
+ totalDetectedSize = ExportRequestInfo .totalLinksFromSavedLinks.intValue.toLong(),
187
+ currentIterationCount = mutableLongStateOf(ExportRequestInfo .currentIterationOfLinksFromSavedLinks.intValue.toLong())
188
+ ),
189
+ DataImportDialogBox (
190
+ itemType = " READING_IMPORTANT_LINKS" ,
191
+ totalDetectedSize = ExportRequestInfo .totalLinksFromImpLinksTable.intValue.toLong(),
192
+ currentIterationCount = mutableLongStateOf(ExportRequestInfo .currentIterationOfLinksFromImpLinksTable.intValue.toLong())
193
+ ),
194
+ DataImportDialogBox (
195
+ itemType = " READING_HISTORY_LINKS" ,
196
+ totalDetectedSize = ExportRequestInfo .totalLinksFromHistoryLinksTable.intValue.toLong(),
197
+ currentIterationCount = mutableLongStateOf(ExportRequestInfo .currentIterationOfLinksFromHistoryLinksTable.intValue.toLong())
198
+ ),
199
+ DataImportDialogBox (
200
+ itemType = " READING_ARCHIVED_LINKS" ,
201
+ totalDetectedSize = ExportRequestInfo .totalLinksFromArchivedLinksTable.intValue.toLong(),
202
+ currentIterationCount = mutableLongStateOf(ExportRequestInfo .currentIterationOfLinksFromArchivedLinksTable.intValue.toLong())
203
+ ),
204
+ DataImportDialogBox (
205
+ itemType = " READING_REGULAR_FOLDERS" ,
206
+ totalDetectedSize = ExportRequestInfo .totalRegularFoldersAndItsLinks.intValue.toLong(),
207
+ currentIterationCount = mutableLongStateOf(ExportRequestInfo .currentIterationOfRegularFoldersAndItsLinks.intValue.toLong())
208
+ ),
209
+ DataImportDialogBox (
210
+ itemType = " READING_ARCHIVED_FOLDERS" ,
211
+ totalDetectedSize = ExportRequestInfo .totalArchivedFoldersAndItsLinks.intValue.toLong(),
212
+ currentIterationCount = mutableLongStateOf(ExportRequestInfo .currentIterationOfArchivedFoldersAndItsLinks.intValue.toLong())
213
+ )
214
+ )
81
215
}
0 commit comments