diff --git a/app/build.gradle b/app/build.gradle index 8bc9144..f03f785 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,12 +12,12 @@ android { keyPassword '123456' } } - compileSdkVersion 29 - buildToolsVersion "29.0.0" + compileSdkVersion 30 + buildToolsVersion "30.0.1" defaultConfig { applicationId "com.opensooq.supernova.gligarexample" minSdkVersion 17 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -33,8 +33,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.core:core-ktx:1.1.0' + implementation "androidx.activity:activity-ktx:1.2.0-beta01" + implementation 'com.google.android.material:material:1.2.1' + implementation "androidx.fragment:fragment-ktx:1.3.0-beta01" + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation project(':gligar') + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation project(":gligar") } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6fe7740..c54d45a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,14 +9,20 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - - + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/opensooq/supernova/gligarexample/ActivityResultLauncher.kt b/app/src/main/java/com/opensooq/supernova/gligarexample/ActivityResultLauncher.kt new file mode 100644 index 0000000..3044ff9 --- /dev/null +++ b/app/src/main/java/com/opensooq/supernova/gligarexample/ActivityResultLauncher.kt @@ -0,0 +1,34 @@ +package com.opensooq.supernova.gligarexample + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.opensooq.supernova.gligar.GligarPicker +import com.opensooq.supernova.gligar.ui.GligarScreenResult +import kotlinx.android.synthetic.main.activity_main.* + +class ActivityResultLauncher : AppCompatActivity() { + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val startForResult = registerForActivityResult(object : GligarScreenResult() { + override fun getGligarIntentLauncher(): Intent { + return GligarPicker() + .singleSelection(true) + .disableCamera(false).cameraDirect(false).requestCode(PICKER_REQUEST_CODE) + .withActivity(this@ActivityResultLauncher).show() + } + }) { + if (!it.isNullOrEmpty()) { + imagesCount.text = "Number of selected Images: ${it.size}" + } + } + + startForResult.launch(0) + } + + +} diff --git a/app/src/main/java/com/opensooq/supernova/gligarexample/ActivityStarterLauncherV2.kt b/app/src/main/java/com/opensooq/supernova/gligarexample/ActivityStarterLauncherV2.kt new file mode 100644 index 0000000..5717dd2 --- /dev/null +++ b/app/src/main/java/com/opensooq/supernova/gligarexample/ActivityStarterLauncherV2.kt @@ -0,0 +1,42 @@ +package com.opensooq.supernova.gligarexample + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import com.opensooq.supernova.gligar.ui.GligarResultBuilder +import kotlinx.android.synthetic.main.activity_main.* + +class ActivityStarterLauncherV2 : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val starter = registerForActivityResult(object : GligarResultBuilder(this@ActivityStarterLauncherV2) { + override fun build(activity: FragmentActivity?, fragment: Fragment?, input: List?): Intent { + this addLimitImages 20 + this addRequestCode REQUEST_CODE + this disableCamera true + this isCustomExtSuported arrayListOf("png", "jpg", "jpeg") + this cameraDirect false + this isSingleSelection false + this isPreItemsSelected input + return getFinalIntent() + } + }) { + if (!it.isNullOrEmpty()) { + imagesCount.text = "Number of selected Images: ${it.size}" + } + } + + starter.launch(arrayListOf( + "/storage/emulated/0/DCIM/Screenshots/Screenshot_20201129-101300_Facebook.jpg", + "/storage/emulated/0/DCIM/Screenshots/Screenshot_20201129-093307_Chrome.jpg", + "/storage/emulated/0/DCIM/Screenshots/Screenshot_20201129-071900_Facebook.jpg", + "/storage/emulated/0/DCIM/Screenshots/Screenshot_20201129-071500_Facebook.jpg" + )) + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/opensooq/supernova/gligarexample/CustomToolbarScreen.kt b/app/src/main/java/com/opensooq/supernova/gligarexample/CustomToolbarScreen.kt new file mode 100644 index 0000000..cc3c73f --- /dev/null +++ b/app/src/main/java/com/opensooq/supernova/gligarexample/CustomToolbarScreen.kt @@ -0,0 +1,49 @@ +package com.opensooq.supernova.gligarexample + +import android.annotation.SuppressLint +import android.os.Bundle +import android.view.MenuItem +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import com.opensooq.supernova.gligar.GligarPicker +import com.opensooq.supernova.gligar.ui.GligarPickerFragment +import com.opensooq.supernova.gligar.ui.GligarPickerListener +import kotlinx.android.synthetic.main.activity_main_custom.* + +class CustomToolbarScreen : AppCompatActivity(), GligarPickerListener { + + @SuppressLint("RestrictedApi") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main_custom) + custom_toolbar?.let { + setSupportActionBar(it) + supportActionBar?.setDisplayShowTitleEnabled(true) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDefaultDisplayHomeAsUpEnabled(true) + } + + supportFragmentManager.beginTransaction() + .replace(R.id.fragment_container, GligarPickerFragment.getInstance(getGligarPicker())) + .commitNowAllowingStateLoss() + } + + private fun getGligarPicker(): GligarPicker { + return GligarPicker() + .cameraDirect(false) + .disableCamera(true) + .limit(20) + .setCustomBackgroundColor("#FFA07A") + .supportExtensions(arrayListOf("png", "jpg", "jpeg")) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + onBackPressed() + return super.onOptionsItemSelected(item) + } + + override fun onImagesSelected(items: Array) { + Toast.makeText(this, "Selected Images : ${items.size}", Toast.LENGTH_SHORT).show() + } + +} diff --git a/app/src/main/java/com/opensooq/supernova/gligarexample/MainScreenLauncher.kt b/app/src/main/java/com/opensooq/supernova/gligarexample/MainScreenLauncher.kt new file mode 100644 index 0000000..7a1bd71 --- /dev/null +++ b/app/src/main/java/com/opensooq/supernova/gligarexample/MainScreenLauncher.kt @@ -0,0 +1,34 @@ +package com.opensooq.supernova.gligarexample + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import kotlinx.android.synthetic.main.activity_main_launcher.* + +class MainScreenLauncher : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main_launcher) + + normal_launcher_button?.setOnClickListener { + startActivity(Intent(this@MainScreenLauncher, NormalActivityStarter::class.java)) + } + + start_launcher_button?.setOnClickListener { + startActivity(Intent(this@MainScreenLauncher, ActivityResultLauncher::class.java)) + } + + supported_files_button?.setOnClickListener { + startActivity(Intent(this@MainScreenLauncher, SupportedFilesLauncher::class.java)) + } + + pre_selected_files_button?.setOnClickListener { + startActivity(Intent(this@MainScreenLauncher, ActivityStarterLauncherV2::class.java)) + } + + custom_screen?.setOnClickListener { + startActivity(Intent(this@MainScreenLauncher, CustomToolbarScreen::class.java)) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/opensooq/supernova/gligarexample/MainActivity.kt b/app/src/main/java/com/opensooq/supernova/gligarexample/NormalActivityStarter.kt similarity index 95% rename from app/src/main/java/com/opensooq/supernova/gligarexample/MainActivity.kt rename to app/src/main/java/com/opensooq/supernova/gligarexample/NormalActivityStarter.kt index 04d4233..ee0bfbe 100644 --- a/app/src/main/java/com/opensooq/supernova/gligarexample/MainActivity.kt +++ b/app/src/main/java/com/opensooq/supernova/gligarexample/NormalActivityStarter.kt @@ -7,7 +7,7 @@ import androidx.appcompat.app.AppCompatActivity import com.opensooq.supernova.gligar.GligarPicker import kotlinx.android.synthetic.main.activity_main.* -class MainActivity : AppCompatActivity() { +class NormalActivityStarter : AppCompatActivity() { val PICKER_REQUEST_CODE = 30 diff --git a/app/src/main/java/com/opensooq/supernova/gligarexample/SupportedFilesLauncher.kt b/app/src/main/java/com/opensooq/supernova/gligarexample/SupportedFilesLauncher.kt new file mode 100644 index 0000000..f298314 --- /dev/null +++ b/app/src/main/java/com/opensooq/supernova/gligarexample/SupportedFilesLauncher.kt @@ -0,0 +1,32 @@ +package com.opensooq.supernova.gligarexample + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.opensooq.supernova.gligar.GligarPicker +import com.opensooq.supernova.gligar.ui.GligarScreenResult +import kotlinx.android.synthetic.main.activity_main.* + +class SupportedFilesLauncher : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val startForResult = registerForActivityResult(object : GligarScreenResult() { + override fun getGligarIntentLauncher(): Intent { + return GligarPicker() + .supportExtensions(arrayListOf("png")) + .singleSelection(true) + .disableCamera(false).cameraDirect(false).requestCode(PICKER_REQUEST_CODE) + .withActivity(this@SupportedFilesLauncher).show() + } + }) { + if (!it.isNullOrEmpty()) { + imagesCount.text = "Number of selected Images: ${it.size}" + } + } + + startForResult.launch(0) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 68363d7..da97492 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".MainActivity"> + tools:context=".ActivityResultLauncher"> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main_launcher.xml b/app/src/main/res/layout/activity_main_launcher.xml new file mode 100644 index 0000000..3fb2b45 --- /dev/null +++ b/app/src/main/res/layout/activity_main_launcher.xml @@ -0,0 +1,58 @@ + + + + + +