Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit c48b7bd

Browse files
committed
finished work on note notifications, updated info page and other changes
1 parent 8d9935b commit c48b7bd

File tree

17 files changed

+307
-197
lines changed

17 files changed

+307
-197
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
applicationId "com.jjewuz.justnotes"
1515
minSdk 30
1616
targetSdk 35
17-
versionCode 184
18-
versionName "5.6.3"
17+
versionCode 200
18+
versionName "5.7.0"
1919

2020
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2121

app/release/output-metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"type": "SINGLE",
1212
"filters": [],
1313
"attributes": [],
14-
"versionCode": 183,
15-
"versionName": "5.6.2",
14+
"versionCode": 184,
15+
"versionName": "5.6.3",
1616
"outputFile": "app-release.apk"
1717
}
1818
],

app/src/main/AndroidManifest.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
1414
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1515
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
16+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
17+
1618

1719
<queries>
1820
<package android:name="com.jjewuz.justnotes" />
@@ -42,7 +44,13 @@
4244
android:exported="false" />
4345

4446
<receiver android:name=".Notifications.NotificationReceiver"
45-
android:enabled="true"/>
47+
android:enabled="true"
48+
android:exported="false">
49+
<intent-filter>
50+
<action android:name="com.jjewuz.NOTIFICATION_DELETED" />
51+
<action android:name="com.jjewuz.NOTIFICATION_HIDE" />
52+
</intent-filter>
53+
</receiver>
4654

4755
<receiver
4856
android:name=".Notes.NoteWidget"
@@ -85,6 +93,14 @@
8593
android:resource="@xml/shortcuts" />
8694
</activity>
8795

96+
<service
97+
android:name=".Utils.Utils$PersistentService"
98+
android:foregroundServiceType="specialUse"
99+
android:exported="false"
100+
android:enabled="true"
101+
android:permission="android.permission.FOREGROUND_SERVICE" />
102+
103+
88104
<service
89105
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
90106
android:enabled="false">

app/src/main/java/com/jjewuz/justnotes/Activities/AddEditNoteActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.jjewuz.justnotes.Activities
22

33

44
import android.app.Activity
5+
import android.app.NotificationManager
56
import android.appwidget.AppWidgetManager
67
import android.content.ComponentName
78
import android.content.ContentValues

app/src/main/java/com/jjewuz/justnotes/Activities/InfoActivity.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import com.jjewuz.justnotes.R
1818

