Skip to content

Commit

Permalink
🚀 product recommendation API integration, finishing (bug fix, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
fikrihandy committed Dec 15, 2023
1 parent f1bc62d commit 02af8fd
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
android:value="AIzaSyCmR6EH3XkpW8VYFpVGhlxImlBv4yrNEuE" />

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package academy.bangkit.trackmate.data.remote.response

import com.google.gson.annotations.SerializedName

data class RecommendationResponse(

@field:SerializedName("data")
val data: DataRecommendation,

@field:SerializedName("count")
val count: Int,

@field:SerializedName("error")
val error: Boolean,

@field:SerializedName("message")
val message: String,

@field:SerializedName("status")
val status: String
)

data class DataRecommendation(

@field:SerializedName("recommended_products")
val recommendedProducts: List<RecommendedProductsItem?>?
)

data class RecommendedProductsItem(

@field:SerializedName("product_id")
val productId: String,

@field:SerializedName("rating_x")
val rating: String,

@field:SerializedName("product_name")
val productName: String,

@field:SerializedName("product_link")
val productLink: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ data class Umkm(
val createdAt: String,

@field:SerializedName("impact")
val impact: List<ImpactItem>,
val impact: List<ImpactItem?>,

@field:SerializedName("contact")
val contact: List<ContactItem>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package academy.bangkit.trackmate.data.remote.retrofit
import academy.bangkit.trackmate.BuildConfig
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class ApiConfig {
companion object {
fun getApiService(token: String? = null): ApiService {
val loggingInterceptor =
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)

// val loggingInterceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)

val authInterceptor = Interceptor { chain ->
val req = chain.request()
Expand All @@ -25,7 +24,7 @@ class ApiConfig {
chain.proceed(requestHeaders)
}
val client = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
//.addInterceptor(loggingInterceptor)
.addInterceptor(authInterceptor)
.build()
val retrofit = Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import academy.bangkit.trackmate.data.remote.response.ImageUploadResponse
import academy.bangkit.trackmate.data.remote.response.ProductsResponse
import academy.bangkit.trackmate.data.remote.response.LoginResponse
import academy.bangkit.trackmate.data.remote.response.LogoutResponse
import academy.bangkit.trackmate.data.remote.response.RecommendationResponse
import academy.bangkit.trackmate.data.remote.response.RegisterResponse
import academy.bangkit.trackmate.data.remote.response.UMKMResponse
import academy.bangkit.trackmate.data.remote.response.RenewTokenResponse
Expand Down Expand Up @@ -88,4 +89,7 @@ interface ApiService {
suspend fun uploadImages(
@Part file: MultipartBody.Part,
): ImageUploadResponse

@GET("recomendation")
suspend fun getProductsRecommendation(): RecommendationResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package academy.bangkit.trackmate.data.repository

import academy.bangkit.trackmate.data.remote.response.DetailResponse
import academy.bangkit.trackmate.data.remote.response.ProductsResponse
import academy.bangkit.trackmate.data.remote.response.RecommendationResponse
import academy.bangkit.trackmate.data.remote.retrofit.ApiConfig

class ProductRepository {
Expand All @@ -18,4 +19,8 @@ class ProductRepository {
ApiConfig.getApiService().getAllProducts()
}
}

suspend fun getProductsRecommendation(): RecommendationResponse {
return ApiConfig.getApiService().getProductsRecommendation()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private fun TopBar(navController: NavHostController) {
IconButton(onClick = { navController.navigateUp() }) {
Icon(
imageVector = Icons.Rounded.ArrowBackIosNew,
contentDescription = ""
contentDescription = stringResource(id = R.string.arrow_back)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fun OverviewAndMaterialPreview() {
}
}

//data sample
//data sample for preview only

object ProductSample {
const val title = "Dirrana Necklace"
Expand All @@ -131,27 +131,27 @@ object ProductSample {

val productMaterials = listOf(
ProductMaterial(
"",
"Batu Alam",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimU-cI7ieeLXk0I90RhV_DIZ1TUb5BhFW_0Z2F2bbdtLtw_tLAIFX2l8-J1HhQZTAm6MbprbG0rVKR7vv8puEL-tcIl3_dKx438-JSRl_MVvSsRbY-K9YFujBwIAz3W6pMWLQdgkD1ehLbfdwe5wJfoV0lRspJu1Ukwrz-kCZ58x2vWkFV1GzBuHolnUM/s1600/Rectangle%2011%281%29.png",
Location(0.0, 0.0, ""),
Location(0.0, 0.0, "Location"),
""
),
ProductMaterial(
"",
"Mutiara",
"https://lzd-img-global.slatic.net/g/p/f69e3cec597835b6e3d08e0abff7cfa5.jpg_720x720q80.jpg",
Location(0.0, 0.0, ""),
Location(0.0, 0.0, "Location"),
""
),
ProductMaterial(
"",
"Manik-manik",
"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbm6ROwsg-1uy1sPiFrdWk9kN9mhIcORdGYBAmczx41kJIIULnOUIOgWGV6NPou33K8nI6QGlAXzG_MhwqpU-AkHCRCFWMx_kluytZM9yKtkh7clx_ZU-jRKZZtQE1MFLrGXTr8dIIhH_ujPT1gbPpOsOVuKhIsPaSJmGYov_azZQKinCo2hid3Sk0jjo/s840/Zarla-bead-logos-3999x2999-20230523.jpeg",
Location(0.0, 0.0, ""),
Location(0.0, 0.0, "Location"),
""
),
ProductMaterial(
"",
"Lorem Ipsum",
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSYZrJAWoX8O2kJ_G5ZMa285VciX8rXIcGSJg5Tkssn&s",
Location(0.0, 0.0, ""),
Location(0.0, 0.0, "Location"),
""
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package academy.bangkit.trackmate.view.app.detail.component.product

import academy.bangkit.trackmate.R
import academy.bangkit.trackmate.data.remote.response.ImpactItem
import academy.bangkit.trackmate.data.remote.response.ProductImpactOverview
import academy.bangkit.trackmate.ui.theme.TrackMateTheme
import academy.bangkit.trackmate.view.app.detail.component.Divider
import academy.bangkit.trackmate.view.app.detail.component.Title
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.TrendingUp
import androidx.compose.material.icons.rounded.Air
Expand All @@ -34,13 +35,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import academy.bangkit.trackmate.R
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource

@Composable
fun ProductImpactAndOverview(productImpact: List<ImpactItem?>, contribution: List<Byte>) {
Expand All @@ -51,13 +51,12 @@ fun ProductImpactAndOverview(productImpact: List<ImpactItem?>, contribution: Lis
if (filteredList.isNotEmpty()) {
Title(title = stringResource(id = R.string.product_impact))

Row(
LazyRow(
modifier = Modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState())
.padding(start = 16.dp, top = 16.dp),
) {
filteredList.forEach { item ->
items(filteredList) { item ->
Card(
modifier = Modifier
.width(190.dp)
Expand All @@ -67,7 +66,7 @@ fun ProductImpactAndOverview(productImpact: List<ImpactItem?>, contribution: Lis
AsyncImage(
contentScale = ContentScale.Crop,
model = item.image,
contentDescription = "Translated description of what the image contains",
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.height(130.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun UmkmContact(email: String, phone: Phone) {
) {
Icon(
imageVector = Icons.Rounded.Call,
contentDescription = "Phone Icon",
contentDescription = null,
modifier = Modifier.size(20.dp),
tint = Color.Black
)
Expand Down Expand Up @@ -79,7 +79,7 @@ fun UmkmContact(email: String, phone: Phone) {
) {
Icon(
imageVector = Icons.Rounded.Email,
contentDescription = "Email Icon",
contentDescription = stringResource(id = R.string.email),
modifier = Modifier.size(20.dp),
tint = Color.Black
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import academy.bangkit.trackmate.R

@Composable
fun UmkmHistory(history: History) {
Divider()
Title(title = "Sejarah")
Title(title = stringResource(id = R.string.history_umkm))
AsyncImage(
model = history.image,
contentDescription = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ import academy.bangkit.trackmate.data.remote.response.ImpactItem
import academy.bangkit.trackmate.view.app.detail.component.Divider
import academy.bangkit.trackmate.view.app.detail.component.Title
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import academy.bangkit.trackmate.R

@Composable
fun UmkmImpact(umkmImpact: List<ImpactItem>) {
Title(title = "UMKM Impact")
fun UmkmImpact(umkmImpact: List<ImpactItem?>) {
Title(title = stringResource(id = R.string.umkm_impact))

Row(
LazyRow(
modifier = Modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState())
.padding(start = 16.dp, top = 16.dp),
) {
umkmImpact.forEach { item ->
items(umkmImpact.filterNotNull()) { item ->
Card(
modifier = Modifier
.width(190.dp)
Expand All @@ -42,7 +42,7 @@ fun UmkmImpact(umkmImpact: List<ImpactItem>) {
AsyncImage(
contentScale = ContentScale.Crop,
model = item.image,
contentDescription = "Translated description of what the image contains",
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.height(130.dp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package academy.bangkit.trackmate.view.app.detail.component.umkm

import academy.bangkit.trackmate.R
import academy.bangkit.trackmate.data.remote.response.ProductItem
import academy.bangkit.trackmate.navigation.Screen
import academy.bangkit.trackmate.view.app.detail.component.Title
import academy.bangkit.trackmate.view.formatToRupiah
import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
Expand All @@ -28,6 +28,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
Expand Down Expand Up @@ -67,7 +68,11 @@ fun ProductCard(product: ProductItem, modifier: Modifier = Modifier) {
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = formatToRupiah(product.price),
text = if (product.price == 0) {
stringResource(R.string.none)
} else {
formatToRupiah(product.price)
},
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
Expand All @@ -80,8 +85,8 @@ fun ProductCard(product: ProductItem, modifier: Modifier = Modifier) {
@Composable
fun UmkmProduct(products: List<ProductItem>? = null, navController: NavController) {

if (products != null){
Title(title = "Product")
if (products != null) {
Title(title = stringResource(id = R.string.products))
LazyRow(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(10.dp)
Expand All @@ -92,7 +97,6 @@ fun UmkmProduct(products: List<ProductItem>? = null, navController: NavControlle
modifier = Modifier
.padding(end = 16.dp)
.clickable {
Log.d("Clicked Product Card", product.id)
navController.navigate(Screen.App.Detail.createRoute(product.id))
}
)
Expand Down
Loading

0 comments on commit 02af8fd

Please sign in to comment.