Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
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
Administrator
Magisk
Commits
92789c31
Commit
92789c31
authored
May 12, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added caching repositories to device
parent
c1c677e1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
11 deletions
+24
-11
ModuleRepository.kt
.../com/topjohnwu/magisk/data/repository/ModuleRepository.kt
+11
-2
RepositoryModule.kt
...src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt
+1
-1
ModuleViewModel.kt
...in/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt
+12
-8
No files found.
app/src/main/java/com/topjohnwu/magisk/data/repository/ModuleRepository.kt
View file @
92789c31
package
com.topjohnwu.magisk.data.repository
package
com.topjohnwu.magisk.data.repository
import
android.content.Context
import
android.content.Context
import
com.skoumal.teanity.extensions.subscribeK
import
com.topjohnwu.magisk.data.database.RepositoryDao
import
com.topjohnwu.magisk.data.network.GithubApiServices
import
com.topjohnwu.magisk.data.network.GithubApiServices
import
com.topjohnwu.magisk.data.network.GithubRawApiServices
import
com.topjohnwu.magisk.data.network.GithubRawApiServices
import
com.topjohnwu.magisk.data.network.GithubServices
import
com.topjohnwu.magisk.data.network.GithubServices
import
com.topjohnwu.magisk.model.entity.GithubRepo
import
com.topjohnwu.magisk.model.entity.GithubRepo
import
com.topjohnwu.magisk.model.entity.toRepository
import
com.topjohnwu.magisk.model.entity.toRepository
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.toSingle
import
com.topjohnwu.magisk.utils.writeToFile
import
com.topjohnwu.magisk.utils.writeToFile
import
com.topjohnwu.magisk.utils.writeToString
import
com.topjohnwu.magisk.utils.writeToString
import
io.reactivex.Single
import
io.reactivex.Single
...
@@ -15,10 +18,15 @@ class ModuleRepository(
...
@@ -15,10 +18,15 @@ class ModuleRepository(
private
val
context
:
Context
,
private
val
context
:
Context
,
private
val
apiRaw
:
GithubRawApiServices
,
private
val
apiRaw
:
GithubRawApiServices
,
private
val
api
:
GithubApiServices
,
private
val
api
:
GithubApiServices
,
private
val
apiWeb
:
GithubServices
private
val
apiWeb
:
GithubServices
,
private
val
repoDao
:
RepositoryDao
)
{
)
{
fun
fetchModules
()
=
fetchAllRepos
()
fun
fetchModules
()
=
Single
.
fromCallable
{
repoDao
.
fetchAll
()
}
.
flatMap
{
if
(
it
.
isEmpty
())
fetchRemoteRepos
()
else
it
.
toSingle
()
}
.
doOnSuccess
{
fetchRemoteRepos
().
subscribeK
()
}
// cache changed for next time or next hot reload
private
fun
fetchRemoteRepos
()
=
fetchAllRepos
()
.
map
{
.
map
{
it
.
mapNotNull
{
it
.
mapNotNull
{
runCatching
{
runCatching
{
...
@@ -26,6 +34,7 @@ class ModuleRepository(
...
@@ -26,6 +34,7 @@ class ModuleRepository(
}.
getOrNull
()
}.
getOrNull
()
}
}
}
}
.
doOnSuccess
{
repoDao
.
insert
(
it
)
}
fun
fetchInstalledModules
()
=
Single
.
fromCallable
{
Utils
.
loadModulesLeanback
()
}
fun
fetchInstalledModules
()
=
Single
.
fromCallable
{
Utils
.
loadModulesLeanback
()
}
.
map
{
it
.
values
.
toList
()
}
.
map
{
it
.
values
.
toList
()
}
...
...
app/src/main/java/com/topjohnwu/magisk/di/RepositoryModule.kt
View file @
92789c31
...
@@ -6,7 +6,7 @@ import org.koin.dsl.module
...
@@ -6,7 +6,7 @@ import org.koin.dsl.module
val
repositoryModule
=
module
{
val
repositoryModule
=
module
{
single
{
MagiskRepository
(
get
(),
get
(),
get
())
}
single
{
MagiskRepository
(
get
(),
get
(),
get
())
}
single
{
ModuleRepository
(
get
(),
get
(),
get
(),
get
())
}
single
{
ModuleRepository
(
get
(),
get
(),
get
(),
get
()
,
get
()
)
}
single
{
LogRepository
(
get
())
}
single
{
LogRepository
(
get
())
}
single
{
AppRepository
(
get
())
}
single
{
AppRepository
(
get
())
}
single
{
SettingRepository
(
get
())
}
single
{
SettingRepository
(
get
())
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt
View file @
92789c31
...
@@ -5,6 +5,7 @@ import android.database.Cursor
...
@@ -5,6 +5,7 @@ import android.database.Cursor
import
androidx.annotation.StringRes
import
androidx.annotation.StringRes
import
com.skoumal.teanity.databinding.ComparableRvItem
import
com.skoumal.teanity.databinding.ComparableRvItem
import
com.skoumal.teanity.extensions.addOnPropertyChangedCallback
import
com.skoumal.teanity.extensions.addOnPropertyChangedCallback
import
com.skoumal.teanity.extensions.doOnSuccessUi
import
com.skoumal.teanity.extensions.subscribeK
import
com.skoumal.teanity.extensions.subscribeK
import
com.skoumal.teanity.util.DiffObservableList
import
com.skoumal.teanity.util.DiffObservableList
import
com.skoumal.teanity.util.KObservableField
import
com.skoumal.teanity.util.KObservableField
...
@@ -20,6 +21,7 @@ import com.topjohnwu.magisk.model.events.OpenFilePickerEvent
...
@@ -20,6 +21,7 @@ import com.topjohnwu.magisk.model.events.OpenFilePickerEvent
import
com.topjohnwu.magisk.ui.base.MagiskViewModel
import
com.topjohnwu.magisk.ui.base.MagiskViewModel
import
com.topjohnwu.magisk.utils.toSingle
import
com.topjohnwu.magisk.utils.toSingle
import
com.topjohnwu.magisk.utils.update
import
com.topjohnwu.magisk.utils.update
import
com.topjohnwu.magisk.utils.zip
import
io.reactivex.disposables.Disposable
import
io.reactivex.disposables.Disposable
import
me.tatarka.bindingcollectionadapter2.OnItemBind
import
me.tatarka.bindingcollectionadapter2.OnItemBind
...
@@ -54,7 +56,16 @@ class ModuleViewModel(
...
@@ -54,7 +56,16 @@ class ModuleViewModel(
fun
downloadPressed
(
item
:
RepoRvItem
)
=
InstallModuleEvent
(
item
.
item
).
publish
()
fun
downloadPressed
(
item
:
RepoRvItem
)
=
InstallModuleEvent
(
item
.
item
).
publish
()
fun
refresh
()
{
fun
refresh
()
{
moduleRepo
.
fetchModules
()
val
updateInstalled
=
moduleRepo
.
fetchInstalledModules
()
.
flattenAsFlowable
{
it
}
.
map
{
ModuleRvItem
(
it
)
}
.
toList
()
.
map
{
it
to
itemsInstalled
.
calculateDiff
(
it
)
}
.
doOnSuccessUi
{
itemsInstalled
.
update
(
it
.
first
,
it
.
second
)
}
val
updateRemote
=
moduleRepo
.
fetchModules
()
zip
(
updateInstalled
,
updateRemote
)
{
_
,
remote
->
remote
}
.
flattenAsFlowable
{
it
}
.
flattenAsFlowable
{
it
}
.
map
{
RepoRvItem
(
it
)
}
.
map
{
RepoRvItem
(
it
)
}
.
toList
()
.
toList
()
...
@@ -62,13 +73,6 @@ class ModuleViewModel(
...
@@ -62,13 +73,6 @@ class ModuleViewModel(
.
flatMap
{
queryRaw
()
}
.
flatMap
{
queryRaw
()
}
.
applyViewModel
(
this
)
.
applyViewModel
(
this
)
.
subscribeK
{
itemsRemote
.
update
(
it
.
first
,
it
.
second
)
}
.
subscribeK
{
itemsRemote
.
update
(
it
.
first
,
it
.
second
)
}
moduleRepo
.
fetchInstalledModules
()
.
flattenAsFlowable
{
it
}
.
map
{
ModuleRvItem
(
it
)
}
.
toList
()
.
map
{
it
to
itemsInstalled
.
calculateDiff
(
it
)
}
.
subscribeK
{
itemsInstalled
.
update
(
it
.
first
,
it
.
second
)
}
}
}
private
fun
query
()
=
queryRaw
()
private
fun
query
()
=
queryRaw
()
...
...
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