Merge branch '305-forum-list-snackbar' into 'master'
Add Snackbar and Toolbar Button to Forum List This MR is a small change that replaces the custom UI elements in the forum list with a Snackbar and a Toolbar menu. It also fixes a background color that was still present with fragment from the NavDrawer. Before:  After:  It addresses one part (2b) of #305 and is part of #121. See merge request !163
|
Before Width: | Height: | Size: 716 B |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 583 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 830 B |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -22,15 +22,13 @@
|
|||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/content_fragment"
|
android:id="@+id/content_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"/>
|
||||||
android:background="@color/default_background"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/container_progress"
|
android:id="@+id/container_progress"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:background="@color/default_background"
|
|
||||||
android:visibility="invisible"
|
android:visibility="invisible"
|
||||||
tools:visibility="visible">
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
|||||||
12
briar-android/res/menu/forum_list_actions.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_create_forum"
|
||||||
|
android:icon="@drawable/ic_add_white"
|
||||||
|
android:title="@string/create_forum_button"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
|
</menu>
|
||||||
@@ -31,10 +31,11 @@
|
|||||||
<color name="briar_text_primary_inverse">#ffffff</color>
|
<color name="briar_text_primary_inverse">#ffffff</color>
|
||||||
<color name="briar_text_secondary">#333333</color>
|
<color name="briar_text_secondary">#333333</color>
|
||||||
<color name="briar_text_tertiary">#333333</color>
|
<color name="briar_text_tertiary">#333333</color>
|
||||||
|
<color name="briar_button_positive">#06b9ff</color>
|
||||||
|
<color name="briar_button_negative">#ff0000</color>
|
||||||
|
|
||||||
<!-- this is needed as preference_category_material layout uses this color as the text color -->
|
<!-- this is needed as preference_category_material layout uses this color as the text color -->
|
||||||
<color name="preference_fallback_accent_color">@color/briar_accent</color>
|
<color name="preference_fallback_accent_color">@color/briar_accent</color>
|
||||||
<color name="default_background">#ffffff</color>
|
|
||||||
<color name="default_separator">#000000</color>
|
<color name="default_separator">#000000</color>
|
||||||
<color name="default_separator_inverted">#ffffff</color>
|
<color name="default_separator_inverted">#ffffff</color>
|
||||||
<color name="menu_background">#FFFFFF</color>
|
<color name="menu_background">#FFFFFF</color>
|
||||||
|
|||||||
@@ -77,6 +77,7 @@
|
|||||||
<item quantity="one">%d forum shared by contacts</item>
|
<item quantity="one">%d forum shared by contacts</item>
|
||||||
<item quantity="other">%d forums shared by contacts</item>
|
<item quantity="other">%d forums shared by contacts</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
<string name="show_forums">Show</string>
|
||||||
<string name="unsubscribe">Unsubscribe</string>
|
<string name="unsubscribe">Unsubscribe</string>
|
||||||
<string name="unsubscribed_toast">Unsubscribed</string>
|
<string name="unsubscribed_toast">Unsubscribed</string>
|
||||||
<string name="no_forum_posts">No posts</string>
|
<string name="no_forum_posts">No posts</string>
|
||||||
|
|||||||
@@ -67,13 +67,13 @@
|
|||||||
<style name="BriarButton.Default"/>
|
<style name="BriarButton.Default"/>
|
||||||
|
|
||||||
<style name="BriarButtonFlat.Negative" parent="Widget.AppCompat.Button.Borderless">
|
<style name="BriarButtonFlat.Negative" parent="Widget.AppCompat.Button.Borderless">
|
||||||
<item name="android:textColor">#ff0000</item>
|
<item name="android:textColor">@color/briar_button_negative</item>
|
||||||
<item name="android:textSize">@dimen/text_size_medium</item>
|
<item name="android:textSize">@dimen/text_size_medium</item>
|
||||||
<item name="android:padding">@dimen/margin_large</item>
|
<item name="android:padding">@dimen/margin_large</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="BriarButtonFlat.Positive" parent="Widget.AppCompat.Button.Borderless">
|
<style name="BriarButtonFlat.Positive" parent="Widget.AppCompat.Button.Borderless">
|
||||||
<item name="android:textColor">#06b9ff</item>
|
<item name="android:textColor">@color/briar_button_positive</item>
|
||||||
<item name="android:textSize">@dimen/text_size_medium</item>
|
<item name="android:textSize">@dimen/text_size_medium</item>
|
||||||
<item name="android:padding">@dimen/margin_large</item>
|
<item name="android:padding">@dimen/margin_large</item>
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class ContactListFragment extends BaseEventFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View contentView =
|
View contentView =
|
||||||
inflater.inflate(R.layout.activity_contact_list, container,
|
inflater.inflate(R.layout.fragment_contact_list, container,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
BaseContactListAdapter.OnItemClickListener onItemClickListener =
|
BaseContactListAdapter.OnItemClickListener onItemClickListener =
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
package org.briarproject.android.forum;
|
package org.briarproject.android.forum;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -21,8 +23,6 @@ import android.widget.Toast;
|
|||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.AndroidComponent;
|
import org.briarproject.android.AndroidComponent;
|
||||||
import org.briarproject.android.fragment.BaseEventFragment;
|
import org.briarproject.android.fragment.BaseEventFragment;
|
||||||
import org.briarproject.android.util.HorizontalBorder;
|
|
||||||
import org.briarproject.android.util.LayoutUtils;
|
|
||||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.db.NoSuchGroupException;
|
import org.briarproject.api.db.NoSuchGroupException;
|
||||||
@@ -43,12 +43,12 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE;
|
||||||
import static android.view.Gravity.CENTER;
|
import static android.view.Gravity.CENTER;
|
||||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||||
import static android.view.Menu.NONE;
|
import static android.view.Menu.NONE;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static android.widget.LinearLayout.HORIZONTAL;
|
|
||||||
import static android.widget.LinearLayout.VERTICAL;
|
import static android.widget.LinearLayout.VERTICAL;
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
@@ -56,7 +56,6 @@ import static java.util.logging.Level.WARNING;
|
|||||||
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
|
import static org.briarproject.android.forum.ForumActivity.FORUM_NAME;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||||
|
|
||||||
public class ForumListFragment extends BaseEventFragment implements
|
public class ForumListFragment extends BaseEventFragment implements
|
||||||
@@ -82,8 +81,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
private ForumListAdapter adapter = null;
|
private ForumListAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
private TextView available = null;
|
private Snackbar snackbar;
|
||||||
private ImageButton newForumButton = null;
|
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject protected volatile ForumManager forumManager;
|
@Inject protected volatile ForumManager forumManager;
|
||||||
@@ -93,13 +91,14 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
LinearLayout layout = new LinearLayout(getContext());
|
LinearLayout layout = new LinearLayout(getContext());
|
||||||
layout.setLayoutParams(MATCH_MATCH);
|
layout.setLayoutParams(MATCH_MATCH);
|
||||||
layout.setOrientation(VERTICAL);
|
layout.setOrientation(VERTICAL);
|
||||||
layout.setGravity(CENTER_HORIZONTAL);
|
layout.setGravity(CENTER_HORIZONTAL);
|
||||||
|
|
||||||
int pad = LayoutUtils.getPadding(getContext());
|
|
||||||
|
|
||||||
empty = new TextView(getContext());
|
empty = new TextView(getContext());
|
||||||
empty.setLayoutParams(MATCH_WRAP_1);
|
empty.setLayoutParams(MATCH_WRAP_1);
|
||||||
empty.setGravity(CENTER);
|
empty.setGravity(CENTER);
|
||||||
@@ -121,32 +120,6 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
loading = new ListLoadingProgressBar(getContext());
|
loading = new ListLoadingProgressBar(getContext());
|
||||||
layout.addView(loading);
|
layout.addView(loading);
|
||||||
|
|
||||||
available = new TextView(getContext());
|
|
||||||
available.setLayoutParams(MATCH_WRAP);
|
|
||||||
available.setGravity(CENTER);
|
|
||||||
available.setTextSize(18);
|
|
||||||
available.setPadding(pad, pad, pad, pad);
|
|
||||||
Resources res = getResources();
|
|
||||||
int background = res.getColor(R.color.forums_available_background);
|
|
||||||
available.setBackgroundColor(background);
|
|
||||||
available.setOnClickListener(this);
|
|
||||||
available.setVisibility(GONE);
|
|
||||||
layout.addView(available);
|
|
||||||
|
|
||||||
layout.addView(new HorizontalBorder(getContext()));
|
|
||||||
|
|
||||||
LinearLayout footer = new LinearLayout(getContext());
|
|
||||||
footer.setLayoutParams(MATCH_WRAP);
|
|
||||||
footer.setOrientation(HORIZONTAL);
|
|
||||||
footer.setGravity(CENTER);
|
|
||||||
footer.setBackgroundColor(res.getColor(R.color.button_bar_background));
|
|
||||||
newForumButton = new ImageButton(getContext());
|
|
||||||
newForumButton.setBackgroundResource(0);
|
|
||||||
newForumButton.setImageResource(R.drawable.social_new_chat);
|
|
||||||
newForumButton.setOnClickListener(this);
|
|
||||||
footer.addView(newForumButton);
|
|
||||||
layout.addView(footer);
|
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,9 +136,36 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
snackbar = Snackbar.make(getView(), "", LENGTH_INDEFINITE);
|
||||||
|
snackbar.getView().setBackgroundResource(R.color.briar_primary);
|
||||||
|
snackbar.setAction(R.string.show_forums, this);
|
||||||
|
snackbar.setActionTextColor(ContextCompat
|
||||||
|
.getColor(getContext(), R.color.briar_button_positive));
|
||||||
|
|
||||||
loadHeaders();
|
loadHeaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.forum_list_actions, menu);
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
|
// Handle presses on the action bar items
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.action_create_forum:
|
||||||
|
Intent intent =
|
||||||
|
new Intent(getContext(), CreateForumActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadHeaders() {
|
private void loadHeaders() {
|
||||||
clearHeaders();
|
clearHeaders();
|
||||||
listener.runOnDbThread(new Runnable() {
|
listener.runOnDbThread(new Runnable() {
|
||||||
@@ -203,7 +203,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
public void run() {
|
public void run() {
|
||||||
empty.setVisibility(GONE);
|
empty.setVisibility(GONE);
|
||||||
list.setVisibility(GONE);
|
list.setVisibility(GONE);
|
||||||
available.setVisibility(GONE);
|
snackbar.dismiss();
|
||||||
loading.setVisibility(VISIBLE);
|
loading.setVisibility(VISIBLE);
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
}
|
}
|
||||||
@@ -240,10 +240,10 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
listener.runOnUiThread(new Runnable() {
|
listener.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (availableCount == 0) {
|
if (availableCount == 0) {
|
||||||
available.setVisibility(GONE);
|
snackbar.dismiss();
|
||||||
} else {
|
} else {
|
||||||
available.setVisibility(VISIBLE);
|
snackbar.show();
|
||||||
available.setText(getResources().getQuantityString(
|
snackbar.setText(getResources().getQuantityString(
|
||||||
R.plurals.forums_shared, availableCount,
|
R.plurals.forums_shared, availableCount,
|
||||||
availableCount));
|
availableCount));
|
||||||
}
|
}
|
||||||
@@ -363,12 +363,8 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (view == available) {
|
// snackbar click
|
||||||
startActivity(new Intent(getContext(),
|
startActivity(new Intent(getContext(), AvailableForumsActivity.class));
|
||||||
AvailableForumsActivity.class));
|
|
||||||
} else if (view == newForumButton) {
|
|
||||||
startActivity(new Intent(getContext(), CreateForumActivity.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||||
|
|||||||