update commons to 3.0.21

This commit is contained in:
tibbi 2017-12-01 18:49:49 +01:00
parent af7f5408cf
commit dba8871459
9 changed files with 64 additions and 73 deletions

View File

@ -47,7 +47,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.0.9'
implementation 'com.simplemobiletools:commons:3.0.21'
implementation 'com.facebook.stetho:stetho:1.5.0'
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"

View File

@ -2,10 +2,9 @@ package com.simplemobiletools.notes
import android.app.Application
import com.facebook.stetho.Stetho
import com.simplemobiletools.commons.extensions.checkUseEnglish
import com.simplemobiletools.notes.BuildConfig.USE_LEAK_CANARY
import com.simplemobiletools.notes.extensions.config
import com.squareup.leakcanary.LeakCanary
import java.util.*
class App : Application() {
override fun onCreate() {
@ -17,11 +16,7 @@ class App : Application() {
LeakCanary.install(this)
}
if (config.useEnglish) {
val conf = resources.configuration
conf.locale = Locale.ENGLISH
resources.updateConfiguration(conf, resources.displayMetrics)
}
checkUseEnglish()
if (BuildConfig.DEBUG)
Stetho.initializeWithDefaults(this)

View File

@ -25,7 +25,6 @@ import com.simplemobiletools.notes.extensions.config
import com.simplemobiletools.notes.extensions.dbHelper
import com.simplemobiletools.notes.extensions.getTextSize
import com.simplemobiletools.notes.extensions.updateWidget
import com.simplemobiletools.notes.helpers.DBHelper
import com.simplemobiletools.notes.helpers.MIME_TEXT_PLAIN
import com.simplemobiletools.notes.helpers.OPEN_NOTE_ID
import com.simplemobiletools.notes.helpers.TYPE_NOTE
@ -38,7 +37,6 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private var mAdapter: NotesPagerAdapter? = null
lateinit var mCurrentNote: Note
lateinit var mDb: DBHelper
lateinit var mNotes: List<Note>
private var noteViewWithTextSelected: MyEditText? = null
@ -48,14 +46,13 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
appLaunched()
mDb = applicationContext.dbHelper
initViewPager()
pager_title_strip.setTextSize(TypedValue.COMPLEX_UNIT_PX, getTextSize())
pager_title_strip.layoutParams.height = (pager_title_strip.height + resources.getDimension(R.dimen.activity_margin) * 2).toInt()
checkWhatsNewDialog()
storeStoragePaths()
intent.apply {
if (action == Intent.ACTION_SEND && type == MIME_TEXT_PLAIN) {
@ -157,7 +154,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun handleText(text: String) {
val notes = mDb.getNotes()
val notes = dbHelper.getNotes()
val list = arrayListOf<RadioItem>().apply {
add(RadioItem(0, getString(R.string.create_new_note)))
notes.forEachIndexed { index, note ->
@ -176,9 +173,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun handleFile(path: String) {
val id = mDb.getNoteId(path)
val id = dbHelper.getNoteId(path)
if (mDb.isValidId(id)) {
if (dbHelper.isValidId(id)) {
updateSelectedNote(id)
return
}
@ -191,7 +188,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun initViewPager() {
mNotes = mDb.getNotes()
mNotes = dbHelper.getNotes()
mCurrentNote = mNotes[0]
var wantedNoteId = intent.getIntExtra(OPEN_NOTE_ID, -1)
if (wantedNoteId == -1)
@ -217,7 +214,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun displayRenameDialog() {
RenameNoteDialog(this, mDb, mCurrentNote) {
RenameNoteDialog(this, dbHelper, mCurrentNote) {
mCurrentNote = it
initViewPager()
}
@ -231,15 +228,15 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun displayNewNoteDialog(value: String = "") {
NewNoteDialog(this, mDb) {
NewNoteDialog(this, dbHelper) {
val newNote = Note(0, it, value, TYPE_NOTE)
addNewNote(newNote)
}
}
private fun addNewNote(note: Note) {
val id = mDb.insertNote(note)
mNotes = mDb.getNotes()
val id = dbHelper.insertNote(note)
mNotes = dbHelper.getNotes()
invalidateOptionsMenu()
initViewPager()
updateSelectedNote(id)
@ -276,7 +273,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
toast(R.string.invalid_file_format)
} else if (file.length() > 10 * 1000 * 1000) {
toast(R.string.file_too_large)
} else if (checkTitle && mDb.doesTitleExist(path.getFilenameFromPath())) {
} else if (checkTitle && dbHelper.doesTitleExist(path.getFilenameFromPath())) {
toast(R.string.title_taken)
} else {
onChecksPassed(file)
@ -286,7 +283,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private fun importFileWithSync(path: String) {
openFile(path, false) {
var title = path.getFilenameFromPath()
if (mDb.doesTitleExist(title))
if (dbHelper.doesTitleExist(title))
title += " (file)"
val note = Note(0, title, "", TYPE_NOTE, path)
@ -372,8 +369,8 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
val deletedNoteId = mCurrentNote.id
val path = mCurrentNote.path
mDb.deleteNote(mCurrentNote.id)
mNotes = mDb.getNotes()
dbHelper.deleteNote(mCurrentNote.id)
mNotes = dbHelper.getNotes()
val firstNoteId = mNotes[0].id
updateSelectedNote(firstNoteId)

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.notes.dialogs
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.notes.R
@ -14,7 +13,7 @@ class DeleteNoteDialog(val activity: SimpleActivity, val note: Note, val callbac
init {
val message = String.format(activity.getString(R.string.delete_note_prompt_message), note.title)
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_delete_note, null).apply {
val view = activity.layoutInflater.inflate(R.layout.dialog_delete_note, null).apply {
if (note.path.isNotEmpty()) {
delete_note_checkbox.text = String.format(activity.getString(R.string.delete_file_itself), note.path)
delete_note_checkbox.beVisible()

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.notes.dialogs
import android.os.Environment
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.WindowManager
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
@ -17,7 +16,7 @@ class ExportAsDialog(val activity: SimpleActivity, val note: Note, val callback:
init {
var realPath = File(note.path).parent ?: Environment.getExternalStorageDirectory().toString()
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_export_as, null).apply {
val view = activity.layoutInflater.inflate(R.layout.dialog_export_as, null).apply {
file_path.text = activity.humanizePath(realPath)
file_name.setText(note.title)
@ -35,27 +34,28 @@ class ExportAsDialog(val activity: SimpleActivity, val note: Note, val callback:
.setNegativeButton(R.string.cancel, null)
.create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
activity.setupDialogStuff(view, this, R.string.export_as_file)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val filename = view.file_name.value
val extension = view.file_extension.value
activity.setupDialogStuff(view, this, R.string.export_as_file) {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.file_name.value
val extension = view.file_extension.value
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
if (filename.isEmpty()) {
activity.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
}
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
val newFile = File(realPath, fullFilename)
if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters)
return@setOnClickListener
}
activity.config.lastUsedExtension = extension
callback(newFile.absolutePath)
dismiss()
}
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
val newFile = File(realPath, fullFilename)
if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters)
return@setOnClickListener
}
activity.config.lastUsedExtension = extension
callback(newFile.absolutePath)
dismiss()
})
}
}
}
}

View File

@ -20,15 +20,16 @@ class NewNoteDialog(val activity: Activity, val db: DBHelper, callback: (title:
.setNegativeButton(R.string.cancel, null)
.create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
activity.setupDialogStuff(view, this, R.string.new_note)
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_name.value
when {
title.isEmpty() -> activity.toast(R.string.no_title)
db.doesTitleExist(title) -> activity.toast(R.string.title_taken)
else -> {
callback(title)
dismiss()
activity.setupDialogStuff(view, this, R.string.new_note) {
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_name.value
when {
title.isEmpty() -> activity.toast(R.string.no_title)
db.doesTitleExist(title) -> activity.toast(R.string.title_taken)
else -> {
callback(title)
dismiss()
}
}
}
}

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.notes.dialogs
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.ViewGroup
import com.simplemobiletools.commons.extensions.getFilenameFromPath
import com.simplemobiletools.commons.extensions.humanizePath
@ -18,7 +17,7 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
private var dialog: AlertDialog
init {
val view = (LayoutInflater.from(activity).inflate(R.layout.dialog_open_file, null) as ViewGroup).apply {
val view = (activity.layoutInflater.inflate(R.layout.dialog_open_file, null) as ViewGroup).apply {
open_file_filename.text = activity.humanizePath(path)
}
@ -26,20 +25,21 @@ class OpenFileDialog(val activity: SimpleActivity, val path: String, val callbac
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.open_file)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == open_file_update_file
val storePath = if (updateFileOnEdit) path else ""
val storeContent = if (updateFileOnEdit) "" else File(path).readText()
activity.setupDialogStuff(view, this, R.string.open_file) {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val updateFileOnEdit = view.open_file_type.checkedRadioButtonId == open_file_update_file
val storePath = if (updateFileOnEdit) path else ""
val storeContent = if (updateFileOnEdit) "" else File(path).readText()
if (updateFileOnEdit) {
activity.handleSAFDialog(File(path)) {
if (updateFileOnEdit) {
activity.handleSAFDialog(File(path)) {
saveNote(storeContent, storePath)
}
} else {
saveNote(storeContent, storePath)
}
} else {
saveNote(storeContent, storePath)
}
})
}
}
}

View File

@ -1,11 +1,10 @@
package com.simplemobiletools.notes.dialogs
import android.app.Activity
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import android.widget.RadioGroup
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.toast
@ -37,7 +36,7 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> U
}
open_note_item_icon.apply {
beVisibleIf(note.path.isNotEmpty())
colorFilter = PorterDuffColorFilter(textColor, PorterDuff.Mode.SRC_IN)
applyColorFilter(textColor)
setOnClickListener {
activity.toast(note.path)
}

View File

@ -23,7 +23,7 @@ class RenameNoteDialog(val activity: SimpleActivity, val db: DBHelper, val note:
.create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
activity.setupDialogStuff(view, this, R.string.rename_note)
getButton(BUTTON_POSITIVE).setOnClickListener({
getButton(BUTTON_POSITIVE).setOnClickListener {
val title = view.note_name.value
when {
title.isEmpty() -> activity.toast(R.string.no_title)
@ -59,7 +59,7 @@ class RenameNoteDialog(val activity: SimpleActivity, val db: DBHelper, val note:
callback(note)
}
}
})
}
}
}
}