Add homework (#181)

This commit is contained in:
Mikołaj Pich 2018-11-14 09:18:00 +01:00 committed by Rafał Borcz
parent 24f59b45c3
commit 9f04dbf60f
25 changed files with 821 additions and 6 deletions

View File

@ -78,7 +78,7 @@ ext.androidx_version = "1.0.0"
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation('com.github.wulkanowy:api:96be34a') { exclude module: "threetenbp" } implementation('com.github.wulkanowy:api:ddb1baa') { exclude module: "threetenbp" }
implementation "androidx.legacy:legacy-support-v4:$androidx_version" implementation "androidx.legacy:legacy-support-v4:$androidx_version"
implementation "androidx.appcompat:appcompat:$androidx_version" implementation "androidx.appcompat:appcompat:$androidx_version"

View File

@ -71,4 +71,8 @@ internal class RepositoryModule {
@Singleton @Singleton
@Provides @Provides
fun provideNoteDao(database: AppDatabase) = database.noteDao() fun provideNoteDao(database: AppDatabase) = database.noteDao()
@Singleton
@Provides
fun provideHomeworkDao(database: AppDatabase) = database.homeworkDao()
} }

View File

@ -9,6 +9,7 @@ import io.github.wulkanowy.data.db.dao.AttendanceDao
import io.github.wulkanowy.data.db.dao.ExamDao import io.github.wulkanowy.data.db.dao.ExamDao
import io.github.wulkanowy.data.db.dao.GradeDao import io.github.wulkanowy.data.db.dao.GradeDao
import io.github.wulkanowy.data.db.dao.GradeSummaryDao import io.github.wulkanowy.data.db.dao.GradeSummaryDao
import io.github.wulkanowy.data.db.dao.HomeworkDao
import io.github.wulkanowy.data.db.dao.NoteDao import io.github.wulkanowy.data.db.dao.NoteDao
import io.github.wulkanowy.data.db.dao.SemesterDao import io.github.wulkanowy.data.db.dao.SemesterDao
import io.github.wulkanowy.data.db.dao.StudentDao import io.github.wulkanowy.data.db.dao.StudentDao
@ -17,6 +18,7 @@ import io.github.wulkanowy.data.db.entities.Attendance
import io.github.wulkanowy.data.db.entities.Exam import io.github.wulkanowy.data.db.entities.Exam
import io.github.wulkanowy.data.db.entities.Grade import io.github.wulkanowy.data.db.entities.Grade
import io.github.wulkanowy.data.db.entities.GradeSummary import io.github.wulkanowy.data.db.entities.GradeSummary
import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.data.db.entities.Note import io.github.wulkanowy.data.db.entities.Note
import io.github.wulkanowy.data.db.entities.Semester import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Student
@ -33,7 +35,8 @@ import javax.inject.Singleton
Attendance::class, Attendance::class,
Grade::class, Grade::class,
GradeSummary::class, GradeSummary::class,
Note::class Note::class,
Homework::class
], ],
version = 1, version = 1,
exportSchema = false exportSchema = false
@ -63,4 +66,6 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun gradeSummaryDao(): GradeSummaryDao abstract fun gradeSummaryDao(): GradeSummaryDao
abstract fun noteDao(): NoteDao abstract fun noteDao(): NoteDao
abstract fun homeworkDao(): HomeworkDao
} }

View File

@ -0,0 +1,22 @@
package io.github.wulkanowy.data.db.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import io.github.wulkanowy.data.db.entities.Homework
import io.reactivex.Maybe
import org.threeten.bp.LocalDate
@Dao
interface HomeworkDao {
@Insert
fun insertAll(homework: List<Homework>)
@Delete
fun deleteAll(homework: List<Homework>)
@Query("SELECT * FROM Homework WHERE semester_id = :semesterId AND student_id = :studentId AND date = :date")
fun getHomework(semesterId: Int, studentId: Int, date: LocalDate): Maybe<List<Homework>>
}

View File

