Skip to content

Instantly share code, notes, and snippets.

View janishar's full-sized avatar
:octocat:
Enthusiastically Curious

Janishar Ali janishar

:octocat:
Enthusiastically Curious
View GitHub Profile
android {
...
}
greendao {
schemaVersion 1
}
@Override
public void onCreate() {
super.onCreate();
mDaoSession =
new DaoMaster(new DbOpenHelper(this, "greendao_demo.db").getWritableDb()).newSession();
// USER CREATION FOR DEMO PURPOSE
if(mDaoSession.getUserDao().loadAll().size() == 0){
mDaoSession.getUserDao().insert(new User(1L, "Janishar Ali","", ""));
}
public class DbOpenHelper extends DaoMaster.OpenHelper {
public DbOpenHelper(Context context, String name) {
super(context, name);
}
@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
super.onUpgrade(db, oldVersion, newVersion);
Log.d("DEBUG", "DB_OLD_VERSION : " + oldVersion + ", DB_NEW_VERSION : " + newVersion);
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView) findViewById(R.id.text);
// Put this in a different thread or use AsyncSession in greenDAO.
<application
...
android:name=".DemoApp"
...
>
</application>
public class DemoApp extends Application {
private DaoSession mDaoSession;
@Override
public void onCreate() {
super.onCreate();
mDaoSession = new DaoMaster(
new DaoMaster.DevOpenHelper(this, "greendao_demo.db").getWritableDb()).newSession();
@Entity(nameInDb = "user")
public class User {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "name")
private String name;
@Property(nameInDb = "created_at")
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
public class MainActivity extends AppCompatActivity {
@Inject
DataManager mDataManager;
private ActivityComponent activityComponent;
private TextView mTvUserInfo;
private TextView mTvAccessToken;
public class DemoApplication extends Application {
protected ApplicationComponent applicationComponent;
@Inject
DataManager dataManager;
public static DemoApplication get(Context context) {
return (DemoApplication) context.getApplicationContext();
}