Skip to content

Commit

Permalink
Merge pull request #10 from aitsuki/fix-9
Browse files Browse the repository at this point in the history
Fix #9
  • Loading branch information
aitsuki authored Oct 18, 2021
2 parents 4cc040c + f398f5f commit 0e4eea7
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 24 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.30'
ext.kotlin_version = '1.5.31'
ext.recyclerview_version = '1.2.1'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
39 changes: 24 additions & 15 deletions demo/src/main/java/com/aitsuki/swipedemo/DemoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,35 @@ class DemoFragment : Fragment() {
behavior.state = BottomSheetBehavior.STATE_EXPANDED
}

styleBinding.itemClassic.content.setOnClickListener {
changeStyle(ClassicItem())
}
styleBinding.apply {
itemClassic.content.setOnClickListener {
changeStyle(ClassicItem())
}

styleBinding.itemOverlay.content.setOnClickListener {
changeStyle(OverlayItem())
}
itemOverlay.content.setOnClickListener {
changeStyle(OverlayItem())
}

styleBinding.itemParallax.content.setOnClickListener {
changeStyle(ParallaxItem())
}
itemParallax.content.setOnClickListener {
changeStyle(ParallaxItem())
}

styleBinding.itemLong.content.setOnClickListener {
changeStyle(LongItem())
}
itemLong.content.setOnClickListener {
changeStyle(LongItem())
}

styleBinding.itemTencentQQ.content.setOnClickListener {
changeStyle(QQItem())
}
itemTencentQQ.content.setOnClickListener {
changeStyle(QQItem())
}

itemWithMargin.content.setOnClickListener {
changeStyle(WithMarginItem())
}

itemWithPadding.content.setOnClickListener {
changeStyle(WithPaddingItem())
}
}
changeStyle(ClassicItem())
return binding.root
}
Expand Down
28 changes: 28 additions & 0 deletions demo/src/main/java/com/aitsuki/swipedemo/items/WithMarginItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.aitsuki.swipedemo.items

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import com.aitsuki.swipedemo.BaseItem
import com.aitsuki.swipedemo.databinding.ItemWithMarginBinding

class WithMarginItem : BaseItem<ItemWithMarginBinding>() {

override fun inflate(inflater: LayoutInflater, parent: ViewGroup): ItemWithMarginBinding {
return ItemWithMarginBinding.inflate(inflater, parent, false)
}

override val bindFun = fun (binding: ItemWithMarginBinding, position: Int) {
binding.content.text = "With margin $position"
binding.content.setOnClickListener {
Toast.makeText(it.context, "With margin $position", Toast.LENGTH_SHORT).show()
}
binding.leftMenu.setOnClickListener {
Toast.makeText(it.context, "LEFT $position", Toast.LENGTH_SHORT).show()
}
binding.rightMenu.setOnClickListener {
Toast.makeText(it.context, "RIGHT $position", Toast.LENGTH_SHORT).show()
}
}

}
28 changes: 28 additions & 0 deletions demo/src/main/java/com/aitsuki/swipedemo/items/WithPaddingItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.aitsuki.swipedemo.items

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import com.aitsuki.swipedemo.BaseItem
import com.aitsuki.swipedemo.databinding.ItemWithPaddingBinding

class WithPaddingItem : BaseItem<ItemWithPaddingBinding>() {

override fun inflate(inflater: LayoutInflater, parent: ViewGroup): ItemWithPaddingBinding {
return ItemWithPaddingBinding.inflate(inflater, parent, false)
}

override val bindFun = fun (binding: ItemWithPaddingBinding, position: Int) {
binding.content.text = "With padding $position"
binding.content.setOnClickListener {
Toast.makeText(it.context, "With padding $position", Toast.LENGTH_SHORT).show()
}
binding.leftMenu.setOnClickListener {
Toast.makeText(it.context, "LEFT $position", Toast.LENGTH_SHORT).show()
}
binding.rightMenu.setOnClickListener {
Toast.makeText(it.context, "RIGHT $position", Toast.LENGTH_SHORT).show()
}
}

}
11 changes: 9 additions & 2 deletions demo/src/main/res/layout/fragment_style.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand Down Expand Up @@ -33,7 +33,14 @@
android:id="@+id/item_tencent_q_q"
layout="@layout/item_tencent_q_q" />

<include
android:id="@+id/item_with_margin"
layout="@layout/item_with_margin" />

<include
android:id="@+id/item_with_padding"
layout="@layout/item_with_padding" />

</LinearLayout>

</ScrollView>
</androidx.core.widget.NestedScrollView>
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/item_parallax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="80dp"
app:autoClose="true"
app:designer="@string/parallax_designer"
app:preview="right">
app:preview="none">

<LinearLayout
android:layout_width="wrap_content"
Expand Down
40 changes: 40 additions & 0 deletions demo/src/main/res/layout/item_with_margin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<com.aitsuki.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="10dp"
app:autoClose="true"
app:designer="@string/classic_designer"
app:preview="none">

<TextView
android:id="@+id/left_menu"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/red500"
android:gravity="center"
android:text="LEFT"
android:textSize="18sp" />

<TextView
android:id="@+id/right_menu"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/blue500"
android:gravity="center"
android:text="RIGHT"
android:textSize="18sp" />

<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:text="With margin"
android:textSize="18sp" />

</com.aitsuki.swipe.SwipeLayout>
40 changes: 40 additions & 0 deletions demo/src/main/res/layout/item_with_padding.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<com.aitsuki.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="10dp"
app:autoClose="true"
app:designer="@string/classic_designer"
app:preview="none">

<TextView
android:id="@+id/left_menu"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/red500"
android:gravity="center"
android:text="LEFT"
android:textSize="18sp" />

<TextView
android:id="@+id/right_menu"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/blue500"
android:gravity="center"
android:text="RIGHT"
android:textSize="18sp" />

<TextView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:text="With padding"
android:textSize="18sp" />

</com.aitsuki.swipe.SwipeLayout>
8 changes: 4 additions & 4 deletions library/src/main/java/com/aitsuki/swipe/SwipeLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ class SwipeLayout @JvmOverloads constructor(
bottom - paddingBottom
)
} else {
offset = (right - paddingRight - contentView.right).toFloat() / activeMenu.width
offset = (right - left - paddingRight - contentView.right).toFloat() / activeMenu.width
designer.onLayout(
activeMenu,
contentView.right,
paddingTop,
right - paddingRight,
right - left - paddingRight,
bottom - paddingBottom
)
}
Expand Down Expand Up @@ -518,9 +518,9 @@ class SwipeLayout @JvmOverloads constructor(
}
}
val parentLeft = paddingLeft
val parentRight = right - paddingRight
val parentRight = right - left - paddingRight
val parentTop = paddingTop
val parentBottom = bottom - paddingBottom
val parentBottom = bottom - top - paddingBottom

for (i in 0 until childCount) {
val child = getChildAt(i)
Expand Down

0 comments on commit 0e4eea7

Please sign in to comment.