diff --git a/build.gradle b/build.gradle index cbeb66b..7b30bba 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' - classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' + classpath 'com.android.tools.build:gradle:3.1.0-rc03' } } @@ -15,16 +15,30 @@ ext { nexusUsername = getEnvOrProperty('NEXUS_USERNAME') nexusPassword = getEnvOrProperty('NEXUS_PASSWORD') - compileSdkVersion = 25 - buildToolsVersion = '25.0.0' - targetSdkVersion = 25 + developers = [ + [ + id : 'laenger', + name : 'Christian Langer', + email: 'mail@laenger.biz' + ] + ] + scm = [ + connection : 'scm:git:git@github.com:laenger/ViewPagerBottomSheet.git', + developerConnection: 'scm:git:git@github.com:laenger/ViewPagerBottomSheet.git', + url : 'https://github.com/laenger/ViewPagerBottomSheet' + ] - supportVersion = '25.1.0' - butterknifeVersion = '8.4.0' + compileSdkVersion = 27 + buildToolsVersion = '27.0.3' + targetSdkVersion = 27 + + supportVersion = '27.1.0' + butterknifeVersion = '8.8.1' } allprojects { repositories { + google() jcenter() maven { url "https://raw.github.com/laenger/maven-releases/master/releases" } maven { url "https://raw.github.com/laenger/maven-releases/master/snapshots" } diff --git a/example/build.gradle b/example/build.gradle index abb7f3c..a8ff1f1 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -1,5 +1,4 @@ apply plugin: 'com.android.application' -apply plugin: 'com.neenbedankt.android-apt' android { compileSdkVersion rootProject.compileSdkVersion @@ -23,15 +22,16 @@ android { } } - lintOptions { - abortOnError false + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { - compile "com.android.support:design:${supportVersion}" - compile project(path: ':vpbs', configuration: 'debug') + implementation "com.android.support:design:${supportVersion}" + implementation project(':vpbs') - compile "com.jakewharton:butterknife:${butterknifeVersion}" - apt "com.jakewharton:butterknife-compiler:${butterknifeVersion}" + implementation "com.jakewharton:butterknife:${butterknifeVersion}" + annotationProcessor "com.jakewharton:butterknife-compiler:${butterknifeVersion}" } diff --git a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/DialogFragment.java b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/DialogFragment.java index 6e683f2..c47a293 100644 --- a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/DialogFragment.java +++ b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/DialogFragment.java @@ -1,7 +1,9 @@ package biz.laenger.android.vpbs.example.fragments; +import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; +import android.support.annotation.NonNull; import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; @@ -21,6 +23,7 @@ public class DialogFragment extends ViewPagerBottomSheetDialogFragment { @BindView(R.id.bottom_sheet_tabs) TabLayout bottomSheetTabLayout; @BindView(R.id.bottom_sheet_viewpager) ViewPager bottomSheetViewPager; + @SuppressLint("RestrictedApi") @Override public void setupDialog(Dialog dialog, int style) { super.setupDialog(dialog, style); @@ -44,7 +47,7 @@ static class SimplePagerAdapter extends android.support.v4.view.PagerAdapter { private final Context context; - public SimplePagerAdapter(Context context) { + SimplePagerAdapter(Context context) { this.context = context; } @@ -59,19 +62,20 @@ public int getCount() { } @Override - public boolean isViewFromObject(View view, Object object) { + public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return object == view; } + @NonNull @Override - public Object instantiateItem(ViewGroup container, int position) { + public Object instantiateItem(@NonNull ViewGroup container, int position) { final View view = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_nested_scroll, container, false); container.addView(view); return view; } @Override - public void destroyItem(ViewGroup container, int position, Object object) { + public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { container.removeView((View) object); } diff --git a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/NestedScrollFragment.java b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/NestedScrollFragment.java index 31cef65..54d2937 100644 --- a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/NestedScrollFragment.java +++ b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/NestedScrollFragment.java @@ -1,6 +1,7 @@ package biz.laenger.android.vpbs.example.fragments; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; @@ -12,7 +13,7 @@ public class NestedScrollFragment extends Fragment { @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_nested_scroll, container, false); } diff --git a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/RecyclerFragment.java b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/RecyclerFragment.java index f20a65e..9d0d66a 100644 --- a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/RecyclerFragment.java +++ b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/RecyclerFragment.java @@ -2,6 +2,7 @@ import android.content.Context; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; @@ -20,14 +21,14 @@ public class RecyclerFragment extends Fragment { @BindView(R.id.recycler_view) RecyclerView recyclerView; @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_recycler, container, false); ButterKnife.bind(this, view); return view; } @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, true)); @@ -41,13 +42,14 @@ private SimpleAdapter(Context context) { layoutInflater = LayoutInflater.from(context); } + @NonNull @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { return new ViewHolder((TextView) layoutInflater.inflate(R.layout.textview, parent, false)); } @Override - public void onBindViewHolder(ViewHolder holder, int position) { + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { holder.textView.setText(String.valueOf(position)); } diff --git a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/ViewPagerFragment.java b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/ViewPagerFragment.java index 6e50dc0..58aa86b 100644 --- a/example/src/main/java/biz/laenger/android/vpbs/example/fragments/ViewPagerFragment.java +++ b/example/src/main/java/biz/laenger/android/vpbs/example/fragments/ViewPagerFragment.java @@ -1,6 +1,7 @@ package biz.laenger.android.vpbs.example.fragments; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; @@ -22,14 +23,14 @@ public class ViewPagerFragment extends Fragment { @BindView(R.id.viewpager) ViewPager viewPager; @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_view_pager, container, false); ButterKnife.bind(this, view); return view; } @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); setupNestedViewPager(); } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dbdc05d..3f0f9be 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip diff --git a/vpbs/build.gradle b/vpbs/build.gradle index 067cf45..ffdd508 100644 --- a/vpbs/build.gradle +++ b/vpbs/build.gradle @@ -1,7 +1,9 @@ apply plugin: 'com.android.library' -description = 'Android BottomSheetBehavior with ViewPager support' group = 'biz.laenger.android' +archivesBaseName = 'vpbs' +ext.title = 'ViewPagerBottomSheetBehavior' +description = 'Android BottomSheetBehavior with ViewPager support' android { compileSdkVersion rootProject.compileSdkVersion @@ -10,7 +12,7 @@ android { publishNonDefault true defaultConfig { - minSdkVersion 9 + minSdkVersion 14 targetSdkVersion rootProject.targetSdkVersion versionName '0.0.4' } @@ -22,23 +24,38 @@ android { } } - libraryVariants.all { variant -> - variant.outputs.each { output -> - def outputFile = output.outputFile - if (outputFile != null && outputFile.name.endsWith('.aar')) { - def fileName = "${project.name}_${android.defaultConfig.versionName}_${buildVersionSuffix()}-${variant.buildType.name}.aar" - output.outputFile = new File(outputFile.parent, fileName) - } - } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation "com.android.support:design:${supportVersion}" +} + +android.libraryVariants.all { variant -> + renameLibraryVariantOutput(variant) + + def sourcesJarTaskName = "generate${variant.name.capitalize()}SourcesJar" + + task(sourcesJarTaskName, type: Jar) { + classifier = 'sources' + from variant.sourceSets*.java.srcDirs.flatten() + baseName = buildLibraryArchiveBaseName(variant) } +} - lintOptions { - abortOnError false +def renameLibraryVariantOutput(variant) { + variant.outputs.all { output -> + if (outputFileName.endsWith('.aar')) { + outputFileName = "${buildLibraryArchiveBaseName(variant)}.aar" + } } } -dependencies { - compile "com.android.support:design:${supportVersion}" +def buildLibraryArchiveBaseName(variant) { + return "${project.name}_${android.defaultConfig.versionName}_${buildVersionSuffix()}-${variant.baseName}" } def buildVersionSuffix() { @@ -48,4 +65,4 @@ def buildVersionSuffix() { return 'local' } -apply from: 'maven.gradle' +apply from: 'publish.gradle' diff --git a/vpbs/maven.gradle b/vpbs/maven.gradle deleted file mode 100644 index cbc1ec2..0000000 --- a/vpbs/maven.gradle +++ /dev/null @@ -1,27 +0,0 @@ -apply plugin: 'maven' - -android.libraryVariants.all { variant -> - task("upload${variant.name.capitalize()}Archives", type: Upload, dependsOn: "assemble${variant.name.capitalize()}") { - - def Configuration variantConfiguration = project.configurations.create("${variant.name}Archives") - variant.outputs.each { output -> - project.artifacts.add(variantConfiguration.name, file(output.outputFile)) - } - configuration = variantConfiguration - - repositories.mavenDeployer { - repository(url: nexusReleasesRepository) { authentication(userName: nexusUsername, password: nexusPassword) } - snapshotRepository(url: nexusSnapshotsRepository) { authentication(userName: nexusUsername, password: nexusPassword) } - - pom.groupId = project.group - pom.artifactId = project.name - pom.version = android.defaultConfig.versionName - pom.packaging = 'aar' - - pom.project { - name project.description - } - } - - } -} diff --git a/vpbs/publish.gradle b/vpbs/publish.gradle new file mode 100644 index 0000000..3de9dd0 --- /dev/null +++ b/vpbs/publish.gradle @@ -0,0 +1,73 @@ +apply plugin: 'maven-publish' + +publishing { + repositories { + maven { + name "nexus" + credentials { + username nexusUsername + password nexusPassword + } + url project.android.defaultConfig.versionName.endsWith('-SNAPSHOT') ? nexusSnapshotsRepository : nexusReleasesRepository + } + } + + publications { + android.libraryVariants.each { variant -> + if (variant.buildType.name == "release") { + "${variant.name}"(MavenPublication) { + groupId project.group + artifactId project.archivesBaseName + version project.android.defaultConfig.versionName + + artifact tasks["bundle${variant.name.capitalize()}"] + artifact tasks["generate${variant.name.capitalize()}SourcesJar"] + + pom.withXml { + def rootNode = asNode() + + rootNode.appendNode('name', project.title) + rootNode.appendNode('description', project.description) + rootNode.appendNode('url', project.scm.url) + + def developersNode = rootNode.appendNode('developers') + project.developers.each { + def developerNode = developersNode.appendNode('developer') + it.each { name, value -> developerNode.appendNode(name, value) } + } + + def scmNode = rootNode.appendNode('scm') + project.scm.each { name, value -> scmNode.appendNode(name, value) } + + def dependenciesNode = rootNode.appendNode('dependencies') + variant.compileConfiguration.allDependencies.each { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + + if (!it.excludeRules.empty) { + def exclusionsNode = dependencyNode.appendNode('exclusions') + it.excludeRules.each { rule -> + def exclusionNode = exclusionsNode.appendNode('exclusion') + exclusionNode.appendNode('groupId', rule.group) + exclusionNode.appendNode('artifactId', rule.module) + } + } + } + } + } + } + } + } +} + +android.libraryVariants.all { variant -> + if (variant.buildType.name == 'release') { + model { + tasks."generatePomFileFor${variant.name.capitalize()}Publication" { + destination = new File(destination.parent, "${buildLibraryArchiveBaseName(variant)}-pom.xml") + } + } + } +} diff --git a/vpbs/src/main/java/biz/laenger/android/vpbs/BottomSheetUtils.java b/vpbs/src/main/java/biz/laenger/android/vpbs/BottomSheetUtils.java index d982095..9b1966b 100644 --- a/vpbs/src/main/java/biz/laenger/android/vpbs/BottomSheetUtils.java +++ b/vpbs/src/main/java/biz/laenger/android/vpbs/BottomSheetUtils.java @@ -26,12 +26,7 @@ private BottomSheetViewPagerListener(ViewPager viewPager, View bottomSheetParent @Override public void onPageSelected(int position) { - viewPager.post(new Runnable() { - @Override - public void run() { - behavior.invalidateScrollingChild(); - } - }); + viewPager.post(behavior::invalidateScrollingChild); } }