Skip to content

Mobile Android challenge #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions Mobile/GameOfThrones/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.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
.cxx
local.properties
3 changes: 3 additions & 0 deletions Mobile/GameOfThrones/.idea/.gitignore

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

1 change: 1 addition & 0 deletions Mobile/GameOfThrones/.idea/.name

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

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

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

19 changes: 19 additions & 0 deletions Mobile/GameOfThrones/.idea/gradle.xml

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

10 changes: 10 additions & 0 deletions Mobile/GameOfThrones/.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 Mobile/GameOfThrones/.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 Mobile/GameOfThrones/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
100 changes: 100 additions & 0 deletions Mobile/GameOfThrones/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'com.google.dagger.hilt.android'
}

android {
namespace 'com.example.gameofthrones'
compileSdk 33

defaultConfig {
applicationId "com.example.gameofthrones"
minSdk 24
targetSdk 33
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
}
}
kapt {
correctErrorTypes true
}
dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.dagger:hilt-android:2.45'
kapt 'com.google.dagger:hilt-compiler:2.45'
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

//Lifecycle
def lifecycle_version = "2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.fragment:fragment-ktx:1.5.2"
//Kotlin Coroutines
def coroutines_android_version = '1.3.7'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_android_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_android_version"

//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.45"
kapt "com.google.dagger:hilt-android-compiler:2.40.5"
implementation 'com.google.dagger:hilt-android:2.45'
kapt 'com.google.dagger:hilt-compiler:2.45'
implementation "androidx.navigation:navigation-compose:2.5.3"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0"
kapt "androidx.hilt:hilt-compiler:1.0.0"
//Room
def room_version = "2.3.0"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"

//Navigation
def nav_version = "2.3.0"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

//Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'

//Timber
implementation 'com.jakewharton.timber:timber:4.7.1'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
21 changes: 21 additions & 0 deletions Mobile/GameOfThrones/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.gameofthrones

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

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

<application
android:name=".GotApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.GameOfThrones"
tools:targetApi="31">
<activity
android:name=".ui.MainActivity"
android:exported="true">
<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,15 @@
package com.example.gameofthrones

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

@HiltAndroidApp
class GotApplication: Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.gameofthrones.adapters

import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.widget.TextView
import com.example.gameofthrones.R
import com.example.gameofthrones.data.GameOfThronesResponsesItem

class GameOfThronesAdapter(private val houses: List<GameOfThronesResponsesItem>) : RecyclerView.Adapter<GameOfThronesAdapter.ViewHolder>(){

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.item_game_of_thrones, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(houses[position])

override fun getItemCount() = houses.size

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(item: GameOfThronesResponsesItem) {
val textView: TextView = itemView.findViewById(R.id.tv_name)
textView.text = item.name
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.gameofthrones.api

import com.example.gameofthrones.data.GameOfThronesResponsesItem
import retrofit2.Call
import retrofit2.http.GET

interface GameOfThronesApi {
@GET("api/houses")
fun getHouses( ):Call<List<GameOfThronesResponsesItem>>


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.gameofthrones.api
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import com.example.gameofthrones.util.Constants.Companion.BASE_URL
import retrofit2.converter.moshi.MoshiConverterFactory

class RetrofitInstance {

companion object {
var mRetrofit: Retrofit? = null

fun getInstance(): Retrofit{
return Retrofit.Builder().baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
// we need to add converter factory to
// convert JSON object to Java object
.build()

}
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.gameofthrones.data

import com.google.gson.annotations.SerializedName

data class GameOfThronesResponsesItem(
val url: String,
val name: String,
val region: String,
val coatOfArms: String,
val words: String,
val titles: List<String>,
val seats: List<String>,
val currentLord: String,
val heir: String,
val overlord: String,
val founded: String,
val founder: String,
val diedOut: String,
val ancestralWeapons: List<String>,
val cadetBranches: List<String>,
val swornMembers: List<String>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.gameofthrones.data.entities

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters

@Entity(tableName = "houses")
data class HouseGameOfThrones(
@TypeConverters(StringListTypeConverter::class)
val ancestralWeapons: List<String>? = null,
val cadetBranches: List<String>? = null,
val coatOfArms: String,
val currentLord: String,
val diedOut: String,
val founded: String,
val founder: String,
val heir: String,
val name: String,
val overlord: String,
val region: String,
val seats: List<String>,
val swornMembers: List<String>? = null,
val titles: List<String>? = null,
val url: String,
val words: String
)
{
@PrimaryKey(autoGenerate = true)
var id: Int? = null
}

Loading