Extract to library

This commit is contained in:
Oleksandr Balan
2022-05-14 22:08:29 +02:00
parent d62d35c898
commit 81d8898d24
48 changed files with 393 additions and 90 deletions

1
demo/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

56
demo/build.gradle Normal file
View File

@@ -0,0 +1,56 @@
plugins {
id "com.android.application"
id "org.jetbrains.kotlin.android"
}
android {
compileSdk 32
defaultConfig {
applicationId "eu.wewox.pagecurl"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = freeCompilerArgs +
"-Xopt-in=kotlin.RequiresOptIn"
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
dependencies {
implementation(project(":pagecurl"))
implementation("androidx.compose.ui:ui:$compose_version")
implementation("androidx.compose.material:material:$compose_version")
implementation("androidx.activity:activity-compose:$activity")
}

21
demo/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.wewox.pagecurl">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PageCurl">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.PageCurl">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,95 @@
@file:OptIn(ExperimentalPageCurlApi::class)
package eu.wewox.pagecurl
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import eu.wewox.pagecurl.config.PageCurlConfig
import eu.wewox.pagecurl.page.PageCurl
import eu.wewox.pagecurl.ui.theme.PageCurlTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PageCurlTheme {
var current by remember { mutableStateOf(0) }
val count = 6
PageCurl(
current = current,
count = count,
onCurrentChange = {
current = it
},
config = PageCurlConfig(),
) { index ->
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.White)
) {
when (index) {
0 -> {
Image(
painter = painterResource(R.drawable.img_sleep),
contentDescription = null,
contentScale = ContentScale.Crop,
)
}
count - 1 -> {
Text(
text = "The End",
fontSize = 34.sp,
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Center)
)
}
else -> {
Text(
text = if (index % 2 == 1) Data.Lorem1 else Data.Lorem2,
fontSize = 22.sp,
modifier = Modifier.padding(16.dp)
)
}
}
Text(
text = index.toString(),
color = Color.White,
modifier = Modifier
.align(Alignment.BottomEnd)
.background(Color.Black, RoundedCornerShape(topStartPercent = 100))
.padding(16.dp)
)
}
}
}
}
}
}
private object Data {
val Lorem1 =
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam erat volutpat. Phasellus enim erat, vestibulum vel, aliquam a, posuere eu, velit. Et harum quidem rerum facilis est et expedita distinctio. In sem justo, commodo ut, suscipit at, pharetra vitae, orci. Vestibulum fermentum tortor id mi. Sed elit dui, pellentesque a, faucibus vel, interdum nec, diam. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat. Nunc tincidunt ante vitae massa. Maecenas fermentum, sem in pharetra pellentesque, velit turpis volutpat ante, in pharetra metus odio a lectus. Proin in tellus sit amet nibh dignissim sagittis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Etiam posuere lacus quis dolor. Class aptent taciti sociosqu ad litora."
val Lorem2 =
"Phasellus enim erat, vestibulum vel, aliquam a, posuere eu, velit. Duis ante orci, molestie vitae vehicula venenatis, tincidunt ac pede. Aliquam in lorem sit amet leo accumsan lacinia. Morbi imperdiet, mauris ac auctor dictum, nisl ligula egestas nulla, et sollicitudin sem purus in lacus. Ut tempus purus at lorem. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer malesuada. Sed vel lectus. Donec odio tempus molestie, porttitor ut, iaculis quis, sem. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Etiam egestas wisi a erat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Maecenas lorem. Mauris dolor felis, sagittis at, luctus sed, aliquam non, tellus. Aenean id metus id velit ullamcorper pulvinar. Integer malesuada."
}

View File

@@ -0,0 +1,8 @@
package eu.wewox.pagecurl.ui.theme
import androidx.compose.ui.graphics.Color
val Purple200 = Color(0xFFBB86FC)
val Purple500 = Color(0xFF6200EE)
val Purple700 = Color(0xFF3700B3)
val Teal200 = Color(0xFF03DAC5)

View File

@@ -0,0 +1,11 @@
package eu.wewox.pagecurl.ui.theme
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.ui.unit.dp
val Shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
)

View File

