Git Product home page Git Product logo

andfun-kotlin-android-trivia's Introduction

Navigation

This is the toy app for lesson 3 of the Android App Development in Kotlin course on Udacity.

Android Trivia

The Android Trivia application is an application that asks the user trivia questions about Android development. It makes use of the Navigation component within Jetpack to move the user between different screens. Each screen is implemented as a Fragment. The app navigates using buttons, the Action Bar, and the Navigation Drawer. Since students haven't yet learned about saving data or the Android lifecycle, it tries to eliminate bugs caused by configuration changes.

Screenshots

Screenshot1 Screenshot2

How to use this repo while taking the course

Each code repository in this class has a chain of commits that looks like this:

listofcommits

These commits show every step you'll take to create the app. Each commit contains instructions for completing the that step.

Each commit also has a branch associated with it of the same name as the commit message, seen below:

branches Access all branches from this tab

listofbranches

branchesdropdown

The branches are also accessible from the drop-down in the "Code" tab

Working with the Course Code

Here are the basic steps for working with and completing exercises in the repo.

The basic steps are:

  1. Clone the repo
  2. Checkout the branch corresponding to the step you want to attempt
  3. Find and complete the TODOs
  4. Optionally commit your code changes
  5. Compare your code with the solution
  6. Repeat steps 2-5 until you've gone trough all the steps to complete the toy app

Step 1: Clone the repo

As you go through the course, you'll be instructed to clone the different exercise repositories, so you don't need to set these up now. You can clone a repository from github in a folder of your choice with the command:

git clone https://github.com/udacity/REPOSITORY_NAME.git

Step 2: Checkout the step branch

As you go through different steps in the code, you'll be told which step you're on, as well as a link to the corresponding branch.

You'll want to check out the branch associated with that step. The command to check out a branch would be:

git checkout BRANCH_NAME

Step 3: Find and complete the TODOs

Once you've checked out the branch, you'll have the code in the exact state you need. You'll even have TODOs, which are special comments that tell you all the steps you need to complete the exercise. You can easily navigate to all the TODOs using Android Studio's TODO tool. To open the TODO tool, click the button at the bottom of the screen that says TODO. This will display a list of all comments with TODO in the project.

We've numbered the TODO steps so you can do them in order: todos

Step 4: Commit your code changes

After You've completed the TODOs, you can optionally commit your changes. This will allow you to see the code you wrote whenever you return to the branch. The following git code will add and save all your changes.

git add .
git commit -m "Your commit message"

Step 5: Compare with the solution

Most exercises will have a list of steps for you to check off in the classroom. Once you've checked these off, you'll see a pop up window with a link to the solution code. Note the Diff link:

solutionwindow

The Diff link will take you to a Github diff as seen below: diff

All of the code that was added in the solution is in green, and the removed code (which will usually be the TODO comments) is in red.

You can also compare your code locally with the branch of the following step.

Report Issues

Notice any issues with a repository? Please file a github issue in the repository.

andfun-kotlin-android-trivia's People

Contributors

dagalpin avatar objcode avatar sudkul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

andfun-kotlin-android-trivia's Issues

Can't add "layout_gravity" property to NavigationView in DrawerLayout

I get the following exception while clicking on hamburger icon:
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT

Here is the activity_main.xml:

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">

        <fragment
            android:id="@+id/myNavHostFragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            app:defaultNavHost="true"
            app:navGraph="@navigation/navigation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </LinearLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/navdrawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>

Regards

Unsolved referense

What is it supposed to refer to GameoverFragmentDirections, TitleFragmentDirections?

AndroidX implementation

This project seems to use, old android versioning for navigation, thus, leading to lot's of confusion when on some exercise. Is there a way, we can rewrite the commit history and fix the versioning and move the code to proper AndroidX?

Gradle sync failure. Could not find androidx.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha07.

Can't build the project as license for sdk is not accepted

Gradle sync shows error on startup

