-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
354 additions
and
257 deletions.
There are no files selected for viewing
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
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
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/example/recyclerview_sticky_headerfooter_example/App.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.recyclerview_sticky_headerfooter_example | ||
|
||
import android.app.Application | ||
import com.example.recyclerview_sticky_headerfooter_example.di.ViewModelModule | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.android.ext.koin.androidLogger | ||
import org.koin.core.context.startKoin | ||
|
||
class App: Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
startKoin { | ||
androidLogger() | ||
androidContext(this@App) | ||
modules(ViewModelModule) | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/example/recyclerview_sticky_headerfooter_example/BindingActivity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.recyclerview_sticky_headerfooter_example | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import androidx.annotation.LayoutRes | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
|
||
abstract class BindingActivity<T: ViewDataBinding> : AppCompatActivity() { | ||
@LayoutRes | ||
abstract fun getLayoutResId(): Int | ||
|
||
protected lateinit var binding: T | ||
private set | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = DataBindingUtil.setContentView(this, getLayoutResId()) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/example/recyclerview_sticky_headerfooter_example/BindingFragment.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.recyclerview_sticky_headerfooter_example | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
|
||
abstract class BindingFragment<T: ViewDataBinding> : Fragment() { | ||
@LayoutRes | ||
abstract fun getLayoutResId(): Int | ||
|
||
protected lateinit var binding: T | ||
private set | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
return DataBindingUtil.inflate<T>(inflater, getLayoutResId(), container, false).apply{ binding = this }.root | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
app/src/main/java/com/example/recyclerview_sticky_headerfooter_example/MainActivity.kt
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/example/recyclerview_sticky_headerfooter_example/di/ViewModelModule.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.recyclerview_sticky_headerfooter_example.di | ||
|
||
import com.example.recyclerview_sticky_headerfooter_example.ui.main.MainTabViewModel | ||
import com.example.recyclerview_sticky_headerfooter_example.ui.main.MainViewModel | ||
import org.koin.androidx.viewmodel.dsl.viewModel | ||
import org.koin.dsl.module | ||
|
||
val ViewModelModule = module { | ||
viewModel { MainViewModel() } | ||
viewModel { MainTabViewModel() } | ||
} |
27 changes: 27 additions & 0 deletions
27
...rc/main/java/com/example/recyclerview_sticky_headerfooter_example/ui/main/MainActivity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.example.recyclerview_sticky_headerfooter_example.ui.main | ||
|
||
import android.os.Bundle | ||
import androidx.annotation.LayoutRes | ||
import com.example.recyclerview_sticky_headerfooter_example.BindingActivity | ||
import com.example.recyclerview_sticky_headerfooter_example.R | ||
import com.example.recyclerview_sticky_headerfooter_example.databinding.ActivityMainBinding | ||
import org.koin.androidx.viewmodel.ext.android.getViewModel | ||
|
||
class MainActivity : BindingActivity<ActivityMainBinding>() { | ||
|
||
@LayoutRes | ||
override fun getLayoutResId() = R.layout.activity_main | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding.lifecycleOwner = this | ||
|
||
initFragment() | ||
} | ||
|
||
private fun initFragment() { | ||
supportFragmentManager.beginTransaction() | ||
.add(R.id.fragment, MainFragment.newInstance(), MainFragment.TAG) | ||
.commit() | ||
} | ||
} |
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
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
39 changes: 39 additions & 0 deletions
39
...java/com/example/recyclerview_sticky_headerfooter_example/ui/main/MainTabFirstFragment.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.recyclerview_sticky_headerfooter_example.ui.main | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.annotation.LayoutRes | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.Observer | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.example.recyclerview_sticky_headerfooter_example.BindingFragment | ||
import com.example.recyclerview_sticky_headerfooter_example.R | ||
import com.example.recyclerview_sticky_headerfooter_example.databinding.FragmentMainBinding | ||
import com.example.recyclerview_sticky_headerfooter_example.databinding.FragmentMainTabFirstBinding | ||
import org.koin.androidx.viewmodel.ext.android.getViewModel | ||
|
||
class MainTabFirstFragment : BindingFragment<FragmentMainTabFirstBinding>() { | ||
|
||
companion object { | ||
val TAG: String = MainTabFirstFragment::class.java.simpleName | ||
fun newInstance() = MainTabFirstFragment() | ||
} | ||
|
||
private lateinit var mVM: MainTabViewModel | ||
|
||
@LayoutRes | ||
override fun getLayoutResId() = R.layout.fragment_main_tab_first | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.vm = getViewModel() | ||
binding.lifecycleOwner = viewLifecycleOwner | ||
|
||
binding.vm?.let { | ||
mVM = it | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ava/com/example/recyclerview_sticky_headerfooter_example/ui/main/MainTabSecondFragment.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.recyclerview_sticky_headerfooter_example.ui.main | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.annotation.LayoutRes | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.Observer | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.example.recyclerview_sticky_headerfooter_example.BindingFragment | ||
import com.example.recyclerview_sticky_headerfooter_example.R | ||
import com.example.recyclerview_sticky_headerfooter_example.databinding.FragmentMainTabFirstBinding | ||
import com.example.recyclerview_sticky_headerfooter_example.databinding.FragmentMainTabSecondBinding | ||
import org.koin.androidx.viewmodel.ext.android.getViewModel | ||
|
||
class MainTabSecondFragment : BindingFragment<FragmentMainTabSecondBinding>() { | ||
|
||
companion object { | ||
val TAG: String = MainTabSecondFragment::class.java.simpleName | ||
fun newInstance() = MainTabSecondFragment() | ||
} | ||
|
||
private lateinit var mVM: MainTabViewModel | ||
|
||
@LayoutRes | ||
override fun getLayoutResId() = R.layout.fragment_main_tab_second | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.vm = getViewModel() | ||
binding.lifecycleOwner = viewLifecycleOwner | ||
|
||
binding.vm?.let { | ||
mVM = it | ||
} | ||
} | ||
} |
Oops, something went wrong.