Skip to content
Open
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
19 changes: 19 additions & 0 deletions Demo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
id 'com.google.dagger.hilt.android'
}

android {
Expand Down Expand Up @@ -37,11 +38,17 @@ android {
viewBinding true
dataBinding true
}

kapt {
correctErrorTypes true
}
}

dependencies {
def lifecycle_version = "2.6.1"
def nav_version = "2.5.3"
def retrofit_version = "2.9.0"
def hilt_version = "2.46.1"

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
Expand All @@ -54,6 +61,7 @@ dependencies {
implementation "androidx.preference:preference-ktx:1.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
implementation 'androidx.fragment:fragment-ktx:1.5.7'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1"

// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
Expand All @@ -65,6 +73,17 @@ dependencies {
// OkHttp3
implementation "com.squareup.okhttp3:okhttp:4.10.0"

// Retrofit2
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

// Hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

// Glide
implementation "com.github.bumptech.glide:glide:4.13.2"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
25 changes: 24 additions & 1 deletion Demo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,33 @@

<activity
android:name=".navigation.ui.activities.TriviaGameActivity"
android:exported="true">
android:exported="true"
android:theme="@style/GitHubTheme">
<nav-graph android:value="@navigation/trivia_nav_graph" />
</activity>

<activity
android:name="com.krunal.demo.githubclient.ui.activity.GitHubClientActivity"
android:launchMode="singleTask"
android:exported="false" />

<activity
android:name="com.krunal.demo.githubclient.ui.activity.AuthorizationActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/GitHubTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="com.krunal.demo"
android:scheme="krunal" />
</intent-filter>
</activity>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand Down
8 changes: 8 additions & 0 deletions Demo/app/src/main/java/com/krunal/demo/DemoApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.krunal.demo

import android.app.Application
import com.krunal.demo.helpers.PreferenceHelper
import com.krunal.demo.helpers.ResourceHelper
import com.krunal.demo.searchwebview.helpers.PackageHelper
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class DemoApplication: Application() {

override fun onCreate() {
Expand All @@ -20,6 +23,11 @@ class DemoApplication: Application() {
* Initialize [PackageHelper]
*/
PackageHelper.initialize(applicationContext)

/**
* Initialize [ResourceHelper]
*/
ResourceHelper.initialize(applicationContext)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object IntentData {
const val AUTH_KEY = "auth_key"
const val WEB_URL = "web_url"
const val USER_ID = "user_id"
const val GITHUB_AUTHORIZATION_TOKEN = "github_authorization_token"

/**
* Actions
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AIReviewRadar

The code changes look good. The addition of the GITHUB_AUTHORIZATION_TOKEN constant in the IntentData object seems appropriate.

However, I have a few suggestions for improving the code and documentation:

  1. Add a comment above the GITHUB_AUTHORIZATION_TOKEN constant to explain its purpose and usage.

    Example:

    /**
     * GitHub Authorization Token key used for passing the token as an intent extra.
     */
    const val GITHUB_AUTHORIZATION_TOKEN = "github_authorization_token"
  2. Consider adding a brief description of the IntentData object in the file-level documentation comment.

    Example:

    /**
     * Utility object for storing intent data keys used throughout the application.
     */
    object IntentData {
      // ...
    }
  3. Update the existing comments in the file to reflect the latest changes. For example, update the comment for AUTH_KEY to mention that it is used for passing authentication keys as an intent extra.

    Example:

    const val AUTH_KEY = "auth_key" // Used for passing authentication keys as an intent extra.

These suggestions will help improve the readability and maintainability of the code.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.krunal.demo.githubclient.annotation

@Target(AnnotationTarget.FUNCTION)
annotation class Retry(val max: Int = 3)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AIReviewRadar

The code changes in the patch for Retry.kt look good.

Here are a few suggestions to improve the code:

  1. It's recommended to add a space between the package declaration and the import statement.
  2. Consider adding a comment explaining the purpose of the Retry annotation.

Updated code:

package com.krunal.demo.githubclient.annotation

// Annotation used to specify the maximum number of retries for a function
@Target(AnnotationTarget.FUNCTION)
annotation class Retry(val max: Int = 3)

Please make these changes and let me know if you have any further questions or concerns.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.krunal.demo.githubclient.data.local

sealed interface DownloadState {
data class Downloading(val progress: Int) : DownloadState
object Finished : DownloadState
data class Failed(val message: String, val error: Throwable? = null) : DownloadState
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AIReviewRadar

The code changes in the DownloadState.kt file look good.

There are no issues with the code according to the provided guidelines. The file defines a sealed interface DownloadState with three implementations: Downloading, Finished, and Failed. Each implementation has the necessary properties and types.

I would recommend adding a newline at the end of the file to follow common coding conventions.

Overall, the code changes in this patch are fine.

Please let me know if you have any further questions or if there's anything else I can assist you with.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.krunal.demo.githubclient.data.local

import android.graphics.drawable.Drawable
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes

sealed interface HomeItem {
val type: Type

data class Heading(
val title: String,
override val type: Type = Type.HEADING
): HomeItem

data class WorkItem(
@DrawableRes val icon: Int,
@ColorInt val iconBackground: Int,
val title: String,
override val type: Type = Type.WORK
): HomeItem

data class Favorite(
val image: Drawable,
val organization: String,
val repoName: String,
override val type: Type = Type.FAVORITES
): HomeItem

data class Recent(
@DrawableRes val icon: Int,
val repo: String,
val title: String,
val authorAvatar: String,
val description: String,
override val type: Type = Type.RECENT
): HomeItem

enum class Type {
HEADING,
WORK,
FAVORITES,
RECENT
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.krunal.demo.githubclient.data.local

import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import com.krunal.demo.BR

data class IssueModel(
private var _title: String,
private var _authorAvatar: String? = null,
private var _body: String? = null,
) : BaseObservable() {

@get:Bindable
var authorAvatar: String? = _authorAvatar
set(value) {
_authorAvatar = value
field = value
notifyPropertyChanged(BR.authorAvatar)
}

@get:Bindable
var title: String = _title
set(value) {
_title = value
field = value
notifyPropertyChanged(BR.title)
}

@get:Bindable
var body: String? = _body
set(value) {
_body = value
field = value
notifyPropertyChanged(BR.body)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.krunal.demo.githubclient.data.local

import androidx.annotation.DrawableRes

enum class NotificationType {
ISSUE_OPENED, PULL_OPENED, PULL_MERGED, PULL_DRAFT, PULL_CLOSED
}

data class NotificationItem(
@DrawableRes val icon: Int,
val repoName: String,
val issueId: Int?,
val title: String,
val isUnread: Boolean,
var description: String? = null,
var authorAvatar: String? = null,
) {

val heading: String
get() = "$repoName #$issueId"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AIReviewRadar

The code changes in the NotificationItem.kt file look good.

Here are a few suggestions to improve the code:

  1. Consider adding documentation comments (KDoc) for the class and properties to provide more information about their purpose and usage.

  2. The NotificationType enum could benefit from having explicit values assigned to each enum constant. For example:

    enum class NotificationType(val value: String) {
        ISSUE_OPENED("issue_opened"),
        PULL_OPENED("pull_opened"),
        PULL_MERGED("pull_merged"),
        PULL_DRAFT("pull_draft"),
        PULL_CLOSED("pull_closed")
    }

    This can make it easier to work with the enum values and avoid potential issues if the enum names change in the future.

Other than these suggestions, the code looks fine. Please make the necessary changes and respond with the updated code.

Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.krunal.demo.githubclient.data.local

import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import com.krunal.demo.R
import com.krunal.demo.githubclient.data.remote.model.response.UserResponse
import com.krunal.demo.helpers.ResourceHelper

enum class DetailType {
NAME, INFO
}

enum class ProfileType {
DETAIL, ITEM
}

data class ProfileModel(
val items: List<ProfileInfo>
)

sealed interface ProfileDetail {

val type: DetailType

data class ProfileName(
val avatar: String,
val username: String,
val name: String? = null,
override val type: DetailType = DetailType.NAME
) : ProfileDetail

data class ProfileInfo(
@DrawableRes val icon: Int,
val title: String,
override val type: DetailType = DetailType.INFO
) : ProfileDetail {
companion object {

fun from(userResponse: UserResponse) = buildList {
with(userResponse) {
bio?.let {
add(ProfileInfo(R.drawable.ic_info, it))
}
company?.let {
add(ProfileInfo(R.drawable.ic_chat, it))
}
blog?.let {
add(ProfileInfo(R.drawable.ic_link_logo, it))
}
email?.let {
add(ProfileInfo(R.drawable.ic_email, it))
}
add(
ProfileInfo(
R.drawable.ic_person_24,
ResourceHelper.resources.getString(R.string.follow_info, followers, following)
)
)
}
}
}
}
}

sealed interface ProfileInfo {
val type: ProfileType

data class ProfileCard(
val profileDetail: List<ProfileDetail>,
override val type: ProfileType = ProfileType.DETAIL
) : ProfileInfo {
companion object {

fun from(userResponse: UserResponse): ProfileCard {
val profileName = with(userResponse) {
ProfileDetail.ProfileName(avatarUrl, username, name)
}
val profileDetails: MutableList<ProfileDetail> =
ProfileDetail.ProfileInfo.from(userResponse).toMutableList()
profileDetails.add(0, profileName)
return ProfileCard(profileDetails)
}
}
}

data class ProfileItem(
@DrawableRes val icon: Int,
@ColorInt val iconBackground: Int,
val title: String,
val count: Int? = null,
override val type: ProfileType = ProfileType.ITEM
) : ProfileInfo {

companion object {
fun from(userResponse: UserResponse) = with(userResponse) {
with(ResourceHelper.resources) {
listOf(
ProfileItem(
R.drawable.ic_repo_24,
getColor(R.color.github_pull, null),
getString(R.string.repositories),
publicRepos
), ProfileItem(
R.drawable.ic_git_pull_request,
getColor(R.color.github_gists, null),
getString(R.string.gists),
publicGists
), ProfileItem(
R.drawable.ic_organization_24,
getColor(R.color.github_organization, null),
getString(R.string.organizations)
), ProfileItem(
R.drawable.ic_star_24,
getColor(R.color.github_starred, null),
getString(R.string.starred)
)
)
}
}
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AIReviewRadar

The code looks good overall. Here are a few suggestions:

  1. In the ProfileDetail sealed interface, consider renaming the type property to detailType for clarity.

  2. In the ProfileInfo sealed interface, consider renaming the type property to profileType for clarity.

  3. In the ProfileItem data class, consider renaming the iconBackground property to backgroundColor for clarity.

  4. Consider adding a blank line between the ProfileModel and sealed interface ProfileDetail sections for better readability.

  5. Consider adding a blank line between the sealed interface ProfileDetail and sealed interface ProfileInfo sections for better readability.

Other than these minor suggestions, the code looks fine. It follows the naming conventions, has proper access modifiers, and doesn't have any syntax errors or logic issues.

Please make the necessary changes and reply with the updated code.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.krunal.demo.githubclient.data.local

import java.util.Date

data class Release(
val repoFullName: String,
val releaseName: String,
val author: String,
val authorAvatar: String,
val releaseDate: Date,
val releaseAssets: List<ReleaseAsset>
)

data class ReleaseAsset(
val name: String,
val size: Int,
val contentType: String,
val downloadUrl: String,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AIReviewRadar

The code changes in the Release.kt file look good.

Here are a few suggestions to improve the code:

  1. It's recommended to add a newline at the end of the file to follow common coding conventions.

Other than that, the code follows the guidelines mentioned earlier. Therefore, the code changes in this patch look good to me.

Please let me know if you have any further questions or concerns.

Loading