Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean and upgrade dependencies #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions ViewPager2/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
compileSdkVersion 32
defaultConfig {
applicationId "com.example.androidx.viewpager2"
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -31,14 +30,19 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.fragment:fragment-ktx:1.2.0-beta02'
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50'

implementation 'androidx.activity:activity-ktx:1.4.0'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'

implementation 'com.google.android.material:material:1.6.1'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.7.0'

// Testing dependencies
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
30 changes: 20 additions & 10 deletions ViewPager2/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,80 @@
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light">

<activity android:name=".CardViewActivity">
<activity android:name=".CardViewActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".CardFragmentActivity">
<activity android:name=".CardFragmentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".MutableCollectionFragmentActivity">
<activity android:name=".MutableCollectionFragmentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".MutableCollectionViewActivity">
<activity android:name=".MutableCollectionViewActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".CardViewTabLayoutActivity">
<activity android:name=".CardViewTabLayoutActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".FakeDragActivity">
<activity android:name=".FakeDragActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".PageTransformerActivity">
<activity android:name=".PageTransformerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".PreviewPagesActivity">
<activity android:name=".PreviewPagesActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".ParallelNestedScrollingActivity">
<activity android:name=".ParallelNestedScrollingActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.SAMPLE_CODE"/>
</intent-filter>
</activity>

<activity android:name=".BrowseActivity">
<activity android:name=".BrowseActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,92 @@

package androidx.viewpager2.integration.testapp

import android.app.ListActivity
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.ListView
import android.widget.SimpleAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

/**
* This activity lists all the activities in this application.
*/
class BrowseActivity : ListActivity() {
class BrowseActivity : Activity() {

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_browse)

listAdapter = SimpleAdapter(this, getData(),
android.R.layout.simple_list_item_1, arrayOf("title"),
intArrayOf(android.R.id.text1))
with(findViewById<RecyclerView>(R.id.list)) {
layoutManager = LinearLayoutManager(this@BrowseActivity)
adapter = BrowseAdapter(data = getData()) { map ->
val intent = Intent(map["intent"] as Intent)
intent.addCategory(Intent.CATEGORY_SAMPLE_CODE)
startActivity(intent)
}
}
}

private fun getData(): List<Map<String, Any>> {
val myData = mutableListOf<Map<String, Any>>()
val data = mutableListOf<Map<String, Any>>()

myData.add(mapOf("title" to "ViewPager2 with Views",
"intent" to activityToIntent(CardViewActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with Fragments",
"intent" to activityToIntent(CardFragmentActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with a Mutable Collection (Views)",
"intent" to activityToIntent(MutableCollectionViewActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with a Mutable Collection (Fragments)",
"intent" to activityToIntent(MutableCollectionFragmentActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with a TabLayout (Views)",
"intent" to activityToIntent(CardViewTabLayoutActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with Fake Dragging",
"intent" to activityToIntent(FakeDragActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with PageTransformers",
"intent" to activityToIntent(PageTransformerActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with a Preview of Next/Prev Page",
"intent" to activityToIntent(PreviewPagesActivity::class.java.name)))
myData.add(mapOf("title" to "ViewPager2 with Nested RecyclerViews",
"intent" to activityToIntent(ParallelNestedScrollingActivity::class.java.name)))
data.add(
mapOf(
"title" to "ViewPager2 with Views",
"intent" to activityToIntent(CardViewActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with Fragments",
"intent" to activityToIntent(CardFragmentActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with a Mutable Collection (Views)",
"intent" to activityToIntent(MutableCollectionViewActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with a Mutable Collection (Fragments)",
"intent" to activityToIntent(MutableCollectionFragmentActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with a TabLayout (Views)",
"intent" to activityToIntent(CardViewTabLayoutActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with Fake Dragging",
"intent" to activityToIntent(FakeDragActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with PageTransformers",
"intent" to activityToIntent(PageTransformerActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with a Preview of Next/Prev Page",
"intent" to activityToIntent(PreviewPagesActivity::class.java.name)
)
)
data.add(
mapOf(
"title" to "ViewPager2 with Nested RecyclerViews",
"intent" to activityToIntent(ParallelNestedScrollingActivity::class.java.name)
)
)

return myData
return data
}

private fun activityToIntent(activity: String): Intent =
Intent(Intent.ACTION_VIEW).setClassName(this.packageName, activity)

override fun onListItemClick(listView: ListView, view: View, position: Int, id: Long) {
val map = listView.getItemAtPosition(position) as Map<*, *>

val intent = Intent(map["intent"] as Intent)
intent.addCategory(Intent.CATEGORY_SAMPLE_CODE)
startActivity(intent)
}
Intent(Intent.ACTION_VIEW).setClassName(this.packageName, activity)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package androidx.viewpager2.integration.testapp

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class BrowseAdapter(
private val data: List<Map<String, Any>>,
private val onItemClickListener: (item: Map<String, Any>) -> Unit
) : RecyclerView.Adapter<BrowseAdapter.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
itemView = LayoutInflater.from(parent.context)
.inflate(android.R.layout.simple_list_item_1, parent, false)
)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(data[position]["title"] as? String ?: "")
}

override fun getItemCount(): Int {
return data.size
}

inner class ViewHolder(
itemView: View
) : RecyclerView.ViewHolder(itemView) {

private val text1 = itemView.findViewById<TextView>(android.R.id.text1)

init {
text1.setOnClickListener {
val adapterPosition = bindingAdapterPosition
if (adapterPosition != RecyclerView.NO_POSITION) {
onItemClickListener.invoke(data[adapterPosition])
}
}
}

fun bind(text: String) {
text1.text = text
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FakeDragActivity : FragmentActivity() {
private var lastValue: Float = 0f

private val isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) ==
ViewCompat.LAYOUT_DIRECTION_RTL
ViewCompat.LAYOUT_DIRECTION_RTL

private val ViewPager2.isHorizontal: Boolean
get() {
Expand Down Expand Up @@ -85,4 +85,4 @@ class FakeDragActivity : FragmentActivity() {
}
return true
}
}
}
7 changes: 7 additions & 0 deletions ViewPager2/app/src/main/res/layout/activity_browse.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">

</androidx.recyclerview.widget.RecyclerView>
8 changes: 4 additions & 4 deletions ViewPager2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50'
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
1 change: 1 addition & 0 deletions ViewPager2/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ org.gradle.jvmargs=-Xmx1536m
# org.gradle.parallel=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.useAndroidX=true
Binary file modified ViewPager2/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions ViewPager2/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Jul 10 09:03:49 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Loading