> Configure project :app
Checking the license for package Android SDK Build-Tools 28.0.3 in /Users/ishaansarna/Library/Android/sdk/licenses
Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
Checking the license for package Android SDK Platform 28 in /Users/ishaansarna/Library/Android/sdk/licenses
Warning: License for package Android SDK Platform 28 not accepted.
Aborting configuration as SDK is missing components in sync mode.

CONFIGURE SUCCESSFUL in 1s

Using Android Studio 4.0

Method onSupportNavigateUp: Sequence of method arguments interchanged

Sequence of method arguments interchanged:

Class:  MainActivity
Method: onSupportNavigateUp()

Change from:
return NavigationUI.navigateUp(drawerLayout, navController)
to:
return NavigationUI.navigateUp(navController, drawerLayout)

Branches affected:

Step.09-Solution-Adding-the-Navigation-Drawer
    Line 44
Step.10-Exercise-Using-Navigation-Listeners
    Line 48
Step.10-Solution-Using-Navigation-Listeners
    Line 54
Step.11-Exercise-Adding-Animation
    Line 54
Step.11-Solution-Adding-Animation
    Line 54

Redundant code in GameFragment.kt (Branch: Step.03-Exercise-Conditional-Navigation)

// The first answer in the original question is always the correct one, so if our
// answer matches, we have the correct answer.
if (answers[answerIndex] == currentQuestion.answers[0]) {
questionIndex++
// Advance to the next question
if (questionIndex < numQuestions) {
currentQuestion = questions[questionIndex]
setQuestion()
binding.invalidateAll()
} else {

The code in line number 96 is redundant because the setQuestion() method also does that. (line 126)

private fun setQuestion() {
currentQuestion = questions[questionIndex]
// randomize the answers into a copy of the array
answers = currentQuestion.answers.toMutableList()

The code in the setQuestion() method can't be changed because it also sets the first question. Therefore it is better to remove the code in line 96.

Step.09-Solution not working

It is giving java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
and marking return NavigationUI.navigateUp(navController, drawerLayout) as the issue.

I tried everything like setting gravity to right|left or just left, even degrading the dependencies, but it's not working at all.

Please someone help as I wasted a lot of time with this.

deprecated way for options Menu

setHasOptionsMenu(true) is deprecated at title fragment
onCreateOptionsMenu is deprecated at title fragment
onOptionsItemSelected is deprecated at title fragment

GameWonFragment compiler error when passing fragment in ShareCompat.IntentBuilder.from()

In GameWonFragment, in the fun getShareIntent the line:

return ShareCompat.IntentBuilder.from(activity)
                .setText(getString(R.string.share_success_text, args.numCorrect, args.numQuestions))
                .setType("text/plain")
                .intent

gives the error:
"Type mismatch. Required: Activity, Found: Fragment Activity?"
image

Error is in starter code branch, and Step 11 Solution Branch so I guess it is in every branch but I have not checked yet.

Can't use safe args

After adding safe-args dependency and plugins, there are no generated class.
GameFragmentDirections doesn't show up.

When I type below code in GameFragment Kotlin file, an error shows up at GameFragmentDirections. The error says unresolved references
(screenshot as below)

safe args issue

Fails to build in Android Studio 3.4, citing Gradle errors or IDE fatal error

This code does not build in Android Studio 3.4. It cites these Gradle errors if I choose "Don't remind me again for this project" when asked to update Gradle, as the lesson asks:

Screen Shot 2019-05-13 at 9 55 28 AM

When I do update Gradle contrary to the lesson plans, and then rebuild, I get this "IDE Fatal Error":

java.lang.IndexOutOfBoundsException: Index: 45, Size: 407
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at com.intellij.ui.speedSearch.FilteringListModel.getElementAt(FilteringListModel.java:111)
	at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1360)
	at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1311)
	at javax.swing.plaf.basic.BasicListUI.getPreferredSize(BasicListUI.java:578)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1663)
	at com.intellij.ui.components.JBList.getPreferredSize(JBList.java:184)
	at javax.swing.JList.getScrollableTracksViewportWidth(JList.java:2772)
	at com.intellij.ui.components.JBScrollPane$Layout.preferredLayoutSize(JBScrollPane.java:699)
	at java.awt.Container.preferredSize(Container.java:1797)
	at java.awt.Container.getPreferredSize(Container.java:1781)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1665)
	at javax.swing.BoxLayout.checkRequests(BoxLayout.java:484)
	at javax.swing.BoxLayout.preferredLayoutSize(BoxLayout.java:301)
	at javax.swing.plaf.basic.DefaultMenuLayout.preferredLayoutSize(DefaultMenuLayout.java:60)
	at java.awt.Container.preferredSize(Container.java:1797)
	at java.awt.Container.getPreferredSize(Container.java:1781)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1665)
	at com.android.tools.adtui.stdui.DefaultLookupUI.getPopupSize(Lookup.kt:314)
	at com.android.tools.adtui.stdui.Lookup.computeLocation(Lookup.kt:221)
	at com.android.tools.adtui.stdui.Lookup.display(Lookup.kt:203)
	at com.android.tools.adtui.stdui.Lookup.updateFilter(Lookup.kt:107)
	at com.android.tools.adtui.stdui.Lookup.showLookup(Lookup.kt:70)
	at com.android.tools.adtui.stdui.CommonTextField$18.textChanged(CommonTextField.kt:78)
	at com.intellij.ui.DocumentAdapter.insertUpdate(DocumentAdapter.java:15)
	at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201)
	at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748)
	at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)
	at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
	at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
	at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1330)
	at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:884)
	at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1663)
	at javax.swing.JComponent.processKeyBinding(JComponent.java:2883)
	at javax.swing.JComponent.processKeyBindings(JComponent.java:2930)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:2846)
	at java.awt.Component.processEvent(Component.java:6325)
	at java.awt.Container.processEvent(Container.java:2237)
	at java.awt.Component.dispatchEventImpl(Component.java:4903)
	at java.awt.Container.dispatchEventImpl(Container.java:2295)
	at java.awt.Component.dispatchEvent(Component.java:4725)
	at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
	at com.intellij.ide.IdeKeyboardFocusManager.dispatchEvent(IdeKeyboardFocusManager.java:27)
	at java.awt.Component.dispatchEventImpl(Component.java:4774)
	at java.awt.Container.dispatchEventImpl(Container.java:2295)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4725)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
	at java.awt.EventQueue$4.run(EventQueue.java:737)
	at java.awt.EventQueue$4.run(EventQueue.java:735)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:755)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:682)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

