[go: nahoru, domu]

Skip to content

Commit

Permalink
Remove XML parsing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
oblakr24 committed Jun 13, 2023
1 parent bb164f2 commit 35e0625
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 126 deletions.
18 changes: 12 additions & 6 deletions app/src/main/java/com/rokoblak/chatbackup/home/HomeInnerContent.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.rokoblak.chatbackup.home

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Upload
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.rokoblak.chatbackup.commonui.*
import com.rokoblak.chatbackup.commonui.ButtonWithIcon
import com.rokoblak.chatbackup.commonui.ConversationsListing
import com.rokoblak.chatbackup.commonui.ConversationsListingUIState
import com.rokoblak.chatbackup.commonui.PreviewDataUtils
import com.rokoblak.chatbackup.commonui.SearchBar
import com.rokoblak.chatbackup.ui.theme.ChatBackupTheme
import com.rokoblak.chatbackup.ui.theme.LocalTypography
import kotlinx.collections.immutable.toImmutableList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import android.net.Uri

sealed interface ImportAction {
object ImportJSONClicked : ImportAction
object ImportXMLClicked : ImportAction
data class JSONFileSelected(val uri: Uri) : ImportAction
data class XMLFileSelected(val uri: Uri) : ImportAction
data class ConversationClicked(val contactId: String, val number: String) : ImportAction
data class ConversationChecked(val contactId: String, val checked: Boolean) : ImportAction
object SelectAll: ImportAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ fun ImportContent(
ButtonWithIcon("Import JSON", icon = Icons.Filled.DataObject) {
onAction(ImportAction.ImportJSONClicked)
}
ButtonWithIcon("Import XML", icon = Icons.Filled.DataArray) {
onAction(ImportAction.ImportXMLClicked)
}
// ButtonWithIcon("Import XML", icon = Icons.Filled.DataArray) {
// onAction(ImportAction.ImportXMLClicked)
// }
}
}
ImportScreenUIState.Loading -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ import android.content.Intent
sealed interface ImportEffect {
data class ShowToast(val message: String) : ImportEffect
data class OpenJSONFilePicker(val intent: Intent) : ImportEffect
data class OpenXMLFilePicker(val intent: Intent) : ImportEffect
data class ShowSetAsDefaultPrompt(val owner: Context): ImportEffect
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ class ImportFileViewModel @Inject constructor(
fun handleAction(act: ImportAction) {
when (act) {
is ImportAction.JSONFileSelected -> importJSONFile(act.uri)
is ImportAction.XMLFileSelected -> importXMLFile(act.uri)
ImportAction.ImportJSONClicked -> openJSONFilePicker()
ImportAction.ImportXMLClicked -> openXMLFilePicker()
is ImportAction.ConversationClicked -> openConversation(act.contactId, act.number)
ImportAction.ClearSelection -> clearSelections()
ImportAction.CloseEditClicked -> editState.update { it.copy(editing = false) }
Expand Down Expand Up @@ -206,12 +204,6 @@ class ImportFileViewModel @Inject constructor(
}
}

private fun importXMLFile(uri: Uri) {
importFile {
importer.importXML(uri)
}
}

private fun importFile(doImport: suspend () -> ImportResult) =
viewModelScope.launch {
loading.value = true
Expand All @@ -232,14 +224,6 @@ class ImportFileViewModel @Inject constructor(
effects.send(ImportEffect.OpenJSONFilePicker(intent))
}

private fun openXMLFilePicker() {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "*/*"
}
effects.send(ImportEffect.OpenXMLFilePicker(intent))
}

private fun openConversation(contactId: String, number: String) {
val input = ConversationRoute.Input(contactId, address = number, isImport = true)
routeNavigator.navigateToRoute(ConversationRoute.get(input))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ fun ImportScreen(viewModel: ImportFileViewModel) {
val jsonChooserLauncher = createChooserLauncher(onAction = {
viewModel.handleAction(ImportAction.JSONFileSelected(it))
})
val xmlChooserLauncher = createChooserLauncher(onAction = {
viewModel.handleAction(ImportAction.XMLFileSelected(it))
})

val defaultAppLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
Expand All @@ -31,7 +28,6 @@ fun ImportScreen(viewModel: ImportFileViewModel) {
Effects(
viewModel = viewModel,
jsonLauncher = jsonChooserLauncher,
xmlLauncher = xmlChooserLauncher,
defaultAppLauncher = defaultAppLauncher,
)

Expand All @@ -53,7 +49,6 @@ private fun createChooserLauncher(onAction: (Uri) -> Unit) = rememberLauncherFor
private fun Effects(
viewModel: ImportFileViewModel,
jsonLauncher: ActivityResultLauncher<Intent>,
xmlLauncher: ActivityResultLauncher<Intent>,
defaultAppLauncher: ActivityResultLauncher<Intent>,
) {
val ctx = LocalContext.current
Expand All @@ -63,9 +58,6 @@ private fun Effects(
is ImportEffect.OpenJSONFilePicker -> {
jsonLauncher.launch(effect.intent)
}
is ImportEffect.OpenXMLFilePicker -> {
xmlLauncher.launch(effect.intent)
}
is ImportEffect.ShowSetAsDefaultPrompt -> {
MessagingUtils.launchChangeDefaultPrompt(effect.owner, defaultAppLauncher)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ fun ImportTopToolbar(
openMoreOptions = false
onAction(ImportAction.ImportJSONClicked)
},
PopupOptions.Option("Open new XML") {
openMoreOptions = false
onAction(ImportAction.ImportXMLClicked)
},
)
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import javax.inject.Inject
class ConversationsImporter @Inject constructor(
private val appScope: AppScope,
private val serializer: JsonSerializer,
private val xmlParser: XMLParser,
) {

suspend fun importJson(uri: Uri): ImportResult = withContext(Dispatchers.IO) {
Expand Down Expand Up @@ -56,15 +55,6 @@ class ConversationsImporter @Inject constructor(
ImportResult.Success(filename, convs)
}

suspend fun importXML(uri: Uri): ImportResult = withContext(Dispatchers.IO) {
val cr = appScope.appContext.contentResolver
val inputStream = cr.openInputStream(uri)
?: return@withContext ImportResult.Error("Failed to open input stream")
val filename = queryName(uri)
val convsResult = xmlParser.parse(inputStream, filename)
convsResult
}

private fun queryName(uri: Uri): String {
val returnCursor: Cursor =
appScope.appContext.contentResolver.query(uri, null, null, null, null)!!
Expand Down

This file was deleted.

0 comments on commit 35e0625

Please sign in to comment.