diff --git a/.gitignore b/.gitignore index d7d6aa00..c88a4b63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,7 @@ -start/.gradle/5.1.1/gc.properties -start/.gradle/5.1.1/executionHistory/executionHistory.bin -start/.gradle/5.1.1/executionHistory/executionHistory.lock -start/.gradle/5.1.1/fileChanges/last-build.bin -start/.gradle/5.1.1/fileHashes/fileHashes.bin -start/.gradle/5.1.1/fileHashes/fileHashes.lock -start/.gradle/5.4.1/gc.properties -start/.gradle/5.4.1/executionHistory/executionHistory.bin -start/.gradle/5.4.1/executionHistory/executionHistory.lock -start/.gradle/5.4.1/fileChanges/last-build.bin -start/.gradle/5.4.1/fileContent/fileContent.lock -start/.gradle/5.4.1/fileHashes/fileHashes.bin -start/.gradle/5.4.1/fileHashes/fileHashes.lock -start/.gradle/5.4.1/fileHashes/resourceHashesCache.bin -start/.gradle/5.4.1/javaCompile/classAnalysis.bin -start/.gradle/5.4.1/javaCompile/jarAnalysis.bin -start/.gradle/5.4.1/javaCompile/javaCompile.lock -start/.gradle/5.4.1/javaCompile/taskHistory.bin -start/.gradle/buildOutputCleanup/buildOutputCleanup.lock -start/.gradle/buildOutputCleanup/cache.properties -start/.gradle/buildOutputCleanup/outputFiles.bin -start/.gradle/vcs-1/gc.properties +*.iml +.gradle +/local.properties +.idea +.DS_Store +/build +/captures diff --git a/.vs/Kotlin/v16/.suo b/.vs/Kotlin/v16/.suo new file mode 100644 index 00000000..b394def0 Binary files /dev/null and b/.vs/Kotlin/v16/.suo differ diff --git a/.vs/Kotlin/v16/Browse.VC.db b/.vs/Kotlin/v16/Browse.VC.db new file mode 100644 index 00000000..3809cd45 Binary files /dev/null and b/.vs/Kotlin/v16/Browse.VC.db differ diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 00000000..f8b48885 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 00000000..34b87a39 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,11 @@ +{ + "ExpandedNodes": [ + "", + "\\app", + "\\app\\src", + "\\app\\src\\main", + "\\app\\src\\main\\res" + ], + "SelectedNode": "\\app\\build.gradle", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/android-kotlin-notifications/v16/.suo b/.vs/android-kotlin-notifications/v16/.suo new file mode 100644 index 00000000..1bcf8871 Binary files /dev/null and b/.vs/android-kotlin-notifications/v16/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 00000000..eaba5547 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/Debug/Kotlin.exe.recipe b/Debug/Kotlin.exe.recipe new file mode 100644 index 00000000..e8654fb2 --- /dev/null +++ b/Debug/Kotlin.exe.recipe @@ -0,0 +1,11 @@ + + + + + C:\Users\MalekPC\Documents\GitHub\android-kotlin-notifications\Debug\Kotlin.exe + + + + + + \ No newline at end of file diff --git a/Debug/Kotlin.log b/Debug/Kotlin.log new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Debug/Kotlin.log @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Debug/Kotlin.tlog/Kotlin.lastbuildstate b/Debug/Kotlin.tlog/Kotlin.lastbuildstate new file mode 100644 index 00000000..069353c4 --- /dev/null +++ b/Debug/Kotlin.tlog/Kotlin.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:VCServicingVersionATL=14.29.30136:VCServicingVersionCrtHeaders=14.29.30136:VCServicingVersionCompilers=14.29.30136:TargetPlatformVersion=10.0.19041.0: +Debug|Win32|C:\Users\MalekPC\Documents\GitHub\android-kotlin-notifications\| diff --git a/Kotlin.sln b/Kotlin.sln new file mode 100644 index 00000000..688af6f5 --- /dev/null +++ b/Kotlin.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31729.503 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Kotlin", "Kotlin.vcxproj", "{1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Debug|x64.ActiveCfg = Debug|x64 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Debug|x64.Build.0 = Debug|x64 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Debug|x86.ActiveCfg = Debug|Win32 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Debug|x86.Build.0 = Debug|Win32 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Release|x64.ActiveCfg = Release|x64 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Release|x64.Build.0 = Release|x64 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Release|x86.ActiveCfg = Release|Win32 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ECB94911-680E-4350-9D68-D0517BA5711B} + EndGlobalSection +EndGlobal diff --git a/Kotlin.vcxproj b/Kotlin.vcxproj new file mode 100644 index 00000000..b3a2e478 --- /dev/null +++ b/Kotlin.vcxproj @@ -0,0 +1,105 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {1C0CA386-EA94-4FD6-ACB0-1C63C27C8733} + Win32Proj + + + + Application + true + v142 + + + Application + false + v142 + + + Application + true + v142 + + + Application + false + v142 + + + + + + + + + + + + + + + + + + + + + true + + + true + + + + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level3 + ProgramDatabase + Disabled + + + MachineX86 + true + Windows + + + + + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDLL + Level3 + ProgramDatabase + + + MachineX86 + true + Windows + true + true + + + + + + + + \ No newline at end of file diff --git a/Kotlin.vcxproj.filters b/Kotlin.vcxproj.filters new file mode 100644 index 00000000..c04a89b8 --- /dev/null +++ b/Kotlin.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + \ No newline at end of file diff --git a/Kotlin.vcxproj.user b/Kotlin.vcxproj.user new file mode 100644 index 00000000..88a55094 --- /dev/null +++ b/Kotlin.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 940cbd74..5ca4e427 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,11 +19,11 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { - compileSdkVersion 29 + compileSdkVersion 30 defaultConfig { applicationId "com.example.android.eggtimernotifications" minSdkVersion 19 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -36,20 +36,20 @@ android { } // Enables data binding. - dataBinding { - enabled = true + buildFeatures { + dataBinding true } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.core:core-ktx:1.0.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.core:core-ktx:1.3.1' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-rc01' + implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-rc01' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' diff --git a/app/src/main/java/com/example/android/eggtimernotifications/receiver/AlarmReceiver.kt b/app/src/main/java/com/example/android/eggtimernotifications/receiver/AlarmReceiver.kt index 5762b242..7313457c 100644 --- a/app/src/main/java/com/example/android/eggtimernotifications/receiver/AlarmReceiver.kt +++ b/app/src/main/java/com/example/android/eggtimernotifications/receiver/AlarmReceiver.kt @@ -29,18 +29,9 @@ class AlarmReceiver: BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { // TODO: Step 1.10 [Optional] remove toast -// Toast.makeText(context, context.getText(R.string.eggs_ready), Toast.LENGTH_SHORT).show() + Toast.makeText(context, context.getText(R.string.eggs_ready), Toast.LENGTH_SHORT).show() // TODO: Step 1.9 add call to sendNotification - val notificationManager = ContextCompat.getSystemService( - context, - NotificationManager::class.java - ) as NotificationManager - - notificationManager.sendNotification( - context.getText(R.string.eggs_ready).toString(), - context - ) } diff --git a/app/src/main/java/com/example/android/eggtimernotifications/receiver/SnoozeReceiver.kt b/app/src/main/java/com/example/android/eggtimernotifications/receiver/SnoozeReceiver.kt index 0f41e8bf..ceea1381 100644 --- a/app/src/main/java/com/example/android/eggtimernotifications/receiver/SnoozeReceiver.kt +++ b/app/src/main/java/com/example/android/eggtimernotifications/receiver/SnoozeReceiver.kt @@ -47,12 +47,6 @@ class SnoozeReceiver: BroadcastReceiver() { triggerTime, notifyPendingIntent ) - - val notificationManager = ContextCompat.getSystemService( - context, - NotificationManager::class.java - ) as NotificationManager - notificationManager.cancelAll() } } \ No newline at end of file diff --git a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt index bec13f9d..0802dc0f 100644 --- a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt +++ b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerFragment.kt @@ -27,7 +27,7 @@ import android.view.ViewGroup import android.widget.Toast import androidx.databinding.DataBindingUtil import androidx.fragment.app.Fragment -import androidx.lifecycle.ViewModelProviders +import androidx.lifecycle.ViewModelProvider import com.example.android.eggtimernotifications.R import com.example.android.eggtimernotifications.databinding.FragmentEggTimerBinding import com.google.firebase.messaging.FirebaseMessaging @@ -45,45 +45,21 @@ class EggTimerFragment : Fragment() { inflater, R.layout.fragment_egg_timer, container, false ) - val viewModel = ViewModelProviders.of(this).get(EggTimerViewModel::class.java) + val viewModel = ViewModelProvider(this).get(EggTimerViewModel::class.java) binding.eggTimerViewModel = viewModel binding.lifecycleOwner = this.viewLifecycleOwner // TODO: Step 1.7 call create channel - createChannel( - getString(R.string.egg_notification_channel_id), - getString(R.string.egg_notification_channel_name) - ) return binding.root } private fun createChannel(channelId: String, channelName: String) { // TODO: Step 1.6 START create a channel - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val notificationChannel = NotificationChannel( - channelId, - channelName, - // TODO: Step 2.4 change importance - NotificationManager.IMPORTANCE_HIGH - )// TODO: Step 2.6 disable badges for this channel - .apply { - setShowBadge(false) - } - - notificationChannel.enableLights(true) - notificationChannel.lightColor = Color.RED - notificationChannel.enableVibration(true) - notificationChannel.description = getString(R.string.breakfast_notification_channel_description) - val notificationManager = requireActivity().getSystemService( - NotificationManager::class.java - ) - notificationManager.createNotificationChannel(notificationChannel) - - } // TODO: Step 1.6 END create a channel + } companion object { diff --git a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt index caa2f07d..934306f1 100644 --- a/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt +++ b/app/src/main/java/com/example/android/eggtimernotifications/ui/EggTimerViewModel.kt @@ -26,7 +26,6 @@ import androidx.core.content.ContextCompat import androidx.lifecycle.* import com.example.android.eggtimernotifications.receiver.AlarmReceiver import com.example.android.eggtimernotifications.R -import com.example.android.eggtimernotifications.util.cancelNotifications import com.example.android.eggtimernotifications.util.sendNotification import kotlinx.coroutines.* @@ -119,13 +118,9 @@ class EggTimerViewModel(private val app: Application) : AndroidViewModel(app) { } val triggerTime = SystemClock.elapsedRealtime() + selectedInterval + // TODO: Step 1.5 get an instance of NotificationManager and call sendNotification + // TODO: Step 1.15 call cancel notification - val notificationManager = - ContextCompat.getSystemService( - app, - NotificationManager::class.java - ) as NotificationManager - notificationManager.cancelNotifications() AlarmManagerCompat.setExactAndAllowWhileIdle( alarmManager, diff --git a/app/src/main/java/com/example/android/eggtimernotifications/util/NotificationUtils.kt b/app/src/main/java/com/example/android/eggtimernotifications/util/NotificationUtils.kt index a6fd2698..2f9e2a2e 100644 --- a/app/src/main/java/com/example/android/eggtimernotifications/util/NotificationUtils.kt +++ b/app/src/main/java/com/example/android/eggtimernotifications/util/NotificationUtils.kt @@ -41,73 +41,30 @@ fun NotificationManager.sendNotification(messageBody: String, applicationContext // Create the content intent for the notification, which launches // this activity // TODO: Step 1.11 create intent - val contentIntent = Intent(applicationContext, MainActivity::class.java) + // TODO: Step 1.12 create PendingIntent - val contentPendingIntent = PendingIntent.getActivity( - applicationContext, - NOTIFICATION_ID, - contentIntent, - PendingIntent.FLAG_UPDATE_CURRENT - ) // TODO: Step 2.0 add style - val eggImage = BitmapFactory.decodeResource( - applicationContext.resources, - R.drawable.cooked_egg - ) - val bigPicStyle = NotificationCompat.BigPictureStyle() - .bigPicture(eggImage) - .bigLargeIcon(null) // TODO: Step 2.2 add snooze action - val snoozeIntent = Intent(applicationContext, SnoozeReceiver::class.java) - val snoozePendingIntent: PendingIntent = PendingIntent.getBroadcast( - applicationContext, - REQUEST_CODE, - snoozeIntent, - FLAGS) // TODO: Step 1.2 get an instance of NotificationCompat.Builder // Build the notification - val builder = NotificationCompat.Builder( - applicationContext, - applicationContext.getString(R.string.egg_notification_channel_id) - ) // TODO: Step 1.8 use the new 'breakfast' notification channel // TODO: Step 1.3 set title, text and icon to builder - .setSmallIcon(R.drawable.cooked_egg) - .setContentTitle(applicationContext - .getString(R.string.notification_title)) - .setContentText(messageBody) // TODO: Step 1.13 set content intent - .setContentIntent(contentPendingIntent) - .setAutoCancel(true) // TODO: Step 2.1 add style to builder - .setStyle(bigPicStyle) - .setLargeIcon(eggImage) // TODO: Step 2.3 add snooze action - .addAction( - R.drawable.egg_icon, - applicationContext.getString(R.string.snooze), - snoozePendingIntent - ) // TODO: Step 2.5 set priority - .setPriority(NotificationCompat.PRIORITY_HIGH) + // TODO: Step 1.4 call notify - notify(NOTIFICATION_ID, builder.build()) + } // TODO: Step 1.14 Cancel all notifications -/** - * Cancels all notifications. - * - */ -fun NotificationManager.cancelNotifications() { - cancelAll() -} diff --git a/build.gradle b/build.gradle index ef9ef3ba..edab77f3 100644 --- a/build.gradle +++ b/build.gradle @@ -16,14 +16,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:4.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0da09962..47a3857d 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-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip