-
Notifications
You must be signed in to change notification settings - Fork 1
Sample for ark-core FileStorage JNI bindings usage
#110
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
cc4e896
2ee8c1b
7337904
eb92dfe
8d9d641
4dd2fa7
af5adf8
38380e9
0ea65b5
69c2fba
8bc704f
b2b330b
2d22945
96e8ce8
bf7accc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,12 +30,16 @@ jobs: | |
| - name: Validate Gradle wrapper | ||
| uses: gradle/[email protected] | ||
|
|
||
|
|
||
| - name: Decrypt the keystore for signing | ||
| run: | | ||
| echo "${{ secrets.KEYSTORE_ENCRYPTED }}" > keystore.asc | ||
| gpg -d --passphrase "${{ secrets.KEYSTORE_PASSWORD }}" --batch keystore.asc > keystore.jks | ||
|
|
||
| - name: Download and extract `ark-core` JNI libs | ||
| run: | | ||
| wget https://github.com/ARK-Builders/ark-core/releases/download/v1.0.0/jniLibs.zip | ||
| unzip -d sample/src/main jniLibs.zip | ||
|
|
||
| - name: Build release sample APK | ||
| run: ./gradlew sample:assembleRelease | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,25 +11,32 @@ import android.view.ViewGroup | |
| import android.view.inputmethod.EditorInfo | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import androidx.fragment.app.DialogFragment | ||
| import dev.arkbuilders.core.FileStorage | ||
| import dev.arkbuilders.sample.R | ||
| import dev.arkbuilders.sample.databinding.FragmentStorageDemoBinding | ||
| import dev.arkbuilders.sample.extension.getAbsolutePath | ||
| import java.io.File | ||
| import java.util.UUID | ||
|
|
||
| class StorageDemoFragment: DialogFragment() { | ||
|
|
||
| private val TAG = StorageDemoFragment::class.java.name | ||
|
|
||
| private lateinit var binding: FragmentStorageDemoBinding | ||
| private val map by lazy { mutableMapOf<String, String>() } | ||
| private var workingDir: String = "/" | ||
| private var storage: FileStorage? = null | ||
oluiscabral marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private val selectDirRequest = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri -> | ||
| uri?.let { | ||
| // call this to persist permission across device reboots | ||
| context?.contentResolver?.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) | ||
| workingDir = uri.getAbsolutePath() | ||
| refreshFilesTree() | ||
| val initialStorageFile = UUID.randomUUID().toString() | ||
| binding.edtStoragePath.setText(initialStorageFile) | ||
| storage = FileStorage(initialStorageFile, | ||
| "$workingDir/$initialStorageFile" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -61,29 +68,39 @@ class StorageDemoFragment: DialogFragment() { | |
|
|
||
| binding.edtStoragePath.setOnEditorActionListener { v, actionId, event -> | ||
| if (actionId == EditorInfo.IME_ACTION_DONE) { | ||
| refreshFilesTree() | ||
| val relativeStoragePath = v.text.toString() | ||
| storage = FileStorage(relativeStoragePath, | ||
| "$workingDir/$relativeStoragePath" | ||
| ) | ||
| binding.tvCurrentAbsolutePath.text = String.format("%s/%s", workingDir, relativeStoragePath) | ||
| return@setOnEditorActionListener true | ||
| } | ||
| false | ||
| } | ||
|
|
||
| binding.btnNewMapEntry.setOnClickListener { | ||
| MapEntryDialog(isDelete = false, onDone = { key, value -> | ||
| map[key] = value ?: "" | ||
| refreshMap() | ||
| if (storage != null) { | ||
| storage!!.set(key, value) | ||
| } | ||
| refreshStorage() | ||
| }).show(parentFragmentManager, MapEntryDialog::class.java.name) | ||
| } | ||
|
|
||
| binding.btnDeleteEntry.setOnClickListener { | ||
| MapEntryDialog(isDelete = true, onDone = { key, value -> | ||
| map.remove(key) | ||
| refreshMap() | ||
| MapEntryDialog(isDelete = true, onDone = { key, _ -> | ||
| if (storage != null) { | ||
| storage!!.remove(key) | ||
| } | ||
| refreshStorage() | ||
| }).show(parentFragmentManager, MapEntryDialog::class.java.name) | ||
| } | ||
|
|
||
| binding.btnClearMap.setOnClickListener { | ||
| map.clear() | ||
| refreshMap() | ||
| if (storage != null) { | ||
| storage!!.erase() | ||
| } | ||
| refreshStorage() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -105,13 +122,14 @@ class StorageDemoFragment: DialogFragment() { | |
| } | ||
| } | ||
|
|
||
| private fun refreshMap() { | ||
| if (map.isEmpty()) { | ||
| private fun refreshStorage() { | ||
| if (storage == null) { | ||
| binding.tvMapValues.text = getString(R.string.empty_map) | ||
| return | ||
| } | ||
| storage!!.writeFS() | ||
|
||
| val mapEntries = StringBuilder() | ||
| for (entry in map) { | ||
| for (entry in storage!!) { | ||
| mapEntries.append(entry.key).append(" -> ").append(entry.value).append("\n") | ||
| } | ||
| binding.tvMapValues.text = mapEntries.toString() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,13 +16,21 @@ dependencyResolutionManagement { | |||||||
| url = URI("https://jitpack.io") | ||||||||
| } | ||||||||
| maven { | ||||||||
| name = "GitHubPackages" | ||||||||
| name = "arklib-android GitHub Packages" | ||||||||
| url = URI("https://maven.pkg.github.com/ARK-Builders/arklib-android") | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use It was just a fat lib when we were prototyping, now we moved to the next level with modular framework 😁
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I don't know if I understood it correctly. This is indeed a reference to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I didn't notice the link leads to the archived repo. We certainly should not use archived repos.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But what do we use from
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kirillt It's being used in at least 23 places, just search for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks guys, I wasn't realizing it.. I'll come up with plan for the upgrade later. |
||||||||
| credentials { | ||||||||
| username = "token" | ||||||||
| password = "\u0037\u0066\u0066\u0036\u0030\u0039\u0033\u0066\u0032\u0037\u0033\u0036\u0033\u0037\u0064\u0036\u0037\u0066\u0038\u0030\u0034\u0039\u0062\u0030\u0039\u0038\u0039\u0038\u0066\u0034\u0066\u0034\u0031\u0064\u0062\u0033\u0064\u0033\u0038\u0065" | ||||||||
| } | ||||||||
| } | ||||||||
| maven { | ||||||||
| name = "ark-core GitHub Packages" | ||||||||
| url = URI("https://maven.pkg.github.com/ARK-Builders/ark-core") | ||||||||
| credentials { | ||||||||
| username = "token" | ||||||||
| password = "\u0037\u0066\u0066\u0036\u0030\u0039\u0033\u0066\u0032\u0037\u0033\u0036\u0033\u0037\u0064\u0036\u0037\u0066\u0038\u0030\u0034\u0039\u0062\u0030\u0039\u0038\u0039\u0038\u0066\u0034\u0066\u0034\u0031\u0064\u0062\u0033\u0064\u0033\u0038\u0065" | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| versionCatalogs { | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for suddenly jumping into this, but I think
implementation(libraries.core)is enough. In theory we don't have to manually download the JNI libs like this because it's already included in the synced dependency ofarkcore.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just repeating what we later discussed:
implementation(libraries.core)is not currently enough, sinceark-core/javais a JAR, that means JNI libs are not available for use from it. However, I'm working on transformingark-core/javainto an AAR instead (to make JNI libs available directly from the package)