Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/bible/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package="nl.plaatsoft.bible">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application android:allowBackup="true"
android:label="@string/app_name"
Expand All @@ -26,6 +28,10 @@
android:windowSoftInputMode="stateVisible|adjustResize"
android:exported="false" />

<service android:name=".services.DailyVerseService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true" />

<activity android:name=".activities.SettingsActivity"
android:parentActivityName=".activities.MainActivity"
android:launchMode="singleTop"
Expand Down
4 changes: 4 additions & 0 deletions bin/bible/res/drawable-anydpi/ic_bell.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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="@color/icon_color" android:pathData="M21,19V20H3V19L5,17V11C5,7.9 7.03,5.17 10,4.29C10,4.19 10,4.1 10,4A2,2 0 0,1 12,2A2,2 0 0,1 14,4C14,4.1 14,4.19 14,4.29C16.97,5.17 19,7.9 19,11V17L21,19M14,21A2,2 0 0,1 12,23A2,2 0 0,1 10,21"/>
</vector>
4 changes: 4 additions & 0 deletions bin/bible/res/drawable-anydpi/ic_book_cross.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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="@color/icon_color" android:pathData="M5.81,2H7V9L9.5,7.5L12,9V2H18A2,2 0 0,1 20,4V20C20,21.05 19.05,22 18,22H6C4.95,22 4,21.05 4,20V4C4,3 4.83,2.09 5.81,2M13,10V13H10V15H13V20H15V15H18V13H15V10H13Z"/>
</vector>
19 changes: 19 additions & 0 deletions bin/bible/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@
</LinearLayout>
</LinearLayout>

<TextView android:text="@string/settings_notifications_label"
style="@style/ListItemSubtitle"/>

<LinearLayout style="@style/ListGroup">
<!-- Daily notification button -->
<LinearLayout android:id="@+id/settings_daily_notification_button"
style="@style/ListItemButton">

<ImageView android:src="@drawable/ic_bell"
style="@style/ListItemButtonIcon" />

<TextView android:text="@string/settings_daily_notification_button"
style="@style/ListItemButtonLabel" />

<Switch android:id="@+id/settings_daily_notification_switch"
style="@style/ListItemButtonSwitch" />
</LinearLayout>
</LinearLayout>

<TextView android:text="@string/settings_information_label"
style="@style/ListItemSubtitle" />

Expand Down
6 changes: 6 additions & 0 deletions bin/bible/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<!-- Settings activity -->
<string name="settings_title_label">Einstellungen</string>

<string name="settings_notifications_label">Benachrichtigungen</string>

<string name="settings_daily_notification_button">Tägliche Vers-Benachrichtigung</string>

<string name="notification_channel_name">Täglicher Vers</string>

<string name="settings_display_label">Anzeige</string>

<string name="settings_font_button">Schriftart</string>
Expand Down
6 changes: 6 additions & 0 deletions bin/bible/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<!-- Settings activity -->
<string name="settings_title_label">Instellingen</string>

<string name="settings_notifications_label">Meldingen</string>

<string name="settings_daily_notification_button">Dagelijkse vers melding</string>

<string name="notification_channel_name">Dagelijks vers</string>

<string name="settings_display_label">Weergave</string>

<string name="settings_font_button">Lettertype</string>
Expand Down
6 changes: 6 additions & 0 deletions bin/bible/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<!-- Settings activity -->
<string name="settings_title_label">Settings</string>

<string name="settings_notifications_label">Notifications</string>

<string name="settings_daily_notification_button">Daily verse notification</string>

<string name="notification_channel_name">Daily Verse</string>

<string name="settings_display_label">Display</string>

<string name="settings_font_button">Font</string>
Expand Down
5 changes: 5 additions & 0 deletions bin/bible/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
<item name="android:textColor">@color/secondary_text_color</item>
</style>

<style name="ListItemButtonSwitch">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>

<style name="ListItemFooter" parent="ListItem">
<item name="android:textColor">@color/secondary_text_color</item>
</style>
Expand Down
13 changes: 12 additions & 1 deletion bin/bible/src/nl/plaatsoft/bible/Settings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024-2025 Bastiaan van der Plaat
* Copyright (c) 2024-2026 Bastiaan van der Plaat
*
* SPDX-License-Identifier: MIT
*/
Expand Down Expand Up @@ -75,6 +75,17 @@ public void setFont(int font) {
prefs.edit().putInt("font", font).apply();
}

