This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from schul-cloud/15-add-submission-support
15 add submission support
- Loading branch information
Showing
65 changed files
with
1,416 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
app/src/main/java/org/schulcloud/mobile/controllers/dashboard/Widget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package org.schulcloud.mobile.controllers.dashboard | ||
|
||
import androidx.fragment.app.Fragment | ||
import org.schulcloud.mobile.controllers.main.Refreshable | ||
import org.schulcloud.mobile.controllers.main.RefreshableImpl | ||
|
||
open class Widget : Fragment() { | ||
open suspend fun refresh() {} | ||
abstract class Widget(refreshableImpl: RefreshableImpl = RefreshableImpl()) : Fragment(), | ||
Refreshable by refreshableImpl { | ||
init { | ||
refreshableImpl.refresh = { refresh() } | ||
} | ||
|
||
abstract suspend fun refresh() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...src/main/java/org/schulcloud/mobile/controllers/homework/detailed/HomeworkPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.schulcloud.mobile.controllers.homework.detailed | ||
|
||
import android.content.Context | ||
import androidx.annotation.IntDef | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.fragment.app.FragmentPagerAdapter | ||
import org.schulcloud.mobile.R | ||
import org.schulcloud.mobile.models.homework.Homework | ||
import kotlin.properties.Delegates | ||
|
||
|
||
class HomeworkPagerAdapter(private val context: Context, fm: FragmentManager) : FragmentPagerAdapter(fm) { | ||
companion object { | ||
private const val TAB_INVALID = 0 | ||
private const val TAB_DETAILS = 1 | ||
private const val TAB_SUBMISSIONS = 2 | ||
|
||
@Retention(AnnotationRetention.SOURCE) | ||
@MustBeDocumented | ||
@IntDef(TAB_INVALID, TAB_DETAILS, TAB_SUBMISSIONS) | ||
annotation class Tab | ||
} | ||
|
||
var homework by Delegates.observable<Homework?>(null) { _, _, _ -> | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getItem(position: Int): Fragment? { | ||
return when (getTabType(position)) { | ||
TAB_DETAILS -> OverviewFragment() | ||
TAB_SUBMISSIONS -> SubmissionsFragment() | ||
|
||
TAB_INVALID -> null | ||
else -> null | ||
} | ||
} | ||
|
||
override fun getPageTitle(position: Int): CharSequence? { | ||
val titleId = when (getTabType(position)) { | ||
TAB_DETAILS -> R.string.homework_overview | ||
TAB_SUBMISSIONS -> R.string.homework_submissions | ||
|
||
TAB_INVALID -> return null | ||
else -> return null | ||
} | ||
return context.getString(titleId) | ||
} | ||
|
||
override fun getCount(): Int { | ||
return if (homework?.canSeeSubmissions() == true) 2 | ||
else 1 | ||
} | ||
|
||
@Tab | ||
private fun getTabType(position: Int): Int { | ||
return when { | ||
position == 0 -> TAB_DETAILS | ||
position == 1 && homework?.canSeeSubmissions() == true -> TAB_SUBMISSIONS | ||
else -> TAB_INVALID | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/org/schulcloud/mobile/controllers/homework/detailed/OverviewFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.schulcloud.mobile.controllers.homework.detailed | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.navigation.fragment.NavHostFragment | ||
import kotlinx.android.synthetic.main.fragment_homework_overview.* | ||
import org.schulcloud.mobile.R | ||
import org.schulcloud.mobile.controllers.homework.submission.SubmissionFragmentArgs | ||
import org.schulcloud.mobile.controllers.main.ParentFragment | ||
import org.schulcloud.mobile.controllers.main.TabFragment | ||
import org.schulcloud.mobile.databinding.FragmentHomeworkOverviewBinding | ||
import org.schulcloud.mobile.viewmodels.HomeworkViewModel | ||
|
||
|
||
class OverviewFragment : TabFragment<HomeworkFragment, HomeworkViewModel>() { | ||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return FragmentHomeworkOverviewBinding.inflate(layoutInflater).also { | ||
it.viewModel = viewModel | ||
it.setLifecycleOwner(this) | ||
}.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
gotoMySubmission.setOnClickListener { | ||
viewModel.mySubmission.value?.id?.also { | ||
NavHostFragment.findNavController(this).navigate( | ||
R.id.action_global_fragment_submission, | ||
SubmissionFragmentArgs.Builder(it).build().toBundle()) | ||
} | ||
} | ||
} | ||
|
||
override suspend fun refresh() { | ||
(parentFragment as? ParentFragment)?.refreshWithChild(true) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/org/schulcloud/mobile/controllers/homework/detailed/SubmissionsAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.schulcloud.mobile.controllers.homework.detailed | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import org.schulcloud.mobile.controllers.base.BaseAdapter | ||
import org.schulcloud.mobile.controllers.base.BaseViewHolder | ||
import org.schulcloud.mobile.databinding.ItemSubmissionBinding | ||
import org.schulcloud.mobile.models.homework.submission.Submission | ||
import org.schulcloud.mobile.models.user.User | ||
|
||
|
||
class SubmissionsAdapter(private val onSelected: (String) -> Unit) : | ||
BaseAdapter<Pair<User, Submission?>, SubmissionsAdapter.SubmissionViewHolder, ItemSubmissionBinding>() { | ||
|
||
fun update(submissions: List<Pair<User, Submission?>>) { | ||
items = submissions | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubmissionViewHolder { | ||
val binding = ItemSubmissionBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
binding.onSelected = onSelected | ||
return SubmissionViewHolder(binding) | ||
} | ||
|
||
|
||
inner class SubmissionViewHolder(binding: ItemSubmissionBinding) : | ||
BaseViewHolder<Pair<User, Submission?>, ItemSubmissionBinding>(binding) { | ||
override fun onItemSet() { | ||
binding.student = item.first | ||
binding.submission = item.second | ||
} | ||
} | ||
} |
Oops, something went wrong.