Skip to content

Commit

Permalink
fenrir_vk_2.110-Kotlin
Browse files Browse the repository at this point in the history
fenrir_vk_2.110-Kotlin
  • Loading branch information
umerov1999 committed Oct 30, 2022
1 parent 800a0d5 commit 5f9452f
Show file tree
Hide file tree
Showing 48 changed files with 810 additions and 259 deletions.
6 changes: 3 additions & 3 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ object Constants {
val AUTH_VERSION = if (DEFAULT_ACCOUNT_TYPE == AccountType.KATE) API_VERSION else "5.122"
const val FILE_PROVIDER_AUTHORITY: String = BuildConfig.APPLICATION_ID + ".file_provider"
const val VK_ANDROID_APP_VERSION_NAME = "8.2"
const val VK_ANDROID_APP_VERSION_CODE = "14408"
const val KATE_APP_VERSION_NAME = "92.2 lite"
const val KATE_APP_VERSION_CODE = "524"
const val VK_ANDROID_APP_VERSION_CODE = "14407"
const val KATE_APP_VERSION_NAME = "94 lite"
const val KATE_APP_VERSION_CODE = "527"
const val API_ID: Int = BuildConfig.VK_API_APP_ID
const val SECRET: String = BuildConfig.VK_CLIENT_SECRET
const val MAIN_OWNER_FIELDS = UserColumns.API_FIELDS + "," + GroupColumns.API_FIELDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ internal class NewsfeedApi(accountId: Int, provider: IServiceProvider) :
}
}

override fun getTop(
filters: String?, returnBanned: Boolean?, startTime: Long?,
endTime: Long?, maxPhotoCount: Int?, sourceIds: String?,
startFrom: String?, count: Int?, fields: String?
): Single<NewsfeedResponse> {
return provideService(INewsfeedService::class.java, TokenType.USER)
.flatMap { service ->
service.getByType(
"top",
filters,
integerFromBoolean(returnBanned),
startTime,
endTime,
maxPhotoCount,
sourceIds,
startFrom,
count,
fields
)
.map(extractResponseWithErrorHandling())
}
}

