Rename variables
parent
8aba3e7e81
commit
7d7a19eb07
|
@ -26,7 +26,7 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
ActivityMainBinding.inflate(layoutInflater)
|
||||
}
|
||||
|
||||
private lateinit var mNativeX: NativeX
|
||||
private lateinit var nativex: NativeX
|
||||
|
||||
private var player: ExoPlayer? = null
|
||||
private var playerUri: Uri? = null
|
||||
|
@ -45,7 +45,7 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
restoreTheme()
|
||||
|
||||
// Initialize services
|
||||
mNativeX = NativeX(this)
|
||||
nativex = NativeX(this)
|
||||
|
||||
// Ensure storage permissions
|
||||
ensureStoragePermissions()
|
||||
|
@ -62,7 +62,7 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
mNativeX.destroy()
|
||||
nativex.destroy()
|
||||
}
|
||||
|
||||
public override fun onResume() {
|
||||
|
@ -120,7 +120,7 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
|
||||
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
||||
return if (request.url.host == "127.0.0.1") {
|
||||
mNativeX.handleRequest(request)
|
||||
nativex.handleRequest(request)
|
||||
} else null
|
||||
}
|
||||
}
|
||||
|
@ -144,26 +144,26 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
webSettings.databaseEnabled = true
|
||||
webSettings.userAgentString = userAgent
|
||||
binding.webview.clearCache(true)
|
||||
binding.webview.addJavascriptInterface(mNativeX, "nativex")
|
||||
binding.webview.addJavascriptInterface(nativex, "nativex")
|
||||
binding.webview.setBackgroundColor(Color.TRANSPARENT)
|
||||
WebView.setWebContentsDebuggingEnabled(true);
|
||||
|
||||
// Welcome page or actual app
|
||||
mNativeX.mAccountService.refreshAuthHeader()
|
||||
nativex.account.refreshAuthHeader()
|
||||
val isApp = loadDefaultUrl()
|
||||
|
||||
// Start version check if loaded account
|
||||
if (isApp) {
|
||||
Thread {
|
||||
mNativeX.mAccountService.checkCredentialsAndVersion()
|
||||
nativex.account.checkCredentialsAndVersion()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun loadDefaultUrl(): Boolean {
|
||||
// Load accounts
|
||||
val authHeader = mNativeX.mAccountService.authHeader
|
||||
val memoriesUrl = mNativeX.mAccountService.memoriesUrl
|
||||
val authHeader = nativex.account.authHeader
|
||||
val memoriesUrl = nativex.account.memoriesUrl
|
||||
|
||||
// Load app interface if authenticated
|
||||
if (authHeader != null && memoriesUrl != null) {
|
||||
|
@ -184,7 +184,7 @@ import gallery.memories.databinding.ActivityMainBinding
|
|||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted: Boolean ->
|
||||
if (isGranted && !hasMediaPermission()) {
|
||||
mNativeX.mQuery.syncFullDb()
|
||||
nativex.query.syncFullDb()
|
||||
}
|
||||
setHasMediaPermission(isGranted)
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ import gallery.memories.service.TimelineQuery
|
|||
import java.io.ByteArrayInputStream
|
||||
import java.net.URLDecoder
|
||||
|
||||
@UnstableApi class NativeX(private val mActivity: MainActivity) {
|
||||
@UnstableApi class NativeX(private val mCtx: MainActivity) {
|
||||
val TAG = "NativeX"
|
||||
|
||||
private var themeStored = false
|
||||
val mImageService = ImageService(mActivity)
|
||||
val mQuery = TimelineQuery(mActivity)
|
||||
val mAccountService = AccountService(mActivity)
|
||||
val image = ImageService(mCtx)
|
||||
val query = TimelineQuery(mCtx)
|
||||
val account = AccountService(mCtx)
|
||||
|
||||
object API {
|
||||
val DAYS = Regex("^/api/days$")
|
||||
|
@ -39,20 +39,20 @@ import java.net.URLDecoder
|
|||
}
|
||||
|
||||
init {
|
||||
mDlService = DownloadService(mActivity)
|
||||
dlService = DownloadService(mCtx)
|
||||
|
||||
// Synchronize the database if possible
|
||||
if (mActivity.hasMediaPermission()) {
|
||||
mQuery.syncDeltaDb()
|
||||
if (mCtx.hasMediaPermission()) {
|
||||
query.syncDeltaDb()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
var mDlService: DownloadService? = null
|
||||
var dlService: DownloadService? = null
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
mDlService = null
|
||||
dlService = null
|
||||
}
|
||||
|
||||
fun handleRequest(request: WebResourceRequest): WebResourceResponse {
|
||||
|
@ -95,20 +95,20 @@ import java.net.URLDecoder
|
|||
|
||||
@JavascriptInterface
|
||||
fun toast(message: String) {
|
||||
mActivity.runOnUiThread {
|
||||
Toast.makeText(mActivity, message, Toast.LENGTH_LONG).show()
|
||||
mCtx.runOnUiThread {
|
||||
Toast.makeText(mCtx, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun login(baseUrl: String?, loginFlowUrl: String?) {
|
||||
if (baseUrl == null || loginFlowUrl == null) return;
|
||||
mAccountService.login(baseUrl, loginFlowUrl)
|
||||
account.login(baseUrl, loginFlowUrl)
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun logout() {
|
||||
mAccountService.loggedOut()
|
||||
account.loggedOut()
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
|
@ -116,25 +116,25 @@ import java.net.URLDecoder
|
|||
// Save for getting it back on next start
|
||||
if (!themeStored) {
|
||||
themeStored = true
|
||||
mActivity.storeTheme(color, isDark);
|
||||
mCtx.storeTheme(color, isDark);
|
||||
}
|
||||
|
||||
// Apply the theme
|
||||
mActivity.runOnUiThread {
|
||||
mActivity.applyTheme(color, isDark)
|
||||
mCtx.runOnUiThread {
|
||||
mCtx.applyTheme(color, isDark)
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun downloadFromUrl(url: String?, filename: String?) {
|
||||
if (url == null || filename == null) return;
|
||||
mDlService!!.queue(url, filename)
|
||||
dlService!!.queue(url, filename)
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun playTouchSound() {
|
||||
mActivity.runOnUiThread {
|
||||
mActivity.binding.webview.playSoundEffect(SoundEffectConstants.CLICK)
|
||||
mCtx.runOnUiThread {
|
||||
mCtx.binding.webview.playSoundEffect(SoundEffectConstants.CLICK)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,13 +144,13 @@ import java.net.URLDecoder
|
|||
|
||||
Thread {
|
||||
// Get URI of local video
|
||||
val videos = SystemImage.getByIds(mActivity, arrayListOf(fileId.toLong()))
|
||||
val videos = SystemImage.getByIds(mCtx, arrayListOf(fileId.toLong()))
|
||||
if (videos.isEmpty()) return@Thread
|
||||
val video = videos[0]
|
||||
|
||||
// Play with exoplayer
|
||||
mActivity.runOnUiThread {
|
||||
mActivity.initializePlayer(video.uri, fileId)
|
||||
mCtx.runOnUiThread {
|
||||
mCtx.initializePlayer(video.uri, fileId)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
@ -158,16 +158,16 @@ import java.net.URLDecoder
|
|||
@JavascriptInterface
|
||||
fun playVideoHls(fileId: String?, url: String?) {
|
||||
if (fileId == null || url == null) return
|
||||
mActivity.runOnUiThread {
|
||||
mActivity.initializePlayer(Uri.parse(url), fileId)
|
||||
mCtx.runOnUiThread {
|
||||
mCtx.initializePlayer(Uri.parse(url), fileId)
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun destroyVideo(fileId: String?) {
|
||||
if (fileId == null) return;
|
||||
mActivity.runOnUiThread {
|
||||
mActivity.destroyPlayer(fileId)
|
||||
mCtx.runOnUiThread {
|
||||
mCtx.destroyPlayer(fileId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,23 +175,23 @@ import java.net.URLDecoder
|
|||
private fun routerGet(path: String): WebResourceResponse {
|
||||
val parts = path.split("/").toTypedArray()
|
||||
if (path.matches(API.IMAGE_PREVIEW)) {
|
||||
return makeResponse(mImageService.getPreview(parts[3].toLong()), "image/jpeg")
|
||||
return makeResponse(image.getPreview(parts[3].toLong()), "image/jpeg")
|
||||
} else if (path.matches(API.IMAGE_FULL)) {
|
||||
return makeResponse(mImageService.getFull(parts[3].toLong()), "image/jpeg")
|
||||
return makeResponse(image.getFull(parts[3].toLong()), "image/jpeg")
|
||||
} else if (path.matches(API.IMAGE_INFO)) {
|
||||
return makeResponse(mQuery.getImageInfo(parts[4].toLong()))
|
||||
return makeResponse(query.getImageInfo(parts[4].toLong()))
|
||||
} else if (path.matches(API.IMAGE_DELETE)) {
|
||||
return makeResponse(mQuery.delete(parseIds(parts[4])))
|
||||
return makeResponse(query.delete(parseIds(parts[4])))
|
||||
} else if (path.matches(API.DAYS)) {
|
||||
return makeResponse(mQuery.getDays())
|
||||
return makeResponse(query.getDays())
|
||||
} else if (path.matches(API.DAY)) {
|
||||
return makeResponse(mQuery.getByDayId(parts[3].toLong()))
|
||||
return makeResponse(query.getByDayId(parts[3].toLong()))
|
||||
} else if (path.matches(API.SHARE_URL)) {
|
||||
return makeResponse(mDlService!!.shareUrl(URLDecoder.decode(parts[4], "UTF-8")))
|
||||
return makeResponse(dlService!!.shareUrl(URLDecoder.decode(parts[4], "UTF-8")))
|
||||
} else if (path.matches(API.SHARE_BLOB)) {
|
||||
return makeResponse(mDlService!!.shareBlobFromUrl(URLDecoder.decode(parts[4], "UTF-8")))
|
||||
return makeResponse(dlService!!.shareBlobFromUrl(URLDecoder.decode(parts[4], "UTF-8")))
|
||||
} else if (path.matches(API.SHARE_LOCAL)) {
|
||||
return makeResponse(mDlService!!.shareLocal(parts[4].toLong()))
|
||||
return makeResponse(dlService!!.shareLocal(parts[4].toLong()))
|
||||
} else {
|
||||
throw Exception("Not Found")
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import okhttp3.Request
|
|||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.json.JSONObject
|
||||
|
||||
@UnstableApi class AccountService(private val mActivity: MainActivity) {
|
||||
@UnstableApi class AccountService(private val mCtx: MainActivity) {
|
||||
companion object {
|
||||
val TAG = "AccountService"
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ import org.json.JSONObject
|
|||
var memoriesUrl: String? = null
|
||||
|
||||
private fun toast(message: String) {
|
||||
mActivity.runOnUiThread {
|
||||
Toast.makeText(mActivity, message, Toast.LENGTH_LONG).show()
|
||||
mCtx.runOnUiThread {
|
||||
Toast.makeText(mCtx, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ import org.json.JSONObject
|
|||
toast("Opening login page...")
|
||||
|
||||
// Open login page in browser
|
||||
mActivity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(loginUrl)))
|
||||
mCtx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(loginUrl)))
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "login: ", e)
|
||||
toast("Failed to parse login flow response")
|
||||
|
@ -75,8 +75,8 @@ import org.json.JSONObject
|
|||
}
|
||||
|
||||
private fun pollLogin(pollUrl: String, pollToken: String, baseUrl: String) {
|
||||
mActivity.binding.webview.post {
|
||||
mActivity.binding.webview.loadUrl("file:///android_asset/waiting.html")
|
||||
mCtx.binding.webview.post {
|
||||
mCtx.binding.webview.loadUrl("file:///android_asset/waiting.html")
|
||||
}
|
||||
|
||||
val client = OkHttpClient()
|
||||
|
@ -111,11 +111,11 @@ import org.json.JSONObject
|
|||
val loginName = json.getString("loginName")
|
||||
val appPassword = json.getString("appPassword")
|
||||
|
||||
mActivity.runOnUiThread {
|
||||
mCtx.runOnUiThread {
|
||||
// Save login info (also updates header)
|
||||
storeCredentials(baseUrl, loginName, appPassword)
|
||||
mActivity.runOnUiThread {
|
||||
mActivity.loadDefaultUrl()
|
||||
mCtx.runOnUiThread {
|
||||
mCtx.loadDefaultUrl()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,12 +142,12 @@ import org.json.JSONObject
|
|||
|
||||
// Could not connect to memories
|
||||
if (response.code == 404) {
|
||||
return toast(mActivity.getString(R.string.err_no_ver))
|
||||
return toast(mCtx.getString(R.string.err_no_ver))
|
||||
}
|
||||
|
||||
// Check body
|
||||
if (body == null || response.code != 200) {
|
||||
toast(mActivity.getString(R.string.err_no_describe))
|
||||
toast(mCtx.getString(R.string.err_no_describe))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -161,22 +161,22 @@ import org.json.JSONObject
|
|||
}
|
||||
|
||||
// Check minimum version
|
||||
if (Version(version) < Version(mActivity.getString(R.string.min_server_version))) {
|
||||
return toast(mActivity.getString(R.string.err_no_ver))
|
||||
if (Version(version) < Version(mCtx.getString(R.string.min_server_version))) {
|
||||
return toast(mCtx.getString(R.string.err_no_ver))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loggedOut() {
|
||||
toast(mActivity.getString(R.string.err_logged_out))
|
||||
toast(mCtx.getString(R.string.err_logged_out))
|
||||
deleteCredentials()
|
||||
mActivity.runOnUiThread {
|
||||
mActivity.loadDefaultUrl()
|
||||
mCtx.runOnUiThread {
|
||||
mCtx.loadDefaultUrl()
|
||||
}
|
||||
}
|
||||
|
||||
fun storeCredentials(url: String, user: String, password: String) {
|
||||
mActivity.getSharedPreferences("credentials", 0).edit()
|
||||
mCtx.getSharedPreferences("credentials", 0).edit()
|
||||
.putString("memoriesUrl", url)
|
||||
.putString("user", user)
|
||||
.putString("password", password)
|
||||
|
@ -186,7 +186,7 @@ import org.json.JSONObject
|
|||
}
|
||||
|
||||
fun getCredentials(): Pair<String, String>? {
|
||||
val prefs = mActivity.getSharedPreferences("credentials", 0)
|
||||
val prefs = mCtx.getSharedPreferences("credentials", 0)
|
||||
memoriesUrl = prefs.getString("memoriesUrl", null)
|
||||
val user = prefs.getString("user", null)
|
||||
val password = prefs.getString("password", null)
|
||||
|
@ -197,7 +197,7 @@ import org.json.JSONObject
|
|||
fun deleteCredentials() {
|
||||
authHeader = null
|
||||
memoriesUrl = null
|
||||
mActivity.getSharedPreferences("credentials", 0).edit()
|
||||
mCtx.getSharedPreferences("credentials", 0).edit()
|
||||
.remove("memoriesUrl")
|
||||
.remove("user")
|
||||
.remove("password")
|
||||
|
|
|
@ -7,6 +7,6 @@ import gallery.memories.NativeX
|
|||
|
||||
class DownloadBroadcastReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
NativeX.mDlService?.runDownloadCallback(intent)
|
||||
NativeX.dlService?.runDownloadCallback(intent)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue