Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/app demo #2

Merged
merged 196 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
a29040c
feat: created empty project
xeewii Jun 14, 2024
a17f7f6
feat: created start screen fragment
xeewii Jun 14, 2024
15db6ce
feat: designed home bottom navigation view
xeewii Jun 14, 2024
75110e1
feat: added main screen view pager
xeewii Jun 14, 2024
a12dcad
feat: added main top app bar
xeewii Jun 17, 2024
26b3d77
feat: added recommendation block
xeewii Jun 17, 2024
0829c94
feat: added card product view
xeewii Jun 17, 2024
bc6df14
feat: added graphs to main fragments
xeewii Jun 18, 2024
c25071d
feat: added card fragment
xeewii Jun 18, 2024
ebd5f79
feat: integrated rees46 sdk
xeewii Jun 19, 2024
c5a207f
refactor: moved view to core ui
xeewii Jun 19, 2024
1f32903
feat: created home adapter for different views
xeewii Jun 20, 2024
ffc3aee
feat: fixed back pressing
xeewii Jun 20, 2024
50128c6
feat: added menu
xeewii Jun 20, 2024
461cacb
feat: added cart fragment
xeewii Jun 21, 2024
8b05663
feat: added customize recommendation block view
xeewii Jun 21, 2024
02b4857
fix: fixed build
xeewii Jun 21, 2024
941692a
feat: added recommend block by real data
xeewii Jun 26, 2024
506947d
feat: added card product by real data
xeewii Jun 26, 2024
019445b
feat: updated sdk with recommendation methods
xeewii Jul 3, 2024
4a9662c
feat: implemented basic work with cart
xeewii Jul 3, 2024
4c8da82
feat: implemented searching
xeewii Jul 3, 2024
d1d0c96
chore: updated lib versions and removed useless
xeewii Jul 3, 2024
c4f3397
feat: implemented mock for getting product for cart
xeewii Jul 3, 2024
a34a238
refactor: common changes
xeewii Jul 3, 2024
ec315bc
feat: changed recommendation block ui
xeewii Jul 3, 2024
855fd5c
feat: added blocks to home
xeewii Jul 3, 2024
998523e
refactor: card product changes
xeewii Jul 3, 2024
b64e864
feat: changed ui
xeewii Jul 4, 2024
810bea2
refactor: card product changes
xeewii Jul 4, 2024
042d261
fix: fixed adding and removing product from cart
xeewii Jul 4, 2024
06ccfd6
feat: added showing categories to search
xeewii Jul 4, 2024
3af4e3a
feat: changed ui
xeewii Jul 4, 2024
6f06172
feat: improved cart
xeewii Jul 4, 2024
26d7bbd
feat: removed useless
xeewii Jul 4, 2024
5f0a97b
refactor: separated entities model
xeewii Jul 8, 2024
8fcb0a3
refactor: separated main feature modules
xeewii Jul 8, 2024
7cca3b9
refactor: separated card product module
xeewii Jul 8, 2024
ceaeee3
refactor: removed base card product view
xeewii Jul 8, 2024
93a8d0b
refactor: separated di
xeewii Jul 8, 2024
356fc27
refactor: moved feature to domain module
xeewii Jul 8, 2024
2590ce6
refactor: renamed entities to DTO
xeewii Jul 8, 2024
7f08aea
refactor: renamed StartScreenFragment to RootFragment
xeewii Jul 8, 2024
101fe2b
refactor: moved BaseFragment to base package
xeewii Jul 8, 2024
50a2be5
refactor: removed useless class
xeewii Jul 8, 2024
527d583
refactor: separated adapters
xeewii Jul 8, 2024
818d828
refactor: simplified di modules
xeewii Jul 8, 2024
d87bfdd
refactor: minor changes
xeewii Jul 8, 2024
78f5d7f
feat: updated sdk
xeewii Jul 9, 2024
680feff
refactor: created presentation module
xeewii Jul 14, 2024
8d2a693
refactor (cart): implemented cart use cases
xeewii Jul 14, 2024
eb363c0
refactor (recommendation): implemented recommendation use cases
xeewii Jul 14, 2024
a8e839e
refactor (presentation): moved home, category and settings to present…
xeewii Jul 14, 2024
36b1e58
refactor (presentation): moved card product to presentation module
xeewii Jul 14, 2024
8b56520
refactor (search): implemented search use cases
xeewii Jul 14, 2024
d0a35f3
refactor (entities): renamed entities
xeewii Jul 14, 2024
84c82e7
fix (di): changed product module
xeewii Jul 14, 2024
91afea3
refactor (di): moved sdk module to data
xeewii Jul 14, 2024
e739008
refactor (entity): implemented category entity
xeewii Jul 14, 2024
6c1b870
refactor (presentation): moved classes to presentation folder
xeewii Jul 14, 2024
9828fa1
refactor (app): renamed presentation to app module
xeewii Jul 14, 2024
bde722f
refactor (di): separated data module
xeewii Jul 15, 2024
8bfb6f8
refactor (recommendation): implemented recommendation entity
xeewii Jul 15, 2024
19bc8c2
feat (recommendation): implemented showing all recommendation products
xeewii Jul 15, 2024
e149d3b
feat (ui): changed views by design
xeewii Jul 15, 2024
5635e48
feat (ui): made old price strikethrough
xeewii Jul 15, 2024
d7d11e1
refactor (ui): moved BaseFragment to app
xeewii Jul 15, 2024
148fe75
refactor (ui): replaced onResume to onViewCreated
xeewii Jul 15, 2024
dadc11d
refactor (domain): separated use cases by features
xeewii Jul 15, 2024
fea9432
refactor (di): moved sdk module to app
xeewii Jul 15, 2024
54f9f8a
refactor (models): renamed entities to dto
xeewii Jul 15, 2024
671d547
fix (ui): changed margin for recommendation in cart
xeewii Jul 15, 2024
f23deab
fix (recommendation): added missing showing all products by recommend…
xeewii Jul 15, 2024
7d3a35b
fix (ui): changed color and padding search view
xeewii Jul 15, 2024
f39bca2
fix (ui): changed showing title in recommendation block
xeewii Jul 15, 2024
afff3b2
docs (readme): add main information
xeewii Jul 15, 2024
504dc56
feat (settings): create settings fragment
xeewii Jul 16, 2024
8acc117
refactor (card product): union card product view and fragment
xeewii Jul 17, 2024
4c3aaa6
fix (ui): change margin for elements in card product views
xeewii Jul 17, 2024
6f8f6ff
feat (ui): add shop button to card product
xeewii Jul 17, 2024
e60477a
feat (ui): show product rating
xeewii Jul 17, 2024
ee75317
feat (ui): improved fragment card product
xeewii Jul 17, 2024
9f3ae52
feat (ui): add error fragment
xeewii Jul 17, 2024
7f8e338
feat (cart): add open cart by top app bar
xeewii Jul 17, 2024
8de1e3b
fix (cart): navigation to card product
xeewii Jul 17, 2024
c68a42d
chore (icon): change app icon
xeewii Jul 17, 2024
e488e25
refactor (splash screen): improve splash screen
xeewii Jul 17, 2024
ce94e26
feat (status bar): add status bar
xeewii Jul 17, 2024
7abad8d
feat (ui): remove loading image
xeewii Jul 17, 2024
3918b34
feat (ui): show recommendation only after loading products
xeewii Jul 17, 2024
e668171
chore (ui): removed useless res
xeewii Jul 17, 2024
3e5eb69
fix (navigation): back pressed navigation
xeewii Jul 17, 2024
c65ebe3
refactor (app): moved view models to domain module
xeewii Jul 17, 2024
d8094db
refactor (navigation): improve bottom navigation
xeewii Jul 17, 2024
fb17744
refactor (ui): move top bar and search view to main activity
xeewii Jul 17, 2024
af37984
refactor (product details): renamed card product to product details
xeewii Jul 17, 2024
d58c087
refactor (feature): separated modules by feature
xeewii Jul 17, 2024
66ec016
refactor (utils): remove useless fragment utils
xeewii Jul 17, 2024
f804e4e
refactor (utils): moved utils to core
xeewii Jul 17, 2024
46af71a
refactor (di): moved sdk module to core
xeewii Jul 17, 2024
4162d4c
refactor (presentation): remove BaseFragment
xeewii Jul 17, 2024
0b6f27f
refactor (res): change res names
xeewii Jul 17, 2024
5127905
refactor (style): change codestyle
xeewii Jul 18, 2024
946c181
refactor (app): move DemoApplication to app
xeewii Jul 18, 2024
a19f5a7
refactor (search): separated search view from main activity
xeewii Jul 18, 2024
c3b6f7b
refactor (navigation): create navigator
xeewii Jul 18, 2024
1606d96
refactor (products): move products
xeewii Jul 18, 2024
9fbce65
refactor (products): revert products showing
xeewii Jul 18, 2024
39f0ac5
refactor (models): separate domain and data models
xeewii Jul 18, 2024
e45c5f6
fix (search): make parent field nullable in category
xeewii Jul 18, 2024
0488bf1
refactor (ui): change ui for design
xeewii Jul 18, 2024
ca53137
refactor (card product): union products adapter
xeewii Jul 18, 2024
5cd9204
refactor (use case): change methods names
xeewii Jul 18, 2024
e902adc
fix (category): inflate category fragment
xeewii Jul 18, 2024
a183543
fix (recommendation): change start padding
xeewii Jul 18, 2024
f69ab87
fix (products): revert navigation to products from details
xeewii Jul 18, 2024
cedff82
refactor (view): replace visibility view to is visible
xeewii Jul 18, 2024
08c19a9
style (view): change if's
xeewii Jul 18, 2024
3ec5df1
refactor (presentation): rename click listener
xeewii Jul 18, 2024
afe985e
refactor (ui): change view cart product item layout to linear
xeewii Jul 18, 2024
09eb4f5
fix (navigation): add changing bottom tab when back press
xeewii Jul 18, 2024
d6423fd
fix (presentation): made recommendation slow by replay one
xeewii Jul 18, 2024
e7cc350
chore (version): update java version to 22
xeewii Jul 25, 2024
2bf6706
fix (app): extend MainActivity from LifecycleOwner
xeewii Jul 25, 2024
e01cf7f
style (name): rename mainActivity parameter to navController
xeewii Jul 25, 2024
8914b57
refactor (cart): change flow for cart products
xeewii Jul 25, 2024
b5c28f1
refactor (recommendation): change flow for recommendation block
xeewii Jul 25, 2024
630c123
refactor (search): change shared flow to state
xeewii Jul 25, 2024
e56c863
refactor (image): made update image extension function
xeewii Jul 25, 2024
b719f75
feat (cart): add listener callback for add and remove product to cart
xeewii Jul 25, 2024
496a0dc
refactor (di): change creating cart in di
xeewii Jul 25, 2024
06c063a
refactor (lifecycle): replace lifecycleScope to viewLifecycleOwner.li…
xeewii Jul 25, 2024
6c20c22
refactor (navigation): add navigation argument fields constants
xeewii Jul 25, 2024
cd23925
style: pass parameters explicitly
xeewii Jul 25, 2024
f3ffd1d
refactor (utils): remove useless function
xeewii Jul 25, 2024
856f80e
refactor (sdk): initialize sdk in app instead koin module
xeewii Jul 26, 2024
a2d06b2
refactor (sdk): add default field for sdk initialize
xeewii Jul 26, 2024
16c1917
refactor (cart): change updating cart sum price
xeewii Jul 26, 2024
0e2935e
style (cart): change work with flow
xeewii Jul 26, 2024
7f4902b
refactor (cart): remove useless updating list
xeewii Jul 26, 2024
240cf8a
refactor (sdk): create sdk settings
xeewii Jul 26, 2024
2556310
refactor (settings): create recommendation settings
xeewii Jul 26, 2024
1198fd9
chore (version): updated gradle plugin to 8.5.1 version
xeewii Jul 30, 2024
054c495
feat (data): implement data mappers
xeewii Jul 30, 2024
7937cd5
feat (image): move loading image to data module
xeewii Jul 30, 2024
c0bee29
feat (flow): replace Flow to StateFlow
xeewii Jul 30, 2024
ef87c9c
feat (image): revert load image on demand
xeewii Jul 31, 2024
3e75100
style: add last empty lines to files
xeewii Jul 31, 2024
78feb04
style (usecase): rename execute methods to invoke
xeewii Jul 31, 2024
d42cb5d
docs (readme): add versions java, kotlin, gradle
xeewii Jul 31, 2024
2bb18e5
feat (product): check product nullable
xeewii Jul 31, 2024
74f39a9
feat (stories): move init stories to onViewCreated
xeewii Jul 31, 2024
f40c54d
style (enum): rename ProductAction enum
xeewii Jul 31, 2024
f339af4
refactor (recommendation): move cart recommended code to Recommendati…
xeewii Jul 31, 2024
a21494e
refactor (ui): create separated buttons
xeewii Aug 1, 2024
1b54e3f
refactor (ui): create common item adapter
xeewii Aug 2, 2024
42a85e9
refactor (ui): implement recommendation recycler view
xeewii Aug 2, 2024
c54fbd1
refactor (ui): implement scroll products recycler view
xeewii Aug 2, 2024
a9c58b1
refactor (ui): implement cart products recycler view
xeewii Aug 2, 2024
6536b95
refactor (ui): implement search products recycler view
xeewii Aug 2, 2024
e6e61a7
refactor (ui): implement search categories recycler view
xeewii Aug 2, 2024
25b4623
refactor (ui): union search products and categories adapters
xeewii Aug 3, 2024
1a088c6
refactor (ui): union search results
xeewii Aug 3, 2024
8527da4
refactor (ui): separated search recyclers
xeewii Aug 3, 2024
f9289c5
refactor (ui): use binding in custom view
xeewii Aug 3, 2024
6af0b23
refactor (ui): replace recycler adapter to list adapter
xeewii Aug 3, 2024
8825565
fix (ui): change areItemsTheSame method for SearchItem
xeewii Aug 3, 2024
0a3440c
refactor (ui): mode items to ListRecyclerView
xeewii Aug 3, 2024
7d8c4da
refactor (ui): create custom common buttons
xeewii Aug 4, 2024
f48d126
refactor (ui): change common buttons
xeewii Aug 4, 2024
c1a891f
refactor (ui): move view_error to ui
xeewii Aug 4, 2024
718b46e
refactor (ui): separate count card view
xeewii Aug 4, 2024
94b9a36
refactor (utils): separate and rename utils
xeewii Aug 5, 2024
95d992f
refactor (ui): add stings to res
xeewii Aug 5, 2024
319f74e
chore: change app name to DEMOSTORE
xeewii Aug 5, 2024
25f0205
refactor (ui): separate resources
xeewii Aug 5, 2024
bc52d82
refactor (core): rename navigator utils to settings
xeewii Aug 5, 2024
39005d2
refactor (ui): take out styles for product details fragment
xeewii Aug 5, 2024
73a213e
refactor (view): separate product details description view
xeewii Aug 6, 2024
7ed882e
refactor (ui): rename recycler item to RecyclerViewItem
xeewii Aug 6, 2024
5f801c9
refactor (ui): move cart views to feature
xeewii Aug 6, 2024
368e943
refactor (ui): move products recycler views to feature
xeewii Aug 6, 2024
953f7be
refactor (ui): move search recycler views to feature
xeewii Aug 7, 2024
25f583a
refactor (ui): separate base recycler views
xeewii Aug 7, 2024
5562474
refactor (ui): separate buttons
xeewii Aug 7, 2024
a603e9a
refactor (ui): separate navigation to module
xeewii Aug 7, 2024
5f42551
refactor (ui): create error layout view
xeewii Aug 7, 2024
223a14b
refactor (ui): move count cart view to feature
xeewii Aug 7, 2024
792bc58
refactor (ui): separate old price text to view
xeewii Aug 7, 2024
f091bdc
refactor (ui): separate ViewColor.utils to extension
xeewii Aug 7, 2024
4c6b3e2
refactor (ui): create context extensions from dimensions converter utils
xeewii Aug 7, 2024
1ed43d2
refactor (ui): create view product details sale card
xeewii Aug 7, 2024
4442de2
refactor (ui): separate dimens
xeewii Aug 7, 2024
04d6226
refactor (ui): separate colors
xeewii Aug 7, 2024
3ccd6b6
refactor (ui): move styles to views
xeewii Aug 7, 2024
bc0bf58
refactor (res): separate resources by modules
xeewii Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# demo-android
Demo app
# REES46 Demo Android

