WIP Implementing detail

This commit is contained in:
Daniele Verducci (ZenPenguin) 2021-09-01 09:25:57 +02:00
parent c4f1415b94
commit 87be0931b3
9 changed files with 150 additions and 9 deletions

View File

@ -0,0 +1,7 @@
package it.danieleverducci.subitobeers
import it.danieleverducci.subitobeers.entities.Beer
interface BeerNavigation {
fun showBeerDetail(beer: Beer)
}

View File

@ -1,10 +1,11 @@
package it.danieleverducci.subitobeers package it.danieleverducci.subitobeers
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import it.danieleverducci.subitobeers.entities.Beer import it.danieleverducci.subitobeers.entities.Beer
import it.danieleverducci.subitobeers.ui.BeerDetailFragment
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity(), BeerNavigation {
companion object { companion object {
val TAG = "MainActivity" val TAG = "MainActivity"
@ -13,14 +14,26 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
} }
fun showBeerDetail(beer: Beer) { override fun showBeerDetail(beer: Beer) {
// TODO val detailFragment = BeerDetailFragment()
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, detailFragment)
.addToBackStack(null)
.commit()
}
override fun onBackPressed() {
super.onBackPressed()
val bsf = supportFragmentManager.backStackEntryCount
if(bsf == 0) {
super.onBackPressed()
} else {
supportFragmentManager.popBackStack()
}
} }
} }

View File

@ -0,0 +1,39 @@
package it.danieleverducci.subitobeers.ui
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import it.danieleverducci.subitobeers.databinding.FragmentBeerDetailBinding
class BeerDetailFragment : Fragment() {
lateinit var binding: FragmentBeerDetailBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentBeerDetailBinding.inflate(
LayoutInflater.from(container!!.context),
container,
false
)
// Populate view
return binding.root
}
override fun onStart() {
super.onStart()
activity?.actionBar?.setDisplayHomeAsUpEnabled(true);
}
override fun onStop() {
super.onStop()
activity?.actionBar?.setDisplayHomeAsUpEnabled(false);
}
}

View File

@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import it.danieleverducci.subitobeers.BeerNavigation
import it.danieleverducci.subitobeers.BeersRepository import it.danieleverducci.subitobeers.BeersRepository
import it.danieleverducci.subitobeers.R import it.danieleverducci.subitobeers.R
import it.danieleverducci.subitobeers.entities.Beer import it.danieleverducci.subitobeers.entities.Beer
@ -64,7 +65,10 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
* Called when an item is clicked in the list * Called when an item is clicked in the list
*/ */
override fun OnItemClicked(item: Beer) { override fun OnItemClicked(item: Beer) {
TODO("Not yet implemented") if (activity is BeerNavigation)
(activity as BeerNavigation).showBeerDetail(item);
else
throw IllegalStateException("Activity must implement BeerNavigation")
} }
/** /**

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20,3h-1L19,1h-2v2L7,3L7,1L5,1v2L4,3c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,5c0,-1.1 -0.9,-2 -2,-2zM20,21L4,21L4,8h16v13z"/>
</vector>

View File

@ -8,7 +8,7 @@
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container" android:id="@+id/fragment_container"
android:name="it.danieleverducci.subitobeers.BeersFragment" android:name="it.danieleverducci.subitobeers.ui.BeersFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
</androidx.fragment.app.FragmentContainerView> </androidx.fragment.app.FragmentContainerView>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.BeerDetailFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/beer_detail_pic"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<TextView
android:id="@+id/beer_detail_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:textSize="24dp"
android:textStyle="bold"
android:textColor="@color/design_default_color_primary"
android:text="@string/placeholder_beertitle"/>
<TextView
android:id="@+id/beer_detail_shortdesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:textStyle="bold"
android:text="@string/placeholder_tagline"/>
<TextView
android:id="@+id/beer_detail_firstbrewed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:drawablePadding="8dp"
android:gravity="center_vertical"
app:drawableStartCompat="@drawable/ic_firstbrewed"
app:drawableTint="@color/design_default_color_primary"
android:text="@string/placeholder_firstbrewed"/>
<TextView
android:id="@+id/beer_detail_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="50dp"
android:gravity="center"
android:text="@string/placeholder_description"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -28,7 +28,7 @@
android:ellipsize="end" android:ellipsize="end"
android:lines="1" android:lines="1"
android:maxLines="1" android:maxLines="1"
android:text="Beer name" android:text="@string/placeholder_beertitle"
android:textSize="20sp" android:textSize="20sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/beer_item_descr" app:layout_constraintBottom_toTopOf="@+id/beer_item_descr"
@ -45,7 +45,7 @@
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="3" android:maxLines="3"
android:text="Beer description lorem ipsum dolor sit amet" android:text="@string/placeholder_tagline"
app:layout_constraintBottom_toBottomOf="@+id/beer_item_pic" app:layout_constraintBottom_toBottomOf="@+id/beer_item_pic"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/beer_item_pic" app:layout_constraintStart_toEndOf="@+id/beer_item_pic"

View File

@ -6,4 +6,10 @@
<!-- Beers detail --> <!-- Beers detail -->
<!-- Generic placeholders -->
<string name="placeholder_beertitle">Beer name</string>
<string name="placeholder_tagline">Lorem ipsum dolor sit amet</string>
<string name="placeholder_firstbrewed">00/0000</string>
<string name="placeholder_description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tristique consectetur felis vel pretium. Praesent tincidunt vestibulum lacus, molestie rhoncus lacus fermentum vel. Morbi vel pulvinar sapien, sed ultrices arcu. Vivamus gravida nulla vel ex varius, vel consequat dolor tincidunt. Fusce maximus quis mi eget tristique. Aenean sed facilisis libero. Aliquam volutpat posuere fringilla. Praesent in lorem at elit ornare congue et quis quam. Maecenas tempus et purus ac rhoncus. Donec in pulvinar ex. Aliquam ac vehicula dolor. Nam vitae tortor id nibh congue sollicitudin id in nisi. Proin lorem eros, congue at euismod et, malesuada porta nunc. Proin laoreet massa ac mi lacinia, eget tincidunt odio vestibulum. Vestibulum fermentum nunc nunc, eget ultrices nisi tempor non. Curabitur lorem leo, fringilla et pellentesque a, pharetra id magna. </string>
</resources> </resources>