Last active
September 15, 2017 10:23
-
-
Save vogella/ff7fb8019a155209310a96edacb2b2e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
View refreshButton = tb.findViewById(R.id.action_refresh); | |
refreshButton.animate().rotation(100f).setDuration(2000); | |
RotateAnimation rotate = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, | |
0.5f, Animation.RELATIVE_TO_SELF, 0.5f); | |
rotate.setDuration(1000); | |
rotate.setRepeatCount(Animation.INFINITE); | |
refreshButton.startAnimation(rotate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.rssfeedlibrary; | |
import android.arch.persistence.room.Database; | |
import android.arch.persistence.room.Room; | |
import android.arch.persistence.room.RoomDatabase; | |
import android.content.Context; | |
@Database(entities = {RssItem.class | |
}, version = 1, exportSchema = false) | |
public abstract class AppDatabase extends RoomDatabase { | |
private static AppDatabase INSTANCE; | |
public abstract RssItemDao rssItemDao(); | |
public static AppDatabase getDatabase(Context context) { | |
if (INSTANCE == null) { | |
INSTANCE = | |
Room.databaseBuilder(context, AppDatabase.class, "rssitems") | |
//Room.inMemoryDatabaseBuilder(context.getApplicationContext(), AppDatabase.class) | |
// To simplify the exercise, allow queries on the main thread. | |
// Don't do this on a real app! | |
.allowMainThreadQueries() | |
// recreate the database if necessary | |
.fallbackToDestructiveMigration() | |
.build(); | |
} | |
return INSTANCE; | |
} | |
public static void destroyInstance() { | |
INSTANCE = null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api 'android.arch.lifecycle:extensions:1.0.0-alpha9' | |
api 'android.arch.persistence.room:runtime:1.0.0-alpha9' | |
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha9' | |
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha9' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ADJUST THE FRAGMENT | |
public class MyListFragment extends Fragment implements LifecycleRegistryOwner { | |
LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this); | |
@Override | |
public LifecycleRegistry getLifecycle() { | |
return lifecycleRegistry; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.rssfeedlibrary; | |
import android.arch.lifecycle.LiveData; | |
import android.arch.persistence.room.Dao; | |
import android.arch.persistence.room.Insert; | |
import android.arch.persistence.room.OnConflictStrategy; | |
import android.arch.persistence.room.Query; | |
import java.util.List; | |
@Dao | |
public interface RssItemDao { | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
void addItem(RssItem item); | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
void addItems(List<RssItem> item); | |
@Query("select * from rssitem") | |
public LiveData<List<RssItem>> getAllRssItems(); | |
@Query("select * from rssitem where id =:id") | |
public LiveData<RssItem> getRssItems(long id); | |
@Query("delete from rssitem") | |
void removeAllRssItems(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment