the biggest gay in existence

This commit is contained in:
Wyatt J. Miller 2020-10-19 19:43:35 -04:00
parent 119540f87d
commit b2a7fc5536
20 changed files with 326 additions and 36 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -30,6 +30,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

View File

@ -9,7 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".DetailsActivity"></activity>
<activity android:name=".ListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -0,0 +1,26 @@
package com.wyattjmiller.favoritefoodrevisited
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class DetailsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_details)
val fragmentManager = supportFragmentManager
var fragment = fragmentManager.findFragmentById(R.id.details_fragment_container)
if (fragment == null) {
val foodId: Int = intent.getIntExtra(EXTRA_FOOD_ID, 1)
fragment = DetailsFragment().newInstance(foodId)
fragmentManager.beginTransaction()
.add(R.id.details_fragment_container, fragment)
.commit()
}
}
companion object {
const val EXTRA_FOOD_ID = "foodId"
}
}

View File

@ -0,0 +1,55 @@
package com.wyattjmiller.favoritefoodrevisited
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.Fragment
class DetailsFragment : Fragment() {
private var mFood: Food? = null
private var btnClick = View.OnClickListener {
val intentUri = Uri.parse(mFood?.website.toString())
val webIntent = Intent(Intent.ACTION_VIEW, intentUri)
startActivity(webIntent)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var foodId: Int = 1
if (arguments != null) {
foodId = arguments!!.getInt("foodId")
}
mFood = context?.let { FoodDatabase.getInstance(it)?.getFood(foodId) }!!
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// inflate!
val view = inflater.inflate(R.layout.fragment_details, container, false)
val nameTextView = view.findViewById(R.id.foodName) as TextView
val websiteButton = view.findViewById(R.id.foodWebsite) as Button
// set texts and buttons
nameTextView.text = mFood!!.name
websiteButton.setOnClickListener(btnClick)
return view
}
fun newInstance(foodId: Int): DetailsFragment {
val fragment = this
val args = Bundle()
args.putInt("foodId", foodId)
fragment.arguments = args
return fragment
}
}

View File

@ -0,0 +1,14 @@
package com.wyattjmiller.favoritefoodrevisited
class Food {
var id = 0
var name: String? = null
var website: String? = null
constructor() {}
constructor(id: Int, name: String?, website: String?) {
this.id = id
this.name = name
this.website = website
}
}

View File

@ -0,0 +1,46 @@
package com.wyattjmiller.favoritefoodrevisited
import android.content.Context
import java.util.*
class FoodDatabase private constructor(context: Context) {
private val mFoods: MutableList<Food>
val bands: List<Any>
get() = mFoods
fun getFood(foodId: Int): Food? {
for (food in mFoods) {
if (food.id === foodId) {
return food
}
}
return null
}
fun getFoods(): List<Food> {
return mFoods
}
companion object {
private var sFoodDatabase: FoodDatabase? = null
fun getInstance(context: Context): FoodDatabase? {
if (sFoodDatabase == null) {
sFoodDatabase = FoodDatabase(context)
}
return sFoodDatabase
}
}
init {
mFoods = ArrayList<Food>()
val res = context.resources
val bands = res.getStringArray(R.array.foods)
val descriptions = res.getStringArray(R.array.websites)
for (i in bands.indices) {
mFoods.add(Food(i + 1, bands[i], descriptions[i]))
}
}
}

View File

@ -0,0 +1,21 @@
package com.wyattjmiller.favoritefoodrevisited
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class ListActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_list)
val fragmentManager = supportFragmentManager
var fragment = fragmentManager.findFragmentById(R.id.list_fragment_container)
if (fragment == null) {
fragment = ListFragment()
fragmentManager.beginTransaction()
.add(R.id.list_fragment_container, fragment)
.commit()
}
}
}

View File

