Skip to content

Commit

Permalink
Toggle icon loading from the views menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxbits committed Jul 20, 2014
1 parent 1dff949 commit 880d1d4
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 11 deletions.
1 change: 1 addition & 0 deletions .classpath
Expand Up @@ -7,6 +7,7 @@
<classpathentry kind="lib" path="libs/httpcore-4.2.2.jar"/>
<classpathentry kind="lib" path="libs/protobuf-java-2.5.0.jar"/>
<classpathentry kind="lib" path="libs/commons-cli-1.2.jar"/>
<classpathentry kind="lib" path="libs/commons-io-2.4.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
5 changes: 5 additions & 0 deletions src/main/java/de/onyxbits/raccoon/App.java
Expand Up @@ -32,6 +32,11 @@ public class App {
*/
public static final String ARCHIVEDIR = "archives";

/**
* Relative path to the homedir for caching files.
*/
public static final String CACHEDIR = "cache";

/**
* Relative path, root directory for the app.
*/
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/de/onyxbits/raccoon/gui/MainActivity.java
Expand Up @@ -17,6 +17,7 @@
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
Expand Down Expand Up @@ -47,6 +48,11 @@ public class MainActivity extends JFrame implements ActionListener, WindowListen
*/
public static final String LASTARCHIVE = "lastarchive"; //$NON-NLS-1$

/**
* Preferences key for whether or not to fetch icons.
*/
public static final String FETCHICONS = "fetchicons"; //$NON-NLS-1$

private JMenuItem quit;
private JMenuItem open;
private JMenuItem search;
Expand All @@ -55,6 +61,7 @@ public class MainActivity extends JFrame implements ActionListener, WindowListen
private JMenuItem downloads;
private JMenuItem contents;
private JMenuItem newArchive;
private JRadioButtonMenuItem fetchIcons;

private JTabbedPane views;
private ListView downloadList;
Expand Down Expand Up @@ -97,6 +104,9 @@ public MainActivity(Archive archive) {
Messages.getString("MainActivity.29"), KeyStroke.getKeyStroke(Messages.getString("MainActivity.30")) //$NON-NLS-1$ //$NON-NLS-2$
.getKeyCode());
newArchive.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));

Preferences prefs = Preferences.userNodeForPackage(getClass());
fetchIcons = new JRadioButtonMenuItem(Messages.getString("MainActivity.34"), prefs.getBoolean(FETCHICONS, false)); //$NON-NLS-1$
file.add(newArchive);
file.add(open);
file.add(new JSeparator());
Expand All @@ -116,6 +126,8 @@ public MainActivity(Archive archive) {
downloads.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK));
view.add(search);
view.add(downloads);
view.add(new JSeparator());
view.add(fetchIcons);
search.setEnabled(false);
downloads.setEnabled(false);
bar.add(view);
Expand Down Expand Up @@ -152,6 +164,7 @@ public void run() {
contents.addActionListener(this);
downloads.addActionListener(this);
updates.addActionListener(this);
fetchIcons.addActionListener(this);
addWindowListener(this);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
doMount(archive);
Expand Down Expand Up @@ -188,11 +201,17 @@ public void actionPerformed(ActionEvent event) {
views.setSelectedIndex(0);
searchView.doUpdateSearch();
}
if (src == fetchIcons) {
Preferences prefs = Preferences.userNodeForPackage(getClass());
prefs.putBoolean(FETCHICONS, fetchIcons.isSelected());
}
}

