Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Room Park Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav Bogdashkin
Room Park Android
Commits
8d91df7d
Commit
8d91df7d
authored
Nov 05, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
files module integrated
parent
358ac8aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
FileModule.kt
...iganto/visual/roompark/data/repository/file/FileModule.kt
+78
-0
No files found.
app/src/main/java/com/biganto/visual/roompark/data/repository/file/FileModule.kt
0 → 100644
View file @
8d91df7d
package
com.biganto.visual.roompark.data.repository.file
import
android.content.Context
import
android.os.Environment
import
com.google.gson.JsonElement
import
dagger.Module
import
timber.log.Timber
import
java.io.File
/**
* Created by Vladislav Bogdashkin on 29.06.2018.
*/
@Module
class
FilesModule
(
private
val
context
:
Context
)
{
private
val
rootFolder
:
File
get
()
{
val
rootFile
=
context
.
filesDir
Environment
.
getDataDirectory
()
if
(!
rootFile
.
exists
())
rootFile
.
mkdirs
()
return
rootFile
}
fun
getFile
(
fileUri
:
String
):
File
{
try
{
val
fileName
=
if
(
fileUri
.
contains
(
"/"
))
fileUri
.
substring
(
fileUri
.
lastIndexOf
(
"/"
))
else
fileUri
val
fileDir
=
if
(
fileUri
.
contains
(
"/"
))
fileUri
.
substring
(
0
,
fileUri
.
lastIndexOf
(
"/"
))
else
""
val
directory
=
File
(
rootFolder
,
fileDir
)
directory
.
mkdirs
()
val
file
=
File
(
directory
,
fileName
)
return
file
}
catch
(
e
:
Exception
)
{
Timber
.
e
(
"Caused file: %s"
,
fileUri
)
throw
error
(
"unconditional file"
)
}
}
fun
saveFileToDisk
(
file
:
File
,
jsonElement
:
JsonElement
){
file
.
writeText
(
"[$jsonElement]"
)
//to json array because core unity method parse data like TourData[] Estate[] etc..
}
fun
saveFileToDisk
(
file
:
File
,
content
:
String
){
file
.
writeText
(
content
)
//to json array because core unity method parse data like TourData[] Estate[] etc..
}
fun
deleteFile
(
uri
:
String
)=
getFile
(
uri
).
delete
()
val
getCoreCacheDirectory
:
String
get
(){
return
rootFolder
.
absolutePath
}
companion
object
{
fun
getDirectory
(
context
:
Context
?,
dirType
:
FileDirectory
):
String
=
context
?.
filesDir
?.
absolutePath
?.
plus
(
dirType
.
dir
)
?:
throw
IllegalArgumentException
(
"Context cannot be null!"
)
fun
assetsDirectory
(
context
:
Context
?):
String
=
context
?.
filesDir
?.
absolutePath
.
?:
throw
IllegalArgumentException
(
"Context cannot be null!"
)
}
sealed
class
FileDirectory
(
val
dir
:
String
)
{
class
PlanTypeDir
(
dir
:
String
=
"estates"
)
:
FileDirectory
(
dir
)
class
ToursDir
(
dir
:
String
=
"tours"
)
:
FileDirectory
(
dir
)
class
FeedsDir
(
dir
:
String
=
"feeds"
)
:
FileDirectory
(
dir
)
class
Albums
(
dir
:
String
=
"photos"
)
:
FileDirectory
(
dir
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment