Skip to content
Merged
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
/captures
.externalNativeBuild
.cxx
local.properties
/data-core/build/
.kotlin
31 changes: 31 additions & 0 deletions app/src/main/java/com/tymex/github/users/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.tymex.github.users.ui

import android.os.Bundle
import android.view.Gravity
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import com.tymex.github.users.databinding.CustomActionbarTitleBinding

abstract class BaseActivity : AppCompatActivity() {

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

supportActionBar?.let {
it.setDisplayHomeAsUpEnabled(true)
it.setDisplayShowTitleEnabled(false)
it.setDisplayShowCustomEnabled(true)

val titleBinding = CustomActionbarTitleBinding.inflate(layoutInflater)
titleBinding.root.text = getToolbarTitle()
val actionBarParams = ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL
)
it.setCustomView(titleBinding.root, actionBarParams)
}
}

abstract fun getToolbarTitle(): String
}
14 changes: 0 additions & 14 deletions app/src/main/java/com/tymex/github/users/ui/UserAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tymex.github.users.ui

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
Expand All @@ -15,7 +14,6 @@ class UserAdapter(

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val user = currentList[position]
Log.d("tuancoltech", "onBindViewHolder pos: " + position + ". User: " + user.login)
(holder as UserHolder).bindItem(user)
}

