Skip to content

Commit 56f1597

Browse files
committed
10th class and 11th class added
1 parent fff11ef commit 56f1597

File tree

7 files changed

+106
-19
lines changed

7 files changed

+106
-19
lines changed

10-TenthClass/README.md

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
# Android Ninja - Class No: 9
2-
Date: 23 September, 2017
1+
# Android Ninja - Class No: 10
2+
Date: 06 October, 2017
33

44
## Topics ##
5-
- Capture image using default camera App of device
6-
- Web scraping using JSOUP library
7-
- `ProgressBar`
5+
- Implement an Abstraction Layer for Retrofit Network call
6+
- Android debugging
7+
- Refactor/rename (class, variable, method etc.)
8+
- Rename Android unique package name
9+
- Change Launcher Icon of Android App
10+
- Some Android Studio keyboard shortcuts
811

912
### Resources ###
10-
- [Bengali Blog Post on JSOUP Library](https://hellohasan.com/2017/02/25/android-web-scraping-jsoup/)
11-
- [Android working with Camera - AndroidHive](https://www.androidhive.info/2013/09/android-working-with-camera-api/)
12-
- [Android Uploading Camera Image, Video to Server with Progress Bar - AndroidHive](https://www.androidhive.info/2014/12/android-uploading-camera-image-video-to-server-with-progress-bar/)
13+
- [Bengali Blog Post on ***Abstraction in network layer using Retrofit***](https://hellohasan.com/2017/10/01/android-retrofit-get-post-method-different-network-layer/)
14+
- [Debug your App - Android Official Documentation](https://developer.android.com/studio/debug/index.html)
15+
- [Refactor/rename file in Android Studio](https://stackoverflow.com/a/28269008/6200296)
16+
- [Refactor your code in Android Studio - OneTouchCode](http://onetouchcode.com/2016/10/12/code-refactor-android-studio/)
17+
- [Rename package in Android Studio](https://stackoverflow.com/a/29092698/6200296)
18+
- [Change Launcher icon](https://stackoverflow.com/a/21385148/6200296)
19+
- [Android Studio Keyboard Shortcuts - Android Official Documentation](https://developer.android.com/studio/intro/keyboard-shortcuts.html)

10-TenthClass/app/src/main/java/com/hellohasan/tenthclass/UserInfoShow/UserInfoActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void seeRepositories() {
6262
}
6363

6464
@OnClick(R.id.seeRepoButton)
65-
public void getUserInfo() {
65+
public void getRepositoryList() {
6666

6767
String userId = userIdEditText.getText().toString();
6868

11-EleventhClass/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Android Ninja - Class No: 11
2+
Date: 07 October, 2017
3+
4+
## Topics ##
5+
- SQLite Database
6+
- Create Database
7+
- Create Table
8+
- Write a record (row) into table
9+
- Read all records from table
10+
- Count the number of row in table
11+
12+
### Resources ###
13+
- [Android SQLite Database - TutorialsPoint](https://www.tutorialspoint.com/android/android_sqlite_database.htm)
14+
- [Local Databases with SQLiteOpenHelper - CodePath](http://guides.codepath.com/android/local-databases-with-sqliteopenhelper)
15+
- [Android SQLite Database Tutorial - AndroidHive](https://www.androidhive.info/2011/11/android-sqlite-database-tutorial/)

11-EleventhClass/app/src/main/java/com/hellohasan/eleventhclass/Database/DatabaseQuery.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.ContentValues;
44
import android.content.Context;
55
import android.database.Cursor;
6+
import android.database.DatabaseUtils;
67
import android.database.sqlite.SQLiteDatabase;
78
import android.database.sqlite.SQLiteException;
89
import android.widget.Toast;
@@ -63,14 +64,14 @@ public List<Student> getAllStudent(){
6364
if(cursor.moveToFirst()){
6465
studentList = new ArrayList<>();
6566
do {
67+
long id = cursor.getLong(cursor.getColumnIndex(Config.COLUMN_STUDENT_ID));
6668
String name = cursor.getString(cursor.getColumnIndex(Config.COLUMN_STUDENT_NAME));
6769
long registrationNumber = cursor.getLong(cursor.getColumnIndex(Config.COLUMN_STUDENT_REGISTRATION));
6870
String phone = cursor.getString(cursor.getColumnIndex(Config.COLUMN_STUDENT_PHONE));
6971
String email = cursor.getString(cursor.getColumnIndex(Config.COLUMN_STUDENT_EMAIL));
70-
studentList.add(new Student(name, registrationNumber, phone, email));
72+
studentList.add(new Student(id, name, registrationNumber, phone, email));
7173
} while (cursor.moveToNext());
7274

73-
7475
}
7576
} catch (Exception e){
7677
Logger.d("Exception: " + e.getMessage());
@@ -83,4 +84,14 @@ public List<Student> getAllStudent(){
8384

8485
return studentList;
8586
}
87+
88+
public long getStudentCount(){
89+
DatabaseHelper databaseHelper = DatabaseHelper.getInstance(context);
90+
SQLiteDatabase sqLiteDatabase = databaseHelper.getReadableDatabase();
91+
92+
long count = DatabaseUtils.queryNumEntries(sqLiteDatabase, Config.TABLE_STUDENT);
93+
sqLiteDatabase.close();
94+
95+
return count;
96+
}
8697
}

11-EleventhClass/app/src/main/java/com/hellohasan/eleventhclass/StudentCreate/Student.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.hellohasan.eleventhclass.StudentCreate;
22

33
public class Student {
4+
private long id;
45
private String name;
56
private long registrationNumber;
67
private String phoneNumber;
@@ -13,9 +14,20 @@ public Student(String name, long registrationNumber, String phoneNumber, String
1314
this.email = email;
1415
}
1516

16-
public Student(String name, long registrationNumber) {
17+
public Student(long id, String name, long registrationNumber, String phoneNumber, String email) {
18+
this.id = id;
1719
this.name = name;
1820
this.registrationNumber = registrationNumber;
21+
this.phoneNumber = phoneNumber;
22+
this.email = email;
23+
}
24+
25+
public long getId() {
26+
return id;
27+
}
28+
29+
public void setId(long id) {
30+
this.id = id;
1931
}
2032

2133
public String getName() {

11-EleventhClass/app/src/main/java/com/hellohasan/eleventhclass/StudentCreate/StudentCreateActivity.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,47 @@
33
import android.os.Bundle;
44
import android.support.v7.app.AppCompatActivity;
55
import android.view.View;
6+
import android.widget.TextView;
67

78
import com.hellohasan.eleventhclass.Database.DatabaseQuery;
89
import com.hellohasan.eleventhclass.R;
910
import com.orhanobut.logger.Logger;
1011

1112
import java.util.List;
1213

14+
import butterknife.BindView;
15+
import butterknife.ButterKnife;
16+
1317
public class StudentCreateActivity extends AppCompatActivity {
1418

19+
@BindView(R.id.studentCountTextView)
20+
TextView studentCountTextView;
21+
22+
private DatabaseQuery databaseQuery = new DatabaseQuery(this);
23+
1524
@Override
1625
protected void onCreate(Bundle savedInstanceState) {
1726
super.onCreate(savedInstanceState);
1827
setContentView(R.layout.activity_student_create);
28+
ButterKnife.bind(this);
1929

20-
30+
//print number of students in db
31+
studentCountTextView.setText(String.valueOf(databaseQuery.getStudentCount()));
2132
}
2233

2334
public void addEntryToDatabase(View view) {
35+
//every time we'll create student object with same data. and insert to database
2436
Student student = new Student("John", 123522, "01522235524", "[email protected]");
25-
DatabaseQuery databaseQuery = new DatabaseQuery(this);
26-
databaseQuery.insertStudent(student);
2737

38+
databaseQuery.insertStudent(student); //insert student object (actually data) into database
39+
40+
//you'll find all students of db in studentList
2841
List<Student> studentList = databaseQuery.getAllStudent();
29-
Logger.d("List Length: " + studentList.size());
42+
Logger.d("Number of Student: " + studentList.size()); //get student count
43+
//place a debugging breakpoint at this line or above line and check the studentList in debug monitor
44+
45+
//another way to count students in db
46+
long count = databaseQuery.getStudentCount();
47+
studentCountTextView.setText(String.valueOf(count)); //print the counter into TextView
3048
}
3149
}

11-EleventhClass/app/src/main/res/layout/activity_student_create.xml

+27-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,37 @@
66
android:layout_height="match_parent"
77
tools:context="com.hellohasan.eleventhclass.StudentCreate.StudentCreateActivity">
88

9-
<TextView
9+
<Button
10+
android:id="@+id/addStudentButton"
1011
android:layout_width="wrap_content"
1112
android:layout_height="wrap_content"
12-
android:text="Hello World!"
13+
android:text="Add Student to DB"
1314
app:layout_constraintBottom_toBottomOf="parent"
1415
app:layout_constraintLeft_toLeftOf="parent"
1516
app:layout_constraintRight_toRightOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
17+
app:layout_constraintTop_toTopOf="parent"
18+
android:onClick="addEntryToDatabase"/>
19+
20+
<TextView
21+
android:id="@+id/studentCountTitle"
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"
24+
app:layout_constraintTop_toBottomOf="@id/addStudentButton"
25+
app:layout_constraintLeft_toLeftOf="parent"
26+
app:layout_constraintRight_toLeftOf="@+id/studentCountTextView"
27+
android:text="Number of Student: "
28+
android:textStyle="bold"
29+
android:textSize="20sp"
30+
app:layout_constraintHorizontal_chainStyle="packed" />
31+
32+
<TextView
33+
android:id="@+id/studentCountTextView"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
app:layout_constraintTop_toBottomOf="@id/addStudentButton"
37+
app:layout_constraintLeft_toRightOf="@id/studentCountTitle"
38+
app:layout_constraintRight_toRightOf="parent"
39+
android:textSize="20sp"
40+
tools:text="12"/>
1741

1842
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)