diff --git a/app/src/main/java/it/danieleverducci/subitobeers/BeerNavigation.kt b/app/src/main/java/it/danieleverducci/subitobeers/BeerNavigation.kt index 7a79cbd..0fe08ce 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/BeerNavigation.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/BeerNavigation.kt @@ -2,6 +2,9 @@ package it.danieleverducci.subitobeers import it.danieleverducci.subitobeers.entities.Beer +/** + * Fragment navigation interface + */ interface BeerNavigation { fun showBeerDetail(beer: Beer) } \ No newline at end of file diff --git a/app/src/main/java/it/danieleverducci/subitobeers/BeersRepository.kt b/app/src/main/java/it/danieleverducci/subitobeers/BeersRepository.kt index 910ca25..8f1116c 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/BeersRepository.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/BeersRepository.kt @@ -9,6 +9,10 @@ import retrofit2.Call import retrofit2.Callback import retrofit2.Response +/** + * Beers repository + * Allows to retrieve beers from Punk API via its Retrofit implementation + */ class BeersRepository { companion object { @@ -23,6 +27,7 @@ class BeersRepository { /** * Obtain a paginated list of beers from the server * Use page property to set the page + * Async: will call listener's onResponse() or onFailure() */ fun getBeers() { // Obtain beers @@ -54,6 +59,9 @@ class BeersRepository { more = true } + /** + * Listener for api callbacks + */ interface Listener { fun onBeersObtained(beers: List, more: Boolean) fun onFailure() diff --git a/app/src/main/java/it/danieleverducci/subitobeers/Config.kt b/app/src/main/java/it/danieleverducci/subitobeers/Config.kt index f607474..9d3c3d7 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/Config.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/Config.kt @@ -1,5 +1,8 @@ package it.danieleverducci.subitobeers +/** + * Static configuration file + */ object Config { val API_BASEURL = "https://api.punkapi.com/" } \ No newline at end of file diff --git a/app/src/main/java/it/danieleverducci/subitobeers/MainActivity.kt b/app/src/main/java/it/danieleverducci/subitobeers/MainActivity.kt index 4b1c352..8160552 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/MainActivity.kt @@ -8,6 +8,10 @@ import androidx.fragment.app.FragmentManager import it.danieleverducci.subitobeers.entities.Beer import it.danieleverducci.subitobeers.ui.BeerDetailFragment +/** + * App entrypoint + * An activity with two fragments (list + detail) + */ class MainActivity : AppCompatActivity(), BeerNavigation { override fun onCreate(savedInstanceState: Bundle?) { @@ -15,6 +19,10 @@ class MainActivity : AppCompatActivity(), BeerNavigation { setContentView(R.layout.activity_main) } + /** + * Show beer detail fragment + * @param beer to show in detail + */ override fun showBeerDetail(beer: Beer) { val detailFragment = BeerDetailFragment(beer) supportFragmentManager.beginTransaction() @@ -25,6 +33,7 @@ class MainActivity : AppCompatActivity(), BeerNavigation { } override fun onBackPressed() { + // Manage fragment navigation val bsf = supportFragmentManager.backStackEntryCount if(bsf == 0) { super.onBackPressed() diff --git a/app/src/main/java/it/danieleverducci/subitobeers/entities/Beer.kt b/app/src/main/java/it/danieleverducci/subitobeers/entities/Beer.kt index 20f17cb..69e93b0 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/entities/Beer.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/entities/Beer.kt @@ -2,6 +2,9 @@ package it.danieleverducci.subitobeers.entities import com.google.gson.annotations.SerializedName +/** + * Represents a Punk API's (https://punkapi.com/documentation/v2) beer item + */ class Beer { val id: Int = 0 val name: String = "" diff --git a/app/src/main/java/it/danieleverducci/subitobeers/networking/BeersFilter.kt b/app/src/main/java/it/danieleverducci/subitobeers/networking/BeersFilter.kt index 12d2c99..cca0504 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/networking/BeersFilter.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/networking/BeersFilter.kt @@ -3,6 +3,9 @@ package it.danieleverducci.subitobeers.networking import android.util.Log import java.util.* +/** + * Class to represent a beer filter. Filters by brewing date. + */ class BeersFilter { // The date format is like "09/2007" (MM/YYYY). Month start from 1. var brewedBefore: String? = null @@ -17,6 +20,9 @@ class BeersFilter { val brewedAfterMonth: Int get() = getMonth(brewedAfter) + /** + * Clears filter + */ fun clear() { brewedBefore = null brewedAfter = null diff --git a/app/src/main/java/it/danieleverducci/subitobeers/networking/PunkAPI.kt b/app/src/main/java/it/danieleverducci/subitobeers/networking/PunkAPI.kt index a0596e7..d1af751 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/networking/PunkAPI.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/networking/PunkAPI.kt @@ -5,11 +5,16 @@ import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Query +/** + * Punk API description for Retrofit + */ interface PunkAPI { + @GET("/v2/beers?per_page=10") fun getBeers( @Query("page") page: Int, @Query("brewed_before") brewedBefore: String?, @Query("brewed_after") brewedAfter: String? ): Call> + } \ No newline at end of file diff --git a/app/src/main/java/it/danieleverducci/subitobeers/networking/RetrofitProvider.kt b/app/src/main/java/it/danieleverducci/subitobeers/networking/RetrofitProvider.kt index bd6757e..efc998c 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/networking/RetrofitProvider.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/networking/RetrofitProvider.kt @@ -7,7 +7,14 @@ import okhttp3.OkHttpClient import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +/** + * Provider for Punk API Retrofit implementation + */ object RetrofitProvider { + + /** + * Punk API Retrofit client + */ val getClient: PunkAPI get() { diff --git a/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerDetailFragment.kt b/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerDetailFragment.kt index a3d0715..153a532 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerDetailFragment.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerDetailFragment.kt @@ -10,6 +10,9 @@ import it.danieleverducci.subitobeers.R import it.danieleverducci.subitobeers.databinding.FragmentBeerDetailBinding import it.danieleverducci.subitobeers.entities.Beer +/** + * A simple beer detail fragment, with an image and some textual data + */ class BeerDetailFragment(val beer: Beer) : Fragment() { lateinit var binding: FragmentBeerDetailBinding diff --git a/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerRecyclerAdapter.kt b/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerRecyclerAdapter.kt index 4919d62..16c7a1c 100644 --- a/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerRecyclerAdapter.kt +++ b/app/src/main/java/it/danieleverducci/subitobeers/ui/BeerRecyclerAdapter.kt @@ -13,6 +13,9 @@ import it.danieleverducci.subitobeers.R import it.danieleverducci.subitobeers.databinding.FragmentBeersListitemBinding import it.danieleverducci.subitobeers.entities.Beer +/** + * RecyclerAdapter for beers list RecyclerView + */ class BeerRecyclerAdapter : RecyclerView.Adapter() { // The click event listener @@ -102,6 +105,9 @@ class BeerRecyclerAdapter : RecyclerView.Adapter val progress: ProgressBar = binding.beerItemProgress } + /** + * List event listener + */ interface Listener { fun OnItemClicked(item: Beer) fun OnLastItemScrolled()