@ -0,0 +1,36 @@
package io.github.wulkanowy.data.db.entities
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import org.threeten.bp.LocalDate
import java.io.Serializable
@Entity(tableName = "Homework")
data class Homework(
@ColumnInfo(name = "semester_id")
var semesterId: Int,
@ColumnInfo(name = "student_id")
var studentId: Int,
var date: LocalDate,
@ColumnInfo(name = "entry_date")
var entryDate: LocalDate,
var subject: String,
var content: String,
var teacher: String,
@ColumnInfo(name = "teacher_symbol")
var teacherSymbol: String
) : Serializable {
@PrimaryKey(autoGenerate = true)
var id: Long = 0
}

View File

@ -0,0 +1,36 @@
package io.github.wulkanowy.data.repositories
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.data.repositories.local.HomeworkLocal
import io.github.wulkanowy.data.repositories.remote.HomeworkRemote
import io.reactivex.Single
import org.threeten.bp.LocalDate
import java.net.UnknownHostException
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class HomeworkRepository @Inject constructor(
private val settings: InternetObservingSettings,
private val local: HomeworkLocal,
private val remote: HomeworkRemote
) {
fun getHomework(semester: Semester, date: LocalDate, forceRefresh: Boolean = false): Single<List<Homework>> {
return local.getHomework(semester, date).filter { !forceRefresh }
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
.flatMap {
if (it) remote.getHomework(semester, date)
else Single.error(UnknownHostException())
}.flatMap { newGrades ->
local.getHomework(semester, date).toSingle(emptyList())
.doOnSuccess { oldGrades ->
local.deleteHomework(oldGrades - newGrades)
local.saveHomework(newGrades - oldGrades)
}
}.flatMap { local.getHomework(semester, date).toSingle(emptyList()) })
}
}

View File

@ -0,0 +1,25 @@
package io.github.wulkanowy.data.repositories.local
import io.github.wulkanowy.data.db.dao.HomeworkDao
import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.data.db.entities.Semester
import io.reactivex.Maybe
import org.threeten.bp.LocalDate
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class HomeworkLocal @Inject constructor(private val homeworkDb: HomeworkDao) {
fun getHomework(semester: Semester, date: LocalDate): Maybe<List<Homework>> {
return homeworkDb.getHomework(semester.semesterId, semester.studentId, date).filter { !it.isEmpty() }
}
fun saveHomework(homework: List<Homework>) {
homeworkDb.insertAll(homework)
}
fun deleteHomework(homework: List<Homework>) {
homeworkDb.deleteAll(homework)
}
}

View File

@ -0,0 +1,37 @@
package io.github.wulkanowy.data.repositories.remote
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.data.db.entities.Semester
import io.github.wulkanowy.utils.toLocalDate
import io.reactivex.Single
import org.threeten.bp.LocalDate
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class HomeworkRemote @Inject constructor(private val api: Api) {
fun getHomework(semester: Semester, date: LocalDate): Single<List<Homework>> {
return Single.just(api.run {
if (diaryId != semester.diaryId) {
diaryId = semester.diaryId
notifyDataChanged()
}
}).flatMap { api.getHomework(date, date) }
.map { homework ->
homework.map {
Homework(
semesterId = semester.semesterId,
studentId = semester.studentId,
date = it.date.toLocalDate(),
entryDate = it.entryDate.toLocalDate(),
subject = it.subject,
content = it.content,
teacher = it.teacher,
teacherSymbol = it.teacherSymbol
)
}
}
}
}

View File

@ -7,6 +7,7 @@ import io.github.wulkanowy.data.repositories.AttendanceRepository
import io.github.wulkanowy.data.repositories.ExamRepository import io.github.wulkanowy.data.repositories.ExamRepository
import io.github.wulkanowy.data.repositories.GradeRepository import io.github.wulkanowy.data.repositories.GradeRepository
import io.github.wulkanowy.data.repositories.GradeSummaryRepository import io.github.wulkanowy.data.repositories.GradeSummaryRepository
import io.github.wulkanowy.data.repositories.HomeworkRepository
import io.github.wulkanowy.data.repositories.NoteRepository import io.github.wulkanowy.data.repositories.NoteRepository
import io.github.wulkanowy.data.repositories.PreferencesRepository import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.data.repositories.SessionRepository import io.github.wulkanowy.data.repositories.SessionRepository
@ -45,6 +46,9 @@ class SyncWorker : SimpleJobService() {
@Inject @Inject
lateinit var note: NoteRepository lateinit var note: NoteRepository
@Inject
lateinit var homework: HomeworkRepository
@Inject @Inject
lateinit var prefRepository: PreferencesRepository lateinit var prefRepository: PreferencesRepository
@ -79,7 +83,9 @@ class SyncWorker : SimpleJobService() {
attendance.getAttendance(it, start, end, true), attendance.getAttendance(it, start, end, true),
exam.getExams(it, start, end, true), exam.getExams(it, start, end, true),
timetable.getTimetable(it, start, end, true), timetable.getTimetable(it, start, end, true),
note.getNotes(it, true, true) note.getNotes(it, true, true),
homework.getHomework(it, LocalDate.now(), true),
homework.getHomework(it, LocalDate.now().plusDays(1), true)
) )
) )
} }

