Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rifqimfahmi committed Nov 29, 2018
0 parents commit a3b1837
Show file tree
Hide file tree
Showing 64 changed files with 1,621 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
60 changes: 60 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.rifqimfahmi.foorballapps"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

implementation "com.google.android.material:material:$rootProject.material"

// Coroutine
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutine"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutine"

// Retrofit
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofit"
implementation "com.squareup.retrofit2:converter-moshi:$rootProject.retrofit"
implementation "com.squareup.moshi:moshi-kotlin:$rootProject.moshi"
implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:$rootProject.retrofit_coroutine_adapter"

// Network image loader
implementation "com.squareup.picasso:picasso:$rootProject.picasso"

// room
implementation "androidx.room:room-runtime:$rootProject.room_version"
kapt "androidx.room:room-compiler:$rootProject.room_version"
testImplementation "androidx.room:room-testing:$rootProject.room_version"

// Lifecycle
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.lifecycle_version"
testImplementation "androidx.arch.core:core-testing:$rootProject.lifecycle_version"
}
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.rifqimfahmi.foorballapps

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

<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.rifqimfahmi.foorballapps.features.matches.MatchesActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
45 changes: 45 additions & 0 deletions app/src/main/java/com/rifqimfahmi/foorballapps/ViewModelFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.rifqimfahmi.foorballapps

import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.rifqimfahmi.foorballapps.data.source.SportRepository
import com.rifqimfahmi.foorballapps.data.source.local.SportDb
import com.rifqimfahmi.foorballapps.data.source.remote.SportServiceFactory
import com.rifqimfahmi.foorballapps.features.matches.MatchesViewModel

/*
* Created by Rifqi Mulya Fahmi on 21/11/18.
*/

class ViewModelFactory private constructor(
private val application: Application,
private val sportRepository: SportRepository
) : ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel?> create(modelClass: Class<T>): T =
with(modelClass) {
when {
isAssignableFrom(MatchesViewModel::class.java) ->
MatchesViewModel(application, sportRepository)
else ->
error("Invalid View Model class")
}
} as T

companion object {
@Volatile
private var INSTANCE: ViewModelFactory? = null

fun getInstance(application: Application): ViewModelFactory {
return INSTANCE ?: synchronized(ViewModelFactory::class.java) {
ViewModelFactory(
application,
SportRepository.getInstance(
SportDb.getDatabase(application.applicationContext).sportDao(),
SportServiceFactory.getService()
)
).also { INSTANCE = it }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.rifqimfahmi.foorballapps.custom

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

/*
* Created by Rifqi Mulya Fahmi on 19/11/18.
*/

class NonSwipeAbleViewPager(context: Context, attrs: AttributeSet?) : ViewPager(context, attrs) {

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(ev: MotionEvent?): Boolean = false

override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.rifqimfahmi.foorballapps.data.source

import com.rifqimfahmi.foorballapps.data.source.local.SportDao
import com.rifqimfahmi.foorballapps.data.source.remote.SportService

/*
* Created by Rifqi Mulya Fahmi on 19/11/18.
*/

class SportRepository (
val sportDb: SportDao,
val sportService: SportService
) {

companion object {
private var INSTANCE: SportRepository? = null

fun getInstance(sportDb: SportDao, sportService: SportService) : SportRepository =
INSTANCE ?: synchronized(SportRepository::class.java) {
SportRepository(sportDb, sportService)
.also { INSTANCE = it }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.rifqimfahmi.foorballapps.data.source.local

import androidx.room.Dao
import androidx.room.Query
import com.rifqimfahmi.foorballapps.vo.Match

/*
* Created by Rifqi Mulya Fahmi on 21/11/18.
*/

@Dao
interface SportDao {

@Query("SELECT * FROM matches")
fun getMatches(): List<Match>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.rifqimfahmi.foorballapps.data.source.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.rifqimfahmi.foorballapps.vo.Match

/*
* Created by Rifqi Mulya Fahmi on 19/11/18.
*/
@Database(entities = [Match::class], version = 2)
abstract class SportDb : RoomDatabase() {

abstract fun sportDao(): SportDao

companion object {

@Volatile
private var INSTANCE: SportDb? = null

fun getDatabase(context: Context) : SportDb {
return INSTANCE ?: synchronized(this) {
Room.databaseBuilder(context.applicationContext, SportDb::class.java, "sport_db")
.fallbackToDestructiveMigration()
.build()
.also { INSTANCE = it }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.rifqimfahmi.foorballapps.data.source.remote

/*
* Created by Rifqi Mulya Fahmi on 19/11/18.
*/

interface SportService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.rifqimfahmi.foorballapps.data.source.remote

import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory

/*
* Created by Rifqi Mulya Fahmi on 21/11/18.
*/

class SportServiceFactory {
companion object {

@Volatile
private var INSTANCE: SportService? = null

private const val BASE_URL = "https://www.thesportsdb.com/api/v1/json/1/"

fun getService() : SportService {
return INSTANCE ?: synchronized(this) {
val instance = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(MoshiConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()
.create(SportService::class.java)
INSTANCE = instance
instance
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.rifqimfahmi.foorballapps.features.matches

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.rifqimfahmi.foorballapps.R
import com.rifqimfahmi.foorballapps.features.matches.adapter.FavoritesPagerAdapter
import kotlinx.android.synthetic.main.fragment_favorites.*

/*
* Created by Rifqi Mulya Fahmi on 19/11/18.
*/

class FavoritesFragment : Fragment() {

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

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setupViewPager()
}

private fun setupViewPager() {
vpFavorites.adapter = FavoritesPagerAdapter(childFragmentManager)
tabFavorites.setupWithViewPager(vpFavorites)
}

companion object {
fun newInstance() = FavoritesFragment()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.rifqimfahmi.foorballapps.features.matches

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.rifqimfahmi.foorballapps.R
import kotlinx.android.synthetic.main.list_items.*

/*
* Created by Rifqi Mulya Fahmi on 19/11/18.
*/

class FavoritesListFragment : Fragment() {

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

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
}

companion object {
fun newInstance() = FavoritesListFragment()
}
}
Loading

0 comments on commit a3b1837

Please sign in to comment.