Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Sync via SyncManager #632

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b5c15d1
implement SAF as SaveSyncManagerImpl target
newhinton Apr 9, 2023
419b954
copy non existent files
newhinton Apr 9, 2023
c43379e
copy outdated saves
newhinton Apr 9, 2023
c66d94c
overhaul permissions request
newhinton Apr 9, 2023
388be20
directly use provided folder
newhinton Apr 9, 2023
9089494
create missing internal folder if required
newhinton Apr 9, 2023
3f8e3e4
fix timestamps of copied files to prevent unnessessary copying
newhinton Apr 9, 2023
8cf3c39
update error handling for selecting path
newhinton Apr 10, 2023
2ce2df9
Split checks into functions
newhinton Apr 10, 2023
80a05db
Refactor and document code
newhinton Apr 10, 2023
40aead7
refactor and improve logging
newhinton Apr 10, 2023
614fd67
compute remote space usage
newhinton Apr 10, 2023
0009111
add newline to satisfy lint
newhinton Apr 13, 2023
95ae1ee
migrate dependencies out of build.gradle.kts
newhinton Apr 20, 2023
d8a456f
improve naming
newhinton Apr 20, 2023
01e7a41
allow folders to be synced recursive to SAF
newhinton May 7, 2023
5c99775
allow folders to be synced recursive from SAF
newhinton May 7, 2023
8e6cf87
also support states
newhinton May 7, 2023
4d4e6db
add intents to persist uris
newhinton May 16, 2023
0eb24e1
calculate saved space for cores properly
newhinton May 16, 2023
95c508d
catch exception for size calculation when sync is not set up
newhinton Jun 10, 2023
c3b47bf
properly persist uri
newhinton Jun 10, 2023
081b443
Merge remote-tracking branch 'newhinton/feature/noid/savemanagerimpl'…
newhinton Jun 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lemuroid-app-ext-free/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ dependencies {

implementation(deps.libs.retrofit)
implementation(deps.libs.kotlinxCoroutinesAndroid)
implementation(deps.libs.androidx.appcompat.appcompat)
implementation(deps.libs.androidx.appcompat.constraintLayout)
implementation(deps.libs.material)
implementation("androidx.documentfile:documentfile:1.0.1")
}
9 changes: 7 additions & 2 deletions lemuroid-app-ext-free/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<manifest package="com.swordfish.lemuroid.ext"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingLeanbackLauncher">
package="com.swordfish.lemuroid.ext"
tools:ignore="MissingLeanbackLauncher,ImpliedTouchscreenHardware,MissingLeanbackSupport">

<application>
<activity android:name="com.swordfish.lemuroid.ext.feature.savesync.ActivateSAFActivity"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.swordfish.lemuroid.ext.feature.savesync

import android.app.Activity
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import com.swordfish.lemuroid.ext.R
import com.swordfish.lemuroid.lib.preferences.SharedPreferencesHelper

class ActivateSAFActivity : AppCompatActivity() {
newhinton marked this conversation as resolved.
Show resolved Hide resolved

companion object {
const val PREF_KEY_STORAGE_URI_NONE = ""
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_activate_safactivity)

openPicker()
}

private fun openPicker() {


val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
this.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
this.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
this.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
this.putExtra(Intent.EXTRA_LOCAL_ONLY, false)
}

val resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
when (result.resultCode) {
Activity.RESULT_OK -> {
val targetUri = result?.data?.data

if (targetUri != null ) {
setStorageUri(targetUri.toString())
updatePersistableUris(targetUri)
}
finish()
}
else -> {
Toast.makeText(this, getString(R.string.saf_save_sync_no_uri_selected), Toast.LENGTH_LONG).show()
setStorageUri(PREF_KEY_STORAGE_URI_NONE)
finish()
}
}
}

resultLauncher.launch(intent)
}

private fun setStorageUri(uri: String) {
val sharedPreferences = SharedPreferencesHelper.getSharedPreferences(this).edit()
val preferenceKey = getString(R.string.pref_key_saf_uri)
sharedPreferences.putString(preferenceKey, uri)
sharedPreferences.apply()
}

private fun updatePersistableUris(uri: Uri) {
val contentResolver = applicationContext.contentResolver

val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION

contentResolver.takePersistableUriPermission(uri, takeFlags)
}

}


Loading