View File

@ -0,0 +1,49 @@
package io.github.wulkanowy.ui.modules.homework
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.utils.toFormattedString
import kotlinx.android.synthetic.main.dialog_homework.*
class HomeworkDialog : DialogFragment() {
private lateinit var homework: Homework
companion object {
private const val ARGUMENT_KEY = "Item"
fun newInstance(homework: Homework): HomeworkDialog {
return HomeworkDialog().apply {
arguments = Bundle().apply { putSerializable(ARGUMENT_KEY, homework) }
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, 0)
arguments?.run {
homework = getSerializable(HomeworkDialog.ARGUMENT_KEY) as Homework
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_homework, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
homeworkDialogDate.text = homework.date.toFormattedString()
homeworkDialogEntryDate.text = homework.entryDate.toFormattedString()
homeworkDialogSubject.text = homework.subject
homeworkDialogTeacher.text = homework.teacher
homeworkDialogContent.text = homework.content
homeworkDialogClose.setOnClickListener { dismiss() }
}
}

View File

@ -0,0 +1,110 @@
package io.github.wulkanowy.ui.modules.homework
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.ui.base.BaseFragment
import io.github.wulkanowy.ui.modules.main.MainView
import io.github.wulkanowy.utils.setOnItemClickListener
import kotlinx.android.synthetic.main.fragment_homework.*
import javax.inject.Inject
class HomeworkFragment : BaseFragment(), HomeworkView, MainView.TitledView {
@Inject
lateinit var presenter: HomeworkPresenter
@Inject
lateinit var homeworkAdapter: FlexibleAdapter<AbstractFlexibleItem<*>>
companion object {
private const val SAVED_DATE_KEY = "CURRENT_DATE"
fun newInstance() = HomeworkFragment()
}
override val titleStringId: Int
get() = R.string.homework_title
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_homework, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
messageContainer = homeworkRecycler
presenter.onAttachView(this, savedInstanceState?.getLong(HomeworkFragment.SAVED_DATE_KEY))
}
override fun initView() {
homeworkAdapter.run {
setOnItemClickListener { presenter.onHomeworkItemSelected(getItem(it)) }
}
homeworkRecycler.run {
layoutManager = SmoothScrollLinearLayoutManager(context)
adapter = homeworkAdapter
}
homeworkSwipe.setOnRefreshListener { presenter.onSwipeRefresh() }
homeworkPreviousButton.setOnClickListener { presenter.onPreviousDay() }
homeworkNextButton.setOnClickListener { presenter.onNextDay() }
}
override fun updateData(data: List<HomeworkItem>) {
homeworkAdapter.updateDataSet(data, true)
}
override fun clearData() {
homeworkAdapter.clear()
}
override fun updateNavigationDay(date: String) {
homeworkNavDate.text = date
}
override fun isViewEmpty() = homeworkAdapter.isEmpty
override fun hideRefresh() {
homeworkSwipe.isRefreshing = false
}
override fun showEmpty(show: Boolean) {
homeworkEmpty.visibility = if (show) View.VISIBLE else View.GONE
}
override fun showProgress(show: Boolean) {
homeworkProgress.visibility = if (show) View.VISIBLE else View.GONE
}
override fun showContent(show: Boolean) {
homeworkRecycler.visibility = if (show) View.VISIBLE else View.GONE
}
override fun showPreButton(show: Boolean) {
homeworkPreviousButton.visibility = if (show) View.VISIBLE else View.INVISIBLE
}
override fun showNextButton(show: Boolean) {
homeworkNextButton.visibility = if (show) View.VISIBLE else View.INVISIBLE
}
override fun showTimetableDialog(homework: Homework) {
HomeworkDialog.newInstance(homework).show(fragmentManager, homework.toString())
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putLong(HomeworkFragment.SAVED_DATE_KEY, presenter.currentDate.toEpochDay())
}
override fun onDestroyView() {
presenter.onDetachView()
super.onDestroyView()
}
}

View File

@ -0,0 +1,54 @@
package io.github.wulkanowy.ui.modules.homework
import android.annotation.SuppressLint
import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Homework
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_homework.*
class HomeworkItem(val homework: Homework) : AbstractFlexibleItem<HomeworkItem.ViewHolder>() {
override fun getLayoutRes(): Int = R.layout.item_homework
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<*>>): ViewHolder {
return ViewHolder(view, adapter)
}
@SuppressLint("SetTextI18n")
override fun bindViewHolder(
adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder,
position: Int, payloads: MutableList<Any>?
) {
holder.apply {
homeworkItemSubject.text = homework.subject
homeworkItemTeacher.text = homework.teacher
homeworkItemContent.text = homework.content
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as HomeworkItem
if (homework != other.homework) return false
return true
}
override fun hashCode(): Int {
return homework.hashCode()
}
class ViewHolder(val view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter),
LayoutContainer {
override val containerView: View
get() = contentView
}
}

View File

@ -0,0 +1,98 @@
package io.github.wulkanowy.ui.modules.homework
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.data.ErrorHandler
import io.github.wulkanowy.data.repositories.HomeworkRepository
import io.github.wulkanowy.data.repositories.SessionRepository
import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.utils.SchedulersProvider
import io.github.wulkanowy.utils.isHolidays
import io.github.wulkanowy.utils.logEvent
import io.github.wulkanowy.utils.nextOrSameSchoolDay
import io.github.wulkanowy.utils.nextSchoolDay
import io.github.wulkanowy.utils.previousSchoolDay
import io.github.wulkanowy.utils.toFormattedString
import org.threeten.bp.LocalDate
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class HomeworkPresenter @Inject constructor(
private val errorHandler: ErrorHandler,
private val schedulers: SchedulersProvider,
private val homeworkRepository: HomeworkRepository,
private val sessionRepository: SessionRepository
) : BasePresenter<HomeworkView>(errorHandler) {
lateinit var currentDate: LocalDate
private set
fun onAttachView(view: HomeworkView, date: Long?) {
super.onAttachView(view)
view.initView()
loadData(LocalDate.ofEpochDay(date ?: LocalDate.now().nextOrSameSchoolDay.toEpochDay()))
reloadView()
}
fun onPreviousDay() {
loadData(currentDate.previousSchoolDay)
reloadView()
logEvent("Homework day changed", mapOf("button" to "prev", "date" to currentDate.toFormattedString()))
}
fun onNextDay() {
loadData(currentDate.nextSchoolDay)
reloadView()
logEvent("Homework day changed", mapOf("button" to "next", "date" to currentDate.toFormattedString()))
}
fun onSwipeRefresh() {
loadData(currentDate, true)
}
fun onHomeworkItemSelected(item: AbstractFlexibleItem<*>?) {
if (item is HomeworkItem) view?.showTimetableDialog(item.homework)
}
private fun loadData(date: LocalDate, forceRefresh: Boolean = false) {
currentDate = date
disposable.apply {
clear()
add(sessionRepository.getSemesters()
.delay(200, TimeUnit.MILLISECONDS)
.map { it.single { semester -> semester.current } }
.flatMap { homeworkRepository.getHomework(it, currentDate, forceRefresh) }
.map { items -> items.map { HomeworkItem(it) } }
.subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread)
.doFinally {
view?.run {
hideRefresh()
showProgress(false)
}
}
.subscribe({
view?.apply {
updateData(it)
showEmpty(it.isEmpty())
showContent(it.isNotEmpty())
}
logEvent("Homework load", mapOf("items" to it.size, "forceRefresh" to forceRefresh, "date" to currentDate.toFormattedString()))
}) {
view?.run { showEmpty(isViewEmpty()) }
errorHandler.proceed(it)
})
}
}
private fun reloadView() {
view?.apply {
showProgress(true)
showContent(false)
showEmpty(false)
clearData()
showNextButton(!currentDate.plusDays(1).isHolidays)
showPreButton(!currentDate.minusDays(1).isHolidays)
updateNavigationDay(currentDate.toFormattedString("EEEE \n dd.MM.YYYY").capitalize())
}
}
}