Expand All @@ -42,21 +40,9 @@ class UserAdapter(

fun appendUsers(newUsers: List<User>) {
val updatedUsers = currentList + newUsers
Log.w("tuancoltech", "currentList ---- \n")
currentList.printOut()
Log.w("tuancoltech", "newUsers ---- \n")
newUsers.printOut()
Log.w("tuancoltech", "updatedUsers ---- \n")
updatedUsers.printOut()
setData(updatedUsers)
}

private fun List<User>.printOut() {
for (idx in this.indices) {
Log.v("tuancoltech", "IDX: " + idx + " is " + this[idx].login)
}
}

class UserHolder(
private val binding: RowUserBinding,
private val onUserClicked: ((User) -> Unit)? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
Expand All @@ -21,9 +20,7 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class UserDetailsActivity : AppCompatActivity() {

private val TAG = /*UsersActivity::class.java.simpleName*/"tuancoltech"
class UserDetailsActivity : BaseActivity() {

private lateinit var usersViewModel: UserViewModel
private lateinit var binding: ActivityUserDetailsBinding
Expand All @@ -32,10 +29,6 @@ class UserDetailsActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = ActivityUserDetailsBinding.inflate(layoutInflater)
setContentView(binding.root)
supportActionBar?.let {
it.setDisplayHomeAsUpEnabled(true)
it.title = getString(R.string.toolbar_title_user_details)
}
initViewModel()

lifecycleScope.launch {
Expand Down Expand Up @@ -100,4 +93,12 @@ class UserDetailsActivity : AppCompatActivity() {
else -> super.onOptionsItemSelected(item)
}
}

override fun getToolbarTitle(): String {
return getString(R.string.toolbar_title_user_details)
}

companion object {
private val TAG by lazy { UsersActivity::class.java.simpleName }
}
}
19 changes: 11 additions & 8 deletions app/src/main/java/com/tymex/github/users/ui/UsersActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
Expand All @@ -16,14 +15,13 @@ import com.tymex.github.data.core.data.model.FlowState
import com.tymex.github.data.core.data.model.GetUsersResult
import com.tymex.github.data.core.viewmodel.UserViewModel
import com.tymex.github.data.core.viewmodel.UserViewModelImpl
import com.tymex.github.users.R
import com.tymex.github.users.databinding.ActivityUsersBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class UsersActivity : AppCompatActivity() {

private val TAG = /*UsersActivity::class.java.simpleName*/"tuancoltech"
class UsersActivity : BaseActivity() {

private lateinit var usersViewModel: UserViewModel
private lateinit var binding: ActivityUsersBinding
Expand All @@ -34,8 +32,9 @@ class UsersActivity : AppCompatActivity() {
private var isLoadingMore = false

companion object {
private const val PAGE_SIZE = 3
private const val PAGE_SIZE = 20
const val BUNDLE_KEY_LOGIN = "bundle_key_login"
private val TAG by lazy { UsersActivity::class.java.simpleName }
}


Expand Down Expand Up @@ -108,9 +107,9 @@ class UsersActivity : AppCompatActivity() {
is FlowState.Success<*> -> {
binding.pbLoading.root.gone()
val getUserResult = flowState.data as? GetUsersResult ?: return
Log.i(
TAG,
"getUsers success: " + getUserResult.users.size + ". isFinal: " + getUserResult.isFinalPage + ". curPage: " + currentPage
Log.i(TAG,
"getUsers success: " + getUserResult.users.size
+ ". isFinal: " + getUserResult.isFinalPage + ". curPage: " + currentPage
)
hasMore = !getUserResult.isFinalPage
isLoadingMore = false
Expand Down Expand Up @@ -141,4 +140,8 @@ class UsersActivity : AppCompatActivity() {
else -> super.onOptionsItemSelected(item)
}
}

override fun getToolbarTitle(): String {
return getString(R.string.app_name)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>

</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_followers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="800dp"
android:height="800dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:pathData="M128.91,21.56c-0.51,0.01 -1.01,0.04 -1.5,0.11C97.75,25.52 74.6,57.76 74.6,96.66c0,21.55 7.39,40.79 18.77,54.5 -61.68,11.59 -66.34,115.44 -66.34,188.35h42.77l11.35,152.16h108.68L199.86,339.51h40.59c0,-73.11 1.47,-178.78 -65.9,-189.22 10.89,-13.65 17.89,-32.61 17.89,-53.63 0,-41.5 -26.44,-74.99 -58.92,-74.99 -1.52,0 -3.09,-0.15 -4.61,-0.11zM368.74,21.56c-0.51,0.01 -1.01,0.04 -1.5,0.11 -29.66,3.85 -52.81,36.09 -52.81,74.99 0,21.55 7.39,40.79 18.77,54.5 -61.68,11.59 -66.34,115.44 -66.34,188.35h30.32l-10.17,-11.42c-0.31,-51.84 1.86,-95.18 24.01,-135.48l-1.54,146.91h0.15l11.35,152.16h86.01l-66.03,-12.01c-11.88,-104.37 -18.4,-205.54 -4.09,-308.36 0,0 9.45,-6.07 24.03,-13.4 -14.16,-12.08 -23.55,-33.24 -23.55,-57.35 0,-37.56 22.8,-68.01 50.92,-68.01 8.89,0 17.24,3.05 24.51,8.39 -10.45,-11.98 -24.28,-19.27 -39.42,-19.27 -1.52,0 -3.09,-0.15 -4.61,-0.11zM437.93,192.87l1.68,147.21 22.32,-0.26c0.31,-51.84 -1.86,-106.65 -24.01,-146.95zM439.62,340.09h-0l0,0.01v-0.01z"
android:fillColor="#000000"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_following.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="800dp"
android:height="800dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M1.984,29.992l0,-2.029c0,-0.795 0.597,-1.045 0.835,-1.154l8.783,-4.145c0.63,-0.289 1.064,-0.885 1.149,-1.573s-0.193,-1.37 -0.733,-1.803c-2.078,-1.668 -3.046,-5.335 -3.046,-7.287v-4.997c0,-2.09 3.637,-4.995 7.004,-4.995 3.396,0 6.998,2.861 6.998,4.995v4.997c0,1.924 -0.8,5.604 -2.945,7.293 -0.547,0.43 -0.831,1.115 -0.749,1.807 0.082,0.692 0.518,1.291 1.151,1.582l5.07,2.414 1.192,-1.69 -5.427,-2.542c2.771,-2.18 3.708,-6.464 3.708,-8.865v-4.997c0,-3.31 -4.582,-6.995 -8.998,-6.995s-9.004,3.686 -9.004,6.995v4.997c0,2.184 0.997,6.601 3.793,8.847l-8.783,4.145s-1.998,0.89 -1.998,1.999v3.001c0,1.105 0.895,1.999 1.998,1.999h19.991l-1.625,-2zM31.632,22.61c-0.434,-0.341 -1.064,-0.264 -1.404,0.171l-4.276,6.522 -2.658,-2.659c-0.39,-0.39 -1.024,-0.39 -1.415,0s-0.39,1.023 0,1.414l3.535,3.535c0.39,0.39 1.023,0.39 1.414,0 0.095,-0.095 0.166,-0.204 0.215,-0.322l4.759,-7.259c0.34,-0.434 0.263,-1.063 -0.172,-1.403z"
android:fillColor="#000000"/>
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/layout/activity_user_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android:layout_width="@dimen/small_image_view_size"
android:layout_height="@dimen/small_image_view_size"
android:layout_marginVertical="@dimen/common_margin"
android:src="@drawable/ic_followers"
app:layout_constraintEnd_toStartOf="@+id/iv_following"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_user_card" />
Expand All @@ -29,6 +30,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/common_margin"
android:gravity="center_horizontal"
app:layout_constraintEnd_toEndOf="@+id/iv_followers"
app:layout_constraintStart_toStartOf="@+id/iv_followers"
app:layout_constraintTop_toBottomOf="@+id/iv_followers"
Expand All @@ -39,6 +41,7 @@
android:layout_width="@dimen/small_image_view_size"
android:layout_height="@dimen/small_image_view_size"
android:layout_marginVertical="@dimen/common_margin"
android:src="@drawable/ic_following"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/iv_followers"
app:layout_constraintTop_toBottomOf="@+id/layout_user_card" />
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/custom_actionbar_title.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/action_bar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textStyle="bold"
android:gravity="center_horizontal"
tools:text="My Centered Title" />
14 changes: 13 additions & 1 deletion app/src/main/res/layout/row_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,36 @@
android:layout_marginStart="20dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/iv_avatar"
app:layout_constraintTop_toTopOf="@+id/iv_avatar"
tools:text="This is a very long text and let's see how long it might take" />

<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="@color/grey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/tv_name"
app:layout_constraintTop_toBottomOf="@+id/tv_name" />

<TextView
android:id="@+id/tv_url"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:autoLink="all"
android:ellipsize="end"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="@+id/iv_avatar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/iv_avatar"
app:layout_constraintTop_toBottomOf="@+id/divider"
tools:text="https://www.test.com" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="grey">#ededeb</color>

<color name="colorPrimary">@color/purple_200</color>
<!-- <color name="colorPrimaryDark">@color/green</color>-->
<!-- <color name="colorAccent">@color/green_accent_1</color>-->
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="common_margin">20dp</dimen>
<dimen name="small_image_view_size">50dp</dimen>
<dimen name="small_image_view_size">40dp</dimen>
</resources>
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<resources>
<string name="app_name">GithubUsers</string>
<string name="app_name">Github Users</string>
<string name="toolbar_title_user_details">User Details</string>
<string name="toast_error_message">Error %s</string>
<string name="blog_header">Blog</string>
<string name="followers_count">%d \nfollowers</string>
<string name="following_count">%d \nfollowing</string>
<string name="followers_count">%d \nFollowers</string>
<string name="following_count">%d \nFollowing</string>
</resources>
23 changes: 10 additions & 13 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<resources>
<style name="Theme.GithubUsers" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<!-- <item name="colorPrimary">@color/purple_500</item>-->
<!-- <item name="colorPrimaryVariant">@color/purple_700</item>-->
<!-- <item name="colorOnPrimary">@color/white</item>-->
<!-- &lt;!&ndash; Secondary brand color. &ndash;&gt;-->
<!-- <item name="colorSecondary">@color/teal_200</item>-->
<!-- <item name="colorSecondaryVariant">@color/teal_700</item>-->
<!-- <item name="colorOnSecondary">@color/black</item>-->
<!-- &lt;!&ndash; Status bar color. &ndash;&gt;-->
<!-- <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>-->
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/white</item>
<item name="actionBarStyle">@style/Widget.AppCompat.ActionBar</item>
<item name="toolbarStyle">@style/CustomActionBar</item>
<item name="android:homeAsUpIndicator">@drawable/ic_back</item>
</style>

<style name="CustomActionBar" parent="Widget.MaterialComponents.Toolbar.Primary">
<item name="titleTextColor">@color/black</item>
<item name="titleCentered">true</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tymex.github.data.core.data.repository.users

import android.util.Log
import com.tymex.github.data.core.data.model.FlowState
import com.tymex.github.data.core.data.model.GetUsersResult
import com.tymex.github.data.core.data.model.User
Expand All @@ -24,7 +23,6 @@ class UserRepositoryImpl @Inject constructor(
when (localUsersFlow) {
is FlowState.Success<*> -> {
val localUsers = (localUsersFlow.data as? GetUsersResult)?.users ?: emptyList()
Log.v("tuancoltech", "Got localUsers with size: " + localUsers.size)
if (localUsers.isNotEmpty()) {
flowOf(localUsersFlow)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import javax.inject.Inject

class UserLocalDataSourceImpl @Inject constructor(
private val userDao: UserDao,
@IoScope private val coroutineScope: CoroutineScope
@IoScope private val coroutineScope: CoroutineScope,
) : UserLocalDataSource {

override fun getUsers(pageSize: Int, page: Int): Flow<FlowState> {
return flow {
emit(FlowState.Loading)
val since = (page - 1) * pageSize
Log.i(
"tuancoltech",
Log.d(
TAG,
"getUsers page: " + page + ". pageSize: " + pageSize + ". since: " + since
)
try {
Expand All @@ -42,8 +43,12 @@ class UserLocalDataSourceImpl @Inject constructor(

override fun insertUsers(users: List<User>) {
coroutineScope.launch {
Log.v("tuancoltech", "insertUsers : $users\nSize: $users.size)" )
Log.v(TAG, "insertUsers : $users\nSize: $users.size)")
userDao.insertUsers(users)
}
}

companion object {
private val TAG by lazy { UserLocalDataSourceImpl::class.java.name }
}
}
Loading
Loading