diff --git a/DonutTracker/NavigationUI/.gitignore b/DonutTracker/NavigationUI/.gitignore deleted file mode 100644 index d471b69..0000000 --- a/DonutTracker/NavigationUI/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -# built application files -*.apk -*.ap_ -# Mac files -.DS_Store -# files for the dex VM -*.dex -# Java class files -*.class -# generated files -bin/ -gen/ -# Ignore gradle files -.gradle/ -build/ -# Local configuration file (sdk path, etc) -local.properties -# Proguard folder generated by Eclipse -proguard/ -proguard-project.txt -# Eclipse files -.project -.classpath -.settings/ -# Android Studio/IDEA -*.iml -.idea \ No newline at end of file diff --git a/DonutTracker/NavigationUI/README.md b/DonutTracker/NavigationUI/README.md deleted file mode 100644 index 76a024f..0000000 --- a/DonutTracker/NavigationUI/README.md +++ /dev/null @@ -1,27 +0,0 @@ -MAD Skills Navigation Sample (Donut Tracker) -============================================== - -This sample shows the features of Navigation component highlighted by the second Navigation -series in the MAD Skills [videos](https://www.youtube.com/user/androiddevelopers) -and [articles](https://medium.com/androiddevelopers). Specifically, episodes -1, 2, 3, and 4 walk through code from this sample. - -### Features - -This sample showcases the following features of the Navigation component: - - * NavigationUI (episode 1) - * Conditional Navigation (episode 2) - * Nested Graphs and Include (episode 3) - * Navigation in Feature Modules (episode 4) - -### Screenshots -Screenshot - -### Other Resources - - * For an overview of using Navigation component, check out - [Get started with the Navigation component](https://developer.android.com/guide/navigation/navigation-getting-started) - * Consider including the [Navigation KTX libraries](https://developer.android.com/topic/libraries/architecture/adding-components#navigation) - for more concise uses of the Navigation component. For example, calls to `Navigation.findNavController(view)` can - be expressed as `view.findNavController()`. \ No newline at end of file diff --git a/DonutTracker/NavigationUI/app/.gitignore b/DonutTracker/NavigationUI/app/.gitignore deleted file mode 100644 index d471b69..0000000 --- a/DonutTracker/NavigationUI/app/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -# built application files -*.apk -*.ap_ -# Mac files -.DS_Store -# files for the dex VM -*.dex -# Java class files -*.class -# generated files -bin/ -gen/ -# Ignore gradle files -.gradle/ -build/ -# Local configuration file (sdk path, etc) -local.properties -# Proguard folder generated by Eclipse -proguard/ -proguard-project.txt -# Eclipse files -.project -.classpath -.settings/ -# Android Studio/IDEA -*.iml -.idea \ No newline at end of file diff --git a/DonutTracker/NavigationUI/app/build.gradle b/DonutTracker/NavigationUI/app/build.gradle deleted file mode 100644 index 53891c4..0000000 --- a/DonutTracker/NavigationUI/app/build.gradle +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -apply plugin: "androidx.navigation.safeargs.kotlin" -apply plugin: 'kotlin-kapt' - -android { - compileSdkVersion 29 - buildToolsVersion "29.0.2" - - buildFeatures { - viewBinding = true - } - - defaultConfig { - applicationId "com.android.samples.navdonutcreator" - minSdkVersion 21 - targetSdkVersion 29 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - -// To inline the bytecode built with JVM target 1.8 into -// bytecode that is being built with JVM target 1.6. (e.g. navArgs) - - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = "1.8" - } - - packagingOptions { - exclude 'META-INF/atomicfu.kotlin_module' - } -} - -configurations { - ktlint -} - -dependencies { - implementation "androidx.appcompat:appcompat:$appCompatVersion" - implementation "androidx.core:core-ktx:$ktxVersion" - implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion" - implementation "androidx.fragment:fragment-ktx:$fragmentVersion" - implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation "androidx.lifecycle:lifecycle-livedata-core-ktx:$archLifecycleVersion" - implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion" - implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion" - implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion" - implementation "androidx.room:room-runtime:$roomVersion" - kapt "androidx.room:room-compiler:$roomVersion" - implementation "androidx.room:room-ktx:$roomVersion" - implementation "com.google.android.material:material:$materialVersion" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" - api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" - - ktlint "com.pinterest:ktlint:$ktlintVersion" -} - - -// Disable the 'paren-spacing' rule which conflicts with non-paren annotations on functional types -task ktlint(type: JavaExec, group: "verification") { - description = "Check Kotlin code style." - main = "com.pinterest.ktlint.Main" - classpath = configurations.ktlint - args "src/**/*.kt", "--disabled_rules", "paren-spacing" -} -check.dependsOn ktlint - -task ktlintFormat(type: JavaExec, group: "formatting") { - description = "Fix Kotlin code style deviations." - main = "com.pinterest.ktlint.Main" - classpath = configurations.ktlint - args "-F", "src/**/*.kt", "--disabled_rules", "paren-spacing" -} \ No newline at end of file diff --git a/DonutTracker/NavigationUI/app/src/main/AndroidManifest.xml b/DonutTracker/NavigationUI/app/src/main/AndroidManifest.xml deleted file mode 100644 index 3849a2a..0000000 --- a/DonutTracker/NavigationUI/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/MainActivity.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/MainActivity.kt deleted file mode 100644 index a5079f9..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/MainActivity.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.Menu -import android.view.MenuItem -import androidx.appcompat.app.AppCompatActivity -import androidx.navigation.NavController -import androidx.navigation.findNavController -import androidx.navigation.fragment.NavHostFragment -import androidx.navigation.ui.AppBarConfiguration -import androidx.navigation.ui.navigateUp -import androidx.navigation.ui.onNavDestinationSelected -import androidx.navigation.ui.setupActionBarWithNavController -import androidx.navigation.ui.setupWithNavController -import com.android.samples.donuttracker.databinding.ActivityMainBinding -import com.google.android.material.bottomnavigation.BottomNavigationView -import com.google.android.material.navigation.NavigationView - -/** - * Main activity class. Not much happens here, just some basic UI setup. - * The main logic occurs in the fragments which populate this activity. - */ -class MainActivity : AppCompatActivity() { - - private lateinit var navController: NavController - private lateinit var appBarConfiguration: AppBarConfiguration - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - val binding = ActivityMainBinding.inflate(LayoutInflater.from(this)) - setContentView(binding.root) - - val navHostFragment = supportFragmentManager.findFragmentById( - R.id.nav_host_fragment - ) as NavHostFragment - navController = navHostFragment.navController - - appBarConfiguration= AppBarConfiguration(navController.graph) - - val toolbar = binding.toolbar - setSupportActionBar(toolbar) - setupActionBarWithNavController(navController, appBarConfiguration) - setupBottomNavMenu(navController) - setupNavigationMenu(navController) - - Notifier.init(this) - } - - private fun setupNavigationMenu(navController: NavController){ - val sideNavView = findViewById(R.id.nav_view) - sideNavView?.setupWithNavController(navController) - } - private fun setupBottomNavMenu(navController: NavController){ - val bottomNav = findViewById(R.id.bottom_nav_view) - bottomNav?.setupWithNavController(navController) - } - - override fun onSupportNavigateUp(): Boolean { - return findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration) - } - - override fun onCreateOptionsMenu(menu: Menu): Boolean { - // Inflate the menu; this adds items to the action bar if it is present. - menuInflater.inflate(R.menu.menu_main, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - return item.onNavDestinationSelected( - findNavController(R.id.nav_host_fragment) - ) || super.onOptionsItemSelected(item) - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/Notifier.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/Notifier.kt deleted file mode 100644 index a9df9c4..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/Notifier.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker - -import android.app.Activity -import android.app.NotificationChannel -import android.app.NotificationManager -import android.app.PendingIntent -import android.content.Context -import android.os.Build -import androidx.appcompat.app.AppCompatActivity -import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationManagerCompat - -/** - * Utility class for posting notifications. - * This class creates the notification channel (as necessary) and posts to it when requested. - */ -object Notifier { - - private const val channelId = "Default" - - fun init(activity: Activity) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val notificationManager = - activity.getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager - val existingChannel = notificationManager.getNotificationChannel(channelId) - if (existingChannel == null) { - // Create the NotificationChannel - val name = activity.getString(R.string.defaultChannel) - val importance = NotificationManager.IMPORTANCE_DEFAULT - val mChannel = NotificationChannel(channelId, name, importance) - mChannel.description = activity.getString(R.string.notificationDescription) - notificationManager.createNotificationChannel(mChannel) - } - } - } - - fun postNotification(id: Long, context: Context, intent: PendingIntent) { - val builder = NotificationCompat.Builder(context, channelId) - builder.setContentTitle(context.getString(R.string.deepLinkNotificationTitle)) - .setSmallIcon(R.drawable.donut_with_sprinkles) - val text = context.getString(R.string.addDonutInfo) - val notification = builder.setContentText(text) - .setPriority(NotificationCompat.PRIORITY_HIGH) - .setContentIntent(intent) - .setAutoCancel(true) - .build() - val notificationManager = NotificationManagerCompat.from(context) - // Remove prior notifications; only allow one at a time to edit the latest item - notificationManager.cancelAll() - notificationManager.notify(id.toInt(), notification) - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeEntryDialogFragment.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeEntryDialogFragment.kt deleted file mode 100644 index b102096..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeEntryDialogFragment.kt +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.coffee - -import android.annotation.SuppressLint -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.viewModels -import androidx.lifecycle.observe -import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs -import com.android.samples.donuttracker.Notifier -import com.android.samples.donuttracker.R -import com.android.samples.donuttracker.databinding.CoffeeEntryDialogBinding -import com.android.samples.donuttracker.model.Coffee -import com.android.samples.donuttracker.storage.SnackDatabase -import com.google.android.material.bottomsheet.BottomSheetDialogFragment - -/** - * This dialog allows the user to enter information about a cup of coffee, either creating a new - * entry or updating an existing one. - */ -class CoffeeEntryDialogFragment : BottomSheetDialogFragment() { - - private enum class EditingState { - NEW_COFFEE, - EXISTING_COFFEE - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return CoffeeEntryDialogBinding.inflate(inflater, container, false).root - } - - @SuppressLint("SetTextI18n") - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val coffeeDao = SnackDatabase.getDatabase(requireContext()).coffeeDao() - - val coffeeEntryViewModel: CoffeeEntryViewModel by viewModels { - CoffeeViewModelFactory(coffeeDao) - } - - val binding = CoffeeEntryDialogBinding.bind(view) - - var coffee: Coffee? = null - val args: CoffeeEntryDialogFragmentArgs by navArgs() - val editingState = - if (args.itemId > 0) { - EditingState.EXISTING_COFFEE - } else { - EditingState.NEW_COFFEE - } - - // If we arrived here with an itemId of >= 0, then we are editing an existing item - if (editingState == EditingState.EXISTING_COFFEE) { - // Request to edit an existing item, whose id was passed in as an argument. - // Retrieve that item and populate the UI with its details - coffeeEntryViewModel.get(args.itemId).observe(viewLifecycleOwner) { coffeeItem -> - binding.apply { - name.setText(coffeeItem.name) - description.setText(coffeeItem.description) - ratingBar.rating = coffeeItem.rating.toFloat() - } - - coffee = coffeeItem - } - } - - // When the user clicks the Done button, use the data here to either update - // an existing item or create a new one - binding.doneButton.setOnClickListener { - // Grab these now since the Fragment may go away before the setupNotification - // lambda below is called - val context = requireContext().applicationContext - val navController = findNavController() - - coffeeEntryViewModel.addData( - coffee?.id ?: 0, - binding.name.text.toString(), - binding.description.text.toString(), - binding.ratingBar.rating.toInt() - ) { actualId -> - val arg = CoffeeEntryDialogFragmentArgs(actualId).toBundle() - val pendingIntent = navController - .createDeepLink() - .setDestination(R.id.coffeeEntryDialogFragment) - .setArguments(arg) - .createPendingIntent() - - Notifier.postNotification(actualId, context, pendingIntent) - } - dismiss() - } - - // User clicked the Cancel button; just exit the dialog without saving the data - binding.cancelButton.setOnClickListener { - dismiss() - } - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeEntryViewModel.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeEntryViewModel.kt deleted file mode 100644 index 07f5df3..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeEntryViewModel.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.coffee - -import androidx.lifecycle.LiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.liveData -import androidx.lifecycle.viewModelScope -import com.android.samples.donuttracker.model.Coffee -import com.android.samples.donuttracker.storage.CoffeeDao -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -class CoffeeEntryViewModel(private val coffeeDao: CoffeeDao) : ViewModel() { - - private var coffeeLiveData: LiveData? = null - - fun get(id: Long): LiveData { - return coffeeLiveData ?: liveData { - emit(coffeeDao.get(id)) - }.also { - coffeeLiveData = it - } - } - - fun addData( - id: Long, - name: String, - description: String, - rating: Int, - setupNotification: (Long) -> Unit - ) { - val coffee = Coffee(id, name, description, rating) - - CoroutineScope(Dispatchers.IO).launch { - var actualId = id - - if (id > 0) { - update(coffee) - } else { - actualId = insert(coffee) - } - - setupNotification(actualId) - } - } - - private suspend fun insert(donut: Coffee) = coffeeDao.insert(donut) - - private fun update(donut: Coffee) = viewModelScope.launch(Dispatchers.IO) { - coffeeDao.update(donut) - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeList.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeList.kt deleted file mode 100644 index 64743a7..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeList.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.coffee - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.core.app.NotificationManagerCompat -import androidx.fragment.app.Fragment -import androidx.lifecycle.ViewModelProvider -import androidx.navigation.findNavController -import androidx.navigation.fragment.findNavController -import com.android.samples.donuttracker.databinding.CoffeeListBinding -import com.android.samples.donuttracker.storage.SnackDatabase - -/** - * Fragment containing the RecyclerView which shows the current list of coffees being tracked. - */ -class CoffeeList : Fragment() { - - private lateinit var coffeeListViewModel: CoffeeListViewModel - - private val adapter = CoffeeListAdapter( - onEdit = { coffee -> - findNavController().navigate( - CoffeeListDirections.actionCoffeeListToCoffeeEntryDialogFragment(coffee.id) - ) - }, - onDelete = { coffee -> - NotificationManagerCompat.from(requireContext()).cancel(coffee.id.toInt()) - coffeeListViewModel.delete(coffee) - } - ) - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return CoffeeListBinding.inflate(inflater, container, false).root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val binding = CoffeeListBinding.bind(view) - val coffeeDao = SnackDatabase.getDatabase(requireContext()).coffeeDao() - - coffeeListViewModel = ViewModelProvider(this, CoffeeViewModelFactory(coffeeDao)) - .get(CoffeeListViewModel::class.java) - - coffeeListViewModel.coffeeList.observe(viewLifecycleOwner) { coffees -> - adapter.submitList(coffees) - } - - binding.recyclerView.adapter = adapter - - binding.fab.setOnClickListener { fabView -> - fabView.findNavController().navigate( - CoffeeListDirections.actionCoffeeListToCoffeeEntryDialogFragment() - ) - } - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeListAdapter.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeListAdapter.kt deleted file mode 100644 index 8fb0f86..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeListAdapter.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.coffee - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.RecyclerView -import com.android.samples.donuttracker.R -import com.android.samples.donuttracker.databinding.CoffeeItemBinding -import com.android.samples.donuttracker.model.Coffee - -/** - * The adapter used by the RecyclerView to display the current list of Coffees - */ -class CoffeeListAdapter( - private var onEdit: (Coffee) -> Unit, - private var onDelete: (Coffee) -> Unit -) : ListAdapter(CoffeeDiffCallback()) { - - class CoffeeListViewHolder( - private val binding: CoffeeItemBinding, - private var onEdit: (Coffee) -> Unit, - private var onDelete: (Coffee) -> Unit - ) : RecyclerView.ViewHolder(binding.root) { - - private var coffeeId: Long = -1 - private var nameView = binding.name - private var description = binding.description - private var thumbnail = binding.thumbnail - private var rating = binding.rating - private var coffee: Coffee? = null - - fun bind(coffee: Coffee) { - coffeeId = coffee.id - nameView.text = coffee.name - description.text = coffee.description - rating.text = coffee.rating.toString() - thumbnail.setImageResource(R.drawable.coffee_cup) - this.coffee = coffee - binding.deleteButton.setOnClickListener { - onDelete(coffee) - } - binding.root.setOnClickListener { - onEdit(coffee) - } - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = CoffeeListViewHolder( - CoffeeItemBinding.inflate(LayoutInflater.from(parent.context), parent, false), - onEdit, - onDelete - ) - - override fun onBindViewHolder(holder: CoffeeListViewHolder, position: Int) { - holder.bind(getItem(position)) - } -} - -class CoffeeDiffCallback : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: Coffee, newItem: Coffee): Boolean { - return oldItem.id == newItem.id - } - - override fun areContentsTheSame(oldItem: Coffee, newItem: Coffee): Boolean { - return oldItem == newItem - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeListViewModel.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeListViewModel.kt deleted file mode 100644 index a5a0f48..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeListViewModel.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.coffee - -import androidx.lifecycle.LiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.android.samples.donuttracker.model.Coffee -import com.android.samples.donuttracker.storage.CoffeeDao -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -/** - * This ViewModel is used to access the underlying data and to observe changes to it. - */ -class CoffeeListViewModel(private val coffeeDao: CoffeeDao) : ViewModel() { - - // Users of this ViewModel will observe changes to its coffees list to know when - // to redisplay those changes - val coffeeList: LiveData> = coffeeDao.getAll() - - fun delete(coffee: Coffee) = viewModelScope.launch(Dispatchers.IO) { - coffeeDao.delete(coffee) - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeViewModelFactory.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeViewModelFactory.kt deleted file mode 100644 index e4dd189..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/coffee/CoffeeViewModelFactory.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.coffee - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import com.android.samples.donuttracker.storage.CoffeeDao - -class CoffeeViewModelFactory(private val coffeeDao: CoffeeDao) : ViewModelProvider.Factory { - - override fun create(modelClass: Class): T { - if (modelClass.isAssignableFrom(CoffeeListViewModel::class.java)) { - @Suppress("UNCHECKED_CAST") - return CoffeeListViewModel(coffeeDao) as T - } else if (modelClass.isAssignableFrom(CoffeeEntryViewModel::class.java)) { - @Suppress("UNCHECKED_CAST") - return CoffeeEntryViewModel(coffeeDao) as T - } - throw IllegalArgumentException("Unknown ViewModel class") - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutEntryDialogFragment.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutEntryDialogFragment.kt deleted file mode 100644 index 74432ce..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutEntryDialogFragment.kt +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.donut - -import android.annotation.SuppressLint -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.viewModels -import androidx.lifecycle.observe -import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs -import com.android.samples.donuttracker.Notifier -import com.android.samples.donuttracker.R -import com.android.samples.donuttracker.databinding.DonutEntryDialogBinding -import com.android.samples.donuttracker.model.Donut -import com.android.samples.donuttracker.storage.SnackDatabase -import com.google.android.material.bottomsheet.BottomSheetDialogFragment - -/** - * This dialog allows the user to enter information about a donut, either creating a new - * entry or updating an existing one. - */ -class DonutEntryDialogFragment : BottomSheetDialogFragment() { - - private enum class EditingState { - NEW_DONUT, - EXISTING_DONUT - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return DonutEntryDialogBinding.inflate(inflater, container, false).root - } - - @SuppressLint("SetTextI18n") - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val donutDao = SnackDatabase.getDatabase(requireContext()).donutDao() - - val donutEntryViewModel: DonutEntryViewModel by viewModels { - DonutViewModelFactory(donutDao) - } - - val binding = DonutEntryDialogBinding.bind(view) - - var donut: Donut? = null - val args: DonutEntryDialogFragmentArgs by navArgs() - val editingState = - if (args.itemId > 0) { - EditingState.EXISTING_DONUT - } else { - EditingState.NEW_DONUT - } - - // If we arrived here with an itemId of >= 0, then we are editing an existing item - if (editingState == EditingState.EXISTING_DONUT) { - // Request to edit an existing item, whose id was passed in as an argument. - // Retrieve that item and populate the UI with its details - donutEntryViewModel.get(args.itemId).observe(viewLifecycleOwner) { donutItem -> - binding.apply { - name.setText(donutItem.name) - description.setText(donutItem.description) - ratingBar.rating = donutItem.rating.toFloat() - } - donut = donutItem - } - } - - // When the user clicks the Done button, use the data here to either update - // an existing item or create a new one - binding.doneButton.setOnClickListener { - // Grab these now since the Fragment may go away before the setupNotification - // lambda below is called - val context = requireContext().applicationContext - val navController = findNavController() - - donutEntryViewModel.addData( - donut?.id ?: 0, - binding.name.text.toString(), - binding.description.text.toString(), - binding.ratingBar.rating.toInt() - ) { actualId -> - val arg = DonutEntryDialogFragmentArgs(actualId).toBundle() - val pendingIntent = navController - .createDeepLink() - .setDestination(R.id.donutEntryDialogFragment) - .setArguments(arg) - .createPendingIntent() - - Notifier.postNotification(actualId, context, pendingIntent) - } - dismiss() - } - - // User clicked the Cancel button; just exit the dialog without saving the data - binding.cancelButton.setOnClickListener { - dismiss() - } - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutEntryViewModel.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutEntryViewModel.kt deleted file mode 100644 index 3c42716..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutEntryViewModel.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.donut - -import androidx.lifecycle.LiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.liveData -import androidx.lifecycle.viewModelScope -import com.android.samples.donuttracker.model.Donut -import com.android.samples.donuttracker.storage.DonutDao -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -class DonutEntryViewModel(private val donutDao: DonutDao) : ViewModel() { - - private var donutLiveData: LiveData? = null - - fun get(id: Long): LiveData { - return donutLiveData ?: liveData { - emit(donutDao.get(id)) - }.also { - donutLiveData = it - } - } - - fun addData( - id: Long, - name: String, - description: String, - rating: Int, - setupNotification: (Long) -> Unit - ) { - val donut = Donut(id, name, description, rating) - - CoroutineScope(Dispatchers.IO).launch { - var actualId = id - - if (id > 0) { - update(donut) - } else { - actualId = insert(donut) - } - - setupNotification(actualId) - } - } - - private suspend fun insert(donut: Donut): Long { - return donutDao.insert(donut) - } - - private fun update(donut: Donut) = viewModelScope.launch(Dispatchers.IO) { - donutDao.update(donut) - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutList.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutList.kt deleted file mode 100644 index 76846c1..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutList.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.donut - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.core.app.NotificationManagerCompat -import androidx.fragment.app.Fragment -import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.observe -import androidx.navigation.findNavController -import androidx.navigation.fragment.findNavController -import com.android.samples.donuttracker.databinding.DonutListBinding -import com.android.samples.donuttracker.storage.SnackDatabase - -/** - * Fragment containing the RecyclerView which shows the current list of donuts being tracked. - */ -class DonutList : Fragment() { - - private lateinit var donutListViewModel: DonutListViewModel - - private val adapter = DonutListAdapter( - onEdit = { donut -> - findNavController().navigate( - DonutListDirections.actionDonutListToDonutEntryDialogFragment(donut.id) - ) - }, - onDelete = { donut -> - NotificationManagerCompat.from(requireContext()).cancel(donut.id.toInt()) - donutListViewModel.delete(donut) - } - ) - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val binding = DonutListBinding.bind(view) - val donutDao = SnackDatabase.getDatabase(requireContext()).donutDao() - donutListViewModel = ViewModelProvider(this, DonutViewModelFactory(donutDao)) - .get(DonutListViewModel::class.java) - - donutListViewModel.donuts.observe(viewLifecycleOwner) { donuts -> - adapter.submitList(donuts) - } - - binding.recyclerView.adapter = adapter - - binding.fab.setOnClickListener { fabView -> - fabView.findNavController().navigate( - DonutListDirections.actionDonutListToDonutEntryDialogFragment() - ) - } - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return DonutListBinding.inflate(inflater, container, false).root - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutListAdapter.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutListAdapter.kt deleted file mode 100644 index b81b36c..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutListAdapter.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.donut - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.RecyclerView -import com.android.samples.donuttracker.R -import com.android.samples.donuttracker.databinding.DonutItemBinding -import com.android.samples.donuttracker.model.Donut - -/** - * The adapter used by the RecyclerView to display the current list of donuts - */ -class DonutListAdapter( - private var onEdit: (Donut) -> Unit, - private var onDelete: (Donut) -> Unit -) : ListAdapter(DonutDiffCallback()) { - - class DonutListViewHolder( - private val binding: DonutItemBinding, - private var onEdit: (Donut) -> Unit, - private var onDelete: (Donut) -> Unit - ) : RecyclerView.ViewHolder(binding.root) { - private var donutId: Long = -1 - private var nameView = binding.name - private var description = binding.description - private var thumbnail = binding.thumbnail - private var rating = binding.rating - private var donut: Donut? = null - - fun bind(donut: Donut) { - donutId = donut.id - nameView.text = donut.name - description.text = donut.description - rating.text = donut.rating.toString() - thumbnail.setImageResource(R.drawable.donut_with_sprinkles) - this.donut = donut - binding.deleteButton.setOnClickListener { - onDelete(donut) - } - binding.root.setOnClickListener { - onEdit(donut) - } - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = DonutListViewHolder( - DonutItemBinding.inflate(LayoutInflater.from(parent.context), parent, false), - onEdit, - onDelete - ) - - override fun onBindViewHolder(holder: DonutListViewHolder, position: Int) { - holder.bind(getItem(position)) - } -} - -class DonutDiffCallback : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: Donut, newItem: Donut): Boolean { - return oldItem.id == newItem.id - } - - override fun areContentsTheSame(oldItem: Donut, newItem: Donut): Boolean { - return oldItem == newItem - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutListViewModel.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutListViewModel.kt deleted file mode 100644 index d6ba069..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutListViewModel.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.donut - -import androidx.lifecycle.LiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.android.samples.donuttracker.model.Donut -import com.android.samples.donuttracker.storage.DonutDao -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -/** - * This ViewModel is used to access the underlying data and to observe changes to it. - */ -class DonutListViewModel(private val donutDao: DonutDao) : ViewModel() { - - // Users of this ViewModel will observe changes to its donuts list to know when - // to redisplay those changes - val donuts: LiveData> = donutDao.getAll() - - fun delete(donut: Donut) = viewModelScope.launch(Dispatchers.IO) { - donutDao.delete(donut) - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutViewModelFactory.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutViewModelFactory.kt deleted file mode 100644 index 765c7d3..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/donut/DonutViewModelFactory.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.donut - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import com.android.samples.donuttracker.storage.DonutDao - -class DonutViewModelFactory(private val donutDao: DonutDao) : ViewModelProvider.Factory { - - override fun create(modelClass: Class): T { - if (modelClass.isAssignableFrom(DonutListViewModel::class.java)) { - @Suppress("UNCHECKED_CAST") - return DonutListViewModel(donutDao) as T - } else if (modelClass.isAssignableFrom(DonutEntryViewModel::class.java)) { - @Suppress("UNCHECKED_CAST") - return DonutEntryViewModel(donutDao) as T - } - throw IllegalArgumentException("Unknown ViewModel class") - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/model/Coffee.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/model/Coffee.kt deleted file mode 100644 index aef8447..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/model/Coffee.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.model - -import androidx.room.Entity -import androidx.room.PrimaryKey - -/** - * This class holds the data that we are tracking for each cup of coffee: its name, a description, - * and a rating. - */ -@Entity -data class Coffee( - @PrimaryKey(autoGenerate = true) val id: Long, - val name: String, - val description: String = "", - val rating: Int -) diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/model/Donut.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/model/Donut.kt deleted file mode 100644 index 5b9191d..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/model/Donut.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.model - -import androidx.room.Entity -import androidx.room.PrimaryKey - -/** - * This class holds the data that we are tracking for each donut: its name, a description, and - * a rating. - */ -@Entity -data class Donut( - @PrimaryKey(autoGenerate = true) val id: Long, - val name: String, - val description: String = "", - val rating: Int -) diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/setup/SelectionFragment.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/setup/SelectionFragment.kt deleted file mode 100644 index 1ab939f..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/setup/SelectionFragment.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.setup - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.navigation.findNavController -import com.android.samples.donuttracker.databinding.FragmentSelectionBinding - -/** - * This Fragment enables/disables coffee tracking feature. - */ -class SelectionFragment : Fragment() { - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - // Inflate the layout for this fragment - return FragmentSelectionBinding.inflate(inflater, container, false).root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val binding = FragmentSelectionBinding.bind(view) - - binding.button.setOnClickListener { button -> - val coffeeEnabled = binding.checkBox.isSelected - //TODO enable coffee tracker - - button.findNavController().navigate( - SelectionFragmentDirections.actionSelectionFragmentToDonutList() - ) - } - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/CoffeeDao.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/CoffeeDao.kt deleted file mode 100644 index f3c9953..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/CoffeeDao.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.storage - -import androidx.lifecycle.LiveData -import androidx.room.Dao -import androidx.room.Delete -import androidx.room.Insert -import androidx.room.Query -import androidx.room.Update -import com.android.samples.donuttracker.model.Coffee - -@Dao -interface CoffeeDao { - @Query("SELECT * FROM coffee") - fun getAll(): LiveData> - - @Query("SELECT * FROM coffee WHERE id = :id") - suspend fun get(id: Long): Coffee - - @Insert - suspend fun insert(coffee: Coffee): Long - - @Delete - suspend fun delete(coffee: Coffee) - - @Update - suspend fun update(coffee: Coffee) -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/DonutDao.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/DonutDao.kt deleted file mode 100644 index d371a16..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/DonutDao.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.storage - -import androidx.lifecycle.LiveData -import androidx.room.Dao -import androidx.room.Delete -import androidx.room.Insert -import androidx.room.Query -import androidx.room.Update -import com.android.samples.donuttracker.model.Donut - -/** - * The Data Access Object used to retrieve and store data from/to the underlying database. - * This API is not used directly; instead, callers should use the Repository which calls into - * this DAO. - */ -@Dao -interface DonutDao { - @Query("SELECT * FROM donut") - fun getAll(): LiveData> - - @Query("SELECT * FROM donut WHERE id = :id") - suspend fun get(id: Long): Donut - - @Insert - suspend fun insert(donut: Donut): Long - - @Delete - suspend fun delete(donut: Donut) - - @Update - suspend fun update(donut: Donut) -} diff --git a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/SnackDatabase.kt b/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/SnackDatabase.kt deleted file mode 100644 index 869c615..0000000 --- a/DonutTracker/NavigationUI/app/src/main/java/com/android/samples/donuttracker/storage/SnackDatabase.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.samples.donuttracker.storage - -import android.content.Context -import androidx.room.Database -import androidx.room.Room -import androidx.room.RoomDatabase -import com.android.samples.donuttracker.model.Coffee -import com.android.samples.donuttracker.model.Donut - -/** - * The underlying database where information about the donuts is stored. - */ -@Database(entities = arrayOf(Donut::class, Coffee::class), version = 1) -abstract class SnackDatabase : RoomDatabase() { - - abstract fun donutDao(): DonutDao - - abstract fun coffeeDao(): CoffeeDao - - companion object { - @Volatile private var INSTANCE: SnackDatabase? = null - - fun getDatabase(context: Context): SnackDatabase { - val tempInstance = INSTANCE - if (tempInstance != null) { - return tempInstance - } - synchronized(this) { - val instance = Room.databaseBuilder( - context, - SnackDatabase::class.java, - "snack_database" - ).build() - INSTANCE = instance - return instance - } - } - } -} diff --git a/DonutTracker/NavigationUI/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/DonutTracker/NavigationUI/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 793e74f..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/DonutTracker/NavigationUI/app/src/main/res/drawable/coffee_cup.xml b/DonutTracker/NavigationUI/app/src/main/res/drawable/coffee_cup.xml deleted file mode 100644 index dbbce61..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/drawable/coffee_cup.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DonutTracker/NavigationUI/app/src/main/res/drawable/donut_with_sprinkles.xml b/DonutTracker/NavigationUI/app/src/main/res/drawable/donut_with_sprinkles.xml deleted file mode 100644 index a85b73f..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/drawable/donut_with_sprinkles.xml +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DonutTracker/NavigationUI/app/src/main/res/drawable/ic_clear_24px.xml b/DonutTracker/NavigationUI/app/src/main/res/drawable/ic_clear_24px.xml deleted file mode 100644 index 48373a7..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/drawable/ic_clear_24px.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - diff --git a/DonutTracker/NavigationUI/app/src/main/res/drawable/ic_launcher_background.xml b/DonutTracker/NavigationUI/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index b6ea9e0..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DonutTracker/NavigationUI/app/src/main/res/layout-w960dp/activity_main.xml b/DonutTracker/NavigationUI/app/src/main/res/layout-w960dp/activity_main.xml deleted file mode 100644 index b6df4a9..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/layout-w960dp/activity_main.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - diff --git a/DonutTracker/NavigationUI/app/src/main/res/layout/activity_main.xml b/DonutTracker/NavigationUI/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 5685d0a..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/DonutTracker/NavigationUI/app/src/main/res/layout/coffee_entry_dialog.xml b/DonutTracker/NavigationUI/app/src/main/res/layout/coffee_entry_dialog.xml deleted file mode 100644 index e7bdccd..0000000 --- a/DonutTracker/NavigationUI/app/src/main/res/layout/coffee_entry_dialog.xml +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -