Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
New library version 0.5.2:
Browse files Browse the repository at this point in the history
- Added new action mode to toolbar (similar to android toolbar actionmode)
- Fixed wrong main button state when using gesture to open main menu
- Toolbar items are now directly accessible to copy them for changes
- Renamed the viewmodel to prevent unwanted usage
- Refactoring
- Updated libraries and kotlin version
  • Loading branch information
Str3l0k committed Dec 14, 2019
1 parent 7ca4fb8 commit 4ab60d2
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 166 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/de/si/backdrop/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MainActivity : BackdropActivity() {

override fun onBackdropContentVisible(view: View): Boolean {
return when (view.id) {
R.id.menu_main_layout -> {
R.id.menu_main_layout -> {
configureTestMenuView(view)
true
}
Expand All @@ -32,14 +32,14 @@ class MainActivity : BackdropActivity() {
}
true
}
else -> false
else -> false
}
}

private fun configureTestMenuView(menuView: View) {
when {
menuView.id != MainMenu.resourceId -> return
mainMenu == null -> {
mainMenu == null -> {
mainMenu = MainMenu(menuView, this)
}
}
Expand Down
23 changes: 7 additions & 16 deletions app/src/main/java/de/si/backdrop/children/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentTransaction
import de.si.backdrop.R
import de.si.backdroplibrary.children.MainCardBackdropFragment
import de.si.backdroplibrary.components.BackdropToolbarItem
import de.si.backdroplibrary.components.BackdropToolbarMainButtonState
import de.si.backdroplibrary.components.toolbar.BackdropToolbarItem
import de.si.backdroplibrary.components.toolbar.BackdropToolbarMainButtonState
import kotlinx.android.synthetic.main.base_card.*
import kotlin.random.Random

class BaseFragment : MainCardBackdropFragment() {
override val menuButtonState: BackdropToolbarMainButtonState
get() = BackdropToolbarMainButtonState.MENU

override val toolbarItem: BackdropToolbarItem = BackdropToolbarItem(title = "Backdrop",
subtitle = "Demonstration",
primaryAction = R.drawable.ic_add,
moreActionEnabled = true)
override val toolbarItem: BackdropToolbarItem =
BackdropToolbarItem(title = "Backdrop",
subtitle = "Demonstration",
primaryAction = R.drawable.ic_add,
moreActionEnabled = true)

override fun onCreateContentView(inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -32,15 +32,6 @@ class BaseFragment : MainCardBackdropFragment() {
button.setOnClickListener {

}

bottomNavigationView.setOnNavigationItemSelectedListener {
val transaction = childFragmentManager.beginTransaction()
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
transaction.replace(R.id.testContainer, TestFragment())
transaction.commit()

true
}
}

override fun onPrimaryActionClicked(): Boolean {
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/de/si/backdrop/children/TestFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.si.backdrop.children

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import de.si.backdrop.R
import de.si.backdroplibrary.children.BackdropFragment
import kotlin.random.Random

class TestFragment : BackdropFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.test_content, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.setBackgroundColor(Color.rgb(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import android.view.View
import android.view.ViewGroup
import de.si.backdrop.R
import de.si.backdroplibrary.children.CardBackdropFragment
import de.si.backdroplibrary.components.BackdropToolbarItem
import de.si.backdroplibrary.components.toolbar.BackdropToolbarItem

class TopCardBackdropFragment : CardBackdropFragment() {
override var toolbarItem: BackdropToolbarItem = BackdropToolbarItem(title = "Mid card",
moreActionEnabled = false,
primaryAction = R.drawable.ic_add)
override var toolbarItem: BackdropToolbarItem =
BackdropToolbarItem(title = "Mid card",
moreActionEnabled = true,
primaryAction = R.drawable.ic_add)

override fun onCreateContentView(inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -33,4 +34,15 @@ class TopCardBackdropFragment : CardBackdropFragment() {
changeToolbarItem(toolbarItem)
return true
}

override fun onMoreActionClicked(): Boolean {
startToolbarActionMode(BackdropToolbarItem(title = "Card action mode",
primaryAction = R.drawable.ic_change_content))
return true
}

override fun onToolbarActionModeFinished(): Boolean {
println("TopCardBackdropFragment.onToolbarActionModeFinished")
return true
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/menu/test_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/one"
android:title="One"
/>
<item
android:id="@+id/two"
android:title="Two"
/>
<item
android:id="@+id/three"
android:title="Three"
/>
</menu>
12 changes: 6 additions & 6 deletions backdroplibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'digital.wup.android-maven-publish'

group='com.github.Str3l0k'
group = 'com.github.Str3l0k'

android {
compileSdkVersion 29
Expand Down Expand Up @@ -55,10 +55,10 @@ dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-beta01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-rc03'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.material:material:1.1.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
implementation 'com.google.android.material:material:1.2.0-alpha02'

testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand All @@ -68,7 +68,7 @@ dependencies {
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation 'androidx.test.ext:truth:1.2.0'

androidTestImplementation 'androidx.test:core:1.2.1-alpha02'
androidTestImplementation 'androidx.test:core:1.3.0-alpha03'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand All @@ -80,7 +80,7 @@ publishing {
maven(MavenPublication) {
groupId = 'de.si.backdrop'
artifactId = 'core'
version = '0.4.0'
version = '0.5.2'

from components.android
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,69 @@ import de.si.backdroplibrary.activity.BackdropActivity
import de.si.backdroplibrary.children.CardBackdropFragment
import de.si.backdroplibrary.children.FullscreenBackdropFragment
import de.si.backdroplibrary.children.FullscreenRevealBackdropFragment
import de.si.backdroplibrary.components.BackdropToolbarItem
import de.si.backdroplibrary.components.toolbar.BackdropToolbarItem

interface BackdropComponent {

//-----------------------------------------
//-----------------------------------------
val backdropActivity: BackdropActivity

val viewModel: BackdropViewModel
val backdropViewModel: BackdropViewModel
get() = BackdropViewModel.registeredInstance(backdropActivity)

//-----------------------------------------
// General
//-----------------------------------------
fun enableGestureNavigation() {
viewModel.gestureNavigationEnabled = true
backdropViewModel.gestureNavigationEnabled = true
}

fun disableGestureNavigation() {
viewModel.gestureNavigationEnabled = false
backdropViewModel.gestureNavigationEnabled = false
}

//-----------------------------------------
// Card stack
//-----------------------------------------
fun addCardFragment(cardFragment: CardBackdropFragment) {
viewModel.emit(Event.ADD_TOP_CARD, cardFragment)
backdropViewModel.emit(Event.ADD_TOP_CARD, cardFragment)
}

fun removeTopCardFragment() {
viewModel.emit(Event.REMOVE_TOP_CARD)
backdropViewModel.emit(Event.REMOVE_TOP_CARD)
}

//-----------------------------------------
// Fullscreen fragments
//-----------------------------------------
fun showFullscreenFragment(fragment: FullscreenBackdropFragment) {
viewModel.emit(Event.SHOW_FULLSCREEN_FRAGMENT, fragment)
backdropViewModel.emit(Event.SHOW_FULLSCREEN_FRAGMENT, fragment)
}

fun revealFullscreenFragment(parameters: FullscreenRevealBackdropFragment, revealEpicenter: Point, concealEpicenter: Point) {
parameters.revealEpiCenter = revealEpicenter
parameters.concealEpiCenter = concealEpicenter
viewModel.emit(Event.REVEAL_FULLSCREEN_FRAGMENT, parameters)
backdropViewModel.emit(Event.REVEAL_FULLSCREEN_FRAGMENT, parameters)
}

fun hideFullscreenFragment() {
viewModel.emit(Event.HIDE_FULLSCREEN_FRAGMENT)
backdropViewModel.emit(Event.HIDE_FULLSCREEN_FRAGMENT)
}

//-----------------------------------------
// Content
//-----------------------------------------
fun prefetchBackdropContent(@LayoutRes layoutResId: Int) {
viewModel.emit(Event.PREFETCH_BACKDROP_CONTENT_VIEW, layoutResId)
backdropViewModel.emit(Event.PREFETCH_BACKDROP_CONTENT_VIEW, layoutResId)
}

fun showBackdropContent(@LayoutRes layoutResId: Int) {
viewModel.emit(Event.SHOW_BACKDROP_CONTENT, layoutResId)
backdropViewModel.emit(Event.SHOW_BACKDROP_CONTENT, layoutResId)
}

fun hideBackdropContent() {
viewModel.emit(Event.HIDE_BACKDROP_CONTENT)
backdropViewModel.emit(Event.HIDE_BACKDROP_CONTENT)
}

fun onBackdropContentVisible(view: View): Boolean {
Expand All @@ -83,8 +83,24 @@ interface BackdropComponent {
//-----------------------------------------
// Toolbar
//-----------------------------------------
fun currentToolbarItem(): BackdropToolbarItem {
return backdropActivity.backdropToolbar.currentToolbarItem
}

fun actionModeToolbarItem(): BackdropToolbarItem? {
return backdropActivity.backdropToolbar.actionModeToolbarItem
}

fun changeToolbarItem(toolbarItem: BackdropToolbarItem) {
viewModel.emit(Event.CHANGE_NAVIGATION_ITEM, toolbarItem)
backdropViewModel.emit(Event.CHANGE_NAVIGATION_ITEM, toolbarItem)
}

fun startToolbarActionMode(toolbarItem: BackdropToolbarItem) {
backdropViewModel.emit(Event.START_ACTION_MODE, toolbarItem)
}

fun finishToolbarActionMode() {
backdropViewModel.emit(Event.FINISH_ACTION_MODE)
}

fun onPrimaryActionClicked(): Boolean {
Expand All @@ -94,4 +110,16 @@ interface BackdropComponent {
fun onMoreActionClicked(): Boolean {
return false
}

fun onPrimaryActionInActionModeClicked(): Boolean {
return false
}

fun onMoreActionInActionModeClicked(): Boolean {
return false
}

fun onToolbarActionModeFinished(): Boolean {
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.si.backdroplibrary
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider

internal typealias BackdropEventCallback = ((Event, Any?) -> Boolean)

Expand All @@ -29,7 +29,9 @@ class BackdropViewModel : ViewModel() {
}

internal fun emit(event: Event, payload: Any? = null) {
val callbackResult = callbackReceivers.reversed().firstOrNull { it.invoke(event, payload) }
val callbackResult = callbackReceivers.reversed().firstOrNull {
it.invoke(event, payload)
}

if (callbackResult == null) {
Log.w("Backdrop Event System", "Nobody consumed event = [$event], payload = [$payload]")
Expand All @@ -40,7 +42,7 @@ class BackdropViewModel : ViewModel() {
//-----------------------------------------
companion object {
internal fun registeredInstance(activity: AppCompatActivity): BackdropViewModel {
return ViewModelProviders.of(activity)[BackdropViewModel::class.java]
return ViewModelProvider(activity)[BackdropViewModel::class.java]
}
}
}
5 changes: 5 additions & 0 deletions backdroplibrary/src/main/java/de/si/backdroplibrary/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ internal enum class Event {
PRIMARY_ACTION_TRIGGERED,
MORE_ACTION_TRIGGERED,
CHANGE_NAVIGATION_ITEM,
START_ACTION_MODE,
FINISH_ACTION_MODE,
PRIMARY_ACTION_ACTIONMODE_TRIGGERED,
MORE_ACTION_ACTIONMODE_TRIGGERED,
ACTION_MODE_FINISHED,

// card stack
ADD_TOP_CARD,
Expand Down
Loading

0 comments on commit 4ab60d2

Please sign in to comment.