Skip to content

Commit

Permalink
feat: Add design for feeds view
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbukachi committed Mar 1, 2020
1 parent ab4f245 commit 5926836
Show file tree
Hide file tree
Showing 18 changed files with 309 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand All @@ -13,8 +13,8 @@
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.DayNight.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />

</resources>
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ object Versions {

const val kotlin = "1.3.61"
const val coroutines = "1.3.3"
const val buildToolsVersion = "3.5.3"
const val buildToolsVersion = "3.6.0"
const val jetPack = "1.1.0"
const val constraintLayout = "1.1.3"
const val ktx = "1.1.0"
const val material = "1.0.0"
const val coil = "0.9.5"

const val junit4 = "4.12"
const val testRunner = "1.1.1"
Expand Down Expand Up @@ -37,6 +38,7 @@ object Libraries {
const val constraintLayout = "androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}"
const val ktxCore = "androidx.core:core-ktx:${Versions.ktx}"
const val materialComponents = "com.google.android.material:material:${Versions.material}"
const val coil = "io.coil-kt:coil:${Versions.coil}"
}

object APIs {
Expand Down
16 changes: 16 additions & 0 deletions features/feed/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,26 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

viewBinding {
isEnabled = true
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

(kotlinOptions as org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions).apply {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

}

dependencies {
implementation (fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation (project(":app"))
implementation(project(":core"))
implementation(Libraries.constraintLayout)
implementation(Libraries.coil)
testImplementation(TestLibraries.junit4)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.android254.droidconKE2020.feed.ui.views

import com.android254.droidconKE2020.feed.R

data class Feed(
val content: String,
val imageUrl: Int = R.drawable.dummy, // TODO Change to String type (image url)
val time: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.android254.droidconKE2020.feed.ui.views

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import coil.api.load
import coil.transform.RoundedCornersTransformation
import com.android254.droidconKE2020.feed.R
import kotlinx.android.synthetic.main.item_feeds.view.*

class FeedAdapter(private val listener: Listener) :
RecyclerView.Adapter<FeedAdapter.FeedViewHolder>() {

private val feeds = mutableListOf<Feed>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_feeds, parent, false)
return FeedViewHolder(view)
}

override fun getItemCount(): Int = feeds.size

override fun onBindViewHolder(holder: FeedViewHolder, position: Int) {
val feed = feeds[position]
holder.bindFeed(feed)
}

fun updateData(list: List<Feed>) {
feeds.clear()
feeds.addAll(list)
notifyDataSetChanged()
}

inner class FeedViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val content: TextView
val image: ImageView
val time: TextView
val shareButton: ImageButton

init {
content = view.content
image = view.image
time = view.time
shareButton = view.shareBtn
}

fun bindFeed(feed: Feed) {
content.text = feed.content
image.load(feed.imageUrl) {
transformations(RoundedCornersTransformation(12f))
}
time.text = feed.time
shareButton.setOnClickListener {
listener.onShareClicked(feed)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
package com.android254.droidconKE2020.feed.ui.views

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.android254.droidconKE2020.feed.R
import com.android254.droidconKE2020.feed.databinding.FragmentFeedBinding

class FeedFragment : Fragment(R.layout.fragment_feed) {
private var _binding: FragmentFeedBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentFeedBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val listener = object : Listener {
override fun onShareClicked(feed: Feed) {
// TODO Handle share logic
Toast.makeText(context!!, "Share button clicked.", Toast.LENGTH_SHORT).show()
}
}
val adapter = FeedAdapter(listener)
binding.feedsList.adapter = adapter
adapter.updateData(createDummyData()) // TODO Remove use of dummy data
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}

private fun createDummyData(): List<Feed> {
val list = mutableListOf<Feed>()
for (i in 0 until 10) {
list.add(Feed(content = context!!.getString(R.string.dummy_text), time = "10:5$i"))
}
return list
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.android254.droidconKE2020.feed.ui.views

interface Listener {
fun onShareClicked(feed: Feed)
}
10 changes: 10 additions & 0 deletions features/feed/src/main/res/drawable-night/ic_share.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="50"
android:viewportHeight="50">
<path
android:fillColor="#FFF"
android:pathData="M49.05,20.11 L26.43,7.05a2.18,2.18 0,0 0,-3.26 1.88v5.82a25.83,25.83 0,0 0,-3.25 1.09,27.15 27.15,0 0,0 -6.37,3.73 31.42,31.42 0,0 0,-4.84 4.8,39.37 39.37,0 0,0 -3.59,5.28 49.8,49.8 0,0 0,-2.69 5.5C1.66,37 1,38.88 0.43,40.76c-0.13,0.47 -0.27,0.93 -0.4,1.4a0.86,0.86 0,0 0,1.51 0.74l0.87,-1.1a54.09,54.09 0,0 1,3.75 -4.21,36.82 36.82,0 0,1 8.42,-6.5A20.85,20.85 0,0 1,19 29.3a14.11,14.11 0,0 1,4.18 -0.48h0v5.76a2.17,2.17 0,0 0,3.26 1.88L49.05,23.4A1.9,1.9 0,0 0,49.05 20.11Z" />
</vector>
Binary file added features/feed/src/main/res/drawable/dummy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions features/feed/src/main/res/drawable/ic_share.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="50"
android:viewportHeight="50">
<path
android:fillColor="#707070"
android:pathData="M49.05,20.11 L26.43,7.05a2.18,2.18 0,0 0,-3.26 1.88v5.82a25.83,25.83 0,0 0,-3.25 1.09,27.15 27.15,0 0,0 -6.37,3.73 31.42,31.42 0,0 0,-4.84 4.8,39.37 39.37,0 0,0 -3.59,5.28 49.8,49.8 0,0 0,-2.69 5.5C1.66,37 1,38.88 0.43,40.76c-0.13,0.47 -0.27,0.93 -0.4,1.4a0.86,0.86 0,0 0,1.51 0.74l0.87,-1.1a54.09,54.09 0,0 1,3.75 -4.21,36.82 36.82,0 0,1 8.42,-6.5A20.85,20.85 0,0 1,19 29.3a14.11,14.11 0,0 1,4.18 -0.48h0v5.76a2.17,2.17 0,0 0,3.26 1.88L49.05,23.4A1.9,1.9 0,0 0,49.05 20.11Z" />
</vector>
10 changes: 10 additions & 0 deletions features/feed/src/main/res/drawable/ic_time.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="50"
android:viewportHeight="50">
<path
android:fillColor="#E4E4E4"
android:pathData="M42.68,7.32a25,25 0,0 0,-35.35 0,25 25,0 0,0 0,35.35A25,25 0,0 0,50 25,24.84 24.84,0 0,0 42.68,7.32ZM29.93,39.77l-7,-14.26V10.28h4.41v14.2l6.57,13.34Z" />
</vector>
6 changes: 6 additions & 0 deletions features/feed/src/main/res/font/roboto.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Roboto"></font-family>
27 changes: 21 additions & 6 deletions features/feed/src/main/res/layout/fragment_feed.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/feedsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_feeds" />

<TextView
android:id="@+id/noFeeds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/feed_content_string"
android:layout_centerInParent="true"
/>

</RelativeLayout>
android:fontFamily="@font/roboto"
android:text="@string/no_feeds_found"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
80 changes: 80 additions & 0 deletions features/feed/src/main/res/layout/item_feeds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:contentPadding="16dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/dummy_text" />

<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="130dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/feed_image"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/content"
tools:srcCompat="@drawable/dummy" />

<ImageButton
android:id="@+id/shareBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="?selectableItemBackground"
android:contentDescription="@string/share_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/image"
app:srcCompat="@drawable/ic_share" />

<ImageView
android:id="@+id/timeIcon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginTop="8dp"
android:contentDescription="@string/time_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/image"
app:srcCompat="@drawable/ic_time" />

<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/roboto"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/timeIcon"
app:layout_constraintTop_toBottomOf="@id/image"
tools:text="10:24" />

</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>
17 changes: 17 additions & 0 deletions features/feed/src/main/res/values/font_certs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="com_google_android_gms_fonts_certs">
<item>@array/com_google_android_gms_fonts_certs_dev</item>
<item>@array/com_google_android_gms_fonts_certs_prod</item>
</array>
<string-array name="com_google_android_gms_fonts_certs_dev">
<item>
MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVml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Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions features/feed/src/main/res/values/preloaded_fonts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="preloaded_fonts" translatable="false">
<item>@font/roboto</item>
</array>
</resources>
5 changes: 5 additions & 0 deletions features/feed/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="feed_content_string">Feed👷🔧🚧</string>
<string name="dummy_text">We are pleased to have a team from Andela Kenya who will have a talk about Software Engineers to the Power of X from an Employer\'s perspective.</string>
<string name="feed_image">Feed image</string>
<string name="share_button">Share button</string>
<string name="time_icon">Time icon</string>
<string name="no_feeds_found">No feeds found</string>
</resources>
Loading

0 comments on commit 5926836

Please sign in to comment.