repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
|---|---|---|---|---|---|---|
TheCreeperOfRedstone/RPG-Items-2
|
src/think/rpgitems/config/ConfigUpdater.java
|
// Path: src/think/rpgitems/Plugin.java
// @SuppressWarnings("deprecation")
// public class Plugin extends JavaPlugin {
//
// public static Logger logger = Logger.getLogger("RPGItems");
//
// public static Plugin plugin;
//
// @Override
// public void onLoad() {
// plugin = this;
// reloadConfig();
// Font.load();
// Power.powers.put("arrow", PowerArrow.class);
// Power.powers.put("tntcannon", PowerTNTCannon.class);
// Power.powers.put("rainbow", PowerRainbow.class);
// Power.powers.put("flame", PowerFlame.class);
// Power.powers.put("lightning", PowerLightning.class);
// Power.powers.put("command", PowerCommand.class);
// Power.powers.put("potionhit", PowerPotionHit.class);
// Power.powers.put("teleport", PowerTeleport.class);
// Power.powers.put("fireball", PowerFireball.class);
// Power.powers.put("ice", PowerIce.class);
// Power.powers.put("knockup", PowerKnockup.class);
// Power.powers.put("rush", PowerRush.class);
// Power.powers.put("potionself", PowerPotionSelf.class);
// Power.powers.put("consume", PowerConsume.class);
// Power.powers.put("unbreakable", PowerUnbreakable.class);
// Power.powers.put("unbreaking", PowerUnbreaking.class);
// Power.powers.put("rumble", PowerRumble.class);
// Power.powers.put("skyhook", PowerSkyHook.class);
// Power.powers.put("potiontick", PowerPotionTick.class);
// Power.powers.put("food", PowerFood.class);
// Power.powers.put("lifesteal", PowerLifeSteal.class);
// }
//
// @Override
// public void onEnable() {
// Locale.init(this);
// updateConfig();
// WorldGuard.init(this);
// ConfigurationSection conf = getConfig();
// if (conf.getBoolean("autoupdate", true)) {
// new Updater(this, 70226, this.getFile(), Updater.UpdateType.DEFAULT, false);
// }
// if (conf.getBoolean("localeInv", false)) {
// Events.useLocaleInv = true;
// }
// getServer().getPluginManager().registerEvents(new Events(), this);
// ItemManager.load(this);
// Commands.register(new Handler());
// Commands.register(new PowerHandler());
// new PowerTicker().runTaskTimer(this, 0, 1);
// }
//
// @Override
// public void saveConfig() {
// FileConfiguration config = getConfig();
// FileOutputStream out = null;
// try {
// File f = new File(getDataFolder(), "config.yml");
// if (!f.exists())
// f.createNewFile();
// out = new FileOutputStream(f);
// out.write(config.saveToString().getBytes("UTF-8"));
// } catch (FileNotFoundException e) {
// } catch (UnsupportedEncodingException e) {
// } catch (IOException e) {
// } finally {
// try {
// if (out != null)
// out.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
//
// public static FileConfiguration config;
//
// @Override
// public void reloadConfig() {
// FileInputStream in = null;
// config = new YamlConfiguration();
// try {
// File f = new File(getDataFolder(), "config.yml");
// in = new FileInputStream(f);
// byte[] data = new byte[(int) f.length()];
// in.read(data);
// String str = new String(data, "UTF-8");
// config.loadFromString(str);
// } catch (FileNotFoundException e) {
// } catch (IOException e) {
// } catch (InvalidConfigurationException e) {
// } finally {
// try {
// if (in != null)
// in.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// public FileConfiguration getConfig() {
// return config;
// }
//
// public void updateConfig() {
// ConfigUpdater.updateConfig(getConfig());
// saveConfig();
// }
//
// @Override
// public void onDisable() {
// }
//
// @Override
// public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(label).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// Commands.exec(sender, out.toString());
// return true;
// }
//
// @Override
// public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(alias).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// return Commands.complete(sender, out.toString());
// }
// }
|
import java.util.HashMap;
import org.bukkit.configuration.ConfigurationSection;
import think.rpgitems.Plugin;
|
static {
updates = new HashMap<String, Updater>();
updates.put("0.1", new Update01To02());
updates.put("0.2", new Update02To03());
updates.put("0.3", new Update03To04());
updates.put("0.4", new Update04To05());
}
public static void updateConfig(ConfigurationSection conf) {
while (!conf.getString("version", "0.0").equals(CONFIG_VERSION)) {
if (!conf.contains("version")) {
if (!conf.contains("autoupdate")) {
conf.set("autoupdate", true);
}
if (!conf.contains("defaults.hand")) {
conf.set("defaults.hand", "One handed");
}
if (!conf.contains("defaults.sword")) {
conf.set("defaults.sword", "Sword");
}
if (!conf.contains("defaults.damage")) {
conf.set("defaults.damage", "Damage");
}
if (!conf.contains("defaults.armour")) {
conf.set("defaults.armour", "Armour");
}
if (!conf.contains("support.worldguard")) {
conf.set("support.worldguard", false);
}
conf.set("version", "0.1");
|
// Path: src/think/rpgitems/Plugin.java
// @SuppressWarnings("deprecation")
// public class Plugin extends JavaPlugin {
//
// public static Logger logger = Logger.getLogger("RPGItems");
//
// public static Plugin plugin;
//
// @Override
// public void onLoad() {
// plugin = this;
// reloadConfig();
// Font.load();
// Power.powers.put("arrow", PowerArrow.class);
// Power.powers.put("tntcannon", PowerTNTCannon.class);
// Power.powers.put("rainbow", PowerRainbow.class);
// Power.powers.put("flame", PowerFlame.class);
// Power.powers.put("lightning", PowerLightning.class);
// Power.powers.put("command", PowerCommand.class);
// Power.powers.put("potionhit", PowerPotionHit.class);
// Power.powers.put("teleport", PowerTeleport.class);
// Power.powers.put("fireball", PowerFireball.class);
// Power.powers.put("ice", PowerIce.class);
// Power.powers.put("knockup", PowerKnockup.class);
// Power.powers.put("rush", PowerRush.class);
// Power.powers.put("potionself", PowerPotionSelf.class);
// Power.powers.put("consume", PowerConsume.class);
// Power.powers.put("unbreakable", PowerUnbreakable.class);
// Power.powers.put("unbreaking", PowerUnbreaking.class);
// Power.powers.put("rumble", PowerRumble.class);
// Power.powers.put("skyhook", PowerSkyHook.class);
// Power.powers.put("potiontick", PowerPotionTick.class);
// Power.powers.put("food", PowerFood.class);
// Power.powers.put("lifesteal", PowerLifeSteal.class);
// }
//
// @Override
// public void onEnable() {
// Locale.init(this);
// updateConfig();
// WorldGuard.init(this);
// ConfigurationSection conf = getConfig();
// if (conf.getBoolean("autoupdate", true)) {
// new Updater(this, 70226, this.getFile(), Updater.UpdateType.DEFAULT, false);
// }
// if (conf.getBoolean("localeInv", false)) {
// Events.useLocaleInv = true;
// }
// getServer().getPluginManager().registerEvents(new Events(), this);
// ItemManager.load(this);
// Commands.register(new Handler());
// Commands.register(new PowerHandler());
// new PowerTicker().runTaskTimer(this, 0, 1);
// }
//
// @Override
// public void saveConfig() {
// FileConfiguration config = getConfig();
// FileOutputStream out = null;
// try {
// File f = new File(getDataFolder(), "config.yml");
// if (!f.exists())
// f.createNewFile();
// out = new FileOutputStream(f);
// out.write(config.saveToString().getBytes("UTF-8"));
// } catch (FileNotFoundException e) {
// } catch (UnsupportedEncodingException e) {
// } catch (IOException e) {
// } finally {
// try {
// if (out != null)
// out.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
//
// public static FileConfiguration config;
//
// @Override
// public void reloadConfig() {
// FileInputStream in = null;
// config = new YamlConfiguration();
// try {
// File f = new File(getDataFolder(), "config.yml");
// in = new FileInputStream(f);
// byte[] data = new byte[(int) f.length()];
// in.read(data);
// String str = new String(data, "UTF-8");
// config.loadFromString(str);
// } catch (FileNotFoundException e) {
// } catch (IOException e) {
// } catch (InvalidConfigurationException e) {
// } finally {
// try {
// if (in != null)
// in.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// public FileConfiguration getConfig() {
// return config;
// }
//
// public void updateConfig() {
// ConfigUpdater.updateConfig(getConfig());
// saveConfig();
// }
//
// @Override
// public void onDisable() {
// }
//
// @Override
// public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(label).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// Commands.exec(sender, out.toString());
// return true;
// }
//
// @Override
// public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(alias).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// return Commands.complete(sender, out.toString());
// }
// }
// Path: src/think/rpgitems/config/ConfigUpdater.java
import java.util.HashMap;
import org.bukkit.configuration.ConfigurationSection;
import think.rpgitems.Plugin;
static {
updates = new HashMap<String, Updater>();
updates.put("0.1", new Update01To02());
updates.put("0.2", new Update02To03());
updates.put("0.3", new Update03To04());
updates.put("0.4", new Update04To05());
}
public static void updateConfig(ConfigurationSection conf) {
while (!conf.getString("version", "0.0").equals(CONFIG_VERSION)) {
if (!conf.contains("version")) {
if (!conf.contains("autoupdate")) {
conf.set("autoupdate", true);
}
if (!conf.contains("defaults.hand")) {
conf.set("defaults.hand", "One handed");
}
if (!conf.contains("defaults.sword")) {
conf.set("defaults.sword", "Sword");
}
if (!conf.contains("defaults.damage")) {
conf.set("defaults.damage", "Damage");
}
if (!conf.contains("defaults.armour")) {
conf.set("defaults.armour", "Armour");
}
if (!conf.contains("support.worldguard")) {
conf.set("support.worldguard", false);
}
conf.set("version", "0.1");
|
Plugin.plugin.saveConfig();
|
TheCreeperOfRedstone/RPG-Items-2
|
src/think/rpgitems/config/Update01To02.java
|
// Path: src/think/rpgitems/Plugin.java
// @SuppressWarnings("deprecation")
// public class Plugin extends JavaPlugin {
//
// public static Logger logger = Logger.getLogger("RPGItems");
//
// public static Plugin plugin;
//
// @Override
// public void onLoad() {
// plugin = this;
// reloadConfig();
// Font.load();
// Power.powers.put("arrow", PowerArrow.class);
// Power.powers.put("tntcannon", PowerTNTCannon.class);
// Power.powers.put("rainbow", PowerRainbow.class);
// Power.powers.put("flame", PowerFlame.class);
// Power.powers.put("lightning", PowerLightning.class);
// Power.powers.put("command", PowerCommand.class);
// Power.powers.put("potionhit", PowerPotionHit.class);
// Power.powers.put("teleport", PowerTeleport.class);
// Power.powers.put("fireball", PowerFireball.class);
// Power.powers.put("ice", PowerIce.class);
// Power.powers.put("knockup", PowerKnockup.class);
// Power.powers.put("rush", PowerRush.class);
// Power.powers.put("potionself", PowerPotionSelf.class);
// Power.powers.put("consume", PowerConsume.class);
// Power.powers.put("unbreakable", PowerUnbreakable.class);
// Power.powers.put("unbreaking", PowerUnbreaking.class);
// Power.powers.put("rumble", PowerRumble.class);
// Power.powers.put("skyhook", PowerSkyHook.class);
// Power.powers.put("potiontick", PowerPotionTick.class);
// Power.powers.put("food", PowerFood.class);
// Power.powers.put("lifesteal", PowerLifeSteal.class);
// }
//
// @Override
// public void onEnable() {
// Locale.init(this);
// updateConfig();
// WorldGuard.init(this);
// ConfigurationSection conf = getConfig();
// if (conf.getBoolean("autoupdate", true)) {
// new Updater(this, 70226, this.getFile(), Updater.UpdateType.DEFAULT, false);
// }
// if (conf.getBoolean("localeInv", false)) {
// Events.useLocaleInv = true;
// }
// getServer().getPluginManager().registerEvents(new Events(), this);
// ItemManager.load(this);
// Commands.register(new Handler());
// Commands.register(new PowerHandler());
// new PowerTicker().runTaskTimer(this, 0, 1);
// }
//
// @Override
// public void saveConfig() {
// FileConfiguration config = getConfig();
// FileOutputStream out = null;
// try {
// File f = new File(getDataFolder(), "config.yml");
// if (!f.exists())
// f.createNewFile();
// out = new FileOutputStream(f);
// out.write(config.saveToString().getBytes("UTF-8"));
// } catch (FileNotFoundException e) {
// } catch (UnsupportedEncodingException e) {
// } catch (IOException e) {
// } finally {
// try {
// if (out != null)
// out.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
//
// public static FileConfiguration config;
//
// @Override
// public void reloadConfig() {
// FileInputStream in = null;
// config = new YamlConfiguration();
// try {
// File f = new File(getDataFolder(), "config.yml");
// in = new FileInputStream(f);
// byte[] data = new byte[(int) f.length()];
// in.read(data);
// String str = new String(data, "UTF-8");
// config.loadFromString(str);
// } catch (FileNotFoundException e) {
// } catch (IOException e) {
// } catch (InvalidConfigurationException e) {
// } finally {
// try {
// if (in != null)
// in.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// public FileConfiguration getConfig() {
// return config;
// }
//
// public void updateConfig() {
// ConfigUpdater.updateConfig(getConfig());
// saveConfig();
// }
//
// @Override
// public void onDisable() {
// }
//
// @Override
// public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(label).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// Commands.exec(sender, out.toString());
// return true;
// }
//
// @Override
// public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(alias).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// return Commands.complete(sender, out.toString());
// }
// }
|
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import think.rpgitems.Plugin;
|
/*
* This file is part of RPG Items.
*
* RPG Items 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.
*
* RPG Items 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 RPG Items. If not, see <http://www.gnu.org/licenses/>.
*/
package think.rpgitems.config;
public class Update01To02 implements Updater {
@Override
public void update(ConfigurationSection section) {
|
// Path: src/think/rpgitems/Plugin.java
// @SuppressWarnings("deprecation")
// public class Plugin extends JavaPlugin {
//
// public static Logger logger = Logger.getLogger("RPGItems");
//
// public static Plugin plugin;
//
// @Override
// public void onLoad() {
// plugin = this;
// reloadConfig();
// Font.load();
// Power.powers.put("arrow", PowerArrow.class);
// Power.powers.put("tntcannon", PowerTNTCannon.class);
// Power.powers.put("rainbow", PowerRainbow.class);
// Power.powers.put("flame", PowerFlame.class);
// Power.powers.put("lightning", PowerLightning.class);
// Power.powers.put("command", PowerCommand.class);
// Power.powers.put("potionhit", PowerPotionHit.class);
// Power.powers.put("teleport", PowerTeleport.class);
// Power.powers.put("fireball", PowerFireball.class);
// Power.powers.put("ice", PowerIce.class);
// Power.powers.put("knockup", PowerKnockup.class);
// Power.powers.put("rush", PowerRush.class);
// Power.powers.put("potionself", PowerPotionSelf.class);
// Power.powers.put("consume", PowerConsume.class);
// Power.powers.put("unbreakable", PowerUnbreakable.class);
// Power.powers.put("unbreaking", PowerUnbreaking.class);
// Power.powers.put("rumble", PowerRumble.class);
// Power.powers.put("skyhook", PowerSkyHook.class);
// Power.powers.put("potiontick", PowerPotionTick.class);
// Power.powers.put("food", PowerFood.class);
// Power.powers.put("lifesteal", PowerLifeSteal.class);
// }
//
// @Override
// public void onEnable() {
// Locale.init(this);
// updateConfig();
// WorldGuard.init(this);
// ConfigurationSection conf = getConfig();
// if (conf.getBoolean("autoupdate", true)) {
// new Updater(this, 70226, this.getFile(), Updater.UpdateType.DEFAULT, false);
// }
// if (conf.getBoolean("localeInv", false)) {
// Events.useLocaleInv = true;
// }
// getServer().getPluginManager().registerEvents(new Events(), this);
// ItemManager.load(this);
// Commands.register(new Handler());
// Commands.register(new PowerHandler());
// new PowerTicker().runTaskTimer(this, 0, 1);
// }
//
// @Override
// public void saveConfig() {
// FileConfiguration config = getConfig();
// FileOutputStream out = null;
// try {
// File f = new File(getDataFolder(), "config.yml");
// if (!f.exists())
// f.createNewFile();
// out = new FileOutputStream(f);
// out.write(config.saveToString().getBytes("UTF-8"));
// } catch (FileNotFoundException e) {
// } catch (UnsupportedEncodingException e) {
// } catch (IOException e) {
// } finally {
// try {
// if (out != null)
// out.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
//
// public static FileConfiguration config;
//
// @Override
// public void reloadConfig() {
// FileInputStream in = null;
// config = new YamlConfiguration();
// try {
// File f = new File(getDataFolder(), "config.yml");
// in = new FileInputStream(f);
// byte[] data = new byte[(int) f.length()];
// in.read(data);
// String str = new String(data, "UTF-8");
// config.loadFromString(str);
// } catch (FileNotFoundException e) {
// } catch (IOException e) {
// } catch (InvalidConfigurationException e) {
// } finally {
// try {
// if (in != null)
// in.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// public FileConfiguration getConfig() {
// return config;
// }
//
// public void updateConfig() {
// ConfigUpdater.updateConfig(getConfig());
// saveConfig();
// }
//
// @Override
// public void onDisable() {
// }
//
// @Override
// public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(label).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// Commands.exec(sender, out.toString());
// return true;
// }
//
// @Override
// public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(alias).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// return Commands.complete(sender, out.toString());
// }
// }
// Path: src/think/rpgitems/config/Update01To02.java
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import think.rpgitems.Plugin;
/*
* This file is part of RPG Items.
*
* RPG Items 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.
*
* RPG Items 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 RPG Items. If not, see <http://www.gnu.org/licenses/>.
*/
package think.rpgitems.config;
public class Update01To02 implements Updater {
@Override
public void update(ConfigurationSection section) {
|
File iFile = new File(Plugin.plugin.getDataFolder(), "items.yml");
|
TheCreeperOfRedstone/RPG-Items-2
|
src/think/rpgitems/data/Font.java
|
// Path: src/think/rpgitems/Plugin.java
// @SuppressWarnings("deprecation")
// public class Plugin extends JavaPlugin {
//
// public static Logger logger = Logger.getLogger("RPGItems");
//
// public static Plugin plugin;
//
// @Override
// public void onLoad() {
// plugin = this;
// reloadConfig();
// Font.load();
// Power.powers.put("arrow", PowerArrow.class);
// Power.powers.put("tntcannon", PowerTNTCannon.class);
// Power.powers.put("rainbow", PowerRainbow.class);
// Power.powers.put("flame", PowerFlame.class);
// Power.powers.put("lightning", PowerLightning.class);
// Power.powers.put("command", PowerCommand.class);
// Power.powers.put("potionhit", PowerPotionHit.class);
// Power.powers.put("teleport", PowerTeleport.class);
// Power.powers.put("fireball", PowerFireball.class);
// Power.powers.put("ice", PowerIce.class);
// Power.powers.put("knockup", PowerKnockup.class);
// Power.powers.put("rush", PowerRush.class);
// Power.powers.put("potionself", PowerPotionSelf.class);
// Power.powers.put("consume", PowerConsume.class);
// Power.powers.put("unbreakable", PowerUnbreakable.class);
// Power.powers.put("unbreaking", PowerUnbreaking.class);
// Power.powers.put("rumble", PowerRumble.class);
// Power.powers.put("skyhook", PowerSkyHook.class);
// Power.powers.put("potiontick", PowerPotionTick.class);
// Power.powers.put("food", PowerFood.class);
// Power.powers.put("lifesteal", PowerLifeSteal.class);
// }
//
// @Override
// public void onEnable() {
// Locale.init(this);
// updateConfig();
// WorldGuard.init(this);
// ConfigurationSection conf = getConfig();
// if (conf.getBoolean("autoupdate", true)) {
// new Updater(this, 70226, this.getFile(), Updater.UpdateType.DEFAULT, false);
// }
// if (conf.getBoolean("localeInv", false)) {
// Events.useLocaleInv = true;
// }
// getServer().getPluginManager().registerEvents(new Events(), this);
// ItemManager.load(this);
// Commands.register(new Handler());
// Commands.register(new PowerHandler());
// new PowerTicker().runTaskTimer(this, 0, 1);
// }
//
// @Override
// public void saveConfig() {
// FileConfiguration config = getConfig();
// FileOutputStream out = null;
// try {
// File f = new File(getDataFolder(), "config.yml");
// if (!f.exists())
// f.createNewFile();
// out = new FileOutputStream(f);
// out.write(config.saveToString().getBytes("UTF-8"));
// } catch (FileNotFoundException e) {
// } catch (UnsupportedEncodingException e) {
// } catch (IOException e) {
// } finally {
// try {
// if (out != null)
// out.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
//
// public static FileConfiguration config;
//
// @Override
// public void reloadConfig() {
// FileInputStream in = null;
// config = new YamlConfiguration();
// try {
// File f = new File(getDataFolder(), "config.yml");
// in = new FileInputStream(f);
// byte[] data = new byte[(int) f.length()];
// in.read(data);
// String str = new String(data, "UTF-8");
// config.loadFromString(str);
// } catch (FileNotFoundException e) {
// } catch (IOException e) {
// } catch (InvalidConfigurationException e) {
// } finally {
// try {
// if (in != null)
// in.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// public FileConfiguration getConfig() {
// return config;
// }
//
// public void updateConfig() {
// ConfigUpdater.updateConfig(getConfig());
// saveConfig();
// }
//
// @Override
// public void onDisable() {
// }
//
// @Override
// public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(label).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// Commands.exec(sender, out.toString());
// return true;
// }
//
// @Override
// public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(alias).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// return Commands.complete(sender, out.toString());
// }
// }
|
import java.io.IOException;
import java.io.InputStream;
import think.rpgitems.Plugin;
|
/*
* This file is part of RPG Items.
*
* RPG Items 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.
*
* RPG Items 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 RPG Items. If not, see <http://www.gnu.org/licenses/>.
*/
package think.rpgitems.data;
public class Font {
public static int[] widths;
public static void load() {
widths = new int[0xFFFF];
try {
|
// Path: src/think/rpgitems/Plugin.java
// @SuppressWarnings("deprecation")
// public class Plugin extends JavaPlugin {
//
// public static Logger logger = Logger.getLogger("RPGItems");
//
// public static Plugin plugin;
//
// @Override
// public void onLoad() {
// plugin = this;
// reloadConfig();
// Font.load();
// Power.powers.put("arrow", PowerArrow.class);
// Power.powers.put("tntcannon", PowerTNTCannon.class);
// Power.powers.put("rainbow", PowerRainbow.class);
// Power.powers.put("flame", PowerFlame.class);
// Power.powers.put("lightning", PowerLightning.class);
// Power.powers.put("command", PowerCommand.class);
// Power.powers.put("potionhit", PowerPotionHit.class);
// Power.powers.put("teleport", PowerTeleport.class);
// Power.powers.put("fireball", PowerFireball.class);
// Power.powers.put("ice", PowerIce.class);
// Power.powers.put("knockup", PowerKnockup.class);
// Power.powers.put("rush", PowerRush.class);
// Power.powers.put("potionself", PowerPotionSelf.class);
// Power.powers.put("consume", PowerConsume.class);
// Power.powers.put("unbreakable", PowerUnbreakable.class);
// Power.powers.put("unbreaking", PowerUnbreaking.class);
// Power.powers.put("rumble", PowerRumble.class);
// Power.powers.put("skyhook", PowerSkyHook.class);
// Power.powers.put("potiontick", PowerPotionTick.class);
// Power.powers.put("food", PowerFood.class);
// Power.powers.put("lifesteal", PowerLifeSteal.class);
// }
//
// @Override
// public void onEnable() {
// Locale.init(this);
// updateConfig();
// WorldGuard.init(this);
// ConfigurationSection conf = getConfig();
// if (conf.getBoolean("autoupdate", true)) {
// new Updater(this, 70226, this.getFile(), Updater.UpdateType.DEFAULT, false);
// }
// if (conf.getBoolean("localeInv", false)) {
// Events.useLocaleInv = true;
// }
// getServer().getPluginManager().registerEvents(new Events(), this);
// ItemManager.load(this);
// Commands.register(new Handler());
// Commands.register(new PowerHandler());
// new PowerTicker().runTaskTimer(this, 0, 1);
// }
//
// @Override
// public void saveConfig() {
// FileConfiguration config = getConfig();
// FileOutputStream out = null;
// try {
// File f = new File(getDataFolder(), "config.yml");
// if (!f.exists())
// f.createNewFile();
// out = new FileOutputStream(f);
// out.write(config.saveToString().getBytes("UTF-8"));
// } catch (FileNotFoundException e) {
// } catch (UnsupportedEncodingException e) {
// } catch (IOException e) {
// } finally {
// try {
// if (out != null)
// out.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
//
// public static FileConfiguration config;
//
// @Override
// public void reloadConfig() {
// FileInputStream in = null;
// config = new YamlConfiguration();
// try {
// File f = new File(getDataFolder(), "config.yml");
// in = new FileInputStream(f);
// byte[] data = new byte[(int) f.length()];
// in.read(data);
// String str = new String(data, "UTF-8");
// config.loadFromString(str);
// } catch (FileNotFoundException e) {
// } catch (IOException e) {
// } catch (InvalidConfigurationException e) {
// } finally {
// try {
// if (in != null)
// in.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// public FileConfiguration getConfig() {
// return config;
// }
//
// public void updateConfig() {
// ConfigUpdater.updateConfig(getConfig());
// saveConfig();
// }
//
// @Override
// public void onDisable() {
// }
//
// @Override
// public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(label).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// Commands.exec(sender, out.toString());
// return true;
// }
//
// @Override
// public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// StringBuilder out = new StringBuilder();
// out.append(alias).append(' ');
// for (String arg : args)
// out.append(arg).append(' ');
// return Commands.complete(sender, out.toString());
// }
// }
// Path: src/think/rpgitems/data/Font.java
import java.io.IOException;
import java.io.InputStream;
import think.rpgitems.Plugin;
/*
* This file is part of RPG Items.
*
* RPG Items 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.
*
* RPG Items 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 RPG Items. If not, see <http://www.gnu.org/licenses/>.
*/
package think.rpgitems.data;
public class Font {
public static int[] widths;
public static void load() {
widths = new int[0xFFFF];
try {
|
InputStream in = Plugin.plugin.getResource("font.bin");
|
bonigarcia/dualsub
|
src/test/java/io/github/bonigarcia/dualsub/test/TestCharset.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Charset.java
// public class Charset {
//
// public static String ISO88591 = "ISO-8859-1";
// public static String UTF8 = "UTF-8";
//
// private static Charset singleton = null;
//
// private UniversalDetector detector;
//
// public Charset() {
// detector = new UniversalDetector(null);
// }
//
// public static Charset getSingleton() {
// if (singleton == null) {
// singleton = new Charset();
// }
// return singleton;
// }
//
// public static String detect(String file) throws IOException {
// InputStream inputStream = Thread.currentThread()
// .getContextClassLoader().getResourceAsStream(file);
// if (inputStream == null) {
// inputStream = new BufferedInputStream(new FileInputStream(file));
// }
// return Charset.detect(inputStream);
// }
//
// public static String detect(InputStream inputStream) throws IOException {
// UniversalDetector detector = Charset.getSingleton()
// .getCharsetDetector();
// byte[] buf = new byte[4096];
// int nread;
// while ((nread = inputStream.read(buf)) > 0 && !detector.isDone()) {
// detector.handleData(buf, 0, nread);
// }
// detector.dataEnd();
// String encoding = detector.getDetectedCharset();
// detector.reset();
// inputStream.close();
// if (encoding == null) {
// // If none encoding is detected, we assume UTF-8
// encoding = UTF8;
// }
// return encoding;
// }
//
// public UniversalDetector getCharsetDetector() {
// return detector;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.Charset;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.test;
/**
* TestCharset.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class TestCharset {
private static final Logger log = LoggerFactory
.getLogger(TestCharset.class);
@Ignore
@Test
public void testCharsetGoT() throws IOException, SAXException {
String gotEnFile = "Game of Thrones 1x01 - Winter Is Coming (English).srt";
String gotEsFile = "Game of Thrones 1x01 - Winter Is Coming (Spanish).srt";
InputStream isEsFile = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(gotEsFile);
InputStream isEnFile = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(gotEnFile);
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Charset.java
// public class Charset {
//
// public static String ISO88591 = "ISO-8859-1";
// public static String UTF8 = "UTF-8";
//
// private static Charset singleton = null;
//
// private UniversalDetector detector;
//
// public Charset() {
// detector = new UniversalDetector(null);
// }
//
// public static Charset getSingleton() {
// if (singleton == null) {
// singleton = new Charset();
// }
// return singleton;
// }
//
// public static String detect(String file) throws IOException {
// InputStream inputStream = Thread.currentThread()
// .getContextClassLoader().getResourceAsStream(file);
// if (inputStream == null) {
// inputStream = new BufferedInputStream(new FileInputStream(file));
// }
// return Charset.detect(inputStream);
// }
//
// public static String detect(InputStream inputStream) throws IOException {
// UniversalDetector detector = Charset.getSingleton()
// .getCharsetDetector();
// byte[] buf = new byte[4096];
// int nread;
// while ((nread = inputStream.read(buf)) > 0 && !detector.isDone()) {
// detector.handleData(buf, 0, nread);
// }
// detector.dataEnd();
// String encoding = detector.getDetectedCharset();
// detector.reset();
// inputStream.close();
// if (encoding == null) {
// // If none encoding is detected, we assume UTF-8
// encoding = UTF8;
// }
// return encoding;
// }
//
// public UniversalDetector getCharsetDetector() {
// return detector;
// }
//
// }
// Path: src/test/java/io/github/bonigarcia/dualsub/test/TestCharset.java
import io.github.bonigarcia.dualsub.util.Charset;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.test;
/**
* TestCharset.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class TestCharset {
private static final Logger log = LoggerFactory
.getLogger(TestCharset.class);
@Ignore
@Test
public void testCharsetGoT() throws IOException, SAXException {
String gotEnFile = "Game of Thrones 1x01 - Winter Is Coming (English).srt";
String gotEsFile = "Game of Thrones 1x01 - Winter Is Coming (Spanish).srt";
InputStream isEsFile = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(gotEsFile);
InputStream isEnFile = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(gotEnFile);
|
log.info(Charset.detect(isEnFile));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/PanelPlayer.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Font.java
// public class Font {
//
// private List<String> fontList;
// private String[] widthList;
// private static Properties properties;
// private static Font singleton = null;
//
// public Font() {
// fontList = new ArrayList<String>();
// widthList = properties.getProperty("widths").split(",");
//
// GraphicsEnvironment e = GraphicsEnvironment
// .getLocalGraphicsEnvironment();
// for (String font : e.getAvailableFontFamilyNames()) {
// fontList.add(font);
// }
// }
//
// public static Font getSingleton() {
// if (singleton == null) {
// singleton = new Font();
// }
// return singleton;
// }
//
// public static void setProperties(Properties properties) {
// Font.properties = properties;
// }
//
// public static String[] getFontList() {
// return Font.getSingleton().fontList.toArray(new String[Font
// .getSingleton().fontList.size()]);
// }
//
// public static String[] getWidthList() {
// return Font.getSingleton().widthList;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.Font;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelPlayer.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelPlayer extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelPlayer.class);
private static final long serialVersionUID = 1L;
// Parent
private DualSub parent;
// UI Elements
private JTextField sizePx;
private JComboBox<String> fontComboBox;
private JComboBox<String> sizeComboBox;
public PanelPlayer(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setLayout(null);
this.setBorder(new TitledBorder(UIManager
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Font.java
// public class Font {
//
// private List<String> fontList;
// private String[] widthList;
// private static Properties properties;
// private static Font singleton = null;
//
// public Font() {
// fontList = new ArrayList<String>();
// widthList = properties.getProperty("widths").split(",");
//
// GraphicsEnvironment e = GraphicsEnvironment
// .getLocalGraphicsEnvironment();
// for (String font : e.getAvailableFontFamilyNames()) {
// fontList.add(font);
// }
// }
//
// public static Font getSingleton() {
// if (singleton == null) {
// singleton = new Font();
// }
// return singleton;
// }
//
// public static void setProperties(Properties properties) {
// Font.properties = properties;
// }
//
// public static String[] getFontList() {
// return Font.getSingleton().fontList.toArray(new String[Font
// .getSingleton().fontList.size()]);
// }
//
// public static String[] getWidthList() {
// return Font.getSingleton().widthList;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/PanelPlayer.java
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.Font;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelPlayer.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelPlayer extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelPlayer.class);
private static final long serialVersionUID = 1L;
// Parent
private DualSub parent;
// UI Elements
private JTextField sizePx;
private JComboBox<String> fontComboBox;
private JComboBox<String> sizeComboBox;
public PanelPlayer(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setLayout(null);
this.setBorder(new TitledBorder(UIManager
|
.getBorder("TitledBorder.border"), I18N
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/PanelPlayer.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Font.java
// public class Font {
//
// private List<String> fontList;
// private String[] widthList;
// private static Properties properties;
// private static Font singleton = null;
//
// public Font() {
// fontList = new ArrayList<String>();
// widthList = properties.getProperty("widths").split(",");
//
// GraphicsEnvironment e = GraphicsEnvironment
// .getLocalGraphicsEnvironment();
// for (String font : e.getAvailableFontFamilyNames()) {
// fontList.add(font);
// }
// }
//
// public static Font getSingleton() {
// if (singleton == null) {
// singleton = new Font();
// }
// return singleton;
// }
//
// public static void setProperties(Properties properties) {
// Font.properties = properties;
// }
//
// public static String[] getFontList() {
// return Font.getSingleton().fontList.toArray(new String[Font
// .getSingleton().fontList.size()]);
// }
//
// public static String[] getWidthList() {
// return Font.getSingleton().widthList;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.Font;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
|
this.setBorder(new TitledBorder(UIManager
.getBorder("TitledBorder.border"), I18N
.getHtmlText("PanelPlayer.border.text"), TitledBorder.LEADING,
TitledBorder.TOP, null, null));
this.setBounds(46, 220, 305, 111);
this.setBackground(parent.getBackground());
// Width
JLabel lblWitdh = new JLabel(
I18N.getHtmlText("PanelPlayer.lblWidth.text"));
lblWitdh.setBounds(10, 26, 140, 20);
this.add(lblWitdh);
sizePx = new JTextField();
sizePx.setColumns(10);
sizePx.setBounds(150, 26, 60, 20);
String savedWitdth = parent.getPreferences().get("width",
parent.getProperties().getProperty("width"));
sizePx.setText(savedWitdth);
this.add(sizePx);
JLabel lblPx = new JLabel(I18N.getHtmlText("PanelPlayer.lblPx.text"));
lblPx.setBounds(215, 26, 40, 20);
this.add(lblPx);
// Font
JLabel lblFont = new JLabel(
I18N.getHtmlText("PanelPlayer.lblFont.text"));
lblFont.setBounds(10, 50, 140, 20);
this.add(lblFont);
fontComboBox = new JComboBox<String>();
fontComboBox.setBounds(150, 49, 150, 20);
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Font.java
// public class Font {
//
// private List<String> fontList;
// private String[] widthList;
// private static Properties properties;
// private static Font singleton = null;
//
// public Font() {
// fontList = new ArrayList<String>();
// widthList = properties.getProperty("widths").split(",");
//
// GraphicsEnvironment e = GraphicsEnvironment
// .getLocalGraphicsEnvironment();
// for (String font : e.getAvailableFontFamilyNames()) {
// fontList.add(font);
// }
// }
//
// public static Font getSingleton() {
// if (singleton == null) {
// singleton = new Font();
// }
// return singleton;
// }
//
// public static void setProperties(Properties properties) {
// Font.properties = properties;
// }
//
// public static String[] getFontList() {
// return Font.getSingleton().fontList.toArray(new String[Font
// .getSingleton().fontList.size()]);
// }
//
// public static String[] getWidthList() {
// return Font.getSingleton().widthList;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/PanelPlayer.java
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.Font;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
this.setBorder(new TitledBorder(UIManager
.getBorder("TitledBorder.border"), I18N
.getHtmlText("PanelPlayer.border.text"), TitledBorder.LEADING,
TitledBorder.TOP, null, null));
this.setBounds(46, 220, 305, 111);
this.setBackground(parent.getBackground());
// Width
JLabel lblWitdh = new JLabel(
I18N.getHtmlText("PanelPlayer.lblWidth.text"));
lblWitdh.setBounds(10, 26, 140, 20);
this.add(lblWitdh);
sizePx = new JTextField();
sizePx.setColumns(10);
sizePx.setBounds(150, 26, 60, 20);
String savedWitdth = parent.getPreferences().get("width",
parent.getProperties().getProperty("width"));
sizePx.setText(savedWitdth);
this.add(sizePx);
JLabel lblPx = new JLabel(I18N.getHtmlText("PanelPlayer.lblPx.text"));
lblPx.setBounds(215, 26, 40, 20);
this.add(lblPx);
// Font
JLabel lblFont = new JLabel(
I18N.getHtmlText("PanelPlayer.lblFont.text"));
lblFont.setBounds(10, 50, 140, 20);
this.add(lblFont);
fontComboBox = new JComboBox<String>();
fontComboBox.setBounds(150, 49, 150, 20);
|
fontComboBox.setModel(new DefaultComboBoxModel<String>(Font
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpTimingDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpTimingDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpTimingDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpTimingDialog.class);
private static final long serialVersionUID = 1L;
public HelpTimingDialog(DualSub parent, boolean modal) {
super(parent, modal);
setHeight(800);
parent.setHelpTiming(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 1000));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpTimingDialog.java
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpTimingDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpTimingDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpTimingDialog.class);
private static final long serialVersionUID = 1L;
public HelpTimingDialog(DualSub parent, boolean modal) {
super(parent, modal);
setHeight(800);
parent.setHelpTiming(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 1000));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
final String title = I18N.getHtmlText("PanelOutput.border.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpTimingDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
|
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 1000));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("PanelOutput.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 435, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("HelpTimingDialog.help.01"));
lblContent01.setBounds(marginLeft, 50, 435, 220);
panel.add(lblContent01);
JLabel lblContent02 = new JLabel(I18N.getHtmlText(
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpTimingDialog.java
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 1000));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("PanelOutput.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 435, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("HelpTimingDialog.help.01"));
lblContent01.setBounds(marginLeft, 50, 435, 220);
panel.add(lblContent01);
JLabel lblContent02 = new JLabel(I18N.getHtmlText(
|
"HelpTimingDialog.help.02", Html.BOLD));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/CharsetItem.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* CharsetItem.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class CharsetItem implements Comparable<Object> {
private String id;
private String description;
public CharsetItem(String id, String description) {
this.id = id;
this.description = description;
}
public String getId() {
return id;
}
public String getDescription() {
return description;
}
public String toString() {
String output = id;
if (!description.isEmpty()) {
output += " - " + description;
}
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/CharsetItem.java
import io.github.bonigarcia.dualsub.util.I18N;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* CharsetItem.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class CharsetItem implements Comparable<Object> {
private String id;
private String description;
public CharsetItem(String id, String description) {
this.id = id;
this.description = description;
}
public String getId() {
return id;
}
public String getDescription() {
return description;
}
public String toString() {
String output = id;
if (!description.isEmpty()) {
output += " - " + description;
}
|
return I18N.HTML_INIT_TAG + output + I18N.HTML_END_TAG;
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpOutputDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpOutputDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpOutputDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpOutputDialog.class);
private static final long serialVersionUID = 1L;
public HelpOutputDialog(DualSub parent, boolean modal) {
super(parent, modal);
setWidth(600);
parent.setHelpOutput(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 100));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpOutputDialog.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpOutputDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpOutputDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpOutputDialog.class);
private static final long serialVersionUID = 1L;
public HelpOutputDialog(DualSub parent, boolean modal) {
super(parent, modal);
setWidth(600);
parent.setHelpOutput(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 100));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
final String title = I18N.getHtmlText("PanelOutput.border.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpOutputDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
|
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 100));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("PanelOutput.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 535, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("HelpOutputDialog.help.01"));
lblContent01.setBounds(marginLeft, 50, 535, 230);
panel.add(lblContent01);
JLabel lblContent02 = new JLabel(I18N.getHtmlText(
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpOutputDialog.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 100));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("PanelOutput.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 535, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("HelpOutputDialog.help.01"));
lblContent01.setBounds(marginLeft, 50, 535, 230);
panel.add(lblContent01);
JLabel lblContent02 = new JLabel(I18N.getHtmlText(
|
"HelpOutputDialog.help.02", Html.MONOSPACE));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/KeyTranslationDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
|
/*
* (C) Copyright 2017 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpTranslationDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.2.0
*/
public class KeyTranslationDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(KeyTranslationDialog.class);
private static final long serialVersionUID = 1L;
private String key;
private JTextField keyValue;
public KeyTranslationDialog(DualSub parent, boolean modal, String key) {
super(parent, modal);
this.key = key;
setHeight(280);
parent.setKeyTranslationDialog(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 30;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight()));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/KeyTranslationDialog.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
/*
* (C) Copyright 2017 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpTranslationDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.2.0
*/
public class KeyTranslationDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(KeyTranslationDialog.class);
private static final long serialVersionUID = 1L;
private String key;
private JTextField keyValue;
public KeyTranslationDialog(DualSub parent, boolean modal, String key) {
super(parent, modal);
this.key = key;
setHeight(280);
parent.setKeyTranslationDialog(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 30;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight()));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
final String title = I18N.getHtmlText("KeyTranslation.border.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/KeyTranslationDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
|
protected void initComponents() {
// Features
final int marginLeft = 30;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight()));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("KeyTranslation.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 435, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("KeyTranslation.help.01"));
lblContent01.setBounds(marginLeft, 50, 435, 80);
panel.add(lblContent01);
JButton lblContent02 = new UrlButton(
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/KeyTranslationDialog.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
protected void initComponents() {
// Features
final int marginLeft = 30;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight()));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("KeyTranslation.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 435, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("KeyTranslation.help.01"));
lblContent01.setBounds(marginLeft, 50, 435, 80);
panel.add(lblContent01);
JButton lblContent02 = new UrlButton(
|
I18N.getHtmlText("KeyTranslation.help.02", Html.LINK),
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/srt/Merger.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import java.io.File;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
} else {
dualSrt.addEntry(t, new Entry[] { subtitlesLeft.get(t),
new Entry() });
}
}
if (!subtitlesRight.isEmpty()) {
for (String t : subtitlesRight.keySet()) {
log.debug("Desynchronization on " + t + " "
+ subtitlesRight.get(t).subtitleLines);
dualSrt.processDesync(t, subtitlesRight.get(t));
}
}
}
return dualSrt;
}
public String getMergedFileName(Srt subs1, Srt subs2) {
String mergedFileName = "";
if (translate) {
Srt srt = subs1.getFileName() == null ? subs2 : subs1;
File file = new File(srt.getFileName());
String fileName = file.getName();
int i = fileName.lastIndexOf('.');
i = i == -1 ? fileName.length() - 1 : i;
String extension = fileName.substring(i);
mergedFileName = getOutputFolder() + File.separator
+ fileName.substring(0, i);
if (merge) {
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/srt/Merger.java
import io.github.bonigarcia.dualsub.util.I18N;
import java.io.File;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
} else {
dualSrt.addEntry(t, new Entry[] { subtitlesLeft.get(t),
new Entry() });
}
}
if (!subtitlesRight.isEmpty()) {
for (String t : subtitlesRight.keySet()) {
log.debug("Desynchronization on " + t + " "
+ subtitlesRight.get(t).subtitleLines);
dualSrt.processDesync(t, subtitlesRight.get(t));
}
}
}
return dualSrt;
}
public String getMergedFileName(Srt subs1, Srt subs2) {
String mergedFileName = "";
if (translate) {
Srt srt = subs1.getFileName() == null ? subs2 : subs1;
File file = new File(srt.getFileName());
String fileName = file.getName();
int i = fileName.lastIndexOf('.');
i = i == -1 ? fileName.length() - 1 : i;
String extension = fileName.substring(i);
mergedFileName = getOutputFolder() + File.separator
+ fileName.substring(0, i);
if (merge) {
|
mergedFileName += " " + I18N.getText("Merger.merged.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpTranslationDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpTranslationDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpTranslationDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpTranslationDialog.class);
private static final long serialVersionUID = 1L;
public HelpTranslationDialog(DualSub parent, boolean modal) {
super(parent, modal);
setHeight(330);
parent.setHelpTranslation(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 30;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight()));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpTranslationDialog.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpTranslationDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpTranslationDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpTranslationDialog.class);
private static final long serialVersionUID = 1L;
public HelpTranslationDialog(DualSub parent, boolean modal) {
super(parent, modal);
setHeight(330);
parent.setHelpTranslation(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 30;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight()));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
final String title = I18N.getHtmlText("PanelTranslation.border.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/PanelTranslation.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.Vector;
import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelTranslation.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelTranslation extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelTranslation.class);
private static final long serialVersionUID = 1L;
// Parent
private DualSub parent;
// UI Elements
private JCheckBox enableTranslation;
private JComboBox<LangItem> fromComboBox;
private JComboBox<LangItem> toComboBox;
private JRadioButton rdbtnMerged;
private JRadioButton rdbtnTranslated;
public PanelTranslation(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setLayout(null);
this.setBorder(
new TitledBorder(UIManager.getBorder("TitledBorder.border"),
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/PanelTranslation.java
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.Vector;
import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelTranslation.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelTranslation extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelTranslation.class);
private static final long serialVersionUID = 1L;
// Parent
private DualSub parent;
// UI Elements
private JCheckBox enableTranslation;
private JComboBox<LangItem> fromComboBox;
private JComboBox<LangItem> toComboBox;
private JRadioButton rdbtnMerged;
private JRadioButton rdbtnTranslated;
public PanelTranslation(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setLayout(null);
this.setBorder(
new TitledBorder(UIManager.getBorder("TitledBorder.border"),
|
I18N.getHtmlText("PanelTranslation.border.text"),
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/PanelTiming.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelTiming.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelTiming extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelTiming.class);
private static final long serialVersionUID = 1L;
// Parent
private DualSub parent;
// UI Elements
private JTextField extensionSeconds;
private JCheckBox progressiveCheckBox;
private JRadioButton rdbtnYes;
private JRadioButton rdbtnNo;
private JComboBox<String> desyncComboBox;
public PanelTiming(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setBorder(new TitledBorder(UIManager
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/PanelTiming.java
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelTiming.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelTiming extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelTiming.class);
private static final long serialVersionUID = 1L;
// Parent
private DualSub parent;
// UI Elements
private JTextField extensionSeconds;
private JCheckBox progressiveCheckBox;
private JRadioButton rdbtnYes;
private JRadioButton rdbtnNo;
private JComboBox<String> desyncComboBox;
public PanelTiming(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setBorder(new TitledBorder(UIManager
|
.getBorder("TitledBorder.border"), I18N
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/ExceptionDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* ExceptionDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class ExceptionDialog extends JDialog {
private static final Logger log = LoggerFactory
.getLogger(ExceptionDialog.class);
private static final long serialVersionUID = 1L;
private DualSub parent;
private Throwable exception;
public ExceptionDialog(DualSub parent, boolean modal, Throwable exception) {
super(parent.getFrame(), modal);
this.parent = parent;
this.exception = exception;
initComponents();
parent.setException(this);
}
public void setVisible() {
final int width = 500;
final int height = 430;
this.setBounds(100, 100, width, height);
Point point = parent.getFrame().getLocationOnScreen();
Dimension size = parent.getFrame().getSize();
this.setLocation(
(int) (point.getX() + ((size.getWidth() - width) / 2)),
(int) (point.getY() + ((size.getHeight() - height) / 2)));
setVisible(true);
}
private void initComponents() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/ExceptionDialog.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* ExceptionDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class ExceptionDialog extends JDialog {
private static final Logger log = LoggerFactory
.getLogger(ExceptionDialog.class);
private static final long serialVersionUID = 1L;
private DualSub parent;
private Throwable exception;
public ExceptionDialog(DualSub parent, boolean modal, Throwable exception) {
super(parent.getFrame(), modal);
this.parent = parent;
this.exception = exception;
initComponents();
parent.setException(this);
}
public void setVisible() {
final int width = 500;
final int height = 430;
this.setBounds(100, 100, width, height);
Point point = parent.getFrame().getLocationOnScreen();
Dimension size = parent.getFrame().getSize();
this.setLocation(
(int) (point.getX() + ((size.getWidth() - width) / 2)),
(int) (point.getY() + ((size.getHeight() - height) / 2)));
setVisible(true);
}
private void initComponents() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
setTitle(I18N.getText("Window.name.text"));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/srt/DualSrt.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.text.ParseException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
|
(s + SrtUtils.EOL).getBytes(Charset.forName(charsetStr)));
fileChannel.write(byteBuffer);
}
byteBuffer = ByteBuffer
.wrap(SrtUtils.EOL.getBytes(Charset.forName(charsetStr)));
fileChannel.write(byteBuffer);
fileChannel.close();
fileOutputStream.close();
}
/**
* Adds an entry in the end of the merged subtitles with the program author.
*
* @param subs
* @throws ParseException
*/
private List<String> signature(boolean translate, boolean merge)
throws ParseException {
String lastEntryTime = (String) subtitles.keySet()
.toArray()[subtitles.keySet().size() - 1];
Date end = SrtUtils.getEndTime(lastEntryTime);
final Date newDateInit = new Date(end.getTime() + signatureGap);
final Date newDateEnd = new Date(end.getTime() + signatureTime);
String newTime = SrtUtils.createSrtTime(newDateInit, newDateEnd);
List<String> signature = new LinkedList<String>();
signature.add(String.valueOf(subtitles.size() + 1));
signature.add(newTime);
String signatureText = "";
if (translate & merge) {
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/srt/DualSrt.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.text.ParseException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
(s + SrtUtils.EOL).getBytes(Charset.forName(charsetStr)));
fileChannel.write(byteBuffer);
}
byteBuffer = ByteBuffer
.wrap(SrtUtils.EOL.getBytes(Charset.forName(charsetStr)));
fileChannel.write(byteBuffer);
fileChannel.close();
fileOutputStream.close();
}
/**
* Adds an entry in the end of the merged subtitles with the program author.
*
* @param subs
* @throws ParseException
*/
private List<String> signature(boolean translate, boolean merge)
throws ParseException {
String lastEntryTime = (String) subtitles.keySet()
.toArray()[subtitles.keySet().size() - 1];
Date end = SrtUtils.getEndTime(lastEntryTime);
final Date newDateInit = new Date(end.getTime() + signatureGap);
final Date newDateEnd = new Date(end.getTime() + signatureTime);
String newTime = SrtUtils.createSrtTime(newDateInit, newDateEnd);
List<String> signature = new LinkedList<String>();
signature.add(String.valueOf(subtitles.size() + 1));
signature.add(newTime);
String signatureText = "";
if (translate & merge) {
|
signatureText = I18N.getText("Merger.signatureboth.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/AddFileListener.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.filechooser.FileFilter;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* AddFileListener.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class AddFileListener implements ActionListener {
private JList<File> list;
private JFrame frame;
public AddFileListener(JFrame frame, JList<File> list) {
this.frame = frame;
this.list = list;
}
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(".srt")
|| f.isDirectory();
}
public String getDescription() {
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/AddFileListener.java
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.filechooser.FileFilter;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* AddFileListener.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class AddFileListener implements ActionListener {
private JList<File> list;
private JFrame frame;
public AddFileListener(JFrame frame, JList<File> list) {
this.frame = frame;
this.list = list;
}
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(".srt")
|| f.isDirectory();
}
public String getDescription() {
|
return I18N.getHtmlText("AddFileListener.fileChooser.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/Menu.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* Menu.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class Menu {
private final DualSub parent;
private String locale;
private JMenuItem addLeftSubItem;
private JMenuItem addRightSubItem;
// Dialogs
private AboutDialog about;
public Menu(DualSub parent, String locale) {
this.parent = parent;
this.locale = locale;
}
public void addMenu(ActionListener... listeners) throws IOException {
JMenuBar menuBar = new JMenuBar();
parent.getFrame().setJMenuBar(menuBar);
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/Menu.java
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* Menu.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class Menu {
private final DualSub parent;
private String locale;
private JMenuItem addLeftSubItem;
private JMenuItem addRightSubItem;
// Dialogs
private AboutDialog about;
public Menu(DualSub parent, String locale) {
this.parent = parent;
this.locale = locale;
}
public void addMenu(ActionListener... listeners) throws IOException {
JMenuBar menuBar = new JMenuBar();
parent.getFrame().setJMenuBar(menuBar);
|
JMenu subtitleMenu = new JMenu(I18N.getHtmlText("Menu.actions.text"));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/Alert.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* Alert.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class Alert {
private static Alert singleton = null;
private JFrame frame;
public static Alert getSingleton() {
if (singleton == null) {
singleton = new Alert();
}
return singleton;
}
public static void error(String message) {
JOptionPane.showMessageDialog(Alert.getSingleton().getFrame(), message,
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/Alert.java
import io.github.bonigarcia.dualsub.util.I18N;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* Alert.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class Alert {
private static Alert singleton = null;
private JFrame frame;
public static Alert getSingleton() {
if (singleton == null) {
singleton = new Alert();
}
return singleton;
}
public static void error(String message) {
JOptionPane.showMessageDialog(Alert.getSingleton().getFrame(), message,
|
I18N.getText("Window.name.text"), JOptionPane.ERROR_MESSAGE);
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/LangListener.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.prefs.Preferences;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* LangListener.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class LangListener implements ActionListener {
private String locale;
private Preferences preferences;
public LangListener(String locale, Preferences preferences) {
this.locale = locale;
this.preferences = preferences;
}
@Override
public void actionPerformed(ActionEvent arg0) {
preferences.put("locale", locale);
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/LangListener.java
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.prefs.Preferences;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* LangListener.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class LangListener implements ActionListener {
private String locale;
private Preferences preferences;
public LangListener(String locale, Preferences preferences) {
this.locale = locale;
this.preferences = preferences;
}
@Override
public void actionPerformed(ActionEvent arg0) {
preferences.put("locale", locale);
|
Alert.info(I18N.getHtmlText("LangListener.changes.alert"));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpPlayerDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpPlayerDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpPlayerDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpPlayerDialog.class);
private static final long serialVersionUID = 1L;
public HelpPlayerDialog(DualSub parent, boolean modal) {
super(parent, modal);
parent.setHelpPlayer(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 140));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpPlayerDialog.java
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpPlayerDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpPlayerDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpPlayerDialog.class);
private static final long serialVersionUID = 1L;
public HelpPlayerDialog(DualSub parent, boolean modal) {
super(parent, modal);
parent.setHelpPlayer(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 140));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
final String title = I18N.getHtmlText("PanelOutput.border.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpPlayerDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
|
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
|
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 140));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("PanelOutput.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 435, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("HelpPlayerDialog.help.01"));
lblContent01.setBounds(marginLeft, 50, 435, 120);
panel.add(lblContent01);
JButton lblContent02 = new UrlButton(I18N.getHtmlText(
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpPlayerDialog.java
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import io.github.bonigarcia.dualsub.util.I18N.Html;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 140));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
final String title = I18N.getHtmlText("PanelOutput.border.text");
setTitle(I18N.getText("Window.name.text"));
JLabel lblTitle = new JLabel(title);
lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
lblTitle.setBounds(marginLeft, 21, 435, 25);
panel.add(lblTitle);
// Content
JLabel lblContent01 = new JLabel(
I18N.getHtmlText("HelpPlayerDialog.help.01"));
lblContent01.setBounds(marginLeft, 50, 435, 120);
panel.add(lblContent01);
JButton lblContent02 = new UrlButton(I18N.getHtmlText(
|
"HelpPlayerDialog.help.02", Html.LINK), parent.getCursor(),
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/HelpSubtitlesDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpSubtitlesDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpSubtitlesDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpSubtitlesDialog.class);
private static final long serialVersionUID = 1L;
public HelpSubtitlesDialog(DualSub parent, boolean modal) {
super(parent, modal);
parent.setHelpSubtitles(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 620));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/HelpSubtitlesDialog.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* HelpSubtitlesDialog.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class HelpSubtitlesDialog extends HelpParent {
private static final Logger log = LoggerFactory
.getLogger(HelpSubtitlesDialog.class);
private static final long serialVersionUID = 1L;
public HelpSubtitlesDialog(DualSub parent, boolean modal) {
super(parent, modal);
parent.setHelpSubtitles(this);
}
@Override
protected void initComponents() {
// Features
final int marginLeft = 23;
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
getContentPane().setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 620));
panel.setBackground(parent.getBackground());
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(scroll);
// Title
|
final String title = I18N.getHtmlText("Window.mergeButton.text");
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/AboutDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Charset.java
// public class Charset {
//
// public static String ISO88591 = "ISO-8859-1";
// public static String UTF8 = "UTF-8";
//
// private static Charset singleton = null;
//
// private UniversalDetector detector;
//
// public Charset() {
// detector = new UniversalDetector(null);
// }
//
// public static Charset getSingleton() {
// if (singleton == null) {
// singleton = new Charset();
// }
// return singleton;
// }
//
// public static String detect(String file) throws IOException {
// InputStream inputStream = Thread.currentThread()
// .getContextClassLoader().getResourceAsStream(file);
// if (inputStream == null) {
// inputStream = new BufferedInputStream(new FileInputStream(file));
// }
// return Charset.detect(inputStream);
// }
//
// public static String detect(InputStream inputStream) throws IOException {
// UniversalDetector detector = Charset.getSingleton()
// .getCharsetDetector();
// byte[] buf = new byte[4096];
// int nread;
// while ((nread = inputStream.read(buf)) > 0 && !detector.isDone()) {
// detector.handleData(buf, 0, nread);
// }
// detector.dataEnd();
// String encoding = detector.getDetectedCharset();
// detector.reset();
// inputStream.close();
// if (encoding == null) {
// // If none encoding is detected, we assume UTF-8
// encoding = UTF8;
// }
// return encoding;
// }
//
// public UniversalDetector getCharsetDetector() {
// return detector;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.Charset;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.markdown4j.Markdown4jProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
public AboutDialog(DualSub parent, boolean modal) {
super(parent.getFrame(), modal);
this.parent = parent;
initComponents();
Runnable doScroll = new Runnable() {
public void run() {
scrollPane.getVerticalScrollBar().setValue(0);
scrollChangelog.getVerticalScrollBar().setValue(0);
scrollLicense.getVerticalScrollBar().setValue(0);
}
};
SwingUtilities.invokeLater(doScroll);
}
public void setVisible() {
final int width = 500;
final int height = 430;
this.setBounds(100, 100, width, height);
Point point = parent.getFrame().getLocationOnScreen();
Dimension size = parent.getFrame().getSize();
this.setLocation(
(int) (point.getX() + ((size.getWidth() - width) / 2)),
(int) (point.getY() + ((size.getHeight() - height) / 2)));
setVisible(true);
}
private void initComponents() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Charset.java
// public class Charset {
//
// public static String ISO88591 = "ISO-8859-1";
// public static String UTF8 = "UTF-8";
//
// private static Charset singleton = null;
//
// private UniversalDetector detector;
//
// public Charset() {
// detector = new UniversalDetector(null);
// }
//
// public static Charset getSingleton() {
// if (singleton == null) {
// singleton = new Charset();
// }
// return singleton;
// }
//
// public static String detect(String file) throws IOException {
// InputStream inputStream = Thread.currentThread()
// .getContextClassLoader().getResourceAsStream(file);
// if (inputStream == null) {
// inputStream = new BufferedInputStream(new FileInputStream(file));
// }
// return Charset.detect(inputStream);
// }
//
// public static String detect(InputStream inputStream) throws IOException {
// UniversalDetector detector = Charset.getSingleton()
// .getCharsetDetector();
// byte[] buf = new byte[4096];
// int nread;
// while ((nread = inputStream.read(buf)) > 0 && !detector.isDone()) {
// detector.handleData(buf, 0, nread);
// }
// detector.dataEnd();
// String encoding = detector.getDetectedCharset();
// detector.reset();
// inputStream.close();
// if (encoding == null) {
// // If none encoding is detected, we assume UTF-8
// encoding = UTF8;
// }
// return encoding;
// }
//
// public UniversalDetector getCharsetDetector() {
// return detector;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/AboutDialog.java
import io.github.bonigarcia.dualsub.util.Charset;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.markdown4j.Markdown4jProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public AboutDialog(DualSub parent, boolean modal) {
super(parent.getFrame(), modal);
this.parent = parent;
initComponents();
Runnable doScroll = new Runnable() {
public void run() {
scrollPane.getVerticalScrollBar().setValue(0);
scrollChangelog.getVerticalScrollBar().setValue(0);
scrollLicense.getVerticalScrollBar().setValue(0);
}
};
SwingUtilities.invokeLater(doScroll);
}
public void setVisible() {
final int width = 500;
final int height = 430;
this.setBounds(100, 100, width, height);
Point point = parent.getFrame().getLocationOnScreen();
Dimension size = parent.getFrame().getSize();
this.setLocation(
(int) (point.getX() + ((size.getWidth() - width) / 2)),
(int) (point.getY() + ((size.getHeight() - height) / 2)));
setVisible(true);
}
private void initComponents() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
setTitle(I18N.getText("Window.name.text"));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/AboutDialog.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Charset.java
// public class Charset {
//
// public static String ISO88591 = "ISO-8859-1";
// public static String UTF8 = "UTF-8";
//
// private static Charset singleton = null;
//
// private UniversalDetector detector;
//
// public Charset() {
// detector = new UniversalDetector(null);
// }
//
// public static Charset getSingleton() {
// if (singleton == null) {
// singleton = new Charset();
// }
// return singleton;
// }
//
// public static String detect(String file) throws IOException {
// InputStream inputStream = Thread.currentThread()
// .getContextClassLoader().getResourceAsStream(file);
// if (inputStream == null) {
// inputStream = new BufferedInputStream(new FileInputStream(file));
// }
// return Charset.detect(inputStream);
// }
//
// public static String detect(InputStream inputStream) throws IOException {
// UniversalDetector detector = Charset.getSingleton()
// .getCharsetDetector();
// byte[] buf = new byte[4096];
// int nread;
// while ((nread = inputStream.read(buf)) > 0 && !detector.isDone()) {
// detector.handleData(buf, 0, nread);
// }
// detector.dataEnd();
// String encoding = detector.getDetectedCharset();
// detector.reset();
// inputStream.close();
// if (encoding == null) {
// // If none encoding is detected, we assume UTF-8
// encoding = UTF8;
// }
// return encoding;
// }
//
// public UniversalDetector getCharsetDetector() {
// return detector;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.Charset;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.markdown4j.Markdown4jProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
tabs.addTab(I18N.getHtmlText("About.license.text"), null, licenseTab,
null);
scrollLicense = new JScrollPane();
scrollLicense.setBounds(0, 0, 470, 327);
licenseTab.add(scrollLicense);
JTextPane txtLicense = new JTextPane();
scrollLicense.setViewportView(txtLicense);
addTextContentToArea(txtLicense, "LICENSE", false);
txtLicense.setEditable(false);
JButton btnOk = new JButton(I18N.getHtmlText("About.ok.text"));
btnOk.setBounds(203, 373, 89, 23);
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
this.getContentPane().add(btnOk);
}
private void addTextContentToArea(JTextPane textArea, String file,
boolean isHtml) {
try {
InputStream is = ClassLoader.getSystemResourceAsStream(file);
if (is == null) {
is = new FileInputStream(file);
}
BufferedReader in = new BufferedReader(new InputStreamReader(is,
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/Charset.java
// public class Charset {
//
// public static String ISO88591 = "ISO-8859-1";
// public static String UTF8 = "UTF-8";
//
// private static Charset singleton = null;
//
// private UniversalDetector detector;
//
// public Charset() {
// detector = new UniversalDetector(null);
// }
//
// public static Charset getSingleton() {
// if (singleton == null) {
// singleton = new Charset();
// }
// return singleton;
// }
//
// public static String detect(String file) throws IOException {
// InputStream inputStream = Thread.currentThread()
// .getContextClassLoader().getResourceAsStream(file);
// if (inputStream == null) {
// inputStream = new BufferedInputStream(new FileInputStream(file));
// }
// return Charset.detect(inputStream);
// }
//
// public static String detect(InputStream inputStream) throws IOException {
// UniversalDetector detector = Charset.getSingleton()
// .getCharsetDetector();
// byte[] buf = new byte[4096];
// int nread;
// while ((nread = inputStream.read(buf)) > 0 && !detector.isDone()) {
// detector.handleData(buf, 0, nread);
// }
// detector.dataEnd();
// String encoding = detector.getDetectedCharset();
// detector.reset();
// inputStream.close();
// if (encoding == null) {
// // If none encoding is detected, we assume UTF-8
// encoding = UTF8;
// }
// return encoding;
// }
//
// public UniversalDetector getCharsetDetector() {
// return detector;
// }
//
// }
//
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/AboutDialog.java
import io.github.bonigarcia.dualsub.util.Charset;
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.markdown4j.Markdown4jProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
tabs.addTab(I18N.getHtmlText("About.license.text"), null, licenseTab,
null);
scrollLicense = new JScrollPane();
scrollLicense.setBounds(0, 0, 470, 327);
licenseTab.add(scrollLicense);
JTextPane txtLicense = new JTextPane();
scrollLicense.setViewportView(txtLicense);
addTextContentToArea(txtLicense, "LICENSE", false);
txtLicense.setEditable(false);
JButton btnOk = new JButton(I18N.getHtmlText("About.ok.text"));
btnOk.setBounds(203, 373, 89, 23);
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
this.getContentPane().add(btnOk);
}
private void addTextContentToArea(JTextPane textArea, String file,
boolean isHtml) {
try {
InputStream is = ClassLoader.getSystemResourceAsStream(file);
if (is == null) {
is = new FileInputStream(file);
}
BufferedReader in = new BufferedReader(new InputStreamReader(is,
|
Charset.ISO88591));
|
bonigarcia/dualsub
|
src/main/java/io/github/bonigarcia/dualsub/gui/PanelOutput.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.MissingResourceException;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelOutput.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelOutput extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelOutput.class);
private static final long serialVersionUID = 1L;
private static final int MAX_SEPARATOR = 100;
// Parent
private DualSub parent;
// UI Elements
private JComboBox<CharsetItem> charsetComboBox;
private JRadioButton rdbtnSpace;
private JRadioButton rdbtnHardSpace;
private JRadioButton rdbtnYes;
private JRadioButton rdbtnNo;
private JRadioButton rdbtnVertical;
private JRadioButton rdbtnHorizontal;
private JTextField separator;
public PanelOutput(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setLayout(null);
this.setBorder(new TitledBorder(UIManager
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/main/java/io/github/bonigarcia/dualsub/gui/PanelOutput.java
import io.github.bonigarcia.dualsub.util.I18N;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.MissingResourceException;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.gui;
/**
* PanelOutput.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class PanelOutput extends JPanel {
private static final Logger log = LoggerFactory
.getLogger(PanelOutput.class);
private static final long serialVersionUID = 1L;
private static final int MAX_SEPARATOR = 100;
// Parent
private DualSub parent;
// UI Elements
private JComboBox<CharsetItem> charsetComboBox;
private JRadioButton rdbtnSpace;
private JRadioButton rdbtnHardSpace;
private JRadioButton rdbtnYes;
private JRadioButton rdbtnNo;
private JRadioButton rdbtnVertical;
private JRadioButton rdbtnHorizontal;
private JTextField separator;
public PanelOutput(DualSub parent) {
this.parent = parent;
initialize();
}
private void initialize() {
this.setLayout(null);
this.setBorder(new TitledBorder(UIManager
|
.getBorder("TitledBorder.border"), I18N
|
bonigarcia/dualsub
|
src/test/java/io/github/bonigarcia/dualsub/test/TestLocale.java
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
|
import io.github.bonigarcia.dualsub.util.I18N;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Locale;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.test;
/**
* TestLocale.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class TestLocale {
private static final Logger log = LoggerFactory.getLogger(TestLocale.class);
@Test
public void testLocale() throws IOException {
Enumeration<URL> classpath = Thread.currentThread()
.getContextClassLoader().getResources("");
File folder;
String[] ls;
String localeStr;
while (classpath.hasMoreElements()) {
folder = new File(classpath.nextElement().getFile());
ls = folder.list();
for (String s : ls) {
|
// Path: src/main/java/io/github/bonigarcia/dualsub/util/I18N.java
// public class I18N {
//
// public static final String MESSAGES = "lang/messages";
//
// public static final String HTML_INIT_TAG = "<html><font face='Lucid'>";
//
// public static final String HTML_END_TAG = "</font></html>";
//
// public enum Html {
// LINK, BOLD, MONOSPACE
// }
//
// private static I18N singleton = null;
//
// private Locale locale;
//
// public I18N() {
// this.locale = Locale.getDefault();
// }
//
// public static I18N getSingleton() {
// if (singleton == null) {
// singleton = new I18N();
// }
// return singleton;
// }
//
// public static String getHtmlText(String key, Html html) {
// String out = HTML_INIT_TAG;
// switch (html) {
// case LINK:
// out += "<a href='#'>" + getText(key) + "</a>";
// break;
// case BOLD:
// out += "<b><u>" + getText(key) + "</u></b>";
// break;
// case MONOSPACE:
// out += "<pre>" + getText(key) + "</pre>";
// break;
// default:
// out += getText(key);
// break;
// }
// out += HTML_END_TAG;
// return out;
// }
//
// public static String getHtmlText(String key) {
// return HTML_INIT_TAG + getText(key) + HTML_END_TAG;
// }
//
// public static String getText(String key) {
// return ResourceBundle.getBundle(MESSAGES, getLocale()).getString(key);
// }
//
// public static Locale getLocale() {
// return I18N.getSingleton().locale;
// }
//
// public static void setLocale(String locale) {
// I18N.getSingleton().locale = new Locale(locale);
// }
//
// public static void setLocale(Locale locale) {
// I18N.getSingleton().locale = locale;
// }
//
// }
// Path: src/test/java/io/github/bonigarcia/dualsub/test/TestLocale.java
import io.github.bonigarcia.dualsub.util.I18N;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Locale;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* (C) Copyright 2014 Boni Garcia (http://bonigarcia.github.io/)
*
* 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 io.github.bonigarcia.dualsub.test;
/**
* TestLocale.
*
* @author Boni Garcia (boni.gg@gmail.com)
* @since 1.0.0
*/
public class TestLocale {
private static final Logger log = LoggerFactory.getLogger(TestLocale.class);
@Test
public void testLocale() throws IOException {
Enumeration<URL> classpath = Thread.currentThread()
.getContextClassLoader().getResources("");
File folder;
String[] ls;
String localeStr;
while (classpath.hasMoreElements()) {
folder = new File(classpath.nextElement().getFile());
ls = folder.list();
for (String s : ls) {
|
if (s.startsWith(I18N.MESSAGES) && s.endsWith(".properties")
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
// @SuppressWarnings("serial")
// public class ByteArrayCacheValue extends BaseCacheValue {
//
// private final byte[] _buffer;
//
// public ByteArrayCacheValue(int length) {
// super(length);
// _buffer = new byte[length];
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(buf, offset, _buffer, position, length);
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(_buffer, position, buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _buffer[position];
// }
//
// @Override
// public void release() {
// _released = true;
// }
//
// @Override
// public int size() {
// return length();
// }
//
// @Override
// public CacheValue trim(int length) {
// if (_buffer.length == length) {
// return this;
// }
// ByteArrayCacheValue cacheValue = new ByteArrayCacheValue(length);
// System.arraycopy(_buffer, 0, cacheValue._buffer, 0, length);
// return cacheValue;
// }
// }
//
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
// @SuppressWarnings("serial")
// public class UnsafeCacheValue extends BaseCacheValue {
//
// private static final String JAVA_NIO_BITS = "java.nio.Bits";
// private static final Unsafe _unsafe;
// private static final AtomicLong _offHeapMemorySize = new AtomicLong();
//
// static {
// try {
// Class<?> clazz = Class.forName(JAVA_NIO_BITS);
// Field field = clazz.getDeclaredField("unsafe");
// field.setAccessible(true);
// _unsafe = (Unsafe) field.get(null);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// private static final int BYTE_ARRAY_BASE_OFFSET = _unsafe.arrayBaseOffset(byte[].class);
//
// private static void copyFromArray(byte[] src, int srcOffset, int length, long destAddress) {
// long offset = BYTE_ARRAY_BASE_OFFSET + srcOffset;
// _unsafe.copyMemory(src, offset, null, destAddress, length);
// }
//
// private static void copyToArray(long srcAddress, byte[] dst, int dstOffset, int length) {
// long offset = BYTE_ARRAY_BASE_OFFSET + dstOffset;
// _unsafe.copyMemory(null, srcAddress, dst, offset, length);
// }
//
// private final long _address;
// private final int _capacity;
//
// public UnsafeCacheValue(int length) {
// super(length);
// _capacity = length;
// _address = _unsafe.allocateMemory(_capacity);
// _offHeapMemorySize.addAndGet(_capacity);
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// copyFromArray(buf, offset, length, resolveAddress(position));
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// copyToArray(resolveAddress(position), buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _unsafe.getByte(resolveAddress(position));
// }
//
// private long resolveAddress(int position) {
// return _address + position;
// }
//
// @Override
// public void release() {
// if (!_released) {
// _unsafe.freeMemory(_address);
// _released = true;
// _offHeapMemorySize.addAndGet(0 - _capacity);
// } else {
// new Throwable().printStackTrace();
// }
// }
//
// @Override
// public int size() {
// return _capacity;
// }
//
// @Override
// public CacheValue trim(int length) {
// if (length == _capacity) {
// return this;
// }
// UnsafeCacheValue unsafeCacheValue = new UnsafeCacheValue(length);
// _unsafe.copyMemory(_address, unsafeCacheValue._address, length);
// release();
// return unsafeCacheValue;
// }
// }
|
import com.bah.lucene.blockcache_v2.cachevalue.ByteArrayCacheValue;
import com.bah.lucene.blockcache_v2.cachevalue.UnsafeCacheValue;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.googlecode.concurrentlinkedhashmap.EvictionListener;
import com.googlecode.concurrentlinkedhashmap.Weigher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.store.IOContext;
import java.io.Closeable;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
|
}
}
private void addToReleaseQueue(CacheKey key, CacheValue value) {
if (value != null) {
if (value.refCount() == 0) {
value.release();
return;
}
long capacity = _cacheMap.capacity();
_cacheMap.setCapacity(capacity - value.size());
ReleaseEntry releaseEntry = new ReleaseEntry();
releaseEntry._key = key;
releaseEntry._value = value;
LOG.debug(MessageFormat.format("CacheValue was not released [{0}]", releaseEntry));
_releaseQueue.add(releaseEntry);
}
}
@Override
public boolean shouldBeQuiet(CacheDirectory directory, String fileName) {
return _quiet.shouldBeQuiet(directory, fileName);
}
@Override
public CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize) {
switch (_store) {
case ON_HEAP:
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
// @SuppressWarnings("serial")
// public class ByteArrayCacheValue extends BaseCacheValue {
//
// private final byte[] _buffer;
//
// public ByteArrayCacheValue(int length) {
// super(length);
// _buffer = new byte[length];
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(buf, offset, _buffer, position, length);
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(_buffer, position, buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _buffer[position];
// }
//
// @Override
// public void release() {
// _released = true;
// }
//
// @Override
// public int size() {
// return length();
// }
//
// @Override
// public CacheValue trim(int length) {
// if (_buffer.length == length) {
// return this;
// }
// ByteArrayCacheValue cacheValue = new ByteArrayCacheValue(length);
// System.arraycopy(_buffer, 0, cacheValue._buffer, 0, length);
// return cacheValue;
// }
// }
//
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
// @SuppressWarnings("serial")
// public class UnsafeCacheValue extends BaseCacheValue {
//
// private static final String JAVA_NIO_BITS = "java.nio.Bits";
// private static final Unsafe _unsafe;
// private static final AtomicLong _offHeapMemorySize = new AtomicLong();
//
// static {
// try {
// Class<?> clazz = Class.forName(JAVA_NIO_BITS);
// Field field = clazz.getDeclaredField("unsafe");
// field.setAccessible(true);
// _unsafe = (Unsafe) field.get(null);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// private static final int BYTE_ARRAY_BASE_OFFSET = _unsafe.arrayBaseOffset(byte[].class);
//
// private static void copyFromArray(byte[] src, int srcOffset, int length, long destAddress) {
// long offset = BYTE_ARRAY_BASE_OFFSET + srcOffset;
// _unsafe.copyMemory(src, offset, null, destAddress, length);
// }
//
// private static void copyToArray(long srcAddress, byte[] dst, int dstOffset, int length) {
// long offset = BYTE_ARRAY_BASE_OFFSET + dstOffset;
// _unsafe.copyMemory(null, srcAddress, dst, offset, length);
// }
//
// private final long _address;
// private final int _capacity;
//
// public UnsafeCacheValue(int length) {
// super(length);
// _capacity = length;
// _address = _unsafe.allocateMemory(_capacity);
// _offHeapMemorySize.addAndGet(_capacity);
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// copyFromArray(buf, offset, length, resolveAddress(position));
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// copyToArray(resolveAddress(position), buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _unsafe.getByte(resolveAddress(position));
// }
//
// private long resolveAddress(int position) {
// return _address + position;
// }
//
// @Override
// public void release() {
// if (!_released) {
// _unsafe.freeMemory(_address);
// _released = true;
// _offHeapMemorySize.addAndGet(0 - _capacity);
// } else {
// new Throwable().printStackTrace();
// }
// }
//
// @Override
// public int size() {
// return _capacity;
// }
//
// @Override
// public CacheValue trim(int length) {
// if (length == _capacity) {
// return this;
// }
// UnsafeCacheValue unsafeCacheValue = new UnsafeCacheValue(length);
// _unsafe.copyMemory(_address, unsafeCacheValue._address, length);
// release();
// return unsafeCacheValue;
// }
// }
// Path: src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
import com.bah.lucene.blockcache_v2.cachevalue.ByteArrayCacheValue;
import com.bah.lucene.blockcache_v2.cachevalue.UnsafeCacheValue;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.googlecode.concurrentlinkedhashmap.EvictionListener;
import com.googlecode.concurrentlinkedhashmap.Weigher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.store.IOContext;
import java.io.Closeable;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
}
}
private void addToReleaseQueue(CacheKey key, CacheValue value) {
if (value != null) {
if (value.refCount() == 0) {
value.release();
return;
}
long capacity = _cacheMap.capacity();
_cacheMap.setCapacity(capacity - value.size());
ReleaseEntry releaseEntry = new ReleaseEntry();
releaseEntry._key = key;
releaseEntry._value = value;
LOG.debug(MessageFormat.format("CacheValue was not released [{0}]", releaseEntry));
_releaseQueue.add(releaseEntry);
}
}
@Override
public boolean shouldBeQuiet(CacheDirectory directory, String fileName) {
return _quiet.shouldBeQuiet(directory, fileName);
}
@Override
public CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize) {
switch (_store) {
case ON_HEAP:
|
return new ByteArrayCacheValue(cacheBlockSize);
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
// @SuppressWarnings("serial")
// public class ByteArrayCacheValue extends BaseCacheValue {
//
// private final byte[] _buffer;
//
// public ByteArrayCacheValue(int length) {
// super(length);
// _buffer = new byte[length];
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(buf, offset, _buffer, position, length);
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(_buffer, position, buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _buffer[position];
// }
//
// @Override
// public void release() {
// _released = true;
// }
//
// @Override
// public int size() {
// return length();
// }
//
// @Override
// public CacheValue trim(int length) {
// if (_buffer.length == length) {
// return this;
// }
// ByteArrayCacheValue cacheValue = new ByteArrayCacheValue(length);
// System.arraycopy(_buffer, 0, cacheValue._buffer, 0, length);
// return cacheValue;
// }
// }
//
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
// @SuppressWarnings("serial")
// public class UnsafeCacheValue extends BaseCacheValue {
//
// private static final String JAVA_NIO_BITS = "java.nio.Bits";
// private static final Unsafe _unsafe;
// private static final AtomicLong _offHeapMemorySize = new AtomicLong();
//
// static {
// try {
// Class<?> clazz = Class.forName(JAVA_NIO_BITS);
// Field field = clazz.getDeclaredField("unsafe");
// field.setAccessible(true);
// _unsafe = (Unsafe) field.get(null);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// private static final int BYTE_ARRAY_BASE_OFFSET = _unsafe.arrayBaseOffset(byte[].class);
//
// private static void copyFromArray(byte[] src, int srcOffset, int length, long destAddress) {
// long offset = BYTE_ARRAY_BASE_OFFSET + srcOffset;
// _unsafe.copyMemory(src, offset, null, destAddress, length);
// }
//
// private static void copyToArray(long srcAddress, byte[] dst, int dstOffset, int length) {
// long offset = BYTE_ARRAY_BASE_OFFSET + dstOffset;
// _unsafe.copyMemory(null, srcAddress, dst, offset, length);
// }
//
// private final long _address;
// private final int _capacity;
//
// public UnsafeCacheValue(int length) {
// super(length);
// _capacity = length;
// _address = _unsafe.allocateMemory(_capacity);
// _offHeapMemorySize.addAndGet(_capacity);
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// copyFromArray(buf, offset, length, resolveAddress(position));
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// copyToArray(resolveAddress(position), buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _unsafe.getByte(resolveAddress(position));
// }
//
// private long resolveAddress(int position) {
// return _address + position;
// }
//
// @Override
// public void release() {
// if (!_released) {
// _unsafe.freeMemory(_address);
// _released = true;
// _offHeapMemorySize.addAndGet(0 - _capacity);
// } else {
// new Throwable().printStackTrace();
// }
// }
//
// @Override
// public int size() {
// return _capacity;
// }
//
// @Override
// public CacheValue trim(int length) {
// if (length == _capacity) {
// return this;
// }
// UnsafeCacheValue unsafeCacheValue = new UnsafeCacheValue(length);
// _unsafe.copyMemory(_address, unsafeCacheValue._address, length);
// release();
// return unsafeCacheValue;
// }
// }
|
import com.bah.lucene.blockcache_v2.cachevalue.ByteArrayCacheValue;
import com.bah.lucene.blockcache_v2.cachevalue.UnsafeCacheValue;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.googlecode.concurrentlinkedhashmap.EvictionListener;
import com.googlecode.concurrentlinkedhashmap.Weigher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.store.IOContext;
import java.io.Closeable;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
|
private void addToReleaseQueue(CacheKey key, CacheValue value) {
if (value != null) {
if (value.refCount() == 0) {
value.release();
return;
}
long capacity = _cacheMap.capacity();
_cacheMap.setCapacity(capacity - value.size());
ReleaseEntry releaseEntry = new ReleaseEntry();
releaseEntry._key = key;
releaseEntry._value = value;
LOG.debug(MessageFormat.format("CacheValue was not released [{0}]", releaseEntry));
_releaseQueue.add(releaseEntry);
}
}
@Override
public boolean shouldBeQuiet(CacheDirectory directory, String fileName) {
return _quiet.shouldBeQuiet(directory, fileName);
}
@Override
public CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize) {
switch (_store) {
case ON_HEAP:
return new ByteArrayCacheValue(cacheBlockSize);
case OFF_HEAP:
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
// @SuppressWarnings("serial")
// public class ByteArrayCacheValue extends BaseCacheValue {
//
// private final byte[] _buffer;
//
// public ByteArrayCacheValue(int length) {
// super(length);
// _buffer = new byte[length];
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(buf, offset, _buffer, position, length);
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(_buffer, position, buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _buffer[position];
// }
//
// @Override
// public void release() {
// _released = true;
// }
//
// @Override
// public int size() {
// return length();
// }
//
// @Override
// public CacheValue trim(int length) {
// if (_buffer.length == length) {
// return this;
// }
// ByteArrayCacheValue cacheValue = new ByteArrayCacheValue(length);
// System.arraycopy(_buffer, 0, cacheValue._buffer, 0, length);
// return cacheValue;
// }
// }
//
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
// @SuppressWarnings("serial")
// public class UnsafeCacheValue extends BaseCacheValue {
//
// private static final String JAVA_NIO_BITS = "java.nio.Bits";
// private static final Unsafe _unsafe;
// private static final AtomicLong _offHeapMemorySize = new AtomicLong();
//
// static {
// try {
// Class<?> clazz = Class.forName(JAVA_NIO_BITS);
// Field field = clazz.getDeclaredField("unsafe");
// field.setAccessible(true);
// _unsafe = (Unsafe) field.get(null);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// private static final int BYTE_ARRAY_BASE_OFFSET = _unsafe.arrayBaseOffset(byte[].class);
//
// private static void copyFromArray(byte[] src, int srcOffset, int length, long destAddress) {
// long offset = BYTE_ARRAY_BASE_OFFSET + srcOffset;
// _unsafe.copyMemory(src, offset, null, destAddress, length);
// }
//
// private static void copyToArray(long srcAddress, byte[] dst, int dstOffset, int length) {
// long offset = BYTE_ARRAY_BASE_OFFSET + dstOffset;
// _unsafe.copyMemory(null, srcAddress, dst, offset, length);
// }
//
// private final long _address;
// private final int _capacity;
//
// public UnsafeCacheValue(int length) {
// super(length);
// _capacity = length;
// _address = _unsafe.allocateMemory(_capacity);
// _offHeapMemorySize.addAndGet(_capacity);
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// copyFromArray(buf, offset, length, resolveAddress(position));
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// copyToArray(resolveAddress(position), buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _unsafe.getByte(resolveAddress(position));
// }
//
// private long resolveAddress(int position) {
// return _address + position;
// }
//
// @Override
// public void release() {
// if (!_released) {
// _unsafe.freeMemory(_address);
// _released = true;
// _offHeapMemorySize.addAndGet(0 - _capacity);
// } else {
// new Throwable().printStackTrace();
// }
// }
//
// @Override
// public int size() {
// return _capacity;
// }
//
// @Override
// public CacheValue trim(int length) {
// if (length == _capacity) {
// return this;
// }
// UnsafeCacheValue unsafeCacheValue = new UnsafeCacheValue(length);
// _unsafe.copyMemory(_address, unsafeCacheValue._address, length);
// release();
// return unsafeCacheValue;
// }
// }
// Path: src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
import com.bah.lucene.blockcache_v2.cachevalue.ByteArrayCacheValue;
import com.bah.lucene.blockcache_v2.cachevalue.UnsafeCacheValue;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.googlecode.concurrentlinkedhashmap.EvictionListener;
import com.googlecode.concurrentlinkedhashmap.Weigher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.store.IOContext;
import java.io.Closeable;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
private void addToReleaseQueue(CacheKey key, CacheValue value) {
if (value != null) {
if (value.refCount() == 0) {
value.release();
return;
}
long capacity = _cacheMap.capacity();
_cacheMap.setCapacity(capacity - value.size());
ReleaseEntry releaseEntry = new ReleaseEntry();
releaseEntry._key = key;
releaseEntry._value = value;
LOG.debug(MessageFormat.format("CacheValue was not released [{0}]", releaseEntry));
_releaseQueue.add(releaseEntry);
}
}
@Override
public boolean shouldBeQuiet(CacheDirectory directory, String fileName) {
return _quiet.shouldBeQuiet(directory, fileName);
}
@Override
public CacheValue newInstance(CacheDirectory directory, String fileName, int cacheBlockSize) {
switch (_store) {
case ON_HEAP:
return new ByteArrayCacheValue(cacheBlockSize);
case OFF_HEAP:
|
return new UnsafeCacheValue(cacheBlockSize);
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/CacheValue.java
// public interface CacheValue {
//
// /**
// * The actual size of the the underlying resource.
// *
// * @return the size.
// */
// int size();
//
// /**
// * The length of the data in this block.
// *
// * @return the length.
// */
// int length();
//
// /**
// * Writes data out to a given position in this block.
// *
// * @param position
// * the position.
// * @param buf
// * the buffer.
// * @param offset
// * the offset in the buffer.
// * @param length
// * the length of bytes to write.
// */
// void write(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads data into the buffer given the position.
// *
// * @param position
// * the position to read.
// * @param buf
// * the buffer to read into.
// * @param offset
// * the offset within the buffer.
// * @param length
// * the length of data to read.
// */
// void read(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads a byte from the given position.
// *
// * @param position
// * the position.
// * @return the byte.
// */
// byte read(int position);
//
// /**
// * Increments the reference.
// */
// void incRef();
//
// /**
// * Decrements the reference.
// */
// void decRef();
//
// /**
// * Gets the reference count.
// */
// long refCount();
//
// /**
// * Releases any underlying resources.
// */
// void release();
//
// /**
// * Reads a short from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the short.
// */
// short readShort(int position);
//
// /**
// * Reads a int from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the int.
// */
// int readInt(int position);
//
// /**
// * Reads a long from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the long.
// */
// long readLong(int position);
//
// /**
// * This method will trim the existing {@link CacheValue} and produce
// * potentially a new {@link CacheValue} with the same data up to the length
// * provided. Also if a new {@link CacheValue} is produced then this method is
// * responsible to calling release on the old {@link CacheValue}.
// *
// * @param length
// * the valid amount of data in the {@link CacheValue}.
// * @return new trim {@link CacheValue} that has been trimmed if needed.
// */
// CacheValue trim(int length);
//
// }
|
import sun.misc.Unsafe;
import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicLong;
import com.bah.lucene.blockcache_v2.CacheValue;
|
protected void readInternal(int position, byte[] buf, int offset, int length) {
copyToArray(resolveAddress(position), buf, offset, length);
}
@Override
protected byte readInternal(int position) {
return _unsafe.getByte(resolveAddress(position));
}
private long resolveAddress(int position) {
return _address + position;
}
@Override
public void release() {
if (!_released) {
_unsafe.freeMemory(_address);
_released = true;
_offHeapMemorySize.addAndGet(0 - _capacity);
} else {
new Throwable().printStackTrace();
}
}
@Override
public int size() {
return _capacity;
}
@Override
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/CacheValue.java
// public interface CacheValue {
//
// /**
// * The actual size of the the underlying resource.
// *
// * @return the size.
// */
// int size();
//
// /**
// * The length of the data in this block.
// *
// * @return the length.
// */
// int length();
//
// /**
// * Writes data out to a given position in this block.
// *
// * @param position
// * the position.
// * @param buf
// * the buffer.
// * @param offset
// * the offset in the buffer.
// * @param length
// * the length of bytes to write.
// */
// void write(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads data into the buffer given the position.
// *
// * @param position
// * the position to read.
// * @param buf
// * the buffer to read into.
// * @param offset
// * the offset within the buffer.
// * @param length
// * the length of data to read.
// */
// void read(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads a byte from the given position.
// *
// * @param position
// * the position.
// * @return the byte.
// */
// byte read(int position);
//
// /**
// * Increments the reference.
// */
// void incRef();
//
// /**
// * Decrements the reference.
// */
// void decRef();
//
// /**
// * Gets the reference count.
// */
// long refCount();
//
// /**
// * Releases any underlying resources.
// */
// void release();
//
// /**
// * Reads a short from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the short.
// */
// short readShort(int position);
//
// /**
// * Reads a int from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the int.
// */
// int readInt(int position);
//
// /**
// * Reads a long from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the long.
// */
// long readLong(int position);
//
// /**
// * This method will trim the existing {@link CacheValue} and produce
// * potentially a new {@link CacheValue} with the same data up to the length
// * provided. Also if a new {@link CacheValue} is produced then this method is
// * responsible to calling release on the old {@link CacheValue}.
// *
// * @param length
// * the valid amount of data in the {@link CacheValue}.
// * @return new trim {@link CacheValue} that has been trimmed if needed.
// */
// CacheValue trim(int length);
//
// }
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
import sun.misc.Unsafe;
import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicLong;
import com.bah.lucene.blockcache_v2.CacheValue;
protected void readInternal(int position, byte[] buf, int offset, int length) {
copyToArray(resolveAddress(position), buf, offset, length);
}
@Override
protected byte readInternal(int position) {
return _unsafe.getByte(resolveAddress(position));
}
private long resolveAddress(int position) {
return _address + position;
}
@Override
public void release() {
if (!_released) {
_unsafe.freeMemory(_address);
_released = true;
_offHeapMemorySize.addAndGet(0 - _capacity);
} else {
new Throwable().printStackTrace();
}
}
@Override
public int size() {
return _capacity;
}
@Override
|
public CacheValue trim(int length) {
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/test/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValueTest.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
// @SuppressWarnings("serial")
// public class ByteArrayCacheValue extends BaseCacheValue {
//
// private final byte[] _buffer;
//
// public ByteArrayCacheValue(int length) {
// super(length);
// _buffer = new byte[length];
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(buf, offset, _buffer, position, length);
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(_buffer, position, buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _buffer[position];
// }
//
// @Override
// public void release() {
// _released = true;
// }
//
// @Override
// public int size() {
// return length();
// }
//
// @Override
// public CacheValue trim(int length) {
// if (_buffer.length == length) {
// return this;
// }
// ByteArrayCacheValue cacheValue = new ByteArrayCacheValue(length);
// System.arraycopy(_buffer, 0, cacheValue._buffer, 0, length);
// return cacheValue;
// }
// }
|
import static org.junit.Assert.*;
import org.junit.Test;
import com.bah.lucene.blockcache_v2.cachevalue.ByteArrayCacheValue;
|
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2.cachevalue;
public class ByteArrayCacheValueTest {
@Test
public void test1() {
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
// @SuppressWarnings("serial")
// public class ByteArrayCacheValue extends BaseCacheValue {
//
// private final byte[] _buffer;
//
// public ByteArrayCacheValue(int length) {
// super(length);
// _buffer = new byte[length];
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(buf, offset, _buffer, position, length);
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// System.arraycopy(_buffer, position, buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _buffer[position];
// }
//
// @Override
// public void release() {
// _released = true;
// }
//
// @Override
// public int size() {
// return length();
// }
//
// @Override
// public CacheValue trim(int length) {
// if (_buffer.length == length) {
// return this;
// }
// ByteArrayCacheValue cacheValue = new ByteArrayCacheValue(length);
// System.arraycopy(_buffer, 0, cacheValue._buffer, 0, length);
// return cacheValue;
// }
// }
// Path: src/test/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValueTest.java
import static org.junit.Assert.*;
import org.junit.Test;
import com.bah.lucene.blockcache_v2.cachevalue.ByteArrayCacheValue;
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2.cachevalue;
public class ByteArrayCacheValueTest {
@Test
public void test1() {
|
ByteArrayCacheValue value = new ByteArrayCacheValue(10);
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/CacheValue.java
// public interface CacheValue {
//
// /**
// * The actual size of the the underlying resource.
// *
// * @return the size.
// */
// int size();
//
// /**
// * The length of the data in this block.
// *
// * @return the length.
// */
// int length();
//
// /**
// * Writes data out to a given position in this block.
// *
// * @param position
// * the position.
// * @param buf
// * the buffer.
// * @param offset
// * the offset in the buffer.
// * @param length
// * the length of bytes to write.
// */
// void write(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads data into the buffer given the position.
// *
// * @param position
// * the position to read.
// * @param buf
// * the buffer to read into.
// * @param offset
// * the offset within the buffer.
// * @param length
// * the length of data to read.
// */
// void read(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads a byte from the given position.
// *
// * @param position
// * the position.
// * @return the byte.
// */
// byte read(int position);
//
// /**
// * Increments the reference.
// */
// void incRef();
//
// /**
// * Decrements the reference.
// */
// void decRef();
//
// /**
// * Gets the reference count.
// */
// long refCount();
//
// /**
// * Releases any underlying resources.
// */
// void release();
//
// /**
// * Reads a short from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the short.
// */
// short readShort(int position);
//
// /**
// * Reads a int from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the int.
// */
// int readInt(int position);
//
// /**
// * Reads a long from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the long.
// */
// long readLong(int position);
//
// /**
// * This method will trim the existing {@link CacheValue} and produce
// * potentially a new {@link CacheValue} with the same data up to the length
// * provided. Also if a new {@link CacheValue} is produced then this method is
// * responsible to calling release on the old {@link CacheValue}.
// *
// * @param length
// * the valid amount of data in the {@link CacheValue}.
// * @return new trim {@link CacheValue} that has been trimmed if needed.
// */
// CacheValue trim(int length);
//
// }
|
import com.bah.lucene.blockcache_v2.CacheValue;
|
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2.cachevalue;
@SuppressWarnings("serial")
public class ByteArrayCacheValue extends BaseCacheValue {
private final byte[] _buffer;
public ByteArrayCacheValue(int length) {
super(length);
_buffer = new byte[length];
}
@Override
protected void writeInternal(int position, byte[] buf, int offset, int length) {
System.arraycopy(buf, offset, _buffer, position, length);
}
@Override
protected void readInternal(int position, byte[] buf, int offset, int length) {
System.arraycopy(_buffer, position, buf, offset, length);
}
@Override
protected byte readInternal(int position) {
return _buffer[position];
}
@Override
public void release() {
_released = true;
}
@Override
public int size() {
return length();
}
@Override
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/CacheValue.java
// public interface CacheValue {
//
// /**
// * The actual size of the the underlying resource.
// *
// * @return the size.
// */
// int size();
//
// /**
// * The length of the data in this block.
// *
// * @return the length.
// */
// int length();
//
// /**
// * Writes data out to a given position in this block.
// *
// * @param position
// * the position.
// * @param buf
// * the buffer.
// * @param offset
// * the offset in the buffer.
// * @param length
// * the length of bytes to write.
// */
// void write(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads data into the buffer given the position.
// *
// * @param position
// * the position to read.
// * @param buf
// * the buffer to read into.
// * @param offset
// * the offset within the buffer.
// * @param length
// * the length of data to read.
// */
// void read(int position, byte[] buf, int offset, int length);
//
// /**
// * Reads a byte from the given position.
// *
// * @param position
// * the position.
// * @return the byte.
// */
// byte read(int position);
//
// /**
// * Increments the reference.
// */
// void incRef();
//
// /**
// * Decrements the reference.
// */
// void decRef();
//
// /**
// * Gets the reference count.
// */
// long refCount();
//
// /**
// * Releases any underlying resources.
// */
// void release();
//
// /**
// * Reads a short from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the short.
// */
// short readShort(int position);
//
// /**
// * Reads a int from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the int.
// */
// int readInt(int position);
//
// /**
// * Reads a long from the given position.
// *
// * @param position
// * the {@link Position} to read from.
// * @return the long.
// */
// long readLong(int position);
//
// /**
// * This method will trim the existing {@link CacheValue} and produce
// * potentially a new {@link CacheValue} with the same data up to the length
// * provided. Also if a new {@link CacheValue} is produced then this method is
// * responsible to calling release on the old {@link CacheValue}.
// *
// * @param length
// * the valid amount of data in the {@link CacheValue}.
// * @return new trim {@link CacheValue} that has been trimmed if needed.
// */
// CacheValue trim(int length);
//
// }
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/ByteArrayCacheValue.java
import com.bah.lucene.blockcache_v2.CacheValue;
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2.cachevalue;
@SuppressWarnings("serial")
public class ByteArrayCacheValue extends BaseCacheValue {
private final byte[] _buffer;
public ByteArrayCacheValue(int length) {
super(length);
_buffer = new byte[length];
}
@Override
protected void writeInternal(int position, byte[] buf, int offset, int length) {
System.arraycopy(buf, offset, _buffer, position, length);
}
@Override
protected void readInternal(int position, byte[] buf, int offset, int length) {
System.arraycopy(_buffer, position, buf, offset, length);
}
@Override
protected byte readInternal(int position) {
return _buffer[position];
}
@Override
public void release() {
_released = true;
}
@Override
public int size() {
return length();
}
@Override
|
public CacheValue trim(int length) {
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/test/java/com/bah/lucene/CacheDirectoryTestSuiteOffHeap.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
// public enum STORE {
// ON_HEAP, OFF_HEAP
// }
|
import org.junit.Test;
import com.bah.lucene.blockcache_v2.BaseCache.STORE;
|
package com.bah.lucene;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class CacheDirectoryTestSuiteOffHeap extends CacheDirectoryTestSuite {
@Test
public void runsTheTests() {
}
@Override
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
// public enum STORE {
// ON_HEAP, OFF_HEAP
// }
// Path: src/test/java/com/bah/lucene/CacheDirectoryTestSuiteOffHeap.java
import org.junit.Test;
import com.bah.lucene.blockcache_v2.BaseCache.STORE;
package com.bah.lucene;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class CacheDirectoryTestSuiteOffHeap extends CacheDirectoryTestSuite {
@Test
public void runsTheTests() {
}
@Override
|
protected STORE getStore() {
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/main/java/com/bah/lucene/blockcache_v2/CacheIndexInput.java
|
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
|
import com.bah.lucene.buffer.BufferStore;
import java.io.IOException;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.IndexInput;
|
private int remaining() {
return _cacheValue.length() - _blockPosition;
}
private void tryToFill() throws IOException {
if (_cacheValue == null) {
fill();
} else if (remaining() == 0) {
releaseCache();
fill();
} else {
return;
}
}
private void releaseCache() {
if (_cacheValue != null) {
_cacheValue.decRef();
_cacheValue = null;
}
}
private void fill() throws IOException {
_key.setBlockId(getBlockId());
_cacheValue = get(_key);
if (_cacheValue == null) {
_cacheValue = _cache.newInstance(_directory, _fileName);
long filePosition = getFilePosition();
_indexInput.seek(filePosition);
|
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
// Path: src/main/java/com/bah/lucene/blockcache_v2/CacheIndexInput.java
import com.bah.lucene.buffer.BufferStore;
import java.io.IOException;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.IndexInput;
private int remaining() {
return _cacheValue.length() - _blockPosition;
}
private void tryToFill() throws IOException {
if (_cacheValue == null) {
fill();
} else if (remaining() == 0) {
releaseCache();
fill();
} else {
return;
}
}
private void releaseCache() {
if (_cacheValue != null) {
_cacheValue.decRef();
_cacheValue = null;
}
}
private void fill() throws IOException {
_key.setBlockId(getBlockId());
_cacheValue = get(_key);
if (_cacheValue == null) {
_cacheValue = _cache.newInstance(_directory, _fileName);
long filePosition = getFilePosition();
_indexInput.seek(filePosition);
|
byte[] buffer = BufferStore.takeBuffer(_bufferSize);
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/test/java/com/bah/lucene/BaseDirectoryTestSuite.java
|
// Path: src/main/java/com/bah/lucene/blockcache/LastModified.java
// public interface LastModified {
//
// long getFileModified(String name) throws IOException;
//
// }
//
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
|
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.IntField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.*;
import org.apache.lucene.util.Version;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bah.lucene.blockcache.LastModified;
import com.bah.lucene.buffer.BufferStore;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import static org.junit.Assert.*;
|
package com.bah.lucene;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public abstract class BaseDirectoryTestSuite {
protected static final File TMPDIR = new File(System.getProperty("blur.tmp.dir", "/tmp"));
protected static final int MAX_NUMBER_OF_WRITES = 10000;
protected static final int MIN_FILE_SIZE = 100;
protected static final int MAX_FILE_SIZE = 100000;
protected static final int MIN_BUFFER_SIZE = 1;
protected static final int MAX_BUFFER_SIZE = 5000;
protected static final int MAX_NUMBER_OF_READS = 10000;
protected Directory directory;
protected File file;
protected File fileControl;
protected long seed;
protected Random random;
@Before
public void setUp() throws IOException {
|
// Path: src/main/java/com/bah/lucene/blockcache/LastModified.java
// public interface LastModified {
//
// long getFileModified(String name) throws IOException;
//
// }
//
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
// Path: src/test/java/com/bah/lucene/BaseDirectoryTestSuite.java
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.IntField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.*;
import org.apache.lucene.util.Version;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bah.lucene.blockcache.LastModified;
import com.bah.lucene.buffer.BufferStore;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import static org.junit.Assert.*;
package com.bah.lucene;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public abstract class BaseDirectoryTestSuite {
protected static final File TMPDIR = new File(System.getProperty("blur.tmp.dir", "/tmp"));
protected static final int MAX_NUMBER_OF_WRITES = 10000;
protected static final int MIN_FILE_SIZE = 100;
protected static final int MAX_FILE_SIZE = 100000;
protected static final int MIN_BUFFER_SIZE = 1;
protected static final int MAX_BUFFER_SIZE = 5000;
protected static final int MAX_NUMBER_OF_READS = 10000;
protected Directory directory;
protected File file;
protected File fileControl;
protected long seed;
protected Random random;
@Before
public void setUp() throws IOException {
|
BufferStore.init(128, 128);
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/test/java/com/bah/lucene/BaseDirectoryTestSuite.java
|
// Path: src/main/java/com/bah/lucene/blockcache/LastModified.java
// public interface LastModified {
//
// long getFileModified(String name) throws IOException;
//
// }
//
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
|
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.IntField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.*;
import org.apache.lucene.util.Version;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bah.lucene.blockcache.LastModified;
import com.bah.lucene.buffer.BufferStore;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import static org.junit.Assert.*;
|
random.nextBytes(buf);
int offset = random.nextInt(buf.length);
int length = random.nextInt(buf.length - offset);
fsOutput.writeBytes(buf, offset, length);
hdfsOutput.writeBytes(buf, offset, length);
}
fsOutput.close();
hdfsOutput.close();
}
private String getName() {
return Long.toString(Math.abs(random.nextLong()));
}
public static void rm(File file) {
if (!file.exists()) {
return;
}
if (file.isDirectory()) {
for (File f : file.listFiles()) {
rm(f);
}
}
file.delete();
}
public static Directory wrapLastModified(Directory dir) {
return new DirectoryLastModified(dir);
}
|
// Path: src/main/java/com/bah/lucene/blockcache/LastModified.java
// public interface LastModified {
//
// long getFileModified(String name) throws IOException;
//
// }
//
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
// Path: src/test/java/com/bah/lucene/BaseDirectoryTestSuite.java
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.IntField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.*;
import org.apache.lucene.util.Version;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.bah.lucene.blockcache.LastModified;
import com.bah.lucene.buffer.BufferStore;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import static org.junit.Assert.*;
random.nextBytes(buf);
int offset = random.nextInt(buf.length);
int length = random.nextInt(buf.length - offset);
fsOutput.writeBytes(buf, offset, length);
hdfsOutput.writeBytes(buf, offset, length);
}
fsOutput.close();
hdfsOutput.close();
}
private String getName() {
return Long.toString(Math.abs(random.nextLong()));
}
public static void rm(File file) {
if (!file.exists()) {
return;
}
if (file.isDirectory()) {
for (File f : file.listFiles()) {
rm(f);
}
}
file.delete();
}
public static Directory wrapLastModified(Directory dir) {
return new DirectoryLastModified(dir);
}
|
public static class DirectoryLastModified extends Directory implements LastModified {
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/test/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValueTest.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
// @SuppressWarnings("serial")
// public class UnsafeCacheValue extends BaseCacheValue {
//
// private static final String JAVA_NIO_BITS = "java.nio.Bits";
// private static final Unsafe _unsafe;
// private static final AtomicLong _offHeapMemorySize = new AtomicLong();
//
// static {
// try {
// Class<?> clazz = Class.forName(JAVA_NIO_BITS);
// Field field = clazz.getDeclaredField("unsafe");
// field.setAccessible(true);
// _unsafe = (Unsafe) field.get(null);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// private static final int BYTE_ARRAY_BASE_OFFSET = _unsafe.arrayBaseOffset(byte[].class);
//
// private static void copyFromArray(byte[] src, int srcOffset, int length, long destAddress) {
// long offset = BYTE_ARRAY_BASE_OFFSET + srcOffset;
// _unsafe.copyMemory(src, offset, null, destAddress, length);
// }
//
// private static void copyToArray(long srcAddress, byte[] dst, int dstOffset, int length) {
// long offset = BYTE_ARRAY_BASE_OFFSET + dstOffset;
// _unsafe.copyMemory(null, srcAddress, dst, offset, length);
// }
//
// private final long _address;
// private final int _capacity;
//
// public UnsafeCacheValue(int length) {
// super(length);
// _capacity = length;
// _address = _unsafe.allocateMemory(_capacity);
// _offHeapMemorySize.addAndGet(_capacity);
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// copyFromArray(buf, offset, length, resolveAddress(position));
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// copyToArray(resolveAddress(position), buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _unsafe.getByte(resolveAddress(position));
// }
//
// private long resolveAddress(int position) {
// return _address + position;
// }
//
// @Override
// public void release() {
// if (!_released) {
// _unsafe.freeMemory(_address);
// _released = true;
// _offHeapMemorySize.addAndGet(0 - _capacity);
// } else {
// new Throwable().printStackTrace();
// }
// }
//
// @Override
// public int size() {
// return _capacity;
// }
//
// @Override
// public CacheValue trim(int length) {
// if (length == _capacity) {
// return this;
// }
// UnsafeCacheValue unsafeCacheValue = new UnsafeCacheValue(length);
// _unsafe.copyMemory(_address, unsafeCacheValue._address, length);
// release();
// return unsafeCacheValue;
// }
// }
|
import static org.junit.Assert.*;
import org.junit.Test;
import com.bah.lucene.blockcache_v2.cachevalue.UnsafeCacheValue;
|
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2.cachevalue;
public class UnsafeCacheValueTest {
@Test
public void test1() {
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValue.java
// @SuppressWarnings("serial")
// public class UnsafeCacheValue extends BaseCacheValue {
//
// private static final String JAVA_NIO_BITS = "java.nio.Bits";
// private static final Unsafe _unsafe;
// private static final AtomicLong _offHeapMemorySize = new AtomicLong();
//
// static {
// try {
// Class<?> clazz = Class.forName(JAVA_NIO_BITS);
// Field field = clazz.getDeclaredField("unsafe");
// field.setAccessible(true);
// _unsafe = (Unsafe) field.get(null);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
//
// private static final int BYTE_ARRAY_BASE_OFFSET = _unsafe.arrayBaseOffset(byte[].class);
//
// private static void copyFromArray(byte[] src, int srcOffset, int length, long destAddress) {
// long offset = BYTE_ARRAY_BASE_OFFSET + srcOffset;
// _unsafe.copyMemory(src, offset, null, destAddress, length);
// }
//
// private static void copyToArray(long srcAddress, byte[] dst, int dstOffset, int length) {
// long offset = BYTE_ARRAY_BASE_OFFSET + dstOffset;
// _unsafe.copyMemory(null, srcAddress, dst, offset, length);
// }
//
// private final long _address;
// private final int _capacity;
//
// public UnsafeCacheValue(int length) {
// super(length);
// _capacity = length;
// _address = _unsafe.allocateMemory(_capacity);
// _offHeapMemorySize.addAndGet(_capacity);
// }
//
// @Override
// protected void writeInternal(int position, byte[] buf, int offset, int length) {
// copyFromArray(buf, offset, length, resolveAddress(position));
// }
//
// @Override
// protected void readInternal(int position, byte[] buf, int offset, int length) {
// copyToArray(resolveAddress(position), buf, offset, length);
// }
//
// @Override
// protected byte readInternal(int position) {
// return _unsafe.getByte(resolveAddress(position));
// }
//
// private long resolveAddress(int position) {
// return _address + position;
// }
//
// @Override
// public void release() {
// if (!_released) {
// _unsafe.freeMemory(_address);
// _released = true;
// _offHeapMemorySize.addAndGet(0 - _capacity);
// } else {
// new Throwable().printStackTrace();
// }
// }
//
// @Override
// public int size() {
// return _capacity;
// }
//
// @Override
// public CacheValue trim(int length) {
// if (length == _capacity) {
// return this;
// }
// UnsafeCacheValue unsafeCacheValue = new UnsafeCacheValue(length);
// _unsafe.copyMemory(_address, unsafeCacheValue._address, length);
// release();
// return unsafeCacheValue;
// }
// }
// Path: src/test/java/com/bah/lucene/blockcache_v2/cachevalue/UnsafeCacheValueTest.java
import static org.junit.Assert.*;
import org.junit.Test;
import com.bah.lucene.blockcache_v2.cachevalue.UnsafeCacheValue;
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2.cachevalue;
public class UnsafeCacheValueTest {
@Test
public void test1() {
|
UnsafeCacheValue value = new UnsafeCacheValue(10);
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/test/java/com/bah/lucene/CacheDirectoryTestSuiteOnHeap.java
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
// public enum STORE {
// ON_HEAP, OFF_HEAP
// }
|
import org.junit.Test;
import com.bah.lucene.blockcache_v2.BaseCache.STORE;
|
package com.bah.lucene;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class CacheDirectoryTestSuiteOnHeap extends CacheDirectoryTestSuite {
@Override
|
// Path: src/main/java/com/bah/lucene/blockcache_v2/BaseCache.java
// public enum STORE {
// ON_HEAP, OFF_HEAP
// }
// Path: src/test/java/com/bah/lucene/CacheDirectoryTestSuiteOnHeap.java
import org.junit.Test;
import com.bah.lucene.blockcache_v2.BaseCache.STORE;
package com.bah.lucene;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class CacheDirectoryTestSuiteOnHeap extends CacheDirectoryTestSuite {
@Override
|
protected STORE getStore() {
|
booz-allen-hamilton/lucene-hdfs-directory
|
src/main/java/com/bah/lucene/blockcache_v2/CacheIndexOutput.java
|
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
|
import java.io.IOException;
import org.apache.lucene.store.IndexOutput;
import com.bah.lucene.buffer.BufferStore;
|
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2;
public class CacheIndexOutput extends IndexOutput {
private final IndexOutput _indexOutput;
private final Cache _cache;
private final String _fileName;
private final CacheDirectory _directory;
private final long _fileId;
private final int _fileBufferSize;
private final int _cacheBlockSize;
private long _position;
private byte[] _buffer;
private int _bufferPosition;
public CacheIndexOutput(CacheDirectory directory, String fileName, IndexOutput indexOutput, Cache cache)
throws IOException {
_cache = cache;
_directory = directory;
_fileName = fileName;
_fileBufferSize = _cache.getFileBufferSize(_directory, _fileName);
_cacheBlockSize = _cache.getCacheBlockSize(_directory, _fileName);
_fileId = _cache.getFileId(_directory, _fileName);
_indexOutput = indexOutput;
|
// Path: src/main/java/com/bah/lucene/buffer/BufferStore.java
// public class BufferStore {
//
// public static final int _1024_DEFAULT_SIZE = 8192;
// public static final int _8192_DEFAULT_SIZE = 8192;
//
// private static final Log LOG = LogFactory.getLog(BufferStore.class);
//
// private static BlockingQueue<byte[]> _1024;
// private static BlockingQueue<byte[]> _8192;
//
// private volatile static boolean setup = false;
//
// public static void init(int _1KSize, int _8KSize) {
// if (!setup) {
// LOG.info(MessageFormat.format("Initializing the 1024 buffers with [{0}] buffers.", _1KSize));
// _1024 = setupBuffers(1024, _1KSize);
// LOG.info(MessageFormat.format("Initializing the 8192 buffers with [{0}] buffers.", _8KSize));
// _8192 = setupBuffers(8192, _8KSize);
// setup = true;
// }
// }
//
// private static BlockingQueue<byte[]> setupBuffers(int bufferSize, int count) {
// BlockingQueue<byte[]> queue = new ArrayBlockingQueue<byte[]>(count);
// for (int i = 0; i < count; i++) {
// queue.add(new byte[bufferSize]);
// }
// return queue;
// }
//
// public static byte[] takeBuffer(int bufferSize) {
// if(_1024 == null || _8192 == null) {
// init(_1024_DEFAULT_SIZE, _8192_DEFAULT_SIZE);
// }
// switch (bufferSize) {
// case 1024:
// return newBuffer1024(_1024.poll());
// case 8192:
// return newBuffer8192(_8192.poll());
// default:
// return newBuffer(bufferSize);
// }
// }
//
// public static void putBuffer(byte[] buffer) {
// if (buffer == null) {
// return;
// }
// int bufferSize = buffer.length;
// switch (bufferSize) {
// case 1024:
// _1024.offer(buffer);
// return;
// case 8192:
// _8192.offer(buffer);
// return;
// }
// }
//
// private static byte[] newBuffer1024(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[1024];
// }
//
// private static byte[] newBuffer8192(byte[] buf) {
// if (buf != null) {
// return buf;
// }
// return new byte[8192];
// }
//
// private static byte[] newBuffer(int size) {
// return new byte[size];
// }
// }
// Path: src/main/java/com/bah/lucene/blockcache_v2/CacheIndexOutput.java
import java.io.IOException;
import org.apache.lucene.store.IndexOutput;
import com.bah.lucene.buffer.BufferStore;
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bah.lucene.blockcache_v2;
public class CacheIndexOutput extends IndexOutput {
private final IndexOutput _indexOutput;
private final Cache _cache;
private final String _fileName;
private final CacheDirectory _directory;
private final long _fileId;
private final int _fileBufferSize;
private final int _cacheBlockSize;
private long _position;
private byte[] _buffer;
private int _bufferPosition;
public CacheIndexOutput(CacheDirectory directory, String fileName, IndexOutput indexOutput, Cache cache)
throws IOException {
_cache = cache;
_directory = directory;
_fileName = fileName;
_fileBufferSize = _cache.getFileBufferSize(_directory, _fileName);
_cacheBlockSize = _cache.getCacheBlockSize(_directory, _fileName);
_fileId = _cache.getFileId(_directory, _fileName);
_indexOutput = indexOutput;
|
_buffer = BufferStore.takeBuffer(_cacheBlockSize);
|
orangesignal/orangesignal-csv
|
src/test/java/com/orangesignal/csv/io/CsvBeanWriterTest.java
|
// Path: src/test/java/com/orangesignal/csv/Constants.java
// public abstract class Constants {
//
// public static final String CR = "\r";
//
// public static final String LF = "\n";
//
// public static final String CRLF = CR + LF;
//
// }
|
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.orangesignal.csv.Constants;
import com.orangesignal.csv.CsvConfig;
import com.orangesignal.csv.CsvWriter;
import com.orangesignal.csv.bean.CsvBeanTemplate;
import com.orangesignal.csv.filters.SimpleCsvNamedValueFilter;
import com.orangesignal.csv.model.SampleBean;
|
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.orangesignal.csv.io;
/**
* {@link CsvBeanWriter} クラスの単体テストです。
*
* @author Koji Sugisawa
* @since 1.4.0
*/
public class CsvBeanWriterTest {
@Rule
public ExpectedException exception = ExpectedException.none();
private static CsvConfig cfg;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
cfg = new CsvConfig(',');
cfg.setEscapeDisabled(false);
cfg.setNullString("NULL");
cfg.setIgnoreTrailingWhitespaces(true);
cfg.setIgnoreLeadingWhitespaces(true);
cfg.setIgnoreEmptyLines(true);
|
// Path: src/test/java/com/orangesignal/csv/Constants.java
// public abstract class Constants {
//
// public static final String CR = "\r";
//
// public static final String LF = "\n";
//
// public static final String CRLF = CR + LF;
//
// }
// Path: src/test/java/com/orangesignal/csv/io/CsvBeanWriterTest.java
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.orangesignal.csv.Constants;
import com.orangesignal.csv.CsvConfig;
import com.orangesignal.csv.CsvWriter;
import com.orangesignal.csv.bean.CsvBeanTemplate;
import com.orangesignal.csv.filters.SimpleCsvNamedValueFilter;
import com.orangesignal.csv.model.SampleBean;
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.orangesignal.csv.io;
/**
* {@link CsvBeanWriter} クラスの単体テストです。
*
* @author Koji Sugisawa
* @since 1.4.0
*/
public class CsvBeanWriterTest {
@Rule
public ExpectedException exception = ExpectedException.none();
private static CsvConfig cfg;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
cfg = new CsvConfig(',');
cfg.setEscapeDisabled(false);
cfg.setNullString("NULL");
cfg.setIgnoreTrailingWhitespaces(true);
cfg.setIgnoreLeadingWhitespaces(true);
cfg.setIgnoreEmptyLines(true);
|
cfg.setLineSeparator(Constants.CRLF);
|
iloveeclipse/datahierarchy
|
DataHierarchy/src/de/loskutov/dh/actions/CancelSearchAction.java
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
|
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import de.loskutov.dh.DataHierarchyPlugin;
|
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.actions;
public class CancelSearchAction implements IViewActionDelegate {
private IAction action;
@Override
public void init(IViewPart view) {
IJobChangeListener listener = new JobChangeAdapter() {
@Override
public void aboutToRun(IJobChangeEvent event) {
if (action == null || action.isEnabled()) {
return;
}
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
// Path: DataHierarchy/src/de/loskutov/dh/actions/CancelSearchAction.java
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import de.loskutov.dh.DataHierarchyPlugin;
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.actions;
public class CancelSearchAction implements IViewActionDelegate {
private IAction action;
@Override
public void init(IViewPart view) {
IJobChangeListener listener = new JobChangeAdapter() {
@Override
public void aboutToRun(IJobChangeEvent event) {
if (action == null || action.isEnabled()) {
return;
}
|
action.setEnabled(event.getJob().belongsTo(DataHierarchyPlugin.JOB_FAMILY));
|
iloveeclipse/datahierarchy
|
DataHierarchy/src/de/loskutov/dh/preferences/DataHierarchyPreferencePage.java
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
|
import java.util.List;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import de.loskutov.dh.DataHierarchyPlugin;
|
TabFolder tabFolder = new TabFolder(parent, SWT.TOP);
tabFolder.setLayout(new GridLayout(1, true));
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
TabItem tabFilter = new TabItem(tabFolder, SWT.NONE);
tabFilter.setText("Filters");
Group defPanel = new Group(tabFolder, SWT.NONE);
defPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
defPanel.setLayout(new GridLayout(1, false));
defPanel.setText("Search Filters");
tabFilter.setControl(defPanel);
TabItem support = new TabItem(tabFolder, SWT.NONE);
support.setText("Misc...");
Composite supportPanel = createContainer(tabFolder);
support.setControl(supportPanel);
SupportPanel.createSupportLinks(supportPanel);
return super.createContents(defPanel);
}
@Override
public void init(IWorkbench workbench) {
// noop
}
@Override
protected IPreferenceStore doGetPreferenceStore() {
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
// Path: DataHierarchy/src/de/loskutov/dh/preferences/DataHierarchyPreferencePage.java
import java.util.List;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import de.loskutov.dh.DataHierarchyPlugin;
TabFolder tabFolder = new TabFolder(parent, SWT.TOP);
tabFolder.setLayout(new GridLayout(1, true));
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
TabItem tabFilter = new TabItem(tabFolder, SWT.NONE);
tabFilter.setText("Filters");
Group defPanel = new Group(tabFolder, SWT.NONE);
defPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
defPanel.setLayout(new GridLayout(1, false));
defPanel.setText("Search Filters");
tabFilter.setControl(defPanel);
TabItem support = new TabItem(tabFolder, SWT.NONE);
support.setText("Misc...");
Composite supportPanel = createContainer(tabFolder);
support.setControl(supportPanel);
SupportPanel.createSupportLinks(supportPanel);
return super.createContents(defPanel);
}
@Override
public void init(IWorkbench workbench) {
// noop
}
@Override
protected IPreferenceStore doGetPreferenceStore() {
|
return DataHierarchyPlugin.getDefault().getPreferenceStore();
|
iloveeclipse/datahierarchy
|
DataHierarchy/src/de/loskutov/dh/search/AbstractReferencesRequestor.java
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
|
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchRequestor;
import de.loskutov.dh.DataHierarchyPlugin;
|
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.search;
public abstract class AbstractReferencesRequestor<V extends IJavaElement> extends SearchRequestor {
private volatile boolean isDone;
/**
* List is used, may be later we will allow duplicated elements?
*/
private final List<SearchMatch> searchResults;
public AbstractReferencesRequestor() {
searchResults = new LinkedList<SearchMatch>();
}
@Override
public void endReporting() {
isDone = true;
}
public List<V> getResults() {
while (!isDone) {
synchronized (this) {
try {
wait(50);
} catch (InterruptedException e) {
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
// Path: DataHierarchy/src/de/loskutov/dh/search/AbstractReferencesRequestor.java
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchRequestor;
import de.loskutov.dh.DataHierarchyPlugin;
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.search;
public abstract class AbstractReferencesRequestor<V extends IJavaElement> extends SearchRequestor {
private volatile boolean isDone;
/**
* List is used, may be later we will allow duplicated elements?
*/
private final List<SearchMatch> searchResults;
public AbstractReferencesRequestor() {
searchResults = new LinkedList<SearchMatch>();
}
@Override
public void endReporting() {
isDone = true;
}
public List<V> getResults() {
while (!isDone) {
synchronized (this) {
try {
wait(50);
} catch (InterruptedException e) {
|
DataHierarchyPlugin.logError("getResults() interrupted...", e);
|
iloveeclipse/datahierarchy
|
DataHierarchy/src/de/loskutov/dh/preferences/SupportPanel.java
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
|
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import de.loskutov.dh.DataHierarchyPlugin;
|
public void handleEvent(Event event) {
handleUrlClick("http://marketplace.eclipse.org/content/data-hierarchy");
}
});
link = new Link(commonPanel, SWT.NONE);
link.setFont(font);
link.setText(" - <a>make a donation to support plugin development</a>");
link.setToolTipText("You do NOT need a PayPal account!");
link.addListener (SWT.Selection, new Listener () {
@Override
public void handleEvent(Event event) {
handleUrlClick("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=R5SHJLNGUXKHU");
}
});
}
private static void handleUrlClick(final String urlStr) {
try {
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser externalBrowser = support.getExternalBrowser();
if(externalBrowser != null){
externalBrowser.openURL(new URL(urlStr));
} else {
IWebBrowser browser = support.createBrowser(urlStr);
if(browser != null){
browser.openURL(new URL(urlStr));
}
}
} catch (PartInitException e) {
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
// Path: DataHierarchy/src/de/loskutov/dh/preferences/SupportPanel.java
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import de.loskutov.dh.DataHierarchyPlugin;
public void handleEvent(Event event) {
handleUrlClick("http://marketplace.eclipse.org/content/data-hierarchy");
}
});
link = new Link(commonPanel, SWT.NONE);
link.setFont(font);
link.setText(" - <a>make a donation to support plugin development</a>");
link.setToolTipText("You do NOT need a PayPal account!");
link.addListener (SWT.Selection, new Listener () {
@Override
public void handleEvent(Event event) {
handleUrlClick("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=R5SHJLNGUXKHU");
}
});
}
private static void handleUrlClick(final String urlStr) {
try {
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser externalBrowser = support.getExternalBrowser();
if(externalBrowser != null){
externalBrowser.openURL(new URL(urlStr));
} else {
IWebBrowser browser = support.createBrowser(urlStr);
if(browser != null){
browser.openURL(new URL(urlStr));
}
}
} catch (PartInitException e) {
|
DataHierarchyPlugin.logError("Failed to open url " + urlStr, e);
|
iloveeclipse/datahierarchy
|
DataHierarchy/src/de/loskutov/dh/views/DefaultToggleAction.java
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
//
// Path: DataHierarchy/src/de/loskutov/dh/Messages.java
// public class Messages extends NLS {
// private static final String BUNDLE_NAME = "de.loskutov.dh.messages";//$NON-NLS-1$
//
// private Messages() {
// // Do not instantiate
// }
//
// static {
// NLS.initializeMessages(BUNDLE_NAME, Messages.class);
// }
//
// public static String get(String key){
// Field field;
// try {
// field = Messages.class.getField(key);
// return (String) field.get(null);
// } catch (Exception e) {
// DataHierarchyPlugin.logError("Missing resource for key: " + key, e);
// return key;
// }
// }
//
// public static String title;
// public static String error;
// public static String pref_Add_filter;
// public static String pref_Add_filterTip;
// public static String pref_RemoveFilter;
// public static String pref_RemoveFilterTip;
// public static String pref_Enable_all;
// public static String pref_Enable_allTip;
// public static String pref_Disable_all;
// public static String pref_Disable_allTip;
// public static String pref_Invalid_file_filter;
// public static String pref_Edit_filter;
// public static String pref_Edit_filterTip;
//
// public static String action_showStaticsOnly_text;
// public static String action_showStaticsOnly_toolTipText;
// public static String action_showStaticsOnly_image;
//
// public static String action_showPrimitivesToo_text;
// public static String action_showPrimitivesToo_toolTipText;
// public static String action_showPrimitivesToo_image;
//
// public static String action_showArrays_text;
// public static String action_showArrays_toolTipText;
// public static String action_showArrays_image;
//
// public static String action_autoRemoveEmptyElements_text;
// public static String action_autoRemoveEmptyElements_toolTipText;
// public static String action_autoRemoveEmptyElements_image;
//
//
// }
|
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import de.loskutov.dh.DataHierarchyPlugin;
import de.loskutov.dh.Messages;
|
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.views;
/**
* Default action which could be used as template for "toggle" action.
* Action image, text and tooltip will be initialized by default.
* To use it, register IPropertyChangeListener and check for IAction.CHECKED
* event name.
*/
public abstract class DefaultToggleAction extends Action {
private static final String ACTION = "action";
public DefaultToggleAction(String id) {
super();
setId(id);
init();
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
//
// Path: DataHierarchy/src/de/loskutov/dh/Messages.java
// public class Messages extends NLS {
// private static final String BUNDLE_NAME = "de.loskutov.dh.messages";//$NON-NLS-1$
//
// private Messages() {
// // Do not instantiate
// }
//
// static {
// NLS.initializeMessages(BUNDLE_NAME, Messages.class);
// }
//
// public static String get(String key){
// Field field;
// try {
// field = Messages.class.getField(key);
// return (String) field.get(null);
// } catch (Exception e) {
// DataHierarchyPlugin.logError("Missing resource for key: " + key, e);
// return key;
// }
// }
//
// public static String title;
// public static String error;
// public static String pref_Add_filter;
// public static String pref_Add_filterTip;
// public static String pref_RemoveFilter;
// public static String pref_RemoveFilterTip;
// public static String pref_Enable_all;
// public static String pref_Enable_allTip;
// public static String pref_Disable_all;
// public static String pref_Disable_allTip;
// public static String pref_Invalid_file_filter;
// public static String pref_Edit_filter;
// public static String pref_Edit_filterTip;
//
// public static String action_showStaticsOnly_text;
// public static String action_showStaticsOnly_toolTipText;
// public static String action_showStaticsOnly_image;
//
// public static String action_showPrimitivesToo_text;
// public static String action_showPrimitivesToo_toolTipText;
// public static String action_showPrimitivesToo_image;
//
// public static String action_showArrays_text;
// public static String action_showArrays_toolTipText;
// public static String action_showArrays_image;
//
// public static String action_autoRemoveEmptyElements_text;
// public static String action_autoRemoveEmptyElements_toolTipText;
// public static String action_autoRemoveEmptyElements_image;
//
//
// }
// Path: DataHierarchy/src/de/loskutov/dh/views/DefaultToggleAction.java
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import de.loskutov.dh.DataHierarchyPlugin;
import de.loskutov.dh.Messages;
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.views;
/**
* Default action which could be used as template for "toggle" action.
* Action image, text and tooltip will be initialized by default.
* To use it, register IPropertyChangeListener and check for IAction.CHECKED
* event name.
*/
public abstract class DefaultToggleAction extends Action {
private static final String ACTION = "action";
public DefaultToggleAction(String id) {
super();
setId(id);
init();
|
IPreferenceStore store = DataHierarchyPlugin.getDefault().getPreferenceStore();
|
iloveeclipse/datahierarchy
|
DataHierarchy/src/de/loskutov/dh/views/DefaultToggleAction.java
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
//
// Path: DataHierarchy/src/de/loskutov/dh/Messages.java
// public class Messages extends NLS {
// private static final String BUNDLE_NAME = "de.loskutov.dh.messages";//$NON-NLS-1$
//
// private Messages() {
// // Do not instantiate
// }
//
// static {
// NLS.initializeMessages(BUNDLE_NAME, Messages.class);
// }
//
// public static String get(String key){
// Field field;
// try {
// field = Messages.class.getField(key);
// return (String) field.get(null);
// } catch (Exception e) {
// DataHierarchyPlugin.logError("Missing resource for key: " + key, e);
// return key;
// }
// }
//
// public static String title;
// public static String error;
// public static String pref_Add_filter;
// public static String pref_Add_filterTip;
// public static String pref_RemoveFilter;
// public static String pref_RemoveFilterTip;
// public static String pref_Enable_all;
// public static String pref_Enable_allTip;
// public static String pref_Disable_all;
// public static String pref_Disable_allTip;
// public static String pref_Invalid_file_filter;
// public static String pref_Edit_filter;
// public static String pref_Edit_filterTip;
//
// public static String action_showStaticsOnly_text;
// public static String action_showStaticsOnly_toolTipText;
// public static String action_showStaticsOnly_image;
//
// public static String action_showPrimitivesToo_text;
// public static String action_showPrimitivesToo_toolTipText;
// public static String action_showPrimitivesToo_image;
//
// public static String action_showArrays_text;
// public static String action_showArrays_toolTipText;
// public static String action_showArrays_image;
//
// public static String action_autoRemoveEmptyElements_text;
// public static String action_autoRemoveEmptyElements_toolTipText;
// public static String action_autoRemoveEmptyElements_image;
//
//
// }
|
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import de.loskutov.dh.DataHierarchyPlugin;
import de.loskutov.dh.Messages;
|
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.views;
/**
* Default action which could be used as template for "toggle" action.
* Action image, text and tooltip will be initialized by default.
* To use it, register IPropertyChangeListener and check for IAction.CHECKED
* event name.
*/
public abstract class DefaultToggleAction extends Action {
private static final String ACTION = "action";
public DefaultToggleAction(String id) {
super();
setId(id);
init();
IPreferenceStore store = DataHierarchyPlugin.getDefault().getPreferenceStore();
boolean isChecked = store.getBoolean(id);
setChecked(isChecked);
}
private void init(){
String myId = getId();
|
// Path: DataHierarchy/src/de/loskutov/dh/DataHierarchyPlugin.java
// public class DataHierarchyPlugin extends AbstractUIPlugin {
//
// private static DataHierarchyPlugin plugin;
//
// private int viewCount;
//
// public static final Object JOB_FAMILY = DataHierarchyPlugin.class;
//
// public DataHierarchyPlugin() {
// super();
// }
//
// public static void logError(String message, Throwable e) {
// if (message == null) {
// message = e.getMessage();
// if (message == null) {
// message = e.toString();
// }
// }
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, e));
// }
//
// public static void showError(String message, Throwable error) {
// Shell shell = getShell();
// if (message == null) {
// message = Messages.error;
// }
// message = message + " " + error.getMessage();
//
// getDefault().getLog().log(new Status(IStatus.ERROR, getId(), IStatus.OK, message, error));
//
// MessageDialog.openError(shell, Messages.title, message);
// }
//
// public static Shell getShell() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// }
//
// public static String getId() {
// return getDefault().getBundle().getSymbolicName();
// }
//
// @Override
// public void start(BundleContext context) throws Exception {
// super.start(context);
// if(plugin == null) {
// plugin = this;
// }
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static DataHierarchyPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(getId(), path);
// }
//
// public static String nextViewId(){
// DataHierarchyPlugin hierarchyPlugin = getDefault();
// int next;
// synchronized (hierarchyPlugin) {
// hierarchyPlugin.viewCount ++;
// next = hierarchyPlugin.viewCount;
// }
// return String.valueOf(next);
// }
// }
//
// Path: DataHierarchy/src/de/loskutov/dh/Messages.java
// public class Messages extends NLS {
// private static final String BUNDLE_NAME = "de.loskutov.dh.messages";//$NON-NLS-1$
//
// private Messages() {
// // Do not instantiate
// }
//
// static {
// NLS.initializeMessages(BUNDLE_NAME, Messages.class);
// }
//
// public static String get(String key){
// Field field;
// try {
// field = Messages.class.getField(key);
// return (String) field.get(null);
// } catch (Exception e) {
// DataHierarchyPlugin.logError("Missing resource for key: " + key, e);
// return key;
// }
// }
//
// public static String title;
// public static String error;
// public static String pref_Add_filter;
// public static String pref_Add_filterTip;
// public static String pref_RemoveFilter;
// public static String pref_RemoveFilterTip;
// public static String pref_Enable_all;
// public static String pref_Enable_allTip;
// public static String pref_Disable_all;
// public static String pref_Disable_allTip;
// public static String pref_Invalid_file_filter;
// public static String pref_Edit_filter;
// public static String pref_Edit_filterTip;
//
// public static String action_showStaticsOnly_text;
// public static String action_showStaticsOnly_toolTipText;
// public static String action_showStaticsOnly_image;
//
// public static String action_showPrimitivesToo_text;
// public static String action_showPrimitivesToo_toolTipText;
// public static String action_showPrimitivesToo_image;
//
// public static String action_showArrays_text;
// public static String action_showArrays_toolTipText;
// public static String action_showArrays_image;
//
// public static String action_autoRemoveEmptyElements_text;
// public static String action_autoRemoveEmptyElements_toolTipText;
// public static String action_autoRemoveEmptyElements_image;
//
//
// }
// Path: DataHierarchy/src/de/loskutov/dh/views/DefaultToggleAction.java
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import de.loskutov.dh.DataHierarchyPlugin;
import de.loskutov.dh.Messages;
/*******************************************************************************
* Copyright (c) 2009 - 2015 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.dh.views;
/**
* Default action which could be used as template for "toggle" action.
* Action image, text and tooltip will be initialized by default.
* To use it, register IPropertyChangeListener and check for IAction.CHECKED
* event name.
*/
public abstract class DefaultToggleAction extends Action {
private static final String ACTION = "action";
public DefaultToggleAction(String id) {
super();
setId(id);
init();
IPreferenceStore store = DataHierarchyPlugin.getDefault().getPreferenceStore();
boolean isChecked = store.getBoolean(id);
setChecked(isChecked);
}
private void init(){
String myId = getId();
|
String imageFilePath = Messages.get(ACTION + "_" + myId + "_" + IMAGE);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/data/api/service/FollowersService.java
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.model.Shot;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.GET;
import retrofit2.http.Query;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/users/followers/
*/
public interface FollowersService {
@GET("/v1/user/following/shots")
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/data/api/service/FollowersService.java
import com.ge.protein.data.model.Shot;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.GET;
import retrofit2.http.Query;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/users/followers/
*/
public interface FollowersService {
@GET("/v1/user/following/shots")
|
Observable<Response<List<Shot>>> listFollowingShots(@Query("per_page") int perPage);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/data/api/service/AccessTokenService.java
|
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.model.AccessToken;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
import retrofit2.http.Url;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
public interface AccessTokenService {
@POST
@FormUrlEncoded
|
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/data/api/service/AccessTokenService.java
import com.ge.protein.data.model.AccessToken;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
import retrofit2.http.Url;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
public interface AccessTokenService {
@POST
@FormUrlEncoded
|
Observable<Response<AccessToken>> getAccessToken(@Url String url,
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthRepository.java
|
// Path: app/src/main/java/com/ge/protein/data/api/ApiConstants.java
// public final class ApiConstants {
//
// private ApiConstants() {
// throw new AssertionError("No construction for constant class");
// }
//
// // general constants of Dribbble API
// public static final String DRIBBBLE_V1_BASE_URL = "https://api.dribbble.com";
// public static final String DRIBBBLE_AUTHORIZE_URL = "https://dribbble.com/oauth/authorize";
// public static final String DRIBBBLE_GET_ACCESS_TOKEN_URL = "https://dribbble.com/oauth/token";
//
// // for both flavor open and play
// public static final String DRIBBBLE_AUTHORIZE_CALLBACK_URI = "x-protein-oauth-dribbble://callback";
// public static final String DRIBBBLE_AUTHORIZE_CALLBACK_URI_SCHEMA = "x-protein-oauth-dribbble";
// public static final String DRIBBBLE_AUTHORIZE_CALLBACK_URI_HOST = "callback";
// public static final String DRIBBBLE_AUTHORIZE_SCOPE = "public write comment upload";
//
// public static final int PER_PAGE = 20;
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/service/AccessTokenService.java
// public interface AccessTokenService {
//
// @POST
// @FormUrlEncoded
// Observable<Response<AccessToken>> getAccessToken(@Url String url,
// @Field("client_id") String clientId,
// @Field("client_secret") String clientSecret,
// @Field("code") String code,
// @Field("redirect_uri") String redirect_uri);
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
|
import com.ge.protein.BuildConfig;
import com.ge.protein.data.api.ApiConstants;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.data.api.service.AccessTokenService;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.util.AccountManager;
import io.reactivex.Observable;
import retrofit2.Response;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthRepository {
private AccessTokenService accessTokenService;
AuthRepository() {
|
// Path: app/src/main/java/com/ge/protein/data/api/ApiConstants.java
// public final class ApiConstants {
//
// private ApiConstants() {
// throw new AssertionError("No construction for constant class");
// }
//
// // general constants of Dribbble API
// public static final String DRIBBBLE_V1_BASE_URL = "https://api.dribbble.com";
// public static final String DRIBBBLE_AUTHORIZE_URL = "https://dribbble.com/oauth/authorize";
// public static final String DRIBBBLE_GET_ACCESS_TOKEN_URL = "https://dribbble.com/oauth/token";
//
// // for both flavor open and play
// public static final String DRIBBBLE_AUTHORIZE_CALLBACK_URI = "x-protein-oauth-dribbble://callback";
// public static final String DRIBBBLE_AUTHORIZE_CALLBACK_URI_SCHEMA = "x-protein-oauth-dribbble";
// public static final String DRIBBBLE_AUTHORIZE_CALLBACK_URI_HOST = "callback";
// public static final String DRIBBBLE_AUTHORIZE_SCOPE = "public write comment upload";
//
// public static final int PER_PAGE = 20;
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/service/AccessTokenService.java
// public interface AccessTokenService {
//
// @POST
// @FormUrlEncoded
// Observable<Response<AccessToken>> getAccessToken(@Url String url,
// @Field("client_id") String clientId,
// @Field("client_secret") String clientSecret,
// @Field("code") String code,
// @Field("redirect_uri") String redirect_uri);
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthRepository.java
import com.ge.protein.BuildConfig;
import com.ge.protein.data.api.ApiConstants;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.data.api.service.AccessTokenService;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.util.AccountManager;
import io.reactivex.Observable;
import retrofit2.Response;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthRepository {
private AccessTokenService accessTokenService;
AuthRepository() {
|
accessTokenService = ServiceGenerator.createService(AccessTokenService.class,
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/data/api/service/ShotsService.java
|
// Path: app/src/main/java/com/ge/protein/data/model/Comment.java
// @AutoValue
// public abstract class Comment implements Parcelable {
//
// public abstract long id();
//
// public abstract String body();
//
// public abstract long likes_count();
//
// public abstract String likes_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public abstract User user();
//
// public static TypeAdapter<Comment> typeAdapter(Gson gson) {
// return new AutoValue_Comment.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/ShotLike.java
// @AutoValue
// public abstract class ShotLike implements Parcelable {
//
//
// public abstract long id();
//
// public abstract String created_at();
//
// public abstract Shot shot();
//
// public static TypeAdapter<ShotLike> typeAdapter(Gson gson) {
// return new AutoValue_ShotLike.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.model.Comment;
import com.ge.protein.data.model.Shot;
import com.ge.protein.data.model.ShotLike;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/shots/
*/
public interface ShotsService {
@GET("/v1/shots/{shot_id}")
|
// Path: app/src/main/java/com/ge/protein/data/model/Comment.java
// @AutoValue
// public abstract class Comment implements Parcelable {
//
// public abstract long id();
//
// public abstract String body();
//
// public abstract long likes_count();
//
// public abstract String likes_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public abstract User user();
//
// public static TypeAdapter<Comment> typeAdapter(Gson gson) {
// return new AutoValue_Comment.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/ShotLike.java
// @AutoValue
// public abstract class ShotLike implements Parcelable {
//
//
// public abstract long id();
//
// public abstract String created_at();
//
// public abstract Shot shot();
//
// public static TypeAdapter<ShotLike> typeAdapter(Gson gson) {
// return new AutoValue_ShotLike.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/data/api/service/ShotsService.java
import com.ge.protein.data.model.Comment;
import com.ge.protein.data.model.Shot;
import com.ge.protein.data.model.ShotLike;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/shots/
*/
public interface ShotsService {
@GET("/v1/shots/{shot_id}")
|
Observable<Response<Shot>> getShot(@Path("shot_id") long shotId);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/data/api/service/ShotsService.java
|
// Path: app/src/main/java/com/ge/protein/data/model/Comment.java
// @AutoValue
// public abstract class Comment implements Parcelable {
//
// public abstract long id();
//
// public abstract String body();
//
// public abstract long likes_count();
//
// public abstract String likes_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public abstract User user();
//
// public static TypeAdapter<Comment> typeAdapter(Gson gson) {
// return new AutoValue_Comment.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/ShotLike.java
// @AutoValue
// public abstract class ShotLike implements Parcelable {
//
//
// public abstract long id();
//
// public abstract String created_at();
//
// public abstract Shot shot();
//
// public static TypeAdapter<ShotLike> typeAdapter(Gson gson) {
// return new AutoValue_ShotLike.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.model.Comment;
import com.ge.protein.data.model.Shot;
import com.ge.protein.data.model.ShotLike;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/shots/
*/
public interface ShotsService {
@GET("/v1/shots/{shot_id}")
Observable<Response<Shot>> getShot(@Path("shot_id") long shotId);
@GET("/v1/shots")
Observable<Response<List<Shot>>> listShots(@Query("list") String list,
@Query("timeframe") String timeframe,
@Query("date") String date,
@Query("sort") String sort,
@Query("per_page") int perPage);
@GET("/v1/users/{user_id}/shots")
Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
@Query("per_page") int perPage);
@GET
Observable<Response<List<Shot>>> listShotsOfNextPage(@Url String url);
@GET("/v1/shots/{shot_id}/comments")
|
// Path: app/src/main/java/com/ge/protein/data/model/Comment.java
// @AutoValue
// public abstract class Comment implements Parcelable {
//
// public abstract long id();
//
// public abstract String body();
//
// public abstract long likes_count();
//
// public abstract String likes_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public abstract User user();
//
// public static TypeAdapter<Comment> typeAdapter(Gson gson) {
// return new AutoValue_Comment.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/ShotLike.java
// @AutoValue
// public abstract class ShotLike implements Parcelable {
//
//
// public abstract long id();
//
// public abstract String created_at();
//
// public abstract Shot shot();
//
// public static TypeAdapter<ShotLike> typeAdapter(Gson gson) {
// return new AutoValue_ShotLike.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/data/api/service/ShotsService.java
import com.ge.protein.data.model.Comment;
import com.ge.protein.data.model.Shot;
import com.ge.protein.data.model.ShotLike;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/shots/
*/
public interface ShotsService {
@GET("/v1/shots/{shot_id}")
Observable<Response<Shot>> getShot(@Path("shot_id") long shotId);
@GET("/v1/shots")
Observable<Response<List<Shot>>> listShots(@Query("list") String list,
@Query("timeframe") String timeframe,
@Query("date") String date,
@Query("sort") String sort,
@Query("per_page") int perPage);
@GET("/v1/users/{user_id}/shots")
Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
@Query("per_page") int perPage);
@GET
Observable<Response<List<Shot>>> listShotsOfNextPage(@Url String url);
@GET("/v1/shots/{shot_id}/comments")
|
Observable<Response<List<Comment>>> listCommentsForShot(@Path("shot_id") long shotId,
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/data/api/service/ShotsService.java
|
// Path: app/src/main/java/com/ge/protein/data/model/Comment.java
// @AutoValue
// public abstract class Comment implements Parcelable {
//
// public abstract long id();
//
// public abstract String body();
//
// public abstract long likes_count();
//
// public abstract String likes_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public abstract User user();
//
// public static TypeAdapter<Comment> typeAdapter(Gson gson) {
// return new AutoValue_Comment.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/ShotLike.java
// @AutoValue
// public abstract class ShotLike implements Parcelable {
//
//
// public abstract long id();
//
// public abstract String created_at();
//
// public abstract Shot shot();
//
// public static TypeAdapter<ShotLike> typeAdapter(Gson gson) {
// return new AutoValue_ShotLike.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.model.Comment;
import com.ge.protein.data.model.Shot;
import com.ge.protein.data.model.ShotLike;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/shots/
*/
public interface ShotsService {
@GET("/v1/shots/{shot_id}")
Observable<Response<Shot>> getShot(@Path("shot_id") long shotId);
@GET("/v1/shots")
Observable<Response<List<Shot>>> listShots(@Query("list") String list,
@Query("timeframe") String timeframe,
@Query("date") String date,
@Query("sort") String sort,
@Query("per_page") int perPage);
@GET("/v1/users/{user_id}/shots")
Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
@Query("per_page") int perPage);
@GET
Observable<Response<List<Shot>>> listShotsOfNextPage(@Url String url);
@GET("/v1/shots/{shot_id}/comments")
Observable<Response<List<Comment>>> listCommentsForShot(@Path("shot_id") long shotId,
@Query("per_page") int perPage);
@GET
Observable<Response<List<Comment>>> listCommentsOfNextPage(@Url String url);
@GET("/v1/shots/{shot_id}/like")
|
// Path: app/src/main/java/com/ge/protein/data/model/Comment.java
// @AutoValue
// public abstract class Comment implements Parcelable {
//
// public abstract long id();
//
// public abstract String body();
//
// public abstract long likes_count();
//
// public abstract String likes_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public abstract User user();
//
// public static TypeAdapter<Comment> typeAdapter(Gson gson) {
// return new AutoValue_Comment.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/ShotLike.java
// @AutoValue
// public abstract class ShotLike implements Parcelable {
//
//
// public abstract long id();
//
// public abstract String created_at();
//
// public abstract Shot shot();
//
// public static TypeAdapter<ShotLike> typeAdapter(Gson gson) {
// return new AutoValue_ShotLike.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/data/api/service/ShotsService.java
import com.ge.protein.data.model.Comment;
import com.ge.protein.data.model.Shot;
import com.ge.protein.data.model.ShotLike;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api.service;
/**
* http://developer.dribbble.com/v1/shots/
*/
public interface ShotsService {
@GET("/v1/shots/{shot_id}")
Observable<Response<Shot>> getShot(@Path("shot_id") long shotId);
@GET("/v1/shots")
Observable<Response<List<Shot>>> listShots(@Query("list") String list,
@Query("timeframe") String timeframe,
@Query("date") String date,
@Query("sort") String sort,
@Query("per_page") int perPage);
@GET("/v1/users/{user_id}/shots")
Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
@Query("per_page") int perPage);
@GET
Observable<Response<List<Shot>>> listShotsOfNextPage(@Url String url);
@GET("/v1/shots/{shot_id}/comments")
Observable<Response<List<Comment>>> listCommentsForShot(@Path("shot_id") long shotId,
@Query("per_page") int perPage);
@GET
Observable<Response<List<Comment>>> listCommentsOfNextPage(@Url String url);
@GET("/v1/shots/{shot_id}/like")
|
Observable<Response<ShotLike>> checkLike(@Path("shot_id") long shotId);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/about/AboutContract.java
|
// Path: app/src/main/java/com/ge/protein/mvp/BasePresenter.java
// public interface BasePresenter {
//
// void start();
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/BaseView.java
// public interface BaseView<T> {
//
// void setPresenter(T presenter);
//
// Context getContext();
// }
|
import com.ge.protein.mvp.BasePresenter;
import com.ge.protein.mvp.BaseView;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.about;
interface AboutContract {
interface View extends BaseView<Presenter> {
}
|
// Path: app/src/main/java/com/ge/protein/mvp/BasePresenter.java
// public interface BasePresenter {
//
// void start();
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/BaseView.java
// public interface BaseView<T> {
//
// void setPresenter(T presenter);
//
// Context getContext();
// }
// Path: app/src/main/java/com/ge/protein/about/AboutContract.java
import com.ge.protein.mvp.BasePresenter;
import com.ge.protein.mvp.BaseView;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.about;
interface AboutContract {
interface View extends BaseView<Presenter> {
}
|
interface Presenter extends BasePresenter {
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthPresenter.java
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
|
this.view = checkNotNull(view, "view cannot be null");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new AuthRepository();
}
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthPresenter.java
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new AuthRepository();
}
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
|
AccessToken accessToken = accessTokenResponse.body();
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new AuthRepository();
}
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthPresenter.java
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new AuthRepository();
}
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
|
AccountManager.getInstance().setAccessToken(accessToken);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new AuthRepository();
}
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
AccountManager.getInstance().setAccessToken(accessToken);
SharedPreferences sp = view.getContext().getSharedPreferences(
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthPresenter.java
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
class AuthPresenter implements AuthContract.Presenter {
@NonNull
private AuthContract.View view;
private AuthRepository repository;
AuthPresenter(@Nullable AuthContract.View view) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new AuthRepository();
}
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
AccountManager.getInstance().setAccessToken(accessToken);
SharedPreferences sp = view.getContext().getSharedPreferences(
|
Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
|
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
AccountManager.getInstance().setAccessToken(accessToken);
SharedPreferences sp = view.getContext().getSharedPreferences(
Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
String strRepre = new GsonBuilder()
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
.create()
.toJson(accessToken);
editor.putString(Constants.ACCESS_TOKEN_KEY, strRepre);
editor.apply();
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthPresenter.java
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
@Override
public void start() {
}
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
AccountManager.getInstance().setAccessToken(accessToken);
SharedPreferences sp = view.getContext().getSharedPreferences(
Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
String strRepre = new GsonBuilder()
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
.create()
.toJson(accessToken);
editor.putString(Constants.ACCESS_TOKEN_KEY, strRepre);
editor.apply();
|
Intent intent = new Intent(view.getContext(), MainActivity.class);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
|
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
AccountManager.getInstance().setAccessToken(accessToken);
SharedPreferences sp = view.getContext().getSharedPreferences(
Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
String strRepre = new GsonBuilder()
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
.create()
.toJson(accessToken);
editor.putString(Constants.ACCESS_TOKEN_KEY, strRepre);
editor.apply();
Intent intent = new Intent(view.getContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
view.getContext().startActivity(intent);
} else {
view.setProgressDialogVisibility(false);
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/ErrorUtils.java
// public class ErrorUtils {
//
// public static APIError parseError(Response<?> response) {
// Converter<ResponseBody, APIError> converter = ServiceGenerator.retrofit()
// .responseBodyConverter(APIError.class, new Annotation[0]);
//
// APIError error;
//
// try {
// error = converter.convert(response.errorBody());
// } catch (IOException e) {
// return null;
// }
//
// return error;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthPresenter.java
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.api.ErrorUtils;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.google.gson.GsonBuilder;
import com.trello.rxlifecycle2.LifecycleProvider;
@Override
public void getAccessToken(String code) {
view.setProgressDialogVisibility(true);
repository.getAccessToken(code)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(accessTokenResponse -> {
view.setProgressDialogVisibility(false);
if (accessTokenResponse.isSuccessful()) {
AccessToken accessToken = accessTokenResponse.body();
AccountManager.getInstance().setAccessToken(accessToken);
SharedPreferences sp = view.getContext().getSharedPreferences(
Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
String strRepre = new GsonBuilder()
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
.create()
.toJson(accessToken);
editor.putString(Constants.ACCESS_TOKEN_KEY, strRepre);
editor.apply();
Intent intent = new Intent(view.getContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
view.getContext().startActivity(intent);
} else {
view.setProgressDialogVisibility(false);
|
view.showSnackbar(ErrorUtils.parseError(accessTokenResponse).error());
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
|
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
|
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.activity;
/**
* This activity is the root base activity for all other activities. It handles login/logout and
* account related logic.
*/
public abstract class BaseProteinActivity extends RxAppCompatActivity {
protected boolean login;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.activity;
/**
* This activity is the root base activity for all other activities. It handles login/logout and
* account related logic.
*/
public abstract class BaseProteinActivity extends RxAppCompatActivity {
protected boolean login;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
login = AccountManager.getInstance().isLogin();
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/widget/CircularImageView.java
|
// Path: app/src/main/java/com/ge/protein/util/ViewUtils.java
// public class ViewUtils {
//
// public static final ViewOutlineProvider CIRCULAR_OUTLINE = new ViewOutlineProvider() {
// @Override
// public void getOutline(View view, Outline outline) {
// outline.setOval(view.getPaddingLeft(),
// view.getPaddingTop(),
// view.getWidth() - view.getPaddingRight(),
// view.getHeight() - view.getPaddingBottom());
// }
// };
//
// public static RippleDrawable createRipple(@NonNull Palette palette,
// @FloatRange(from = 0f, to = 1f) float darkAlpha,
// @FloatRange(from = 0f, to = 1f) float lightAlpha,
// @ColorInt int fallbackColor,
// boolean bounded) {
// int rippleColor = fallbackColor;
// if (palette != null) {
// // try the named swatches in preference order
// if (palette.getVibrantSwatch() != null) {
// rippleColor =
// ColorUtils.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha);
//
// } else if (palette.getLightVibrantSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getLightVibrantSwatch().getRgb(),
// lightAlpha);
// } else if (palette.getDarkVibrantSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(),
// darkAlpha);
// } else if (palette.getMutedSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha);
// } else if (palette.getLightMutedSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getLightMutedSwatch().getRgb(),
// lightAlpha);
// } else if (palette.getDarkMutedSwatch() != null) {
// rippleColor =
// ColorUtils.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha);
// }
// }
// return new RippleDrawable(ColorStateList.valueOf(rippleColor), null,
// bounded ? new ColorDrawable(Color.WHITE) : null);
// }
//
// }
|
import android.content.Context;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import com.ge.protein.util.ViewUtils;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.widget;
public class CircularImageView extends AppCompatImageView {
public CircularImageView(Context context, AttributeSet attrs) {
super(context, attrs);
|
// Path: app/src/main/java/com/ge/protein/util/ViewUtils.java
// public class ViewUtils {
//
// public static final ViewOutlineProvider CIRCULAR_OUTLINE = new ViewOutlineProvider() {
// @Override
// public void getOutline(View view, Outline outline) {
// outline.setOval(view.getPaddingLeft(),
// view.getPaddingTop(),
// view.getWidth() - view.getPaddingRight(),
// view.getHeight() - view.getPaddingBottom());
// }
// };
//
// public static RippleDrawable createRipple(@NonNull Palette palette,
// @FloatRange(from = 0f, to = 1f) float darkAlpha,
// @FloatRange(from = 0f, to = 1f) float lightAlpha,
// @ColorInt int fallbackColor,
// boolean bounded) {
// int rippleColor = fallbackColor;
// if (palette != null) {
// // try the named swatches in preference order
// if (palette.getVibrantSwatch() != null) {
// rippleColor =
// ColorUtils.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha);
//
// } else if (palette.getLightVibrantSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getLightVibrantSwatch().getRgb(),
// lightAlpha);
// } else if (palette.getDarkVibrantSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(),
// darkAlpha);
// } else if (palette.getMutedSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha);
// } else if (palette.getLightMutedSwatch() != null) {
// rippleColor = ColorUtils.modifyAlpha(palette.getLightMutedSwatch().getRgb(),
// lightAlpha);
// } else if (palette.getDarkMutedSwatch() != null) {
// rippleColor =
// ColorUtils.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha);
// }
// }
// return new RippleDrawable(ColorStateList.valueOf(rippleColor), null,
// bounded ? new ColorDrawable(Color.WHITE) : null);
// }
//
// }
// Path: app/src/main/java/com/ge/protein/ui/widget/CircularImageView.java
import android.content.Context;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import com.ge.protein.util.ViewUtils;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.widget;
public class CircularImageView extends AppCompatImageView {
public CircularImageView(Context context, AttributeSet attrs) {
super(context, attrs);
|
setOutlineProvider(ViewUtils.CIRCULAR_OUTLINE);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/main/MainActivity.java
|
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
|
import android.os.Bundle;
import com.ge.protein.R;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
import hugo.weaving.DebugLog;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.main;
public class MainActivity extends BaseProteinActivity {
private MainPresenter mainPresenter;
@DebugLog
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
import android.os.Bundle;
import com.ge.protein.R;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
import hugo.weaving.DebugLog;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.main;
public class MainActivity extends BaseProteinActivity {
private MainPresenter mainPresenter;
@DebugLog
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
FirebaseCrashUtils.log("MainActivity created");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/epoxy/models/LoadMoreModel.java
|
// Path: app/src/main/java/com/ge/protein/ui/epoxy/BaseEpoxyHolder.java
// public abstract class BaseEpoxyHolder extends EpoxyHolder {
// @CallSuper
// @Override
// protected void bindView(View itemView) {
// ButterKnife.bind(this, itemView);
// }
// }
|
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import com.airbnb.epoxy.EpoxyModelClass;
import com.airbnb.epoxy.EpoxyModelWithHolder;
import com.ge.protein.R;
import com.ge.protein.ui.epoxy.BaseEpoxyHolder;
import butterknife.BindView;
|
ObjectAnimator innerXAnimator = ObjectAnimator.ofFloat(holder.inner, "scaleX", 1.33f);
innerXAnimator.setRepeatCount(ValueAnimator.INFINITE);
innerXAnimator.setRepeatMode(ValueAnimator.REVERSE);
ObjectAnimator innerYAnimator = ObjectAnimator.ofFloat(holder.inner, "scaleY", 1.33f);
innerYAnimator.setRepeatCount(ValueAnimator.INFINITE);
innerYAnimator.setRepeatMode(ValueAnimator.REVERSE);
animatorSet = new AnimatorSet();
animatorSet.playTogether(outerXAnimator, outerYAnimator, innerXAnimator, innerYAnimator);
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.setDuration(400);
}
animatorSet.start();
}
@Override
public void unbind(LoadMoreHolder holder) {
super.unbind(holder);
if (animatorSet != null) {
animatorSet.cancel();
}
}
@Override
public int getSpanSize(int totalSpanCount, int position, int itemCount) {
return 2;
}
|
// Path: app/src/main/java/com/ge/protein/ui/epoxy/BaseEpoxyHolder.java
// public abstract class BaseEpoxyHolder extends EpoxyHolder {
// @CallSuper
// @Override
// protected void bindView(View itemView) {
// ButterKnife.bind(this, itemView);
// }
// }
// Path: app/src/main/java/com/ge/protein/ui/epoxy/models/LoadMoreModel.java
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import com.airbnb.epoxy.EpoxyModelClass;
import com.airbnb.epoxy.EpoxyModelWithHolder;
import com.ge.protein.R;
import com.ge.protein.ui.epoxy.BaseEpoxyHolder;
import butterknife.BindView;
ObjectAnimator innerXAnimator = ObjectAnimator.ofFloat(holder.inner, "scaleX", 1.33f);
innerXAnimator.setRepeatCount(ValueAnimator.INFINITE);
innerXAnimator.setRepeatMode(ValueAnimator.REVERSE);
ObjectAnimator innerYAnimator = ObjectAnimator.ofFloat(holder.inner, "scaleY", 1.33f);
innerYAnimator.setRepeatCount(ValueAnimator.INFINITE);
innerYAnimator.setRepeatMode(ValueAnimator.REVERSE);
animatorSet = new AnimatorSet();
animatorSet.playTogether(outerXAnimator, outerYAnimator, innerXAnimator, innerYAnimator);
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.setDuration(400);
}
animatorSet.start();
}
@Override
public void unbind(LoadMoreHolder holder) {
super.unbind(holder);
if (animatorSet != null) {
animatorSet.cancel();
}
}
@Override
public int getSpanSize(int totalSpanCount, int position, int itemCount) {
return 2;
}
|
static class LoadMoreHolder extends BaseEpoxyHolder {
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/comment/post/CommentPostPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxBus.java
// public class RxBus {
//
// private RxBus() {}
//
// private static final RxBus rxBus = new RxBus();
//
// public static RxBus getInstance() {
// return rxBus;
// }
//
// private PublishSubject<Object> subject = PublishSubject.create();
//
// public void post(Object o) {
// subject.onNext(o);
// }
//
// public <T> Observable<T> toObservable(Class<T> eventType) {
// return subject.ofType(eventType);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.Shot;
import com.ge.protein.util.RxBus;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.comment.post;
public class CommentPostPresenter implements CommentPostContract.Presenter {
@NonNull
private CommentPostContract.View view;
private CommentPostRepository repository;
@NonNull
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxBus.java
// public class RxBus {
//
// private RxBus() {}
//
// private static final RxBus rxBus = new RxBus();
//
// public static RxBus getInstance() {
// return rxBus;
// }
//
// private PublishSubject<Object> subject = PublishSubject.create();
//
// public void post(Object o) {
// subject.onNext(o);
// }
//
// public <T> Observable<T> toObservable(Class<T> eventType) {
// return subject.ofType(eventType);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/comment/post/CommentPostPresenter.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.Shot;
import com.ge.protein.util.RxBus;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.comment.post;
public class CommentPostPresenter implements CommentPostContract.Presenter {
@NonNull
private CommentPostContract.View view;
private CommentPostRepository repository;
@NonNull
|
private Shot shot;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/comment/post/CommentPostPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxBus.java
// public class RxBus {
//
// private RxBus() {}
//
// private static final RxBus rxBus = new RxBus();
//
// public static RxBus getInstance() {
// return rxBus;
// }
//
// private PublishSubject<Object> subject = PublishSubject.create();
//
// public void post(Object o) {
// subject.onNext(o);
// }
//
// public <T> Observable<T> toObservable(Class<T> eventType) {
// return subject.ofType(eventType);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.Shot;
import com.ge.protein.util.RxBus;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.comment.post;
public class CommentPostPresenter implements CommentPostContract.Presenter {
@NonNull
private CommentPostContract.View view;
private CommentPostRepository repository;
@NonNull
private Shot shot;
public CommentPostPresenter(@Nullable Shot shot, @NonNull CommentPostContract.View view) {
repository = new CommentPostRepository();
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxBus.java
// public class RxBus {
//
// private RxBus() {}
//
// private static final RxBus rxBus = new RxBus();
//
// public static RxBus getInstance() {
// return rxBus;
// }
//
// private PublishSubject<Object> subject = PublishSubject.create();
//
// public void post(Object o) {
// subject.onNext(o);
// }
//
// public <T> Observable<T> toObservable(Class<T> eventType) {
// return subject.ofType(eventType);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/comment/post/CommentPostPresenter.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.Shot;
import com.ge.protein.util.RxBus;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.comment.post;
public class CommentPostPresenter implements CommentPostContract.Presenter {
@NonNull
private CommentPostContract.View view;
private CommentPostRepository repository;
@NonNull
private Shot shot;
public CommentPostPresenter(@Nullable Shot shot, @NonNull CommentPostContract.View view) {
repository = new CommentPostRepository();
|
this.shot = checkNotNull(shot, "shot cannot be null");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/comment/post/CommentPostPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxBus.java
// public class RxBus {
//
// private RxBus() {}
//
// private static final RxBus rxBus = new RxBus();
//
// public static RxBus getInstance() {
// return rxBus;
// }
//
// private PublishSubject<Object> subject = PublishSubject.create();
//
// public void post(Object o) {
// subject.onNext(o);
// }
//
// public <T> Observable<T> toObservable(Class<T> eventType) {
// return subject.ofType(eventType);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.Shot;
import com.ge.protein.util.RxBus;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.comment.post;
public class CommentPostPresenter implements CommentPostContract.Presenter {
@NonNull
private CommentPostContract.View view;
private CommentPostRepository repository;
@NonNull
private Shot shot;
public CommentPostPresenter(@Nullable Shot shot, @NonNull CommentPostContract.View view) {
repository = new CommentPostRepository();
this.shot = checkNotNull(shot, "shot cannot be null");
this.view = checkNotNull(view, "view cannot be null");
view.setPresenter(this);
}
@Override
public void start() {
// do nothing
}
@Override
public void postComment(String comment) {
repository.createCommentForShot(shot.id(), comment)
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(commentResponse -> {
if (commentResponse.code() == 201 && commentResponse.body() != null) {
view.fillInput("");
|
// Path: app/src/main/java/com/ge/protein/data/model/Shot.java
// @AutoValue
// public abstract class Shot implements Parcelable {
//
// public abstract long id();
//
// public abstract String title();
//
// @Nullable
// public abstract String description();
//
// public abstract int width();
//
// public abstract int height();
//
// public abstract Images images();
//
// public abstract long views_count();
//
// public abstract long likes_count();
//
// public abstract long comments_count();
//
// public abstract long attachments_count();
//
// public abstract long rebounds_count();
//
// public abstract long buckets_count();
//
// public abstract Date created_at();
//
// public abstract Date updated_at();
//
// public abstract String html_url();
//
// public abstract String attachments_url();
//
// public abstract String buckets_url();
//
// public abstract String comments_url();
//
// public abstract String likes_url();
//
// public abstract String projects_url();
//
// public abstract String rebounds_url();
//
// public abstract boolean animated();
//
// public abstract List<String> tags();
//
// @Nullable
// public abstract User user();
//
// @Nullable
// public abstract Team team();
//
// public abstract Shot withUser(User user);
//
// public abstract Shot withLikesCount(long likes_count);
//
// public static TypeAdapter<Shot> typeAdapter(Gson gson) {
// return new AutoValue_Shot.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxBus.java
// public class RxBus {
//
// private RxBus() {}
//
// private static final RxBus rxBus = new RxBus();
//
// public static RxBus getInstance() {
// return rxBus;
// }
//
// private PublishSubject<Object> subject = PublishSubject.create();
//
// public void post(Object o) {
// subject.onNext(o);
// }
//
// public <T> Observable<T> toObservable(Class<T> eventType) {
// return subject.ofType(eventType);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/comment/post/CommentPostPresenter.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.Shot;
import com.ge.protein.util.RxBus;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.comment.post;
public class CommentPostPresenter implements CommentPostContract.Presenter {
@NonNull
private CommentPostContract.View view;
private CommentPostRepository repository;
@NonNull
private Shot shot;
public CommentPostPresenter(@Nullable Shot shot, @NonNull CommentPostContract.View view) {
repository = new CommentPostRepository();
this.shot = checkNotNull(shot, "shot cannot be null");
this.view = checkNotNull(view, "view cannot be null");
view.setPresenter(this);
}
@Override
public void start() {
// do nothing
}
@Override
public void postComment(String comment) {
repository.createCommentForShot(shot.id(), comment)
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(commentResponse -> {
if (commentResponse.code() == 201 && commentResponse.body() != null) {
view.fillInput("");
|
RxBus.getInstance().post(commentResponse.body());
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/auth/AuthActivity.java
|
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
|
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
public class AuthActivity extends BaseProteinActivity {
private AuthPresenter authPresenter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
// Path: app/src/main/java/com/ge/protein/auth/AuthActivity.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.auth;
public class AuthActivity extends BaseProteinActivity {
private AuthPresenter authPresenter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
FirebaseCrashUtils.log("AuthActivity created");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/activity/DeepLinkActivity.java
|
// Path: app/src/main/java/com/ge/protein/ProteinDeepLinkModule.java
// @DeepLinkModule
// public class ProteinDeepLinkModule {
// }
//
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
|
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.airbnb.deeplinkdispatch.DeepLinkHandler;
import com.ge.protein.ProteinDeepLinkModule;
import com.ge.protein.ProteinDeepLinkModuleLoader;
import com.ge.protein.firebase.FirebaseCrashUtils;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.activity;
@DeepLinkHandler(ProteinDeepLinkModule.class)
public class DeepLinkActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
// Path: app/src/main/java/com/ge/protein/ProteinDeepLinkModule.java
// @DeepLinkModule
// public class ProteinDeepLinkModule {
// }
//
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
// Path: app/src/main/java/com/ge/protein/ui/activity/DeepLinkActivity.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.airbnb.deeplinkdispatch.DeepLinkHandler;
import com.ge.protein.ProteinDeepLinkModule;
import com.ge.protein.ProteinDeepLinkModuleLoader;
import com.ge.protein.firebase.FirebaseCrashUtils;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.activity;
@DeepLinkHandler(ProteinDeepLinkModule.class)
public class DeepLinkActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
FirebaseCrashUtils.log("DeepLinkActivity created");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserRepository.java
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/service/UserService.java
// public interface UserService {
//
// @GET("/v1/user")
// Observable<Response<User>> getMe();
//
// @GET("/v1/users/{user_id}/shots")
// Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET("/v1/users/{user_id}/likes")
// Observable<Response<List<ShotLike>>> listShotLikesForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<ShotLike>>> listShotLikesForUserOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/following")
// Observable<Response<List<Followee>>> listUserFollowing(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Followee>>> listFolloweeOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/followers")
// Observable<Response<List<Follower>>> listUserFollowers(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Follower>>> listFollowerOfNextPage(@Url String url);
//
// @GET("/v1/user/following/{user_id}")
// Observable<Response<Body>> isFollowing(@Path("user_id") long userId);
//
// @PUT("/v1/users/{user_id}/follow")
// Observable<Response<Body>> follow(@Path("user_id") long userId);
//
// @DELETE("/v1/users/{user_id}/follow")
// Observable<Response<Body>> unfollow(@Path("user_id") long userId);
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
|
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.data.api.service.UserService;
import com.ge.protein.util.AccountManager;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.Body;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserRepository {
private UserService userService;
UserRepository() {
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/service/UserService.java
// public interface UserService {
//
// @GET("/v1/user")
// Observable<Response<User>> getMe();
//
// @GET("/v1/users/{user_id}/shots")
// Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET("/v1/users/{user_id}/likes")
// Observable<Response<List<ShotLike>>> listShotLikesForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<ShotLike>>> listShotLikesForUserOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/following")
// Observable<Response<List<Followee>>> listUserFollowing(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Followee>>> listFolloweeOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/followers")
// Observable<Response<List<Follower>>> listUserFollowers(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Follower>>> listFollowerOfNextPage(@Url String url);
//
// @GET("/v1/user/following/{user_id}")
// Observable<Response<Body>> isFollowing(@Path("user_id") long userId);
//
// @PUT("/v1/users/{user_id}/follow")
// Observable<Response<Body>> follow(@Path("user_id") long userId);
//
// @DELETE("/v1/users/{user_id}/follow")
// Observable<Response<Body>> unfollow(@Path("user_id") long userId);
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
// Path: app/src/main/java/com/ge/protein/user/UserRepository.java
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.data.api.service.UserService;
import com.ge.protein.util.AccountManager;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.Body;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserRepository {
private UserService userService;
UserRepository() {
|
userService = ServiceGenerator.createService(UserService.class,
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserRepository.java
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/service/UserService.java
// public interface UserService {
//
// @GET("/v1/user")
// Observable<Response<User>> getMe();
//
// @GET("/v1/users/{user_id}/shots")
// Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET("/v1/users/{user_id}/likes")
// Observable<Response<List<ShotLike>>> listShotLikesForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<ShotLike>>> listShotLikesForUserOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/following")
// Observable<Response<List<Followee>>> listUserFollowing(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Followee>>> listFolloweeOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/followers")
// Observable<Response<List<Follower>>> listUserFollowers(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Follower>>> listFollowerOfNextPage(@Url String url);
//
// @GET("/v1/user/following/{user_id}")
// Observable<Response<Body>> isFollowing(@Path("user_id") long userId);
//
// @PUT("/v1/users/{user_id}/follow")
// Observable<Response<Body>> follow(@Path("user_id") long userId);
//
// @DELETE("/v1/users/{user_id}/follow")
// Observable<Response<Body>> unfollow(@Path("user_id") long userId);
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
|
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.data.api.service.UserService;
import com.ge.protein.util.AccountManager;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.Body;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserRepository {
private UserService userService;
UserRepository() {
userService = ServiceGenerator.createService(UserService.class,
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/data/api/service/UserService.java
// public interface UserService {
//
// @GET("/v1/user")
// Observable<Response<User>> getMe();
//
// @GET("/v1/users/{user_id}/shots")
// Observable<Response<List<Shot>>> listShotsForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET("/v1/users/{user_id}/likes")
// Observable<Response<List<ShotLike>>> listShotLikesForUser(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<ShotLike>>> listShotLikesForUserOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/following")
// Observable<Response<List<Followee>>> listUserFollowing(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Followee>>> listFolloweeOfNextPage(@Url String url);
//
// @GET("/v1/users/{user_id}/followers")
// Observable<Response<List<Follower>>> listUserFollowers(@Path("user_id") long userId,
// @Query("per_page") int perPage);
//
// @GET
// Observable<Response<List<Follower>>> listFollowerOfNextPage(@Url String url);
//
// @GET("/v1/user/following/{user_id}")
// Observable<Response<Body>> isFollowing(@Path("user_id") long userId);
//
// @PUT("/v1/users/{user_id}/follow")
// Observable<Response<Body>> follow(@Path("user_id") long userId);
//
// @DELETE("/v1/users/{user_id}/follow")
// Observable<Response<Body>> unfollow(@Path("user_id") long userId);
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
// Path: app/src/main/java/com/ge/protein/user/UserRepository.java
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.data.api.service.UserService;
import com.ge.protein.util.AccountManager;
import io.reactivex.Observable;
import retrofit2.Response;
import retrofit2.http.Body;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserRepository {
private UserService userService;
UserRepository() {
userService = ServiceGenerator.createService(UserService.class,
|
AccountManager.getInstance().getAccessToken());
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserView.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/widget/TabCustomView.java
// public class TabCustomView extends LinearLayout {
//
// private TextView countText;
// private TextView contentCategoryText;
//
// private long count;
// private String contentCategory;
//
// public TabCustomView(Context context) {
// super(context);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs) {
// super(context, attrs);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
// init(context);
// }
//
// private void init(Context context) {
// LayoutInflater.from(context).inflate(R.layout.tab_custom_view_content, this, true);
// setOrientation(LinearLayout.VERTICAL);
//
// countText = (TextView) findViewById(R.id.count);
// contentCategoryText = (TextView) findViewById(R.id.content_category);
// }
//
// public void setContentCategory(@StringRes int categoryId) {
// setContentCategory(getContext().getString(categoryId));
// }
//
// public long getCount() {
// return count;
// }
//
// public void setCount(long count) {
// this.count = count;
// countText.setText(String.valueOf(this.count));
// }
//
// public String getContentCategory() {
// return contentCategory;
// }
//
// public void setContentCategory(String category) {
// contentCategory = category;
// contentCategoryText.setText(contentCategory);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/StringUtils.java
// public class StringUtils {
//
// public static CharSequence trimTrailingWhitespace(CharSequence source) {
//
// if (source == null) {
// return "";
// }
//
// int i = source.length();
//
// // loop back to the first non-whitespace character
// while (--i >= 0 && Character.isWhitespace(source.charAt(i))) {
// }
//
// return source.subSequence(0, i + 1);
// }
//
// }
|
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.ui.widget.TabCustomView;
import com.ge.protein.util.StringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
|
TabLayout tabLayout;
@BindView(R.id.view_pager)
ViewPager viewPager;
public UserView(Context context) {
super(context);
init(context);
}
public UserView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public UserView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.user_view_content, this, true);
ButterKnife.bind(this);
}
@Override
public void setPresenter(UserContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/widget/TabCustomView.java
// public class TabCustomView extends LinearLayout {
//
// private TextView countText;
// private TextView contentCategoryText;
//
// private long count;
// private String contentCategory;
//
// public TabCustomView(Context context) {
// super(context);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs) {
// super(context, attrs);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
// init(context);
// }
//
// private void init(Context context) {
// LayoutInflater.from(context).inflate(R.layout.tab_custom_view_content, this, true);
// setOrientation(LinearLayout.VERTICAL);
//
// countText = (TextView) findViewById(R.id.count);
// contentCategoryText = (TextView) findViewById(R.id.content_category);
// }
//
// public void setContentCategory(@StringRes int categoryId) {
// setContentCategory(getContext().getString(categoryId));
// }
//
// public long getCount() {
// return count;
// }
//
// public void setCount(long count) {
// this.count = count;
// countText.setText(String.valueOf(this.count));
// }
//
// public String getContentCategory() {
// return contentCategory;
// }
//
// public void setContentCategory(String category) {
// contentCategory = category;
// contentCategoryText.setText(contentCategory);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/StringUtils.java
// public class StringUtils {
//
// public static CharSequence trimTrailingWhitespace(CharSequence source) {
//
// if (source == null) {
// return "";
// }
//
// int i = source.length();
//
// // loop back to the first non-whitespace character
// while (--i >= 0 && Character.isWhitespace(source.charAt(i))) {
// }
//
// return source.subSequence(0, i + 1);
// }
//
// }
// Path: app/src/main/java/com/ge/protein/user/UserView.java
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.ui.widget.TabCustomView;
import com.ge.protein.util.StringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
TabLayout tabLayout;
@BindView(R.id.view_pager)
ViewPager viewPager;
public UserView(Context context) {
super(context);
init(context);
}
public UserView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public UserView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.user_view_content, this, true);
ButterKnife.bind(this);
}
@Override
public void setPresenter(UserContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
|
public void setupView(User user) {
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserView.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/widget/TabCustomView.java
// public class TabCustomView extends LinearLayout {
//
// private TextView countText;
// private TextView contentCategoryText;
//
// private long count;
// private String contentCategory;
//
// public TabCustomView(Context context) {
// super(context);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs) {
// super(context, attrs);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
// init(context);
// }
//
// private void init(Context context) {
// LayoutInflater.from(context).inflate(R.layout.tab_custom_view_content, this, true);
// setOrientation(LinearLayout.VERTICAL);
//
// countText = (TextView) findViewById(R.id.count);
// contentCategoryText = (TextView) findViewById(R.id.content_category);
// }
//
// public void setContentCategory(@StringRes int categoryId) {
// setContentCategory(getContext().getString(categoryId));
// }
//
// public long getCount() {
// return count;
// }
//
// public void setCount(long count) {
// this.count = count;
// countText.setText(String.valueOf(this.count));
// }
//
// public String getContentCategory() {
// return contentCategory;
// }
//
// public void setContentCategory(String category) {
// contentCategory = category;
// contentCategoryText.setText(contentCategory);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/StringUtils.java
// public class StringUtils {
//
// public static CharSequence trimTrailingWhitespace(CharSequence source) {
//
// if (source == null) {
// return "";
// }
//
// int i = source.length();
//
// // loop back to the first non-whitespace character
// while (--i >= 0 && Character.isWhitespace(source.charAt(i))) {
// }
//
// return source.subSequence(0, i + 1);
// }
//
// }
|
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.ui.widget.TabCustomView;
import com.ge.protein.util.StringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
|
ButterKnife.bind(this);
}
@Override
public void setPresenter(UserContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
public void setupView(User user) {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.getNavigationIcon().setColorFilter(
getResources().getColor(R.color.icon_grey), PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationOnClickListener(v -> presenter.back());
userBio.setMovementMethod(LinkMovementMethod.getInstance());
Drawable[] drawables = location.getCompoundDrawables();
if (drawables[0] != null) {
drawables[0].setColorFilter(getResources().getColor(R.color.icon_grey), PorterDuff.Mode.SRC_IN);
}
followButton.setOnClickListener(this);
location.setOnClickListener(this);
twitter.setOnClickListener(this);
web.setOnClickListener(this);
viewPager.setAdapter(new UserPagerAdapter(((FragmentActivity)getContext()).getSupportFragmentManager(), user));
TabLayout.Tab shotsTab = tabLayout.newTab();
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/widget/TabCustomView.java
// public class TabCustomView extends LinearLayout {
//
// private TextView countText;
// private TextView contentCategoryText;
//
// private long count;
// private String contentCategory;
//
// public TabCustomView(Context context) {
// super(context);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs) {
// super(context, attrs);
// init(context);
// }
//
// public TabCustomView(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
// init(context);
// }
//
// private void init(Context context) {
// LayoutInflater.from(context).inflate(R.layout.tab_custom_view_content, this, true);
// setOrientation(LinearLayout.VERTICAL);
//
// countText = (TextView) findViewById(R.id.count);
// contentCategoryText = (TextView) findViewById(R.id.content_category);
// }
//
// public void setContentCategory(@StringRes int categoryId) {
// setContentCategory(getContext().getString(categoryId));
// }
//
// public long getCount() {
// return count;
// }
//
// public void setCount(long count) {
// this.count = count;
// countText.setText(String.valueOf(this.count));
// }
//
// public String getContentCategory() {
// return contentCategory;
// }
//
// public void setContentCategory(String category) {
// contentCategory = category;
// contentCategoryText.setText(contentCategory);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/StringUtils.java
// public class StringUtils {
//
// public static CharSequence trimTrailingWhitespace(CharSequence source) {
//
// if (source == null) {
// return "";
// }
//
// int i = source.length();
//
// // loop back to the first non-whitespace character
// while (--i >= 0 && Character.isWhitespace(source.charAt(i))) {
// }
//
// return source.subSequence(0, i + 1);
// }
//
// }
// Path: app/src/main/java/com/ge/protein/user/UserView.java
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.ui.widget.TabCustomView;
import com.ge.protein.util.StringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
ButterKnife.bind(this);
}
@Override
public void setPresenter(UserContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
public void setupView(User user) {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.getNavigationIcon().setColorFilter(
getResources().getColor(R.color.icon_grey), PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationOnClickListener(v -> presenter.back());
userBio.setMovementMethod(LinkMovementMethod.getInstance());
Drawable[] drawables = location.getCompoundDrawables();
if (drawables[0] != null) {
drawables[0].setColorFilter(getResources().getColor(R.color.icon_grey), PorterDuff.Mode.SRC_IN);
}
followButton.setOnClickListener(this);
location.setOnClickListener(this);
twitter.setOnClickListener(this);
web.setOnClickListener(this);
viewPager.setAdapter(new UserPagerAdapter(((FragmentActivity)getContext()).getSupportFragmentManager(), user));
TabLayout.Tab shotsTab = tabLayout.newTab();
|
TabCustomView shotsTabCustomView = new TabCustomView(getContext());
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/about/AboutFragment.java
|
// Path: app/src/main/java/com/ge/protein/mvp/BaseFragment.java
// public class BaseFragment extends RxFragment {
// }
//
// Path: app/src/main/java/com/ge/protein/ui/widget/FourThreeImageView.java
// public class FourThreeImageView extends AppCompatImageView {
//
// public FourThreeImageView(Context context, AttributeSet attrs) {
// super(context, attrs);
// }
//
// @Override
// protected void onMeasure(int widthSpec, int heightSpec) {
// int fourThreeHeight = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthSpec) * 3 / 4,
// MeasureSpec.EXACTLY);
// super.onMeasure(widthSpec, fourThreeHeight);
// }
// }
|
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.Toolbar;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.ge.protein.mvp.BaseFragment;
import com.ge.protein.BuildConfig;
import com.ge.protein.R;
import com.ge.protein.ui.widget.FourThreeImageView;
import butterknife.BindView;
import butterknife.ButterKnife;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.about;
public class AboutFragment extends BaseFragment implements AboutContract.View {
private AboutContract.Presenter presenter;
@BindView(R.id.banner_image)
|
// Path: app/src/main/java/com/ge/protein/mvp/BaseFragment.java
// public class BaseFragment extends RxFragment {
// }
//
// Path: app/src/main/java/com/ge/protein/ui/widget/FourThreeImageView.java
// public class FourThreeImageView extends AppCompatImageView {
//
// public FourThreeImageView(Context context, AttributeSet attrs) {
// super(context, attrs);
// }
//
// @Override
// protected void onMeasure(int widthSpec, int heightSpec) {
// int fourThreeHeight = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthSpec) * 3 / 4,
// MeasureSpec.EXACTLY);
// super.onMeasure(widthSpec, fourThreeHeight);
// }
// }
// Path: app/src/main/java/com/ge/protein/about/AboutFragment.java
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.Toolbar;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.ge.protein.mvp.BaseFragment;
import com.ge.protein.BuildConfig;
import com.ge.protein.R;
import com.ge.protein.ui.widget.FourThreeImageView;
import butterknife.BindView;
import butterknife.ButterKnife;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.about;
public class AboutFragment extends BaseFragment implements AboutContract.View {
private AboutContract.Presenter presenter;
@BindView(R.id.banner_image)
|
FourThreeImageView bannerImage;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/mvp/ListPresenter.java
|
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import static com.ge.protein.util.Preconditions.checkNotNull;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.mvp;
public abstract class ListPresenter<DATA> implements ListContract.Presenter<DATA> {
protected static final String STATE_NEXT_PAGE_URL = "state_next_page_url";
// only save first page data, or the App may occur TransactionTooLargeException
// see https://developer.android.com/reference/android/os/TransactionTooLargeException.html
// FIXME still happens
protected static final String STATE_FIRST_PAGE_DATA = "state_first_page_data";
@NonNull
protected ListContract.View view;
@Nullable
private String nextPageUrl;
public ListPresenter(@NonNull ListContract.View view) {
|
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/mvp/ListPresenter.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import static com.ge.protein.util.Preconditions.checkNotNull;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.mvp;
public abstract class ListPresenter<DATA> implements ListContract.Presenter<DATA> {
protected static final String STATE_NEXT_PAGE_URL = "state_next_page_url";
// only save first page data, or the App may occur TransactionTooLargeException
// see https://developer.android.com/reference/android/os/TransactionTooLargeException.html
// FIXME still happens
protected static final String STATE_FIRST_PAGE_DATA = "state_first_page_data";
@NonNull
protected ListContract.View view;
@Nullable
private String nextPageUrl;
public ListPresenter(@NonNull ListContract.View view) {
|
this.view = checkNotNull(view, "view cannot be null");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/dialog/LogoutDialog.java
|
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
|
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LogoutDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setTitle(R.string.logout_title)
.setMessage(R.string.logout_message)
.setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
.setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
|
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
// Path: app/src/main/java/com/ge/protein/ui/dialog/LogoutDialog.java
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LogoutDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setTitle(R.string.logout_title)
.setMessage(R.string.logout_message)
.setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
.setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
|
AccountManager.getInstance().clear();
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/dialog/LogoutDialog.java
|
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
|
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LogoutDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setTitle(R.string.logout_title)
.setMessage(R.string.logout_message)
.setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
.setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
AccountManager.getInstance().clear();
|
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
// Path: app/src/main/java/com/ge/protein/ui/dialog/LogoutDialog.java
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LogoutDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setTitle(R.string.logout_title)
.setMessage(R.string.logout_message)
.setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
.setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
AccountManager.getInstance().clear();
|
SharedPreferences sp = getActivity().getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES,
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/dialog/LogoutDialog.java
|
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
|
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LogoutDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setTitle(R.string.logout_title)
.setMessage(R.string.logout_message)
.setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
.setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
AccountManager.getInstance().clear();
SharedPreferences sp = getActivity().getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES,
Context.MODE_PRIVATE);
sp.edit().remove(Constants.ACCESS_TOKEN_KEY).remove(Constants.USER).apply();
|
// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
//
// private MainPresenter mainPresenter;
//
// @DebugLog
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("MainActivity created");
// setContentView(R.layout.activity_main);
//
// mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
// mainPresenter.start();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
// Path: app/src/main/java/com/ge/protein/ui/dialog/LogoutDialog.java
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LogoutDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getContext())
.setTitle(R.string.logout_title)
.setMessage(R.string.logout_message)
.setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
.setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
AccountManager.getInstance().clear();
SharedPreferences sp = getActivity().getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES,
Context.MODE_PRIVATE);
sp.edit().remove(Constants.ACCESS_TOKEN_KEY).remove(Constants.USER).apply();
|
Intent intent = new Intent(getContext(), MainActivity.class);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import android.content.Context;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.ge.protein.BuildConfig;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api;
public class ServiceGenerator {
private static String lastToken;
private static Gson gson = new GsonBuilder()
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
import android.content.Context;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.ge.protein.BuildConfig;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api;
public class ServiceGenerator {
private static String lastToken;
private static Gson gson = new GsonBuilder()
|
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import android.content.Context;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.ge.protein.BuildConfig;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api;
public class ServiceGenerator {
private static String lastToken;
private static Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
.create();
private static Cache cache;
private static Retrofit retrofit;
public static void init(Context context) {
if (cache != null) {
throw new IllegalStateException("Retrofit cache already initialized.");
}
cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
}
public static Retrofit retrofit() {
return retrofit;
}
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
import android.content.Context;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.ge.protein.BuildConfig;
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.data.api;
public class ServiceGenerator {
private static String lastToken;
private static Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
.create();
private static Cache cache;
private static Retrofit retrofit;
public static void init(Context context) {
if (cache != null) {
throw new IllegalStateException("Retrofit cache already initialized.");
}
cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
}
public static Retrofit retrofit() {
return retrofit;
}
|
public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/dialog/LoginGuideDialog.java
|
// Path: app/src/main/java/com/ge/protein/auth/AuthActivity.java
// public class AuthActivity extends BaseProteinActivity {
//
// private AuthPresenter authPresenter;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("AuthActivity created");
//
// setContentView(R.layout.activity_simple_fragment);
//
// AuthFragment authFragment = (AuthFragment) getSupportFragmentManager()
// .findFragmentByTag(AuthFragment.class.getSimpleName());
// if (authFragment == null) {
// authFragment = AuthFragment.newInstance();
// getSupportFragmentManager()
// .beginTransaction()
// .add(R.id.container, authFragment, AuthFragment.class.getSimpleName())
// .commit();
// }
//
// authPresenter = new AuthPresenter(authFragment);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
|
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import com.ge.protein.R;
import com.ge.protein.auth.AuthActivity;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LoginGuideDialog extends DialogFragment {
public static LoginGuideDialog newInstance() {
return new LoginGuideDialog();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogLoginGuide;
}
@NonNull
@Override
@SuppressLint("InflateParams")
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View root = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_guide, null);
View loginButton = root.findViewById(R.id.login_button);
RxView.clicks(loginButton)
|
// Path: app/src/main/java/com/ge/protein/auth/AuthActivity.java
// public class AuthActivity extends BaseProteinActivity {
//
// private AuthPresenter authPresenter;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("AuthActivity created");
//
// setContentView(R.layout.activity_simple_fragment);
//
// AuthFragment authFragment = (AuthFragment) getSupportFragmentManager()
// .findFragmentByTag(AuthFragment.class.getSimpleName());
// if (authFragment == null) {
// authFragment = AuthFragment.newInstance();
// getSupportFragmentManager()
// .beginTransaction()
// .add(R.id.container, authFragment, AuthFragment.class.getSimpleName())
// .commit();
// }
//
// authPresenter = new AuthPresenter(authFragment);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
// Path: app/src/main/java/com/ge/protein/ui/dialog/LoginGuideDialog.java
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import com.ge.protein.R;
import com.ge.protein.auth.AuthActivity;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LoginGuideDialog extends DialogFragment {
public static LoginGuideDialog newInstance() {
return new LoginGuideDialog();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogLoginGuide;
}
@NonNull
@Override
@SuppressLint("InflateParams")
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View root = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_guide, null);
View loginButton = root.findViewById(R.id.login_button);
RxView.clicks(loginButton)
|
.throttleFirst(RxUtils.WINDOW_DURATION, RxUtils.TIME_UNIT)
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ui/dialog/LoginGuideDialog.java
|
// Path: app/src/main/java/com/ge/protein/auth/AuthActivity.java
// public class AuthActivity extends BaseProteinActivity {
//
// private AuthPresenter authPresenter;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("AuthActivity created");
//
// setContentView(R.layout.activity_simple_fragment);
//
// AuthFragment authFragment = (AuthFragment) getSupportFragmentManager()
// .findFragmentByTag(AuthFragment.class.getSimpleName());
// if (authFragment == null) {
// authFragment = AuthFragment.newInstance();
// getSupportFragmentManager()
// .beginTransaction()
// .add(R.id.container, authFragment, AuthFragment.class.getSimpleName())
// .commit();
// }
//
// authPresenter = new AuthPresenter(authFragment);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
|
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import com.ge.protein.R;
import com.ge.protein.auth.AuthActivity;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LoginGuideDialog extends DialogFragment {
public static LoginGuideDialog newInstance() {
return new LoginGuideDialog();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogLoginGuide;
}
@NonNull
@Override
@SuppressLint("InflateParams")
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View root = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_guide, null);
View loginButton = root.findViewById(R.id.login_button);
RxView.clicks(loginButton)
.throttleFirst(RxUtils.WINDOW_DURATION, RxUtils.TIME_UNIT)
.subscribe(view -> {
dismiss();
|
// Path: app/src/main/java/com/ge/protein/auth/AuthActivity.java
// public class AuthActivity extends BaseProteinActivity {
//
// private AuthPresenter authPresenter;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// FirebaseCrashUtils.log("AuthActivity created");
//
// setContentView(R.layout.activity_simple_fragment);
//
// AuthFragment authFragment = (AuthFragment) getSupportFragmentManager()
// .findFragmentByTag(AuthFragment.class.getSimpleName());
// if (authFragment == null) {
// authFragment = AuthFragment.newInstance();
// getSupportFragmentManager()
// .beginTransaction()
// .add(R.id.container, authFragment, AuthFragment.class.getSimpleName())
// .commit();
// }
//
// authPresenter = new AuthPresenter(authFragment);
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
// Path: app/src/main/java/com/ge/protein/ui/dialog/LoginGuideDialog.java
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import com.ge.protein.R;
import com.ge.protein.auth.AuthActivity;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.ui.dialog;
public class LoginGuideDialog extends DialogFragment {
public static LoginGuideDialog newInstance() {
return new LoginGuideDialog();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogLoginGuide;
}
@NonNull
@Override
@SuppressLint("InflateParams")
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View root = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_guide, null);
View loginButton = root.findViewById(R.id.login_button);
RxView.clicks(loginButton)
.throttleFirst(RxUtils.WINDOW_DURATION, RxUtils.TIME_UNIT)
.subscribe(view -> {
dismiss();
|
startActivity(new Intent(getContext(), AuthActivity.class));
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserActivity.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
|
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
public class UserActivity extends BaseProteinActivity {
public static final String EXTRA_USER = "extra_user";
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
// Path: app/src/main/java/com/ge/protein/user/UserActivity.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
public class UserActivity extends BaseProteinActivity {
public static final String EXTRA_USER = "extra_user";
|
private User user;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserActivity.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
|
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
public class UserActivity extends BaseProteinActivity {
public static final String EXTRA_USER = "extra_user";
private User user;
private UserPresenter userPresenter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/open/java/com/ge/protein/firebase/FirebaseCrashUtils.java
// public class FirebaseCrashUtils {
//
// public static void log(String message) {
// // no-op for product flavor open
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/activity/BaseProteinActivity.java
// public abstract class BaseProteinActivity extends RxAppCompatActivity {
//
// protected boolean login;
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// login = AccountManager.getInstance().isLogin();
// }
//
// }
// Path: app/src/main/java/com/ge/protein/user/UserActivity.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.firebase.FirebaseCrashUtils;
import com.ge.protein.ui.activity.BaseProteinActivity;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
public class UserActivity extends BaseProteinActivity {
public static final String EXTRA_USER = "extra_user";
private User user;
private UserPresenter userPresenter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
FirebaseCrashUtils.log("UserActivity created");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ProteinApp.java
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
|
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein;
public class ProteinApp extends Application {
private RefWatcher refWatcher;
@DebugLog
@Override
public void onCreate() {
super.onCreate();
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
// Path: app/src/main/java/com/ge/protein/ProteinApp.java
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein;
public class ProteinApp extends Application {
private RefWatcher refWatcher;
@DebugLog
@Override
public void onCreate() {
super.onCreate();
|
ServiceGenerator.init(this);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ProteinApp.java
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
|
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein;
public class ProteinApp extends Application {
private RefWatcher refWatcher;
@DebugLog
@Override
public void onCreate() {
super.onCreate();
ServiceGenerator.init(this);
if (BuildConfig.DEBUG) {
Stetho.initializeWithDefaults(this);
}
initAccessToken();
ButterKnife.setDebug(BuildConfig.DEBUG);
refWatcher = installLeakCanary();
}
private void initAccessToken() {
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
// Path: app/src/main/java/com/ge/protein/ProteinApp.java
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein;
public class ProteinApp extends Application {
private RefWatcher refWatcher;
@DebugLog
@Override
public void onCreate() {
super.onCreate();
ServiceGenerator.init(this);
if (BuildConfig.DEBUG) {
Stetho.initializeWithDefaults(this);
}
initAccessToken();
ButterKnife.setDebug(BuildConfig.DEBUG);
refWatcher = installLeakCanary();
}
private void initAccessToken() {
|
SharedPreferences sp = getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES, MODE_PRIVATE);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/ProteinApp.java
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
|
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein;
public class ProteinApp extends Application {
private RefWatcher refWatcher;
@DebugLog
@Override
public void onCreate() {
super.onCreate();
ServiceGenerator.init(this);
if (BuildConfig.DEBUG) {
Stetho.initializeWithDefaults(this);
}
initAccessToken();
ButterKnife.setDebug(BuildConfig.DEBUG);
refWatcher = installLeakCanary();
}
private void initAccessToken() {
SharedPreferences sp = getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES, MODE_PRIVATE);
String accessToken = sp.getString(Constants.ACCESS_TOKEN_KEY, null);
if (!TextUtils.isEmpty(accessToken)) {
|
// Path: app/src/main/java/com/ge/protein/data/api/ServiceGenerator.java
// public class ServiceGenerator {
//
// private static String lastToken;
//
// private static Gson gson = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create();
//
// private static Cache cache;
//
// private static Retrofit retrofit;
//
// public static void init(Context context) {
// if (cache != null) {
// throw new IllegalStateException("Retrofit cache already initialized.");
// }
// cache = new Cache(context.getCacheDir(), 20 * 1024 * 1024);
// }
//
// public static Retrofit retrofit() {
// return retrofit;
// }
//
// public static <S> S createService(Class<S> serviceClass, final AccessToken token) {
// String currentToken = token == null ? BuildConfig.DRIBBBLE_CLIENT_ACCESS_TOKEN : token.access_token();
// if (retrofit == null || !currentToken.equals(lastToken)) {
// lastToken = currentToken;
// OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
// httpClientBuilder.addInterceptor(chain -> {
// Request original = chain.request();
//
// Request.Builder requestBuilder = original.newBuilder()
// .header("Accept", "application/json")
// .header("Authorization", "Bearer" + " " + lastToken)
// .method(original.method(), original.body());
//
// Request request = requestBuilder.build();
// return chain.proceed(request);
// }).cache(cache);
// if (BuildConfig.DEBUG) {
// httpClientBuilder.addNetworkInterceptor(new StethoInterceptor());
// }
// Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
// .baseUrl(ApiConstants.DRIBBBLE_V1_BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create());
// OkHttpClient httpClient = httpClientBuilder.build();
// retrofit = retrofitBuilder.client(httpClient).build();
// }
//
// return retrofit.create(serviceClass);
// }
//
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
//
// private Constants() {
// throw new AssertionError("No construction for constant class");
// }
//
// public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
//
// public static final String ACCESS_TOKEN_KEY = "access_token";
//
// public static final String USER = "user";
//
// }
// Path: app/src/main/java/com/ge/protein/ProteinApp.java
import android.app.Application;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.facebook.stetho.Stetho;
import com.ge.protein.data.api.ServiceGenerator;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
import com.squareup.leakcanary.RefWatcher;
import butterknife.ButterKnife;
import hugo.weaving.DebugLog;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein;
public class ProteinApp extends Application {
private RefWatcher refWatcher;
@DebugLog
@Override
public void onCreate() {
super.onCreate();
ServiceGenerator.init(this);
if (BuildConfig.DEBUG) {
Stetho.initializeWithDefaults(this);
}
initAccessToken();
ButterKnife.setDebug(BuildConfig.DEBUG);
refWatcher = installLeakCanary();
}
private void initAccessToken() {
SharedPreferences sp = getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES, MODE_PRIVATE);
String accessToken = sp.getString(Constants.ACCESS_TOKEN_KEY, null);
if (!TextUtils.isEmpty(accessToken)) {
|
AccountManager.getInstance().setAccessToken(accessToken);
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/util/AccountManager.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.data.model.User;
import com.google.gson.GsonBuilder;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.util;
public class AccountManager {
private static AccountManager accountManager = new AccountManager();
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.data.model.User;
import com.google.gson.GsonBuilder;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.util;
public class AccountManager {
private static AccountManager accountManager = new AccountManager();
|
private AccessToken accessToken;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/util/AccountManager.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.data.model.User;
import com.google.gson.GsonBuilder;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.util;
public class AccountManager {
private static AccountManager accountManager = new AccountManager();
private AccessToken accessToken;
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.data.model.User;
import com.google.gson.GsonBuilder;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.util;
public class AccountManager {
private static AccountManager accountManager = new AccountManager();
private AccessToken accessToken;
|
private User me;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/util/AccountManager.java
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
|
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.data.model.User;
import com.google.gson.GsonBuilder;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.util;
public class AccountManager {
private static AccountManager accountManager = new AccountManager();
private AccessToken accessToken;
private User me;
private AccountManager() {
}
public static AccountManager getInstance() {
return accountManager;
}
public AccessToken getAccessToken() {
return accessToken;
}
public void setAccessToken(AccessToken accessToken) {
this.accessToken = accessToken;
}
public void setAccessToken(String token) {
accessToken = new GsonBuilder()
|
// Path: app/src/main/java/com/ge/protein/data/ProteinAdapterFactory.java
// @GsonTypeAdapterFactory
// public abstract class ProteinAdapterFactory implements TypeAdapterFactory {
//
// public static TypeAdapterFactory create() {
// return new AutoValueGson_ProteinAdapterFactory();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/AccessToken.java
// @AutoValue
// public abstract class AccessToken {
//
// public abstract String access_token();
//
// public abstract String token_type();
//
// public abstract String scope();
//
// public static TypeAdapter<AccessToken> typeAdapter(Gson gson) {
// return new AutoValue_AccessToken.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
import com.ge.protein.data.ProteinAdapterFactory;
import com.ge.protein.data.model.AccessToken;
import com.ge.protein.data.model.User;
import com.google.gson.GsonBuilder;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.util;
public class AccountManager {
private static AccountManager accountManager = new AccountManager();
private AccessToken accessToken;
private User me;
private AccountManager() {
}
public static AccountManager getInstance() {
return accountManager;
}
public AccessToken getAccessToken() {
return accessToken;
}
public void setAccessToken(AccessToken accessToken) {
this.accessToken = accessToken;
}
public void setAccessToken(String token) {
accessToken = new GsonBuilder()
|
.registerTypeAdapterFactory(ProteinAdapterFactory.create())
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/InstanceStatePresenter.java
// public interface InstanceStatePresenter {
//
// void onSaveInstanceState(@NonNull Bundle outState);
//
// void onRestoreInstanceState(@NonNull Bundle savedInstanceState);
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.ge.protein.data.model.User;
import com.ge.protein.mvp.InstanceStatePresenter;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserPresenter implements UserContract.Presenter, InstanceStatePresenter {
private static final String STATE_FOLLOWING_CHECKED = "state_following_checked";
private static final String STATE_FOLLOWING = "state_following";
@NonNull
private UserContract.View view;
private UserRepository repository;
@NonNull
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/InstanceStatePresenter.java
// public interface InstanceStatePresenter {
//
// void onSaveInstanceState(@NonNull Bundle outState);
//
// void onRestoreInstanceState(@NonNull Bundle savedInstanceState);
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/user/UserPresenter.java
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.ge.protein.data.model.User;
import com.ge.protein.mvp.InstanceStatePresenter;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserPresenter implements UserContract.Presenter, InstanceStatePresenter {
private static final String STATE_FOLLOWING_CHECKED = "state_following_checked";
private static final String STATE_FOLLOWING = "state_following";
@NonNull
private UserContract.View view;
private UserRepository repository;
@NonNull
|
private User user;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/InstanceStatePresenter.java
// public interface InstanceStatePresenter {
//
// void onSaveInstanceState(@NonNull Bundle outState);
//
// void onRestoreInstanceState(@NonNull Bundle savedInstanceState);
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.ge.protein.data.model.User;
import com.ge.protein.mvp.InstanceStatePresenter;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserPresenter implements UserContract.Presenter, InstanceStatePresenter {
private static final String STATE_FOLLOWING_CHECKED = "state_following_checked";
private static final String STATE_FOLLOWING = "state_following";
@NonNull
private UserContract.View view;
private UserRepository repository;
@NonNull
private User user;
private boolean followingChecked;
private boolean following;
UserPresenter(@NonNull UserContract.View view, @NonNull User user) {
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/InstanceStatePresenter.java
// public interface InstanceStatePresenter {
//
// void onSaveInstanceState(@NonNull Bundle outState);
//
// void onRestoreInstanceState(@NonNull Bundle savedInstanceState);
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/user/UserPresenter.java
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.ge.protein.data.model.User;
import com.ge.protein.mvp.InstanceStatePresenter;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserPresenter implements UserContract.Presenter, InstanceStatePresenter {
private static final String STATE_FOLLOWING_CHECKED = "state_following_checked";
private static final String STATE_FOLLOWING = "state_following";
@NonNull
private UserContract.View view;
private UserRepository repository;
@NonNull
private User user;
private boolean followingChecked;
private boolean following;
UserPresenter(@NonNull UserContract.View view, @NonNull User user) {
|
this.view = checkNotNull(view, "view cannot be null");
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/user/UserPresenter.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/InstanceStatePresenter.java
// public interface InstanceStatePresenter {
//
// void onSaveInstanceState(@NonNull Bundle outState);
//
// void onRestoreInstanceState(@NonNull Bundle savedInstanceState);
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
|
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.ge.protein.data.model.User;
import com.ge.protein.mvp.InstanceStatePresenter;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserPresenter implements UserContract.Presenter, InstanceStatePresenter {
private static final String STATE_FOLLOWING_CHECKED = "state_following_checked";
private static final String STATE_FOLLOWING = "state_following";
@NonNull
private UserContract.View view;
private UserRepository repository;
@NonNull
private User user;
private boolean followingChecked;
private boolean following;
UserPresenter(@NonNull UserContract.View view, @NonNull User user) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new UserRepository();
this.user = checkNotNull(user, "user cannot be null");
}
@Override
public void start() {
view.setupView(user);
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/mvp/InstanceStatePresenter.java
// public interface InstanceStatePresenter {
//
// void onSaveInstanceState(@NonNull Bundle outState);
//
// void onRestoreInstanceState(@NonNull Bundle savedInstanceState);
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/Preconditions.java
// public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
// if(reference == null) {
// throw new NullPointerException(String.valueOf(errorMessage));
// } else {
// return reference;
// }
// }
// Path: app/src/main/java/com/ge/protein/user/UserPresenter.java
import io.reactivex.schedulers.Schedulers;
import static com.ge.protein.util.Preconditions.checkNotNull;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.ge.protein.data.model.User;
import com.ge.protein.mvp.InstanceStatePresenter;
import com.ge.protein.util.AccountManager;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.user;
class UserPresenter implements UserContract.Presenter, InstanceStatePresenter {
private static final String STATE_FOLLOWING_CHECKED = "state_following_checked";
private static final String STATE_FOLLOWING = "state_following";
@NonNull
private UserContract.View view;
private UserRepository repository;
@NonNull
private User user;
private boolean followingChecked;
private boolean following;
UserPresenter(@NonNull UserContract.View view, @NonNull User user) {
this.view = checkNotNull(view, "view cannot be null");
this.view.setPresenter(this);
repository = new UserRepository();
this.user = checkNotNull(user, "user cannot be null");
}
@Override
public void start() {
view.setupView(user);
|
if (AccountManager.getInstance().getMe() == null || AccountManager.getInstance().getMe().equals(user)) {
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/mvp/ListFragment.java
|
// Path: app/src/main/java/com/ge/protein/ui/epoxy/ProteinAdapter.java
// public class ProteinAdapter extends EpoxyAdapter {
//
// private final LoadMoreModel loadMoreModel;
//
// public ProteinAdapter() {
// loadMoreModel = new LoadMoreModel_();
// }
//
// public void swap(Collection<? extends EpoxyModel<?>> epoxyModels) {
// removeAllModels();
// addModels(epoxyModels);
// }
//
// public void addMore(Collection<? extends EpoxyModel<?>> epoxyModels) {
// addModels(epoxyModels);
// }
//
// public void addModel(EpoxyModel<?> modelToAdd) {
// super.addModel(modelToAdd);
// }
//
// public void showLoadMore(boolean visible) {
// if (visible) {
// addModel(loadMoreModel);
// } else {
// removeModel(loadMoreModel);
// }
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/epoxy/RecyclerViewObserver.java
// public class RecyclerViewObserver {
//
// private RecyclerView recyclerView;
// private RecyclerView.LayoutManager layoutManager;
//
// private boolean loading;
//
// private OnLoadMoreListener onLoadMoreListener;
//
// public RecyclerViewObserver subscribeOn(RecyclerView recyclerView) {
// this.recyclerView = recyclerView;
// return this;
// }
//
// public void unSubscribe() {
// recyclerView = null;
// onLoadMoreListener = null;
// }
//
// public RecyclerViewObserver setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
// this.onLoadMoreListener = onLoadMoreListener;
// return this;
// }
//
// public void setLoading(boolean loading) {
// this.loading = loading;
// }
//
// public boolean isLoading() {
// return loading;
// }
//
// public RecyclerViewObserver initialize() {
// layoutManager = recyclerView.getLayoutManager();
// if (!(layoutManager instanceof LinearLayoutManager)) {
// throw new IllegalArgumentException("Support only LinearLayoutManager now.");
// }
// recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// @Override
// public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
//
// int totalItemCount = recyclerView.getAdapter().getItemCount();
// int lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
//
// if (!loading && lastVisibleItemPosition == (totalItemCount - 1)) {
// if (onLoadMoreListener != null) {
// Log.d("RecyclerViewObserver", "onLoadMore");
// onLoadMoreListener.onLoadMore();
// }
// }
// }
// });
//
// return this;
// }
//
// public interface OnLoadMoreListener {
// void onLoadMore();
// }
//
// }
|
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.airbnb.epoxy.EpoxyModel;
import com.ge.protein.R;
import com.ge.protein.ui.epoxy.ProteinAdapter;
import com.ge.protein.ui.epoxy.RecyclerViewObserver;
import java.util.Collection;
import butterknife.BindView;
import butterknife.ButterKnife;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.mvp;
/**
* Base list fragment implemented with {@link RecyclerView}.
*/
public abstract class ListFragment extends BaseFragment implements
SwipeRefreshLayout.OnRefreshListener, ListContract.View<ListContract.Presenter> {
@BindView(R.id.toolbar)
protected Toolbar toolbar;
@BindView(R.id.swipe_refresh_layout)
protected SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.recycler_view)
protected RecyclerView recyclerView;
@BindView(R.id.empty_view)
protected View emptyView;
@BindView(R.id.error_view)
protected View errorView;
@BindView(R.id.button_retry)
protected Button retry;
protected ListContract.Presenter listPresenter;
|
// Path: app/src/main/java/com/ge/protein/ui/epoxy/ProteinAdapter.java
// public class ProteinAdapter extends EpoxyAdapter {
//
// private final LoadMoreModel loadMoreModel;
//
// public ProteinAdapter() {
// loadMoreModel = new LoadMoreModel_();
// }
//
// public void swap(Collection<? extends EpoxyModel<?>> epoxyModels) {
// removeAllModels();
// addModels(epoxyModels);
// }
//
// public void addMore(Collection<? extends EpoxyModel<?>> epoxyModels) {
// addModels(epoxyModels);
// }
//
// public void addModel(EpoxyModel<?> modelToAdd) {
// super.addModel(modelToAdd);
// }
//
// public void showLoadMore(boolean visible) {
// if (visible) {
// addModel(loadMoreModel);
// } else {
// removeModel(loadMoreModel);
// }
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/epoxy/RecyclerViewObserver.java
// public class RecyclerViewObserver {
//
// private RecyclerView recyclerView;
// private RecyclerView.LayoutManager layoutManager;
//
// private boolean loading;
//
// private OnLoadMoreListener onLoadMoreListener;
//
// public RecyclerViewObserver subscribeOn(RecyclerView recyclerView) {
// this.recyclerView = recyclerView;
// return this;
// }
//
// public void unSubscribe() {
// recyclerView = null;
// onLoadMoreListener = null;
// }
//
// public RecyclerViewObserver setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
// this.onLoadMoreListener = onLoadMoreListener;
// return this;
// }
//
// public void setLoading(boolean loading) {
// this.loading = loading;
// }
//
// public boolean isLoading() {
// return loading;
// }
//
// public RecyclerViewObserver initialize() {
// layoutManager = recyclerView.getLayoutManager();
// if (!(layoutManager instanceof LinearLayoutManager)) {
// throw new IllegalArgumentException("Support only LinearLayoutManager now.");
// }
// recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// @Override
// public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
//
// int totalItemCount = recyclerView.getAdapter().getItemCount();
// int lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
//
// if (!loading && lastVisibleItemPosition == (totalItemCount - 1)) {
// if (onLoadMoreListener != null) {
// Log.d("RecyclerViewObserver", "onLoadMore");
// onLoadMoreListener.onLoadMore();
// }
// }
// }
// });
//
// return this;
// }
//
// public interface OnLoadMoreListener {
// void onLoadMore();
// }
//
// }
// Path: app/src/main/java/com/ge/protein/mvp/ListFragment.java
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.airbnb.epoxy.EpoxyModel;
import com.ge.protein.R;
import com.ge.protein.ui.epoxy.ProteinAdapter;
import com.ge.protein.ui.epoxy.RecyclerViewObserver;
import java.util.Collection;
import butterknife.BindView;
import butterknife.ButterKnife;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.mvp;
/**
* Base list fragment implemented with {@link RecyclerView}.
*/
public abstract class ListFragment extends BaseFragment implements
SwipeRefreshLayout.OnRefreshListener, ListContract.View<ListContract.Presenter> {
@BindView(R.id.toolbar)
protected Toolbar toolbar;
@BindView(R.id.swipe_refresh_layout)
protected SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.recycler_view)
protected RecyclerView recyclerView;
@BindView(R.id.empty_view)
protected View emptyView;
@BindView(R.id.error_view)
protected View errorView;
@BindView(R.id.button_retry)
protected Button retry;
protected ListContract.Presenter listPresenter;
|
protected ProteinAdapter proteinAdapter;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/mvp/ListFragment.java
|
// Path: app/src/main/java/com/ge/protein/ui/epoxy/ProteinAdapter.java
// public class ProteinAdapter extends EpoxyAdapter {
//
// private final LoadMoreModel loadMoreModel;
//
// public ProteinAdapter() {
// loadMoreModel = new LoadMoreModel_();
// }
//
// public void swap(Collection<? extends EpoxyModel<?>> epoxyModels) {
// removeAllModels();
// addModels(epoxyModels);
// }
//
// public void addMore(Collection<? extends EpoxyModel<?>> epoxyModels) {
// addModels(epoxyModels);
// }
//
// public void addModel(EpoxyModel<?> modelToAdd) {
// super.addModel(modelToAdd);
// }
//
// public void showLoadMore(boolean visible) {
// if (visible) {
// addModel(loadMoreModel);
// } else {
// removeModel(loadMoreModel);
// }
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/epoxy/RecyclerViewObserver.java
// public class RecyclerViewObserver {
//
// private RecyclerView recyclerView;
// private RecyclerView.LayoutManager layoutManager;
//
// private boolean loading;
//
// private OnLoadMoreListener onLoadMoreListener;
//
// public RecyclerViewObserver subscribeOn(RecyclerView recyclerView) {
// this.recyclerView = recyclerView;
// return this;
// }
//
// public void unSubscribe() {
// recyclerView = null;
// onLoadMoreListener = null;
// }
//
// public RecyclerViewObserver setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
// this.onLoadMoreListener = onLoadMoreListener;
// return this;
// }
//
// public void setLoading(boolean loading) {
// this.loading = loading;
// }
//
// public boolean isLoading() {
// return loading;
// }
//
// public RecyclerViewObserver initialize() {
// layoutManager = recyclerView.getLayoutManager();
// if (!(layoutManager instanceof LinearLayoutManager)) {
// throw new IllegalArgumentException("Support only LinearLayoutManager now.");
// }
// recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// @Override
// public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
//
// int totalItemCount = recyclerView.getAdapter().getItemCount();
// int lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
//
// if (!loading && lastVisibleItemPosition == (totalItemCount - 1)) {
// if (onLoadMoreListener != null) {
// Log.d("RecyclerViewObserver", "onLoadMore");
// onLoadMoreListener.onLoadMore();
// }
// }
// }
// });
//
// return this;
// }
//
// public interface OnLoadMoreListener {
// void onLoadMore();
// }
//
// }
|
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.airbnb.epoxy.EpoxyModel;
import com.ge.protein.R;
import com.ge.protein.ui.epoxy.ProteinAdapter;
import com.ge.protein.ui.epoxy.RecyclerViewObserver;
import java.util.Collection;
import butterknife.BindView;
import butterknife.ButterKnife;
|
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.mvp;
/**
* Base list fragment implemented with {@link RecyclerView}.
*/
public abstract class ListFragment extends BaseFragment implements
SwipeRefreshLayout.OnRefreshListener, ListContract.View<ListContract.Presenter> {
@BindView(R.id.toolbar)
protected Toolbar toolbar;
@BindView(R.id.swipe_refresh_layout)
protected SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.recycler_view)
protected RecyclerView recyclerView;
@BindView(R.id.empty_view)
protected View emptyView;
@BindView(R.id.error_view)
protected View errorView;
@BindView(R.id.button_retry)
protected Button retry;
protected ListContract.Presenter listPresenter;
protected ProteinAdapter proteinAdapter;
|
// Path: app/src/main/java/com/ge/protein/ui/epoxy/ProteinAdapter.java
// public class ProteinAdapter extends EpoxyAdapter {
//
// private final LoadMoreModel loadMoreModel;
//
// public ProteinAdapter() {
// loadMoreModel = new LoadMoreModel_();
// }
//
// public void swap(Collection<? extends EpoxyModel<?>> epoxyModels) {
// removeAllModels();
// addModels(epoxyModels);
// }
//
// public void addMore(Collection<? extends EpoxyModel<?>> epoxyModels) {
// addModels(epoxyModels);
// }
//
// public void addModel(EpoxyModel<?> modelToAdd) {
// super.addModel(modelToAdd);
// }
//
// public void showLoadMore(boolean visible) {
// if (visible) {
// addModel(loadMoreModel);
// } else {
// removeModel(loadMoreModel);
// }
// }
// }
//
// Path: app/src/main/java/com/ge/protein/ui/epoxy/RecyclerViewObserver.java
// public class RecyclerViewObserver {
//
// private RecyclerView recyclerView;
// private RecyclerView.LayoutManager layoutManager;
//
// private boolean loading;
//
// private OnLoadMoreListener onLoadMoreListener;
//
// public RecyclerViewObserver subscribeOn(RecyclerView recyclerView) {
// this.recyclerView = recyclerView;
// return this;
// }
//
// public void unSubscribe() {
// recyclerView = null;
// onLoadMoreListener = null;
// }
//
// public RecyclerViewObserver setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
// this.onLoadMoreListener = onLoadMoreListener;
// return this;
// }
//
// public void setLoading(boolean loading) {
// this.loading = loading;
// }
//
// public boolean isLoading() {
// return loading;
// }
//
// public RecyclerViewObserver initialize() {
// layoutManager = recyclerView.getLayoutManager();
// if (!(layoutManager instanceof LinearLayoutManager)) {
// throw new IllegalArgumentException("Support only LinearLayoutManager now.");
// }
// recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
// @Override
// public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
//
// int totalItemCount = recyclerView.getAdapter().getItemCount();
// int lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
//
// if (!loading && lastVisibleItemPosition == (totalItemCount - 1)) {
// if (onLoadMoreListener != null) {
// Log.d("RecyclerViewObserver", "onLoadMore");
// onLoadMoreListener.onLoadMore();
// }
// }
// }
// });
//
// return this;
// }
//
// public interface OnLoadMoreListener {
// void onLoadMore();
// }
//
// }
// Path: app/src/main/java/com/ge/protein/mvp/ListFragment.java
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.airbnb.epoxy.EpoxyModel;
import com.ge.protein.R;
import com.ge.protein.ui.epoxy.ProteinAdapter;
import com.ge.protein.ui.epoxy.RecyclerViewObserver;
import java.util.Collection;
import butterknife.BindView;
import butterknife.ButterKnife;
/*
* Copyright 2017 Jiaheng Ge
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ge.protein.mvp;
/**
* Base list fragment implemented with {@link RecyclerView}.
*/
public abstract class ListFragment extends BaseFragment implements
SwipeRefreshLayout.OnRefreshListener, ListContract.View<ListContract.Presenter> {
@BindView(R.id.toolbar)
protected Toolbar toolbar;
@BindView(R.id.swipe_refresh_layout)
protected SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.recycler_view)
protected RecyclerView recyclerView;
@BindView(R.id.empty_view)
protected View emptyView;
@BindView(R.id.error_view)
protected View errorView;
@BindView(R.id.button_retry)
protected Button retry;
protected ListContract.Presenter listPresenter;
protected ProteinAdapter proteinAdapter;
|
protected RecyclerViewObserver recyclerViewObserver;
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/main/MainView.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
|
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
|
ViewPager viewPager;
public MainView(Context context) {
super(context);
init(context);
}
public MainView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MainView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.main_view_content, this, true);
ButterKnife.bind(this);
}
@Override
public void setPresenter(MainContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
public void setupView() {
RxView.clicks(userLayout)
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
// Path: app/src/main/java/com/ge/protein/main/MainView.java
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
ViewPager viewPager;
public MainView(Context context) {
super(context);
init(context);
}
public MainView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MainView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.main_view_content, this, true);
ButterKnife.bind(this);
}
@Override
public void setPresenter(MainContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
public void setupView() {
RxView.clicks(userLayout)
|
.throttleFirst(RxUtils.WINDOW_DURATION, RxUtils.TIME_UNIT)
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/main/MainView.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
|
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
|
init(context);
}
public MainView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MainView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.main_view_content, this, true);
ButterKnife.bind(this);
}
@Override
public void setPresenter(MainContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
public void setupView() {
RxView.clicks(userLayout)
.throttleFirst(RxUtils.WINDOW_DURATION, RxUtils.TIME_UNIT)
.subscribe(o -> presenter.onToolbarUserClicked());
toolbar.inflateMenu(R.menu.main_menu);
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
// Path: app/src/main/java/com/ge/protein/main/MainView.java
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
init(context);
}
public MainView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MainView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.main_view_content, this, true);
ButterKnife.bind(this);
}
@Override
public void setPresenter(MainContract.Presenter presenter) {
this.presenter = presenter;
}
@Override
public void setupView() {
RxView.clicks(userLayout)
.throttleFirst(RxUtils.WINDOW_DURATION, RxUtils.TIME_UNIT)
.subscribe(o -> presenter.onToolbarUserClicked());
toolbar.inflateMenu(R.menu.main_menu);
|
toolbar.getMenu().findItem(R.id.action_logout).setEnabled(AccountManager.getInstance().isLogin());
|
gejiaheng/Protein
|
app/src/main/java/com/ge/protein/main/MainView.java
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
|
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
|
}
return false;
});
viewPager.setAdapter(new MainPagerAdapter(((FragmentActivity) getContext()).getSupportFragmentManager()));
// Add 4 tabs for TabLayout
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_popular)); // Popular
if (AccountManager.getInstance().isLogin()) {
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_following)); // Following
}
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_recent)); // Recent
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_debuts)); // Debuts
// Setup sync between TabLayout and ViewPager
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
viewPager.setOffscreenPageLimit(3);
}
@Override
public void setDefaultUserInfo() {
Glide.with(getContext())
.load(R.mipmap.ic_launcher)
.transition(withCrossFade())
.into(userAvatar);
setUserName(getContext().getString(R.string.action_login));
}
@Override
|
// Path: app/src/main/java/com/ge/protein/data/model/User.java
// @AutoValue
// public abstract class User implements Parcelable {
//
// public abstract long id();
//
// public abstract String name();
//
// public abstract String username();
//
// public abstract String html_url();
//
// public abstract String avatar_url();
//
// public abstract String bio();
//
// @Nullable
// public abstract String location();
//
// public abstract Links links();
//
// public abstract long buckets_count();
//
// public abstract long comments_received_count();
//
// public abstract long followers_count();
//
// public abstract long followings_count();
//
// public abstract long likes_count();
//
// public abstract long likes_received_count();
//
// public abstract long projects_count();
//
// public abstract long rebounds_received_count();
//
// public abstract long shots_count();
//
// public abstract long teams_count();
//
// public abstract boolean can_upload_shot();
//
// public abstract String type();
//
// public abstract boolean pro();
//
// public abstract String buckets_url();
//
// public abstract String followers_url();
//
// public abstract String following_url();
//
// public abstract String likes_url();
//
// public abstract String shots_url();
//
// @Nullable
// public abstract String teams_url();
//
// public abstract String created_at();
//
// public abstract String updated_at();
//
// public static TypeAdapter<User> typeAdapter(Gson gson) {
// return new AutoValue_User.GsonTypeAdapter(gson).nullSafe();
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
//
// private static AccountManager accountManager = new AccountManager();
// private AccessToken accessToken;
// private User me;
//
// private AccountManager() {
// }
//
// public static AccountManager getInstance() {
// return accountManager;
// }
//
// public AccessToken getAccessToken() {
// return accessToken;
// }
//
// public void setAccessToken(AccessToken accessToken) {
// this.accessToken = accessToken;
// }
//
// public void setAccessToken(String token) {
// accessToken = new GsonBuilder()
// .registerTypeAdapterFactory(ProteinAdapterFactory.create())
// .create()
// .fromJson(token, AccessToken.class);
// }
//
// public boolean isLogin() {
// return accessToken != null;
// }
//
// public User getMe() {
// return me;
// }
//
// public void setMe(User me) {
// this.me = me;
// }
//
// public void clear() {
// accessToken = null;
// me = null;
// }
// }
//
// Path: app/src/main/java/com/ge/protein/util/RxUtils.java
// public class RxUtils {
//
// public static final int WINDOW_DURATION = 500;
// public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
//
// }
// Path: app/src/main/java/com/ge/protein/main/MainView.java
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ge.protein.R;
import com.ge.protein.data.model.User;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.RxUtils;
import com.jakewharton.rxbinding2.view.RxView;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.bumptech.glide.request.RequestOptions.placeholderOf;
}
return false;
});
viewPager.setAdapter(new MainPagerAdapter(((FragmentActivity) getContext()).getSupportFragmentManager()));
// Add 4 tabs for TabLayout
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_popular)); // Popular
if (AccountManager.getInstance().isLogin()) {
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_following)); // Following
}
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_recent)); // Recent
tabLayout.addTab(tabLayout.newTab().setText(R.string.home_tab_debuts)); // Debuts
// Setup sync between TabLayout and ViewPager
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
viewPager.setOffscreenPageLimit(3);
}
@Override
public void setDefaultUserInfo() {
Glide.with(getContext())
.load(R.mipmap.ic_launcher)
.transition(withCrossFade())
.into(userAvatar);
setUserName(getContext().getString(R.string.action_login));
}
@Override
|
public void setUserInfo(User user) {
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.