Added reverse image search.

Closes #14
captchafix
Florens Douwes 11 years ago
parent 902d661e0e
commit bce8131422
  1. 61
      Clover/app/src/main/java/org/floens/chan/chan/ImageSearch.java
  2. 15
      Clover/app/src/main/java/org/floens/chan/ui/activity/ImageViewActivity.java
  3. 24
      Clover/app/src/main/java/org/floens/chan/ui/fragment/ImageViewFragment.java
  4. 22
      Clover/app/src/main/res/menu/image_view.xml
  5. 30
      Clover/app/src/main/res/values/ids.xml
  6. 1
      Clover/app/src/main/res/values/strings.xml

@ -0,0 +1,61 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.chan;
import org.floens.chan.R;
import java.util.ArrayList;
import java.util.List;
public abstract class ImageSearch {
public static final List<ImageSearch> engines = new ArrayList<>();
public abstract int getId();
public abstract String getName();
public abstract String getUrl(String imageUrl);
static {
engines.add(new ImageSearch() {
public int getId() {
return R.id.action_0;
}
public String getName() {
return "Google";
}
public String getUrl(String imageUrl) {
return "https://www.google.com/searchbyimage?image_url=" + imageUrl;
}
});
engines.add(new ImageSearch() {
public int getId() {
return R.id.action_1;
}
public String getName() {
return "iqdb";
}
public String getUrl(String imageUrl) {
return "http://iqdb.org/?url=" + imageUrl;
}
});
}
}

@ -24,12 +24,14 @@ import android.support.v4.view.ViewPager;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.chan.ImageSearch;
import org.floens.chan.core.ChanPreferences; import org.floens.chan.core.ChanPreferences;
import org.floens.chan.core.model.Post; import org.floens.chan.core.model.Post;
import org.floens.chan.ui.adapter.ImageViewAdapter; import org.floens.chan.ui.adapter.ImageViewAdapter;
@ -195,10 +197,11 @@ public class ImageViewActivity extends Activity implements ViewPager.OnPageChang
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) { switch (item.getItemId()) {
case android.R.id.home:
finish(); finish();
return true; return true;
} else if (item.getItemId() == R.id.action_download_album) { case R.id.action_download_album:
List<ImageSaver.DownloadPair> list = new ArrayList<>(); List<ImageSaver.DownloadPair> list = new ArrayList<>();
String name = "downloaded"; String name = "downloaded";
@ -217,7 +220,7 @@ public class ImageViewActivity extends Activity implements ViewPager.OnPageChang
} }
return true; return true;
} else { default:
ImageViewFragment fragment = getFragment(currentPosition); ImageViewFragment fragment = getFragment(currentPosition);
if (fragment != null) { if (fragment != null) {
fragment.customOnOptionsItemSelected(item); fragment.customOnOptionsItemSelected(item);
@ -231,6 +234,12 @@ public class ImageViewActivity extends Activity implements ViewPager.OnPageChang
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.image_view, menu); getMenuInflater().inflate(R.menu.image_view, menu);
MenuItem imageSearch = menu.findItem(R.id.action_image_search);
SubMenu subMenu = imageSearch.getSubMenu();
for (ImageSearch engine : ImageSearch.engines) {
subMenu.add(Menu.NONE, engine.getId(), Menu.NONE, engine.getName());
}
return true; return true;
} }

