Some layout improvements and fixes

This commit is contained in:
Christian Basler 2016-10-01 17:40:38 +02:00
parent a18ef1ac29
commit 34000e7b79
10 changed files with 118 additions and 43 deletions

View File

@ -70,7 +70,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
private Label currentLabel;
private MenuItem emptyTrashMenuItem;
private MessageRepository messageRepo;
private List<Plaintext> messages;
private boolean activateOnItemClick;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
@ -105,7 +105,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
}
private void doUpdateList(Label label) {
messages = Singleton.getMessageRepository(getContext()).findMessages(label);
List<Plaintext> messages = Singleton.getMessageRepository(getContext()).findMessages(label);
if (getActivity() instanceof ActionBarListener) {
if (label != null) {
((ActionBarListener) getActivity()).updateTitle(label.toString());
@ -153,6 +153,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
//adapter
adapter = new SwipeableMessageAdapter();
adapter.setActivateOnItemClick(activateOnItemClick);
adapter.setEventListener(new SwipeableMessageAdapter.EventListener() {
@Override
public void onItemDeleted(Plaintext item) {
@ -174,6 +175,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
@Override
public void onItemViewClicked(View v, boolean pinned) {
int position = recyclerView.getChildAdapterPosition(v);
adapter.setSelectedPosition(position);
if (position != RecyclerView.NO_POSITION) {
Plaintext item = adapter.getItem(position);
((MainActivity) getActivity()).onItemSelected(item);
@ -263,6 +265,9 @@ public class MessageListFragment extends Fragment implements ListHolder {
@Override
public void setActivateOnItemClick(boolean activateOnItemClick) {
// TODO
if (adapter != null) {
adapter.setActivateOnItemClick(activateOnItemClick);
}
this.activateOnItemClick = activateOnItemClick;
}
}

View File

@ -34,7 +34,6 @@ import ch.dissem.bitmessage.entity.BitmessageAddress;
/**
* @author Christian Basler
*/
public class AddressSelectorAdapter
extends RecyclerView.Adapter<AddressSelectorAdapter.ViewHolder> {
@ -88,15 +87,6 @@ public class AddressSelectorAdapter
}
}
private static class Selectable<T> {
private final T data;
private boolean selected = false;
private Selectable(T data) {
this.data = data;
}
}
public List<BitmessageAddress> getSelected() {
List<BitmessageAddress> result = new LinkedList<>();
for (Selectable<BitmessageAddress> selectable : data) {

View File

@ -0,0 +1,29 @@
/*
* Copyright 2016 Christian Basler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.dissem.apps.abit.adapter;
/**
* @author Christian Basler
*/
class Selectable<T> {
final T data;
boolean selected = false;
Selectable(T data) {
this.data = data;
}
}

View File

@ -17,6 +17,7 @@
package ch.dissem.apps.abit.adapter;
import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -50,7 +51,7 @@ import static ch.dissem.apps.abit.util.Strings.normalizeWhitespaces;
*
* @author Christian Basler
* @see <a href="https://github.com/h6ah4i/android-advancedrecyclerview">
* https://github.com/h6ah4i/android-advancedrecyclerview</a>
* https://github.com/h6ah4i/android-advancedrecyclerview</a>
*/
public class SwipeableMessageAdapter
extends RecyclerView.Adapter<SwipeableMessageAdapter.ViewHolder>
@ -62,6 +63,12 @@ public class SwipeableMessageAdapter
private View.OnClickListener swipeableViewContainerOnClickListener;
private Label label;
private int selectedPosition;
private boolean activateOnItemClick;
public void setActivateOnItemClick(boolean activateOnItemClick) {
this.activateOnItemClick = activateOnItemClick;
}
public interface EventListener {
void onItemDeleted(Plaintext item);
@ -71,14 +78,15 @@ public class SwipeableMessageAdapter
void onItemViewClicked(View v, boolean pinned);
}
public static class ViewHolder extends AbstractSwipeableItemViewHolder {
@SuppressWarnings("WeakerAccess")
static class ViewHolder extends AbstractSwipeableItemViewHolder {
public FrameLayout container;
public final ImageView avatar;
public final TextView sender;
public final TextView subject;
public final TextView extract;
public ViewHolder(View v) {
ViewHolder(View v) {
super(v);
container = (FrameLayout) v.findViewById(R.id.container);
avatar = (ImageView) v.findViewById(R.id.avatar);
@ -150,6 +158,14 @@ public class SwipeableMessageAdapter
public void onBindViewHolder(ViewHolder holder, int position) {
final Plaintext item = data.get(position);
if (activateOnItemClick) {
holder.container.setBackgroundResource(
position == selectedPosition
? R.drawable.bg_item_selected_state
: R.drawable.bg_item_normal_state
);
}
// set listeners
// (if the item is *pinned*, click event comes to the itemView)
holder.itemView.setOnClickListener(itemViewOnClickListener);
@ -184,6 +200,7 @@ public class SwipeableMessageAdapter
}
@Override
@SuppressLint("SwitchIntDef")
public void onSetSwipeBackground(ViewHolder holder, int position, int type) {
int bgRes = 0;
switch (type) {
@ -205,6 +222,7 @@ public class SwipeableMessageAdapter
}
@Override
@SuppressLint("SwitchIntDef")
public SwipeResultAction onSwipeItem(ViewHolder holder, final int position, int result) {
switch (result) {
// swipe right
@ -223,6 +241,13 @@ public class SwipeableMessageAdapter
this.eventListener = eventListener;
}
public void setSelectedPosition(int selectedPosition) {
int oldPosition = this.selectedPosition;
this.selectedPosition = selectedPosition;
notifyItemChanged(oldPosition);
notifyItemChanged(selectedPosition);
}
private static class SwipeLeftResultAction extends SwipeResultActionMoveToSwipedDirection {
private SwipeableMessageAdapter adapter;
private final int position;

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Haruki Hasegawa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/bg_item_selected_state"/>
</item>
</layer-list>

View File

@ -1,52 +1,53 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:gravity="center">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp"
tools:ignore="UnusedAttribute"/>
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
tools:ignore="UnusedAttribute"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_below="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_below="@id/toolbar"
android:background="@color/bg_item_selected_state"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".MessageListActivity">
tools:context=".MainActivity">
<!--
This layout is a two-pane layout for the Messages
master/detail flow.
-->
<FrameLayout
android:id="@+id/item_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:context=".MessageListActivity"
tools:layout="@android:layout/list_content"/>
android:id="@+id/item_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:context=".MessageListActivity"
tools:layout="@layout/fragment_message_list"/>
<FrameLayout
android:id="@+id/message_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"/>
android:id="@+id/message_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:layout_weight="2"
android:background="@color/contentBackground"
android:elevation="2dp"
tools:layout="@layout/fragment_message_detail"/>
</LinearLayout>
</RelativeLayout>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -15,7 +16,8 @@
android:paddingBottom="88dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"/>
android:scrollbars="vertical"
tools:listitem="@layout/message_row"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_compose_message"

View File

@ -8,6 +8,7 @@
<color name="colorAccent">#607D8B</color>
<color name="colorPrimaryText">#212121</color>
<color name="colorSecondaryText">#727272</color>
<color name="contentBackground">#FFFFFF</color>
<color name="icons">#212121</color>
<color name="divider">#B6B6B6</color>
@ -49,6 +50,7 @@
<color name="bg_item_normal_state">#ffffffff</color>
<color name="bg_item_swiping_state">@color/colorPrimaryLight</color>
<color name="bg_item_swiping_active_state">@color/colorPrimary</color>
<color name="bg_item_selected_state">@color/colorPrimaryLight</color>
<color name="bg_swipe_item_neutral">@android:color/transparent</color>
<color name="bg_swipe_item_trash">#fff45f30</color>
<color name="bg_swipe_item_archive">#fff9930d</color>