Skip to content

Commit 834b22b

Browse files
authored
Merge pull request #4 from cpcincubator/branch-shuvo-fragment
ready to release the alpha version
2 parents 7c35b4d + ba686df commit 834b22b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2056
-59
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ android {
1313

1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515
}
16+
compileOptions {
17+
sourceCompatibility JavaVersion.VERSION_1_8
18+
targetCompatibility JavaVersion.VERSION_1_8
19+
}
1620

1721
buildTypes {
1822
release {
@@ -33,6 +37,17 @@ dependencies {
3337
// Room
3438
implementation "androidx.room:room-runtime:$room_version"
3539
annotationProcessor "androidx.room:room-compiler:$room_version"
40+
// ButterKnife
41+
implementation 'com.jakewharton:butterknife:10.2.1'
42+
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
43+
// Material Design
44+
implementation 'com.google.android.material:material:1.1.0'
45+
// SpinKit
46+
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
47+
// OK http
48+
implementation "com.squareup.okhttp3:okhttp:4.7.2"
49+
// GSON
50+
implementation 'com.google.code.gson:gson:2.8.6'
3651
implementation 'androidx.appcompat:appcompat:1.1.0'
3752
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3853
testImplementation 'junit:junit:4.12'

app/src/main/AndroidManifest.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="cpc.class_planner.sam">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
8+
59
<application
610
android:allowBackup="true"
711
android:icon="@mipmap/ic_launcher"
812
android:label="@string/app_name"
913
android:roundIcon="@mipmap/ic_launcher_round"
1014
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
<activity android:name=".view.BaseActivity">
15+
android:theme="@style/AppTheme"
16+
android:usesCleartextTraffic="true">
17+
<activity android:name=".view.CloudExportActivity"
18+
android:exported="true"></activity>
19+
<activity
20+
android:name=".view.SetupWizardActivity"
21+
android:exported="true" />
22+
<activity
23+
android:name=".view.InputRoutineActivity"
24+
android:exported="true" />
25+
<activity android:name=".view.BaseActivity"
26+
27+
>
1328
<intent-filter>
1429
<action android:name="android.intent.action.MAIN" />
1530

20 KB
Loading

app/src/main/java/cpc/class_planner/sam/data/RoutineDao.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package cpc.class_planner.sam.data;
22

3+
import androidx.lifecycle.LiveData;
34
import androidx.room.Dao;
5+
import androidx.room.Delete;
46
import androidx.room.Insert;
7+
import androidx.room.Query;
8+
9+
import java.util.List;
510

611
import cpc.class_planner.sam.model.Routine;
712

@@ -10,4 +15,21 @@ public interface RoutineDao {
1015

1116
@Insert
1217
void insertData(Routine routine);
18+
19+
@Query("SELECT * FROM routine WHERE dayOfTheWeek LIKE :today ORDER BY startingTime")
20+
LiveData<List<Routine>> getTodayRoutine(String today);
21+
22+
@Query("SELECT DISTINCT courseTitle FROM routine")
23+
List<String> getCourseNames();
24+
25+
@Query("SELECT * FROM routine WHERE courseTitle = :courseTitle LIMIT 1")
26+
Routine getRoutineByCourseName(String courseTitle);
27+
28+
@Delete
29+
void deleteData(Routine routine);
30+
31+
@Query("SELECT * FROM routine")
32+
List<Routine> getFullRoutine();
33+
@Query("DELETE FROM routine")
34+
void deleteAll();
1335
}

app/src/main/java/cpc/class_planner/sam/data/RoutineDatabase.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import android.content.Context;
44
import android.util.Log;
55

6+
import androidx.annotation.NonNull;
67
import androidx.room.Database;
78
import androidx.room.Room;
89
import androidx.room.RoomDatabase;
10+
import androidx.sqlite.db.SupportSQLiteDatabase;
911

1012
import cpc.class_planner.sam.model.Routine;
1113

@@ -37,11 +39,28 @@ public static RoutineDatabase getInstance(final Context context){
3739
routineDatabaseInstance = Room.databaseBuilder(context.getApplicationContext(),
3840
RoutineDatabase.class,
3941
databaseName)
42+
.addCallback(roomCallBack)
43+
.allowMainThreadQueries()
4044
.build();
4145
}
4246

4347
return routineDatabaseInstance;
4448
}
4549

50+
private static RoomDatabase.Callback roomCallBack = new RoomDatabase.Callback(){
51+
@Override
52+
public void onCreate(@NonNull SupportSQLiteDatabase db) {
53+
super.onCreate(db);
54+
final RoutineDao routineDao;
55+
routineDao = routineDatabaseInstance.routineDao();
56+
new Thread(new Runnable() {
57+
@Override
58+
public void run() {
59+
routineDao.insertData(new Routine("Saturday",1000,1130,"Test Course","SE442","SMN Shuvo","Meet","Z"));
60+
}
61+
}).start();
62+
}
63+
};
64+
4665
}
4766

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cpc.class_planner.sam.data.repo;
2+
// This class should have been utilized better
3+
4+
import com.google.gson.Gson;
5+
import com.google.gson.JsonArray;
6+
7+
import org.jetbrains.annotations.NotNull;
8+
import org.json.JSONArray;
9+
import org.json.JSONException;
10+
11+
import java.io.IOException;
12+
import java.lang.reflect.Type;
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
import okhttp3.Call;
17+
import okhttp3.Callback;
18+
import okhttp3.OkHttpClient;
19+
import okhttp3.Request;
20+
import okhttp3.Response;
21+
22+
public class CloudApi {
23+
24+
25+
26+
27+
28+
// reused the existing version
29+
public int getVersion(){
30+
OkHttpClient httpClient = new OkHttpClient();
31+
String URL = "http://smnshuvo.000webhostapp.com/cpc_getList.php?query=Serial";
32+
List<String> spinnerDataList = new ArrayList<String>();
33+
String responseText;
34+
int cloudVersion = 0;
35+
Request request = new Request.Builder()
36+
.url(URL)
37+
.build();
38+
try {
39+
Response response = httpClient.newCall(request).execute();
40+
responseText = response.body().string();
41+
JSONArray jsonArray = new JSONArray(responseText);
42+
cloudVersion = jsonArray.optInt(0);
43+
} catch (IOException | JSONException e) {
44+
e.printStackTrace();
45+
}
46+
47+
return cloudVersion;
48+
49+
}
50+
51+
}

app/src/main/java/cpc/class_planner/sam/model/Routine.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public class Routine {
1414
@ColumnInfo
1515
private String dayOfTheWeek; // this is the day of the week. ie: Saturday
1616
@ColumnInfo
17-
private String startingTime; // the time when the class changes, data type may change in future
17+
private int startingTime; // the time when the class changes, data type may change in future
1818
@ColumnInfo
19-
private String endingTime; // time when class ends, ie: 10 PM
19+
private int endingTime; // time when class ends, ie: 10 PM
2020
@ColumnInfo
2121
private String courseTitle; // Title of the course
2222
@ColumnInfo
@@ -25,18 +25,21 @@ public class Routine {
2525
private String teacher; // Professor who conducts the course
2626
@ColumnInfo
2727
private String roomNo; // the room no that has been assigned for the course
28+
@ColumnInfo
29+
private String section; // the room no that has been assigned for the course
2830

2931
// constructor
3032

3133

32-
public Routine(@NonNull String dayOfTheWeek, String startingTime, String endingTime, String courseTitle, String courseCode, String teacher, String roomNo) {
34+
public Routine(@NonNull String dayOfTheWeek, int startingTime, int endingTime, String courseTitle, String courseCode, String teacher, String roomNo, String section) {
3335
this.dayOfTheWeek = dayOfTheWeek;
3436
this.startingTime = startingTime;
3537
this.endingTime = endingTime;
3638
this.courseTitle = courseTitle;
3739
this.courseCode = courseCode;
3840
this.teacher = teacher;
3941
this.roomNo = roomNo;
42+
this.section = section;
4043
}
4144

4245
// Getters
@@ -50,11 +53,11 @@ public String getDayOfTheWeek() {
5053
return dayOfTheWeek;
5154
}
5255

53-
public String getStartingTime() {
56+
public int getStartingTime() {
5457
return startingTime;
5558
}
5659

57-
public String getEndingTime() {
60+
public int getEndingTime() {
5861
return endingTime;
5962
}
6063

@@ -74,6 +77,10 @@ public String getRoomNo() {
7477
return roomNo;
7578
}
7679

80+
public String getSection() {
81+
return this.section;
82+
}
83+
7784
// Setter
7885

7986
public void setId(long id) {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cpc.class_planner.sam.model;
2+
3+
import android.app.AlertDialog;
4+
import android.app.AliasActivity;
5+
import android.content.DialogInterface;
6+
import android.os.Bundle;
7+
import android.util.Log;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
import android.widget.AdapterView;
12+
import android.widget.ArrayAdapter;
13+
import android.widget.ImageView;
14+
import android.widget.ListView;
15+
import android.widget.TextView;
16+
17+
import androidx.annotation.NonNull;
18+
import androidx.annotation.Nullable;
19+
import androidx.fragment.app.Fragment;
20+
import androidx.lifecycle.Observer;
21+
import androidx.lifecycle.ViewModelProviders;
22+
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
26+
import butterknife.BindView;
27+
import butterknife.ButterKnife;
28+
import cpc.class_planner.sam.R;
29+
import cpc.class_planner.sam.model.adapter.RoutineItemVIewAdapter;
30+
import cpc.class_planner.sam.view.BaseActivity;
31+
import cpc.class_planner.sam.viewmodel.BaseActivityViewModel;
32+
33+
public class RoutineFragment extends Fragment {
34+
@BindView(R.id.routine_no_class_bg)
35+
ImageView noClassBg;
36+
BaseActivityViewModel viewModel;
37+
private String dayOfTheWeek;
38+
@Nullable
39+
@Override
40+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
41+
View view = inflater.inflate(R.layout.routine_view_pager, container, false);
42+
viewModel = ViewModelProviders.of(this).get(BaseActivityViewModel.class);
43+
ButterKnife.bind(this, view);
44+
// TODO: Need the change the listView ID
45+
ListView listView = view.findViewById(R.id.sample_list_view);
46+
// get the routine for today's day of the week
47+
//List<Routine> routines =
48+
viewModel.getDailyRoutine(this.dayOfTheWeek).observe(this, new Observer<List<Routine>>() {
49+
@Override
50+
public void onChanged(List<Routine> routines) {
51+
if(routines.size() == 0){
52+
noClassBg.setVisibility(View.VISIBLE);
53+
} else{
54+
RoutineItemVIewAdapter adapter = new RoutineItemVIewAdapter((ArrayList<Routine>) routines, getContext());
55+
listView.setAdapter(adapter);
56+
adapter.notifyDataSetChanged();
57+
}
58+
}
59+
});
60+
61+
62+
return view;
63+
}
64+
65+
public RoutineFragment(String text){
66+
this.dayOfTheWeek = text;
67+
}
68+
}

0 commit comments

Comments
 (0)