Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
9 changes: 2 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 33

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

Expand Down Expand Up @@ -55,11 +53,8 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:$core_ktx_version"
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"
}
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Words">
<activity android:name=".MainActivity">
<activity
android:name=".DetailActivity"
android:parentActivityName=".MainActivity" />
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
52 changes: 52 additions & 0 deletions app/src/main/java/com/example/wordsapp/DetailActivity.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
88 changes: 0 additions & 88 deletions app/src/main/java/com/example/wordsapp/DetailListFragment.kt

This file was deleted.

24 changes: 6 additions & 18 deletions app/src/main/java/com/example/wordsapp/LetterAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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)
Expand All @@ -64,38 +62,28 @@ 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
// an accessibility service
companion object Accessibility : View.AccessibilityDelegate() {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
host: View,
info: AccessibilityNodeInfo
) {
super.onInitializeAccessibilityNodeInfo(host, info)
// With `null` as the second argument to [AccessibilityAction], the
// accessibility service announces "double tap to activate".
// If a custom string is provided,
// it announces "double tap to <custom string>".
val customString = host?.context?.getString(R.string.look_up_words)
val customString = host.context?.getString(R.string.look_up_words)
val customClick =
AccessibilityNodeInfo.AccessibilityAction(
AccessibilityNodeInfo.ACTION_CLICK,
customString
)
info?.addAction(customClick)
info.addAction(customClick)
}
}
}
31 changes: 12 additions & 19 deletions app/src/main/java/com/example/wordsapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
Loading