-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c12a823
commit 4c456b9
Showing
15 changed files
with
269 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/kotlin/id/shaderboi/koffie/ui/coupons/CouponsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package id.shaderboi.koffie.ui.coupons | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.content.ContextCompat | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.recyclerview.widget.DividerItemDecoration | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import id.shaderboi.koffie.R | ||
import id.shaderboi.koffie.core.domain.model.Coupon | ||
import id.shaderboi.koffie.databinding.ActivityCouponsBinding | ||
import id.shaderboi.koffie.ui.coupons.adapter.CouponAdapter | ||
import id.shaderboi.koffie.ui.coupons.adapter.CouponShimmerAdapter | ||
import kotlinx.coroutines.delay | ||
|
||
@AndroidEntryPoint | ||
class CouponsActivity : AppCompatActivity() { | ||
private var _binding: ActivityCouponsBinding? = null | ||
val binding get() = _binding!! | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
_binding = ActivityCouponsBinding.inflate(layoutInflater) | ||
|
||
collectUIEvent() | ||
setupView() | ||
|
||
setContentView(binding.root) | ||
} | ||
|
||
private fun collectUIEvent() { | ||
val coupons = mutableListOf<Coupon>() | ||
for (i in 1..10) { | ||
coupons.add( | ||
Coupon( | ||
0, | ||
"ABC", | ||
"asdasdasdasd\nzxczcxzcxzcxc" | ||
) | ||
) | ||
coupons.add( | ||
Coupon( | ||
1, | ||
"asdzxzx", | ||
"asdasdasdasd\nzxczcxzcxzcxc" | ||
) | ||
) | ||
} | ||
lifecycleScope.launchWhenCreated { | ||
delay(3000) | ||
binding.shimmerFrameLayoutMain.hideShimmer() | ||
binding.recyclerViewCoupons.adapter = CouponAdapter(coupons) { view, coupon -> | ||
val intent = Intent() | ||
intent.putExtra("SELECTED_COUPON", coupon.id) | ||
setResult(1, intent) | ||
} | ||
} | ||
} | ||
|
||
private fun setupView() { | ||
setSupportActionBar(binding.toolbar) | ||
supportActionBar?.apply { | ||
setDisplayHomeAsUpEnabled(true) | ||
setDisplayShowHomeEnabled(true) | ||
} | ||
binding.toolbar.setNavigationOnClickListener { | ||
onBackPressed() | ||
} | ||
|
||
val dividerItemDecoration = DividerItemDecoration(this, DividerItemDecoration.VERTICAL) | ||
dividerItemDecoration.setDrawable( | ||
ContextCompat.getDrawable(this, R.drawable.divider8dp)!! | ||
); | ||
binding.recyclerViewCoupons.apply { | ||
addItemDecoration(dividerItemDecoration) | ||
adapter = CouponShimmerAdapter() | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/kotlin/id/shaderboi/koffie/ui/coupons/adapter/CouponAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package id.shaderboi.koffie.ui.coupons.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import id.shaderboi.koffie.core.domain.model.Coupon | ||
import id.shaderboi.koffie.databinding.ItemCouponBinding | ||
|
||
class CouponAdapter( | ||
private val coupons: List<Coupon>, | ||
private val onClick: (view: View, coupon: Coupon) -> Unit | ||
) : | ||
RecyclerView.Adapter<CouponAdapter.ViewHolder>() { | ||
|
||
class ViewHolder(val binding: ItemCouponBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
return ViewHolder(ItemCouponBinding.inflate(inflater, parent, false)) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val coupon = coupons[position] | ||
holder.binding.apply { | ||
textViewDescription.text = coupon.description | ||
textViewTitle.text = coupon.title | ||
root.setOnClickListener { view -> | ||
onClick(view, coupon) | ||
} | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int = coupons.size | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/kotlin/id/shaderboi/koffie/ui/coupons/adapter/CouponShimmerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package id.shaderboi.koffie.ui.coupons.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.databinding.ItemCouponBinding | ||
|
||
class CouponShimmerAdapter() : | ||
RecyclerView.Adapter<CouponShimmerAdapter.ViewHolder>() { | ||
|
||
class ViewHolder(val binding: ItemCouponBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
return ViewHolder(ItemCouponBinding.inflate(inflater, parent, false)) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val context = holder.binding.root.context | ||
holder.binding.apply { | ||
textViewDescription.apply { | ||
background = ContextCompat.getDrawable(context, R.color.placeholder) | ||
minLines = 3 | ||
} | ||
textViewTitle.background = | ||
ContextCompat.getDrawable(context, R.color.placeholder) | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int = 10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
app/src/main/kotlin/id/shaderboi/koffie/ui/promo/PromoActivity.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:liftOnScroll="true"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:elevation="12dp" | ||
android:minHeight="?attr/actionBarSize" | ||
app:layout_collapseMode="pin" | ||
app:title="Promos for you" /> | ||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<com.facebook.shimmer.ShimmerFrameLayout | ||
app:shimmer_auto_start="true" | ||
android:id="@+id/shimmerFrameLayoutMain" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingStart="24dp" | ||
android:paddingTop="24dp" | ||
android:paddingEnd="24dp" | ||
android:paddingBottom="24dp"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recyclerViewCoupons" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" | ||
tools:listitem="@layout/item_coupon" /> | ||
</com.facebook.shimmer.ShimmerFrameLayout> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout 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="wrap_content" | ||
android:background="@drawable/round_bordered8dp" | ||
android:paddingStart="24dp" | ||
android:paddingTop="16dp" | ||
android:paddingEnd="24dp" | ||
android:paddingBottom="16dp"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:divider="@drawable/divider8dp" | ||
android:orientation="vertical" | ||
android:showDividers="middle"> | ||
|
||
<TextView | ||
android:id="@+id/textViewTitle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textSize="16sp" | ||
android:textStyle="bold" | ||
tools:text="3k delivery discount" /> | ||
|
||
<TextView | ||
android:id="@+id/textViewDescription" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
tools:text="15k off food + 3k off delivery" /> | ||
</LinearLayout> | ||
|
||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
core/src/main/kotlin/id/shaderboi/koffie/core/domain/model/Coupon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package id.shaderboi.koffie.core.domain.model | ||
|
||
data class Coupon( | ||
val id: Int, | ||
val title: String, | ||
val description: String, | ||
) |