diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 45b5654..88ea3aa 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,8 +1,5 @@ - - diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 169fd0d..674414f 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,8 +1,11 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a7509..7bfef59 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/app/build.gradle b/app/build.gradle index bbade9a..f1048ce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,6 +4,8 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' + android { compileSdkVersion 29 buildToolsVersion "29.0.2" @@ -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' } diff --git a/app/src/main/assets/monster_data.json b/app/src/main/assets/monster_data.json new file mode 100644 index 0000000..c81f8c0 --- /dev/null +++ b/app/src/main/assets/monster_data.json @@ -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 + } +] \ No newline at end of file diff --git a/app/src/main/java/com/anelcc/monster/Global.kt b/app/src/main/java/com/anelcc/monster/Global.kt new file mode 100644 index 0000000..f00d15b --- /dev/null +++ b/app/src/main/java/com/anelcc/monster/Global.kt @@ -0,0 +1,3 @@ +package com.anelcc.monster + +const val LOG_TAG = "monsterLogging" \ No newline at end of file diff --git a/app/src/main/java/com/anelcc/monster/MainViewModel.kt b/app/src/main/java/com/anelcc/monster/MainViewModel.kt new file mode 100644 index 0000000..740be75 --- /dev/null +++ b/app/src/main/java/com/anelcc/monster/MainViewModel.kt @@ -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> = 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})") + } + } +} diff --git a/app/src/main/java/com/anelcc/monster/data/Monster.kt b/app/src/main/java/com/anelcc/monster/data/Monster.kt new file mode 100644 index 0000000..727a983 --- /dev/null +++ b/app/src/main/java/com/anelcc/monster/data/Monster.kt @@ -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 +) diff --git a/app/src/main/java/com/anelcc/monster/main/MainFragment.kt b/app/src/main/java/com/anelcc/monster/main/MainFragment.kt new file mode 100644 index 0000000..2505cf8 --- /dev/null +++ b/app/src/main/java/com/anelcc/monster/main/MainFragment.kt @@ -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 + } +} diff --git a/app/src/main/java/com/anelcc/monster/utilities/FileHelper.kt b/app/src/main/java/com/anelcc/monster/utilities/FileHelper.kt new file mode 100644 index 0000000..948a4e0 --- /dev/null +++ b/app/src/main/java/com/anelcc/monster/utilities/FileHelper.kt @@ -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() + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4fc2444..4ecbf01 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,13 +6,12 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml new file mode 100644 index 0000000..95e9363 --- /dev/null +++ b/app/src/main/res/layout/fragment_main.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml new file mode 100644 index 0000000..c5cad7a --- /dev/null +++ b/app/src/main/res/navigation/nav_graph.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/raw/monster_data.json b/app/src/main/res/raw/monster_data.json new file mode 100644 index 0000000..c81f8c0 --- /dev/null +++ b/app/src/main/res/raw/monster_data.json @@ -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 + } +] \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index acbd736..b1e7a89 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,6 @@ Monster + + + Hello blank fragment