@ -0,0 +1,46 @@
package com.wyattjmiller.favoritefoodrevisited
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
class ListFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater.inflate(R.layout.fragment_list, container, false)
val layout = view as LinearLayout
val foodList: List<Food> = context?.let { FoodDatabase.getInstance(it)?.getFoods() }!!
for (i in foodList.indices) {
val button = Button(context)
val layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
layoutParams.setMargins(0, 0, 0, 10) // 10 px
button.layoutParams = layoutParams
val food: Food = context?.let { FoodDatabase.getInstance(it)?.getFood(i + 1) }!!
button.text = food.name
button.tag = food.id.toString()
button.setOnClickListener(buttonClickListener)
layout.addView(button)
}
return view
}
private val buttonClickListener =
View.OnClickListener { view ->
val intent = Intent(activity, DetailsActivity::class.java)
val foodId = view.tag as String
intent.putExtra(DetailsActivity.EXTRA_FOOD_ID, foodId.toInt())
startActivity(intent)
}
}

View File

@ -1,11 +0,0 @@
package com.wyattjmiller.favoritefoodrevisited
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}

View File

@ -0,0 +1,7 @@
<?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:id="@+id/details_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -0,0 +1,7 @@
<?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:id="@+id/list_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,23 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
tools:context="com.wyattjmiller.favoritefoodrevisited.DetailsFragment">
<TextView
android:id="@+id/foodName"
style="@style/foodName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="food name" />
<Button
android:id="@+id/foodWebsite"
style="@style/foodWebsite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Visit the website" />
</LinearLayout>

View File

@ -0,0 +1,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
tools:context="com.wyattjmiller.favoritefoodrevisited.ListFragment" />

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>
<color name="colorPrimary">#42A5F5</color>
<color name="colorPrimaryDark">#42A5F5</color>
<color name="colorAccent">#FF4081</color>
<color name="colorText">#FFF</color>
</resources>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="list_text_size">30sp</dimen>
<dimen name="list_padding">12dp</dimen>
<dimen name="detail_food_text_size">40sp</dimen>
<dimen name="detail_description_text_size">30sp</dimen>
<dimen name="detail_padding">30dp</dimen>
</resources>

View File

@ -1,3 +1,20 @@
<resources>
<string name="app_name">FavoriteFoodRevisited</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string-array name="foods">
<item>Blue Tractor</item>
<item>Buffalo Wild Wings</item>
<item>Bubbas</item>
<item>Burger King</item>
</string-array>
<string-array name="websites">
<item>http://www.bluetractorcookshop.com/bt-tc-temp.html</item>
<item>https://www.buffalowildwings.com/</item>
<item>http://www.tcbubbas.com/</item>
<item>https://www.bk.com/</item>
</string-array>
</resources>

View File

@ -1,10 +1,39 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">@color/colorText</item>
<item name="android:buttonStyle">@style/buttonStyle</item>
</style>
<style name="foodListName">
<item name="android:textSize">@dimen/list_text_size</item>
<item name="android:padding">@dimen/list_padding</item>
</style>
<style name="foodName">
<item name="android:textSize">@dimen/detail_food_text_size</item>
<item name="android:textStyle">bold</item>
<item name="android:paddingLeft">@dimen/detail_padding</item>
<item name="android:paddingRight">@dimen/detail_padding</item>
<item name="android:paddingTop">@dimen/detail_padding</item>
</style>
<style name="foodWebsite">
<item name="android:textSize">@dimen/detail_description_text_size</item>
<item name="android:paddingLeft">@dimen/detail_padding</item>
<item name="android:paddingRight">@dimen/detail_padding</item>
<item name="android:paddingTop">@dimen/detail_padding</item>
</style>
<style name="buttonStyle">
<item name="android:background">@color/colorPrimary</item>
<item name="android:minWidth">@dimen/abc_action_button_min_width_material</item>
<item name="android:minHeight">@dimen/abc_action_button_min_height_material</item>
<item name="android:scaleType">center</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/colorText</item>
<item name="android:textSize">@dimen/list_text_size</item>
</style>
</resources>