я не помню, что тут
This commit is contained in:
@@ -6,6 +6,7 @@ import com.meloda.fast.common.AppGlobal
|
||||
|
||||
object UserConfig {
|
||||
|
||||
private const val FAST_TOKEN = "fast_token"
|
||||
private const val TOKEN = "token"
|
||||
private const val USER_ID = "user_id"
|
||||
|
||||
@@ -25,8 +26,16 @@ object UserConfig {
|
||||
AppGlobal.preferences.edit().putString(TOKEN, value).apply()
|
||||
}
|
||||
|
||||
var fastToken: String = ""
|
||||
get() = AppGlobal.preferences.getString(FAST_TOKEN, "") ?: ""
|
||||
set(value) {
|
||||
field = value
|
||||
AppGlobal.preferences.edit().putString(FAST_TOKEN, value).apply()
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
accessToken = ""
|
||||
fastToken = ""
|
||||
userId = -1
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ object VKConstants {
|
||||
const val USER_FIELDS =
|
||||
"photo_50,photo_100,photo_200,status,screen_name,online,online_mobile,last_seen,verified,sex,online_info"
|
||||
|
||||
const val ALL_FIELDS = "$USER_FIELDS,$GROUP_FIELDS"
|
||||
|
||||
const val API_VERSION = "5.132"
|
||||
const val VK_APP_ID = "2274003"
|
||||
const val VK_SECRET = "hHbZxrka2uZ6jB1inYsH"
|
||||
|
||||
@@ -42,6 +42,12 @@ object VkUtils {
|
||||
return forwards
|
||||
}
|
||||
|
||||
fun parseReplyMessage(baseReplyMessage: BaseVkMessage?): VkMessage? {
|
||||
if (baseReplyMessage == null) return null
|
||||
|
||||
return baseReplyMessage.asVkMessage()
|
||||
}
|
||||
|
||||
fun parseAttachments(baseAttachments: List<BaseVkAttachmentItem>?): List<VkAttachment>? {
|
||||
if (baseAttachments.isNullOrEmpty()) return null
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.meloda.fast.api.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.PrimaryKey
|
||||
import com.meloda.fast.api.model.attachments.VkAttachment
|
||||
import com.meloda.fast.base.adapter.SelectableItem
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Entity(tableName = "messages")
|
||||
@@ -24,9 +27,21 @@ data class VkMessage(
|
||||
val actionMessage: String? = null,
|
||||
val geoType: String? = null,
|
||||
val important: Boolean = false,
|
||||
|
||||
var forwards: List<VkMessage>? = null,
|
||||
var attachments: List<VkAttachment>? = null
|
||||
) : Parcelable {
|
||||
var attachments: List<VkAttachment>? = null,
|
||||
|
||||
// @Embedded(prefix = "replyMessage_")
|
||||
var replyMessage: VkMessage? = null
|
||||
) : SelectableItem() {
|
||||
|
||||
@Ignore
|
||||
@IgnoredOnParcel
|
||||
val user = MutableLiveData<VkUser?>()
|
||||
|
||||
@Ignore
|
||||
@IgnoredOnParcel
|
||||
val group = MutableLiveData<VkGroup?>()
|
||||
|
||||
fun isPeerChat() = peerId > 2_000_000_000
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.meloda.fast.api.model.attachments
|
||||
|
||||
import androidx.room.Ignore
|
||||
import com.meloda.fast.api.model.base.attachments.BaseVkPhoto
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import java.util.*
|
||||
|
||||
@Parcelize
|
||||
data class VkPhoto(
|
||||
@@ -17,13 +19,58 @@ data class VkPhoto(
|
||||
val userId: Int?
|
||||
) : VkAttachment() {
|
||||
|
||||
@Ignore
|
||||
@IgnoredOnParcel
|
||||
private val sizesChars = Stack<Char>()
|
||||
|
||||
init {
|
||||
sizesChars.push('s')
|
||||
sizesChars.push('m')
|
||||
sizesChars.push('x')
|
||||
sizesChars.push('o')
|
||||
sizesChars.push('p')
|
||||
sizesChars.push('q')
|
||||
sizesChars.push('r')
|
||||
sizesChars.push('y')
|
||||
sizesChars.push('z')
|
||||
sizesChars.push('w')
|
||||
}
|
||||
|
||||
@IgnoredOnParcel
|
||||
val className: String = this::class.java.name
|
||||
|
||||
fun sizeOfType(type: Char): BaseVkPhoto.Size? {
|
||||
fun getMaxSize(): BaseVkPhoto.Size? {
|
||||
return getSizeOrSmaller(sizesChars.peek())
|
||||
}
|
||||
|
||||
fun getSizeOrNull(type: Char): BaseVkPhoto.Size? {
|
||||
for (size in sizes) {
|
||||
if (size.type == type.toString())
|
||||
if (size.type == type.toString()) return size
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun getSizeOrSmaller(type: Char): BaseVkPhoto.Size? {
|
||||
val photoStack = sizesChars.clone() as Stack<Char>
|
||||
|
||||
val sizeIndex = photoStack.search(type)
|
||||
|
||||
if (sizeIndex == -1) return null
|
||||
|
||||
for (i in 0 until sizeIndex) {
|
||||
photoStack.pop()
|
||||
}
|
||||
|
||||
for (i in 0 until photoStack.size) {
|
||||
val size = getSizeOrNull(photoStack.peek())
|
||||
|
||||
if (size == null) {
|
||||
photoStack.pop()
|
||||
continue
|
||||
} else {
|
||||
return size
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
@@ -23,7 +23,8 @@ data class BaseVkMessage(
|
||||
val payload: String,
|
||||
val geo: Geo?,
|
||||
val action: Action?,
|
||||
val ttl: Int
|
||||
val ttl: Int,
|
||||
val reply_message: BaseVkMessage?
|
||||
) : Parcelable {
|
||||
|
||||
fun asVkMessage() = VkMessage(
|
||||
@@ -44,6 +45,7 @@ data class BaseVkMessage(
|
||||
).also {
|
||||
it.attachments = VkUtils.parseAttachments(attachments)
|
||||
it.forwards = VkUtils.parseForwards(fwd_messages)
|
||||
it.replyMessage = VkUtils.parseReplyMessage(reply_message)
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
|
||||
@@ -17,6 +17,7 @@ class AuthInterceptor : Interceptor {
|
||||
builder.addQueryParameter("access_token", URLEncoder.encode(it, "utf-8"))
|
||||
}
|
||||
|
||||
// TODO: 9/29/2021 crash on timeout
|
||||
return chain.proceed(chain.request().newBuilder().apply { url(builder.build()) }.build())
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user