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
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

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

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

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

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

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

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

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# NewsProject

This is a test project for job opening. And skill showcase in some degree, I guess.

Full task description here - http://testtask.sebbia.com/swagger-ui.html#!/news-controller/detailsUsingGET

I've spent around 19-20 hours completing the task. That's including some time on studying/reading about Retrofit2, Hilt, View Binding, mb some other stuff. (all off which was relatively new to me)

In current state I don't really like transitions between different screen, I would like to add Loading and Fail states sometime in the future
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
63 changes: 63 additions & 0 deletions app/build.gradle
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'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

android {
compileSdk 31

defaultConfig {
applicationId "com.example.newsproject"
minSdk 26
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled 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 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'

implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'

implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.0'
implementation "androidx.paging:paging-runtime:3.1.0"

implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-compiler:2.38.1"

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
21 changes: 21 additions & 0 deletions 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.example.newsproject

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.newsproject", appContext.packageName)
}
}
26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newsproject">

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NewsProject">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/newsproject/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.newsproject

import android.app.Application
import dagger.hilt.InstallIn
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class App : Application()
23 changes: 23 additions & 0 deletions app/src/main/java/com/example/newsproject/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.newsproject

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.findNavController
import com.example.newsproject.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
private val TAG = "MyMainActivity"
private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
navController = findNavController(R.id.nav_host_fragment_activity_main)
}
}
85 changes: 85 additions & 0 deletions app/src/main/java/com/example/newsproject/data/Models.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.example.newsproject.data

import java.time.Instant
import java.util.Date

//API Models
data class ApiCategoryList(
val code: Int = -1,
val message: String = "",
val list: List<Category> = emptyList()
)

data class ApiNewsList(
val code: Int = -1,
val message: String = "",
val list: MutableList<News> = mutableListOf()
)

data class ApiNews(
val code: Int = -1,
val message: String = "",
val news: News = News()
)

//Cached Data
data class NewsCache(
val newsPageList: MutableList<NewsPage> = mutableListOf(),
var categoryList: List<Category> = listOf()
) {

fun containsNewsPage(categoryId: Long, page: Int): Boolean {
for (item in newsPageList)
if (item.categoryId == categoryId && item.page == page) return true
return false
}

fun addNewsPage(categoryId: Long, page: Int, list: MutableList<News>) {
newsPageList.add(NewsPage(categoryId, page, list))
}

fun getNewsList(categoryId: Long, page: Int): List<News> {
for (item in newsPageList)
if (item.categoryId == categoryId && item.page == page) return item.newsList
return listOf()
}

fun getNews(newsId: Long): News {
for (page in newsPageList)
for (news in page.newsList)
if (news.id == newsId) return news
return News()
}

fun setNews(news: News, state: Boolean = false) {
for (page in newsPageList)
for (i in page.newsList.indices)
if (page.newsList[i].id == news.id) {
news.state = state
page.newsList[i] = news
return
}
}
}

data class NewsPage(
val categoryId: Long = -1,
val page: Int = -1,
val newsList: MutableList<News> = mutableListOf()
)


//Data Model
data class Category(
val id: Long = -1,
val name: String = ""
)

data class News(
val id: Long = -1,
val title: String = "",
val date: Date = Date.from(Instant.now()),
val shortDescription: String = "",
val fullDescription: String = "",
var state: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.newsproject.data

interface NewsRemoteDataSource {
fun getCategoryList(callback: (Result<ApiCategoryList?>) -> Unit)

fun getNewsList(
categoryId: Long,
page: Int,
callback: (Result<ApiNewsList?>) -> Unit
)

fun getNews(
newsId: Long,
callback: (Result<ApiNews?>) -> Unit
)
}
Loading