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
6 changes: 6 additions & 0 deletions .idea/AndroidProjectSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask2agent.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/deviceManager.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions .idea/modules.xml

This file was deleted.

8 changes: 8 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
namespace 'com.hitanshudhawan.annotationprocessingexample'
Expand All @@ -25,18 +26,25 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'

implementation 'com.google.code.gson:gson:2.13.2'

implementation project(':butterknife')
implementation project(':butterknife-annotations')
annotationProcessor project(':butterknife-compiler')
kapt project(':butterknife-compiler')

implementation project(':singleton-annotations')
annotationProcessor project(':singleton-compiler')
kapt project(':singleton-compiler')

implementation project(':ksingleton-annotations')
annotationProcessor project(':ksingleton-compiler')
kapt project(':ksingleton-compiler')

implementation project(':network-model-validator-annotations')
kapt project(':network-model-validator-compiler')
lintChecks project(':network-model-validator-lint')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hitanshudhawan.annotationprocessingexample

import com.hitanshudhawan.annotationprocessingexample.models.LoginRequest
import com.hitanshudhawan.annotationprocessingexample.models.LoginResponse
import com.hitanshudhawan.annotationprocessingexample.network.HttpRequestType
import com.hitanshudhawan.annotationprocessingexample.network.NetworkRequestBuilder
import com.hitanshudhawan.annotationprocessingexample.network.NetworkResponse

class LoginRepository {

suspend fun login() {
val loginRequest = LoginRequest(
email = "user@example.com",
password = "password123",
rememberMe = true
)

val networkResponse: NetworkResponse = NetworkRequestBuilder()
.httpMethod(HttpRequestType.POST)
.subUrl("/api/v1/auth/login")
.body(loginRequest)
.build()
.processSync()

val successResponse1: LoginResponse? = networkResponse.getSuccessResponse<LoginResponse>()
val successResponse2: LoginResponse? = networkResponse.getSuccessResponse(LoginResponse::class.java)
val successResponse3: LoginResponse? = networkResponse.getResponse(LoginResponse::class.java)

val errorResponse = networkResponse.getErrorResponse<String>()
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hitanshudhawan.annotationprocessingexample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hitanshudhawan.annotationprocessingexample.models

import com.google.gson.annotations.SerializedName
import com.hitanshudhawan.networkmodelvalidator.NetworkModel

/**
* Sample login request model in Kotlin.
* Demonstrates proper usage of @NetworkModel and @SerializedName annotations.
*/
@NetworkModel
data class LoginRequest(

@SerializedName("email")
val email: String,

@SerializedName("password")
val password: String,

@SerializedName("remember_me")
val rememberMe: Boolean = false

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hitanshudhawan.annotationprocessingexample.models;

import com.google.gson.annotations.SerializedName;
import com.hitanshudhawan.networkmodelvalidator.NetworkModel;

/**
* Sample login request model in Java.
* Demonstrates proper usage of @NetworkModel and @SerializedName annotations.
*/
@NetworkModel
public class LoginRequestJava {

@SerializedName("email")
private final String email;

@SerializedName("password")
private final String password;

@SerializedName("remember_me")
private final boolean rememberMe;

public LoginRequestJava(String email, String password, boolean rememberMe) {
this.email = email;
this.password = password;
this.rememberMe = rememberMe;
}

public String getEmail() {
return email;
}

public String getPassword() {
return password;
}

public boolean isRememberMe() {
return rememberMe;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.hitanshudhawan.annotationprocessingexample.models

import com.google.gson.annotations.SerializedName
import com.hitanshudhawan.networkmodelvalidator.NetworkModel

/**
* Sample login response model in Kotlin.
* Demonstrates proper usage of @NetworkModel and @SerializedName annotations.
*/
@NetworkModel
data class LoginResponse(

@SerializedName("success")
val success: Boolean,

@SerializedName("message")
val message: String,

@SerializedName("user")
val user: UserData?,

@SerializedName("access_token")
val accessToken: String,

@SerializedName("refresh_token")
val refreshToken: String,

@SerializedName("expires_in")
val expiresIn: Long

)

/**
* Nested user data model in Kotlin.
* Must also be annotated with @NetworkModel.
*/
@NetworkModel
data class UserData(

@SerializedName("user_id")
val userId: String,

@SerializedName("email")
val email: String,

@SerializedName("display_name")
val displayName: String,

@SerializedName("avatar_url")
val avatarUrl: String?

)
Loading