View File

@ -0,0 +1,31 @@
package io.github.wulkanowy.ui.modules.homework
import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.ui.base.BaseView
interface HomeworkView : BaseView {
fun initView()
fun updateData(data: List<HomeworkItem>)
fun clearData()
fun updateNavigationDay(date: String)
fun isViewEmpty(): Boolean
fun hideRefresh()
fun showEmpty(show: Boolean)
fun showProgress(show: Boolean)
fun showContent(show: Boolean)
fun showPreButton(show: Boolean)
fun showNextButton(show: Boolean)
fun showTimetableDialog(homework: Homework)
}

View File

@ -13,6 +13,7 @@ import io.github.wulkanowy.ui.modules.attendance.AttendanceFragment
import io.github.wulkanowy.ui.modules.exam.ExamFragment import io.github.wulkanowy.ui.modules.exam.ExamFragment
import io.github.wulkanowy.ui.modules.grade.GradeFragment import io.github.wulkanowy.ui.modules.grade.GradeFragment
import io.github.wulkanowy.ui.modules.grade.GradeModule import io.github.wulkanowy.ui.modules.grade.GradeModule
import io.github.wulkanowy.ui.modules.homework.HomeworkFragment
import io.github.wulkanowy.ui.modules.more.MoreFragment import io.github.wulkanowy.ui.modules.more.MoreFragment
import io.github.wulkanowy.ui.modules.note.NoteFragment import io.github.wulkanowy.ui.modules.note.NoteFragment
import io.github.wulkanowy.ui.modules.settings.SettingsFragment import io.github.wulkanowy.ui.modules.settings.SettingsFragment
@ -61,4 +62,7 @@ abstract class MainModule {
@ContributesAndroidInjector @ContributesAndroidInjector
abstract fun bindNoteFragment(): NoteFragment abstract fun bindNoteFragment(): NoteFragment
@ContributesAndroidInjector
abstract fun bindHomeworkFragment(): HomeworkFragment
} }

