mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 02:39:34 +02:00
Add introduction at time limit rule screen
This commit is contained in:
parent
2913a72217
commit
f89974b561
7 changed files with 112 additions and 7 deletions
|
@ -117,4 +117,5 @@ object HintsToShow {
|
|||
const val OVERVIEW_INTRODUCTION = 1L
|
||||
const val DEVICE_SCREEN_INTRODUCTION = 2L
|
||||
const val CATEGORIES_INTRODUCTION = 4L
|
||||
const val TIME_LIMIT_RULE_INTRODUCTION = 8L
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import io.timelimit.android.R
|
|||
import io.timelimit.android.data.model.TimeLimitRule
|
||||
import io.timelimit.android.databinding.AddItemViewBinding
|
||||
import io.timelimit.android.databinding.FragmentCategoryTimeLimitRuleItemBinding
|
||||
import io.timelimit.android.databinding.TimeLimitRuleIntroductionBinding
|
||||
import io.timelimit.android.util.JoinUtil
|
||||
import io.timelimit.android.util.TimeTextUtil
|
||||
import kotlin.properties.Delegates
|
||||
|
@ -31,6 +32,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
companion object {
|
||||
private const val TYPE_ITEM = 1
|
||||
private const val TYPE_ADD = 2
|
||||
private const val TYPE_INTRO = 3
|
||||
}
|
||||
|
||||
var data: List<TimeLimitRuleItem> by Delegates.observable(emptyList()) { _, _, _ -> notifyDataSetChanged() }
|
||||
|
@ -58,6 +60,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
override fun getItemViewType(position: Int) = when (getItem(position)) {
|
||||
AddTimeLimitRuleItem -> TYPE_ADD
|
||||
is TimeLimitRuleRuleItem -> TYPE_ITEM
|
||||
TimeLimitRuleIntroductionItem -> TYPE_INTRO
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
|
||||
|
@ -82,6 +85,19 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
}.root
|
||||
)
|
||||
}
|
||||
TYPE_INTRO -> {
|
||||
ViewHolder(
|
||||
TimeLimitRuleIntroductionBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
).apply {
|
||||
okButton.setOnClickListener {
|
||||
handlers?.onConfirmIntroduction()
|
||||
}
|
||||
}.root
|
||||
)
|
||||
}
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
|
||||
|
@ -92,6 +108,9 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
AddTimeLimitRuleItem -> {
|
||||
// nothing to do
|
||||
}
|
||||
is TimeLimitRuleIntroductionItem -> {
|
||||
// nothing to do
|
||||
}
|
||||
is TimeLimitRuleRuleItem -> {
|
||||
val rule = item.rule
|
||||
val binding = (holder as ItemViewHolder).view
|
||||
|
@ -119,7 +138,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
}.let { /* require handling all paths */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,4 +148,5 @@ class ItemViewHolder(val view: FragmentCategoryTimeLimitRuleItemBinding): ViewHo
|
|||
interface Handlers {
|
||||
fun onTimeLimitRuleClicked(rule: TimeLimitRule)
|
||||
fun onAddTimeLimitRuleClicked()
|
||||
fun onConfirmIntroduction()
|
||||
}
|
||||
|
|
|
@ -25,8 +25,10 @@ import androidx.lifecycle.Observer
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import io.timelimit.android.R
|
||||
import io.timelimit.android.async.Threads
|
||||
import io.timelimit.android.data.Database
|
||||
import io.timelimit.android.data.extensions.getDateLive
|
||||
import io.timelimit.android.data.model.HintsToShow
|
||||
import io.timelimit.android.data.model.TimeLimitRule
|
||||
import io.timelimit.android.livedata.map
|
||||
import io.timelimit.android.livedata.switchMap
|
||||
|
@ -79,13 +81,23 @@ class CategoryTimeLimitRulesFragment : Fragment(), EditTimeLimitRuleDialogFragme
|
|||
)
|
||||
}
|
||||
|
||||
rules
|
||||
.map { rules ->
|
||||
rules.sortedBy { it.dayMask }.map { TimeLimitRuleRuleItem(it) }
|
||||
val hasHiddenIntro = database.config().wereHintsShown(HintsToShow.TIME_LIMIT_RULE_INTRODUCTION)
|
||||
|
||||
rules.map { rules ->
|
||||
rules.sortedBy { it.dayMask }.map { TimeLimitRuleRuleItem(it) }
|
||||
}.switchMap {
|
||||
val baseList = it + listOf(AddTimeLimitRuleItem)
|
||||
|
||||
hasHiddenIntro.map { hasHiddenIntro ->
|
||||
if (hasHiddenIntro) {
|
||||
baseList
|
||||
} else {
|
||||
listOf(TimeLimitRuleIntroductionItem) + baseList
|
||||
}
|
||||
.observe(this, Observer {
|
||||
adapter.data = it + listOf(AddTimeLimitRuleItem)
|
||||
})
|
||||
}
|
||||
}.observe(this, Observer {
|
||||
adapter.data = it
|
||||
})
|
||||
|
||||
usedTimeItems.observe(this, Observer {
|
||||
usedTimes ->
|
||||
|
@ -105,6 +117,12 @@ class CategoryTimeLimitRulesFragment : Fragment(), EditTimeLimitRuleDialogFragme
|
|||
EditTimeLimitRuleDialogFragment.newInstance(params.categoryId, this@CategoryTimeLimitRulesFragment).show(fragmentManager!!)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfirmIntroduction() {
|
||||
Threads.database.execute {
|
||||
database.config().setHintsShownSync(HintsToShow.TIME_LIMIT_RULE_INTRODUCTION)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ import io.timelimit.android.data.model.TimeLimitRule
|
|||
|
||||
sealed class TimeLimitRuleItem
|
||||
object AddTimeLimitRuleItem: TimeLimitRuleItem()
|
||||
object TimeLimitRuleIntroductionItem: TimeLimitRuleItem()
|
||||
data class TimeLimitRuleRuleItem(val rule: TimeLimitRule): TimeLimitRuleItem()
|
51
app/src/main/res/layout/time_limit_rule_introduction.xml
Normal file
51
app/src/main/res/layout/time_limit_rule_introduction.xml
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Open TimeLimit Copyright <C> 2019 Jonas Lochmann
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<androidx.cardview.widget.CardView
|
||||
app:cardUseCompatPadding="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:textAppearance="?android:textAppearanceLarge"
|
||||
android:text="@string/category_time_limit_rules"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:text="@string/category_time_limit_rules_about"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/ok_button"
|
||||
android:text="@string/generic_ok"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_gravity="end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
</layout>
|
|
@ -16,6 +16,13 @@
|
|||
-->
|
||||
<resources>
|
||||
<string name="category_time_limit_rules">Zeitbegrenzungen</string>
|
||||
<string name="category_time_limit_rules_about">
|
||||
Hier können Sie Zeitbegrenzungsregeln einstellen.
|
||||
Jede Regel entspricht einem Grenzwert.
|
||||
Regeln, bei denen mehrere Tage gewählt wurden,
|
||||
begrenzen die Gesamtnutzungsdauer in einer Woche an den gewählten Tagen.
|
||||
Regeln, bei denen nur ein Tag gewählt wurde, begrenzen nur diesen Tag.
|
||||
</string>
|
||||
<string name="category_time_limit_rules_applied_to_extra_time">gilt auch für ggf. vorhandene Extra-Zeit</string>
|
||||
<string name="category_time_limit_rule_dialog_new">Regel erstellen</string>
|
||||
<string name="category_time_limit_rule_dialog_edit">Regel bearbeiten</string>
|
||||
|
|
|
@ -16,6 +16,13 @@
|
|||
-->
|
||||
<resources>
|
||||
<string name="category_time_limit_rules">time limit rules</string>
|
||||
<string name="category_time_limit_rules_about">
|
||||
Here you can configure time limit rules.
|
||||
Every rule describes one limit.
|
||||
Rules at which multiple days are checked
|
||||
limit the total usage duration during a week at all selected days.
|
||||
Rules at which only one day is checked only limit the selected day.
|
||||
</string>
|
||||
<string name="category_time_limit_rules_applied_to_extra_time">is applied to extra time, too</string>
|
||||
<string name="category_time_limit_rule_dialog_new">Create rule</string>
|
||||
<string name="category_time_limit_rule_dialog_edit">Edit rule</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue