├── 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 |