匿名用户2021年11月23日
58阅读
开发技术Java
所属分类AndroidUI组件、手机/移动开发、Android UI 组件
授权协议Apache-2.0 License

作品详情

Splitties

SplittiesisacollectionofsmallKotlinmultiplatformlibraries(withAndroidasfirsttarget).

Theselibrariesareintendedtoreducetheamountofcodeyouhavetowrite,freeingcodereadingandwritingtime,soyoucanfocusmoreonwhatyouwanttobuildforyourusers(evenifyou'retheonlyone),orhavemoretimetohavefun.

Thisprojectisnamed"Splitties"becauseitissplitinsmallmodules,distributedasindependentlibraries,soyoucanaddonlytheonesyouneedtoyourproject/module,helpingreducethesizeofthefinalbinarythatusersdeviceswillneedtodownloadandkeepinthelimitedstorage(BTW,everythingislimited).

SomeAndroidtargetingmoduleshaveacontentsimilartowhatAnkooffers.SeeashortcomparisonofSplittieswithAnkohere.

Eachmodulehasbeendesignedtohaveasmallfootprintandbeasefficientaspossible.

Afewexamples

Splittiesisallaboutsimplifyingyourcode.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.DownloadGradleinstructions

MakesureyouhavemavenCentral()intherepositoriesdefinedinyourproject's(root)build.gradlefile(defaultfornewAndroidStudioprojects).

TomakeiteasiertotakeadvantageofthecontentsofSplittiesforyourAndroidprojects,therearegroupingartifactsthatincludemostsplits.

Androidbase

AddingwithrefreshVersions:Splitties.pack.androidBaseorSplitties.pack.androidBaseWithViewsDsl.

These2packsdon'tincludeAppCompatandaresuitableforWearOSapps.

Includesthefollowingmodules:

activitiesappctxbitflagsbundlecollectionscoroutinesdimensionsfragmentsfragmentargsintentslifecycle-coroutinesmainhandlermainthreadmaterial-colorspermissionspreferencesresourcessystemservicestoastviewsviews-coroutinesviews-recyclerviewviews-selectableviews-selectable-constraintlayout

Gradledependency:

implementation("com.louiscad.splitties:splitties-fun-pack-android-base:3.0.0")

There'salsoaversionwithViewsDSL.Itadditionallyincludesthefollowingmodules:

views-dslviews-dsl-constraintlayoutviews-dsl-recyclerview

Gradledependency:

implementation("com.louiscad.splitties:splitties-fun-pack-android-base-with-views-dsl:3.0.0")AndroidAppCompat

AddingwithrefreshVersions:Splitties.pack.appCompatorSplitties.pack.appCompatWithViewsDsl.

These2packsincludetheAndroidbasepack,andthefollowingmodules:

alertdialog-appcompatalertdialog-appcompat-coroutinesviews-appcompatviews-selectable-appcompat

Gradledependency:

implementation("com.louiscad.splitties:splitties-fun-pack-android-appcompat:3.0.0")

There'salsoaversionwithViewsDSL.ItadditionallyincludestheViewsDSLversionoftheAndroidbasepackandthefollowingmodule:

views-dsl-appcompat

Gradledependency:

implementation("com.louiscad.splitties:splitties-fun-pack-android-appcompat-with-views-dsl:3.0.0")AndroidMaterialComponents

AddingwithrefreshVersions:Splitties.pack.androidMdcorSplitties.pack.androidMdcWithViewsDsl.

These2packsincludetheAndroidAppCompatpack,andthefollowingmodules:

alertdialog-materialmaterial-listssnackbarviews-cardviewviews-coroutines-materialviews-material

Gradledependency:

implementation("com.louiscad.splitties:splitties-fun-pack-android-material-components:3.0.0")

There'salsoaversionwithViewsDSL.ItadditionallyincludestheViewsDSLversionoftheAndroidAppCompatpackandthefollowingmodules:

views-dsl-coordinatorlayoutviews-dsl-material

Gradledependency:

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-constraintlayoutSnapshots

Let'ssayyouneedtotryanewfeatureorafixthatdidnotmakeittoareleaseyet:

Youcangrabitinthesnapshotversionbyaddingthecorrespondingrepositoryasshownbelow,andchangingthelibraryversiontothelatestsnapshot,3.0.0-SNAPSHOT:

allProjects{repositories{mavenCentral()google()//Addsonatypesnapshotsrepobelowmaven(url="https://oss.sonatype.org/content/repositories/snapshots")}}Newversionsnotifications

ReleasesareannouncedonGitHub,youcansubscribebyclickingon"Watch",then"Releasesonly".

However,ifyouuserefreshVersions,you'llalsolearnaboutupdateswhenyouruntherefreshVersionstaskrightintheversions.propertiesfile.

Improvethislibrary

Ifyouwantthislibrarytohaveanewfeatureoranimprovementinaneworinanexistingmodule,please,openanissueorvote/commentasimilaronefirst,soitcanbediscussed.

Documentationcontributionsarealsowelcome.Fortyposorothersmallimprovements,feelfreetosubmitaPR(pullrequest)directly.Formoresignificantdoccontributions,pleaseopenanissuefirst,soitcanbediscussed.

Ifyoufindabug,pleaseopenanissuewithalltheimportantdetails.IfyouknowasimplefixthatisnotAPIbreakingandthatdoesnothavesideeffectsthatneedtobeconsidered,youmayalsodirectlysubmitaPR.

YoucanalsojointhediscussiononKotlin'sSlackinthe#splittieschannel(youcangetaninvitationhere).

Whatisasplit

A"split"isamoduleoftheSplittieslibrarythatyoucanaddasadependency.Itonlyincludestherequiredtransitivedependencies.Thisallowsyoutoonlyaddwhatyouneedinyourapporlibrarymodule,sothefinalapk/ipa/appisassmallaspossibleanddoesn'tincludestuffnotusedbyyourapp.

Let'ssayyou'rebuildingaWearOSappusingtheViewsDSL.WearOSappsdon'tneedAppCompat.Includingitwouldbeawasteofbandwidthandstorage.TheViewsDSLcoremodulereliesontheAndroidSDKbutnotonAppCompat,soyoudon'tbloatyourwristappwithAppCompatbyusingViewsDSL.However,ifyouarebuildingaphone,tabletorcomputerAndroidapp,there'saViewsDSLAppCompatsplitwithafewextensionsforyoutouse.

Credits

SpecialthankstoJovcheMitrejchevskiforhelpingintakingdecisionsforthisproject.

ThankstoJetBrainsandthecontributorsforAnko,whichwasagreatsourceofinspiration,especiallyforViewsDSL,andofcoursethanksfortheexcellentKotlinprogramminglanguagethatmakesthisprojectpossible.

ThankstoDougStevensonforhisarticles"Kotlin&Android:ABrassTacksExperiment".ItisfairtosaythatViewsDSLhasitsrootinthisexperiment.

License

ThislibraryispublishedunderApacheLicenseversion2.0whichyoucanseehere.

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论