override fun getRecommended(
startTime: Long?, endTime: Long?,
maxPhotoCount: Int?, startFrom: String?, count: Int?, fields: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ interface INewsfeedApi {
maxPhotoCount: Int?, sourceIds: String?, startFrom: String?, count: Int?, fields: String?
): Single<NewsfeedResponse>

@CheckResult
fun getTop(
filters: String?, returnBanned: Boolean?, startTime: Long?,
endTime: Long?, maxPhotoCount: Int?, sourceIds: String?,
startFrom: String?, count: Int?, fields: String?
): Single<NewsfeedResponse>

@CheckResult
fun getRecommended(
startTime: Long?, endTime: Long?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ interface INewsfeedService {
@Field("fields") fields: String?
): Single<BaseResponse<NewsfeedResponse>>

@FormUrlEncoded
@POST("newsfeed.getByType")
fun getByType(
@Field("feed_type") feed_type: String,
@Field("filters") filters: String?,
@Field("return_banned") returnBanned: Int?,
@Field("start_time") startTime: Long?,
@Field("end_time") endTime: Long?,
@Field("max_photos") maxPhotoCount: Int?,
@Field("source_ids") sourceIds: String?,
@Field("start_from") startFrom: String?,
@Field("count") count: Int?,
@Field("fields") fields: String?
): Single<BaseResponse<NewsfeedResponse>>

@FormUrlEncoded
@POST("newsfeed.getRecommended")
fun getRecommended(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.ragnarok.fenrir.domain.IOwnersRepository
import dev.ragnarok.fenrir.domain.mappers.Dto2Model
import dev.ragnarok.fenrir.model.*
import dev.ragnarok.fenrir.settings.ISettings.IAccountsSettings
import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.Utils
import dev.ragnarok.fenrir.util.Utils.listEmptyIfNull
import io.reactivex.rxjava3.core.Completable
Expand Down Expand Up @@ -118,7 +119,18 @@ class AccountsInteractor(

override fun getAll(refresh: Boolean): Single<List<Account>> {
return Single.create { emitter: SingleEmitter<List<Account>> ->
val ids: Collection<Int> = settings.registered
val tmpIds: Collection<Int> = settings.registered
val ids: Collection<Int> = if (!Settings.get().security().IsShow_hidden_accounts()) {
val lst = ArrayList<Int>()
for (i in tmpIds) {
if (!Utils.isHiddenAccount(i)) {
lst.add(i)
}
}
lst
} else {
tmpIds
}
val accounts: MutableList<Account> = ArrayList(ids.size)
for (id in ids) {
if (emitter.isDisposed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,36 @@ class FeedInteractor(
maxPhotos: Int?,
sourceIds: String?
): Single<Pair<List<News>, String?>> {
return if ("likes" == sourceIds) {
networker.vkDefault(accountId)
.newsfeed()
.getFeedLikes(maxPhotos, startFrom, count, Constants.MAIN_OWNER_FIELDS)
.flatMap { response ->
return when (sourceIds) {
"likes", "recommendation", "top" -> {
when (sourceIds) {
"likes" -> networker.vkDefault(accountId)
.newsfeed()
.getFeedLikes(maxPhotos, startFrom, count, Constants.MAIN_OWNER_FIELDS)
"recommendation" -> networker.vkDefault(accountId)
.newsfeed()
.getRecommended(
null,
null,
maxPhotos,
startFrom,
count,
Constants.MAIN_OWNER_FIELDS
)
else -> networker.vkDefault(accountId)
.newsfeed()
.getTop(
null,
null,
null,
null,
maxPhotos,
null,
startFrom,
count,
Constants.MAIN_OWNER_FIELDS
)
}.flatMap { response ->
val nextFrom = response.nextFrom
val owners = transformOwners(response.profiles, response.groups)
val feed = listEmptyIfNull(response.items)
Expand Down Expand Up @@ -114,113 +139,67 @@ class FeedInteractor(
}
}
}
} else if ("recommendation" == sourceIds) {
networker.vkDefault(accountId)
.newsfeed()
.getRecommended(
null,
null,
maxPhotos,
startFrom,
count,
Constants.MAIN_OWNER_FIELDS
)
.flatMap { response ->
val nextFrom = response.nextFrom
val owners = transformOwners(response.profiles, response.groups)
val feed = listEmptyIfNull(response.items)
val dbos: MutableList<NewsDboEntity> = ArrayList(feed.size)
val ownIds = VKOwnIds()
for (news in feed) {
if (news.source_id == 0) {
continue
}
else -> {
networker.vkDefault(accountId)
.newsfeed()[filters, null, null, null, maxPhotos, if (setOf(
"updates_photos",
"updates_videos",
"updates_full",
"updates_audios"
).contains(sourceIds)
) null else sourceIds, startFrom, count, Constants.MAIN_OWNER_FIELDS]
.flatMap { response ->
val blockAds = Settings.get().other().isAd_block_story_news
val needStripRepost = Settings.get().other().isStrip_news_repost
val rgx = Settings.get().other().isBlock_news_by_words
val nextFrom = response.nextFrom
val owners = transformOwners(response.profiles, response.groups)
val feed = listEmptyIfNull(response.items)
val dbos: MutableList<NewsDboEntity> = ArrayList(feed.size)
val ownIds = VKOwnIds()
for (dto in feed) {
if (dto.source_id == 0 || blockAds && (dto.type == "ads" || dto.mark_as_ads != 0) || needStripRepost && dto.isOnlyRepost || containInWords(
rgx,
dto
)
) {
continue
}
dbos.add(mapNews(dto))
ownIds.appendNews(dto)
}
dbos.add(mapNews(news))
ownIds.appendNews(news)
}
val ownerEntities = mapOwners(response.profiles, response.groups)
stores.feed()
.store(accountId, dbos, ownerEntities, startFrom.isNullOrEmpty())
.flatMap {
otherSettings.storeFeedNextFrom(accountId, nextFrom)
otherSettings.setFeedSourceIds(accountId, sourceIds)
ownersRepository.findBaseOwnersDataAsBundle(
accountId,
ownIds.all,
IOwnersRepository.MODE_ANY,
owners
)
.map {
val news: MutableList<News> = ArrayList(feed.size)
for (dto in feed) {
if (dto.source_id == 0) {
continue
val ownerEntities = mapOwners(response.profiles, response.groups)
stores.feed()
.store(accountId, dbos, ownerEntities, startFrom.isNullOrEmpty())
.flatMap {
otherSettings.storeFeedNextFrom(accountId, nextFrom)
otherSettings.setFeedSourceIds(accountId, sourceIds)
ownersRepository.findBaseOwnersDataAsBundle(
accountId,
ownIds.all,
IOwnersRepository.MODE_ANY,
owners
)
.map {
val news: MutableList<News> = ArrayList(feed.size)
for (dto in feed) {
if (dto.source_id == 0 || blockAds && (dto.type == "ads" || dto.mark_as_ads != 0) || needStripRepost && dto.isOnlyRepost || containInWords(
rgx,
dto
)
) {
continue
} else if (needStripRepost && dto.hasCopyHistory()) {
dto.stripRepost()
}
news.add(buildNews(dto, it))
}
news.add(buildNews(dto, it))
create(news, nextFrom)
}
create(news, nextFrom)
}
}
}
} else {
networker.vkDefault(accountId)
.newsfeed()[filters, null, null, null, maxPhotos, if (setOf(
"updates_photos",
"updates_videos",
"updates_full",
"updates_audios"
).contains(sourceIds)
) null else sourceIds, startFrom, count, Constants.MAIN_OWNER_FIELDS]
.flatMap { response ->
val blockAds = Settings.get().other().isAd_block_story_news
val needStripRepost = Settings.get().other().isStrip_news_repost
val rgx = Settings.get().other().isBlock_news_by_words
val nextFrom = response.nextFrom
val owners = transformOwners(response.profiles, response.groups)
val feed = listEmptyIfNull(response.items)
val dbos: MutableList<NewsDboEntity> = ArrayList(feed.size)
val ownIds = VKOwnIds()
for (dto in feed) {
if (dto.source_id == 0 || blockAds && (dto.type == "ads" || dto.mark_as_ads != 0) || needStripRepost && dto.isOnlyRepost || containInWords(
rgx,
dto
)
) {
continue
}
dbos.add(mapNews(dto))
ownIds.appendNews(dto)
}
}
val ownerEntities = mapOwners(response.profiles, response.groups)
stores.feed()
.store(accountId, dbos, ownerEntities, startFrom.isNullOrEmpty())
.flatMap {
otherSettings.storeFeedNextFrom(accountId, nextFrom)
otherSettings.setFeedSourceIds(accountId, sourceIds)
ownersRepository.findBaseOwnersDataAsBundle(
accountId,
ownIds.all,
IOwnersRepository.MODE_ANY,
owners
)
.map {
val news: MutableList<News> = ArrayList(feed.size)
for (dto in feed) {
if (dto.source_id == 0 || blockAds && (dto.type == "ads" || dto.mark_as_ads != 0) || needStripRepost && dto.isOnlyRepost || containInWords(
rgx,
dto
)
) {
continue
} else if (needStripRepost && dto.hasCopyHistory()) {
dto.stripRepost()
}
news.add(buildNews(dto, it))
}
create(news, nextFrom)
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,24 @@ class PreferencesFragment : AbsPreferencesFragment(), PreferencesAdapter.OnScree
switch("delete_cache_images") {
titleRes = R.string.delete_cache_images
}

singleChoice(
"limit_cache_images",
selItems(
R.array.array_limit_cache_images_names,
R.array.array_limit_cache_images_items
),
parentFragmentManager
) {
initialSelection = "2"
titleRes = R.string.limit_cache_images
onSelectionChange {
TempDataHelper.helper.clear()
cleanUICache(requireActivity(), false)
cleanCache(requireActivity(), true)
requireActivity().recreate()
}
}
}

switch("compress_incoming_traffic") {
Expand All @@ -1788,18 +1806,6 @@ class PreferencesFragment : AbsPreferencesFragment(), PreferencesAdapter.OnScree
}
}

switch("limit_cache") {
defaultValue = false
titleRes = R.string.limit_cache
onCheckedChange {
TempDataHelper.helper.clear()
cleanUICache(requireActivity(), false)
cleanCache(requireActivity(), true)
Includes.proxySettings.broadcastUpdate(null)
requireActivity().recreate()
}
}

pref("delete_dynamic_shortcuts") {
dependency = "developer_mode"
titleRes = R.string.delete_dynamic_shortcuts
Expand Down
Loading

0 comments on commit 5f9452f

Please sign in to comment.