Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_weight="1"
android:src="@drawable/logo_711_50"
android:src="@drawable/logo_711_red"
app:civ_border_color="@color/googleRed"
app:civ_circle_background_color="@color/googleRed" />

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,33 +1,70 @@
package com.iceteaviet.fastfoodfinder.data.remote.store

import android.content.Context
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.iceteaviet.fastfoodfinder.data.remote.store.model.Comment
import com.iceteaviet.fastfoodfinder.data.remote.store.model.Store
import com.iceteaviet.fastfoodfinder.utils.exception.NotFoundException
import java.util.*
import com.iceteaviet.fastfoodfinder.utils.StoreType
import java.util.TreeMap
import kotlin.collections.ArrayList

class FakeFirebaseStoreApiHelper : StoreApiHelper {
class FakeFirebaseStoreApiHelper(private val context: Context) : StoreApiHelper {

private var STORE_SERVICE_DATA: MutableList<Store> = ArrayList()
private var STORE_COMMENT_SERVICE_DATA: MutableMap<String, MutableList<Comment>> = TreeMap()

override suspend fun getAllStores(): List<Store> {
if (STORE_SERVICE_DATA.isEmpty()) {
STORE_SERVICE_DATA = com.iceteaviet.fastfoodfinder.utils.getFakeStoreList().toMutableList()
STORE_SERVICE_DATA = loadStoresFromAssets().toMutableList()
}
return STORE_SERVICE_DATA
}

override suspend fun getComments(storeId: String): List<Comment> {
return STORE_COMMENT_SERVICE_DATA.get(storeId) ?: ArrayList()
return STORE_COMMENT_SERVICE_DATA[storeId] ?: ArrayList()
}

override fun insertOrUpdateComment(storeId: String, comment: Comment) {
var comments = STORE_COMMENT_SERVICE_DATA.get(storeId)
if (comments == null) {
comments = ArrayList()
}
val comments = STORE_COMMENT_SERVICE_DATA.getOrPut(storeId) { ArrayList() }
comments.add(comment)
STORE_COMMENT_SERVICE_DATA.put(storeId, comments)
}

private fun loadStoresFromAssets(): List<Store> {
val gson = Gson()
val stores = ArrayList<Store>()
val fileToType = mapOf(
"circle_k.json" to StoreType.TYPE_CIRCLE_K,
"ministop.json" to StoreType.TYPE_MINI_STOP,
"familymart.json" to StoreType.TYPE_FAMILY_MART,
"bsmart.json" to StoreType.TYPE_BSMART,
"shopngo.json" to StoreType.TYPE_SHOP_N_GO,
"711.json" to StoreType.TYPE_7_ELEVEN,
)

var id = 1
for ((fileName, type) in fileToType) {
try {
val json = context.assets.open("stores_data/$fileName")
.bufferedReader().use { it.readText() }
val root = gson.fromJson(json, object : TypeToken<Map<String, List<Map<String, String>>>>() {}) as Map<String, *>
@Suppress("UNCHECKED_CAST")
val markers = root["markers_add"] as? List<Map<String, String>> ?: continue
for (marker in markers) {
stores.add(Store(
id++,
marker["title"].orEmpty(),
marker["address"].orEmpty(),
marker["lat"] ?: "0",
marker["lng"] ?: "0",
marker["tel"].orEmpty(),
type
))
}
} catch (e: Exception) {
throw RuntimeException("Failed to load stores from stores_data/$fileName", e)
}
}
return stores
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ object RepositoryModule {

@Provides
@Singleton
fun provideStoreRepository(): StoreRepository {
val remote = FakeFirebaseStoreApiHelper()
fun provideStoreRepository(@ApplicationContext context: Context): StoreRepository {
val remote = FakeFirebaseStoreApiHelper(context)
val local = FakeStoreDAO()
return AppStoreRepository(remote, local)
}
Expand Down
Loading