Some layout improvements and fixes
This commit is contained in:
parent
a18ef1ac29
commit
34000e7b79
@ -70,7 +70,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
|
|||||||
private Label currentLabel;
|
private Label currentLabel;
|
||||||
private MenuItem emptyTrashMenuItem;
|
private MenuItem emptyTrashMenuItem;
|
||||||
private MessageRepository messageRepo;
|
private MessageRepository messageRepo;
|
||||||
private List<Plaintext> messages;
|
private boolean activateOnItemClick;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
* 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) {
|
private void doUpdateList(Label label) {
|
||||||
messages = Singleton.getMessageRepository(getContext()).findMessages(label);
|
List<Plaintext> messages = Singleton.getMessageRepository(getContext()).findMessages(label);
|
||||||
if (getActivity() instanceof ActionBarListener) {
|
if (getActivity() instanceof ActionBarListener) {
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
((ActionBarListener) getActivity()).updateTitle(label.toString());
|
((ActionBarListener) getActivity()).updateTitle(label.toString());
|
||||||
@ -153,6 +153,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
|
|||||||
|
|
||||||
//adapter
|
//adapter
|
||||||
adapter = new SwipeableMessageAdapter();
|
adapter = new SwipeableMessageAdapter();
|
||||||
|
adapter.setActivateOnItemClick(activateOnItemClick);
|
||||||
adapter.setEventListener(new SwipeableMessageAdapter.EventListener() {
|
adapter.setEventListener(new SwipeableMessageAdapter.EventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemDeleted(Plaintext item) {
|
public void onItemDeleted(Plaintext item) {
|
||||||
@ -174,6 +175,7 @@ public class MessageListFragment extends Fragment implements ListHolder {
|
|||||||
@Override
|
@Override
|
||||||
public void onItemViewClicked(View v, boolean pinned) {
|
public void onItemViewClicked(View v, boolean pinned) {
|
||||||
int position = recyclerView.getChildAdapterPosition(v);
|
int position = recyclerView.getChildAdapterPosition(v);
|
||||||
|
adapter.setSelectedPosition(position);
|
||||||
if (position != RecyclerView.NO_POSITION) {
|
if (position != RecyclerView.NO_POSITION) {
|
||||||
Plaintext item = adapter.getItem(position);
|
Plaintext item = adapter.getItem(position);
|
||||||
((MainActivity) getActivity()).onItemSelected(item);
|
((MainActivity) getActivity()).onItemSelected(item);
|
||||||
@ -263,6 +265,9 @@ public class MessageListFragment extends Fragment implements ListHolder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setActivateOnItemClick(boolean activateOnItemClick) {
|
public void setActivateOnItemClick(boolean activateOnItemClick) {
|
||||||
// TODO
|
if (adapter != null) {
|
||||||
|
adapter.setActivateOnItemClick(activateOnItemClick);
|
||||||
|
}
|
||||||
|
this.activateOnItemClick = activateOnItemClick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|||||||
/**
|
/**
|
||||||
* @author Christian Basler
|
* @author Christian Basler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class AddressSelectorAdapter
|
public class AddressSelectorAdapter
|
||||||
extends RecyclerView.Adapter<AddressSelectorAdapter.ViewHolder> {
|
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() {
|
public List<BitmessageAddress> getSelected() {
|
||||||
List<BitmessageAddress> result = new LinkedList<>();
|
List<BitmessageAddress> result = new LinkedList<>();
|
||||||
for (Selectable<BitmessageAddress> selectable : data) {
|
for (Selectable<BitmessageAddress> selectable : data) {
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package ch.dissem.apps.abit.adapter;
|
package ch.dissem.apps.abit.adapter;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -62,6 +63,12 @@ public class SwipeableMessageAdapter
|
|||||||
private View.OnClickListener swipeableViewContainerOnClickListener;
|
private View.OnClickListener swipeableViewContainerOnClickListener;
|
||||||
|
|
||||||
private Label label;
|
private Label label;
|
||||||
|
private int selectedPosition;
|
||||||
|
private boolean activateOnItemClick;
|
||||||
|
|
||||||
|
public void setActivateOnItemClick(boolean activateOnItemClick) {
|
||||||
|
this.activateOnItemClick = activateOnItemClick;
|
||||||
|
}
|
||||||
|
|
||||||
public interface EventListener {
|
public interface EventListener {
|
||||||
void onItemDeleted(Plaintext item);
|
void onItemDeleted(Plaintext item);
|
||||||
@ -71,14 +78,15 @@ public class SwipeableMessageAdapter
|
|||||||
void onItemViewClicked(View v, boolean pinned);
|
void onItemViewClicked(View v, boolean pinned);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ViewHolder extends AbstractSwipeableItemViewHolder {
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
static class ViewHolder extends AbstractSwipeableItemViewHolder {
|
||||||
public FrameLayout container;
|
public FrameLayout container;
|
||||||
public final ImageView avatar;
|
public final ImageView avatar;
|
||||||
public final TextView sender;
|
public final TextView sender;
|
||||||
public final TextView subject;
|
public final TextView subject;
|
||||||
public final TextView extract;
|
public final TextView extract;
|
||||||
|
|
||||||
public ViewHolder(View v) {
|
ViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
container = (FrameLayout) v.findViewById(R.id.container);
|
container = (FrameLayout) v.findViewById(R.id.container);
|
||||||
avatar = (ImageView) v.findViewById(R.id.avatar);
|
avatar = (ImageView) v.findViewById(R.id.avatar);
|
||||||
@ -150,6 +158,14 @@ public class SwipeableMessageAdapter
|
|||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
final Plaintext item = data.get(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
|
// set listeners
|
||||||
// (if the item is *pinned*, click event comes to the itemView)
|
// (if the item is *pinned*, click event comes to the itemView)
|
||||||
holder.itemView.setOnClickListener(itemViewOnClickListener);
|
holder.itemView.setOnClickListener(itemViewOnClickListener);
|
||||||
@ -184,6 +200,7 @@ public class SwipeableMessageAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressLint("SwitchIntDef")
|
||||||
public void onSetSwipeBackground(ViewHolder holder, int position, int type) {
|
public void onSetSwipeBackground(ViewHolder holder, int position, int type) {
|
||||||
int bgRes = 0;
|
int bgRes = 0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -205,6 +222,7 @@ public class SwipeableMessageAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressLint("SwitchIntDef")
|
||||||
public SwipeResultAction onSwipeItem(ViewHolder holder, final int position, int result) {
|
public SwipeResultAction onSwipeItem(ViewHolder holder, final int position, int result) {
|
||||||
switch (result) {
|
switch (result) {
|
||||||
// swipe right
|
// swipe right
|
||||||
@ -223,6 +241,13 @@ public class SwipeableMessageAdapter
|
|||||||
this.eventListener = eventListener;
|
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 static class SwipeLeftResultAction extends SwipeResultActionMoveToSwipedDirection {
|
||||||
private SwipeableMessageAdapter adapter;
|
private SwipeableMessageAdapter adapter;
|
||||||
private final int position;
|
private final int position;
|
||||||
|
21
app/src/main/res/drawable/bg_item_selected_state.xml
Normal file
21
app/src/main/res/drawable/bg_item_selected_state.xml
Normal 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>
|
@ -1,37 +1,34 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:gravity="center"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<android.support.v7.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:background="?attr/colorPrimary"
|
android:background="?attr/colorPrimary"
|
||||||
|
android:elevation="4dp"
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||||
android:elevation="4dp"
|
|
||||||
tools:ignore="UnusedAttribute"/>
|
tools:ignore="UnusedAttribute"/>
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_below="@id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_below="@id/toolbar"
|
||||||
android:layout_marginRight="16dp"
|
android:background="@color/bg_item_selected_state"
|
||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
android:divider="?android:attr/dividerHorizontal"
|
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:showDividers="middle"
|
android:showDividers="middle"
|
||||||
tools:context=".MessageListActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
This layout is a two-pane layout for the Messages
|
This layout is a two-pane layout for the Messages
|
||||||
master/detail flow.
|
master/detail flow.
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
@ -40,13 +37,17 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
tools:context=".MessageListActivity"
|
tools:context=".MessageListActivity"
|
||||||
tools:layout="@android:layout/list_content"/>
|
tools:layout="@layout/fragment_message_list"/>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/message_detail_container"
|
android:id="@+id/message_detail_container"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="3"/>
|
android:layout_margin="16dp"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:background="@color/contentBackground"
|
||||||
|
android:elevation="2dp"
|
||||||
|
tools:layout="@layout/fragment_message_detail"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -15,7 +16,8 @@
|
|||||||
|
|
||||||
android:paddingBottom="88dp"
|
android:paddingBottom="88dp"
|
||||||
android:scrollbarStyle="outsideOverlay"
|
android:scrollbarStyle="outsideOverlay"
|
||||||
android:scrollbars="vertical"/>
|
android:scrollbars="vertical"
|
||||||
|
tools:listitem="@layout/message_row"/>
|
||||||
|
|
||||||
<android.support.design.widget.FloatingActionButton
|
<android.support.design.widget.FloatingActionButton
|
||||||
android:id="@+id/fab_compose_message"
|
android:id="@+id/fab_compose_message"
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<color name="colorAccent">#607D8B</color>
|
<color name="colorAccent">#607D8B</color>
|
||||||
<color name="colorPrimaryText">#212121</color>
|
<color name="colorPrimaryText">#212121</color>
|
||||||
<color name="colorSecondaryText">#727272</color>
|
<color name="colorSecondaryText">#727272</color>
|
||||||
|
<color name="contentBackground">#FFFFFF</color>
|
||||||
<color name="icons">#212121</color>
|
<color name="icons">#212121</color>
|
||||||
<color name="divider">#B6B6B6</color>
|
<color name="divider">#B6B6B6</color>
|
||||||
|
|
||||||
@ -49,6 +50,7 @@
|
|||||||
<color name="bg_item_normal_state">#ffffffff</color>
|
<color name="bg_item_normal_state">#ffffffff</color>
|
||||||
<color name="bg_item_swiping_state">@color/colorPrimaryLight</color>
|
<color name="bg_item_swiping_state">@color/colorPrimaryLight</color>
|
||||||
<color name="bg_item_swiping_active_state">@color/colorPrimary</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_neutral">@android:color/transparent</color>
|
||||||
<color name="bg_swipe_item_trash">#fff45f30</color>
|
<color name="bg_swipe_item_trash">#fff45f30</color>
|
||||||
<color name="bg_swipe_item_archive">#fff9930d</color>
|
<color name="bg_swipe_item_archive">#fff9930d</color>
|
||||||
|
Loading…
Reference in New Issue
Block a user