1
1
package me.ash.reader.infrastructure.rss
2
2
3
- import android.content.Context
4
3
import be.ceau.opml.OpmlParser
5
- import dagger.hilt.android.qualifiers.ApplicationContext
6
4
import kotlinx.coroutines.CoroutineDispatcher
7
5
import me.ash.reader.domain.model.feed.Feed
8
6
import me.ash.reader.domain.model.group.Group
9
7
import me.ash.reader.domain.model.group.GroupWithFeed
10
8
import me.ash.reader.infrastructure.di.IODispatcher
11
- import me.ash.reader.ui.ext.currentAccountId
9
+ import me.ash.reader.infrastructure.preference.PreferencesReader
12
10
import me.ash.reader.ui.ext.extractDomain
13
11
import me.ash.reader.ui.ext.spacerDollar
14
12
import java.io.InputStream
15
13
import java.util.*
16
14
import javax.inject.Inject
17
15
18
16
class OPMLDataSource @Inject constructor(
19
- @ApplicationContext
20
- private val context : Context ,
17
+ private val preferences : PreferencesReader ,
21
18
@IODispatcher
22
19
private val ioDispatcher : CoroutineDispatcher ,
23
20
) {
@@ -27,7 +24,7 @@ class OPMLDataSource @Inject constructor(
27
24
inputStream : InputStream ,
28
25
defaultGroup : Group ,
29
26
): List <GroupWithFeed > {
30
- val accountId = context .currentAccountId
27
+ val accountId = preferences .currentAccountId
31
28
val opml = OpmlParser ().parse(inputStream)
32
29
val groupWithFeedList = mutableListOf<GroupWithFeed >().also {
33
30
it.addGroup(defaultGroup)
@@ -41,7 +38,7 @@ class OPMLDataSource @Inject constructor(
41
38
if (! it.attributes.getOrDefault(" isDefault" , null ).toBoolean()) {
42
39
groupWithFeedList.addGroup(
43
40
Group (
44
- id = context .currentAccountId.spacerDollar(
41
+ id = preferences .currentAccountId.spacerDollar(
45
42
UUID .randomUUID().toString()
46
43
),
47
44
name = it.attributes.getOrDefault(" title" , null ) ? : it.text!! ,
@@ -52,7 +49,7 @@ class OPMLDataSource @Inject constructor(
52
49
} else {
53
50
groupWithFeedList.addFeedToDefault(
54
51
Feed (
55
- id = context .currentAccountId.spacerDollar(
52
+ id = preferences .currentAccountId.spacerDollar(
56
53
UUID .randomUUID().toString()
57
54
),
58
55
name = it.attributes.getOrDefault(" title" , null ) ? : it.text!! ,
@@ -71,7 +68,7 @@ class OPMLDataSource @Inject constructor(
71
68
var groupId = defaultGroup.id
72
69
if (! it.attributes.getOrDefault(" isDefault" , null ).toBoolean()) {
73
70
groupId =
74
- context .currentAccountId.spacerDollar(UUID .randomUUID().toString())
71
+ preferences .currentAccountId.spacerDollar(UUID .randomUUID().toString())
75
72
groupWithFeedList.addGroup(
76
73
Group (
77
74
id = groupId,
@@ -86,7 +83,7 @@ class OPMLDataSource @Inject constructor(
86
83
? : throw IllegalArgumentException (" ${outline.attributes} xmlUrl is null" )
87
84
groupWithFeedList.addFeed(
88
85
Feed (
89
- id = context .currentAccountId.spacerDollar(
86
+ id = preferences .currentAccountId.spacerDollar(
90
87
UUID .randomUUID().toString()
91
88
),
92
89
name = outline.attributes.getOrDefault(" title" , null )
0 commit comments