Skip to content

Commit

Permalink
[UPDATE] - updated project with new version of flutter and added some…
Browse files Browse the repository at this point in the history
… feature (check CHANGELOG)
  • Loading branch information
andreamainella98 committed Nov 4, 2024
1 parent 1096c6d commit ec5ad75
Show file tree
Hide file tree
Showing 67 changed files with 633 additions and 487 deletions.
3 changes: 1 addition & 2 deletions .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"flutterSdkVersion": "stable",
"flavors": {}
"flutterSdkVersion": "stable"
}
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "stable"
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ app.*.symbols
!/dev/ci/**/Gemfile.lock

#Fvm
.fvm/flutter_sdk

# FVM Version Cache
.fvm/
27 changes: 25 additions & 2 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@
# This file should be version controlled and should not be manually edited.

version:
revision: db747aa1331bd95bc9b3874c842261ca2d302cd5
channel: stable
revision: "2663184aa79047d0a33a14a3b607954f8fdd8730"
channel: "stable"

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: android
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: ios
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.0
- Updated dependencies
- Updated version of flutter to stable
- Updated Android Build
- Add initial instance of PhoneState with initial status of device - Request of [@MINEGHOST007](https://github.com/MINEGHOST007) with issue [#29](https://github.com/andreamainella98/phone_state/issues/29)
- Fixed value of stream by [@Penguin-Lin](https://github.com/andreamainella98/phone_state/pull/34) with pr [#34](https://github.com/andreamainella98/phone_state/pull/34)
## 1.0.4
- Updated dependencies, minimum version of ios and formatted code
## 1.0.3
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This plugin allows you to know quickly and easily if your Android or iOS device
dependencies:
flutter:
sdk: flutter
phone_state: 1.0.4
phone_state: 2.0.0
```
#### Android: Added permission on manifest
```xml
Expand All @@ -35,7 +35,6 @@ dependencies:

```dart
StreamBuilder<PhoneState>(
initialData: PhoneState.nothing(),
stream: PhoneState.stream,
...
```
Expand Down
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.DS_Store
/build
/captures
.cxx
38 changes: 17 additions & 21 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
group 'it.mainella.phone_state'
version '1.0.1'
group = "it.mainella.phone_state"
version = "1.0-SNAPSHOT"

buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = "1.8.22"
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("com.android.tools.build:gradle:8.1.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}

rootProject.allprojects {
allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: "com.android.library"
apply plugin: "kotlin-android"

android {
compileSdkVersion 31

if (project.android.hasProperty('namespace')) {
namespace 'it.mainella.phone_state'
if (project.android.hasProperty("namespace")) {
namespace = "it.mainella.phone_state"
}

compileSdk = 34

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = JavaVersion.VERSION_1_8
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.java.srcDirs += "src/main/kotlin"
}

defaultConfig {
minSdkVersion 16
minSdk = 21
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
5 changes: 0 additions & 5 deletions android/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

4 changes: 3 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<manifest package="it.mainella.phone_state" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.mainella.phone_state">
</manifest>
22 changes: 10 additions & 12 deletions android/src/main/kotlin/it/mainella/phone_state/PhoneStatePlugin.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package it.mainella.phone_state

import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import it.mainella.phone_state.handler.FlutterHandler

class PhoneStatePlugin : FlutterPlugin {
private lateinit var flutterHandler: FlutterHandler

override fun onAttachedToEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
flutterHandler = FlutterHandler(binding)
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
flutterHandler.dispose()
}
/** PhoneStatePlugin */
class PhoneStatePlugin: FlutterPlugin {
private lateinit var flutterHandler: FlutterHandler

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
flutterHandler = FlutterHandler(flutterPluginBinding)
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
flutterHandler.dispose()
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package it.mainella.phone_state.handler

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.telephony.TelephonyManager
import androidx.annotation.NonNull
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel
import it.mainella.phone_state.receiver.PhoneStateReceiver
import it.mainella.phone_state.utils.Constants

class FlutterHandler(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
class FlutterHandler(binding: FlutterPlugin.FlutterPluginBinding) {
private var phoneStateEventChannel: EventChannel = EventChannel(binding.binaryMessenger, Constants.EVENT_CHANNEL)

init {
Expand All @@ -35,6 +31,26 @@ class FlutterHandler(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
)
}
}
val context = binding.applicationContext
val hasPhoneStatePermission = ContextCompat.checkSelfPermission(
context,
Manifest.permission.READ_PHONE_STATE
) == PackageManager.PERMISSION_GRANTED

val hasCallLogPermission = ContextCompat.checkSelfPermission(
context,
Manifest.permission.READ_CALL_LOG
) == PackageManager.PERMISSION_GRANTED

if (hasPhoneStatePermission && hasCallLogPermission) {
receiver.instance(context)
events?.success(
mapOf(
"status" to receiver.status.name,
"phoneNumber" to receiver.phoneNumber
)
)
}

binding.applicationContext.registerReceiver(
receiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ import android.telephony.TelephonyManager
import it.mainella.phone_state.utils.PhoneStateStatus

open class PhoneStateReceiver : BroadcastReceiver() {
var status: PhoneStateStatus = PhoneStateStatus.NOTHING;
var phoneNumber: String? = null;
var status: PhoneStateStatus = PhoneStateStatus.NOTHING
var phoneNumber: String? = null

fun instance(context: Context) {
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager

status = when (telephonyManager.callState) {
TelephonyManager.CALL_STATE_RINGING -> PhoneStateStatus.CALL_INCOMING
TelephonyManager.CALL_STATE_OFFHOOK -> PhoneStateStatus.CALL_STARTED
TelephonyManager.CALL_STATE_IDLE -> PhoneStateStatus.CALL_ENDED
else -> PhoneStateStatus.NOTHING
}
phoneNumber = null
}

override fun onReceive(context: Context?, intent: Intent?) {
try {
status = when (intent?.getStringExtra(TelephonyManager.EXTRA_STATE)) {
Expand Down
Loading

0 comments on commit ec5ad75

Please sign in to comment.