mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: share settings
This commit is contained in:
parent
5838550188
commit
2a89ef797f
@ -54,5 +54,10 @@
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
<provider
|
||||
android:name=".utils.share.ShareProvider"
|
||||
android:authorities="app.revanced.manager.flutter.provider"
|
||||
android:exported="true">
|
||||
</provider>
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -27,6 +27,13 @@ import java.io.StringWriter
|
||||
import java.util.logging.LogRecord
|
||||
import java.util.logging.Logger
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
|
||||
import android.util.Log
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private lateinit var installerChannel: MethodChannel
|
||||
@ -39,6 +46,21 @@ class MainActivity : FlutterActivity() {
|
||||
val patcherChannel = "app.revanced.manager.flutter/patcher"
|
||||
val installerChannel = "app.revanced.manager.flutter/installer"
|
||||
|
||||
val contentProviderUri = Uri.parse("content://app.revanced.manager.flutter.provider/settings")
|
||||
val contentResolver: ContentResolver = context.contentResolver
|
||||
val cursor: Cursor? = contentResolver.query(contentProviderUri, null, null, null, null)
|
||||
|
||||
Log.d("app.revanced.manager.flutter.debug", "byhithere")
|
||||
if (cursor != null) {
|
||||
Log.d("app.revanced.manager.flutter.debug", "test2")
|
||||
if (cursor.moveToFirst()) {
|
||||
val helloValue = cursor.getString(cursor.getColumnIndex("settings"))
|
||||
// Process the retrieved "hello" value
|
||||
Log.d("testing2", helloValue)
|
||||
}
|
||||
cursor.close()
|
||||
}
|
||||
|
||||
val mainChannel =
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, patcherChannel)
|
||||
|
||||
|
@ -0,0 +1,80 @@
|
||||
package app.revanced.manager.flutter.utils.share
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.UriMatcher
|
||||
import android.database.Cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.net.Uri
|
||||
import org.json.JSONObject
|
||||
|
||||
import android.util.Log
|
||||
|
||||
class ShareProvider : ContentProvider() {
|
||||
private val authority = "app.revanced.manager.flutter.provider"
|
||||
private val URI_CODE_SETTINGS = 1
|
||||
|
||||
private val uriMatcher = UriMatcher(UriMatcher.NO_MATCH).apply {
|
||||
addURI(authority, "settings", URI_CODE_SETTINGS)
|
||||
}
|
||||
|
||||
override fun onCreate(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
fun getSettings(): String {
|
||||
val json = JSONObject()
|
||||
|
||||
// Default Data
|
||||
|
||||
// TODO: load default data
|
||||
|
||||
// Load Shared Preferences
|
||||
val sharedPreferences = context!!.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
|
||||
val allEntries: Map<String, *> = sharedPreferences.getAll()
|
||||
for ((key, value) in allEntries.entries) {
|
||||
Log.d("map values", key + ": " + value.toString())
|
||||
json.put(key.replace("flutter.", ""), value)
|
||||
}
|
||||
|
||||
// TODO: Load keystore
|
||||
|
||||
return json.toString()
|
||||
}
|
||||
|
||||
override fun query(
|
||||
uri: Uri,
|
||||
projection: Array<out String>?,
|
||||
selection: String?,
|
||||
selectionArgs: Array<out String>?,
|
||||
sortOrder: String?
|
||||
):Cursor? {
|
||||
when (uriMatcher.match(uri)) {
|
||||
URI_CODE_SETTINGS -> {
|
||||
val cursor = MatrixCursor(arrayOf("settings"))
|
||||
val row = arrayOf(getSettings())
|
||||
cursor.addRow(row)
|
||||
return cursor
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unknown URI: $uri")
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? {
|
||||
throw UnsupportedOperationException("Insert operation is not supported")
|
||||
}
|
||||
|
||||
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int {
|
||||
throw UnsupportedOperationException("Update operation is not supported")
|
||||
}
|
||||
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
|
||||
throw UnsupportedOperationException("Delete operation is not supported")
|
||||
}
|
||||
|
||||
override fun getType(uri: Uri): String? {
|
||||
throw UnsupportedOperationException("Get type operation is not supported")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user