I've been having a lot of trouble going through these lessons in Android Studio 3.4.

Adding the Up-Button causes app crashing

I had an issue with adding the Up-Button, where my App crashed with the message that my MainActivity would not have a NavController set.

I fixed this by accessing the navHostFragment directly:
// Delete this line
val navController = this.findNavController(R.id.myNavHostFragment)

//Replace it with:
val navHostFragment = supportFragmentManager.findFragmentById(R.id.myNavHostFragment) as NavHostFragment
val navController = navHostFragment.navController

//Continue with
NavigationUI.setupActionBarWithNavController(this, navController)

NavigationUp

val navController = this.findNavController(R.id.myNavHostFragment)

For this code, below error is showing:
"

Type mismatch: inferred type is Int but View was expected ย 

"

ActivityMainBinding and FragmentTitleBinding unresolved reference

I don't know if this only happened to me, but when I tried binding the layout to the TitleFragment, the com.example.android.navigation.databinding.ActivityMainBinding (in MainActivity.kt) and com.example.android.navigation.databinding.FragmentTitleBinding (in TitleFragment) imports were giving me an unresolved reference error and consequently a compilation error.

I fixed them by adding kapt "com.android.databinding:compiler:3.1.4" to the app build.gradle file and that seems to have done the trick, but given that I am somewhat of a novice I'm unsure whether it's just a quick fix or it was the right thing to do. Could you please confirm? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.