From 8844116ebfa5dcab29ffacc66ffab4d20447a104 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 4 Jul 2017 17:04:05 -0700 Subject: Set up base --- .../main/res/transition/kau_enter_slide_bottom.xml | 38 ++++++++++++ docs/Changelog.md | 4 +- .../kau/imagepicker/ImagePickerActivityBase.kt | 72 +++++++++++++++++----- .../main/res/layout/kau_activity_image_picker.xml | 29 ++++++--- .../src/main/res/layout/kau_iitem_image.xml | 16 +++-- imagepicker/src/main/res/values/styles.xml | 8 +++ sample/src/main/AndroidManifest.xml | 3 + .../kotlin/ca/allanwang/kau/sample/AnimActivity.kt | 14 +---- .../ca/allanwang/kau/sample/ImageActivity.kt | 8 +++ .../kotlin/ca/allanwang/kau/sample/MainActivity.kt | 2 +- sample/src/main/res/menu/menu_main.xml | 2 +- sample/src/main/res/xml/changelog.xml | 4 +- 12 files changed, 149 insertions(+), 51 deletions(-) create mode 100644 core/src/main/res/transition/kau_enter_slide_bottom.xml create mode 100644 imagepicker/src/main/res/values/styles.xml create mode 100644 sample/src/main/kotlin/ca/allanwang/kau/sample/ImageActivity.kt diff --git a/core/src/main/res/transition/kau_enter_slide_bottom.xml b/core/src/main/res/transition/kau_enter_slide_bottom.xml new file mode 100644 index 0000000..7eb2097 --- /dev/null +++ b/core/src/main/res/transition/kau_enter_slide_bottom.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/docs/Changelog.md b/docs/Changelog.md index 08b6529..9161280 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -8,8 +8,8 @@ ## v1.4 * Added about activities -* Added themed fast item adapter -* Added chained adapter +* Added themed fast item imageAdapter +* Added chained imageAdapter * Added item animators * Ported some views over from Plaid * Add string arg option for sendEmail diff --git a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt index 216939f..d5562aa 100644 --- a/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt +++ b/imagepicker/src/main/kotlin/ca/allanwang/kau/imagepicker/ImagePickerActivityBase.kt @@ -1,39 +1,77 @@ package ca.allanwang.kau.imagepicker -import android.graphics.drawable.Drawable +import android.database.Cursor import android.os.Bundle +import android.provider.MediaStore +import android.support.v4.app.LoaderManager +import android.support.v4.content.CursorLoader +import android.support.v4.content.Loader import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView import android.support.v7.widget.Toolbar import android.transition.TransitionInflater -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import ca.allanwang.kau.R -import ca.allanwang.kau.adapters.FastItemThemedAdapter -import ca.allanwang.kau.adapters.ThemableIItemColors -import ca.allanwang.kau.adapters.ThemableIItemColorsDelegate -import ca.allanwang.kau.iitems.LibraryIItem +import ca.allanwang.kau.logging.KL import ca.allanwang.kau.utils.bindView -import ca.allanwang.kau.utils.string import ca.allanwang.kau.widgets.ElasticDragDismissFrameLayout -import com.mikepenz.aboutlibraries.Libs -import com.mikepenz.aboutlibraries.entity.Library import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter -import java.security.InvalidParameterException + /** * Created by Allan Wang on 2017-07-04. * */ -abstract class ImagePickerActivityBase : AppCompatActivity() { +abstract class ImagePickerActivityBase : AppCompatActivity(), LoaderManager.LoaderCallbacks { - val toolbar:Toolbar by bindView(R.id.kau_toolbar) - val recycler:RecyclerView by bindView(R.id.kau_recycler) - val adapter = FastItemAdapter() + val toolbar: Toolbar by bindView(R.id.kau_toolbar) + val draggableFrame: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable) + val recycler: RecyclerView by bindView(R.id.kau_recycler) + val imageAdapter = FastItemAdapter() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.kau_activity_image_picker) + with(recycler) { + layoutManager = GridLayoutManager(this@ImagePickerActivityBase, 3) + adapter = this@ImagePickerActivityBase.imageAdapter + } + imageAdapter.add(arrayOf("a", "b", "c").map { ImageItem(it) }) + draggableFrame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) { + override fun onDragDismissed() { + if (draggableFrame.translationY < 0) { + window.returnTransition = TransitionInflater.from(this@ImagePickerActivityBase) + .inflateTransition(R.transition.kau_about_return_upwards) + } + finishAfterTransition() + } + }) + } + + override fun onCreateLoader(id: Int, args: Bundle?): Loader { + val columns = arrayOf( + MediaStore.Images.Media._ID, + MediaStore.Images.Media.DATA, + MediaStore.Images.Media.DISPLAY_NAME, + MediaStore.Images.Media.DATE_MODIFIED) + + return CursorLoader(this, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, null) + } + + override fun onLoadFinished(loader: Loader, data: Cursor) { + val dataIndex = data.getColumnIndex(MediaStore.Images.Media.DATA) + val alstPhotos = mutableListOf() + + data.moveToLast() + while (!data.isBeforeFirst) { + val photoPath = data.getString(dataIndex) + KL.d(photoPath) + alstPhotos.add(photoPath) + data.moveToPrevious() + } + imageAdapter.add(alstPhotos.map { ImageItem(it) }) + } + + override fun onLoaderReset(loader: Loader) { + imageAdapter.clear() } } \ No newline at end of file diff --git a/imagepicker/src/main/res/layout/kau_activity_image_picker.xml b/imagepicker/src/main/res/layout/kau_activity_image_picker.xml index d3739dd..3c12a84 100644 --- a/imagepicker/src/main/res/layout/kau_activity_image_picker.xml +++ b/imagepicker/src/main/res/layout/kau_activity_image_picker.xml @@ -1,18 +1,29 @@ + android:id="@+id/kau_draggable" + app:dragDismissDistance="@dimen/kau_drag_dismiss_distance" + app:dragDismissScale="0.95"> - - - + android:layout_marginTop="@dimen/kau_drag_dismiss_distance" + android:orientation="vertical"> + + + + + + \ No newline at end of file diff --git a/imagepicker/src/main/res/layout/kau_iitem_image.xml b/imagepicker/src/main/res/layout/kau_iitem_image.xml index 824ae7b..22cc998 100644 --- a/imagepicker/src/main/res/layout/kau_iitem_image.xml +++ b/imagepicker/src/main/res/layout/kau_iitem_image.xml @@ -1,11 +1,15 @@ - + + android:layout_width="0dp" + android:layout_height="0dp" + android:scaleType="centerCrop" + android:background="#f0f" + app:layout_constraintDimensionRatio="1:1" /> - \ No newline at end of file + \ No newline at end of file diff --git a/imagepicker/src/main/res/values/styles.xml b/imagepicker/src/main/res/values/styles.xml new file mode 100644 index 0000000..1dc5149 --- /dev/null +++ b/imagepicker/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 5a364b6..0ab360e 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -28,6 +28,9 @@ + \ No newline at end of file diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt index 2ba7731..fbcb88f 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt @@ -26,7 +26,7 @@ class AnimActivity : AppCompatActivity() { PERMISSION_ACCESS_COARSE_LOCATION, PERMISSION_ACCESS_FINE_LOCATION ).map { PermissionCheckbox(it) }) - val withOnClickListener = adapter.withOnClickListener { _, _, item, _ -> + adapter.withOnClickListener { _, _, item, _ -> KL.d("Perm Click") kauRequestPermissions(item.permission) { granted, deniedPerm -> @@ -35,18 +35,6 @@ class AnimActivity : AppCompatActivity() { } true } - kauRequestPermissions(PERMISSION_READ_EXTERNAL_STORAGE) { - granted, deniedPerm -> - if (!granted) return@kauRequestPermissions - val cursor = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, - arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_MODIFIED), - null, null, MediaStore.Images.Media.DEFAULT_SORT_ORDER, null) - while (!cursor.isLast) { - cursor.moveToNext() - KL.d(cursor.getString(1)) - } - cursor.close() - } } override fun onBackPressed() { diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/ImageActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/ImageActivity.kt new file mode 100644 index 0000000..a0b3dc5 --- /dev/null +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/ImageActivity.kt @@ -0,0 +1,8 @@ +package ca.allanwang.kau.sample + +import ca.allanwang.kau.imagepicker.ImagePickerActivityBase + +/** + * Created by Allan Wang on 2017-07-04. + */ +class ImageActivity : ImagePickerActivityBase() \ No newline at end of file diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index 53fa68e..d0a5ee1 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -212,7 +212,7 @@ class MainActivity : KPrefActivity() { when (item.itemId) { R.id.action_settings -> startActivity(AnimActivity::class.java, clearStack = true) R.id.action_email -> sendEmail(R.string.your_email, R.string.your_subject) - R.id.test -> prefHolder.showNext() + R.id.test -> startActivity(ImageActivity::class.java, transition = true) else -> return super.onOptionsItemSelected(item) } return true diff --git a/sample/src/main/res/menu/menu_main.xml b/sample/src/main/res/menu/menu_main.xml index 0481ae5..039c2c9 100644 --- a/sample/src/main/res/menu/menu_main.xml +++ b/sample/src/main/res/menu/menu_main.xml @@ -24,7 +24,7 @@ diff --git a/sample/src/main/res/xml/changelog.xml b/sample/src/main/res/xml/changelog.xml index 1fe0a61..f4ac5bf 100644 --- a/sample/src/main/res/xml/changelog.xml +++ b/sample/src/main/res/xml/changelog.xml @@ -18,8 +18,8 @@ - - + + -- cgit v1.2.3