pull/653/merge
Varun Patil 2023-10-01 19:26:11 -07:00
parent a612b02dfa
commit 0eee69bacb
2 changed files with 58 additions and 43 deletions

View File

@ -5,6 +5,7 @@ import android.net.Uri
import android.util.Base64 import android.util.Base64
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.media3.common.util.UnstableApi
import gallery.memories.MainActivity import gallery.memories.MainActivity
import gallery.memories.R import gallery.memories.R
import io.github.g00fy2.versioncompare.Version import io.github.g00fy2.versioncompare.Version
@ -16,6 +17,7 @@ import okhttp3.Response
import org.json.JSONObject import org.json.JSONObject
import java.net.SocketTimeoutException import java.net.SocketTimeoutException
@UnstableApi
class AccountService(private val mCtx: MainActivity) { class AccountService(private val mCtx: MainActivity) {
companion object { companion object {
val TAG = AccountService::class.java.simpleName val TAG = AccountService::class.java.simpleName
@ -140,53 +142,53 @@ class AccountService(private val mCtx: MainActivity) {
} }
fun checkCredentialsAndVersion() { fun checkCredentialsAndVersion() {
memoriesUrl.let { base -> if (memoriesUrl == null) return
val request = Request.Builder()
.url(base + "api/describe")
.get()
.header("Authorization", authHeader ?: "")
.build()
val response: Response val request = Request.Builder()
try { .url(memoriesUrl + "api/describe")
response = OkHttpClient().newCall(request).execute() .get()
} catch (e: Exception) { .header("Authorization", authHeader ?: "")
Log.w(TAG, "checkCredentialsAndVersion: ", e) .build()
return
}
val body = response.body?.string() val response: Response
response.body?.close() try {
response = OkHttpClient().newCall(request).execute()
} catch (e: Exception) {
Log.w(TAG, "checkCredentialsAndVersion: ", e)
return
}
// Check status code val body = response.body?.string()
if (response.code == 401) { response.body?.close()
return loggedOut()
}
// Could not connect to memories // Check status code
if (response.code == 404) { if (response.code == 401) {
return toast(mCtx.getString(R.string.err_no_ver)) return loggedOut()
} }
// Check body // Could not connect to memories
if (body == null || response.code != 200) { if (response.code == 404) {
toast(mCtx.getString(R.string.err_no_describe)) return toast(mCtx.getString(R.string.err_no_ver))
return }
}
val json = JSONObject(body) // Check body
val version = json.getString("version") if (body == null || response.code != 200) {
val uid = json.get("uid") toast(mCtx.getString(R.string.err_no_describe))
return
}
// Check UID exists val json = JSONObject(body)
if (uid.equals(null) && authHeader != null) { val version = json.getString("version")
return loggedOut() val uid = json.get("uid")
}
// Check minimum version // Check UID exists
if (Version(version) < Version(mCtx.getString(R.string.min_server_version))) { if (uid.equals(null) && authHeader != null) {
return toast(mCtx.getString(R.string.err_no_ver)) return loggedOut()
} }
// Check minimum version
if (Version(version) < Version(mCtx.getString(R.string.min_server_version))) {
return toast(mCtx.getString(R.string.err_no_ver))
} }
} }

View File

@ -26,7 +26,8 @@ import java.io.IOException
import java.time.Instant import java.time.Instant
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
@UnstableApi class TimelineQuery(private val mCtx: MainActivity) { @UnstableApi
class TimelineQuery(private val mCtx: MainActivity) {
private val TAG = TimelineQuery::class.java.simpleName private val TAG = TimelineQuery::class.java.simpleName
private val mConfigService = ConfigService(mCtx) private val mConfigService = ConfigService(mCtx)
@ -228,7 +229,7 @@ import java.util.concurrent.CountDownLatch
} }
// Delete from database // Delete from database
mPhotoDao.deleteFileIds(sysImgs.map { it.fileId}) mPhotoDao.deleteFileIds(sysImgs.map { it.fileId })
} finally { } finally {
synchronized(this) { deleting = false } synchronized(this) { deleting = false }
} }
@ -254,13 +255,25 @@ import java.util.concurrent.CountDownLatch
var updates = 0 var updates = 0
// Iterate all images from system store // Iterate all images from system store
for (image in SystemImage.cursor(mCtx, SystemImage.IMAGE_URI, selection, selectionArgs, null)) { for (image in SystemImage.cursor(
mCtx,
SystemImage.IMAGE_URI,
selection,
selectionArgs,
null
)) {
insertItemDb(image) insertItemDb(image)
updates++ updates++
} }
// Iterate all videos from system store // Iterate all videos from system store
for (video in SystemImage.cursor(mCtx, SystemImage.VIDEO_URI, selection, selectionArgs, null)) { for (video in SystemImage.cursor(
mCtx,
SystemImage.VIDEO_URI,
selection,
selectionArgs,
null
)) {
insertItemDb(video) insertItemDb(video)
updates++ updates++
} }