Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5ca9586
Removals and additions to make starter branch.
jwill Dec 15, 2020
4f98c1c
Merge pull request #3 from jwill/starter
jkcoolmom Dec 15, 2020
1c3bcc3
Fix reference to incorrect listItem layout
calren Nov 5, 2021
48f76e6
Merge pull request #209 from google-developer-training/starter_fix_mi…
calren Nov 5, 2021
81a1353
finally got the right branch working and the course make waaayyy more…
Loogibot Apr 28, 2022
dbfd8ca
dependancies updated
Loogibot Apr 28, 2022
71faa53
dependencies and manifest updated, DetailActivity and LetterAdapter a…
Loogibot Apr 28, 2022
5581446
app builds and intents opens browser, as it should!
Loogibot Apr 28, 2022
38a91f3
added vector assets
Loogibot Apr 30, 2022
cfa598a
MainActivity updated with menu button functions
Loogibot Apr 30, 2022
c463398
words app completed
Loogibot Apr 30, 2022
0a61841
added fragments with accompanying xmls and activities, emptied both c…
Loogibot May 4, 2022
066000e
added fragments with accompanying xmls and activities, emptied both clas
Loogibot May 4, 2022
bef49d5
fixed activities
Loogibot May 4, 2022
47fe0e5
some of this words app fragments is going over my head, but I'm getti…
Loogibot May 4, 2022
69a5f3b
dependencies for jetpack navigation added to gradle
Loogibot May 4, 2022
3081eca
added navGraph and navigation action between letterListFragment and w…
Loogibot May 4, 2022
f3372ce
fixed strings resources and changed detailactivity call to wordlistfr…
Loogibot May 4, 2022
4fde891
fixed the setOnClickListener in LetterAdapter to actually work as a b…
Loogibot May 4, 2022
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
41 changes: 40 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
<<<<<<< HEAD
*/.gitignore
.gradle
.DS_Store

=======
>>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47
# built application files
*.apk
*.ap_

<<<<<<< HEAD
=======
# Mac files
.DS_Store

>>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47
# files for the dex VM
*.dex

Expand All @@ -13,6 +23,34 @@

# generated files
bin/
<<<<<<< HEAD
out/
gen/

# Libraries used by the app
/libs

# Build stuff (auto-generated by android update project ...)
build.xml
ant.properties
local.properties
project.properties

# Eclipse project files
.classpath
.project

# idea project files
.idea/
.idea/.name
*.iml
*.ipr
*.iws

# Gradle-based build
build/

=======
gen/

# Ignore gradle files
Expand All @@ -33,4 +71,5 @@ proguard-project.txt

# Android Studio/IDEA
*.iml
.idea
.idea
>>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47
10 changes: 7 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 32
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.example.wordsapp"
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 32
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -59,4 +60,7 @@ dependencies {
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "com.google.android.material:material:$material_version"
implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
}
9 changes: 3 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Words">
<activity
android:name=".DetailActivity"
android:parentActivityName=".MainActivity" />
<activity android:name=".MainActivity">
<activity android:name=".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>
</manifest>
61 changes: 0 additions & 61 deletions app/src/main/java/com/example/wordsapp/DetailActivity.kt

This file was deleted.

20 changes: 7 additions & 13 deletions app/src/main/java/com/example/wordsapp/LetterAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.view.ViewGroup
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.Button
import androidx.annotation.RequiresApi
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView


Expand Down Expand Up @@ -51,9 +52,9 @@ class LetterAdapter :
*/
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LetterViewHolder {
val layout = LayoutInflater
.from(parent.context)
.inflate(R.layout.item_view, parent, false)
.from(parent.context)
.inflate(R.layout.item_view, parent, false)

// Setup custom accessibility delegate to set the text read
layout.accessibilityDelegate = Accessibility
return LetterViewHolder(layout)
Expand All @@ -66,17 +67,10 @@ class LetterAdapter :
val item = list.get(position)
holder.button.text = item.toString()

// Assigns a [OnClickListener] to the button contained in the [ViewHolder]
holder.button.setOnClickListener {
val context = holder.view.context
// Create an intent with a destination of DetailActivity
val intent = Intent(context, DetailActivity::class.java)
// Add the selected letter to the intent as extra data
// The text of Buttons are [CharSequence], a list of characters,
// so it must be explicitly converted into a [String].
intent.putExtra(DetailActivity.LETTER, holder.button.text.toString())
// Start an activity using the data and destination from the Intent.
context.startActivity(intent)
val action = LetterListFragmentDirections
.actionLetterListFragmentToWordListFragment(letter = holder.button.text.toString())
holder.view.findNavController().navigate(action)
}
}

Expand Down
110 changes: 110 additions & 0 deletions app/src/main/java/com/example/wordsapp/LetterListFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.example.wordsapp

import android.os.Bundle
import android.view.*
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.wordsapp.databinding.FragmentLetterListBinding

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
* A simple [Fragment] subclass.
* Use the [LetterListFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class LetterListFragment : Fragment() {
private var _binding: FragmentLetterListBinding? = null
private val binding get() = _binding!!
private lateinit var recyclerView: RecyclerView
private var isLinearLayoutManager = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentLetterListBinding.inflate(inflater, container, false)
val view = binding.root
return view
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
recyclerView = binding.recyclerView
chooseLayout()
}

override fun onDestroy() {
super.onDestroy()
_binding = null
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.layout_menu, menu)

val layoutButton = menu.findItem(R.id.action_switch_layout)
setIcon(layoutButton)
}

private fun chooseLayout() {
when (isLinearLayoutManager) {
true -> {
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = LetterAdapter()
}
false -> {
recyclerView.layoutManager = GridLayoutManager(context, 4)
recyclerView.adapter = LetterAdapter()
}
}
}

private fun setIcon(menuItem: MenuItem?) {
if (menuItem == null)
return

// Set the drawable for the menu icon based on which LayoutManager is currently in use

// An if-clause can be used on the right side of an assignment if all paths return a value.
// The following code is equivalent to
// if (isLinearLayoutManager)
// menu.icon = ContextCompat.getDrawable(this, R.drawable.ic_grid_layout)
// else menu.icon = ContextCompat.getDrawable(this, R.drawable.ic_linear_layout)
menuItem.icon =
if (isLinearLayoutManager)
ContextCompat.getDrawable(this.requireContext(), R.drawable.ic_grid_layout)
else ContextCompat.getDrawable(this.requireContext(), R.drawable.ic_linear_layout)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_switch_layout -> {
// Sets isLinearLayoutManager (a Boolean) to the opposite value
isLinearLayoutManager = !isLinearLayoutManager
// Sets layout and icon
chooseLayout()
setIcon(item)

return true
}
// Otherwise, do nothing and use the core event handling

// when clauses require that all possible paths be accounted for explicitly,
// for instance both the true and false cases if the value is a Boolean,
// or an else to catch all unhandled cases.
else -> super.onOptionsItemSelected(item)
}

}
}
Loading