Skip to content

Commit

Permalink
Merge pull request #12 from AliElDerawi/code_improvements
Browse files Browse the repository at this point in the history
feat: Code improvements
  • Loading branch information
AliElDerawi authored Jan 6, 2025
2 parents a6b891c + 338929f commit 7b945eb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface AsteroidDao {
): Flow<List<AsteroidModel>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(vararg asteroidList: AsteroidModel)
suspend fun insertAll(vararg asteroidList: AsteroidModel)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MainActivity : AppCompatActivity() {
root.applyWindowsPadding()
setStatusBarColorAndStyle(getCompatColor(R.color.colorPrimary))
}
setTitle(R.string.app_name)
initListener()
initViewModelObserver()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package com.udacity.asteroidradar.features.main.view

import android.content.Context
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Lifecycle
import com.udacity.asteroidradar.R
import com.udacity.asteroidradar.api.AsteroidApiFilter
import com.udacity.asteroidradar.api.models.AsteroidModel
import com.udacity.asteroidradar.databinding.FragmentMainBinding
import com.udacity.asteroidradar.data.BaseFragment
import com.udacity.asteroidradar.data.NavigationCommand
import com.udacity.asteroidradar.features.main.viewModel.MainViewModel
import com.udacity.asteroidradar.databinding.FragmentMainBinding
import com.udacity.asteroidradar.features.main.adapter.AsteroidItemAdapter
import com.udacity.asteroidradar.features.main.viewModel.MainViewModel
import com.udacity.asteroidradar.util.AppSharedMethods.setDisplayHomeAsUpEnabled
import com.udacity.asteroidradar.util.AppSharedMethods.setTitle
import org.koin.android.ext.android.inject
Expand Down Expand Up @@ -68,14 +72,17 @@ class MainFragment : BaseFragment() {
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
mViewModel.updateSelectedItem(0)
mViewModel.updateFilter(
when (menuItem.itemId) {
R.id.show_week_menu -> AsteroidApiFilter.SHOW_WEEK
R.id.show_today_menu -> AsteroidApiFilter.SHOW_TODAY
else -> AsteroidApiFilter.SHOW_SAVED
}
)
with(mViewModel){
updateSelectedItem(0)
updateFilter(
when (menuItem.itemId) {
R.id.show_week_menu -> AsteroidApiFilter.SHOW_WEEK
R.id.show_today_menu -> AsteroidApiFilter.SHOW_TODAY
else -> AsteroidApiFilter.SHOW_SAVED
}
)
}

return true
}
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="viewModel"
type="com.udacity.asteroidradar.features.main.viewModel.MainViewModel" />

<variable
name="mLifecycleOwner"
type="androidx.lifecycle.LifecycleOwner" />

</data>

<androidx.core.widget.NestedScrollView
Expand Down

0 comments on commit 7b945eb

Please sign in to comment.