From 00f9b3815ec14ac817ec969f772f5b9616923744 Mon Sep 17 00:00:00 2001 From: Shinovon Date: Sun, 26 Dec 2021 16:48:57 +0500 Subject: [PATCH] r3.1 & UI Changes and optimizations (pre r3.2) --- Application Descriptor | 2 +- res/jtlng.cn | Bin 0 -> 1111 bytes src/App.java | 96 ++++++++++++++++------ src/IScheduledShowHide.java | 7 ++ src/Locale.java | 16 ++-- src/LocaleConstants.java | 1 + src/Settings.java | 9 +- src/cc/nnproject/utils/PlatformUtils.java | 14 +++- src/models/ChannelModel.java | 2 +- src/models/VideoModel.java | 64 ++++++++++----- src/ui/AppUI.java | 24 ++++-- src/ui/ChannelForm.java | 33 ++++++-- src/ui/SettingsForm.java | 8 ++ src/ui/VideoForm.java | 1 + src/ui/custom/VideoItem.java | 67 +++++++-------- 15 files changed, 239 insertions(+), 105 deletions(-) create mode 100644 res/jtlng.cn create mode 100644 src/IScheduledShowHide.java diff --git a/Application Descriptor b/Application Descriptor index 8d973dc..5cf701c 100644 --- a/Application Descriptor +++ b/Application Descriptor @@ -1,4 +1,4 @@ -MIDlet-Version: 1.4.0 +MIDlet-Version: 1.4.2 MicroEdition-Configuration: CLDC-1.0 Nokia-MIDlet-UID-1: 0xAFCE0816 MIDlet-Name: JTube diff --git a/res/jtlng.cn b/res/jtlng.cn new file mode 100644 index 0000000000000000000000000000000000000000..64eef47f5b0e4285355cbdfa031c9f71310ce445 GIT binary patch literal 1111 zcmYjQTUQfT7~PdNHEk4)Shck}R$IXfcxh?1^?q5>wYusm{sEUh$b;hY_TW>ZhGfWP zK$5VK6iE<>NHP&HL|~FXGvAprPyPh`CKFh`?Q_m|&i?kd_W|Jh`}*VCJ$ICQy*GM# z@dZ3GU$BfK*1;nNGS)&4O=yzY7`}vuw6rKk@D-zK%nk(LVH92>Z317zVmoKdHO?9v`AOrgrH0YW zH7_Um5j!_%2Zyi;%@hfXc#a|^@h<4}wE43wS&mYF4Sx9Tsk9wX<#ZoklnZ$~tYHhk z`YJ8wVrYSnLS=I~EsIr0=T`Wfo(#hpEs~MKcWCLl^Qh-$Pw&I~%DJmu3Khr9Y82bx zXHs){!W!rknK<=lX(W&B@Y86OyLAspja#f?2e#3uK}DvSu*QQ*YghNb%JHL}oo)D@ z2VBgF$Rd7NLp#^dkBnRyySPnlSj^^REn&TQhTS}jx*a?cspp_Lcj^N6@JS{h(j`|g zep;<;toOo8{o^dqtQ4>hJ~{owF=jR^QYHM1O_a_sO@~>Dy9mGVg~d7224yyn{cMb; z$yy1mY+fxZf;!rmyEY~glQ@9wc5+1O`iGUERZyuKvcqwyr`p@wageF%RqhrJ!OMt> zFKA#8hv9V(9c}GyEDQr3b!yiS9AVGgz#U!nh+e&w3zIm;Ws(1BI!duLj-yG$2kT}myMZSn>gLdfB$sj49~AvG7YWq4bM8(IgxgI#JN?U z8{gwRi**z7x!4Qvn#&>kY)hUTXXJ@e|LrJ>&oY literal 0 HcmV?d00001 diff --git a/src/App.java b/src/App.java index a186036..3084e78 100644 --- a/src/App.java +++ b/src/App.java @@ -1,16 +1,13 @@ import java.io.IOException; -import java.io.OutputStream; import java.util.Vector; import javax.microedition.io.ConnectionNotFoundException; -import javax.microedition.io.Connector; -import javax.microedition.io.file.FileConnection; import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Display; -import javax.microedition.media.Manager; -import javax.microedition.media.Player; +import javax.microedition.lcdui.Displayable; +import javax.microedition.lcdui.Form; import ui.AppUI; import ui.TestCanvas; @@ -21,11 +18,10 @@ import cc.nnproject.json.JSONObject; import cc.nnproject.json.AbstractJSON; import cc.nnproject.json.JSONException; -import cc.nnproject.utils.PlatformUtils; public class App implements Constants { - public static final String ver = "r3"; + public static final String ver = "r3 patch2"; // Settings public static String videoRes; @@ -44,12 +40,13 @@ public class App implements Constants { public static boolean rmsPreviews; public static boolean searchPlaylists; public static String customLocale; + public static boolean debugMemory; public static App inst; public static App2 midlet; private AppUI ui; - private static PlayerCanvas playerCanv; + //private static PlayerCanvas playerCanv; public static boolean asyncLoading; @@ -72,12 +69,22 @@ public void run() { tasksLock.wait(); } while(queuedTasks.size() > 0) { + Object o = queuedTasks.elementAt(0); + queuedTasks.removeElementAt(0); try { - ((Runnable)queuedTasks.elementAt(0)).run(); + if(o instanceof Runnable) ((Runnable)o).run(); + else if(o instanceof Object[]) { + Object[] oo = (Object[]) o; + IScheduledShowHide i = (IScheduledShowHide) oo[0]; + boolean b = ((Boolean) oo[1]).booleanValue(); + if(b) { + i.show(); + } else { + i.hide(); + } + } } catch (Exception e) { - e.printStackTrace(); } - queuedTasks.removeElementAt(0); Thread.yield(); } } catch (InterruptedException e) { @@ -87,9 +94,11 @@ public void run() { } }; - public void scheduleRunnable(Runnable r) { - if(queuedTasks.contains(r)) return; - queuedTasks.addElement(r); + private int startSys; + + public void schedule(Object o) { + if(queuedTasks.contains(o)) return; + queuedTasks.addElement(o); synchronized(tasksLock) { tasksLock.notify(); } @@ -99,6 +108,10 @@ public void scheduleRunnable(Runnable r) { public static int height; public void startApp() { + String p = System.getProperty("com.nokia.memoryramfree"); + if(p != null) { + startSys = Integer.parseInt(p)/1024; + } region = System.getProperty("user.country"); if(region == null) { region = System.getProperty("microedition.locale"); @@ -137,6 +150,41 @@ public void startApp() { t0.start(); } ui.loadForm(); + if(debugMemory) { + Thread t = new Thread() { + public void run() { + try { + while(true) { + Displayable d = AppUI.display.getCurrent(); + if(d != null && d instanceof Form) { + Runtime r = Runtime.getRuntime(); + int t = (int) (r.totalMemory() / 1024); + int f = (int) (r.freeMemory() / 1024); + int m = t - f; + String p = System.getProperty("com.nokia.memoryramfree"); + String sys = ""; + if(p != null) { + int sy = Integer.parseInt(p)/1024; + String sysfree = "" + (int)((sy/1024D)*10)/10D; + String syst = "" + (startSys/1024); + String sysalloc = "" + (startSys - sy)/1024; + sys = sysalloc + "/" + syst+ "-" + sysfree; + } + //long gt = System.currentTimeMillis(); + App.gc(); + //gt = System.currentTimeMillis() - gt; + String s = ((int)((m/1024D)*10)/10D) + "/" + ((int)((t/1024D)*10)/10D) + "-" + ((int)((f/1024D)*10)/10D) + " s:" + sys/* + " gc:" + gt*/; + ((Form)d).setTitle(s); + } + Thread.sleep(1000); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + t.start(); + } } private void initUI() { @@ -304,16 +352,17 @@ public static void download(final String id) { } public static void watch(final String id) { - ILoader r = new ILoader() { + System.out.println("watch"); + /*ILoader r = new ILoader() { public void load() { - // TODO other variants + // TODO other variants*/ try { String url = getVideoLink(id, videoRes); - switch(watchMethod) { - case 0: { + //switch(watchMethod) { + //case 0: { platReq(url); - break; - } + //break; + /*} case 1: { Player p = Manager.createPlayer(url); playerCanv = new PlayerCanvas(p); @@ -352,16 +401,17 @@ public void load() { platReq(file); break; } - } + }*/ } catch (Exception e) { e.printStackTrace(); error(null, Errors.App_watch, e); } - } + /*} }; - inst.stopDoingAsyncTasks(); inst.addAsyncLoad(r); inst.notifyAsyncTasks(); + */ + inst.stopDoingAsyncTasks(); } public static void gc() { diff --git a/src/IScheduledShowHide.java b/src/IScheduledShowHide.java new file mode 100644 index 0000000..9c78809 --- /dev/null +++ b/src/IScheduledShowHide.java @@ -0,0 +1,7 @@ + +public interface IScheduledShowHide { + + public void show(); + public void hide(); + +} diff --git a/src/Locale.java b/src/Locale.java index a29a18b..858a87c 100644 --- a/src/Locale.java +++ b/src/Locale.java @@ -54,7 +54,10 @@ public static void init() { try { int i; while( (i = d.readShort()) != -1) { - table.put(new Integer(i), d.readUTF()); + Integer n = new Integer(i); + String sl = d.readUTF(); + if(table.containsKey(n)) continue; + table.put(n, sl); } } catch (IOException e) { e.printStackTrace(); @@ -81,11 +84,12 @@ public static void init() { } public static String s(int c) { - if(loaded) { - return (String) table.get(new Integer(c)); + Integer i = new Integer(c); + if(loaded && table.containsKey(i)) { + return (String) table.get(i); } // Автор - if(c == 0) { + if(c == 0 && !loaded) { return "Shinovon"; } switch(localei) { @@ -221,6 +225,8 @@ public static String s(int c) { return "(Used only if http streaming is on)"; case SET_Tip2: return "(Leave images proxy empty if HTTPS is supported)"; + case BTN_Playlists: + return "Playlists"; } } case 1: { @@ -254,7 +260,7 @@ public static String s(int c) { case CMD_Videos: return "Видео"; case CMD_ViewChannel: - return "View channel"; + return "Открыть канал"; case CMD_SwitchToPopular: return "Сменить на популярные"; case CMD_SwitchToTrends: diff --git a/src/LocaleConstants.java b/src/LocaleConstants.java index b811330..615fe10 100644 --- a/src/LocaleConstants.java +++ b/src/LocaleConstants.java @@ -72,5 +72,6 @@ public interface LocaleConstants { public static final int SET_VQ_NoAudio = 68; public static final int SET_Tip1 = 69; public static final int SET_Tip2 = 70; + public static final int BTN_Playlists = 71; } diff --git a/src/Settings.java b/src/Settings.java index 208277b..9f9e380 100644 --- a/src/Settings.java +++ b/src/Settings.java @@ -106,7 +106,7 @@ else if(downloadDir.startsWith("file:///")) } else { App.asyncLoading = true; } - if(PlatformUtils.isSymbianTouch() || PlatformUtils.isBada()) { + if(PlatformUtils.isSymbian3Based() || PlatformUtils.isBada()) { App.customItems = true; } App.rememberSearch = true; @@ -117,10 +117,10 @@ else if(downloadDir.startsWith("file:///")) if(PlatformUtils.isAsha()) { App.videoPreviews = true; App.customItems = true; - } else if(s40 || (PlatformUtils.isNotS60() && !PlatformUtils.isS603rd() && PlatformUtils.startMemory > 512 * 1024 && PlatformUtils.startMemory < 2024 * 1024)) { + } else if(s40 /*|| (PlatformUtils.isNotS60() && !PlatformUtils.isS603rd() && PlatformUtils.startMemory > 512 * 1024 && PlatformUtils.startMemory < 2024 * 1024)*/) { App.videoPreviews = true; App.customItems = true; - if(s40) App.rmsPreviews = true; + App.rmsPreviews = true; } int min = Math.min(App.width, App.height); // Symbian 9.4 can't handle H.264/AVC @@ -164,6 +164,8 @@ else if(downloadDir.startsWith("file:///")) App.customLocale = j.getString("customLocale"); if(j.has("searchPlaylists")) App.searchPlaylists = j.getBoolean("searchPlaylists"); + if(j.has("debugMemory")) + App.debugMemory = j.getBoolean("debugMemory"); return; } catch (Exception e) { e.printStackTrace(); @@ -195,6 +197,7 @@ public static void saveConfig() { j.put("rmsPreviews", new Boolean(App.rmsPreviews)); j.put("customLocale", "\"" + App.customLocale + "\""); j.put("searchPlaylists", new Boolean(App.searchPlaylists)); + j.put("debugMemory", new Boolean(App.debugMemory)); byte[] b = j.build().getBytes("UTF-8"); r.addRecord(b, 0, b.length); diff --git a/src/cc/nnproject/utils/PlatformUtils.java b/src/cc/nnproject/utils/PlatformUtils.java index 341c37a..6d85475 100644 --- a/src/cc/nnproject/utils/PlatformUtils.java +++ b/src/cc/nnproject/utils/PlatformUtils.java @@ -41,16 +41,24 @@ public static boolean isNotS60() { } public static boolean isSymbianTouch() { - return !isNotS60() && (isS60PlatformVersion("5")); + return !isNotS60() && isS60PlatformVersion("5"); } - public static boolean isSymbian3() { - return !isNotS60() && (isS60PlatformVersion("5.1") || isS60PlatformVersion("5.2") || isS60PlatformVersion("5.3") || isS60PlatformVersion("5.4") || isS60PlatformVersion("5.5")); + public static boolean isSymbian3Based() { + return isSymbianTouch() && !isS60PlatformVersion("5.0"); } public static boolean isSymbian94() { return !isNotS60() && isS60PlatformVersion("5.0"); } + + public static boolean isSymbianAnna() { + return !isNotS60() && isS60PlatformVersion("5.2"); + } + + public static boolean isSymbian93() { + return isS60PlatformVersion("3.2"); + } public static boolean isS603rd() { if(isS603rd != -1) return isS603rd == 1; diff --git a/src/models/ChannelModel.java b/src/models/ChannelModel.java index 7cf7afe..097a5c6 100644 --- a/src/models/ChannelModel.java +++ b/src/models/ChannelModel.java @@ -88,7 +88,7 @@ private Item makeItem() { if(App.customItems) { return customItem = new ChannelItem(this); } - if(!App.videoPreviews || App.rmsPreviews) { + if(!App.videoPreviews) { return new StringItem(null, author); } return item = new ImageItem(author, img, Item.LAYOUT_CENTER, null); diff --git a/src/models/VideoModel.java b/src/models/VideoModel.java index 58c45ae..79e5616 100644 --- a/src/models/VideoModel.java +++ b/src/models/VideoModel.java @@ -40,7 +40,6 @@ public class VideoModel extends AbstractModel implements ItemCommandListener, IL private String thumbnailUrl; private int imageWidth; private ImageItem imageItem; - private Image img; private JSONArray authorThumbnails; private boolean extended; @@ -54,6 +53,7 @@ public class VideoModel extends AbstractModel implements ItemCommandListener, IL private Form formContainer; private int index = -1; + private boolean imgLoaded; // create model without parsing public VideoModel(String id) { @@ -125,7 +125,7 @@ private Item makeItem() { if(!App.videoPreviews) { return new StringItem(author, title); } - return imageItem = new ImageItem(title, img, Item.LAYOUT_CENTER, null, ImageItem.BUTTON); + return imageItem = new ImageItem(title, null, Item.LAYOUT_CENTER, null, ImageItem.BUTTON); } public Item makeItemForList() { @@ -137,6 +137,7 @@ public Item makeItemForList() { } public ImageItem makeImageItemForPage() { + Image img = null; if(customItem != null) { img = customItem.getImage(); } @@ -146,6 +147,23 @@ public ImageItem makeImageItemForPage() { } catch (IOException e) { } } + if(img == null && imageItem != null) { + img = imageItem.getImage(); + } + if(img == null) { + try { + byte[] b = App.hproxy(thumbnailUrl); + img = Image.createImage(b, 0, b.length); + b = null; + App.gc(); + float iw = img.getWidth(); + float ih = img.getHeight(); + float nw = (float) imageWidth; + int nh = (int) (nw * (ih / iw)); + img = ImageUtils.resize(img, imageWidth, nh); + } catch (IOException e) { + } + } return imageItem = new ImageItem(null, img, Item.LAYOUT_CENTER, null); } @@ -155,6 +173,7 @@ public Image customResize(Image img) { float nw = (float) imageWidth; int nh = (int) (nw * (ih / iw)); img = ImageUtils.resize(img, imageWidth, nh); + App.gc(); float f = iw / ih; if(f == 4F / 3F) { // cropping to 16:9 @@ -166,45 +185,50 @@ public Image customResize(Image img) { } public void loadImage() { - if(img != null) return; + if(imgLoaded) return; + imgLoaded = true; if(thumbnailUrl == null) return; if(imageItem == null && customItem == null && !extended) return; try { - if(App.rmsPreviews) { + if(App.rmsPreviews && App.customItems) { if(index <= 1 && index != -1) { - if(imageItem != null) { + /*if(imageItem != null) { float iw = img.getWidth(); float ih = img.getHeight(); float nw = (float) imageWidth; int nh = (int) (nw * (ih / iw)); img = ImageUtils.resize(Records.saveOrGetImage(videoId, thumbnailUrl), imageWidth, nh); imageItem.setImage(img); - } else if(customItem != null) { + } else */if(customItem != null) { customItem.setImage(customResize(Records.saveOrGetImage(videoId, thumbnailUrl))); } } else { Records.save(videoId, thumbnailUrl); } - App.gc(); } else { byte[] b = App.hproxy(thumbnailUrl); - img = Image.createImage(b, 0, b.length); + Image img = Image.createImage(b, 0, b.length); + b = null; + App.gc(); if(imageItem != null) { - float iw = img.getWidth(); - float ih = img.getHeight(); - float nw = (float) imageWidth; - int nh = (int) (nw * (ih / iw)); - img = ImageUtils.resize(img, imageWidth, nh); + if(App.width >= 480) { + img = customResize(img); + } else { + float iw = img.getWidth(); + float ih = img.getHeight(); + float nw = (float) imageWidth; + int nh = (int) (nw * (ih / iw)); + img = ImageUtils.resize(img, imageWidth, nh); + } imageItem.setImage(img); } else if(customItem != null) { - customItem.setImage(img = customResize(img)); + customItem.setImage(customResize(img)); } } thumbnailUrl = null; + App.gc(); } catch (NullPointerException e) { - img = null; } catch (RuntimeException e) { - img = null; throw e; } catch (Exception e) { e.printStackTrace(); @@ -230,6 +254,9 @@ private void loadAuthorImg() { } private int getImgItemWidth() { + //if(App.width >= 480) { + // return (int) (App.height); + //} return (int) (App.width * 2F / 3F); } @@ -331,7 +358,6 @@ public boolean isFromPlaylist() { public void dispose() { thumbnailUrl = null; - img = null; if(imageItem != null) imageItem.setImage(null); } @@ -354,10 +380,6 @@ public int getDislikeCount() { public boolean isExtended() { return extended; } - - public Image getCachedImage() { - return img; - } public ModelForm makeForm() { return new VideoForm(this); diff --git a/src/ui/AppUI.java b/src/ui/AppUI.java index 6c4b028..9af8fb0 100644 --- a/src/ui/AppUI.java +++ b/src/ui/AppUI.java @@ -29,7 +29,7 @@ public class AppUI implements CommandListener, Commands, Constants { - private static final Display display = Display.getDisplay(App.midlet); + public static final Display display = Display.getDisplay(App.midlet); public static AppUI inst; @@ -122,6 +122,11 @@ public void loadTrends() { j = null; app.notifyAsyncTasks(); } catch (RuntimeException e) { + if(!e.getClass().equals(RuntimeException.class)) { + e.printStackTrace(); + App.error(this, Errors.App_loadPopular, e); + return; + } throw e; } catch (Exception e) { e.printStackTrace(); @@ -153,6 +158,11 @@ void loadPopular() { j = null; app.notifyAsyncTasks(); } catch (RuntimeException e) { + if(!e.getClass().equals(RuntimeException.class)) { + e.printStackTrace(); + App.error(this, Errors.App_loadPopular, e); + return; + } throw e; } catch (Exception e) { e.printStackTrace(); @@ -464,9 +474,7 @@ public static void open(AbstractModel model, Form formContainer) { if(model.isFromSearch() && !App.rememberSearch) { ui.disposeSearchForm(); } - System.out.println("stop doung tasks"); app.stopDoingAsyncTasks(); - System.out.println("stop doung tasks done"); ModelForm form = model.makeForm(); AppUI.display(form); if(form instanceof VideoForm) { @@ -482,17 +490,17 @@ public static void open(AbstractModel model, Form formContainer) { Thread.sleep(50); } catch (InterruptedException e) { } - System.out.println("addin async load"); app.addAsyncLoad(form); - System.out.println("notyfin async thread"); app.notifyAsyncTasks(); - System.out.println("async thread notyfied"); } public static int getPlatformWidthOffset() { if(PlatformUtils.isKemulator) return 5; - if(PlatformUtils.isS40()) return 8; - if(PlatformUtils.isSymbian94()) return 8; + if(PlatformUtils.isAshaFullTouch()) return 24; + if(PlatformUtils.isS40()) return 12; + if(PlatformUtils.isSymbianAnna()) return 38; + if(PlatformUtils.isSymbian94()) return 32; + if(PlatformUtils.isSymbian3Based()) return 20; return 4; } diff --git a/src/ui/ChannelForm.java b/src/ui/ChannelForm.java index 122b72b..d57404e 100644 --- a/src/ui/ChannelForm.java +++ b/src/ui/ChannelForm.java @@ -26,14 +26,14 @@ public class ChannelForm extends ModelForm implements CommandListener, Commands, private static final Command lastVideosCmd = new Command(Locale.s(BTN_LatestVideos), Command.ITEM, 2); private static final Command searchVideosCmd = new Command(Locale.s(BTN_SearchVideos), Command.ITEM, 3); - private static final Command infoCmd = new Command(Locale.s(BTN_ChannelInformation), Command.ITEM, 4); + private static final Command playlistsCmd = new Command(Locale.s(BTN_Playlists), Command.ITEM, 4); private ChannelModel channel; private StringItem loadingItem; private StringItem lastVideosBtn; private StringItem searchVideosBtn; - private StringItem infoBtn; + private StringItem playlistsBtn; private Form lastVideosForm; private Form searchForm; @@ -68,12 +68,12 @@ private void init() { searchVideosBtn.setDefaultCommand(searchVideosCmd); searchVideosBtn.setItemCommandListener(this); append(searchVideosBtn); - infoBtn = new StringItem(null, Locale.s(BTN_ChannelInformation), Item.BUTTON); - infoBtn.setLayout(Item.LAYOUT_EXPAND | Item.LAYOUT_NEWLINE_AFTER); - infoBtn.addCommand(infoCmd); - infoBtn.setDefaultCommand(infoCmd); - infoBtn.setItemCommandListener(this); - append(infoBtn); + playlistsBtn = new StringItem(null, Locale.s(BTN_Playlists), Item.BUTTON); + playlistsBtn.setLayout(Item.LAYOUT_EXPAND | Item.LAYOUT_NEWLINE_AFTER); + playlistsBtn.addCommand(playlistsCmd); + playlistsBtn.setDefaultCommand(playlistsCmd); + playlistsBtn.setItemCommandListener(this); + append(playlistsBtn); } public void load() { @@ -146,6 +146,7 @@ private Item parseAndMakeItem(JSONObject j, boolean search) { public void commandAction(Command c, Displayable d) { if(c == lastVideosCmd) { latestVideos(); + return; } if(c == searchVideosCmd && d instanceof Form) { App.inst.stopDoingAsyncTasks(); @@ -158,9 +159,15 @@ public void commandAction(Command c, Displayable d) { t.addCommand(searchOkCmd); t.addCommand(cancelCmd); AppUI.display(t); + return; } if(c == searchOkCmd && d instanceof TextBox) { search(((TextBox) d).getString()); + return; + } + if(c == cancelCmd && d instanceof TextBox) { + AppUI.display(this); + return; } if(d == searchForm && c == backCmd) { AppUI.display(this); @@ -180,6 +187,11 @@ public void commandAction(Command c, Displayable d) { AppUI.inst.commandAction(c, d); } + private void playlists() { + // TODO Auto-generated method stub + + } + private void disposeLastVideosForm() { if(lastVideosForm == null) return; lastVideosForm.deleteAll(); @@ -221,6 +233,11 @@ public void commandAction(Command c, Item i) { t.addCommand(searchOkCmd); t.addCommand(cancelCmd); AppUI.display(t); + return; + } + if(c == playlistsCmd) { + playlists(); + return; } if(c == lastVideosCmd) { latestVideos(); diff --git a/src/ui/SettingsForm.java b/src/ui/SettingsForm.java index a583f65..6f88a44 100644 --- a/src/ui/SettingsForm.java +++ b/src/ui/SettingsForm.java @@ -39,6 +39,9 @@ public class SettingsForm extends Form implements CommandListener, ItemCommandLi Locale.s(SET_VideoPreviews), Locale.s(SET_SearchChannels), Locale.s(SET_SearchPlaylists) }; + static final String[] DEBUG_CHECKS = new String[] { + "Debug memory" + }; private ChoiceGroup videoResChoice; private TextField regionText; @@ -50,6 +53,7 @@ public class SettingsForm extends Form implements CommandListener, ItemCommandLi private ChoiceGroup uiChoice; private StringItem dirBtn; private TextField customLocaleText; + private ChoiceGroup debugChoice; private List dirList; private String curDir; @@ -88,6 +92,8 @@ public SettingsForm() { append(Locale.s(SET_Tip2) + "\n"); customLocaleText = new TextField(Locale.s(SET_CustomLocaleId), App.customLocale, 8, TextField.ANY); append(customLocaleText); + debugChoice = new ChoiceGroup("Debug", ChoiceGroup.MULTIPLE, DEBUG_CHECKS, null); + append(debugChoice); } public void show() { @@ -98,6 +104,7 @@ public void show() { checksChoice.setSelectedIndex(0, App.rememberSearch); checksChoice.setSelectedIndex(1, App.httpStream); checksChoice.setSelectedIndex(2, App.rmsPreviews); + debugChoice.setSelectedIndex(0, App.debugMemory); //checksChoice.setSelectedIndex(4, App.apiProxy); if(App.videoRes == null) { videoResChoice.setSelectedIndex(1, true); @@ -151,6 +158,7 @@ private void applySettings() { App.inv = invidiousText.getString(); App.imgproxy = imgProxyText.getString(); App.customLocale = customLocaleText.getString().trim().toLowerCase(); + App.debugMemory = debugChoice.isSelected(0); Settings.saveConfig(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/ui/VideoForm.java b/src/ui/VideoForm.java index cb4e06e..c909f2e 100644 --- a/src/ui/VideoForm.java +++ b/src/ui/VideoForm.java @@ -157,6 +157,7 @@ public void commandAction(Command c, Displayable d) { public void commandAction(Command c, Item i) { if(c == watchCmd) { App.watch(video.getVideoId()); + return; } } diff --git a/src/ui/custom/VideoItem.java b/src/ui/custom/VideoItem.java index e82c00f..7131634 100644 --- a/src/ui/custom/VideoItem.java +++ b/src/ui/custom/VideoItem.java @@ -10,9 +10,10 @@ import Records; import ui.AppUI; import models.VideoModel; +import IScheduledShowHide; import cc.nnproject.utils.PlatformUtils; -public class VideoItem extends CustomButtonItem { +public class VideoItem extends CustomButtonItem implements IScheduledShowHide { private static int globalWidth; @@ -30,40 +31,14 @@ public class VideoItem extends CustomButtonItem { private int imgHeight; private int textWidth; - private Runnable loadImgRMS = new Runnable() { - public void run() { - try { - if(!drawn) return; - Image img = Records.saveOrGetImage(video.getVideoId(), null); - if(img == null) { - //System.out.println("img null " + VideoItem.this.toString()); - return; - } - //System.out.println("img " + VideoItem.this.toString()); - setImage(video.customResize(img)); - } catch (Exception e) { - e.printStackTrace(); - } - } - }; - - private Runnable setImgNull = new Runnable() { - public void run() { - try { - if(!drawn) return; - setImage(null); - } catch (Exception e) { - e.printStackTrace(); - } - } - }; - private boolean drawn; + + private Object showmsg = new Object[] {this, new Boolean(true)}; + private Object hidemsg = new Object[] {this, new Boolean(false)}; public VideoItem(VideoModel v) { super(v); this.video = v; - this.img = v.getCachedImage(); this.lengthStr = timeStr(v.getLengthSeconds()); this.title = v.getTitle(); this.author = v.getAuthor(); @@ -80,6 +55,7 @@ protected void paint(Graphics g, int w, int h) { g.setColor(0); if(img != null) { g.drawImage(img, -2, 0, 0); + if(PlatformUtils.isS40() || PlatformUtils.isS603rd() || !PlatformUtils.isNotS60()) disposeImage(); } else { g.fillRect(0, 0, w, ih); } @@ -105,6 +81,10 @@ protected void paint(Graphics g, int w, int h) { } } + private void disposeImage() { + img = null; + } + private void makeTitleArr() { int w = getTextMaxWidth(); String[] arr = getStringArray(title, w, mediumfont); @@ -193,14 +173,14 @@ private static String timeStr(int i) { protected void showNotify() { //System.out.println("showNotify " + toString()); if(App.rmsPreviews) { - App.inst.scheduleRunnable(loadImgRMS); + App.inst.schedule(showmsg); } } protected void hideNotify() { //System.out.println("hideNotify " + toString()); if(App.rmsPreviews) { - App.inst.scheduleRunnable(setImgNull); + App.inst.schedule(hidemsg); } } @@ -267,4 +247,27 @@ public static int getImageWidth() { return App.width - 4; } + public void show() { + try { + if(!drawn) return; + Image img = Records.saveOrGetImage(video.getVideoId(), null); + if(img == null) { + //System.out.println("img null " + VideoItem.this.toString()); + return; + } + //System.out.println("img " + VideoItem.this.toString()); + setImage(video.customResize(img)); + } catch (Exception e) { + } + + } + + public void hide() { + try { + if(!drawn) return; + setImage(null); + } catch (Exception e) { + } + } + }