Commit fd312036 authored by NiklasFix's avatar NiklasFix

added models and some TODOs

parent eae6aed3
Pipeline #382 failed with stages
in 8 minutes and 21 seconds
......@@ -48,7 +48,7 @@
android:name=".features.dashboard.settings.SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".features.dashboard.MainActivity"/>
<activity android:name=".features.flashcards.TrainingSubjectActivity"></activity>
<activity android:name=".features.training.TrainingSubjectActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package de.akamu.tudarmstadt.api;
import android.util.ArrayMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import de.akamu.tudarmstadt.exceptions.AkamuAPIException;
import de.akamu.tudarmstadt.model.CourseSubject;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public final class V2APISubject {
public static List<CourseSubject> getAllCourseSubjects(int courseId) throws IOException, AkamuAPIException {
Map<String, String> parameters = new ArrayMap<>(1);
parameters.put("author", Integer.toString(courseId));
String response = V2API.get("course/subject", parameters);
Gson gsonBuilder = new GsonBuilder().create();
CourseSubject[] subjects = gsonBuilder.fromJson(response, CourseSubject[].class);
return Arrays.asList(subjects);
}
}
package de.akamu.tudarmstadt.data.training
import de.akamu.tudarmstadt.model.Course
interface TrainingDataSource {
interface FetchAllCoursesCallback {
fun onFetchAllCoursesSuccess(courses: ArrayList<Course>)
fun onFetchAllCoursesFailed(reason: String)
}
fun fetchTrainingSubjects(callback: FetchAllCoursesCallback)
}
\ No newline at end of file
package de.akamu.tudarmstadt.data.training
import android.os.AsyncTask
import de.akamu.tudarmstadt.model.Course
class TrainingDataSourceImpl : TrainingDataSource {
override fun fetchTrainingSubjects(callback: TrainingDataSource.FetchAllCoursesCallback) {
}
class FetchTrainingSubjectsTask(var callback: TrainingDataSource.FetchAllCoursesCallback)
: AsyncTask<Void, Void, Boolean>() {
var courses : List<Course> = ArrayList()
private var errorMessage : String = "Oops. Something went wrong..."
override fun doInBackground(vararg params: Void?): Boolean{
return try {
// TODO: fetch Courses
true
} catch (e : Exception) {
e.printStackTrace()
errorMessage = e.message!!
false
}
}
override fun onPostExecute(success: Boolean?) {
if(success!!) {
callback.onFetchAllCoursesSuccess(ArrayList(courses))
} else {
callback.onFetchAllCoursesFailed(errorMessage)
}
}
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.ImageButton
import androidx.fragment.app.Fragment
import de.akamu.tudarmstadt.R
import de.akamu.tudarmstadt.features.training.TrainingSubjectActivity
import de.akamu.tudarmstadt.features.friends.FriendsListActivity
import kotlinx.android.synthetic.main.fragment_game_mode.*
......@@ -27,10 +28,16 @@ class GameModeFragment : Fragment(), View.OnClickListener {
override fun onClick(v: View?) {
if(v!!.id == imageButton_challenge_classic.id) {
navigateToFriendsListActivity()
} else if (v.id == imageButton_challenge_training.id) {
navigateToTrainingSubjectActivity()
}
}
fun navigateToFriendsListActivity() {
startActivity(Intent(this.context, FriendsListActivity::class.java))
}
fun navigateToTrainingSubjectActivity() {
startActivity(Intent(this.context, TrainingSubjectActivity::class.java))
}
}
\ No newline at end of file
package de.akamu.tudarmstadt.features.flashcards
package de.akamu.tudarmstadt.features.training
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import de.akamu.tudarmstadt.R
import de.akamu.tudarmstadt.model.Subject
class TrainingSubjectActivity : AppCompatActivity() {
class TrainingSubjectActivity :
AppCompatActivity(),
TrainingSubjectContract.View {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -14,7 +16,7 @@ class TrainingSubjectActivity : AppCompatActivity() {
// fetchSubjects()
}
fun bindSubjectAdapter(subjects: ArrayList<Subject>) {
override fun bindSubjectAdapter(subjects: ArrayList<Subject>) {
}
}
package de.akamu.tudarmstadt.features.flashcards
package de.akamu.tudarmstadt.features.training
import android.view.LayoutInflater
import android.view.View
......
package de.akamu.tudarmstadt.features.training
import de.akamu.tudarmstadt.model.Subject
interface TrainingSubjectContract {
interface View {
fun bindSubjectAdapter(subjects: ArrayList<Subject>)
}
interface Presenter {
fun fetchSubjects()
}
}
\ No newline at end of file
package de.akamu.tudarmstadt.features.training
import de.akamu.tudarmstadt.data.training.TrainingDataSource
import de.akamu.tudarmstadt.data.training.TrainingDataSourceImpl
class TrainingSubjectInteractor (private val dataSource: TrainingDataSourceImpl) : TrainingDataSource {
override fun fetchTrainingSubjects(callback: TrainingDataSource.FetchAllCoursesCallback) {
//TODO: implement when available from server side
}
}
\ No newline at end of file
package de.akamu.tudarmstadt.features.training
class TrainingSubjectPresenter(var interactor: TrainingSubjectInteractor, var view: TrainingSubjectContract.View)
: TrainingSubjectContract.Presenter {
override fun fetchSubjects() {
interactor
}
}
\ No newline at end of file
package de.akamu.tudarmstadt.model;
public class Course {
private int id;
private String name;
private String shortForm;
/** Department like FBxx at TU Darmstadt. */
private String departement;
/** Name of the university this course is offered at. */
private String university;
/** Brief description of what this course is about. */
private String description;
public Course(int id, String name, String shortForm, String departement, String university, String description) {
this.id = id;
this.name = name;
this.shortForm = shortForm;
this.departement = departement;
this.university = university;
this.description = description;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getShortForm() {
return shortForm;
}
public void setShortForm(String shortForm) {
this.shortForm = shortForm;
}
public String getDepartement() {
return departement;
}
public void setDepartement(String departement) {
this.departement = departement;
}
public String getUniversity() {
return university;
}
public void setUniversity(String university) {
this.university = university;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
package de.akamu.tudarmstadt.model;
public class CourseSubject {
private Course course;
private Subject subject;
private int semester;
public CourseSubject(Course course, Subject subject, int semester) {
this.course = course;
this.subject = subject;
this.semester = semester;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public Subject getSubject() {
return subject;
}
public void setSubject(Subject subject) {
this.subject = subject;
}
public int getSemester() {
return semester;
}
public void setSemester(int semester) {
this.semester = semester;
}
}
......@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".features.flashcards.TrainingSubjectActivity">
tools:context=".features.training.TrainingSubjectActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment