Skip to content

Commit

Permalink
- RepoDetail Fragment created
Browse files Browse the repository at this point in the history
- Other resource files updated
- App screenshots added
- Readme updated
  • Loading branch information
ankitb committed Sep 10, 2018
1 parent 58c2158 commit f94d336
Show file tree
Hide file tree
Showing 22 changed files with 331 additions and 16 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# trending-git
Trending Git App

- MVVM (KOTLIN)
- ViewModel
- LiveData
- Navigation Component
- Data binding

Screen Shots

![alt text](screenshot/s1.png)
![alt text](screenshot/s2.png)
![alt text](screenshot/s3.png)
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ankit.trendinggit"
minSdkVersion 16
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -50,6 +50,9 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'

// Picasso
implementation 'com.squareup.picasso:picasso:2.71828'

// Databinding compiler
kapt 'com.android.databinding:compiler:3.2.0-alpha10'
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".TrendingGitApp"
android:allowBackup="false"
android:icon="@drawable/git_icon"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ankit.trendinggit.model.api
package com.ankit.trendinggit.model

import com.ankit.trendinggit.model.GitResponse
import com.ankit.trendinggit.model.api.ApiClient
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -10,13 +10,13 @@ class RepoRepository {
// GET repo list
fun getRepoList(onResult: (isSuccess: Boolean, response: GitResponse?) -> Unit) {

ApiClient.instance.getRepo().enqueue(object :Callback<GitResponse> {
ApiClient.instance.getRepo().enqueue(object : Callback<GitResponse> {
override fun onResponse(call: Call<GitResponse>?, response: Response<GitResponse>?) {
if (response != null && response.isSuccessful)
onResult(true, response.body()!!)
else
onResult(false, null)
}
}

override fun onFailure(call: Call<GitResponse>?, t: Throwable?) {
onResult(false, null)
Expand All @@ -27,8 +27,9 @@ class RepoRepository {

companion object {
private var INSTANCE: RepoRepository? = null
fun getInstance() = INSTANCE ?: RepoRepository().also {
INSTANCE = it
}
fun getInstance() = INSTANCE
?: RepoRepository().also {
INSTANCE = it
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import retrofit2.http.Query
interface ApiService {

@GET("search/repositories")
fun getRepo(@Query("q") search: String = "trending"): Call<GitResponse>
fun getRepo(@Query("q") search: String = "trending", @Query("sort") sort: String = "stars"): Call<GitResponse>
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
package com.ankit.trendinggit.view.adapter.viewHolders

import androidx.databinding.ViewDataBinding
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.ankit.trendinggit.BR
import com.ankit.trendinggit.R
import com.ankit.trendinggit.model.Item
import com.ankit.trendinggit.view.ui.repolist.RepoListViewModel
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.view_repo_list_item.view.*
import org.jetbrains.anko.bundleOf
import org.jetbrains.anko.sdk25.coroutines.onClick

class RepoListViewHolder constructor(private val dataBinding: ViewDataBinding, private val repoListViewModel: RepoListViewModel)
: RecyclerView.ViewHolder(dataBinding.root) {

val avatarImage = itemView.item_avatar
fun setup(itemData: Item) {
dataBinding.setVariable(BR.itemData, itemData)
dataBinding.executePendingBindings()

Picasso.get().load(itemData.owner.avatar_url).into(avatarImage);

itemView.onClick {
val bundle = bundleOf("url" to itemData.html_url)
itemView.findNavController().navigate(R.id.action_repoListFragment_to_repoDetailFragment, bundle)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ open class BaseViewModel : ViewModel() {
val dataLoading = MutableLiveData<Boolean>().apply { value = false }

val toastMessage = MutableLiveData<String>()

val appContext get() = TrendingGitApp.instance
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.ankit.trendinggit.view.ui.repodetail

import android.graphics.Bitmap
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.fragment.app.Fragment
import com.ankit.trendinggit.R
import kotlinx.android.synthetic.main.fragment_repo_detail.*
import org.jetbrains.anko.sdk25.coroutines.onClick


class RepoDetailFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_repo_detail, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val url = RepoDetailFragmentArgs.fromBundle(arguments).url

setupWebView()
setClickListeners()

repo_web_view.loadUrl(url)
}

private fun setClickListeners() {
repo_back_button.onClick {
repo_web_view.goBack()
}

repo_forward_button.onClick {
repo_web_view.goForward()
}

repo_refresh_button.onClick {
repo_web_view.reload()
}
}

private fun setupWebView() {
repo_web_view.setInitialScale(1)
val webSettings = repo_web_view.settings
webSettings.setAppCacheEnabled(false)
webSettings.builtInZoomControls = true
webSettings.displayZoomControls = false
webSettings.javaScriptEnabled = true
webSettings.useWideViewPort = true
webSettings.domStorageEnabled = true

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW;
}

repo_web_view.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
if (repo_back_button != null && repo_forward_button != null && repo_web_view != null && repo_progress_view != null) {
repo_back_button.isEnabled = repo_web_view.canGoBack()
repo_forward_button.isEnabled = repo_web_view.canGoForward()
repo_progress_view.visibility = View.VISIBLE
}
}

override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
if (repo_back_button != null && repo_forward_button != null && repo_web_view != null && repo_progress_view != null) {
repo_back_button.isEnabled = repo_web_view.canGoBack()
repo_forward_button.isEnabled = repo_web_view.canGoForward()
repo_progress_view.visibility = View.GONE
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.ankit.trendinggit.databinding.FragmentRepoListBinding
import com.ankit.trendinggit.view.adapter.RepoListAdapter
import kotlinx.android.synthetic.main.fragment_repo_list.*
import org.jetbrains.anko.longToast

class RepoListFragment : Fragment() {

Expand All @@ -33,10 +34,15 @@ class RepoListFragment : Fragment() {
setupAdapter()
setupObservers()
}

private fun setupObservers() {
viewDataBinding.viewmodel?.repoListLive?.observe(viewLifecycleOwner, Observer {
adapter.updateRepoList(it)
})

viewDataBinding.viewmodel?.toastMessage?.observe(viewLifecycleOwner, Observer {
activity?.longToast(it)
})
}

private fun setupAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.ankit.trendinggit.view.ui.repolist

import androidx.lifecycle.MutableLiveData
import com.ankit.trendinggit.model.Item
import com.ankit.trendinggit.model.api.RepoRepository
import com.ankit.trendinggit.model.RepoRepository
import com.ankit.trendinggit.view.base.BaseViewModel

class RepoListViewModel : BaseViewModel() {
Expand All @@ -12,7 +12,7 @@ class RepoListViewModel : BaseViewModel() {
dataLoading.value = true
RepoRepository.getInstance().getRepoList { isSuccess, response ->
dataLoading.value = false
if(isSuccess) {
if (isSuccess) {
repoListLive.value = response?.items
empty.value = false
} else {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_arrow_backward.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#828282"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_arrow_forward.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#828282"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
</vector>
Binary file added app/src/main/res/drawable/ic_fork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_refresh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#828282"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_star_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>
62 changes: 62 additions & 0 deletions app/src/main/res/layout/fragment_repo_detail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".view.ui.MainActivity">

<WebView
android:id="@+id/repo_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/repo_btn_container" />

<RelativeLayout
android:id="@+id/repo_btn_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="@dimen/_20dp">

<Button
android:id="@+id/repo_back_button"
android:layout_width="@dimen/_20dp"
android:layout_height="@dimen/_20dp"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/_20dp"
android:layout_marginEnd="@dimen/_20dp"
android:background="@drawable/ic_arrow_backward"
android:enabled="false" />

<Button
android:id="@+id/repo_forward_button"
android:layout_width="@dimen/_20dp"
android:layout_height="@dimen/_20dp"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/_20dp"
android:layout_marginEnd="@dimen/_20dp"
android:layout_toEndOf="@id/repo_back_button"
android:background="@drawable/ic_arrow_forward"
android:enabled="false" />

<Button
android:id="@+id/repo_refresh_button"
android:layout_width="@dimen/_20dp"
android:layout_height="@dimen/_20dp"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/_20dp"
android:layout_marginEnd="@dimen/_20dp"
android:layout_toEndOf="@id/repo_forward_button"
android:background="@drawable/ic_refresh" />

<ProgressBar
android:id="@+id/repo_progress_view"
style="?android:attr/progressBarStyleLarge"
android:layout_width="@dimen/_20dp"
android:layout_height="@dimen/_20dp"
android:layout_centerInParent="true"
android:layout_marginStart="@dimen/_20dp"
android:layout_toEndOf="@id/repo_refresh_button" />
</RelativeLayout>
</RelativeLayout>
Loading

0 comments on commit f94d336

Please sign in to comment.