@ -28,6 +28,7 @@ import android.view.ViewGroup;
import android.widget.VideoView; import android.widget.VideoView;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.chan.ImageSearch;
import org.floens.chan.core.ChanPreferences; import org.floens.chan.core.ChanPreferences;
import org.floens.chan.core.model.Post; import org.floens.chan.core.model.Post;
import org.floens.chan.ui.activity.ImageViewActivity; import org.floens.chan.ui.activity.ImageViewActivity;
@ -209,7 +210,8 @@ public class ImageViewFragment extends Fragment implements ThumbnailImageViewCal
} }
public void customOnOptionsItemSelected(MenuItem item) { public void customOnOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_image_play_state) { switch (item.getItemId()) {
case R.id.action_image_play_state:
if (!videoVisible) { if (!videoVisible) {
startVideo(); startVideo();
} else { } else {
@ -224,12 +226,26 @@ public class ImageViewFragment extends Fragment implements ThumbnailImageViewCal
} }
activity.invalidateActionBar(); activity.invalidateActionBar();
} else if (item.getItemId() == R.id.action_open_browser) { break;
case R.id.action_open_browser:
Utils.openLink(context, post.imageUrl); Utils.openLink(context, post.imageUrl);
} else if (item.getItemId() == R.id.action_image_save) { break;
case R.id.action_image_save:
ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, false); ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, false);
} else if (item.getItemId() == R.id.action_share) { break;
case R.id.action_share:
ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, true); ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, true);
break;
default:
// Search if it was an ImageSearch item
for (ImageSearch engine : ImageSearch.engines) {
if (item.getItemId() == engine.getId()) {
Utils.openLink(context, engine.getUrl(post.imageUrl));
break;
}
}
break;
} }
} }

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?><!--
<!--
Clover - 4chan browser https://github.com/Floens/Clover/ Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens Copyright (C) 2014 Floens
@ -23,26 +22,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:icon="@drawable/ic_action_play" android:icon="@drawable/ic_action_play"
android:orderInCategory="1" android:orderInCategory="1"
android:showAsAction="always" android:showAsAction="always"
android:title="@string/image_play_state"/> android:title="@string/image_play_state" />
<item <item
android:id="@+id/action_image_save" android:id="@+id/action_image_save"
android:orderInCategory="2" android:orderInCategory="2"
android:showAsAction="never" android:showAsAction="never"
android:title="@string/image_save"/> android:title="@string/image_save" />
<item <item
android:id="@+id/action_open_browser" android:id="@+id/action_open_browser"
android:orderInCategory="3" android:orderInCategory="3"
android:showAsAction="never" android:showAsAction="never"
android:title="@string/action_open_browser"/> android:title="@string/action_open_browser" />
<item <item
android:id="@+id/action_share" android:id="@+id/action_share"
android:orderInCategory="4" android:orderInCategory="4"
android:showAsAction="never" android:showAsAction="never"
android:title="@string/action_share"/> android:title="@string/action_share" />
<item <item
android:id="@+id/action_download_album" android:id="@+id/action_image_search"
android:orderInCategory="5" android:orderInCategory="5"
android:showAsAction="never" android:showAsAction="never"
android:title="@string/action_download_album"/> android:title="@string/action_search_image">
<menu></menu>
</item>
<item
android:id="@+id/action_download_album"
android:orderInCategory="6"
android:showAsAction="never"
android:title="@string/action_download_album" />
</menu> </menu>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?><!--
Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
<!-- placeholder id's for when programmatically xml is needed -->
<item type="id" name="action_0" />
<item type="id" name="action_1" />
<item type="id" name="action_2" />
<item type="id" name="action_3" />
<item type="id" name="action_4" />
<item type="id" name="action_5" />
<item type="id" name="action_6" />
<item type="id" name="action_7" />
<item type="id" name="action_8" />
<item type="id" name="action_9" />
</resources>

@ -44,6 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="action_search">Search</string> <string name="action_search">Search</string>
<string name="action_search_board">Search board</string> <string name="action_search_board">Search board</string>
<string name="action_search_thread">Search thread</string> <string name="action_search_thread">Search thread</string>
<string name="action_search_image">Image search</string>
<string name="search_hint">Search posts</string> <string name="search_hint">Search posts</string>
<string name="search_results">Found %1$s %2$s for "%3$s"</string> <string name="search_results">Found %1$s %2$s for "%3$s"</string>

Loading…
Cancel
Save