SplittiesisacollectionofsmallKotlinmultiplatformlibraries(withAndroidasfirsttarget).
Theselibrariesareintendedtoreducetheamountofcodeyouhavetowrite,freeingcodereadingandwritingtime,soyoucanfocusmoreonwhatyouwanttobuildforyourusers(evenifyou'retheonlyone),orhavemoretimetohavefun.
Thisprojectisnamed"Splitties"becauseitissplitinsmallmodules,distributedasindependentlibraries,soyoucanaddonlytheonesyouneedtoyourproject/module,helpingreducethesizeofthefinalbinarythatusersdeviceswillneedtodownloadandkeepinthelimitedstorage(BTW,everythingislimited).
SomeAndroidtargetingmoduleshaveacontentsimilartowhatAnkooffers.SeeashortcomparisonofSplittieswithAnkohere.
Eachmodulehasbeendesignedtohaveasmallfootprintandbeasefficientaspossible.
AfewexamplesSplittiesisallaboutsimplifyingyourcode.Hereareafewexamples:
Kotlin:
startActivity(Intent(this,DemoActivity::class.java))KotlinwithSplittiesActivities:
start<DemoActivity>()Kotlin:
Snackbar.make(root,R.string.refresh_successful,Snackbar.LENGTH_SHORT).show()KotlinwithSplittiesSnackbar:
root.snack(R.string.refresh_successful)Racingcoroutines:(raceOf(…)comesfromtheCoroutinesmodule)
suspendfunawaitUserChoice(ui:SomeUi,choices:List<Stuff>):Stuff?=raceOf({ui.awaitSomeUserAction(choices)},{ui.awaitDismissal()null},{ui.showSomethingInRealtimeUntilCancelled()//ReturnsNothing,willrun,butnever"win".})Kotlin:
Snackbar.make(root,getString(R.string.deleted_x_items,deletedCount),Snackbar.LENGTH_LONG).setAction(android.R.string.cancel){deleteOperation.requestRollback()}.setActionTextColor(ContextCompat.getColor(this,R.color.fancy_color)).show()KotlinwithSplittiesSnackbar:
root.longSnack(str(R.string.deleted_x_items,deletedCount)){action(android.R.string.cancel,textColor=color(R.color.fancy_color)){deleteOperation.requestRollback()}}OverviewSysteminteraction(Androidonly)UserinputanduserinterfacerelatedsplitsSmallmessages(Androidonly)Dialogs(Androidonly)SystemUI(Androidonly)ExtensionsforViews(Androidonly)CreatingViewbasedUIswiththepowerofKotlin(Androidonly)VariousUIutilities(Androidonly)MaterialDesignhelpers(Androidonly)Interandcrossappcommunication:Activities,Fragments,Intents,andBundlesConcurrency(Multiplatform)Datapersistence(Multiplatform)Utilities(Multiplatform)Debugging(Androidonly)Legacy(Androidonly)Systeminteraction(Androidonly):AppContext:AlwayshaveyourapplicationContextathandwithappCtx.SystemServices:Nomorecontext.getSystemService(NAME_OF_SERVICE)asNameOfManager.Userinputanduserinterfacerelatedsplits:Smallmessages(Androidonly)Snackbar:Grabasnackwithoutceremonywithsnack(…)andlongSnack(…).Toast:Showatoastbyjustcallingtoast(yourText),anddodgeAPI25BadTokenException.Dialogs(Androidonly)AlertDialog:Createsimplealertdialogswithsimplecode.AlertDialogAppCompat:AppCompatversionofAlertDialog.AlertDialogAppCompatCoroutines:showAndAwaitextensionfunctionsforAppCompatAlertDialog.AlertDialogMaterial:MaterialComponentsextensionofAlertDialogAppCompat.SystemUI(Androidonly)Dangerouspermissions:Requestruntimepermissionswithoutpollutingyourcodebase.ExtensionsforViews(Androidonly)Views:ExtensionsfunctionandpropertiesonViews.ViewsAppCompat:AppCompatextensionofViews.IncludeshelpersforImageViewtinting,ActionBarandtooltip.ViewsCardView:CardViewextensionofViews.ProvidesacontentPaddingproperty.ViewsMaterial:MaterialComponentsextensionofViews.ViewsCoroutinesMaterial:MaterialComponents+Kotlincoroutines.ViewsRecyclerView:RecyclerViewextensionofViews.ViewsCoroutines:AndroidViews+Kotlincoroutines.CreatingViewbasedUIswiththepowerofKotlin(Androidonly)ViewsDSL:CreateUIswithreadableKotlincode(IDEpreviewsupported).ViewsDSLAppCompat:AppCompatextensionofViewsDSL.ViewsDSLConstraintLayout:ConstraintLayoutextensionofViewsDSL.ViewsDSLCoordinatorLayout:CoordinatorLayoutextensionofViewsDSL.ViewsDSLMaterial:MaterialComponentsextensionofViewsDSL.ViewsDSLRecyclerView:RecyclerViewextensionofViewsDSL.VariousUIutilities(Androidonly)Resources:Extensionstogetresourceslikestrings,colorsordrawableseasily,withsupportforthemedattributes.Dimensions:AndroiddpextensionsforViewandContext.ParticularlyhandywhenusingViewsDSL.SelectableviewsSelectableViews:SelectableViewswithforegroundpropertybeforeAPI23.SelectableViewsAppCompat:SelectableViewsforAppCompatTextView.SelectableViewsConstraintLayout:SelectableViewsforConstraintLayout.TypesafeRecyclerView:TypesafeViewHolderandItemViewHolderforeasybasicusageofRecyclerView.MaterialDesignhelpers(Androidonly)MaterialColors:2014MaterialDesigncolorpalettesascolorresources.MaterialLists:ListitemViewsimplementingMaterialDesignguidelines(perfectforusageinaRecyclerView).Interandcrossappcommunication:Activities,Fragments,Intents,andBundlesActivities:Startactivitieswithminimalboilerplate.Intents:Transformcompanionobjectsintopowerfultypesafeintentspecs,andcreatePendingIntentsthecleanandeasyway.Fragments:Startactivitiesfromfragmentsanddotransactionswithminimalboilerplate.FragmentArgs:Fragmentargumentswithoutceremonythankstodelegatedproperties.Bundle:BundleSpectouseBundlewithpropertysyntaxforIntentextrasandmore.Concurrency(Multiplatform)Coroutines:Generalpurposeextensionstokotlinx.coroutines.LifecycleCoroutines(Androidonly):CoroutinesintegrationwithAndroidXLifecycle.MainThread:Propertiesandpreconditioncheckersrelatedtothemainthread.MainHandler(Androidonly):Top-levelmainHandlerpropertytostopallocatingmultipleHandlersformainLooper.CheckedLazy(Androidonly):mainThreadLazythatcheckspropertyaccessonDatapersistence(Multiplatform)Preferences:PropertysyntaxforAndroid'sSharedPreferences/DataStoreandmacOS/iOS/watchOSNSUserDefaults.ArchRoom:RoomhelperstoinstantiateyourDBandperformtransactionsinKotlin.Utilities(Multiplatform)BitFlags:hasFlag,withFlagandminusFlagextensionsonLong,Int,Short,Byte,andtheirunsignedcounterparts.Collections:forEachforListswithoutIteratorallocation.Debugging(Androidonly)Stethoinit:HaveStethoforyourdebugbuilds,withoutwritinganycode!Legacy(Androidonly)Exceptions:unexpectedValue(…),unsupportedAction(…)andsimilarfunctionsthatreturnNothing.ArchLifecycle:ExtensionstogetViewModels,useLiveDataandobserveLifecycles.DownloadGradleinstructionsMakesureyouhavemavenCentral()intherepositoriesdefinedinyourproject's(root)build.gradlefile(defaultfornewAndroidStudioprojects).
TomakeiteasiertotakeadvantageofthecontentsofSplittiesforyourAndroidprojects,therearegroupingartifactsthatincludemostsplits.
AndroidbaseAddingwithrefreshVersions:Splitties.pack.androidBaseorSplitties.pack.androidBaseWithViewsDsl.
These2packsdon'tincludeAppCompatandaresuitableforWearOSapps.
Includesthefollowingmodules:
activitiesappctxbitflagsbundlecollectionscoroutinesdimensionsfragmentsfragmentargsintentslifecycle-coroutinesmainhandlermainthreadmaterial-colorspermissionspreferencesresourcessystemservicestoastviewsviews-coroutinesviews-recyclerviewviews-selectableviews-selectable-constraintlayoutGradledependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-base:3.0.0")There'salsoaversionwithViewsDSL.Itadditionallyincludesthefollowingmodules:
views-dslviews-dsl-constraintlayoutviews-dsl-recyclerviewGradledependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-base-with-views-dsl:3.0.0")AndroidAppCompatAddingwithrefreshVersions:Splitties.pack.appCompatorSplitties.pack.appCompatWithViewsDsl.
These2packsincludetheAndroidbasepack,andthefollowingmodules:
alertdialog-appcompatalertdialog-appcompat-coroutinesviews-appcompatviews-selectable-appcompatGradledependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-appcompat:3.0.0")There'salsoaversionwithViewsDSL.ItadditionallyincludestheViewsDSLversionoftheAndroidbasepackandthefollowingmodule:
views-dsl-appcompatGradledependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-appcompat-with-views-dsl:3.0.0")AndroidMaterialComponentsAddingwithrefreshVersions:Splitties.pack.androidMdcorSplitties.pack.androidMdcWithViewsDsl.
These2packsincludetheAndroidAppCompatpack,andthefollowingmodules:
alertdialog-materialmaterial-listssnackbarviews-cardviewviews-coroutines-materialviews-materialGradledependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-material-components:3.0.0")There'salsoaversionwithViewsDSL.ItadditionallyincludestheViewsDSLversionoftheAndroidAppCompatpackandthefollowingmodules:
views-dsl-coordinatorlayoutviews-dsl-materialGradledependency:
implementation("com.louiscad.splitties:splitties-fun-pack-android-material-components-with-views-dsl:3.0.0")Alltheartifacts(47)Sinceyoumightusemultipleartifacts,tonotrepeatyourself,werecommendyoutoputtheversioninacentralplace,soit'slittleefforttoupgradetonewerversions.
ThebestwaytodothisistouserefreshVersions,ithasbuilt-independencynotationsforSplitties,andalsomanyotherpopularandqualitativelibraries,likekotlinx,AndroidX,librariesfromSquare/CashAppandlibrariesfromGoogle.
Mostimportantly,withit,runningtherefreshVersionstaskwillshowyoutheavailableupdatesinamatterofseconds,forallofyourdependencies,rightintotheversions.properties,inawaythatmakesupgradingeffortless,evenwithjustthekeyboard.
FYI,thecurrentlatestreleaseofSplittiesistheversion3.0.0
Herearethemavencoordinatesofalltheartifactsofthislibrary,forreference.(Clicktoexpand)com.louiscad.splitties:splitties-activitiescom.louiscad.splitties:splitties-alertdialogcom.louiscad.splitties:splitties-alertdialog-appcompatcom.louiscad.splitties:splitties-alertdialog-appcompat-coroutinescom.louiscad.splitties:splitties-appctxcom.louiscad.splitties:splitties-arch-lifecyclecom.louiscad.splitties:splitties-arch-roomcom.louiscad.splitties:splitties-bitflagscom.louiscad.splitties:splitties-bundlecom.louiscad.splitties:splitties-checkedlazycom.louiscad.splitties:splitties-collectionscom.louiscad.splitties:splitties-coroutinescom.louiscad.splitties:splitties-dimensionscom.louiscad.splitties:splitties-exceptionscom.louiscad.splitties:splitties-fragmentscom.louiscad.splitties:splitties-fragmentargscom.louiscad.splitties:splitties-intentscom.louiscad.splitties:splitties-lifecycle-coroutinescom.louiscad.splitties:splitties-mainhandlercom.louiscad.splitties:splitties-mainthreadcom.louiscad.splitties:splitties-material-colorscom.louiscad.splitties:splitties-material-listscom.louiscad.splitties:splitties-permissionscom.louiscad.splitties:splitties-preferencescom.louiscad.splitties:splitties-resourcescom.louiscad.splitties:splitties-snackbarcom.louiscad.splitties:splitties-stetho-initcom.louiscad.splitties:splitties-systemservicescom.louiscad.splitties:splitties-toastcom.louiscad.splitties:splitties-typesaferecyclerviewcom.louiscad.splitties:splitties-viewscom.louiscad.splitties:splitties-views-appcompatcom.louiscad.splitties:splitties-views-cardviewcom.louiscad.splitties:splitties-views-coroutinescom.louiscad.splitties:splitties-views-coroutines-materialcom.louiscad.splitties:splitties-views-dslcom.louiscad.splitties:splitties-views-dsl-appcompatcom.louiscad.splitties:splitties-views-dsl-constraintlayoutcom.louiscad.splitties:splitties-views-dsl-coordinatorlayoutcom.louiscad.splitties:splitties-views-dsl-ide-previewcom.louiscad.splitties:splitties-views-dsl-materialcom.louiscad.splitties:splitties-views-dsl-recyclerviewcom.louiscad.splitties:splitties-views-materialcom.louiscad.splitties:splitties-views-recyclerviewcom.louiscad.splitties:splitties-views-selectablecom.louiscad.splitties:splitties-views-selectable-appcompatcom.louiscad.splitties:splitties-views-selectable-constraintlayoutSnapshotsLet'ssayyouneedtotryanewfeatureorafixthatdidnotmakeittoareleaseyet:
Youcangrabitinthesnapshotversionbyaddingthecorrespondingrepositoryasshownbelow,andchangingthelibraryversiontothelatestsnapshot,3.0.0-SNAPSHOT:
allProjects{repositories{mavenCentral()google()//Addsonatypesnapshotsrepobelowmaven(url="https://oss.sonatype.org/content/repositories/snapshots")}}NewversionsnotificationsReleasesareannouncedonGitHub,youcansubscribebyclickingon"Watch",then"Releasesonly".
However,ifyouuserefreshVersions,you'llalsolearnaboutupdateswhenyouruntherefreshVersionstaskrightintheversions.propertiesfile.
ImprovethislibraryIfyouwantthislibrarytohaveanewfeatureoranimprovementinaneworinanexistingmodule,please,openanissueorvote/commentasimilaronefirst,soitcanbediscussed.
Documentationcontributionsarealsowelcome.Fortyposorothersmallimprovements,feelfreetosubmitaPR(pullrequest)directly.Formoresignificantdoccontributions,pleaseopenanissuefirst,soitcanbediscussed.
Ifyoufindabug,pleaseopenanissuewithalltheimportantdetails.IfyouknowasimplefixthatisnotAPIbreakingandthatdoesnothavesideeffectsthatneedtobeconsidered,youmayalsodirectlysubmitaPR.
YoucanalsojointhediscussiononKotlin'sSlackinthe#splittieschannel(youcangetaninvitationhere).
WhatisasplitA"split"isamoduleoftheSplittieslibrarythatyoucanaddasadependency.Itonlyincludestherequiredtransitivedependencies.Thisallowsyoutoonlyaddwhatyouneedinyourapporlibrarymodule,sothefinalapk/ipa/appisassmallaspossibleanddoesn'tincludestuffnotusedbyyourapp.
Let'ssayyou'rebuildingaWearOSappusingtheViewsDSL.WearOSappsdon'tneedAppCompat.Includingitwouldbeawasteofbandwidthandstorage.TheViewsDSLcoremodulereliesontheAndroidSDKbutnotonAppCompat,soyoudon'tbloatyourwristappwithAppCompatbyusingViewsDSL.However,ifyouarebuildingaphone,tabletorcomputerAndroidapp,there'saViewsDSLAppCompatsplitwithafewextensionsforyoutouse.
CreditsSpecialthankstoJovcheMitrejchevskiforhelpingintakingdecisionsforthisproject.
ThankstoJetBrainsandthecontributorsforAnko,whichwasagreatsourceofinspiration,especiallyforViewsDSL,andofcoursethanksfortheexcellentKotlinprogramminglanguagethatmakesthisprojectpossible.
ThankstoDougStevensonforhisarticles"Kotlin&Android:ABrassTacksExperiment".ItisfairtosaythatViewsDSLhasitsrootinthisexperiment.
LicenseThislibraryispublishedunderApacheLicenseversion2.0whichyoucanseehere.
评论