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

Android Studio 3.6.1 [slices samples] #133

Open
wants to merge 3 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion InteractiveSliceProviderKotlin/app/.gitignore

This file was deleted.

21 changes: 14 additions & 7 deletions InteractiveSliceProviderKotlin/app/build.gradle
Expand Up @@ -13,6 +13,14 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
}
buildTypes {
release {
Expand All @@ -23,10 +31,9 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "androidx.core:core-ktx:1.0.1"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.core:core-ktx:1.2.0"

// The slice builder ktx library has a number of dependencies. For reference, since this is a
// slice sample, below are a list of the slice dependencies:
Expand All @@ -35,10 +42,10 @@ dependencies {
implementation "androidx.slice:slice-builders-ktx:1.0.0-alpha6"

implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "com.google.firebase:firebase-appindexing:17.1.0"
testImplementation "junit:junit:4.12"
androidTestImplementation "androidx.test:runner:1.1.1"
androidTestImplementation "androidx.test.espresso:espresso-core:3.1.1"
implementation "com.google.firebase:firebase-appindexing:19.1.0"
testImplementation "junit:junit:4.13"
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
}

apply plugin: "com.google.gms.google-services"
10 changes: 3 additions & 7 deletions InteractiveSliceProviderKotlin/build.gradle
@@ -1,17 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.0'
ext.kotlin_version = '1.3.70'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.3.3'
}
}

Expand Down
@@ -1,6 +1,6 @@
#Thu May 24 23:16:35 PDT 2018
#Wed Feb 19 12:27:54 CET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
17 changes: 10 additions & 7 deletions SliceViewerKotlin/app/build.gradle
Expand Up @@ -8,14 +8,14 @@ repositories {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
implementation "androidx.lifecycle:lifecycle-common:2.0.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common:2.2.0"
implementation "androidx.slice:slice-view:1.1.0-alpha01"
implementation "androidx.slice:slice-builders-ktx:1.0.0-alpha6"
implementation "androidx.appcompat:appcompat:1.0.0"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.core:core-ktx:1.0.0"
implementation "androidx.core:core-ktx:1.2.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}

Expand All @@ -31,7 +31,10 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
}
Expand Up @@ -30,62 +30,57 @@ import androidx.slice.core.SliceHints
import androidx.slice.widget.SliceLiveData
import androidx.slice.widget.SliceView
import androidx.slice.widget.SliceView.OnSliceActionListener
import com.example.android.sliceviewer.ui.list.SliceViewerActivity
import com.example.android.sliceviewer.ui.list.SliceViewerActivity.Companion.TAG

fun SliceView.bind(
context: Context,
lifecycleOwner: LifecycleOwner,
uri: Uri,
onSliceActionListener: OnSliceActionListener = OnSliceActionListener { _, _ -> },
onClickListener: OnClickListener = OnClickListener { },
onLongClickListener: OnLongClickListener = OnLongClickListener { false },
scrollable: Boolean = false
context: Context,
lifecycleOwner: LifecycleOwner,
uri: Uri,
onSliceActionListener: OnSliceActionListener = OnSliceActionListener { _, _ -> },
onClickListener: OnClickListener = OnClickListener { },
onLongClickListener: OnLongClickListener = OnLongClickListener { false },
scrollable: Boolean = false
) {
setOnSliceActionListener(onSliceActionListener)
setOnClickListener(onClickListener)
setScrollable(scrollable)
isScrollable = scrollable
setOnLongClickListener(onLongClickListener)
if (uri.scheme == null) {
Log.w(TAG, "Scheme is null for URI $uri")
return
}
// If someone accidentally prepends the "slice-" prefix to their scheme, let's remove it.
val scheme =
if (uri.scheme.startsWith("slice-")) {
uri.scheme.replace("slice-", "")
}
else {
uri.scheme
}
if (uri.scheme.startsWith("slice-")) {
uri.scheme.replace("slice-", "")
} else {
uri.scheme
}
if (scheme == ContentResolver.SCHEME_CONTENT ||
scheme.equals("https", true) ||
scheme.equals("http", true)
scheme.equals("https", true) ||
scheme.equals("http", true)
) {
val intent = Intent(Intent.ACTION_VIEW, uri)
val sliceLiveData = SliceLiveData.fromIntent(context, intent)
sliceLiveData?.removeObservers(lifecycleOwner)
sliceLiveData.removeObservers(lifecycleOwner)
try {
sliceLiveData?.observe(lifecycleOwner, Observer { updatedSlice ->
sliceLiveData.observe(lifecycleOwner, Observer { updatedSlice ->
if (updatedSlice == null) return@Observer
slice = updatedSlice
val expiry = SliceMetadata.from(context, updatedSlice).expiry
if (expiry != SliceHints.INFINITY) {
// Shows the updated text after the TTL expires.
postDelayed(
{ slice = updatedSlice },
expiry - System.currentTimeMillis() + 15
{ slice = updatedSlice },
expiry - System.currentTimeMillis() + 15
)
}
Log.d(SliceViewerActivity.TAG, "Update Slice: $updatedSlice")
Log.d(TAG, "Update Slice: $updatedSlice")
})
} catch (e: Exception) {
Log.e(
SliceViewerActivity.TAG,
"Failed to find a valid ContentProvider for authority: $uri"
)
Log.e(TAG, "Failed to find a valid ContentProvider for authority: $uri")
}
} else {
Log.w(SliceViewerActivity.TAG, "Invalid uri, skipping slice: $uri")
Log.w(TAG, "Invalid uri, skipping slice: $uri")
}
}
9 changes: 4 additions & 5 deletions SliceViewerKotlin/build.gradle
@@ -1,19 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.71'
ext.kotlin_version = '1.3.70'
repositories {
jcenter()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
jcenter()
google()
jcenter()
}
}
4 changes: 2 additions & 2 deletions SliceViewerKotlin/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Tue Jun 12 10:02:08 PDT 2018
#Mon Mar 23 08:09:41 CET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip