Add new approach to the bar with time and nav below the pass ( no more wrapped drawables )

This commit is contained in:
ligi 2016-10-30 09:13:49 +01:00
parent 6652b5166c
commit bfb9c03dfe
No known key found for this signature in database
GPG key ID: 8E81894010ABF23D
12 changed files with 161 additions and 160 deletions

View file

@ -79,7 +79,7 @@ public class ThePassViewActivity {
act_pass.setCalendarTimespan(new PassImpl.TimeSpan(ZonedDateTime.now(), null, null)); act_pass.setCalendarTimespan(new PassImpl.TimeSpan(ZonedDateTime.now(), null, null));
rule.launchActivity(null); rule.launchActivity(null);
onView(withId(R.id.addCalendar)).check(matches(isDisplayed())); onView(withText(R.string.pass_to_calendar)).check(matches(isDisplayed()));
} }
@Test @Test
@ -90,7 +90,7 @@ public class ThePassViewActivity {
act_pass.setCalendarTimespan(null); act_pass.setCalendarTimespan(null);
rule.launchActivity(null); rule.launchActivity(null);
onView(withId(R.id.addCalendar)).perform(click()); onView(withText(R.string.pass_to_calendar)).perform(click());
onView(withText(R.string.expiration_date_to_calendar_warning_message)).check(matches(isDisplayed())); onView(withText(R.string.expiration_date_to_calendar_warning_message)).check(matches(isDisplayed()));
} }
@ -109,7 +109,7 @@ public class ThePassViewActivity {
act_pass.setValidTimespans(new ArrayList<PassImpl.TimeSpan>()); act_pass.setValidTimespans(new ArrayList<PassImpl.TimeSpan>());
rule.launchActivity(null); rule.launchActivity(null);
onView(withId(R.id.addCalendar)).check(matches(not(isDisplayed()))); onView(withText(R.string.pass_to_calendar)).check(matches(not(isDisplayed())));
} }
@Test @Test

View file

@ -21,7 +21,7 @@ class CondensedPassViewHolder(view: CardView) : PassViewHolder(view) {
view.date.visibility = View.GONE view.date.visibility = View.GONE
} }
view.addCalendar.text = getTimeInfoString(pass) view.timeAndNavBar.timeTextView.text = getTimeInfoString(pass)
} }
} }

View file

