diff --git a/app/build.gradle b/app/build.gradle index 23c347d605d..c94f714539a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,37 +1,24 @@ apply plugin: 'com.android.application' - apply plugin: 'kotlin-android' - apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 28 + compileSdkVersion 29 + defaultConfig { applicationId "io.homeassistant.android" - minSdkVersion 24 - targetSdkVersion 28 + minSdkVersion 21 + targetSdkVersion 29 versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } + versionName "1.0.0" } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'com.google.firebase:firebase-core:16.0.1' - implementation 'com.google.firebase:firebase-messaging:17.5.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "androidx.appcompat:appcompat:1.1.0" + implementation "com.google.firebase:firebase-core:17.2.0" + implementation "com.google.firebase:firebase-messaging:20.0.0" } -apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin \ No newline at end of file +apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png deleted file mode 100644 index 7cb6807adbc..00000000000 Binary files a/app/src/main/ic_launcher-web.png and /dev/null differ diff --git a/app/src/main/java/io/homeassistant/android/MainActivity.kt b/app/src/main/java/io/homeassistant/android/MainActivity.kt index 3392e4f6b04..ada1708a9f5 100644 --- a/app/src/main/java/io/homeassistant/android/MainActivity.kt +++ b/app/src/main/java/io/homeassistant/android/MainActivity.kt @@ -1,17 +1,13 @@ package io.homeassistant.android -import android.util.Log -import android.support.v7.app.AppCompatActivity import android.os.Bundle +import android.util.Log +import android.webkit.WebView +import android.webkit.WebViewClient import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity import com.google.android.gms.tasks.OnCompleteListener import com.google.firebase.iid.FirebaseInstanceId -import com.google.firebase.messaging.FirebaseMessaging -import android.webkit.WebView -import android.webkit.WebViewClient -import android.support.v4.content.ContextCompat -import android.view.WindowManager - class MainActivity : AppCompatActivity() { @@ -20,35 +16,28 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - val window = getWindow() - - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) - - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) - - window.setStatusBarColor(ContextCompat.getColor(applicationContext, R.color.colorPrimary)) - - val myWebView: WebView = findViewById(R.id.webview) - myWebView.settings.javaScriptEnabled = true - myWebView.settings.domStorageEnabled = true - myWebView.webViewClient = WebViewClient() - myWebView.loadUrl("https://demo.home-assistant.io") - - FirebaseInstanceId.getInstance().instanceId - .addOnCompleteListener(OnCompleteListener { task -> - if (!task.isSuccessful) { - Log.w(TAG, "getInstanceId failed", task.exception) - return@OnCompleteListener - } - - // Get new Instance ID token - val token = task.result?.token - - // Log and toast - val msg = getString(R.string.msg_token_fmt, token) - Log.d(TAG, msg) - Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show() - }) + findViewById(R.id.webview).apply { + settings.javaScriptEnabled = true + settings.domStorageEnabled = true + webViewClient = WebViewClient() + loadUrl("https://demo.home-assistant.io") + } + + FirebaseInstanceId.getInstance() + .instanceId.addOnCompleteListener(OnCompleteListener { task -> + if (!task.isSuccessful) { + Log.w(TAG, "getInstanceId failed", task.exception) + return@OnCompleteListener + } + + // Get new Instance ID token + val token = task.result?.token + + // Log and toast + val msg = getString(R.string.msg_token_fmt, token) + Log.d(TAG, msg) + Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show() + }) } companion object { diff --git a/app/src/main/java/io/homeassistant/android/MessagingService.kt b/app/src/main/java/io/homeassistant/android/MessagingService.kt index e9fe9129ea0..85e19ebd248 100644 --- a/app/src/main/java/io/homeassistant/android/MessagingService.kt +++ b/app/src/main/java/io/homeassistant/android/MessagingService.kt @@ -3,50 +3,45 @@ package io.homeassistant.android import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent -import android.app.Service import android.content.Context -import android.content.Context.NOTIFICATION_SERVICE import android.content.Intent import android.media.RingtoneManager -import android.net.Uri import android.os.Build -import android.os.IBinder -import android.support.v4.app.NotificationCompat -import android.support.v4.content.ContextCompat.getSystemService import android.util.Log +import androidx.core.app.NotificationCompat import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage -import io.homeassistant.android.MainActivity -import io.homeassistant.android.R class MessagingService : FirebaseMessagingService() { - override fun onMessageReceived(remoteMessage: RemoteMessage?) { + override fun onMessageReceived(remoteMessage: RemoteMessage) { // Handle data payload of FCM messages. // TODO(developer): Handle FCM messages here. // Not getting messages here? See why this may be: https://goo.gl/39bRNJ - Log.d(TAG, "From: ${remoteMessage?.from}") + Log.d(TAG, "From: ${remoteMessage.from}") // Check if message contains a data payload. - remoteMessage?.data?.isNotEmpty()?.let { + remoteMessage.data.isNotEmpty().let { Log.d(TAG, "Message data payload: " + remoteMessage.data) } // Check if message contains a notification payload. - remoteMessage?.notification?.let { + remoteMessage.notification?.let { Log.d(TAG, "Message Notification Body: ${it.body}") } - sendNotification(remoteMessage!!) + sendNotification(remoteMessage) } private fun sendNotification(remoteMessage: RemoteMessage) { val intent = Intent(this, MainActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - val pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, - PendingIntent.FLAG_ONE_SHOT) + val pendingIntent = PendingIntent.getActivity( + this, 0 /* Request code */, intent, + PendingIntent.FLAG_ONE_SHOT + ) val channelId = getString(R.string.default_notification_channel_id) val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) @@ -59,13 +54,16 @@ class MessagingService : FirebaseMessagingService() { .setSound(defaultSoundUri) .setContentIntent(pendingIntent) - val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val notificationManager = + getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channel = NotificationChannel(channelId, + val channel = NotificationChannel( + channelId, "Channel human readable title", - NotificationManager.IMPORTANCE_DEFAULT) + NotificationManager.IMPORTANCE_DEFAULT + ) notificationManager.createNotificationChannel(channel) } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 384554a44dd..9ee06079469 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,16 +1,5 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/build.gradle b/build.gradle index b158d855b82..8f9f6582723 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,14 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { - ext.kotlin_version = '1.3.21' + ext.kotlin_version = '1.3.50' repositories { google() jcenter() - + } dependencies { - classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.android.tools.build:gradle:3.5.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.google.gms:google-services:4.2.0' // Google Services plugin - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.google.gms:google-services:4.3.2' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b86a80670dd..339337ad069 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip