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
android { | |
... | |
} | |
greendao { | |
schemaVersion 1 | |
} |
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
@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","", "")); | |
} |
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
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); |
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
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. |
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
<application | |
... | |
android:name=".DemoApp" | |
... | |
> | |
</application> |
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
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(); |
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
@Entity(nameInDb = "user") | |
public class User { | |
@Id(autoincrement = true) | |
private Long id; | |
@Property(nameInDb = "name") | |
private String name; | |
@Property(nameInDb = "created_at") |
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
<?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" |
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
public class MainActivity extends AppCompatActivity { | |
@Inject | |
DataManager mDataManager; | |
private ActivityComponent activityComponent; | |
private TextView mTvUserInfo; | |
private TextView mTvAccessToken; |
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
public class DemoApplication extends Application { | |
protected ApplicationComponent applicationComponent; | |
@Inject | |
DataManager dataManager; | |
public static DemoApplication get(Context context) { | |
return (DemoApplication) context.getApplicationContext(); | |
} |
NewerOlder