Skip to content

Commit

Permalink
26
Browse files Browse the repository at this point in the history
26
  • Loading branch information
umerov1999 committed May 9, 2023
1 parent aea901a commit 4f63242
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class DeltaOwnerActivity : AppCompatActivity(), PlaceProvider, AppStyleable {
public override fun onCreate(savedInstanceState: Bundle?) {
setTheme(ThemesController.currentStyle())
Utils.prepareDensity(this)
Utils.registerColorsThorVG(this)
super.onCreate(savedInstanceState)
attach(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class LottieActivity : AppCompatActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
setTheme(currentStyle())
Utils.prepareDensity(this)
Utils.registerColorsThorVG(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_lottie)
lottie = findViewById(R.id.lottie_preview)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ import dev.ragnarok.fenrir.model.*
import dev.ragnarok.fenrir.model.drawer.AbsMenuItem
import dev.ragnarok.fenrir.model.drawer.RecentChat
import dev.ragnarok.fenrir.model.drawer.SectionMenuItem
import dev.ragnarok.fenrir.module.FenrirNative
import dev.ragnarok.fenrir.module.thorvg.ThorVGRender
import dev.ragnarok.fenrir.place.Place
import dev.ragnarok.fenrir.place.PlaceFactory
import dev.ragnarok.fenrir.place.PlaceProvider
Expand Down Expand Up @@ -350,18 +348,7 @@ open class MainActivity : AppCompatActivity(), NavigationDrawerCallbacks, OnSect
}
setTheme(currentStyle())
Utils.prepareDensity(this)

if (FenrirNative.isNativeLoaded && getMainActivityTransform() == MainActivityTransforms.MAIN) {
ThorVGRender.registerColors(
mapOf(
"primary_color" to CurrentTheme.getColorPrimary(this),
"secondary_color" to CurrentTheme.getColorSecondary(this),
"on_surface_color" to CurrentTheme.getColorOnSurface(this),
"white_color_contrast_fix" to CurrentTheme.getColorWhiteContrastFix(this),
"black_color_contrast_fix" to CurrentTheme.getColorBlackContrastFix(this)
)
)
}
Utils.registerColorsThorVG(this)

super.onCreate(savedInstanceState)
isActivityDestroyed = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class NoMainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(currentStyle())
Utils.prepareDensity(this)
Utils.registerColorsThorVG(this)
super.onCreate(savedInstanceState)
isZoomPhoto = Settings.get().other().isDo_zoom_photo
setContentView(getNoMainContentView())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PostPublishPrepareActivity : AppCompatActivity(), RecyclerMenuAdapter.Acti
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(currentStyle())
Utils.prepareDensity(this)
Utils.registerColorsThorVG(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_post_publish_prepare)
adapter = RecyclerMenuAdapter(R.layout.item_advanced_menu_alternative, emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class VideoPlayerActivity : AppCompatActivity(), SurfaceHolder.Callback,
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(currentStyle())
Utils.prepareDensity(this)
Utils.registerColorsThorVG(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_video)
val surfaceContainer = findViewById<ViewGroup>(R.id.videoSurfaceContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,24 @@ internal class MessagesApi(accountId: Long, provider: IServiceProvider) :
mediaType: String?,
startFrom: String?,
photoSizes: Int?,
preserve_order: Int?,
max_forwards_level: Int?,
count: Int?,
fields: String?
): Single<AttachmentsHistoryResponse> {
return serviceRx(TokenType.USER, TokenType.COMMUNITY)
.flatMap { service ->
service
.getHistoryAttachments(peerId, mediaType, startFrom, count, photoSizes, fields)
.getHistoryAttachments(
peerId,
mediaType,
startFrom,
count,
photoSizes,
preserve_order,
max_forwards_level,
fields
)
.map(extractResponseWithErrorHandling())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ interface IMessagesApi {

@CheckResult
fun getHistoryAttachments(
peerId: Long, mediaType: String?, startFrom: String?, photoSizes: Int?,
count: Int?, fields: String?
peerId: Long,
mediaType: String?,
startFrom: String?,
photoSizes: Int?,
preserve_order: Int?,
max_forwards_level: Int?,
count: Int?,
fields: String?
): Single<AttachmentsHistoryResponse>

@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ class IMessageService : IServiceRest() {
startFrom: String?,
count: Int?,
photoSizes: Int?,
preserve_order: Int?,
max_forwards_level: Int?,
fields: String?
): Single<BaseResponse<AttachmentsHistoryResponse>> {
return rest.request(
Expand All @@ -411,7 +413,9 @@ class IMessageService : IServiceRest() {
"start_from" to startFrom,
"count" to count,
"photo_sizes" to photoSizes,
"fields" to fields
"fields" to fields,
"preserve_order" to preserve_order,
"max_forwards_level" to max_forwards_level
),
base(AttachmentsHistoryResponse.serializer())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import dev.ragnarok.fenrir.R
import dev.ragnarok.fenrir.api.Apis.get
import dev.ragnarok.fenrir.api.model.VKApiAudio
import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment
import dev.ragnarok.fenrir.domain.mappers.Dto2Model
import dev.ragnarok.fenrir.fragment.conversation.abschatattachments.BaseChatAttachmentsPresenter
import dev.ragnarok.fenrir.model.Audio
Expand All @@ -30,7 +31,7 @@ class ChatAttachmentAudioPresenter(peerId: Long, accountId: Long, savedInstanceS
): Single<Pair<String?, List<Audio>>> {
return get().vkDefault(accountId)
.messages()
.getHistoryAttachments(peerId, "audio", nextFrom, 0, 50, null)
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_AUDIO, nextFrom, 0, 1, 45, 50, null)
.map { response ->
val audios: MutableList<Audio> = ArrayList(
Utils.safeCountOf(response.items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChatAttachmentDocsPresenter(peerId: Long, accountId: Long, savedInstanceSt
): Single<Pair<String?, List<Document>>> {
return get().vkDefault(accountId)
.messages()
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_DOC, nextFrom, 1, 50, null)
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_DOC, nextFrom, 1, 1, 45, 50, null)
.map { response ->
val docs: MutableList<Document> = ArrayList(
Utils.safeCountOf(response.items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChatAttachmentLinksPresenter(peerId: Long, accountId: Long, savedInstanceS
): Single<Pair<String?, List<Link>>> {
return get().vkDefault(accountId)
.messages()
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_LINK, nextFrom, 1, 50, null)
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_LINK, nextFrom, 1, 1, 45, 50, null)
.map { response ->
val docs: MutableList<Link> = ArrayList(Utils.safeCountOf(response.items))
response.items.nonNullNoEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import dev.ragnarok.fenrir.R
import dev.ragnarok.fenrir.api.Apis.get
import dev.ragnarok.fenrir.api.model.VKApiPhoto
import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment
import dev.ragnarok.fenrir.db.Stores
import dev.ragnarok.fenrir.db.serialize.Serializers
import dev.ragnarok.fenrir.domain.mappers.Dto2Model
Expand Down Expand Up @@ -36,7 +37,7 @@ class ChatAttachmentPhotoPresenter(peerId: Long, accountId: Long, savedInstanceS
): Single<Pair<String?, List<Photo>>> {
return get().vkDefault(accountId)
.messages()
.getHistoryAttachments(peerId, "photo", nextFrom, 1, 50, null)
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_PHOTO, nextFrom, 1, 1, 45, 50, null)
.map { response ->
val photos: MutableList<Photo> = ArrayList()
response.items.nonNullNoEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChatAttachmentPostsPresenter(peerId: Long, accountId: Long, savedInstanceS
): Single<Pair<String?, List<Link>>> {
return get().vkDefault(accountId)
.messages()
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_POST, nextFrom, 1, 50, null)
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_POST, nextFrom, 1, 1, 45, 50, null)
.map { response ->
val docs: MutableList<Link> = ArrayList(Utils.safeCountOf(response.items))
response.items.nonNullNoEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import dev.ragnarok.fenrir.R
import dev.ragnarok.fenrir.api.Apis.get
import dev.ragnarok.fenrir.api.model.VKApiVideo
import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment
import dev.ragnarok.fenrir.domain.mappers.Dto2Model
import dev.ragnarok.fenrir.fragment.conversation.abschatattachments.BaseChatAttachmentsPresenter
import dev.ragnarok.fenrir.model.Video
Expand All @@ -30,7 +31,7 @@ class ChatAttachmentVideoPresenter(peerId: Long, accountId: Long, savedInstanceS
): Single<Pair<String?, List<Video>>> {
return get().vkDefault(accountId)
.messages()
.getHistoryAttachments(peerId, "video", nextFrom, 1, 50, null)
.getHistoryAttachments(peerId, VKApiAttachment.TYPE_VIDEO, nextFrom, 1, 1, 45, 50, null)
.map { response ->
val videos: MutableList<Video> = ArrayList(
Utils.safeCountOf(response.items)
Expand Down
23 changes: 23 additions & 0 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.graphics.*
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Parcel
import android.util.ArrayMap
import android.util.SparseArray
import android.util.TypedValue
import android.view.Display
Expand Down Expand Up @@ -50,7 +51,9 @@ import dev.ragnarok.fenrir.link.internal.OwnerLinkSpanFactory
import dev.ragnarok.fenrir.media.exo.OkHttpDataSource
import dev.ragnarok.fenrir.model.*
import dev.ragnarok.fenrir.model.Sticker.LocalSticker
import dev.ragnarok.fenrir.module.FenrirNative
import dev.ragnarok.fenrir.module.rlottie.RLottieDrawable
import dev.ragnarok.fenrir.module.thorvg.ThorVGRender
import dev.ragnarok.fenrir.place.Place
import dev.ragnarok.fenrir.place.PlaceFactory.getOwnerWallPlace
import dev.ragnarok.fenrir.settings.CurrentTheme
Expand Down Expand Up @@ -90,6 +93,8 @@ object Utils {
var isCompressOutgoingTraffic = false
var currentParser = 0

var currentColorsReplacement = ArrayMap<String, Int>()

fun getCachedMyStickers(): MutableList<LocalSticker> {
return cachedMyStickers
}
Expand All @@ -108,6 +113,24 @@ object Utils {
}
*/

fun registerColorsThorVG(context: Context) {
if (!FenrirNative.isNativeLoaded) {
return
}
val tmpMap = mapOf(
"primary_color" to CurrentTheme.getColorPrimary(context),
"secondary_color" to CurrentTheme.getColorSecondary(context),
"on_surface_color" to CurrentTheme.getColorOnSurface(context),
"white_color_contrast_fix" to CurrentTheme.getColorWhiteContrastFix(context),
"black_color_contrast_fix" to CurrentTheme.getColorBlackContrastFix(context)
)
if (currentColorsReplacement != tmpMap) {
currentColorsReplacement.clear()
currentColorsReplacement.putAll(tmpMap)
ThorVGRender.registerColors(currentColorsReplacement)
}
}

fun needReloadNews(account_id: Long): Boolean {
if (!reload_news.contains(account_id)) {
reload_news.add(account_id)
Expand Down

0 comments on commit 4f63242

Please sign in to comment.