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. 59
      Clover/app/src/main/java/org/floens/chan/ui/activity/ImageViewActivity.java
  3. 52
      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.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import org.floens.chan.R;
import org.floens.chan.chan.ImageSearch;
import org.floens.chan.core.ChanPreferences;
import org.floens.chan.core.model.Post;
import org.floens.chan.ui.adapter.ImageViewAdapter;
@ -195,35 +197,36 @@ public class ImageViewActivity extends Activity implements ViewPager.OnPageChang
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else if (item.getItemId() == R.id.action_download_album) {
List<ImageSaver.DownloadPair> list = new ArrayList<>();
String name = "downloaded";
String filename;
for (Post post : adapter.getList()) {
filename = (ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename) + "." + post.ext;
list.add(new ImageSaver.DownloadPair(post.imageUrl, filename));
name = post.board + "_" + post.resto;
}
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_download_album:
List<ImageSaver.DownloadPair> list = new ArrayList<>();
String name = "downloaded";
String filename;
for (Post post : adapter.getList()) {
filename = (ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename) + "." + post.ext;
list.add(new ImageSaver.DownloadPair(post.imageUrl, filename));
name = post.board + "_" + post.resto;
}
if (list.size() > 0) {
if (!TextUtils.isEmpty(name)) {
ImageSaver.saveAll(this, name, list);
if (list.size() > 0) {
if (!TextUtils.isEmpty(name)) {
ImageSaver.saveAll(this, name, list);
}
}
}
return true;
} else {
ImageViewFragment fragment = getFragment(currentPosition);
if (fragment != null) {
fragment.customOnOptionsItemSelected(item);
}
return true;
default:
ImageViewFragment fragment = getFragment(currentPosition);
if (fragment != null) {
fragment.customOnOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
return super.onOptionsItemSelected(item);
}
}
@ -231,6 +234,12 @@ public class ImageViewActivity extends Activity implements ViewPager.OnPageChang
public boolean onCreateOptionsMenu(Menu 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;
}

@ -28,6 +28,7 @@ import android.view.ViewGroup;
import android.widget.VideoView;
import org.floens.chan.R;
import org.floens.chan.chan.ImageSearch;
import org.floens.chan.core.ChanPreferences;
import org.floens.chan.core.model.Post;
import org.floens.chan.ui.activity.ImageViewActivity;
@ -209,27 +210,42 @@ public class ImageViewFragment extends Fragment implements ThumbnailImageViewCal
}
public void customOnOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_image_play_state) {
if (!videoVisible) {
startVideo();
} else {
VideoView view = imageView.getVideoView();
if (view != null) {
if (!view.isPlaying()) {
view.start();
} else {
view.pause();
switch (item.getItemId()) {
case R.id.action_image_play_state:
if (!videoVisible) {
startVideo();
} else {
VideoView view = imageView.getVideoView();
if (view != null) {
if (!view.isPlaying()) {
view.start();
} else {
view.pause();
}
}
}
activity.invalidateActionBar();
break;
case R.id.action_open_browser:
Utils.openLink(context, post.imageUrl);
break;
case R.id.action_image_save:
ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, false);
break;
case R.id.action_share:
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;
}
}
}
activity.invalidateActionBar();
} else if (item.getItemId() == R.id.action_open_browser) {
Utils.openLink(context, post.imageUrl);
} else if (item.getItemId() == R.id.action_image_save) {
ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, false);
} else if (item.getItemId() == R.id.action_share) {
ImageSaver.saveImage(context, post.imageUrl, ChanPreferences.getImageSaveOriginalFilename() ? post.tim : post.filename, post.ext, true);
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/
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:orderInCategory="1"
android:showAsAction="always"
android:title="@string/image_play_state"/>
android:title="@string/image_play_state" />
<item
android:id="@+id/action_image_save"
android:orderInCategory="2"
android:showAsAction="never"
android:title="@string/image_save"/>
android:title="@string/image_save" />
<item
android:id="@+id/action_open_browser"
android:orderInCategory="3"
android:showAsAction="never"
android:title="@string/action_open_browser"/>
android:title="@string/action_open_browser" />
<item
android:id="@+id/action_share"
android:orderInCategory="4"
android:showAsAction="never"
android:title="@string/action_share"/>
android:title="@string/action_share" />
<item
android:id="@+id/action_download_album"
android:id="@+id/action_image_search"
android:orderInCategory="5"
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>

@ -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_board">Search board</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_results">Found %1$s %2$s for "%3$s"</string>

Loading…
Cancel
Save