Skip to content

Commit

Permalink
Add stores screen
Browse files Browse the repository at this point in the history
  • Loading branch information
andraantariksa committed Apr 18, 2022
1 parent c771422 commit 840805a
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
build/
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id "com.google.gms.google-services"
id "com.google.firebase.crashlytics"
id "androidx.navigation.safeargs.kotlin"
id "com.google.android.libraries.mapsplatform.secrets-gradle-plugin"
}

apply from: 'script/versioning.gradle'
Expand All @@ -26,7 +27,6 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildConfigField "String", "GOOGLE_MAPS_API", "\"AIzaSyDDKYRqId60GnoNYw7jjLPFAgWZr8Qd4To\""
buildConfigField "String", "MIDTRANS_API", "\"SB-Mid-client-FGDd5FsG_5p0EiWB\""
}

Expand Down Expand Up @@ -77,6 +77,7 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.android.gms:play-services-location:19.0.1'
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"

// Hilt
Expand All @@ -92,6 +93,9 @@ dependencies {
// Datetime
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.3.2"

// Maps
implementation "com.google.android.gms:play-services-maps:18.0.2"

implementation "com.google.firebase:firebase-appcheck-safetynet:16.0.0-beta06"
implementation "androidx.core:core-splashscreen:1.0.0-beta02"
implementation "com.airbnb.android:lottie:$lottieVersion"
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,43 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<application
android:name=".KoffieApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.Koffie"
android:supportsRtl="true"
android:theme="@style/Theme.Koffie"
tools:replace="android:allowBackup">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<uses-library
android:name="org.apache.http.legacy"
android:required="false" />

<activity
android:name=".ui.main.MainActivity"
android:theme="@style/Theme.Koffie.SplashScreen"
android:exported="true">
android:exported="true"
android:theme="@style/Theme.Koffie.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.location.LocationActivity"
android:exported="false" />
<activity
android:name=".ui.auth.AuthActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
package id.shaderboi.koffie.ui.location

import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import dagger.hilt.android.AndroidEntryPoint
import id.shaderboi.koffie.databinding.ActivityLocationBinding
import Bundle as BundleConst

class LocationActivity : AppCompatActivity(), OnMapReadyCallback {
@AndroidEntryPoint
class LocationActivity : AppCompatActivity() {
private lateinit var map: GoogleMap

override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
private var _binding: ActivityLocationBinding? = null
val binding get() = _binding!!

setupMap()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

_binding = ActivityLocationBinding.inflate(layoutInflater)

var mapViewBundle: Bundle? = null
if (savedInstanceState != null) {
mapViewBundle = savedInstanceState.getBundle(BundleConst.MAPVIEW_KEY)
}

binding.mapView.onCreate(mapViewBundle)
binding.mapView.getMapAsync { _map ->
map = _map
setupMap()
}

setContentView(binding.root)
}

private fun setupMap() {
Expand All @@ -26,4 +47,52 @@ class LocationActivity : AppCompatActivity(), OnMapReadyCallback {
map.moveCamera(CameraUpdateFactory.newLatLng(shop))
}

override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
super.onSaveInstanceState(outState, outPersistentState)

var mapViewBundle = outState.getBundle(BundleConst.MAPVIEW_KEY)
if (mapViewBundle == null) {
mapViewBundle = Bundle()
outState.putBundle(BundleConst.MAPVIEW_KEY, mapViewBundle)
}

binding.mapView.onSaveInstanceState(mapViewBundle)
}

override fun onLowMemory() {
super.onLowMemory()

binding.mapView.onLowMemory()
}

override fun onPause() {
binding.mapView.onPause()

super.onPause()
}

override fun onStop() {
super.onStop()

binding.mapView.onStop()
}

override fun onStart() {
super.onStart()

binding.mapView.onStart()
}

override fun onResume() {
super.onResume()

binding.mapView.onResume()
}

override fun onDestroy() {
binding.mapView.onDestroy()

super.onDestroy()
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package id.shaderboi.koffie.ui.main.home.adapter
package id.shaderboi.koffie.ui.main.store.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package id.shaderboi.koffie.ui.main.home.adapter
package id.shaderboi.koffie.ui.main.store.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import id.shaderboi.koffie.R
import id.shaderboi.koffie.core.domain.model.store.products.Product
import id.shaderboi.koffie.databinding.ItemProductBinding
import java.text.DecimalFormat

class ProductsShimmerAdapter :
RecyclerView.Adapter<ProductsShimmerAdapter.ViewHolder>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package id.shaderboi.koffie.ui.main.stores

import MAPVIEW_BUNDLE_KEY
import Bundle as BundleConst
import Permission
import android.os.Bundle
import android.view.LayoutInflater
Expand Down Expand Up @@ -50,7 +50,7 @@ class StoresFragment : Fragment() {
super.onCreate(savedInstanceState)

if (savedInstanceState != null) {
mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY)
mapViewBundle = savedInstanceState.getBundle(BundleConst.MAPVIEW_KEY)
}
}

Expand Down Expand Up @@ -83,10 +83,10 @@ class StoresFragment : Fragment() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)

var mapViewBundle = outState.getBundle(MAPVIEW_BUNDLE_KEY)
var mapViewBundle = outState.getBundle(BundleConst.MAPVIEW_KEY)
if (mapViewBundle == null) {
mapViewBundle = Bundle()
outState.putBundle(MAPVIEW_BUNDLE_KEY, mapViewBundle)
outState.putBundle(BundleConst.MAPVIEW_KEY, mapViewBundle)
}

binding.mapView.onSaveInstanceState(mapViewBundle)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package id.shaderboi.koffie.ui.main.stores.view_model

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import id.shaderboi.koffie.core.domain.model.common.Coordinate
import id.shaderboi.koffie.core.domain.model.common.toCoordinate
import id.shaderboi.koffie.core.domain.model.store.Store
import id.shaderboi.koffie.core.domain.repository.StoreRepository
import id.shaderboi.koffie.core.util.Resource
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class StoresViewModel @Inject constructor(
val storeRepository: StoreRepository
) : ViewModel() {
private val _stores = MutableSharedFlow<Resource<List<Store>>>()
val stores = _stores.asSharedFlow()

fun onEvent(event: StoresEvent) {
when (event) {
is StoresEvent.Load -> load(event.location.toCoordinate())
}
}

private fun load(coordinate: Coordinate) = viewModelScope.launch {
_stores.emit(Resource.Loading())
// _stores.emit(Resource.Loaded(storeRepository.getStores(coordinate)))
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_location.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
android:background="@color/primary">

<com.google.android.flexbox.FlexboxLayout
android:id="@+id/flexboxLayout"
Expand Down Expand Up @@ -55,6 +55,7 @@
android:id="@+id/buttonSignOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/onPrimary"
android:text="@string/sign_out" />
</com.google.android.flexbox.FlexboxLayout>
</FrameLayout>
Expand Down
61 changes: 61 additions & 0 deletions app/src/main/res/layout/fragment_stores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="450dp">

<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">

<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax" />

<!-- <androidx.appcompat.widget.Toolbar-->
<!-- android:id="@+id/toolbar"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="?attr/actionBarSize"-->
<!-- app:layout_collapseMode="pin" />-->
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollViewMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="8dp"
android:paddingTop="24dp"
android:paddingEnd="8dp"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

<com.facebook.shimmer.ShimmerFrameLayout
app:shimmer_auto_start="true"
android:id="@+id/shimmerFrameLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewStores"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_store" />

</com.facebook.shimmer.ShimmerFrameLayout>

</androidx.core.widget.NestedScrollView>


</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading

0 comments on commit 840805a

Please sign in to comment.