From 482102e7ebe7cca0db5dbebcc9fcc9c86dfbe2fb Mon Sep 17 00:00:00 2001 From: AhsanSarwar45 Date: Sun, 8 Sep 2024 23:19:49 +0500 Subject: [PATCH] Fix database --- .../kotlin/com/vicolo/chrono/MainActivity.kt | 138 ++++-------------- assets/timezones.db | Bin 397312 -> 397312 bytes 2 files changed, 27 insertions(+), 111 deletions(-) diff --git a/android/app/src/main/kotlin/com/vicolo/chrono/MainActivity.kt b/android/app/src/main/kotlin/com/vicolo/chrono/MainActivity.kt index ec29168e..b1a86021 100644 --- a/android/app/src/main/kotlin/com/vicolo/chrono/MainActivity.kt +++ b/android/app/src/main/kotlin/com/vicolo/chrono/MainActivity.kt @@ -1,123 +1,39 @@ package com.vicolo.chrono -import android.app.Activity +import android.content.Context import android.content.Intent -import android.net.Uri -import androidx.documentfile.provider.DocumentFile +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result +import io.flutter.plugin.common.PluginRegistry.Registrar +import java.util.ArrayList +import androidx.annotation.NonNull import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine -import io.flutter.plugin.common.MethodChannel - -class MainActivity : FlutterActivity() { - private val channel = "com.vicolo.chrono/documents" - private lateinit var result: MethodChannel.Result - - override fun configureFlutterEngine(flutterEngine: FlutterEngine) { - super.configureFlutterEngine(flutterEngine) - MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel) - .setMethodCallHandler { call, result -> - when (call.method) { - "getDirectoryPath" -> { - this.result = result - val intent = Intent(this, DirectoryPickerActivity::class.java) - startActivityForResult(intent, PICK_DIRECTORY_REQUEST_CODE) - } - "listDirectories" -> { - val uriString = call.argument("uri")!! - val uri = Uri.parse(uriString) - val directories = listDirectories(uri) - result.success(directories) - } - "listFiles" -> { - val uriString = call.argument("uri")!! - val uri = Uri.parse(uriString) - val files = listFiles(uri) - result.success(files) - } - "getFileChunk" -> { - val uriString = call.argument("uri")!! - val offset = call.argument("offset")!! - val chunkSize = call.argument("chunkSize")!! - val uri = Uri.parse(uriString) - val chunk = readFileChunk(uri, offset, chunkSize) - if (chunk != null) { - result.success(chunk) - } else { - result.error("READ_ERROR", "Failed to read file chunk", null) - } - } - else -> result.notImplemented() - } - } - } +import io.flutter.plugins.GeneratedPluginRegistrant; - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (requestCode == PICK_DIRECTORY_REQUEST_CODE && resultCode == Activity.RESULT_OK) { - val pickedDirectoryUri = data?.getStringExtra("getDirectoryUri") - if (pickedDirectoryUri != null) { - result.success(pickedDirectoryUri) - } else { - result.error("NO_DIRECTORY_URI", "No directory URI found", null) - } - } - } - private fun listDirectories(uri: Uri): List { - val directory = DocumentFile.fromTreeUri(this, uri) - val directories = mutableListOf() - if (directory != null && directory.isDirectory) { - for (item in directory.listFiles()) { - if (item.isDirectory) { - directories.add(item.uri.toString()) - } - } - } +class MainActivity: FlutterActivity() { + private val CHANNEL = "com.vicolo.chrono/alarm" + + // // create static method channel + // companion object { + // lateinit var channel: MethodChannel + // } - return directories - } + // override fun onCreate(savedInstanceState: Bundle?) { + // super.onCreate(savedInstanceState) + // // MethodChannelHolder.init(flutterView) + // // MethodChannelHolder.invokeMethod("onBoot") + // } - private fun listFiles(uri: Uri): List> { - val directory = DocumentFile.fromTreeUri(this, uri) - val files = mutableListOf>() - - if (directory != null && directory.isDirectory) { - for (item in directory.listFiles()) { - if (item.isFile) { - val fileInfo: Map = mapOf( - "uri" to item.uri.toString(), - "name" to (item.name ?: "Unknown"), - "size" to item.length(), - "modified" to item.lastModified() - ) - files.add(fileInfo) - } - } - } - - return files - } - - private fun readFileChunk(uri: Uri, offset: Int, chunkSize: Int): ByteArray? { - return try { - contentResolver.openInputStream(uri)?.use { inputStream -> - inputStream.skip(offset.toLong()) - val buffer = ByteArray(chunkSize) - val bytesRead = inputStream.read(buffer, 0, chunkSize) - if (bytesRead != -1) { - buffer.copyOf(bytesRead) - } else { - null - } - } - } catch (e: Exception) { - e.printStackTrace() - null - } - } - - companion object { - const val PICK_DIRECTORY_REQUEST_CODE = 1 + override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + // GeneratedPluginRegistrant.registerWith(flutterEngine) + // flutterEngine.plugins.add(InitiateCallsToDartInBgPlugin()) + } } diff --git a/assets/timezones.db b/assets/timezones.db index cdb2ee337f2d7860b996de5c60d75202a881e6ef..1ae1ea1590e34c2349ab8d5afda50f94b99e9380 100644 GIT binary patch delta 654 zcmZozAknZuVuCay^F$eEer5)}vTj}m1_nm{i46P`Hx?@JZ|>tSKET9NHktW?31ib{ ziwkx+sUh3xgcak16aW+k7KERm3 z*tb390HYkIFi;;{yTUX!7Daja>76GTr5RJVZ#>Buz$VSt$B@bJl!5;m|3>~c{tSM1 zenoyJzT14e_-1XFxxiS&r-N*S>@;r{X?c0C#H7TWN-U1pzUv;NJ0lavj_J$~7_%6U zY|neZ=*5BJ3c2aAERxFd)Azq%lmxos=?g}ga3+=m)0rKZRxzI0zRrP3h(#CKPPsYx zAPs(rNjas(V1Ik0CKcu9!F|5{tqYTgG!u`&bmjymD@K{^b_q35EK*3!QE*Dk!RCPNd`zsL zZJC&l0z-i{kI{U3kprtW<3(U#u!=Jab7&*tQ0{OgIP}gqvw}kJlQXL&i$1c23WuXX Wk?fRMS)$;Rn1MBtqC8la9R~oDk*(YS delta 605 zcmZozAknZuVuCay(?l6(ekKMz|5{!K1_nm{i46P`Hx?@JZ|>tSKETAlFq!#+31iu2 ziwkxVaY`XEL?VoqvtNoHPVVxB@sYEe;UNq$k~=J|J$9s@N` zXFkA~z}U1sZx(5J^XUukF-q{FxMTaSdyMXkV232W%KE$Uoc9dX?XgAQ6?O$!GUQN;f*Z0BQQ{cH>IAZs3@_VgkLR%^ziK!37|GxKU4t_1nhDY2v^ hvk03%KRL5nvastMjs`{KbUP1LX*A=bJXn_<2LR0q#nb=*