private void doNewArchive() {
String res = JOptionPane.showInputDialog(this,
Messages.getString("MainActivity.32"), Messages.getString("MainActivity.31"), JOptionPane.QUESTION_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
String res = JOptionPane
.showInputDialog(
this,
Messages.getString("MainActivity.32"), Messages.getString("MainActivity.31"), JOptionPane.QUESTION_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
if (res != null && res.length() > 0) {
File file = new File(App.getDir(App.ARCHIVEDIR), res);
MainActivity ma = new MainActivity(new Archive(file));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/onyxbits/raccoon/gui/ResultView.java
Expand Up @@ -5,6 +5,7 @@
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -111,6 +112,10 @@ private ResultView(SearchView searchView, DocV2 doc) {
model.put("cover_date", doc.getDetails().getAppDetails().getUploadDate()); //$NON-NLS-1$
model.put("cover_size", Archive.humanReadableByteCount(doc.getDetails().getAppDetails() //$NON-NLS-1$
.getInstallationSize(), true));
File icon = SearchWorker.getImageCacheFile(doc.getBackendDocid(),4);
if (icon.exists()) {
model.put("cover_icon",icon.toURI());
}

List<String> perms = doc.getDetails().getAppDetails().getPermissionList();
if (perms.size() > 0) {
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/de/onyxbits/raccoon/gui/SearchWorker.java
@@ -1,16 +1,23 @@
package de.onyxbits.raccoon.gui;

import java.io.File;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import java.util.concurrent.ExecutionException;
import java.util.prefs.Preferences;

import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;

import org.apache.commons.io.FileUtils;

import com.akdeniz.googleplaycrawler.GooglePlay.BulkDetailsEntry;
import com.akdeniz.googleplaycrawler.GooglePlay.BulkDetailsResponse;
import com.akdeniz.googleplaycrawler.GooglePlay.DocV2;
import com.akdeniz.googleplaycrawler.GooglePlay.Image;
import com.akdeniz.googleplaycrawler.GooglePlay.SearchResponse;
import com.akdeniz.googleplaycrawler.GooglePlayAPI;
import com.akdeniz.googleplaycrawler.GooglePlayException;
Expand All @@ -33,6 +40,7 @@ class SearchWorker extends SwingWorker<Vector<BulkDetailsEntry>, String> {
private int limit;
private String localization;
private Archive archive;
private boolean fetchIcons;

/**
*
Expand All @@ -54,6 +62,8 @@ public SearchWorker(Archive archive, String search, SearchView callback) {
if (callback == null) {
throw new NullPointerException();
}
Preferences prefs = Preferences.userNodeForPackage(MainActivity.class);
fetchIcons = prefs.getBoolean(MainActivity.FETCHICONS, false);
}

/**
Expand Down Expand Up @@ -113,6 +123,9 @@ private Vector<BulkDetailsEntry> doUpdateSearch() throws Exception {
if (!archive.fileUnder(pn, vc).exists()) {
ret.add(bulkDetailsEntry);
}
if (fetchIcons) {
fetchIcon(doc);
}
}
return ret;
}
Expand All @@ -127,6 +140,9 @@ private Vector<BulkDetailsEntry> doQuerySearch() throws Exception {
DocV2 all = response.getDoc(0);
for (int i = 0; i < all.getChildCount(); i++) {
apps.add(all.getChild(i).getBackendDocid());
if (fetchIcons) {
fetchIcon(all.getChild(i));
}
}
}
BulkDetailsResponse bdr = service.bulkDetails(apps);
Expand All @@ -137,6 +153,40 @@ private Vector<BulkDetailsEntry> doQuerySearch() throws Exception {
return ret;
}

private void fetchIcon(DocV2 doc) {
List<Image> lst = doc.getImageList();
Iterator<Image> it = lst.iterator();
while (it.hasNext()) {
Image img = it.next();
if (img.getImageType() == 4) {
try {
File f = getImageCacheFile(doc.getBackendDocid(), 4);
if (!f.exists()) {
URL u = new URL(img.getImageUrl());
FileUtils.copyURLToFile(u, f);
}
f.deleteOnExit();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}

/**
* Figure out where to images
*
* @param appId
* package id
* @param type
* the numerical type of the image
* @return where to cache the image.
*/
public static File getImageCacheFile(String appId, int type) {
return new File(App.getDir(App.CACHEDIR), appId + "-img-" + type);
}

@Override
protected void done() {
Vector<BulkDetailsEntry> response = new Vector<BulkDetailsEntry>();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/onyxbits/raccoon/gui/TmplTool.java
Expand Up @@ -3,6 +3,8 @@
import java.io.InputStream;
import java.util.HashMap;

import org.apache.commons.io.IOUtils;

import com.floreysoft.jmte.Engine;

/**
Expand Down Expand Up @@ -43,9 +45,7 @@ private static String getTemplate(String path) {
String tmpl = ""; //$NON-NLS-1$
try {
InputStream ins = new Object().getClass().getResourceAsStream(path);
byte[] b = new byte[ins.available()];
ins.read(b);
tmpl = new String(b);
tmpl = IOUtils.toString(ins,"UTF-8");
ins.close();
}
catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/rsrc/messages.properties
Expand Up @@ -42,6 +42,7 @@ MainActivity.30=N
MainActivity.3=Open archive
MainActivity.31=New Archive
MainActivity.32=Name
MainActivity.34=Fetch icons
MainActivity.4=Close
MainActivity.5=Updates
MainActivity.6=View
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/rsrc/messages_de.properties
Expand Up @@ -38,6 +38,7 @@ MainActivity.28=alt I
MainActivity.29=Neues Archiv
MainActivity.30=N
MainActivity.31=Neues Archiv
MainActivity.34=Icons laden
MainActivity.3=Archiv \u00F6ffnen
MainActivity.4=Schliessen
MainActivity.6=Ansicht
Expand All @@ -48,7 +49,7 @@ ResultView.1=Installationen
ResultView.3=Bewertung
ResultView.5=Preis
ResultView.7=Ver\u00F6ffentlicht
ResultView.9=Gr\u00F6\u00dfe
ResultView.9=Gr\u00F6\u00DFe
ResultView.22=Keine Berechtigungen deklariert.
ResultView.27=Berechtigungen
ResultView.84=Internet Zugang
Expand Down
16 changes: 11 additions & 5 deletions src/main/resources/rsrc/templates/cover.html
Expand Up @@ -18,11 +18,17 @@
}
</style>
<body>
<u>
<h1>${cover_title}</h1>
</u>
<strong>${cover_author}</strong> |
<code>${cover_package}</code>
<table style="border: none">
<tr>
${if cover_icon}
<td><img src="${cover_icon}" width="100" height="100"></td>
${end}

<td valign="top"><u>
<h1>${cover_title}</h1>
</u> <strong>${cover_author}</strong><br><code>${cover_package}</code></td>
</tr>
</table>
<p>
<table>
<tr>
Expand Down

0 comments on commit 880d1d4

Please sign in to comment.