Added some actions

This commit is contained in:
Christian Basler 2015-09-06 17:45:21 +02:00
parent 496fffe6ee
commit a17685fd10
32 changed files with 297 additions and 36 deletions

View File

@ -3,11 +3,15 @@ package ch.dissem.apps.abit;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import ch.dissem.bitmessage.entity.BitmessageAddress;
/**
* Compose a new message.
*/
public class ComposeMessageActivity extends AppCompatActivity {
public static final String EXTRA_IDENTITY = "ch.dissem.abit.Message.SENDER";
public static final String EXTRA_RECIPIENT = "ch.dissem.abit.Message.RECIPIENT";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -21,8 +25,10 @@ public class ComposeMessageActivity extends AppCompatActivity {
getSupportActionBar().setHomeButtonEnabled(false);
// Display the fragment as the main content.
ComposeMessageFragment fragment = new ComposeMessageFragment();
fragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.replace(R.id.content, new ComposeMessageFragment())
.replace(R.id.content, fragment)
.commit();
}
}

View File

@ -9,19 +9,13 @@ import android.widget.Toast;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.entity.BitmessageAddress;
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_IDENTITY;
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_RECIPIENT;
/**
* Compose a new message.
*/
public class ComposeMessageFragment extends Fragment {
/**
* The fragment argument representing the sender identity.
*/
public static final String ARG_IDENTITY = "from";
/**
* The fragment argument representing the recipient.
*/
public static final String ARG_RECIPIENT = "to";
private BitmessageContext bmCtx;
private BitmessageAddress identity;
private BitmessageAddress recipient;
@ -37,11 +31,11 @@ public class ComposeMessageFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
if (getArguments().containsKey(ARG_IDENTITY)) {
identity = (BitmessageAddress) getArguments().getSerializable(ARG_IDENTITY);
if (getArguments().containsKey(EXTRA_IDENTITY)) {
identity = (BitmessageAddress) getArguments().getSerializable(EXTRA_IDENTITY);
}
if (getArguments().containsKey(ARG_RECIPIENT)) {
recipient = (BitmessageAddress) getArguments().getSerializable(ARG_RECIPIENT);
if (getArguments().containsKey(EXTRA_RECIPIENT)) {
recipient = (BitmessageAddress) getArguments().getSerializable(EXTRA_RECIPIENT);
}
}
setHasOptionsMenu(true);
@ -51,6 +45,10 @@ public class ComposeMessageFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_compose_message, container, false);
if (recipient != null) {
EditText recipientInput = (EditText) rootView.findViewById(R.id.recipient);
recipientInput.setText(recipient.toString());
}
EditText body = (EditText) rootView.findViewById(R.id.body);
body.setInputType(EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
body.setImeOptions(EditorInfo.IME_ACTION_SEND | EditorInfo.IME_FLAG_NO_ENTER_ACTION);

View File

@ -1,16 +1,18 @@
package ch.dissem.apps.abit;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.*;
import android.widget.ImageView;
import android.widget.TextView;
import ch.dissem.apps.abit.service.Singleton;
import ch.dissem.apps.abit.utils.Drawables;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.entity.BitmessageAddress;
import ch.dissem.bitmessage.entity.Plaintext;
import ch.dissem.bitmessage.entity.valueobject.Label;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import java.util.Iterator;
@ -29,10 +31,11 @@ public class MessageDetailFragment extends Fragment {
public static final String ARG_ITEM = "item";
/**
* The dummy content this fragment is presenting.
* The content this fragment is presenting.
*/
private Plaintext item;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
@ -50,6 +53,7 @@ public class MessageDetailFragment extends Fragment {
// to load content from a content provider.
item = (Plaintext) getArguments().getSerializable(ARG_ITEM);
}
setHasOptionsMenu(true);
}
@Override
@ -84,4 +88,57 @@ public class MessageDetailFragment extends Fragment {
}
return rootView;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.message, menu);
Drawables.addIcon(getActivity(), menu, R.id.reply, GoogleMaterial.Icon.gmd_reply);
Drawables.addIcon(getActivity(), menu, R.id.delete, GoogleMaterial.Icon.gmd_delete);
Drawables.addIcon(getActivity(), menu, R.id.mark_unread, GoogleMaterial.Icon.gmd_markunread);
Drawables.addIcon(getActivity(), menu, R.id.archive, GoogleMaterial.Icon.gmd_archive);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
BitmessageContext bmc = Singleton.getBitmessageContext(getActivity());
switch (menuItem.getItemId()) {
case R.id.reply:
Intent replyIntent = new Intent(getActivity().getApplicationContext(), ComposeMessageActivity.class);
replyIntent.putExtra(ComposeMessageActivity.EXTRA_RECIPIENT, item.getFrom());
replyIntent.putExtra(ComposeMessageActivity.EXTRA_IDENTITY, item.getTo());
startActivity(replyIntent);
return true;
case R.id.delete:
if (isInTrash(item)) {
bmc.messages().remove(item);
} else {
item.getLabels().clear();
item.addLabels(bmc.messages().getLabels(Label.Type.TRASH));
bmc.messages().save(item);
}
return true;
case R.id.mark_unread:
item.addLabels(bmc.messages().getLabels(Label.Type.UNREAD));
bmc.messages().save(item);
return true;
case R.id.archive:
item.getLabels().clear();
bmc.messages().save(item);
return true;
default:
return false;
}
}
private boolean isInTrash(Plaintext item) {
for (Label label : item.getLabels()) {
if (label.getType() == Label.Type.TRASH) {
return true;
}
}
return false;
}
}

