├── 01.SQLite-Single-Table-CRUD
├── .gitignore
├── README.md
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hellohasan
│ │ │ └── sqlite_project
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hellohasan
│ │ │ │ └── sqlite_project
│ │ │ │ ├── Database
│ │ │ │ ├── DatabaseHelper.java
│ │ │ │ └── DatabaseQueryClass.java
│ │ │ │ ├── Features
│ │ │ │ ├── CreateStudent
│ │ │ │ │ ├── Student.java
│ │ │ │ │ ├── StudentCreateDialogFragment.java
│ │ │ │ │ └── StudentCreateListener.java
│ │ │ │ ├── ShowStudentList
│ │ │ │ │ ├── CustomViewHolder.java
│ │ │ │ │ ├── StudentListActivity.java
│ │ │ │ │ └── StudentListRecyclerViewAdapter.java
│ │ │ │ └── UpdateStudentInfo
│ │ │ │ │ ├── StudentUpdateDialogFragment.java
│ │ │ │ │ └── StudentUpdateListener.java
│ │ │ │ └── Util
│ │ │ │ └── Config.java
│ │ └── res
│ │ │ ├── drawable-hdpi
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_add_subject.png
│ │ │ ├── ic_delete_black_24dp.png
│ │ │ ├── ic_mode_edit_black_24dp.png
│ │ │ └── ic_person_add_white_24dp.png
│ │ │ ├── drawable-mdpi
│ │ │ ├── ic_delete_black_24dp.png
│ │ │ ├── ic_mode_edit_black_24dp.png
│ │ │ └── ic_person_add_white_24dp.png
│ │ │ ├── drawable-xhdpi
│ │ │ ├── ic_delete_black_24dp.png
│ │ │ ├── ic_mode_edit_black_24dp.png
│ │ │ └── ic_person_add_white_24dp.png
│ │ │ ├── drawable-xxhdpi
│ │ │ ├── ic_delete_black_24dp.png
│ │ │ ├── ic_mode_edit_black_24dp.png
│ │ │ └── ic_person_add_white_24dp.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ ├── ic_delete_black_24dp.png
│ │ │ ├── ic_mode_edit_black_24dp.png
│ │ │ └── ic_person_add_white_24dp.png
│ │ │ ├── drawable
│ │ │ └── ic_delete_white_24dp.xml
│ │ │ ├── layout
│ │ │ ├── activity_student_list.xml
│ │ │ ├── content_main.xml
│ │ │ ├── fragment_student_create_dialog.xml
│ │ │ ├── fragment_student_update_dialog.xml
│ │ │ ├── student_info.xml
│ │ │ └── student_item.xml
│ │ │ ├── menu
│ │ │ └── menu_main.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hellohasan
│ │ └── sqlite_project
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── 02.SQLite-Multiple-(Two)-Tables-CRUD
├── .gitignore
├── README.md
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hellohasan
│ │ │ └── sqlite_project
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hellohasan
│ │ │ │ └── sqlite_project
│ │ │ │ ├── Database
│ │ │ │ ├── DatabaseHelper.java
│ │ │ │ └── DatabaseQueryClass.java
│ │ │ │ ├── Features
│ │ │ │ ├── StudentCRUD
│ │ │ │ │ ├── CreateStudent
│ │ │ │ │ │ ├── Student.java
│ │ │ │ │ │ ├── StudentCreateDialogFragment.java
│ │ │ │ │ │ └── StudentCreateListener.java
│ │ │ │ │ ├── ShowStudentList
│ │ │ │ │ │ ├── CustomViewHolder.java
│ │ │ │ │ │ ├── StudentListActivity.java
│ │ │ │ │ │ └── StudentListRecyclerViewAdapter.java
│ │ │ │ │ └── UpdateStudentInfo
│ │ │ │ │ │ ├── StudentUpdateDialogFragment.java
│ │ │ │ │ │ └── StudentUpdateListener.java
│ │ │ │ └── SubjectCRUD
│ │ │ │ │ ├── CreateSubject
│ │ │ │ │ ├── Subject.java
│ │ │ │ │ ├── SubjectCreateDialogFragment.java
│ │ │ │ │ └── SubjectCreateListener.java
│ │ │ │ │ ├── ShowSubjectList
│ │ │ │ │ ├── CustomViewHolder.java
│ │ │ │ │ ├── SubjectListActivity.java
│ │ │ │ │ └── SubjectListRecyclerViewAdapter.java
│ │ │ │ │ └── UpdateSubjectInfo
│ │ │ │ │ ├── SubjectUpdateDialogFragment.java
│ │ │ │ │ └── SubjectUpdateListener.java
│ │ │ │ └── Util
│ │ │ │ └── Config.java
│ │ └── res
│ │ │ ├── drawable-hdpi
│ │ │ └── drawable-xxhdpi
│ │ │ │ └── ic_add_subject.png
│ │ │ ├── drawable
│ │ │ ├── ic_delete_black_24dp.xml
│ │ │ ├── ic_delete_white_24dp.xml
│ │ │ ├── ic_mode_edit_black_24dp.xml
│ │ │ ├── ic_person_add_white_24dp.xml
│ │ │ └── ic_subject_add_24dp.xml
│ │ │ ├── layout
│ │ │ ├── activity_student_list.xml
│ │ │ ├── activity_subject_list.xml
│ │ │ ├── content_main.xml
│ │ │ ├── fragment_student_create_dialog.xml
│ │ │ ├── fragment_student_update_dialog.xml
│ │ │ ├── fragment_subject_create_dialog.xml
│ │ │ ├── fragment_subject_update_dialog.xml
│ │ │ ├── item_student.xml
│ │ │ ├── item_subject.xml
│ │ │ └── student_info.xml
│ │ │ ├── menu
│ │ │ └── menu_main.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hellohasan
│ │ └── sqlite_project
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── hs_err_pid6548.log
└── settings.gradle
├── 03.SQLite-Multiple-(Three)-Tables-CRUD
├── .gitignore
├── README.md
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hellohasan
│ │ │ └── sqlite_multiple_three_tables_crud
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hellohasan
│ │ │ │ └── sqlite_multiple_three_tables_crud
│ │ │ │ ├── database
│ │ │ │ ├── DatabaseHelper.java
│ │ │ │ ├── QueryContract.java
│ │ │ │ ├── QueryResponse.java
│ │ │ │ ├── StudentQueryImplementation.java
│ │ │ │ ├── SubjectQueryImplementation.java
│ │ │ │ ├── TableRowCountQueryImplementation.java
│ │ │ │ └── TakenSubjectQueryImplementation.java
│ │ │ │ ├── features
│ │ │ │ ├── student_crud
│ │ │ │ │ ├── StudentCrudListener.java
│ │ │ │ │ ├── student_create
│ │ │ │ │ │ └── StudentCreateDialogFragment.java
│ │ │ │ │ ├── student_list_show
│ │ │ │ │ │ ├── StudentListActivity.java
│ │ │ │ │ │ ├── StudentListAdapter.java
│ │ │ │ │ │ └── StudentViewHolder.java
│ │ │ │ │ └── student_update
│ │ │ │ │ │ └── StudentUpdateDialogFragment.java
│ │ │ │ ├── subject_crud
│ │ │ │ │ ├── SubjectCrudListener.java
│ │ │ │ │ ├── subject_create
│ │ │ │ │ │ └── SubjectCreateDialogFragment.java
│ │ │ │ │ ├── subject_list_show
│ │ │ │ │ │ ├── SubjectListActivity.java
│ │ │ │ │ │ ├── SubjectListAdapter.java
│ │ │ │ │ │ └── SubjectViewHolder.java
│ │ │ │ │ └── subject_update
│ │ │ │ │ │ └── SubjectUpdateDialogFragment.java
│ │ │ │ └── taken_subject_crud
│ │ │ │ │ ├── TakenSubjectCrudListener.java
│ │ │ │ │ ├── subject_assign
│ │ │ │ │ ├── SubjectAssignActivity.java
│ │ │ │ │ ├── SubjectAssignListAdapter.java
│ │ │ │ │ └── SubjectAssignViewHolder.java
│ │ │ │ │ └── taken_subject_show
│ │ │ │ │ ├── StudentTakenSubjectActivity.java
│ │ │ │ │ ├── TakenSubjectListAdapter.java
│ │ │ │ │ └── TakenSubjectViewHolder.java
│ │ │ │ ├── model
│ │ │ │ ├── Student.java
│ │ │ │ ├── Subject.java
│ │ │ │ ├── TableRowCount.java
│ │ │ │ └── TakenSubject.java
│ │ │ │ └── util
│ │ │ │ ├── Constants.java
│ │ │ │ └── MyApp.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ ├── ic_add_subject_24dp.xml
│ │ │ ├── ic_delete_black_24dp.xml
│ │ │ ├── ic_edit_black_24dp.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── ic_person_add_24dp.xml
│ │ │ └── ic_subject_24dp.xml
│ │ │ ├── layout
│ │ │ ├── activity_student_list.xml
│ │ │ ├── activity_student_taken_subject.xml
│ │ │ ├── activity_subject_assign.xml
│ │ │ ├── activity_subject_list.xml
│ │ │ ├── activity_taken_subject.xml
│ │ │ ├── content_main.xml
│ │ │ ├── content_subjects.xml
│ │ │ ├── fragment_student_create_dialog.xml
│ │ │ ├── fragment_student_update_dialog.xml
│ │ │ ├── fragment_subject_create_dialog.xml
│ │ │ ├── fragment_subject_update_dialog.xml
│ │ │ ├── item_student_card_view.xml
│ │ │ ├── item_subject_assign.xml
│ │ │ ├── item_subject_card_view.xml
│ │ │ ├── item_taken_subject.xml
│ │ │ ├── layout_student_info.xml
│ │ │ └── layout_table_row_count.xml
│ │ │ ├── menu
│ │ │ └── menu_main.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hellohasan
│ │ └── sqlite_multiple_three_tables_crud
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── README.md
└── data
├── Android-SQLite-Multiple-table-CRUD.gif
├── Android-SQLite-three-table-tutorial.gif
└── sqlite-app-screenshot.gif
/01.SQLite-Single-Table-CRUD/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.hellohasan.sqlite_project"
7 | minSdkVersion 15
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
24 | exclude group: 'com.android.support', module: 'support-annotations'
25 | })
26 | implementation 'androidx.appcompat:appcompat:1.1.0'
27 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
28 | implementation 'com.google.android.material:material:1.0.0'
29 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
30 | implementation 'com.orhanobut:logger:2.2.0'
31 | implementation 'androidx.cardview:cardview:1.0.0'
32 | implementation 'androidx.recyclerview:recyclerview:1.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | }
35 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/hasan/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/androidTest/java/com/hellohasan/sqlite_project/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hellohasan.sqlite_project", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Database/DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Database;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | import com.hellohasan.sqlite_project.Util.Config;
8 | import com.orhanobut.logger.AndroidLogAdapter;
9 | import com.orhanobut.logger.Logger;
10 |
11 | public class DatabaseHelper extends SQLiteOpenHelper {
12 |
13 | private static DatabaseHelper databaseHelper;
14 |
15 | // All Static variables
16 | private static final int DATABASE_VERSION = 1;
17 |
18 | // Database Name
19 | private static final String DATABASE_NAME = Config.DATABASE_NAME;
20 |
21 | // Constructor
22 | private DatabaseHelper(Context context) {
23 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
24 | Logger.addLogAdapter(new AndroidLogAdapter());
25 | }
26 |
27 | public static synchronized DatabaseHelper getInstance(Context context){
28 | if(databaseHelper==null){
29 | databaseHelper = new DatabaseHelper(context);
30 | }
31 | return databaseHelper;
32 | }
33 |
34 | @Override
35 | public void onCreate(SQLiteDatabase db) {
36 |
37 | // Create tables SQL execution
38 | String CREATE_STUDENT_TABLE = "CREATE TABLE " + Config.TABLE_STUDENT + "("
39 | + Config.COLUMN_STUDENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
40 | + Config.COLUMN_STUDENT_NAME + " TEXT NOT NULL, "
41 | + Config.COLUMN_STUDENT_REGISTRATION + " INTEGER NOT NULL UNIQUE, "
42 | + Config.COLUMN_STUDENT_PHONE + " TEXT, " //nullable
43 | + Config.COLUMN_STUDENT_EMAIL + " TEXT " //nullable
44 | + ")";
45 |
46 | Logger.d("Table create SQL: " + CREATE_STUDENT_TABLE);
47 |
48 | db.execSQL(CREATE_STUDENT_TABLE);
49 |
50 | Logger.d("DB created!");
51 | }
52 |
53 | @Override
54 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
55 | // Drop older table if existed
56 | db.execSQL("DROP TABLE IF EXISTS " + Config.TABLE_STUDENT);
57 |
58 | // Create tables again
59 | onCreate(db);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/CreateStudent/Student.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.CreateStudent;
2 |
3 | public class Student {
4 | private long id;
5 | private String name;
6 | private long registrationNumber;
7 | private String phoneNumber;
8 | private String email;
9 |
10 | public Student(int id, String name, long registrationNumber, String phoneNumber, String email) {
11 | this.id = id;
12 | this.name = name;
13 | this.registrationNumber = registrationNumber;
14 | this.phoneNumber = phoneNumber;
15 | this.email = email;
16 | }
17 |
18 | public long getId() {
19 | return id;
20 | }
21 |
22 | public void setId(long id) {
23 | this.id = id;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | public long getRegistrationNumber() {
35 | return registrationNumber;
36 | }
37 |
38 | public void setRegistrationNumber(long registrationNumber) {
39 | this.registrationNumber = registrationNumber;
40 | }
41 |
42 | public String getPhoneNumber() {
43 | return phoneNumber;
44 | }
45 |
46 | public void setPhoneNumber(String phoneNumber) {
47 | this.phoneNumber = phoneNumber;
48 | }
49 |
50 | public String getEmail() {
51 | return email;
52 | }
53 |
54 | public void setEmail(String email) {
55 | this.email = email;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/CreateStudent/StudentCreateDialogFragment.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.CreateStudent;
2 |
3 | import android.app.Dialog;
4 | import android.os.Bundle;
5 | import androidx.fragment.app.DialogFragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 |
12 | import com.hellohasan.sqlite_project.Util.Config;
13 | import com.hellohasan.sqlite_project.Database.DatabaseQueryClass;
14 | import com.hellohasan.sqlite_project.R;
15 |
16 |
17 | public class StudentCreateDialogFragment extends DialogFragment {
18 |
19 | private static StudentCreateListener studentCreateListener;
20 |
21 | private EditText nameEditText;
22 | private EditText registrationEditText;
23 | private EditText phoneEditText;
24 | private EditText emailEditText;
25 | private Button createButton;
26 | private Button cancelButton;
27 |
28 | private String nameString = "";
29 | private long registrationNumber = -1;
30 | private String phoneString = "";
31 | private String emailString = "";
32 |
33 | public StudentCreateDialogFragment() {
34 | // Required empty public constructor
35 | }
36 |
37 | public static StudentCreateDialogFragment newInstance(String title, StudentCreateListener listener){
38 | studentCreateListener = listener;
39 | StudentCreateDialogFragment studentCreateDialogFragment = new StudentCreateDialogFragment();
40 | Bundle args = new Bundle();
41 | args.putString("title", title);
42 | studentCreateDialogFragment.setArguments(args);
43 |
44 | studentCreateDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);
45 |
46 | return studentCreateDialogFragment;
47 | }
48 |
49 |
50 | @Override
51 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
52 | Bundle savedInstanceState) {
53 |
54 | View view = inflater.inflate(R.layout.fragment_student_create_dialog, container, false);
55 |
56 | nameEditText = view.findViewById(R.id.studentNameEditText);
57 | registrationEditText = view.findViewById(R.id.registrationEditText);
58 | phoneEditText = view.findViewById(R.id.phoneEditText);
59 | emailEditText = view.findViewById(R.id.emailEditText);
60 | createButton = view.findViewById(R.id.createButton);
61 | cancelButton = view.findViewById(R.id.cancelButton);
62 |
63 | String title = getArguments().getString(Config.TITLE);
64 | getDialog().setTitle(title);
65 |
66 | createButton.setOnClickListener(new View.OnClickListener() {
67 | @Override
68 | public void onClick(View view) {
69 | nameString = nameEditText.getText().toString();
70 | registrationNumber = Integer.parseInt(registrationEditText.getText().toString());
71 | phoneString = phoneEditText.getText().toString();
72 | emailString = emailEditText.getText().toString();
73 |
74 | Student student = new Student(-1, nameString, registrationNumber, phoneString, emailString);
75 |
76 | DatabaseQueryClass databaseQueryClass = new DatabaseQueryClass(getContext());
77 |
78 | long id = databaseQueryClass.insertStudent(student);
79 |
80 | if(id>0){
81 | student.setId(id);
82 | studentCreateListener.onStudentCreated(student);
83 | getDialog().dismiss();
84 | }
85 | }
86 | });
87 |
88 | cancelButton.setOnClickListener(new View.OnClickListener() {
89 | @Override
90 | public void onClick(View view) {
91 | getDialog().dismiss();
92 | }
93 | });
94 |
95 |
96 | return view;
97 | }
98 |
99 | @Override
100 | public void onStart() {
101 | super.onStart();
102 | Dialog dialog = getDialog();
103 | if (dialog != null) {
104 | int width = ViewGroup.LayoutParams.MATCH_PARENT;
105 | int height = ViewGroup.LayoutParams.WRAP_CONTENT;
106 | //noinspection ConstantConditions
107 | dialog.getWindow().setLayout(width, height);
108 | }
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/CreateStudent/StudentCreateListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.CreateStudent;
2 |
3 | public interface StudentCreateListener {
4 | void onStudentCreated(Student student);
5 | }
6 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/ShowStudentList/CustomViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.ShowStudentList;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.hellohasan.sqlite_project.R;
9 |
10 | public class CustomViewHolder extends RecyclerView.ViewHolder {
11 |
12 | TextView nameTextView;
13 | TextView registrationNumTextView;
14 | TextView emailTextView;
15 | TextView phoneTextView;
16 | ImageView crossButtonImageView;
17 | ImageView editButtonImageView;
18 |
19 | public CustomViewHolder(View itemView) {
20 | super(itemView);
21 |
22 | nameTextView = itemView.findViewById(R.id.nameTextView);
23 | registrationNumTextView = itemView.findViewById(R.id.registrationNumTextView);
24 | emailTextView = itemView.findViewById(R.id.emailTextView);
25 | phoneTextView = itemView.findViewById(R.id.phoneTextView);
26 | crossButtonImageView = itemView.findViewById(R.id.crossImageView);
27 | editButtonImageView = itemView.findViewById(R.id.editImageView);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/UpdateStudentInfo/StudentUpdateListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.UpdateStudentInfo;
2 |
3 | import com.hellohasan.sqlite_project.Features.CreateStudent.Student;
4 |
5 | public interface StudentUpdateListener {
6 | void onStudentInfoUpdated(Student student, int position);
7 | }
8 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Util/Config.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Util;
2 |
3 | public class Config {
4 |
5 | public static final String DATABASE_NAME = "student-db";
6 |
7 | //column names of student table
8 | public static final String TABLE_STUDENT = "student";
9 | public static final String COLUMN_STUDENT_ID = "_id";
10 | public static final String COLUMN_STUDENT_NAME = "name";
11 | public static final String COLUMN_STUDENT_REGISTRATION = "registration_no";
12 | public static final String COLUMN_STUDENT_PHONE = "phone";
13 | public static final String COLUMN_STUDENT_EMAIL = "email";
14 |
15 | //others for general purpose key-value pair data
16 | public static final String TITLE = "title";
17 | public static final String CREATE_STUDENT = "create_student";
18 | public static final String UPDATE_STUDENT = "update_student";
19 | }
20 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/drawable-xxhdpi/ic_add_subject.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/drawable-xxhdpi/ic_add_subject.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/ic_delete_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/ic_delete_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/ic_mode_edit_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/ic_mode_edit_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/ic_person_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-hdpi/ic_person_add_white_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-mdpi/ic_delete_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-mdpi/ic_delete_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-mdpi/ic_mode_edit_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-mdpi/ic_mode_edit_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-mdpi/ic_person_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-mdpi/ic_person_add_white_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xhdpi/ic_delete_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xhdpi/ic_delete_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xhdpi/ic_mode_edit_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xhdpi/ic_mode_edit_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xhdpi/ic_person_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xhdpi/ic_person_add_white_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxhdpi/ic_delete_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxhdpi/ic_delete_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxhdpi/ic_mode_edit_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxhdpi/ic_mode_edit_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxhdpi/ic_person_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxhdpi/ic_person_add_white_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxxhdpi/ic_delete_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxxhdpi/ic_delete_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxxhdpi/ic_mode_edit_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxxhdpi/ic_mode_edit_black_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxxhdpi/ic_person_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable-xxxhdpi/ic_person_add_white_24dp.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/drawable/ic_delete_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/layout/activity_student_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
19 |
20 |
21 |
22 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/layout/fragment_student_create_dialog.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
38 |
39 |
48 |
49 |
57 |
58 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/layout/fragment_student_update_dialog.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
38 |
39 |
48 |
49 |
57 |
58 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/layout/student_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
26 |
27 |
35 |
36 |
44 |
45 |
53 |
54 |
62 |
63 |
71 |
72 |
80 |
81 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #efeaeaea
7 | #ffffff
8 |
9 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SQLite-Single-Table-CRUD
3 | Settings
4 |
5 |
6 | Hello blank fragment
7 | CreateSubjectActivity
8 | Registration No
9 | Email
10 | Phone
11 | Delete student from SQLite database
12 | Student List is Empty!
13 | Student Name
14 | Update
15 | Cancel
16 | Create
17 | All Delete
18 | Edit Single student information
19 |
20 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/app/src/test/java/com/hellohasan/sqlite_project/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.1'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/01.SQLite-Single-Table-CRUD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 31 11:10:54 BDT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/01.SQLite-Single-Table-CRUD/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.hellohasan.sqlite_project"
7 | minSdkVersion 19
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | vectorDrawables.useSupportLibrary = true
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | implementation 'androidx.appcompat:appcompat:1.1.0'
28 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
29 | implementation 'com.google.android.material:material:1.0.0'
30 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
31 | implementation 'com.orhanobut:logger:2.2.0'
32 | implementation 'androidx.cardview:cardview:1.0.0'
33 | implementation 'androidx.recyclerview:recyclerview:1.0.0'
34 | testImplementation 'junit:junit:4.12'
35 | }
36 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/hasan/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/androidTest/java/com/hellohasan/sqlite_project/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hellohasan.sqlite_project", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Database/DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Database;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | import com.hellohasan.sqlite_project.Util.Config;
8 | import com.orhanobut.logger.AndroidLogAdapter;
9 | import com.orhanobut.logger.Logger;
10 |
11 | public class DatabaseHelper extends SQLiteOpenHelper {
12 |
13 | private static DatabaseHelper databaseHelper;
14 |
15 | // All Static variables
16 | private static final int DATABASE_VERSION = 1;
17 |
18 | // Database Name
19 | private static final String DATABASE_NAME = Config.DATABASE_NAME;
20 |
21 | // Constructor
22 | private DatabaseHelper(Context context) {
23 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
24 | Logger.addLogAdapter(new AndroidLogAdapter());
25 | }
26 |
27 | public static DatabaseHelper getInstance(Context context) {
28 | if(databaseHelper==null){
29 | synchronized (DatabaseHelper.class) {
30 | if(databaseHelper==null)
31 | databaseHelper = new DatabaseHelper(context);
32 | }
33 | }
34 | return databaseHelper;
35 | }
36 |
37 | @Override
38 | public void onCreate(SQLiteDatabase db) {
39 |
40 | // Create tables SQL execution
41 | String CREATE_STUDENT_TABLE = "CREATE TABLE " + Config.TABLE_STUDENT + "("
42 | + Config.COLUMN_STUDENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
43 | + Config.COLUMN_STUDENT_NAME + " TEXT NOT NULL, "
44 | + Config.COLUMN_STUDENT_REGISTRATION + " INTEGER NOT NULL UNIQUE, "
45 | + Config.COLUMN_STUDENT_PHONE + " TEXT, " //nullable
46 | + Config.COLUMN_STUDENT_EMAIL + " TEXT " //nullable
47 | + ")";
48 |
49 | String CREATE_SUBJECT_TABLE = "CREATE TABLE " + Config.TABLE_SUBJECT + "("
50 | + Config.COLUMN_SUBJECT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
51 | + Config.COLUMN_REGISTRATION_NUMBER + " INTEGER NOT NULL, "
52 | + Config.COLUMN_SUBJECT_NAME + " TEXT NOT NULL, "
53 | + Config.COLUMN_SUBJECT_CODE + " INTEGER NOT NULL, "
54 | + Config.COLUMN_SUBJECT_CREDIT + " REAL, " //nullable
55 | + "FOREIGN KEY (" + Config.COLUMN_REGISTRATION_NUMBER + ") REFERENCES " + Config.TABLE_STUDENT + "(" + Config.COLUMN_STUDENT_REGISTRATION + ") ON UPDATE CASCADE ON DELETE CASCADE, "
56 | + "CONSTRAINT " + Config.STUDENT_SUB_CONSTRAINT + " UNIQUE (" + Config.COLUMN_REGISTRATION_NUMBER + "," + Config.COLUMN_SUBJECT_CODE + ")"
57 | + ")";
58 |
59 | db.execSQL(CREATE_STUDENT_TABLE);
60 | db.execSQL(CREATE_SUBJECT_TABLE);
61 |
62 | Logger.d("DB created!");
63 | }
64 |
65 | @Override
66 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
67 | // Drop older table if existed
68 | db.execSQL("DROP TABLE IF EXISTS " + Config.TABLE_STUDENT);
69 | db.execSQL("DROP TABLE IF EXISTS " + Config.TABLE_SUBJECT);
70 |
71 | // Create tables again
72 | onCreate(db);
73 | }
74 |
75 | @Override
76 | public void onOpen(SQLiteDatabase db) {
77 | super.onOpen(db);
78 |
79 | //enable foreign key constraints like ON UPDATE CASCADE, ON DELETE CASCADE
80 | db.execSQL("PRAGMA foreign_keys=ON;");
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/StudentCRUD/CreateStudent/Student.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.StudentCRUD.CreateStudent;
2 |
3 | public class Student {
4 | private long id;
5 | private String name;
6 | private long registrationNumber;
7 | private String phoneNumber;
8 | private String email;
9 |
10 | public Student(int id, String name, long registrationNumber, String phoneNumber, String email) {
11 | this.id = id;
12 | this.name = name;
13 | this.registrationNumber = registrationNumber;
14 | this.phoneNumber = phoneNumber;
15 | this.email = email;
16 | }
17 |
18 | public long getId() {
19 | return id;
20 | }
21 |
22 | public void setId(long id) {
23 | this.id = id;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | public long getRegistrationNumber() {
35 | return registrationNumber;
36 | }
37 |
38 | public void setRegistrationNumber(long registrationNumber) {
39 | this.registrationNumber = registrationNumber;
40 | }
41 |
42 | public String getPhoneNumber() {
43 | return phoneNumber;
44 | }
45 |
46 | public void setPhoneNumber(String phoneNumber) {
47 | this.phoneNumber = phoneNumber;
48 | }
49 |
50 | public String getEmail() {
51 | return email;
52 | }
53 |
54 | public void setEmail(String email) {
55 | this.email = email;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/StudentCRUD/CreateStudent/StudentCreateDialogFragment.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.StudentCRUD.CreateStudent;
2 |
3 | import android.app.Dialog;
4 | import android.os.Bundle;
5 | import androidx.fragment.app.DialogFragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 |
12 | import com.hellohasan.sqlite_project.Util.Config;
13 | import com.hellohasan.sqlite_project.Database.DatabaseQueryClass;
14 | import com.hellohasan.sqlite_project.R;
15 |
16 |
17 | public class StudentCreateDialogFragment extends DialogFragment {
18 |
19 | private static StudentCreateListener studentCreateListener;
20 |
21 | private EditText nameEditText;
22 | private EditText registrationEditText;
23 | private EditText phoneEditText;
24 | private EditText emailEditText;
25 | private Button createButton;
26 | private Button cancelButton;
27 |
28 | private String nameString = "";
29 | private long registrationNumber = -1;
30 | private String phoneString = "";
31 | private String emailString = "";
32 |
33 | public StudentCreateDialogFragment() {
34 | // Required empty public constructor
35 | }
36 |
37 | public static StudentCreateDialogFragment newInstance(String title, StudentCreateListener listener){
38 | studentCreateListener = listener;
39 | StudentCreateDialogFragment studentCreateDialogFragment = new StudentCreateDialogFragment();
40 | Bundle args = new Bundle();
41 | args.putString("title", title);
42 | studentCreateDialogFragment.setArguments(args);
43 |
44 | studentCreateDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);
45 |
46 | return studentCreateDialogFragment;
47 | }
48 |
49 |
50 | @Override
51 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
52 | Bundle savedInstanceState) {
53 |
54 | View view = inflater.inflate(R.layout.fragment_student_create_dialog, container, false);
55 |
56 | nameEditText = view.findViewById(R.id.studentNameEditText);
57 | registrationEditText = view.findViewById(R.id.registrationEditText);
58 | phoneEditText = view.findViewById(R.id.phoneEditText);
59 | emailEditText = view.findViewById(R.id.emailEditText);
60 | createButton = view.findViewById(R.id.createButton);
61 | cancelButton = view.findViewById(R.id.cancelButton);
62 |
63 | String title = getArguments().getString(Config.TITLE);
64 | getDialog().setTitle(title);
65 |
66 | createButton.setOnClickListener(new View.OnClickListener() {
67 | @Override
68 | public void onClick(View view) {
69 | nameString = nameEditText.getText().toString();
70 | registrationNumber = Integer.parseInt(registrationEditText.getText().toString());
71 | phoneString = phoneEditText.getText().toString();
72 | emailString = emailEditText.getText().toString();
73 |
74 | Student student = new Student(-1, nameString, registrationNumber, phoneString, emailString);
75 |
76 | DatabaseQueryClass databaseQueryClass = new DatabaseQueryClass(getContext());
77 |
78 | long id = databaseQueryClass.insertStudent(student);
79 |
80 | if(id>0){
81 | student.setId(id);
82 | studentCreateListener.onStudentCreated(student);
83 | getDialog().dismiss();
84 | }
85 | }
86 | });
87 |
88 | cancelButton.setOnClickListener(new View.OnClickListener() {
89 | @Override
90 | public void onClick(View view) {
91 | getDialog().dismiss();
92 | }
93 | });
94 |
95 | return view;
96 | }
97 |
98 | @Override
99 | public void onStart() {
100 | super.onStart();
101 | Dialog dialog = getDialog();
102 | if (dialog != null) {
103 | int width = ViewGroup.LayoutParams.MATCH_PARENT;
104 | int height = ViewGroup.LayoutParams.WRAP_CONTENT;
105 | //noinspection ConstantConditions
106 | dialog.getWindow().setLayout(width, height);
107 | }
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/StudentCRUD/CreateStudent/StudentCreateListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.StudentCRUD.CreateStudent;
2 |
3 | public interface StudentCreateListener {
4 | void onStudentCreated(Student student);
5 | }
6 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/StudentCRUD/ShowStudentList/CustomViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.StudentCRUD.ShowStudentList;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.hellohasan.sqlite_project.R;
9 |
10 | public class CustomViewHolder extends RecyclerView.ViewHolder {
11 |
12 | TextView nameTextView;
13 | TextView registrationNumTextView;
14 | TextView emailTextView;
15 | TextView phoneTextView;
16 | ImageView crossButtonImageView;
17 | ImageView editButtonImageView;
18 |
19 | public CustomViewHolder(View itemView) {
20 | super(itemView);
21 |
22 | nameTextView = itemView.findViewById(R.id.nameTextView);
23 | registrationNumTextView = itemView.findViewById(R.id.registrationNumTextView);
24 | emailTextView = itemView.findViewById(R.id.emailTextView);
25 | phoneTextView = itemView.findViewById(R.id.phoneTextView);
26 | crossButtonImageView = itemView.findViewById(R.id.crossImageView);
27 | editButtonImageView = itemView.findViewById(R.id.editImageView);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/StudentCRUD/UpdateStudentInfo/StudentUpdateListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.StudentCRUD.UpdateStudentInfo;
2 |
3 | import com.hellohasan.sqlite_project.Features.StudentCRUD.CreateStudent.Student;
4 |
5 | public interface StudentUpdateListener {
6 | void onStudentInfoUpdated(Student student, int position);
7 | }
8 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/SubjectCRUD/CreateSubject/Subject.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.SubjectCRUD.CreateSubject;
2 |
3 | public class Subject {
4 | private long id;
5 | private String name;
6 | private int code;
7 | private double credit;
8 |
9 | public Subject(long id, String name, int code, double credit) {
10 | this.id = id;
11 | this.name = name;
12 | this.code = code;
13 | this.credit = credit;
14 | }
15 |
16 | public long getId() {
17 | return id;
18 | }
19 |
20 | public void setId(long id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public int getCode() {
33 | return code;
34 | }
35 |
36 | public void setCode(int code) {
37 | this.code = code;
38 | }
39 |
40 | public double getCredit() {
41 | return credit;
42 | }
43 |
44 | public void setCredit(double credit) {
45 | this.credit = credit;
46 | }
47 | }
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/SubjectCRUD/CreateSubject/SubjectCreateDialogFragment.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.SubjectCRUD.CreateSubject;
2 |
3 |
4 | import android.app.Dialog;
5 | import android.os.Bundle;
6 | import androidx.fragment.app.DialogFragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 |
13 | import com.hellohasan.sqlite_project.Database.DatabaseQueryClass;
14 | import com.hellohasan.sqlite_project.R;
15 |
16 |
17 | public class SubjectCreateDialogFragment extends DialogFragment {
18 |
19 | private static long studentRegistrationNumber;
20 | private static SubjectCreateListener subjectCreateListener;
21 |
22 | private EditText subjectNameEditText;
23 | private EditText subjectCodeEditText;
24 | private EditText subjectCreditEditText;
25 | private Button createButton;
26 | private Button cancelButton;
27 |
28 | public SubjectCreateDialogFragment() {
29 | // Required empty public constructor
30 | }
31 |
32 | public static SubjectCreateDialogFragment newInstance(long studentRegNo, SubjectCreateListener listener){
33 | studentRegistrationNumber = studentRegNo;
34 | subjectCreateListener = listener;
35 |
36 | SubjectCreateDialogFragment subjectCreateDialogFragment = new SubjectCreateDialogFragment();
37 |
38 | subjectCreateDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);
39 |
40 | return subjectCreateDialogFragment;
41 | }
42 |
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
45 | Bundle savedInstanceState) {
46 | View view = inflater.inflate(R.layout.fragment_subject_create_dialog, container, false);
47 | getDialog().setTitle(getResources().getString(R.string.add_new_subject));
48 |
49 | subjectNameEditText = view.findViewById(R.id.subjectNameEditText);
50 | subjectCodeEditText = view.findViewById(R.id.subjectCodeEditText);
51 | subjectCreditEditText = view.findViewById(R.id.subjectCreditEditText);
52 | createButton = view.findViewById(R.id.createButton);
53 | cancelButton = view.findViewById(R.id.cancelButton);
54 |
55 | createButton.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View view) {
58 | String subjectName = subjectNameEditText.getText().toString();
59 | int subjectCode = Integer.parseInt(subjectCodeEditText.getText().toString());
60 | double subjectCredit = Double.parseDouble(subjectCreditEditText.getText().toString());
61 |
62 | Subject subject = new Subject(-1, subjectName, subjectCode, subjectCredit);
63 |
64 | DatabaseQueryClass databaseQueryClass = new DatabaseQueryClass(getContext());
65 |
66 | long id = databaseQueryClass.insertSubject(subject, studentRegistrationNumber);
67 |
68 | if(id>0){
69 | subject.setId(id);
70 | subjectCreateListener.onSubjectCreated(subject);
71 | getDialog().dismiss();
72 | }
73 | }
74 | });
75 |
76 | cancelButton.setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View view) {
79 | getDialog().dismiss();
80 | }
81 | });
82 |
83 | return view;
84 | }
85 |
86 | @Override
87 | public void onStart() {
88 | super.onStart();
89 | Dialog dialog = getDialog();
90 | if (dialog != null) {
91 | int width = ViewGroup.LayoutParams.MATCH_PARENT;
92 | int height = ViewGroup.LayoutParams.WRAP_CONTENT;
93 | //noinspection ConstantConditions
94 | dialog.getWindow().setLayout(width, height);
95 | }
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/SubjectCRUD/CreateSubject/SubjectCreateListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.SubjectCRUD.CreateSubject;
2 |
3 | public interface SubjectCreateListener {
4 | void onSubjectCreated(Subject subject);
5 | }
6 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/SubjectCRUD/ShowSubjectList/CustomViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.SubjectCRUD.ShowSubjectList;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.hellohasan.sqlite_project.R;
9 |
10 | public class CustomViewHolder extends RecyclerView.ViewHolder {
11 |
12 | TextView subjectNameTextView;
13 | TextView subjectCodeTextView;
14 | TextView subjectCreditTextView;
15 | ImageView crossButtonImageView;
16 | ImageView editButtonImageView;
17 |
18 | public CustomViewHolder(View itemView) {
19 | super(itemView);
20 |
21 | subjectNameTextView = itemView.findViewById(R.id.subjectNameTextView);
22 | subjectCodeTextView = itemView.findViewById(R.id.subjectCodeTextView);
23 | subjectCreditTextView = itemView.findViewById(R.id.subjectCreditTextView);
24 | crossButtonImageView = itemView.findViewById(R.id.crossImageView);
25 | editButtonImageView = itemView.findViewById(R.id.editImageView);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Features/SubjectCRUD/UpdateSubjectInfo/SubjectUpdateListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Features.SubjectCRUD.UpdateSubjectInfo;
2 |
3 | import com.hellohasan.sqlite_project.Features.SubjectCRUD.CreateSubject.Subject;
4 |
5 | public interface SubjectUpdateListener {
6 | void onSubjectInfoUpdate(Subject subject, int position);
7 | }
8 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_project/Util/Config.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project.Util;
2 |
3 | public class Config {
4 |
5 | public static final String DATABASE_NAME = "student-db";
6 |
7 | //column names of student table
8 | public static final String TABLE_STUDENT = "student";
9 | public static final String COLUMN_STUDENT_ID = "_id";
10 | public static final String COLUMN_STUDENT_NAME = "name";
11 | public static final String COLUMN_STUDENT_REGISTRATION = "registration_no";
12 | public static final String COLUMN_STUDENT_PHONE = "phone";
13 | public static final String COLUMN_STUDENT_EMAIL = "email";
14 |
15 | //column names of subject table
16 | public static final String TABLE_SUBJECT = "subject";
17 | public static final String COLUMN_SUBJECT_ID = "_id";
18 | public static final String COLUMN_REGISTRATION_NUMBER = "fk_registration_no";
19 | public static final String COLUMN_SUBJECT_NAME = "name";
20 | public static final String COLUMN_SUBJECT_CODE = "subject_code";
21 | public static final String COLUMN_SUBJECT_CREDIT = "credit";
22 | public static final String STUDENT_SUB_CONSTRAINT = "student_sub_unique";
23 |
24 | //others for general purpose key-value pair data
25 | public static final String TITLE = "title";
26 | public static final String CREATE_STUDENT = "create_student";
27 | public static final String UPDATE_STUDENT = "update_student";
28 | public static final String CREATE_SUBJECT = "create_subject";
29 | public static final String UPDATE_SUBJECT = "update_subject";
30 | public static final String STUDENT_REGISTRATION = "student_registration";
31 | }
32 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/drawable-hdpi/drawable-xxhdpi/ic_add_subject.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/drawable-hdpi/drawable-xxhdpi/ic_add_subject.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/drawable/ic_delete_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/drawable/ic_delete_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/drawable/ic_mode_edit_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/drawable/ic_person_add_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/drawable/ic_subject_add_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/activity_student_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/activity_subject_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
20 |
21 |
29 |
30 |
31 |
32 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/fragment_student_create_dialog.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
38 |
39 |
48 |
49 |
57 |
58 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/fragment_student_update_dialog.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
38 |
39 |
48 |
49 |
57 |
58 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/fragment_subject_create_dialog.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
38 |
39 |
47 |
48 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/fragment_subject_update_dialog.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
18 |
19 |
28 |
29 |
38 |
39 |
47 |
48 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/item_subject.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
25 |
26 |
37 |
38 |
47 |
48 |
56 |
57 |
66 |
67 |
75 |
76 |
85 |
86 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/layout/student_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
26 |
27 |
35 |
36 |
44 |
45 |
53 |
54 |
63 |
64 |
73 |
74 |
82 |
83 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #efeaeaea
7 | #ffffff
8 |
9 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SQLite-Multiple-Tables-CRUD
3 | Settings
4 | CreateSubjectActivity
5 | Registration No
6 | Email
7 | Phone
8 | Delete student from SQLite database
9 | List is Empty!
10 | Student Name
11 | Update
12 | Cancel
13 | Create
14 | All Delete
15 | Edit Single student information
16 | Subject Name
17 | Subject Code
18 | Subject Credit
19 | Add New Subject
20 | Student Information
21 | Name
22 | Registration Number:
23 | Subject List
24 | Student List
25 | Total Student: %1$d. Total Subject: %2$d
26 |
27 |
28 | Hello blank fragment
29 | Update
30 |
31 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/app/src/test/java/com/hellohasan/sqlite_project/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_project;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.1'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/02.SQLite-Multiple-(Two)-Tables-CRUD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 31 11:21:27 BDT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/02.SQLite-Multiple-(Two)-Tables-CRUD/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/README.md:
--------------------------------------------------------------------------------
1 | # Android SQLite Multiple (Three) Tables CRUD Tutorial
2 |
3 | We'll design this type of sample Android App using `SQLite` database to store data. Here I've created three tables `student`, `subject` and `student_subject`. Here `student_subject` is a pivot table. This table will store data which student is taken which subjects.
4 |
5 |
6 |
7 | You will find all of database related code in [this package](https://github.com/hasancse91/Android-SQLite-Tutorial/tree/master/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/database).
8 | Thare are some interfaces and their implementations. I tried to separate database related code from Activity.
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.hellohasan.sqlite_multiple_three_tables_crud"
7 | minSdkVersion 19
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | vectorDrawables.useSupportLibrary = true
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'androidx.appcompat:appcompat:1.1.0'
25 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
26 | implementation 'com.google.android.material:material:1.0.0'
27 | implementation 'androidx.cardview:cardview:1.0.0'
28 | implementation 'androidx.recyclerview:recyclerview:1.0.0'
29 | testImplementation 'junit:junit:4.12'
30 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
31 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
32 | implementation 'com.orhanobut:logger:2.2.0'
33 | }
34 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/androidTest/java/com/hellohasan/sqlite_multiple_three_tables_crud/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hellohasan.sqlite_multiple_three_tables_crud", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
29 |
33 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/database/DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.database;
2 |
3 | import android.database.sqlite.SQLiteDatabase;
4 | import android.database.sqlite.SQLiteOpenHelper;
5 |
6 | import com.hellohasan.sqlite_multiple_three_tables_crud.util.MyApp;
7 |
8 | import static com.hellohasan.sqlite_multiple_three_tables_crud.util.Constants.*;
9 |
10 | public class DatabaseHelper extends SQLiteOpenHelper {
11 |
12 | private static final String DATABASE_NAME = "student-db";
13 | private static final int DATABASE_VERSION = 1;
14 |
15 | private static DatabaseHelper databaseHelper;
16 |
17 | private DatabaseHelper() {
18 | super(MyApp.context, DATABASE_NAME, null, DATABASE_VERSION);
19 | }
20 |
21 | public static DatabaseHelper getInstance() {
22 |
23 | if (databaseHelper == null) {
24 | synchronized (DatabaseHelper.class){ //thread safe singleton
25 | if (databaseHelper == null)
26 | databaseHelper = new DatabaseHelper();
27 | }
28 | }
29 |
30 | return databaseHelper;
31 | }
32 |
33 | @Override
34 | public void onCreate(SQLiteDatabase sqLiteDatabase) {
35 |
36 | String CREATE_STUDENT_TABLE = "CREATE TABLE " + TABLE_STUDENT + "("
37 | + STUDENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
38 | + STUDENT_NAME + " TEXT NOT NULL, "
39 | + STUDENT_REGISTRATION_NUM + " INTEGER NOT NULL UNIQUE, "
40 | + STUDENT_PHONE + " TEXT, " //nullable
41 | + STUDENT_EMAIL + " TEXT " //nullable
42 | + ")";
43 |
44 | String CREATE_SUBJECT_TABLE = "CREATE TABLE " + TABLE_SUBJECT + "("
45 | + SUBJECT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
46 | + SUBJECT_NAME + " TEXT NOT NULL, "
47 | + SUBJECT_CODE + " INTEGER NOT NULL UNIQUE, "
48 | + SUBJECT_CREDIT + " REAL" //nullable
49 | + ")";
50 |
51 | String CREATE_TAKEN_SUBJECT_TABLE = "CREATE TABLE " + TABLE_STUDENT_SUBJECT + "("
52 | + STUDENT_ID_FK + " INTEGER NOT NULL, "
53 | + SUBJECT_ID_FK + " INTEGER NOT NULL, "
54 | + "FOREIGN KEY (" + STUDENT_ID_FK + ") REFERENCES " + TABLE_STUDENT + "(" + STUDENT_ID + ") ON UPDATE CASCADE ON DELETE CASCADE, "
55 | + "FOREIGN KEY (" + SUBJECT_ID_FK + ") REFERENCES " + TABLE_SUBJECT + "(" + SUBJECT_ID + ") ON UPDATE CASCADE ON DELETE CASCADE, "
56 | + "CONSTRAINT " + STUDENT_SUB_CONSTRAINT + " UNIQUE (" + STUDENT_ID_FK + "," + SUBJECT_ID_FK + ")"
57 | + ")";
58 |
59 | sqLiteDatabase.execSQL(CREATE_STUDENT_TABLE);
60 | sqLiteDatabase.execSQL(CREATE_SUBJECT_TABLE);
61 | sqLiteDatabase.execSQL(CREATE_TAKEN_SUBJECT_TABLE);
62 | }
63 |
64 | @Override
65 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
66 | // Drop older table if existed
67 | sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_STUDENT);
68 | sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_SUBJECT);
69 | sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_STUDENT_SUBJECT);
70 |
71 | // Create tables again
72 | onCreate(sqLiteDatabase);
73 | }
74 |
75 | @Override
76 | public void onOpen(SQLiteDatabase db) {
77 | super.onOpen(db);
78 |
79 | //enable foreign key constraints like ON UPDATE CASCADE, ON DELETE CASCADE
80 | db.execSQL("PRAGMA foreign_keys=ON;");
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/database/QueryContract.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.database;
2 |
3 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.Student;
4 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.Subject;
5 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.TableRowCount;
6 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.TakenSubject;
7 |
8 | import java.util.List;
9 |
10 | public class QueryContract {
11 |
12 | public interface StudentQuery {
13 | void createStudent(Student student, QueryResponse response);
14 | void readStudent(int studentId, QueryResponse response);
15 | void readAllStudent(QueryResponse> response);
16 | void updateStudent(Student student, QueryResponse response);
17 | void deleteStudent(int studentId, QueryResponse response);
18 | }
19 |
20 | public interface SubjectQuery {
21 | void createSubject(Subject subject, QueryResponse response);
22 | void readAllSubject(QueryResponse> response);
23 | void updateSubject(Subject subject, QueryResponse response);
24 | void deleteSubject(int subjectId, QueryResponse response);
25 | }
26 |
27 | public interface TakenSubjectQuery {
28 | void createTakenSubject(int studentId, int subjectId, QueryResponse response);
29 | void readAllTakenSubjectByStudentId(int studentId, QueryResponse> response);
30 | void readAllSubjectWithTakenStatus(int studentId, QueryResponse> response);
31 | void deleteTakenSubject(int studentId, int subjectId, QueryResponse response);
32 | }
33 |
34 | public interface TableRowCountQuery {
35 | void getTableRowCount(QueryResponse response);
36 | }
37 | }
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/database/QueryResponse.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.database;
2 |
3 | public interface QueryResponse {
4 | void onSuccess(T data);
5 | void onFailure(String message);
6 | }
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/database/TableRowCountQueryImplementation.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.database;
2 |
3 | import android.database.DatabaseUtils;
4 | import android.database.sqlite.SQLiteDatabase;
5 |
6 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.TableRowCount;
7 |
8 | import static com.hellohasan.sqlite_multiple_three_tables_crud.util.Constants.*;
9 |
10 | public class TableRowCountQueryImplementation implements QueryContract.TableRowCountQuery {
11 |
12 | @Override
13 | public void getTableRowCount(QueryResponse response) {
14 | DatabaseHelper databaseHelper = DatabaseHelper.getInstance();
15 | SQLiteDatabase sqLiteDatabase = databaseHelper.getReadableDatabase();
16 |
17 | try {
18 | long studentCount = DatabaseUtils.queryNumEntries(sqLiteDatabase, TABLE_STUDENT);
19 | long subjectCount = DatabaseUtils.queryNumEntries(sqLiteDatabase, TABLE_SUBJECT);
20 | long takenSubjectCount = DatabaseUtils.queryNumEntries(sqLiteDatabase, TABLE_STUDENT_SUBJECT);
21 |
22 | TableRowCount tableRowCount = new TableRowCount(studentCount, subjectCount, takenSubjectCount);
23 | response.onSuccess(tableRowCount);
24 |
25 | } catch (Exception e){
26 | response.onFailure(e.getMessage());
27 | } finally {
28 | sqLiteDatabase.close();
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/student_crud/StudentCrudListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.student_crud;
2 |
3 | public interface StudentCrudListener {
4 | void onStudentListUpdate(boolean isUpdated);
5 | }
6 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/student_crud/student_list_show/StudentViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.student_crud.student_list_show;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.hellohasan.sqlite_multiple_three_tables_crud.R;
9 |
10 | class StudentViewHolder extends RecyclerView.ViewHolder {
11 |
12 | TextView nameTextView;
13 | TextView registrationNumTextView;
14 | TextView emailTextView;
15 | TextView phoneTextView;
16 | ImageView editImageView;
17 | ImageView deleteImageView;
18 |
19 | StudentViewHolder(View itemView) {
20 | super(itemView);
21 | nameTextView = itemView.findViewById(R.id.nameTextView);
22 | registrationNumTextView = itemView.findViewById(R.id.registrationNumTextView);
23 | emailTextView = itemView.findViewById(R.id.emailTextView);
24 | phoneTextView = itemView.findViewById(R.id.phoneTextView);
25 | editImageView = itemView.findViewById(R.id.editImageView);
26 | deleteImageView = itemView.findViewById(R.id.deleteImageView);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/subject_crud/SubjectCrudListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.subject_crud;
2 |
3 | public interface SubjectCrudListener {
4 | void onSubjectListUpdate(boolean isUpdate);
5 | }
6 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/subject_crud/subject_list_show/SubjectViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.subject_crud.subject_list_show;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.hellohasan.sqlite_multiple_three_tables_crud.R;
9 |
10 | public class SubjectViewHolder extends RecyclerView.ViewHolder {
11 |
12 | TextView subjectNameTextView;
13 | TextView courseCodeTextView;
14 | TextView creditTextView;
15 | ImageView editIcon;
16 | ImageView deleteIcon;
17 |
18 | public SubjectViewHolder(View itemView) {
19 | super(itemView);
20 |
21 | subjectNameTextView = itemView.findViewById(R.id.subjectNameTextView);
22 | courseCodeTextView = itemView.findViewById(R.id.courseCodeTextView);
23 | creditTextView = itemView.findViewById(R.id.creditTextView);
24 | editIcon = itemView.findViewById(R.id.editIcon);
25 | deleteIcon = itemView.findViewById(R.id.deleteIcon);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/taken_subject_crud/TakenSubjectCrudListener.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.taken_subject_crud;
2 |
3 | public interface TakenSubjectCrudListener {
4 | void onTakenSubjectUpdated(boolean isUpdated);
5 | }
6 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/taken_subject_crud/subject_assign/SubjectAssignActivity.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.taken_subject_crud.subject_assign;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import androidx.recyclerview.widget.LinearLayoutManager;
6 | import androidx.recyclerview.widget.RecyclerView;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.hellohasan.sqlite_multiple_three_tables_crud.R;
12 | import com.hellohasan.sqlite_multiple_three_tables_crud.database.*;
13 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.TakenSubject;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import static com.hellohasan.sqlite_multiple_three_tables_crud.util.Constants.STUDENT_ID;
19 |
20 | public class SubjectAssignActivity extends AppCompatActivity {
21 |
22 | private RecyclerView recyclerView;
23 | private TextView noDataFoundTextView;
24 |
25 | private List takenSubjectList = new ArrayList<>();
26 | private SubjectAssignListAdapter adapter;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_subject_assign);
32 | getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
33 |
34 | recyclerView = findViewById(R.id.recyclerView);
35 | noDataFoundTextView = findViewById(R.id.noDataFoundTextView);
36 |
37 | int studentId = getIntent().getIntExtra(STUDENT_ID, -1);
38 |
39 | adapter = new SubjectAssignListAdapter(this, studentId, takenSubjectList);
40 | recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
41 | recyclerView.setAdapter(adapter);
42 |
43 | QueryContract.TakenSubjectQuery query = new TakenSubjectQueryImplementation();
44 | query.readAllSubjectWithTakenStatus(studentId, new QueryResponse>() {
45 | @Override
46 | public void onSuccess(List data) {
47 | recyclerView.setVisibility(View.VISIBLE);
48 | noDataFoundTextView.setVisibility(View.GONE);
49 |
50 | takenSubjectList.clear();
51 | takenSubjectList.addAll(data);
52 | adapter.notifyDataSetChanged();
53 | }
54 |
55 | @Override
56 | public void onFailure(String message) {
57 | recyclerView.setVisibility(View.GONE);
58 | noDataFoundTextView.setVisibility(View.VISIBLE);
59 | }
60 | });
61 |
62 | }
63 |
64 | public void closeActivity(View view) {
65 | finish();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/taken_subject_crud/subject_assign/SubjectAssignListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.taken_subject_crud.subject_assign;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.NonNull;
5 | import androidx.recyclerview.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.CompoundButton;
10 | import android.widget.Toast;
11 |
12 | import com.hellohasan.sqlite_multiple_three_tables_crud.R;
13 | import com.hellohasan.sqlite_multiple_three_tables_crud.database.*;
14 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.TakenSubject;
15 |
16 | import java.util.List;
17 |
18 | public class SubjectAssignListAdapter extends RecyclerView.Adapter {
19 |
20 | private Context context;
21 | private int studentId;
22 | private List takenSubjectList;
23 |
24 | public SubjectAssignListAdapter(Context context, int studentId, List takenSubjectList) {
25 | this.context = context;
26 | this.studentId = studentId;
27 | this.takenSubjectList = takenSubjectList;
28 | }
29 |
30 | @NonNull
31 | @Override
32 | public SubjectAssignViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
33 | View view = LayoutInflater.from(context).inflate(R.layout.item_subject_assign, parent, false);
34 | return new SubjectAssignViewHolder(view);
35 | }
36 |
37 | @Override
38 | public void onBindViewHolder(@NonNull SubjectAssignViewHolder holder, int position) {
39 | final TakenSubject subject = takenSubjectList.get(position);
40 |
41 | holder.subjectNameTextView.setText(subject.getName());
42 | holder.courseCodeTextView.setText(context.getString(R.string.course_code, subject.getCode()));
43 | holder.creditTextView.setText(context.getString(R.string.course_credit, subject.getCredit()));
44 | holder.checkBox.setChecked(subject.isTaken());
45 |
46 | holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
47 | @Override
48 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
49 | if (isChecked)
50 | assignSubject(subject.getId());
51 | else
52 | removeAssignedSubject(subject.getId());
53 | }
54 | });
55 | }
56 |
57 | @Override
58 | public int getItemCount() {
59 | return takenSubjectList.size();
60 | }
61 |
62 | private void assignSubject(int subjectId) {
63 | QueryContract.TakenSubjectQuery query = new TakenSubjectQueryImplementation();
64 | query.createTakenSubject(studentId, subjectId, new QueryResponse() {
65 | @Override
66 | public void onSuccess(Boolean data) {
67 | // We did nothing here. because we don't need to update (set checked) CheckBox manually
68 | // CheckBox is updated by default after clicking on it
69 | }
70 |
71 | @Override
72 | public void onFailure(String message) {
73 | Toast.makeText(context, message, Toast.LENGTH_LONG).show();
74 | }
75 | });
76 | }
77 |
78 | private void removeAssignedSubject(int subjectId) {
79 | QueryContract.TakenSubjectQuery query = new TakenSubjectQueryImplementation();
80 | query.deleteTakenSubject(studentId, subjectId, new QueryResponse() {
81 | @Override
82 | public void onSuccess(Boolean data) {
83 | // We did nothing here. because we don't need to update (set unchecked) CheckBox manually
84 | // CheckBox is updated by default after clicking on it
85 | }
86 |
87 | @Override
88 | public void onFailure(String message) {
89 | Toast.makeText(context, message, Toast.LENGTH_LONG).show();
90 | }
91 | });
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/taken_subject_crud/subject_assign/SubjectAssignViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.taken_subject_crud.subject_assign;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.CheckBox;
6 | import android.widget.TextView;
7 |
8 | import com.hellohasan.sqlite_multiple_three_tables_crud.R;
9 |
10 | public class SubjectAssignViewHolder extends RecyclerView.ViewHolder {
11 |
12 | CheckBox checkBox;
13 | TextView subjectNameTextView;
14 | TextView courseCodeTextView;
15 | TextView creditTextView;
16 |
17 | public SubjectAssignViewHolder(View itemView) {
18 | super(itemView);
19 | checkBox = itemView.findViewById(R.id.checkbox);
20 | subjectNameTextView = itemView.findViewById(R.id.subjectNameTextView);
21 | courseCodeTextView = itemView.findViewById(R.id.courseCodeTextView);
22 | creditTextView = itemView.findViewById(R.id.creditTextView);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/taken_subject_crud/taken_subject_show/TakenSubjectListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.taken_subject_crud.taken_subject_show;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.NonNull;
5 | import androidx.recyclerview.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Toast;
10 |
11 | import com.hellohasan.sqlite_multiple_three_tables_crud.R;
12 | import com.hellohasan.sqlite_multiple_three_tables_crud.database.QueryContract;
13 | import com.hellohasan.sqlite_multiple_three_tables_crud.database.QueryResponse;
14 | import com.hellohasan.sqlite_multiple_three_tables_crud.database.TakenSubjectQueryImplementation;
15 | import com.hellohasan.sqlite_multiple_three_tables_crud.features.taken_subject_crud.TakenSubjectCrudListener;
16 | import com.hellohasan.sqlite_multiple_three_tables_crud.model.Subject;
17 |
18 | import java.util.List;
19 |
20 | public class TakenSubjectListAdapter extends RecyclerView.Adapter {
21 |
22 | private Context context;
23 | private int studentId;
24 | private List subjectList;
25 | private TakenSubjectCrudListener listener;
26 |
27 | public TakenSubjectListAdapter(Context context, int studentId, List subjectList, TakenSubjectCrudListener listener) {
28 | this.context = context;
29 | this.studentId = studentId;
30 | this.subjectList = subjectList;
31 | this.listener = listener;
32 | }
33 |
34 | @NonNull
35 | @Override
36 | public TakenSubjectViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
37 | View view = LayoutInflater.from(context).inflate(R.layout.item_taken_subject, parent, false);
38 | return new TakenSubjectViewHolder(view);
39 | }
40 |
41 | @Override
42 | public void onBindViewHolder(@NonNull TakenSubjectViewHolder holder, int position) {
43 | final int itemPos = position;
44 | final Subject subject = subjectList.get(position);
45 |
46 | holder.subjectNameTextView.setText(subject.getName());
47 | holder.courseCodeTextView.setText(context.getString(R.string.course_code, subject.getCode()));
48 | holder.creditTextView.setText(context.getString(R.string.course_credit, subject.getCredit()));
49 |
50 | holder.deleteIcon.setOnClickListener(new View.OnClickListener() {
51 | @Override
52 | public void onClick(View v) {
53 | removeAssignedSubject(subject.getId(), itemPos);
54 | }
55 | });
56 | }
57 |
58 | @Override
59 | public int getItemCount() {
60 | return subjectList.size();
61 | }
62 |
63 | private void removeAssignedSubject(int subjectId, final int itemPosition) {
64 | QueryContract.TakenSubjectQuery query = new TakenSubjectQueryImplementation();
65 | query.deleteTakenSubject(studentId, subjectId, new QueryResponse() {
66 | @Override
67 | public void onSuccess(Boolean data) {
68 | if(data){
69 | subjectList.remove(itemPosition);
70 | notifyDataSetChanged();
71 | listener.onTakenSubjectUpdated(true);
72 | } else
73 | Toast.makeText(context, "Failed to remove subject", Toast.LENGTH_LONG).show();
74 | }
75 |
76 | @Override
77 | public void onFailure(String message) {
78 | Toast.makeText(context, message, Toast.LENGTH_LONG).show();
79 | }
80 | });
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/features/taken_subject_crud/taken_subject_show/TakenSubjectViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.features.taken_subject_crud.taken_subject_show;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 | import android.widget.TextView;
7 |
8 | import com.hellohasan.sqlite_multiple_three_tables_crud.R;
9 |
10 | class TakenSubjectViewHolder extends RecyclerView.ViewHolder {
11 |
12 | TextView subjectNameTextView;
13 | TextView courseCodeTextView;
14 | TextView creditTextView;
15 | ImageView deleteIcon;
16 |
17 | public TakenSubjectViewHolder(View itemView) {
18 | super(itemView);
19 |
20 | subjectNameTextView = itemView.findViewById(R.id.subjectNameTextView);
21 | courseCodeTextView = itemView.findViewById(R.id.courseCodeTextView);
22 | creditTextView = itemView.findViewById(R.id.creditTextView);
23 | deleteIcon = itemView.findViewById(R.id.deleteIcon);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/model/Student.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.model;
2 |
3 | public class Student {
4 | private int id;
5 | private String name;
6 | private long registrationNumber;
7 | private String phone;
8 | private String email;
9 |
10 | public Student(int id, String name, long registrationNumber, String phone, String email) {
11 | this.id = id;
12 | this.name = name;
13 | this.registrationNumber = registrationNumber;
14 | this.phone = phone;
15 | this.email = email;
16 | }
17 |
18 | public int getId() {
19 | return id;
20 | }
21 |
22 | public void setId(int id) {
23 | this.id = id;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | public long getRegistrationNumber() {
35 | return registrationNumber;
36 | }
37 |
38 | public void setRegistrationNumber(long registrationNumber) {
39 | this.registrationNumber = registrationNumber;
40 | }
41 |
42 | public String getPhone() {
43 | return phone;
44 | }
45 |
46 | public void setPhone(String phone) {
47 | this.phone = phone;
48 | }
49 |
50 | public String getEmail() {
51 | return email;
52 | }
53 |
54 | public void setEmail(String email) {
55 | this.email = email;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/model/Subject.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.model;
2 |
3 | public class Subject {
4 | private int id;
5 | private String name;
6 | private int code;
7 | private double credit;
8 |
9 | public Subject(int id, String name, int code, double credit) {
10 | this.id = id;
11 | this.name = name;
12 | this.code = code;
13 | this.credit = credit;
14 | }
15 |
16 | public int getId() {
17 | return id;
18 | }
19 |
20 | public void setId(int id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public int getCode() {
33 | return code;
34 | }
35 |
36 | public void setCode(int code) {
37 | this.code = code;
38 | }
39 |
40 | public double getCredit() {
41 | return credit;
42 | }
43 |
44 | public void setCredit(double credit) {
45 | this.credit = credit;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/model/TableRowCount.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.model;
2 |
3 | public class TableRowCount {
4 | private long studentRow;
5 | private long subjectRow;
6 | private long takenSubjectRow;
7 |
8 | public TableRowCount(long studentRow, long subjectRow, long takenSubjectRow) {
9 | this.studentRow = studentRow;
10 | this.subjectRow = subjectRow;
11 | this.takenSubjectRow = takenSubjectRow;
12 | }
13 |
14 | public long getStudentRow() {
15 | return studentRow;
16 | }
17 |
18 | public long getSubjectRow() {
19 | return subjectRow;
20 | }
21 |
22 | public long getTakenSubjectRow() {
23 | return takenSubjectRow;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/model/TakenSubject.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.model;
2 |
3 | public class TakenSubject extends Subject{
4 |
5 | private boolean isTaken;
6 |
7 | public TakenSubject(int id, String name, int code, double credit, boolean isTaken) {
8 | super(id, name, code, credit);
9 | this.isTaken = isTaken;
10 | }
11 |
12 | public boolean isTaken() {
13 | return isTaken;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/util/Constants.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.util;
2 |
3 | public class Constants {
4 |
5 | //column names of student table
6 | public static final String TABLE_STUDENT = "student";
7 | public static final String STUDENT_ID = "_id";
8 | public static final String STUDENT_NAME = "name";
9 | public static final String STUDENT_REGISTRATION_NUM = "registration_no";
10 | public static final String STUDENT_PHONE = "phone";
11 | public static final String STUDENT_EMAIL = "email";
12 |
13 | //column names of subject table
14 | public static final String TABLE_SUBJECT = "subject";
15 | public static final String SUBJECT_ID = "_id";
16 | public static final String SUBJECT_NAME = "name";
17 | public static final String SUBJECT_CODE = "code";
18 | public static final String SUBJECT_CREDIT = "credit";
19 |
20 | //column names of student_subject pivot table
21 | public static final String TABLE_STUDENT_SUBJECT = "student_subject";
22 | public static final String STUDENT_ID_FK = "student_id";
23 | public static final String SUBJECT_ID_FK = "subject_id";
24 | public static final String STUDENT_SUB_CONSTRAINT = "student_sub_unique";
25 |
26 | //others for general purpose key-value pair data
27 | public static final String TITLE = "title";
28 | public static final String CREATE_STUDENT = "create_student";
29 | public static final String UPDATE_STUDENT = "update_student";
30 | public static final String CREATE_SUBJECT = "create_subject";
31 | public static final String UPDATE_SUBJECT = "update_subject";
32 | }
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/java/com/hellohasan/sqlite_multiple_three_tables_crud/util/MyApp.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud.util;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | public class MyApp extends Application {
7 |
8 | public static Context context = null;
9 |
10 | @Override
11 | public void onCreate() {
12 | super.onCreate();
13 | context = getApplicationContext();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/drawable/ic_add_subject_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/drawable/ic_delete_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/drawable/ic_edit_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/drawable/ic_person_add_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/drawable/ic_subject_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/activity_student_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/activity_student_taken_subject.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
29 |
30 |
40 |
41 |
51 |
52 |
53 |
54 |
63 |
64 |
72 |
73 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/activity_subject_assign.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
20 |
21 |
30 |
31 |
40 |
41 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/activity_subject_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
26 |
27 |
34 |
35 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/activity_taken_subject.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
23 |
24 |
32 |
33 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/content_subjects.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
23 |
24 |
32 |
33 |
44 |
45 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/fragment_student_create_dialog.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
17 |
18 |
27 |
28 |
37 |
38 |
47 |
48 |
56 |
57 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/fragment_student_update_dialog.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
17 |
18 |
27 |
28 |
37 |
38 |
47 |
48 |
56 |
57 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/fragment_subject_create_dialog.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
15 |
16 |
25 |
26 |
35 |
36 |
37 |
45 |
46 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/fragment_subject_update_dialog.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
15 |
16 |
25 |
26 |
35 |
36 |
44 |
45 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/item_student_card_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
21 |
22 |
32 |
33 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/item_subject_assign.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
25 |
26 |
35 |
36 |
43 |
44 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/item_subject_card_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
27 |
28 |
35 |
36 |
43 |
44 |
53 |
54 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/item_taken_subject.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
27 |
28 |
35 |
36 |
43 |
44 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/layout_student_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
26 |
27 |
35 |
36 |
44 |
45 |
53 |
54 |
62 |
63 |
71 |
72 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/layout/layout_table_row_count.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
25 |
26 |
33 |
34 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #f1f1f1
7 |
8 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SQLite Three Tables CRUD
3 | Add Subject
4 | Course Code: %d
5 | Course Credit: %.2f
6 | Subject List
7 | No data found in database!
8 | Number of Student: %d
9 | Number of Subject: %d
10 | Number of Taken Subject: %d
11 | This icon is responsible for delete the resource
12 | Settings
13 | CreateSubjectActivity
14 | Registration No
15 | Email
16 | Phone
17 | Delete student from SQLite database
18 | List is Empty!
19 | Student Name
20 | Update
21 | Cancel
22 | Create
23 | All Delete
24 | Edit Single student information
25 | Subject Name
26 | Subject Code
27 | Subject Credit
28 | Add New Subject
29 | Student Information
30 | Name
31 | Registration Number:
32 | Subject List
33 | Student List
34 | Total Student: %1$d. Total Subject: %2$d
35 | Update
36 | Table row count failed
37 | Taken Subjects by Student
38 |
39 | This student haven\'t taken any subject
40 | Subject Assign to Student
41 | Close
42 | No subject is found in database. Please add subject from Home page\'s menu
43 |
44 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/app/src/test/java/com/hellohasan/sqlite_multiple_three_tables_crud/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.sqlite_multiple_three_tables_crud;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.5.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/03.SQLite-Multiple-(Three)-Tables-CRUD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 31 11:30:33 BDT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/03.SQLite-Multiple-(Three)-Tables-CRUD/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android SQLite Tutorial
2 |
3 | We'll develop these types of sample Android App using `SQLite` database. There are multiple sample project in this repository. Check below list:
4 |
5 | ### 1. [Single table CRUD Operation](https://github.com/hasancse91/Android-SQLite-Tutorial/tree/master/01.SQLite-Single-Table-CRUD)
6 |
7 |
8 | ### 2. [Multiple (two) tables CRUD Operation](https://github.com/hasancse91/Android-SQLite-Tutorial/tree/master/02.SQLite-Multiple-(Two)-Tables-CRUD)
9 |
10 |
11 | ### 3. [Multiple (three) tables CRUD Operation](https://github.com/hasancse91/Android-SQLite-Tutorial/tree/master/03.SQLite-Multiple-(Three)-Tables-CRUD)
12 |
13 |
--------------------------------------------------------------------------------
/data/Android-SQLite-Multiple-table-CRUD.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/data/Android-SQLite-Multiple-table-CRUD.gif
--------------------------------------------------------------------------------
/data/Android-SQLite-three-table-tutorial.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/data/Android-SQLite-three-table-tutorial.gif
--------------------------------------------------------------------------------
/data/sqlite-app-screenshot.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/Android-SQLite-Tutorial/c85d0a2f275d9ea6b7c3b2ee9581f65369aa56c6/data/sqlite-app-screenshot.gif
--------------------------------------------------------------------------------