diff --git a/src/main/assets/img/ic_action_pin.svg b/src/main/assets/img/ic_action_pin.svg new file mode 100644 index 0000000..ba67d57 --- /dev/null +++ b/src/main/assets/img/ic_action_pin.svg @@ -0,0 +1,112 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/assets/img/ic_action_unpin.svg b/src/main/assets/img/ic_action_unpin.svg new file mode 100644 index 0000000..e64d1e8 --- /dev/null +++ b/src/main/assets/img/ic_action_unpin.svg @@ -0,0 +1,119 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/cdot/lists/ChecklistActivity.kt b/src/main/java/com/cdot/lists/ChecklistActivity.kt index f25981a..d4fb8a8 100644 --- a/src/main/java/com/cdot/lists/ChecklistActivity.kt +++ b/src/main/java/com/cdot/lists/ChecklistActivity.kt @@ -20,13 +20,11 @@ package com.cdot.lists import android.content.DialogInterface import android.content.Intent +import android.os.Build import android.os.Bundle import android.text.InputType import android.util.Log -import android.view.KeyEvent -import android.view.Menu -import android.view.MenuItem -import android.view.View +import android.view.* import android.view.inputmethod.EditorInfo import android.widget.* import androidx.appcompat.app.AlertDialog @@ -42,17 +40,21 @@ import org.json.JSONException */ class ChecklistActivity : EntryListActivity() { private lateinit var binding: ChecklistActivityBinding // init in onCreate + private var isPinned: Boolean = false + override lateinit var list: EntryList // init in onCreate override fun onSaveInstanceState(state: Bundle) { super.onSaveInstanceState(state) state.putInt(UID_EXTRA, list.sessionUID) + state.putInt(PINNED, if (isPinned) 1 else 0) } override fun onRestoreInstanceState(state: Bundle) { super.onRestoreInstanceState(state) val uid = state.getInt(UID_EXTRA) if (uid > 0) list = lister.lists.findBySessionUID(uid) as EntryList + isPinned = (state.getInt(PINNED) == 1) } override fun onCreate(state: Bundle?) { @@ -65,7 +67,7 @@ class ChecklistActivity : EntryListActivity() { Log.d(TAG, "onCreate list $list") makeAdapter() binding.addItemET.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES - binding.addItemET.setOnEditorActionListener { textView: TextView?, i: Int, keyEvent: KeyEvent? -> + binding.addItemET.setOnEditorActionListener { _: TextView?, i: Int, _: KeyEvent? -> if (i == EditorInfo.IME_ACTION_DONE) { val text = binding.addItemET.text.toString() if (text.trim { it <= ' ' }.isNotEmpty()) { @@ -86,6 +88,7 @@ class ChecklistActivity : EntryListActivity() { if (list.size() == 0) enableAddingMode() setContentView(binding.root) supportActionBar!!.title = list.text + pin() } override val helpAsset: Int = R.raw.checklist_help @@ -111,15 +114,16 @@ class ChecklistActivity : EntryListActivity() { override fun onPrepareOptionsMenu(menu: Menu): Boolean { super.onPrepareOptionsMenu(menu) - val it = menu.findItem(R.id.action_add_items) - if (isInAddingMode) { - it.setIcon(R.drawable.ic_action_item_add_off) - it.setTitle(R.string.action_item_add_off) + val pinned = menu.findItem(R.id.action_pin) + if (isPinned) { + pinned.setIcon(R.drawable.ic_action_unpin) + pinned.setTitle(R.string.action_unpin) } else { - it.setIcon(R.drawable.ic_action_item_add_on) - it.setTitle(R.string.action_item_add_on) + pinned.setIcon(R.drawable.ic_action_pin) + pinned.setTitle(R.string.action_pin) } - menu.findItem(R.id.action_preferences).isEnabled = !isInAddingMode + + menu.findItem(R.id.action_preferences).isEnabled = !addItemTextView.isShown menu.findItem(R.id.action_check_all).isEnabled = (list as Checklist).countFlaggedEntries(ChecklistItem.IS_DONE) < list.size() menu.findItem(R.id.action_uncheck_all).isEnabled = (list as Checklist).countFlaggedEntries(ChecklistItem.IS_DONE) > 0 menu.findItem(R.id.action_undo_delete).isEnabled = list.removeCount > 0 @@ -133,6 +137,14 @@ class ChecklistActivity : EntryListActivity() { if (super.onOptionsItemSelected(menuItem)) return true val checklist = list as Checklist when (menuItem.itemId) { + + R.id.action_pin -> { + isPinned = !isPinned + Log.d(TAG, if (isPinned) "Pinning" else "Unpinning") + pin() + messageHandler.sendMessage(messageHandler.obtainMessage(MESSAGE_UPDATE_DISPLAY)) + } + R.id.action_check_all -> if (checklist.setFlagOnAll(ChecklistItem.IS_DONE, true)) { list.notifyChangeListeners() Log.d(TAG, "check all") @@ -164,7 +176,7 @@ class ChecklistActivity : EntryListActivity() { editText.isSingleLine = true editText.setText(list.text) builder.setView(editText) - builder.setPositiveButton(R.string.ok) { dialogInterface: DialogInterface?, i: Int -> + builder.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int -> Log.d(TAG, "list renamed") list.text = editText.text.toString() lister.lists.notifyChangeListeners() @@ -249,6 +261,32 @@ class ChecklistActivity : EntryListActivity() { checkpoint() } + override fun onAttachedToWindow() { + // onAttachedToWindow is called after onResume (and it happens only once per lifecycle). + // ActivityThread.handleResumeActivity call will add DecorView to the current WindowManger + // which will in turn call WindowManagerGlobal.addView() which than traverse all the views + // and call onAttachedToWindow on each view. + pin() + } + + // Do whatever is needed to keep the app in front of the lock screen + private fun pin() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) + setShowWhenLocked(isPinned) + else { + if (isPinned) + window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) + else + window.clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) + } + + // Do what is needed to keep the device awake while the app is active + if (isPinned) + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + else + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + companion object { private val TAG = ChecklistActivity::class.simpleName } diff --git a/src/main/java/com/cdot/lists/ChecklistsActivity.kt b/src/main/java/com/cdot/lists/ChecklistsActivity.kt index 93667b3..2961926 100644 --- a/src/main/java/com/cdot/lists/ChecklistsActivity.kt +++ b/src/main/java/com/cdot/lists/ChecklistsActivity.kt @@ -81,14 +81,14 @@ class ChecklistsActivity : EntryListActivity() { // Are we opening from a data source? if (Intent.ACTION_VIEW == intent.action && intent.data != null) { // If we are able to load from this URI, then the cache should be ignored - if (lister.getUri(Lister.PREF_FILE_URI) != intent.data) { - Log.d(TAG, "onResume new URI from Intent " + lister.getUri(Lister.PREF_FILE_URI)) - lister.setUri(Lister.PREF_FILE_URI, intent.data) + if (lister.getUri(PREF_FILE_URI) != intent.data) { + Log.d(TAG, "onResume new URI from Intent " + lister.getUri(PREF_FILE_URI)) + lister.setUri(PREF_FILE_URI, intent.data) lister.unloadLists() } else - Log.d(TAG, "onResume same URI from Intent==Prefs " + lister.getUri(Lister.PREF_FILE_URI)) + Log.d(TAG, "onResume same URI from Intent==Prefs " + lister.getUri(PREF_FILE_URI)) } else - Log.d(TAG, "onResume URI from Prefs " + lister.getUri(Lister.PREF_FILE_URI)) + Log.d(TAG, "onResume URI from Prefs " + lister.getUri(PREF_FILE_URI)) ensureListsLoaded( object : Lister.SuccessCallback { override fun succeeded(data: Any?) { @@ -149,7 +149,7 @@ class ChecklistsActivity : EntryListActivity() { editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES editText.isSingleLine = true builder.setView(editText) - builder.setPositiveButton(R.string.ok) { dialogInterface: DialogInterface?, i: Int -> + builder.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int -> val text = editText.text.toString().trim { it <= ' ' } if (text.isNotEmpty()) { if (!lister.getBool(Lister.PREF_WARN_DUPLICATE)) { diff --git a/src/main/java/com/cdot/lists/EntryListActivity.kt b/src/main/java/com/cdot/lists/EntryListActivity.kt index 4f24c67..af80435 100644 --- a/src/main/java/com/cdot/lists/EntryListActivity.kt +++ b/src/main/java/com/cdot/lists/EntryListActivity.kt @@ -45,12 +45,16 @@ import java.util.* */ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListener { + @JvmField protected var arrayAdapter: EntryListAdapter? = null + // The item currently being moved @JvmField @Transient var movingItem: EntryListItem? = null + // The entry currently moving. This is a temporary view that exists only while the + // item is being dragged. @Transient private var movingView: EntryListItemView? = null @@ -58,8 +62,9 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene abstract val list: EntryList abstract val listView: ListView - // When in edit mode, sorting and moving checked items is disabled - protected var isInAddingMode = false + // The view used to add new items. We are in "adding mode" if this is non-null and is shown + // This only applies to checklists, but is managed here in case we decide to add it to the + // checklists activity at some point. abstract val addItemTextView : TextView // Set the common bindings, obtained from the ViewBinding, and create the array adapter @@ -99,7 +104,10 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene get() { val dl: MutableList = ArrayList() dl.addAll(list.children) - if (isInAddingMode) return dl // unsorted list + try { + if (addItemTextView.isShown) return dl + } catch (_ : NoSuchElementException) {} + // unsorted list if (list.getFlag(EntryList.DISPLAY_SORTED)) dl.sortWith { o1, o2 -> o1.text.compareTo(o2.text, ignoreCase = true) } return dl @@ -113,8 +121,7 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene abstract fun addItem(str: String) protected fun enableAddingMode() { - if (isInAddingMode) return - isInAddingMode = true + if (addItemTextView.isShown) return addItemTextView.visibility = View.VISIBLE addItemTextView.isFocusable = true addItemTextView.isFocusableInTouchMode = true @@ -125,8 +132,7 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene } protected fun disableAddingMode() { - if (!isInAddingMode) return - isInAddingMode = false + if (!addItemTextView.isShown) return addItemTextView.visibility = View.INVISIBLE val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow((currentFocus ?: addItemTextView).windowToken, 0) @@ -134,7 +140,7 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene } protected fun toggleAddingMode() { - if (isInAddingMode) disableAddingMode() else enableAddingMode() + if (addItemTextView.isShown) disableAddingMode() else enableAddingMode() } /** @@ -147,7 +153,7 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene val builder = AlertDialog.Builder(this) builder.setTitle(R.string.similar_item_already_in_list) builder.setMessage(getString(R.string.similar_item_x_already_in_list, similar, proposed)) - builder.setPositiveButton(R.string.ok) { dialogInterface: DialogInterface?, i: Int -> addItem(proposed) } + builder.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int -> addItem(proposed) } builder.setNegativeButton(R.string.cancel, null) builder.show() } @@ -176,7 +182,7 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene // Check the item can be moved if (movingItem == null) return super.dispatchTouchEvent(motionEvent) val movingItem = movingItem!! - if (!(movingItem.parent?.childrenAreMoveable ?: true)) return super.dispatchTouchEvent(motionEvent) + if (movingItem.parent?.childrenAreMoveable == false) return super.dispatchTouchEvent(motionEvent) // get screen position of the ListView and the Activity val iArr = IntArray(2) @@ -273,21 +279,23 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene val alphaSort = menu.findItem(R.id.action_alpha_sort) if (list.getFlag(EntryList.DISPLAY_SORTED)) { - alphaSort.setIcon(R.drawable.ic_action_alpha_sort_off) + alphaSort.setIcon(R.drawable.ic_action_unsort) alphaSort.setTitle(R.string.action_alpha_sort_off) } else { - alphaSort.setIcon(R.drawable.ic_action_alpha_sort_on) + alphaSort.setIcon(R.drawable.ic_action_sort) alphaSort.setTitle(R.string.action_alpha_sort_on) } val adding = menu.findItem(R.id.action_add_items) - if (isInAddingMode) { - adding.setIcon(R.drawable.ic_action_item_add_off) - adding.setTitle(R.string.action_add_items_off) - } else { - adding.setIcon(R.drawable.ic_action_item_add_on) - adding.setTitle(R.string.action_add_items_on) - } + try { + if (addItemTextView.isShown) { + adding.setIcon(R.drawable.ic_action_item_add_off) + adding.setTitle(R.string.action_add_items_off) + } else { + adding.setIcon(R.drawable.ic_action_item_add_on) + adding.setTitle(R.string.action_add_items_on) + } + } catch (_ : NoSuchElementException) {} val save = menu.findItem(R.id.action_save) save.isVisible = lister.getBool(Lister.PREF_LAST_STORE_FAILED) @@ -300,17 +308,20 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene */ inner class EntryListAdapter internal constructor(act: AppCompatActivity?) : ArrayAdapter(act!!, 0) { override fun getView(i: Int, convertView: View?, viewGroup: ViewGroup): View { + //Log.d(TAG, "getView") val dl = displayOrder // get sorted list - if (i < dl.size) { - val itemView = if (convertView == null) makeItemView(dl[i], false) else convertView as EntryListItemView - itemView.item = dl[i] - itemView.updateView() - return itemView - } else if (convertView != null) - return convertView - else { - // Sometimes on startup we get here, with list size 0 and item index 1. Why? - throw Error("Empty display order") + return when { + i < dl.size -> { + val itemView = if (convertView == null) makeItemView(dl[i], false) else convertView as EntryListItemView + itemView.item = dl[i] + itemView.updateView() + itemView + } + convertView != null -> convertView + else -> { + // Sometimes on startup we get here, with list size 0 and item index 1. Why? + throw Error("Empty display order") + } } } @@ -321,7 +332,7 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene /** * Share the list e.g. to email in JSON format - * @param the list to share. We can't use the list for this view, as it might have some + * @param list the list to share. We can't use the list for this view, as it might have some * preprocessing before it's ready to share */ internal fun share(list: EntryList, listName: String) { @@ -341,7 +352,7 @@ abstract class EntryListActivity : ListerActivity(), EntryListItem.ChangeListene override fun onNothingSelected(parent: AdapterView<*>?) {} } builder.setView(picker) - builder.setPositiveButton(R.string.ok) { dialog: DialogInterface?, id: Int -> + builder.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int -> doShare(list, listName, resources.getStringArray(R.array.share_format_mimetype)[mPlace]) } builder.setNegativeButton(R.string.cancel, null) diff --git a/src/main/java/com/cdot/lists/HelpActivity.kt b/src/main/java/com/cdot/lists/HelpActivity.kt index 81709b3..031e8f5 100644 --- a/src/main/java/com/cdot/lists/HelpActivity.kt +++ b/src/main/java/com/cdot/lists/HelpActivity.kt @@ -51,11 +51,10 @@ class HelpActivity : AppCompatActivity() { // Expand resource identifiers val regex = Regex("@([a-z_]*)") val r = resources - val pack = getPackageName() val html = regex.replace(sb.toString()) { m -> - val resName = m.groups[1]!!.value; - val id = r.getIdentifier(resName, "string", pack) - if (id == 0) "" + resName + "" + val resName = m.groups[1]!!.value + val id = r.getIdentifier(resName, "string", packageName) + if (id == 0) "$resName" else "" + r.getString(id) + "" }.replace("#version_info", r.getString(R.string.version_info, BuildConfig.VERSION_NAME, BuildConfig.BUILD_TIME)) binding.webview.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null) diff --git a/src/main/java/com/cdot/lists/Lister.kt b/src/main/java/com/cdot/lists/Lister.kt index 98543b5..7d5934b 100644 --- a/src/main/java/com/cdot/lists/Lister.kt +++ b/src/main/java/com/cdot/lists/Lister.kt @@ -338,12 +338,10 @@ class Lister : Application() { companion object { // Shared Preferences - const val PREF_ALWAYS_SHOW = "showListInFrontOfLockScreen" const val PREF_GREY_CHECKED = "greyCheckedItems" const val PREF_ENTIRE_ROW_TOGGLES = "entireRowTogglesItem" const val PREF_LAST_STORE_FAILED = "lastStoreSaveFailed" const val PREF_LEFT_HANDED = "checkBoxOnLeftSide" - const val PREF_STAY_AWAKE = "stayAwake" const val PREF_STRIKE_CHECKED = "strikeThroughCheckedItems" const val PREF_TEXT_SIZE_INDEX = "textSizeIndex" const val PREF_FILE_URI = "backingStore" @@ -366,13 +364,11 @@ class Lister : Application() { init { put(PREF_TEXT_SIZE_INDEX, TEXT_SIZE_DEFAULT) put(PREF_FILE_URI, null) - put(PREF_ALWAYS_SHOW, false) put(PREF_GREY_CHECKED, true) put(PREF_WARN_DUPLICATE, true) put(PREF_ENTIRE_ROW_TOGGLES, true) put(PREF_LAST_STORE_FAILED, false) put(PREF_LEFT_HANDED, false) - put(PREF_STAY_AWAKE, false) put(PREF_STRIKE_CHECKED, true) put(PREF_DISABLE_FILE, false) put(PREF_DISABLE_CACHE, false) diff --git a/src/main/java/com/cdot/lists/ListerActivity.kt b/src/main/java/com/cdot/lists/ListerActivity.kt index 7dd9dc2..b6a54bd 100644 --- a/src/main/java/com/cdot/lists/ListerActivity.kt +++ b/src/main/java/com/cdot/lists/ListerActivity.kt @@ -28,7 +28,6 @@ import android.os.Looper import android.provider.DocumentsContract import android.util.Log import android.view.View -import android.view.WindowManager import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import com.cdot.lists.Lister.FailCallback @@ -74,35 +73,11 @@ abstract class ListerActivity : AppCompatActivity() { */ protected open val helpAsset: Int = 0 - // Do whatever is needed to keep the app in front of the lock screen - internal fun configureShowOverLockScreen() { - val show = lister.getBool(Lister.PREF_ALWAYS_SHOW) - - // None of this achieves anything on my Moto G8 Plus with Android 10, but works fine on a - // G6 running Android 9. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) - setShowWhenLocked(show) - else { - if (show) - window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) - else - window.clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED) - } - } - - // Do whatever is needed to keep the device awake while the app is active - internal fun configureStayAwake() { - if (lister.getBool(Lister.PREF_STAY_AWAKE)) - window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - else - window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - } - private fun handleUriAccessDenied() { val builder = AlertDialog.Builder(this) builder.setTitle(R.string.failed_access_denied) builder.setMessage(R.string.failed_file_access) - builder.setPositiveButton(R.string.ok) { dialogInterface: DialogInterface?, i: Int -> + builder.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int -> val intent = Intent(Intent.ACTION_OPEN_DOCUMENT) // Callers must include CATEGORY_OPENABLE in the Intent to obtain URIs that can be opened with ContentResolver#openFileDescriptor(Uri, String) intent.addCategory(Intent.CATEGORY_OPENABLE) @@ -170,10 +145,10 @@ abstract class ListerActivity : AppCompatActivity() { if (ps.isNotEmpty()) { // Note use of spread (*) operator to pass varargs array as varargs Snackbar.make(rootView!!, resources.getString(code, *ps), duration) - .setAction(R.string.close) { x: View? -> }.show() + .setAction(R.string.close) { }.show() } else { Snackbar.make(rootView!!, code, duration) - .setAction(R.string.close) { x: View? -> }.show() + .setAction(R.string.close) { }.show() } } return true @@ -211,15 +186,6 @@ abstract class ListerActivity : AppCompatActivity() { lister.lists.fromJSON(state.getString(JSON_EXTRA)!!) } - override fun onAttachedToWindow() { - // onAttachedToWindow is called after onResume (and it happens only once per lifecycle). - // ActivityThread.handleResumeActivity call will add DecorView to the current WindowManger - // which will in turn call WindowManagerGlobal.addView() which than traverse all the views - // and call onAttachedToWindow on each view. - configureShowOverLockScreen() - configureStayAwake() - } - override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) Log.d(TAG, "onNewIntent " + intent.data) @@ -326,5 +292,6 @@ abstract class ListerActivity : AppCompatActivity() { @JvmField val UID_EXTRA = "$CLASS_NAME.uid_extra" val JSON_EXTRA = "$CLASS_NAME.json_extra" + val PINNED = "$CLASS_NAME.pinned" } } \ No newline at end of file diff --git a/src/main/java/com/cdot/lists/model/EntryListItem.kt b/src/main/java/com/cdot/lists/model/EntryListItem.kt index a4e8091..f3a392e 100644 --- a/src/main/java/com/cdot/lists/model/EntryListItem.kt +++ b/src/main/java/com/cdot/lists/model/EntryListItem.kt @@ -237,7 +237,7 @@ abstract class EntryListItem internal constructor(t: String) { } override fun toString(): String { - return TAG + ":" + sessionUID + "(" + text + ")" + return "$TAG:$sessionUID($text)" } companion object { @@ -245,7 +245,7 @@ abstract class EntryListItem internal constructor(t: String) { // Rather than allowing names to be null, we choose to use a unique name for otherwise // namelists EntryListItems - val NO_NAME = "\bM\r Lis\te\r\b" // Very, very unlikely to encounter this! + const val NO_NAME = "\bM\r Lis\te\r\b" // Very, very unlikely to encounter this! // UID's are assigned when an item is created. They allow us to track list entries // across activities (list item text need not be unique). UIDs are not serialised. diff --git a/src/main/java/com/cdot/lists/preferences/ChecklistPreferencesFragment.kt b/src/main/java/com/cdot/lists/preferences/ChecklistPreferencesFragment.kt index dace9f8..7a2dbc8 100644 --- a/src/main/java/com/cdot/lists/preferences/ChecklistPreferencesFragment.kt +++ b/src/main/java/com/cdot/lists/preferences/ChecklistPreferencesFragment.kt @@ -41,7 +41,7 @@ class ChecklistPreferencesFragment(private var theList: Checklist) : Preferences val cbPref = findPreference(k) if (cbPref != null) { cbPref.isChecked = theList.getFlag(k) - cbPref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference: Preference?, newValue: Any -> + cbPref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any -> Log.d(TAG, "setting $k to $newValue") if (newValue as Boolean) theList.setFlag(k) else theList.clearFlag(k) (activity as PreferencesActivity?)!!.checkpoint() diff --git a/src/main/java/com/cdot/lists/preferences/PreferencesActivity.kt b/src/main/java/com/cdot/lists/preferences/PreferencesActivity.kt index b94ed8e..7eb4838 100644 --- a/src/main/java/com/cdot/lists/preferences/PreferencesActivity.kt +++ b/src/main/java/com/cdot/lists/preferences/PreferencesActivity.kt @@ -18,7 +18,6 @@ */ package com.cdot.lists.preferences -import android.content.SharedPreferences import android.os.Bundle import android.view.View import com.cdot.lists.Lister @@ -26,9 +25,11 @@ import com.cdot.lists.ListerActivity import com.cdot.lists.model.Checklist /** - * Activity used to host preference fragments + * Activity used to host preference fragments - supports share preferences and local checklist + * preferences */ -class PreferencesActivity : ListerActivity(), SharedPreferences.OnSharedPreferenceChangeListener { +class PreferencesActivity : ListerActivity() { + @JvmField var fragment: PreferencesFragment? = null // Flag that suppresses reporting during activity onResume/onCreate, so we don't get spammed @@ -62,23 +63,6 @@ class PreferencesActivity : ListerActivity(), SharedPreferences.OnSharedPreferen return true } - public override fun onPause() { - lister.prefs.unregisterOnSharedPreferenceChangeListener(this) - super.onPause() - } - - public override fun onResume() { - super.onResume() - lister.prefs.registerOnSharedPreferenceChangeListener(this) - } - - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { - when (key) { - Lister.PREF_ALWAYS_SHOW -> configureShowOverLockScreen() - Lister.PREF_STAY_AWAKE -> configureStayAwake() - } - } - companion object { private val TAG = PreferencesActivity::class.simpleName } diff --git a/src/main/java/com/cdot/lists/preferences/SharedPreferencesFragment.kt b/src/main/java/com/cdot/lists/preferences/SharedPreferencesFragment.kt index 0f6b6bc..41b28a4 100644 --- a/src/main/java/com/cdot/lists/preferences/SharedPreferencesFragment.kt +++ b/src/main/java/com/cdot/lists/preferences/SharedPreferencesFragment.kt @@ -41,7 +41,7 @@ class SharedPreferencesFragment(private val lister: Lister) : PreferencesFragmen private fun initBoolPref(name: String) { val cbPref = findPreference(name)!! cbPref.isChecked = lister.getBool(name) - cbPref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference: Preference?, newValue: Any -> + cbPref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any -> Log.d(TAG, "setting $name to $newValue") lister.setBool(name, newValue as Boolean) true @@ -55,8 +55,6 @@ class SharedPreferencesFragment(private val lister: Lister) : PreferencesFragmen initBoolPref(Lister.PREF_STRIKE_CHECKED) initBoolPref(Lister.PREF_LEFT_HANDED) initBoolPref(Lister.PREF_ENTIRE_ROW_TOGGLES) - initBoolPref(Lister.PREF_ALWAYS_SHOW) - initBoolPref(Lister.PREF_STAY_AWAKE) initBoolPref(Lister.PREF_WARN_DUPLICATE) initBoolPref(Lister.PREF_DISABLE_CACHE) initBoolPref(Lister.PREF_DISABLE_FILE) diff --git a/src/main/res/drawable-v23/ic_action_check_all.xml b/src/main/res/drawable-v23/ic_action_check_all.xml index 610ceda..9375b40 100644 --- a/src/main/res/drawable-v23/ic_action_check_all.xml +++ b/src/main/res/drawable-v23/ic_action_check_all.xml @@ -6,7 +6,7 @@ diff --git a/src/main/res/drawable-v23/ic_action_delete.xml b/src/main/res/drawable-v23/ic_action_delete.xml index 598c46d..94ff8cd 100644 --- a/src/main/res/drawable-v23/ic_action_delete.xml +++ b/src/main/res/drawable-v23/ic_action_delete.xml @@ -5,7 +5,7 @@ android:viewportHeight="24"> diff --git a/src/main/res/drawable-v23/ic_action_item_add_off.xml b/src/main/res/drawable-v23/ic_action_item_add_off.xml index bf982d3..94988e7 100644 --- a/src/main/res/drawable-v23/ic_action_item_add_off.xml +++ b/src/main/res/drawable-v23/ic_action_item_add_off.xml @@ -5,16 +5,13 @@ android:viewportHeight="24"> + android:fillType="nonZero"/> + + diff --git a/src/main/res/drawable-v23/ic_action_rename.xml b/src/main/res/drawable-v23/ic_action_rename.xml index 076a6a9..d48a86c 100644 --- a/src/main/res/drawable-v23/ic_action_rename.xml +++ b/src/main/res/drawable-v23/ic_action_rename.xml @@ -4,7 +4,7 @@ android:viewportWidth="24" android:viewportHeight="24"> diff --git a/src/main/res/drawable-v23/ic_action_settings.xml b/src/main/res/drawable-v23/ic_action_settings.xml index cd67473..cdb54c6 100644 --- a/src/main/res/drawable-v23/ic_action_settings.xml +++ b/src/main/res/drawable-v23/ic_action_settings.xml @@ -6,14 +6,14 @@ diff --git a/src/main/res/drawable-v23/ic_action_alpha_sort_on.xml b/src/main/res/drawable-v23/ic_action_sort.xml similarity index 100% rename from src/main/res/drawable-v23/ic_action_alpha_sort_on.xml rename to src/main/res/drawable-v23/ic_action_sort.xml diff --git a/src/main/res/drawable-v23/ic_action_store_new.xml b/src/main/res/drawable-v23/ic_action_store_new.xml index fb5595b..624d303 100644 --- a/src/main/res/drawable-v23/ic_action_store_new.xml +++ b/src/main/res/drawable-v23/ic_action_store_new.xml @@ -6,14 +6,14 @@ + android:fillColor="#FFFFFF"/> diff --git a/src/main/res/drawable-v23/ic_action_unpin.xml b/src/main/res/drawable-v23/ic_action_unpin.xml new file mode 100644 index 0000000..980d26a --- /dev/null +++ b/src/main/res/drawable-v23/ic_action_unpin.xml @@ -0,0 +1,16 @@ + + + + diff --git a/src/main/res/drawable-v23/ic_action_alpha_sort_off.xml b/src/main/res/drawable-v23/ic_action_unsort.xml similarity index 100% rename from src/main/res/drawable-v23/ic_action_alpha_sort_off.xml rename to src/main/res/drawable-v23/ic_action_unsort.xml diff --git a/src/main/res/drawable-v23/ic_help.xml b/src/main/res/drawable-v23/ic_help.xml index 2539c95..e48f5fd 100644 --- a/src/main/res/drawable-v23/ic_help.xml +++ b/src/main/res/drawable-v23/ic_help.xml @@ -6,16 +6,14 @@ diff --git a/src/main/res/drawable-v24/ic_action_check_all.xml b/src/main/res/drawable-v24/ic_action_check_all.xml index baf764f..d20fccd 100644 --- a/src/main/res/drawable-v24/ic_action_check_all.xml +++ b/src/main/res/drawable-v24/ic_action_check_all.xml @@ -6,7 +6,7 @@ diff --git a/src/main/res/drawable-v24/ic_action_delete.xml b/src/main/res/drawable-v24/ic_action_delete.xml index bee1953..1d303b0 100644 --- a/src/main/res/drawable-v24/ic_action_delete.xml +++ b/src/main/res/drawable-v24/ic_action_delete.xml @@ -5,7 +5,7 @@ android:viewportHeight="24"> diff --git a/src/main/res/drawable-v24/ic_action_item_add_off.xml b/src/main/res/drawable-v24/ic_action_item_add_off.xml index aff2ed3..da54844 100644 --- a/src/main/res/drawable-v24/ic_action_item_add_off.xml +++ b/src/main/res/drawable-v24/ic_action_item_add_off.xml @@ -5,18 +5,13 @@ android:viewportHeight="24"> + android:fillType="nonZero"/> diff --git a/src/main/res/drawable-v24/ic_action_move.xml b/src/main/res/drawable-v24/ic_action_move.xml index 42a651c..5aba2b3 100644 --- a/src/main/res/drawable-v24/ic_action_move.xml +++ b/src/main/res/drawable-v24/ic_action_move.xml @@ -5,14 +5,14 @@ android:viewportHeight="6.3500004"> + + diff --git a/src/main/res/drawable-v24/ic_action_rename.xml b/src/main/res/drawable-v24/ic_action_rename.xml index 05a3a44..5eb3b6e 100644 --- a/src/main/res/drawable-v24/ic_action_rename.xml +++ b/src/main/res/drawable-v24/ic_action_rename.xml @@ -4,7 +4,7 @@ android:viewportWidth="24" android:viewportHeight="24"> diff --git a/src/main/res/drawable-v24/ic_action_settings.xml b/src/main/res/drawable-v24/ic_action_settings.xml index 470f0ac..cd6226f 100644 --- a/src/main/res/drawable-v24/ic_action_settings.xml +++ b/src/main/res/drawable-v24/ic_action_settings.xml @@ -6,14 +6,14 @@ diff --git a/src/main/res/drawable-v24/ic_action_alpha_sort_on.xml b/src/main/res/drawable-v24/ic_action_sort.xml similarity index 100% rename from src/main/res/drawable-v24/ic_action_alpha_sort_on.xml rename to src/main/res/drawable-v24/ic_action_sort.xml diff --git a/src/main/res/drawable-v24/ic_action_store_new.xml b/src/main/res/drawable-v24/ic_action_store_new.xml index 1111ac6..c8fe2dd 100644 --- a/src/main/res/drawable-v24/ic_action_store_new.xml +++ b/src/main/res/drawable-v24/ic_action_store_new.xml @@ -6,14 +6,14 @@ + android:fillColor="?android:colorControlNormal"/> diff --git a/src/main/res/drawable-v24/ic_action_unpin.xml b/src/main/res/drawable-v24/ic_action_unpin.xml new file mode 100644 index 0000000..ea44c56 --- /dev/null +++ b/src/main/res/drawable-v24/ic_action_unpin.xml @@ -0,0 +1,16 @@ + + + + diff --git a/src/main/res/drawable-v24/ic_action_alpha_sort_off.xml b/src/main/res/drawable-v24/ic_action_unsort.xml similarity index 89% rename from src/main/res/drawable-v24/ic_action_alpha_sort_off.xml rename to src/main/res/drawable-v24/ic_action_unsort.xml index 4c2dfda..7a47238 100644 --- a/src/main/res/drawable-v24/ic_action_alpha_sort_off.xml +++ b/src/main/res/drawable-v24/ic_action_unsort.xml @@ -8,11 +8,9 @@ android:fillColor="?android:colorControlNormal" /> diff --git a/src/main/res/drawable-v24/ic_help.xml b/src/main/res/drawable-v24/ic_help.xml index d335edd..a3f5117 100644 --- a/src/main/res/drawable-v24/ic_help.xml +++ b/src/main/res/drawable-v24/ic_help.xml @@ -6,16 +6,14 @@ diff --git a/src/main/res/menu/checklist.xml b/src/main/res/menu/checklist.xml index 200a5e9..2af6221 100644 --- a/src/main/res/menu/checklist.xml +++ b/src/main/res/menu/checklist.xml @@ -1,6 +1,12 @@ + diff --git a/src/main/res/menu/checklists.xml b/src/main/res/menu/checklists.xml index 1a3208e..9bd2ebd 100644 --- a/src/main/res/menu/checklists.xml +++ b/src/main/res/menu/checklists.xml @@ -15,7 +15,7 @@ app:showAsAction="ifRoom" /> diff --git a/src/main/res/raw/checklist_help.html b/src/main/res/raw/checklist_help.html index 2fc22f8..adca933 100644 --- a/src/main/res/raw/checklist_help.html +++ b/src/main/res/raw/checklist_help.html @@ -14,6 +14,12 @@ lets you move the item to another position in the list. Touch and hold to drag the item.

Actions

+
+ @action_pin / + @action_unpin +
+
Pin/Unpin the list. When a list is pinned, it will stay in the foreground even when the device is locked. +
@action_alpha_sort_on / @action_alpha_sort_off diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index cc982fe..b224ca1 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -111,4 +111,6 @@ About %1$d touches away from debug %2$s Debug %1$s + Pin + Unpin diff --git a/src/main/res/xml/shared_preferences.xml b/src/main/res/xml/shared_preferences.xml index d7ce765..2083ece 100644 --- a/src/main/res/xml/shared_preferences.xml +++ b/src/main/res/xml/shared_preferences.xml @@ -26,16 +26,6 @@ android:title="@string/option_left_hand" android:summary="@string/help_left_hand" /> - - - -