diff --git a/app/src/main/kotlin/org/fossify/notes/App.kt b/app/src/main/kotlin/org/fossify/notes/App.kt index 399b539b..bfea5ab9 100644 --- a/app/src/main/kotlin/org/fossify/notes/App.kt +++ b/app/src/main/kotlin/org/fossify/notes/App.kt @@ -1,11 +1,7 @@ package org.fossify.notes -import android.app.Application -import org.fossify.commons.extensions.checkUseEnglish +import org.fossify.commons.FossifyApp -class App : Application() { - override fun onCreate() { - super.onCreate() - checkUseEnglish() - } +class App : FossifyApp() { + override val isAppLockFeatureAvailable = true } diff --git a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt index aebdb5eb..529218c8 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/MainActivity.kt @@ -2,10 +2,13 @@ package org.fossify.notes.activities import android.accounts.NetworkErrorException import android.annotation.SuppressLint -import android.app.Activity import android.content.ActivityNotFoundException -import android.content.Context import android.content.Intent +import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK +import android.content.Intent.FLAG_ACTIVITY_NEW_TASK +import android.content.Intent.FLAG_ACTIVITY_NO_HISTORY +import android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION +import android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION import android.content.pm.ShortcutInfo import android.content.pm.ShortcutManager import android.graphics.drawable.Icon @@ -27,10 +30,62 @@ import android.webkit.WebViewClient import android.widget.ImageView import android.widget.TextView import android.widget.Toast +import androidx.appcompat.content.res.AppCompatResources +import androidx.core.net.toUri import androidx.viewpager.widget.ViewPager -import org.fossify.commons.dialogs.* -import org.fossify.commons.extensions.* -import org.fossify.commons.helpers.* +import org.fossify.commons.dialogs.ConfirmationAdvancedDialog +import org.fossify.commons.dialogs.ConfirmationDialog +import org.fossify.commons.dialogs.FilePickerDialog +import org.fossify.commons.dialogs.RadioGroupDialog +import org.fossify.commons.dialogs.SecurityDialog +import org.fossify.commons.extensions.appLaunched +import org.fossify.commons.extensions.appLockManager +import org.fossify.commons.extensions.applyColorFilter +import org.fossify.commons.extensions.baseConfig +import org.fossify.commons.extensions.beVisibleIf +import org.fossify.commons.extensions.checkWhatsNew +import org.fossify.commons.extensions.clearBackgroundSpans +import org.fossify.commons.extensions.convertToBitmap +import org.fossify.commons.extensions.deleteFile +import org.fossify.commons.extensions.fadeIn +import org.fossify.commons.extensions.fadeOut +import org.fossify.commons.extensions.getContrastColor +import org.fossify.commons.extensions.getCurrentFormattedDateTime +import org.fossify.commons.extensions.getDocumentFile +import org.fossify.commons.extensions.getFilenameFromContentUri +import org.fossify.commons.extensions.getFilenameFromPath +import org.fossify.commons.extensions.getProperBackgroundColor +import org.fossify.commons.extensions.getProperPrimaryColor +import org.fossify.commons.extensions.getProperStatusBarColor +import org.fossify.commons.extensions.getRealPathFromURI +import org.fossify.commons.extensions.handleDeletePasswordProtection +import org.fossify.commons.extensions.hasPermission +import org.fossify.commons.extensions.hideKeyboard +import org.fossify.commons.extensions.highlightText +import org.fossify.commons.extensions.isMediaFile +import org.fossify.commons.extensions.launchMoreAppsFromUsIntent +import org.fossify.commons.extensions.needsStupidWritePermissions +import org.fossify.commons.extensions.onGlobalLayout +import org.fossify.commons.extensions.onPageChangeListener +import org.fossify.commons.extensions.onTextChangeListener +import org.fossify.commons.extensions.performSecurityCheck +import org.fossify.commons.extensions.searchMatches +import org.fossify.commons.extensions.shortcutManager +import org.fossify.commons.extensions.showErrorToast +import org.fossify.commons.extensions.showKeyboard +import org.fossify.commons.extensions.toast +import org.fossify.commons.extensions.updateTextColors +import org.fossify.commons.extensions.value +import org.fossify.commons.extensions.viewBinding +import org.fossify.commons.helpers.LICENSE_RTL +import org.fossify.commons.helpers.PERMISSION_READ_STORAGE +import org.fossify.commons.helpers.PERMISSION_WRITE_STORAGE +import org.fossify.commons.helpers.PROTECTION_NONE +import org.fossify.commons.helpers.REAL_FILE_PATH +import org.fossify.commons.helpers.SHOW_ALL_TABS +import org.fossify.commons.helpers.ensureBackgroundThread +import org.fossify.commons.helpers.isNougatMR1Plus +import org.fossify.commons.helpers.isQPlus import org.fossify.commons.models.FAQItem import org.fossify.commons.models.FileDirItem import org.fossify.commons.models.RadioItem @@ -41,15 +96,33 @@ import org.fossify.notes.R import org.fossify.notes.adapters.NotesPagerAdapter import org.fossify.notes.databases.NotesDatabase import org.fossify.notes.databinding.ActivityMainBinding -import org.fossify.notes.dialogs.* -import org.fossify.notes.extensions.* +import org.fossify.notes.dialogs.DeleteNoteDialog +import org.fossify.notes.dialogs.ExportFileDialog +import org.fossify.notes.dialogs.ImportFolderDialog +import org.fossify.notes.dialogs.NewNoteDialog +import org.fossify.notes.dialogs.OpenFileDialog +import org.fossify.notes.dialogs.OpenNoteDialog +import org.fossify.notes.dialogs.RenameNoteDialog +import org.fossify.notes.dialogs.SortChecklistDialog +import org.fossify.notes.extensions.config +import org.fossify.notes.extensions.getPercentageFontSize +import org.fossify.notes.extensions.notesDB +import org.fossify.notes.extensions.parseChecklistItems +import org.fossify.notes.extensions.updateWidgets +import org.fossify.notes.extensions.widgetsDB import org.fossify.notes.fragments.TextFragment -import org.fossify.notes.helpers.* +import org.fossify.notes.helpers.MIME_TEXT_PLAIN +import org.fossify.notes.helpers.MyMovementMethod +import org.fossify.notes.helpers.NEW_CHECKLIST +import org.fossify.notes.helpers.NEW_TEXT_NOTE +import org.fossify.notes.helpers.NotesHelper +import org.fossify.notes.helpers.OPEN_NOTE_ID +import org.fossify.notes.helpers.SHORTCUT_NEW_CHECKLIST +import org.fossify.notes.helpers.SHORTCUT_NEW_TEXT_NOTE import org.fossify.notes.models.Note import org.fossify.notes.models.NoteType import java.io.File import java.nio.charset.Charset -import java.util.Arrays class MainActivity : SimpleActivity() { private val EXPORT_FILE_SYNC = 1 @@ -83,9 +156,6 @@ class MainActivity : SimpleActivity() { private val binding by viewBinding(ActivityMainBinding::inflate) - private var mIsPasswordProtectionPending = false - private var mWasProtectionHandled = false - override fun onCreate(savedInstanceState: Bundle?) { isMaterialActivity = true super.onCreate(savedInstanceState) @@ -94,7 +164,12 @@ class MainActivity : SimpleActivity() { setupOptionsMenu() refreshMenuItems() - updateMaterialActivityViews(binding.mainCoordinator, null, useTransparentNavigation = false, useTopSearchMenu = false) + updateMaterialActivityViews( + mainCoordinatorLayout = binding.mainCoordinator, + nestedView = null, + useTransparentNavigation = false, + useTopSearchMenu = false + ) searchQueryET = findViewById(org.fossify.commons.R.id.search_query) searchPrevBtn = findViewById(org.fossify.commons.R.id.search_previous) @@ -116,35 +191,14 @@ class MainActivity : SimpleActivity() { checkIntents(intent) storeStateVariables() + if (config.showNotePicker && savedInstanceState == null && hasNoIntent) { + displayOpenNoteDialog() + } wasInit = true checkAppOnSDCard() setupSearchButtons() - - mIsPasswordProtectionPending = config.isAppPasswordProtectionOn - - if (config.showNotePicker && savedInstanceState == null && hasNoIntent && !mIsPasswordProtectionPending) { - displayOpenNoteDialog() - } - - if (savedInstanceState == null) { - binding.viewPager.beGoneIf(mIsPasswordProtectionPending) - if (mIsPasswordProtectionPending && !mWasProtectionHandled) { - handleAppPasswordProtection { - mWasProtectionHandled = it - if (it) { - mIsPasswordProtectionPending = false - if (config.showNotePicker && savedInstanceState == null && hasNoIntent) { - displayOpenNoteDialog() - } - binding.viewPager.beVisible() - } else { - finish() - } - } - } - } } override fun onResume() { @@ -218,9 +272,12 @@ class MainActivity : SimpleActivity() { findItem(R.id.remove_done_items).isVisible = isCurrentItemChecklist findItem(R.id.sort_checklist).isVisible = isCurrentItemChecklist findItem(R.id.import_folder).isVisible = !isQPlus() - findItem(R.id.lock_note).isVisible = mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && !mCurrentNote.isLocked()) - findItem(R.id.unlock_note).isVisible = mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && mCurrentNote.isLocked()) - findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(org.fossify.commons.R.bool.hide_google_relations) + findItem(R.id.lock_note).isVisible = + mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && !mCurrentNote.isLocked()) + findItem(R.id.unlock_note).isVisible = + mNotes.isNotEmpty() && (::mCurrentNote.isInitialized && mCurrentNote.isLocked()) + findItem(R.id.more_apps_from_us).isVisible = + !resources.getBoolean(org.fossify.commons.R.bool.hide_google_relations) saveNoteButton = findItem(R.id.save_note) saveNoteButton!!.isVisible = @@ -290,20 +347,22 @@ class MainActivity : SimpleActivity() { override fun onBackPressed() { if (!config.autosaveNotes && mAdapter?.anyHasUnsavedChanges() == true) { ConfirmationAdvancedDialog( - this, - "", - R.string.unsaved_changes_warning, - org.fossify.commons.R.string.save, - org.fossify.commons.R.string.discard + activity = this, + message = "", + messageId = R.string.unsaved_changes_warning, + positive = org.fossify.commons.R.string.save, + negative = org.fossify.commons.R.string.discard ) { if (it) { mAdapter?.saveAllFragmentTexts() } + appLockManager.lock() super.onBackPressed() } } else if (isSearchActive) { closeSearch() } else { + appLockManager.lock() super.onBackPressed() } } @@ -317,16 +376,27 @@ class MainActivity : SimpleActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { super.onActivityResult(requestCode, resultCode, resultData) - if (requestCode == PICK_OPEN_FILE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null) { - importUri(resultData.data!!) - } else if (requestCode == PICK_EXPORT_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null && mNotes.isNotEmpty()) { - val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - applicationContext.contentResolver.takePersistableUriPermission(resultData.data!!, takeFlags) - showExportFilePickUpdateDialog(resultData.dataString!!, getCurrentNoteValue()) + if (resultCode != RESULT_OK || resultData?.data == null) return + + val dataUri = resultData.data!! + when (requestCode) { + PICK_OPEN_FILE_INTENT -> importUri(dataUri) + PICK_EXPORT_FILE_INTENT -> if (mNotes.isNotEmpty()) { + applicationContext.contentResolver.takePersistableUriPermission( + dataUri, FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION + ) + showExportFilePickUpdateDialog(resultData.dataString!!, getCurrentNoteValue()) + } } } - private fun isCurrentItemChecklist() = if (::mCurrentNote.isInitialized) mCurrentNote.type == NoteType.TYPE_CHECKLIST else false + private fun isCurrentItemChecklist(): Boolean { + return if (::mCurrentNote.isInitialized) { + mCurrentNote.type == NoteType.TYPE_CHECKLIST + } else { + false + } + } @SuppressLint("NewApi") private fun checkShortcuts() { @@ -336,9 +406,9 @@ class MainActivity : SimpleActivity() { val newChecklist = getNewChecklistShortcut(appIconColor) try { - shortcutManager.dynamicShortcuts = Arrays.asList(newTextNote, newChecklist) + shortcutManager.dynamicShortcuts = listOf(newTextNote, newChecklist) config.lastHandledShortcutColor = appIconColor - } catch (ignored: Exception) { + } catch (_: Exception) { } } } @@ -347,8 +417,12 @@ class MainActivity : SimpleActivity() { private fun getNewTextNoteShortcut(appIconColor: Int): ShortcutInfo { val shortLabel = getString(R.string.text_note) val longLabel = getString(R.string.new_text_note) - val drawable = resources.getDrawable(org.fossify.commons.R.drawable.shortcut_plus) - (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor) + val drawable = AppCompatResources.getDrawable( + this, org.fossify.commons.R.drawable.shortcut_plus + ) + + (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background) + .applyColorFilter(appIconColor) val bmp = drawable.convertToBitmap() val intent = Intent(this, MainActivity::class.java) @@ -366,8 +440,9 @@ class MainActivity : SimpleActivity() { private fun getNewChecklistShortcut(appIconColor: Int): ShortcutInfo { val shortLabel = getString(R.string.checklist) val longLabel = getString(R.string.new_checklist) - val drawable = resources.getDrawable(R.drawable.shortcut_check) - (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor) + val drawable = AppCompatResources.getDrawable(this, R.drawable.shortcut_check) + (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background) + .applyColorFilter(appIconColor) val bmp = drawable.convertToBitmap() val intent = Intent(this, MainActivity::class.java) @@ -398,11 +473,29 @@ class MainActivity : SimpleActivity() { val file = File(realPath) handleUri(Uri.fromFile(file)) } else if (intent.getBooleanExtra(NEW_TEXT_NOTE, false)) { - val newTextNote = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_TEXT, "", PROTECTION_NONE, "") - addNewNote(newTextNote) + addNewNote( + Note( + id = null, + title = getCurrentFormattedDateTime(), + value = "", + type = NoteType.TYPE_TEXT, + path = "", + protectionType = PROTECTION_NONE, + protectionHash = "" + ) + ) } else if (intent.getBooleanExtra(NEW_CHECKLIST, false)) { - val newChecklist = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "") - addNewNote(newChecklist) + addNewNote( + Note( + id = null, + title = getCurrentFormattedDateTime(), + value = "", + type = NoteType.TYPE_CHECKLIST, + path = "", + protectionType = PROTECTION_NONE, + protectionHash = "" + ) + ) } else { handleUri(data!!) } @@ -604,14 +697,13 @@ class MainActivity : SimpleActivity() { private fun getWantedNoteIndex(wantedNoteId: Long?): Int { intent.removeExtra(OPEN_NOTE_ID) - val noteIdToOpen = if (wantedNoteId == null || wantedNoteId == -1L) config.currentNoteId else wantedNoteId + val noteIdToOpen = + if (wantedNoteId == null || wantedNoteId == -1L) config.currentNoteId else wantedNoteId return getNoteIndexWithId(noteIdToOpen) } - private fun currentNotesView() = if (binding.viewPager == null) { - null - } else { - mAdapter?.getCurrentNotesView(binding.viewPager.currentItem) + private fun currentNotesView(): MyEditText? { + return mAdapter?.getCurrentNotesView(binding.viewPager.currentItem) } private fun displayRenameDialog() { @@ -635,7 +727,12 @@ class MainActivity : SimpleActivity() { } } - private fun displayNewNoteDialog(value: String = "", title: String? = null, path: String = "", setChecklistAsDefault: Boolean = false) { + private fun displayNewNoteDialog( + value: String = "", + title: String? = null, + path: String = "", + setChecklistAsDefault: Boolean = false, + ) { NewNoteDialog(this, title, setChecklistAsDefault) { it.value = value it.path = path @@ -666,18 +763,50 @@ class MainActivity : SimpleActivity() { val licenses = LICENSE_RTL val faqItems = arrayListOf( - FAQItem(org.fossify.commons.R.string.faq_1_title_commons, org.fossify.commons.R.string.faq_1_text_commons), - FAQItem(R.string.faq_1_title, R.string.faq_1_text) + FAQItem( + title = org.fossify.commons.R.string.faq_1_title_commons, + text = org.fossify.commons.R.string.faq_1_text_commons + ), + FAQItem( + title = R.string.faq_1_title, + text = R.string.faq_1_text + ) ) if (!resources.getBoolean(org.fossify.commons.R.bool.hide_google_relations)) { - faqItems.add(FAQItem(org.fossify.commons.R.string.faq_2_title_commons, org.fossify.commons.R.string.faq_2_text_commons)) - faqItems.add(FAQItem(org.fossify.commons.R.string.faq_6_title_commons, org.fossify.commons.R.string.faq_6_text_commons)) - faqItems.add(FAQItem(org.fossify.commons.R.string.faq_7_title_commons, org.fossify.commons.R.string.faq_7_text_commons)) - faqItems.add(FAQItem(org.fossify.commons.R.string.faq_10_title_commons, org.fossify.commons.R.string.faq_10_text_commons)) + faqItems.add( + FAQItem( + title = org.fossify.commons.R.string.faq_2_title_commons, + text = org.fossify.commons.R.string.faq_2_text_commons + ) + ) + faqItems.add( + FAQItem( + title = org.fossify.commons.R.string.faq_6_title_commons, + text = org.fossify.commons.R.string.faq_6_text_commons + ) + ) + faqItems.add( + FAQItem( + title = org.fossify.commons.R.string.faq_7_title_commons, + text = org.fossify.commons.R.string.faq_7_text_commons + ) + ) + faqItems.add( + FAQItem( + title = org.fossify.commons.R.string.faq_10_title_commons, + text = org.fossify.commons.R.string.faq_10_text_commons + ) + ) } - startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) + startAboutActivity( + appNameId = R.string.app_name, + licenseMask = licenses, + versionName = BuildConfig.VERSION_NAME, + faqItems = faqItems, + showFAQBeforeMail = true + ) } private fun tryOpenFile() { @@ -710,16 +839,33 @@ class MainActivity : SimpleActivity() { val checklistItems = fileText.parseChecklistItems() if (checklistItems != null) { val title = it.absolutePath.getFilenameFromPath().substringBeforeLast('.') - val note = Note(null, title, fileText, NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "") + val note = Note( + id = null, + title = title, + value = fileText, + type = NoteType.TYPE_CHECKLIST, + path = "", + protectionType = PROTECTION_NONE, + protectionHash = "" + ) runOnUiThread { OpenFileDialog(this, it.path) { - displayNewNoteDialog(note.value, title = it.title, it.path, setChecklistAsDefault = true) + displayNewNoteDialog( + note.value, + title = it.title, + it.path, + setChecklistAsDefault = true + ) } } } else { runOnUiThread { OpenFileDialog(this, it.path) { - displayNewNoteDialog(it.value, title = it.title, it.path) + displayNewNoteDialog( + value = it.value, + title = it.title, + path = it.path + ) } } } @@ -728,7 +874,11 @@ class MainActivity : SimpleActivity() { } } - private fun checkFile(path: String, checkTitle: Boolean, onChecksPassed: (file: File) -> Unit) { + private fun checkFile( + path: String, + checkTitle: Boolean, + onChecksPassed: (file: File) -> Unit, + ) { val file = File(path) if (path.isMediaFile()) { toast(org.fossify.commons.R.string.invalid_file_format) @@ -742,17 +892,16 @@ class MainActivity : SimpleActivity() { } private fun checkUri(uri: Uri, onChecksPassed: () -> Unit) { - val inputStream = try { - contentResolver.openInputStream(uri) ?: return + try { + contentResolver.openInputStream(uri)?.use { inputStream -> + if (inputStream.available() > 1000 * 1000) { + toast(R.string.file_too_large) + } else { + onChecksPassed() + } + } ?: return } catch (e: Exception) { showErrorToast(e) - return - } - - if (inputStream.available() > 1000 * 1000) { - toast(R.string.file_too_large) - } else { - onChecksPassed() } } @@ -790,7 +939,9 @@ class MainActivity : SimpleActivity() { private fun addNoteFromUri(uri: Uri, filename: String? = null) { val noteTitle = when { filename?.isEmpty() == false -> filename - uri.toString().startsWith("content://") -> getFilenameFromContentUri(uri) ?: getNewNoteTitle() + uri.toString().startsWith("content://") -> getFilenameFromContentUri(uri) + ?: getNewNoteTitle() + else -> getNewNoteTitle() } @@ -804,7 +955,7 @@ class MainActivity : SimpleActivity() { true } else { try { - val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + val takeFlags = FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION applicationContext.contentResolver.takePersistableUriPermission(uri, takeFlags) true } catch (e: Exception) { @@ -814,7 +965,16 @@ class MainActivity : SimpleActivity() { val noteType = if (checklistItems != null) NoteType.TYPE_CHECKLIST else NoteType.TYPE_TEXT if (!canSyncNoteWithFile) { - val note = Note(null, noteTitle, content, noteType, "", PROTECTION_NONE, "") + val note = Note( + id = null, + title = noteTitle, + value = content, + type = noteType, + path = "", + protectionType = PROTECTION_NONE, + protectionHash = "" + ) + displayNewNoteDialog(note.value, title = noteTitle, "") } else { val items = arrayListOf( @@ -825,8 +985,16 @@ class MainActivity : SimpleActivity() { RadioGroupDialog(this, items) { val syncFile = it as Int == IMPORT_FILE_SYNC val path = if (syncFile) uri.toString() else "" - val note = Note(null, noteTitle, content, noteType, "", PROTECTION_NONE, "") - displayNewNoteDialog(note.value, title = noteTitle, path) + val note = Note( + id = null, + title = noteTitle, + value = content, + type = noteType, + path = "", + protectionType = PROTECTION_NONE, + protectionHash = "" + ) + displayNewNoteDialog(value = note.value, title = noteTitle, path = path) } } } @@ -838,9 +1006,25 @@ class MainActivity : SimpleActivity() { val fileText = it.readText().trim() val checklistItems = fileText.parseChecklistItems() val note = if (checklistItems != null) { - Note(null, title.substringBeforeLast('.'), fileText, NoteType.TYPE_CHECKLIST, "", PROTECTION_NONE, "") + Note( + id = null, + title = title.substringBeforeLast('.'), + value = fileText, + type = NoteType.TYPE_CHECKLIST, + path = "", + protectionType = PROTECTION_NONE, + protectionHash = "" + ) } else { - Note(null, title, "", NoteType.TYPE_TEXT, path, PROTECTION_NONE, "") + Note( + id = null, + title = title, + value = "", + type = NoteType.TYPE_TEXT, + path = path, + protectionType = PROTECTION_NONE, + protectionHash = "" + ) } if (mNotes.any { it.title.equals(note.title, true) }) { @@ -911,13 +1095,23 @@ class MainActivity : SimpleActivity() { private fun exportAsFile() { ExportFileDialog(this, mCurrentNote) { - val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value + val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT) { + getCurrentNoteText() + } else { + mCurrentNote.value + } + if (textToExport == null || textToExport.isEmpty()) { toast(org.fossify.commons.R.string.unknown_error_occurred) } else if (mCurrentNote.type == NoteType.TYPE_TEXT) { showExportFilePickUpdateDialog(it, textToExport) } else { - tryExportNoteValueToFile(it, mCurrentNote.title, textToExport, true) + tryExportNoteValueToFile( + path = it, + title = mCurrentNote.title, + content = textToExport, + showSuccessToasts = true + ) } } } @@ -930,7 +1124,12 @@ class MainActivity : SimpleActivity() { RadioGroupDialog(this, items) { val syncFile = it as Int == EXPORT_FILE_SYNC - tryExportNoteValueToFile(exportPath, mCurrentNote.title, textToExport, true) { exportedSuccessfully -> + tryExportNoteValueToFile( + path = exportPath, + title = mCurrentNote.title, + content = textToExport, + showSuccessToasts = true + ) { exportedSuccessfully -> if (exportedSuccessfully) { if (syncFile) { mCurrentNote.path = exportPath @@ -940,16 +1139,32 @@ class MainActivity : SimpleActivity() { mCurrentNote.value = textToExport } - getPagerAdapter().updateCurrentNoteData(binding.viewPager.currentItem, mCurrentNote.path, mCurrentNote.value) + getPagerAdapter().updateCurrentNoteData( + position = binding.viewPager.currentItem, + path = mCurrentNote.path, + value = mCurrentNote.value + ) NotesHelper(this).insertOrUpdateNote(mCurrentNote) } } } } - fun tryExportNoteValueToFile(path: String, title: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) { + fun tryExportNoteValueToFile( + path: String, + title: String, + content: String, + showSuccessToasts: Boolean, + callback: ((success: Boolean) -> Unit)? = null, + ) { if (path.startsWith("content://")) { - exportNoteValueToUri(Uri.parse(path), title, content, showSuccessToasts, callback) + exportNoteValueToUri( + uri = path.toUri(), + title = title, + content = content, + showSuccessToasts = showSuccessToasts, + callback = callback + ) } else { handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { @@ -959,7 +1174,12 @@ class MainActivity : SimpleActivity() { } } - private fun exportNoteValueToFile(path: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) { + private fun exportNoteValueToFile( + path: String, + content: String, + showSuccessToasts: Boolean, + callback: ((success: Boolean) -> Unit)? = null, + ) { try { if (File(path).isDirectory) { toast(org.fossify.commons.R.string.name_taken) @@ -1002,7 +1222,13 @@ class MainActivity : SimpleActivity() { } } - private fun exportNoteValueToUri(uri: Uri, title: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) { + private fun exportNoteValueToUri( + uri: Uri, + title: String, + content: String, + showSuccessToasts: Boolean, + callback: ((success: Boolean) -> Unit)? = null, + ) { try { val outputStream = contentResolver.openOutputStream(uri, "rwt") outputStream!!.bufferedWriter().use { out -> @@ -1034,7 +1260,8 @@ class MainActivity : SimpleActivity() { try { val webView = WebView(this) webView.webViewClient = object : WebViewClient() { - override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest) = false + override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest) = + false override fun onPageFinished(view: WebView, url: String) { createWebPrintJob(view) @@ -1051,7 +1278,7 @@ class MainActivity : SimpleActivity() { val jobName = mCurrentNote.title val printAdapter = webView.createPrintDocumentAdapter(jobName) - (getSystemService(Context.PRINT_SERVICE) as? PrintManager)?.apply { + (getSystemService(PRINT_SERVICE) as? PrintManager)?.apply { try { print(jobName, printAdapter, PrintAttributes.Builder().build()) } catch (e: IllegalStateException) { @@ -1062,7 +1289,9 @@ class MainActivity : SimpleActivity() { private fun getPagerAdapter() = binding.viewPager.adapter as NotesPagerAdapter - private fun getCurrentNoteText() = getPagerAdapter().getCurrentNoteViewText(binding.viewPager.currentItem) + private fun getCurrentNoteText(): String? { + return getPagerAdapter().getCurrentNoteViewText(binding.viewPager.currentItem) + } private fun getCurrentNoteValue(): String { return if (mCurrentNote.type == NoteType.TYPE_TEXT) { @@ -1084,12 +1313,15 @@ class MainActivity : SimpleActivity() { } } - private fun addTextToCurrentNote(text: String) = getPagerAdapter().appendText(binding.viewPager.currentItem, text) + private fun addTextToCurrentNote(text: String) { + getPagerAdapter().appendText(binding.viewPager.currentItem, text) + } private fun saveCurrentNote(force: Boolean, callback: ((note: Note) -> Unit)? = null) { getPagerAdapter().saveCurrentNote(binding.viewPager.currentItem, force, callback) if (mCurrentNote.type == NoteType.TYPE_CHECKLIST) { - mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(binding.viewPager.currentItem) ?: "" + mCurrentNote.value = getPagerAdapter() + .getNoteChecklistItems(binding.viewPager.currentItem) ?: "" } } @@ -1122,7 +1354,8 @@ class MainActivity : SimpleActivity() { private fun doDeleteNote(note: Note, deleteFile: Boolean) { ensureBackgroundThread { val currentNoteIndex = mNotes.indexOf(note) - val noteToRefresh = mNotes[if (currentNoteIndex > 0) currentNoteIndex - 1 else currentNoteIndex + 1] + val noteToRefresh = + mNotes[if (currentNoteIndex > 0) currentNoteIndex - 1 else currentNoteIndex + 1] notesDB.deleteNote(note) widgetsDB.deleteNoteWidgets(note.id!!) @@ -1192,7 +1425,12 @@ class MainActivity : SimpleActivity() { } private fun shareText() { - val text = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value + val text = if (mCurrentNote.type == NoteType.TYPE_TEXT) { + getCurrentNoteText() + } else { + mCurrentNote.value + } + if (text.isNullOrEmpty()) { toast(R.string.cannot_share_empty_text) return @@ -1214,14 +1452,16 @@ class MainActivity : SimpleActivity() { val manager = getSystemService(ShortcutManager::class.java) if (manager.isRequestPinShortcutSupported) { val note = mCurrentNote - val drawable = resources.getDrawable(R.drawable.shortcut_note).mutate() + val drawable = AppCompatResources.getDrawable(this, R.drawable.shortcut_note)?.mutate() val appIconColor = baseConfig.appIconColor - (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor) + (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background) + .applyColorFilter(appIconColor) val intent = Intent(this, SplashActivity::class.java) intent.action = Intent.ACTION_VIEW intent.putExtra(OPEN_NOTE_ID, note.id) - intent.flags = intent.flags or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NO_HISTORY + intent.flags = + intent.flags or FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK or FLAG_ACTIVITY_NO_HISTORY val shortcut = ShortcutInfo.Builder(this, note.hashCode().toString()) .setShortLabel(mCurrentNote.title) @@ -1234,7 +1474,13 @@ class MainActivity : SimpleActivity() { } private fun lockNote() { - ConfirmationDialog(this, "", R.string.locking_warning, org.fossify.commons.R.string.ok, org.fossify.commons.R.string.cancel) { + ConfirmationDialog( + activity = this, + message = "", + messageId = R.string.locking_warning, + positive = org.fossify.commons.R.string.ok, + negative = org.fossify.commons.R.string.cancel + ) { SecurityDialog(this, "", SHOW_ALL_TABS) { hash, type, success -> if (success) { mCurrentNote.protectionHash = hash diff --git a/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt index 30be93e4..0fa3212b 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt @@ -15,16 +15,58 @@ import org.fossify.commons.dialogs.ConfirmationDialog import org.fossify.commons.dialogs.PermissionRequiredDialog import org.fossify.commons.dialogs.RadioGroupDialog import org.fossify.commons.dialogs.SecurityDialog -import org.fossify.commons.extensions.* -import org.fossify.commons.helpers.* +import org.fossify.commons.extensions.beGone +import org.fossify.commons.extensions.beVisible +import org.fossify.commons.extensions.beVisibleIf +import org.fossify.commons.extensions.getProperPrimaryColor +import org.fossify.commons.extensions.openRequestExactAlarmSettings +import org.fossify.commons.extensions.showErrorToast +import org.fossify.commons.extensions.toast +import org.fossify.commons.extensions.updateTextColors +import org.fossify.commons.extensions.viewBinding +import org.fossify.commons.helpers.IS_CUSTOMIZING_COLORS +import org.fossify.commons.helpers.NavigationIcon +import org.fossify.commons.helpers.PROTECTION_FINGERPRINT +import org.fossify.commons.helpers.SHOW_ALL_TABS +import org.fossify.commons.helpers.ensureBackgroundThread +import org.fossify.commons.helpers.isOreoPlus +import org.fossify.commons.helpers.isQPlus +import org.fossify.commons.helpers.isRPlus +import org.fossify.commons.helpers.isSPlus +import org.fossify.commons.helpers.isTiramisuPlus import org.fossify.commons.models.RadioItem import org.fossify.notes.BuildConfig import org.fossify.notes.R import org.fossify.notes.databinding.ActivitySettingsBinding import org.fossify.notes.dialogs.ExportNotesDialog import org.fossify.notes.dialogs.ManageAutoBackupsDialog -import org.fossify.notes.extensions.* -import org.fossify.notes.helpers.* +import org.fossify.notes.extensions.cancelScheduledAutomaticBackup +import org.fossify.notes.extensions.config +import org.fossify.notes.extensions.requestUnlockNotes +import org.fossify.notes.extensions.scheduleNextAutomaticBackup +import org.fossify.notes.extensions.updateWidgets +import org.fossify.notes.extensions.widgetsDB +import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_BG_COLOR +import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_ID +import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_KEY_ID +import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_NOTE_ID +import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_SHOW_TITLE +import org.fossify.notes.helpers.CUSTOMIZED_WIDGET_TEXT_COLOR +import org.fossify.notes.helpers.FONT_SIZE_100_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_125_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_150_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_175_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_200_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_250_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_300_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_50_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_60_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_75_PERCENT +import org.fossify.notes.helpers.FONT_SIZE_90_PERCENT +import org.fossify.notes.helpers.GRAVITY_CENTER +import org.fossify.notes.helpers.GRAVITY_END +import org.fossify.notes.helpers.GRAVITY_START +import org.fossify.notes.helpers.NotesHelper import org.fossify.notes.models.Note import org.fossify.notes.models.Widget import java.util.Locale @@ -47,7 +89,12 @@ class SettingsActivity : SimpleActivity() { super.onCreate(savedInstanceState) setContentView(binding.root) - updateMaterialActivityViews(binding.settingsCoordinator, binding.settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false) + updateMaterialActivityViews( + mainCoordinatorLayout = binding.settingsCoordinator, + nestedView = binding.settingsHolder, + useTransparentNavigation = true, + useTopSearchMenu = false + ) setupMaterialScrollListener(binding.settingsNestedScrollview, binding.settingsToolbar) } @@ -105,18 +152,19 @@ class SettingsActivity : SimpleActivity() { } } - private val saveDocument = registerForActivityResult(ActivityResultContracts.CreateDocument(notesFileType)) { uri -> - if (uri != null) { - toast(org.fossify.commons.R.string.exporting) - NotesHelper(this).getNotes { notes -> - requestUnlockNotes(notes) { unlockedNotes -> - val notLockedNotes = notes.filterNot { it.isLocked() } - val notesToExport = unlockedNotes + notLockedNotes - exportNotes(notesToExport, uri) + private val saveDocument = + registerForActivityResult(ActivityResultContracts.CreateDocument(notesFileType)) { uri -> + if (uri != null) { + toast(org.fossify.commons.R.string.exporting) + NotesHelper(this).getNotes { notes -> + requestUnlockNotes(notes) { unlockedNotes -> + val notLockedNotes = notes.filterNot { it.isLocked() } + val notesToExport = unlockedNotes + notLockedNotes + exportNotes(notesToExport, uri) + } } } } - } private fun setupCustomizeColors() { binding.settingsColorCustomizationHolder.setOnClickListener { @@ -136,9 +184,13 @@ class SettingsActivity : SimpleActivity() { private fun setupLanguage() { binding.settingsLanguage.text = Locale.getDefault().displayLanguage - binding.settingsLanguageHolder.beVisibleIf(isTiramisuPlus()) - binding.settingsLanguageHolder.setOnClickListener { - launchChangeAppLanguageIntent() + if (isTiramisuPlus()) { + binding.settingsLanguageHolder.beVisible() + binding.settingsLanguageHolder.setOnClickListener { + launchChangeAppLanguageIntent() + } + } else { + binding.settingsLanguageHolder.beGone() } } @@ -241,7 +293,9 @@ class SettingsActivity : SimpleActivity() { private fun setupGravity() { binding.settingsGravity.text = getGravityText() binding.settingsGravityHolder.setOnClickListener { - val items = listOf(GRAVITY_START, GRAVITY_CENTER, GRAVITY_END).map { RadioItem(it, getGravityOptionLabel(it)) } + val items = listOf(GRAVITY_START, GRAVITY_CENTER, GRAVITY_END).map { + RadioItem(it, getGravityOptionLabel(it)) + } RadioGroupDialog(this@SettingsActivity, ArrayList(items), config.gravity) { config.gravity = it as Int binding.settingsGravity.text = getGravityText() @@ -251,13 +305,15 @@ class SettingsActivity : SimpleActivity() { } private fun getGravityOptionLabel(gravity: Int): String { - val leftToRightDirection = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_LTR + val leftToRightDirection = TextUtilsCompat + .getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_LTR val leftRightLabels = listOf(R.string.left, R.string.right) val startEndLabels = if (leftToRightDirection) { leftRightLabels } else { leftRightLabels.reversed() } + return getString( when (gravity) { GRAVITY_START -> startEndLabels.first() @@ -436,8 +492,17 @@ class SettingsActivity : SimpleActivity() { private fun setupAppPasswordProtection() { binding.settingsAppPasswordProtection.isChecked = config.isAppPasswordProtectionOn binding.settingsAppPasswordProtectionHolder.setOnClickListener { - val tabToShow = if (config.isAppPasswordProtectionOn) config.appProtectionType else SHOW_ALL_TABS - SecurityDialog(this, config.appPasswordHash, tabToShow) { hash, type, success -> + val tabToShow = if (config.isAppPasswordProtectionOn) { + config.appProtectionType + } else { + SHOW_ALL_TABS + } + + SecurityDialog( + activity = this, + requiredHash = config.appPasswordHash, + showTabIndex = tabToShow + ) { hash, type, success -> if (success) { val hasPasswordProtection = config.isAppPasswordProtectionOn binding.settingsAppPasswordProtection.isChecked = !hasPasswordProtection @@ -446,9 +511,20 @@ class SettingsActivity : SimpleActivity() { config.appProtectionType = type if (config.isAppPasswordProtectionOn) { - val confirmationTextId = if (config.appProtectionType == PROTECTION_FINGERPRINT) - org.fossify.commons.R.string.fingerprint_setup_successfully else org.fossify.commons.R.string.protection_setup_successfully - ConfirmationDialog(this, "", confirmationTextId, org.fossify.commons.R.string.ok, 0) { } + val confirmationTextId = + if (config.appProtectionType == PROTECTION_FINGERPRINT) { + org.fossify.commons.R.string.fingerprint_setup_successfully + } else { + org.fossify.commons.R.string.protection_setup_successfully + } + + ConfirmationDialog( + activity = this, + message = "", + messageId = confirmationTextId, + positive = org.fossify.commons.R.string.ok, + negative = 0 + ) { } } } } @@ -456,21 +532,44 @@ class SettingsActivity : SimpleActivity() { } private fun setupNoteDeletionPasswordProtection() { - binding.settingsNoteDeletionPasswordProtection.isChecked = config.isDeletePasswordProtectionOn + binding.settingsNoteDeletionPasswordProtection.isChecked = + config.isDeletePasswordProtectionOn + binding.settingsNoteDeletionPasswordProtectionHolder.setOnClickListener { - val tabToShow = if (config.isDeletePasswordProtectionOn) config.deleteProtectionType else SHOW_ALL_TABS - SecurityDialog(this, config.deletePasswordHash, tabToShow) { hash, type, success -> + val tabToShow = if (config.isDeletePasswordProtectionOn) { + config.deleteProtectionType + } else { + SHOW_ALL_TABS + } + + SecurityDialog( + activity = this, + requiredHash = config.deletePasswordHash, + showTabIndex = tabToShow + ) { hash, type, success -> if (success) { val hasPasswordProtection = config.isDeletePasswordProtectionOn - binding.settingsNoteDeletionPasswordProtection.isChecked = !hasPasswordProtection + binding.settingsNoteDeletionPasswordProtection.isChecked = + !hasPasswordProtection config.isDeletePasswordProtectionOn = !hasPasswordProtection config.deletePasswordHash = if (hasPasswordProtection) "" else hash config.deleteProtectionType = type if (config.isDeletePasswordProtectionOn) { - val confirmationTextId = if (config.deleteProtectionType == PROTECTION_FINGERPRINT) - org.fossify.commons.R.string.fingerprint_setup_successfully else org.fossify.commons.R.string.protection_setup_successfully - ConfirmationDialog(this, "", confirmationTextId, org.fossify.commons.R.string.ok, 0) { } + val confirmationTextId = + if (config.deleteProtectionType == PROTECTION_FINGERPRINT) { + org.fossify.commons.R.string.fingerprint_setup_successfully + } else { + org.fossify.commons.R.string.protection_setup_successfully + } + + ConfirmationDialog( + activity = this, + message = "", + messageId = confirmationTextId, + positive = org.fossify.commons.R.string.ok, + negative = 0 + ) { } } } } diff --git a/app/src/main/kotlin/org/fossify/notes/activities/SimpleActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/SimpleActivity.kt index 7b811f45..c4aa7275 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/SimpleActivity.kt @@ -27,4 +27,6 @@ open class SimpleActivity : BaseSimpleActivity() { ) override fun getAppLauncherName() = getString(R.string.app_launcher_name) + + override fun getRepositoryName() = "Notes" } diff --git a/app/src/main/kotlin/org/fossify/notes/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/org/fossify/notes/activities/WidgetConfigureActivity.kt index 30619b5f..1b6202f9 100644 --- a/app/src/main/kotlin/org/fossify/notes/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/org/fossify/notes/activities/WidgetConfigureActivity.kt @@ -85,10 +85,10 @@ class WidgetConfigureActivity : SimpleActivity() { } else { mBgColor = extras?.getInt(CUSTOMIZED_WIDGET_BG_COLOR) ?: config.widgetBgColor mTextColor = extras?.getInt(CUSTOMIZED_WIDGET_TEXT_COLOR) ?: config.widgetTextColor - mShowTitle = extras?.getBoolean(CUSTOMIZED_WIDGET_SHOW_TITLE) ?: false + mShowTitle = extras?.getBoolean(CUSTOMIZED_WIDGET_SHOW_TITLE) == true } - if (mTextColor == resources.getColor(org.fossify.commons.R.color.default_widget_text_color) && config.isUsingSystemTheme) { + if (mTextColor == resources.getColor(org.fossify.commons.R.color.default_widget_text_color) && isDynamicTheme()) { mTextColor = resources.getColor(org.fossify.commons.R.color.you_primary_color, theme) } diff --git a/app/src/main/kotlin/org/fossify/notes/adapters/OpenNoteAdapter.kt b/app/src/main/kotlin/org/fossify/notes/adapters/OpenNoteAdapter.kt index ab333220..531395c2 100644 --- a/app/src/main/kotlin/org/fossify/notes/adapters/OpenNoteAdapter.kt +++ b/app/src/main/kotlin/org/fossify/notes/adapters/OpenNoteAdapter.kt @@ -107,7 +107,7 @@ class OpenNoteAdapter( Color.BLACK } - val cardBackground = if (context.config.isUsingSystemTheme) { + val cardBackground = if (context.isDynamicTheme()) { org.fossify.commons.R.drawable.dialog_you_background } else { org.fossify.commons.R.drawable.dialog_bg diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1c1f162e..18c88680 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,20 +1,20 @@ [versions] #jetbrains -kotlin = "1.9.24" +kotlin = "1.9.25" #KSP kotlinxSerializationJson = "1.6.3" -ksp = "1.9.24-1.0.20" +ksp = "1.9.25-1.0.20" #Detekt detekt = "1.23.3" #AndroidX -androidx-constraintlayout = "2.1.4" +androidx-constraintlayout = "2.2.1" androidx-documentfile = "1.0.1" #Room room = "2.6.1" #Fossify -commons = "54f71d56a6" +commons = "29e9b0d13e" #Gradle -gradlePlugins-agp = "8.5.0" +gradlePlugins-agp = "8.9.0" #build app-build-compileSDKVersion = "34" app-build-targetSDK = "34" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 05ef575b..a4b76b95 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ff94dfe0..e2847c82 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Tue Nov 03 19:54:48 CET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip diff --git a/gradlew b/gradlew index 9d82f789..f5feea6d 100755 --- a/gradlew +++ b/gradlew @@ -1,74 +1,130 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -77,84 +133,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec99730..9b42019c 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,22 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -8,26 +26,30 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -35,54 +57,36 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal