Skip to content

Commit

Permalink
20
Browse files Browse the repository at this point in the history
20
  • Loading branch information
umerov1999 committed Apr 10, 2023
1 parent 8da0f5a commit 5d538ee
Show file tree
Hide file tree
Showing 56 changed files with 712 additions and 415 deletions.
4 changes: 2 additions & 2 deletions app_fenrir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp-android:$okhttpLibraryVersion")
//implementation("com.squareup.okhttp3:logging-interceptor:$okhttpLibraryVersion")
implementation("com.squareup.okio:okio:$okioVersion")
implementation("com.google.android.exoplayer:exoplayer-core:$exoLibraryVersion")
implementation("com.google.android.exoplayer:exoplayer-hls:$exoLibraryVersion")
implementation("androidx.constraintlayout:constraintlayout:$constraintlayoutVersion")
implementation("androidx.biometric:biometric-ktx:$biometricVersion")
implementation("androidx.media:media:$mediaVersion")
implementation("androidx.media3:media3-exoplayer:$media3Version")
implementation("androidx.media3:media3-exoplayer-hls:$media3Version")
implementation("androidx.coordinatorlayout:coordinatorlayout:$coordinatorlayoutVersion")
implementation("androidx.activity:activity-ktx:$activityVersion")
implementation("androidx.fragment:fragment-ktx:$fragmentVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dev.ragnarok.fenrir.db.model.entity

import androidx.annotation.Keep
import kotlinx.serialization.Serializable

@Keep
@Serializable
class DialogDboEntity(val peerId: Long) : DboEntity() {
var title: String? = null
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class MessagesRepository(
})
}

