From 5ca958624ef832c5ffe366c6420ca77fd0fda309 Mon Sep 17 00:00:00 2001 From: James Williams Date: Tue, 15 Dec 2020 10:08:48 -0800 Subject: [PATCH 01/16] Removals and additions to make starter branch. --- app/.gitignore | 1 + app/build.gradle | 3 - app/src/main/AndroidManifest.xml | 3 + .../com/example/wordsapp/DetailActivity.kt | 52 +++++++ .../example/wordsapp/DetailListFragment.kt | 88 ----------- .../com/example/wordsapp/LetterAdapter.kt | 16 +- .../java/com/example/wordsapp/MainActivity.kt | 31 ++-- .../java/com/example/wordsapp/WordAdapter.kt | 12 +- .../com/example/wordsapp/WordListFragment.kt | 140 ------------------ app/src/main/res/drawable/ic_grid_layout.xml | 27 ---- .../res/drawable/ic_launcher_background.xml | 19 +-- .../main/res/drawable/ic_linear_layout.xml | 27 ---- ...nt_detail_list.xml => activity_detail.xml} | 6 +- app/src/main/res/layout/activity_main.xml | 27 ++-- .../main/res/layout/fragment_word_list.xml | 30 ---- app/src/main/res/menu/layout_menu.xml | 23 --- app/src/main/res/navigation/nav_graph.xml | 41 ----- app/src/main/res/values/strings.xml | 1 - app/src/main/res/values/themes.xml | 1 - 19 files changed, 92 insertions(+), 456 deletions(-) create mode 100644 app/.gitignore create mode 100644 app/src/main/java/com/example/wordsapp/DetailActivity.kt delete mode 100644 app/src/main/java/com/example/wordsapp/DetailListFragment.kt delete mode 100644 app/src/main/java/com/example/wordsapp/WordListFragment.kt delete mode 100644 app/src/main/res/drawable/ic_grid_layout.xml delete mode 100644 app/src/main/res/drawable/ic_linear_layout.xml rename app/src/main/res/layout/{fragment_detail_list.xml => activity_detail.xml} (91%) delete mode 100644 app/src/main/res/layout/fragment_word_list.xml delete mode 100644 app/src/main/res/menu/layout_menu.xml delete mode 100644 app/src/main/res/navigation/nav_graph.xml diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 5f10d213..489ec986 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,7 +17,6 @@ plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' - id 'androidx.navigation.safeargs.kotlin' } android { @@ -60,6 +59,4 @@ dependencies { implementation "androidx.appcompat:appcompat:$appcompat_version" implementation "com.google.android.material:material:$material_version" implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version" - implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" - implementation "androidx.navigation:navigation-ui-ktx:$nav_version" } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c484b611..de8ddd12 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,9 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Words"> + diff --git a/app/src/main/java/com/example/wordsapp/DetailActivity.kt b/app/src/main/java/com/example/wordsapp/DetailActivity.kt new file mode 100644 index 00000000..289b0046 --- /dev/null +++ b/app/src/main/java/com/example/wordsapp/DetailActivity.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.wordsapp + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import com.example.wordsapp.databinding.ActivityDetailBinding + + +class DetailActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // Retrieve a binding object that allows you to refer to views by id name + // Names are converted from snake case to camel case. + // For example, a View with the id word_one is referenced as binding.wordOne + val binding = ActivityDetailBinding.inflate(layoutInflater) + setContentView(binding.root) + + // Retrieve the LETTER from the Intent extras + // intent.extras.getString returns String? (String or null) + // so toString() guarantees that the value will be a String + val letterId = "A" + + val recyclerView = binding.recyclerView + recyclerView.layoutManager = LinearLayoutManager(this) + recyclerView.adapter = WordAdapter(letterId, this) + + // Adds a [DividerItemDecoration] between items + recyclerView.addItemDecoration( + DividerItemDecoration(this, DividerItemDecoration.VERTICAL) + ) + + title = getString(R.string.detail_prefix) + " " + letterId + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/DetailListFragment.kt b/app/src/main/java/com/example/wordsapp/DetailListFragment.kt deleted file mode 100644 index 38f57dcc..00000000 --- a/app/src/main/java/com/example/wordsapp/DetailListFragment.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.wordsapp - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.LinearLayoutManager -import com.example.wordsapp.databinding.FragmentDetailListBinding - -/** - * Displays a [RecyclerView] of words with search buttons to look them up. - */ -class DetailListFragment : Fragment() { - private lateinit var letterId: String - - private var _binding: FragmentDetailListBinding? = null - - // This property is only valid between onCreateView and - // onDestroyView. - private val binding get() = _binding!! - - - /** - * Provides global access to these variables from anywhere in the app - * via DetailListFragment. without needing to create - * a DetailListFragment instance. - */ - companion object { - val LETTER = "letter" - val SEARCH_PREFIX = "https://www.google.com/search?q=" - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - // Retrieve the LETTER from the Fragment arguments - arguments?.let { - letterId = it.getString(LETTER).toString() - } - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - // Retrieve and inflate the layout for this fragment - _binding = FragmentDetailListBinding.inflate(inflater, container, false) - val view = binding.root - return view - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - val recyclerView = binding.recyclerView - recyclerView.layoutManager = LinearLayoutManager(requireContext()) - recyclerView.adapter = WordAdapter(letterId, requireContext()) - - // Adds a [DividerItemDecoration] between items - recyclerView.addItemDecoration( - DividerItemDecoration(context, DividerItemDecoration.VERTICAL) - ) - } - - /** - * Frees the binding object when the Fragment is destroyed. - */ - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index 54d09d35..ef68d862 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -22,7 +22,6 @@ 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 /** @@ -50,9 +49,8 @@ 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) @@ -64,16 +62,6 @@ class LetterAdapter : override fun onBindViewHolder(holder: LetterViewHolder, position: Int) { val item = list.get(position) holder.button.text = item.toString() - - // Assigns a [OnClickListener] to the button contained in the [ViewHolder] - holder.button.setOnClickListener { - // Create an action from WordList to DetailList - // using the required arguments - val action = WordListFragmentDirections - .actionWordListToDetailList(letter = holder.button.text.toString()) - // Navigate using that action - holder.view.findNavController().navigate(action) - } } // Setup custom accessibility delegate to set the text read with diff --git a/app/src/main/java/com/example/wordsapp/MainActivity.kt b/app/src/main/java/com/example/wordsapp/MainActivity.kt index 120761d3..1b503795 100644 --- a/app/src/main/java/com/example/wordsapp/MainActivity.kt +++ b/app/src/main/java/com/example/wordsapp/MainActivity.kt @@ -17,33 +17,26 @@ package com.example.wordsapp import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import androidx.navigation.NavController -import androidx.navigation.fragment.NavHostFragment -import androidx.navigation.ui.setupActionBarWithNavController +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.example.wordsapp.databinding.ActivityMainBinding /** - * Main Activity and entry point for the app. + * Main Activity and entry point for the app. Displays a RecyclerView of letters. */ class MainActivity : AppCompatActivity() { - private lateinit var navController: NavController + private lateinit var recyclerView: RecyclerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - // Get the navigation host fragment from this Activity - val navHostFragment = supportFragmentManager - .findFragmentById(R.id.nav_host_fragment) as NavHostFragment - // Instantiate the navController using the NavHostFragment - navController = navHostFragment.navController - // Make sure actions in the ActionBar get propagated to the NavController - setupActionBarWithNavController(navController) - } + val binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) - /** - * Enables back button support. Simply navigates one element up on the stack. - */ - override fun onSupportNavigateUp(): Boolean { - return navController.navigateUp() || super.onSupportNavigateUp() + recyclerView = binding.recyclerView + // Sets the LinearLayoutManager of the recyclerview + recyclerView.layoutManager = LinearLayoutManager(this) + recyclerView.adapter = LetterAdapter() } + } diff --git a/app/src/main/java/com/example/wordsapp/WordAdapter.kt b/app/src/main/java/com/example/wordsapp/WordAdapter.kt index 4ef6f041..9322bcb2 100644 --- a/app/src/main/java/com/example/wordsapp/WordAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/WordAdapter.kt @@ -16,8 +16,6 @@ package com.example.wordsapp import android.content.Context -import android.content.Intent -import android.net.Uri import android.os.Build import android.view.LayoutInflater import android.view.View @@ -28,7 +26,7 @@ import androidx.annotation.RequiresApi import androidx.recyclerview.widget.RecyclerView /** - * Adapter for the [RecyclerView] in [DetailListFragment]. + * Adapter for the [RecyclerView] in [DetailActivity]. */ class WordAdapter(private val letterId: String, context: Context) : RecyclerView.Adapter() { @@ -68,6 +66,7 @@ class WordAdapter(private val letterId: String, context: Context) : // Setup custom accessibility delegate to set the text read layout.accessibilityDelegate = Accessibility + return WordViewHolder(layout) } @@ -83,14 +82,7 @@ class WordAdapter(private val letterId: String, context: Context) : // Set the text of the WordViewHolder holder.button.text = item - // Assigns a [OnClickListener] to the button contained in the [ViewHolder] - holder.button.setOnClickListener { - val queryUrl: Uri = Uri.parse("${DetailListFragment.SEARCH_PREFIX}${item}") - val intent = Intent(Intent.ACTION_VIEW, queryUrl) - context.startActivity(intent) - } } - // Setup custom accessibility delegate to set the text read with // an accessibility service companion object Accessibility : View.AccessibilityDelegate() { diff --git a/app/src/main/java/com/example/wordsapp/WordListFragment.kt b/app/src/main/java/com/example/wordsapp/WordListFragment.kt deleted file mode 100644 index dfd25f42..00000000 --- a/app/src/main/java/com/example/wordsapp/WordListFragment.kt +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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.FragmentWordListBinding - -/** - * Entry fragment for the app. Displays a [RecyclerView] of letters. - */ -class WordListFragment : Fragment() { - private var _binding: FragmentWordListBinding? = null - - // This property is only valid between onCreateView and - // onDestroyView. - private val binding get() = _binding!! - - private lateinit var recyclerView: RecyclerView - // Keeps track of which LayoutManager is in use for the [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? { - // Retrieve and inflate the layout for this fragment - _binding = FragmentWordListBinding.inflate(inflater, container, false) - val view = binding.root - return view - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - recyclerView = binding.recyclerView - // Sets the LayoutManager of the recyclerview - // On the first run of the app, it will be LinearLayoutManager - chooseLayout() - } - - /** - * Sets the LayoutManager for the [RecyclerView] based on the desired orientation of the list. - * - * Notice that because the enclosing class has changed from an Activity to a Fragment, - * the signature of the LayoutManagers has to slightly change. - */ - private fun chooseLayout() { - if (isLinearLayoutManager) { - recyclerView.layoutManager = LinearLayoutManager(context) - } else { - 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 - // val context = this.requireContext() - // if (isLinearLayoutManager) - // menu.icon = ContextCompat.getDrawable(context, R.drawable.ic_grid_layout) - // else menu.icon = ContextCompat.getDrawable(context, 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) - } - - /** - * Initializes the [Menu] to be used with the current [Activity] - * - * The signature of this function has also changed slightly when changing from - * an Activity to a Fragment - */ - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - inflater.inflate(R.menu.layout_menu, menu) - - val layoutButton = menu.findItem(R.id.action_switch_layout) - // Calls code to set the icon based on the LinearLayoutManager of the RecyclerView - setIcon(layoutButton) - } - - /** - * Determines how to handle interactions with the selected [MenuItem] - */ - 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) - } - } - - /** - * Frees the binding object when the Fragment is destroyed. - */ - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } -} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_grid_layout.xml b/app/src/main/res/drawable/ic_grid_layout.xml deleted file mode 100644 index 60a42149..00000000 --- a/app/src/main/res/drawable/ic_grid_layout.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml index 2ed32296..eec440af 100644 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -15,14 +15,11 @@ limitations under the License. --> - - - - \ No newline at end of file + android:width="108.3dp" + android:height="108.3dp" + android:viewportWidth="108.3" + android:viewportHeight="108.3"> + + diff --git a/app/src/main/res/drawable/ic_linear_layout.xml b/app/src/main/res/drawable/ic_linear_layout.xml deleted file mode 100644 index a01e25a9..00000000 --- a/app/src/main/res/drawable/ic_linear_layout.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/fragment_detail_list.xml b/app/src/main/res/layout/activity_detail.xml similarity index 91% rename from app/src/main/res/layout/fragment_detail_list.xml rename to app/src/main/res/layout/activity_detail.xml index d9482de3..67b295a5 100644 --- a/app/src/main/res/layout/fragment_detail_list.xml +++ b/app/src/main/res/layout/activity_detail.xml @@ -18,7 +18,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".DetailListFragment"> + tools:context=".DetailActivity"> + tools:listitem="@layout/word_item_view" /> - \ 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 fc5bf299..884928d8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,4 @@ - - - - - - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_word_list.xml b/app/src/main/res/layout/fragment_word_list.xml deleted file mode 100644 index 7b60a5c1..00000000 --- a/app/src/main/res/layout/fragment_word_list.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/layout_menu.xml b/app/src/main/res/menu/layout_menu.xml deleted file mode 100644 index 43b11cc7..00000000 --- a/app/src/main/res/menu/layout_menu.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - \ 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 deleted file mode 100644 index 03a34660..00000000 --- a/app/src/main/res/navigation/nav_graph.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - \ 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 241a1c4b..b3e4004c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,5 +20,4 @@ Switch Layout Look up word in a Browser Search Show Stored Words - Words That Start With {letter} \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 9973e0d6..d4dac5e4 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -22,7 +22,6 @@ @color/teal_900 @color/white - @color/blue_200 @color/blue_700 @color/black From 1c3bcc3b42a46fdec4e01ade6c93f5994ba8a129 Mon Sep 17 00:00:00 2001 From: Caren Chang Date: Fri, 5 Nov 2021 11:06:32 -0700 Subject: [PATCH 02/16] Fix reference to incorrect listItem layout --- .gitignore | 42 +++++++++++++++++++++ app/src/main/res/layout/activity_detail.xml | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..260192c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +*/.gitignore +.gradle +.DS_Store + +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +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/ + diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml index 67b295a5..93074c8e 100644 --- a/app/src/main/res/layout/activity_detail.xml +++ b/app/src/main/res/layout/activity_detail.xml @@ -26,6 +26,6 @@ android:layout_height="match_parent" android:clipToPadding="false" android:padding="16dp" - tools:listitem="@layout/word_item_view" /> + tools:listitem="@layout/item_view" /> From 81a13534652ab0f3360679e37cf2dba3760f71e1 Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Thu, 28 Apr 2022 16:10:19 -0400 Subject: [PATCH 03/16] finally got the right branch working and the course make waaayyy more sense --- app/src/main/java/com/example/wordsapp/LetterAdapter.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index ef68d862..a5db93ba 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -15,6 +15,7 @@ */ package com.example.wordsapp +import android.content.Intent import android.os.Build import android.view.LayoutInflater import android.view.View @@ -62,6 +63,14 @@ class LetterAdapter : override fun onBindViewHolder(holder: LetterViewHolder, position: Int) { val item = list.get(position) holder.button.text = item.toString() + + holder.button.setOnClickListener { + // when a letter is pressed, this will + val context = holder.view.context + val intent = Intent(context, DetailActivity::class.java) + intent.putExtra("letter", holder.button.text.toString()) + context.startActivity(Intent()) + } } // Setup custom accessibility delegate to set the text read with From dbfd8ca2ec4b3a3f7fff0a581f56eef24f437f53 Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Thu, 28 Apr 2022 16:17:20 -0400 Subject: [PATCH 04/16] dependancies updated --- app/build.gradle | 6 +++--- build.gradle | 14 +++++++------- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 489ec986..6bb50448 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,13 +20,13 @@ plugins { } 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" diff --git a/build.gradle b/build.gradle index 7116699b..d3c867f5 100644 --- a/build.gradle +++ b/build.gradle @@ -16,19 +16,19 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { - appcompat_version = "1.2.0" - constraintlayout_version = "2.0.2" - core_ktx_version = "1.3.2" - kotlin_version = "1.3.72" - material_version = "1.2.1" - nav_version = "2.3.1" + appcompat_version = "1.4.1" + constraintlayout_version = "2.1.3" + core_ktx_version = "1.7.0" + kotlin_version = "1.6.21" + material_version = "1.5.0" + nav_version = '2.4.1' } repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4f04f629..c3af661f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip From 71faa533f56d28fe8e02c9aaf3071a1a494edadb Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Thu, 28 Apr 2022 16:43:39 -0400 Subject: [PATCH 05/16] dependencies and manifest updated, DetailActivity and LetterAdapter are coming along --- app/src/main/AndroidManifest.xml | 3 ++- app/src/main/java/com/example/wordsapp/DetailActivity.kt | 6 +++++- app/src/main/java/com/example/wordsapp/LetterAdapter.kt | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index de8ddd12..8c90bcc6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,7 +27,8 @@ - + diff --git a/app/src/main/java/com/example/wordsapp/DetailActivity.kt b/app/src/main/java/com/example/wordsapp/DetailActivity.kt index 289b0046..d022f82b 100644 --- a/app/src/main/java/com/example/wordsapp/DetailActivity.kt +++ b/app/src/main/java/com/example/wordsapp/DetailActivity.kt @@ -24,6 +24,10 @@ import com.example.wordsapp.databinding.ActivityDetailBinding class DetailActivity : AppCompatActivity() { + companion object { + const val LETTER = "letter" + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -36,7 +40,7 @@ class DetailActivity : AppCompatActivity() { // Retrieve the LETTER from the Intent extras // intent.extras.getString returns String? (String or null) // so toString() guarantees that the value will be a String - val letterId = "A" + val letterId = intent?.extras?.getString(LETTER).toString() val recyclerView = binding.recyclerView recyclerView.layoutManager = LinearLayoutManager(this) diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index a5db93ba..33e4375c 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -68,7 +68,7 @@ class LetterAdapter : // when a letter is pressed, this will val context = holder.view.context val intent = Intent(context, DetailActivity::class.java) - intent.putExtra("letter", holder.button.text.toString()) + intent.putExtra(DetailActivity.LETTER, holder.button.text.toString()) context.startActivity(Intent()) } } From 558144696747309cfb2608c6a0f42e55d517617f Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Thu, 28 Apr 2022 18:14:54 -0400 Subject: [PATCH 06/16] app builds and intents opens browser, as it should! --- app/src/main/java/com/example/wordsapp/DetailActivity.kt | 1 + app/src/main/java/com/example/wordsapp/LetterAdapter.kt | 2 +- app/src/main/java/com/example/wordsapp/WordAdapter.kt | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/wordsapp/DetailActivity.kt b/app/src/main/java/com/example/wordsapp/DetailActivity.kt index d022f82b..b37cad3e 100644 --- a/app/src/main/java/com/example/wordsapp/DetailActivity.kt +++ b/app/src/main/java/com/example/wordsapp/DetailActivity.kt @@ -26,6 +26,7 @@ class DetailActivity : AppCompatActivity() { companion object { const val LETTER = "letter" + const val SEARCH_PREFIX = "https://www.google.com/search?q=" } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index 33e4375c..64cb7e1d 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -69,7 +69,7 @@ class LetterAdapter : val context = holder.view.context val intent = Intent(context, DetailActivity::class.java) intent.putExtra(DetailActivity.LETTER, holder.button.text.toString()) - context.startActivity(Intent()) + context.startActivity(intent) } } diff --git a/app/src/main/java/com/example/wordsapp/WordAdapter.kt b/app/src/main/java/com/example/wordsapp/WordAdapter.kt index 9322bcb2..0d2815b7 100644 --- a/app/src/main/java/com/example/wordsapp/WordAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/WordAdapter.kt @@ -16,6 +16,8 @@ package com.example.wordsapp import android.content.Context +import android.content.Intent +import android.net.Uri import android.os.Build import android.view.LayoutInflater import android.view.View @@ -81,6 +83,11 @@ class WordAdapter(private val letterId: String, context: Context) : // Set the text of the WordViewHolder holder.button.text = item + holder.button.setOnClickListener { + val queryUrl: Uri = Uri.parse("${DetailActivity.SEARCH_PREFIX}${item}") + val intent = Intent(Intent.ACTION_VIEW, queryUrl) + context.startActivity(intent) + } } // Setup custom accessibility delegate to set the text read with From 38a91f37bb27c274065d22081112ee21b0eeca5b Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Sat, 30 Apr 2022 11:01:08 -0400 Subject: [PATCH 07/16] added vector assets --- app/src/main/res/drawable/ic_grid_layout.xml | 10 ++++++++++ app/src/main/res/drawable/ic_linear_layout.xml | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 app/src/main/res/drawable/ic_grid_layout.xml create mode 100644 app/src/main/res/drawable/ic_linear_layout.xml diff --git a/app/src/main/res/drawable/ic_grid_layout.xml b/app/src/main/res/drawable/ic_grid_layout.xml new file mode 100644 index 00000000..78298cd2 --- /dev/null +++ b/app/src/main/res/drawable/ic_grid_layout.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_linear_layout.xml b/app/src/main/res/drawable/ic_linear_layout.xml new file mode 100644 index 00000000..9884aeb8 --- /dev/null +++ b/app/src/main/res/drawable/ic_linear_layout.xml @@ -0,0 +1,10 @@ + + + From cfa598adb1dfbf79e52815d0594e510a58dd263c Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Sat, 30 Apr 2022 12:17:50 -0400 Subject: [PATCH 08/16] MainActivity updated with menu button functions --- .../java/com/example/wordsapp/MainActivity.kt | 45 +++++++++++++++++++ app/src/main/res/menu/layout_menu.xml | 8 ++++ 2 files changed, 53 insertions(+) create mode 100644 app/src/main/res/menu/layout_menu.xml diff --git a/app/src/main/java/com/example/wordsapp/MainActivity.kt b/app/src/main/java/com/example/wordsapp/MainActivity.kt index 1b503795..6b699fdc 100644 --- a/app/src/main/java/com/example/wordsapp/MainActivity.kt +++ b/app/src/main/java/com/example/wordsapp/MainActivity.kt @@ -16,7 +16,11 @@ package com.example.wordsapp import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.example.wordsapp.databinding.ActivityMainBinding @@ -26,6 +30,7 @@ import com.example.wordsapp.databinding.ActivityMainBinding */ class MainActivity : AppCompatActivity() { private lateinit var recyclerView: RecyclerView + private var isLinearLayoutManager = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -37,6 +42,46 @@ class MainActivity : AppCompatActivity() { // Sets the LinearLayoutManager of the recyclerview recyclerView.layoutManager = LinearLayoutManager(this) recyclerView.adapter = LetterAdapter() + + } + + private fun chooseLayout() { + if (isLinearLayoutManager) { + recyclerView.layoutManager = LinearLayoutManager(this) + } else { + recyclerView.layoutManager = GridLayoutManager(this, 4) + } + recyclerView.adapter = LetterAdapter() } + private fun setIcon(menuItem: MenuItem?) { + if (menuItem == null) + return + menuItem.icon = + if (isLinearLayoutManager) + ContextCompat.getDrawable(this, R.drawable.ic_grid_layout) + else ContextCompat.getDrawable(this, R.drawable.ic_linear_layout) + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.layout_menu, menu) + + val layoutButton = menu?.findItem(R.id.action_switch_layout) + setIcon(layoutButton) + + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when(item.itemId) { + R.id.action_switch_layout -> { + isLinearLayoutManager = !isLinearLayoutManager + chooseLayout() + setIcon(item) + + return true + } + else -> super.onOptionsItemSelected(item) + } + } } diff --git a/app/src/main/res/menu/layout_menu.xml b/app/src/main/res/menu/layout_menu.xml new file mode 100644 index 00000000..d7a57e4c --- /dev/null +++ b/app/src/main/res/menu/layout_menu.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file From c4633981b88b9c1cc68d63e4fdb3348096387c0d Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Sat, 30 Apr 2022 12:30:34 -0400 Subject: [PATCH 09/16] words app completed --- app/src/main/java/com/example/wordsapp/MainActivity.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/wordsapp/MainActivity.kt b/app/src/main/java/com/example/wordsapp/MainActivity.kt index 6b699fdc..edbb816b 100644 --- a/app/src/main/java/com/example/wordsapp/MainActivity.kt +++ b/app/src/main/java/com/example/wordsapp/MainActivity.kt @@ -16,6 +16,7 @@ package com.example.wordsapp import android.os.Bundle +import android.os.PersistableBundle import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity @@ -40,9 +41,7 @@ class MainActivity : AppCompatActivity() { recyclerView = binding.recyclerView // Sets the LinearLayoutManager of the recyclerview - recyclerView.layoutManager = LinearLayoutManager(this) - recyclerView.adapter = LetterAdapter() - + chooseLayout() } private fun chooseLayout() { From 0a61841ea0765ccd4fb90111574871a5b026bd40 Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Wed, 4 May 2022 10:55:41 -0400 Subject: [PATCH 10/16] added fragments with accompanying xmls and activities, emptied both classes and copied main and detail xml into corresponding fragment xmls --- app/build.gradle | 1 + .../example/wordsapp/LetterListFragment.kt | 21 +++++++++++++ .../java/com/example/wordsapp/MainActivity.kt | 3 +- .../com/example/wordsapp/WordListFragment.kt | 21 +++++++++++++ .../main/res/layout/fragment_letter_list.xml | 28 +++++++++++++++++ .../main/res/layout/fragment_word_list.xml | 31 +++++++++++++++++++ app/src/main/res/values/strings.xml | 5 +-- 7 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/example/wordsapp/LetterListFragment.kt create mode 100644 app/src/main/java/com/example/wordsapp/WordListFragment.kt create mode 100644 app/src/main/res/layout/fragment_letter_list.xml create mode 100644 app/src/main/res/layout/fragment_word_list.xml diff --git a/app/build.gradle b/app/build.gradle index 6bb50448..77f8627c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,4 +59,5 @@ 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' } \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/LetterListFragment.kt b/app/src/main/java/com/example/wordsapp/LetterListFragment.kt new file mode 100644 index 00000000..54c7c4d5 --- /dev/null +++ b/app/src/main/java/com/example/wordsapp/LetterListFragment.kt @@ -0,0 +1,21 @@ +package com.example.wordsapp + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +// 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() { + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/MainActivity.kt b/app/src/main/java/com/example/wordsapp/MainActivity.kt index edbb816b..609459db 100644 --- a/app/src/main/java/com/example/wordsapp/MainActivity.kt +++ b/app/src/main/java/com/example/wordsapp/MainActivity.kt @@ -29,6 +29,7 @@ import com.example.wordsapp.databinding.ActivityMainBinding /** * Main Activity and entry point for the app. Displays a RecyclerView of letters. */ + class MainActivity : AppCompatActivity() { private lateinit var recyclerView: RecyclerView private var isLinearLayoutManager = true @@ -83,4 +84,4 @@ class MainActivity : AppCompatActivity() { else -> super.onOptionsItemSelected(item) } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/WordListFragment.kt b/app/src/main/java/com/example/wordsapp/WordListFragment.kt new file mode 100644 index 00000000..6a1d1645 --- /dev/null +++ b/app/src/main/java/com/example/wordsapp/WordListFragment.kt @@ -0,0 +1,21 @@ +package com.example.wordsapp + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + +// 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 [WordListFragment.newInstance] factory method to + * create an instance of this fragment. + */ +class WordListFragment : Fragment() { + +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_letter_list.xml b/app/src/main/res/layout/fragment_letter_list.xml new file mode 100644 index 00000000..74978bed --- /dev/null +++ b/app/src/main/res/layout/fragment_letter_list.xml @@ -0,0 +1,28 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_word_list.xml b/app/src/main/res/layout/fragment_word_list.xml new file mode 100644 index 00000000..6cf10f97 --- /dev/null +++ b/app/src/main/res/layout/fragment_word_list.xml @@ -0,0 +1,31 @@ + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3e4004c..2683f697 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,4 @@ - - + Hello blank fragment \ No newline at end of file From bef49d58c3fb74ca7451b6a686fc134325df9d3e Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Wed, 4 May 2022 13:47:15 -0400 Subject: [PATCH 11/16] fixed activities --- .../com/example/wordsapp/DetailActivity.kt | 4 +- .../com/example/wordsapp/LetterAdapter.kt | 18 +++---- .../example/wordsapp/LetterListFragment.kt | 25 ++++++++++ .../java/com/example/wordsapp/MainActivity.kt | 48 +------------------ 4 files changed, 34 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/com/example/wordsapp/DetailActivity.kt b/app/src/main/java/com/example/wordsapp/DetailActivity.kt index 4a137485..de0bf0a1 100644 --- a/app/src/main/java/com/example/wordsapp/DetailActivity.kt +++ b/app/src/main/java/com/example/wordsapp/DetailActivity.kt @@ -23,15 +23,13 @@ import com.example.wordsapp.databinding.ActivityDetailBinding class DetailActivity : AppCompatActivity() { -<<<<<<< HEAD -======= /** * Provides global access to these variables from anywhere in the app * via DetailActivity. without needing to create * a DetailActivity instance. */ ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 + companion object { const val LETTER = "letter" const val SEARCH_PREFIX = "https://www.google.com/search?q=" diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index 1974799e..28072aed 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -51,14 +51,11 @@ class LetterAdapter : */ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LetterViewHolder { val layout = LayoutInflater -<<<<<<< HEAD + .from(parent.context) .inflate(R.layout.item_view, parent, false) -======= - .from(parent.context) - .inflate(R.layout.item_view, parent, false) - ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 + + // Setup custom accessibility delegate to set the text read layout.accessibilityDelegate = Accessibility return LetterViewHolder(layout) @@ -72,12 +69,10 @@ class LetterAdapter : holder.button.text = item.toString() holder.button.setOnClickListener { -<<<<<<< HEAD + // when a letter is pressed, this will - val context = holder.view.context - val intent = Intent(context, DetailActivity::class.java) - intent.putExtra(DetailActivity.LETTER, holder.button.text.toString()) -======= + + val context = holder.view.context // Create an intent with a destination of DetailActivity val intent = Intent(context, DetailActivity::class.java) @@ -86,7 +81,6 @@ class LetterAdapter : // 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. ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 context.startActivity(intent) } } diff --git a/app/src/main/java/com/example/wordsapp/LetterListFragment.kt b/app/src/main/java/com/example/wordsapp/LetterListFragment.kt index 54c7c4d5..8c554086 100644 --- a/app/src/main/java/com/example/wordsapp/LetterListFragment.kt +++ b/app/src/main/java/com/example/wordsapp/LetterListFragment.kt @@ -5,6 +5,8 @@ import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +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 @@ -17,5 +19,28 @@ private const val ARG_PARAM2 = "param2" * create an instance of this fragment. */ class LetterListFragment : Fragment() { + private var _binding: FragmentLetterListBinding? = null + private val binding get() = _binding!! + private lateinit var recyclerView: RecyclerView + + 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() + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/MainActivity.kt b/app/src/main/java/com/example/wordsapp/MainActivity.kt index b1baafc3..ce64bb2f 100644 --- a/app/src/main/java/com/example/wordsapp/MainActivity.kt +++ b/app/src/main/java/com/example/wordsapp/MainActivity.kt @@ -16,10 +16,6 @@ package com.example.wordsapp import android.os.Bundle -<<<<<<< HEAD -import android.os.PersistableBundle -======= ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity @@ -35,10 +31,9 @@ import com.example.wordsapp.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { private lateinit var recyclerView: RecyclerView -<<<<<<< HEAD -======= + // Keeps track of which LayoutManager is in use for the [RecyclerView] ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 + private var isLinearLayoutManager = true override fun onCreate(savedInstanceState: Bundle?) { @@ -52,15 +47,6 @@ class MainActivity : AppCompatActivity() { chooseLayout() } -<<<<<<< HEAD - private fun chooseLayout() { - if (isLinearLayoutManager) { - recyclerView.layoutManager = LinearLayoutManager(this) - } else { - recyclerView.layoutManager = GridLayoutManager(this, 4) - } - recyclerView.adapter = LetterAdapter() -======= /** * Sets the LayoutManager for the [RecyclerView] based on the desired orientation of the list. */ @@ -124,37 +110,7 @@ class MainActivity : AppCompatActivity() { // or an else to catch all unhandled cases. else -> super.onOptionsItemSelected(item) } ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 - } - - private fun setIcon(menuItem: MenuItem?) { - if (menuItem == null) - return - menuItem.icon = - if (isLinearLayoutManager) - ContextCompat.getDrawable(this, R.drawable.ic_grid_layout) - else ContextCompat.getDrawable(this, R.drawable.ic_linear_layout) - } - - override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.layout_menu, menu) - - val layoutButton = menu?.findItem(R.id.action_switch_layout) - setIcon(layoutButton) - return true } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when(item.itemId) { - R.id.action_switch_layout -> { - isLinearLayoutManager = !isLinearLayoutManager - chooseLayout() - setIcon(item) - - return true - } - else -> super.onOptionsItemSelected(item) - } - } } \ No newline at end of file From 47fe0e5956552327760f62633b42750add03db99 Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Wed, 4 May 2022 15:17:17 -0400 Subject: [PATCH 12/16] some of this words app fragments is going over my head, but I'm getting something --- app/src/main/AndroidManifest.xml | 9 +-- .../com/example/wordsapp/DetailActivity.kt | 63 ----------------- .../com/example/wordsapp/LetterAdapter.kt | 3 +- .../example/wordsapp/LetterListFragment.kt | 70 ++++++++++++++++++- .../java/com/example/wordsapp/MainActivity.kt | 68 +----------------- .../java/com/example/wordsapp/WordAdapter.kt | 2 +- .../com/example/wordsapp/WordListFragment.kt | 36 +++++++++- app/src/main/res/layout/activity_detail.xml | 31 -------- 8 files changed, 106 insertions(+), 176 deletions(-) delete mode 100644 app/src/main/java/com/example/wordsapp/DetailActivity.kt delete mode 100644 app/src/main/res/layout/activity_detail.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 963a7805..4fba8363 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,15 +24,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Words"> - -<<<<<<< HEAD -======= - ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 @@ -41,4 +34,4 @@ - + \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/DetailActivity.kt b/app/src/main/java/com/example/wordsapp/DetailActivity.kt deleted file mode 100644 index de0bf0a1..00000000 --- a/app/src/main/java/com/example/wordsapp/DetailActivity.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.wordsapp - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.LinearLayoutManager -import com.example.wordsapp.databinding.ActivityDetailBinding - - -class DetailActivity : AppCompatActivity() { - - /** - * Provides global access to these variables from anywhere in the app - * via DetailActivity. without needing to create - * a DetailActivity instance. - */ - - companion object { - const val LETTER = "letter" - const val SEARCH_PREFIX = "https://www.google.com/search?q=" - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - // Retrieve a binding object that allows you to refer to views by id name - // Names are converted from snake case to camel case. - // For example, a View with the id word_one is referenced as binding.wordOne - val binding = ActivityDetailBinding.inflate(layoutInflater) - setContentView(binding.root) - - // Retrieve the LETTER from the Intent extras - // intent.extras.getString returns String? (String or null) - // so toString() guarantees that the value will be a String - val letterId = intent?.extras?.getString(LETTER).toString() - - val recyclerView = binding.recyclerView - recyclerView.layoutManager = LinearLayoutManager(this) - recyclerView.adapter = WordAdapter(letterId, this) - - // Adds a [DividerItemDecoration] between items - recyclerView.addItemDecoration( - DividerItemDecoration(this, DividerItemDecoration.VERTICAL) - ) - - title = getString(R.string.detail_prefix) + " " + letterId - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index 28072aed..75e37d88 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -72,14 +72,13 @@ class LetterAdapter : // when a letter is pressed, this will - 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()) + intent.putExtra(WordListFragment.LETTER, holder.button.text.toString()) // Start an activity using the data and destination from the Intent. context.startActivity(intent) } diff --git a/app/src/main/java/com/example/wordsapp/LetterListFragment.kt b/app/src/main/java/com/example/wordsapp/LetterListFragment.kt index 8c554086..da1a388a 100644 --- a/app/src/main/java/com/example/wordsapp/LetterListFragment.kt +++ b/app/src/main/java/com/example/wordsapp/LetterListFragment.kt @@ -1,10 +1,11 @@ package com.example.wordsapp import android.os.Bundle +import android.view.* +import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.example.wordsapp.databinding.FragmentLetterListBinding @@ -22,6 +23,7 @@ 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) @@ -43,4 +45,66 @@ class LetterListFragment : Fragment() { 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) + } + + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/MainActivity.kt b/app/src/main/java/com/example/wordsapp/MainActivity.kt index ce64bb2f..80ad1bf6 100644 --- a/app/src/main/java/com/example/wordsapp/MainActivity.kt +++ b/app/src/main/java/com/example/wordsapp/MainActivity.kt @@ -44,73 +44,7 @@ class MainActivity : AppCompatActivity() { recyclerView = binding.recyclerView // Sets the LinearLayoutManager of the recyclerview - chooseLayout() - } - - /** - * Sets the LayoutManager for the [RecyclerView] based on the desired orientation of the list. - */ - private fun chooseLayout() { - if (isLinearLayoutManager) { - recyclerView.layoutManager = LinearLayoutManager(this) - } else { - recyclerView.layoutManager = GridLayoutManager(this, 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, R.drawable.ic_grid_layout) - else ContextCompat.getDrawable(this, R.drawable.ic_linear_layout) - } - - /** - * Initializes the [Menu] to be used with the current [Activity] - */ - override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.layout_menu, menu) - - val layoutButton = menu?.findItem(R.id.action_switch_layout) - // Calls code to set the icon based on the LinearLayoutManager of the RecyclerView - setIcon(layoutButton) - - return true - } - - /** - * Determines how to handle interactions with the selected [MenuItem] - */ - 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) - } - + setContentView(binding.root) } } \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/WordAdapter.kt b/app/src/main/java/com/example/wordsapp/WordAdapter.kt index 0d2815b7..b2dd55ce 100644 --- a/app/src/main/java/com/example/wordsapp/WordAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/WordAdapter.kt @@ -84,7 +84,7 @@ class WordAdapter(private val letterId: String, context: Context) : // Set the text of the WordViewHolder holder.button.text = item holder.button.setOnClickListener { - val queryUrl: Uri = Uri.parse("${DetailActivity.SEARCH_PREFIX}${item}") + val queryUrl: Uri = Uri.parse("${WordListFragment.SEARCH_PREFIX}${item}") val intent = Intent(Intent.ACTION_VIEW, queryUrl) context.startActivity(intent) } diff --git a/app/src/main/java/com/example/wordsapp/WordListFragment.kt b/app/src/main/java/com/example/wordsapp/WordListFragment.kt index 6a1d1645..32275ac6 100644 --- a/app/src/main/java/com/example/wordsapp/WordListFragment.kt +++ b/app/src/main/java/com/example/wordsapp/WordListFragment.kt @@ -5,6 +5,9 @@ import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import com.example.wordsapp.databinding.FragmentLetterListBinding // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER @@ -18,4 +21,35 @@ private const val ARG_PARAM2 = "param2" */ class WordListFragment : Fragment() { -} \ No newline at end of file + companion object { + const val LETTER = "letter" + const val SEARCH_PREFIX = "https://www.google.com/search?q=" + } + + private var _binding: FragmentLetterListBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + _binding = FragmentLetterListBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + val recyclerView = binding.recyclerView + recyclerView.layoutManager = LinearLayoutManager(requireContext()) + recyclerView.adapter = WordAdapter(activity?.intent?.extras?.getString(LETTER).toString(), requireContext()) + + recyclerView.addItemDecoration( + DividerItemDecoration(context, DividerItemDecoration.VERTICAL) + ) + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml deleted file mode 100644 index 93074c8e..00000000 --- a/app/src/main/res/layout/activity_detail.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - From 69a5f3b5705d2796790c258dcf36a4bbe18dcc8d Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Wed, 4 May 2022 15:30:04 -0400 Subject: [PATCH 13/16] dependencies for jetpack navigation added to gradle --- app/build.gradle | 6 +++--- build.gradle | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 41edce48..206ae4c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,6 +17,7 @@ plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' + id 'androidx.navigation.safeargs.kotlin' } android { @@ -59,8 +60,7 @@ dependencies { implementation "androidx.appcompat:appcompat:$appcompat_version" implementation "com.google.android.material:material:$material_version" implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version" -<<<<<<< HEAD implementation 'androidx.legacy:legacy-support-v4:1.0.0' -======= ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 + implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" + implementation "androidx.navigation:navigation-ui-ktx:$nav_version" } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6abb2e7a..56d39017 100644 --- a/build.gradle +++ b/build.gradle @@ -16,20 +16,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { -<<<<<<< HEAD + appcompat_version = "1.4.1" constraintlayout_version = "2.1.3" core_ktx_version = "1.7.0" kotlin_version = "1.6.21" material_version = "1.5.0" - nav_version = '2.4.1' -======= - appcompat_version = "1.2.0" - constraintlayout_version = "2.0.2" - core_ktx_version = "1.3.2" - kotlin_version = "1.3.72" - material_version = "1.2.1" ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 + nav_version = '2.4.2' + } repositories { google() @@ -38,6 +32,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 3081eca1b50fc67f26a6df60c97725c76178c91f Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Wed, 4 May 2022 16:54:33 -0400 Subject: [PATCH 14/16] added navGraph and navigation action between letterListFragment and wordListFragment --- app/src/main/AndroidManifest.xml | 1 - app/src/main/res/layout/activity_main.xml | 11 ++++++---- app/src/main/res/navigation/nav_graph.xml | 26 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/navigation/nav_graph.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4fba8363..4588a9f2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,7 +28,6 @@ android:exported="true"> - diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 884928d8..a462c3f7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,14 +15,17 @@ --> - + app:defaultNavHost="true" + app:navGraph="@navigation/nav_graph" + /> \ 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 00000000..2c2d4153 --- /dev/null +++ b/app/src/main/res/navigation/nav_graph.xml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file From f3372ce7f265b950122c5efea81687dff34b3674 Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Wed, 4 May 2022 17:27:15 -0400 Subject: [PATCH 15/16] fixed strings resources and changed detailactivity call to wordlistfragment, updated mainactivity and wordlistfragment --- .../com/example/wordsapp/LetterAdapter.kt | 14 ++----------- .../java/com/example/wordsapp/MainActivity.kt | 20 ++++++++++++------- .../com/example/wordsapp/WordListFragment.kt | 14 +++++++++++-- app/src/main/res/values/strings.xml | 5 ++--- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index 75e37d88..633066db 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -55,7 +55,6 @@ class LetterAdapter : .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) @@ -69,18 +68,9 @@ class LetterAdapter : holder.button.text = item.toString() holder.button.setOnClickListener { + val action = LetterListFragmentDirections + .actionLetterListFragmentToWordListFragment(letter = holder.button.text.toString()) - // when a letter is pressed, this will - - 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(WordListFragment.LETTER, holder.button.text.toString()) - // Start an activity using the data and destination from the Intent. - context.startActivity(intent) } } diff --git a/app/src/main/java/com/example/wordsapp/MainActivity.kt b/app/src/main/java/com/example/wordsapp/MainActivity.kt index 80ad1bf6..b93904da 100644 --- a/app/src/main/java/com/example/wordsapp/MainActivity.kt +++ b/app/src/main/java/com/example/wordsapp/MainActivity.kt @@ -20,6 +20,9 @@ import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat +import androidx.navigation.NavController +import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.ui.setupActionBarWithNavController import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -30,11 +33,8 @@ import com.example.wordsapp.databinding.ActivityMainBinding */ class MainActivity : AppCompatActivity() { - private lateinit var recyclerView: RecyclerView - // Keeps track of which LayoutManager is in use for the [RecyclerView] - - private var isLinearLayoutManager = true + private lateinit var navController: NavController override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -42,9 +42,15 @@ class MainActivity : AppCompatActivity() { val binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - recyclerView = binding.recyclerView - // Sets the LinearLayoutManager of the recyclerview - setContentView(binding.root) + val navHostFragment = supportFragmentManager + .findFragmentById(R.id.nav_host_fragment) as NavHostFragment + navController = navHostFragment.navController + + setupActionBarWithNavController(navController) + } + override fun onSupportNavigateUp(): Boolean { + return navController.navigateUp() || super.onSupportNavigateUp() + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/wordsapp/WordListFragment.kt b/app/src/main/java/com/example/wordsapp/WordListFragment.kt index 32275ac6..e608b07c 100644 --- a/app/src/main/java/com/example/wordsapp/WordListFragment.kt +++ b/app/src/main/java/com/example/wordsapp/WordListFragment.kt @@ -11,8 +11,8 @@ 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" +// private const val ARG_PARAM1 = "param1" +// private const val ARG_PARAM2 = "param2" /** * A simple [Fragment] subclass. @@ -29,6 +29,16 @@ class WordListFragment : Fragment() { private var _binding: FragmentLetterListBinding? = null private val binding get() = _binding!! + private lateinit var letterId: String + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + arguments?.let { + letterId = it.getString(LETTER).toString() + } + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 70433dfa..fac77dcc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,9 +19,8 @@ Switch Layout Look up word in a Browser Search Show Stored Words -<<<<<<< HEAD + Hello blank fragment -======= ->>>>>>> ee3fc3113323afc9bd4b22252aab337033d65f47 + \ No newline at end of file From 4fde891dd65b156b9884158a3570090be4745558 Mon Sep 17 00:00:00 2001 From: Loogibot <94766364+Loogibot@users.noreply.github.com> Date: Wed, 4 May 2022 18:08:55 -0400 Subject: [PATCH 16/16] fixed the setOnClickListener in LetterAdapter to actually work as a button, app runs now --- app/src/main/java/com/example/wordsapp/LetterAdapter.kt | 4 ++-- app/src/main/java/com/example/wordsapp/WordAdapter.kt | 2 +- .../main/java/com/example/wordsapp/WordListFragment.kt | 4 ++-- app/src/main/res/navigation/nav_graph.xml | 8 ++++---- app/src/main/res/values/strings.xml | 1 + 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt index 633066db..bfc8c295 100644 --- a/app/src/main/java/com/example/wordsapp/LetterAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/LetterAdapter.kt @@ -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 @@ -51,7 +52,6 @@ class LetterAdapter : */ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LetterViewHolder { val layout = LayoutInflater - .from(parent.context) .inflate(R.layout.item_view, parent, false) @@ -70,7 +70,7 @@ class LetterAdapter : holder.button.setOnClickListener { val action = LetterListFragmentDirections .actionLetterListFragmentToWordListFragment(letter = holder.button.text.toString()) - + holder.view.findNavController().navigate(action) } } diff --git a/app/src/main/java/com/example/wordsapp/WordAdapter.kt b/app/src/main/java/com/example/wordsapp/WordAdapter.kt index b2dd55ce..df2bd907 100644 --- a/app/src/main/java/com/example/wordsapp/WordAdapter.kt +++ b/app/src/main/java/com/example/wordsapp/WordAdapter.kt @@ -28,7 +28,7 @@ import androidx.annotation.RequiresApi import androidx.recyclerview.widget.RecyclerView /** - * Adapter for the [RecyclerView] in [DetailActivity]. + * Adapter for the [RecyclerView] in [WordListFragment]. */ class WordAdapter(private val letterId: String, context: Context) : RecyclerView.Adapter() { diff --git a/app/src/main/java/com/example/wordsapp/WordListFragment.kt b/app/src/main/java/com/example/wordsapp/WordListFragment.kt index e608b07c..8bf9319a 100644 --- a/app/src/main/java/com/example/wordsapp/WordListFragment.kt +++ b/app/src/main/java/com/example/wordsapp/WordListFragment.kt @@ -43,7 +43,7 @@ class WordListFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { _binding = FragmentLetterListBinding.inflate(inflater, container, false) return binding.root } @@ -51,7 +51,7 @@ class WordListFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { val recyclerView = binding.recyclerView recyclerView.layoutManager = LinearLayoutManager(requireContext()) - recyclerView.adapter = WordAdapter(activity?.intent?.extras?.getString(LETTER).toString(), requireContext()) + recyclerView.adapter = WordAdapter(letterId, requireContext()) recyclerView.addItemDecoration( DividerItemDecoration(context, DividerItemDecoration.VERTICAL) diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 2c2d4153..a9fddcf5 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -8,8 +8,8 @@ + android:label="@string/word_list_fragment_label" + tools:layout="@layout/fragment_word_list"> @@ -17,8 +17,8 @@ + android:label="@string/app_name" + tools:layout="@layout/fragment_letter_list"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fac77dcc..bd95c23c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,7 @@ --> Words + Words That Start With {letter} Words That Start With Switch Layout Look up word in a Browser Search