Skip to content

Commit

Permalink
Handle absence of the folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrlzy committed Jul 30, 2023
1 parent 1d9218e commit 8ff541a
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ import space.taran.arkshelf.domain.UserPreferences
import java.nio.file.Path
import javax.inject.Inject
import kotlin.io.path.Path
import kotlin.io.path.exists

class UserPreferencesImpl @Inject constructor(
private val context: Context
) : UserPreferences {
private val prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE)

override fun getLinkFolder() =
prefs.getString(SAVE_PATH_KEY, null)?.let { Path(it) }
prefs.getString(SAVE_PATH_KEY, null)
?.let {
val linkFolder = Path(it)
if (linkFolder.exists())
linkFolder
else
null
}


override fun setLinkFolder(path: Path) = with(prefs.edit()) {
Expand Down

0 comments on commit 8ff541a

Please sign in to comment.