1919
class InfoActivity : AppCompatActivity() {
2020

21-
private lateinit var ghBtn: LinearLayout
22-
private lateinit var sourceBtn: LinearLayout
23-
private lateinit var siteBtn: LinearLayout
24-
private lateinit var weblateBtn: LinearLayout
21+
private lateinit var siteProfile: Button
22+
private lateinit var ghBtn: Button
23+
private lateinit var sourceBtn: Button
24+
private lateinit var siteBtn: Button
25+
private lateinit var weblateBtn: Button
2526
private lateinit var licenseBtn: Button
2627

2728
private lateinit var tou: Button
@@ -59,6 +60,7 @@ class InfoActivity : AppCompatActivity() {
5960
supportActionBar?.setDisplayHomeAsUpEnabled(true)
6061
enableEdgeToEdge()
6162

63+
siteProfile = findViewById(R.id.profile_site)
6264
ghBtn = findViewById(R.id.github_profile)
6365
sourceBtn = findViewById(R.id.github_code)
6466
siteBtn = findViewById(R.id.site)
@@ -75,13 +77,14 @@ class InfoActivity : AppCompatActivity() {
7577
versionTxt.text = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
7678

7779
ghBtn.setOnClickListener { openLink("https://github.com/jjewuz/JustNotes") }
80+
siteProfile.setOnClickListener{ openLink("https://jjewuz.com") }
7881
sourceBtn.setOnClickListener { openLink("https://github.com/jjewuz") }
7982
siteBtn.setOnClickListener{ openLink("https://jjewuz.com/justnotes.html") }
8083
weblateBtn.setOnClickListener {openLink("https://hosted.weblate.org/engage/justnotes/")}
8184
licenseBtn.setOnClickListener { startActivity(Intent(this, OssLicensesMenuActivity::class.java)) }
82-
tou.setOnClickListener { openLink("https://jjewuz.com/justnotes/termsofuse.html") }
83-
pp.setOnClickListener { openLink("https://jjewuz.com/justnotes/privacypolicy.html") }
84-
tgBtn.setOnClickListener { openLink("https://t.me/jjewuz_support") }
85+
tou.setOnClickListener { openLink("https://jjewuz.com/en/justnotes/termsofuse.html") }
86+
pp.setOnClickListener { openLink("https://jjewuz.com/en/justnotes/privacypolicy.html") }
87+
tgBtn.setOnClickListener { openLink("https://t.me/jjewuz") }
8588
vkBtn.setOnClickListener { openLink("https://vk.com/jjewuzhub") }
8689

8790

app/src/main/java/com/jjewuz/justnotes/Activities/MainActivity.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ class ModalBottomSheet: BottomSheetDialogFragment(){
9191
val notesCountText = view.findViewById<TextView>(R.id.notes_count)
9292
val notesText = resources.getString(R.string.total_notes)
9393
val lastBackupText = view.findViewById<TextView>(R.id.last_backup)
94-
val jmCard = view.findViewById<MaterialCardView>(R.id.ad_card)
95-
jmCard.setOnClickListener{
96-
val url = "https://play.google.com/store/apps/details?id=com.jjewuz.executor"
97-
val i = Intent(Intent.ACTION_VIEW, Uri.parse(url))
98-
startActivity(i)
99-
}
10094

10195
viewModel.getNotes().observe(this, Observer { notes ->
10296
val notesCount = notes.size
@@ -579,9 +573,9 @@ class MainActivity : AppCompatActivity() {
579573
val builder = MaterialAlertDialogBuilder(this)
580574
val inflater = this.layoutInflater.inflate(R.layout.contions, null)
581575
val tou = inflater.findViewById<Button>(R.id.terms_of_use)
582-
tou.setOnClickListener { openLink("https://jjewuz.ru/justnotes/termsofuse.html") }
576+
tou.setOnClickListener { openLink("https://jjewuz.ru/en/justnotes/termsofuse.html") }
583577
val pp = inflater.findViewById<Button>(R.id.privacy_policy)
584-
pp.setOnClickListener { openLink("https://jjewuz.ru/justnotes/privacypolicy.html") }
578+
pp.setOnClickListener { openLink("https://jjewuz.ru/en/justnotes/privacypolicy.html") }
585579
builder.setView(inflater)
586580
.setTitle(R.string.agreement)
587581
.setIcon(R.drawable.info)

app/src/main/java/com/jjewuz/justnotes/Fragments/NotesFragment.kt

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package com.jjewuz.justnotes.Fragments
22

33
import android.app.NotificationManager
44
import android.app.PendingIntent
5+
import android.app.Service
56
import android.appwidget.AppWidgetManager
67
import android.content.ComponentName
78
import android.content.Context
89
import android.content.Intent
910
import android.content.SharedPreferences
1011
import android.os.Build
1112
import android.os.Bundle
13+
import android.os.IBinder
1214
import android.text.Html
1315
import android.text.Spanned
1416
import android.view.LayoutInflater
@@ -22,6 +24,7 @@ import android.widget.SearchView
2224
import android.widget.TextView
2325
import android.widget.Toast
2426
import androidx.core.app.NotificationCompat
27+
import androidx.core.content.ContextCompat
2528
import androidx.core.content.res.ResourcesCompat
2629
import androidx.core.view.ViewCompat
2730
import androidx.core.view.WindowInsetsCompat
@@ -53,6 +56,7 @@ import com.jjewuz.justnotes.Notes.NoteWidget
5356
import com.jjewuz.justnotes.R
5457
import com.jjewuz.justnotes.Utils.OnSwipeTouchListener
5558
import com.jjewuz.justnotes.Utils.Utils
59+
import com.jjewuz.justnotes.Utils.Utils.fromHtml
5660

5761
class NotesFragment : Fragment(), NoteClickInterface, NoteLongClickInterface {
5862
lateinit var viewModal: NoteViewModal
@@ -339,7 +343,7 @@ class NotesFragment : Fragment(), NoteClickInterface, NoteLongClickInterface {
339343
editor.cancel()
340344
}
341345
notify.setOnClickListener {
342-
sendNotification(requireContext(), note)
346+
startPersistentNotification(requireContext(), note)
343347
Toast.makeText(requireContext(), "Notification sent", Toast.LENGTH_SHORT).show()
344348
editor.cancel()
345349
}
@@ -369,50 +373,28 @@ class NotesFragment : Fragment(), NoteClickInterface, NoteLongClickInterface {
369373
}
370374
}
371375

372-
private fun sendNotification(context: Context, note: Note) {
373-
val notificationId = note.id
374-
val notificationManager =
375-
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
376+
private fun startPersistentNotification(context: Context, note: Note) {
376377

377-
// Создаем Intent для открытия AddEditNoteActivity
378-
val intent = Intent(context, AddEditNoteActivity::class.java).apply {
379-
putExtra("noteType", "Edit")
378+
val spannedContent =
379+
Html.fromHtml(note.noteDescription, Html.FROM_HTML_MODE_COMPACT).toString()
380+
val content = if (spannedContent.length > 100) {
381+
"${spannedContent.take(150)}..."
382+
} else {
383+
spannedContent
384+
}
385+
386+
val serviceIntent = Intent(context, Utils.PersistentService::class.java).apply {
380387
putExtra("noteId", note.id)
388+
putExtra(Utils.PersistentService.NOTE_ID_KEY, note.id)
389+
putExtra(Utils.PersistentService.NOTE_LABEL_ID, note.categoryId ?: 0)
381390
putExtra("noteTitle", note.noteTitle)
382391
putExtra("noteDescription", note.noteDescription)
383392
putExtra("timestamp", note.timeStamp)
384393
putExtra("categoryId", note.categoryId ?: 0)
385394
putExtra("security", note.security)
386-
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
387395
}
388-
389-
val pendingIntent = PendingIntent.getActivity(
390-
context,
391-
notificationId,
392-
intent,
393-
PendingIntent.FLAG_IMMUTABLE
394-
)
395-
396-
val spannedContent = Html.fromHtml(note.noteDescription, Html.FROM_HTML_MODE_COMPACT).toString()
397-
val content = if (spannedContent.length > 50) {
398-
"${spannedContent.take(50)}..."
399-
} else {
400-
spannedContent
401-
}
402-
403-
val notification = NotificationCompat.Builder(context, "1")
404-
.setSmallIcon(R.drawable.note)
405-
.setContentTitle(note.noteTitle)
406-
.setContentText(content)
407-
.setContentIntent(pendingIntent)
408-
.setAutoCancel(true)
409-
.setOngoing(true)
410-
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
411-
.build()
412-
413-
notificationManager.notify(notificationId, notification)
396+
ContextCompat.startForegroundService(context, serviceIntent)
414397
}
415398

416399

417-
418400
}

app/src/main/java/com/jjewuz/justnotes/Notifications/NotificationReciever.kt

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,31 @@ import android.content.BroadcastReceiver
55
import android.content.Context
66
import android.content.Intent
77
import android.util.Log
8-
import androidx.core.app.NotificationCompat
9-
import com.jjewuz.justnotes.R
8+
import androidx.core.content.ContextCompat
9+
import com.jjewuz.justnotes.Utils.Utils
1010

11-
class NotificationReceiver : BroadcastReceiver() {
1211

12+
class NotificationReceiver : BroadcastReceiver() {
1313
override fun onReceive(context: Context, intent: Intent) {
14-
val title = intent.getStringExtra("title")
15-
val message = intent.getStringExtra("message")
16-
val id = intent.getIntExtra("id", -1)
17-
18-
val notificationManager =
19-
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
14+
when (intent.action) {
15+
"com.jjewuz.NOTIFICATION_DELETED" -> {
16+
val serviceIntent = Intent(context, Utils.PersistentService::class.java).apply {
17+
putExtra("noteId", intent.getIntExtra("noteId", -1))
18+
putExtra("noteTitle", intent.getStringExtra("noteTitle"))
19+
putExtra("noteDescription", intent.getStringExtra("noteDescription"))
20+
}
21+
Log.d("NotesService", "Open note with ${intent.getStringExtra("noteTitle")}")
22+
ContextCompat.startForegroundService(context, serviceIntent)
23+
}
2024

21-
val notificationBuilder = NotificationCompat.Builder(context, "0")
22-
.setContentTitle(title)
23-
.setContentText(message)
24-
.setSmallIcon(R.drawable.reminders)
25-
.setAutoCancel(true)
26-
27-
Log.d("NotificationReceiver", "Received notification: $title - $message")
28-
29-
notificationManager.notify(id, notificationBuilder.build())
25+
"com.jjewuz.NOTIFICATION_HIDE" -> {
26+
val noteId = intent.getIntExtra("noteId", -1)
27+
val notificationManager =
28+
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
29+
notificationManager.cancel(noteId)
30+
Log.d("NotesService", "Closed note with $noteId")
31+
}
32+
}
3033
}
3134
}
35+

0 commit comments

Comments
 (0)