This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viewLifecycleOwner.lifecycleScope.launch { | |
val items = arrayOf("Foo", "Bar", "Baz") | |
val currentCheckedIdx = 0 | |
val newCheckedItem = suspendCancellableCoroutine<String> { cont -> | |
MaterialAlertDialogBuilder(requireContext()) | |
.setTitle(R.string.some_title) | |
.setSingleChoiceItems( | |
modesStrings, | |
currentCheckedIdx | |
) { dialog, which: Int -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Fragment.overrideBackButtonWith(block: () -> Unit) { | |
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, | |
object : OnBackPressedCallback(true) { | |
override fun handleOnBackPressed() { | |
block() | |
remove() // remove this back button handler | |
} | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# All of these process could be easily written with lambda functions. | |
# However in combining with Scrapy Compose and MapCompose, I think Processor objects are more consice and readable. | |
class DropLast: | |
def __call__(self, values: Sequence): | |
return values[:-1] | |
class TakeWhile: | |
def __init__(self, condition: Callable[[Any], bool]): | |
self.condition = condition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PostsDatabaseHelper extends SQLiteOpenHelper { | |
@Override | |
public void onCreate(SQLiteDatabase db) { | |
String CREATE_POSTS_TABLE = "CREATE TABLE " + TABLE_POSTS + | |
"(" + | |
KEY_POST_ID + " INTEGER PRIMARY KEY," + // Define a primary key | |
KEY_POST_USER_ID_FK + " INTEGER REFERENCES " + TABLE_USERS + "," + // Define a foreign key | |
KEY_POST_TEXT + " TEXT" + | |
")"; |