added swipe functionality
This commit is contained in:
parent
dab0d7e48f
commit
7a2475241c
5 changed files with 212 additions and 124 deletions
|
@ -1,129 +1,77 @@
|
|||
package org.ligi.passandroid.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.NavUtils
|
||||
import android.support.v4.app.TaskStackBuilder
|
||||
import android.support.v4.text.util.LinkifyCompat
|
||||
import android.text.util.Linkify
|
||||
import android.support.v4.app.*
|
||||
import android.support.v4.view.ViewPager
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import kotlinx.android.synthetic.main.activity_pass_view.*
|
||||
import kotlinx.android.synthetic.main.activity_pass_view_base.*
|
||||
import kotlinx.android.synthetic.main.barcode.*
|
||||
import kotlinx.android.synthetic.main.edit.*
|
||||
import kotlinx.android.synthetic.main.pass_view_extra_data.*
|
||||
import org.ligi.compat.HtmlCompat
|
||||
import org.ligi.kaxt.disableRotation
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.maps.PassbookMapsFacade
|
||||
import org.ligi.passandroid.model.PassBitmapDefinitions
|
||||
import org.ligi.passandroid.model.PassStoreProjection
|
||||
import org.ligi.passandroid.model.pass.Pass
|
||||
import org.ligi.passandroid.ui.pass_view_holder.VerbosePassViewHolder
|
||||
|
||||
class PassViewActivity : PassViewActivityBase() {
|
||||
|
||||
val passViewHelper by lazy { PassViewHelper(this) }
|
||||
|
||||
internal fun processImage(view: ImageView, name: String, pass: Pass) {
|
||||
val bitmap = pass.getBitmap(passStore, name)
|
||||
if (bitmap != null && bitmap.width > 300) {
|
||||
view.setOnClickListener {
|
||||
val intent = Intent(view.context, TouchImageActivity::class.java)
|
||||
intent.putExtra("IMAGE", name)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
passViewHelper.setBitmapSafe(view, bitmap)
|
||||
}
|
||||
|
||||
override fun refresh() {
|
||||
super.refresh()
|
||||
|
||||
BarcodeUIController(findViewById(android.R.id.content), currentPass.barCode, this, passViewHelper)
|
||||
|
||||
processImage(logo_img_view, PassBitmapDefinitions.BITMAP_LOGO, currentPass)
|
||||
processImage(footer_img_view, PassBitmapDefinitions.BITMAP_FOOTER, currentPass)
|
||||
processImage(thumbnail_img_view, PassBitmapDefinitions.BITMAP_THUMBNAIL, currentPass)
|
||||
processImage(strip_img_view, PassBitmapDefinitions.BITMAP_STRIP, currentPass)
|
||||
|
||||
if (map_container != null) {
|
||||
if (!(currentPass.locations.isNotEmpty() && PassbookMapsFacade.init(this))) {
|
||||
map_container.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
val back_str = StringBuilder()
|
||||
|
||||
front_field_container.removeAllViews()
|
||||
|
||||
for (field in currentPass.fields) {
|
||||
if (field.hide) {
|
||||
back_str.append(field.toHtmlSnippet())
|
||||
} else {
|
||||
val v = layoutInflater.inflate(R.layout.main_field_item, front_field_container, false)
|
||||
val key = v.findViewById(R.id.key) as TextView
|
||||
key.text = field.label
|
||||
val value = v.findViewById(R.id.value) as TextView
|
||||
value.text = field.value
|
||||
|
||||
front_field_container.addView(v)
|
||||
LinkifyCompat.addLinks(key, Linkify.ALL)
|
||||
LinkifyCompat.addLinks(value, Linkify.ALL)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (back_str.isNotEmpty()) {
|
||||
back_fields.text = HtmlCompat.fromHtml(back_str.toString())
|
||||
moreTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
moreTextView.visibility = View.GONE
|
||||
}
|
||||
|
||||
|
||||
LinkifyCompat.addLinks(back_fields, Linkify.ALL)
|
||||
|
||||
val passViewHolder = VerbosePassViewHolder(pass_card)
|
||||
passViewHolder.apply(currentPass, passStore, this)
|
||||
|
||||
}
|
||||
private lateinit var pagerAdapter: CollectionPagerAdapter
|
||||
private lateinit var viewPager: ViewPager
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
disableRotation()
|
||||
|
||||
setContentView(R.layout.activity_pass_view)
|
||||
|
||||
val passExtrasView = layoutInflater.inflate(R.layout.pass_view_extra_data, passExtrasContainer, false)
|
||||
passExtrasContainer.addView(passExtrasView)
|
||||
pagerAdapter = CollectionPagerAdapter(supportFragmentManager, PassStoreProjection(passStore,
|
||||
passStore.classifier.getTopic(currentPass, ""),
|
||||
settings.getSortOrder()))
|
||||
viewPager = pager
|
||||
viewPager.adapter = pagerAdapter
|
||||
viewPager.currentItem = pagerAdapter.getPos(currentPass)
|
||||
viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
|
||||
override fun onPageSelected(i: Int) {
|
||||
currentPass = pagerAdapter.getPass(i)
|
||||
passStore.currentPass = currentPass
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun refresh() {
|
||||
super.refresh()
|
||||
|
||||
pagerAdapter.refresh()
|
||||
}
|
||||
|
||||
inner class CollectionPagerAdapter(fm: FragmentManager, private var passStoreProjection: PassStoreProjection) : FragmentStatePagerAdapter(fm) {
|
||||
|
||||
override fun getCount(): Int = passStoreProjection.passList.count()
|
||||
|
||||
override fun getItem(i: Int): Fragment {
|
||||
|
||||
val fragment = PassViewFragment()
|
||||
fragment.arguments = Bundle().apply {
|
||||
putString(PassViewActivityBase.EXTRA_KEY_UUID, getPass(i).id)
|
||||
}
|
||||
return fragment
|
||||
}
|
||||
|
||||
fun getPass(i: Int): Pass {
|
||||
return passStoreProjection.passList[i]
|
||||
}
|
||||
|
||||
fun getPos(pass: Pass): Int {
|
||||
return passStoreProjection.passList.indexOf(pass)
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
passStoreProjection.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResumeFragments() {
|
||||
super.onResumeFragments()
|
||||
|
||||
moreTextView.setOnClickListener {
|
||||
if (back_fields.visibility == View.VISIBLE) {
|
||||
back_fields.visibility = View.GONE
|
||||
moreTextView.setText(R.string.more)
|
||||
} else {
|
||||
back_fields.visibility = View.VISIBLE
|
||||
moreTextView.setText(R.string.less)
|
||||
}
|
||||
}
|
||||
|
||||
barcode_img.setOnClickListener {
|
||||
startActivityFromClass(FullscreenBarcodeActivity::class.java)
|
||||
}
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
configureActionBar()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.ligi.passandroid.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.app.ProgressDialog
|
||||
import android.content.ComponentName
|
||||
|
@ -10,10 +11,7 @@ import android.os.Build
|
|||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.WindowManager
|
||||
import android.view.*
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
|
@ -28,6 +26,7 @@ import permissions.dispatcher.NeedsPermission
|
|||
import permissions.dispatcher.RuntimePermissions
|
||||
import java.io.IOException
|
||||
|
||||
@SuppressLint("Registered")
|
||||
@RuntimePermissions
|
||||
open class PassViewActivityBase : PassAndroidActivity() {
|
||||
|
||||
|
@ -53,6 +52,7 @@ open class PassViewActivityBase : PassAndroidActivity() {
|
|||
// Ignore - but at least we tried ;-)
|
||||
}
|
||||
|
||||
updateCurrentPass()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -63,16 +63,22 @@ open class PassViewActivityBase : PassAndroidActivity() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
configureActionBar()
|
||||
|
||||
if (settings.isAutomaticLightEnabled()) {
|
||||
setToFullBrightness()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCurrentPass() {
|
||||
val uuid = intent.getStringExtra(EXTRA_KEY_UUID)
|
||||
|
||||
if (uuid != null) {
|
||||
val passbookForId = passStore.getPassbookForId(uuid)
|
||||
passStore.currentPass = passbookForId
|
||||
passStore.currentPass = passStore.getPassbookForId(uuid)
|
||||
}
|
||||
|
||||
if (passStore.currentPass == null) {
|
||||
val passbookForId = passStore.getPassbookForId(State.lastSelectedPassUUID)
|
||||
passStore.currentPass = passbookForId
|
||||
passStore.currentPass = passStore.getPassbookForId(State.lastSelectedPassUUID)
|
||||
}
|
||||
|
||||
if (passStore.currentPass == null) {
|
||||
|
@ -82,12 +88,6 @@ open class PassViewActivityBase : PassAndroidActivity() {
|
|||
}
|
||||
|
||||
currentPass = passStore.currentPass!!
|
||||
|
||||
configureActionBar()
|
||||
|
||||
if (settings.isAutomaticLightEnabled()) {
|
||||
setToFullBrightness()
|
||||
}
|
||||
}
|
||||
|
||||
protected fun configureActionBar() {
|
||||
|
@ -258,7 +258,7 @@ open class PassViewActivityBase : PassAndroidActivity() {
|
|||
const val EXTRA_KEY_UUID = "uuid"
|
||||
|
||||
fun mightPassBeAbleToUpdate(pass: Pass?): Boolean {
|
||||
return pass != null && pass.webServiceURL != null && pass.passIdent != null && pass.serial != null
|
||||
return pass?.webServiceURL != null && pass.passIdent != null && pass.serial != null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package org.ligi.passandroid.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.text.util.LinkifyCompat
|
||||
import android.text.util.Linkify
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.github.salomonbrys.kodein.instance
|
||||
import kotlinx.android.synthetic.main.activity_pass_view.*
|
||||
import kotlinx.android.synthetic.main.barcode.*
|
||||
import kotlinx.android.synthetic.main.pass_list_item.*
|
||||
import kotlinx.android.synthetic.main.pass_view_extra_data.*
|
||||
import org.ligi.compat.HtmlCompat
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.maps.PassbookMapsFacade
|
||||
import org.ligi.passandroid.model.PassBitmapDefinitions
|
||||
import org.ligi.passandroid.model.PassStore
|
||||
import org.ligi.passandroid.model.pass.Pass
|
||||
import org.ligi.passandroid.ui.pass_view_holder.VerbosePassViewHolder
|
||||
|
||||
class PassViewFragment : Fragment() {
|
||||
|
||||
private val passViewHelper by lazy { PassViewHelper(activity) }
|
||||
private var passStore : PassStore = App.kodein.instance()
|
||||
lateinit var currentPass : Pass
|
||||
|
||||
private fun processImage(view: ImageView, name: String, pass: Pass) {
|
||||
val bitmap = pass.getBitmap(passStore, name)
|
||||
if (bitmap != null && bitmap.width > 300) {
|
||||
view.setOnClickListener {
|
||||
val intent = Intent(view.context, TouchImageActivity::class.java)
|
||||
intent.putExtra("IMAGE", name)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
passViewHelper.setBitmapSafe(view, bitmap)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
moreTextView.setOnClickListener {
|
||||
if (back_fields.visibility == View.VISIBLE) {
|
||||
back_fields.visibility = View.GONE
|
||||
moreTextView.setText(R.string.more)
|
||||
} else {
|
||||
back_fields.visibility = View.VISIBLE
|
||||
moreTextView.setText(R.string.less)
|
||||
}
|
||||
}
|
||||
|
||||
barcode_img.setOnClickListener {
|
||||
activity.startActivityFromClass(FullscreenBarcodeActivity::class.java)
|
||||
}
|
||||
|
||||
BarcodeUIController(view!!, currentPass.barCode, activity, passViewHelper)
|
||||
|
||||
processImage(logo_img_view, PassBitmapDefinitions.BITMAP_LOGO, currentPass)
|
||||
processImage(footer_img_view, PassBitmapDefinitions.BITMAP_FOOTER, currentPass)
|
||||
processImage(thumbnail_img_view, PassBitmapDefinitions.BITMAP_THUMBNAIL, currentPass)
|
||||
processImage(strip_img_view, PassBitmapDefinitions.BITMAP_STRIP, currentPass)
|
||||
|
||||
if (map_container != null) {
|
||||
if (!(currentPass.locations.isNotEmpty() && PassbookMapsFacade.init(activity))) {
|
||||
@Suppress("PLUGIN_WARNING")
|
||||
map_container.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
val backStrBuilder = StringBuilder()
|
||||
|
||||
front_field_container.removeAllViews()
|
||||
|
||||
for (field in currentPass.fields) {
|
||||
if (field.hide) {
|
||||
backStrBuilder.append(field.toHtmlSnippet())
|
||||
} else {
|
||||
val v = activity.layoutInflater.inflate(R.layout.main_field_item, front_field_container, false)
|
||||
val key = v.findViewById(R.id.key) as TextView
|
||||
key.text = field.label
|
||||
val value = v.findViewById(R.id.value) as TextView
|
||||
value.text = field.value
|
||||
|
||||
front_field_container.addView(v)
|
||||
LinkifyCompat.addLinks(key, Linkify.ALL)
|
||||
LinkifyCompat.addLinks(value, Linkify.ALL)
|
||||
}
|
||||
}
|
||||
|
||||
if (backStrBuilder.isNotEmpty()) {
|
||||
back_fields.text = HtmlCompat.fromHtml(backStrBuilder.toString())
|
||||
moreTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
moreTextView.visibility = View.GONE
|
||||
}
|
||||
|
||||
LinkifyCompat.addLinks(back_fields, Linkify.ALL)
|
||||
|
||||
val passViewHolder = VerbosePassViewHolder(pass_card)
|
||||
passViewHolder.apply(currentPass, passStore, activity)
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View {
|
||||
|
||||
val rootView = inflater.inflate(R.layout.activity_pass_view_page, container, false)
|
||||
arguments?.takeIf { it.containsKey(PassViewActivityBase.EXTRA_KEY_UUID) }?.apply {
|
||||
val uuid = getString(PassViewActivityBase.EXTRA_KEY_UUID)
|
||||
|
||||
if (uuid != null) {
|
||||
val passbookForId = passStore.getPassbookForId(uuid)
|
||||
passStore.currentPass = passbookForId
|
||||
}
|
||||
|
||||
currentPass = passStore.currentPass!!
|
||||
}
|
||||
|
||||
return rootView
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val passExtrasView = activity.layoutInflater.inflate(R.layout.pass_view_extra_data, passExtrasContainer, false)
|
||||
passExtrasContainer.addView(passExtrasView)
|
||||
}
|
||||
}
|
|
@ -22,14 +22,10 @@
|
|||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
|
||||
<include layout="@layout/pass_list_item" />
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
9
android/src/main/res/layout/activity_pass_view_page.xml
Normal file
9
android/src/main/res/layout/activity_pass_view_page.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<include layout="@layout/pass_list_item" />
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
Loading…
Reference in a new issue