Skip to content

Commit

Permalink
Popup menu for blocks, replacing the ActionMode.
Browse files Browse the repository at this point in the history
  • Loading branch information
schildbach committed Jul 4, 2015
1 parent 29c17ae commit 2d6768c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
12 changes: 12 additions & 0 deletions wallet/res/layout/block_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
android:id="@+id/block_list_row_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Space
android:layout_width="24dp"
android:layout_height="0px" />
</LinearLayout>

<TextView
Expand All @@ -41,6 +45,14 @@
android:paddingTop="2dp" />
</LinearLayout>

<ImageButton
android:id="@+id/block_list_row_menu"
style="@style/My.Widget.Button.Borderless.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:src="@drawable/ic_more_vert_grey600_18dp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
Expand Down
9 changes: 6 additions & 3 deletions wallet/src/de/schildbach/wallet/ui/BlockListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import de.schildbach.wallet.AddressBookProvider;
import de.schildbach.wallet.util.WalletUtils;
Expand Down Expand Up @@ -189,12 +190,12 @@ public void onBindViewHolder(final BlockViewHolder holder, final int position)

if (onClickListener != null)
{
holder.itemView.setOnClickListener(new View.OnClickListener()
holder.menuView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
onClickListener.onClick(storedBlock);
onClickListener.onBlockMenuClick(v, storedBlock);
}
});
}
Expand Down Expand Up @@ -245,7 +246,7 @@ else if (address != null)

public interface OnClickListener
{
void onClick(StoredBlock block);
void onBlockMenuClick(View view, StoredBlock block);
}

public static class BlockViewHolder extends RecyclerView.ViewHolder
Expand All @@ -254,6 +255,7 @@ public static class BlockViewHolder extends RecyclerView.ViewHolder
private final TextView heightView;
private final TextView timeView;
private final TextView hashView;
private final ImageButton menuView;

private BlockViewHolder(final View itemView)
{
Expand All @@ -263,6 +265,7 @@ private BlockViewHolder(final View itemView)
heightView = (TextView) itemView.findViewById(R.id.block_list_row_height);
timeView = (TextView) itemView.findViewById(R.id.block_list_row_time);
hashView = (TextView) itemView.findViewById(R.id.block_list_row_hash);
menuView = (ImageButton) itemView.findViewById(R.id.block_list_row_menu);
}
}
}
40 changes: 9 additions & 31 deletions wallet/src/de/schildbach/wallet/ui/BlockListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.ViewAnimator;
import de.schildbach.wallet.Configuration;
import de.schildbach.wallet.Constants;
Expand Down Expand Up @@ -173,49 +172,28 @@ public void onDestroy()
}

@Override
public void onClick(final StoredBlock block)
public void onBlockMenuClick(final View view, final StoredBlock block)
{
activity.startActionMode(new ActionMode.Callback()
{
@Override
public boolean onCreateActionMode(final ActionMode mode, final Menu menu)
{
final MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.blocks_context, menu);

return true;
}

@Override
public boolean onPrepareActionMode(final ActionMode mode, final Menu menu)
{
mode.setTitle(Integer.toString(block.getHeight()));
mode.setSubtitle(block.getHeader().getHashAsString());

return true;
}
final PopupMenu popupMenu = new PopupMenu(activity, view);
popupMenu.inflate(R.menu.blocks_context);

popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener()
{
@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item)
public boolean onMenuItemClick(final MenuItem item)
{
switch (item.getItemId())
{
case R.id.blocks_context_browse:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "block/"
+ block.getHeader().getHashAsString())));

mode.finish();
return true;
}

return false;
}

@Override
public void onDestroyActionMode(final ActionMode mode)
{
}
});
popupMenu.show();
}

private final ServiceConnection serviceConnection = new ServiceConnection()
Expand Down

0 comments on commit 2d6768c

Please sign in to comment.