View File

@ -12,6 +12,7 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.ui.base.BaseFragment import io.github.wulkanowy.ui.base.BaseFragment
import io.github.wulkanowy.ui.modules.about.AboutFragment import io.github.wulkanowy.ui.modules.about.AboutFragment
import io.github.wulkanowy.ui.modules.homework.HomeworkFragment
import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import io.github.wulkanowy.ui.modules.note.NoteFragment import io.github.wulkanowy.ui.modules.note.NoteFragment
@ -35,6 +36,13 @@ class MoreFragment : BaseFragment(), MoreView, MainView.TitledView, MainView.Mai
override val titleStringId: Int override val titleStringId: Int
get() = R.string.more_title get() = R.string.more_title
override val homeworkRes: Pair<String, Drawable?>?
get() {
return context?.run {
getString(R.string.homework_title) to ContextCompat.getDrawable(this, R.drawable.ic_menu_main_homework_24dp)
}
}
override val noteRes: Pair<String, Drawable?>? override val noteRes: Pair<String, Drawable?>?
get() { get() {
return context?.run { return context?.run {
@ -84,6 +92,10 @@ class MoreFragment : BaseFragment(), MoreView, MainView.TitledView, MainView.Mai
moreAdapter.updateDataSet(data) moreAdapter.updateDataSet(data)
} }
override fun openHomeworkView() {
(activity as? MainActivity)?.pushView(HomeworkFragment.newInstance())
}
override fun openNoteView() { override fun openNoteView() {
(activity as? MainActivity)?.pushView(NoteFragment.newInstance()) (activity as? MainActivity)?.pushView(NoteFragment.newInstance())
} }

View File

@ -17,6 +17,7 @@ class MorePresenter @Inject constructor(errorHandler: ErrorHandler) : BasePresen
if (item is MoreItem) { if (item is MoreItem) {
view?.run { view?.run {
when (item.title) { when (item.title) {
homeworkRes?.first -> openHomeworkView()
noteRes?.first -> openNoteView() noteRes?.first -> openNoteView()
settingsRes?.first -> openSettingsView() settingsRes?.first -> openSettingsView()
aboutRes?.first -> openAboutView() aboutRes?.first -> openAboutView()
@ -32,6 +33,7 @@ class MorePresenter @Inject constructor(errorHandler: ErrorHandler) : BasePresen
private fun loadData() { private fun loadData() {
view?.run { view?.run {
updateData(listOfNotNull( updateData(listOfNotNull(
homeworkRes?.let { MoreItem(it.first, it.second) },
noteRes?.let { MoreItem(it.first, it.second) }, noteRes?.let { MoreItem(it.first, it.second) },
settingsRes?.let { MoreItem(it.first, it.second) }, settingsRes?.let { MoreItem(it.first, it.second) },
aboutRes?.let { MoreItem(it.first, it.second) }) aboutRes?.let { MoreItem(it.first, it.second) })

View File

@ -5,6 +5,8 @@ import io.github.wulkanowy.ui.base.BaseView
interface MoreView : BaseView { interface MoreView : BaseView {
val homeworkRes: Pair<String, Drawable?>?
val noteRes: Pair<String, Drawable?>? val noteRes: Pair<String, Drawable?>?
val settingsRes: Pair<String, Drawable?>? val settingsRes: Pair<String, Drawable?>?
@ -20,5 +22,8 @@ interface MoreView : BaseView {
fun openAboutView() fun openAboutView()
fun popView() fun popView()
fun openHomeworkView()
fun openNoteView() fun openNoteView()
} }

View File

@ -0,0 +1,10 @@
<!--https://materialdesignicons.com/icon/notebook-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000"
android:pathData="M3,7V5H5V4C5,2.89 5.9,2 7,2H13V9L15.5,7.5L18,9V2H19C20.05,2 21,2.95 21,4V20C21,21.05 20.05,22 19,22H7C5.95,22 5,21.05 5,20V19H3V17H5V13H3V11H5V7H3M7,11H5V13H7V11M7,7V5H5V7H7M7,19V17H5V19H7Z" />
</vector>

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:id="@+id/homework_dialog_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:text="@string/all_details"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/all_subject"
android:textSize="17sp" />
<TextView
android:id="@+id/homeworkDialogSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/all_no_data"
android:textIsSelectable="true"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/all_teacher"
android:textSize="17sp" />
<TextView
android:id="@+id/homeworkDialogTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/all_no_data"
android:textIsSelectable="true"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/all_date"
android:textSize="17sp" />
<TextView
android:id="@+id/homeworkDialogDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/all_no_data"
android:textIsSelectable="true"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/all_entry_date"
android:textSize="17sp" />
<TextView
android:id="@+id/homeworkDialogEntryDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/all_no_data"
android:textIsSelectable="true"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/all_content"
android:textSize="17sp" />
<TextView
android:id="@+id/homeworkDialogContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:lineSpacingMultiplier="1.2"
android:text="@string/all_no_data"
android:textIsSelectable="true"
android:textSize="12sp" />
<Button
android:id="@+id/homeworkDialogClose"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="15dp"
android:text="@string/all_close"
android:textAllCaps="true"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>

View File

@ -69,7 +69,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:text="@string/note_content" android:text="@string/all_content"
android:textSize="17sp" /> android:textSize="17sp" />
<TextView <TextView

View File

@ -0,0 +1,96 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp">
<ProgressBar
android:id="@+id/homeworkProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/homeworkSwipe"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/homeworkRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/homeworkEmpty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
android:visibility="gone">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:minHeight="100dp"
app:srcCompat="@drawable/ic_menu_main_homework_24dp"
app:tint="?android:attr/textColorPrimary"
tools:ignore="contentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="@string/homework_no_items"
android:textSize="20sp" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
android:elevation="10dp"
android:orientation="horizontal">
<Button
android:id="@+id/homeworkPreviousButton"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="4dp"
android:gravity="start|center"
android:text="@string/all_prev"
android:textAlignment="gravity" />
<TextView
android:id="@+id/homeworkNavDate"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/app_name" />
<Button
android:id="@+id/homeworkNextButton"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:drawablePadding="4dp"
android:gravity="end|center"
android:text="@string/all_next"
android:textAlignment="gravity" />
</LinearLayout>
</FrameLayout>

View File

@ -0,0 +1,49 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/homework_subitem_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_all_divider"
android:foreground="?attr/selectableItemBackgroundBorderless">
<TextView
android:id="@+id/homeworkItemSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:text="@string/all_date"
android:textSize="17sp" />
<TextView
android:id="@+id/homeworkItemTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:layout_toEndOf="@id/homeworkItemSubject"
android:layout_toRightOf="@id/homeworkItemSubject"
android:gravity="end"
android:text="@string/all_teacher"
android:textSize="13sp" />
<TextView
android:id="@+id/homeworkItemContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/homeworkItemSubject"
android:layout_alignStart="@id/homeworkItemSubject"
android:layout_alignLeft="@id/homeworkItemSubject"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:lineSpacingMultiplier="1.2"
android:text="@string/all_content"
android:textSize="14sp" />
</RelativeLayout>

View File

@ -12,6 +12,7 @@
<string name="more_title">Więcej</string> <string name="more_title">Więcej</string>
<string name="about_title">O aplikacji</string> <string name="about_title">O aplikacji</string>
<string name="note_title">Uwagi i osiągnięcia</string> <string name="note_title">Uwagi i osiągnięcia</string>
<string name="homework_title">Zadania domowe</string>
<!--Login form--> <!--Login form-->
@ -120,7 +121,6 @@
<!--Note--> <!--Note-->
<string name="note_no_items">Brak informacji o uwagach</string> <string name="note_no_items">Brak informacji o uwagach</string>
<string name="note_content">Treść</string>
<plurals name="note_number_item"> <plurals name="note_number_item">
<item quantity="one">%d uwaga</item> <item quantity="one">%d uwaga</item>
<item quantity="few">%d uwagi</item> <item quantity="few">%d uwagi</item>
@ -136,11 +136,17 @@
</plurals> </plurals>
<!--Homework-->
<string name="homework_no_items">Brak zadań domowych</string>
<!--Generic--> <!--Generic-->
<string name="all_content">Treść</string>
<string name="all_description">Opis</string> <string name="all_description">Opis</string>
<string name="all_no_description">Brak opisu</string> <string name="all_no_description">Brak opisu</string>
<string name="all_teacher">Nauczyciel</string> <string name="all_teacher">Nauczyciel</string>
<string name="all_date">Data</string> <string name="all_date">Data</string>
<string name="all_entry_date">Data wpisu</string>
<string name="all_color">Kolor</string> <string name="all_color">Kolor</string>
<string name="all_details">Szczegóły</string> <string name="all_details">Szczegóły</string>
<string name="all_category">Kategoria</string> <string name="all_category">Kategoria</string>

View File

@ -12,6 +12,7 @@
<string name="more_title">More</string> <string name="more_title">More</string>
<string name="about_title">About</string> <string name="about_title">About</string>
<string name="note_title">Notes and achievements</string> <string name="note_title">Notes and achievements</string>
<string name="homework_title">Homework</string>
<!--Login form--> <!--Login form-->
@ -109,7 +110,6 @@
<!--Note--> <!--Note-->
<string name="note_no_items">No info about notes</string> <string name="note_no_items">No info about notes</string>
<string name="note_content">Content</string>
<plurals name="note_number_item"> <plurals name="note_number_item">
<item quantity="one">%d note</item> <item quantity="one">%d note</item>
<item quantity="other">%d notes</item> <item quantity="other">%d notes</item>
@ -121,11 +121,17 @@
</plurals> </plurals>
<!--Homework-->
<string name="homework_no_items">No info about homework</string>
<!--Generic--> <!--Generic-->
<string name="all_content">Content</string>
<string name="all_description">Description</string> <string name="all_description">Description</string>
<string name="all_no_description">No description</string> <string name="all_no_description">No description</string>
<string name="all_teacher">Teacher</string> <string name="all_teacher">Teacher</string>
<string name="all_date">Date</string> <string name="all_date">Date</string>
<string name="all_entry_date">Entry date</string>
<string name="all_color">Color</string> <string name="all_color">Color</string>
<string name="all_details">Details</string> <string name="all_details">Details</string>
<string name="all_category">Category</string> <string name="all_category">Category</string>