// Daily notification
public boolean isDailyNotification() {
return prefs.getBoolean("daily_notification", false);
}

public void setDailyNotification(boolean dailyNotification) {
if (isDailyNotification() == dailyNotification)
return;
prefs.edit().putBoolean("daily_notification", dailyNotification).apply();
}

// Installed assets version
public String getInstalledAssetsVersion() {
return prefs.getString("installed_assets_version", "");
Expand Down
38 changes: 37 additions & 1 deletion bin/bible/src/nl/plaatsoft/bible/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import nl.plaatsoft.bible.models.SongWithText;
import nl.plaatsoft.bible.models.Verse;
import nl.plaatsoft.bible.services.BibleService;
import nl.plaatsoft.bible.services.DailyVerseService;
import nl.plaatsoft.bible.services.SongBundleService;
import nl.plaatsoft.bible.views.BooksDialogBuilder;
import nl.plaatsoft.bible.views.ChapterView;
Expand Down Expand Up @@ -249,7 +250,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

bibles = bibleService.getInstalledBibles(this);
songBundles = songBundleService.getInstalledSongBundles(this);
handler.post(() -> openFromSettings());
handler.post(() -> {
openFromSettings();
handleNotificationIntent(getIntent());
});
};
installAssetsAndOpen.run();

Expand All @@ -259,6 +263,38 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
SettingsActivity.STORE_PAGE_URL);
}

@Override
public void onNewIntent(@SuppressWarnings("null") Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleNotificationIntent(intent);
}

private void handleNotificationIntent(@Nullable Intent intent) {
if (intent == null)
return;
var bookKey = intent.getStringExtra(DailyVerseService.NOTIFICATION_BOOK_KEY);
if (bookKey == null)
return;
var chapterNumber = intent.getIntExtra(DailyVerseService.NOTIFICATION_CHAPTER_NUMBER, 1);
var verseId = intent.getIntExtra(DailyVerseService.NOTIFICATION_VERSE_ID, -1);
settings.setOpenType(Settings.OPEN_TYPE_BIBLE);
openBible = bibleService.readBible(this, settings.getOpenBible(), true);
// Find the book and open the chapter with verse highlight
for (var testament : Objects.requireNonNull(openBible).testaments()) {
for (var book : testament.books()) {
if (book.key().equals(bookKey)) {
for (var chapter : book.chapters()) {
if (chapter.number() == chapterNumber) {
openChapter(book, chapter, 0, verseId);
return;
}
}
}
}
}
}

@Override
public boolean onMenuItemClick(@SuppressWarnings("null") MenuItem item) {
if (item.getItemId() == R.id.menu_options_last_open_chapter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024-2025 Bastiaan van der Plaat
* Copyright (c) 2024-2026 Bastiaan van der Plaat
*
* SPDX-License-Identifier: MIT
*/
Expand All @@ -10,16 +10,21 @@

import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import nl.plaatsoft.bible.R;
import nl.plaatsoft.bible.Settings;
import nl.plaatsoft.bible.services.DailyVerseService;

import org.jspecify.annotations.Nullable;

Expand Down Expand Up @@ -114,6 +119,28 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
alertDialog.getListView().setPadding(0, 0, 0, (int)(16 * density));
});

// Daily notification switch
var dailyNotificationSwitch = (Switch)findViewById(R.id.settings_daily_notification_switch);
dailyNotificationSwitch.setChecked(settings.isDailyNotification());
dailyNotificationSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
if (isChecked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS)
!= PackageManager.PERMISSION_GRANTED) {
buttonView.setChecked(false);
requestPermissions(new String[] {android.Manifest.permission.POST_NOTIFICATIONS}, 0);
return;
}
}
settings.setDailyNotification(isChecked);
if (isChecked) {
DailyVerseService.schedule(this);
} else {
DailyVerseService.cancel(this);
}
});
((LinearLayout)findViewById(R.id.settings_daily_notification_button))
.setOnClickListener(v -> dailyNotificationSwitch.toggle());

// Version button easter egg
try {
((TextView)findViewById(R.id.settings_version_label))
Expand Down Expand Up @@ -161,4 +188,12 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(ABOUT_WEBSITE_URL)));
});
}

@Override
public void onRequestPermissionsResult(
int requestCode, @SuppressWarnings("null") String[] permissions, @SuppressWarnings("null") int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
((Switch)findViewById(R.id.settings_daily_notification_switch)).setChecked(true);
}
}
}
Loading