coming! Real Material Design version of playing Android

Posted May 27, 20203 min read

Everyone is familiar with playing Android. It is an open source knowledge website of Hongyang Gang. At present, various versions of APPs based on playing the Android open source API are mostly like fur.

So after a period of hard work, today I brought you a new version of the ship that I have never had before.

design

The overall UI is based on the official design of Google and the style of Material Design is rough. It should bring a refreshing feeling to everyone.

Let's take a look at the renderings first

The bottom navigation bar uses BottomAppbar and FloatingActionButton components

MaterialShapeDrawable realizes the material sliding drawing of the expanded menu

private val foregroundShapeDrawable:MaterialShapeDrawable by lazy(NONE) {
        val foregroundContext = binding.foregroundContainer.context
        MaterialShapeDrawable(
            foregroundContext,
            null,
            R.attr.bottomSheetStyle,
            0
       ) .apply {
            fillColor = ColorStateList.valueOf(
                foregroundContext.themeColor(R.attr.colorPrimarySurface)
           )
            elevation = resources.getDimension(R.dimen.plane_16)
            shadowCompatibilityMode = MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER
            initializeElevationOverlay(requireContext())
            shapeAppearanceModel = shapeAppearanceModel.toBuilder()
                .setTopEdge(
                    SemiCircleEdgeCutoutTreatment(
                        resources.getDimension(R.dimen.grid_2),
                        resources.getDimension(R.dimen.grid_3),
                        0F,
                        resources.getDimension(R.dimen.navigation_drawer_profile_image_size_padded)
                   )
               )
                .build()
        }
    }

technology

The technical aspect is implemented in Kotlin language. The overall architecture is MVVM, which uses coroutines and Retrofit to create and process asynchronous tasks for network requests.

Lazy loading encapsulating dataBinding and viewBinding

/**
* Fragment ViewBinding Delegate
* /
fun <T:ViewBinding> Fragment.viewBinding(viewBindingFactory:(View)-> T) =
FragmentViewBindingDelegate(this, viewBindingFactory)

class FragmentViewBindingDelegate <T:ViewBinding>(
    val fragment:Fragment,
    val viewBindingFactory:(View)-> T

):ReadOnlyProperty <Fragment, T> {
private var _binding:T? = null

    init {
        fragment.lifecycle.addObserver(object:DefaultLifecycleObserver {
            override fun onCreate(owner:LifecycleOwner) {
                fragment.viewLifecycleOwnerLiveData.observe(fragment) {viewLifecycleOwner->
                    viewLifecycleOwner.lifecycle.addObserver(object:DefaultLifecycleObserver {
                        override fun onDestroy(owner:LifecycleOwner) {
                            _binding = null
                        }
                    })
                }
            }
        })
    }

    override fun getValue(thisRef:Fragment, property:KProperty <*>):T {
        val binding = _binding
        if(binding! = null) {
            return binding
        }

        val lifecycle = fragment.viewLifecycleOwner.lifecycle
        if(! lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
            throw IllegalStateException("Should not attempt to get bindings when Fragment views are destroyed.")
        }

        return viewBindingFactory(thisRef.requireView()). also {_binding = it}
    }
}

project address

For the complete code of the project, please go to the GitHub repository WanAndroid \ _Gank

At the same time, everyone is welcome to give me a star encouragement.