Skip to content

Commit

Permalink
Add open URL action
Browse files Browse the repository at this point in the history
  • Loading branch information
nning committed Apr 20, 2017
1 parent 7e5435b commit d289a17
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
23 changes: 18 additions & 5 deletions app/src/main/java/net/orgizm/imgshr/GalleryListActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.orgizm.imgshr;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.support.design.widget.CollapsingToolbarLayout;
Expand Down Expand Up @@ -84,13 +86,24 @@ public void onClick(View v) {
public boolean onContextItemSelected(MenuItem item) {
final int position = adapter.getPosition();

if (item.getItemId() == R.id.delete_from_list) {
galleriesList.remove(position);
adapter.notifyDataSetChanged();
switch (item.getItemId()) {
case R.id.delete_from_list:
galleriesList.remove(position);
adapter.notifyDataSetChanged();

preferences.setLastSlugs(galleriesList);
preferences.setLastSlugs(galleriesList);

Toast.makeText(getApplicationContext(), R.string.gallery_deleted, Toast.LENGTH_SHORT).show();

break;

case R.id.open_url:
Gallery gallery = galleriesList.get(position);
String url = "https://imgshr.space/!" + gallery.getSlug();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
getApplicationContext().startActivity(intent);

Toast.makeText(getApplicationContext(), R.string.gallery_deleted, Toast.LENGTH_SHORT).show();
break;
}

return super.onContextItemSelected(item);
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/net/orgizm/imgshr/GalleryListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GalleryListAdapter extends RecyclerView.Adapter<GalleryListAdapter.
private List<Gallery> galleriesList;
private int position;

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnCreateContextMenuListener {
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnCreateContextMenuListener, View.OnClickListener {
public TextView slug;

public ViewHolder(View view) {
Expand All @@ -23,13 +23,20 @@ public ViewHolder(View view) {
slug = (TextView) view.findViewById(R.id.slug);

view.setOnCreateContextMenuListener(this);
view.setOnClickListener(this);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
Gallery gallery = galleriesList.get(this.getAdapterPosition());
menu.setHeaderTitle(gallery.getSlug());
menu.add(Menu.NONE, R.id.delete_from_list, Menu.NONE, R.string.delete_from_list);
menu.add(Menu.NONE, R.id.open_url, Menu.NONE, R.string.open_url);
}

@Override
public void onClick(View view) {
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/menu/gallery_context_menu.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/delete_from_list" android:title="@string/delete_from_list"/>
<item android:id="@+id/open_url" android:title="@string/open_url"/>
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<string name="saved_slug">Saved slug!</string>
<string name="delete_from_list">Delete from list</string>
<string name="gallery_deleted">Gallery deleted!</string>
<string name="open_url">Open URL</string>
</resources>

0 comments on commit d289a17

Please sign in to comment.