Merge pull request #1011 from Bnyro/master

break reminder
This commit is contained in:
Bnyro 2022-08-10 17:02:11 +02:00 committed by GitHub
commit 70b5dcf4fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import android.widget.LinearLayout
import android.widget.Toast
import androidx.appcompat.widget.SearchView
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.widget.ConstraintLayout
@ -39,6 +40,7 @@ import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.CronetHelper
import com.github.libretube.util.LocaleHelper
import com.github.libretube.util.ThemeHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.elevation.SurfaceColors
import com.google.android.material.navigation.NavigationBarView
@ -163,6 +165,40 @@ class MainActivity : BaseActivity() {
*/
val log = PreferenceHelper.getErrorLog()
if (log != "") ErrorDialog().show(supportFragmentManager, null)
setupBreakReminder()
}
/**
* Show a break reminder when watched too long
*/
private fun setupBreakReminder() {
val breakReminderPref = PreferenceHelper.getString(
PreferenceKeys.BREAK_REMINDER,
"disabled"
)
if (breakReminderPref == "disabled") return
Handler(Looper.getMainLooper()).postDelayed(
{
try {
MaterialAlertDialogBuilder(this)
.setTitle(getString(R.string.share_with_time))
.setMessage(
getString(
R.string.already_spent_time,
breakReminderPref
)
)
.setPositiveButton(R.string.okay, null)
.show()
} catch (e: Exception) {
kotlin.runCatching {
Toast.makeText(this, R.string.take_a_break, Toast.LENGTH_LONG).show()
}
}
},
breakReminderPref.toLong() * 60 * 1000
)
}
private fun removeSearchFocus() {

View File

@ -37,5 +37,12 @@ class GeneralSettings : MaterialPreferenceFragment() {
restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name)
true
}
val breakReminder = findPreference<ListPreference>(PreferenceKeys.BREAK_REMINDER)
breakReminder?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name)
true
}
}
}

View File

@ -10,6 +10,7 @@ object PreferenceKeys {
const val LANGUAGE = "language"
const val REGION = "region"
const val AUTO_ROTATION = "auto_rotation"
const val BREAK_REMINDER = "break_reminder"
/**
* Appearance

View File

@ -828,4 +828,22 @@
<item>unlimited</item>
</string-array>
<string-array name="breakReminder">
<item>@string/disabled</item>
<item>15 min</item>
<item>30 min</item>
<item>60 min</item>
<item>90 min</item>
<item>120 min</item>
</string-array>
<string-array name="breakReminderValues">
<item>disabled</item>
<item>15</item>
<item>30</item>
<item>60</item>
<item>90</item>
<item>120</item>
</string-array>
</resources>

View File

@ -298,4 +298,8 @@
<string name="unlimited">Unlimited</string>
<string name="background_mode">Background mode</string>
<string name="add_to_queue">Add to queue</string>
<string name="misc">Misc</string>
<string name="break_reminder">Break reminder</string>
<string name="take_a_break">Time to take a break</string>
<string name="already_spent_time">You already spent %1$s minutes in the app, time to take a break.</string>
</resources>

View File

@ -61,4 +61,17 @@
</PreferenceCategory>
<PreferenceCategory app:title="@string/misc">
<ListPreference
android:icon="@drawable/ic_time"
app:defaultValue="disabled"
app:entries="@array/breakReminder"
app:entryValues="@array/breakReminderValues"
app:key="break_reminder"
app:title="@string/break_reminder"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
</PreferenceScreen>