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
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
## Android Programming Task
## Ruby on Rails latest commits
A quick app to practice Kotlin and MVVM

In order to be considered for the Android position, you must complete the following steps.
![image](screenshots/solution.png)

## The Solution
See [source](source).

## The Challenge

In order to be considered for the Android position, you must complete the following steps.

*Note: This task should take no longer than 1-2 hours at the most.*



### Prerequisites

- Please note that this will require some basic [Java](http://heather.cs.ucdavis.edu/~matloff/Java/JavaIntro.html) and [Android](http://d.android.com) knowledge.
- Please note that this will require some basic [Java](http://heather.cs.ucdavis.edu/~matloff/Java/JavaIntro.html) and [Android](http://d.android.com) knowledge.

- If you don't know java, [take a few minutes to learn the basics](http://mobile.tutsplus.com/series/learn-java-android-development/) and if you don't know Android [learn about it here](http://d.android.com/resources/index.html).

Expand All @@ -17,14 +25,12 @@ In order to be considered for the Android position, you must complete the follow
## Task

1. Fork this repository (if you don't know how to do that, Google is your friend)
2. Create a *source* folder to contain your code.
2. Create a *source* folder to contain your code.
3. In the *source* directory, please create an Android app that accomplishes the following:
- Connect to the [Github API](http://developer.github.com/)
- Find the [rails/rails](http://github.com/rails/rails) repository
- Find the most recent commits (choose at least 25 or more of the commits)
- Create a RecyclerView that displays the recent commits by author in a view.
- [Click here](example.jpg) for a screenshot mock up of what the final product should look like
- Create a RecyclerView that displays the recent commits by author in a view.
- [Click here](screenshots/example.jpg) for a screenshot mock up of what the final product should look like
4. Commit and Push your code to your new repository
5. Send us a pull request, we will review your code and get back to you


File renamed without changes
Binary file added screenshots/solution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions source/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.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
10 changes: 10 additions & 0 deletions source/.idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions source/.idea/codeStyles/codeStyleConfig.xml

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

20 changes: 20 additions & 0 deletions source/.idea/gradle.xml

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

9 changes: 9 additions & 0 deletions source/.idea/misc.xml

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

6 changes: 6 additions & 0 deletions source/.idea/vcs.xml

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

1 change: 1 addition & 0 deletions source/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
42 changes: 42 additions & 0 deletions source/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.westgoten.ruby_on_rails_latest_commits"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

kotlinOptions {
jvmTarget = "1.8"
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0-beta01'
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
21 changes: 21 additions & 0 deletions source/app/proguard-rules.pro
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.westgoten.ruby_on_rails_latest_commits

import androidx.test.InstrumentationRegistry
import androidx.test.runner.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.getTargetContext()
assertEquals("com.westgoten.mygithubcommits", appContext.packageName)
}
}
23 changes: 23 additions & 0 deletions source/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.westgoten.ruby_on_rails_latest_commits">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.westgoten.ruby_on_rails_latest_commits.view.MainActivity">
<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,5 @@
package com.westgoten.ruby_on_rails_latest_commits.model

data class Author(
var name: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.westgoten.ruby_on_rails_latest_commits.model

data class Commit(
var author: Author? = null,
var message: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.westgoten.ruby_on_rails_latest_commits.model

data class CommitMetadata(
var sha: String? = null,
var commit: Commit? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.westgoten.ruby_on_rails_latest_commits.model.api

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.westgoten.ruby_on_rails_latest_commits.model.CommitMetadata
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object GithubCaller {
private var service: GithubService? = null

fun getCommits(owner: String, repo: String): LiveData<List<CommitMetadata>?> {
if (service == null)
createService()
val observableCommitList = MutableLiveData<List<CommitMetadata>>()
val call = service?.getCommits(owner, repo)
startRequest(call, observableCommitList)
return observableCommitList
}

private fun createService() {
val retrofit = Retrofit.Builder()
.baseUrl(GithubService.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()

service = retrofit.create(GithubService::class.java)
}

private fun startRequest(call: Call<List<CommitMetadata>>?,
observableCommitList: MutableLiveData<List<CommitMetadata>>) {
call?.enqueue(object: Callback<List<CommitMetadata>> {
override fun onFailure(call: Call<List<CommitMetadata>>, t: Throwable) {
Log.e("ApiCaller", "Failed request: ${t.message}")
}

override fun onResponse(call: Call<List<CommitMetadata>>, response: Response<List<CommitMetadata>>) {
if (response.isSuccessful)
observableCommitList.value = response.body()
else
Log.e("ApiCaller", "Failed request: ${response.code()} - ${response.message()}")
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.westgoten.ruby_on_rails_latest_commits.model.api

import com.westgoten.ruby_on_rails_latest_commits.model.CommitMetadata
import retrofit2.http.GET
import retrofit2.Call
import retrofit2.http.Headers
import retrofit2.http.Path

interface GithubService {
companion object {
const val BASE_URL = "https://api.github.com/"
const val HEADER_ACCEPT_VERSION = "Accept: application/vnd.github.v3+json"
}

@Headers(HEADER_ACCEPT_VERSION)
@GET("repos/{owner}/{repo}/commits")
fun getCommits(@Path("owner") owner: String, @Path("repo") repo: String): Call<List<CommitMetadata>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.westgoten.ruby_on_rails_latest_commits.view

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.RecyclerView
import com.westgoten.ruby_on_rails_latest_commits.model.CommitMetadata
import com.westgoten.ruby_on_rails_latest_commits.R

class CommitListAdapter(observableCommitList: LiveData<List<CommitMetadata>?>?,
lifecycleOwner: AppCompatActivity) :
RecyclerView.Adapter<CommitListAdapter.CommitListViewHolder>() {

private var commitList: List<CommitMetadata>? = null
private val activity = lifecycleOwner

init {
observableCommitList?.observe(lifecycleOwner, Observer {
commitList = it
notifyDataSetChanged()
})
}

class CommitListViewHolder(val item: LinearLayout,
val authorName: TextView,
val commitHash: TextView,
val commitMessage: TextView) : RecyclerView.ViewHolder(item)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommitListViewHolder {
val item = LayoutInflater.from(parent.context).inflate(R.layout.item_commit_list,
parent, false) as LinearLayout
val authorName: TextView = item.findViewById(R.id.commit_author_name)
val commitHash: TextView = item.findViewById(R.id.commit_hash)
val commitMessage: TextView = item.findViewById(R.id.commit_message)

return CommitListViewHolder(item, authorName, commitHash, commitMessage)
}

override fun getItemCount(): Int {
return commitList?.size ?: 0
}

override fun onBindViewHolder(holder: CommitListViewHolder, position: Int) {
val commitMetadata = commitList?.get(position)
val commit = commitMetadata?.commit
val author = commit?.author

holder.authorName.text = author?.name
holder.commitHash.text = String.format(activity.getString(R.string.commit_hash_format),
commitMetadata?.sha ?: "")
holder.commitMessage.text = commit?.message
}
}
Loading