diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-01 10:48:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-01 10:48:37 -0700 |
commit | 7d894be6de118357ec908d2d171b6152ce67307d (patch) | |
tree | f34f0676e78433f7f58d6a5bad800430f8e767a0 /mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt | |
parent | 48213d0b427c478865c75fee912ff1ae8bbaffb5 (diff) | |
download | kau-7d894be6de118357ec908d2d171b6152ce67307d.tar.gz kau-7d894be6de118357ec908d2d171b6152ce67307d.tar.bz2 kau-7d894be6de118357ec908d2d171b6152ce67307d.zip |
Imagepicker -> mediapicker (#16)3.2.1
* Readme
* Fix kau direction bits
* Truly support transparent ripples
* Update changelog
* Test rect as base
* Replace fab transition with generic fade scale transition
* Add scalexy func
* Add scaleXY
* Add arguments to fadeScaleTransition
* Clean up ink indicator
* Create setOnSingleTapListener
* Fix lint and add rndColor
* Create kotterknife resettables
* Add readme and missing objec
* Create lazy resettable registered
* Update core docs
* Opt for separate class for resettable registry
* Clean up resettable registry
* Rename functions
* Add ripple callback listener
* Adjust kprefactivity desc color
* Add more transitions
* Add delete keys option
* Add instrumentation tests
* switch id
* Revert automatic instrumental tests
* Generify imagepickercore and prepare video alternative
* Create working video picker
* Address possible null issue
* Update searchview
* Make layouts public
* Add changelog test
* Update logo link
* Add custom color gif
* Rename imagepicker to mediapicker
* Clean up
* Fix remaining merge conflicts
* Update readme
* Update readme
Diffstat (limited to 'mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt')
-rw-r--r-- | mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt new file mode 100644 index 0000000..2ba6b43 --- /dev/null +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt @@ -0,0 +1,100 @@ +package ca.allanwang.kau.mediapicker + +import android.content.Intent +import android.database.Cursor +import android.os.Bundle +import android.support.design.widget.AppBarLayout +import android.support.design.widget.CoordinatorLayout +import android.support.design.widget.FloatingActionButton +import android.support.v4.content.Loader +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.Toolbar +import android.widget.TextView +import ca.allanwang.kau.utils.* +import com.mikepenz.google_material_typeface_library.GoogleMaterial + +/** + * Created by Allan Wang on 2017-07-04. + * + * Base activity for selecting images from storage + * Images are blurred when selected, and multiple images can be selected at a time. + * Having three layered images makes this slightly slower than [MediaPickerActivityOverlayBase] + */ +abstract class MediaPickerActivityBase(mediaType: MediaType) : MediaPickerCore<MediaItem>(mediaType) { + + val coordinator: CoordinatorLayout by bindView(R.id.kau_coordinator) + val toolbar: Toolbar by bindView(R.id.kau_toolbar) + val selectionCount: TextView by bindView(R.id.kau_selection_count) + val recycler: RecyclerView by bindView(R.id.kau_recyclerview) + val fab: FloatingActionButton by bindView(R.id.kau_fab) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.kau_activity_image_picker) + + selectionCount.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null) + + setSupportActionBar(toolbar) + supportActionBar?.apply { + setDisplayHomeAsUpEnabled(true) + setDisplayShowHomeEnabled(true) + setHomeAsUpIndicator(GoogleMaterial.Icon.gmd_close.toDrawable(this@MediaPickerActivityBase, 18)) + } + toolbar.setNavigationOnClickListener { onBackPressed() } + + initializeRecycler(recycler) + + MediaItem.bindEvents(adapter) + adapter.withSelectionListener({ _, _ -> selectionCount.text = adapter.selections.size.toString() }) + + fab.apply { + show() + setIcon(GoogleMaterial.Icon.gmd_send) + setOnClickListener { + val selection = adapter.selectedItems + if (selection.isEmpty()) { + toast(R.string.kau_no_items_selected) + } else { + val intent = Intent() + val data = ArrayList(selection.map { it.data }) + intent.putParcelableArrayListExtra(MEDIA_PICKER_RESULT, data) + setResult(RESULT_OK, intent) + finish() + } + } + hideOnDownwardsScroll(recycler) + } + + loadItems() + } + + override fun converter(model: MediaModel): MediaItem = MediaItem(model) + + /** + * Decide whether the toolbar can hide itself + * We typically want this behaviour unless we don't have enough images + * to fill the entire screen. In that case we don't want the recyclerview to be scrollable + * which means the toolbar shouldn't scroll either + + * @param scrollable true if scroll flags are enabled, false otherwise + */ + private fun setToolbarScrollable(scrollable: Boolean) { + val params = toolbar.layoutParams as AppBarLayout.LayoutParams + if (scrollable) + params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL + else + params.scrollFlags = 0 + } + + override fun onLoadFinished(loader: Loader<Cursor>?, data: Cursor?) { + super.onLoadFinished(loader, data) + setToolbarScrollable((recycler.layoutManager as LinearLayoutManager).findLastCompletelyVisibleItemPosition() < adapter.getItemCount() - 1) + } + + override fun onStatusChange(loaded: Boolean) { + setToolbarScrollable(loaded) + } + +}
\ No newline at end of file |