Skip to content

Commit 9378c7d

Browse files
Merge pull request #96 from Omega-R/develop
Referrer, multiple images issue
2 parents 87d7140 + 16e0a8a commit 9378c7d

9 files changed

Lines changed: 59 additions & 39 deletions

File tree

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.2.41'
5-
ext.supportVersion = '27.1.1'
6-
ext.compileSdkVersion = 27
7-
ext.targetSdkVersion = 27
4+
5+
ext.kotlin_version = '1.3.11'
6+
ext.supportVersion = '28.0.0'
7+
ext.sdkVersion = 28
88
ext.javapoet = '1.9.0'
99

1010
repositories {
1111
google()
1212
jcenter()
1313
}
1414
dependencies {
15-
classpath 'com.android.tools.build:gradle:3.1.2'
15+
classpath 'com.android.tools.build:gradle:3.2.1'
1616
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17-
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
17+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1818

1919
// NOTE: Do not place your application dependencies here; they belong
2020
// in the individual module build.gradle files

core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ group = 'com.github.Omega-R'
77
def suffixAuthority = 'omegashare'
88

99
android {
10-
compileSdkVersion rootProject.ext.compileSdkVersion
10+
compileSdkVersion rootProject.ext.sdkVersion
1111

1212
defaultConfig {
1313
minSdkVersion 16
14-
targetSdkVersion rootProject.ext.targetSdkVersion
14+
targetSdkVersion rootProject.ext.sdkVersion
1515
versionCode 1
1616
versionName "1.0"
1717

core/src/main/java/com/omega_r/libs/omegaintentbuilder/builders/BaseUriBuilder.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ abstract class BaseUriBuilder(private val context: Context): BaseActivityBuilder
2323

2424
private val uriSet: MutableSet<Uri> = mutableSetOf()
2525
private val downloadBuilder = DownloadBuilder(context, this)
26+
private var bitmapIndex = 0
2627
internal var localFilesDir: File
2728

2829
companion object {
2930
private const val FILE_DIR = "intent_files" // this value from xml/file_paths.xml
30-
private const val DEFAULT_IMAGE_FILE_NAME = "omegaOutput.jpg"
31+
private const val DEFAULT_IMAGE_FILE_NAME = "File"
32+
private const val DEFAULT_IMAGE_FILE_TYPE = ".jpg";
3133
}
3234

3335
init {
@@ -134,18 +136,21 @@ abstract class BaseUriBuilder(private val context: Context): BaseActivityBuilder
134136
}
135137

136138
/**
137-
* @param bitmap Bitmap
139+
* @param bitmaps Bitmap
138140
* @return BaseUriBuilder for method chaining
139141
*/
140-
fun bitmap(bitmap: Bitmap): BaseUriBuilder {
141-
uriSet.add(toUri(bitmap))
142+
fun bitmap(vararg bitmaps: Bitmap): BaseUriBuilder {
143+
bitmaps.forEach { bitmap ->
144+
uriSet.add(bitmap.toUri(bitmapIndex))
145+
bitmapIndex++
146+
}
142147
return this
143148
}
144149

145-
private fun toUri(bitmap: Bitmap): Uri {
146-
val file = File(localFilesDir, DEFAULT_IMAGE_FILE_NAME)
150+
private fun Bitmap.toUri(fileIndex: Int): Uri {
151+
val file = File(localFilesDir, DEFAULT_IMAGE_FILE_NAME + fileIndex + DEFAULT_IMAGE_FILE_TYPE)
147152
val fileOutputStream = FileOutputStream(file)
148-
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)
153+
this.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)
149154
fileOutputStream.close()
150155

151156
return FileProvider.getLocalFileUri(context, file)

core/src/main/java/com/omega_r/libs/omegaintentbuilder/builders/PlayStoreBuilder.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.support.annotation.StringRes
88
class PlayStoreBuilder(private val context: Context): BaseActivityBuilder(context) {
99

1010
private var packageName: String? = null
11+
private var referrer: String? = null
1112

1213
fun packageName(packageName: String): PlayStoreBuilder {
1314
this.packageName = packageName
@@ -19,12 +20,27 @@ class PlayStoreBuilder(private val context: Context): BaseActivityBuilder(contex
1920
return this
2021
}
2122

23+
fun referrer(referrer: String): PlayStoreBuilder {
24+
this.referrer = referrer
25+
return this
26+
}
27+
28+
fun referrer(@StringRes referrerRes: Int): PlayStoreBuilder {
29+
this.referrer = context.getString(referrerRes)
30+
return this
31+
}
32+
2233
override fun createIntent(): Intent {
2334
if (packageName.isNullOrBlank()) {
2435
packageName = context.packageName
2536
}
2637

27-
return Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName))
38+
var referrerAppendix = ""
39+
if (!referrer.isNullOrBlank()) {
40+
referrerAppendix = "&referrer=$referrer"
41+
}
42+
43+
return Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageName$referrerAppendix"))
2844
}
2945

3046
}

core/src/main/java/com/omega_r/libs/omegaintentbuilder/builders/share/BaseShareBuilder.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ package com.omega_r.libs.omegaintentbuilder.builders.share
1212

1313
import android.content.Context
1414
import android.content.Intent
15+
import android.net.Uri
1516
import android.os.Build
1617
import android.support.annotation.StringRes
1718
import android.text.Html
1819
import com.omega_r.libs.omegaintentbuilder.builders.BaseUriBuilder
20+
import com.omega_r.libs.omegaintentbuilder.types.MimeTypes
1921
import java.util.*
22+
import kotlin.collections.ArrayList
2023

2124
@Suppress("UNCHECKED_CAST")
2225
open class BaseShareBuilder<T>(private val context: Context): BaseUriBuilder(context) {
@@ -165,13 +168,11 @@ open class BaseShareBuilder<T>(private val context: Context): BaseUriBuilder(con
165168
intent.action = Intent.ACTION_SEND
166169
val uriSet = getUriSet()
167170

168-
if (uriSet.size == 1) {
169-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
170-
intent.putExtra(Intent.EXTRA_STREAM, uriSet.elementAt(0))
171-
} else if (uriSet.size > 1) {
171+
if (uriSet.isNotEmpty()) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
172+
if (uriSet.size == 1) intent.putExtra(Intent.EXTRA_STREAM, uriSet.first())
173+
if (uriSet.size > 1) {
172174
intent.action = Intent.ACTION_SEND_MULTIPLE
173-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
174-
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, convertSetToArrayList(uriSet))
175+
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriSet.toArrayList())
175176
}
176177
if (toAddressesSet.isNotEmpty()) {
177178
intent.putExtra(Intent.EXTRA_EMAIL, toAddressesSet.toTypedArray())
@@ -186,10 +187,6 @@ open class BaseShareBuilder<T>(private val context: Context): BaseUriBuilder(con
186187
return intent
187188
}
188189

189-
private fun <T> convertSetToArrayList(sets: MutableSet<T>): ArrayList<T> {
190-
val list: ArrayList<T> = arrayListOf()
191-
sets.forEach { it -> list.add(it) }
192-
return list
193-
}
190+
private fun Set<Uri>.toArrayList(): ArrayList<Uri> = ArrayList(this.toList())
194191

195192
}

core/src/main/java/com/omega_r/libs/omegaintentbuilder/builders/share/ShareIntentBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ class ShareIntentBuilder internal constructor(context: Context) : BaseShareBuild
120120
intent.putExtra(Intent.EXTRA_BCC, bccAddressesSet.toTypedArray())
121121
}
122122
if (!mimeType.isNullOrEmpty()) {
123-
intent.setType(mimeType)
123+
intent.type = mimeType
124124
} else {
125-
intent.setType(MimeTypes.TEXT_PLAIN)
125+
intent.type = if (getUriSet().isEmpty()) MimeTypes.TEXT_PLAIN else MimeTypes.FILE
126126
}
127127

128128
return intent

core/src/main/java/com/omega_r/libs/omegaintentbuilder/downloader/DownloadAsyncTask.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import android.support.annotation.NonNull
77
import android.util.Log
88
import com.omega_r.libs.omegaintentbuilder.builders.BaseUriBuilder
99
import com.omega_r.libs.omegaintentbuilder.models.FileInfo
10-
import com.omega_r.libs.omegaintentbuilder.providers.FileProvider.*
10+
import com.omega_r.libs.omegaintentbuilder.providers.FileProvider.getFileName
11+
import com.omega_r.libs.omegaintentbuilder.providers.FileProvider.getLocalFileUri
1112
import java.io.File
1213
import java.io.FileOutputStream
1314
import java.io.IOException
1415
import java.io.InputStream
1516
import java.net.HttpURLConnection
1617
import java.net.URL
17-
import java.util.*
1818

19-
internal class DownloadAsyncTask<T>(private val context: Context,
20-
private val intentBuilder: T,
21-
private val localDirFile: File,
22-
private val downloadCallback: DownloadCallback) : AsyncTask<Set<FileInfo>, Void, List<Uri>>() where T : BaseUriBuilder {
19+
internal class DownloadAsyncTask<T>(
20+
private val context: Context,
21+
private val intentBuilder: T,
22+
private val localDirFile: File,
23+
private val downloadCallback: DownloadCallback
24+
) : AsyncTask<Set<FileInfo>, Void, List<Uri>>() where T : BaseUriBuilder {
2325

2426
companion object {
2527
private val TAG = DownloadAsyncTask::class.java.simpleName

examples/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ kapt {
77
}
88

99
android {
10-
compileSdkVersion rootProject.ext.compileSdkVersion
10+
compileSdkVersion rootProject.ext.sdkVersion
1111
defaultConfig {
1212
applicationId "com.omega_r.omegaintentbuilder"
1313
minSdkVersion 16
14-
targetSdkVersion rootProject.ext.targetSdkVersion
14+
targetSdkVersion rootProject.ext.sdkVersion
1515
versionCode 1
1616
versionName "1.0"
1717
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -36,7 +36,7 @@ dependencies {
3636
implementation "com.android.support:appcompat-v7:$supportVersion"
3737
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3838

39-
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
39+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
4040
implementation "com.android.support:support-v4:$supportVersion"
4141
implementation "com.android.support:design:$supportVersion"
4242

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 commit comments

Comments
 (0)