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
20 changes: 16 additions & 4 deletions app/src/main/java/com/tymex/github/users/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@ 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
import com.tymex.github.users.databinding.ToolbarBinding

abstract class BaseActivity : AppCompatActivity() {

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

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

val titleBinding = CustomActionbarTitleBinding.inflate(layoutInflater)
titleBinding.root.text = getToolbarTitle()
val titleBinding = ToolbarBinding.inflate(layoutInflater)
titleBinding.tvTitle.text = getToolbarTitle()
titleBinding.ivBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
val actionBarParams = ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL
)
it.setCustomView(titleBinding.root, actionBarParams)
}

window.apply {
setLightStatusBar()
setStatusBarColorCompat(android.R.color.white)
}

}

/**
* Override this to set Toolbar's title text
*/
abstract fun getToolbarTitle(): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class UserDetailsActivity : BaseActivity() {
usersViewModel = ViewModelProvider(this)[UserViewModelImpl::class.java]
}


/**
* Parse & display user details from a [FlowState]
*/
private fun handleUserDetailsFlow(flowState: FlowState) {
when (flowState) {
is FlowState.Loading -> {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/tymex/github/users/ui/UsersActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class UsersActivity : BaseActivity() {
super.onCreate(savedInstanceState)
binding = ActivityUsersBinding.inflate(layoutInflater)
setContentView(binding.root)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
initUsersList()
initViewModel()

Expand Down Expand Up @@ -98,6 +97,9 @@ class UsersActivity : BaseActivity() {
}
}

/**
* Parse users data from [FlowState] to inflate into list view
*/
private fun handleUsersFlow(flowState: FlowState) {
when (flowState) {
is FlowState.Loading -> {
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/com/tymex/github/users/ui/WindowExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.tymex.github.users.ui

import android.R
import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowInsetsController
import android.view.WindowManager
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

fun Window.setLightStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
this.insetsController?.setSystemBarsAppearance(
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
} else {
this.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
}

fun Window.setStatusBarColorCompat(color: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {

this.decorView.setBackgroundColor(ContextCompat.getColor(this.context, color))

// Apply window insets to avoid overlapping with system bars
ViewCompat.setOnApplyWindowInsetsListener(
this.decorView.findViewById(R.id.content)
) { v, insets ->
val systemBarsInsets =
insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(
v.getPaddingLeft(),
systemBarsInsets.top,
v.getPaddingRight(),
systemBarsInsets.bottom
)
WindowInsetsCompat.CONSUMED
}
} else {
this.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
this.statusBarColor = ContextCompat.getColor(this.context, color)
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_user_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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_following"
app:layout_constraintStart_toStartOf="@+id/iv_following"
app:layout_constraintTop_toBottomOf="@+id/iv_followers"
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/res/layout/custom_actionbar_title.xml

This file was deleted.

32 changes: 32 additions & 0 deletions app/src/main/res/layout/toolbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_back"
android:layout_width="@dimen/toolbar_back_indicator_size"
android:layout_height="@dimen/toolbar_back_indicator_size"
android:padding="12dp"
android:src="@drawable/ic_back"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/toolbar_back_indicator_size"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="My Centered Title" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.GithubUsers" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<dimen name="common_margin">20dp</dimen>
<dimen name="small_image_view_size">40dp</dimen>
<dimen name="toolbar_back_indicator_size">48dp</dimen>
</resources>
2 changes: 1 addition & 1 deletion data-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package com.tymex.github.data.core.data.model

/**
* A sealed hierarchy describing the state of the feed of users lists/user details
*/
sealed class FlowState {

/**
* User(s) data is loading
*/
data object Loading : FlowState()

/**
* There's an error with loading user(s) data
*/
data class Error(val message: String? = null) : FlowState()

/**
* User data is successfully loaded and ready to use
*/
data class Success<T>(val data: T) : FlowState()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.tymex.github.data.core.data.model

/**
* A wrapper of users list returned from a data repository
* [users] List of users
* [isFinalPage] true if this is the final page of data available, false otherwise
*/
data class GetUsersResult(
val users: List<User>,
val isFinalPage: Boolean = false,
var isDirty: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class UserLocalDataSourceImpl @Inject constructor(
return flow {
emit(FlowState.Loading)
val since = (page - 1) * pageSize
Log.d(
TAG,
"getUsers page: " + page + ". pageSize: " + pageSize + ". since: " + since
Log.d(TAG,
"getUsers page: $page. pageSize: $pageSize. since: $since"
)
try {
val response = userDao.getUsers(pageSize, since)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UserRemoteDataSourceImpl @Inject constructor(

var isFinalPage = false
val since = (page - 1) * pageSize
Log.d(TAG, "getUsers page: $page"+ ". pageSize: $pageSize"+ ". since: $since")
Log.d(TAG, "getUsers page: $page. pageSize: $pageSize. since: $since")
val networkResponse: NetworkResponse<List<User>> = try {
val response = userService.getUsers(pageSize, since)
isFinalPage = response.headers()["Link"]?.isLastPage() ?: false
Expand Down Expand Up @@ -52,7 +52,7 @@ class UserRemoteDataSourceImpl @Inject constructor(
return flow {
emit(FlowState.Loading)

Log.i(TAG, "getUserDetails login: " + login)
Log.i(TAG, "getUserDetails login: $login")
val networkResponse: NetworkResponse<UserDetails> = try {
userService.getUserDetails(login).toNetworkResponse()
} catch (ex: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ import javax.inject.Singleton
@Retention(AnnotationRetention.RUNTIME)
annotation class IoScope

@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class DefaultScope

@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class MainScope

@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class ApplicationScope

@Module
@InstallIn(SingletonComponent::class)
object CoroutineScopeModule {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ class ParserModule {
@Singleton
@Provides
fun provideMoshi(): Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()


@Singleton
@Provides
fun provideJsonHelper(moshi: Moshi): JsonHelper = JsonHelper(moshi)
}
Loading