Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ build/
.idea/libraries/Dart_SDK.xml
.idea/workspace.xml
example/.flutter-plugins-dependencies

.idea/
Empty file removed .idea/.gitignore
Empty file.
19 changes: 0 additions & 19 deletions .idea/libraries/Dart_SDK.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/libraries/Flutter_Plugins.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/libraries/Flutter_for_Android.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/runConfigurations/example_lib_main_dart.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

65 changes: 0 additions & 65 deletions .idea/workspace.xml

This file was deleted.

5 changes: 2 additions & 3 deletions android/.idea/gradle.xml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.idea should not be commited.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions android/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion android/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'de.appgewaltig.disk_space'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.72'
ext.kotlin_version = '1.7.10'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.appgewaltig.disk_space

import android.content.Context
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel
Expand All @@ -9,21 +10,15 @@ class DiskSpacePlugin: FlutterPlugin {

companion object {
private var channel: MethodChannel? = null
private var handler: MethodHandlerImpl = MethodHandlerImpl()

@JvmStatic
fun registerWith(registrar: PluginRegistry.Registrar) {
registerChannel(registrar.messenger())
}

private fun registerChannel(messenger: BinaryMessenger) {
private fun registerChannel(messenger: BinaryMessenger, context: Context) {
channel = MethodChannel(messenger, "disk_space")
channel!!.setMethodCallHandler(handler)
channel!!.setMethodCallHandler(MethodHandlerImpl(context))
}
}

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
registerChannel(binding.binaryMessenger)
registerChannel(binding.binaryMessenger, binding.getApplicationContext())
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.appgewaltig.disk_space

import android.content.Context
import android.os.Environment
import android.os.StatFs
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class MethodHandlerImpl : MethodChannel.MethodCallHandler {
class MethodHandlerImpl(private val context: Context) : MethodChannel.MethodCallHandler {
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when(call.method) {
"getFreeDiskSpace" -> result.success(getFreeDiskSpace())
Expand All @@ -16,10 +17,9 @@ class MethodHandlerImpl : MethodChannel.MethodCallHandler {
}

private fun getFreeDiskSpace(): Double {
val stat = StatFs(Environment.getExternalStorageDirectory().path)
val stat = StatFs(getFilesPath())

val bytesAvailable: Long
bytesAvailable = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
val bytesAvailable: Long = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
stat.blockSizeLong * stat.availableBlocksLong
else
stat.blockSize.toLong() * stat.availableBlocks.toLong()
Expand All @@ -28,23 +28,33 @@ class MethodHandlerImpl : MethodChannel.MethodCallHandler {

private fun getFreeDiskSpaceForPath(path: String): Double {
val stat = StatFs(path)

val bytesAvailable: Long
bytesAvailable = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)

val bytesAvailable: Long = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
stat.blockSizeLong * stat.availableBlocksLong
else
stat.blockSize.toLong() * stat.availableBlocks.toLong()
return (bytesAvailable / (1024f * 1024f)).toDouble()
}

private fun getTotalDiskSpace(): Double {
val stat = StatFs(Environment.getExternalStorageDirectory().path)
val stat = StatFs(getFilesPath())

val bytesAvailable: Long
bytesAvailable = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
val bytesAvailable: Long = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
stat.blockSizeLong * stat.blockCountLong
else
stat.blockSize.toLong() * stat.blockCount.toLong()
return (bytesAvailable / (1024f * 1024f)).toDouble()
}

private fun getFilesPath(): String {
val state = Environment.getExternalStorageState()

return if (Environment.MEDIA_MOUNTED == state) {
// We can read and write the media
context.getExternalFilesDir(null)?.path.toString()
} else {
// Load another directory, probably local memory
context.filesDir?.path.toString()
}
}
}
2 changes: 2 additions & 0 deletions disk_space.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"disk_space","path":"/Users/marvinknabe/Entwicklung/flutter/disk_space/","dependencies":[]}],"android":[{"name":"disk_space","path":"/Users/marvinknabe/Entwicklung/flutter/disk_space/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"disk_space","dependencies":[]}],"date_created":"2021-05-27 18:22:29.500956","version":"2.2.0"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"disk_space","path":"C:\\\\Users\\\\ahmed\\\\AndroidStudioProjects\\\\disk_space\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\ahmed\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"disk_space","path":"C:\\\\Users\\\\ahmed\\\\AndroidStudioProjects\\\\disk_space\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"C:\\\\Users\\\\ahmed\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.0\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\ahmed\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\ahmed\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\ahmed\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.2.1\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"disk_space","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-09-21 14:31:22.573296","version":"3.10.6"}
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
7 changes: 0 additions & 7 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:name=".EmbeddingV1Activity"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
Expand Down
Loading