forked from tunitowen/DevDrawer
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit reimplements the UI with JetPack Compose.
- Loading branch information
Showing
62 changed files
with
2,183 additions
and
1,107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
language: android | ||
jdk: | ||
- openjdk11 | ||
android: | ||
components: | ||
- tools | ||
|
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
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 |
---|---|---|
@@ -1,59 +1,26 @@ | ||
package de.psdev.devdrawer | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.CallSuper | ||
import androidx.annotation.StringRes | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.LifecycleCoroutineScope | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.viewbinding.ViewBinding | ||
import de.psdev.devdrawer.analytics.TrackingService | ||
import javax.inject.Inject | ||
|
||
abstract class BaseFragment<T : ViewBinding> : Fragment() { | ||
open class BaseFragment : Fragment() { | ||
|
||
@Inject | ||
lateinit var trackingService: TrackingService | ||
|
||
private var _binding: T? = null | ||
// This property is only valid between onCreateView and onDestroyView. | ||
protected val binding get() = _binding!! | ||
|
||
protected var toolbarTitle: CharSequence | ||
get() = requireActivity().title | ||
set(value) { | ||
requireActivity().title = value | ||
} | ||
|
||
final override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View = createViewBinding(inflater, container, savedInstanceState).also { viewBinding -> | ||
_binding = viewBinding | ||
}.root | ||
|
||
protected abstract fun createViewBinding( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): T | ||
|
||
@CallSuper | ||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
val Fragment.viewLifecycleScope: LifecycleCoroutineScope | ||
get() = viewLifecycleOwner.lifecycleScope | ||
|
||
protected fun updateToolbarTitle(@StringRes resId: Int) { | ||
requireActivity().setTitle(resId) | ||
trackingService.trackScreen(this::class.java, getString(resId)) | ||
} | ||
|
||
val Fragment.viewLifecycleScope: LifecycleCoroutineScope | ||
get() = viewLifecycleOwner.lifecycleScope | ||
|
||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
app/src/main/java/de/psdev/devdrawer/ViewBindingBaseFragment.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,37 @@ | ||
package de.psdev.devdrawer | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.CallSuper | ||
import androidx.viewbinding.ViewBinding | ||
|
||
abstract class ViewBindingBaseFragment<T : ViewBinding> : BaseFragment() { | ||
|
||
private var _binding: T? = null | ||
|
||
// This property is only valid between onCreateView and onDestroyView. | ||
protected val binding get() = _binding!! | ||
|
||
final override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View = createViewBinding(inflater, container, savedInstanceState).also { viewBinding -> | ||
_binding = viewBinding | ||
}.root | ||
|
||
protected abstract fun createViewBinding( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): T | ||
|
||
@CallSuper | ||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
} |
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
Oops, something went wrong.