@ -8,6 +8,8 @@ import android.support.v7.widget.CardView
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.widget.DatePicker import android.widget.DatePicker
import android.widget.TimePicker import android.widget.TimePicker
import kotlinx.android.synthetic.main.edit.view.*
import org.ligi.passandroid.R
import org.ligi.passandroid.model.PassStore import org.ligi.passandroid.model.PassStore
import org.ligi.passandroid.model.pass.Pass import org.ligi.passandroid.model.pass.Pass
import org.ligi.passandroid.model.pass.PassImpl import org.ligi.passandroid.model.pass.PassImpl
@ -20,14 +22,6 @@ class EditViewHolder(view: CardView) : VerbosePassViewHolder(view), TimePickerDi
lateinit private var pass: PassImpl lateinit private var pass: PassImpl
lateinit private var passStore: PassStore lateinit private var passStore: PassStore
override fun clickAddToCalendar(pass: Pass) {
DatePickerDialog(view.context, this, time.year, time.month.value - 1, time.dayOfMonth).show()
}
override fun performNavigate(activity: Activity, pass: Pass) {
AlertDialog.Builder(view.context).setMessage("Not yet available").setPositiveButton(android.R.string.ok, null).show()
}
override fun apply(pass: Pass, passStore: PassStore, activity: Activity) { override fun apply(pass: Pass, passStore: PassStore, activity: Activity) {
super.apply(pass, passStore, activity) super.apply(pass, passStore, activity)
@ -42,6 +36,21 @@ class EditViewHolder(view: CardView) : VerbosePassViewHolder(view), TimePickerDi
} }
} }
override fun setupButtons(activity: Activity, pass: Pass) {
view.timeAndNavBar.timeTextView.text = view.context.getString(R.string.edit_time)
view.timeAndNavBar.navTextView.text = view.context.getString(R.string.edit_location)
view.timeAndNavBar.timeTextView.setOnClickListener {
DatePickerDialog(view.context, this, time.year, time.month.value - 1, time.dayOfMonth).show()
}
view.timeAndNavBar.navTextView.setOnClickListener {
AlertDialog.Builder(view.context).setMessage("Not yet available").setPositiveButton(android.R.string.ok, null).show()
}
}
@Visibility @Visibility
override fun getVisibilityForGlobalAndLocal(global: Boolean, local: Boolean): Int { override fun getVisibilityForGlobalAndLocal(global: Boolean, local: Boolean): Int {
return VISIBLE return VISIBLE

View file

@ -6,6 +6,7 @@ import android.support.v7.widget.RecyclerView
import android.text.format.DateUtils import android.text.format.DateUtils
import android.view.View.* import android.view.View.*
import kotlinx.android.synthetic.main.pass_list_item.view.* import kotlinx.android.synthetic.main.pass_list_item.view.*
import org.ligi.passandroid.R
import org.ligi.passandroid.actions.AddToCalendar import org.ligi.passandroid.actions.AddToCalendar
import org.ligi.passandroid.model.PassBitmapDefinitions import org.ligi.passandroid.model.PassBitmapDefinitions
import org.ligi.passandroid.model.PassStore import org.ligi.passandroid.model.PassStore
@ -18,25 +19,34 @@ import org.threeten.bp.ZonedDateTime
abstract class PassViewHolder(val view: CardView) : RecyclerView.ViewHolder(view) { abstract class PassViewHolder(val view: CardView) : RecyclerView.ViewHolder(view) {
open fun apply(pass: Pass, passStore: PassStore, activity: Activity) { open fun apply(pass: Pass, passStore: PassStore, activity: Activity) {
view.addCalendar.setOnClickListener { setupButtons(activity, pass)
clickAddToCalendar(pass)
}
view.navigateTo.setOnClickListener {
performNavigate(activity, pass)
}
refresh(pass, passStore) refresh(pass, passStore)
} }
open fun setupButtons(activity: Activity, pass: Pass) {
view.timeAndNavBar.timeTextView.text = view.context.getString(R.string.pass_to_calendar)
view.timeAndNavBar.navTextView.text = view.context.getString(R.string.pass_directions)
view.timeAndNavBar.timeTextView.setOnClickListener {
val dateOrExtraText = getDateOrExtraText(pass)
AddToCalendar.tryAddDateToCalendar(pass, view, dateOrExtraText)
}
view.timeAndNavBar.navTextView.setOnClickListener {
NavigateToLocationsDialog.perform(activity, pass, false)
}
}
protected fun refresh(pass: Pass, passStore: PassStore) { protected fun refresh(pass: Pass, passStore: PassStore) {
val dateOrExtraText = getDateOrExtraText(pass) val dateOrExtraText = getDateOrExtraText(pass)
val noButtons = dateOrExtraText == null && pass.locations.size <= 0 val noButtons = dateOrExtraText == null && pass.locations.size <= 0
view.actionsSeparator.visibility = getVisibilityForGlobalAndLocal(noButtons, true) view.actionsSeparator.visibility = getVisibilityForGlobalAndLocal(noButtons, true)
view.navigateTo.visibility = getVisibilityForGlobalAndLocal(noButtons, pass.locations.size > 0) view.timeAndNavBar.navTextView.visibility = getVisibilityForGlobalAndLocal(noButtons, pass.locations.size > 0)
view.addCalendar.visibility = getVisibilityForGlobalAndLocal(noButtons, dateOrExtraText != null) view.timeAndNavBar.timeTextView.visibility = getVisibilityForGlobalAndLocal(noButtons, dateOrExtraText != null)
val iconBitmap = pass.getBitmap(passStore, PassBitmapDefinitions.BITMAP_ICON) val iconBitmap = pass.getBitmap(passStore, PassBitmapDefinitions.BITMAP_ICON)
@ -49,15 +59,6 @@ abstract class PassViewHolder(val view: CardView) : RecyclerView.ViewHolder(view
view.passTitle.text = pass.description view.passTitle.text = pass.description
} }
protected open fun performNavigate(activity: Activity, pass: Pass) {
NavigateToLocationsDialog.perform(activity, pass, false)
}
protected open fun clickAddToCalendar(pass: Pass) {
val dateOrExtraText = getDateOrExtraText(pass)
AddToCalendar.tryAddDateToCalendar(pass, view, dateOrExtraText)
}
fun getExtraString(pass: Pass) = pass.fields.firstOrNull()?.let { getExtraStringForField(it) } fun getExtraString(pass: Pass) = pass.fields.firstOrNull()?.let { getExtraStringForField(it) }

View file

@ -0,0 +1,51 @@
package org.ligi.passandroid.ui.views
import android.content.Context
import android.support.v7.widget.AppCompatDrawableManager
import android.util.AttributeSet
import android.view.Gravity
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import org.ligi.passandroid.R
open class TimeAndNavBar constructor(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
private fun baseTextView(context: Context) = TextView(context).apply {
layoutParams = weightLayoutParams
val dimension = context.resources.getDimension(R.dimen.rhythm).toInt()
setPadding(dimension, dimension, dimension, dimension)
isClickable = true
setBackgroundResource(R.drawable.clickable_bg)
}
val navTextView by lazy {
baseTextView(context)
}
val timeTextView by lazy {
baseTextView(context).apply {
gravity = Gravity.RIGHT
}
}
val weightLayoutParams by lazy {
LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT).apply {
weight = 1.toFloat()
}
}
override fun onFinishInflate() {
super.onFinishInflate()
addView(navTextView)
addView(timeTextView)
val drawableManager = AppCompatDrawableManager.get()
val navDrawable = drawableManager.getDrawable(context, R.drawable.ic_maps_place)
navTextView.setCompoundDrawablesWithIntrinsicBounds(navDrawable, null, null, null)
val timeDrawable = drawableManager.getDrawable(context, R.drawable.ic_action_today)
timeTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, timeDrawable, null)
}
}

View file

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF757575"
android:pathData="M19,3h-1L18,1h-2v2L8,3L8,1L6,1v2L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM12,6c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM18,18L6,18v-1c0,-2 4,-3.1 6,-3.1s6,1.1 6,3.1v1z"/>
</vector>

View file

@ -1,4 +0,0 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_action_perm_contact_calendar"/>
</selector>

View file

@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="18dp"
android:height="24dp" android:height="18dp"
android:viewportWidth="24.0" android:viewportWidth="24.0"
android:viewportHeight="24.0"> android:viewportHeight="24.0">
<path <path
android:fillColor="#FFFFFFFF" android:fillColor="?colorControlNormal"
android:pathData="M19,3h-1L18,1h-2v2L8,3L8,1L6,1v2L5,3c-1.11,0 -1.99,0.9 -1.99,2L3,19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,19L5,19L5,8h14v11zM7,10h5v5L7,15z"/> android:pathData="M19,3h-1L18,1h-2v2L8,3L8,1L6,1v2L5,3c-1.11,0 -1.99,0.9 -1.99,2L3,19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,19L5,19L5,8h14v11zM7,10h5v5L7,15z"/>
</vector> </vector>

View file

@ -4,6 +4,6 @@
android:viewportWidth="24.0" android:viewportWidth="24.0"
android:viewportHeight="24.0"> android:viewportHeight="24.0">
<path <path
android:fillColor="#FF757575" android:fillColor="?colorControlNormal"
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/> android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
</vector> </vector>

View file

@ -1,3 +0,0 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_maps_place" />
</selector>

View file

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" android:layout_width="match_parent"
android:orientation="vertical"> android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:id="@+id/pass_card" android:id="@+id/pass_card"
@ -15,9 +16,11 @@
android:orientation="vertical"> android:orientation="vertical">
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_height="match_parent"> android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout <LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -69,7 +72,6 @@
android:id="@+id/actionsSeparator" android:id="@+id/actionsSeparator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="2dip" android:layout_height="2dip"
android:layout_below="@id/pass_top"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
@ -77,38 +79,15 @@
android:background="#dfdfdf" android:background="#dfdfdf"
android:padding="7dp"/> android:padding="7dp"/>
<org.ligi.passandroid.ui.views.TimeAndNavBar
<TextView android:id="@+id/timeAndNavBar"
android:id="@+id/navigateTo" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_below="@id/actionsSeparator"
android:layout_gravity="center_vertical"
android:background="@drawable/clickable_bg"
android:clickable="true"
android:drawableLeft="@drawable/ic_maps_place_wrapped"
android:padding="8dp"
android:text="@string/edit_location"/>
<TextView
android:id="@+id/addCalendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/actionsSeparator"
android:layout_gravity="center_vertical"
android:background="@drawable/clickable_bg"
android:clickable="true"
android:drawableRight="@drawable/ic_action_perm_contact_calendar_wrapped"
android:padding="8dp"
android:text="@string/edit_time"/>
<LinearLayout <LinearLayout
android:id="@+id/passExtrasContainer" android:id="@+id/passExtrasContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/addCalendar"
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
@ -134,7 +113,7 @@
android:id="@+id/container_for_primary_fields" android:id="@+id/container_for_primary_fields"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> />
<include layout="@layout/barcode"/> <include layout="@layout/barcode"/>
@ -144,13 +123,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:text="@string/add_barcode" android:text="@string/add_barcode"
/> />
<FrameLayout <FrameLayout
android:id="@+id/container_for_secondary_fields" android:id="@+id/container_for_secondary_fields"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> />
<ImageView <ImageView
@ -194,7 +173,7 @@
</LinearLayout> </LinearLayout>
</RelativeLayout> </LinearLayout>
</ScrollView> </ScrollView>

View file

@ -1,52 +1,54 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.widget.CardView
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pass_card" xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:id="@+id/pass_card"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:layout_margin="4dp" android:layout_height="wrap_content"
android.support.v7.cardview:cardMaxElevation="@dimen/card_longclick_elevation_half" android:layout_margin="8dp"
android.support.v7.cardview:cardMaxElevation="@dimen/card_longclick_elevation_half"
android:orientation="vertical">
android:orientation="vertical"> <LinearLayout
android:background="@color/card_view_background"
<RelativeLayout android:layout_width="wrap_content"
android:background="@color/card_view_background" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="wrap_content"> >
<LinearLayout <LinearLayout
android:id="@+id/pass_top" android:id="@+id/pass_top"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<LinearLayout <LinearLayout
android:layout_width="0dip" android:layout_width="0dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_weight="1" android:layout_weight="1"
android:padding="8dp" android:padding="8dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/date" android:id="@+id/date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
tools:text="12.10.2013 17:00" /> tools:text="12.10.2013 17:00"/>
<TextView <TextView
android:id="@+id/passTitle" android:id="@+id/passTitle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="4dp" android:paddingTop="4dp"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
tools:text="Title" /> tools:text="Title"/>
</LinearLayout> </LinearLayout>
<org.ligi.passandroid.ui.views.CategoryIndicatorViewWithIcon <org.ligi.passandroid.ui.views.CategoryIndicatorViewWithIcon
@ -54,7 +56,7 @@
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="74dp" android:layout_height="74dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="8dp" /> android:layout_margin="8dp"/>
</LinearLayout> </LinearLayout>
@ -62,51 +64,26 @@
android:id="@+id/actionsSeparator" android:id="@+id/actionsSeparator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="2dip" android:layout_height="2dip"
android:layout_below="@id/pass_top"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:background="#dfdfdf" android:background="#dfdfdf"
android:padding="7dp" /> android:padding="7dp"/>
<org.ligi.passandroid.ui.views.TimeAndNavBar
<TextView android:id="@+id/timeAndNavBar"
android:layout_width="match_parent"
android:id="@+id/navigateTo" android:layout_height="wrap_content"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/actionsSeparator"
android:layout_gravity="center_vertical"
android:background="@drawable/clickable_bg"
android:clickable="true"
android:textColor="?android:attr/textColorPrimary"
android:drawableLeft="@drawable/ic_maps_place_wrapped"
android:padding="8dp"
android:text="@string/pass_directions" />
<TextView
android:id="@+id/addCalendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/actionsSeparator"
android:layout_gravity="center_vertical"
android:background="@drawable/clickable_bg"
android:clickable="true"
android:drawableRight="@drawable/ic_action_perm_contact_calendar_wrapped"
android:padding="8dp"
android:text="@string/pass_to_calendar" />
<LinearLayout <LinearLayout
android:id="@+id/passExtrasContainer" android:id="@+id/passExtrasContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/addCalendar" android:orientation="vertical"/>
android:orientation="vertical" />
</RelativeLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>