Skip to content
Merged
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: 0 additions & 3 deletions .idea/codeStyles/Project.xml

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

4 changes: 3 additions & 1 deletion .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

20 changes: 19 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
Expand All @@ -25,11 +27,27 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

// KTN Android Components navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.1'

// KTX
implementation 'androidx.core:core-ktx:1.0.1'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"

// This container view models and data
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

// This container view models and data
implementation 'com.squareup.moshi:moshi-kotlin:1.9.2'
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.9.2'
}
98 changes: 98 additions & 0 deletions app/src/main/assets/monster_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[
{
"imageFile": "monster01",
"monsterName": "Mingle",
"caption": "Double Trouble",
"description": "Mingle excels at doing twice the work in half the time, with pinpoint accuracy. These skills serve her well in her role as Senior Data Analyst for an international cloud computing company. She's also got a penchant for ballroom dance, line dancing, and pretty much any kind of activity that lets her groove to music.",
"price": 0.29,
"scariness": 2
},
{
"imageFile": "monster02",
"monsterName": "Yodel",
"caption": "Yodelay Hee Hoo!",
"description": "Yodel grew up in a family of singers and loud talkers and could never get a word in edgewise. Then his vast talent for yodeling emerged. Now he performs to adoring fans throughout the world, and always has the loudest voice at the dinner table. Incidentally, he's also a loud proponent of net neutrality, and spends countless hours moderating an internet forum devoted solely to that subject.",
"price": 0.19,
"scariness": 4
},
{
"imageFile": "monster03",
"monsterName": "Squido",
"caption": "An Eye for Design",
"description": "Squido's got his hands or rather tentacles, in everything. First and foremost, he's a web designer with an eye for visual aesthetics, but he's also rather keen on UX design and making sure what he creates translates optimally to the end user. In his off-hours he's an avid nature photographer and bowler.",
"price": 0.29,
"scariness": 3
},
{
"imageFile": "monster04",
"monsterName": "Spook",
"caption": "Safe and Sound",
"description": "Cracking code and battling hackers is Spook's forte. She holds a prominent position as Head of Cyber Security for the Department of Monster Defense, where she thwarts attacks on government computer systems as often as she blinks. When not at work, Spook delights in serving up a fright at haunted mansions and ghost walks.",
"price": 0.29,
"scariness": 5
},
{
"imageFile": "monster05",
"monsterName": "Melville",
"caption": "Networking Guru",
"description": "Setting up computer networks has always come easily to Melville. In his role as Senior Network Engineer for Landon Hotel, Melville builds complex blueprints for communication networks, a task that requires enormous attention to detail and patience. When not at work, Melville chooses less taxing mental activities, like hiking in the hills near his Silicon Valley home.",
"price": 0.19,
"scariness": 2
},
{
"imageFile": "monster06",
"monsterName": "Filo",
"caption": "Baker by Day, Techie by Night",
"description": "Filo was named after the wonderful, buttery pastry crust that monsters adore. She’s a prominent baker and pastry chef in monster circles and is always exploring and sharing new dessert trends. In her off time, however, she's quite the techie and dabbles in web and mobile app development. She even built a custom cake ordering app for her pastry business.",
"price": 0.29,
"scariness": 3
},
{
"imageFile": "monster07",
"monsterName": "Blade",
"caption": "Monster APPetite",
"description": "Blade freelances as a mobile app developer and has built some of the most popular Android and iOS apps used in modern monster society, including the award-winning Monster APPetite, which tracks calorie consumption and activity for the health-conscious monster. In his spare time, he competes in national agility contests with his border collie Winston.",
"price": 0.29,
"scariness": 5
},
{
"imageFile": "monster08",
"monsterName": "Timber",
"caption": "Database Expert",
"description": "A natural-born problem-solver, Timber's especially excited to solve complex business problems using databases. As a database administrator for Globe Bank International, he's able to flex his mental muscles using his certifications in Oracle, Microsoft SQL Server, and MySQL. When not behind the computer, Timber can often be found biking, surfing, or lounging around with a good detective novel.",
"price": 0.19,
"scariness": 2
},
{
"imageFile": "monster09",
"monsterName": "Skedaddle",
"caption": "Game of Life",
"description": "When Skedaddle was a teenager, his parents couldn't keep him away from his Game Boy. In fact, they seriously worried that he might not find a suitable career. Now as a prominent game developer for Red30 Tech, he's found his true calling…and put his family's worries to rest. You probably could have guessed this, but in his spare time Skedaddle loves to pay computer games.",
"price": 0.29,
"scariness": 4
},
{
"imageFile": "monster10",
"monsterName": "Smiley",
"caption": "Don’t Worry, Be Happy!",
"description": "With the bad rap they get from movies, monsters have it pretty tough. Perhaps no monster has done more to squash stereotypes than Smiley, who can take anyone’s frown and turn it upside down. That's why Smiley has a reputation as the best computer support specialist on her IT team, three years running.",
"price": 0.29,
"scariness": 1
},
{
"imageFile": "monster11",
"monsterName": "Frex",
"caption": "Born Leader",
"description": "Frex has always had a knack for leadership, starting from his days of being a Monster Scout. After studying computer science in college, and working as an IT specialist at several large companies, he naturally followed the management path. Now, as an IT manager for a Fortune 500 company, he gets to put his technical know-how to work, while also leading a team of talented engineers. Frex's hobbies include golf, billiards, and community service.",
"price": 0.19,
"scariness": 3
},
{
"imageFile": "monster12",
"monsterName": "Drift",
"caption": "In the Clouds",
"description": "After years of everyone saying her head was in the clouds, Drift found her calling as a software engineer developing a well-known cloud solution for the computing giant, Red30 Tech. After work, she prefers to unwind by catching wind in her sail and paragliding high in the sky.",
"price": 0.29,
"scariness": 4
}
]
3 changes: 3 additions & 0 deletions app/src/main/java/com/anelcc/monster/Global.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.anelcc.monster

