Skip to content

Commit 28b509f

Browse files
committed
♻️ Add README.md. Refactor AndroidManifest.xml, MainActivity.kt, PastaFragment.kt, TopFragment.kt, CaptionedImagesAdapter.kt, Pizza.kt, build.gradle, gradle.properties, and gradle-wrapper.properties files.
Signed-off-by: Dmytro Turskyi <[email protected]>
1 parent 836d25d commit 28b509f

16 files changed

+113
-39
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)
2+
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/Turskyi/PastaAndPizzaz-NavDrawer">
3+
4+
# PastaAndPizzaz Delivery
5+
6+
A nice way of implementing a navigation drawer for an Android app. The project
7+
serves as a feature demonstration and doesn't have functional delivery
8+
capabilities.
9+
10+
## Features
11+
12+
- [Android](https://developer.android.com/studio/intro): Built
13+
using [Kotlin](https://kotlinlang.org/).
14+
- **Architecture
15+
**: [Monolith](https://en.wikipedia.org/wiki/Monolithic_architecture).
16+
- **Collapsing Toolbar**: For a smooth and dynamic UI.
17+
- **Grid of Pizzas**: Displays pizzas on the main screen; clicking opens a
18+
details screen.
19+
- **Order Form**: A "+" button in the app bar opens a form to order pizza.
20+
- **Share Button**: Includes options for Bluetooth and Nearby sharing.
21+
- **Code Readability:** code is easily readable with no unnecessary blank
22+
lines, no unused variables or methods, and no commented-out code, all
23+
variables, methods, and resource IDs are descriptively named such that another
24+
developer reading the code can easily understand their function.
25+
26+
## Screenshots
27+
28+
<!--suppress CheckImageSize -->
29+
<img src="screenshots/Main_Screenshot_20240723.png" width="200" alt="screenshot">
30+
<img src="screenshots/Form_Screenshot_20240723.png" width="200" alt="screenshot">
31+
<img src="screenshots/Menu_Screenshot_20240723.png" width="200" alt="screenshot">
32+
<img src="screenshots/Details_Screenshot_20240723.png" width="200" alt="screenshot">
33+
34+
## Installation Instructions
35+
36+
- Clone the repository:
37+
38+
```bash
39+
git clone https://github.com/Turskyi/PastaAndPizzaz-NavDrawer.git
40+
```
41+
42+
- Open the project in Android Studio.
43+
- Run the project on an emulator or a physical Android device.
44+
45+
## Usage
46+
47+
The project is intended for educational purposes. You can copy and paste the
48+
code for reuse in your own projects.
49+
50+
## Contributing
51+
52+
Contributions are welcome! Feel free to create a pull request into the `master`
53+
branch. However, please note that this is a sample app and contributions may
54+
not be necessary.
55+
56+
## License
57+
58+
No intentional license was used for this project.
59+
60+
## Acknowledgments
61+
62+
This project was inspired by the tutorial from the book "Head First Android
63+
Development" by Dawn Griffiths and David Griffiths.
64+

app/build.gradle

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 30
6-
buildToolsVersion "30.0.2"
5+
compileSdkVersion 34
76

87
defaultConfig {
98
applicationId "io.github.turskyi.pastaandpizzaz"
109
minSdkVersion 21
11-
targetSdkVersion 30
10+
targetSdkVersion 34
1211
versionCode 1
1312
versionName "1.0.0"
14-
13+
multiDexEnabled true
1514
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1615
}
1716
buildFeatures {
@@ -31,24 +30,23 @@ android {
3130
kotlinOptions {
3231
jvmTarget = '1.8'
3332
}
33+
namespace 'io.github.turskyi.pastaandpizzaz'
3434
}
3535

3636
dependencies {
3737
implementation fileTree(dir: "libs", include: ["*.jar"])
3838
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
39-
implementation 'androidx.core:core-ktx:1.3.2'
40-
implementation 'androidx.appcompat:appcompat:1.2.0'
39+
implementation 'androidx.core:core-ktx:1.13.1'
40+
implementation 'androidx.appcompat:appcompat:1.7.0'
4141
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
42-
implementation 'com.google.android.material:material:1.3.0'
43-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
44-
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
45-
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
42+
implementation 'com.google.android.material:material:1.12.0'
43+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
44+
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
45+
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
4646
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
47-
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
48-
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
49-
47+
implementation("androidx.multidex:multidex:2.0.1")
5048
testImplementation 'junit:junit:4.13.2'
51-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
52-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
49+
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
50+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
5351

5452
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="io.github.turskyi.pastaandpizzaz">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<application
65
android:allowBackup="true"
@@ -12,6 +11,7 @@
1211
android:theme="@style/AppTheme">
1312
<activity
1413
android:name=".MainActivity"
14+
android:exported="true"
1515
android:label="@string/app_name">
1616
<intent-filter>
1717
<action android:name="android.intent.action.MAIN" />

app/src/main/java/io/github/turskyi/pastaandpizzaz/MainActivity.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
4747
override fun onCreateOptionsMenu(menu: Menu): Boolean {
4848
/* Inflate the menu; this adds items to the app bar. */
4949
menuInflater.inflate(R.menu.menu_main, menu)
50-
val menuItem:MenuItem = menu.findItem(R.id.action_share)
51-
shareActionProvider = MenuItemCompat.getActionProvider(menuItem) as ShareActionProvider
50+
val menuItem: MenuItem = menu.findItem(R.id.action_share)
51+
shareActionProvider =
52+
MenuItemCompat.getActionProvider(menuItem) as ShareActionProvider
5253
"Want to join me for pizza?".setShareActionIntent()
5354
return super.onCreateOptionsMenu(menu)
5455
}
@@ -73,6 +74,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
7374
startActivity(intent)
7475
true
7576
}
77+
7678
else -> super.onOptionsItemSelected(item)
7779
}
7880
}
@@ -144,7 +146,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
144146
/* Populate the ListView */
145147
drawerList.adapter = ArrayAdapter(
146148
this,
147-
android.R.layout.simple_list_item_activated_1, titles as Array<out String>
149+
android.R.layout.simple_list_item_activated_1,
150+
titles as Array<out String>
148151
)
149152
/* Create the ActionBarDrawerToggle */
150153
drawerToggle = ActionBarDrawerToggle(
@@ -171,7 +174,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
171174
3 -> StoresFragment()
172175
else -> TopFragment()
173176
}
174-
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
177+
val fragmentTransaction: FragmentTransaction =
178+
supportFragmentManager.beginTransaction()
175179
fragmentTransaction.apply {
176180
/* adding a tag of "visible_fragment" to the replace() method. Every fragment that’s
177181
displayed in MainActivity will be tagged with this value. */
@@ -185,7 +189,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
185189
setActionBarTitle(position)
186190

187191
/* Close the drawer */
188-
val drawerLayout = findViewById<View>(R.id.drawer_layout) as DrawerLayout
192+
val drawerLayout =
193+
findViewById<View>(R.id.drawer_layout) as DrawerLayout
189194
drawerLayout.closeDrawer(drawerList)
190195
}
191196

app/src/main/java/io/github/turskyi/pastaandpizzaz/Pizza.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package io.github.turskyi.pastaandpizzaz
22

3-
data class Pizza constructor(
3+
data class Pizza(
44
val name: String,
55
val imageResourceId: Int
66
) {
7-
// imitating retrieving objects from datasource
7+
// Imitating retrieving objects from datasource.
88
companion object {
99
val pizzas = arrayOf(
1010
Pizza("Diavolo", R.drawable.pic_diavolo),

app/src/main/java/io/github/turskyi/pastaandpizzaz/ui/pasta/PastaFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.widget.ArrayAdapter
88
import androidx.fragment.app.ListFragment
99
import io.github.turskyi.pastaandpizzaz.R
1010

11-
1211
class PastaFragment : ListFragment() {
1312

1413
override fun onCreateView(

app/src/main/java/io/github/turskyi/pastaandpizzaz/ui/pizza/CaptionedImagesAdapter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class CaptionedImagesAdapter(
2020
fun onClick(position: Int)
2121
}
2222

23-
override fun getItemCount()= captions.size
23+
override fun getItemCount() = captions.size
2424

2525
fun setListener(listener: Listener?) {
2626
this.listener = listener
@@ -36,14 +36,14 @@ internal class CaptionedImagesAdapter(
3636

3737
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
3838
val cardView: CardView = holder.cardView
39-
val imageView = cardView.findViewById(R.id.info_image) as ImageView
39+
val imageView: ImageView = cardView.findViewById(R.id.info_image)
4040
val drawable: Drawable? = ContextCompat.getDrawable(
4141
cardView.context,
4242
imageIds[position]
4343
)
4444
imageView.setImageDrawable(drawable)
4545
imageView.contentDescription = captions[position]
46-
val textView = cardView.findViewById(R.id.info_text) as TextView
46+
val textView: TextView = cardView.findViewById(R.id.info_text)
4747
textView.text = captions[position]
4848
cardView.setOnClickListener {
4949
listener?.onClick(position)

app/src/main/java/io/github/turskyi/pastaandpizzaz/ui/top/TopFragment.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ import io.github.turskyi.pastaandpizzaz.ui.pizza.CaptionedImagesAdapter
1515
import io.github.turskyi.pastaandpizzaz.ui.pizza.PizzaDetailActivity
1616

1717

18-
class TopFragment :Fragment() {
18+
class TopFragment : Fragment() {
1919
override fun onCreateView(
2020
inflater: LayoutInflater, container: ViewGroup?,
2121
savedInstanceState: Bundle?
2222
): View {
23-
val layout: RelativeLayout = inflater.inflate(R.layout.fragment_top, container, false) as RelativeLayout
24-
val pizzaRecycler = layout.findViewById<View>(R.id.pizza_recycler) as RecyclerView
23+
val layout: RelativeLayout = inflater.inflate(
24+
R.layout.fragment_top,
25+
container,
26+
false
27+
) as RelativeLayout
28+
val pizzaRecycler =
29+
layout.findViewById<View>(R.id.pizza_recycler) as RecyclerView
2530
val pizzaNames = arrayOfNulls<String>(2)
2631
for (i in 0..1) {
2732
pizzaNames[i] = Pizza.pizzas[i].name
@@ -35,7 +40,7 @@ class TopFragment :Fragment() {
3540
val adapter = CaptionedImagesAdapter(pizzaNames, pizzaImages)
3641
pizzaRecycler.adapter = adapter
3742
adapter.setListener(object : CaptionedImagesAdapter.Listener {
38-
override fun onClick(position: Int) {
43+
override fun onClick(position: Int) {
3944
val intent = Intent(activity, PizzaDetailActivity::class.java)
4045
intent.putExtra(PizzaDetailActivity.EXTRA_PIZZA_ID, position)
4146
requireActivity().startActivity(intent)

app/src/main/res/layout/activity_order.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
android:layout_height="wrap_content"
6868
android:layout_gravity="end|bottom"
6969
android:layout_margin="16dp"
70+
android:contentDescription="@string/content_description_button"
7071
android:onClick="onClickDone"
71-
android:src="@drawable/ic_done_white_24dp"
72-
android:contentDescription="@string/content_description_button" />
72+
android:src="@drawable/ic_done_white_24dp" />
7373

7474
</androidx.coordinatorlayout.widget.CoordinatorLayout>

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.4.32"
3+
ext.kotlin_version = "2.0.0"
44
repositories {
55
google()
66
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:4.2.0'
9+
classpath 'com.android.tools.build:gradle:8.5.1'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111

1212
// NOTE: Do not place your application dependencies here; they belong
@@ -21,6 +21,6 @@ allprojects {
2121
}
2222
}
2323

24-
task clean(type: Delete) {
24+
tasks.register('clean', Delete) {
2525
delete rootProject.buildDir
2626
}

gradle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ android.useAndroidX=true
1818
# Automatically convert third-party libraries to use AndroidX
1919
android.enableJetifier=true
2020
# Kotlin code style for this project: "official" or "obsolete":
21-
kotlin.code.style=official
21+
kotlin.code.style=official
22+
android.defaults.buildfeatures.buildconfig=true
23+
android.nonTransitiveRClass=false
24+
android.nonFinalResIds=false

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
1.57 MB
Loading
1.08 MB
Loading
3.27 MB
Loading
1.44 MB
Loading

0 commit comments

Comments
 (0)