Migrate to viewbinding and kotlin gradle scripts

- Replaced kotlinx sythetic with viewbinding
- Update build scripts to kotlin
- Intoduced version catalog, similar to Commons
- Updated kotlin from 1.7.10 to 1.9.0
- Updated room from 2.5.2 to 2.6.0-alpha02 (same as Commons)
- Updated Android Gradle Plugin to 8.1.0
This commit is contained in:
Ensar Sarajčić 2023-08-04 10:20:31 +02:00
parent 311175d1c1
commit cf50f6a2bb
36 changed files with 853 additions and 604 deletions

View File

@ -1,78 +0,0 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlin_version"
}
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdk 34
defaultConfig {
applicationId "com.simplemobiletools.notes.pro"
minSdkVersion 23
targetSdkVersion 34
versionCode 108
versionName "6.16.0"
setProperty("archivesBaseName", "notes")
}
signingConfigs {
if (keystorePropertiesFile.exists()) {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (keystorePropertiesFile.exists()) {
signingConfig signingConfigs.release
}
}
}
flavorDimensions "variants"
productFlavors {
core {}
fdroid {}
prepaid {}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:2a2c17151e'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.documentfile:documentfile:1.0.1'
kapt 'androidx.room:room-compiler:2.5.2'
implementation 'androidx.room:room-runtime:2.5.2'
annotationProcessor 'androidx.room:room-compiler:2.5.2'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
}

102
app/build.gradle.kts Normal file
View File

@ -0,0 +1,102 @@
import java.io.FileInputStream
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.konan.properties.Properties
plugins {
alias(libs.plugins.android)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.ksp)
alias(libs.plugins.kotlinSerialization)
}
val keystorePropertiesFile: File = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
android {
compileSdk = project.libs.versions.app.build.compileSDKVersion.get().toInt()
defaultConfig {
applicationId = libs.versions.app.version.appId.get()
minSdk = project.libs.versions.app.build.minimumSDK.get().toInt()
targetSdk = project.libs.versions.app.build.targetSDK.get().toInt()
versionName = project.libs.versions.app.version.versionName.get()
versionCode = project.libs.versions.app.version.versionCode.get().toInt()
setProperty("archivesBaseName", "notes")
ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
signingConfigs {
if (keystorePropertiesFile.exists()) {
register("release") {
keyAlias = keystoreProperties.getProperty("keyAlias")
keyPassword = keystoreProperties.getProperty("keyPassword")
storeFile = file(keystoreProperties.getProperty("storeFile"))
storePassword = keystoreProperties.getProperty("storePassword")
}
}
}
buildFeatures {
viewBinding = true
buildConfig = true
}
buildTypes {
debug {
applicationIdSuffix = ".debug"
}
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
if (keystorePropertiesFile.exists()) {
signingConfig = signingConfigs.getByName("release")
}
}
}
flavorDimensions.add("variants")
productFlavors {
register("core")
register("fdroid")
register("prepaid")
}
sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
}
compileOptions {
val currentJavaVersionFromLibs = JavaVersion.valueOf(libs.versions.app.build.javaVersion.get().toString())
sourceCompatibility = currentJavaVersionFromLibs
targetCompatibility = currentJavaVersionFromLibs
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = project.libs.versions.app.build.kotlinJVMTarget.get()
}
namespace = libs.versions.app.version.appId.get()
lint {
checkReleaseBuilds = false
abortOnError = false
}
}
dependencies {
implementation(libs.simple.tools.commons)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.documentfile)
implementation(libs.kotlinx.serialization.json)
implementation(libs.bundles.room)
ksp(libs.androidx.room.compiler)
}

View File

