-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fd7b7e
commit 75e5536
Showing
9 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
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
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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.example.androidtechies.majorproject.RoomSample; | ||
|
||
import android.arch.persistence.room.Database; | ||
import android.arch.persistence.room.Room; | ||
import android.arch.persistence.room.RoomDatabase; | ||
import android.content.Context; | ||
|
||
|
||
@Database(entities = {Project.class}, version = 1) | ||
public abstract class AppDatabase extends RoomDatabase { | ||
|
||
private static AppDatabase INSTANCE; | ||
|
||
public abstract ProjectDao projectDao(); | ||
|
||
|
||
public static AppDatabase getAppDatabase(Context context) { | ||
if (INSTANCE == null) { | ||
INSTANCE = | ||
Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "user-database") | ||
// allow queries on the main thread. | ||
// Not suggested to do on real application! | ||
.allowMainThreadQueries() | ||
.build(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public static void destroyInstance() { | ||
INSTANCE = null; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.example.androidtechies.majorproject.RoomSample; | ||
|
||
import android.content.Context; | ||
import android.os.AsyncTask; | ||
import android.support.annotation.NonNull; | ||
import android.util.Log; | ||
|
||
import java.util.List; | ||
|
||
public class DatabaseInitializer { | ||
private static final String TAG = DatabaseInitializer.class.getName(); | ||
|
||
|
||
public static void populateAsync(@NonNull final AppDatabase db) { | ||
PopulateDbAsync task = new PopulateDbAsync(db); | ||
task.execute(); | ||
} | ||
|
||
public static void populateSync(@NonNull final AppDatabase db) { | ||
populateWithTestData(db); | ||
} | ||
|
||
private static Project addProject (final AppDatabase db, Project project) { | ||
db.projectDao().insertAll(project); | ||
return project; | ||
} | ||
|
||
private static void populateWithTestData(AppDatabase db) { | ||
|
||
Project project = new Project(); | ||
project.setTitleOfProject("Hinton"); | ||
project.setIntroOfProject("Hinton is a fake news generator (video) platform that aims to create\n" + | ||
" awareness among the society "); | ||
project.setModulesOfProject("news"); | ||
project.setProjectBranch("IT"); | ||
project.setTechnologyUsed("Machine learning"); | ||
addProject(db, project); | ||
|
||
List<Project> projectsList = db.projectDao().getAll(); | ||
|
||
int count = db.projectDao().countProjects(); | ||
// Log.d(DatabaseInitializer.TAG,); | ||
Log.d(DatabaseInitializer.TAG, "Branch name: " + projectsList.get(0).getProjectBranch()+ "\nNumber of rows: "+count); | ||
} | ||
|
||
private static class PopulateDbAsync extends AsyncTask<Void, Void, Void> { | ||
|
||
private final AppDatabase mDb; | ||
|
||
PopulateDbAsync(AppDatabase db) { | ||
mDb = db; | ||
} | ||
|
||
@Override | ||
protected Void doInBackground(final Void... params) { | ||
populateWithTestData(mDb); | ||
return null; | ||
} | ||
|
||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.androidtechies.majorproject.RoomSample; | ||
|
||
import android.arch.persistence.room.ColumnInfo; | ||
import android.arch.persistence.room.Entity; | ||
import android.arch.persistence.room.PrimaryKey; | ||
|
||
@Entity(tableName = "project_table") | ||
public class Project { | ||
|
||
@PrimaryKey(autoGenerate = true) | ||
private int id; | ||
|
||
@ColumnInfo(name = "branch") | ||
private String projectBranch; | ||
|
||
@ColumnInfo(name = "title_project") | ||
private String titleOfProject; | ||
|
||
@ColumnInfo(name = "intro_project") | ||
private String introOfProject; | ||
|
||
@ColumnInfo(name = "technology_used") | ||
private String technologyUsed; | ||
|
||
@ColumnInfo(name = "modules") | ||
private String modulesOfProject; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getProjectBranch() { | ||
return projectBranch; | ||
} | ||
|
||
public void setProjectBranch(String projectBranch) { | ||
this.projectBranch = projectBranch; | ||
} | ||
|
||
public String getTitleOfProject() { | ||
return titleOfProject; | ||
} | ||
|
||
public void setTitleOfProject(String titleOfProject) { | ||
this.titleOfProject = titleOfProject; | ||
} | ||
|
||
public String getIntroOfProject() { | ||
return introOfProject; | ||
} | ||
|
||
public void setIntroOfProject(String introOfProject) { | ||
this.introOfProject = introOfProject; | ||
} | ||
|
||
public String getTechnologyUsed() { | ||
return technologyUsed; | ||
} | ||
|
||
public void setTechnologyUsed(String technologyUsed) { | ||
this.technologyUsed = technologyUsed; | ||
} | ||
|
||
public String getModulesOfProject() { | ||
return modulesOfProject; | ||
} | ||
|
||
public void setModulesOfProject(String modulesOfProject) { | ||
this.modulesOfProject = modulesOfProject; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.example.androidtechies.majorproject.RoomSample; | ||
|
||
|
||
import android.arch.persistence.room.Dao; | ||
import android.arch.persistence.room.Delete; | ||
import android.arch.persistence.room.Insert; | ||
import android.arch.persistence.room.Query; | ||
|
||
import java.util.List; | ||
|
||
@Dao | ||
public interface ProjectDao { | ||
|
||
@Query("SELECT * FROM project_table") | ||
List<Project> getAll(); | ||
|
||
|
||
@Query("SELECT COUNT(*) from project_table") | ||
int countProjects(); | ||
|
||
@Insert | ||
void insertAll(Project... users); | ||
|
||
@Delete | ||
void delete(Project user); | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#9E9E9E</color> | ||
<color name="colorPrimaryDark">#616161</color> | ||
<color name="colorAccent">#FF4081</color> | ||
<color name="colorPrimary">#673AB7</color> | ||
<color name="colorPrimaryDark">#512DA8</color> | ||
<color name="colorAccent">#607D8B</color> | ||
<color name="black">#000000</color> | ||
|
||
<color name="primary_text">#212121</color> | ||
<color name="secondary_text">#757575</color> | ||
<color name="icons">#FFFFFF</color> | ||
<color name="divider">#BDBDBD</color> | ||
</resources> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Mar 13 13:19:59 IST 2018 | ||
#Tue Mar 27 20:08:43 IST 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip |