Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Migrate to Compose Navigation and delete fragments (#827)
Browse files Browse the repository at this point in the history
* Migrate PlantListFragment content to Compose.

Change-Id: Ic6789a43249d93eba333cfbaba9eea0f1f042009

* Update tests.

Change-Id: I623bcbb75fd8d6e10bc882c961fafbc5636516e3

* Migrate HomeViewPagerFragment to Compose.

Change-Id: I52ad72604742bb89255980c27b5a5808e1fb43f0

* Use HorizontalPager in Compose 1.4.0

Change-Id: Ia552340497a889d9bc03a88c99ebf13d98455010

* Update migration journey.

Change-Id: I6fb161f6e8efb58dd8f1e435111ea30e2116f239

* Migrate to Compose Navigation and delete fragments.

Change-Id: Ice6a7a1f720cd242349a47054cf5f7b40285ed79

* Update migration journey.

Change-Id: I2ff9b1cd1bea6d16d83f5b082ac7071a5a7c7e31

* Delete unused assets.

Change-Id: I1abd27a79f8d637f1c8076ddd570f518e2020ba7

* PR feedback.

Change-Id: I6666aea6868467255d880fe84fdc658766a279ad
  • Loading branch information
arriolac committed Feb 7, 2023
1 parent bea8e85 commit 28bb121
Show file tree
Hide file tree
Showing 31 changed files with 224 additions and 845 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ plugins {
id("kotlin-parcelize")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
id("androidx.navigation.safeargs.kotlin")
}

android {
Expand Down Expand Up @@ -114,11 +113,9 @@ dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.fragment.ktx)
implementation(libs.androidx.lifecycle.livedata.ktx)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.paging.compose)
implementation(libs.androidx.paging.runtime.ktx)
implementation(libs.androidx.room.ktx)
Expand All @@ -131,6 +128,7 @@ dependencies {
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.hilt.android)
implementation(libs.hilt.navigation.compose)
implementation(libs.androidx.profileinstaller)
implementation(libs.androidx.tracing.ktx)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,66 @@
package com.google.samples.apps.sunflower

import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.MenuProvider
import androidx.core.view.WindowCompat
import androidx.databinding.DataBindingUtil.setContentView
import com.google.samples.apps.sunflower.databinding.ActivityGardenBinding
import com.google.accompanist.themeadapter.material.MdcTheme
import com.google.samples.apps.sunflower.compose.SunflowerApp
import com.google.samples.apps.sunflower.compose.home.SunflowerPage
import com.google.samples.apps.sunflower.viewmodels.PlantListViewModel
import dagger.hilt.android.AndroidEntryPoint

// TODO: update the superclass to ComponentActivity https://github.com/android/sunflower/issues/829
@AndroidEntryPoint
class GardenActivity : AppCompatActivity() {

private val viewModel: PlantListViewModel by viewModels()

private val menuProvider = object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.menu_plant_list, menu)
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
R.id.filter_zone -> {
viewModel.updateData()
true
}
else -> false
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Displaying edge-to-edge
WindowCompat.setDecorFitsSystemWindows(window, false)

setContentView<ActivityGardenBinding>(this, R.layout.activity_garden)
setContent {
MdcTheme {
SunflowerApp(
onAttached = { toolbar ->
setSupportActionBar(toolbar)
},
onPageChange = { page ->
when (page) {
SunflowerPage.MY_GARDEN -> removeMenuProvider(menuProvider)
SunflowerPage.PLANT_LIST -> addMenuProvider(
menuProvider,
this
)
}
}
)
}
}
}
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 28bb121

Please sign in to comment.