use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method getClassList.
@Override
public List<Class> getClassList() throws ClassException {
final List<Class> _classList = new ArrayList<>();
try {
return new AsyncTask<String, List<Class>, List<Class>>() {
@Override
protected List<Class> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload);
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
_classList.add(gson.fromJson(jsonArray.get(ctr).toString(), Class.class));
}
return _classList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Class");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return _classList;
} else
throw new ClassException("Server Error");
} catch (ClassException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method getClassListByTeacherId.
@Override
public List<Class> getClassListByTeacherId(final long teacherId) throws ClassException {
final List<Class> _classList = new ArrayList<>();
try {
return new AsyncTask<String, List<Class>, List<Class>>() {
@Override
protected List<Class> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?teacherId=").concat(String.valueOf(teacherId));
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
_classList.add(gson.fromJson(jsonArray.get(ctr).toString(), Class.class));
}
return _classList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Class");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return _classList;
} else
throw new ClassException("Server Error");
} catch (ClassException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method getClassListByStudentId.
@Override
public List<Class> getClassListByStudentId(final long studentId) throws ClassException {
final List<Class> _classList = new ArrayList<>();
try {
return new AsyncTask<String, List<Class>, List<Class>>() {
@Override
protected List<Class> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?studentId=").concat(String.valueOf(studentId));
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
_classList.add(gson.fromJson(jsonArray.get(ctr).toString(), Class.class));
}
return _classList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Class");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return _classList;
} else
throw new ClassException("Server Error");
} catch (ClassException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ScheduleViewActivity method initRView.
public void initRView(final long classId) {
final Handler handler = new Handler(getMainLooper());
new Thread(new Runnable() {
@Override
public void run() {
try {
final ClassServiceImpl classService = new ClassServiceImpl();
final List<Schedule> scheduleList = new ArrayList<>();
final Set<Schedule> scheduleSet = classService.getScheduleList(classId);
for (Schedule schedule : scheduleSet) scheduleList.add(schedule);
final ScheduleAdapter scheduleAdapter = new ScheduleAdapter(ScheduleViewActivity.this, scheduleList);
final LinearLayoutManager layoutManager = new LinearLayoutManager(ScheduleViewActivity.this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
handler.post(new Runnable() {
@Override
public void run() {
recyclerView.setAdapter(scheduleAdapter);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
if (scheduleSet.size() < 1)
txtMsgContent.setVisibility(View.VISIBLE);
}
});
} catch (ClassException e) {
e.printStackTrace();
}
}
}).start();
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class Home_Schedule_Slidebar_Fragment method init.
public void init() {
new Thread(new Runnable() {
@Override
public void run() {
try {
final List<Schedule> scheduleList = new ArrayList<>();
TeacherHelper teacherHelper = new TeacherHelper(getContext());
ClassServiceImpl classService = new ClassServiceImpl();
Class _class = null;
for (Class c : classService.getClassList()) {
if (c.getTeacher() == null)
continue;
if (c.getTeacher().getId() == teacherHelper.loadUser().get().getId()) {
_class = c;
Log.i("myTAG", "id : " + c.getId());
break;
}
}
// test
_class = classService.getClassById(40);
if (_class != null) {
for (Schedule schedule : classService.getScheduleList(_class.getId())) scheduleList.add(schedule);
}
handler.post(new Runnable() {
@Override
public void run() {
scheduleRecyclerView = (RecyclerView) customView.findViewById(R.id.shedule_recyclerview);
ScheduleAdapter scheduleAdapter = new ScheduleAdapter(getContext(), scheduleList);
scheduleRecyclerView.setAdapter(scheduleAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
scheduleRecyclerView.setLayoutManager(layoutManager);
scheduleRecyclerView.setItemAnimator(new DefaultItemAnimator());
}
});
} catch (ClassException e) {
e.printStackTrace();
}
}
}).start();
}
Aggregations