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
103 changed files
with
4,230 additions
and
1,420 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">DevDrawer2 (Debug)</string> | ||
<string name="app_name" translatable="false">DevDrawer2 (Debug)</string> | ||
</resources> |
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
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,56 @@ | ||
package de.psdev.devdrawer | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Grid3x3 | ||
import androidx.compose.material.icons.filled.Info | ||
import androidx.compose.material.icons.filled.Settings | ||
import androidx.compose.material.icons.filled.Widgets | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import de.psdev.devdrawer.database.Widget | ||
import de.psdev.devdrawer.database.WidgetProfile | ||
|
||
sealed class DevDrawerScreen( | ||
val route: String | ||
) | ||
|
||
sealed class TopLevelScreen(route: String): DevDrawerScreen(route) { | ||
abstract val icon: ImageVector | ||
@get:StringRes abstract val label: Int | ||
} | ||
|
||
object Widgets: TopLevelScreen( | ||
route = "widgets" | ||
) { | ||
override val icon: ImageVector = Icons.Filled.Widgets | ||
override val label: Int = R.string.widgets | ||
} | ||
|
||
object Profiles: TopLevelScreen( | ||
route = "profiles" | ||
) { | ||
override val icon: ImageVector = Icons.Filled.Grid3x3 | ||
override val label: Int = R.string.profiles | ||
} | ||
|
||
object Settings: TopLevelScreen( | ||
route = "settings" | ||
) { | ||
override val icon: ImageVector = Icons.Filled.Settings | ||
override val label: Int = R.string.settings | ||
} | ||
|
||
object AppInfo: TopLevelScreen( | ||
route = "info" | ||
) { | ||
override val icon: ImageVector = Icons.Filled.Info | ||
override val label: Int = R.string.app_info | ||
} | ||
|
||
data class WidgetEditorDestination( | ||
val widget: Widget | ||
): DevDrawerScreen(route = "widgets/${widget.id}") | ||
|
||
data class ProfileEditorDestination( | ||
val widgetProfile: WidgetProfile | ||
): DevDrawerScreen(route = "profiles/${widgetProfile.id}") |
Oops, something went wrong.