View File

@ -8,6 +8,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import ch.dissem.apps.abit.listeners.ActionBarListener;
import ch.dissem.apps.abit.service.Singleton;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.entity.BitmessageAddress;
@ -51,7 +52,7 @@ import java.util.ArrayList;
* </p>
*/
public class MessageListActivity extends AppCompatActivity
implements MessageListFragment.Callbacks {
implements MessageListFragment.Callbacks, ActionBarListener {
public static final String EXTRA_SHOW_MESSAGE = "ch.dissem.abit.ShowMessage";
public static final String ACTION_SHOW_INBOX = "ch.dissem.abit.ShowInbox";
@ -157,7 +158,30 @@ public class MessageListActivity extends AppCompatActivity
ArrayList<IDrawerItem> drawerItems = new ArrayList<>();
for (Label label : bmc.messages().getLabels()) {
drawerItems.add(new PrimaryDrawerItem().withName(label.toString()).withTag(label));
PrimaryDrawerItem item = new PrimaryDrawerItem().withName(label.toString()).withTag(label);
switch (label.getType()) {
case INBOX:
item.withIcon(GoogleMaterial.Icon.gmd_inbox);
break;
case DRAFT:
item.withIcon(CommunityMaterial.Icon.cmd_file);
break;
case SENT:
item.withIcon(CommunityMaterial.Icon.cmd_send);
break;
case BROADCAST:
item.withIcon(CommunityMaterial.Icon.cmd_rss);
break;
case UNREAD:
item.withIcon(GoogleMaterial.Icon.gmd_markunread_mailbox);
break;
case TRASH:
item.withIcon(GoogleMaterial.Icon.gmd_delete);
break;
default:
item.withIcon(CommunityMaterial.Icon.cmd_label);
}
drawerItems.add(item);
}
new DrawerBuilder()
@ -168,7 +192,7 @@ public class MessageListActivity extends AppCompatActivity
.addStickyDrawerItems(
new SecondaryDrawerItem()
.withName(getString(R.string.subscriptions))
.withIcon(CommunityMaterial.Icon.cmd_rss),
.withIcon(CommunityMaterial.Icon.cmd_rss_box),
new SecondaryDrawerItem()
.withName(R.string.settings)
.withIcon(GoogleMaterial.Icon.gmd_settings)
@ -254,6 +278,11 @@ public class MessageListActivity extends AppCompatActivity
}
}
@Override
public void updateTitle(CharSequence title) {
getSupportActionBar().setTitle(title);
}
public Label getSelectedLabel() {
return selectedLabel;
}

View File

@ -6,17 +6,17 @@ import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.*;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import ch.dissem.apps.abit.listeners.ActionBarListener;
import ch.dissem.apps.abit.service.Singleton;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.entity.Plaintext;
import ch.dissem.bitmessage.entity.valueobject.Label;
import ch.dissem.bitmessage.ports.MessageRepository;
/**
* A list fragment representing a list of Messages. This fragment
@ -39,12 +39,15 @@ public class MessageListFragment extends ListFragment {
* The fragment's current callback object, which is notified of list item
* clicks.
*/
private Callbacks mCallbacks = sDummyCallbacks;
private Callbacks callbacks = dummyCallbacks;
/**
* The current activated item position. Only used on tablets.
*/
private int mActivatedPosition = ListView.INVALID_POSITION;
private int activatedPosition = ListView.INVALID_POSITION;
private Label currentLabel;
private MenuItem emptyTrashMenuItem;
private BitmessageContext bmc;
@ -64,7 +67,7 @@ public class MessageListFragment extends ListFragment {
* A dummy implementation of the {@link Callbacks} interface that does
* nothing. Used only when this fragment is not attached to an activity.
*/
private static Callbacks sDummyCallbacks = new Callbacks() {
private static Callbacks dummyCallbacks = new Callbacks() {
@Override
public void onItemSelected(Plaintext plaintext) {
}
@ -82,6 +85,7 @@ public class MessageListFragment extends ListFragment {
super.onCreate(savedInstanceState);
bmc = Singleton.getBitmessageContext(getActivity());
setHasOptionsMenu(true);
}
@Override
@ -92,6 +96,7 @@ public class MessageListFragment extends ListFragment {
}
public void updateList(Label label) {
currentLabel = label;
setListAdapter(new ArrayAdapter<Plaintext>(
getActivity(),
android.R.layout.simple_list_item_activated_1,
@ -120,6 +125,12 @@ public class MessageListFragment extends ListFragment {
return convertView;
}
});
if (getActivity() instanceof ActionBarListener) {
((ActionBarListener) getActivity()).updateTitle(label.toString());
}
if (emptyTrashMenuItem != null) {
emptyTrashMenuItem.setVisible(label != null && label.getType() == Label.Type.TRASH);
}
}
@Override
@ -158,7 +169,7 @@ public class MessageListFragment extends ListFragment {
throw new IllegalStateException("Activity must implement fragment's callbacks.");
}
mCallbacks = (Callbacks) activity;
callbacks = (Callbacks) activity;
}
@Override
@ -166,7 +177,31 @@ public class MessageListFragment extends ListFragment {
super.onDetach();
// Reset the active callbacks interface to the dummy implementation.
mCallbacks = sDummyCallbacks;
callbacks = dummyCallbacks;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.message_list, menu);
emptyTrashMenuItem = menu.findItem(R.id.empty_trash);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.empty_trash:
if (currentLabel.getType() != Label.Type.TRASH) return true;
MessageRepository repo = bmc.messages();
for (Plaintext message : repo.findMessages(currentLabel)) {
repo.remove(message);
}
updateList(currentLabel);
return true;
default:
return false;
}
}
@Override
@ -175,15 +210,15 @@ public class MessageListFragment extends ListFragment {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mCallbacks.onItemSelected((Plaintext) listView.getItemAtPosition(position));
callbacks.onItemSelected((Plaintext) listView.getItemAtPosition(position));
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION) {
if (activatedPosition != ListView.INVALID_POSITION) {
// Serialize and persist the activated item position.
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
outState.putInt(STATE_ACTIVATED_POSITION, activatedPosition);
}
}
@ -201,11 +236,11 @@ public class MessageListFragment extends ListFragment {
private void setActivatedPosition(int position) {
if (position == ListView.INVALID_POSITION) {
getListView().setItemChecked(mActivatedPosition, false);
getListView().setItemChecked(activatedPosition, false);
} else {
getListView().setItemChecked(position, true);
}
mActivatedPosition = position;
activatedPosition = position;
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2015 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.listeners;
/**
* Created by chris on 06.09.15.
*/
public interface ActionBarListener {
void updateTitle(CharSequence title);
}

View File

@ -14,9 +14,10 @@
* limitations under the License.
*/
package ch.dissem.apps.abit;
package ch.dissem.apps.abit.listeners;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
@ -33,6 +34,9 @@ import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import ch.dissem.apps.abit.Identicon;
import ch.dissem.apps.abit.MessageListActivity;
import ch.dissem.apps.abit.R;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.entity.Plaintext;

View File

@ -1,7 +1,7 @@
package ch.dissem.apps.abit.service;
import android.content.Context;
import ch.dissem.apps.abit.MessageListener;
import ch.dissem.apps.abit.listeners.MessageListener;
import ch.dissem.apps.abit.repositories.AndroidAddressRepository;
import ch.dissem.apps.abit.repositories.AndroidInventory;
import ch.dissem.apps.abit.repositories.AndroidMessageRepository;

View File

@ -0,0 +1,32 @@
/*
* Copyright 2015 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.utils;
import android.content.Context;
import android.view.Menu;
import ch.dissem.apps.abit.R;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;
/**
* Some helper methods to work with drawables.
*/
public class Drawables {
public static void addIcon(Context ctx, Menu menu, int menuItem, GoogleMaterial.Icon icon) {
menu.findItem(menuItem).setIcon(new IconicsDrawable(ctx, icon).colorRes(R.color.primary_text_default_material_dark).actionBar());
}
}

BIN
app/src/main/res/drawable-hdpi/ic_action_delete.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 642 B

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

BIN
app/src/main/res/drawable-hdpi/ic_action_reply.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 486 B

After

Width:  |  Height:  |  Size: 632 B

BIN
app/src/main/res/drawable-mdpi/ic_action_delete.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 428 B

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

BIN
app/src/main/res/drawable-mdpi/ic_action_reply.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 330 B

After

Width:  |  Height:  |  Size: 412 B

BIN
app/src/main/res/drawable-xhdpi/ic_action_delete.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 775 B

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

BIN
app/src/main/res/drawable-xhdpi/ic_action_reply.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 623 B

After

Width:  |  Height:  |  Size: 849 B

BIN
app/src/main/res/drawable-xxhdpi/ic_action_delete.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 849 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
app/src/main/res/drawable-xxhdpi/ic_action_reply.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 929 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,31 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/android:list"
android:paddingBottom="88dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_compose_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_fab_compose_message"
app:elevation="8dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"/>
</RelativeLayout>

View File

@ -0,0 +1,25 @@
<?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/reply"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_placeholder"
android:title="@string/reply"/>
<item
android:id="@+id/delete"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_placeholder"
android:title="@string/delete"/>
<item
android:id="@+id/mark_unread"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_placeholder"
android:title="@string/mark_unread"/>
<item
android:id="@+id/archive"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_placeholder"
android:title="@string/archive"/>
</menu>

View File

@ -0,0 +1,11 @@
<?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/empty_trash"
app:showAsAction="never"
android:icon="@drawable/ic_action_placeholder"
android:title="@string/empty_trash"
android:visible="false"/>
</menu>

View File

@ -24,4 +24,10 @@
<string name="manage_identity">Identität verwalten</string>
<string name="subscribe">Abonnieren</string>
<string name="title_activity_open_bitmessage_link">Kontakt importieren</string>
<string name="delete">Löschen</string>
<string name="reply">Antworten</string>
<string name="n_new_messages">%d neue Nachrichten</string>
<string name="archive">Archiv</string>
<string name="empty_trash">Papierkorb leeren</string>
<string name="mark_unread">Als ungelesen markieren</string>
</resources>

View File

@ -27,4 +27,7 @@
<string name="n_new_messages">%d new messages</string>
<string name="reply">Reply</string>
<string name="delete">Delete</string>
<string name="mark_unread">Mark unread</string>
<string name="archive">Archive</string>
<string name="empty_trash">Empty Trash</string>
</resources>