const val LOG_TAG = "monsterLogging"
39 changes: 39 additions & 0 deletions app/src/main/java/com/anelcc/monster/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.anelcc.monster

import android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import com.anelcc.monster.data.Monster
import com.anelcc.monster.utilities.FileHelper
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory

class MainViewModel(app: Application) : AndroidViewModel(app) {

private val listType = Types.newParameterizedType(
List::class.java, Monster::class.java
)

init {
val resourcesText = FileHelper.getTextFromResources(app, R.raw.monster_data)
Log.i(LOG_TAG, "Resources: $resourcesText")

val assetsText = FileHelper.getTextFromAssets(app, "monster_data.json")
Log.i(LOG_TAG, "Assets: $assetsText")

parseText(assetsText)
}

fun parseText(text: String) {
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
val adapter: JsonAdapter<List<Monster>> = moshi.adapter(listType)
//This is parsing the data
val monsterData = adapter.fromJson(text)

for (monster in monsterData ?: emptyList()) {
Log.i(LOG_TAG,"parseText: ${monster.name} (\$${monster.price})")
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/anelcc/monster/data/Monster.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.anelcc.monster.data

import com.squareup.moshi.Json

data class Monster (
@Json(name = "monsterName")
val name: String,
val imageFile: String,
val caption: String,
val description: String,
val price: Double,
val scariness: Int
)
40 changes: 40 additions & 0 deletions app/src/main/java/com/anelcc/monster/main/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.anelcc.monster.main


import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import com.anelcc.monster.MainViewModel

import com.anelcc.monster.R
import com.anelcc.monster.data.Monster

class MainFragment : Fragment() {

companion object {
fun newInstance() = MainFragment()
}

private lateinit var viewModel: MainViewModel

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {

val monster = Monster("Bob", "myfile", "a caption", "a description", .19, 3)
Log.i("monsterLogging", monster.toString())

return inflater.inflate(R.layout.fragment_main, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
// TODO: Use the ViewModel
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/anelcc/monster/utilities/FileHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.anelcc.monster.utilities

import android.content.Context

class FileHelper {
//In java you create Static methods in Kotlin you function member of the companions
companion object {

fun getTextFromResources(context: Context, resourceId: Int): String {
return context.resources.openRawResource(resourceId).use {
it.bufferedReader().use {
it.readText()
}
}
}

fun getTextFromAssets(context: Context, fileName: String): String {
return context.assets.open(fileName).use {
it.bufferedReader().use {
it.readText()
}
}
}
}
}
15 changes: 7 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="@navigation/nav_graph"
app:defaultNavHost="true"
android:id="@+id/fragment"/>

</androidx.constraintlayout.widget.ConstraintLayout>
14 changes: 14 additions & 0 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".main.MainFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/mainFragment">

<fragment
android:id="@+id/mainFragment"
android:name="com.anelcc.monster.main.MainFragment"
android:label="main_fragment"
tools:layout="@layout/fragment_main"/>
</navigation>
Loading