From 1832fce83e9063df7c3d4a056417499bcc5383e3 Mon Sep 17 00:00:00 2001 From: Anamika Date: Thu, 29 Mar 2018 23:50:29 +0530 Subject: [PATCH 1/8] room library added for SQLite --- app/build.gradle | 6 +- .../majorproject/HomeScreen.java | 19 ++++- .../majorproject/RoomSample/AppDatabase.java | 33 ++++++++ .../RoomSample/DatabaseInitializer.java | 61 +++++++++++++++ .../majorproject/RoomSample/Project.java | 75 +++++++++++++++++++ .../majorproject/RoomSample/ProjectDao.java | 27 +++++++ app/src/main/res/values/colors.xml | 11 ++- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 9 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java diff --git a/app/build.gradle b/app/build.gradle index 9ede0a1..10200c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,7 +28,11 @@ dependencies { androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + + //Room dependencies + implementation 'android.arch.persistence.room:runtime:1.0.0' + annotationProcessor 'android.arch.persistence.room:compiler:1.0.0' // butter knife - compile 'com.jakewharton:butterknife:8.8.1' + implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' } diff --git a/app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java b/app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java index 65a80ca..0e5eb3d 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java @@ -6,12 +6,16 @@ import android.view.View; import android.widget.Button; +import com.example.androidtechies.majorproject.RoomSample.AppDatabase; +import com.example.androidtechies.majorproject.RoomSample.DatabaseInitializer; + public class HomeScreen extends AppCompatActivity { public static final String HomeScreenTag = "HomeScreen"; public static final Integer cseValue = 0; public static final Integer it = 0; public static final Integer ece = 0; public static final Integer eee = 0; + AppDatabase appDatabase; @Override protected void onCreate(Bundle savedInstanceState) { @@ -24,12 +28,17 @@ protected void onCreate(Bundle savedInstanceState) { cse.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent cseIntent = new Intent(HomeScreen.this, ListPage.class); - cseIntent.putExtra(HomeScreenTag, cseValue); - startActivity(cseIntent); +// Intent cseIntent = new Intent(HomeScreen.this, ListPage.class); +// cseIntent.putExtra(HomeScreenTag, cseValue); +// startActivity(cseIntent); + populateDatabase(); } }); + + + + // ece.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { @@ -55,5 +64,9 @@ public void onClick(View view) { // } // }); } + + private void populateDatabase() { + DatabaseInitializer.populateAsync(AppDatabase.getAppDatabase(this)); } +} diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java new file mode 100644 index 0000000..17fa5ca --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java @@ -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; + } + +} diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java new file mode 100644 index 0000000..ab45c0d --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java @@ -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 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 { + + private final AppDatabase mDb; + + PopulateDbAsync(AppDatabase db) { + mDb = db; + } + + @Override + protected Void doInBackground(final Void... params) { + populateWithTestData(mDb); + return null; + } + + } +} diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java new file mode 100644 index 0000000..dab46d9 --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java @@ -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; + } +} diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java new file mode 100644 index 0000000..26ded65 --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java @@ -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 getAll(); + + + @Query("SELECT COUNT(*) from project_table") + int countProjects(); + + @Insert + void insertAll(Project... users); + + @Delete + void delete(Project user); + +} diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e04526b..fe20846 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,8 +1,11 @@ - #9E9E9E - #616161 - #FF4081 + #673AB7 + #512DA8 + #607D8B #000000 - + #212121 + #757575 + #FFFFFF + #BDBDBD diff --git a/build.gradle b/build.gradle index e6b32bc..47825b2 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.1.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 57a3ad8..abedcad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 From dfeda34c7aaae93ab35a56908c0aef3aba1d1e39 Mon Sep 17 00:00:00 2001 From: Anamika Date: Mon, 2 Apr 2018 13:34:34 +0530 Subject: [PATCH 2/8] room implemented --- app/src/main/AndroidManifest.xml | 4 +- .../majorproject/BranchPage/HomeContract.java | 13 ++++ .../BranchPage/HomePresenter.java | 18 +++++ .../BranchPage/HomeScreenActivity.java | 68 ++++++++++++++++++ .../{RoomSample => Data}/AppDatabase.java | 21 +++--- .../DatabaseInitializer.java | 29 +++++++- .../{RoomSample => Data}/Project.java | 10 ++- .../{RoomSample => Data}/ProjectDao.java | 6 +- .../majorproject/HomeScreen.java | 72 ------------------- .../{ => ListProjects}/ListAdapter.java | 5 +- .../{ => ListProjects}/ListPage.java | 12 +++- .../majorproject/SplashScreen.java | 4 +- .../majorproject/Utils/AppExecutors.java | 24 +++++++ .../main/res/layout/activity_home_screen.xml | 2 +- .../main/res/layout/activity_list_page.xml | 2 +- 15 files changed, 195 insertions(+), 95 deletions(-) create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeContract.java create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomePresenter.java create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeScreenActivity.java rename app/src/main/java/com/example/androidtechies/majorproject/{RoomSample => Data}/AppDatabase.java (52%) rename app/src/main/java/com/example/androidtechies/majorproject/{RoomSample => Data}/DatabaseInitializer.java (70%) rename app/src/main/java/com/example/androidtechies/majorproject/{RoomSample => Data}/Project.java (89%) rename app/src/main/java/com/example/androidtechies/majorproject/{RoomSample => Data}/ProjectDao.java (72%) delete mode 100644 app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java rename app/src/main/java/com/example/androidtechies/majorproject/{ => ListProjects}/ListAdapter.java (91%) rename app/src/main/java/com/example/androidtechies/majorproject/{ => ListProjects}/ListPage.java (85%) create mode 100644 app/src/main/java/com/example/androidtechies/majorproject/Utils/AppExecutors.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ba96da7..b373bbf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,8 +16,8 @@ - - + + diff --git a/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeContract.java b/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeContract.java new file mode 100644 index 0000000..2f8186f --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeContract.java @@ -0,0 +1,13 @@ +package com.example.androidtechies.majorproject.BranchPage; + + +public interface HomeContract { + + interface IHomePresenter { + void openNewActivity(int i); + } + + interface IHomeView { + void showNewActivity(int i); + } +} diff --git a/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomePresenter.java b/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomePresenter.java new file mode 100644 index 0000000..6996768 --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomePresenter.java @@ -0,0 +1,18 @@ +package com.example.androidtechies.majorproject.BranchPage; + +import com.example.androidtechies.majorproject.Data.DatabaseInitializer; + +public class HomePresenter implements HomeContract.IHomePresenter{ + + private HomeContract.IHomeView view; + + public HomePresenter(HomeContract.IHomeView view) { + this.view = view; + } + + @Override + public void openNewActivity(int branchValue) { + view.showNewActivity(branchValue); + + } +} diff --git a/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeScreenActivity.java b/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeScreenActivity.java new file mode 100644 index 0000000..f621b9d --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/BranchPage/HomeScreenActivity.java @@ -0,0 +1,68 @@ +package com.example.androidtechies.majorproject.BranchPage; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +import com.example.androidtechies.majorproject.ListProjects.ListPage; +import com.example.androidtechies.majorproject.R; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class HomeScreenActivity extends AppCompatActivity implements View.OnClickListener,HomeContract.IHomeView{ + public static final String HomeScreenTag = "HomeScreenActivity"; + + @BindView(R.id.cseTag) + Button cseButton; + @BindView(R.id.itTag) + Button itButton; + @BindView(R.id.eceTag) + Button eceButton; + @BindView(R.id.eeeTag) + Button eeeButton; + + HomePresenter presenter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_home_screen); + + ButterKnife.bind(this); + presenter = new HomePresenter(this); + //setting listeners on all buttons + cseButton.setOnClickListener(this); + itButton.setOnClickListener(this); + eceButton.setOnClickListener(this); + eeeButton.setOnClickListener(this); + + } + +// private void populateDatabase() { +// DatabaseInitializer.populateAsync(AppDatabase.getAppDatabase(this)); +// } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.cseTag : break; + case R.id.itTag : presenter.openNewActivity(1); + break; + case R.id.eceTag : break; + case R.id.eeeTag : break; + } + } + + //Todo ask for any other way of handling multiple buttons openin same activity with some passing value + @Override + public void showNewActivity(int branchValue) { + Intent intent = new Intent(this, ListPage.class); + intent.putExtra(HomeScreenTag, branchValue); + startActivity(intent); + } + +} + diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java b/app/src/main/java/com/example/androidtechies/majorproject/Data/AppDatabase.java similarity index 52% rename from app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java rename to app/src/main/java/com/example/androidtechies/majorproject/Data/AppDatabase.java index 17fa5ca..3d0340f 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/AppDatabase.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/Data/AppDatabase.java @@ -1,4 +1,4 @@ -package com.example.androidtechies.majorproject.RoomSample; +package com.example.androidtechies.majorproject.Data; import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; @@ -13,17 +13,20 @@ public abstract class AppDatabase extends RoomDatabase { public abstract ProjectDao projectDao(); + private static final Object sLock = new Object(); + 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(); + synchronized (sLock) { + if (INSTANCE == null) { + INSTANCE = + Room.databaseBuilder(context.getApplicationContext(), + AppDatabase.class, "user-database") + .build(); + } + return INSTANCE; } - return INSTANCE; + } public static void destroyInstance() { diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java b/app/src/main/java/com/example/androidtechies/majorproject/Data/DatabaseInitializer.java similarity index 70% rename from app/src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java rename to app/src/main/java/com/example/androidtechies/majorproject/Data/DatabaseInitializer.java index ab45c0d..c18e9df 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/DatabaseInitializer.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/Data/DatabaseInitializer.java @@ -1,6 +1,5 @@ -package com.example.androidtechies.majorproject.RoomSample; +package com.example.androidtechies.majorproject.Data; -import android.content.Context; import android.os.AsyncTask; import android.support.annotation.NonNull; import android.util.Log; @@ -8,12 +7,15 @@ import java.util.List; public class DatabaseInitializer { + //tag by class name private static final String TAG = DatabaseInitializer.class.getName(); + //creates & executes populate async-task public static void populateAsync(@NonNull final AppDatabase db) { PopulateDbAsync task = new PopulateDbAsync(db); task.execute(); + } public static void populateSync(@NonNull final AppDatabase db) { @@ -58,4 +60,27 @@ protected Void doInBackground(final Void... params) { } } + + private static class GetProjectsAsync extends AsyncTask> { + + private final AppDatabase database; + + public GetProjectsAsync(AppDatabase database) { + this.database = database; + } + + @Override + protected List doInBackground(String... strings) { + String branchName = strings[0]; + List projects = database.projectDao().getBranchAllData(branchName); + + return projects; + } + + @Override + protected void onPostExecute(List projects) { + super.onPostExecute(projects); + + } + } } diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java b/app/src/main/java/com/example/androidtechies/majorproject/Data/Project.java similarity index 89% rename from app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java rename to app/src/main/java/com/example/androidtechies/majorproject/Data/Project.java index dab46d9..beee290 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/Project.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/Data/Project.java @@ -1,12 +1,14 @@ -package com.example.androidtechies.majorproject.RoomSample; +package com.example.androidtechies.majorproject.Data; import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.Entity; import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; @Entity(tableName = "project_table") public class Project { + @NonNull @PrimaryKey(autoGenerate = true) private int id; @@ -22,9 +24,13 @@ public class Project { @ColumnInfo(name = "technology_used") private String technologyUsed; - @ColumnInfo(name = "modules") + @ColumnInfo(name = "modules_used") private String modulesOfProject; + /* + Getters and Setters + */ + public int getId() { return id; } diff --git a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java b/app/src/main/java/com/example/androidtechies/majorproject/Data/ProjectDao.java similarity index 72% rename from app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java rename to app/src/main/java/com/example/androidtechies/majorproject/Data/ProjectDao.java index 26ded65..3ee7aba 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/RoomSample/ProjectDao.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/Data/ProjectDao.java @@ -1,4 +1,4 @@ -package com.example.androidtechies.majorproject.RoomSample; +package com.example.androidtechies.majorproject.Data; import android.arch.persistence.room.Dao; @@ -24,4 +24,8 @@ public interface ProjectDao { @Delete void delete(Project user); + @Query("SELECT * FROM project_table where branch = :branchName ") + List getBranchAllData(String branchName); + + } diff --git a/app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java b/app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java deleted file mode 100644 index 0e5eb3d..0000000 --- a/app/src/main/java/com/example/androidtechies/majorproject/HomeScreen.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.example.androidtechies.majorproject; - -import android.content.Intent; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; - -import com.example.androidtechies.majorproject.RoomSample.AppDatabase; -import com.example.androidtechies.majorproject.RoomSample.DatabaseInitializer; - -public class HomeScreen extends AppCompatActivity { - public static final String HomeScreenTag = "HomeScreen"; - public static final Integer cseValue = 0; - public static final Integer it = 0; - public static final Integer ece = 0; - public static final Integer eee = 0; - AppDatabase appDatabase; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_home_screen); - final Button cse = (Button) findViewById(R.id.cseTag); - Button ece = (Button) findViewById(R.id.eceTag); - Button it = (Button) findViewById(R.id.itTag); - Button eee = (Button) findViewById(R.id.eeeTag); - cse.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { -// Intent cseIntent = new Intent(HomeScreen.this, ListPage.class); -// cseIntent.putExtra(HomeScreenTag, cseValue); -// startActivity(cseIntent); - populateDatabase(); - - } - }); - - - - -// ece.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// Intent ece = new Intent(HomeScreen.this, ECEHomeScreen.class); -// startActivity(ece); -// -// } -// }); -// it.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// Intent it = new Intent(HomeScreen.this, ITHomeScreen.class); -// startActivity(it); -// -// } -// }); -// eee.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// Intent eee = new Intent(HomeScreen.this, EEEHomeScreen.class); -// startActivity(eee); -// -// } -// }); - } - - private void populateDatabase() { - DatabaseInitializer.populateAsync(AppDatabase.getAppDatabase(this)); - } -} - diff --git a/app/src/main/java/com/example/androidtechies/majorproject/ListAdapter.java b/app/src/main/java/com/example/androidtechies/majorproject/ListProjects/ListAdapter.java similarity index 91% rename from app/src/main/java/com/example/androidtechies/majorproject/ListAdapter.java rename to app/src/main/java/com/example/androidtechies/majorproject/ListProjects/ListAdapter.java index a566d9f..2a99bd5 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/ListAdapter.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/ListProjects/ListAdapter.java @@ -1,4 +1,4 @@ -package com.example.androidtechies.majorproject; +package com.example.androidtechies.majorproject.ListProjects; import android.content.Context; import android.support.v7.widget.RecyclerView; @@ -7,6 +7,9 @@ import android.view.ViewGroup; import android.widget.TextView; +import com.example.androidtechies.majorproject.InformationModel; +import com.example.androidtechies.majorproject.R; + import java.util.ArrayList; /** diff --git a/app/src/main/java/com/example/androidtechies/majorproject/ListPage.java b/app/src/main/java/com/example/androidtechies/majorproject/ListProjects/ListPage.java similarity index 85% rename from app/src/main/java/com/example/androidtechies/majorproject/ListPage.java rename to app/src/main/java/com/example/androidtechies/majorproject/ListProjects/ListPage.java index e479454..da36f28 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/ListPage.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/ListProjects/ListPage.java @@ -1,4 +1,4 @@ -package com.example.androidtechies.majorproject; +package com.example.androidtechies.majorproject.ListProjects; import android.content.Intent; import android.support.v7.app.AppCompatActivity; @@ -6,9 +6,13 @@ import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.util.Log; import android.view.View; +import com.example.androidtechies.majorproject.BranchPage.HomeScreenActivity; +import com.example.androidtechies.majorproject.DescriptionActivity; +import com.example.androidtechies.majorproject.InformationModel; +import com.example.androidtechies.majorproject.R; + import java.util.ArrayList; public class ListPage extends AppCompatActivity { @@ -19,8 +23,10 @@ public class ListPage extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list_page); + + Intent intent = getIntent(); - Integer value = intent.getIntExtra(HomeScreen.HomeScreenTag,0); + Integer value = intent.getIntExtra(HomeScreenActivity.HomeScreenTag,0); informationModelArrayList = new ArrayList<>(); informationModelArrayList = createFakeData(value); diff --git a/app/src/main/java/com/example/androidtechies/majorproject/SplashScreen.java b/app/src/main/java/com/example/androidtechies/majorproject/SplashScreen.java index 109febf..def5909 100644 --- a/app/src/main/java/com/example/androidtechies/majorproject/SplashScreen.java +++ b/app/src/main/java/com/example/androidtechies/majorproject/SplashScreen.java @@ -8,6 +8,8 @@ import android.view.animation.AnimationUtils; import android.widget.*; +import com.example.androidtechies.majorproject.BranchPage.HomeScreenActivity; + public class SplashScreen extends AppCompatActivity { private TextView textView; private ImageView imageView; @@ -21,7 +23,7 @@ protected void onCreate(Bundle savedInstanceState) { Animation myanim = AnimationUtils.loadAnimation(this,R.anim.mytransition); textView.startAnimation(myanim); imageView.startAnimation(myanim); - final Intent branch = new Intent(this,HomeScreen.class); + final Intent branch = new Intent(this,HomeScreenActivity.class); Thread timer = new Thread(){ public void run(){ try { diff --git a/app/src/main/java/com/example/androidtechies/majorproject/Utils/AppExecutors.java b/app/src/main/java/com/example/androidtechies/majorproject/Utils/AppExecutors.java new file mode 100644 index 0000000..b97e386 --- /dev/null +++ b/app/src/main/java/com/example/androidtechies/majorproject/Utils/AppExecutors.java @@ -0,0 +1,24 @@ +package com.example.androidtechies.majorproject.Utils; + +import android.support.annotation.NonNull; + +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +public class AppExecutors implements Executor { + + private final Executor mDiskIO; + @Override + public void execute(@NonNull Runnable command) { + mDiskIO.execute(command); + + } + + public AppExecutors() { + mDiskIO = Executors.newSingleThreadExecutor(); + } + + public Executor diskIO() { + return mDiskIO; + } +} diff --git a/app/src/main/res/layout/activity_home_screen.xml b/app/src/main/res/layout/activity_home_screen.xml index 79bbb87..b0c0a13 100644 --- a/app/src/main/res/layout/activity_home_screen.xml +++ b/app/src/main/res/layout/activity_home_screen.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" android:background="@color/colorPrimary" - tools:context="com.example.androidtechies.majorproject.HomeScreen"> + tools:context="com.example.androidtechies.majorproject.BranchPage.HomeScreenActivity">