Coder Social home page Coder Social logo

android-persistence's Introduction

android-persistence's People

Contributors

josealcerreca 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-persistence's Issues

UsersActivity (Step 1) code is different from what is on page

At https://codelabs.developers.google.com/codelabs/android-persistence/#3 there is this paragraph "Next, open the step1 package and review the UsersActivity class, which fetches data from the database using the following code:" and in code box there is " List youngUsers = mDb.userModel().loadAllUsers();"

But in UsersActivity (Step 1) code there is already List youngUsers = mDb.userModel().findYoungerThan(35);

Step 1 page at Codelab should be the correct, initially.

Step 3: error during compiling on JankShowUserActivity.java if LiveData is used as return type

If the method findBooksBorrowedByNameSync return type is changed to LiveData<List < Book > >, then during compilation an error will occur at JankShowUserActivity.java's fetchData method. Changing all instances of parameters with List < Book > type in JankShowUserActivity with result in the foreach method giving a compile time error saying

error: for-each not applicable to expression type for (Book book : books) { ^ required: array or java.lang.Iterable found: LiveData<List<Book>>

Configurations not available to run

Downloaded the source and compiled/updated. the "Step 1" configuration is not available to run. The only config available is "app" which doesn't run.
as1

How can one fix this?

Android Studio Version 3.1.1
The resolution for this is to either update the source code, adding the appropriate Run Configurations, or update the CodeLab Instructions describing how users can properly create the needed Run Configurations.

Please remove popup everywhere on page content

http://prntscr.com/kisz0p

This one is not about persistence exactly - I've seen this on other codelabs also. More like a "feature" for everywhere on site.

Whenever you move mouse it animates and shows this popup, which has no sense in appearing at all, but does a ton of distraction (maybe it's just me, maybe I have ADHD or whatever - this is killing me).

Pretty please - pass this to someone responsible for supporting the whole codelabs platform. Thanks!

getTodayPlusDays method

Hi. I think it's wrong to use set method instead of add to add days in the following method:

private static Date getTodayPlusDays(int daysAgo) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DATE, daysAgo);
    return calendar.getTime();
}

Same mistake in code labs.

Addition line should look like this

calendar.add(Calendar.DATE, daysAgo);

P.S. Thanks for examples.

Update Project for Android Oreo

To ensure that the project builds and runs on Android Oreo, the version numbers in the build.gradle need to be updated.
The LifecycleActivity extensions need to be replaced with AppCompatActivity in version 1.0.0 of LifeCycle Extensions.
There are changes to Room 1.0.0 that require Primary Keys to have the annotation @NonNull.

As well as this, Issue #2 needs to be fixed too, before the project will build.

Wrong code snippet in Step 1

The code snippet for fetchData() contains the call mDb.userModel().loadAllUsers() instead of mDb.userModel().findUsersYoungerThan(35) as in the provided project.

That makes the sentence about an "impostor" in the sentence that follows confusing because you'd expect to have all ages there.

Database is not being reloaded

I modified this code to populate dummy data only for the first time (when app is opened in step 3 solution). I used sharedpreference for that. But now opening for second time, no data is being displayed. Please help me in this.
I used following snippet -

String PREFERENCE_PATH = "com";
SharedPreferences prefs = getApplication().getSharedPreferences(PREFERENCE_PATH, MODE_PRIVATE);

// changed here in BooksBorrowedByUserViewModel class
public void createDb() {
mDb = AppDatabase.getInMemoryDatabase(this.getApplication());

    if (isAppLaunchedForFirstTime()) {
        prefs.edit().putBoolean(IS_APP_LAUNCHED_FOR_FIRST_TIME, false).apply();
        // Populate it with initial data
        DatabaseInitializer.populateAsync(mDb);
    }
}

private Boolean isAppLaunchedForFirstTime() {
return prefs.getBoolean(IS_APP_LAUNCHED_FOR_FIRST_TIME, true);
}

Link to PersistenceBasicSample

There is a comment to find PersistenceBasicSample that shows how we perform background tasks
Please provide the link ๐Ÿ‘

Function call in tutorial has an extra argument.

On the Persistence Codelab tutorial on 5. Step 3 - Observer Live Data From a ViewModel, on the following step:
5. Next, complete the subscribeUiBooks method by subscribing the activity to changes in the ViewModel object's list of books,:

private void subscribeUiBooks() {
    mViewModel.books.observe(this, new Observer<List<Book>>() {
        @Override
        public void onChanged(@NonNull final List<Book> books) {
            showBooksInUi(books, mBooksTextView);
        }
     });
}

the function call for showBooksInUi() should only take the list books, and the mBooksTextView should not be part of the call. That is in accordance with the definition of showBooksInUi() in the in the file com.example.android.persistence.codelab/step3/BooksBorrowedByUserActivity.java. The function definition is as follows:

private void showBooksInUi(final @NonNull List<Book> books) {
        StringBuilder sb = new StringBuilder();
        for (Book book : books) {
            sb.append(book.title);
            sb.append("\n");
        }
        mBooksTextView.setText(sb.toString());
    }

Thank you.

Extra argument "mBooksTextView" in step 3-5

After going through step 3 point 5, I observed that if you copy and paste the code provided from the tutorial here the code does not compile as there is an extra parameter in showBooksInUi(books, **mBooksTextView**);

The method showBooksInUi expects a List not a List and TextView

Impl does not exist, Kotlin with Android Studio 3.0

Using the latest version of Android Studio, Kotlin and Room. Database_impl does not exist when creating an instance of the database

gradle dependencies

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
}

Database class

@database(entities = arrayOf(Task::class), version = 1, exportSchema = false)
abstract class AppDatabase: RoomDatabase(){

companion object : SingletonHolder<AppDatabase, Context> ({
    Room.databaseBuilder(it.applicationContext,
            AppDatabase::class.java, "Tasks.db")
            .build()
})

abstract var taskDao : TaskDao

}

Default not activity found

Today ( Feb 19th 2018), I downloaded the code. I was not able to install straight away. The error being
'Error Running app: Default Activity not found'.

Solution : add inside tag in the manifest.xml ( you can add to any activity, I think to begin with step1.UsersActivity would be right place particularly if you are following the Room CodeLab)

(Just thought some one might find this useful)

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.