private fun onUpdloadSuccess(upload: Upload) {
private fun onUploadSuccess(upload: Upload) {
val accountId = upload.accountId
val messagesId = upload.destination.id
compositeDisposable.add(uploadManager[accountId, upload.destination]
Expand Down Expand Up @@ -1774,7 +1774,7 @@ class MessagesRepository(
uploadManager.observeResults()
.filter { it.first.destination.method == Method.TO_MESSAGE }
.subscribe({ result ->
onUpdloadSuccess(
onUploadSuccess(
result.first
)
}, ignore())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import dev.ragnarok.fenrir.api.model.response.BaseResponse
import dev.ragnarok.fenrir.api.rest.HttpException
import dev.ragnarok.fenrir.api.util.VKStringUtils
import dev.ragnarok.fenrir.db.DBHelper
import dev.ragnarok.fenrir.db.model.entity.DialogDboEntity
import dev.ragnarok.fenrir.domain.IAccountsInteractor
import dev.ragnarok.fenrir.domain.IOwnersRepository
import dev.ragnarok.fenrir.domain.InteractorFactory
Expand All @@ -37,6 +38,7 @@ import dev.ragnarok.fenrir.model.Account
import dev.ragnarok.fenrir.model.IOwnersBundle
import dev.ragnarok.fenrir.model.SaveAccount
import dev.ragnarok.fenrir.model.User
import dev.ragnarok.fenrir.model.criteria.DialogsCriteria
import dev.ragnarok.fenrir.nonNullNoEmpty
import dev.ragnarok.fenrir.nonNullNoEmptyOr
import dev.ragnarok.fenrir.requireNonNull
Expand All @@ -53,15 +55,18 @@ import dev.ragnarok.fenrir.util.serializeble.json.JsonObjectBuilder
import dev.ragnarok.fenrir.util.serializeble.json.contentOrNull
import dev.ragnarok.fenrir.util.serializeble.json.decodeFromStream
import dev.ragnarok.fenrir.util.serializeble.json.intOrNull
import dev.ragnarok.fenrir.util.serializeble.json.jsonArray
import dev.ragnarok.fenrir.util.serializeble.json.jsonObject
import dev.ragnarok.fenrir.util.serializeble.json.jsonPrimitive
import dev.ragnarok.fenrir.util.serializeble.json.long
import dev.ragnarok.fenrir.util.serializeble.json.longOrNull
import dev.ragnarok.fenrir.util.serializeble.json.put
import dev.ragnarok.fenrir.util.serializeble.msgpack.MsgPack
import dev.ragnarok.fenrir.util.toast.CustomToast
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.core.SingleEmitter
import io.reactivex.rxjava3.exceptions.Exceptions
import kotlinx.serialization.builtins.ListSerializer
import okhttp3.FormBody
import okhttp3.Request
import okhttp3.Response
Expand Down Expand Up @@ -495,6 +500,26 @@ class AccountsPresenter(savedInstanceState: Bundle?) :
R.string.need_restart
)
}
try {
if (obj.has("conversations_saved")) {
for (i in obj["conversations_saved"]?.asJsonArray.orEmpty()) {
val aid = i.asJsonObject["account_id"]?.jsonPrimitive?.long ?: continue
val dialogsJsonElem =
i.asJsonObject["conversation"]?.jsonArray ?: continue
if (!dialogsJsonElem.isEmpty()) {
Includes.stores.dialogs().insertDialogs(
aid, kJson.decodeFromJsonElement(
ListSerializer(
DialogDboEntity.serializer()
), dialogsJsonElem
), true
).blockingAwait()
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
view?.customToast?.showToast(
R.string.accounts_restored,
Expand Down Expand Up @@ -533,7 +558,8 @@ class AccountsPresenter(savedInstanceState: Bundle?) :
try {
val root = JsonObjectBuilder()
val arr = JsonArrayBuilder()
for (i in Settings.get().accounts().registered) {
val registered = Settings.get().accounts().registered
for (i in registered) {
val temp = JsonObjectBuilder()
val owner = Users?.getById(i)
temp.put("user_name", owner?.fullName)
Expand All @@ -560,6 +586,33 @@ class AccountsPresenter(savedInstanceState: Bundle?) :
root.put("fenrir_accounts", arr.build())
val settings = SettingsBackup().doBackup()
root.put("settings", settings)

val arrDialogs = JsonArrayBuilder()
for (i in registered) {
if (Utils.isHiddenAccount(i)) {
try {
val dialogs =
Includes.stores.dialogs().getDialogs(DialogsCriteria(i)).blockingGet()
val tmp = JsonObjectBuilder()
tmp.put(
"account_id", i
)
tmp.put(
"conversation", kJson.encodeToJsonElement(
ListSerializer(
DialogDboEntity.serializer()
), dialogs
)
)
arrDialogs.add(
tmp.build()
)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
root.put("conversations_saved", arrDialogs.build())
val bytes = Json { prettyPrint = true }.printJsonElement(root.build()).toByteArray(
Charsets.UTF_8
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class DialogsFragment : BaseMvpFragment<DialogsPresenter, IDialogsView>(), IDial
})
mSwipeRefreshLayout = root.findViewById(R.id.swipeRefreshLayout)
mSwipeRefreshLayout?.setOnRefreshListener {
presenter?.fireRefresh()
presenter?.fireRefreshConfirmationHidden()
}
setupSwipeRefreshLayoutWithCurrentTheme(requireActivity(), mSwipeRefreshLayout)
mAdapter = DialogsAdapter(requireActivity(), emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ class DialogsPresenter(
requestAtLast()
}

fun fireRefreshConfirmationHidden() {
if (isHiddenAccount(accountId)) {
resolveRefreshingView()
view?.askToReload()
} else {
fireRefresh()
}
}

fun fireSearchClick() {
assertPositive(dialogsOwnerId)
view?.goToSearch(accountId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.ragnarok.fenrir.media.exo

import com.google.android.exoplayer2.ExoPlayer
import androidx.media3.exoplayer.ExoPlayer

object ExoUtil {
fun pausePlayer(player: ExoPlayer?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package dev.ragnarok.fenrir.media.exo

import android.net.Uri
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlayerLibraryInfo
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.upstream.*
import com.google.android.exoplayer2.upstream.HttpDataSource.*
import com.google.android.exoplayer2.util.Assertions
import com.google.android.exoplayer2.util.Util
import androidx.media3.common.C
import androidx.media3.common.MediaLibraryInfo
import androidx.media3.common.PlaybackException
import androidx.media3.common.util.Assertions
import androidx.media3.common.util.Util
import androidx.media3.datasource.BaseDataSource
import androidx.media3.datasource.DataSourceException
import androidx.media3.datasource.DataSpec
import androidx.media3.datasource.HttpDataSource
import androidx.media3.datasource.HttpUtil
import androidx.media3.datasource.TransferListener
import com.google.common.base.Predicate
import com.google.common.net.HttpHeaders
import com.google.common.util.concurrent.SettableFuture
Expand All @@ -28,24 +32,25 @@ import java.util.concurrent.ExecutionException
* priority) the `dataSpec`, [.setRequestProperty] and the default parameters used to
* construct the instance.
*/
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class OkHttpDataSource internal constructor(
callFactory: OkHttpClient,
userAgent: String?,
cacheControl: CacheControl?,
defaultRequestProperties: RequestProperties?,
defaultRequestProperties: HttpDataSource.RequestProperties?,
contentTypePredicate: Predicate<String>?
) : BaseDataSource( /* isNetwork = */true), HttpDataSource {
companion object {
init {
ExoPlayerLibraryInfo.registerModule("goog.exo.okhttp")
MediaLibraryInfo.registerModule("media3.datasource.okhttp")
}
}

private val callFactory: OkHttpClient
private val requestProperties: RequestProperties
private val requestProperties: HttpDataSource.RequestProperties
private val userAgent: String?
private val cacheControl: CacheControl?
private val defaultRequestProperties: RequestProperties?
private val defaultRequestProperties: HttpDataSource.RequestProperties?
private val contentTypePredicate: Predicate<String>?
private var dataSpec: DataSpec? = null
private var response: Response? = null
Expand Down Expand Up @@ -80,7 +85,7 @@ class OkHttpDataSource internal constructor(
requestProperties.clear()
}

@Throws(HttpDataSourceException::class)
@Throws(HttpDataSource.HttpDataSourceException::class)
override fun open(dataSpec: DataSpec): Long {
this.dataSpec = dataSpec
bytesRead = 0
Expand All @@ -96,8 +101,8 @@ class OkHttpDataSource internal constructor(
responseBody = response?.body ?: return -1
responseByteStream = responseBody.byteStream()
} catch (e: IOException) {
throw HttpDataSourceException.createForIOException(
e, dataSpec, HttpDataSourceException.TYPE_OPEN
throw HttpDataSource.HttpDataSourceException.createForIOException(
e, dataSpec, HttpDataSource.HttpDataSourceException.TYPE_OPEN
)
}
val responseCode = response.code
Expand All @@ -123,7 +128,7 @@ class OkHttpDataSource internal constructor(
closeConnectionQuietly()
val cause: IOException? =
if (responseCode == 416) DataSourceException(PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE) else null
throw InvalidResponseCodeException(
throw HttpDataSource.InvalidResponseCodeException(
responseCode, response.message, cause, headers, dataSpec, errorResponseBody
)
}
Expand All @@ -133,7 +138,7 @@ class OkHttpDataSource internal constructor(
val contentType = mediaType?.toString() ?: ""
if (contentTypePredicate != null && !contentTypePredicate.apply(contentType)) {
closeConnectionQuietly()
throw InvalidContentTypeException(contentType, dataSpec)
throw HttpDataSource.InvalidContentTypeException(contentType, dataSpec)
}

// If we requested a range starting from a non-zero position and received a 200 rather than a
Expand All @@ -153,20 +158,20 @@ class OkHttpDataSource internal constructor(
transferStarted(dataSpec)
try {
skipFully(bytesToSkip, dataSpec)
} catch (e: HttpDataSourceException) {
} catch (e: HttpDataSource.HttpDataSourceException) {
closeConnectionQuietly()
throw e
}
return bytesToRead
}

@Throws(HttpDataSourceException::class)
@Throws(HttpDataSource.HttpDataSourceException::class)
override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
return try {
readInternal(buffer, offset, length)
} catch (e: IOException) {
throw HttpDataSourceException.createForIOException(
e, Util.castNonNull(dataSpec), HttpDataSourceException.TYPE_READ
throw HttpDataSource.HttpDataSourceException.createForIOException(
e, Util.castNonNull(dataSpec), HttpDataSource.HttpDataSourceException.TYPE_READ
)
}
}
Expand All @@ -182,16 +187,16 @@ class OkHttpDataSource internal constructor(
/**
* Establishes a connection.
*/
@Throws(HttpDataSourceException::class)
@Throws(HttpDataSource.HttpDataSourceException::class)
private fun makeRequest(dataSpec: DataSpec): Request {
val position = dataSpec.position
val length = dataSpec.length
val url = dataSpec.uri.toString().toHttpUrlOrNull()
?: throw HttpDataSourceException(
?: throw HttpDataSource.HttpDataSourceException(
"Malformed URL",
dataSpec,
PlaybackException.ERROR_CODE_FAILED_RUNTIME_CHECK,
HttpDataSourceException.TYPE_OPEN
HttpDataSource.HttpDataSourceException.TYPE_OPEN
)
val builder: Request.Builder = Request.Builder().url(url)
if (cacheControl != null) {
Expand Down Expand Up @@ -259,11 +264,11 @@ class OkHttpDataSource internal constructor(
*
* @param bytesToSkipLong The number of bytes to skip.
* @param dataSpec The [DataSpec].
* @throws HttpDataSourceException If the thread is interrupted during the operation, or an error
* @throws HttpDataSource.HttpDataSourceException If the thread is interrupted during the operation, or an error
* occurs while reading from the source, or if the data ended before skipping the specified
* number of bytes.
*/
@Throws(HttpDataSourceException::class)
@Throws(HttpDataSource.HttpDataSourceException::class)
private fun skipFully(bytesToSkipLong: Long, dataSpec: DataSpec) {
var bytesToSkip = bytesToSkipLong
if (bytesToSkip == 0L) {
Expand All @@ -278,23 +283,23 @@ class OkHttpDataSource internal constructor(
throw InterruptedIOException()
}
if (read == -1) {
throw HttpDataSourceException(
throw HttpDataSource.HttpDataSourceException(
dataSpec,
PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
HttpDataSourceException.TYPE_OPEN
HttpDataSource.HttpDataSourceException.TYPE_OPEN
)
}
bytesToSkip -= read.toLong()
bytesTransferred(read)
}
} catch (e: IOException) {
if (e is HttpDataSourceException) {
if (e is HttpDataSource.HttpDataSourceException) {
throw e
} else {
throw HttpDataSourceException(
throw HttpDataSource.HttpDataSourceException(
dataSpec,
PlaybackException.ERROR_CODE_IO_UNSPECIFIED,
HttpDataSourceException.TYPE_OPEN
HttpDataSource.HttpDataSourceException.TYPE_OPEN
)
}
}
Expand Down Expand Up @@ -349,10 +354,11 @@ class OkHttpDataSource internal constructor(
}

/**
* [DataSource.Factory] for [OkHttpDataSource] instances.
* [androidx.media3.datasource.DataSource.Factory] for [OkHttpDataSource] instances.
*/
class Factory(private val callFactory: OkHttpClient) : HttpDataSource.Factory {
private val defaultRequestProperties: RequestProperties = RequestProperties()
private val defaultRequestProperties: HttpDataSource.RequestProperties =
HttpDataSource.RequestProperties()
private var userAgent: String? = null
private var transferListener: TransferListener? = null
private var cacheControl: CacheControl? = null
Expand Down Expand Up @@ -419,7 +425,7 @@ class OkHttpDataSource internal constructor(
* The default is `null`.
*
*
* See [DataSource.addTransferListener].
* See [androidx.media3.datasource.DataSource.addTransferListener].
*
* @param transferListener The listener that will be used.
* @return This factory.
Expand All @@ -446,6 +452,6 @@ class OkHttpDataSource internal constructor(
this.cacheControl = cacheControl
this.defaultRequestProperties = defaultRequestProperties
this.contentTypePredicate = contentTypePredicate
requestProperties = RequestProperties()
requestProperties = HttpDataSource.RequestProperties()
}
}
}
Loading

0 comments on commit 5d538ee

Please sign in to comment.