Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
r3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
shinovon committed Dec 30, 2021
1 parent 00f9b38 commit 192f1ad
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class App implements Constants {

public static final String ver = "r3 patch2";
public static final String ver = "r3.2";

// Settings
public static String videoRes;
Expand Down Expand Up @@ -474,7 +474,7 @@ public void stopDoingAsyncTasks() {

private void testCanvas() {
Canvas c = new TestCanvas();
Display.getDisplay(midlet).setCurrent(c);
//Display.getDisplay(midlet).setCurrent(c);
width = c.getWidth();
height = c.getHeight();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public interface Constants {
static final String CONFIG_RECORD_NAME = "ytconfig";

// Limits
static final int TRENDS_LIMIT_S60 = 25;
static final int SEARCH_LIMIT_S60 = 35;
static final int TRENDS_LIMIT_S60 = 23;
static final int SEARCH_LIMIT_S60 = 30;
static final int TRENDS_LIMIT_LOWEND = 20;
static final int SEARCH_LIMIT_LOWEND = 25;
static final int TRENDS_LIMIT = PlatformUtils.isNotS60() ? TRENDS_LIMIT_LOWEND : TRENDS_LIMIT_S60;
Expand Down
1 change: 1 addition & 0 deletions src/Errors.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class Errors {
public static final int PlaylistForm_load = 13;
public static final int PlaylistForm_init = 14;
public static final int PlaylistForm_init_previews = 15;
public static final int App_commandAction_switchCmd = 16;

}
2 changes: 2 additions & 0 deletions src/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ public static String s(int c) {
return "(Использован только если включен HTTP стриминг через прокси)";
case SET_Tip2:
return "(Оставьте пустым если ваше устройство поддерживает HTTPS)";
case BTN_Playlists:
return "Плейлисты";
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions src/models/PlaylistModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.StringItem;

import App;
import Locale;
import ui.AppUI;
import ui.ModelForm;
Expand All @@ -31,6 +34,8 @@ public class PlaylistModel extends AbstractModel implements ILoader, ItemCommand

private PlaylistItem customItem;

private Form formContainer;

public PlaylistModel(JSONObject o) {
parse(o, false);
}
Expand All @@ -39,12 +44,19 @@ public PlaylistModel(JSONObject o, boolean extended) {
parse(o, extended);
}

public PlaylistModel(JSONObject j, Form form, ChannelModel channel) {
this(j, false);
this.formContainer = form;
//this.channel = channel;
authorId = channel.getAuthorId();
}

private void parse(JSONObject o, boolean extended) {
this.extended = extended;
title = o.getString("title");
playlistId = o.getString("playlistId");
author = o.getString("author");
authorId = o.getString("authorId");
author = o.getNullableString("author");
authorId = o.getNullableString("authorId");
videoCount = o.getInt("videoCount", 0);
/*
if(extended) {
Expand All @@ -71,6 +83,13 @@ public void load() {
}

public Item makeItemForList() {
if(!App.customItems) {
StringItem item = new StringItem(title, Locale.videos(getVideoCount()) + (formContainer == null ? "\n" + author : ""));
item.addCommand(pOpenCmd);
item.setDefaultCommand(pOpenCmd);
item.setItemCommandListener(this);
return item;
}
customItem = new PlaylistItem(this);
customItem.addCommand(pOpenCmd);
customItem.setDefaultCommand(pOpenCmd);
Expand Down Expand Up @@ -132,4 +151,8 @@ public int getVideoCount() {
return videoCount;
}

public Form getFormContainer() {
return formContainer;
}

}
1 change: 1 addition & 0 deletions src/models/VideoModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public Item makeAuthorItem() {
}*/
authorItem = new ImageItem(null, null, Item.LAYOUT_LEFT | Item.LAYOUT_NEWLINE_BEFORE, null, Item.BUTTON);
authorItem.addCommand(vOpenChannelCmd);
authorItem.setDefaultCommand(vOpenChannelCmd);
authorItem.setItemCommandListener(this);
return authorItem;
}
Expand Down
106 changes: 58 additions & 48 deletions src/ui/AppUI.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package ui;
import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
Expand Down Expand Up @@ -61,6 +63,7 @@ public void loadForm() {
} else {
loadPopular();
}
display(mainForm);
App.gc();
} catch (InvidiousException e) {
App.error(this, Errors.App_loadForm, e);
Expand Down Expand Up @@ -91,10 +94,9 @@ public void initForm() {
mainForm.addCommand(idCmd);
mainForm.addCommand(settingsCmd);
mainForm.addCommand(exitCmd);
display(mainForm);
}

public void loadTrends() {
public void loadTrends() throws IOException {
boolean b = App.needsCheckMemory();
mainForm.addCommand(switchToPopularCmd);
try {
Expand Down Expand Up @@ -128,14 +130,14 @@ public void loadTrends() {
return;
}
throw e;
} catch (Exception e) {
}/* catch (Exception e) {
e.printStackTrace();
App.error(this, Errors.App_loadTrends, e);
}
}*/
App.gc();
}

void loadPopular() {
void loadPopular() throws IOException {
boolean b = App.needsCheckMemory();
mainForm.addCommand(switchToTrendsCmd);
try {
Expand Down Expand Up @@ -164,10 +166,10 @@ void loadPopular() {
return;
}
throw e;
} catch (Exception e) {
}/* catch (Exception e) {
e.printStackTrace();
App.error(this, Errors.App_loadPopular, e);
}
}*/
App.gc();
}

Expand All @@ -178,7 +180,7 @@ void search(String q) {
searchForm.addCommand(settingsCmd);
searchForm.addCommand(searchCmd);
display(searchForm);
if(Settings.isLowEndDevice()) {
if(Settings.isLowEndDevice() || !App.rememberSearch) {
disposeMainForm();
}
if(mainForm != null) {
Expand Down Expand Up @@ -251,7 +253,7 @@ private void openVideo(String id) {
if(id.startsWith(watch)) id = id.substring(watch.length());
try {
open(new VideoModel(id).extend());
if(Settings.isLowEndDevice()) {
if(Settings.isLowEndDevice() || !App.rememberSearch) {
disposeMainForm();
}
} catch (Exception e) {
Expand All @@ -260,7 +262,7 @@ private void openVideo(String id) {
}

void disposeMainForm() {
if(mainForm != null) return;
if(mainForm == null) return;
mainForm.deleteAll();
mainForm = null;
App.gc();
Expand Down Expand Up @@ -373,43 +375,47 @@ public void commandAction(Command c, Displayable d) {
disposeSearchForm();
return;
}
if(c == switchToPopularCmd) {
App.startScreen = 1;
app.stopDoingAsyncTasks();
if(mainForm != null) {
mainForm.deleteAll();
} else {
initForm();
}
if(searchForm != null) {
disposeSearchForm();
} else {
d.removeCommand(c);
}
loadPopular();
Settings.saveConfig();
return;
}
if(c == switchToTrendsCmd) {
App.startScreen = 0;
app.stopDoingAsyncTasks();
if(mainForm != null) {
mainForm.deleteAll();
} else {
initForm();
try {
if(c == switchToPopularCmd) {
App.startScreen = 1;
app.stopDoingAsyncTasks();
if(mainForm != null) {
mainForm.deleteAll();
} else {
initForm();
}
if(searchForm != null) {
disposeSearchForm();
} else {
d.removeCommand(c);
}
loadPopular();
Settings.saveConfig();
return;
}
if(searchForm != null) {
disposeSearchForm();
} else {
d.removeCommand(c);
if(c == switchToTrendsCmd) {
App.startScreen = 0;
app.stopDoingAsyncTasks();
if(mainForm != null) {
mainForm.deleteAll();
} else {
initForm();
}
if(searchForm != null) {
disposeSearchForm();
} else {
d.removeCommand(c);
}
loadTrends();
Settings.saveConfig();
}
loadTrends();
Settings.saveConfig();
} catch (Exception e) {
App.error(this, Errors.App_commandAction_switchCmd, e);
e.printStackTrace();
}
}

public static void display(Displayable d) {
boolean b = false;
AppUI ui = inst;
if(d == null) {
if(ui.videoForm != null) {
Expand All @@ -422,17 +428,16 @@ public static void display(Displayable d) {
d = ui.mainForm;
} else {
ui.initForm();
d = ui.mainForm;
b = true;
ui.loadForm();
return;
}
}
if(!(d instanceof Alert)) {
lastd = d;
display.setCurrent(d);
} else {
display.setCurrent((Alert) d, lastd);
display.setCurrent((Alert) d, lastd == null ? ui.mainForm : lastd);
}
if(b) ui.loadForm();
}

public static void back(Form f) {
Expand All @@ -443,7 +448,7 @@ public static void back(Form f) {
AppUI.display(ui.mainForm);
} else {
ui.initForm();
AppUI.display(ui.mainForm);
//AppUI.display(ui.mainForm);
ui.loadForm();
}
}
Expand Down Expand Up @@ -471,8 +476,12 @@ public static void open(AbstractModel model, Form formContainer) {
return;
}
}
if(model.isFromSearch() && !App.rememberSearch) {
ui.disposeSearchForm();
if(!App.rememberSearch) {
if(model.isFromSearch()) {
ui.disposeSearchForm();
} else if(ui.mainForm != null) {
ui.disposeMainForm();
}
}
app.stopDoingAsyncTasks();
ModelForm form = model.makeForm();
Expand All @@ -496,6 +505,7 @@ public static void open(AbstractModel model, Form formContainer) {

public static int getPlatformWidthOffset() {
if(PlatformUtils.isKemulator) return 5;
if(PlatformUtils.isJ2ML()) return 0;
if(PlatformUtils.isAshaFullTouch()) return 24;
if(PlatformUtils.isS40()) return 12;
if(PlatformUtils.isSymbianAnna()) return 38;
Expand Down
Loading

0 comments on commit 192f1ad

Please sign in to comment.