├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── drawable
│ │ │ ├── ic_fork.png
│ │ │ ├── git_icon.png
│ │ │ ├── ic_arrow_forward.xml
│ │ │ ├── ic_arrow_backward.xml
│ │ │ ├── ic_star_black.xml
│ │ │ └── ic_refresh.xml
│ │ ├── navigation
│ │ │ └── nav_graph.xml
│ │ └── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── fragment_repo_list.xml
│ │ │ ├── fragment_repo_detail.xml
│ │ │ └── view_repo_list_item.xml
│ │ ├── java
│ │ └── com
│ │ │ └── ankit
│ │ │ └── trendinggit
│ │ │ ├── view
│ │ │ ├── utils
│ │ │ │ └── Constants.kt
│ │ │ ├── base
│ │ │ │ └── BaseViewModel.kt
│ │ │ ├── ui
│ │ │ │ ├── MainActivity.kt
│ │ │ │ ├── repolist
│ │ │ │ │ ├── RepoListViewModel.kt
│ │ │ │ │ └── RepoListFragment.kt
│ │ │ │ └── repodetail
│ │ │ │ │ └── RepoDetailFragment.kt
│ │ │ └── adapter
│ │ │ │ ├── RepoListAdapter.kt
│ │ │ │ └── viewHolders
│ │ │ │ └── RepoListViewHolder.kt
│ │ │ ├── TrendingGitApp.kt
│ │ │ └── model
│ │ │ ├── api
│ │ │ ├── ApiService.kt
│ │ │ └── ApiClient.kt
│ │ │ ├── RepoRepository.kt
│ │ │ └── ApiResponse.kt
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshot
├── s1.png
├── s2.png
└── s3.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshot/s1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ankitbisht/trending-git/HEAD/screenshot/s1.png
--------------------------------------------------------------------------------
/screenshot/s2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ankitbisht/trending-git/HEAD/screenshot/s2.png
--------------------------------------------------------------------------------
/screenshot/s3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ankitbisht/trending-git/HEAD/screenshot/s3.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Trending Git
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ankitbisht/trending-git/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_fork.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ankitbisht/trending-git/HEAD/app/src/main/res/drawable/ic_fork.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/git_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ankitbisht/trending-git/HEAD/app/src/main/res/drawable/git_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008000
4 | #005e00
5 | #008000
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # trending-git
2 | Trending Git App
3 |
4 | - MVVM (KOTLIN)
5 | - ViewModel
6 | - LiveData
7 | - Navigation Component
8 | - Data binding
9 |
10 | Screen Shots
11 |
12 | 
13 | 
14 | 
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue May 07 12:47:37 IST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/utils/Constants.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.utils
2 |
3 | class Constants {
4 | companion object {
5 | const val BASE_URL = "https://api.github.com/"
6 | const val REQUEST_TIMEOUT_DURATION = 10
7 | const val DEBUG = true
8 | }
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/TrendingGitApp.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit
2 |
3 | import android.app.Application
4 |
5 | class TrendingGitApp : Application() {
6 |
7 | override fun onCreate() {
8 | super.onCreate()
9 | instance = this
10 | }
11 |
12 | companion object {
13 | lateinit var instance: TrendingGitApp
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_forward.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_backward.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/model/api/ApiService.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.model.api
2 |
3 | import com.ankit.trendinggit.model.GitResponse
4 | import retrofit2.Call
5 | import retrofit2.http.GET
6 | import retrofit2.http.Query
7 |
8 | interface ApiService {
9 |
10 | @GET("search/repositories")
11 | fun getRepo(@Query("q") search: String = "trending", @Query("sort") sort: String = "stars"): Call
12 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_star_black.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 30dp
3 |
4 |
5 | 25dp
6 | 20dp
7 | 10dp
8 | 5dp
9 |
10 |
11 | 20sp
12 | 18sp
13 | 16sp
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/base/BaseViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.base
2 |
3 | import androidx.lifecycle.MutableLiveData
4 | import androidx.lifecycle.ViewModel
5 | import com.ankit.trendinggit.TrendingGitApp
6 |
7 | open class BaseViewModel : ViewModel() {
8 |
9 | val empty = MutableLiveData().apply { value = false }
10 |
11 | val dataLoading = MutableLiveData().apply { value = false }
12 |
13 | val toastMessage = MutableLiveData()
14 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_refresh.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/ui/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.ui
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.navigation.findNavController
6 | import androidx.navigation.ui.NavigationUI
7 | import com.ankit.trendinggit.R
8 | import kotlinx.android.synthetic.main.activity_main.*
9 |
10 | class MainActivity : AppCompatActivity() {
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(R.layout.activity_main)
15 | setSupportActionBar(toolbar)
16 | NavigationUI.setupActionBarWithNavController(this, findNavController(R.id.main_nav_fragment))
17 | }
18 |
19 | override fun onSupportNavigateUp() = findNavController(R.id.main_nav_fragment).navigateUp()
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/ui/repolist/RepoListViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.ui.repolist
2 |
3 | import androidx.lifecycle.MutableLiveData
4 | import com.ankit.trendinggit.model.Item
5 | import com.ankit.trendinggit.model.RepoRepository
6 | import com.ankit.trendinggit.view.base.BaseViewModel
7 |
8 | class RepoListViewModel : BaseViewModel() {
9 | val repoListLive = MutableLiveData>()
10 |
11 | fun fetchRepoList() {
12 | dataLoading.value = true
13 | RepoRepository.getInstance().getRepoList { isSuccess, response ->
14 | dataLoading.value = false
15 | if (isSuccess) {
16 | repoListLive.value = response?.items
17 | empty.value = false
18 | } else {
19 | empty.value = true
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
15 |
16 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/model/RepoRepository.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.model
2 |
3 | import com.ankit.trendinggit.model.api.ApiClient
4 | import retrofit2.Call
5 | import retrofit2.Callback
6 | import retrofit2.Response
7 |
8 | class RepoRepository {
9 |
10 | // GET repo list
11 | fun getRepoList(onResult: (isSuccess: Boolean, response: GitResponse?) -> Unit) {
12 |
13 | ApiClient.instance.getRepo().enqueue(object : Callback {
14 | override fun onResponse(call: Call?, response: Response?) {
15 | if (response != null && response.isSuccessful)
16 | onResult(true, response.body()!!)
17 | else
18 | onResult(false, null)
19 | }
20 |
21 | override fun onFailure(call: Call?, t: Throwable?) {
22 | onResult(false, null)
23 | }
24 |
25 | })
26 | }
27 |
28 | companion object {
29 | private var INSTANCE: RepoRepository? = null
30 | fun getInstance() = INSTANCE
31 | ?: RepoRepository().also {
32 | INSTANCE = it
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/adapter/RepoListAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.adapter
2 |
3 | import android.view.LayoutInflater
4 | import android.view.ViewGroup
5 | import androidx.recyclerview.widget.RecyclerView
6 | import com.ankit.trendinggit.databinding.ViewRepoListItemBinding
7 | import com.ankit.trendinggit.model.Item
8 | import com.ankit.trendinggit.view.adapter.viewHolders.RepoListViewHolder
9 | import com.ankit.trendinggit.view.ui.repolist.RepoListViewModel
10 |
11 | class RepoListAdapter(private val repoListViewModel: RepoListViewModel) : RecyclerView.Adapter() {
12 | var repoList: List- = emptyList()
13 |
14 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepoListViewHolder {
15 | val inflater = LayoutInflater.from(parent.context)
16 | val dataBinding = ViewRepoListItemBinding.inflate(inflater, parent, false)
17 | return RepoListViewHolder(dataBinding, repoListViewModel)
18 | }
19 |
20 | override fun getItemCount() = repoList.size
21 |
22 | override fun onBindViewHolder(holder: RepoListViewHolder, position: Int) {
23 | holder.setup(repoList[position])
24 | }
25 |
26 | fun updateRepoList(repoList: List
- ) {
27 | this.repoList = repoList
28 | notifyDataSetChanged()
29 | }
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/adapter/viewHolders/RepoListViewHolder.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.adapter.viewHolders
2 |
3 | import androidx.databinding.ViewDataBinding
4 | import androidx.navigation.findNavController
5 | import androidx.recyclerview.widget.RecyclerView
6 | import com.ankit.trendinggit.BR
7 | import com.ankit.trendinggit.R
8 | import com.ankit.trendinggit.model.Item
9 | import com.ankit.trendinggit.view.ui.repolist.RepoListViewModel
10 | import com.squareup.picasso.Picasso
11 | import kotlinx.android.synthetic.main.view_repo_list_item.view.*
12 | import org.jetbrains.anko.bundleOf
13 | import org.jetbrains.anko.sdk27.coroutines.onClick
14 |
15 | class RepoListViewHolder constructor(private val dataBinding: ViewDataBinding, private val repoListViewModel: RepoListViewModel)
16 | : RecyclerView.ViewHolder(dataBinding.root) {
17 |
18 | val avatarImage = itemView.item_avatar
19 | fun setup(itemData: Item) {
20 | dataBinding.setVariable(BR.itemData, itemData)
21 | dataBinding.executePendingBindings()
22 |
23 | Picasso.get().load(itemData.owner.avatar_url).into(avatarImage);
24 |
25 | itemView.onClick {
26 | val bundle = bundleOf("url" to itemData.html_url)
27 | itemView.findNavController().navigate(R.id.action_repoListFragment_to_repoDetailFragment, bundle)
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_repo_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
16 |
17 |
22 |
23 |
29 |
30 |
37 |
38 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'androidx.navigation.safeargs'
5 | apply plugin: 'kotlin-kapt'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "com.ankit.trendinggit"
11 | minSdkVersion 17
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | dataBinding {
24 | enabled = true
25 | }
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
31 | implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
32 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
33 |
34 | // Navigation component
35 | implementation "android.arch.navigation:navigation-fragment:$rootProject.nav_version" // use -ktx for Kotlin
36 | implementation "android.arch.navigation:navigation-ui:$rootProject.nav_version" // use -ktx for Kotlin
37 | implementation "android.arch.navigation:navigation-runtime-ktx:$rootProject.nav_version" // use -ktx for Kotlin
38 | implementation "android.arch.work:work-runtime-ktx:$rootProject.workVersion" // use -ktx for Kotlin
39 |
40 | // Anko
41 | implementation "org.jetbrains.anko:anko:$rootProject.anko_version"
42 | implementation "org.jetbrains.anko:anko-commons:$rootProject.anko_version"
43 |
44 | // Retrofit
45 | implementation 'com.squareup.retrofit2:retrofit:2.3.0'
46 | implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
47 | implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
48 |
49 | // Picasso
50 | implementation 'com.squareup.picasso:picasso:2.71828'
51 |
52 | // Databinding compiler
53 | kapt 'com.android.databinding:compiler:3.2.0-alpha10'
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/model/api/ApiClient.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.model.api
2 |
3 | import com.ankit.trendinggit.view.utils.Constants.Companion.BASE_URL
4 | import com.ankit.trendinggit.view.utils.Constants.Companion.DEBUG
5 | import com.ankit.trendinggit.view.utils.Constants.Companion.REQUEST_TIMEOUT_DURATION
6 | import com.google.gson.GsonBuilder
7 | import okhttp3.Interceptor
8 | import okhttp3.OkHttpClient
9 | import okhttp3.logging.HttpLoggingInterceptor
10 | import retrofit2.Retrofit
11 | import retrofit2.converter.gson.GsonConverterFactory
12 | import java.util.concurrent.TimeUnit
13 |
14 | object ApiClient {
15 |
16 | val instance: ApiService = Retrofit.Builder().run {
17 | val gson = GsonBuilder()
18 | .enableComplexMapKeySerialization()
19 | .setPrettyPrinting()
20 | .create()
21 |
22 | baseUrl(BASE_URL)
23 | addConverterFactory(GsonConverterFactory.create(gson))
24 | client(createRequestInterceptorClient())
25 | build()
26 | }.create(ApiService::class.java)
27 |
28 |
29 | private fun createRequestInterceptorClient(): OkHttpClient {
30 | val interceptor = Interceptor { chain ->
31 | val original = chain.request()
32 | val requestBuilder = original.newBuilder()
33 | val request = requestBuilder.build()
34 | chain.proceed(request)
35 | }
36 |
37 | return if (DEBUG) {
38 | OkHttpClient.Builder()
39 | .addInterceptor(interceptor)
40 | .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
41 | .connectTimeout(REQUEST_TIMEOUT_DURATION.toLong(), TimeUnit.SECONDS)
42 | .readTimeout(REQUEST_TIMEOUT_DURATION.toLong(), TimeUnit.SECONDS)
43 | .writeTimeout(REQUEST_TIMEOUT_DURATION.toLong(), TimeUnit.SECONDS)
44 | .build()
45 | } else {
46 | OkHttpClient.Builder()
47 | .addInterceptor(interceptor)
48 | .connectTimeout(REQUEST_TIMEOUT_DURATION.toLong(), TimeUnit.SECONDS)
49 | .readTimeout(REQUEST_TIMEOUT_DURATION.toLong(), TimeUnit.SECONDS)
50 | .writeTimeout(REQUEST_TIMEOUT_DURATION.toLong(), TimeUnit.SECONDS)
51 | .build()
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/ui/repolist/RepoListFragment.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.ui.repolist
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.lifecycle.Observer
9 | import androidx.lifecycle.ViewModelProviders
10 | import androidx.recyclerview.widget.DividerItemDecoration
11 | import androidx.recyclerview.widget.LinearLayoutManager
12 | import com.ankit.trendinggit.databinding.FragmentRepoListBinding
13 | import com.ankit.trendinggit.view.adapter.RepoListAdapter
14 | import kotlinx.android.synthetic.main.fragment_repo_list.*
15 | import org.jetbrains.anko.longToast
16 |
17 | class RepoListFragment : Fragment() {
18 |
19 | private lateinit var viewDataBinding: FragmentRepoListBinding
20 | private lateinit var adapter: RepoListAdapter
21 |
22 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
23 | viewDataBinding = FragmentRepoListBinding.inflate(inflater, container, false).apply {
24 | viewmodel = ViewModelProviders.of(this@RepoListFragment).get(RepoListViewModel::class.java)
25 | setLifecycleOwner(viewLifecycleOwner)
26 | }
27 | return viewDataBinding.root
28 | }
29 |
30 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
31 | super.onViewCreated(view, savedInstanceState)
32 | viewDataBinding.viewmodel?.fetchRepoList()
33 |
34 | setupAdapter()
35 | setupObservers()
36 | }
37 |
38 | private fun setupObservers() {
39 | viewDataBinding.viewmodel?.repoListLive?.observe(viewLifecycleOwner, Observer {
40 | adapter.updateRepoList(it)
41 | })
42 |
43 | viewDataBinding.viewmodel?.toastMessage?.observe(viewLifecycleOwner, Observer {
44 | activity?.longToast(it)
45 | })
46 | }
47 |
48 | private fun setupAdapter() {
49 | val viewModel = viewDataBinding.viewmodel
50 | if (viewModel != null) {
51 | adapter = RepoListAdapter(viewDataBinding.viewmodel!!)
52 | val layoutManager = LinearLayoutManager(activity)
53 | repo_list_rv.layoutManager = layoutManager
54 | repo_list_rv.addItemDecoration(DividerItemDecoration(activity, layoutManager.orientation))
55 | repo_list_rv.adapter = adapter
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Android ###
2 | # Built application files
3 | *.apk
4 | *.ap_
5 |
6 | # Files for the Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 | /*/build/
20 |
21 | # Local configuration file (sdk path, etc)
22 | local.properties
23 |
24 | # Proguard folder generated by Eclipse
25 | proguard/
26 |
27 | # Log Files
28 | *.log
29 |
30 |
31 | ### OSX ###
32 | .DS_Store
33 | .AppleDouble
34 | .LSOverride
35 |
36 | # Icon must end with two \r
37 | Icon
38 |
39 |
40 | # Thumbnails
41 | ._*
42 |
43 | # Files that might appear on external disk
44 | .Spotlight-V100
45 | .Trashes
46 |
47 | # Directories potentially created on remote AFP share
48 | .AppleDB
49 | .AppleDesktop
50 | Network Trash Folder
51 | Temporary Items
52 | .apdisk
53 |
54 |
55 | ### Windows ###
56 | # Windows image file caches
57 | Thumbs.db
58 | ehthumbs.db
59 |
60 | # Folder config file
61 | Desktop.ini
62 |
63 | # Recycle Bin used on file shares
64 | $RECYCLE.BIN/
65 |
66 | # Windows Installer files
67 | *.cab
68 | *.msi
69 | *.msm
70 | *.msp
71 |
72 | # Windows shortcuts
73 | *.lnk
74 |
75 |
76 | ### Linux ###
77 | *~
78 |
79 | # KDE directory preferences
80 | .directory
81 |
82 | # Linux trash folder which might appear on any partition or disk
83 | .Trash-*
84 |
85 |
86 | ### Intellij ###
87 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
88 |
89 | *.iml
90 |
91 | ## Directory-based project format:
92 | .idea/
93 | # if you remove the above rule, at least ignore the following:
94 |
95 | # User-specific stuff:
96 | # .idea/workspace.xml
97 | # .idea/tasks.xml
98 | # .idea/dictionaries
99 |
100 | # Sensitive or high-churn files:
101 | # .idea/dataSources.ids
102 | # .idea/dataSources.xml
103 | # .idea/sqlDataSources.xml
104 | # .idea/dynamic.xml
105 | # .idea/uiDesigner.xml
106 |
107 | # Gradle:
108 | # .idea/gradle.xml
109 | # .idea/libraries
110 |
111 | # Mongo Explorer plugin:
112 | # .idea/mongoSettings.xml
113 |
114 | ## File-based project format:
115 | *.ipr
116 | *.iws
117 |
118 | ## Plugin-specific files:
119 |
120 | # IntelliJ
121 | out/
122 |
123 | # mpeltonen/sbt-idea plugin
124 | .idea_modules/
125 |
126 | # JIRA plugin
127 | atlassian-ide-plugin.xml
128 |
129 | # Crashlytics plugin (for Android Studio and IntelliJ)
130 | com_crashlytics_export_strings.xml
131 | crashlytics.properties
132 | crashlytics-build.properties
133 |
134 | # Output file
135 | app/prod/release/output.json
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_repo_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
31 |
32 |
42 |
43 |
52 |
53 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/view/ui/repodetail/RepoDetailFragment.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.view.ui.repodetail
2 |
3 | import android.graphics.Bitmap
4 | import android.os.Build
5 | import android.os.Bundle
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import android.webkit.WebSettings
10 | import android.webkit.WebView
11 | import android.webkit.WebViewClient
12 | import androidx.fragment.app.Fragment
13 | import com.ankit.trendinggit.R
14 | import kotlinx.android.synthetic.main.fragment_repo_detail.*
15 | import org.jetbrains.anko.sdk27.coroutines.onClick
16 |
17 |
18 | class RepoDetailFragment : Fragment() {
19 |
20 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
21 | return inflater.inflate(R.layout.fragment_repo_detail, container, false)
22 | }
23 |
24 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
25 | super.onViewCreated(view, savedInstanceState)
26 | val url = arguments?.let { RepoDetailFragmentArgs.fromBundle(it).url }
27 |
28 | setupWebView()
29 | setClickListeners()
30 |
31 | repo_web_view.loadUrl(url)
32 | }
33 |
34 | private fun setClickListeners() {
35 | repo_back_button.onClick {
36 | repo_web_view.goBack()
37 | }
38 |
39 | repo_forward_button.onClick {
40 | repo_web_view.goForward()
41 | }
42 |
43 | repo_refresh_button.onClick {
44 | repo_web_view.reload()
45 | }
46 | }
47 |
48 | private fun setupWebView() {
49 | repo_web_view.setInitialScale(1)
50 | val webSettings = repo_web_view.settings
51 | webSettings.setAppCacheEnabled(false)
52 | webSettings.builtInZoomControls = true
53 | webSettings.displayZoomControls = false
54 | webSettings.javaScriptEnabled = true
55 | webSettings.useWideViewPort = true
56 | webSettings.domStorageEnabled = true
57 |
58 | repo_web_view.webViewClient = object : WebViewClient() {
59 | override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
60 | super.onPageStarted(view, url, favicon)
61 | if (repo_back_button != null && repo_forward_button != null && repo_web_view != null && repo_progress_view != null) {
62 | repo_back_button.isEnabled = repo_web_view.canGoBack()
63 | repo_forward_button.isEnabled = repo_web_view.canGoForward()
64 | repo_progress_view.visibility = View.VISIBLE
65 | }
66 | }
67 |
68 | override fun onPageFinished(view: WebView?, url: String?) {
69 | super.onPageFinished(view, url)
70 | if (repo_back_button != null && repo_forward_button != null && repo_web_view != null && repo_progress_view != null) {
71 | repo_back_button.isEnabled = repo_web_view.canGoBack()
72 | repo_forward_button.isEnabled = repo_web_view.canGoForward()
73 | repo_progress_view.visibility = View.GONE
74 | }
75 | }
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ankit/trendinggit/model/ApiResponse.kt:
--------------------------------------------------------------------------------
1 | package com.ankit.trendinggit.model
2 |
3 | data class GitResponse(
4 | val total_count: Int,
5 | val incomplete_results: Boolean,
6 | val items: List
-
7 | )
8 |
9 | data class Item(
10 | val id: Int,
11 | val node_id: String,
12 | val name: String,
13 | val full_name: String,
14 | val owner: Owner,
15 | val private: Boolean,
16 | val html_url: String,
17 | val description: String,
18 | val fork: Boolean,
19 | val url: String,
20 | val forks_url: String,
21 | val keys_url: String,
22 | val collaborators_url: String,
23 | val teams_url: String,
24 | val hooks_url: String,
25 | val issue_events_url: String,
26 | val events_url: String,
27 | val assignees_url: String,
28 | val branches_url: String,
29 | val tags_url: String,
30 | val blobs_url: String,
31 | val git_tags_url: String,
32 | val git_refs_url: String,
33 | val trees_url: String,
34 | val statuses_url: String,
35 | val languages_url: String,
36 | val stargazers_url: String,
37 | val contributors_url: String,
38 | val subscribers_url: String,
39 | val subscription_url: String,
40 | val commits_url: String,
41 | val git_commits_url: String,
42 | val comments_url: String,
43 | val issue_comment_url: String,
44 | val contents_url: String,
45 | val compare_url: String,
46 | val merges_url: String,
47 | val archive_url: String,
48 | val downloads_url: String,
49 | val issues_url: String,
50 | val pulls_url: String,
51 | val milestones_url: String,
52 | val notifications_url: String,
53 | val labels_url: String,
54 | val releases_url: String,
55 | val deployments_url: String,
56 | val created_at: String,
57 | val updated_at: String,
58 | val pushed_at: String,
59 | val git_url: String,
60 | val ssh_url: String,
61 | val clone_url: String,
62 | val svn_url: String,
63 | val homepage: String,
64 | val size: Int,
65 | val stargazers_count: Int,
66 | val watchers_count: Int,
67 | val language: String,
68 | val has_issues: Boolean,
69 | val has_projects: Boolean,
70 | val has_downloads: Boolean,
71 | val has_wiki: Boolean,
72 | val has_pages: Boolean,
73 | val forks_count: Int,
74 | val mirror_url: Any,
75 | val archived: Boolean,
76 | val open_issues_count: Int,
77 | val license: License,
78 | val forks: Int,
79 | val open_issues: Int,
80 | val watchers: Int,
81 | val default_branch: String,
82 | val score: Double
83 | )
84 |
85 | data class Owner(
86 | val login: String,
87 | val id: Int,
88 | val node_id: String,
89 | val avatar_url: String,
90 | val gravatar_id: String,
91 | val url: String,
92 | val html_url: String,
93 | val followers_url: String,
94 | val following_url: String,
95 | val gists_url: String,
96 | val starred_url: String,
97 | val subscriptions_url: String,
98 | val organizations_url: String,
99 | val repos_url: String,
100 | val events_url: String,
101 | val received_events_url: String,
102 | val type: String,
103 | val site_admin: Boolean
104 | )
105 |
106 | data class License(
107 | val key: String,
108 | val name: String,
109 | val spdx_id: String,
110 | val url: String,
111 | val node_id: String
112 | )
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_repo_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
17 |
18 |
23 |
24 |
29 |
30 |
40 |
41 |
42 |
51 |
52 |
59 |
60 |
65 |
66 |
73 |
74 |
75 |
84 |
85 |
90 |
91 |
98 |
99 |
100 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------