## Description

REES46 Demo Android - application to demonstrate working with SDK.

## Configure

Versions:
Java 22
Kotlin 2.0.0
Gradle 8.8
Android Gradle Plugin 8.5.1

Copy `google-services.json` file from [Firebase console](https://console.firebase.google.com/u/0/) to app module.

## Documentation

For detailed information on methods used from the SDK, please refer to the documentation available at the following link:

[Official API references](https://reference.api.rees46.com/#introduction)
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
59 changes: 59 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
id("com.google.gms.google-services")
id("androidx.navigation.safeargs.kotlin")
}

android {
namespace = "rees46.demo_android.app"
compileSdk = 34

defaultConfig {
applicationId = "rees46.demo_android"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_22
targetCompatibility = JavaVersion.VERSION_22
}
kotlinOptions {
jvmTarget = "22"
}
buildFeatures {
viewBinding = true
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.koin.core)
implementation(libs.koin.android)
implementation(libs.koin.compat)
implementation(libs.androidx.navigation.fragment)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.androidx.core.splashscreen)
implementation(project(":core"))
implementation(project(":feature"))
implementation(project(":navigation"))
implementation(project(":sdkRees46"))
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".DemoApplication"
android:allowBackup="true"
android:icon="@drawable/ic_app"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_app"
android:supportsRtl="true"
android:theme="@style/Theme.Demoandroid.Starting"
tools:targetApi="31">
<activity
android:name=".presentation.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
59 changes: 59 additions & 0 deletions app/src/main/java/rees46/demo_android/app/DemoApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package rees46.demo_android.app

import android.app.Application
import com.personalizatio.SDK
import org.koin.android.ext.android.getKoin
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import rees46.demo_android.app.di.navigatorModule
import rees46.demo_android.core.di.sdkModule
import rees46.demo_android.core.utils.SdkUtils
import rees46.demo_android.feature.cart.di.cartModule
import rees46.demo_android.feature.category.di.categoryModule
import rees46.demo_android.feature.home.di.homeModule
import rees46.demo_android.feature.productDetails.di.productDetailsModule
import rees46.demo_android.feature.products.di.productsModule
import rees46.demo_android.feature.recommendationBlock.di.recommendationBlockModule
import rees46.demo_android.feature.search.di.searchModule
import rees46.demo_android.feature.settings.di.settingsModule

class DemoApplication : Application() {

override fun onCreate() {
super.onCreate()

startKoin {
androidContext(this@DemoApplication)

modules(
listOf(
navigatorModule,
sdkModule,
homeModule,
recommendationBlockModule,
cartModule,
categoryModule,
productDetailsModule,
productsModule,
settingsModule,
searchModule
)
)
}

initializeSdk()
}

private fun initializeSdk() {
val sdk = getKoin().get<SDK>()
SdkUtils.initialize(
sdk = sdk,
context = this@DemoApplication,
shopId = SHOP_ID
)
}

companion object {
private const val SHOP_ID = "357382bf66ac0ce2f1722677c59511"
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/rees46/demo_android/app/di/NavigatorModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rees46.demo_android.app.di

import androidx.navigation.NavController
import com.rees46.demo_android.navigation.Navigator
import org.koin.dsl.module
import rees46.demo_android.app.navigation.AppNavigator

val navigatorModule = module {
single<Navigator> {
(navController: NavController) ->
AppNavigator(
navController = navController
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package rees46.demo_android.app.navigation

import android.os.Bundle
import androidx.annotation.IdRes
import androidx.core.os.bundleOf
import androidx.navigation.NavController
import com.rees46.demo_android.navigation.Destination
import com.rees46.demo_android.navigation.Navigator
import com.rees46.demo_android.navigation.ProductDetails
import com.rees46.demo_android.navigation.ProductsDetails
import rees46.demo_android.app.R
import rees46.demo_android.core.settings.NavigationSettings

class AppNavigator(private val navController: NavController) : Navigator {

override fun navigate(destination: Destination) {
when(destination) {
is ProductDetails -> {
val bundle = bundleOf(NavigationSettings.PRODUCT_ARGUMENT_FIELD to destination.navigationProduct)
navigate(
resId = R.id.productDetailsFragment,
args = bundle
)
}
is ProductsDetails -> {
val bundle = bundleOf(NavigationSettings.PRODUCTS_ARGUMENT_FIELD to destination.navigationProducts)
navigate(
resId = R.id.productsFragment,
args = bundle
)
}
else -> {}
}
}

override fun navigate(id: Int) {
navController.navigate(id)
}

override fun popBackStack() {
navController.popBackStack()
}

override fun getCurrentDestination() : Int? =
navController.currentDestination?.id

private fun navigate(@IdRes resId: Int, args: Bundle?) {
navController.navigate(
resId = resId,
args = args
)
}
}
114 changes: 114 additions & 0 deletions app/src/main/java/rees46/demo_android/app/presentation/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package rees46.demo_android.app.presentation

import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.MenuProvider
import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.fragment.NavHostFragment
import org.koin.android.ext.android.get
import org.koin.core.parameter.parametersOf
import rees46.demo_android.app.R
import rees46.demo_android.app.databinding.ActivityMainBinding
import com.rees46.demo_android.navigation.Navigator

class MainActivity : AppCompatActivity(), LifecycleOwner {

private lateinit var binding: ActivityMainBinding

private val navigator by lazy {
get<Navigator> {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
parametersOf(navHostFragment.navController)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.getRoot())

setupTopAppBar()
setupBottomNavigationView()
setupPopBackStack()
createOptionMenu()
}

private fun setupTopAppBar() {
setSupportActionBar(binding.topAppBar)
}

private fun setupBottomNavigationView() {
binding.bottomNavigation.setOnItemSelectedListener {
when (it.itemId) {
R.id.home -> switchBottomTab(R.id.homeFragment)
R.id.category -> switchBottomTab(R.id.categoryFragment)
R.id.cart -> switchBottomTab(R.id.cartFragment)
R.id.settings -> switchBottomTab(R.id.settingsFragment)
}

true
}
}

private fun switchBottomTab(id: Int) {
if(navigator.getCurrentDestination() == id) return

navigator.navigate(id)
}

private fun setupPopBackStack() {
onBackPressedDispatcher.addCallback(
owner = this,
onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
navigator.popBackStack()

changeSelectedBottomItem()
}
}
)
}

private fun changeSelectedBottomItem() {
with(binding.bottomNavigation) {
when (navigator.getCurrentDestination()) {
R.id.homeFragment -> selectedItemId = R.id.home
R.id.categoryFragment -> selectedItemId = R.id.category
R.id.cartFragment -> selectedItemId = R.id.cart
R.id.settingsFragment -> selectedItemId = R.id.settingsFragment
}
}
}


private fun createOptionMenu() {
addMenuProvider(object : MenuProvider {
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.main_top_app_bar_menu, menu)
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
R.id.menu_top_app_cart -> {
binding.bottomNavigation.selectedItemId = R.id.cart
true
}
R.id.menu_top_app_search -> {
supportActionBar?.hide()
binding.bottomNavigation.isVisible = false
navigator.navigate(R.id.searchFragment)
true
}
else -> false
}
}
})
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_app.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="76dp"
android:height="86dp"
android:viewportWidth="76"
android:viewportHeight="86"
android:tint="#000000">
<path
android:pathData="M65.53,22.241L42.023,8.541C39.535,7.091 36.465,7.091 33.977,8.541L10.47,22.241C7.998,23.682 6.467,26.341 6.467,29.229V56.771C6.467,59.659 7.998,62.318 10.47,63.759L33.977,77.459C36.465,78.909 39.535,78.909 42.023,77.459L65.53,63.759C68.002,62.318 69.533,59.659 69.533,56.771V29.229C69.533,26.341 68.002,23.682 65.53,22.241ZM44.91,3.588C40.638,1.097 35.362,1.097 31.09,3.588L7.583,17.288C3.343,19.759 0.733,24.308 0.733,29.229V56.771C0.733,61.692 3.343,66.241 7.583,68.712L31.09,82.412C35.362,84.903 40.638,84.903 44.91,82.412L68.417,68.712C72.657,66.241 75.267,61.692 75.267,56.771V29.229C75.267,24.308 72.657,19.759 68.417,17.288L44.91,3.588Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
<path
android:pathData="M38.236,56.558C40.1,55.098 42.109,53.423 44.153,51.546C54.122,42.386 59.47,32.271 61.705,27.268C62.607,29.724 63.11,32.63 63.138,35.781C59.577,40.319 53.786,47.264 48.402,51.795C45.384,54.334 42.674,56.443 40.336,58.162C40.605,58.362 40.869,58.557 41.128,58.746C43.264,57.248 45.649,55.482 48.159,53.48C54.322,48.564 59.335,42.885 63.084,37.939C62.993,39.512 62.787,41.133 62.457,42.776C62.257,43.776 62.005,44.771 61.709,45.753C58.631,48.834 55.345,51.854 52.378,54.017C48.898,56.556 45.83,58.618 43.245,60.256C43.518,60.446 43.782,60.628 44.037,60.802C46.293,59.452 48.818,57.847 51.475,56.009C54.886,53.648 57.997,51.057 60.774,48.449C59.654,51.3 58.181,53.972 56.511,56.261C56.217,56.456 55.926,56.645 55.638,56.826C50.042,60.353 45.463,62.801 42.181,64.407C41.87,64.57 41.573,64.723 41.244,64.88L41.223,64.87C40.983,64.984 40.752,65.093 40.529,65.197L40.541,65.203C39.764,65.568 39.2,65.811 38.677,66.034C38.523,66.101 38.378,66.164 38.239,66.223L38.236,66.222L38.233,66.223C38.095,66.164 37.949,66.101 37.796,66.034C37.272,65.811 36.708,65.568 35.931,65.203L35.944,65.197C35.721,65.093 35.49,64.984 35.25,64.87L35.229,64.88C34.9,64.723 34.602,64.57 34.291,64.407C31.009,62.801 26.431,60.353 20.834,56.826C20.547,56.645 20.256,56.456 19.962,56.261C18.292,53.972 16.818,51.3 15.698,48.449C18.475,51.057 21.587,53.648 24.997,56.009C27.654,57.847 30.179,59.452 32.436,60.802C32.69,60.628 32.954,60.446 33.227,60.256C30.643,58.618 27.575,56.556 24.095,54.017C21.128,51.854 17.841,48.834 14.763,45.753C14.467,44.771 14.215,43.776 14.015,42.776C13.685,41.133 13.479,39.512 13.388,37.939C17.138,42.885 22.15,48.564 28.313,53.48C30.823,55.482 33.208,57.248 35.344,58.746C35.603,58.557 35.868,58.362 36.137,58.162C33.798,56.443 31.088,54.334 28.071,51.795C22.687,47.264 16.895,40.319 13.334,35.781C13.362,32.63 13.865,29.724 14.767,27.268C17.002,32.271 22.35,42.386 32.319,51.546C34.363,53.423 36.372,55.098 38.236,56.558ZM38.386,63.227C38.125,63.389 37.875,63.544 37.636,63.69C37.895,63.842 38.145,63.987 38.386,64.126C38.627,63.987 38.877,63.842 39.136,63.69C38.897,63.544 38.647,63.389 38.386,63.227ZM34.636,62.209C34.876,62.057 35.126,61.897 35.387,61.728C35.643,61.881 35.893,62.028 36.136,62.171C35.877,62.331 35.627,62.483 35.388,62.627C35.142,62.492 34.892,62.353 34.636,62.209ZM41.086,61.728C40.83,61.881 40.58,62.028 40.336,62.171C40.595,62.331 40.845,62.483 41.085,62.627C41.33,62.492 41.581,62.353 41.836,62.209C41.597,62.057 41.346,61.897 41.086,61.728ZM37.636,60.091C37.88,59.942 38.13,59.789 38.386,59.631C38.642,59.789 38.892,59.942 39.136,60.091C38.881,60.241 38.631,60.388 38.386,60.53C38.141,60.388 37.891,60.241 37.636,60.091Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
</vector>
Loading