-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
id("kotlin-parcelize") | ||
} | ||
|
||
android { | ||
namespace = "com.example.githubuser" | ||
compileSdk = 33 | ||
|
||
defaultConfig { | ||
applicationId = "com.example.githubuser" | ||
minSdk = 24 | ||
targetSdk = 33 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
buildFeatures { | ||
viewBinding = true | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
|
||
implementation ("com.squareup.retrofit2:retrofit:2.9.0") | ||
implementation ("com.squareup.retrofit2:converter-gson:2.9.0") | ||
implementation ("com.squareup.okhttp3:logging-interceptor:4.11.0") | ||
|
||
implementation ("com.github.bumptech.glide:glide:4.16.0") | ||
|
||
implementation ("com.squareup.picasso:picasso:2.8") | ||
|
||
implementation ("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-rc01") | ||
|
||
implementation("androidx.core:core-ktx:1.9.0") | ||
implementation("androidx.appcompat:appcompat:1.6.1") | ||
implementation("com.google.android.material:material:1.9.0") | ||
implementation("androidx.constraintlayout:constraintlayout:2.1.4") | ||
testImplementation("junit:junit:4.13.2") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.githubuser | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.example.githubuser", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.GithubUser" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".ui.ProfileActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".ui.MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.githubuser.data.model | ||
|
||
data class Profile( | ||
val login: String, | ||
val id: Int, | ||
val avatar_url: String, | ||
val followers_url: String, | ||
val following_url: String, | ||
val name: String, | ||
val following: Int, | ||
val followers: Int | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.githubuser.data.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class User( | ||
@field:SerializedName("items") | ||
val items: ArrayList<UserDetail> | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.githubuser.data.model | ||
|
||
data class UserDetail( | ||
val login: String, | ||
val id: Int, | ||
val avatar_url: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.example.githubuser.data.networking | ||
|
||
import com.example.githubuser.data.model.Profile | ||
import com.example.githubuser.data.model.User | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Headers | ||
import retrofit2.http.Path | ||
import retrofit2.http.Query | ||
|
||
interface Api { | ||
// search user | ||
@GET("search/users") | ||
@Headers("Authorization: token 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") | ||
fun getUsers( | ||
@Query("q") query: String | ||
): Call<User> | ||
|
||
// detail user | ||
@GET("users/{username}") | ||
@Headers("Authorization: token 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") | ||
fun getProfile( | ||
@Path("username") username: String? | ||
): Call<Profile> | ||
|
||
@GET("users/{username}/followers") | ||
@Headers("Authorization: token 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") | ||
fun getFollowers( | ||
@Path("username") username: String | ||
): Call<ArrayList<Profile>> | ||
|
||
@GET("users/{username}/following") | ||
@Headers("Authorization: token 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") | ||
fun getFollowing( | ||
@Path("username") username: String | ||
): Call<ArrayList<Profile>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.githubuser.data.networking | ||
|
||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitClient { | ||
private const val BASE_URL = "https://api.github.com/" | ||
|
||
val retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
|
||
val apiInstance = retrofit.create(Api::class.java) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.example.githubuser.ui | ||
|
||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.view.KeyEvent | ||
import android.view.View | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.example.githubuser.R | ||
import com.example.githubuser.data.model.UserDetail | ||
import com.example.githubuser.databinding.ActivityMainBinding | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding : ActivityMainBinding | ||
private lateinit var viewModel: UserViewModel | ||
private lateinit var adapter: UserAdapter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityMainBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
adapter = UserAdapter() | ||
adapter.notifyDataSetChanged() | ||
|
||
adapter.setOnItemClickFunction(object : UserAdapter.OnItemClickCallback{ | ||
override fun onFunctionClicked(data: UserDetail){ | ||
Intent(this@MainActivity, ProfileActivity::class.java).also { | ||
it.putExtra(ProfileActivity.EXTRA_USERNAME, data.login) | ||
startActivity(it) | ||
} | ||
} | ||
}) | ||
|
||
viewModel = ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()) | ||
.get(UserViewModel::class.java) | ||
|
||
binding.apply { | ||
rvUser.layoutManager = LinearLayoutManager(this@MainActivity) | ||
rvUser.setHasFixedSize(true) | ||
rvUser.adapter = adapter | ||
|
||
searchBtn.setOnClickListener{ | ||
searchUser() | ||
} | ||
|
||
inputQuery.setOnKeyListener { v, keyCode, event -> | ||
if (event.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER){ | ||
return@setOnKeyListener true | ||
} | ||
return@setOnKeyListener false | ||
} | ||
} | ||
|
||
viewModel.getUsers().observe(this) { | ||
if (it != null) { | ||
adapter.setList(it) | ||
loadingAnimation(false) | ||
} | ||
} | ||
} | ||
|
||
private fun searchUser() { | ||
binding.apply { | ||
val query = inputQuery.text.toString() | ||
if(query.isEmpty()) return | ||
loadingAnimation(true) | ||
viewModel.setSearchUsers(query) | ||
} | ||
} | ||
|
||
private fun loadingAnimation(state: Boolean){ | ||
if(state){ | ||
binding.progressBar.visibility = View.VISIBLE | ||
}else{ | ||
binding.progressBar.visibility = View.GONE | ||
} | ||
} | ||
} |