This is a android library for multi-view-status-placeholder.
-
Adding Hilt to you application.
-
Add it in your root build.gradle at the end of repositories.
repositories { jcenter() }
-
Add dependencies.
implementation 'com.murphy.view.status.placeholder:view-status-placeholder:1.0.0'
-
Define module provide template placeholder fragment in you application that mapping common multi-view-status-placeholder.
import com.murphy.status.placeholder.PlaceholderFragment @Module @InstallIn(ActivityComponent::class) class PlaceholderModule { @Provides @ActivityScoped @Blank fun provideBlankPlaceholder(): PlaceholderFragment { return BlankFragment() } @Provides @ActivityScoped @Loading fun provideLoadingPlaceholder(): PlaceholderFragment { return LoadingFragment() } @Provides @ActivityScoped @Error fun provideErrorPlaceholder(): PlaceholderFragment { return ErrorFragment() } }
-
Use inject for PlaceholderNavigation.
@AndroidEntryPoint class MainActivity : AppCompatActivity() { @Inject lateinit var placeholderNavigation: PlaceholderNavigation override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //placeholderNavigation.navigationPlaceholder(this, LOADING) placeholderNavigation.navigationPlaceholder(this, LOADING, R.id.container) } }
-
And you can also define you placeholder fragment for special.
import com.murphy.status.placeholder.PlaceholderFragment class NetErrorFragment constructor(): PlaceholderFragment() { override fun getPlaceholderLayout(): Int { return R.layout.common_fragment_net_error_placeholder } }
then use it that you defined
placeholderNavigation.navigationPlaceholder(this, NetErrorFragment())
- see source code!