Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
https://curiousjr.com

Janishar Ali janishar

💻
https://curiousjr.com
View GitHub Profile
View shipsy-greendao-DemoApp-custom-deohelper.java
@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","", ""));
}
View shipsy-greendao-DbOpenHelper.java
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);
View shipsy-greendao-MainActivity.java
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.
View shipsy-greendao-manifest.xml
<application
...
android:name=".DemoApp"
...
>
</application>
View shipsy-greendao-DemoApp.java
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();
View shipsy-greendao-user.java
@Entity(nameInDb = "user")
public class User {
@Id(autoincrement = true)
private Long id;
@Property(nameInDb = "name")
private String name;
@Property(nameInDb = "created_at")
View dagger2-demo-activity_main.xml
<?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"
View dagger2-demo-MainActivity.java
public class MainActivity extends AppCompatActivity {
@Inject
DataManager mDataManager;
private ActivityComponent activityComponent;
private TextView mTvUserInfo;
private TextView mTvAccessToken;
View dagger2-demo-DemoApplication.java
public class DemoApplication extends Application {
protected ApplicationComponent applicationComponent;
@Inject
DataManager dataManager;
public static DemoApplication get(Context context) {
return (DemoApplication) context.getApplicationContext();
}