Skip to content

Commit

Permalink
Merge pull request #71 from chenxiaolong/output-dir-friendly
Browse files Browse the repository at this point in the history
SettingsActivity: Show user-friendly path for output directory
  • Loading branch information
chenxiaolong authored Jun 6, 2022
2 parents 5c0eb0e + f0cda28 commit 0f8f3b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 21 additions & 2 deletions app/src/main/java/com/chiller3/bcr/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.chiller3.bcr

import android.content.ContentResolver
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Bundle
import android.provider.DocumentsContract
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
Expand Down Expand Up @@ -105,9 +107,26 @@ class SettingsActivity : AppCompatActivity() {
}

private fun refreshOutputDir() {
val outputDir = Preferences.getOutputDir(requireContext())
val context = requireContext()
val outputDirUri = Preferences.getOutputDir(context)
val outputDirFormatted = when {
outputDirUri.scheme == ContentResolver.SCHEME_FILE -> outputDirUri.path
outputDirUri.scheme == ContentResolver.SCHEME_CONTENT
&& outputDirUri.authority == "com.android.externalstorage.documents" -> {
val treeDocumentId = DocumentsContract.getTreeDocumentId(outputDirUri)
val childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(
outputDirUri, treeDocumentId)

DocumentsContract.findDocumentPath(context.contentResolver, childrenUri)
?.path
?.joinToString("/")
?: outputDirUri.toString()
}
else -> outputDirUri.toString()
}

val summary = getString(R.string.pref_output_dir_desc)
prefOutputDir.summary = "${summary}\n\n${outputDir}"
prefOutputDir.summary = "${summary}\n\n${outputDirFormatted}"
}

private fun refreshOutputFormat() {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/chiller3/bcr/format/SampleRates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package com.chiller3.bcr.format

import android.content.Context
import com.chiller3.bcr.Preferences
import com.chiller3.bcr.R

object SampleRates {
/**
Expand Down

0 comments on commit 0f8f3b3

Please sign in to comment.