@ -0,0 +1,140 @@
{
"formatVersion": 1,
"database": {
"version": 4,
"identityHash": "e470b6e1411ee6659417cf4dbe54f453",
"entities": [
{
"tableName": "notes",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` TEXT NOT NULL, `value` TEXT NOT NULL, `type` INTEGER NOT NULL, `path` TEXT NOT NULL, `protection_type` INTEGER NOT NULL, `protection_hash` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "path",
"columnName": "path",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "protectionType",
"columnName": "protection_type",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "protectionHash",
"columnName": "protection_hash",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_notes_id",
"unique": true,
"columnNames": [
"id"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_notes_id` ON `${TABLE_NAME}` (`id`)"
}
],
"foreignKeys": []
},
{
"tableName": "widgets",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `widget_id` INTEGER NOT NULL, `note_id` INTEGER NOT NULL, `widget_bg_color` INTEGER NOT NULL, `widget_text_color` INTEGER NOT NULL, `widget_show_title` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "widgetId",
"columnName": "widget_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "noteId",
"columnName": "note_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "widgetBgColor",
"columnName": "widget_bg_color",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "widgetTextColor",
"columnName": "widget_text_color",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "widgetShowTitle",
"columnName": "widget_show_title",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_widgets_widget_id",
"unique": true,
"columnNames": [
"widget_id"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_widgets_widget_id` ON `${TABLE_NAME}` (`widget_id`)"
}
],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'e470b6e1411ee6659417cf4dbe54f453')"
]
}
}

View File

@ -39,14 +39,13 @@ import com.simplemobiletools.notes.pro.BuildConfig
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.adapters.NotesPagerAdapter
import com.simplemobiletools.notes.pro.databases.NotesDatabase
import com.simplemobiletools.notes.pro.databinding.ActivityMainBinding
import com.simplemobiletools.notes.pro.dialogs.*
import com.simplemobiletools.notes.pro.extensions.*
import com.simplemobiletools.notes.pro.fragments.TextFragment
import com.simplemobiletools.notes.pro.helpers.*
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.item_checklist.*
import java.io.File
import java.nio.charset.Charset
import java.util.*
@ -81,26 +80,29 @@ class MainActivity : SimpleActivity() {
private lateinit var searchNextBtn: ImageView
private lateinit var searchClearBtn: ImageView
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
appLaunched(BuildConfig.APPLICATION_ID)
setupOptionsMenu()
refreshMenuItems()
updateMaterialActivityViews(main_coordinator, null, useTransparentNavigation = false, useTopSearchMenu = false)
updateMaterialActivityViews(binding.mainCoordinator, null, useTransparentNavigation = false, useTopSearchMenu = false)
searchQueryET = findViewById(R.id.search_query)
searchPrevBtn = findViewById(R.id.search_previous)
searchNextBtn = findViewById(R.id.search_next)
searchClearBtn = findViewById(R.id.search_clear)
searchQueryET = findViewById(com.simplemobiletools.commons.R.id.search_query)
searchPrevBtn = findViewById(com.simplemobiletools.commons.R.id.search_previous)
searchNextBtn = findViewById(com.simplemobiletools.commons.R.id.search_next)
searchClearBtn = findViewById(com.simplemobiletools.commons.R.id.search_clear)
initViewPager(intent.getLongExtra(OPEN_NOTE_ID, -1L))
pager_tab_strip.drawFullUnderline = false
pager_tab_strip.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
pager_tab_strip.layoutParams.height =
(pager_tab_strip.height + resources.getDimension(R.dimen.activity_margin) * 2 * (config.fontSizePercentage / 100f)).toInt()
binding.pagerTabStrip.drawFullUnderline = false
binding.pagerTabStrip.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
binding.pagerTabStrip.layoutParams.height =
(binding.pagerTabStrip.height + resources.getDimension(com.simplemobiletools.commons.R.dimen.activity_margin) * 2 * (config.fontSizePercentage / 100f)).toInt()
checkWhatsNewDialog()
checkIntents(intent)
@ -115,14 +117,14 @@ class MainActivity : SimpleActivity() {
setupSearchButtons()
if (isPackageInstalled("com.simplemobiletools.notes")) {
val dialogText = getString(R.string.upgraded_from_free_notes)
ConfirmationDialog(this, dialogText, 0, R.string.ok, 0, false) {}
val dialogText = getString(com.simplemobiletools.commons.R.string.upgraded_from_free_notes)
ConfirmationDialog(this, dialogText, 0, com.simplemobiletools.commons.R.string.ok, 0, false) {}
}
}
override fun onResume() {
super.onResume()
setupToolbar(main_toolbar)
setupToolbar(binding.mainToolbar)
if (storedEnableLineWrap != config.enableLineWrap) {
initViewPager()
}
@ -134,24 +136,24 @@ class MainActivity : SimpleActivity() {
}
refreshMenuItems()
pager_tab_strip.apply {
binding.pagerTabStrip.apply {
setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
setGravity(Gravity.CENTER_VERTICAL)
setNonPrimaryAlpha(0.4f)
setTextColor(getProperPrimaryColor())
tabIndicatorColor = getProperPrimaryColor()
}
updateTextColors(view_pager)
updateTextColors(binding.viewPager)
checkShortcuts()
search_wrapper.setBackgroundColor(getProperStatusBarColor())
binding.searchWrapper.setBackgroundColor(getProperStatusBarColor())
val contrastColor = getProperPrimaryColor().getContrastColor()
arrayListOf(searchPrevBtn, searchNextBtn, searchClearBtn).forEach {
it.applyColorFilter(contrastColor)
}
updateTopBarColors(main_toolbar, getProperBackgroundColor())
updateTopBarColors(binding.mainToolbar, getProperBackgroundColor())
}
override fun onPause() {
@ -170,7 +172,7 @@ class MainActivity : SimpleActivity() {
val multipleNotesExist = mNotes.size > 1
val isCurrentItemChecklist = isCurrentItemChecklist()
main_toolbar.menu.apply {
binding.mainToolbar.menu.apply {
findItem(R.id.undo).apply {
isVisible = showUndoButton && mCurrentNote.type == NoteType.TYPE_TEXT
icon?.alpha = if (isEnabled) 255 else 127
@ -190,18 +192,18 @@ class MainActivity : SimpleActivity() {
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(R.bool.hide_google_relations)
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations)
saveNoteButton = findItem(R.id.save_note)
saveNoteButton!!.isVisible =
!config.autosaveNotes && showSaveButton && (::mCurrentNote.isInitialized && mCurrentNote.type == NoteType.TYPE_TEXT)
}
pager_tab_strip.beVisibleIf(multipleNotesExist)
binding.pagerTabStrip.beVisibleIf(multipleNotesExist)
}
private fun setupOptionsMenu() {
main_toolbar.setOnMenuItemClickListener { menuItem ->
binding.mainToolbar.setOnMenuItemClickListener { menuItem ->
if (config.autosaveNotes && menuItem.itemId != R.id.undo && menuItem.itemId != R.id.redo) {
saveCurrentNote(false)
}
@ -257,7 +259,7 @@ class MainActivity : SimpleActivity() {
override fun onBackPressed() {
if (!config.autosaveNotes && mAdapter?.anyHasUnsavedChanges() == true) {
ConfirmationAdvancedDialog(this, "", R.string.unsaved_changes_warning, R.string.save, R.string.discard) {
ConfirmationAdvancedDialog(this, "", R.string.unsaved_changes_warning, com.simplemobiletools.commons.R.string.save, com.simplemobiletools.commons.R.string.discard) {
if (it) {
mAdapter?.saveAllFragmentTexts()
}
@ -273,7 +275,7 @@ class MainActivity : SimpleActivity() {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1L)
view_pager.currentItem = getWantedNoteIndex(wantedNoteId)
binding.viewPager.currentItem = getWantedNoteIndex(wantedNoteId)
checkIntents(intent)
}
@ -309,7 +311,7 @@ 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(R.drawable.shortcut_plus)
val drawable = resources.getDrawable(com.simplemobiletools.commons.R.drawable.shortcut_plus)
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_plus_background).applyColorFilter(appIconColor)
val bmp = drawable.convertToBitmap()
@ -426,7 +428,7 @@ class MainActivity : SimpleActivity() {
mNotes = notes
mCurrentNote = mNotes[0]
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
view_pager.apply {
binding.viewPager.apply {
adapter = mAdapter
currentItem = getWantedNoteIndex(wantedNoteId)
config.currentNoteId = mCurrentNote.id!!
@ -462,7 +464,7 @@ class MainActivity : SimpleActivity() {
closeSearch()
}
view_pager.onPageChangeListener {
binding.viewPager.onPageChangeListener {
currentTextFragment?.removeTextWatcher()
currentNotesView()?.let { noteView ->
noteView.text!!.clearBackgroundSpans()
@ -529,9 +531,9 @@ class MainActivity : SimpleActivity() {
}
}
private fun getCurrentFragment() = mAdapter?.getFragment(view_pager.currentItem)
private fun getCurrentFragment() = mAdapter?.getFragment(binding.viewPager.currentItem)
private val currentTextFragment: TextFragment? get() = mAdapter?.textFragment(view_pager.currentItem)
private val currentTextFragment: TextFragment? get() = mAdapter?.textFragment(binding.viewPager.currentItem)
private fun selectSearchMatch(editText: MyEditText) {
if (searchMatches.isNotEmpty()) {
@ -544,7 +546,7 @@ class MainActivity : SimpleActivity() {
private fun openSearch() {
isSearchActive = true
search_wrapper.fadeIn()
binding.searchWrapper.fadeIn()
showKeyboard(searchQueryET)
currentNotesView()?.let { noteView ->
@ -560,7 +562,7 @@ class MainActivity : SimpleActivity() {
private fun closeSearch() {
searchQueryET.text?.clear()
isSearchActive = false
search_wrapper.fadeOut()
binding.searchWrapper.fadeOut()
hideKeyboard()
}
@ -570,10 +572,10 @@ class MainActivity : SimpleActivity() {
return getNoteIndexWithId(noteIdToOpen)
}
private fun currentNotesView() = if (view_pager == null) {
private fun currentNotesView() = if (binding.viewPager == null) {
null
} else {
mAdapter?.getCurrentNotesView(view_pager.currentItem)
mAdapter?.getCurrentNotesView(binding.viewPager.currentItem)
}
private fun displayRenameDialog() {
@ -592,7 +594,7 @@ class MainActivity : SimpleActivity() {
}
} else {
val index = getNoteIndexWithId(id)
view_pager.currentItem = index
binding.viewPager.currentItem = index
mCurrentNote = mNotes[index]
}
}
@ -613,7 +615,7 @@ class MainActivity : SimpleActivity() {
showRedoButton = false
initViewPager(newNoteId)
updateSelectedNote(newNoteId)
view_pager.onGlobalLayout {
binding.viewPager.onGlobalLayout {
mAdapter?.focusEditText(getNoteIndexWithId(newNoteId))
}
}
@ -628,15 +630,15 @@ class MainActivity : SimpleActivity() {
val licenses = LICENSE_RTL
val faqItems = arrayListOf(
FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons),
FAQItem(com.simplemobiletools.commons.R.string.faq_1_title_commons, com.simplemobiletools.commons.R.string.faq_1_text_commons),
FAQItem(R.string.faq_1_title, R.string.faq_1_text)
)
if (!resources.getBoolean(R.bool.hide_google_relations)) {
faqItems.add(FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons))
faqItems.add(FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons))
faqItems.add(FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons))
faqItems.add(FAQItem(R.string.faq_10_title_commons, R.string.faq_10_text_commons))
if (!resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations)) {
faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_2_title_commons, com.simplemobiletools.commons.R.string.faq_2_text_commons))
faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_6_title_commons, com.simplemobiletools.commons.R.string.faq_6_text_commons))
faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_7_title_commons, com.simplemobiletools.commons.R.string.faq_7_text_commons))
faqItems.add(FAQItem(com.simplemobiletools.commons.R.string.faq_10_title_commons, com.simplemobiletools.commons.R.string.faq_10_text_commons))
}
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
@ -656,7 +658,7 @@ class MainActivity : SimpleActivity() {
putExtra(Intent.EXTRA_MIME_TYPES, mimetypes)
startActivityForResult(this, PICK_OPEN_FILE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
toast(com.simplemobiletools.commons.R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
@ -693,7 +695,7 @@ class MainActivity : SimpleActivity() {
private fun checkFile(path: String, checkTitle: Boolean, onChecksPassed: (file: File) -> Unit) {
val file = File(path)
if (path.isMediaFile()) {
toast(R.string.invalid_file_format)
toast(com.simplemobiletools.commons.R.string.invalid_file_format)
} else if (file.length() > 1000 * 1000) {
toast(R.string.file_too_large)
} else if (checkTitle && mNotes.any { it.title.equals(path.getFilenameFromPath(), true) }) {
@ -734,7 +736,7 @@ class MainActivity : SimpleActivity() {
if (realPath != null) {
openPath(realPath)
} else {
R.string.unknown_error_occurred
com.simplemobiletools.commons.R.string.unknown_error_occurred
}
} else if (realPath != null && realPath != "") {
checkFile(realPath, false) {
@ -831,7 +833,7 @@ class MainActivity : SimpleActivity() {
}
}
} else {
toast(R.string.no_storage_permissions)
toast(com.simplemobiletools.commons.R.string.no_storage_permissions)
}
}
}
@ -861,7 +863,7 @@ class MainActivity : SimpleActivity() {
try {
startActivityForResult(this, PICK_EXPORT_FILE_INTENT)
} catch (e: ActivityNotFoundException) {
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
toast(com.simplemobiletools.commons.R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: NetworkErrorException) {
toast(getString(R.string.cannot_load_over_internet), Toast.LENGTH_LONG)
} catch (e: Exception) {
@ -875,7 +877,7 @@ class MainActivity : SimpleActivity() {
ExportFileDialog(this, mCurrentNote) {
val textToExport = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
if (textToExport == null || textToExport.isEmpty()) {
toast(R.string.unknown_error_occurred)
toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
} else if (mCurrentNote.type == NoteType.TYPE_TEXT) {
showExportFilePickUpdateDialog(it, textToExport)
} else {
@ -902,7 +904,7 @@ class MainActivity : SimpleActivity() {
mCurrentNote.value = textToExport
}
getPagerAdapter().updateCurrentNoteData(view_pager.currentItem, mCurrentNote.path, mCurrentNote.value)
getPagerAdapter().updateCurrentNoteData(binding.viewPager.currentItem, mCurrentNote.path, mCurrentNote.value)
NotesHelper(this).insertOrUpdateNote(mCurrentNote)
}
}
@ -924,7 +926,7 @@ class MainActivity : SimpleActivity() {
private fun exportNoteValueToFile(path: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) {
try {
if (File(path).isDirectory) {
toast(R.string.name_taken)
toast(com.simplemobiletools.commons.R.string.name_taken)
return
}
@ -1022,15 +1024,15 @@ class MainActivity : SimpleActivity() {
}
}
private fun getPagerAdapter() = view_pager.adapter as NotesPagerAdapter
private fun getPagerAdapter() = binding.viewPager.adapter as NotesPagerAdapter
private fun getCurrentNoteText() = getPagerAdapter().getCurrentNoteViewText(view_pager.currentItem)
private fun getCurrentNoteText() = getPagerAdapter().getCurrentNoteViewText(binding.viewPager.currentItem)
private fun getCurrentNoteValue(): String {
return if (mCurrentNote.type == NoteType.TYPE_TEXT) {
getCurrentNoteText() ?: ""
} else {
getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
getPagerAdapter().getNoteChecklistItems(binding.viewPager.currentItem) ?: ""
}
}
@ -1039,19 +1041,19 @@ class MainActivity : SimpleActivity() {
getCurrentNoteText() ?: ""
} else {
var printableText = ""
getPagerAdapter().getNoteChecklistRawItems(view_pager.currentItem)?.forEach {
getPagerAdapter().getNoteChecklistRawItems(binding.viewPager.currentItem)?.forEach {
printableText += "${it.title}\n\n"
}
printableText
}
}
private fun addTextToCurrentNote(text: String) = getPagerAdapter().appendText(view_pager.currentItem, text)
private fun addTextToCurrentNote(text: String) = getPagerAdapter().appendText(binding.viewPager.currentItem, text)
private fun saveCurrentNote(force: Boolean) {
getPagerAdapter().saveCurrentNote(view_pager.currentItem, force)
getPagerAdapter().saveCurrentNote(binding.viewPager.currentItem, force)
if (mCurrentNote.type == NoteType.TYPE_CHECKLIST) {
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(binding.viewPager.currentItem) ?: ""
}
}
@ -1102,7 +1104,7 @@ class MainActivity : SimpleActivity() {
if (deleteFile) {
deleteFile(FileDirItem(note.path, note.title)) {
if (!it) {
toast(R.string.unknown_error_occurred)
toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
}
}
}
@ -1130,11 +1132,11 @@ class MainActivity : SimpleActivity() {
}
private fun undo() {
mAdapter?.undo(view_pager.currentItem)
mAdapter?.undo(binding.viewPager.currentItem)
}
private fun redo() {
mAdapter?.redo(view_pager.currentItem)
mAdapter?.redo(binding.viewPager.currentItem)
}
private fun getNoteIndexWithId(id: Long): Int {
@ -1155,7 +1157,7 @@ class MainActivity : SimpleActivity() {
}
val res = resources
val shareTitle = res.getString(R.string.share_via)
val shareTitle = res.getString(com.simplemobiletools.commons.R.string.share_via)
Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_SUBJECT, mCurrentNote.title)
@ -1190,7 +1192,7 @@ class MainActivity : SimpleActivity() {
}
private fun lockNote() {
ConfirmationDialog(this, "", R.string.locking_warning, R.string.ok, R.string.cancel) {
ConfirmationDialog(this, "", R.string.locking_warning, com.simplemobiletools.commons.R.string.ok, com.simplemobiletools.commons.R.string.cancel) {
SecurityDialog(this, "", SHOW_ALL_TABS) { hash, type, success ->
if (success) {
mCurrentNote.protectionHash = hash
@ -1271,12 +1273,12 @@ class MainActivity : SimpleActivity() {
}
private fun removeDoneItems() {
getPagerAdapter().removeDoneCheckListItems(view_pager.currentItem)
getPagerAdapter().removeDoneCheckListItems(binding.viewPager.currentItem)
}
private fun displaySortChecklistDialog() {
SortChecklistDialog(this) {
getPagerAdapter().refreshChecklist(view_pager.currentItem)
getPagerAdapter().refreshChecklist(binding.viewPager.currentItem)
updateWidgets()
}
}

View File

@ -12,15 +12,14 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.databinding.ActivitySettingsBinding
import com.simplemobiletools.notes.pro.dialogs.ExportNotesDialog
import com.simplemobiletools.notes.pro.dialogs.ManageAutoBackupsDialog
import com.simplemobiletools.notes.pro.extensions.*
import com.simplemobiletools.notes.pro.helpers.*
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.Widget
import kotlinx.android.synthetic.main.activity_settings.*
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.util.Locale
@ -28,19 +27,21 @@ import kotlin.system.exitProcess
class SettingsActivity : SimpleActivity() {
private val notesFileType = "application/json"
private lateinit var binding: ActivitySettingsBinding
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
updateMaterialActivityViews(settings_coordinator, settings_holder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(settings_nested_scrollview, settings_toolbar)
updateMaterialActivityViews(binding.settingsCoordinator, binding.settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(binding.settingsNestedScrollview, binding.settingsToolbar)
}
override fun onResume() {
super.onResume()
setupToolbar(settings_toolbar, NavigationIcon.Arrow)
setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow)
setupCustomizeColors()
setupUseEnglish()
@ -62,16 +63,16 @@ class SettingsActivity : SimpleActivity() {
setupNotesImport()
setupEnableAutomaticBackups()
setupManageAutomaticBackups()
updateTextColors(settings_nested_scrollview)
updateTextColors(binding.settingsNestedScrollview)
arrayOf(
settings_color_customization_section_label,
settings_general_settings_label,
settings_text_label,
settings_startup_label,
settings_saving_label,
settings_migrating_label,
settings_backups_label,
binding.settingsColorCustomizationLabel,
binding.settingsGeneralSettingsLabel,
binding.settingsTextLabel,
binding.settingsStartupLabel,
binding.settingsSavingLabel,
binding.settingsMigratingLabel,
binding.settingsBackupsLabel,
).forEach {
it.setTextColor(getProperPrimaryColor())
}
@ -84,14 +85,14 @@ class SettingsActivity : SimpleActivity() {
private val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
if (uri != null) {
toast(R.string.importing)
toast(com.simplemobiletools.commons.R.string.importing)
importNotes(uri)
}
}
private val saveDocument = registerForActivityResult(ActivityResultContracts.CreateDocument(notesFileType)) { uri ->
if (uri != null) {
toast(R.string.exporting)
toast(com.simplemobiletools.commons.R.string.exporting)
NotesHelper(this).getNotes { notes ->
requestUnlockNotes(notes) { unlockedNotes ->
val notLockedNotes = notes.filterNot { it.isLocked() }
@ -103,101 +104,101 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupCustomizeColors() {
settings_color_customization_holder.setOnClickListener {
binding.settingsColorCustomizationHolder.setOnClickListener {
startCustomizationActivity()
}
}
private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
settings_use_english.isChecked = config.useEnglish
settings_use_english_holder.setOnClickListener {
settings_use_english.toggle()
config.useEnglish = settings_use_english.isChecked
binding.settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
binding.settingsUseEnglish.isChecked = config.useEnglish
binding.settingsUseEnglishHolder.setOnClickListener {
binding.settingsUseEnglish.toggle()
config.useEnglish = binding.settingsUseEnglish.isChecked
exitProcess(0)
}
}
private fun setupLanguage() {
settings_language.text = Locale.getDefault().displayLanguage
settings_language_holder.beVisibleIf(isTiramisuPlus())
settings_language_holder.setOnClickListener {
binding.settingsLanguage.text = Locale.getDefault().displayLanguage
binding.settingsLanguageHolder.beVisibleIf(isTiramisuPlus())
binding.settingsLanguageHolder.setOnClickListener {
launchChangeAppLanguageIntent()
}
}
private fun setupAutosaveNotes() {
settings_autosave_notes.isChecked = config.autosaveNotes
settings_autosave_notes_holder.setOnClickListener {
settings_autosave_notes.toggle()
config.autosaveNotes = settings_autosave_notes.isChecked
binding.settingsAutosaveNotes.isChecked = config.autosaveNotes
binding.settingsAutosaveNotesHolder.setOnClickListener {
binding.settingsAutosaveNotes.toggle()
config.autosaveNotes = binding.settingsAutosaveNotes.isChecked
}
}
private fun setupDisplaySuccess() {
settings_display_success.isChecked = config.displaySuccess
settings_display_success_holder.setOnClickListener {
settings_display_success.toggle()
config.displaySuccess = settings_display_success.isChecked
binding.settingsDisplaySuccess.isChecked = config.displaySuccess
binding.settingsDisplaySuccessHolder.setOnClickListener {
binding.settingsDisplaySuccess.toggle()
config.displaySuccess = binding.settingsDisplaySuccess.isChecked
}
}
private fun setupClickableLinks() {
settings_clickable_links.isChecked = config.clickableLinks
settings_clickable_links_holder.setOnClickListener {
settings_clickable_links.toggle()
config.clickableLinks = settings_clickable_links.isChecked
binding.settingsClickableLinks.isChecked = config.clickableLinks
binding.settingsClickableLinksHolder.setOnClickListener {
binding.settingsClickableLinks.toggle()
config.clickableLinks = binding.settingsClickableLinks.isChecked
}
}
private fun setupMonospacedFont() {
settings_monospaced_font.isChecked = config.monospacedFont
settings_monospaced_font_holder.setOnClickListener {
settings_monospaced_font.toggle()
config.monospacedFont = settings_monospaced_font.isChecked
binding.settingsMonospacedFont.isChecked = config.monospacedFont
binding.settingsMonospacedFontHolder.setOnClickListener {
binding.settingsMonospacedFont.toggle()
config.monospacedFont = binding.settingsMonospacedFont.isChecked
updateWidgets()
}
}
private fun setupShowKeyboard() {
settings_show_keyboard.isChecked = config.showKeyboard
settings_show_keyboard_holder.setOnClickListener {
settings_show_keyboard.toggle()
config.showKeyboard = settings_show_keyboard.isChecked
binding.settingsShowKeyboard.isChecked = config.showKeyboard
binding.settingsShowKeyboardHolder.setOnClickListener {
binding.settingsShowKeyboard.toggle()
config.showKeyboard = binding.settingsShowKeyboard.isChecked
}
}
private fun setupShowNotePicker() {
NotesHelper(this).getNotes {
settings_show_note_picker_holder.beVisibleIf(it.size > 1)
binding.settingsShowNotePickerHolder.beVisibleIf(it.size > 1)
}
settings_show_note_picker.isChecked = config.showNotePicker
settings_show_note_picker_holder.setOnClickListener {
settings_show_note_picker.toggle()
config.showNotePicker = settings_show_note_picker.isChecked
binding.settingsShowNotePicker.isChecked = config.showNotePicker
binding.settingsShowNotePickerHolder.setOnClickListener {
binding.settingsShowNotePicker.toggle()
config.showNotePicker = binding.settingsShowNotePicker.isChecked
}
}
private fun setupShowWordCount() {
settings_show_word_count.isChecked = config.showWordCount
settings_show_word_count_holder.setOnClickListener {
settings_show_word_count.toggle()
config.showWordCount = settings_show_word_count.isChecked
binding.settingsShowWordCount.isChecked = config.showWordCount
binding.settingsShowWordCountHolder.setOnClickListener {
binding.settingsShowWordCount.toggle()
config.showWordCount = binding.settingsShowWordCount.isChecked
}
}
private fun setupEnableLineWrap() {
settings_enable_line_wrap.isChecked = config.enableLineWrap
settings_enable_line_wrap_holder.setOnClickListener {
settings_enable_line_wrap.toggle()
config.enableLineWrap = settings_enable_line_wrap.isChecked
binding.settingsEnableLineWrap.isChecked = config.enableLineWrap
binding.settingsEnableLineWrapHolder.setOnClickListener {
binding.settingsEnableLineWrap.toggle()
config.enableLineWrap = binding.settingsEnableLineWrap.isChecked
}
}
private fun setupFontSize() {
settings_font_size.text = getFontSizePercentText(config.fontSizePercentage)
settings_font_size_holder.setOnClickListener {
binding.settingsFontSize.text = getFontSizePercentText(config.fontSizePercentage)
binding.settingsFontSizeHolder.setOnClickListener {
val items = arrayListOf(
RadioItem(FONT_SIZE_50_PERCENT, getFontSizePercentText(FONT_SIZE_50_PERCENT)),
RadioItem(FONT_SIZE_60_PERCENT, getFontSizePercentText(FONT_SIZE_60_PERCENT)),
@ -214,7 +215,7 @@ class SettingsActivity : SimpleActivity() {
RadioGroupDialog(this@SettingsActivity, items, config.fontSizePercentage) {
config.fontSizePercentage = it as Int
settings_font_size.text = getFontSizePercentText(config.fontSizePercentage)
binding.settingsFontSize.text = getFontSizePercentText(config.fontSizePercentage)
updateWidgets()
}
}
@ -223,12 +224,12 @@ class SettingsActivity : SimpleActivity() {
private fun getFontSizePercentText(fontSizePercentage: Int): String = "$fontSizePercentage%"
private fun setupGravity() {
settings_gravity.text = getGravityText()
settings_gravity_holder.setOnClickListener {
binding.settingsGravity.text = getGravityText()
binding.settingsGravityHolder.setOnClickListener {
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
settings_gravity.text = getGravityText()
binding.settingsGravity.text = getGravityText()
updateWidgets()
}
}
@ -254,17 +255,17 @@ class SettingsActivity : SimpleActivity() {
private fun getGravityText() = getGravityOptionLabel(config.gravity)
private fun setupCursorPlacement() {
settings_cursor_placement.isChecked = config.placeCursorToEnd
settings_cursor_placement_holder.setOnClickListener {
settings_cursor_placement.toggle()
config.placeCursorToEnd = settings_cursor_placement.isChecked
binding.settingsCursorPlacement.isChecked = config.placeCursorToEnd
binding.settingsCursorPlacementHolder.setOnClickListener {
binding.settingsCursorPlacement.toggle()
config.placeCursorToEnd = binding.settingsCursorPlacement.isChecked
}
}
private fun setupCustomizeWidgetColors() {
var widgetToCustomize: Widget? = null
settings_widget_color_customization_holder.setOnClickListener {
binding.settingsWidgetColorCustomizationHolder.setOnClickListener {
Intent(this, WidgetConfigureActivity::class.java).apply {
putExtra(IS_CUSTOMIZING_COLORS, true)
@ -290,16 +291,16 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupIncognitoMode() {
settings_use_incognito_mode_holder.beVisibleIf(isOreoPlus())
settings_use_incognito_mode.isChecked = config.useIncognitoMode
settings_use_incognito_mode_holder.setOnClickListener {
settings_use_incognito_mode.toggle()
config.useIncognitoMode = settings_use_incognito_mode.isChecked
binding.settingsUseIncognitoModeHolder.beVisibleIf(isOreoPlus())
binding.settingsUseIncognitoMode.isChecked = config.useIncognitoMode
binding.settingsUseIncognitoModeHolder.setOnClickListener {
binding.settingsUseIncognitoMode.toggle()
config.useIncognitoMode = binding.settingsUseIncognitoMode.isChecked
}
}
private fun setupNotesExport() {
settings_export_notes_holder.setOnClickListener {
binding.settingsExportNotesHolder.setOnClickListener {
ExportNotesDialog(this) { filename ->
saveDocument.launch(filename)
}
@ -307,14 +308,14 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupNotesImport() {
settings_import_notes_holder.setOnClickListener {
binding.settingsImportNotesHolder.setOnClickListener {
getContent.launch(notesFileType)
}
}
private fun exportNotes(notes: List<Note>, uri: Uri) {
if (notes.isEmpty()) {
toast(R.string.no_entries_for_exporting)
toast(com.simplemobiletools.commons.R.string.no_entries_for_exporting)
} else {
try {
val outputStream = contentResolver.openOutputStream(uri)!!
@ -323,7 +324,7 @@ class SettingsActivity : SimpleActivity() {
outputStream.use {
it.write(jsonString.toByteArray())
}
toast(R.string.exporting_successful)
toast(com.simplemobiletools.commons.R.string.exporting_successful)
} catch (e: Exception) {
showErrorToast(e)
}
@ -337,31 +338,31 @@ class SettingsActivity : SimpleActivity() {
}
val objects = Json.decodeFromString<List<Note>>(jsonString)
if (objects.isEmpty()) {
toast(R.string.no_entries_for_importing)
toast(com.simplemobiletools.commons.R.string.no_entries_for_importing)
return
}
NotesHelper(this).importNotes(this, objects) { importResult ->
when (importResult) {
NotesHelper.ImportResult.IMPORT_OK -> toast(R.string.importing_successful)
NotesHelper.ImportResult.IMPORT_PARTIAL -> toast(R.string.importing_some_entries_failed)
NotesHelper.ImportResult.IMPORT_NOTHING_NEW -> toast(R.string.no_new_items)
else -> toast(R.string.importing_failed)
NotesHelper.ImportResult.IMPORT_OK -> toast(com.simplemobiletools.commons.R.string.importing_successful)
NotesHelper.ImportResult.IMPORT_PARTIAL -> toast(com.simplemobiletools.commons.R.string.importing_some_entries_failed)
NotesHelper.ImportResult.IMPORT_NOTHING_NEW -> toast(com.simplemobiletools.commons.R.string.no_new_items)
else -> toast(com.simplemobiletools.commons.R.string.importing_failed)
}
}
} catch (_: SerializationException) {
toast(R.string.invalid_file_format)
toast(com.simplemobiletools.commons.R.string.invalid_file_format)
} catch (_: IllegalArgumentException) {
toast(R.string.invalid_file_format)
toast(com.simplemobiletools.commons.R.string.invalid_file_format)
} catch (e: Exception) {
showErrorToast(e)
}
}
private fun setupEnableAutomaticBackups() {
settings_backups_label.beVisibleIf(isRPlus())
settings_enable_automatic_backups_holder.beVisibleIf(isRPlus())
settings_enable_automatic_backups.isChecked = config.autoBackup
settings_enable_automatic_backups_holder.setOnClickListener {
binding.settingsBackupsLabel.beVisibleIf(isRPlus())
binding.settingsEnableAutomaticBackupsHolder.beVisibleIf(isRPlus())
binding.settingsEnableAutomaticBackups.isChecked = config.autoBackup
binding.settingsEnableAutomaticBackupsHolder.setOnClickListener {
val wasBackupDisabled = !config.autoBackup
if (wasBackupDisabled) {
ManageAutoBackupsDialog(
@ -379,8 +380,8 @@ class SettingsActivity : SimpleActivity() {
}
private fun setupManageAutomaticBackups() {
settings_manage_automatic_backups_holder.beVisibleIf(isRPlus() && config.autoBackup)
settings_manage_automatic_backups_holder.setOnClickListener {
binding.settingsManageAutomaticBackupsHolder.beVisibleIf(isRPlus() && config.autoBackup)
binding.settingsManageAutomaticBackupsHolder.setOnClickListener {
ManageAutoBackupsDialog(
activity = this,
onSuccess = {
@ -392,7 +393,7 @@ class SettingsActivity : SimpleActivity() {
private fun enableOrDisableAutomaticBackups(enable: Boolean) {
config.autoBackup = enable
settings_enable_automatic_backups.isChecked = enable
settings_manage_automatic_backups_holder.beVisibleIf(enable)
binding.settingsEnableAutomaticBackups.isChecked = enable
binding.settingsManageAutomaticBackupsHolder.beVisibleIf(enable)
}
}

View File

@ -21,6 +21,7 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter
import com.simplemobiletools.notes.pro.databinding.WidgetConfigBinding
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
import com.simplemobiletools.notes.pro.extensions.widgetsDB
@ -29,9 +30,6 @@ import com.simplemobiletools.notes.pro.models.ChecklistItem
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import com.simplemobiletools.notes.pro.models.Widget
import kotlinx.android.synthetic.main.widget_config.*
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
class WidgetConfigureActivity : SimpleActivity() {
private var mBgAlpha = 0f
@ -43,12 +41,14 @@ class WidgetConfigureActivity : SimpleActivity() {
private var mIsCustomizingColors = false
private var mShowTitle = false
private var mNotes = listOf<Note>()
private lateinit var binding: WidgetConfigBinding
public override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false
super.onCreate(savedInstanceState)
setResult(RESULT_CANCELED)
setContentView(R.layout.widget_config)
binding = WidgetConfigBinding.inflate(layoutInflater)
setContentView(binding.root)
initVariables()
mWidgetId = intent.extras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID) ?: AppWidgetManager.INVALID_APPWIDGET_ID
@ -57,25 +57,25 @@ class WidgetConfigureActivity : SimpleActivity() {
finish()
}
updateTextColors(notes_picker_holder)
config_save.setOnClickListener { saveConfig() }
config_bg_color.setOnClickListener { pickBackgroundColor() }
config_text_color.setOnClickListener { pickTextColor() }
notes_picker_value.setOnClickListener { showNoteSelector() }
updateTextColors(binding.notesPickerHolder)
binding.configSave.setOnClickListener { saveConfig() }
binding.configBgColor.setOnClickListener { pickBackgroundColor() }
binding.configTextColor.setOnClickListener { pickTextColor() }
binding.notesPickerValue.setOnClickListener { showNoteSelector() }
val primaryColor = getProperPrimaryColor()
config_bg_seekbar.setColors(mTextColor, primaryColor, primaryColor)
notes_picker_holder.background = ColorDrawable(getProperBackgroundColor())
binding.configBgSeekbar.setColors(mTextColor, primaryColor, primaryColor)
binding.notesPickerHolder.background = ColorDrawable(getProperBackgroundColor())
show_note_title_holder.setOnClickListener {
show_note_title.toggle()
binding.showNoteTitleHolder.setOnClickListener {
binding.showNoteTitle.toggle()
handleNoteTitleDisplay()
}
}
override fun onResume() {
super.onResume()
text_note_view.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
binding.textNoteView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getPercentageFontSize())
}
private fun initVariables() {
@ -89,14 +89,14 @@ class WidgetConfigureActivity : SimpleActivity() {
mShowTitle = extras?.getBoolean(CUSTOMIZED_WIDGET_SHOW_TITLE) ?: false
}
if (mTextColor == resources.getColor(R.color.default_widget_text_color) && config.isUsingSystemTheme) {
mTextColor = resources.getColor(R.color.you_primary_color, theme)
if (mTextColor == resources.getColor(com.simplemobiletools.commons.R.color.default_widget_text_color) && config.isUsingSystemTheme) {
mTextColor = resources.getColor(com.simplemobiletools.commons.R.color.you_primary_color, theme)
}
mBgAlpha = Color.alpha(mBgColor) / 255.toFloat()
mBgColorWithoutTransparency = Color.rgb(Color.red(mBgColor), Color.green(mBgColor), Color.blue(mBgColor))
config_bg_seekbar.apply {
binding.configBgSeekbar.apply {
progress = (mBgAlpha * 100).toInt()
onSeekBarChangeListener {
@ -108,12 +108,12 @@ class WidgetConfigureActivity : SimpleActivity() {
updateTextColor()
mIsCustomizingColors = extras?.getBoolean(IS_CUSTOMIZING_COLORS) ?: false
notes_picker_holder.beVisibleIf(!mIsCustomizingColors)
text_note_view_title.beGoneIf(!mShowTitle)
binding.notesPickerHolder.beVisibleIf(!mIsCustomizingColors)
binding.textNoteViewTitle.beGoneIf(!mShowTitle)
NotesHelper(this).getNotes {
mNotes = it
notes_picker_holder.beVisibleIf(mNotes.size > 1 && !mIsCustomizingColors)
binding.notesPickerHolder.beVisibleIf(mNotes.size > 1 && !mIsCustomizingColors)
var note = mNotes.firstOrNull { !it.isLocked() }
if (mNotes.size == 1 && note == null) {
@ -157,8 +157,8 @@ class WidgetConfigureActivity : SimpleActivity() {
private fun updateCurrentNote(note: Note) {
mCurrentNoteId = note.id!!
notes_picker_value.text = note.title
text_note_view_title.text = note.title
binding.notesPickerValue.text = note.title
binding.textNoteViewTitle.text = note.title
if (note.type == NoteType.TYPE_CHECKLIST) {
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
val items = Gson().fromJson<ArrayList<ChecklistItem>>(note.value, checklistItemType) ?: ArrayList(1)
@ -172,18 +172,18 @@ class WidgetConfigureActivity : SimpleActivity() {
}
}
ChecklistAdapter(this, items, null, checklist_note_view, false) {}.apply {
ChecklistAdapter(this, items, null, binding.checklistNoteView, false) {}.apply {
updateTextColor(mTextColor)
checklist_note_view.adapter = this
binding.checklistNoteView.adapter = this
}
text_note_view.beGone()
checklist_note_view.beVisible()
binding.textNoteView.beGone()
binding.checklistNoteView.beVisible()
} else {
val sampleValue = if (note.value.isEmpty() || mIsCustomizingColors) getString(R.string.widget_config) else note.value
text_note_view.text = sampleValue
text_note_view.typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT
text_note_view.beVisible()
checklist_note_view.beGone()
binding.textNoteView.text = sampleValue
binding.textNoteView.typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT
binding.textNoteView.beVisible()
binding.checklistNoteView.beGone()
}
}
@ -233,19 +233,19 @@ class WidgetConfigureActivity : SimpleActivity() {
private fun updateBackgroundColor() {
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
text_note_view.setBackgroundColor(mBgColor)
checklist_note_view.setBackgroundColor(mBgColor)
text_note_view_title.setBackgroundColor(mBgColor)
config_bg_color.setFillWithStroke(mBgColor, mBgColor)
config_save.backgroundTintList = ColorStateList.valueOf(getProperPrimaryColor())
binding.textNoteView.setBackgroundColor(mBgColor)
binding.checklistNoteView.setBackgroundColor(mBgColor)
binding.textNoteViewTitle.setBackgroundColor(mBgColor)
binding.configBgColor.setFillWithStroke(mBgColor, mBgColor)
binding.configSave.backgroundTintList = ColorStateList.valueOf(getProperPrimaryColor())
}
private fun updateTextColor() {
text_note_view.setTextColor(mTextColor)
text_note_view_title.setTextColor(mTextColor)
(checklist_note_view.adapter as? ChecklistAdapter)?.updateTextColor(mTextColor)
config_text_color.setFillWithStroke(mTextColor, mTextColor)
config_save.setTextColor(getProperPrimaryColor().getContrastColor())
binding.textNoteView.setTextColor(mTextColor)
binding.textNoteViewTitle.setTextColor(mTextColor)
(binding.checklistNoteView.adapter as? ChecklistAdapter)?.updateTextColor(mTextColor)
binding.configTextColor.setFillWithStroke(mTextColor, mTextColor)
binding.configSave.setTextColor(getProperPrimaryColor().getContrastColor())
}
private fun pickBackgroundColor() {
@ -267,8 +267,8 @@ class WidgetConfigureActivity : SimpleActivity() {
}
private fun handleNoteTitleDisplay() {
val showTitle = show_note_title.isChecked
text_note_view_title.beGoneIf(!showTitle)
val showTitle = binding.showNoteTitle.isChecked
binding.textNoteViewTitle.beGoneIf(!showTitle)
mShowTitle = showTitle
}
}

View File

@ -21,14 +21,14 @@ import com.simplemobiletools.commons.interfaces.ItemTouchHelperContract
import com.simplemobiletools.commons.interfaces.StartReorderDragListener
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.databinding.ItemChecklistBinding
import com.simplemobiletools.notes.pro.dialogs.RenameChecklistItemDialog
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
import com.simplemobiletools.notes.pro.helpers.DONE_CHECKLIST_ITEM_ALPHA
import com.simplemobiletools.notes.pro.interfaces.ChecklistItemsListener
import com.simplemobiletools.notes.pro.models.ChecklistItem
import kotlinx.android.synthetic.main.item_checklist.view.*
import java.util.*
import java.util.Collections
class ChecklistAdapter(
activity: BaseSimpleActivity, var items: MutableList<ChecklistItem>, val listener: ChecklistItemsListener?,
@ -95,7 +95,9 @@ class ChecklistAdapter(
menu.findItem(R.id.cab_rename).isVisible = isOneItemSelected()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_checklist, parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return createViewHolder(ItemChecklistBinding.inflate(layoutInflater, parent, false).root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = items[position]
@ -109,8 +111,14 @@ class ChecklistAdapter(
private fun initDrawables() {
val res = activity.resources
crossDrawable = res.getColoredDrawableWithColor(R.drawable.ic_cross_vector, res.getColor(R.color.md_red_700))
checkDrawable = res.getColoredDrawableWithColor(R.drawable.ic_check_vector, res.getColor(R.color.md_green_700))
crossDrawable = res.getColoredDrawableWithColor(
com.simplemobiletools.commons.R.drawable.ic_cross_vector,
res.getColor(com.simplemobiletools.commons.R.color.md_red_700)
)
checkDrawable = res.getColoredDrawableWithColor(
com.simplemobiletools.commons.R.drawable.ic_check_vector,
res.getColor(com.simplemobiletools.commons.R.color.md_green_700)
)
}
private fun renameChecklistItem() {
@ -182,8 +190,8 @@ class ChecklistAdapter(
private fun setupView(view: View, checklistItem: ChecklistItem, holder: ViewHolder) {
val isSelected = selectedKeys.contains(checklistItem.id)
view.apply {
checklist_title.apply {
ItemChecklistBinding.bind(view).apply {
checklistTitle.apply {
text = checklistItem.title
setTextColor(textColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
@ -198,13 +206,13 @@ class ChecklistAdapter(
}
}
checklist_image.setImageDrawable(if (checklistItem.isDone) checkDrawable else crossDrawable)
checklist_image.beVisibleIf(showIcons && selectedKeys.isEmpty())
checklist_holder.isSelected = isSelected
checklistImage.setImageDrawable(if (checklistItem.isDone) checkDrawable else crossDrawable)
checklistImage.beVisibleIf(showIcons && selectedKeys.isEmpty())
checklistHolder.isSelected = isSelected
checklist_drag_handle.beVisibleIf(selectedKeys.isNotEmpty())
checklist_drag_handle.applyColorFilter(textColor)
checklist_drag_handle.setOnTouchListener { v, event ->
checklistDragHandle.beVisibleIf(selectedKeys.isNotEmpty())
checklistDragHandle.applyColorFilter(textColor)
checklistDragHandle.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
startReorderDragListener.requestDrag(holder)
}

View File

@ -18,15 +18,11 @@ import com.simplemobiletools.commons.extensions.isBlackAndWhiteTheme
import com.simplemobiletools.commons.helpers.LOWER_ALPHA_INT
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.databinding.OpenNoteItemBinding
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.models.ChecklistItem
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.open_note_item.view.icon_lock
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
class OpenNoteAdapter(
activity: BaseSimpleActivity, var items: List<Note>,
@ -51,7 +47,7 @@ class OpenNoteAdapter(
override fun prepareActionMode(menu: Menu) {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return createViewHolder(R.layout.open_note_item, parent)
return createViewHolder(OpenNoteItemBinding.inflate(layoutInflater, parent, false).root)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
@ -65,26 +61,26 @@ class OpenNoteAdapter(
override fun getItemCount() = items.size
private fun setupView(view: View, note: Note) {
view.apply {
setupCard(open_note_item_holder)
open_note_item_title.apply {
OpenNoteItemBinding.bind(view).apply {
root.setupCard()
openNoteItemTitle.apply {
text = note.title
setTextColor(properPrimaryColor)
}
val formattedText = note.getFormattedValue(context)
open_note_item_text.beGoneIf(formattedText.isNullOrBlank() || note.isLocked())
icon_lock.beVisibleIf(note.isLocked())
icon_lock.setImageDrawable(activity.resources.getColoredDrawableWithColor(R.drawable.ic_lock_vector, properPrimaryColor))
open_note_item_text.apply {
val formattedText = note.getFormattedValue(root.context)
openNoteItemText.beGoneIf(formattedText.isNullOrBlank() || note.isLocked())
iconLock.beVisibleIf(note.isLocked())
iconLock.setImageDrawable(activity.resources.getColoredDrawableWithColor(com.simplemobiletools.commons.R.drawable.ic_lock_vector, properPrimaryColor))
openNoteItemText.apply {
text = formattedText
setTextColor(textColor)
}
}
}
private fun View.setupCard(holder: View) {
private fun View.setupCard() {
if (context.isBlackAndWhiteTheme()) {
holder.setBackgroundResource(R.drawable.black_dialog_background)
setBackgroundResource(com.simplemobiletools.commons.R.drawable.black_dialog_background)
} else {
val cardBackgroundColor = if (backgroundColor == Color.BLACK) {
Color.WHITE
@ -92,11 +88,11 @@ class OpenNoteAdapter(
Color.BLACK
}
val cardBackground = if (context.config.isUsingSystemTheme) {
R.drawable.dialog_you_background
com.simplemobiletools.commons.R.drawable.dialog_you_background
} else {
R.drawable.dialog_bg
com.simplemobiletools.commons.R.drawable.dialog_bg
}
holder.background =
background =
activity.resources.getColoredDrawableWithColor(cardBackground, cardBackgroundColor, LOWER_ALPHA_INT)
}
}

View File

@ -28,7 +28,7 @@ abstract class NotesDatabase : RoomDatabase() {
private var defaultWidgetBgColor = 0
fun getInstance(context: Context): NotesDatabase {
defaultWidgetBgColor = context.resources.getColor(R.color.default_widget_bg_color)
defaultWidgetBgColor = context.resources.getColor(com.simplemobiletools.commons.R.color.default_widget_bg_color)
if (db == null) {
synchronized(NotesDatabase::class) {
if (db == null) {

View File

@ -10,7 +10,7 @@ class DateTimePatternInfoDialog(activity: BaseSimpleActivity) {
init {
val view = activity.layoutInflater.inflate(R.layout.datetime_pattern_info_layout, null)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { _, _ -> { } }
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { _, _ -> { } }
.apply {
activity.setupDialogStuff(view, this)
}

View File

@ -6,30 +6,30 @@ import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogDeleteNoteBinding
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_delete_note.view.*
class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callback: (deleteFile: Boolean) -> Unit) {
var dialog: AlertDialog? = null
init {
val message = String.format(activity.getString(R.string.delete_note_prompt_message), note.title)
val view = activity.layoutInflater.inflate(R.layout.dialog_delete_note, null).apply {
val binding = DialogDeleteNoteBinding.inflate(activity.layoutInflater).apply{
if (note.path.isNotEmpty()) {
delete_note_checkbox.text = String.format(activity.getString(R.string.delete_file_itself), note.path)
delete_note_checkbox_holder.beVisible()
delete_note_checkbox_holder.setOnClickListener {
delete_note_checkbox.toggle()
deleteNoteCheckbox.text = String.format(activity.getString(R.string.delete_file_itself), note.path)
deleteNoteCheckboxHolder.beVisible()
deleteNoteCheckboxHolder.setOnClickListener {
deleteNoteCheckbox.toggle()
}
}
delete_note_description.text = message
deleteNoteDescription.text = message
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.delete) { dialog, which -> dialogConfirmed(view.delete_note_checkbox.isChecked) }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.delete) { dialog, which -> dialogConfirmed(binding.deleteNoteCheckbox.isChecked) }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this)
activity.setupDialogStuff(binding.root, this)
}
}

View File

@ -5,46 +5,46 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogExportFileBinding
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_export_file.view.*
import java.io.File
class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callback: (exportPath: String) -> Unit) {
init {
var realPath = File(note.path).parent ?: activity.config.lastUsedSavePath
val view = activity.layoutInflater.inflate(R.layout.dialog_export_file, null).apply {
file_path.setText(activity.humanizePath(realPath))
val binding = DialogExportFileBinding.inflate(activity.layoutInflater).apply {
filePath.setText(activity.humanizePath(realPath))
file_name.setText(note.title)
fileName.setText(note.title)
extension.setText(activity.config.lastUsedExtension)
file_path.setOnClickListener {
filePath.setOnClickListener {
FilePickerDialog(activity, realPath, false, false, true, true) {
file_path.setText(activity.humanizePath(it))
filePath.setText(activity.humanizePath(it))
realPath = it
}
}
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog ->
alertDialog.showKeyboard(view.file_name)
activity.setupDialogStuff(binding.root, this, R.string.export_as_file) { alertDialog ->
alertDialog.showKeyboard(binding.fileName)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.file_name.value
val extension = view.extension.value
val filename = binding.fileName.value
val extension = binding.extension.value
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
activity.toast(com.simplemobiletools.commons.R.string.filename_cannot_be_empty)
return@setOnClickListener
}
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
if (!fullFilename.isAValidFilename()) {
activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename)))
activity.toast(String.format(activity.getString(com.simplemobiletools.commons.R.string.filename_invalid_characters_placeholder, fullFilename)))
return@setOnClickListener
}

View File

@ -5,34 +5,34 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogExportFilesBinding
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_export_files.view.*
class ExportFilesDialog(val activity: SimpleActivity, val notes: ArrayList<Note>, val callback: (parent: String, extension: String) -> Unit) {
init {
var realPath = activity.config.lastUsedSavePath
val view = activity.layoutInflater.inflate(R.layout.dialog_export_files, null).apply {
folder_path.setText(activity.humanizePath(realPath))
val binding = DialogExportFilesBinding.inflate(activity.layoutInflater).apply {
folderPath.setText(activity.humanizePath(realPath))
extension.setText(activity.config.lastUsedExtension)
folder_path.setOnClickListener {
folderPath.setOnClickListener {
FilePickerDialog(activity, realPath, false, false, true, true) {
folder_path.setText(activity.humanizePath(it))
folderPath.setText(activity.humanizePath(it))
realPath = it
}
}
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.export_as_file) { alertDialog ->
alertDialog.showKeyboard(view.extension)
activity.setupDialogStuff(binding.root, this, R.string.export_as_file) { alertDialog ->
alertDialog.showKeyboard(binding.extension)
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
activity.handleSAFDialog(realPath) {
val extension = view.extension.value
val extension = binding.extension.value
activity.config.lastUsedExtension = extension
activity.config.lastUsedSavePath = realPath
callback(realPath, extension)

View File

@ -1,38 +1,37 @@
package com.simplemobiletools.notes.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import kotlinx.android.synthetic.main.dialog_export_notes.view.export_notes_filename
import com.simplemobiletools.notes.pro.databinding.DialogExportNotesBinding
class ExportNotesDialog(val activity: SimpleActivity, callback: (filename: String) -> Unit) {
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_export_notes, null) as ViewGroup).apply {
export_notes_filename.setText(
val binding = DialogExportNotesBinding.inflate(activity.layoutInflater).apply {
exportNotesFilename.setText(
buildString {
append(context.getString(R.string.notes))
append(root.context.getString(com.simplemobiletools.commons.R.string.notes))
append("_")
append(context.getCurrentFormattedDateTime())
append(root.context.getCurrentFormattedDateTime())
}
)
}
activity.getAlertDialogBuilder().setPositiveButton(R.string.ok, null).setNegativeButton(R.string.cancel, null).apply {
activity.setupDialogStuff(view, this, R.string.export_notes) { alertDialog ->
activity.getAlertDialogBuilder().setPositiveButton(com.simplemobiletools.commons.R.string.ok, null).setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null).apply {
activity.setupDialogStuff(binding.root, this, R.string.export_notes) { alertDialog ->
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.export_notes_filename.value
val filename = binding.exportNotesFilename.value
when {
filename.isEmpty() -> activity.toast(R.string.empty_name)
filename.isEmpty() -> activity.toast(com.simplemobiletools.commons.R.string.empty_name)
filename.isAValidFilename() -> {
callback(filename)
alertDialog.dismiss()
}
else -> activity.toast(R.string.invalid_name)
else -> activity.toast(com.simplemobiletools.commons.R.string.invalid_name)
}
}
}

View File

@ -1,37 +1,35 @@
package com.simplemobiletools.notes.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogImportFolderBinding
import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.extensions.parseChecklistItems
import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.dialog_import_folder.view.open_file_filename
import kotlinx.android.synthetic.main.dialog_import_folder.view.open_file_type
import java.io.File
class ImportFolderDialog(val activity: SimpleActivity, val path: String, val callback: () -> Unit) : AlertDialog.Builder(activity) {
private var dialog: AlertDialog? = null
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_folder, null) as ViewGroup).apply {
open_file_filename.setText(activity.humanizePath(path))
val binding = DialogImportFolderBinding.inflate(activity.layoutInflater).apply {
openFileFilename.setText(activity.humanizePath(path))
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.import_folder) { alertDialog ->
activity.setupDialogStuff(binding.root, this, R.string.import_folder) { alertDialog ->
dialog = alertDialog
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val updateFilesOnEdit = view.open_file_type.checkedRadioButtonId == R.id.open_file_update_file
val updateFilesOnEdit = binding.openFileType.checkedRadioButtonId == R.id.open_file_update_file
ensureBackgroundThread {
saveFolder(updateFilesOnEdit)
}

View File

@ -1,58 +1,55 @@
package com.simplemobiletools.notes.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogManageAutomaticBackupsBinding
import com.simplemobiletools.notes.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_filename
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_filename_hint
import kotlinx.android.synthetic.main.dialog_manage_automatic_backups.view.backup_notes_folder
import java.io.File
class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: () -> Unit) {
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
private val binding = DialogManageAutomaticBackupsBinding.inflate(activity.layoutInflater)
private val view = binding.root
private val config = activity.config
private var backupFolder = config.autoBackupFolder
init {
view.apply {
backup_notes_folder.setText(activity.humanizePath(backupFolder))
binding.apply {
backupNotesFolder.setText(activity.humanizePath(backupFolder))
val filename = config.autoBackupFilename.ifEmpty {
"${activity.getString(R.string.notes)}_%Y%M%D_%h%m%s"
"${activity.getString(com.simplemobiletools.commons.R.string.notes)}_%Y%M%D_%h%m%s"
}
backup_notes_filename.setText(filename)
backup_notes_filename_hint.setEndIconOnClickListener {
backupNotesFilename.setText(filename)
backupNotesFilenameHint.setEndIconOnClickListener {
DateTimePatternInfoDialog(activity)
}
backup_notes_filename_hint.setEndIconOnLongClickListener {
backupNotesFilenameHint.setEndIconOnLongClickListener {
DateTimePatternInfoDialog(activity)
true
}
backup_notes_folder.setOnClickListener {
backupNotesFolder.setOnClickListener {
selectBackupFolder()
}
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.manage_automatic_backups) { dialog ->
activity.setupDialogStuff(view, this, com.simplemobiletools.commons.R.string.manage_automatic_backups) { dialog ->
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.backup_notes_filename.value
val filename = binding.backupNotesFilename.value
when {
filename.isEmpty() -> activity.toast(R.string.empty_name)
filename.isEmpty() -> activity.toast(com.simplemobiletools.commons.R.string.empty_name)
filename.isAValidFilename() -> {
val file = File(backupFolder, "$filename.json")
if (file.exists() && !file.canWrite()) {
activity.toast(R.string.name_taken)
activity.toast(com.simplemobiletools.commons.R.string.name_taken)
return@setOnClickListener
}
@ -70,7 +67,7 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
}
}
else -> activity.toast(R.string.invalid_name)
else -> activity.toast(com.simplemobiletools.commons.R.string.invalid_name)
}
}
}
@ -78,7 +75,7 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
}
private fun selectBackupFolder() {
activity.hideKeyboard(view.backup_notes_filename)
activity.hideKeyboard(binding.backupNotesFilename)
FilePickerDialog(activity, backupFolder, false, showFAB = true) { path ->
activity.handleSAFDialog(path) { grantedSAF ->
if (!grantedSAF) {
@ -91,7 +88,7 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
}
backupFolder = path
view.backup_notes_folder.setText(activity.humanizePath(path))
binding.backupNotesFolder.setText(activity.humanizePath(path))
}
}
}

View File

@ -4,20 +4,20 @@ import android.app.Activity
import android.content.DialogInterface.BUTTON_POSITIVE
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.appcompat.widget.AppCompatEditText
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.DARK_GREY
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.databinding.DialogNewChecklistItemBinding
import com.simplemobiletools.notes.pro.databinding.ItemAddChecklistBinding
import com.simplemobiletools.notes.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
import kotlinx.android.synthetic.main.item_add_checklist.view.*
class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayList<String>) -> Unit) {
private val titles = mutableListOf<AppCompatEditText>()
private val view: ViewGroup = activity.layoutInflater.inflate(R.layout.dialog_new_checklist_item, null) as ViewGroup
private val binding = DialogNewChecklistItemBinding.inflate(activity.layoutInflater)
private val view = binding.root
init {
addNewEditText()
@ -27,25 +27,25 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
activity.getProperPrimaryColor().getContrastColor()
}
view.apply {
add_item.applyColorFilter(plusTextColor)
add_item.setOnClickListener {
binding.apply {
addItem.applyColorFilter(plusTextColor)
addItem.setOnClickListener {
addNewEditText()
}
settings_add_checklist_top.beVisibleIf(activity.config.sorting == SORT_BY_CUSTOM)
settings_add_checklist_top.isChecked = activity.config.addNewChecklistItemsTop
settingsAddChecklistTop.beVisibleIf(activity.config.sorting == SORT_BY_CUSTOM)
settingsAddChecklistTop.isChecked = activity.config.addNewChecklistItemsTop
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) { alertDialog ->
alertDialog.showKeyboard(titles.first())
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
activity.config.addNewChecklistItemsTop = view.settings_add_checklist_top.isChecked
activity.config.addNewChecklistItemsTop = binding.settingsAddChecklistTop.isChecked
when {
titles.all { it.text!!.isEmpty() } -> activity.toast(R.string.empty_name)
titles.all { it.text!!.isEmpty() } -> activity.toast(com.simplemobiletools.commons.R.string.empty_name)
else -> {
val titles = titles.map { it.text.toString() }.filter { it.isNotEmpty() }.toMutableList() as ArrayList<String>
callback(titles)
@ -58,8 +58,8 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
}
private fun addNewEditText() {
activity.layoutInflater.inflate(R.layout.item_add_checklist, null).apply {
title_edit_text.setOnEditorActionListener { _, actionId, _ ->
ItemAddChecklistBinding.inflate(activity.layoutInflater).apply {
titleEditText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || actionId == KeyEvent.KEYCODE_ENTER) {
addNewEditText()
true
@ -67,12 +67,12 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
false
}
}
titles.add(title_edit_text)
view.checklist_holder.addView(this)
activity.updateTextColors(view.checklist_holder)
view.dialog_holder.post {
view.dialog_holder.fullScroll(View.FOCUS_DOWN)
activity.showKeyboard(title_edit_text)
titles.add(titleEditText)
binding.checklistHolder.addView(this.root)
activity.updateTextColors(binding.checklistHolder)
binding.dialogHolder.post {
binding.dialogHolder.fullScroll(View.FOCUS_DOWN)
activity.showKeyboard(titleEditText)
}
}
}

View File

@ -6,40 +6,40 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.databinding.DialogNewNoteBinding
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.dialog_new_note.view.*
class NewNoteDialog(val activity: Activity, title: String? = null, val setChecklistAsDefault: Boolean, callback: (note: Note) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_new_note, null).apply {
val binding = DialogNewNoteBinding.inflate(activity.layoutInflater).apply {
val defaultType = when {
setChecklistAsDefault -> type_checklist.id
activity.config.lastCreatedNoteType == NoteType.TYPE_TEXT.value -> type_text_note.id
else -> type_checklist.id
setChecklistAsDefault -> typeChecklist.id
activity.config.lastCreatedNoteType == NoteType.TYPE_TEXT.value -> typeTextNote.id
else -> typeChecklist.id
}
new_note_type.check(defaultType)
newNoteType.check(defaultType)
}
view.locked_note_title.setText(title)
binding.lockedNoteTitle.setText(title)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.new_note) { alertDialog ->
alertDialog.showKeyboard(view.locked_note_title)
activity.setupDialogStuff(binding.root, this, R.string.new_note) { alertDialog ->
alertDialog.showKeyboard(binding.lockedNoteTitle)
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.locked_note_title.value
val newTitle = binding.lockedNoteTitle.value
ensureBackgroundThread {
when {
newTitle.isEmpty() -> activity.toast(R.string.no_title)
activity.notesDB.getNoteIdWithTitle(newTitle) != null -> activity.toast(R.string.title_taken)
else -> {
val type = if (view.new_note_type.checkedRadioButtonId == view.type_checklist.id) {
val type = if (binding.newNoteType.checkedRadioButtonId == binding.typeChecklist.id) {
NoteType.TYPE_CHECKLIST
} else {
NoteType.TYPE_TEXT

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.notes.pro.dialogs
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.getFilenameFromPath
@ -9,27 +8,27 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogOpenFileBinding
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import kotlinx.android.synthetic.main.dialog_open_file.view.*
import java.io.File
class OpenFileDialog(val activity: SimpleActivity, val path: String, val callback: (note: Note) -> Unit) : AlertDialog.Builder(activity) {
private var dialog: AlertDialog? = null
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_open_file, null) as ViewGroup).apply {
open_file_filename.setText(activity.humanizePath(path))
val binding = DialogOpenFileBinding.inflate(activity.layoutInflater).apply {
openFileFilename.setText(activity.humanizePath(path))
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.open_file) { alertDialog ->
activity.setupDialogStuff(binding.root, this, R.string.open_file) { alertDialog ->
dialog = alertDialog
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == view.open_file_update_file.id
val updateFileOnEdit = binding.openFileType.checkedRadioButtonId == binding.openFileUpdateFile.id
val storePath = if (updateFileOnEdit) path else ""
val storeContent = if (updateFileOnEdit) "" else File(path).readText()

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.notes.pro.dialogs
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity
@ -9,33 +8,32 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.views.AutoStaggeredGridLayoutManager
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.adapters.OpenNoteAdapter
import com.simplemobiletools.notes.pro.databinding.DialogOpenNoteBinding
import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_open_note.view.dialog_open_note_list
import kotlinx.android.synthetic.main.dialog_open_note.view.new_note_fab
class OpenNoteDialog(val activity: BaseSimpleActivity, val callback: (checkedId: Long, newNote: Note?) -> Unit) {
private var dialog: AlertDialog? = null
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_open_note, null)
val binding = DialogOpenNoteBinding.inflate(activity.layoutInflater)
val noteItemWidth = activity.resources.getDimensionPixelSize(R.dimen.grid_note_item_width)
view.dialog_open_note_list.layoutManager = AutoStaggeredGridLayoutManager(noteItemWidth, StaggeredGridLayoutManager.VERTICAL)
binding.dialogOpenNoteList.layoutManager = AutoStaggeredGridLayoutManager(noteItemWidth, StaggeredGridLayoutManager.VERTICAL)
NotesHelper(activity).getNotes {
initDialog(it, view)
initDialog(it, binding)
}
}
private fun initDialog(notes: List<Note>, view: View) {
view.dialog_open_note_list.adapter = OpenNoteAdapter(activity, notes, view.dialog_open_note_list) {
private fun initDialog(notes: List<Note>, binding: DialogOpenNoteBinding) {
binding.dialogOpenNoteList.adapter = OpenNoteAdapter(activity, notes, binding.dialogOpenNoteList) {
it as Note
callback(it.id!!, null)
dialog?.dismiss()
}
view.new_note_fab.setOnClickListener {
binding.newNoteFab.setOnClickListener {
NewNoteDialog(activity, setChecklistAsDefault = false) {
callback(0, it)
dialog?.dismiss()
@ -43,9 +41,9 @@ class OpenNoteDialog(val activity: BaseSimpleActivity, val callback: (checkedId:
}
activity.getAlertDialogBuilder()
.setNegativeButton(R.string.cancel, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.open_note) { alertDialog ->
activity.setupDialogStuff(binding.root, this, R.string.open_note) { alertDialog ->
dialog = alertDialog
}
}

View File

@ -3,25 +3,24 @@ package com.simplemobiletools.notes.pro.dialogs
import android.app.Activity
import android.content.DialogInterface.BUTTON_POSITIVE
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import kotlinx.android.synthetic.main.dialog_rename_checklist_item.view.*
import com.simplemobiletools.notes.pro.databinding.DialogRenameChecklistItemBinding
class RenameChecklistItemDialog(val activity: Activity, val oldTitle: String, callback: (newTitle: String) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_checklist_item, null).apply {
checklist_item_title.setText(oldTitle)
val binding = DialogRenameChecklistItemBinding.inflate(activity.layoutInflater).apply {
checklistItemTitle.setText(oldTitle)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this) { alertDialog ->
alertDialog.showKeyboard(view.checklist_item_title)
activity.setupDialogStuff(binding.root, this) { alertDialog ->
alertDialog.showKeyboard(binding.checklistItemTitle)
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
val newTitle = view.checklist_item_title.value
val newTitle = binding.checklistItemTitle.value
when {
newTitle.isEmpty() -> activity.toast(R.string.empty_name)
newTitle.isEmpty() -> activity.toast(com.simplemobiletools.commons.R.string.empty_name)
else -> {
callback(newTitle)
alertDialog.dismiss()

View File

@ -6,28 +6,29 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogRenameNoteBinding
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.extensions.updateWidgets
import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_new_note.view.*
import java.io.File
class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val currentNoteText: String?, val callback: (note: Note) -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_note, null)
view.locked_note_title.setText(note.title)
val binding = DialogRenameNoteBinding.inflate(activity.layoutInflater)
val view = binding.root
binding.lockedNoteTitle.setText(note.title)
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.rename_note) { alertDialog ->
alertDialog.showKeyboard(view.locked_note_title)
alertDialog.showKeyboard(binding.lockedNoteTitle)
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.locked_note_title.value
val title = binding.lockedNoteTitle.value
ensureBackgroundThread {
newTitleConfirmed(title, alertDialog)
}
@ -55,14 +56,14 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val current
}
} else {
if (title.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
activity.toast(com.simplemobiletools.commons.R.string.filename_cannot_be_empty)
return
}
val file = File(path)
val newFile = File(file.parent, title)
if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.invalid_name)
activity.toast(com.simplemobiletools.commons.R.string.invalid_name)
return
}
@ -74,7 +75,7 @@ class RenameNoteDialog(val activity: SimpleActivity, val note: Note, val current
callback(note)
}
} else {
activity.toast(R.string.rename_file_error)
activity.toast(com.simplemobiletools.commons.R.string.rename_file_error)
return@renameFile
}
}

View File

@ -9,11 +9,12 @@ import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.databinding.DialogSortChecklistBinding
import com.simplemobiletools.notes.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_sort_checklist.view.*
class SortChecklistDialog(private val activity: SimpleActivity, private val callback: () -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_sort_checklist, null)
private val binding = DialogSortChecklistBinding.inflate(activity.layoutInflater)
private val view = binding.root
private val config = activity.config
private var currSorting = config.sorting
@ -23,56 +24,55 @@ class SortChecklistDialog(private val activity: SimpleActivity, private val call
setupMoveUndoneChecklistItems()
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok) { _, _ -> dialogConfirmed() }
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.ok) { _, _ -> dialogConfirmed() }
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.sort_by)
activity.setupDialogStuff(view, this, com.simplemobiletools.commons.R.string.sort_by)
}
}
private fun setupSortRadio() {
val fieldRadio = view.sorting_dialog_radio_sorting
val fieldRadio = binding.sortingDialogRadioSorting
fieldRadio.setOnCheckedChangeListener { group, checkedId ->
val isCustomSorting = checkedId == fieldRadio.sorting_dialog_radio_custom.id
view.sorting_dialog_radio_order.beGoneIf(isCustomSorting)
view.sorting_dialog_order_divider.beGoneIf(isCustomSorting)
view.move_undone_checklist_items_divider.beGoneIf(isCustomSorting)
view.settings_move_undone_checklist_items_holder.beGoneIf(isCustomSorting)
val isCustomSorting = checkedId == binding.sortingDialogRadioCustom.id
binding.sortingDialogRadioOrder.beGoneIf(isCustomSorting)
binding.sortingDialogOrderDivider.beGoneIf(isCustomSorting)
binding.moveUndoneChecklistItemsDivider.beGoneIf(isCustomSorting)
binding.settingsMoveUndoneChecklistItemsHolder.beGoneIf(isCustomSorting)
}
var fieldBtn = fieldRadio.sorting_dialog_radio_title
var fieldBtn = binding.sortingDialogRadioTitle
if (currSorting and SORT_BY_DATE_CREATED != 0) {
fieldBtn = fieldRadio.sorting_dialog_radio_date_created
fieldBtn = binding.sortingDialogRadioDateCreated
}
if (currSorting and SORT_BY_CUSTOM != 0) {
fieldBtn = fieldRadio.sorting_dialog_radio_custom
fieldBtn = binding.sortingDialogRadioCustom
}
fieldBtn.isChecked = true
}
private fun setupOrderRadio() {
val orderRadio = view.sorting_dialog_radio_order
var orderBtn = orderRadio.sorting_dialog_radio_ascending
var orderBtn = binding.sortingDialogRadioAscending
if (currSorting and SORT_DESCENDING != 0) {
orderBtn = orderRadio.sorting_dialog_radio_descending
orderBtn = binding.sortingDialogRadioDescending
}
orderBtn.isChecked = true
}
private fun setupMoveUndoneChecklistItems() {
view.settings_move_undone_checklist_items.isChecked = config.moveDoneChecklistItems
view.settings_move_undone_checklist_items_holder.setOnClickListener {
view.settings_move_undone_checklist_items.toggle()
binding.settingsMoveUndoneChecklistItems.isChecked = config.moveDoneChecklistItems
binding.settingsMoveUndoneChecklistItemsHolder.setOnClickListener {
binding.settingsMoveUndoneChecklistItems.toggle()
}
}
private fun dialogConfirmed() {
val sortingRadio = view.sorting_dialog_radio_sorting
val sortingRadio = binding.sortingDialogRadioSorting
var sorting = when (sortingRadio.checkedRadioButtonId) {
R.id.sorting_dialog_radio_date_created -> SORT_BY_DATE_CREATED
R.id.sorting_dialog_radio_custom -> SORT_BY_CUSTOM
@ -80,7 +80,7 @@ class SortChecklistDialog(private val activity: SimpleActivity, private val call
}
if (sortingRadio.checkedRadioButtonId != R.id.sorting_dialog_radio_custom
&& view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending
&& binding.sortingDialogRadioOrder.checkedRadioButtonId == R.id.sorting_dialog_radio_descending
) {
sorting = sorting or SORT_DESCENDING
}
@ -89,7 +89,7 @@ class SortChecklistDialog(private val activity: SimpleActivity, private val call
config.sorting = sorting
}
config.moveDoneChecklistItems = view.settings_move_undone_checklist_items.isChecked
config.moveDoneChecklistItems = binding.settingsMoveUndoneChecklistItems.isChecked
callback()
}
}

View File

@ -1,20 +1,20 @@
package com.simplemobiletools.notes.pro.dialogs
import android.content.DialogInterface
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.databinding.DialogUnlockNotesBinding
import com.simplemobiletools.notes.pro.databinding.ItemLockedNoteBinding
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.dialog_unlock_notes.view.*
import kotlinx.android.synthetic.main.item_locked_note.view.*
class UnlockNotesDialog(val activity: BaseSimpleActivity, val notes: List<Note>, callback: (unlockedNotes: List<Note>) -> Unit) {
private var dialog: AlertDialog? = null
private val view = activity.layoutInflater.inflate(R.layout.dialog_unlock_notes, null) as ViewGroup
private val redColor = activity.getColor(R.color.md_red)
private val greenColor = activity.getColor(R.color.md_green)
private val binding = DialogUnlockNotesBinding.inflate(activity.layoutInflater)
private val view = binding.root
private val redColor = activity.getColor(com.simplemobiletools.commons.R.color.md_red)
private val greenColor = activity.getColor(com.simplemobiletools.commons.R.color.md_green)
private val unlockedNoteIds = mutableListOf<Long>()
init {
@ -23,8 +23,8 @@ class UnlockNotesDialog(val activity: BaseSimpleActivity, val notes: List<Note>,
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.skip, null)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(com.simplemobiletools.commons.R.string.skip, null)
.setNegativeButton(com.simplemobiletools.commons.R.string.cancel, null)
.apply {
activity.setupDialogStuff(view, this, R.string.unlock_notes, cancelOnTouchOutside = false) { alertDialog ->
dialog = alertDialog
@ -37,19 +37,19 @@ class UnlockNotesDialog(val activity: BaseSimpleActivity, val notes: List<Note>,
}
private fun addLockedNoteView(note: Note) {
activity.layoutInflater.inflate(R.layout.item_locked_note, null).apply {
view.notes_holder.addView(this)
activity.updateTextColors(view.notes_holder)
locked_note_title.text = note.title
locked_unlocked_image.applyColorFilter(redColor)
locked_note_holder.setOnClickListener {
ItemLockedNoteBinding.inflate(activity.layoutInflater).apply {
binding.notesHolder.addView(this.root)
activity.updateTextColors(binding.notesHolder)
lockedNoteTitle.text = note.title
lockedUnlockedImage.applyColorFilter(redColor)
lockedNoteHolder.setOnClickListener {
if (note.id !in unlockedNoteIds) {
activity.performSecurityCheck(
protectionType = note.protectionType,
requiredHash = note.protectionHash,
successCallback = { _, _ ->
unlockedNoteIds.add(note.id!!)
locked_unlocked_image.apply {
lockedUnlockedImage.apply {
setImageResource(R.drawable.ic_lock_open_vector)
applyColorFilter(greenColor)
}
@ -58,8 +58,8 @@ class UnlockNotesDialog(val activity: BaseSimpleActivity, val notes: List<Note>,
)
} else {
unlockedNoteIds.remove(note.id)
locked_unlocked_image.apply {
setImageResource(R.drawable.ic_lock_vector)
lockedUnlockedImage.apply {
setImageResource(com.simplemobiletools.commons.R.drawable.ic_lock_vector)
applyColorFilter(redColor)
}
updatePositiveButton()
@ -70,9 +70,9 @@ class UnlockNotesDialog(val activity: BaseSimpleActivity, val notes: List<Note>,
private fun updatePositiveButton() {
dialog?.getButton(DialogInterface.BUTTON_POSITIVE)?.text = if (unlockedNoteIds.isNotEmpty()) {
activity.getString(R.string.ok)
activity.getString(com.simplemobiletools.commons.R.string.ok)
} else {
activity.getString(R.string.skip)
activity.getString(com.simplemobiletools.commons.R.string.skip)
}
}
}

View File

@ -41,7 +41,7 @@ fun Context.updateWidgets() {
}
}
fun Context.getPercentageFontSize() = resources.getDimension(R.dimen.middle_text_size) * (config.fontSizePercentage / 100f)
fun Context.getPercentageFontSize() = resources.getDimension(com.simplemobiletools.commons.R.dimen.middle_text_size) * (config.fontSizePercentage / 100f)
fun BaseSimpleActivity.requestUnlockNotes(notes: List<Note>, callback: (unlockedNotes: List<Note>) -> Unit) {
val lockedNotes = notes.filter { it.isLocked() }
@ -95,7 +95,7 @@ fun Context.backupNotes() {
val config = config
NotesHelper(this).getNotes { notesToBackup ->
if (notesToBackup.isEmpty()) {
toast(R.string.no_entries_for_exporting)
toast(com.simplemobiletools.commons.R.string.no_entries_for_exporting)
config.lastAutoBackupTime = DateTime.now().millis
scheduleNextAutomaticBackup()
return@getNotes
@ -153,7 +153,7 @@ fun Context.backupNotes() {
}
if (exportResult == ExportResult.EXPORT_FAIL) {
toast(R.string.exporting_failed)
toast(com.simplemobiletools.commons.R.string.exporting_failed)
}
config.lastAutoBackupTime = DateTime.now().millis

View File

@ -4,14 +4,16 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.SimpleActivity
import com.simplemobiletools.notes.pro.adapters.ChecklistAdapter
import com.simplemobiletools.notes.pro.databinding.FragmentChecklistBinding
import com.simplemobiletools.notes.pro.dialogs.NewChecklistItemDialog
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.updateWidgets
@ -20,22 +22,21 @@ import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.interfaces.ChecklistItemsListener
import com.simplemobiletools.notes.pro.models.ChecklistItem
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.fragment_checklist.view.*
import java.io.File
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
private var noteId = 0L
lateinit var view: ViewGroup
lateinit var binding: FragmentChecklistBinding
var items = mutableListOf<ChecklistItem>()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentChecklistBinding.inflate(inflater, container, false)
noteId = requireArguments().getLong(NOTE_ID, 0L)
setupFragmentColors()
return view
return binding.root
}
override fun onResume() {
@ -48,8 +49,8 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
if (menuVisible) {
activity?.hideKeyboard()
} else if (::view.isInitialized) {
(view.checklist_list.adapter as? ChecklistAdapter)?.finishActMode()
} else if (::binding.isInitialized) {
(binding.checklistList.adapter as? ChecklistAdapter)?.finishActMode()
}
}
@ -105,7 +106,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
private fun setupFragmentColors() {
val adjustedPrimaryColor = requireActivity().getProperPrimaryColor()
view.checklist_fab.apply {
binding.checklistFab.apply {
setColors(
requireActivity().getProperTextColor(),
adjustedPrimaryColor,
@ -114,12 +115,12 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
setOnClickListener {
showNewItemDialog()
(view.checklist_list.adapter as? ChecklistAdapter)?.finishActMode()
(binding.checklistList.adapter as? ChecklistAdapter)?.finishActMode()
}
}
view.fragment_placeholder.setTextColor(requireActivity().getProperTextColor())
view.fragment_placeholder_2.apply {
binding.fragmentPlaceholder.setTextColor(requireActivity().getProperTextColor())
binding.fragmentPlaceholder2.apply {
setTextColor(adjustedPrimaryColor)
underlineText()
setOnClickListener {
@ -133,10 +134,10 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
return
}
view.apply {
checklist_content_holder.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
checklist_fab.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
setupLockedViews(this, note!!)
binding.apply {
checklistContentHolder.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
checklistFab.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
setupLockedViews(this.toCommonBinding(), note!!)
}
}
@ -176,7 +177,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
activity = activity as SimpleActivity,
items = items,
listener = this,
recyclerView = view.checklist_list,
recyclerView = binding.checklistList,
showIcons = true
) { item ->
val clickedNote = item as ChecklistItem
@ -185,7 +186,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
saveNote(items.indexOfFirst { it.id == clickedNote.id })
context?.updateWidgets()
}.apply {
view.checklist_list.adapter = this
binding.checklistList.adapter = this
}
}
@ -204,8 +205,8 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
if (note != null) {
if (refreshIndex != -1) {
view.checklist_list.post {
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
binding.checklistList.post {
binding.checklistList.adapter?.notifyItemChanged(refreshIndex)
}
}
@ -225,10 +226,10 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
}
private fun updateUIVisibility() {
view.apply {
fragment_placeholder.beVisibleIf(items.isEmpty())
fragment_placeholder_2.beVisibleIf(items.isEmpty())
checklist_list.beVisibleIf(items.isNotEmpty())
binding.apply {
fragmentPlaceholder.beVisibleIf(items.isEmpty())
fragmentPlaceholder2.beVisibleIf(items.isEmpty())
checklistList.beVisibleIf(items.isNotEmpty())
}
}
@ -242,4 +243,14 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
loadNoteById(noteId)
setupAdapter()
}
private fun FragmentChecklistBinding.toCommonBinding(): CommonNoteBinding = this.let {
object : CommonNoteBinding {
override val root: View = it.root
override val noteLockedLayout: View = it.noteLockedLayout
override val noteLockedImage: ImageView = it.noteLockedImage
override val noteLockedLabel: TextView = it.noteLockedLabel
override val noteLockedShow: TextView = it.noteLockedShow
}
}
}

View File

@ -1,7 +1,9 @@
package com.simplemobiletools.notes.pro.fragments
import android.util.TypedValue
import android.view.ViewGroup
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
@ -10,24 +12,23 @@ import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.fragment_checklist.view.*
abstract class NoteFragment : Fragment() {
protected var note: Note? = null
var shouldShowLockedContent = false
protected fun setupLockedViews(view: ViewGroup, note: Note) {
view.apply {
note_locked_layout.beVisibleIf(note.isLocked() && !shouldShowLockedContent)
note_locked_image.applyColorFilter(requireContext().getProperTextColor())
protected fun setupLockedViews(binding: CommonNoteBinding, note: Note) {
binding.apply {
noteLockedLayout.beVisibleIf(note.isLocked() && !shouldShowLockedContent)
noteLockedImage.applyColorFilter(requireContext().getProperTextColor())
note_locked_label.setTextColor(requireContext().getProperTextColor())
note_locked_label.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
noteLockedLabel.setTextColor(requireContext().getProperTextColor())
noteLockedLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, binding.root.context.getPercentageFontSize())
note_locked_show.underlineText()
note_locked_show.setTextColor(requireContext().getProperPrimaryColor())
note_locked_show.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
note_locked_show.setOnClickListener {
noteLockedShow.underlineText()
noteLockedShow.setTextColor(requireContext().getProperPrimaryColor())
noteLockedShow.setTextSize(TypedValue.COMPLEX_UNIT_PX, binding.root.context.getPercentageFontSize())
noteLockedShow.setOnClickListener {
handleUnlocking()
}
}
@ -72,4 +73,12 @@ abstract class NoteFragment : Fragment() {
}
abstract fun checkLockState()
interface CommonNoteBinding {
val root: View
val noteLockedLayout: View
val noteLockedImage: ImageView
val noteLockedLabel: TextView
val noteLockedShow: TextView
}
}

View File

@ -16,9 +16,17 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.TextView
import androidx.viewbinding.ViewBinding
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.views.MyEditText
import com.simplemobiletools.commons.views.MyTextView
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.activities.MainActivity
import com.simplemobiletools.notes.pro.databinding.FragmentTextBinding
import com.simplemobiletools.notes.pro.databinding.NoteViewHorizScrollableBinding
import com.simplemobiletools.notes.pro.databinding.NoteViewStaticBinding
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
import com.simplemobiletools.notes.pro.extensions.updateWidgets
@ -27,8 +35,6 @@ import com.simplemobiletools.notes.pro.helpers.NOTE_ID
import com.simplemobiletools.notes.pro.helpers.NotesHelper
import com.simplemobiletools.notes.pro.models.TextHistory
import com.simplemobiletools.notes.pro.models.TextHistoryItem
import kotlinx.android.synthetic.main.fragment_text.view.*
import kotlinx.android.synthetic.main.note_view_horiz_scrollable.view.*
import java.io.File
// text history handling taken from https://gist.github.com/zeleven/0cfa738c1e8b65b23ff7df1fc30c9f7e
@ -42,29 +48,41 @@ class TextFragment : NoteFragment() {
private var touchDownX = 0f
private var moveXThreshold = 0 // make sure swiping across notes works well, do not swallow the gestures
lateinit var view: ViewGroup
private lateinit var binding: FragmentTextBinding
private lateinit var innerBinding: ViewBinding
private lateinit var noteEditText: MyEditText
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
view = inflater.inflate(R.layout.fragment_text, container, false) as ViewGroup
binding = FragmentTextBinding.inflate(inflater, container, false)
noteId = requireArguments().getLong(NOTE_ID, 0L)
moveXThreshold = resources.getDimension(R.dimen.activity_margin).toInt()
moveXThreshold = resources.getDimension(com.simplemobiletools.commons.R.dimen.activity_margin).toInt()
retainInstance = true
val layoutToInflate = if (config!!.enableLineWrap) R.layout.note_view_static else R.layout.note_view_horiz_scrollable
inflater.inflate(layoutToInflate, view.notes_relative_layout, true)
innerBinding = if (config!!.enableLineWrap) {
NoteViewStaticBinding.inflate(inflater, binding.notesRelativeLayout, true).apply {
noteEditText = textNoteView
}
} else {
NoteViewHorizScrollableBinding.inflate(inflater, binding.notesRelativeLayout, true).apply {
noteEditText = textNoteView
}
}
if (config!!.clickableLinks) {
view.text_note_view.apply {
noteEditText.apply {
linksClickable = true
autoLinkMask = Linkify.WEB_URLS or Linkify.EMAIL_ADDRESSES
movementMethod = MyMovementMethod.getInstance()
}
}
view.notes_horizontal_scrollview?.onGlobalLayout {
view.text_note_view.minWidth = view.notes_horizontal_scrollview.width
if (innerBinding is NoteViewHorizScrollableBinding) {
val casted = innerBinding as NoteViewHorizScrollableBinding
casted.notesHorizontalScrollview.onGlobalLayout {
casted.textNoteView.minWidth = casted.notesHorizontalScrollview.width
}
}
return view
return binding.root
}
override fun onResume() {
@ -113,14 +131,14 @@ class TextFragment : NoteFragment() {
if (savedInstanceState != null && note != null && savedInstanceState.containsKey(TEXT)) {
skipTextUpdating = true
val newText = savedInstanceState.getString(TEXT) ?: ""
view.text_note_view.setText(newText)
innerBinding.root.findViewById<MyTextView>(R.id.text_note_view).text = newText
}
}
@SuppressLint("ClickableViewAccessibility")
private fun setupFragment() {
val config = config ?: return
view.text_note_view.apply {
noteEditText.apply {
typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT
val fileContents = note!!.getNoteStoredValue(context)
@ -162,13 +180,13 @@ class TextFragment : NoteFragment() {
}
}
view.text_note_view.setOnTouchListener { v, event ->
noteEditText.setOnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> touchDownX = event.x
MotionEvent.ACTION_MOVE -> {
val diffX = Math.abs(event.x - touchDownX)
if (diffX > moveXThreshold) {
view.requestDisallowInterceptTouchEvent(false)
binding.root.requestDisallowInterceptTouchEvent(false)
}
}
}
@ -176,8 +194,8 @@ class TextFragment : NoteFragment() {
}
if (config.showWordCount) {
view.notes_counter.setTextColor(requireContext().getProperTextColor())
setWordCounter(view.text_note_view.text.toString())
binding.notesCounter.setTextColor(requireContext().getProperTextColor())
setWordCounter(noteEditText.text.toString())
}
checkLockState()
@ -185,27 +203,27 @@ class TextFragment : NoteFragment() {
}
fun setTextWatcher() {
view.text_note_view.apply {
noteEditText.apply {
removeTextChangedListener(textWatcher)
addTextChangedListener(textWatcher)
}
}
fun removeTextWatcher() = view.text_note_view.removeTextChangedListener(textWatcher)
fun removeTextWatcher() = noteEditText.removeTextChangedListener(textWatcher)
override fun checkLockState() {
if (note == null) {
return
}
view.apply {
notes_counter.beVisibleIf((!note!!.isLocked() || shouldShowLockedContent) && config!!.showWordCount)
notes_scrollview.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
setupLockedViews(this, note!!)
binding.apply {
notesCounter.beVisibleIf((!note!!.isLocked() || shouldShowLockedContent) && config!!.showWordCount)
notesScrollview.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
setupLockedViews(this.toCommonBinding(), note!!)
}
}
fun getNotesView() = view.text_note_view
fun getNotesView() = noteEditText
fun saveText(force: Boolean) {
if (note == null) {
@ -232,20 +250,20 @@ class TextFragment : NoteFragment() {
fun hasUnsavedChanges() = note != null && getCurrentNoteViewText() != note!!.getNoteStoredValue(requireContext())
fun focusEditText() {
view.text_note_view.requestFocus()
noteEditText.requestFocus()
}
fun getCurrentNoteViewText() = view.text_note_view?.text?.toString()
fun getCurrentNoteViewText() = noteEditText.text?.toString()
private fun setWordCounter(text: String) {
val words = text.replace("\n", " ").split(" ")
view.notes_counter.text = words.count { it.isNotEmpty() }.toString()
binding.notesCounter.text = words.count { it.isNotEmpty() }.toString()
}
fun undo() {
val edit = textHistory.getPrevious() ?: return
val text = view.text_note_view.editableText
val text = noteEditText.editableText
val start = edit.start
val end = start + if (edit.after != null) edit.after.length else 0
@ -275,7 +293,7 @@ class TextFragment : NoteFragment() {
fun redo() {
val edit = textHistory.getNext() ?: return
val text = view.text_note_view.editableText
val text = noteEditText.editableText
val start = edit.start
val end = start + if (edit.before != null) edit.before.length else 0
@ -323,4 +341,14 @@ class TextFragment : NoteFragment() {
(activity as MainActivity).currentNoteTextChanged(text, isUndoAvailable(), isRedoAvailable())
}
}
private fun FragmentTextBinding.toCommonBinding(): CommonNoteBinding = this.let {
object : CommonNoteBinding {
override val root: View = it.root
override val noteLockedLayout: View = it.noteLockedLayout
override val noteLockedImage: ImageView = it.noteLockedImage
override val noteLockedLabel: TextView = it.noteLockedLabel
override val noteLockedShow: TextView = it.noteLockedShow
}
}
}

View File

@ -348,7 +348,7 @@
</RelativeLayout>
<include
android:id="@+id/settings_general_settings_divider"
android:id="@+id/settings_saving_divider"
layout="@layout/divider" />
<TextView

View File

@ -1,30 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

6
build.gradle.kts Normal file
View File

@ -0,0 +1,6 @@
plugins {
alias(libs.plugins.android).apply(false)
alias(libs.plugins.kotlinAndroid).apply(false)
alias(libs.plugins.ksp).apply(false)
alias(libs.plugins.kotlinSerialization).apply(false)
}

View File

@ -1,2 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true
android.nonTransitiveRClass=true

47
gradle/libs.versions.toml Normal file
View File

@ -0,0 +1,47 @@
[versions]
#jetbrains
kotlin = "1.9.0"
#KSP
kotlinxSerializationJson = "1.5.1"
ksp = "1.9.0-1.0.12"
#AndroidX
androidx-constraintlayout = "2.1.4"
androidx-documentfile = "1.0.1"
#Room
room = "2.6.0-alpha02"
#Simple tools
simple-commons = "c5a32fb1f3"
#Gradle
gradlePlugins-agp = "8.1.0"
#build
app-build-compileSDKVersion = "34"
app-build-targetSDK = "34"
app-build-minimumSDK = "23"
app-build-javaVersion = "VERSION_17"
app-build-kotlinJVMTarget = "17"
#versioning
app-version-appId = "com.simplemobiletools.notes.pro"
app-version-versionCode = "108"
app-version-versionName = "6.16.0"
[libraries]
#AndroidX
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" }
androidx-documentfile = { module = "androidx.documentfile:documentfile", version.ref = "androidx-documentfile" }
#Room
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
#Simple Mobile Tools
simple-tools-commons = { module = "com.github.SimpleMobileTools:Simple-Commons", version.ref = "simple-commons" }
#Kotlin
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
[bundles]
room = [
"androidx-room-ktx",
"androidx-room-runtime",
]
[plugins]
android = { id = "com.android.application", version.ref = "gradlePlugins-agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip

View File

@ -1 +0,0 @@
include ':app'

16
settings.gradle.kts Normal file
View File

@ -0,0 +1,16 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { setUrl("https://jitpack.io") }
}
}
include(":app")