@@ -0,0 +1,44 @@
package eu.wewox.pagecurl.ui.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable
private val DarkColorPalette = darkColors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200
)
private val LightColorPalette = lightColors(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200
/* Other default colors to override
background = Color.White,
surface = Color.White,
onPrimary = Color.White,
onSecondary = Color.Black,
onBackground = Color.Black,
onSurface = Color.Black,
*/
)
@Composable
fun PageCurlTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}
MaterialTheme(
colors = colors,
typography = Typography,
shapes = Shapes,
content = content
)
}

View File

@@ -0,0 +1,28 @@
package eu.wewox.pagecurl.ui.theme
import androidx.compose.material.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
// Set of Material typography styles to start with
val Typography = Typography(
body1 = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
)
/* Other default text styles to override
button = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.W500,
fontSize = 14.sp
),
caption = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 12.sp
)
*/
)

View File

@@ -0,0 +1,27 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group
android:scaleX="2.475"
android:scaleY="2.475"
android:translateX="34.2"
android:translateY="34.2">
<path
android:fillColor="#FFF281"
android:pathData="M4,0.375H12C14.002,0.375 15.625,1.9981 15.625,4.0001V4.0052V4.0103V4.0154V4.0205V4.0256V4.0307V4.0358V4.0409V4.046V4.0511V4.0561V4.0612V4.0663V4.0714V4.0765V4.0816V4.0867V4.0917V4.0968V4.1019V4.107V4.1121V4.1171V4.1222V4.1273V4.1324V4.1374V4.1425V4.1476V4.1526V4.1577V4.1628V4.1678V4.1729V4.178V4.183V4.1881V4.1932V4.1982V4.2033V4.2083V4.2134V4.2184V4.2235V4.2285V4.2336V4.2386V4.2437V4.2487V4.2538V4.2588V4.2639V4.2689V4.274V4.279V4.284V4.2891V4.2941V4.2991V4.3042V4.3092V4.3142V4.3193V4.3243V4.3293V4.3343V4.3394V4.3444V4.3494V4.3544V4.3594V4.3644V4.3695V4.3745V4.3795V4.3845V4.3895V4.3945V4.3995V4.4045V4.4095V4.4145V4.4195V4.4245V4.4295V4.4345V4.4395V4.4445V4.4495V4.4545V4.4595V4.4644V4.4694V4.4744V4.4794V4.4844V4.4893V4.4943V4.4993V4.5043V4.5092V4.5142V4.5192V4.5241V4.5291V4.5341V4.539V4.544V4.5489V4.5539V4.5588V4.5638V4.5687V4.5737V4.5786V4.5836V4.5885V4.5934V4.5984V4.6033V4.6083V4.6132V4.6181V4.623V4.628V4.6329V4.6378V4.6427V4.6476V4.6526V4.6575V4.6624V4.6673V4.6722V4.6771V4.682V4.6869V4.6918V4.6967V4.7016V4.7065V4.7114V4.7163V4.7211V4.726V4.7309V4.7358V4.7407V4.7456V4.7504V4.7553V4.7602V4.765V4.7699V4.7748V4.7796V4.7845V4.7893V4.7942V4.799V4.8039V4.8087V4.8136V4.8184V4.8232V4.8281V4.8329V4.8377V4.8426V4.8474V4.8522V4.8571V4.8619V4.8667V4.8715V4.8763V4.8811V4.8859V4.8907V4.8955V4.9004V4.9051V4.9099V4.9147V4.9195V4.9243V4.9291V4.9339V4.9387V4.9434V4.9482V4.953V4.9578V4.9625V4.9673V4.9721V4.9768V4.9816V4.9863V4.9911V4.9958V5.0006V5.0053V5.01V5.0148V5.0195V5.0243V5.029V5.0337V5.0384V5.0432V5.0479V5.0526V5.0573V5.062V5.0667V5.0714V5.0761V5.0808V5.0855V5.0902V5.0949V5.0996V5.1043V5.109V5.1136V5.1183V5.123V5.1277V5.1323V5.137V5.1417V5.1463V5.151V5.1556V5.1603V5.1649V5.1696V5.1742V5.1788V5.1835V5.1881V5.1927V5.1974V5.202V5.2066V5.2112V5.2158V5.2204V5.225V5.2296V5.2342V5.2388V5.2434V5.248V5.2526V5.2572V5.2618V5.2663V5.2709V5.2755V5.2801V5.2846V5.2892V5.2937V5.2983V5.3029V5.3074V5.312V5.3165V5.321V5.3256V5.3301V5.3346V5.3391V5.3437V5.3482V5.3527V5.3572V5.3617V5.3662V5.3707V5.3752V5.3797V5.3842V5.3887V5.3932V5.3977V5.4021V5.4066V5.4111V5.4155V5.42V5.4245V5.4289V5.4334V5.4378V5.4423V5.4467V5.4511V5.4556V5.46V5.4644V5.4689V5.4733V5.4777V5.4821V5.4865V5.4909V5.4953V5.4997V5.5041V5.5085V5.5129V5.5173V5.5216V5.526V5.5304V5.5348V5.5391V5.5435V5.5478V5.5522V5.5565V5.5609V5.5652V5.5696V5.5739V5.5782V5.5826V5.5869V5.5912V5.5955V5.5998V5.6041V5.6084V5.6127V5.617V5.6213V5.6256V5.6299V5.6341V5.6384V5.6427V5.6469V5.6512V5.6555V5.6597V5.664V5.6682V5.6725V5.6767V5.6809V5.6852V5.6894V5.6936V5.6978V5.702V5.7062V5.7104V5.7146V5.7188V5.723V5.7272V5.7314V5.7356V5.7397V5.7439V5.7481V5.7523V5.7564V5.7606V5.7647V5.7689V5.773V5.7771V5.7813V5.7854V5.7895V5.7936V5.7977V5.8019V5.806V5.8101V5.8142V5.8183V5.8223V5.8264V5.8305V5.8346V5.8387V5.8427V5.8468V5.8508V5.8549V5.8589V5.863V5.867V5.871V5.8751V5.8791V5.8831V5.8871V5.8911V5.8952V5.8992V5.9032V5.9071V5.9111V5.9151V5.9191V5.9231V5.927V5.931V5.935V5.9389V5.9429V5.9468V5.9508V5.9547V5.9586V5.9626V5.9665V5.9704V5.9743V5.9782V5.9821V5.986V5.9899V5.9938V5.9977V6.0016V6.0054V6.0093V6.0132V6.017V6.0209V6.0247V6.0286V6.0324V6.0363V6.0401V6.0439V6.0477V6.0515V6.0554V6.0592V6.063V6.0668V6.0705V6.0743V6.0781V6.0819V6.0857V6.0894V6.0932V6.0969V6.1007V6.1044V6.1082V6.1119V6.1156V6.1194V6.1231V6.1268V6.1305V6.1342V6.1379V6.1416V6.1453V6.149V6.1526V6.1563V6.16V6.1636V6.1673V6.1709V6.1746V6.1782V6.1819V6.1855V6.1891V6.1927V6.1964V6.2V6.2036V6.2072V6.2108V6.2144V6.2179V6.2215V6.2251V6.2287V6.2322V6.2358V6.2393V6.2428V6.2464V6.2499V6.2534V6.257V6.2605V6.264V6.2675V6.271V6.2745V6.278V6.2815V6.2849V6.2884V6.2919V6.2954C15.625,6.6481 15.4851,6.9846 15.2348,7.2348L7.2348,15.2348C6.985,15.4847 6.6462,15.625 6.2929,15.625H4C1.998,15.625 0.375,14.002 0.375,12V4C0.375,1.998 1.998,0.375 4,0.375Z"
android:strokeWidth="0.75"
android:strokeColor="#000000" />
<path
android:fillColor="#FFF9C2"
android:pathData="M10,6.375H15.5902C15.5151,6.7764 15.3206,7.1491 15.0277,7.4419L11.7348,10.7348L7.4419,15.0277C7.1491,15.3206 6.7764,15.5151 6.375,15.5902V10C6.375,7.998 7.998,6.375 10,6.375Z"
android:strokeWidth="0.75"
android:strokeColor="#000000" />
<path
android:fillColor="#6DD3FF"
android:pathData="M7.4057,15.1246L15.1251,7.4053V11.4979C15.1251,13.4994 13.503,15.1221 11.5016,15.1229L7.4057,15.1246Z"
android:strokeWidth="0.75"
android:strokeColor="#000000" />
</group>
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 KiB

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">PageCurl</string>
</resources>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.PageCurl" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@color/purple_700</item>
</style>
</resources>