Skip to content

Commit

Permalink
Merge pull request #39 from lovoo/develop
Browse files Browse the repository at this point in the history
dev to master
  • Loading branch information
olliwear authored Aug 18, 2022
2 parents c2ffc89 + 9b0d31c commit eb861da
Show file tree
Hide file tree
Showing 25 changed files with 338 additions and 278 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ android {
}
}

buildFeatures {
viewBinding true
}

lintOptions {
abortOnError false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object AppStart {
val context = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext
InstrumentationRegistry.getInstrumentation().uiAutomation.grantRuntimePermission(context.packageName, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
InstrumentationRegistry.getInstrumentation().uiAutomation.grantRuntimePermission(context.packageName, android.Manifest.permission.READ_EXTERNAL_STORAGE)
InstrumentationRegistry.getInstrumentation().uiAutomation.grantRuntimePermission(context.packageName, android.Manifest.permission.READ_MEDIA_IMAGES)

// permissions for google camera
val cameraPackage = getCameraPackageName(context)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<activity
android:name=".ExampleActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
19 changes: 11 additions & 8 deletions app/src/main/kotlin/com/lovoo/android/pickpic/ExampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.lovoo.android.pickapp.model.PickPicConfig
import com.lovoo.android.pickapp.view.PickPicActivity
import kotlinx.android.synthetic.main.activity_example.*
import com.lovoo.android.pickpic.databinding.ActivityExampleBinding

/**
* Demo Activity to show how to use PickPic
*/
class ExampleActivity : AppCompatActivity() {

private lateinit var binding: ActivityExampleBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_example)
binding = ActivityExampleBinding.inflate(layoutInflater)
setContentView(binding.root)

button.setOnClickListener { view ->
binding.button.setOnClickListener { view ->
// create an Intent, apply the configuration and start for result
Intent(view.context, PickPicActivity::class.java).let {
val config = PickPicConfig(
Expand All @@ -51,10 +54,10 @@ class ExampleActivity : AppCompatActivity() {
}
}

result_list.let {
it.layoutManager = LinearLayoutManager(it.context)
it.addItemDecoration(ExampleDecorator())
it.adapter = ExampleAdapter(it.context)
binding.resultList.apply {
layoutManager = LinearLayoutManager(this.context)
addItemDecoration(ExampleDecorator())
adapter = ExampleAdapter(this.context)
}
}

Expand All @@ -70,7 +73,7 @@ class ExampleActivity : AppCompatActivity() {
} else {
supportActionBar?.hide()
}
(result_list?.adapter as? ExampleAdapter)?.list = result
(binding.resultList.adapter as? ExampleAdapter)?.list = result
}

companion object {
Expand Down
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.10'
ext.multidex_version = "2.0.1"
Expand All @@ -15,7 +14,7 @@ buildscript {
ext.exif_version = "1.2.0"
ext.media_version = "1.1.0"
ext.arch_version = "2.2.0"
ext.arch_worker_version = "2.3.4"
ext.arch_worker_version = "2.7.1"
ext.lifecycle_version = "2.2.0"

ext.rx_java_version = '2.2.15'
Expand All @@ -24,19 +23,19 @@ buildscript {
ext.gson_version = '2.8.6'
ext.facebook_version = '5.11.2'

ext.espresso_version = "3.2.0"
ext.espresso_version = "3.4.0"
ext.uiautomator_version = "2.2.0"
ext.orchestrator_version = "1.2.0"
ext.androidX_test_version = "1.2.0"

ext.target_version = 30
ext.target_version = 33
ext.min_version = 18

def version = System.getenv("VERSION")
def code = System.getenv("VERSION_CODE")
def artifactory_user = project.hasProperty('lovoo.repo.username') ? project.property('lovoo.repo.username') : System.getenv("ARTIFACTORY_USER")
def artifactory_pwd = project.hasProperty('lovoo.repo.password') ? project.property('lovoo.repo.password') : System.getenv("ARTIFACTORY_PWD")
ext.version_name = version == null ? "1.3.0" : version
ext.version_name = version == null ? "1.7.0-SNAPSHOT" : version
ext.version_code = code == null ? 10 : code.toInteger()
ext.repository_name = version_name.endsWith("-SNAPSHOT") ? "libs-snapshot" : "libs-release"
ext.artifactory_user = artifactory_user
Expand All @@ -54,7 +53,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:0.9.18'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.27.1'
Expand All @@ -65,7 +64,6 @@ buildscript {
}
}


allprojects {
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
4 changes: 4 additions & 0 deletions pickapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ android {
}
}

buildFeatures {
viewBinding true
}

lintOptions {
abortOnError false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.google.android.material.appbar.CollapsingToolbarLayout
import com.lovoo.android.pickapp.R
import com.lovoo.android.pickapp.adapter.PickPicAdapter
import com.lovoo.android.pickapp.databinding.PickpicActivityBinding
import com.lovoo.android.pickapp.factory.GlideEngine
import com.lovoo.android.pickapp.factory.PickDependencies
import com.lovoo.android.pickapp.model.PickPicConfig
Expand All @@ -47,8 +47,6 @@ import com.lovoo.android.pickcore.model.Gallery
import com.lovoo.android.pickcore.model.convertToUi
import com.lovoo.android.pickcore.permission.Permission
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.pickpic_activity.*
import kotlinx.android.synthetic.main.pickpic_layout_toolbar.*

/**
* Ready to use PickPic implementation. Configurable with [PickPicConfig].
Expand All @@ -57,6 +55,7 @@ class PickPicActivity : AppCompatActivity(), SelectionHolder, CameraEngine, Capt

private lateinit var config: PickPicConfig
private lateinit var picker: Picker
private lateinit var binding: PickpicActivityBinding
private val subscriptions = CompositeDisposable()
private val dependencies = PickDependencies()
private var externalToggleListener: MutableMap<Any, ToggleCallback> = mutableMapOf()
Expand Down Expand Up @@ -94,8 +93,8 @@ class PickPicActivity : AppCompatActivity(), SelectionHolder, CameraEngine, Capt
if (config.style != 0) {
theme.applyStyle(config.style, true)
}

setContentView(R.layout.pickpic_activity)
binding = PickpicActivityBinding.inflate(layoutInflater)
setContentView(binding.root)

picker = Picker(Picker.PickConfig(config.minCount, config.maxCount))

Expand All @@ -107,7 +106,7 @@ class PickPicActivity : AppCompatActivity(), SelectionHolder, CameraEngine, Capt
initSelectionBar()
initPreview()
} else {
selection_bar.visibility = View.GONE
binding.selectionBar.selectionBar.visibility = View.GONE
}

if (!config.isPreviewEnabled()) {
Expand Down Expand Up @@ -244,74 +243,78 @@ class PickPicActivity : AppCompatActivity(), SelectionHolder, CameraEngine, Capt
}

private fun initToolbar() {
toolbar.let {
it.title = config.title
it.inflateMenu(R.menu.menu_pickpic)
it.setOnMenuItemClickListener {
when (it.itemId) {
R.id.pickpic_menu_faq -> onFaqClick()
R.id.pickpic_menu_remove -> {
selectedUri?.let {
return@setOnMenuItemClickListener picker.remove(it)
} ?: return@setOnMenuItemClickListener false
binding.toolbarInclude.apply {
toolbar.apply {
title = config.title
inflateMenu(R.menu.menu_pickpic)
setOnMenuItemClickListener {
when (it.itemId) {
R.id.pickpic_menu_faq -> onFaqClick()
R.id.pickpic_menu_remove -> {
selectedUri?.let { uri ->
return@setOnMenuItemClickListener picker.remove(uri)
} ?: return@setOnMenuItemClickListener false
}
else -> false
}
else -> false
}
setNavigationOnClickListener { onBackPressed() }
navigationIcon = navigationIcon?.mutate()?.apply {
val color = ContextCompat.getColor(context, R.color.pickpic_text_actionbar)
colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)
}
}
it.setNavigationOnClickListener { onBackPressed() }
it.navigationIcon = it.navigationIcon?.mutate()?.apply {
val color = ContextCompat.getColor(it.context, R.color.pickpic_text_actionbar)
colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)
}
}
toolbar_text.let {
if (config.header.isNullOrEmpty()) {
it.visibility = View.GONE
} else {
it.text = config.header
it.visibility = View.VISIBLE
toolbarText.apply {
if (config.header.isNullOrEmpty()) {
visibility = View.GONE
} else {
text = config.header
visibility = View.VISIBLE
}
}
}
}

private fun updateToolbar() {
toolbar?.menu?.let {
it.findItem(R.id.pickpic_menu_faq)?.isVisible = selectedUri == null && !config.faqUrl.isNullOrEmpty()
it.findItem(R.id.pickpic_menu_remove)?.isVisible = selectedUri != null
}
binding.toolbarInclude.apply {
toolbar.menu?.let {
it.findItem(R.id.pickpic_menu_faq)?.isVisible = selectedUri == null && !config.faqUrl.isNullOrEmpty()
it.findItem(R.id.pickpic_menu_remove)?.isVisible = selectedUri != null
}

// hide tab layout when preview picture is selected or adapter has only one item
tab_layout?.visibility = if (selectedUri == null && fragment_pager.adapter?.count ?: 0 > 1) View.VISIBLE else View.GONE
// hide tab layout when preview picture is selected or adapter has only one item
tabLayout.visibility = if (selectedUri == null && binding.fragmentPager.adapter?.count ?: 0 > 1) View.VISIBLE else View.GONE
}
}

private fun initPickerFragments() {
fragment_pager.adapter = PickPicAdapter(this, supportFragmentManager, dependencies)

// hide tab layout when adapter has only one item
if (fragment_pager.adapter?.count ?: 0 <= 1) {
tab_layout.visibility = View.GONE

val paddingBottom = resources.getDimensionPixelOffset(R.dimen.pickpic_actionbar_headline_margin)
toolbar_text.setPadding(
toolbar_text.paddingStart,
toolbar_text.paddingTop,
toolbar_text.paddingEnd,
paddingBottom
)

val mode = CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PIN
(toolbar.layoutParams as CollapsingToolbarLayout.LayoutParams).collapseMode = mode
} else {
tab_layout.setupWithViewPager(fragment_pager)
binding.apply {
fragmentPager.adapter = PickPicAdapter(root.context, supportFragmentManager, dependencies)
toolbarInclude.apply {
if (fragmentPager.adapter?.count ?: 0 <= 1) {
tabLayout.visibility = View.GONE
toolbarText.apply {
setPadding(
this.paddingStart,
this.paddingTop,
this.paddingEnd,
resources.getDimensionPixelOffset(R.dimen.pickpic_actionbar_headline_margin)
)
}
(toolbar.layoutParams as CollapsingToolbarLayout.LayoutParams).collapseMode =
CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PIN
} else {
tabLayout.setupWithViewPager(binding.fragmentPager)
}
}
}
}

private fun initSelectionBar() {
val selectionView = findViewById<ViewGroup>(R.id.selection_bar)
selectionbar = Selectionbar(
picker,
selectionView,
arrayOf(fragment_pager, preview_pager)
binding.selectionBar,
arrayOf(binding.fragmentPager, binding.previewPager)
).apply {

setButtonText(this@PickPicActivity.config.sendText)
Expand All @@ -321,7 +324,7 @@ class PickPicActivity : AppCompatActivity(), SelectionHolder, CameraEngine, Capt
}

private fun initPreview() {
preview = Preview(preview_pager, supportFragmentManager, picker)
preview = Preview(binding.previewPager, supportFragmentManager, picker)
}

private fun finishSelection() {
Expand Down
Loading

0 comments on commit eb861da

Please sign in to comment.