Skip to content

Commit

Permalink
[feat]: using .log files
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Oct 1, 2023
1 parent a10e94d commit 264a43f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
13 changes: 11 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="content" />
<data android:mimeType="text/plain" />
<data android:scheme="content"/>
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.log" />
<data android:pathPattern=".*\\..*\\.log" />
<data android:pathPattern=".*\\..*\\..*\\.log" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.log" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.log" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.log" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.log" />
<data android:host="*" />
</intent-filter>

<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RecordingsRepository @Inject constructor(

recordingTime = System.currentTimeMillis()
fileMutex.withLock {
recordingFile = File(recordingDir, "${recordingTime.exportFormatted}.txt").apply {
recordingFile = File(recordingDir, "${recordingTime.exportFormatted}.log").apply {
createNewFile()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class RecordingBottomSheet: BaseViewModelBottomSheet<RecordingViewModel, SheetRe
viewModel.recording.value ?: return@registerForActivityResult
)
}
private val logExportLauncher = registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) {
// no plain because android will append .txt itself
private val logExportLauncher = registerForActivityResult(ActivityResultContracts.CreateDocument("text/*")) {
viewModel.exportFile(it ?: return@registerForActivityResult)
}

Expand All @@ -54,7 +55,7 @@ class RecordingBottomSheet: BaseViewModelBottomSheet<RecordingViewModel, SheetRe
))
}
binding.exportLayout.setOnClickListener {
logExportLauncher.launch("${logRecording.dateAndTime.exportFormatted}.txt")
logExportLauncher.launch("${logRecording.dateAndTime.exportFormatted}.log")
}
binding.shareLayout.setOnClickListener {
requireContext().shareFileIntent(File(logRecording.file))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ class LogsFragment: BaseViewModelFragment<LogsViewModel, FragmentLogsBinding>(),
binding.toolbar.apply {
menu.findItem(R.id.pause_item).isVisible = !it

title = if (it)
viewModel.fileUri?.readFileName(requireContext())
else getString(R.string.app_name)
title = when (it) {
true -> viewModel.fileUri?.readFileName(requireContext())

else -> getString(R.string.app_name)
}

if (it) setNavigationIcon(R.drawable.ic_clear)
else {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/f0x1d/logfox/utils/ExportImportUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ fun OutputStream.exportFilters(context: Context, filters: List<UserFilter>) = us
}

fun OutputStream.exportCrashToZip(context: Context, log: String) = exportToZip(context) {
putZipEntry("log.txt", log.encodeToByteArray())
putZipEntry("crash.log", log.encodeToByteArray())
}

fun OutputStream.exportLogToZip(context: Context, logFile: String) = exportToZip(context) {
putZipEntry("log.txt", File(logFile))
putZipEntry("crash.log", File(logFile))
}

private fun OutputStream.exportToZip(context: Context, block: ZipOutputStream.() -> Unit) = use {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/drawable/ic_clear.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<vector android:height="24dp"
android:tint="#000000"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/logs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:label="LogsFragment" >
<deepLink
app:uri="content"
app:mimeType="text/plain"
app:mimeType="*/*"
app:action="android.intent.action.VIEW" />

<argument
Expand Down

0 comments on commit 264a43f

Please sign in to comment.