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
RokLenarcic/AhoCorasick
src/main/java/com/roklenarcic/util/strings/LongestMatchMap.java
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // }
import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder;
package com.roklenarcic.util.strings; // Matches leftmost longest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class LongestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public LongestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) {
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // } // Path: src/main/java/com/roklenarcic/util/strings/LongestMatchMap.java import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder; package com.roklenarcic.util.strings; // Matches leftmost longest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class LongestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public LongestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) {
this(keywords, values, caseSensitive, new RangeNodeThreshold());
RokLenarcic/AhoCorasick
src/main/java/com/roklenarcic/util/strings/LongestMatchMap.java
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // }
import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder;
package com.roklenarcic.util.strings; // Matches leftmost longest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class LongestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public LongestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) { this(keywords, values, caseSensitive, new RangeNodeThreshold()); }
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // } // Path: src/main/java/com/roklenarcic/util/strings/LongestMatchMap.java import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder; package com.roklenarcic.util.strings; // Matches leftmost longest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class LongestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public LongestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) { this(keywords, values, caseSensitive, new RangeNodeThreshold()); }
public LongestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive, final Thresholder thresholdStrategy) {
RokLenarcic/AhoCorasick
src/main/java/com/roklenarcic/util/strings/ShortestMatchMap.java
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // }
import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder;
package com.roklenarcic.util.strings; // Matches leftmost shortest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class ShortestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public ShortestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) {
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // } // Path: src/main/java/com/roklenarcic/util/strings/ShortestMatchMap.java import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder; package com.roklenarcic.util.strings; // Matches leftmost shortest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class ShortestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public ShortestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) {
this(keywords, values, caseSensitive, new RangeNodeThreshold());
RokLenarcic/AhoCorasick
src/main/java/com/roklenarcic/util/strings/ShortestMatchMap.java
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // }
import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder;
package com.roklenarcic.util.strings; // Matches leftmost shortest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class ShortestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public ShortestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) { this(keywords, values, caseSensitive, new RangeNodeThreshold()); }
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // } // Path: src/main/java/com/roklenarcic/util/strings/ShortestMatchMap.java import java.io.IOException; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Iterator; import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder; package com.roklenarcic.util.strings; // Matches leftmost shortest matches. Useful when you want non-overlapping // matches with a string set that doesn't have strings that are prefix to other strings in the set. public class ShortestMatchMap<T> implements StringMap<T> { private boolean caseSensitive = true; private int charBufferSize = 0; private TrieNode<T> root; public ShortestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive) { this(keywords, values, caseSensitive, new RangeNodeThreshold()); }
public ShortestMatchMap(final Iterable<String> keywords, final Iterable<? extends T> values, boolean caseSensitive, final Thresholder thresholdStrategy) {
RokLenarcic/AhoCorasick
src/main/java/com/roklenarcic/util/strings/WholeWordLongestMatchSet.java
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // }
import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder;
package com.roklenarcic.util.strings; // A set that matches only whole word matches. Non-word characters are user defined (with a default). // Any non-word characters around input strings get trimmed. Non-word characters are allowed in the keywords. public class WholeWordLongestMatchSet implements StringSet { private boolean caseSensitive = true; private TrieNode root; private boolean[] wordChars; // Set where digits and letters, '-' and '_' are considered word characters. public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive) {
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // } // Path: src/main/java/com/roklenarcic/util/strings/WholeWordLongestMatchSet.java import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder; package com.roklenarcic.util.strings; // A set that matches only whole word matches. Non-word characters are user defined (with a default). // Any non-word characters around input strings get trimmed. Non-word characters are allowed in the keywords. public class WholeWordLongestMatchSet implements StringSet { private boolean caseSensitive = true; private TrieNode root; private boolean[] wordChars; // Set where digits and letters, '-' and '_' are considered word characters. public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive) {
this(keywords, caseSensitive, new RangeNodeThreshold());
RokLenarcic/AhoCorasick
src/main/java/com/roklenarcic/util/strings/WholeWordLongestMatchSet.java
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // }
import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder;
package com.roklenarcic.util.strings; // A set that matches only whole word matches. Non-word characters are user defined (with a default). // Any non-word characters around input strings get trimmed. Non-word characters are allowed in the keywords. public class WholeWordLongestMatchSet implements StringSet { private boolean caseSensitive = true; private TrieNode root; private boolean[] wordChars; // Set where digits and letters, '-' and '_' are considered word characters. public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive) { this(keywords, caseSensitive, new RangeNodeThreshold()); } // Set where the characters in the given array are considered word characters public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive, char[] wordCharacters) { this(keywords, caseSensitive, wordCharacters, new RangeNodeThreshold()); } // Set where digits and letters and '-' and '_' are considered word characters but modified by the two // given arrays public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive, char[] wordCharacters, boolean[] toggleFlags) { this(keywords, caseSensitive, wordCharacters, toggleFlags, new RangeNodeThreshold()); } // Set where digits and letters and '-' and '_' are considered word characters but modified by the two // given arrays public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive, char[] wordCharacters, boolean[] toggleFlags,
// Path: src/main/java/com/roklenarcic/util/strings/threshold/RangeNodeThreshold.java // public class RangeNodeThreshold implements Thresholder { // // private double exponent, linearFactor, maxValue, constantFactor; // // public RangeNodeThreshold() { // this(1); // } // // public RangeNodeThreshold(double exponent) { // this(exponent, 1, 0.65, 2); // } // // public RangeNodeThreshold(double exponent, double linearFactor, double maxValue, double constantFactor) { // super(); // this.exponent = exponent; // this.linearFactor = linearFactor; // this.maxValue = maxValue; // this.constantFactor = constantFactor; // } // // public boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize) { // if (keyIntervalSize <= 8) { // return true; // } // int charArrayCost = (nodeSize / 4) + 3; // Char array costs 24 bytes + 2 bytes per char // return nodeSize + charArrayCost > keyIntervalSize * (maxValue - linearFactor / Math.pow(constantFactor + nodeLevel, exponent)); // } // // } // // Path: src/main/java/com/roklenarcic/util/strings/threshold/Thresholder.java // public interface Thresholder { // boolean isOverThreshold(int nodeSize, int nodeLevel, int keyIntervalSize); // } // Path: src/main/java/com/roklenarcic/util/strings/WholeWordLongestMatchSet.java import com.roklenarcic.util.strings.threshold.RangeNodeThreshold; import com.roklenarcic.util.strings.threshold.Thresholder; package com.roklenarcic.util.strings; // A set that matches only whole word matches. Non-word characters are user defined (with a default). // Any non-word characters around input strings get trimmed. Non-word characters are allowed in the keywords. public class WholeWordLongestMatchSet implements StringSet { private boolean caseSensitive = true; private TrieNode root; private boolean[] wordChars; // Set where digits and letters, '-' and '_' are considered word characters. public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive) { this(keywords, caseSensitive, new RangeNodeThreshold()); } // Set where the characters in the given array are considered word characters public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive, char[] wordCharacters) { this(keywords, caseSensitive, wordCharacters, new RangeNodeThreshold()); } // Set where digits and letters and '-' and '_' are considered word characters but modified by the two // given arrays public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive, char[] wordCharacters, boolean[] toggleFlags) { this(keywords, caseSensitive, wordCharacters, toggleFlags, new RangeNodeThreshold()); } // Set where digits and letters and '-' and '_' are considered word characters but modified by the two // given arrays public WholeWordLongestMatchSet(final Iterable<String> keywords, boolean caseSensitive, char[] wordCharacters, boolean[] toggleFlags,
Thresholder thresholdStrategy) {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/AbstractPropertyBuilder.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/Property.java // enum Type { // // /** // * Boolean-valued property type. // */ // BOOLEAN, // // /** // * Integer-valued property type. // */ // INTEGER, // // /** // * Double-valued property type. // */ // DOUBLE, // // /** // * String-valued property type. // */ // STRING // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/Property.java // public interface Property<W extends Enum<W>> extends Serializable { // // /** // * Represents the type of a property. // */ // enum Type { // // /** // * Boolean-valued property type. // */ // BOOLEAN, // // /** // * Integer-valued property type. // */ // INTEGER, // // /** // * Double-valued property type. // */ // DOUBLE, // // /** // * String-valued property type. // */ // STRING // } // // /** // * Returns the type of the display property. // * // * @return the type of the display property // */ // Type getType(); // // /** // * Returns the widget used to display values of the property. // * // * @return the widget used to display values of the property // */ // W getWidget(); // // /** // * Returns the localized human-readable name of the display property for labels // * and error messages. // * // * @param localizationContext the localization context // * @return the localized human-readable name of the display property for labels // * and error messages // */ // String getName(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable description of the display property. // * // * @param localizationContext the localization context // * @return the localized human-readable description of the display property // */ // String getDescription(LocalizationContext localizationContext); // // /** // * Returns whether the display property contains sensitive information. // * // * @return whether the display property contains sensitive information // */ // boolean isSensitive(); // // /** // * Returns whether the display property should be hidden from the user interface. // * // * @return whether the display property should be hidden from the user interface // */ // boolean isHidden(); // }
import static com.cloudera.director.spi.v2.model.Property.Type; import com.cloudera.director.spi.v2.model.Property;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for property builder implementations. */ public abstract class AbstractPropertyBuilder <W extends Enum<W>, P extends Property<W>, B extends AbstractPropertyBuilder<W, P, B>> { /** * The property key. */ private String key; /** * The type of the configuration property. */
// Path: src/main/java/com/cloudera/director/spi/v2/model/Property.java // enum Type { // // /** // * Boolean-valued property type. // */ // BOOLEAN, // // /** // * Integer-valued property type. // */ // INTEGER, // // /** // * Double-valued property type. // */ // DOUBLE, // // /** // * String-valued property type. // */ // STRING // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/Property.java // public interface Property<W extends Enum<W>> extends Serializable { // // /** // * Represents the type of a property. // */ // enum Type { // // /** // * Boolean-valued property type. // */ // BOOLEAN, // // /** // * Integer-valued property type. // */ // INTEGER, // // /** // * Double-valued property type. // */ // DOUBLE, // // /** // * String-valued property type. // */ // STRING // } // // /** // * Returns the type of the display property. // * // * @return the type of the display property // */ // Type getType(); // // /** // * Returns the widget used to display values of the property. // * // * @return the widget used to display values of the property // */ // W getWidget(); // // /** // * Returns the localized human-readable name of the display property for labels // * and error messages. // * // * @param localizationContext the localization context // * @return the localized human-readable name of the display property for labels // * and error messages // */ // String getName(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable description of the display property. // * // * @param localizationContext the localization context // * @return the localized human-readable description of the display property // */ // String getDescription(LocalizationContext localizationContext); // // /** // * Returns whether the display property contains sensitive information. // * // * @return whether the display property contains sensitive information // */ // boolean isSensitive(); // // /** // * Returns whether the display property should be hidden from the user interface. // * // * @return whether the display property should be hidden from the user interface // */ // boolean isHidden(); // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/AbstractPropertyBuilder.java import static com.cloudera.director.spi.v2.model.Property.Type; import com.cloudera.director.spi.v2.model.Property; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for property builder implementations. */ public abstract class AbstractPropertyBuilder <W extends Enum<W>, P extends Property<W>, B extends AbstractPropertyBuilder<W, P, B>> { /** * The property key. */ private String key; /** * The type of the configuration property. */
private Type type;
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/SimpleConfigurationPropertyValue.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyValue.java // public interface ConfigurationPropertyValue { // // /** // * Returns the internal value of the configuration property value. // */ // String getValue(); // // /** // * Returns the human-readable localized label for the configuration property value. // */ // String getLabel(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // }
import com.cloudera.director.spi.v2.model.ConfigurationPropertyValue; import com.cloudera.director.spi.v2.util.Preconditions;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Simple configuration property value implementation. */ public class SimpleConfigurationPropertyValue implements ConfigurationPropertyValue { /** * The internal value of the configuration property value. */ private final String value; /** * The human-readable localized label for the configuration property value. */ private final String label; /** * Creates a configuration property value with the specified parameters. * * @param value the internal value of the configuration property value * @param label the human-readable localized label for the configuration property value */ public SimpleConfigurationPropertyValue(String value, String label) {
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyValue.java // public interface ConfigurationPropertyValue { // // /** // * Returns the internal value of the configuration property value. // */ // String getValue(); // // /** // * Returns the human-readable localized label for the configuration property value. // */ // String getLabel(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleConfigurationPropertyValue.java import com.cloudera.director.spi.v2.model.ConfigurationPropertyValue; import com.cloudera.director.spi.v2.util.Preconditions; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Simple configuration property value implementation. */ public class SimpleConfigurationPropertyValue implements ConfigurationPropertyValue { /** * The internal value of the configuration property value. */ private final String value; /** * The human-readable localized label for the configuration property value. */ private final String label; /** * Creates a configuration property value with the specified parameters. * * @param value the internal value of the configuration property value * @param label the human-readable localized label for the configuration property value */ public SimpleConfigurationPropertyValue(String value, String label) {
this.value = Preconditions.checkNotNull(value, "value is null");
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionConditionAccumulator.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionCondition.java // public static enum Type { // // /** // * Represents an error. // */ // ERROR, // // /** // * Represents a warning. // */ // WARNING // }
import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.ERROR; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.WARNING; import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import java.util.Set;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.exception; /** * Accumulator for plugin exception conditions. */ public class PluginExceptionConditionAccumulator { /** * The conditions contributing to the exception, partitioned by key. The {@code null} key * represents general conditions not tied to a specific key. */ private final Map<String, Collection<PluginExceptionCondition>> conditionsByKey; /** * The condition types observed so far. */
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionCondition.java // public static enum Type { // // /** // * Represents an error. // */ // ERROR, // // /** // * Represents a warning. // */ // WARNING // } // Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionConditionAccumulator.java import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.ERROR; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.WARNING; import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import java.util.Set; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.exception; /** * Accumulator for plugin exception conditions. */ public class PluginExceptionConditionAccumulator { /** * The conditions contributing to the exception, partitioned by key. The {@code null} key * represents general conditions not tied to a specific key. */ private final Map<String, Collection<PluginExceptionCondition>> conditionsByKey; /** * The condition types observed so far. */
private final Set<Type> conditionTypes;
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/provider/InstanceProvider.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/Instance.java // public interface Instance<T extends InstanceTemplate> extends Resource<T> { // // /** // * Returns the private IP address of the instance, which may be <code>null</code> // * (if, for example, the instance has not finished being provisioned). // * // * @return the private IP address of the instance, which may be <code>null</code> // */ // InetAddress getPrivateIpAddress(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceTemplate.java // public class InstanceTemplate extends SimpleResourceTemplate { // // /** // * The list of configuration properties (including inherited properties). // */ // private static final List<ConfigurationProperty> CONFIGURATION_PROPERTIES = // ConfigurationPropertiesUtil.merge( // SimpleResourceTemplate.getConfigurationProperties(), // ConfigurationPropertiesUtil.asConfigurationPropertyList( // InstanceTemplateConfigurationPropertyToken.values()) // ); // // /** // * Returns the list of configuration properties for creating an instance template, // * including inherited properties. // * // * @return the list of configuration properties for creating an instance template, // * including inherited properties // */ // public static List<ConfigurationProperty> getConfigurationProperties() { // return CONFIGURATION_PROPERTIES; // } // // /** // * Instance template configuration property tokens. // */ // // Fully qualifying class name due to compiler bug // public static enum InstanceTemplateConfigurationPropertyToken // implements com.cloudera.director.spi.v2.model.ConfigurationPropertyToken { // // /** // * String to use as prefix for instance names. // */ // INSTANCE_NAME_PREFIX(new SimpleConfigurationPropertyBuilder() // .configKey("instanceNamePrefix") // .name("Instance name prefix") // .defaultValue("director") // .defaultDescription("Prefix used when generating instance names in AWS" // + " (not part of the hostname).") // .build()); // // /** // * The configuration property. // */ // private final ConfigurationProperty configurationProperty; // // /** // * Creates a configuration property token with the specified parameters. // * // * @param configurationProperty the configuration property // */ // private InstanceTemplateConfigurationPropertyToken( // ConfigurationProperty configurationProperty) { // this.configurationProperty = configurationProperty; // } // // @Override // public ConfigurationProperty unwrap() { // return configurationProperty; // } // } // // /** // * The instance name prefix. // */ // private final String instanceNamePrefix; // // /** // * Creates an instance template with the specified parameters. // * // * @param name the name of the template // * @param configuration the source of configuration // * @param tags the map of tags to be applied to resources created from // * the template // * @param providerLocalizationContext the parent provider localization context // */ // public InstanceTemplate(String name, Configured configuration, Map<String, String> tags, // LocalizationContext providerLocalizationContext) { // super(name, configuration, tags, providerLocalizationContext); // LocalizationContext localizationContext = getLocalizationContext(); // this.instanceNamePrefix = // configuration.getConfigurationValue(INSTANCE_NAME_PREFIX, localizationContext); // } // // /** // * Returns the string to use as a prefix for instance names. // * // * @return the string to use as a prefix for instance names // */ // public String getInstanceNamePrefix() { // return instanceNamePrefix; // } // }
import com.cloudera.director.spi.v2.model.Instance; import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceTemplate; import java.util.Collection; import java.util.Map;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.provider; /** * Represents a provider of instances. */ public interface InstanceProvider<I extends Instance<T>, T extends InstanceTemplate> extends ResourceProvider<I, T> { /** * Returns a map from instance identifiers to instance state for the specified instances. * * Preconditions: * 1. if template.isAutomatic is true, then instanceIds are a collection of provider-specific instance Ids * 2. if template.isAutomatic is false, currently the instances are a collection of virtual instance Ids * * @param template the resource template used for create the instances * @param instanceIds the unique identifiers for the instances * @return the map from instance identifiers to instance state for the specified batch of instances */
// Path: src/main/java/com/cloudera/director/spi/v2/model/Instance.java // public interface Instance<T extends InstanceTemplate> extends Resource<T> { // // /** // * Returns the private IP address of the instance, which may be <code>null</code> // * (if, for example, the instance has not finished being provisioned). // * // * @return the private IP address of the instance, which may be <code>null</code> // */ // InetAddress getPrivateIpAddress(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceTemplate.java // public class InstanceTemplate extends SimpleResourceTemplate { // // /** // * The list of configuration properties (including inherited properties). // */ // private static final List<ConfigurationProperty> CONFIGURATION_PROPERTIES = // ConfigurationPropertiesUtil.merge( // SimpleResourceTemplate.getConfigurationProperties(), // ConfigurationPropertiesUtil.asConfigurationPropertyList( // InstanceTemplateConfigurationPropertyToken.values()) // ); // // /** // * Returns the list of configuration properties for creating an instance template, // * including inherited properties. // * // * @return the list of configuration properties for creating an instance template, // * including inherited properties // */ // public static List<ConfigurationProperty> getConfigurationProperties() { // return CONFIGURATION_PROPERTIES; // } // // /** // * Instance template configuration property tokens. // */ // // Fully qualifying class name due to compiler bug // public static enum InstanceTemplateConfigurationPropertyToken // implements com.cloudera.director.spi.v2.model.ConfigurationPropertyToken { // // /** // * String to use as prefix for instance names. // */ // INSTANCE_NAME_PREFIX(new SimpleConfigurationPropertyBuilder() // .configKey("instanceNamePrefix") // .name("Instance name prefix") // .defaultValue("director") // .defaultDescription("Prefix used when generating instance names in AWS" // + " (not part of the hostname).") // .build()); // // /** // * The configuration property. // */ // private final ConfigurationProperty configurationProperty; // // /** // * Creates a configuration property token with the specified parameters. // * // * @param configurationProperty the configuration property // */ // private InstanceTemplateConfigurationPropertyToken( // ConfigurationProperty configurationProperty) { // this.configurationProperty = configurationProperty; // } // // @Override // public ConfigurationProperty unwrap() { // return configurationProperty; // } // } // // /** // * The instance name prefix. // */ // private final String instanceNamePrefix; // // /** // * Creates an instance template with the specified parameters. // * // * @param name the name of the template // * @param configuration the source of configuration // * @param tags the map of tags to be applied to resources created from // * the template // * @param providerLocalizationContext the parent provider localization context // */ // public InstanceTemplate(String name, Configured configuration, Map<String, String> tags, // LocalizationContext providerLocalizationContext) { // super(name, configuration, tags, providerLocalizationContext); // LocalizationContext localizationContext = getLocalizationContext(); // this.instanceNamePrefix = // configuration.getConfigurationValue(INSTANCE_NAME_PREFIX, localizationContext); // } // // /** // * Returns the string to use as a prefix for instance names. // * // * @return the string to use as a prefix for instance names // */ // public String getInstanceNamePrefix() { // return instanceNamePrefix; // } // } // Path: src/main/java/com/cloudera/director/spi/v2/provider/InstanceProvider.java import com.cloudera.director.spi.v2.model.Instance; import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceTemplate; import java.util.Collection; import java.util.Map; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.provider; /** * Represents a provider of instances. */ public interface InstanceProvider<I extends Instance<T>, T extends InstanceTemplate> extends ResourceProvider<I, T> { /** * Returns a map from instance identifiers to instance state for the specified instances. * * Preconditions: * 1. if template.isAutomatic is true, then instanceIds are a collection of provider-specific instance Ids * 2. if template.isAutomatic is false, currently the instances are a collection of virtual instance Ids * * @param template the resource template used for create the instances * @param instanceIds the unique identifiers for the instances * @return the map from instance identifiers to instance state for the specified batch of instances */
Map<String, InstanceState> getInstanceState(T template, Collection<String> instanceIds);
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/model/util/AbstractDisplayPropertyTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // }
import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import org.junit.Test;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Tests {@link public class AbstractDisplayProperty}. */ public class AbstractDisplayPropertyTest { private static class TestDisplayProperty extends AbstractDisplayProperty { private TestDisplayProperty(String displayKey, Type type, String name, Widget widget, String defaultDescription, boolean sensitive, boolean hidden) { super(displayKey, type, name, widget, defaultDescription, sensitive, hidden); } } @Test public void testGeneral() { TestDisplayProperty testDisplayProperty = new TestDisplayProperty(
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // Path: src/test/java/com/cloudera/director/spi/v2/model/util/AbstractDisplayPropertyTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import org.junit.Test; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Tests {@link public class AbstractDisplayProperty}. */ public class AbstractDisplayPropertyTest { private static class TestDisplayProperty extends AbstractDisplayProperty { private TestDisplayProperty(String displayKey, Type type, String name, Widget widget, String defaultDescription, boolean sensitive, boolean hidden) { super(displayKey, type, name, widget, defaultDescription, sensitive, hidden); } } @Test public void testGeneral() { TestDisplayProperty testDisplayProperty = new TestDisplayProperty(
"displayKey", DisplayProperty.Type.STRING, "name",
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/ChildLocalizationContext.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // }
import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.util.Preconditions;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * A localization context with a namespace nested inside a parent localization context. */ public class ChildLocalizationContext extends AbstractLocalizationContext { /** * The parent localization context. */ private final LocalizationContext parentContext; /** * The key component for the child context. */ private final String keyComponent; /** * Creates a child localization context with the specified parameters. * * @param parentContext the parent localization context * @param keyComponent the key component for the child context */ public ChildLocalizationContext(LocalizationContext parentContext, String keyComponent) {
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/ChildLocalizationContext.java import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.util.Preconditions; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * A localization context with a namespace nested inside a parent localization context. */ public class ChildLocalizationContext extends AbstractLocalizationContext { /** * The parent localization context. */ private final LocalizationContext parentContext; /** * The key component for the child context. */ private final String keyComponent; /** * Creates a child localization context with the specified parameters. * * @param parentContext the parent localization context * @param keyComponent the key component for the child context */ public ChildLocalizationContext(LocalizationContext parentContext, String keyComponent) {
super(Preconditions.checkNotNull(parentContext, "parentContext is null").getLocale(),
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/ConfigurationValidator.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionConditionAccumulator.java // public class PluginExceptionConditionAccumulator { // // /** // * The conditions contributing to the exception, partitioned by key. The {@code null} key // * represents general conditions not tied to a specific key. // */ // private final Map<String, Collection<PluginExceptionCondition>> conditionsByKey; // // /** // * The condition types observed so far. // */ // private final Set<Type> conditionTypes; // // /** // * Creates a plugin exception condition accumulator with the specified parameters. // */ // public PluginExceptionConditionAccumulator() { // conditionsByKey = new HashMap<String, Collection<PluginExceptionCondition>>(); // conditionTypes = EnumSet.noneOf(Type.class); // } // // /** // * Returns the conditions contributing to the exception, partitioned by key. The {@code null} key // * represents general conditions not tied to a specific key. // * // * @return the conditions contributing to the exception, partitioned by key. The {@code null} key // * represents general conditions not tied to a specific key. // */ // public Map<String, Collection<PluginExceptionCondition>> getConditionsByKey() { // return conditionsByKey; // } // // /** // * Returns whether the accumulator has at least one error. // * // * @return whether the accumulator has at least one error // */ // public boolean hasError() { // return conditionTypes.contains(ERROR); // } // // /** // * Adds an error condition with only a message to the accumulator. // * // * @param key the key // * @param message the message // */ // public void addError(String key, String message) { // addCondition(key, ERROR, message); // } // // /** // * Adds an error condition with detailed exception information to the accumulator. // * // * @param key the key // * @param exceptionInfo detailed exception information // */ // public void addError(String key, Map<String, String> exceptionInfo) { // addCondition(key, ERROR, exceptionInfo); // } // // /** // * Adds a general error condition (using key of null) with detailed exception // * information to the accumulator. // * // * @param exceptionInfo detailed exception information // */ // public void addError(Map<String, String> exceptionInfo) { // addCondition(null, ERROR, exceptionInfo); // } // // /** // * Returns whether the accumulator has at least one warning. // * // * @return whether the accumulator has at least one warning // */ // public boolean hasWarning() { // return conditionTypes.contains(WARNING); // } // // /** // * Adds a warning condition with only a message to the accumulator. // * // * @param key the key // * @param message the message // */ // public void addWarning(String key, String message) { // addCondition(key, WARNING, message); // } // // /** // * Adds a warning condition with detailed exception information to the accumulator. // * // * @param key the key // * @param exceptionInfo detailed exception information // */ // public void addWarning(String key, Map<String, String> exceptionInfo) { // addCondition(key, WARNING, exceptionInfo); // } // // /** // * Adds a general warning condition (using key of null) with detailed exception // * information to the accumulator. // * // * @param exceptionInfo detailed exception information // */ // public void addWarning(Map<String, String> exceptionInfo) { // addCondition(null, WARNING, exceptionInfo); // } // // private synchronized void addCondition(String key, Type type, String message) { // addCondition(key, type, PluginExceptionCondition.toExceptionInfoMap(message)); // } // // private synchronized void addCondition(String key, Type type, Map<String, String> exceptionInfo) { // Collection<PluginExceptionCondition> keyConditions = conditionsByKey.get(key); // if (keyConditions == null) { // keyConditions = new ArrayList<PluginExceptionCondition>(); // conditionsByKey.put(key, keyConditions); // } // PluginExceptionCondition condition = // new PluginExceptionCondition(type, exceptionInfo); // keyConditions.add(condition); // conditionTypes.add(type); // } // }
import com.cloudera.director.spi.v2.model.exception.PluginExceptionConditionAccumulator;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model; /** * Validates a configuration. */ public interface ConfigurationValidator { /** * Validates the specified configuration using the specified localization context, * accumulating errors and warnings in the specified accumulator. * * @param name the name of the object being validated * @param configuration the configuration to be validated * @param accumulator the exception condition accumulator * @param localizationContext the localization context */ void validate(String name, Configured configuration,
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionConditionAccumulator.java // public class PluginExceptionConditionAccumulator { // // /** // * The conditions contributing to the exception, partitioned by key. The {@code null} key // * represents general conditions not tied to a specific key. // */ // private final Map<String, Collection<PluginExceptionCondition>> conditionsByKey; // // /** // * The condition types observed so far. // */ // private final Set<Type> conditionTypes; // // /** // * Creates a plugin exception condition accumulator with the specified parameters. // */ // public PluginExceptionConditionAccumulator() { // conditionsByKey = new HashMap<String, Collection<PluginExceptionCondition>>(); // conditionTypes = EnumSet.noneOf(Type.class); // } // // /** // * Returns the conditions contributing to the exception, partitioned by key. The {@code null} key // * represents general conditions not tied to a specific key. // * // * @return the conditions contributing to the exception, partitioned by key. The {@code null} key // * represents general conditions not tied to a specific key. // */ // public Map<String, Collection<PluginExceptionCondition>> getConditionsByKey() { // return conditionsByKey; // } // // /** // * Returns whether the accumulator has at least one error. // * // * @return whether the accumulator has at least one error // */ // public boolean hasError() { // return conditionTypes.contains(ERROR); // } // // /** // * Adds an error condition with only a message to the accumulator. // * // * @param key the key // * @param message the message // */ // public void addError(String key, String message) { // addCondition(key, ERROR, message); // } // // /** // * Adds an error condition with detailed exception information to the accumulator. // * // * @param key the key // * @param exceptionInfo detailed exception information // */ // public void addError(String key, Map<String, String> exceptionInfo) { // addCondition(key, ERROR, exceptionInfo); // } // // /** // * Adds a general error condition (using key of null) with detailed exception // * information to the accumulator. // * // * @param exceptionInfo detailed exception information // */ // public void addError(Map<String, String> exceptionInfo) { // addCondition(null, ERROR, exceptionInfo); // } // // /** // * Returns whether the accumulator has at least one warning. // * // * @return whether the accumulator has at least one warning // */ // public boolean hasWarning() { // return conditionTypes.contains(WARNING); // } // // /** // * Adds a warning condition with only a message to the accumulator. // * // * @param key the key // * @param message the message // */ // public void addWarning(String key, String message) { // addCondition(key, WARNING, message); // } // // /** // * Adds a warning condition with detailed exception information to the accumulator. // * // * @param key the key // * @param exceptionInfo detailed exception information // */ // public void addWarning(String key, Map<String, String> exceptionInfo) { // addCondition(key, WARNING, exceptionInfo); // } // // /** // * Adds a general warning condition (using key of null) with detailed exception // * information to the accumulator. // * // * @param exceptionInfo detailed exception information // */ // public void addWarning(Map<String, String> exceptionInfo) { // addCondition(null, WARNING, exceptionInfo); // } // // private synchronized void addCondition(String key, Type type, String message) { // addCondition(key, type, PluginExceptionCondition.toExceptionInfoMap(message)); // } // // private synchronized void addCondition(String key, Type type, Map<String, String> exceptionInfo) { // Collection<PluginExceptionCondition> keyConditions = conditionsByKey.get(key); // if (keyConditions == null) { // keyConditions = new ArrayList<PluginExceptionCondition>(); // conditionsByKey.put(key, keyConditions); // } // PluginExceptionCondition condition = // new PluginExceptionCondition(type, exceptionInfo); // keyConditions.add(condition); // conditionTypes.add(type); // } // } // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationValidator.java import com.cloudera.director.spi.v2.model.exception.PluginExceptionConditionAccumulator; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model; /** * Validates a configuration. */ public interface ConfigurationValidator { /** * Validates the specified configuration using the specified localization context, * accumulating errors and warnings in the specified accumulator. * * @param name the name of the object being validated * @param configuration the configuration to be validated * @param accumulator the exception condition accumulator * @param localizationContext the localization context */ void validate(String name, Configured configuration,
PluginExceptionConditionAccumulator accumulator, LocalizationContext localizationContext);
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionConditionTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionCondition.java // public static enum Type { // // /** // * Represents an error. // */ // ERROR, // // /** // * Represents a warning. // */ // WARNING // }
import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.ERROR; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.WARNING; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import java.util.Map; import org.junit.Test;
package com.cloudera.director.spi.v2.model.exception; /** * Tests {@link PluginExceptionCondition}. */ public class PluginExceptionConditionTest { protected static final String MSG0 = "msg0"; protected static final String MSG1 = "msg1"; protected static final String[] MESSAGES = {MSG0, MSG1}; private PluginExceptionCondition condition; @Test public void testConstructor() {
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionCondition.java // public static enum Type { // // /** // * Represents an error. // */ // ERROR, // // /** // * Represents a warning. // */ // WARNING // } // Path: src/test/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionConditionTest.java import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.ERROR; import static com.cloudera.director.spi.v2.model.exception.PluginExceptionCondition.Type.WARNING; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import java.util.Map; import org.junit.Test; package com.cloudera.director.spi.v2.model.exception; /** * Tests {@link PluginExceptionCondition}. */ public class PluginExceptionConditionTest { protected static final String MSG0 = "msg0"; protected static final String MSG1 = "msg1"; protected static final String[] MESSAGES = {MSG0, MSG1}; private PluginExceptionCondition condition; @Test public void testConstructor() {
for (Type expectedType : Type.values()) {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/AbstractLocalizationContext.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // }
import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.util.Preconditions; import java.util.Locale;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for localication context implementations. */ public abstract class AbstractLocalizationContext implements LocalizationContext { /** * Builds a localization key from the specified key components. Individual components * may not be {@code null}, but may be empty. The may not start or end with a period, * but may have embedded period. The resulting key will be formed by concatenating all * the nonempty components, separated by periods. * * @param keyComponents the key components * @return the derived localization key * @throws NullPointerException if any key component is {@code null} * @throws IllegalArgumentException if any key component starts or ends with a period */ protected static String buildKey(String... keyComponents) { StringBuilder buf = new StringBuilder(); for (String keyComponent : keyComponents) {
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/AbstractLocalizationContext.java import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.util.Preconditions; import java.util.Locale; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for localication context implementations. */ public abstract class AbstractLocalizationContext implements LocalizationContext { /** * Builds a localization key from the specified key components. Individual components * may not be {@code null}, but may be empty. The may not start or end with a period, * but may have embedded period. The resulting key will be formed by concatenating all * the nonempty components, separated by periods. * * @param keyComponents the key components * @return the derived localization key * @throws NullPointerException if any key component is {@code null} * @throws IllegalArgumentException if any key component starts or ends with a period */ protected static String buildKey(String... keyComponents) { StringBuilder buf = new StringBuilder(); for (String keyComponent : keyComponents) {
Preconditions.checkNotNull(keyComponent, "keyComponent is null");
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/AbstractDisplayPropertyBuilder.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // }
import static com.cloudera.director.spi.v2.model.DisplayProperty.Widget; import com.cloudera.director.spi.v2.model.DisplayProperty;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for display property builder implementations. */ public abstract class AbstractDisplayPropertyBuilder <P extends DisplayProperty, B extends AbstractDisplayPropertyBuilder<P, B>>
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/AbstractDisplayPropertyBuilder.java import static com.cloudera.director.spi.v2.model.DisplayProperty.Widget; import com.cloudera.director.spi.v2.model.DisplayProperty; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for display property builder implementations. */ public abstract class AbstractDisplayPropertyBuilder <P extends DisplayProperty, B extends AbstractDisplayPropertyBuilder<P, B>>
extends AbstractPropertyBuilder<Widget, P, B> {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/AbstractProperty.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/Property.java // public interface Property<W extends Enum<W>> extends Serializable { // // /** // * Represents the type of a property. // */ // enum Type { // // /** // * Boolean-valued property type. // */ // BOOLEAN, // // /** // * Integer-valued property type. // */ // INTEGER, // // /** // * Double-valued property type. // */ // DOUBLE, // // /** // * String-valued property type. // */ // STRING // } // // /** // * Returns the type of the display property. // * // * @return the type of the display property // */ // Type getType(); // // /** // * Returns the widget used to display values of the property. // * // * @return the widget used to display values of the property // */ // W getWidget(); // // /** // * Returns the localized human-readable name of the display property for labels // * and error messages. // * // * @param localizationContext the localization context // * @return the localized human-readable name of the display property for labels // * and error messages // */ // String getName(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable description of the display property. // * // * @param localizationContext the localization context // * @return the localized human-readable description of the display property // */ // String getDescription(LocalizationContext localizationContext); // // /** // * Returns whether the display property contains sensitive information. // * // * @return whether the display property contains sensitive information // */ // boolean isSensitive(); // // /** // * Returns whether the display property should be hidden from the user interface. // * // * @return whether the display property should be hidden from the user interface // */ // boolean isHidden(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // }
import static com.cloudera.director.spi.v2.model.CommonLocalizableAttribute.DESCRIPTION; import static com.cloudera.director.spi.v2.model.CommonLocalizableAttribute.NAME; import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.model.Property; import com.cloudera.director.spi.v2.util.Preconditions;
return name; } @Override public W getWidget() { return widget; } /** * Returns the default human-readable description of the display property, used when a * localized description cannot be found. * * @return the default human-readable description of the display property, used when a * localized description cannot be found */ public String getDefaultDescription() { return defaultDescription; } @Override public boolean isSensitive() { return sensitive; } @Override public boolean isHidden() { return hidden; } @Override
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/Property.java // public interface Property<W extends Enum<W>> extends Serializable { // // /** // * Represents the type of a property. // */ // enum Type { // // /** // * Boolean-valued property type. // */ // BOOLEAN, // // /** // * Integer-valued property type. // */ // INTEGER, // // /** // * Double-valued property type. // */ // DOUBLE, // // /** // * String-valued property type. // */ // STRING // } // // /** // * Returns the type of the display property. // * // * @return the type of the display property // */ // Type getType(); // // /** // * Returns the widget used to display values of the property. // * // * @return the widget used to display values of the property // */ // W getWidget(); // // /** // * Returns the localized human-readable name of the display property for labels // * and error messages. // * // * @param localizationContext the localization context // * @return the localized human-readable name of the display property for labels // * and error messages // */ // String getName(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable description of the display property. // * // * @param localizationContext the localization context // * @return the localized human-readable description of the display property // */ // String getDescription(LocalizationContext localizationContext); // // /** // * Returns whether the display property contains sensitive information. // * // * @return whether the display property contains sensitive information // */ // boolean isSensitive(); // // /** // * Returns whether the display property should be hidden from the user interface. // * // * @return whether the display property should be hidden from the user interface // */ // boolean isHidden(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public final class Preconditions { // // /** // * Private constructor to prevent instantiation. // */ // private Preconditions() { // } // // /** // * Ensures that an object reference passed as a parameter to the calling // * method is not null. // * // * @param instance an object // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @return the non-null reference that was validated // * @throws NullPointerException if {@code reference} is null // */ // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // /** // * Ensures the truth of an expression involving one or more parameters to the // * calling method. // * // * @param expression a boolean expression // * @param message the exception message to use if the check fails; will // * be converted to a string using {@link String#valueOf(Object)} // * @throws IllegalArgumentException if {@code expression} is false // */ // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/AbstractProperty.java import static com.cloudera.director.spi.v2.model.CommonLocalizableAttribute.DESCRIPTION; import static com.cloudera.director.spi.v2.model.CommonLocalizableAttribute.NAME; import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.model.Property; import com.cloudera.director.spi.v2.util.Preconditions; return name; } @Override public W getWidget() { return widget; } /** * Returns the default human-readable description of the display property, used when a * localized description cannot be found. * * @return the default human-readable description of the display property, used when a * localized description cannot be found */ public String getDefaultDescription() { return defaultDescription; } @Override public boolean isSensitive() { return sensitive; } @Override public boolean isHidden() { return hidden; } @Override
public String getName(LocalizationContext localizationContext) {
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtilTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleDisplayPropertyBuilder.java // public class SimpleDisplayPropertyBuilder extends AbstractDisplayPropertyBuilder // <SimpleDisplayProperty, SimpleDisplayPropertyBuilder> { // // @Override // public SimpleDisplayPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleDisplayProperty build() { // return new SimpleDisplayProperty(getDisplayKey(), getType(), getName(), getWidget(), // getDefaultDescription(), isSensitive(), isHidden()); // } // }
import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleDisplayPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class DisplayPropertiesUtilTest { @Test public void testAsDisplayPropertyList() {
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleDisplayPropertyBuilder.java // public class SimpleDisplayPropertyBuilder extends AbstractDisplayPropertyBuilder // <SimpleDisplayProperty, SimpleDisplayPropertyBuilder> { // // @Override // public SimpleDisplayPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleDisplayProperty build() { // return new SimpleDisplayProperty(getDisplayKey(), getType(), getName(), getWidget(), // getDefaultDescription(), isSensitive(), isHidden()); // } // } // Path: src/test/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtilTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleDisplayPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class DisplayPropertiesUtilTest { @Test public void testAsDisplayPropertyList() {
final DisplayProperty display1 = makeDisplayProperty("displayKey1", "displayDesc1");
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtilTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleDisplayPropertyBuilder.java // public class SimpleDisplayPropertyBuilder extends AbstractDisplayPropertyBuilder // <SimpleDisplayProperty, SimpleDisplayPropertyBuilder> { // // @Override // public SimpleDisplayPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleDisplayProperty build() { // return new SimpleDisplayProperty(getDisplayKey(), getType(), getName(), getWidget(), // getDefaultDescription(), isSensitive(), isHidden()); // } // }
import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleDisplayPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class DisplayPropertiesUtilTest { @Test public void testAsDisplayPropertyList() { final DisplayProperty display1 = makeDisplayProperty("displayKey1", "displayDesc1"); final DisplayProperty display2 = makeDisplayProperty("displayKey2", "displayDesc2"); List<DisplayProperty> displayProperties = Arrays.asList(display1, display2);
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleDisplayPropertyBuilder.java // public class SimpleDisplayPropertyBuilder extends AbstractDisplayPropertyBuilder // <SimpleDisplayProperty, SimpleDisplayPropertyBuilder> { // // @Override // public SimpleDisplayPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleDisplayProperty build() { // return new SimpleDisplayProperty(getDisplayKey(), getType(), getName(), getWidget(), // getDefaultDescription(), isSensitive(), isHidden()); // } // } // Path: src/test/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtilTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleDisplayPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class DisplayPropertiesUtilTest { @Test public void testAsDisplayPropertyList() { final DisplayProperty display1 = makeDisplayProperty("displayKey1", "displayDesc1"); final DisplayProperty display2 = makeDisplayProperty("displayKey2", "displayDesc2"); List<DisplayProperty> displayProperties = Arrays.asList(display1, display2);
List<DisplayPropertyToken> displayPropertyTokens = Arrays.asList(
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtilTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleDisplayPropertyBuilder.java // public class SimpleDisplayPropertyBuilder extends AbstractDisplayPropertyBuilder // <SimpleDisplayProperty, SimpleDisplayPropertyBuilder> { // // @Override // public SimpleDisplayPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleDisplayProperty build() { // return new SimpleDisplayProperty(getDisplayKey(), getType(), getName(), getWidget(), // getDefaultDescription(), isSensitive(), isHidden()); // } // }
import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleDisplayPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test;
public void testMerge() { DisplayProperty display1 = makeDisplayProperty("displayKey1", "displayDesc1"); DisplayProperty display2 = makeDisplayProperty("displayKey2", "displayDesc2"); DisplayProperty display3 = makeDisplayProperty("displayKey3", "displayDesc3"); DisplayProperty display4 = makeDisplayProperty("displayKey4", "displayDesc4"); DisplayProperty display5 = makeDisplayProperty("displayKey5", "displayDesc5"); DisplayProperty display6 = makeDisplayProperty("displayKey6", "displayDesc6"); assertThat( DisplayPropertiesUtil.merge(Lists.newArrayList(display1, display2, display3), Lists.newArrayList(display4, display5, display6))) .containsOnly(display1, display2, display3, display4, display5, display6); } @Test public void testMergeReplace() { DisplayProperty display1 = makeDisplayProperty("displayKey1", "displayDesc1"); DisplayProperty display2 = makeDisplayProperty("displayKey2", "displayDesc2"); DisplayProperty display3 = makeDisplayProperty("displayKey3", "displayDesc3"); DisplayProperty display1b = makeDisplayProperty("displayKey1", "displayDesc3"); assertThat( DisplayPropertiesUtil.merge(Lists.newArrayList(display1, display2), Lists.newArrayList(display1b, display3))) .containsOnly(display1b, display2, display3); } private DisplayProperty makeDisplayProperty(String displayKey, String description) {
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleDisplayPropertyBuilder.java // public class SimpleDisplayPropertyBuilder extends AbstractDisplayPropertyBuilder // <SimpleDisplayProperty, SimpleDisplayPropertyBuilder> { // // @Override // public SimpleDisplayPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleDisplayProperty build() { // return new SimpleDisplayProperty(getDisplayKey(), getType(), getName(), getWidget(), // getDefaultDescription(), isSensitive(), isHidden()); // } // } // Path: src/test/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtilTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleDisplayPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test; public void testMerge() { DisplayProperty display1 = makeDisplayProperty("displayKey1", "displayDesc1"); DisplayProperty display2 = makeDisplayProperty("displayKey2", "displayDesc2"); DisplayProperty display3 = makeDisplayProperty("displayKey3", "displayDesc3"); DisplayProperty display4 = makeDisplayProperty("displayKey4", "displayDesc4"); DisplayProperty display5 = makeDisplayProperty("displayKey5", "displayDesc5"); DisplayProperty display6 = makeDisplayProperty("displayKey6", "displayDesc6"); assertThat( DisplayPropertiesUtil.merge(Lists.newArrayList(display1, display2, display3), Lists.newArrayList(display4, display5, display6))) .containsOnly(display1, display2, display3, display4, display5, display6); } @Test public void testMergeReplace() { DisplayProperty display1 = makeDisplayProperty("displayKey1", "displayDesc1"); DisplayProperty display2 = makeDisplayProperty("displayKey2", "displayDesc2"); DisplayProperty display3 = makeDisplayProperty("displayKey3", "displayDesc3"); DisplayProperty display1b = makeDisplayProperty("displayKey1", "displayDesc3"); assertThat( DisplayPropertiesUtil.merge(Lists.newArrayList(display1, display2), Lists.newArrayList(display1b, display3))) .containsOnly(display1b, display2, display3); } private DisplayProperty makeDisplayProperty(String displayKey, String description) {
return new SimpleDisplayPropertyBuilder()
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtil.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // }
import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating display properties. */ public final class DisplayPropertiesUtil { /** * Private constructor to prevent instantiation. */ private DisplayPropertiesUtil() { } /** * Returns an unmodifiable list containing the display properties identified by the * specified tokens. * * @param tokens the display property tokens * @param <T> the type of display property token * @return an unmodifiable list containing the specified display properties */
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // Path: src/main/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtil.java import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating display properties. */ public final class DisplayPropertiesUtil { /** * Private constructor to prevent instantiation. */ private DisplayPropertiesUtil() { } /** * Returns an unmodifiable list containing the display properties identified by the * specified tokens. * * @param tokens the display property tokens * @param <T> the type of display property token * @return an unmodifiable list containing the specified display properties */
public static <T extends DisplayPropertyToken>
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtil.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // }
import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating display properties. */ public final class DisplayPropertiesUtil { /** * Private constructor to prevent instantiation. */ private DisplayPropertiesUtil() { } /** * Returns an unmodifiable list containing the display properties identified by the * specified tokens. * * @param tokens the display property tokens * @param <T> the type of display property token * @return an unmodifiable list containing the specified display properties */ public static <T extends DisplayPropertyToken>
// Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayProperty.java // public interface DisplayProperty extends Property<DisplayProperty.Widget> { // // /** // * Represents the widget used to display a property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File download widget. // */ // FILE, // // /** // * Multiple display widget for a fixed set of values. // */ // MULTI // } // // /** // * Returns the display key. // * // * @return the display key // */ // String getDisplayKey(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/DisplayPropertyToken.java // public interface DisplayPropertyToken { // // /** // * Returns the display property. // * // * @return the display property // */ // DisplayProperty unwrap(); // } // Path: src/main/java/com/cloudera/director/spi/v2/util/DisplayPropertiesUtil.java import com.cloudera.director.spi.v2.model.DisplayProperty; import com.cloudera.director.spi.v2.model.DisplayPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating display properties. */ public final class DisplayPropertiesUtil { /** * Private constructor to prevent instantiation. */ private DisplayPropertiesUtil() { } /** * Returns an unmodifiable list containing the display properties identified by the * specified tokens. * * @param tokens the display property tokens * @param <T> the type of display property token * @return an unmodifiable list containing the specified display properties */ public static <T extends DisplayPropertyToken>
List<DisplayProperty> asDisplayPropertyList(T[] tokens) {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionDetails.java
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // }
import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.exception; /** * Provides additional exception details to enable better UI feedback when * exceptions occur. */ public class PluginExceptionDetails implements Serializable { private static final long serialVersionUID = 1L; /** * The default empty map of conditions by key. */ public static final Map<String, ? extends Collection<PluginExceptionCondition>> DEFAULT_CONDITIONS_BY_KEY = Collections.emptyMap(); /** * Default plugin exception details. */ public static final PluginExceptionDetails DEFAULT_DETAILS = new PluginExceptionDetails( DEFAULT_CONDITIONS_BY_KEY ); /** * Builds an unmodifiable map from keys to sorted sets of conditions, based on the specified * map from keys to collections of conditions. * * @param conditionsByKey the conditions contributing to the exception, partitioned by key. * The {@code null} key represents general conditions not tied to a * specific key. * @return the unmodifiable map from keys to sorted sets of conditions, based on the specified * map from keys to collections of conditions */ private static Map<String, SortedSet<PluginExceptionCondition>> buildConditionsByKey( Map<String, ? extends Collection<PluginExceptionCondition>> conditionsByKey ) {
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionDetails.java import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.exception; /** * Provides additional exception details to enable better UI feedback when * exceptions occur. */ public class PluginExceptionDetails implements Serializable { private static final long serialVersionUID = 1L; /** * The default empty map of conditions by key. */ public static final Map<String, ? extends Collection<PluginExceptionCondition>> DEFAULT_CONDITIONS_BY_KEY = Collections.emptyMap(); /** * Default plugin exception details. */ public static final PluginExceptionDetails DEFAULT_DETAILS = new PluginExceptionDetails( DEFAULT_CONDITIONS_BY_KEY ); /** * Builds an unmodifiable map from keys to sorted sets of conditions, based on the specified * map from keys to collections of conditions. * * @param conditionsByKey the conditions contributing to the exception, partitioned by key. * The {@code null} key represents general conditions not tied to a * specific key. * @return the unmodifiable map from keys to sorted sets of conditions, based on the specified * map from keys to collections of conditions */ private static Map<String, SortedSet<PluginExceptionCondition>> buildConditionsByKey( Map<String, ? extends Collection<PluginExceptionCondition>> conditionsByKey ) {
checkNotNull(conditionsByKey, "conditionsByKey is null");
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/provider/CredentialsProvider.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/Configured.java // public interface Configured { // // /** // * Returns the unmodifiable map of configuration parameter values. // * // * @param localizationContext the localization context // * @return the unmodifiable map of configuration parameter values // */ // Map<String, String> getConfiguration(LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param token the configuration property token // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationPropertyToken token, // LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param property the configuration property // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationProperty property, // LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // }
import com.cloudera.director.spi.v2.model.Configured; import com.cloudera.director.spi.v2.model.LocalizationContext;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.provider; /** * Represents a provider of cloud credentials. * * @param <T> the type of credentials provided */ public interface CredentialsProvider<T> { /** * Returns the credentials provider metadata. * * @return the credentials provider metadata */ CredentialsProviderMetadata getMetadata(); /** * Creates credentials based on the specified configuration. * * @param configuration the configuration * @param localizationContext the localization context * @return the credentials */
// Path: src/main/java/com/cloudera/director/spi/v2/model/Configured.java // public interface Configured { // // /** // * Returns the unmodifiable map of configuration parameter values. // * // * @param localizationContext the localization context // * @return the unmodifiable map of configuration parameter values // */ // Map<String, String> getConfiguration(LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param token the configuration property token // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationPropertyToken token, // LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param property the configuration property // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationProperty property, // LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // Path: src/main/java/com/cloudera/director/spi/v2/provider/CredentialsProvider.java import com.cloudera.director.spi.v2.model.Configured; import com.cloudera.director.spi.v2.model.LocalizationContext; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.provider; /** * Represents a provider of cloud credentials. * * @param <T> the type of credentials provided */ public interface CredentialsProvider<T> { /** * Returns the credentials provider metadata. * * @return the credentials provider metadata */ CredentialsProviderMetadata getMetadata(); /** * Creates credentials based on the specified configuration. * * @param configuration the configuration * @param localizationContext the localization context * @return the credentials */
T createCredentials(Configured configuration, LocalizationContext localizationContext);
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/provider/CredentialsProvider.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/Configured.java // public interface Configured { // // /** // * Returns the unmodifiable map of configuration parameter values. // * // * @param localizationContext the localization context // * @return the unmodifiable map of configuration parameter values // */ // Map<String, String> getConfiguration(LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param token the configuration property token // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationPropertyToken token, // LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param property the configuration property // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationProperty property, // LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // }
import com.cloudera.director.spi.v2.model.Configured; import com.cloudera.director.spi.v2.model.LocalizationContext;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.provider; /** * Represents a provider of cloud credentials. * * @param <T> the type of credentials provided */ public interface CredentialsProvider<T> { /** * Returns the credentials provider metadata. * * @return the credentials provider metadata */ CredentialsProviderMetadata getMetadata(); /** * Creates credentials based on the specified configuration. * * @param configuration the configuration * @param localizationContext the localization context * @return the credentials */
// Path: src/main/java/com/cloudera/director/spi/v2/model/Configured.java // public interface Configured { // // /** // * Returns the unmodifiable map of configuration parameter values. // * // * @param localizationContext the localization context // * @return the unmodifiable map of configuration parameter values // */ // Map<String, String> getConfiguration(LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param token the configuration property token // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationPropertyToken token, // LocalizationContext localizationContext); // // /** // * Returns the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional. // * // * @param property the configuration property // * @param localizationContext the localization context // * @return the value of the specified configuration property, or the default value if the value // * is not present and the configuration property is optional // * @throws IllegalArgumentException if the specified configuration property is not present and // * required // */ // String getConfigurationValue(ConfigurationProperty property, // LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // Path: src/main/java/com/cloudera/director/spi/v2/provider/CredentialsProvider.java import com.cloudera.director.spi.v2.model.Configured; import com.cloudera.director.spi.v2.model.LocalizationContext; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.provider; /** * Represents a provider of cloud credentials. * * @param <T> the type of credentials provided */ public interface CredentialsProvider<T> { /** * Returns the credentials provider metadata. * * @return the credentials provider metadata */ CredentialsProviderMetadata getMetadata(); /** * Creates credentials based on the specified configuration. * * @param configuration the configuration * @param localizationContext the localization context * @return the credentials */
T createCredentials(Configured configuration, LocalizationContext localizationContext);
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtil.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // }
import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating configuration properties. */ public final class ConfigurationPropertiesUtil { /** * Private constructor to prevent instantiation. */ private ConfigurationPropertiesUtil() { } /** * Returns an unmodifiable list containing the configuration properties identified by the * specified tokens. * * @param tokens the configuration property tokens * @param <T> the type of configuration property token * @return an unmodifiable list containing the specified configuration properties */
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // } // Path: src/main/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtil.java import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating configuration properties. */ public final class ConfigurationPropertiesUtil { /** * Private constructor to prevent instantiation. */ private ConfigurationPropertiesUtil() { } /** * Returns an unmodifiable list containing the configuration properties identified by the * specified tokens. * * @param tokens the configuration property tokens * @param <T> the type of configuration property token * @return an unmodifiable list containing the specified configuration properties */
public static <T extends ConfigurationPropertyToken>
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtil.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // }
import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating configuration properties. */ public final class ConfigurationPropertiesUtil { /** * Private constructor to prevent instantiation. */ private ConfigurationPropertiesUtil() { } /** * Returns an unmodifiable list containing the configuration properties identified by the * specified tokens. * * @param tokens the configuration property tokens * @param <T> the type of configuration property token * @return an unmodifiable list containing the specified configuration properties */ public static <T extends ConfigurationPropertyToken>
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // } // Path: src/main/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtil.java import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; /** * Provides utility methods for manipulating configuration properties. */ public final class ConfigurationPropertiesUtil { /** * Private constructor to prevent instantiation. */ private ConfigurationPropertiesUtil() { } /** * Returns an unmodifiable list containing the configuration properties identified by the * specified tokens. * * @param tokens the configuration property tokens * @param <T> the type of configuration property token * @return an unmodifiable list containing the specified configuration properties */ public static <T extends ConfigurationPropertyToken>
List<ConfigurationProperty> asConfigurationPropertyList(T[] tokens) {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/AbstractResource.java
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/Resource.java // public interface Resource<T extends ResourceTemplate> { // // /** // * Represents a type of cloud resource. // */ // interface Type { // // /** // * Returns a localized human-readable description of the resource type. // * // * @param localizationContext the localization context // * @return a loczlized human-readable description of the resource type // */ // String getDescription(LocalizationContext localizationContext); // } // // /** // * Returns the type of the resource. // * // * @return the type of the resource // */ // Type getType(); // // /** // * Returns the template from which the resource was created. // * // * @return the template from which the resource was created // */ // T getTemplate(); // // /** // * Returns an external identifier which uniquely identifies the resource within its type and scope. // * // * @return the identifier // */ // String getId(); // // /** // * Returns a localized human-readable description of the resource. // * // * @param localizationContext the localization context // * @return a localized human-readable description of the resource // */ // String getDescription(LocalizationContext localizationContext); // // /** // * Returns a map representing the properties of the resource. // * // * @return a map representing the properties of the resource // */ // Map<String, String> getProperties(); // // /** // * <p>Returns the provider specific underlying implementation of this resource.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ResourceTemplate.java // public interface ResourceTemplate extends Configured { // // /** // * Returns the name of the template. // * // * @return the name of the template // */ // String getName(); // // /** // * Returns the unique ID of the group containing instances created from this template. // * // * @return the unique ID of the group containing instances created from this template // */ // String getGroupId(); // // /** // * Returns the map of tags to be applied to resources created from the template. // * // * @return the map of tags to be applied to resources created from the template // */ // Map<String, String> getTags(); // // /** // * <p>Return the underlying cloud provider specific implementation or null</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // }
import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.model.Resource; import com.cloudera.director.spi.v2.model.ResourceTemplate;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for resource implementations. * * @param <T> the type of resource template from which resources are constructed * @param <D> the type of resource details */ public abstract class AbstractResource<T extends ResourceTemplate, D> implements Resource<T> { /** * The resource type representing a generic resource. */ public static final Type TYPE = new ResourceType("Resource"); /** * Resource type. */ protected static class ResourceType implements Type { /** * The description of the resource type. */ private final String description; public ResourceType(String description) { if (description == null) { throw new NullPointerException("description is null"); } this.description = description; } @Override // NOTE: This implementation does not do any actual localization, and simply returns the fixed description. // Plugin implementers may override to perform localization.
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/Resource.java // public interface Resource<T extends ResourceTemplate> { // // /** // * Represents a type of cloud resource. // */ // interface Type { // // /** // * Returns a localized human-readable description of the resource type. // * // * @param localizationContext the localization context // * @return a loczlized human-readable description of the resource type // */ // String getDescription(LocalizationContext localizationContext); // } // // /** // * Returns the type of the resource. // * // * @return the type of the resource // */ // Type getType(); // // /** // * Returns the template from which the resource was created. // * // * @return the template from which the resource was created // */ // T getTemplate(); // // /** // * Returns an external identifier which uniquely identifies the resource within its type and scope. // * // * @return the identifier // */ // String getId(); // // /** // * Returns a localized human-readable description of the resource. // * // * @param localizationContext the localization context // * @return a localized human-readable description of the resource // */ // String getDescription(LocalizationContext localizationContext); // // /** // * Returns a map representing the properties of the resource. // * // * @return a map representing the properties of the resource // */ // Map<String, String> getProperties(); // // /** // * <p>Returns the provider specific underlying implementation of this resource.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ResourceTemplate.java // public interface ResourceTemplate extends Configured { // // /** // * Returns the name of the template. // * // * @return the name of the template // */ // String getName(); // // /** // * Returns the unique ID of the group containing instances created from this template. // * // * @return the unique ID of the group containing instances created from this template // */ // String getGroupId(); // // /** // * Returns the map of tags to be applied to resources created from the template. // * // * @return the map of tags to be applied to resources created from the template // */ // Map<String, String> getTags(); // // /** // * <p>Return the underlying cloud provider specific implementation or null</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/AbstractResource.java import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import com.cloudera.director.spi.v2.model.LocalizationContext; import com.cloudera.director.spi.v2.model.Resource; import com.cloudera.director.spi.v2.model.ResourceTemplate; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for resource implementations. * * @param <T> the type of resource template from which resources are constructed * @param <D> the type of resource details */ public abstract class AbstractResource<T extends ResourceTemplate, D> implements Resource<T> { /** * The resource type representing a generic resource. */ public static final Type TYPE = new ResourceType("Resource"); /** * Resource type. */ protected static class ResourceType implements Type { /** * The description of the resource type. */ private final String description; public ResourceType(String description) { if (description == null) { throw new NullPointerException("description is null"); } this.description = description; } @Override // NOTE: This implementation does not do any actual localization, and simply returns the fixed description. // Plugin implementers may override to perform localization.
public String getDescription(LocalizationContext localizationContext) {
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/model/exception/AbstractPluginExceptionTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionDetails.java // public static final PluginExceptionDetails DEFAULT_DETAILS = new PluginExceptionDetails( // DEFAULT_CONDITIONS_BY_KEY // );
import static com.cloudera.director.spi.v2.model.exception.PluginExceptionDetails.DEFAULT_DETAILS; import static org.assertj.core.api.Assertions.assertThat; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.junit.Test;
* The constructor parameter types. */ private final Class[] parameterTypes; /** * Creates an arg variant with the specified parameters. * * @param parameterTypes the constructor parameter types */ private ConstructorVariant(Class[] parameterTypes) { this.parameterTypes = parameterTypes; } /** * Returns the constructor parameter types. * * @return the constructor parameter types */ public Class[] getParameterTypes() { return parameterTypes; } public abstract Object[] getParameterValues(String message, Throwable cause, PluginExceptionDetails details); } @Test public void testConstructors() throws Exception { for (ConstructorVariant constructorVariant : ConstructorVariant.values()) { try {
// Path: src/main/java/com/cloudera/director/spi/v2/model/exception/PluginExceptionDetails.java // public static final PluginExceptionDetails DEFAULT_DETAILS = new PluginExceptionDetails( // DEFAULT_CONDITIONS_BY_KEY // ); // Path: src/test/java/com/cloudera/director/spi/v2/model/exception/AbstractPluginExceptionTest.java import static com.cloudera.director.spi.v2.model.exception.PluginExceptionDetails.DEFAULT_DETAILS; import static org.assertj.core.api.Assertions.assertThat; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.junit.Test; * The constructor parameter types. */ private final Class[] parameterTypes; /** * Creates an arg variant with the specified parameters. * * @param parameterTypes the constructor parameter types */ private ConstructorVariant(Class[] parameterTypes) { this.parameterTypes = parameterTypes; } /** * Returns the constructor parameter types. * * @return the constructor parameter types */ public Class[] getParameterTypes() { return parameterTypes; } public abstract Object[] getParameterValues(String message, Throwable cause, PluginExceptionDetails details); } @Test public void testConstructors() throws Exception { for (ConstructorVariant constructorVariant : ConstructorVariant.values()) { try {
throwException(TEST_MESSAGE, TEST_THROWABLE, DEFAULT_DETAILS, constructorVariant);
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/database/DatabaseServerProvider.java
// Path: src/main/java/com/cloudera/director/spi/v2/provider/InstanceProvider.java // public interface InstanceProvider<I extends Instance<T>, T extends InstanceTemplate> // extends ResourceProvider<I, T> { // // /** // * Returns a map from instance identifiers to instance state for the specified instances. // * // * Preconditions: // * 1. if template.isAutomatic is true, then instanceIds are a collection of provider-specific instance Ids // * 2. if template.isAutomatic is false, currently the instances are a collection of virtual instance Ids // * // * @param template the resource template used for create the instances // * @param instanceIds the unique identifiers for the instances // * @return the map from instance identifiers to instance state for the specified batch of instances // */ // Map<String, InstanceState> getInstanceState(T template, Collection<String> instanceIds); // // }
import com.cloudera.director.spi.v2.provider.InstanceProvider;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.database; /** * Represents a provider of database server instances. */ public interface DatabaseServerProvider <R extends DatabaseServerInstance<T>, T extends DatabaseServerInstanceTemplate>
// Path: src/main/java/com/cloudera/director/spi/v2/provider/InstanceProvider.java // public interface InstanceProvider<I extends Instance<T>, T extends InstanceTemplate> // extends ResourceProvider<I, T> { // // /** // * Returns a map from instance identifiers to instance state for the specified instances. // * // * Preconditions: // * 1. if template.isAutomatic is true, then instanceIds are a collection of provider-specific instance Ids // * 2. if template.isAutomatic is false, currently the instances are a collection of virtual instance Ids // * // * @param template the resource template used for create the instances // * @param instanceIds the unique identifiers for the instances // * @return the map from instance identifiers to instance state for the specified batch of instances // */ // Map<String, InstanceState> getInstanceState(T template, Collection<String> instanceIds); // // } // Path: src/main/java/com/cloudera/director/spi/v2/database/DatabaseServerProvider.java import com.cloudera.director.spi.v2.provider.InstanceProvider; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.database; /** * Represents a provider of database server instances. */ public interface DatabaseServerProvider <R extends DatabaseServerInstance<T>, T extends DatabaseServerInstanceTemplate>
extends InstanceProvider<R, T> {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/SimpleInstanceState.java
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceStatus.java // public enum InstanceStatus { // // /** // * The instance has been requested (initially or after being stopped), but is not yet known to be available. // */ // PENDING, // // /** // * The instance is running, although it may not be accessible. // */ // RUNNING, // // /** // * The instance is stopping, and may be restarted later. // */ // STOPPING, // // /** // * The instance is stopped, and may be restarted. // */ // STOPPED, // // /** // * The instance is being removed permanently. // */ // DELETING, // // /** // * The instance has been removed permanently. // */ // DELETED, // // /** // * The instance has failed, and cannot be reused. // */ // FAILED, // // /** // * The instance state cannot be determined. // */ // UNKNOWN // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // }
import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceStatus; import com.cloudera.director.spi.v2.model.LocalizationContext;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * A simple wrapper around {@code InstanceStatus} for instance state. */ public class SimpleInstanceState implements InstanceState { /** * The instance status. */ private final InstanceStatus instanceStatus; /** * Creates an abstract instance state with the specified parameters. * * @param instanceStatus the instance status */ public SimpleInstanceState(InstanceStatus instanceStatus) {
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceStatus.java // public enum InstanceStatus { // // /** // * The instance has been requested (initially or after being stopped), but is not yet known to be available. // */ // PENDING, // // /** // * The instance is running, although it may not be accessible. // */ // RUNNING, // // /** // * The instance is stopping, and may be restarted later. // */ // STOPPING, // // /** // * The instance is stopped, and may be restarted. // */ // STOPPED, // // /** // * The instance is being removed permanently. // */ // DELETING, // // /** // * The instance has been removed permanently. // */ // DELETED, // // /** // * The instance has failed, and cannot be reused. // */ // FAILED, // // /** // * The instance state cannot be determined. // */ // UNKNOWN // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleInstanceState.java import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceStatus; import com.cloudera.director.spi.v2.model.LocalizationContext; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * A simple wrapper around {@code InstanceStatus} for instance state. */ public class SimpleInstanceState implements InstanceState { /** * The instance status. */ private final InstanceStatus instanceStatus; /** * Creates an abstract instance state with the specified parameters. * * @param instanceStatus the instance status */ public SimpleInstanceState(InstanceStatus instanceStatus) {
this.instanceStatus = checkNotNull(instanceStatus, "instanceStatus is null");
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/SimpleInstanceState.java
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceStatus.java // public enum InstanceStatus { // // /** // * The instance has been requested (initially or after being stopped), but is not yet known to be available. // */ // PENDING, // // /** // * The instance is running, although it may not be accessible. // */ // RUNNING, // // /** // * The instance is stopping, and may be restarted later. // */ // STOPPING, // // /** // * The instance is stopped, and may be restarted. // */ // STOPPED, // // /** // * The instance is being removed permanently. // */ // DELETING, // // /** // * The instance has been removed permanently. // */ // DELETED, // // /** // * The instance has failed, and cannot be reused. // */ // FAILED, // // /** // * The instance state cannot be determined. // */ // UNKNOWN // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // }
import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceStatus; import com.cloudera.director.spi.v2.model.LocalizationContext;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * A simple wrapper around {@code InstanceStatus} for instance state. */ public class SimpleInstanceState implements InstanceState { /** * The instance status. */ private final InstanceStatus instanceStatus; /** * Creates an abstract instance state with the specified parameters. * * @param instanceStatus the instance status */ public SimpleInstanceState(InstanceStatus instanceStatus) { this.instanceStatus = checkNotNull(instanceStatus, "instanceStatus is null"); } @Override public InstanceStatus getInstanceStatus() { return instanceStatus; } @Override // NOTE: This implementation does not do any actual localization, and simply calls toString() // on the instance status details. Plugin implementers may override to perform localization.
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceStatus.java // public enum InstanceStatus { // // /** // * The instance has been requested (initially or after being stopped), but is not yet known to be available. // */ // PENDING, // // /** // * The instance is running, although it may not be accessible. // */ // RUNNING, // // /** // * The instance is stopping, and may be restarted later. // */ // STOPPING, // // /** // * The instance is stopped, and may be restarted. // */ // STOPPED, // // /** // * The instance is being removed permanently. // */ // DELETING, // // /** // * The instance has been removed permanently. // */ // DELETED, // // /** // * The instance has failed, and cannot be reused. // */ // FAILED, // // /** // * The instance state cannot be determined. // */ // UNKNOWN // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleInstanceState.java import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceStatus; import com.cloudera.director.spi.v2.model.LocalizationContext; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * A simple wrapper around {@code InstanceStatus} for instance state. */ public class SimpleInstanceState implements InstanceState { /** * The instance status. */ private final InstanceStatus instanceStatus; /** * Creates an abstract instance state with the specified parameters. * * @param instanceStatus the instance status */ public SimpleInstanceState(InstanceStatus instanceStatus) { this.instanceStatus = checkNotNull(instanceStatus, "instanceStatus is null"); } @Override public InstanceStatus getInstanceStatus() { return instanceStatus; } @Override // NOTE: This implementation does not do any actual localization, and simply calls toString() // on the instance status details. Plugin implementers may override to perform localization.
public String getInstanceStateDescription(LocalizationContext localizationContext) {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/DefaultLocalizationContext.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // }
import com.cloudera.director.spi.v2.model.LocalizationContext; import java.util.Locale;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Localization context that does not do any actual localization. */ public class DefaultLocalizationContext extends AbstractLocalizationContext { /** * Default localization context factory implementation. */ public static final Factory FACTORY = new Factory() { @Override
// Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/DefaultLocalizationContext.java import com.cloudera.director.spi.v2.model.LocalizationContext; import java.util.Locale; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Localization context that does not do any actual localization. */ public class DefaultLocalizationContext extends AbstractLocalizationContext { /** * Default localization context factory implementation. */ public static final Factory FACTORY = new Factory() { @Override
public LocalizationContext createRootLocalizationContext(Locale locale) {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/model/util/AbstractInstanceState.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceStatus.java // public enum InstanceStatus { // // /** // * The instance has been requested (initially or after being stopped), but is not yet known to be available. // */ // PENDING, // // /** // * The instance is running, although it may not be accessible. // */ // RUNNING, // // /** // * The instance is stopping, and may be restarted later. // */ // STOPPING, // // /** // * The instance is stopped, and may be restarted. // */ // STOPPED, // // /** // * The instance is being removed permanently. // */ // DELETING, // // /** // * The instance has been removed permanently. // */ // DELETED, // // /** // * The instance has failed, and cannot be reused. // */ // FAILED, // // /** // * The instance state cannot be determined. // */ // UNKNOWN // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // }
import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceStatus; import com.cloudera.director.spi.v2.model.LocalizationContext;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for instance state implementations. */ public class AbstractInstanceState<T> implements InstanceState { /** * The instance status. */ private final InstanceStatus instanceStatus; /** * The provider-specific instance state details. */ private final T instanceStateDetails; /** * Creates an abstract instance state with the specified parameters. * * @param instanceStatus the instance status * @param instanceStateDetails the provider-specific instance state details */ public AbstractInstanceState(InstanceStatus instanceStatus, T instanceStateDetails) { if (instanceStatus == null) { throw new NullPointerException("instanceStatus is null"); } this.instanceStatus = instanceStatus; this.instanceStateDetails = instanceStateDetails; } @Override public InstanceStatus getInstanceStatus() { return instanceStatus; } @Override public T unwrap() { return instanceStateDetails; } @Override // NOTE: This implementation does not do any actual localization, and simply calls toString() // on the instance state details. Plugin implementors may override to perform localization.
// Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceState.java // public interface InstanceState { // // /** // * Returns the instance status. // * // * @return the instance status // */ // InstanceStatus getInstanceStatus(); // // /** // * Returns a localized human-readable version of the instance state. // * // * @param localizationContext the localization context // * @return a localized human-readable version of the instance state // */ // String getInstanceStateDescription(LocalizationContext localizationContext); // // /** // * <p>Returns the provider specific version of this state object or null.</p> // * <p>Intended for internal provider use only. The consumer of the API will not try // * to use this in any way.</p> // */ // Object unwrap(); // // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/InstanceStatus.java // public enum InstanceStatus { // // /** // * The instance has been requested (initially or after being stopped), but is not yet known to be available. // */ // PENDING, // // /** // * The instance is running, although it may not be accessible. // */ // RUNNING, // // /** // * The instance is stopping, and may be restarted later. // */ // STOPPING, // // /** // * The instance is stopped, and may be restarted. // */ // STOPPED, // // /** // * The instance is being removed permanently. // */ // DELETING, // // /** // * The instance has been removed permanently. // */ // DELETED, // // /** // * The instance has failed, and cannot be reused. // */ // FAILED, // // /** // * The instance state cannot be determined. // */ // UNKNOWN // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/LocalizationContext.java // public interface LocalizationContext { // // /** // * Localization context factory. // */ // interface Factory { // // /** // * Creates a root localization context for the specified locale. // * // * @param locale the locale // * @return a root localization context for the specified locale // */ // LocalizationContext createRootLocalizationContext(Locale locale); // } // // /** // * Returns the locale. // * // * @return the locale // */ // Locale getLocale(); // // /** // * Returns the key prefix of the context, which can be used for property namespacing. // * // * @return the key prefix of the context // */ // String getKeyPrefix(); // // /** // * Returns a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined. // * // * @param defaultValue the default value to return if a localized value cannot be determined // * @param keyComponents the localization key suffix components // * @return a localized value for the specified localization key suffix components, // * or the specified default value if a localized value cannot be determined // */ // String localize(String defaultValue, String... keyComponents); // } // Path: src/main/java/com/cloudera/director/spi/v2/model/util/AbstractInstanceState.java import com.cloudera.director.spi.v2.model.InstanceState; import com.cloudera.director.spi.v2.model.InstanceStatus; import com.cloudera.director.spi.v2.model.LocalizationContext; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.model.util; /** * Abstract base class for instance state implementations. */ public class AbstractInstanceState<T> implements InstanceState { /** * The instance status. */ private final InstanceStatus instanceStatus; /** * The provider-specific instance state details. */ private final T instanceStateDetails; /** * Creates an abstract instance state with the specified parameters. * * @param instanceStatus the instance status * @param instanceStateDetails the provider-specific instance state details */ public AbstractInstanceState(InstanceStatus instanceStatus, T instanceStateDetails) { if (instanceStatus == null) { throw new NullPointerException("instanceStatus is null"); } this.instanceStatus = instanceStatus; this.instanceStateDetails = instanceStateDetails; } @Override public InstanceStatus getInstanceStatus() { return instanceStatus; } @Override public T unwrap() { return instanceStateDetails; } @Override // NOTE: This implementation does not do any actual localization, and simply calls toString() // on the instance state details. Plugin implementors may override to perform localization.
public String getInstanceStateDescription(LocalizationContext localizationContext) {
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/common/http/HttpProxyParameters.java
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // }
import static com.cloudera.director.spi.v2.util.Preconditions.checkArgument; import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List;
// (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.common.http; /** * Houses and validates HTTP proxy parameters. */ public class HttpProxyParameters { private final String host; private final int port; private final String username; private final String password; private final String domain; private final String workstation; private final boolean preemptiveBasicProxyAuth; private final List<String> proxyBypassHosts; /** * Constructs HTTP proxy parameters with default configuration. */ public HttpProxyParameters() { this(null, -1, null, null, null, null, false, Collections.<String>emptyList()); } /** * <p>Creates HTTP proxy parameters with the specified parameters.</p> * <p>The host and port must be specified together.</p> * <p>The username and password must also be specified together and must accompany the * host and port.</p> * <p>The domain and workstation must be specified together and must accompany the * username, password, host, and port.</p> * * @param host the proxy host * @param port the proxy port * @param username the proxy username * @param password the proxy password * @param domain the proxy domain (NTLM authentication only) * @param workstation the proxy workstation (NTLM authentication only) * @param preemptiveBasicProxyAuth whether the proxy should preemptively authenticate * @param proxyBypassHosts hosts or domain extensions that should be used to determine if the proxy * should be used for a domain */ @SuppressWarnings("PMD.UselessParentheses") public HttpProxyParameters(String host, int port, String username, String password, String domain, String workstation, boolean preemptiveBasicProxyAuth, List<String> proxyBypassHosts) { this.host = host; this.port = port;
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // Path: src/main/java/com/cloudera/director/spi/v2/common/http/HttpProxyParameters.java import static com.cloudera.director.spi.v2.util.Preconditions.checkArgument; import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; // (c) Copyright 2015 Cloudera, Inc. // // 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.cloudera.director.spi.v2.common.http; /** * Houses and validates HTTP proxy parameters. */ public class HttpProxyParameters { private final String host; private final int port; private final String username; private final String password; private final String domain; private final String workstation; private final boolean preemptiveBasicProxyAuth; private final List<String> proxyBypassHosts; /** * Constructs HTTP proxy parameters with default configuration. */ public HttpProxyParameters() { this(null, -1, null, null, null, null, false, Collections.<String>emptyList()); } /** * <p>Creates HTTP proxy parameters with the specified parameters.</p> * <p>The host and port must be specified together.</p> * <p>The username and password must also be specified together and must accompany the * host and port.</p> * <p>The domain and workstation must be specified together and must accompany the * username, password, host, and port.</p> * * @param host the proxy host * @param port the proxy port * @param username the proxy username * @param password the proxy password * @param domain the proxy domain (NTLM authentication only) * @param workstation the proxy workstation (NTLM authentication only) * @param preemptiveBasicProxyAuth whether the proxy should preemptively authenticate * @param proxyBypassHosts hosts or domain extensions that should be used to determine if the proxy * should be used for a domain */ @SuppressWarnings("PMD.UselessParentheses") public HttpProxyParameters(String host, int port, String username, String password, String domain, String workstation, boolean preemptiveBasicProxyAuth, List<String> proxyBypassHosts) { this.host = host; this.port = port;
checkArgument((host == null) || (this.port > 0 && this.port < 65536),
cloudera/director-spi
src/main/java/com/cloudera/director/spi/v2/common/http/HttpProxyParameters.java
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // }
import static com.cloudera.director.spi.v2.util.Preconditions.checkArgument; import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List;
* should be used for a domain */ @SuppressWarnings("PMD.UselessParentheses") public HttpProxyParameters(String host, int port, String username, String password, String domain, String workstation, boolean preemptiveBasicProxyAuth, List<String> proxyBypassHosts) { this.host = host; this.port = port; checkArgument((host == null) || (this.port > 0 && this.port < 65536), "The supplied port must be a positive number less than 65536"); this.username = username; this.password = password; checkArgument((username == null) == (password == null), "Both the proxy username and password must be supplied"); checkArgument((host != null) || (username == null), "A host and port must be supplied with a username and password"); this.domain = domain; this.workstation = workstation; checkArgument((domain == null) == (workstation == null), "Both the proxy domain and workstation must be supplied"); checkArgument((username != null) || (domain == null), "NTLM requires a username, password, domain, and workstation to be supplied."); this.preemptiveBasicProxyAuth = preemptiveBasicProxyAuth;
// Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static void checkArgument( // boolean expression, Object message) { // if (!expression) { // throw new IllegalArgumentException(String.valueOf(message)); // } // } // // Path: src/main/java/com/cloudera/director/spi/v2/util/Preconditions.java // public static <T> T checkNotNull(T instance, String message) { // if (instance == null) { // throw new NullPointerException(message); // } // return instance; // } // Path: src/main/java/com/cloudera/director/spi/v2/common/http/HttpProxyParameters.java import static com.cloudera.director.spi.v2.util.Preconditions.checkArgument; import static com.cloudera.director.spi.v2.util.Preconditions.checkNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; * should be used for a domain */ @SuppressWarnings("PMD.UselessParentheses") public HttpProxyParameters(String host, int port, String username, String password, String domain, String workstation, boolean preemptiveBasicProxyAuth, List<String> proxyBypassHosts) { this.host = host; this.port = port; checkArgument((host == null) || (this.port > 0 && this.port < 65536), "The supplied port must be a positive number less than 65536"); this.username = username; this.password = password; checkArgument((username == null) == (password == null), "Both the proxy username and password must be supplied"); checkArgument((host != null) || (username == null), "A host and port must be supplied with a username and password"); this.domain = domain; this.workstation = workstation; checkArgument((domain == null) == (workstation == null), "Both the proxy domain and workstation must be supplied"); checkArgument((username != null) || (domain == null), "NTLM requires a username, password, domain, and workstation to be supplied."); this.preemptiveBasicProxyAuth = preemptiveBasicProxyAuth;
this.proxyBypassHosts = new ArrayList<String>(checkNotNull(proxyBypassHosts, "proxyBypassHosts is null"));
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtilTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleConfigurationPropertyBuilder.java // public class SimpleConfigurationPropertyBuilder extends AbstractConfigurationPropertyBuilder // <SimpleConfigurationProperty, SimpleConfigurationPropertyBuilder> { // // @Override // public SimpleConfigurationPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleConfigurationProperty build() { // return new SimpleConfigurationProperty(getConfigKey(), getType(), getName(), isRequired(), // getWidget(), getDefaultValue(), getDefaultDescription(), getDefaultErrorMessage(), // getValidValues(), isSensitive(), isHidden(), getDefaultPlaceholder()); // } // }
import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleConfigurationPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class ConfigurationPropertiesUtilTest { @Test public void testAsConfigurationPropertyList() {
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleConfigurationPropertyBuilder.java // public class SimpleConfigurationPropertyBuilder extends AbstractConfigurationPropertyBuilder // <SimpleConfigurationProperty, SimpleConfigurationPropertyBuilder> { // // @Override // public SimpleConfigurationPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleConfigurationProperty build() { // return new SimpleConfigurationProperty(getConfigKey(), getType(), getName(), isRequired(), // getWidget(), getDefaultValue(), getDefaultDescription(), getDefaultErrorMessage(), // getValidValues(), isSensitive(), isHidden(), getDefaultPlaceholder()); // } // } // Path: src/test/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtilTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleConfigurationPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class ConfigurationPropertiesUtilTest { @Test public void testAsConfigurationPropertyList() {
final ConfigurationProperty config1 = makeConfigProperty("configKey1", "configDesc1");
cloudera/director-spi
src/test/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtilTest.java
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleConfigurationPropertyBuilder.java // public class SimpleConfigurationPropertyBuilder extends AbstractConfigurationPropertyBuilder // <SimpleConfigurationProperty, SimpleConfigurationPropertyBuilder> { // // @Override // public SimpleConfigurationPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleConfigurationProperty build() { // return new SimpleConfigurationProperty(getConfigKey(), getType(), getName(), isRequired(), // getWidget(), getDefaultValue(), getDefaultDescription(), getDefaultErrorMessage(), // getValidValues(), isSensitive(), isHidden(), getDefaultPlaceholder()); // } // }
import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleConfigurationPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test;
/* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class ConfigurationPropertiesUtilTest { @Test public void testAsConfigurationPropertyList() { final ConfigurationProperty config1 = makeConfigProperty("configKey1", "configDesc1"); final ConfigurationProperty config2 = makeConfigProperty("configKey2", "configDesc2"); List<ConfigurationProperty> configProperties = Arrays.asList(config1, config2);
// Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationProperty.java // public interface ConfigurationProperty extends Property<ConfigurationProperty.Widget> { // // /** // * Represents the widget used to display and edit a configuration property. // */ // enum Widget { // // /** // * Radio button widget. // */ // RADIO, // // /** // * Checkbox widget. // */ // CHECKBOX, // // /** // * Text box widget. // */ // TEXT, // // /** // * Password widget. // */ // PASSWORD, // // /** // * Numeric widget. // */ // NUMBER, // // /** // * Text area widget. // */ // TEXTAREA, // // /** // * File upload widget. // */ // FILE, // // /** // * List widget with fixed set of values. // */ // LIST, // // /** // * List widget that supports typing additional values. // */ // OPENLIST, // // /** // * Multiple selection widget for a fixed set of values. // */ // MULTI, // // /** // * Multiple selection widget that supports typing additional values. // */ // OPENMULTI // } // // /** // * Represents an attribute of a configuration property that can be localized. // */ // enum ConfigurationPropertyLocalizableAttribute implements LocalizableAttribute { // // /** // * Missing value error message attribute. // */ // MISSING_VALUE_ERROR_MESSAGE("missingValueErrorMessage"), // // /** // * Placeholder message attribute. // */ // PLACEHOLDER("placeholder"), // // /** // * Valid values message attribute. // */ // VALID_VALUES("validValues"); // // /** // * The key component, used in building a localization key. // */ // private final String keyComponent; // // /** // * Creates a localizable attribute with the specified parameters. // * // * @param keyComponent the key component, used in building a localization key // */ // private ConfigurationPropertyLocalizableAttribute(String keyComponent) { // this.keyComponent = keyComponent; // } // // /** // * Returns the key component, used in building a localization key. // * // * @return the key component, used in building a localization key // */ // public String getKeyComponent() { // return keyComponent; // } // } // // /** // * Returns the configuration key. // * // * @return the configuration key // */ // String getConfigKey(); // // /** // * Returns whether the configuration property is required. // * // * @return whether the configuration property is required // */ // boolean isRequired(); // // /** // * Returns the default value of the configuration property. // * // * @return the default value of the configuration property // */ // String getDefaultValue(); // // /** // * Returns the human-readable placeholder message when no value has been set for a // * configuration property. // // * // * @param localizationContext the localization context // * @return the human-readable placeholder message when no value has been set for a // * configuration property // */ // String getPlaceholder(LocalizationContext localizationContext); // // /** // * Returns the localized human-readable error message for when a required configuration property // * is missing. // * // * @param localizationContext the localization context // * @return the localized human-readable error message for when a required configuration property // * is missing // */ // String getMissingValueErrorMessage(LocalizationContext localizationContext); // // /** // * Returns a list of valid values for the configuration property with localized labels. Normally // * applies to properties that use LIST, OPENLIST, MULTI, or OPENMULTI widgets, but can apply to // * other widget types. // * // * @param localizationContext the localizationContext // * @return the valid values for the configuration property // */ // List<ConfigurationPropertyValue> getValidValues(LocalizationContext localizationContext); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/ConfigurationPropertyToken.java // public interface ConfigurationPropertyToken { // // /** // * Returns the configuration property. // * // * @return the configuration property // */ // ConfigurationProperty unwrap(); // } // // Path: src/main/java/com/cloudera/director/spi/v2/model/util/SimpleConfigurationPropertyBuilder.java // public class SimpleConfigurationPropertyBuilder extends AbstractConfigurationPropertyBuilder // <SimpleConfigurationProperty, SimpleConfigurationPropertyBuilder> { // // @Override // public SimpleConfigurationPropertyBuilder getThis() { // return this; // } // // @Override // public SimpleConfigurationProperty build() { // return new SimpleConfigurationProperty(getConfigKey(), getType(), getName(), isRequired(), // getWidget(), getDefaultValue(), getDefaultDescription(), getDefaultErrorMessage(), // getValidValues(), isSensitive(), isHidden(), getDefaultPlaceholder()); // } // } // Path: src/test/java/com/cloudera/director/spi/v2/util/ConfigurationPropertiesUtilTest.java import static org.assertj.core.api.Assertions.assertThat; import com.cloudera.director.spi.v2.model.ConfigurationProperty; import com.cloudera.director.spi.v2.model.ConfigurationPropertyToken; import com.cloudera.director.spi.v2.model.util.SimpleConfigurationPropertyBuilder; import java.util.Arrays; import java.util.List; import org.assertj.core.util.Lists; import org.junit.Test; /* * Copyright (c) 2015 Cloudera, Inc. * * 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.cloudera.director.spi.v2.util; public class ConfigurationPropertiesUtilTest { @Test public void testAsConfigurationPropertyList() { final ConfigurationProperty config1 = makeConfigProperty("configKey1", "configDesc1"); final ConfigurationProperty config2 = makeConfigProperty("configKey2", "configDesc2"); List<ConfigurationProperty> configProperties = Arrays.asList(config1, config2);
List<ConfigurationPropertyToken> configurationPropertyTokens = Arrays.asList(
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/WeatherListPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WeatherListViewIA.java // public interface WeatherListViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // }
import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.WeatherListViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WeatherListPresenter { private WeatherListViewIA mWeatherListViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WeatherListViewIA.java // public interface WeatherListViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/WeatherListPresenter.java import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.WeatherListViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WeatherListPresenter { private WeatherListViewIA mWeatherListViewIA;
private WeatherIA mWeatherIA;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/WeatherListPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WeatherListViewIA.java // public interface WeatherListViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // }
import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.WeatherListViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WeatherListPresenter { private WeatherListViewIA mWeatherListViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public WeatherListPresenter(WeatherListViewIA mWeatherListViewIA) { this.mWeatherListViewIA = mWeatherListViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WeatherListViewIA.java // public interface WeatherListViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/WeatherListPresenter.java import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.WeatherListViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WeatherListPresenter { private WeatherListViewIA mWeatherListViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public WeatherListPresenter(WeatherListViewIA mWeatherListViewIA) { this.mWeatherListViewIA = mWeatherListViewIA;
this.mWeatherIA = new WeatherModel();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/WeatherListPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WeatherListViewIA.java // public interface WeatherListViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // }
import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.WeatherListViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WeatherListPresenter { private WeatherListViewIA mWeatherListViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public WeatherListPresenter(WeatherListViewIA mWeatherListViewIA) { this.mWeatherListViewIA = mWeatherListViewIA; this.mWeatherIA = new WeatherModel(); } public void loadData(final int pageNum) { mWeatherIA.getServerData(LAT, LON, CNT) .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser .doOnSubscribe(new Action0() { @Override public void call() { mWeatherListViewIA.showProgressDialog(); // 需要在主线程执行 } }) .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WeatherListViewIA.java // public interface WeatherListViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/WeatherListPresenter.java import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.WeatherListViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WeatherListPresenter { private WeatherListViewIA mWeatherListViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public WeatherListPresenter(WeatherListViewIA mWeatherListViewIA) { this.mWeatherListViewIA = mWeatherListViewIA; this.mWeatherIA = new WeatherModel(); } public void loadData(final int pageNum) { mWeatherIA.getServerData(LAT, LON, CNT) .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser .doOnSubscribe(new Action0() { @Override public void call() { mWeatherListViewIA.showProgressDialog(); // 需要在主线程执行 } }) .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果
.subscribe(new Subscriber<List<WeatherData>>() {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/RecyclerGridPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/RecyclerGridViewIA.java // public interface RecyclerGridViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // }
import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.RecyclerGridViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class RecyclerGridPresenter { private RecyclerGridViewIA mRecyclerGridViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/RecyclerGridViewIA.java // public interface RecyclerGridViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/RecyclerGridPresenter.java import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.RecyclerGridViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class RecyclerGridPresenter { private RecyclerGridViewIA mRecyclerGridViewIA;
private WeatherIA mWeatherIA;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/RecyclerGridPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/RecyclerGridViewIA.java // public interface RecyclerGridViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // }
import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.RecyclerGridViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class RecyclerGridPresenter { private RecyclerGridViewIA mRecyclerGridViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public RecyclerGridPresenter(RecyclerGridViewIA mRecyclerGridViewIA) { this.mRecyclerGridViewIA = mRecyclerGridViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/RecyclerGridViewIA.java // public interface RecyclerGridViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/RecyclerGridPresenter.java import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.RecyclerGridViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class RecyclerGridPresenter { private RecyclerGridViewIA mRecyclerGridViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public RecyclerGridPresenter(RecyclerGridViewIA mRecyclerGridViewIA) { this.mRecyclerGridViewIA = mRecyclerGridViewIA;
this.mWeatherIA = new WeatherModel();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/RecyclerGridPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/RecyclerGridViewIA.java // public interface RecyclerGridViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // }
import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.RecyclerGridViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class RecyclerGridPresenter { private RecyclerGridViewIA mRecyclerGridViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public RecyclerGridPresenter(RecyclerGridViewIA mRecyclerGridViewIA) { this.mRecyclerGridViewIA = mRecyclerGridViewIA; this.mWeatherIA = new WeatherModel(); } public void loadData(final int pageNum) { mWeatherIA.getServerData(LAT, LON, CNT) .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser .doOnSubscribe(new Action0() { @Override public void call() { mRecyclerGridViewIA.showProgressDialog(); // 需要在主线程执行 } }) .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果
// Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java // public class WeatherModel extends BaseModel implements WeatherIA { // private static final String ENDPOINT = "http://api.openweathermap.org"; // private final Service mService; // // public WeatherModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<WeatherListData>() { // }.getType(), // new ResultsDeserializer<WeatherListData>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) { // return mService.getWeatherList(lat, lon, cnt, "82baf3673f8b23cb70d1165d3ce73b9c") // .flatMap(new Func1<WeatherListData, Observable<List<WeatherData>>>() { // @Override // public Observable<List<WeatherData>> call(WeatherListData data) { // List<WeatherData> list = data.getList(); // return Observable.just(list); // } // }); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/data/2.5/find") // Observable<WeatherListData> getWeatherList(@Query("lat") String lat, @Query("lon") String lon, @Query("cnt") String cnt, @Query("APPID") String appId); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/RecyclerGridViewIA.java // public interface RecyclerGridViewIA extends BaseViewIA { // void refresh(List<WeatherData> data); // void loadNews(List<WeatherData> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/RecyclerGridPresenter.java import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.module.main.model.WeatherModel; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.example.app.rxjava.module.main.view.ia.RecyclerGridViewIA; import java.util.List; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class RecyclerGridPresenter { private RecyclerGridViewIA mRecyclerGridViewIA; private WeatherIA mWeatherIA; private static final String LAT = "55.5", LON = "37.5", CNT = "10"; public RecyclerGridPresenter(RecyclerGridViewIA mRecyclerGridViewIA) { this.mRecyclerGridViewIA = mRecyclerGridViewIA; this.mWeatherIA = new WeatherModel(); } public void loadData(final int pageNum) { mWeatherIA.getServerData(LAT, LON, CNT) .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser .doOnSubscribe(new Action0() { @Override public void call() { mRecyclerGridViewIA.showProgressDialog(); // 需要在主线程执行 } }) .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果
.subscribe(new Subscriber<List<WeatherData>>() {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/receiver/ConnectionReceiver.java
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // }
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import com.example.app.rxjava.AppApplication;
package com.example.app.rxjava.receiver; /** * 检测网络连接状态 * Created by Administrator on 2016/3/9. */ public class ConnectionReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = conn.getActiveNetworkInfo(); if (info != null) {
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // Path: app/src/main/java/com/example/app/rxjava/receiver/ConnectionReceiver.java import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import com.example.app.rxjava.AppApplication; package com.example.app.rxjava.receiver; /** * 检测网络连接状态 * Created by Administrator on 2016/3/9. */ public class ConnectionReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = conn.getActiveNetworkInfo(); if (info != null) {
AppApplication.isNetConnect = info.isConnected();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/widget/model/WidgetModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/interceptor/RequestInterceptor.java // public class RequestInterceptor implements Interceptor { // // private final String mApiKey = "111111"; // // public RequestInterceptor() { // // } // // @Override // public Response intercept(Interceptor.Chain chain) throws IOException { // Request oldRequest = chain.request(); // // 添加新的参数 // HttpUrl.Builder authorizedUrlBuilder = oldRequest.url() // .newBuilder() // .scheme(oldRequest.url().scheme()) // .host(oldRequest.url().host()) // .addQueryParameter("mApiKey", mApiKey); // // // 新的请求 // Request newRequest = oldRequest.newBuilder() // .method(oldRequest.method(), oldRequest.body()) // .url(authorizedUrlBuilder.build()) // .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") // .addHeader("Accept-Encoding", "gzip, deflate") // .addHeader("Connection", "keep-alive") // .addHeader("Accept", "*/*") // .addHeader("Cookie", "add cookies here") // .build(); // // return chain.proceed(newRequest); // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/widget/model/ia/WidgetIA.java // public interface WidgetIA { // public Observable<Picture> getData(); // }
import com.example.app.rxjava.base.interceptor.RequestInterceptor; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.widget.model.ia.WidgetIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable;
package com.example.app.rxjava.widget.model; /** * Created by Administrator on 2016/2/29. */ public class WidgetModel implements WidgetIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WidgetModel() { // Log信息 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // 拦截器,在请求中增加额外参数
// Path: app/src/main/java/com/example/app/rxjava/base/interceptor/RequestInterceptor.java // public class RequestInterceptor implements Interceptor { // // private final String mApiKey = "111111"; // // public RequestInterceptor() { // // } // // @Override // public Response intercept(Interceptor.Chain chain) throws IOException { // Request oldRequest = chain.request(); // // 添加新的参数 // HttpUrl.Builder authorizedUrlBuilder = oldRequest.url() // .newBuilder() // .scheme(oldRequest.url().scheme()) // .host(oldRequest.url().host()) // .addQueryParameter("mApiKey", mApiKey); // // // 新的请求 // Request newRequest = oldRequest.newBuilder() // .method(oldRequest.method(), oldRequest.body()) // .url(authorizedUrlBuilder.build()) // .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") // .addHeader("Accept-Encoding", "gzip, deflate") // .addHeader("Connection", "keep-alive") // .addHeader("Accept", "*/*") // .addHeader("Cookie", "add cookies here") // .build(); // // return chain.proceed(newRequest); // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/widget/model/ia/WidgetIA.java // public interface WidgetIA { // public Observable<Picture> getData(); // } // Path: app/src/main/java/com/example/app/rxjava/widget/model/WidgetModel.java import com.example.app.rxjava.base.interceptor.RequestInterceptor; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.widget.model.ia.WidgetIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; package com.example.app.rxjava.widget.model; /** * Created by Administrator on 2016/2/29. */ public class WidgetModel implements WidgetIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WidgetModel() { // Log信息 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // 拦截器,在请求中增加额外参数
RequestInterceptor requestInterceptor = new RequestInterceptor();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/widget/model/WidgetModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/interceptor/RequestInterceptor.java // public class RequestInterceptor implements Interceptor { // // private final String mApiKey = "111111"; // // public RequestInterceptor() { // // } // // @Override // public Response intercept(Interceptor.Chain chain) throws IOException { // Request oldRequest = chain.request(); // // 添加新的参数 // HttpUrl.Builder authorizedUrlBuilder = oldRequest.url() // .newBuilder() // .scheme(oldRequest.url().scheme()) // .host(oldRequest.url().host()) // .addQueryParameter("mApiKey", mApiKey); // // // 新的请求 // Request newRequest = oldRequest.newBuilder() // .method(oldRequest.method(), oldRequest.body()) // .url(authorizedUrlBuilder.build()) // .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") // .addHeader("Accept-Encoding", "gzip, deflate") // .addHeader("Connection", "keep-alive") // .addHeader("Accept", "*/*") // .addHeader("Cookie", "add cookies here") // .build(); // // return chain.proceed(newRequest); // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/widget/model/ia/WidgetIA.java // public interface WidgetIA { // public Observable<Picture> getData(); // }
import com.example.app.rxjava.base.interceptor.RequestInterceptor; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.widget.model.ia.WidgetIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable;
package com.example.app.rxjava.widget.model; /** * Created by Administrator on 2016/2/29. */ public class WidgetModel implements WidgetIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WidgetModel() { // Log信息 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // 拦截器,在请求中增加额外参数 RequestInterceptor requestInterceptor = new RequestInterceptor(); // OkHttp3.0的使用方式 OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(requestInterceptor) .addInterceptor(loggingInterceptor) .build(); // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder()
// Path: app/src/main/java/com/example/app/rxjava/base/interceptor/RequestInterceptor.java // public class RequestInterceptor implements Interceptor { // // private final String mApiKey = "111111"; // // public RequestInterceptor() { // // } // // @Override // public Response intercept(Interceptor.Chain chain) throws IOException { // Request oldRequest = chain.request(); // // 添加新的参数 // HttpUrl.Builder authorizedUrlBuilder = oldRequest.url() // .newBuilder() // .scheme(oldRequest.url().scheme()) // .host(oldRequest.url().host()) // .addQueryParameter("mApiKey", mApiKey); // // // 新的请求 // Request newRequest = oldRequest.newBuilder() // .method(oldRequest.method(), oldRequest.body()) // .url(authorizedUrlBuilder.build()) // .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") // .addHeader("Accept-Encoding", "gzip, deflate") // .addHeader("Connection", "keep-alive") // .addHeader("Accept", "*/*") // .addHeader("Cookie", "add cookies here") // .build(); // // return chain.proceed(newRequest); // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/widget/model/ia/WidgetIA.java // public interface WidgetIA { // public Observable<Picture> getData(); // } // Path: app/src/main/java/com/example/app/rxjava/widget/model/WidgetModel.java import com.example.app.rxjava.base.interceptor.RequestInterceptor; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.widget.model.ia.WidgetIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; package com.example.app.rxjava.widget.model; /** * Created by Administrator on 2016/2/29. */ public class WidgetModel implements WidgetIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WidgetModel() { // Log信息 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // 拦截器,在请求中增加额外参数 RequestInterceptor requestInterceptor = new RequestInterceptor(); // OkHttp3.0的使用方式 OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(requestInterceptor) .addInterceptor(loggingInterceptor) .build(); // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder()
.registerTypeAdapter(new TypeToken<List<Picture>>() {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/widget/model/WidgetModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/interceptor/RequestInterceptor.java // public class RequestInterceptor implements Interceptor { // // private final String mApiKey = "111111"; // // public RequestInterceptor() { // // } // // @Override // public Response intercept(Interceptor.Chain chain) throws IOException { // Request oldRequest = chain.request(); // // 添加新的参数 // HttpUrl.Builder authorizedUrlBuilder = oldRequest.url() // .newBuilder() // .scheme(oldRequest.url().scheme()) // .host(oldRequest.url().host()) // .addQueryParameter("mApiKey", mApiKey); // // // 新的请求 // Request newRequest = oldRequest.newBuilder() // .method(oldRequest.method(), oldRequest.body()) // .url(authorizedUrlBuilder.build()) // .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") // .addHeader("Accept-Encoding", "gzip, deflate") // .addHeader("Connection", "keep-alive") // .addHeader("Accept", "*/*") // .addHeader("Cookie", "add cookies here") // .build(); // // return chain.proceed(newRequest); // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/widget/model/ia/WidgetIA.java // public interface WidgetIA { // public Observable<Picture> getData(); // }
import com.example.app.rxjava.base.interceptor.RequestInterceptor; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.widget.model.ia.WidgetIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable;
package com.example.app.rxjava.widget.model; /** * Created by Administrator on 2016/2/29. */ public class WidgetModel implements WidgetIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WidgetModel() { // Log信息 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // 拦截器,在请求中增加额外参数 RequestInterceptor requestInterceptor = new RequestInterceptor(); // OkHttp3.0的使用方式 OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(requestInterceptor) .addInterceptor(loggingInterceptor) .build(); // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<List<Picture>>() { }.getType(),
// Path: app/src/main/java/com/example/app/rxjava/base/interceptor/RequestInterceptor.java // public class RequestInterceptor implements Interceptor { // // private final String mApiKey = "111111"; // // public RequestInterceptor() { // // } // // @Override // public Response intercept(Interceptor.Chain chain) throws IOException { // Request oldRequest = chain.request(); // // 添加新的参数 // HttpUrl.Builder authorizedUrlBuilder = oldRequest.url() // .newBuilder() // .scheme(oldRequest.url().scheme()) // .host(oldRequest.url().host()) // .addQueryParameter("mApiKey", mApiKey); // // // 新的请求 // Request newRequest = oldRequest.newBuilder() // .method(oldRequest.method(), oldRequest.body()) // .url(authorizedUrlBuilder.build()) // .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") // .addHeader("Accept-Encoding", "gzip, deflate") // .addHeader("Connection", "keep-alive") // .addHeader("Accept", "*/*") // .addHeader("Cookie", "add cookies here") // .build(); // // return chain.proceed(newRequest); // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/widget/model/ia/WidgetIA.java // public interface WidgetIA { // public Observable<Picture> getData(); // } // Path: app/src/main/java/com/example/app/rxjava/widget/model/WidgetModel.java import com.example.app.rxjava.base.interceptor.RequestInterceptor; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.widget.model.ia.WidgetIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; package com.example.app.rxjava.widget.model; /** * Created by Administrator on 2016/2/29. */ public class WidgetModel implements WidgetIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WidgetModel() { // Log信息 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // 拦截器,在请求中增加额外参数 RequestInterceptor requestInterceptor = new RequestInterceptor(); // OkHttp3.0的使用方式 OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(requestInterceptor) .addInterceptor(loggingInterceptor) .build(); // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<List<Picture>>() { }.getType(),
new ResultsDeserializer<List<Picture>>())
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherListData.java // public class WeatherListData { // private String message; // private String cod; // private int count; // private List<WeatherData> list; // public String getMessage() { // return message; // } // public void setMessage(String message) { // this.message = message; // } // public String getCod() { // return cod; // } // public void setCod(String cod) { // this.cod = cod; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public List<WeatherData> getList() { // return list; // } // public void setList(List<WeatherData> list) { // this.list = list; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // }
import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.bean.weather.WeatherListData; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; import rx.functions.Func1;
package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WeatherModel extends BaseModel implements WeatherIA { private static final String ENDPOINT = "http://api.openweathermap.org"; private final Service mService; public WeatherModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder()
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherListData.java // public class WeatherListData { // private String message; // private String cod; // private int count; // private List<WeatherData> list; // public String getMessage() { // return message; // } // public void setMessage(String message) { // this.message = message; // } // public String getCod() { // return cod; // } // public void setCod(String cod) { // this.cod = cod; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public List<WeatherData> getList() { // return list; // } // public void setList(List<WeatherData> list) { // this.list = list; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.bean.weather.WeatherListData; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; import rx.functions.Func1; package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WeatherModel extends BaseModel implements WeatherIA { private static final String ENDPOINT = "http://api.openweathermap.org"; private final Service mService; public WeatherModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder()
.registerTypeAdapter(new TypeToken<WeatherListData>() {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherListData.java // public class WeatherListData { // private String message; // private String cod; // private int count; // private List<WeatherData> list; // public String getMessage() { // return message; // } // public void setMessage(String message) { // this.message = message; // } // public String getCod() { // return cod; // } // public void setCod(String cod) { // this.cod = cod; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public List<WeatherData> getList() { // return list; // } // public void setList(List<WeatherData> list) { // this.list = list; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // }
import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.bean.weather.WeatherListData; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; import rx.functions.Func1;
package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WeatherModel extends BaseModel implements WeatherIA { private static final String ENDPOINT = "http://api.openweathermap.org"; private final Service mService; public WeatherModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<WeatherListData>() { }.getType(),
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherListData.java // public class WeatherListData { // private String message; // private String cod; // private int count; // private List<WeatherData> list; // public String getMessage() { // return message; // } // public void setMessage(String message) { // this.message = message; // } // public String getCod() { // return cod; // } // public void setCod(String cod) { // this.cod = cod; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public List<WeatherData> getList() { // return list; // } // public void setList(List<WeatherData> list) { // this.list = list; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.bean.weather.WeatherListData; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; import rx.functions.Func1; package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WeatherModel extends BaseModel implements WeatherIA { private static final String ENDPOINT = "http://api.openweathermap.org"; private final Service mService; public WeatherModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<WeatherListData>() { }.getType(),
new ResultsDeserializer<WeatherListData>())
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherListData.java // public class WeatherListData { // private String message; // private String cod; // private int count; // private List<WeatherData> list; // public String getMessage() { // return message; // } // public void setMessage(String message) { // this.message = message; // } // public String getCod() { // return cod; // } // public void setCod(String cod) { // this.cod = cod; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public List<WeatherData> getList() { // return list; // } // public void setList(List<WeatherData> list) { // this.list = list; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // }
import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.bean.weather.WeatherListData; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; import rx.functions.Func1;
package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WeatherModel extends BaseModel implements WeatherIA { private static final String ENDPOINT = "http://api.openweathermap.org"; private final Service mService; public WeatherModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<WeatherListData>() { }.getType(), new ResultsDeserializer<WeatherListData>()) .create(); // 适配器 Retrofit mRetrofit = getRetrofitBuilder() .baseUrl(ENDPOINT) .addConverterFactory(GsonConverterFactory.create(gsonInstance)) .build(); // 服务 mService = mRetrofit.create(Service.class); }
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherData.java // @ModelContainer // @Table(database = AppDatabase.class) // public class WeatherData extends BaseModel { // @PrimaryKey(autoincrement = false) // private long id; // @Column // private String name; // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/bean/weather/WeatherListData.java // public class WeatherListData { // private String message; // private String cod; // private int count; // private List<WeatherData> list; // public String getMessage() { // return message; // } // public void setMessage(String message) { // this.message = message; // } // public String getCod() { // return cod; // } // public void setCod(String cod) { // this.cod = cod; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public List<WeatherData> getList() { // return list; // } // public void setList(List<WeatherData> list) { // this.list = list; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WeatherIA.java // public interface WeatherIA { // public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WeatherModel.java import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.weather.WeatherData; import com.example.app.rxjava.bean.weather.WeatherListData; import com.example.app.rxjava.module.main.model.ia.WeatherIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.util.List; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; import rx.functions.Func1; package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WeatherModel extends BaseModel implements WeatherIA { private static final String ENDPOINT = "http://api.openweathermap.org"; private final Service mService; public WeatherModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<WeatherListData>() { }.getType(), new ResultsDeserializer<WeatherListData>()) .create(); // 适配器 Retrofit mRetrofit = getRetrofitBuilder() .baseUrl(ENDPOINT) .addConverterFactory(GsonConverterFactory.create(gsonInstance)) .build(); // 服务 mService = mRetrofit.create(Service.class); }
public Observable<List<WeatherData>> getServerData(final String lat, final String lon, final String cnt) {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/login/presenter/LoginPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/LoginModel.java // public class LoginModel implements LoginIA { // public Observable<Boolean> validUserInfo(final User user) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // if(!user.getEmail().contains("@")) { // subscriber.onNext(false); // } else if(user.getPassword().length() < 1) { // subscriber.onNext(false); // } else { // subscriber.onNext(true); // } // subscriber.onCompleted(); // } // }); // } // public Observable<Boolean> login(final String email, final String password) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // //SystemClock.sleep(2000); // // if(email.equals("q@qq.com") && password.equals("1")) { // subscriber.onNext(true); // } else { // subscriber.onNext(false); // } // subscriber.onCompleted(); // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/ia/LoginIA.java // public interface LoginIA { // public Observable<Boolean> validUserInfo(final User user); // public Observable<Boolean> login(final String email, final String password); // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/LoginActivity.java // public class LoginActivity extends BaseActivity implements LoginViewIA { // private Context context; // // // UI references. // private AutoCompleteTextView mEmailView; // private EditText mPasswordView; // private View mLoginFormView; // // private LoginPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_login); // context = this; // // Set up the login form. // mEmailView = (AutoCompleteTextView) findViewById(R.id.email); // mPasswordView = (EditText) findViewById(R.id.password); // mLoginFormView = findViewById(R.id.login_form); // Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); // presenter = new LoginPresenter(this); // // mEmailSignInButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View view) { // presenter.login(); // } // }); // // // TODO: 从Cookie中获取登录状态参数,判断是否直接跳转到内容页 // } // // @Override // public User getInfo() { // User user = new User(); // user.setEmail(mEmailView.getText().toString()); // user.setPassword(mPasswordView.getText().toString()); // return user; // } // // @Override // public void toNextView() { // Intent intent = new Intent(LoginActivity.this, MainActivity.class); // startActivity(intent); // finish(); // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/ia/LoginViewIA.java // public interface LoginViewIA extends BaseViewIA { // // User getInfo(); // // void toNextView(); // // }
import com.example.app.rxjava.R; import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.login.model.LoginModel; import com.example.app.rxjava.module.login.model.ia.LoginIA; import com.example.app.rxjava.module.login.view.LoginActivity; import com.example.app.rxjava.module.login.view.ia.LoginViewIA; import rx.Observable; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.login.presenter; /** * Created by Administrator on 2016/2/29. */ public class LoginPresenter { private LoginViewIA mLoginViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/LoginModel.java // public class LoginModel implements LoginIA { // public Observable<Boolean> validUserInfo(final User user) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // if(!user.getEmail().contains("@")) { // subscriber.onNext(false); // } else if(user.getPassword().length() < 1) { // subscriber.onNext(false); // } else { // subscriber.onNext(true); // } // subscriber.onCompleted(); // } // }); // } // public Observable<Boolean> login(final String email, final String password) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // //SystemClock.sleep(2000); // // if(email.equals("q@qq.com") && password.equals("1")) { // subscriber.onNext(true); // } else { // subscriber.onNext(false); // } // subscriber.onCompleted(); // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/ia/LoginIA.java // public interface LoginIA { // public Observable<Boolean> validUserInfo(final User user); // public Observable<Boolean> login(final String email, final String password); // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/LoginActivity.java // public class LoginActivity extends BaseActivity implements LoginViewIA { // private Context context; // // // UI references. // private AutoCompleteTextView mEmailView; // private EditText mPasswordView; // private View mLoginFormView; // // private LoginPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_login); // context = this; // // Set up the login form. // mEmailView = (AutoCompleteTextView) findViewById(R.id.email); // mPasswordView = (EditText) findViewById(R.id.password); // mLoginFormView = findViewById(R.id.login_form); // Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); // presenter = new LoginPresenter(this); // // mEmailSignInButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View view) { // presenter.login(); // } // }); // // // TODO: 从Cookie中获取登录状态参数,判断是否直接跳转到内容页 // } // // @Override // public User getInfo() { // User user = new User(); // user.setEmail(mEmailView.getText().toString()); // user.setPassword(mPasswordView.getText().toString()); // return user; // } // // @Override // public void toNextView() { // Intent intent = new Intent(LoginActivity.this, MainActivity.class); // startActivity(intent); // finish(); // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/ia/LoginViewIA.java // public interface LoginViewIA extends BaseViewIA { // // User getInfo(); // // void toNextView(); // // } // Path: app/src/main/java/com/example/app/rxjava/module/login/presenter/LoginPresenter.java import com.example.app.rxjava.R; import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.login.model.LoginModel; import com.example.app.rxjava.module.login.model.ia.LoginIA; import com.example.app.rxjava.module.login.view.LoginActivity; import com.example.app.rxjava.module.login.view.ia.LoginViewIA; import rx.Observable; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.login.presenter; /** * Created by Administrator on 2016/2/29. */ public class LoginPresenter { private LoginViewIA mLoginViewIA;
private LoginIA mLoginIA;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/login/presenter/LoginPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/LoginModel.java // public class LoginModel implements LoginIA { // public Observable<Boolean> validUserInfo(final User user) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // if(!user.getEmail().contains("@")) { // subscriber.onNext(false); // } else if(user.getPassword().length() < 1) { // subscriber.onNext(false); // } else { // subscriber.onNext(true); // } // subscriber.onCompleted(); // } // }); // } // public Observable<Boolean> login(final String email, final String password) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // //SystemClock.sleep(2000); // // if(email.equals("q@qq.com") && password.equals("1")) { // subscriber.onNext(true); // } else { // subscriber.onNext(false); // } // subscriber.onCompleted(); // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/ia/LoginIA.java // public interface LoginIA { // public Observable<Boolean> validUserInfo(final User user); // public Observable<Boolean> login(final String email, final String password); // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/LoginActivity.java // public class LoginActivity extends BaseActivity implements LoginViewIA { // private Context context; // // // UI references. // private AutoCompleteTextView mEmailView; // private EditText mPasswordView; // private View mLoginFormView; // // private LoginPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_login); // context = this; // // Set up the login form. // mEmailView = (AutoCompleteTextView) findViewById(R.id.email); // mPasswordView = (EditText) findViewById(R.id.password); // mLoginFormView = findViewById(R.id.login_form); // Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); // presenter = new LoginPresenter(this); // // mEmailSignInButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View view) { // presenter.login(); // } // }); // // // TODO: 从Cookie中获取登录状态参数,判断是否直接跳转到内容页 // } // // @Override // public User getInfo() { // User user = new User(); // user.setEmail(mEmailView.getText().toString()); // user.setPassword(mPasswordView.getText().toString()); // return user; // } // // @Override // public void toNextView() { // Intent intent = new Intent(LoginActivity.this, MainActivity.class); // startActivity(intent); // finish(); // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/ia/LoginViewIA.java // public interface LoginViewIA extends BaseViewIA { // // User getInfo(); // // void toNextView(); // // }
import com.example.app.rxjava.R; import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.login.model.LoginModel; import com.example.app.rxjava.module.login.model.ia.LoginIA; import com.example.app.rxjava.module.login.view.LoginActivity; import com.example.app.rxjava.module.login.view.ia.LoginViewIA; import rx.Observable; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.login.presenter; /** * Created by Administrator on 2016/2/29. */ public class LoginPresenter { private LoginViewIA mLoginViewIA; private LoginIA mLoginIA; public LoginPresenter(LoginViewIA mLoginViewIA) { this.mLoginViewIA = mLoginViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/LoginModel.java // public class LoginModel implements LoginIA { // public Observable<Boolean> validUserInfo(final User user) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // if(!user.getEmail().contains("@")) { // subscriber.onNext(false); // } else if(user.getPassword().length() < 1) { // subscriber.onNext(false); // } else { // subscriber.onNext(true); // } // subscriber.onCompleted(); // } // }); // } // public Observable<Boolean> login(final String email, final String password) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // //SystemClock.sleep(2000); // // if(email.equals("q@qq.com") && password.equals("1")) { // subscriber.onNext(true); // } else { // subscriber.onNext(false); // } // subscriber.onCompleted(); // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/ia/LoginIA.java // public interface LoginIA { // public Observable<Boolean> validUserInfo(final User user); // public Observable<Boolean> login(final String email, final String password); // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/LoginActivity.java // public class LoginActivity extends BaseActivity implements LoginViewIA { // private Context context; // // // UI references. // private AutoCompleteTextView mEmailView; // private EditText mPasswordView; // private View mLoginFormView; // // private LoginPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_login); // context = this; // // Set up the login form. // mEmailView = (AutoCompleteTextView) findViewById(R.id.email); // mPasswordView = (EditText) findViewById(R.id.password); // mLoginFormView = findViewById(R.id.login_form); // Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); // presenter = new LoginPresenter(this); // // mEmailSignInButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View view) { // presenter.login(); // } // }); // // // TODO: 从Cookie中获取登录状态参数,判断是否直接跳转到内容页 // } // // @Override // public User getInfo() { // User user = new User(); // user.setEmail(mEmailView.getText().toString()); // user.setPassword(mPasswordView.getText().toString()); // return user; // } // // @Override // public void toNextView() { // Intent intent = new Intent(LoginActivity.this, MainActivity.class); // startActivity(intent); // finish(); // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/ia/LoginViewIA.java // public interface LoginViewIA extends BaseViewIA { // // User getInfo(); // // void toNextView(); // // } // Path: app/src/main/java/com/example/app/rxjava/module/login/presenter/LoginPresenter.java import com.example.app.rxjava.R; import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.login.model.LoginModel; import com.example.app.rxjava.module.login.model.ia.LoginIA; import com.example.app.rxjava.module.login.view.LoginActivity; import com.example.app.rxjava.module.login.view.ia.LoginViewIA; import rx.Observable; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.login.presenter; /** * Created by Administrator on 2016/2/29. */ public class LoginPresenter { private LoginViewIA mLoginViewIA; private LoginIA mLoginIA; public LoginPresenter(LoginViewIA mLoginViewIA) { this.mLoginViewIA = mLoginViewIA;
this.mLoginIA = new LoginModel();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/login/presenter/LoginPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/LoginModel.java // public class LoginModel implements LoginIA { // public Observable<Boolean> validUserInfo(final User user) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // if(!user.getEmail().contains("@")) { // subscriber.onNext(false); // } else if(user.getPassword().length() < 1) { // subscriber.onNext(false); // } else { // subscriber.onNext(true); // } // subscriber.onCompleted(); // } // }); // } // public Observable<Boolean> login(final String email, final String password) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // //SystemClock.sleep(2000); // // if(email.equals("q@qq.com") && password.equals("1")) { // subscriber.onNext(true); // } else { // subscriber.onNext(false); // } // subscriber.onCompleted(); // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/ia/LoginIA.java // public interface LoginIA { // public Observable<Boolean> validUserInfo(final User user); // public Observable<Boolean> login(final String email, final String password); // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/LoginActivity.java // public class LoginActivity extends BaseActivity implements LoginViewIA { // private Context context; // // // UI references. // private AutoCompleteTextView mEmailView; // private EditText mPasswordView; // private View mLoginFormView; // // private LoginPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_login); // context = this; // // Set up the login form. // mEmailView = (AutoCompleteTextView) findViewById(R.id.email); // mPasswordView = (EditText) findViewById(R.id.password); // mLoginFormView = findViewById(R.id.login_form); // Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); // presenter = new LoginPresenter(this); // // mEmailSignInButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View view) { // presenter.login(); // } // }); // // // TODO: 从Cookie中获取登录状态参数,判断是否直接跳转到内容页 // } // // @Override // public User getInfo() { // User user = new User(); // user.setEmail(mEmailView.getText().toString()); // user.setPassword(mPasswordView.getText().toString()); // return user; // } // // @Override // public void toNextView() { // Intent intent = new Intent(LoginActivity.this, MainActivity.class); // startActivity(intent); // finish(); // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/ia/LoginViewIA.java // public interface LoginViewIA extends BaseViewIA { // // User getInfo(); // // void toNextView(); // // }
import com.example.app.rxjava.R; import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.login.model.LoginModel; import com.example.app.rxjava.module.login.model.ia.LoginIA; import com.example.app.rxjava.module.login.view.LoginActivity; import com.example.app.rxjava.module.login.view.ia.LoginViewIA; import rx.Observable; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.login.presenter; /** * Created by Administrator on 2016/2/29. */ public class LoginPresenter { private LoginViewIA mLoginViewIA; private LoginIA mLoginIA; public LoginPresenter(LoginViewIA mLoginViewIA) { this.mLoginViewIA = mLoginViewIA; this.mLoginIA = new LoginModel(); } public void login() {
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/LoginModel.java // public class LoginModel implements LoginIA { // public Observable<Boolean> validUserInfo(final User user) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // if(!user.getEmail().contains("@")) { // subscriber.onNext(false); // } else if(user.getPassword().length() < 1) { // subscriber.onNext(false); // } else { // subscriber.onNext(true); // } // subscriber.onCompleted(); // } // }); // } // public Observable<Boolean> login(final String email, final String password) { // return Observable.create(new Observable.OnSubscribe<Boolean>() { // @Override // public void call(Subscriber<? super Boolean> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // //SystemClock.sleep(2000); // // if(email.equals("q@qq.com") && password.equals("1")) { // subscriber.onNext(true); // } else { // subscriber.onNext(false); // } // subscriber.onCompleted(); // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/model/ia/LoginIA.java // public interface LoginIA { // public Observable<Boolean> validUserInfo(final User user); // public Observable<Boolean> login(final String email, final String password); // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/LoginActivity.java // public class LoginActivity extends BaseActivity implements LoginViewIA { // private Context context; // // // UI references. // private AutoCompleteTextView mEmailView; // private EditText mPasswordView; // private View mLoginFormView; // // private LoginPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_login); // context = this; // // Set up the login form. // mEmailView = (AutoCompleteTextView) findViewById(R.id.email); // mPasswordView = (EditText) findViewById(R.id.password); // mLoginFormView = findViewById(R.id.login_form); // Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); // presenter = new LoginPresenter(this); // // mEmailSignInButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View view) { // presenter.login(); // } // }); // // // TODO: 从Cookie中获取登录状态参数,判断是否直接跳转到内容页 // } // // @Override // public User getInfo() { // User user = new User(); // user.setEmail(mEmailView.getText().toString()); // user.setPassword(mPasswordView.getText().toString()); // return user; // } // // @Override // public void toNextView() { // Intent intent = new Intent(LoginActivity.this, MainActivity.class); // startActivity(intent); // finish(); // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/login/view/ia/LoginViewIA.java // public interface LoginViewIA extends BaseViewIA { // // User getInfo(); // // void toNextView(); // // } // Path: app/src/main/java/com/example/app/rxjava/module/login/presenter/LoginPresenter.java import com.example.app.rxjava.R; import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.login.model.LoginModel; import com.example.app.rxjava.module.login.model.ia.LoginIA; import com.example.app.rxjava.module.login.view.LoginActivity; import com.example.app.rxjava.module.login.view.ia.LoginViewIA; import rx.Observable; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.login.presenter; /** * Created by Administrator on 2016/2/29. */ public class LoginPresenter { private LoginViewIA mLoginViewIA; private LoginIA mLoginIA; public LoginPresenter(LoginViewIA mLoginViewIA) { this.mLoginViewIA = mLoginViewIA; this.mLoginIA = new LoginModel(); } public void login() {
final User user = mLoginViewIA.getInfo();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/view/MainActivity.java
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/BaseActivity.java // public class BaseActivity extends AppCompatActivity implements BaseViewIA { // /** // * 进度条 // */ // private ProgressDialog mProgressDialog; // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // mProgressDialog = new ProgressDialog(this); // mProgressDialog.setMessage("正在加载,请稍后.."); // } // // @Override // protected void onDestroy() { // super.onDestroy(); // } // // @Override // public void showProgressDialog() { // mProgressDialog.show(); // } // @Override // public void hideProgressDialog() { // mProgressDialog.hide(); // } // @Override // public void showError(String msg) { // Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); // } // } // // Path: app/src/main/java/com/example/app/rxjava/receiver/ConnectionReceiver.java // public class ConnectionReceiver extends BroadcastReceiver { // @Override // public void onReceive(Context context, Intent intent) { // if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { // ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // NetworkInfo info = conn.getActiveNetworkInfo(); // if (info != null) { // AppApplication.isNetConnect = info.isConnected(); // } else { // AppApplication.isNetConnect = false; // } // } // } // }
import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.ShareActionProvider; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Toast; import com.example.app.rxjava.AppApplication; import com.example.app.rxjava.R; import com.example.app.rxjava.base.BaseActivity; import com.example.app.rxjava.receiver.ConnectionReceiver;
package com.example.app.rxjava.module.main.view; public class MainActivity extends BaseActivity { private Context context = this;
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/BaseActivity.java // public class BaseActivity extends AppCompatActivity implements BaseViewIA { // /** // * 进度条 // */ // private ProgressDialog mProgressDialog; // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // mProgressDialog = new ProgressDialog(this); // mProgressDialog.setMessage("正在加载,请稍后.."); // } // // @Override // protected void onDestroy() { // super.onDestroy(); // } // // @Override // public void showProgressDialog() { // mProgressDialog.show(); // } // @Override // public void hideProgressDialog() { // mProgressDialog.hide(); // } // @Override // public void showError(String msg) { // Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); // } // } // // Path: app/src/main/java/com/example/app/rxjava/receiver/ConnectionReceiver.java // public class ConnectionReceiver extends BroadcastReceiver { // @Override // public void onReceive(Context context, Intent intent) { // if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { // ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // NetworkInfo info = conn.getActiveNetworkInfo(); // if (info != null) { // AppApplication.isNetConnect = info.isConnected(); // } else { // AppApplication.isNetConnect = false; // } // } // } // } // Path: app/src/main/java/com/example/app/rxjava/module/main/view/MainActivity.java import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.ShareActionProvider; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Toast; import com.example.app.rxjava.AppApplication; import com.example.app.rxjava.R; import com.example.app.rxjava.base.BaseActivity; import com.example.app.rxjava.receiver.ConnectionReceiver; package com.example.app.rxjava.module.main.view; public class MainActivity extends BaseActivity { private Context context = this;
private AppApplication application = null;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/widget/UILWidgetProvider.java
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // // Path: app/src/main/java/com/example/app/rxjava/widget/presenter/WidgetPresenter.java // public class WidgetPresenter { // private UILWidgetProvider widgetProvider; // private WidgetIA mWidgetIA; // private int totalNum; // // public WidgetPresenter(UILWidgetProvider widgetProvider) { // this.widgetProvider = widgetProvider; // this.mWidgetIA = new WidgetModel(); // } // // public void loadData() { // if (!AppApplication.isNetConnect) { // return; // } // mWidgetIA.getData() // .flatMap(new Func1<Picture, Observable<List<String>>>() { // @Override // public Observable<List<String>> call(Picture picture) { // totalNum = picture.getTotalNum(); // List<String> imgList = getImageList(picture); // return Observable.just(imgList); // } // }) // .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser // .doOnSubscribe(new Action0() { // @Override // public void call() { // // 需要在主线程执行 // } // }) // .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 // .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果 // .subscribe(new Subscriber<List<String>>() { // @Override // public void onNext(List<String> data) { // widgetProvider.getData(data); // } // // @Override // public void onError(Throwable e) { // // } // // @Override // public void onCompleted() { // // } // }); // } // // /** // * 得到网页中图片的地址 // */ // private List<String> getImageList(Picture picture) { // List<String> imgList = new ArrayList<String>(); // List<Data> list = picture.getData(); // for(int i = 0, len = list.size(); i < len; i++) { // imgList.add(list.get(i).getThumbnail_url()); // } // return imgList; // } // }
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.graphics.Bitmap; import android.view.View; import android.widget.RemoteViews; import com.example.app.rxjava.AppApplication; import com.example.app.rxjava.R; import com.example.app.rxjava.widget.presenter.WidgetPresenter; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.ImageSize; import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; import java.util.ArrayList; import java.util.List;
package com.example.app.rxjava.widget; /** * Example widget provider * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) */ public class UILWidgetProvider extends AppWidgetProvider { private static DisplayImageOptions displayOptions;
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // // Path: app/src/main/java/com/example/app/rxjava/widget/presenter/WidgetPresenter.java // public class WidgetPresenter { // private UILWidgetProvider widgetProvider; // private WidgetIA mWidgetIA; // private int totalNum; // // public WidgetPresenter(UILWidgetProvider widgetProvider) { // this.widgetProvider = widgetProvider; // this.mWidgetIA = new WidgetModel(); // } // // public void loadData() { // if (!AppApplication.isNetConnect) { // return; // } // mWidgetIA.getData() // .flatMap(new Func1<Picture, Observable<List<String>>>() { // @Override // public Observable<List<String>> call(Picture picture) { // totalNum = picture.getTotalNum(); // List<String> imgList = getImageList(picture); // return Observable.just(imgList); // } // }) // .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser // .doOnSubscribe(new Action0() { // @Override // public void call() { // // 需要在主线程执行 // } // }) // .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 // .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果 // .subscribe(new Subscriber<List<String>>() { // @Override // public void onNext(List<String> data) { // widgetProvider.getData(data); // } // // @Override // public void onError(Throwable e) { // // } // // @Override // public void onCompleted() { // // } // }); // } // // /** // * 得到网页中图片的地址 // */ // private List<String> getImageList(Picture picture) { // List<String> imgList = new ArrayList<String>(); // List<Data> list = picture.getData(); // for(int i = 0, len = list.size(); i < len; i++) { // imgList.add(list.get(i).getThumbnail_url()); // } // return imgList; // } // } // Path: app/src/main/java/com/example/app/rxjava/widget/UILWidgetProvider.java import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.graphics.Bitmap; import android.view.View; import android.widget.RemoteViews; import com.example.app.rxjava.AppApplication; import com.example.app.rxjava.R; import com.example.app.rxjava.widget.presenter.WidgetPresenter; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.ImageSize; import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; import java.util.ArrayList; import java.util.List; package com.example.app.rxjava.widget; /** * Example widget provider * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) */ public class UILWidgetProvider extends AppWidgetProvider { private static DisplayImageOptions displayOptions;
private WidgetPresenter presenter;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/widget/UILWidgetProvider.java
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // // Path: app/src/main/java/com/example/app/rxjava/widget/presenter/WidgetPresenter.java // public class WidgetPresenter { // private UILWidgetProvider widgetProvider; // private WidgetIA mWidgetIA; // private int totalNum; // // public WidgetPresenter(UILWidgetProvider widgetProvider) { // this.widgetProvider = widgetProvider; // this.mWidgetIA = new WidgetModel(); // } // // public void loadData() { // if (!AppApplication.isNetConnect) { // return; // } // mWidgetIA.getData() // .flatMap(new Func1<Picture, Observable<List<String>>>() { // @Override // public Observable<List<String>> call(Picture picture) { // totalNum = picture.getTotalNum(); // List<String> imgList = getImageList(picture); // return Observable.just(imgList); // } // }) // .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser // .doOnSubscribe(new Action0() { // @Override // public void call() { // // 需要在主线程执行 // } // }) // .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 // .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果 // .subscribe(new Subscriber<List<String>>() { // @Override // public void onNext(List<String> data) { // widgetProvider.getData(data); // } // // @Override // public void onError(Throwable e) { // // } // // @Override // public void onCompleted() { // // } // }); // } // // /** // * 得到网页中图片的地址 // */ // private List<String> getImageList(Picture picture) { // List<String> imgList = new ArrayList<String>(); // List<Data> list = picture.getData(); // for(int i = 0, len = list.size(); i < len; i++) { // imgList.add(list.get(i).getThumbnail_url()); // } // return imgList; // } // }
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.graphics.Bitmap; import android.view.View; import android.widget.RemoteViews; import com.example.app.rxjava.AppApplication; import com.example.app.rxjava.R; import com.example.app.rxjava.widget.presenter.WidgetPresenter; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.ImageSize; import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; import java.util.ArrayList; import java.util.List;
package com.example.app.rxjava.widget; /** * Example widget provider * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) */ public class UILWidgetProvider extends AppWidgetProvider { private static DisplayImageOptions displayOptions; private WidgetPresenter presenter; private UpdateWidgetListener listener; static { displayOptions = DisplayImageOptions.createSimple(); } @Override public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) { presenter = new WidgetPresenter(this); presenter.loadData();
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // // Path: app/src/main/java/com/example/app/rxjava/widget/presenter/WidgetPresenter.java // public class WidgetPresenter { // private UILWidgetProvider widgetProvider; // private WidgetIA mWidgetIA; // private int totalNum; // // public WidgetPresenter(UILWidgetProvider widgetProvider) { // this.widgetProvider = widgetProvider; // this.mWidgetIA = new WidgetModel(); // } // // public void loadData() { // if (!AppApplication.isNetConnect) { // return; // } // mWidgetIA.getData() // .flatMap(new Func1<Picture, Observable<List<String>>>() { // @Override // public Observable<List<String>> call(Picture picture) { // totalNum = picture.getTotalNum(); // List<String> imgList = getImageList(picture); // return Observable.just(imgList); // } // }) // .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser // .doOnSubscribe(new Action0() { // @Override // public void call() { // // 需要在主线程执行 // } // }) // .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 // .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果 // .subscribe(new Subscriber<List<String>>() { // @Override // public void onNext(List<String> data) { // widgetProvider.getData(data); // } // // @Override // public void onError(Throwable e) { // // } // // @Override // public void onCompleted() { // // } // }); // } // // /** // * 得到网页中图片的地址 // */ // private List<String> getImageList(Picture picture) { // List<String> imgList = new ArrayList<String>(); // List<Data> list = picture.getData(); // for(int i = 0, len = list.size(); i < len; i++) { // imgList.add(list.get(i).getThumbnail_url()); // } // return imgList; // } // } // Path: app/src/main/java/com/example/app/rxjava/widget/UILWidgetProvider.java import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.graphics.Bitmap; import android.view.View; import android.widget.RemoteViews; import com.example.app.rxjava.AppApplication; import com.example.app.rxjava.R; import com.example.app.rxjava.widget.presenter.WidgetPresenter; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.ImageSize; import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; import java.util.ArrayList; import java.util.List; package com.example.app.rxjava.widget; /** * Example widget provider * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) */ public class UILWidgetProvider extends AppWidgetProvider { private static DisplayImageOptions displayOptions; private WidgetPresenter presenter; private UpdateWidgetListener listener; static { displayOptions = DisplayImageOptions.createSimple(); } @Override public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) { presenter = new WidgetPresenter(this); presenter.loadData();
AppApplication.initImageLoader(context);
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/base/BaseListAdapter.java
// Path: app/src/main/java/com/example/app/rxjava/base/gesture/ItemTouchHelperAdapter.java // public interface ItemTouchHelperAdapter { // // /** // * Called when an item has been dragged far enough to trigger a move. This is called every time // * an item is shifted, and <strong>not</strong> at the end of a "drop" event.<br/> // * <br/> // * Implementations should call {@link RecyclerView.Adapter#notifyItemMoved(int, int)} after // * adjusting the underlying data to reflect this move. // * // * @param fromPosition The start position of the moved item. // * @param toPosition Then resolved position of the moved item. // * @return True if the item was moved to the new adapter position. // * // * @see RecyclerView#getAdapterPositionFor(RecyclerView.ViewHolder) // * @see RecyclerView.ViewHolder#getAdapterPosition() // */ // boolean onItemMove(int fromPosition, int toPosition); // // // /** // * Called when an item has been dismissed by a swipe.<br/> // * <br/> // * Implementations should call {@link RecyclerView.Adapter#notifyItemRemoved(int)} after // * adjusting the underlying data to reflect this removal. // * // * @param position The position of the item dismissed. // * // * @see RecyclerView#getAdapterPositionFor(RecyclerView.ViewHolder) // * @see RecyclerView.ViewHolder#getAdapterPosition() // */ // void onItemDismiss(int position); // } // // Path: app/src/main/java/com/example/app/rxjava/base/gesture/ItemTouchHelperViewHolder.java // public interface ItemTouchHelperViewHolder { // // /** // * Called when the {@link ItemTouchHelper} first registers an item as being moved or swiped. // * Implementations should update the item view to indicate it's active state. // */ // void onItemSelected(); // // // /** // * Called when the {@link ItemTouchHelper} has completed the move or swipe, and the active item // * state should be cleared. // */ // void onItemClear(); // }
import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.app.rxjava.R; import com.example.app.rxjava.base.gesture.ItemTouchHelperAdapter; import com.example.app.rxjava.base.gesture.ItemTouchHelperViewHolder; import java.util.Collections; import java.util.List;
return null; } @Override public boolean onItemMove(int fromPosition, int toPosition) { Collections.swap(mValues, fromPosition, toPosition); notifyItemMoved(fromPosition, toPosition); return true; } @Override public void onItemDismiss(int position) { mValues.remove(position); notifyItemRemoved(position); } @Override public int getItemCount() { return mValues.size(); } @Override public int getItemViewType(int position) { if (position >= 0) { return TYPE_ITEM0; } else { return TYPE_ITEM1; } }
// Path: app/src/main/java/com/example/app/rxjava/base/gesture/ItemTouchHelperAdapter.java // public interface ItemTouchHelperAdapter { // // /** // * Called when an item has been dragged far enough to trigger a move. This is called every time // * an item is shifted, and <strong>not</strong> at the end of a "drop" event.<br/> // * <br/> // * Implementations should call {@link RecyclerView.Adapter#notifyItemMoved(int, int)} after // * adjusting the underlying data to reflect this move. // * // * @param fromPosition The start position of the moved item. // * @param toPosition Then resolved position of the moved item. // * @return True if the item was moved to the new adapter position. // * // * @see RecyclerView#getAdapterPositionFor(RecyclerView.ViewHolder) // * @see RecyclerView.ViewHolder#getAdapterPosition() // */ // boolean onItemMove(int fromPosition, int toPosition); // // // /** // * Called when an item has been dismissed by a swipe.<br/> // * <br/> // * Implementations should call {@link RecyclerView.Adapter#notifyItemRemoved(int)} after // * adjusting the underlying data to reflect this removal. // * // * @param position The position of the item dismissed. // * // * @see RecyclerView#getAdapterPositionFor(RecyclerView.ViewHolder) // * @see RecyclerView.ViewHolder#getAdapterPosition() // */ // void onItemDismiss(int position); // } // // Path: app/src/main/java/com/example/app/rxjava/base/gesture/ItemTouchHelperViewHolder.java // public interface ItemTouchHelperViewHolder { // // /** // * Called when the {@link ItemTouchHelper} first registers an item as being moved or swiped. // * Implementations should update the item view to indicate it's active state. // */ // void onItemSelected(); // // // /** // * Called when the {@link ItemTouchHelper} has completed the move or swipe, and the active item // * state should be cleared. // */ // void onItemClear(); // } // Path: app/src/main/java/com/example/app/rxjava/base/BaseListAdapter.java import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.app.rxjava.R; import com.example.app.rxjava.base.gesture.ItemTouchHelperAdapter; import com.example.app.rxjava.base.gesture.ItemTouchHelperViewHolder; import java.util.Collections; import java.util.List; return null; } @Override public boolean onItemMove(int fromPosition, int toPosition) { Collections.swap(mValues, fromPosition, toPosition); notifyItemMoved(fromPosition, toPosition); return true; } @Override public void onItemDismiss(int position) { mValues.remove(position); notifyItemRemoved(position); } @Override public int getItemCount() { return mValues.size(); } @Override public int getItemViewType(int position) { if (position >= 0) { return TYPE_ITEM0; } else { return TYPE_ITEM1; } }
public class BaseItemViewHolder extends RecyclerView.ViewHolder implements ItemTouchHelperViewHolder {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // }
import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable;
package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WaterfallModel extends BaseModel implements WaterfallIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WaterfallModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder()
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WaterfallModel extends BaseModel implements WaterfallIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WaterfallModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder()
.registerTypeAdapter(new TypeToken<Picture>() {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // }
import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable;
package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WaterfallModel extends BaseModel implements WaterfallIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WaterfallModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<Picture>() { }.getType(),
// Path: app/src/main/java/com/example/app/rxjava/base/BaseModel.java // public class BaseModel { // public static final String API_SERVER = "服务器地址"; // private static volatile HttpLoggingInterceptor loggingInterceptor; // private static volatile RequestInterceptor requestInterceptor; // private static volatile CacheInterceptor cacheInterceptor; // private static volatile File httpCacheDirectory; // private static volatile Cache cache; // // OkHttp3.0的使用方式 // private static volatile OkHttpClient client; // // protected Retrofit.Builder getRetrofitBuilder() { // if (loggingInterceptor == null) { // synchronized (BaseModel.class) { // // Log信息 // loggingInterceptor = new HttpLoggingInterceptor(); // loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); // // // 拦截器,在请求中增加额外参数 // requestInterceptor = new RequestInterceptor(); // // // 缓存拦截器 // cacheInterceptor = new CacheInterceptor(); // //设置缓存路径 // httpCacheDirectory = new File(AppApplication.getInstance().getCacheDir(), "responses"); // //设置缓存大小 10M // cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); // client = new OkHttpClient.Builder() // .cookieJar(new CookiesManager()) // .addInterceptor(requestInterceptor) // .addInterceptor(loggingInterceptor) // .addInterceptor(cacheInterceptor) // .addNetworkInterceptor(cacheInterceptor) // .cache(cache) // .build(); // } // } // // // 适配器 // Retrofit.Builder builder = new Retrofit.Builder() // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .client(client); // return builder; // } // } // // Path: app/src/main/java/com/example/app/rxjava/base/ResultsDeserializer.java // public class ResultsDeserializer<T> implements JsonDeserializer<T> { // @Override // public T deserialize(JsonElement je, Type typeOfT, // JsonDeserializationContext context) throws JsonParseException { // // 转换Json的数据, 获取内部有用的信息 // JsonElement results = je.getAsJsonObject(); // return new Gson().fromJson(results, typeOfT); // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java import com.example.app.rxjava.base.BaseModel; import com.example.app.rxjava.base.ResultsDeserializer; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; package com.example.app.rxjava.module.main.model; /** * Created by Administrator on 2016/2/29. */ public class WaterfallModel extends BaseModel implements WaterfallIA { private static final String ENDPOINT = "http://image.baidu.com"; private final Service mService; public static final int ROWNUM = 30; public WaterfallModel() { // 对返回的数据进行解析 Gson gsonInstance = new GsonBuilder() .registerTypeAdapter(new TypeToken<Picture>() { }.getType(),
new ResultsDeserializer<Picture>())
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/user/presenter/UserPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/UserModel.java // public class UserModel implements UserIA { // public Observable<User> getUser() { // return Observable.create(new Observable.OnSubscribe<User>() { // @Override // public void call(Subscriber<? super User> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // // // final User user = null; // final User user = new User(); // user.setName("Smith"); // if (user == null) { // subscriber.onError(new Exception("User = null")); // } else { // subscriber.onNext(user); // subscriber.onCompleted(); // } // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/ia/UserIA.java // public interface UserIA { // public Observable<User> getUser(); // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/view/ia/UserViewIA.java // public interface UserViewIA extends BaseViewIA { // void updateView(User user); // }
import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.user.model.UserModel; import com.example.app.rxjava.module.user.model.ia.UserIA; import com.example.app.rxjava.module.user.view.ia.UserViewIA; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.user.presenter; /** * Created by Administrator on 2016/2/29. */ public class UserPresenter { private UserViewIA mUserViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/UserModel.java // public class UserModel implements UserIA { // public Observable<User> getUser() { // return Observable.create(new Observable.OnSubscribe<User>() { // @Override // public void call(Subscriber<? super User> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // // // final User user = null; // final User user = new User(); // user.setName("Smith"); // if (user == null) { // subscriber.onError(new Exception("User = null")); // } else { // subscriber.onNext(user); // subscriber.onCompleted(); // } // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/ia/UserIA.java // public interface UserIA { // public Observable<User> getUser(); // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/view/ia/UserViewIA.java // public interface UserViewIA extends BaseViewIA { // void updateView(User user); // } // Path: app/src/main/java/com/example/app/rxjava/module/user/presenter/UserPresenter.java import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.user.model.UserModel; import com.example.app.rxjava.module.user.model.ia.UserIA; import com.example.app.rxjava.module.user.view.ia.UserViewIA; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.user.presenter; /** * Created by Administrator on 2016/2/29. */ public class UserPresenter { private UserViewIA mUserViewIA;
private UserIA mUserIA;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/user/presenter/UserPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/UserModel.java // public class UserModel implements UserIA { // public Observable<User> getUser() { // return Observable.create(new Observable.OnSubscribe<User>() { // @Override // public void call(Subscriber<? super User> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // // // final User user = null; // final User user = new User(); // user.setName("Smith"); // if (user == null) { // subscriber.onError(new Exception("User = null")); // } else { // subscriber.onNext(user); // subscriber.onCompleted(); // } // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/ia/UserIA.java // public interface UserIA { // public Observable<User> getUser(); // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/view/ia/UserViewIA.java // public interface UserViewIA extends BaseViewIA { // void updateView(User user); // }
import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.user.model.UserModel; import com.example.app.rxjava.module.user.model.ia.UserIA; import com.example.app.rxjava.module.user.view.ia.UserViewIA; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.user.presenter; /** * Created by Administrator on 2016/2/29. */ public class UserPresenter { private UserViewIA mUserViewIA; private UserIA mUserIA; public UserPresenter(UserViewIA mUserViewIA) { this.mUserViewIA = mUserViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/UserModel.java // public class UserModel implements UserIA { // public Observable<User> getUser() { // return Observable.create(new Observable.OnSubscribe<User>() { // @Override // public void call(Subscriber<? super User> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // // // final User user = null; // final User user = new User(); // user.setName("Smith"); // if (user == null) { // subscriber.onError(new Exception("User = null")); // } else { // subscriber.onNext(user); // subscriber.onCompleted(); // } // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/ia/UserIA.java // public interface UserIA { // public Observable<User> getUser(); // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/view/ia/UserViewIA.java // public interface UserViewIA extends BaseViewIA { // void updateView(User user); // } // Path: app/src/main/java/com/example/app/rxjava/module/user/presenter/UserPresenter.java import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.user.model.UserModel; import com.example.app.rxjava.module.user.model.ia.UserIA; import com.example.app.rxjava.module.user.view.ia.UserViewIA; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.user.presenter; /** * Created by Administrator on 2016/2/29. */ public class UserPresenter { private UserViewIA mUserViewIA; private UserIA mUserIA; public UserPresenter(UserViewIA mUserViewIA) { this.mUserViewIA = mUserViewIA;
this.mUserIA = new UserModel();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/user/presenter/UserPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/UserModel.java // public class UserModel implements UserIA { // public Observable<User> getUser() { // return Observable.create(new Observable.OnSubscribe<User>() { // @Override // public void call(Subscriber<? super User> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // // // final User user = null; // final User user = new User(); // user.setName("Smith"); // if (user == null) { // subscriber.onError(new Exception("User = null")); // } else { // subscriber.onNext(user); // subscriber.onCompleted(); // } // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/ia/UserIA.java // public interface UserIA { // public Observable<User> getUser(); // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/view/ia/UserViewIA.java // public interface UserViewIA extends BaseViewIA { // void updateView(User user); // }
import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.user.model.UserModel; import com.example.app.rxjava.module.user.model.ia.UserIA; import com.example.app.rxjava.module.user.view.ia.UserViewIA; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.user.presenter; /** * Created by Administrator on 2016/2/29. */ public class UserPresenter { private UserViewIA mUserViewIA; private UserIA mUserIA; public UserPresenter(UserViewIA mUserViewIA) { this.mUserViewIA = mUserViewIA; this.mUserIA = new UserModel(); } public void getUser() { // 这里如果使用 Lambda 会更简洁 mUserIA.getUser() .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser .doOnSubscribe(new Action0() { @Override public void call() { mUserViewIA.showProgressDialog(); } }) .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果
// Path: app/src/main/java/com/example/app/rxjava/bean/User.java // public class User { // private String name; // private String password; // private String email; // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/UserModel.java // public class UserModel implements UserIA { // public Observable<User> getUser() { // return Observable.create(new Observable.OnSubscribe<User>() { // @Override // public void call(Subscriber<? super User> subscriber) { // // 设置个2000ms的延迟,模拟网络访问、数据库操作等等延时操作 // SystemClock.sleep(2000); // // // final User user = null; // final User user = new User(); // user.setName("Smith"); // if (user == null) { // subscriber.onError(new Exception("User = null")); // } else { // subscriber.onNext(user); // subscriber.onCompleted(); // } // } // }); // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/model/ia/UserIA.java // public interface UserIA { // public Observable<User> getUser(); // } // // Path: app/src/main/java/com/example/app/rxjava/module/user/view/ia/UserViewIA.java // public interface UserViewIA extends BaseViewIA { // void updateView(User user); // } // Path: app/src/main/java/com/example/app/rxjava/module/user/presenter/UserPresenter.java import com.example.app.rxjava.bean.User; import com.example.app.rxjava.module.user.model.UserModel; import com.example.app.rxjava.module.user.model.ia.UserIA; import com.example.app.rxjava.module.user.view.ia.UserViewIA; import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.user.presenter; /** * Created by Administrator on 2016/2/29. */ public class UserPresenter { private UserViewIA mUserViewIA; private UserIA mUserIA; public UserPresenter(UserViewIA mUserViewIA) { this.mUserViewIA = mUserViewIA; this.mUserIA = new UserModel(); } public void getUser() { // 这里如果使用 Lambda 会更简洁 mUserIA.getUser() .subscribeOn(Schedulers.io())// 在非UI线程中执行getUser .doOnSubscribe(new Action0() { @Override public void call() { mUserViewIA.showProgressDialog(); } }) .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果
.subscribe(new Subscriber<User>() {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/ChartPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/module/main/model/ChartModel.java // public class ChartModel extends BaseModel implements ChartIA { // private static final String ENDPOINT = "http://m.xueka.com"; // private final Service mService; // // public ChartModel() { // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(HtmlConverterFactory.create()) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<LineData> getServerData(int count, float range) { // mService.getData().flatMap(new Func1<String, Observable<?>>() { // @Override // public Observable<?> call(String data) { // Log.e("result", data); // return null; // } // }); // // ArrayList<String> xVals = new ArrayList<String>(); // for (int i = 0; i < count; i++) { // xVals.add((i) + ""); // } // // ArrayList<Entry> yVals = new ArrayList<Entry>(); // // for (int i = 0; i < count; i++) { // // float mult = (range + 1); // float val = (float) (Math.random() * mult) + 3;// + (float) // // ((mult * // // 0.1) / 10); // yVals.add(new Entry(val, i)); // } // // // create a dataset and give it a type // LineDataSet set1 = new LineDataSet(yVals, "DataSet 1"); // // set1.setFillAlpha(110); // // set1.setFillColor(Color.RED); // // // set the line to be drawn like this "- - - - - -" // set1.enableDashedLine(10f, 5f, 0f); // set1.enableDashedHighlightLine(10f, 5f, 0f); // set1.setColor(Color.BLACK); // set1.setCircleColor(Color.BLACK); // set1.setLineWidth(1f); // set1.setCircleRadius(3f); // set1.setDrawCircleHole(false); // set1.setValueTextSize(9f); // Drawable drawable = ContextCompat.getDrawable(AppApplication.getInstance(), R.drawable.fade_red); // set1.setFillDrawable(drawable); // set1.setDrawFilled(true); // // ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); // dataSets.add(set1); // add the datasets // // // create a data object with the datasets // LineData data = new LineData(xVals, dataSets); // return Observable.just(data); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/student/version.action") // Observable<String> getData(); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/ChartIA.java // public interface ChartIA { // public Observable<LineData> getServerData(int count, float range); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/ChartViewIA.java // public interface ChartViewIA extends BaseViewIA { // void refresh(LineData data); // }
import com.example.app.rxjava.module.main.model.ChartModel; import com.example.app.rxjava.module.main.model.ia.ChartIA; import com.example.app.rxjava.module.main.view.ia.ChartViewIA; import com.github.mikephil.charting.data.LineData; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class ChartPresenter { private ChartViewIA mChartViewIA;
// Path: app/src/main/java/com/example/app/rxjava/module/main/model/ChartModel.java // public class ChartModel extends BaseModel implements ChartIA { // private static final String ENDPOINT = "http://m.xueka.com"; // private final Service mService; // // public ChartModel() { // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(HtmlConverterFactory.create()) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<LineData> getServerData(int count, float range) { // mService.getData().flatMap(new Func1<String, Observable<?>>() { // @Override // public Observable<?> call(String data) { // Log.e("result", data); // return null; // } // }); // // ArrayList<String> xVals = new ArrayList<String>(); // for (int i = 0; i < count; i++) { // xVals.add((i) + ""); // } // // ArrayList<Entry> yVals = new ArrayList<Entry>(); // // for (int i = 0; i < count; i++) { // // float mult = (range + 1); // float val = (float) (Math.random() * mult) + 3;// + (float) // // ((mult * // // 0.1) / 10); // yVals.add(new Entry(val, i)); // } // // // create a dataset and give it a type // LineDataSet set1 = new LineDataSet(yVals, "DataSet 1"); // // set1.setFillAlpha(110); // // set1.setFillColor(Color.RED); // // // set the line to be drawn like this "- - - - - -" // set1.enableDashedLine(10f, 5f, 0f); // set1.enableDashedHighlightLine(10f, 5f, 0f); // set1.setColor(Color.BLACK); // set1.setCircleColor(Color.BLACK); // set1.setLineWidth(1f); // set1.setCircleRadius(3f); // set1.setDrawCircleHole(false); // set1.setValueTextSize(9f); // Drawable drawable = ContextCompat.getDrawable(AppApplication.getInstance(), R.drawable.fade_red); // set1.setFillDrawable(drawable); // set1.setDrawFilled(true); // // ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); // dataSets.add(set1); // add the datasets // // // create a data object with the datasets // LineData data = new LineData(xVals, dataSets); // return Observable.just(data); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/student/version.action") // Observable<String> getData(); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/ChartIA.java // public interface ChartIA { // public Observable<LineData> getServerData(int count, float range); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/ChartViewIA.java // public interface ChartViewIA extends BaseViewIA { // void refresh(LineData data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/ChartPresenter.java import com.example.app.rxjava.module.main.model.ChartModel; import com.example.app.rxjava.module.main.model.ia.ChartIA; import com.example.app.rxjava.module.main.view.ia.ChartViewIA; import com.github.mikephil.charting.data.LineData; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class ChartPresenter { private ChartViewIA mChartViewIA;
private ChartIA mChartIA;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/ChartPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/module/main/model/ChartModel.java // public class ChartModel extends BaseModel implements ChartIA { // private static final String ENDPOINT = "http://m.xueka.com"; // private final Service mService; // // public ChartModel() { // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(HtmlConverterFactory.create()) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<LineData> getServerData(int count, float range) { // mService.getData().flatMap(new Func1<String, Observable<?>>() { // @Override // public Observable<?> call(String data) { // Log.e("result", data); // return null; // } // }); // // ArrayList<String> xVals = new ArrayList<String>(); // for (int i = 0; i < count; i++) { // xVals.add((i) + ""); // } // // ArrayList<Entry> yVals = new ArrayList<Entry>(); // // for (int i = 0; i < count; i++) { // // float mult = (range + 1); // float val = (float) (Math.random() * mult) + 3;// + (float) // // ((mult * // // 0.1) / 10); // yVals.add(new Entry(val, i)); // } // // // create a dataset and give it a type // LineDataSet set1 = new LineDataSet(yVals, "DataSet 1"); // // set1.setFillAlpha(110); // // set1.setFillColor(Color.RED); // // // set the line to be drawn like this "- - - - - -" // set1.enableDashedLine(10f, 5f, 0f); // set1.enableDashedHighlightLine(10f, 5f, 0f); // set1.setColor(Color.BLACK); // set1.setCircleColor(Color.BLACK); // set1.setLineWidth(1f); // set1.setCircleRadius(3f); // set1.setDrawCircleHole(false); // set1.setValueTextSize(9f); // Drawable drawable = ContextCompat.getDrawable(AppApplication.getInstance(), R.drawable.fade_red); // set1.setFillDrawable(drawable); // set1.setDrawFilled(true); // // ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); // dataSets.add(set1); // add the datasets // // // create a data object with the datasets // LineData data = new LineData(xVals, dataSets); // return Observable.just(data); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/student/version.action") // Observable<String> getData(); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/ChartIA.java // public interface ChartIA { // public Observable<LineData> getServerData(int count, float range); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/ChartViewIA.java // public interface ChartViewIA extends BaseViewIA { // void refresh(LineData data); // }
import com.example.app.rxjava.module.main.model.ChartModel; import com.example.app.rxjava.module.main.model.ia.ChartIA; import com.example.app.rxjava.module.main.view.ia.ChartViewIA; import com.github.mikephil.charting.data.LineData; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class ChartPresenter { private ChartViewIA mChartViewIA; private ChartIA mChartIA; public ChartPresenter(ChartViewIA mChartViewIA) { this.mChartViewIA = mChartViewIA;
// Path: app/src/main/java/com/example/app/rxjava/module/main/model/ChartModel.java // public class ChartModel extends BaseModel implements ChartIA { // private static final String ENDPOINT = "http://m.xueka.com"; // private final Service mService; // // public ChartModel() { // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(HtmlConverterFactory.create()) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<LineData> getServerData(int count, float range) { // mService.getData().flatMap(new Func1<String, Observable<?>>() { // @Override // public Observable<?> call(String data) { // Log.e("result", data); // return null; // } // }); // // ArrayList<String> xVals = new ArrayList<String>(); // for (int i = 0; i < count; i++) { // xVals.add((i) + ""); // } // // ArrayList<Entry> yVals = new ArrayList<Entry>(); // // for (int i = 0; i < count; i++) { // // float mult = (range + 1); // float val = (float) (Math.random() * mult) + 3;// + (float) // // ((mult * // // 0.1) / 10); // yVals.add(new Entry(val, i)); // } // // // create a dataset and give it a type // LineDataSet set1 = new LineDataSet(yVals, "DataSet 1"); // // set1.setFillAlpha(110); // // set1.setFillColor(Color.RED); // // // set the line to be drawn like this "- - - - - -" // set1.enableDashedLine(10f, 5f, 0f); // set1.enableDashedHighlightLine(10f, 5f, 0f); // set1.setColor(Color.BLACK); // set1.setCircleColor(Color.BLACK); // set1.setLineWidth(1f); // set1.setCircleRadius(3f); // set1.setDrawCircleHole(false); // set1.setValueTextSize(9f); // Drawable drawable = ContextCompat.getDrawable(AppApplication.getInstance(), R.drawable.fade_red); // set1.setFillDrawable(drawable); // set1.setDrawFilled(true); // // ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); // dataSets.add(set1); // add the datasets // // // create a data object with the datasets // LineData data = new LineData(xVals, dataSets); // return Observable.just(data); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/student/version.action") // Observable<String> getData(); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/ChartIA.java // public interface ChartIA { // public Observable<LineData> getServerData(int count, float range); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/ChartViewIA.java // public interface ChartViewIA extends BaseViewIA { // void refresh(LineData data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/ChartPresenter.java import com.example.app.rxjava.module.main.model.ChartModel; import com.example.app.rxjava.module.main.model.ia.ChartIA; import com.example.app.rxjava.module.main.view.ia.ChartViewIA; import com.github.mikephil.charting.data.LineData; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class ChartPresenter { private ChartViewIA mChartViewIA; private ChartIA mChartIA; public ChartPresenter(ChartViewIA mChartViewIA) { this.mChartViewIA = mChartViewIA;
this.mChartIA = new ChartModel();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/base/interceptor/CacheInterceptor.java
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // }
import com.example.app.rxjava.AppApplication; import java.io.IOException; import java.util.logging.Logger; import okhttp3.CacheControl; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response;
package com.example.app.rxjava.base.interceptor; /** * Created by Administrator on 2016/3/4. */ /** * 有网络时,发起网络请求 * 无网络时先从缓存中取值,如果缓存时间超过4周,则发起网络请求 * <p> * */ public class CacheInterceptor implements Interceptor { //private int maxAge = 0;// 有网络时 设置缓存超时时间0秒 private int maxStale = 60 * 60 * 24 * 28;// 无网络时,设置超时为4周 public CacheInterceptor() { } @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request();
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java // public class AppApplication extends Application { // // /*网络是否连接*/ // public static boolean isNetConnect;/*网络连接状态监听*/ // private ConnectionReceiver connectionReceiver = new ConnectionReceiver(); // public static AppApplication APP_APPLICATION; // // //刷新广播监听 // public static final String REFRESH_ACTION = "REFRESH_ACTION"; // // public static AppApplication getInstance() { // return APP_APPLICATION; // } // // @Override // public void onCreate() { // super.onCreate(); // // Create global configuration and initialize ImageLoader with this config // APP_APPLICATION = this; // initImageLoader(getApplicationContext()); // registerNetReceiver(); // // FlowManager.init(this); // } // // public static void initImageLoader(Context context) { // // This configuration tuning is custom. You can tune every option, you may tune some of them, // // or you can create default configuration by // // ImageLoaderConfiguration.createDefault(this); // // method. // ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); // config.threadPriority(Thread.NORM_PRIORITY - 2); // config.denyCacheImageMultipleSizesInMemory(); // config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); // config.diskCacheSize(50 * 1024 * 1024); // 50 MiB // config.tasksProcessingOrder(QueueProcessingType.LIFO); // config.writeDebugLogs(); // Remove for release app // // // Initialize ImageLoader with configuration. // ImageLoader.getInstance().init(config.build()); // } // // /** // * 注册网络连接状态监听 // */ // public void registerNetReceiver() { // IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); // registerReceiver(connectionReceiver, connectionIntentFilter); // } // // /** // * 注销网络连接状态监听 // */ // public void unregisterNetReceiver() { // if (connectionReceiver != null) { // unregisterReceiver(connectionReceiver); // } // } // } // Path: app/src/main/java/com/example/app/rxjava/base/interceptor/CacheInterceptor.java import com.example.app.rxjava.AppApplication; import java.io.IOException; import java.util.logging.Logger; import okhttp3.CacheControl; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; package com.example.app.rxjava.base.interceptor; /** * Created by Administrator on 2016/3/4. */ /** * 有网络时,发起网络请求 * 无网络时先从缓存中取值,如果缓存时间超过4周,则发起网络请求 * <p> * */ public class CacheInterceptor implements Interceptor { //private int maxAge = 0;// 有网络时 设置缓存超时时间0秒 private int maxStale = 60 * 60 * 24 * 28;// 无网络时,设置超时为4周 public CacheInterceptor() { } @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request();
if(!AppApplication.isNetConnect){
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // }
import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WaterfallPresenter { private WaterfallViewIA mWaterfallViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WaterfallPresenter { private WaterfallViewIA mWaterfallViewIA;
private WaterfallIA mWaterfallIA;
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // }
import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WaterfallPresenter { private WaterfallViewIA mWaterfallViewIA; private WaterfallIA mWaterfallIA; private int totalNum; public WaterfallPresenter(WaterfallViewIA mWaterfallViewIA) { this.mWaterfallViewIA = mWaterfallViewIA;
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WaterfallPresenter { private WaterfallViewIA mWaterfallViewIA; private WaterfallIA mWaterfallIA; private int totalNum; public WaterfallPresenter(WaterfallViewIA mWaterfallViewIA) { this.mWaterfallViewIA = mWaterfallViewIA;
this.mWaterfallIA = new WaterfallModel();
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // }
import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers;
package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WaterfallPresenter { private WaterfallViewIA mWaterfallViewIA; private WaterfallIA mWaterfallIA; private int totalNum; public WaterfallPresenter(WaterfallViewIA mWaterfallViewIA) { this.mWaterfallViewIA = mWaterfallViewIA; this.mWaterfallIA = new WaterfallModel(); } public void loadData(final int pageNum) { if(pageNum > 0 && pageNum * WaterfallModel.ROWNUM >= totalNum) { return; } mWaterfallIA.getServerData(pageNum)
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers; package com.example.app.rxjava.module.main.presenter; /** * Created by Administrator on 2016/2/29. */ public class WaterfallPresenter { private WaterfallViewIA mWaterfallViewIA; private WaterfallIA mWaterfallIA; private int totalNum; public WaterfallPresenter(WaterfallViewIA mWaterfallViewIA) { this.mWaterfallViewIA = mWaterfallViewIA; this.mWaterfallIA = new WaterfallModel(); } public void loadData(final int pageNum) { if(pageNum > 0 && pageNum * WaterfallModel.ROWNUM >= totalNum) { return; } mWaterfallIA.getServerData(pageNum)
.flatMap(new Func1<Picture, Observable<List<String>>>() {
zhaoyangzhou/RXJava
app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // }
import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers;
.subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果 .subscribe(new Subscriber<List<String>>() { @Override public void onNext(List<String> data) { if(pageNum == 0) { mWaterfallViewIA.refresh(data); } else { mWaterfallViewIA.loadNews(data); } } @Override public void onError(Throwable e) { mWaterfallViewIA.showError(e.getMessage()); mWaterfallViewIA.hideProgressDialog(); } @Override public void onCompleted() { mWaterfallViewIA.hideProgressDialog(); } }); } /** * 得到网页中图片的地址 */ public List<String> getImageList(Picture picture) { List<String> imgList = new ArrayList<String>();
// Path: app/src/main/java/com/example/app/rxjava/bean/picture/Data.java // public class Data { // private String id; // private String setId; // private int pn; // private String thumbnail_url; // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getSetId() { // return setId; // } // // public void setSetId(String setId) { // this.setId = setId; // } // // public int getPn() { // return pn; // } // // public void setPn(int pn) { // this.pn = pn; // } // // public String getThumbnail_url() { // return thumbnail_url; // } // // public void setThumbnail_url(String thumbnail_url) { // this.thumbnail_url = thumbnail_url; // } // } // // Path: app/src/main/java/com/example/app/rxjava/bean/picture/Picture.java // public class Picture { // private String tag1; // private String tag2; // private int totalNum; // private int start_index; // private int return_number; // private List<Data> data; // // public String getTag1() { // return tag1; // } // // public void setTag1(String tag1) { // this.tag1 = tag1; // } // // public String getTag2() { // return tag2; // } // // public void setTag2(String tag2) { // this.tag2 = tag2; // } // // public int getTotalNum() { // return totalNum; // } // // public void setTotalNum(int totalNum) { // this.totalNum = totalNum; // } // // public int getStart_index() { // return start_index; // } // // public void setStart_index(int start_index) { // this.start_index = start_index; // } // // public int getReturn_number() { // return return_number; // } // // public void setReturn_number(int return_number) { // this.return_number = return_number; // } // // public List<Data> getData() { // return data; // } // // public void setData(List<Data> data) { // this.data = data; // } // // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/WaterfallModel.java // public class WaterfallModel extends BaseModel implements WaterfallIA { // private static final String ENDPOINT = "http://image.baidu.com"; // private final Service mService; // // public static final int ROWNUM = 30; // // public WaterfallModel() { // // 对返回的数据进行解析 // Gson gsonInstance = new GsonBuilder() // .registerTypeAdapter(new TypeToken<Picture>() { // }.getType(), // new ResultsDeserializer<Picture>()) // .create(); // // // 适配器 // Retrofit mRetrofit = getRetrofitBuilder() // .baseUrl(ENDPOINT) // .addConverterFactory(GsonConverterFactory.create(gsonInstance)) // .build(); // // // 服务 // mService = mRetrofit.create(Service.class); // } // // @Override // public Observable<Picture> getServerData(int pageNum) { // return mService.getData(pageNum, ROWNUM, "宠物", "全部"); // } // // /** // * 服务接口 // */ // private interface Service { // // @GET("/channel/listjson") // Observable<Picture> getData(@Query("pn") int pn, @Query("rn") int rn, @Query("tag1") String tag1, @Query("tag2") String tag2); // // } // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/model/ia/WaterfallIA.java // public interface WaterfallIA { // public Observable<Picture> getServerData(int pageNum); // } // // Path: app/src/main/java/com/example/app/rxjava/module/main/view/ia/WaterfallViewIA.java // public interface WaterfallViewIA extends BaseViewIA { // void refresh(List<String> data); // void loadNews(List<String> data); // } // Path: app/src/main/java/com/example/app/rxjava/module/main/presenter/WaterfallPresenter.java import com.example.app.rxjava.bean.picture.Data; import com.example.app.rxjava.bean.picture.Picture; import com.example.app.rxjava.module.main.model.WaterfallModel; import com.example.app.rxjava.module.main.model.ia.WaterfallIA; import com.example.app.rxjava.module.main.view.ia.WaterfallViewIA; import java.util.ArrayList; import java.util.List; import rx.Observable; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action0; import rx.functions.Func1; import rx.schedulers.Schedulers; .subscribeOn(AndroidSchedulers.mainThread()) // 指定主线程 .observeOn(AndroidSchedulers.mainThread())// 在UI线程中执行结果 .subscribe(new Subscriber<List<String>>() { @Override public void onNext(List<String> data) { if(pageNum == 0) { mWaterfallViewIA.refresh(data); } else { mWaterfallViewIA.loadNews(data); } } @Override public void onError(Throwable e) { mWaterfallViewIA.showError(e.getMessage()); mWaterfallViewIA.hideProgressDialog(); } @Override public void onCompleted() { mWaterfallViewIA.hideProgressDialog(); } }); } /** * 得到网页中图片的地址 */ public List<String> getImageList(Picture picture) { List<String> imgList = new ArrayList<String>();
List<Data> list = picture.getData();
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/details/ChapterGridAdapter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // }
import moe.yukinoneko.gcomic.database.model.ReadHistoryModel; import android.content.Context; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.data.ComicData;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/7. */ public class ChapterGridAdapter extends RecyclerView.Adapter<ChapterGridAdapter.ViewHolder> { private final String TAG = "ChapterGridAdapter"; private Context mContext; private LayoutInflater mInflater;
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/details/ChapterGridAdapter.java import moe.yukinoneko.gcomic.database.model.ReadHistoryModel; import android.content.Context; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.data.ComicData; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/7. */ public class ChapterGridAdapter extends RecyclerView.Adapter<ChapterGridAdapter.ViewHolder> { private final String TAG = "ChapterGridAdapter"; private Context mContext; private LayoutInflater mInflater;
private List<ComicData.ChaptersBean.ChapterBean> mData;
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/details/ChapterGridAdapter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // }
import moe.yukinoneko.gcomic.database.model.ReadHistoryModel; import android.content.Context; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.data.ComicData;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/7. */ public class ChapterGridAdapter extends RecyclerView.Adapter<ChapterGridAdapter.ViewHolder> { private final String TAG = "ChapterGridAdapter"; private Context mContext; private LayoutInflater mInflater; private List<ComicData.ChaptersBean.ChapterBean> mData; private List<Integer> mDownloadedChapters;
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/details/ChapterGridAdapter.java import moe.yukinoneko.gcomic.database.model.ReadHistoryModel; import android.content.Context; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.data.ComicData; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/7. */ public class ChapterGridAdapter extends RecyclerView.Adapter<ChapterGridAdapter.ViewHolder> { private final String TAG = "ChapterGridAdapter"; private Context mContext; private LayoutInflater mInflater; private List<ComicData.ChaptersBean.ChapterBean> mData; private List<Integer> mDownloadedChapters;
private ReadHistoryModel mReadHistory;
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/classify/ClassifyPresenter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // }
import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.classify; /** * Created by SamuelGjk on 2016/4/18. */ public class ClassifyPresenter extends BasePresenter<IClassifyView> { public ClassifyPresenter(Context context, IClassifyView iView) { super(context, iView); } void fetchClassifyData(int tagId, int page) { Subscription subscription = GComicApi.getInstance() .fetchClassifyData(tagId, page) .observeOn(AndroidSchedulers.mainThread())
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/classify/ClassifyPresenter.java import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.classify; /** * Created by SamuelGjk on 2016/4/18. */ public class ClassifyPresenter extends BasePresenter<IClassifyView> { public ClassifyPresenter(Context context, IClassifyView iView) { super(context, iView); } void fetchClassifyData(int tagId, int page) { Subscription subscription = GComicApi.getInstance() .fetchClassifyData(tagId, page) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<ClassifyData>>() {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/about/AboutActivity.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/Utils.java // public class Utils { // // public static float dp2px(Context context, float dp) { // return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); // } // // public static String getFirstCharacter(String str) { // return str.substring(0, 1); // } // // public static int getNavigationBarHeight(Context context) { // Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); // DisplayMetrics dm1 = new DisplayMetrics(); // display.getMetrics(dm1); // // DisplayMetrics dm2 = new DisplayMetrics(); // if (Build.VERSION.SDK_INT >= 17) { // display.getRealMetrics(dm2); // } else { // try { // Class c = Class.forName("android.view.Display"); // Method method = c.getMethod("getRealMetrics", DisplayMetrics.class); // method.invoke(display, dm2); // } catch (Exception e) { // e.printStackTrace(); // } // } // // return dm2.heightPixels - dm1.heightPixels; // } // // /** // * 判断网络是否连接 // */ // public static boolean isConnected(Context context) { // ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // // if (null != cm) { // NetworkInfo info = cm.getActiveNetworkInfo(); // if (null != info && info.isConnected()) { // return true; // } // } // return false; // } // // /** // * 判断是否是 wifi 连接 // */ // public static boolean isWifi(Context context) { // ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // // return null != cm && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI; // } // // public static String getVersionName(Context context) { // try { // PackageManager packageManager = context.getPackageManager(); // PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); // return packageInfo.versionName; // // } catch (PackageManager.NameNotFoundException e) { // e.printStackTrace(); // } // return "unknown"; // } // // public static boolean isNightMode(Context context) { // int uiMode = context.getResources().getConfiguration().uiMode; // int dayNightUiMode = uiMode & Configuration.UI_MODE_NIGHT_MASK; // // return dayNightUiMode == Configuration.UI_MODE_NIGHT_YES; // } // }
import android.support.v7.widget.AppCompatTextView; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.utils.Utils;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.about; /** * Created by SamuelGjk on 2016/5/30. */ public class AboutActivity extends ToolBarActivity<AboutPresenter> implements IBaseView { @BindView(R.id.text_app_version) AppCompatTextView textAppVersion; @Override protected int provideContentViewId() { return R.layout.activity_about; } @Override protected void initPresenter() { presenter = new AboutPresenter(this, this); presenter.init(); } @Override public void init() {
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/Utils.java // public class Utils { // // public static float dp2px(Context context, float dp) { // return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); // } // // public static String getFirstCharacter(String str) { // return str.substring(0, 1); // } // // public static int getNavigationBarHeight(Context context) { // Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); // DisplayMetrics dm1 = new DisplayMetrics(); // display.getMetrics(dm1); // // DisplayMetrics dm2 = new DisplayMetrics(); // if (Build.VERSION.SDK_INT >= 17) { // display.getRealMetrics(dm2); // } else { // try { // Class c = Class.forName("android.view.Display"); // Method method = c.getMethod("getRealMetrics", DisplayMetrics.class); // method.invoke(display, dm2); // } catch (Exception e) { // e.printStackTrace(); // } // } // // return dm2.heightPixels - dm1.heightPixels; // } // // /** // * 判断网络是否连接 // */ // public static boolean isConnected(Context context) { // ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // // if (null != cm) { // NetworkInfo info = cm.getActiveNetworkInfo(); // if (null != info && info.isConnected()) { // return true; // } // } // return false; // } // // /** // * 判断是否是 wifi 连接 // */ // public static boolean isWifi(Context context) { // ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // // return null != cm && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI; // } // // public static String getVersionName(Context context) { // try { // PackageManager packageManager = context.getPackageManager(); // PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); // return packageInfo.versionName; // // } catch (PackageManager.NameNotFoundException e) { // e.printStackTrace(); // } // return "unknown"; // } // // public static boolean isNightMode(Context context) { // int uiMode = context.getResources().getConfiguration().uiMode; // int dayNightUiMode = uiMode & Configuration.UI_MODE_NIGHT_MASK; // // return dayNightUiMode == Configuration.UI_MODE_NIGHT_YES; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/about/AboutActivity.java import android.support.v7.widget.AppCompatTextView; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.utils.Utils; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.about; /** * Created by SamuelGjk on 2016/5/30. */ public class AboutActivity extends ToolBarActivity<AboutPresenter> implements IBaseView { @BindView(R.id.text_app_version) AppCompatTextView textAppVersion; @Override protected int provideContentViewId() { return R.layout.activity_about; } @Override protected void initPresenter() { presenter = new AboutPresenter(this, this); presenter.init(); } @Override public void init() {
textAppVersion.setText(getString(R.string.app_version, Utils.getVersionName(this)));
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/search/SearchPresenter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // }
import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.SearchData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.search; /** * Created by SamuelGjk on 2016/4/18. */ public class SearchPresenter extends BasePresenter<ISearchView> { public SearchPresenter(Context context, ISearchView iView) { super(context, iView); } void search(String keyword, int page) { Subscription subscription = GComicApi.getInstance() .search(keyword, page) .observeOn(AndroidSchedulers.mainThread())
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/search/SearchPresenter.java import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.SearchData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.search; /** * Created by SamuelGjk on 2016/4/18. */ public class SearchPresenter extends BasePresenter<ISearchView> { public SearchPresenter(Context context, ISearchView iView) { super(context, iView); } void search(String keyword, int page) { Subscription subscription = GComicApi.getInstance() .search(keyword, page) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<SearchData>>() {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/details/IComicDetailsView.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // }
import moe.yukinoneko.gcomic.data.ComicData; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.database.model.ReadHistoryModel;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/19. */ public interface IComicDetailsView extends IBaseView { void showMessageSnackbar(String message);
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/details/IComicDetailsView.java import moe.yukinoneko.gcomic.data.ComicData; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.database.model.ReadHistoryModel; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/19. */ public interface IComicDetailsView extends IBaseView { void showMessageSnackbar(String message);
void updateComicDetailsContent(ComicData comicData);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/details/IComicDetailsView.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // }
import moe.yukinoneko.gcomic.data.ComicData; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.database.model.ReadHistoryModel;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/19. */ public interface IComicDetailsView extends IBaseView { void showMessageSnackbar(String message); void updateComicDetailsContent(ComicData comicData); void updateFavoriteMenu(boolean isFavorite);
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java // public class ComicData { // public int id; // public String islong; // public int direction; // public String title; // @Json(name = "is_dmzj") public int isDmzj; // public String cover; // public String description; // @Json(name = "last_updatetime") public int lastUpdatetime; // public int copyright; // @Json(name = "first_letter") public String firstLetter; // @Json(name = "hot_num") public int hotNum; // public Object uid; // @Json(name = "subscribe_num") public int subscribeNum; // public CommentBean comment; // public List<TypesBean> types; // public List<AuthorsBean> authors; // public List<StatusBean> status; // public List<ChaptersBean> chapters; // // public List<Integer> downloadedChapters = new ArrayList<>(); // // public ReadHistoryModel readHistory; // // public static class CommentBean { // @Json(name = "comment_count") public int commentCount; // @Json(name = "latest_comment") public List<LatestCommentBean> latestComment; // // public static class LatestCommentBean { // @Json(name = "comment_id") public int commentId; // public int uid; // public String content; // public int createtime; // public String nickname; // @Json(name = "avatar_url") public String avatarUrl; // } // } // // public static class TypesBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class AuthorsBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class StatusBean { // @Json(name = "tag_id") public int tagId; // @Json(name = "tag_name") public String tagName; // } // // public static class ChaptersBean { // public String title; // public List<ChapterBean> data; // // public static class ChapterBean implements Parcelable { // @Json(name = "chapter_id") public int chapterId; // @Json(name = "chapter_title") public String chapterTitle; // public int updatetime; // public long filesize; // @Json(name = "chapter_order") public int chapterOrder; // // public boolean isDownloaded; // // public ChapterBean() { // // } // // protected ChapterBean(Parcel in) { // chapterId = in.readInt(); // chapterTitle = in.readString(); // updatetime = in.readInt(); // filesize = in.readLong(); // chapterOrder = in.readInt(); // } // // public static final Creator<ChapterBean> CREATOR = new Creator<ChapterBean>() { // @Override // public ChapterBean createFromParcel(Parcel in) { // return new ChapterBean(in); // } // // @Override // public ChapterBean[] newArray(int size) { // return new ChapterBean[size]; // } // }; // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(chapterId); // dest.writeString(chapterTitle); // dest.writeInt(updatetime); // dest.writeLong(filesize); // dest.writeInt(chapterOrder); // } // } // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/details/IComicDetailsView.java import moe.yukinoneko.gcomic.data.ComicData; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.database.model.ReadHistoryModel; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.details; /** * Created by SamuelGjk on 2016/4/19. */ public interface IComicDetailsView extends IBaseView { void showMessageSnackbar(String message); void updateComicDetailsContent(ComicData comicData); void updateFavoriteMenu(boolean isFavorite);
void updateReadHistory(ReadHistoryModel history);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/download/DownloadedComicActivity.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/DownloadTaskModel.java // @Table("gcomic_download") // public class DownloadTaskModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int id; // // public int comicId; // public String comicTitle; // public String comicCover; // // public int chapterId; // public String chapterTitle; // // public String firstLetter; // // public int position; // public int chaptersSize; // // public String url; // public String path; // // public DownloadTaskModel(int id, int comicId, String comicTitle, String comicCover, int chapterId, String chapterTitle, String firstLetter, int position, int chaptersSize, String url, String path) { // this.id = id; // this.comicId = comicId; // this.comicTitle = comicTitle; // this.comicCover = comicCover; // this.chapterId = chapterId; // this.chapterTitle = chapterTitle; // this.firstLetter = firstLetter; // this.position = position; // this.chaptersSize = chaptersSize; // this.url = url; // this.path = path; // } // }
import android.content.Intent; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.database.model.DownloadTaskModel;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.download; /** * Created by SamuelGjk on 2016/5/13. */ public class DownloadedComicActivity extends ToolBarActivity<DownloadedComicPresenter> implements IDownloadedComicView { public static final String TAG = "DownloadedComicActivity"; static final int REQUEST_CODE_DOWNLOADED_COMIC = 10001; @BindView(R.id.downloaded_comic_grid) RecyclerView downloadedComicGrid; private DownloadedComicGridAdapter mAdapter; @Override protected int provideContentViewId() { return R.layout.activity_downloaded_comic; } @Override protected void initPresenter() { presenter = new DownloadedComicPresenter(this, this); presenter.init(); } @Override public void init() { mToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { downloadedComicGrid.smoothScrollToPosition(0); } }); downloadedComicGrid.setHasFixedSize(true); mAdapter = new DownloadedComicGridAdapter(this); downloadedComicGrid.setAdapter(mAdapter); presenter.fetchDownloadedComic(); } @Override
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/DownloadTaskModel.java // @Table("gcomic_download") // public class DownloadTaskModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int id; // // public int comicId; // public String comicTitle; // public String comicCover; // // public int chapterId; // public String chapterTitle; // // public String firstLetter; // // public int position; // public int chaptersSize; // // public String url; // public String path; // // public DownloadTaskModel(int id, int comicId, String comicTitle, String comicCover, int chapterId, String chapterTitle, String firstLetter, int position, int chaptersSize, String url, String path) { // this.id = id; // this.comicId = comicId; // this.comicTitle = comicTitle; // this.comicCover = comicCover; // this.chapterId = chapterId; // this.chapterTitle = chapterTitle; // this.firstLetter = firstLetter; // this.position = position; // this.chaptersSize = chaptersSize; // this.url = url; // this.path = path; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/download/DownloadedComicActivity.java import android.content.Intent; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.database.model.DownloadTaskModel; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.download; /** * Created by SamuelGjk on 2016/5/13. */ public class DownloadedComicActivity extends ToolBarActivity<DownloadedComicPresenter> implements IDownloadedComicView { public static final String TAG = "DownloadedComicActivity"; static final int REQUEST_CODE_DOWNLOADED_COMIC = 10001; @BindView(R.id.downloaded_comic_grid) RecyclerView downloadedComicGrid; private DownloadedComicGridAdapter mAdapter; @Override protected int provideContentViewId() { return R.layout.activity_downloaded_comic; } @Override protected void initPresenter() { presenter = new DownloadedComicPresenter(this, this); presenter.init(); } @Override public void init() { mToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { downloadedComicGrid.smoothScrollToPosition(0); } }); downloadedComicGrid.setHasFixedSize(true); mAdapter = new DownloadedComicGridAdapter(this); downloadedComicGrid.setAdapter(mAdapter); presenter.fetchDownloadedComic(); } @Override
public void updateDownloadedComicList(List<DownloadTaskModel> comics) {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/main/SearchSuggestionsAdapter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/SearchHistoryModel.java // @Table("gcomic_search_history") // public class SearchHistoryModel { // @PrimaryKey(AssignType.BY_MYSELF) // public int _id; // // public String keyword; // // public SearchHistoryModel(int _id, String keyword) { // this._id = _id; // this.keyword = keyword; // } // }
import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.database.model.SearchHistoryModel; import android.content.Context; import android.support.v7.widget.AppCompatImageButton; import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main; /** * Created by SamuelGjk on 2016/5/30. */ public class SearchSuggestionsAdapter extends RecyclerView.Adapter<SearchSuggestionsAdapter.ViewHolder> { private LayoutInflater mInflater;
// Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/SearchHistoryModel.java // @Table("gcomic_search_history") // public class SearchHistoryModel { // @PrimaryKey(AssignType.BY_MYSELF) // public int _id; // // public String keyword; // // public SearchHistoryModel(int _id, String keyword) { // this._id = _id; // this.keyword = keyword; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/main/SearchSuggestionsAdapter.java import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.database.model.SearchHistoryModel; import android.content.Context; import android.support.v7.widget.AppCompatImageButton; import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main; /** * Created by SamuelGjk on 2016/5/30. */ public class SearchSuggestionsAdapter extends RecyclerView.Adapter<SearchSuggestionsAdapter.ViewHolder> { private LayoutInflater mInflater;
private List<SearchHistoryModel> mData;
SamuelGjk/GComic
FloatingSearchView/src/main/java/com/mypopsy/widget/FloatingSearchView.java
// Path: FloatingSearchView/src/main/java/com/mypopsy/widget/internal/ViewUtils.java // public class ViewUtils { // private static final int[] TEMP_ARRAY = new int[1]; // // public static void showSoftKeyboardDelayed(final EditText editText, long delay) { // editText.postDelayed(new Runnable() { // @Override // public void run() { // InputMethodManager inputMethodManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); // inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); // } // }, delay); // } // // public static void closeSoftKeyboard(Activity activity) { // View currentFocusView = activity.getCurrentFocus(); // if (currentFocusView != null) { // InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); // imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0); // } // } // // public static int dpToPx(int dp) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // return (int) (dp * metrics.density); // } // // public static int pxToDp(int px) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // return (int) (px / metrics.density); // } // // public static int getThemeAttrColor(Context context, @AttrRes int attr) { // TEMP_ARRAY[0] = attr; // TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); // try { // return a.getColor(0, 0); // } finally { // a.recycle(); // } // } // // public static Drawable getTinted(Drawable icon, @ColorInt int color) { // if (icon == null) return null; // icon = DrawableCompat.wrap(icon); // DrawableCompat.setTint(icon, color); // return icon; // } // }
import android.animation.LayoutTransition; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.Activity; import android.content.Context; import android.content.ContextWrapper; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.Canvas; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.AttrRes; import android.support.annotation.ColorInt; import android.support.annotation.DrawableRes; import android.support.annotation.MenuRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StyleRes; import android.support.v4.content.res.ResourcesCompat; import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.view.MarginLayoutParamsCompat; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorCompat; import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.AppCompatEditText; import android.text.TextWatcher; import android.util.AttributeSet; import android.util.Xml; import android.view.InflateException; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ImageView; import android.widget.RelativeLayout; import com.mypopsy.floatingsearchview.R; import com.mypopsy.widget.internal.RoundRectDrawableWithShadow; import com.mypopsy.widget.internal.SuggestionItemDecorator; import com.mypopsy.widget.internal.ViewUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.BOTTOM; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.LEFT; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.RIGHT; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.TOP;
private Drawable mBackgroundDrawable; private boolean mSuggestionsShown; public FloatingSearchView(Context context) { this(context, null); } public FloatingSearchView(Context context, AttributeSet attrs) { this(context, attrs, R.attr.floatingSearchViewStyle); } public FloatingSearchView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); mActivity = getActivity(); setFocusable(true); setFocusableInTouchMode(true); inflate(getContext(), R.layout.fsv_floating_search_layout, this); mSearchInput = (LogoEditText) findViewById(R.id.fsv_search_text); mNavButtonView = (ImageView) findViewById(R.id.fsv_search_action_navigation); mRecyclerView = (RecyclerView) findViewById(R.id.fsv_suggestions_list); mDivider = findViewById(R.id.fsv_suggestions_divider); mSearchContainer = (ViewGroup) findViewById(R.id.fsv_search_container); mActionMenu = (ActionMenuView) findViewById(R.id.fsv_search_action_menu); //TODO: move elevation parameters to XML attributes mSearchBackground = new RoundRectDrawableWithShadow(
// Path: FloatingSearchView/src/main/java/com/mypopsy/widget/internal/ViewUtils.java // public class ViewUtils { // private static final int[] TEMP_ARRAY = new int[1]; // // public static void showSoftKeyboardDelayed(final EditText editText, long delay) { // editText.postDelayed(new Runnable() { // @Override // public void run() { // InputMethodManager inputMethodManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); // inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); // } // }, delay); // } // // public static void closeSoftKeyboard(Activity activity) { // View currentFocusView = activity.getCurrentFocus(); // if (currentFocusView != null) { // InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); // imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0); // } // } // // public static int dpToPx(int dp) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // return (int) (dp * metrics.density); // } // // public static int pxToDp(int px) { // DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); // return (int) (px / metrics.density); // } // // public static int getThemeAttrColor(Context context, @AttrRes int attr) { // TEMP_ARRAY[0] = attr; // TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); // try { // return a.getColor(0, 0); // } finally { // a.recycle(); // } // } // // public static Drawable getTinted(Drawable icon, @ColorInt int color) { // if (icon == null) return null; // icon = DrawableCompat.wrap(icon); // DrawableCompat.setTint(icon, color); // return icon; // } // } // Path: FloatingSearchView/src/main/java/com/mypopsy/widget/FloatingSearchView.java import android.animation.LayoutTransition; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.Activity; import android.content.Context; import android.content.ContextWrapper; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.Canvas; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.AttrRes; import android.support.annotation.ColorInt; import android.support.annotation.DrawableRes; import android.support.annotation.MenuRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StyleRes; import android.support.v4.content.res.ResourcesCompat; import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.view.MarginLayoutParamsCompat; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorCompat; import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.AppCompatEditText; import android.text.TextWatcher; import android.util.AttributeSet; import android.util.Xml; import android.view.InflateException; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ImageView; import android.widget.RelativeLayout; import com.mypopsy.floatingsearchview.R; import com.mypopsy.widget.internal.RoundRectDrawableWithShadow; import com.mypopsy.widget.internal.SuggestionItemDecorator; import com.mypopsy.widget.internal.ViewUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.BOTTOM; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.LEFT; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.RIGHT; import static com.mypopsy.widget.internal.RoundRectDrawableWithShadow.TOP; private Drawable mBackgroundDrawable; private boolean mSuggestionsShown; public FloatingSearchView(Context context) { this(context, null); } public FloatingSearchView(Context context, AttributeSet attrs) { this(context, attrs, R.attr.floatingSearchViewStyle); } public FloatingSearchView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); mActivity = getActivity(); setFocusable(true); setFocusableInTouchMode(true); inflate(getContext(), R.layout.fsv_floating_search_layout, this); mSearchInput = (LogoEditText) findViewById(R.id.fsv_search_text); mNavButtonView = (ImageView) findViewById(R.id.fsv_search_action_navigation); mRecyclerView = (RecyclerView) findViewById(R.id.fsv_suggestions_list); mDivider = findViewById(R.id.fsv_suggestions_divider); mSearchContainer = (ViewGroup) findViewById(R.id.fsv_search_container); mActionMenu = (ActionMenuView) findViewById(R.id.fsv_search_action_menu); //TODO: move elevation parameters to XML attributes mSearchBackground = new RoundRectDrawableWithShadow(
DEFAULT_CONTENT_COLOR, ViewUtils.dpToPx(DEFAULT_RADIUS),
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/gallery/external/ExternalGalleryPagerAdapter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/module/gallery/PictureFragment.java // public class PictureFragment extends BaseFragment<PictureFragment.PicturePresenter> implements IBaseView { // private static final String PIC_URL = "PIC_URL"; // private static final String PIC_BYTE = "PIC_BYTE"; // private static final String IS_FROM_DISK = "IS_FROM_DISK"; // // @BindView(R.id.pv_picture) PhotoView pvPicture; // @BindView(R.id.loading_progress_bar) ProgressBar loadingProgressBar; // // private String mPicUrl; // private byte[] mPicByte; // private boolean isFromDisk; // // public static PictureFragment newInstance(String picUrl, byte[] picByte, boolean isFromDisk) { // PictureFragment fragment = new PictureFragment(); // Bundle args = new Bundle(); // args.putString(PIC_URL, picUrl); // args.putByteArray(PIC_BYTE, picByte); // args.putBoolean(IS_FROM_DISK, isFromDisk); // fragment.setArguments(args); // return fragment; // } // // @Override // protected int provideViewLayoutId() { // return R.layout.fragment_picture; // } // // @Override // protected void initPresenter() { // presenter = new PicturePresenter(getContext(), this); // presenter.init(); // } // // @Override // public void init() { // if (getArguments() != null) { // mPicUrl = getArguments().getString(PIC_URL); // mPicByte = getArguments().getByteArray(PIC_BYTE); // isFromDisk = getArguments().getBoolean(IS_FROM_DISK); // } // pvPicture.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() { // @Override // public void onViewTap(View view, float x, float y) { // FragmentActivity activity = getActivity(); // if (activity instanceof GalleryActivity) { // ((GalleryActivity) getActivity()).toggleSystemUi(); // } else { // ((ExternalGalleryActivity) getActivity()).toggleSystemUi(); // } // } // }); // // // 别问我为什么这样写= = // if (isFromDisk) { // Glide.with(this) // .load(mPicByte) // .listener(new RequestListener<byte[], GlideDrawable>() { // @Override // public boolean onException(Exception e, byte[] model, Target<GlideDrawable> target, boolean isFirstResource) { // return false; // } // // @Override // public boolean onResourceReady(GlideDrawable resource, byte[] model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { // loadingProgressBar.setVisibility(View.INVISIBLE); // return false; // } // }) // .into(pvPicture); // } else { // Glide.with(this) // .load(GlideUrlFactory.newGlideUrlInstance(mPicUrl)) // .listener(new RequestListener<GlideUrl, GlideDrawable>() { // @Override // public boolean onException(Exception e, GlideUrl model, Target<GlideDrawable> target, boolean isFirstResource) { // return false; // } // // @Override // public boolean onResourceReady(GlideDrawable resource, GlideUrl model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { // loadingProgressBar.setVisibility(View.INVISIBLE); // return false; // } // }) // .into(pvPicture); // } // } // // class PicturePresenter extends BasePresenter<IBaseView> { // public PicturePresenter(Context context, IBaseView iView) { // super(context, iView); // } // } // }
import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.module.gallery.PictureFragment;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.gallery.external; /** * Created by SamuelGjk on 2016/7/5. */ public class ExternalGalleryPagerAdapter extends FragmentStatePagerAdapter { private List<byte[]> mBytes; public ExternalGalleryPagerAdapter(FragmentManager fm) { super(fm); mBytes = new ArrayList<>(); } @Override public Fragment getItem(int position) {
// Path: app/src/main/java/moe/yukinoneko/gcomic/module/gallery/PictureFragment.java // public class PictureFragment extends BaseFragment<PictureFragment.PicturePresenter> implements IBaseView { // private static final String PIC_URL = "PIC_URL"; // private static final String PIC_BYTE = "PIC_BYTE"; // private static final String IS_FROM_DISK = "IS_FROM_DISK"; // // @BindView(R.id.pv_picture) PhotoView pvPicture; // @BindView(R.id.loading_progress_bar) ProgressBar loadingProgressBar; // // private String mPicUrl; // private byte[] mPicByte; // private boolean isFromDisk; // // public static PictureFragment newInstance(String picUrl, byte[] picByte, boolean isFromDisk) { // PictureFragment fragment = new PictureFragment(); // Bundle args = new Bundle(); // args.putString(PIC_URL, picUrl); // args.putByteArray(PIC_BYTE, picByte); // args.putBoolean(IS_FROM_DISK, isFromDisk); // fragment.setArguments(args); // return fragment; // } // // @Override // protected int provideViewLayoutId() { // return R.layout.fragment_picture; // } // // @Override // protected void initPresenter() { // presenter = new PicturePresenter(getContext(), this); // presenter.init(); // } // // @Override // public void init() { // if (getArguments() != null) { // mPicUrl = getArguments().getString(PIC_URL); // mPicByte = getArguments().getByteArray(PIC_BYTE); // isFromDisk = getArguments().getBoolean(IS_FROM_DISK); // } // pvPicture.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() { // @Override // public void onViewTap(View view, float x, float y) { // FragmentActivity activity = getActivity(); // if (activity instanceof GalleryActivity) { // ((GalleryActivity) getActivity()).toggleSystemUi(); // } else { // ((ExternalGalleryActivity) getActivity()).toggleSystemUi(); // } // } // }); // // // 别问我为什么这样写= = // if (isFromDisk) { // Glide.with(this) // .load(mPicByte) // .listener(new RequestListener<byte[], GlideDrawable>() { // @Override // public boolean onException(Exception e, byte[] model, Target<GlideDrawable> target, boolean isFirstResource) { // return false; // } // // @Override // public boolean onResourceReady(GlideDrawable resource, byte[] model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { // loadingProgressBar.setVisibility(View.INVISIBLE); // return false; // } // }) // .into(pvPicture); // } else { // Glide.with(this) // .load(GlideUrlFactory.newGlideUrlInstance(mPicUrl)) // .listener(new RequestListener<GlideUrl, GlideDrawable>() { // @Override // public boolean onException(Exception e, GlideUrl model, Target<GlideDrawable> target, boolean isFirstResource) { // return false; // } // // @Override // public boolean onResourceReady(GlideDrawable resource, GlideUrl model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { // loadingProgressBar.setVisibility(View.INVISIBLE); // return false; // } // }) // .into(pvPicture); // } // } // // class PicturePresenter extends BasePresenter<IBaseView> { // public PicturePresenter(Context context, IBaseView iView) { // super(context, iView); // } // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/gallery/external/ExternalGalleryPagerAdapter.java import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.module.gallery.PictureFragment; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.gallery.external; /** * Created by SamuelGjk on 2016/7/5. */ public class ExternalGalleryPagerAdapter extends FragmentStatePagerAdapter { private List<byte[]> mBytes; public ExternalGalleryPagerAdapter(FragmentManager fm) { super(fm); mBytes = new ArrayList<>(); } @Override public Fragment getItem(int position) {
return PictureFragment.newInstance(null, mBytes.get(position), true);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/favorite/FavoriteActivity.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/FavoriteModel.java // @Table("gcomic_favorite") // public class FavoriteModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public String comicTitle; // // public String comicAuthors; // // public String comicCover; // // public long favoriteTime; // // public FavoriteModel(int comicId, String comicTitle, String comicAuthors, String comicCover, long favoriteTime) { // this.comicId = comicId; // this.comicTitle = comicTitle; // this.comicAuthors = comicAuthors; // this.comicCover = comicCover; // this.favoriteTime = favoriteTime; // } // }
import android.content.Intent; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.database.model.FavoriteModel;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.favorite; /** * Created by SamuelGjk on 2016/5/9. */ public class FavoriteActivity extends ToolBarActivity<FavoritePresenter> implements IFavoriteView { static final int REQUEST_CODE_FAVORITE_COMIC = 10001; @BindView(R.id.favorite_comic_grid) RecyclerView mFavoriteComicGrid; private FavoriteGridAdapter mAdapter; @Override protected int provideContentViewId() { return R.layout.activity_favorite; } @Override protected void initPresenter() { presenter = new FavoritePresenter(this, this); presenter.init(); } @Override public void init() { mToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFavoriteComicGrid.smoothScrollToPosition(0); } }); mFavoriteComicGrid.setHasFixedSize(true); mAdapter = new FavoriteGridAdapter(this); mFavoriteComicGrid.setAdapter(mAdapter); presenter.fetchFavoriteData(); } @Override
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/FavoriteModel.java // @Table("gcomic_favorite") // public class FavoriteModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public String comicTitle; // // public String comicAuthors; // // public String comicCover; // // public long favoriteTime; // // public FavoriteModel(int comicId, String comicTitle, String comicAuthors, String comicCover, long favoriteTime) { // this.comicId = comicId; // this.comicTitle = comicTitle; // this.comicAuthors = comicAuthors; // this.comicCover = comicCover; // this.favoriteTime = favoriteTime; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/favorite/FavoriteActivity.java import android.content.Intent; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.database.model.FavoriteModel; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.favorite; /** * Created by SamuelGjk on 2016/5/9. */ public class FavoriteActivity extends ToolBarActivity<FavoritePresenter> implements IFavoriteView { static final int REQUEST_CODE_FAVORITE_COMIC = 10001; @BindView(R.id.favorite_comic_grid) RecyclerView mFavoriteComicGrid; private FavoriteGridAdapter mAdapter; @Override protected int provideContentViewId() { return R.layout.activity_favorite; } @Override protected void initPresenter() { presenter = new FavoritePresenter(this, this); presenter.init(); } @Override public void init() { mToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFavoriteComicGrid.smoothScrollToPosition(0); } }); mFavoriteComicGrid.setHasFixedSize(true); mAdapter = new FavoriteGridAdapter(this); mFavoriteComicGrid.setAdapter(mAdapter); presenter.fetchFavoriteData(); } @Override
public void updateFavoriteList(List<FavoriteModel> favorites) {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/main/rank/RankPresenter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/RankData.java // public class RankData { // @Json(name = "comic_id") public int comicId; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // }
import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.RankData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.rank; /** * Created by SamuelGjk on 2016/4/7. */ public class RankPresenter extends BasePresenter<IRankView> { public RankPresenter(Context context, IRankView iView) { super(context, iView); } void fetchRankData(int page) { Subscription subscription = GComicApi.getInstance() .fetchRankData(page) .observeOn(AndroidSchedulers.mainThread())
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/RankData.java // public class RankData { // @Json(name = "comic_id") public int comicId; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/main/rank/RankPresenter.java import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.RankData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.rank; /** * Created by SamuelGjk on 2016/4/7. */ public class RankPresenter extends BasePresenter<IRankView> { public RankPresenter(Context context, IRankView iView) { super(context, iView); } void fetchRankData(int page) { Subscription subscription = GComicApi.getInstance() .fetchRankData(page) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<RankData>>() {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/main/rank/IRankView.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/RankData.java // public class RankData { // @Json(name = "comic_id") public int comicId; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // }
import java.util.List; import moe.yukinoneko.gcomic.data.RankData; import moe.yukinoneko.gcomic.base.IBaseView;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.rank; /** * Created by SamuelGjk on 2016/4/7. */ public interface IRankView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/RankData.java // public class RankData { // @Json(name = "comic_id") public int comicId; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/main/rank/IRankView.java import java.util.List; import moe.yukinoneko.gcomic.data.RankData; import moe.yukinoneko.gcomic.base.IBaseView; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.rank; /** * Created by SamuelGjk on 2016/4/7. */ public interface IRankView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
void updateRankList(List<RankData> rankDatas);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/search/SearchActivity.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // }
import moe.yukinoneko.gcomic.utils.SnackbarUtils; import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.SearchData;
super.onScrolled(recyclerView, dx, dy); if (dy > 0 && !mSwipeRefreshLayout.isRefreshing() && mLayoutManager.findLastCompletelyVisibleItemPosition() > mAdapter.getItemCount() - 3) { setRefreshing(true); isRefresh = false; presenter.search(keyword, page); } } }); mSwipeRefreshLayout.postDelayed(new Runnable() { @Override public void run() { doRefresh(); } }, 358); } private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.search(keyword, 0); } @Override public void showMessageSnackbar(int resId) {
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/search/SearchActivity.java import moe.yukinoneko.gcomic.utils.SnackbarUtils; import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.SearchData; super.onScrolled(recyclerView, dx, dy); if (dy > 0 && !mSwipeRefreshLayout.isRefreshing() && mLayoutManager.findLastCompletelyVisibleItemPosition() > mAdapter.getItemCount() - 3) { setRefreshing(true); isRefresh = false; presenter.search(keyword, page); } } }); mSwipeRefreshLayout.postDelayed(new Runnable() { @Override public void run() { doRefresh(); } }, 358); } private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.search(keyword, 0); } @Override public void showMessageSnackbar(int resId) {
SnackbarUtils.showShort(mSwipeRefreshLayout, resId);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/search/SearchActivity.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // }
import moe.yukinoneko.gcomic.utils.SnackbarUtils; import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.SearchData;
private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.search(keyword, 0); } @Override public void showMessageSnackbar(int resId) { SnackbarUtils.showShort(mSwipeRefreshLayout, resId); } @Override public void setRefreshing(final boolean refreshing) { new Handler().postDelayed(new Runnable() { @Override public void run() { if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(refreshing); } } }, refreshing ? 0 : 1000); } @Override
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/search/SearchActivity.java import moe.yukinoneko.gcomic.utils.SnackbarUtils; import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.SearchData; private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.search(keyword, 0); } @Override public void showMessageSnackbar(int resId) { SnackbarUtils.showShort(mSwipeRefreshLayout, resId); } @Override public void setRefreshing(final boolean refreshing) { new Handler().postDelayed(new Runnable() { @Override public void run() { if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(refreshing); } } }, refreshing ? 0 : 1000); } @Override
public void updateResultList(List<SearchData> searchDatas) {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/main/category/CategoryPresenter.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/CategoryData.java // public class CategoryData { // @Json(name = "tag_id") public int tagId; // public String title; // public String cover; // }
import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.CategoryData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.category; /** * Created by SamuelGjk on 2016/4/18. */ public class CategoryPresenter extends BasePresenter<ICategoryView> { public CategoryPresenter(Context context, ICategoryView iView) { super(context, iView); } void fetchCategoryData() { Subscription subscription = GComicApi.getInstance() .fetchCategoryData() .observeOn(AndroidSchedulers.mainThread())
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/BasePresenter.java // public abstract class BasePresenter<T extends IBaseView> { // protected CompositeSubscription mCompositeSubscription; // protected Context mContext; // protected T iView; // // public BasePresenter(Context context, T iView) { // this.mContext = context; // this.iView = iView; // } // // public void init() { // iView.init(); // } // // public void release() { // if (this.mCompositeSubscription != null) { // this.mCompositeSubscription.unsubscribe(); // } // } // // public void addSubscription(Subscription s) { // if (this.mCompositeSubscription == null) { // this.mCompositeSubscription = new CompositeSubscription(); // } // this.mCompositeSubscription.add(s); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/CategoryData.java // public class CategoryData { // @Json(name = "tag_id") public int tagId; // public String title; // public String cover; // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/main/category/CategoryPresenter.java import android.content.Context; import java.util.List; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.BasePresenter; import moe.yukinoneko.gcomic.data.CategoryData; import moe.yukinoneko.gcomic.network.GComicApi; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.category; /** * Created by SamuelGjk on 2016/4/18. */ public class CategoryPresenter extends BasePresenter<ICategoryView> { public CategoryPresenter(Context context, ICategoryView iView) { super(context, iView); } void fetchCategoryData() { Subscription subscription = GComicApi.getInstance() .fetchCategoryData() .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<CategoryData>>() {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // }
import android.os.Parcel; import android.os.Parcelable; import com.squareup.moshi.Json; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.database.model.ReadHistoryModel;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.data; /** * Created by SamuelGjk on 2016/4/6. */ public class ComicData { public int id; public String islong; public int direction; public String title; @Json(name = "is_dmzj") public int isDmzj; public String cover; public String description; @Json(name = "last_updatetime") public int lastUpdatetime; public int copyright; @Json(name = "first_letter") public String firstLetter; @Json(name = "hot_num") public int hotNum; public Object uid; @Json(name = "subscribe_num") public int subscribeNum; public CommentBean comment; public List<TypesBean> types; public List<AuthorsBean> authors; public List<StatusBean> status; public List<ChaptersBean> chapters; public List<Integer> downloadedChapters = new ArrayList<>();
// Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/ReadHistoryModel.java // @Table("gcomic_read_history") // public class ReadHistoryModel { // // @PrimaryKey(AssignType.BY_MYSELF) // public int comicId; // // public int chapterId; // // public int browsePosition; // // public ReadHistoryModel(int comicId, int chapterId, int browsePosition) { // this.comicId = comicId; // this.chapterId = chapterId; // this.browsePosition = browsePosition; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/data/ComicData.java import android.os.Parcel; import android.os.Parcelable; import com.squareup.moshi.Json; import java.util.ArrayList; import java.util.List; import moe.yukinoneko.gcomic.database.model.ReadHistoryModel; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.data; /** * Created by SamuelGjk on 2016/4/6. */ public class ComicData { public int id; public String islong; public int direction; public String title; @Json(name = "is_dmzj") public int isDmzj; public String cover; public String description; @Json(name = "last_updatetime") public int lastUpdatetime; public int copyright; @Json(name = "first_letter") public String firstLetter; @Json(name = "hot_num") public int hotNum; public Object uid; @Json(name = "subscribe_num") public int subscribeNum; public CommentBean comment; public List<TypesBean> types; public List<AuthorsBean> authors; public List<StatusBean> status; public List<ChaptersBean> chapters; public List<Integer> downloadedChapters = new ArrayList<>();
public ReadHistoryModel readHistory;
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/main/category/ICategoryView.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/CategoryData.java // public class CategoryData { // @Json(name = "tag_id") public int tagId; // public String title; // public String cover; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // }
import java.util.List; import moe.yukinoneko.gcomic.data.CategoryData; import moe.yukinoneko.gcomic.base.IBaseView;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.category; /** * Created by SamuelGjk on 2016/4/18. */ public interface ICategoryView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/CategoryData.java // public class CategoryData { // @Json(name = "tag_id") public int tagId; // public String title; // public String cover; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/main/category/ICategoryView.java import java.util.List; import moe.yukinoneko.gcomic.data.CategoryData; import moe.yukinoneko.gcomic.base.IBaseView; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main.category; /** * Created by SamuelGjk on 2016/4/18. */ public interface ICategoryView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
void updateCategoryList(List<CategoryData> categoryDatas);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/classify/ClassifyActivity.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // }
import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.utils.SnackbarUtils;
super.onScrolled(recyclerView, dx, dy); if (dy > 0 && !mSwipeRefreshLayout.isRefreshing() && mLayoutManager.findLastCompletelyVisibleItemPosition() > mAdapter.getItemCount() - 3) { setRefreshing(true); isRefresh = false; presenter.fetchClassifyData(tagId, page); } } }); mSwipeRefreshLayout.postDelayed(new Runnable() { @Override public void run() { doRefresh(); } }, 358); } private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.fetchClassifyData(tagId, 0); } @Override public void showMessageSnackbar(int resId) {
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/classify/ClassifyActivity.java import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.utils.SnackbarUtils; super.onScrolled(recyclerView, dx, dy); if (dy > 0 && !mSwipeRefreshLayout.isRefreshing() && mLayoutManager.findLastCompletelyVisibleItemPosition() > mAdapter.getItemCount() - 3) { setRefreshing(true); isRefresh = false; presenter.fetchClassifyData(tagId, page); } } }); mSwipeRefreshLayout.postDelayed(new Runnable() { @Override public void run() { doRefresh(); } }, 358); } private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.fetchClassifyData(tagId, 0); } @Override public void showMessageSnackbar(int resId) {
SnackbarUtils.showShort(mSwipeRefreshLayout, resId);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/classify/ClassifyActivity.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // }
import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.utils.SnackbarUtils;
private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.fetchClassifyData(tagId, 0); } @Override public void showMessageSnackbar(int resId) { SnackbarUtils.showShort(mSwipeRefreshLayout, resId); } @Override public void setRefreshing(final boolean refreshing) { new Handler().postDelayed(new Runnable() { @Override public void run() { if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(refreshing); } } }, refreshing ? 0 : 1000); } @Override
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/ToolBarActivity.java // public abstract class ToolBarActivity<T extends BasePresenter> extends BaseActivity<T> { // protected ActionBar mActionBar; // // @BindView(R.id.toolbar) // protected Toolbar mToolbar; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // initToolBar(); // } // // protected void initToolBar() { // setSupportActionBar(mToolbar); // mActionBar = getSupportActionBar(); // if (mActionBar != null) mActionBar.setDisplayHomeAsUpEnabled(true); // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // onBackPressed(); // break; // } // return super.onOptionsItemSelected(item); // } // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/utils/SnackbarUtils.java // public class SnackbarUtils { // /** // * 短时间显示Snackbar // * // * @param view // * @param message // */ // public static void showShort(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 短时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showShort(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_SHORT).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param message // */ // public static void showLong(View view, CharSequence message) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示Snackbar // * // * @param view // * @param resId // */ // public static void showLong(View view, @StringRes int resId) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param message // */ // public static void showLongWithAction(View view, CharSequence message, CharSequence actionMessage, View.OnClickListener action) { // Snackbar.make(view, message, Snackbar.LENGTH_LONG).setAction(actionMessage, action).show(); // } // // /** // * 长时间显示带Action的Snackbar // * // * @param view // * @param resId // */ // public static void showLongWithAction(View view, @StringRes int resId, @StringRes int actionResId, View.OnClickListener action) { // Snackbar.make(view, resId, Snackbar.LENGTH_LONG).setAction(actionResId, action).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param message // * @param duration // */ // public static void show(View view, CharSequence message, int duration) { // Snackbar.make(view, message, duration).show(); // } // // /** // * 自定义显示Snackbar时间 // * // * @param view // * @param resId // * @param duration // */ // public static void show(View view, @StringRes int resId, int duration) { // Snackbar.make(view, resId, duration).show(); // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/classify/ClassifyActivity.java import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import java.util.List; import butterknife.BindView; import moe.yukinoneko.gcomic.R; import moe.yukinoneko.gcomic.base.ToolBarActivity; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.utils.SnackbarUtils; private void doRefresh() { if (mSwipeRefreshLayout == null) { return; } setRefreshing(true); mSwipeTarget.smoothScrollToPosition(0); isRefresh = true; presenter.fetchClassifyData(tagId, 0); } @Override public void showMessageSnackbar(int resId) { SnackbarUtils.showShort(mSwipeRefreshLayout, resId); } @Override public void setRefreshing(final boolean refreshing) { new Handler().postDelayed(new Runnable() { @Override public void run() { if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(refreshing); } } }, refreshing ? 0 : 1000); } @Override
public void updateClassifyList(List<ClassifyData> classifyDatas) {
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/main/IMainView.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/SearchHistoryModel.java // @Table("gcomic_search_history") // public class SearchHistoryModel { // @PrimaryKey(AssignType.BY_MYSELF) // public int _id; // // public String keyword; // // public SearchHistoryModel(int _id, String keyword) { // this._id = _id; // this.keyword = keyword; // } // }
import java.util.List; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.database.model.SearchHistoryModel;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main; /** * Created by SamuelGjk on 2016/5/30. */ public interface IMainView extends IBaseView { String getSearchKeyword();
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/database/model/SearchHistoryModel.java // @Table("gcomic_search_history") // public class SearchHistoryModel { // @PrimaryKey(AssignType.BY_MYSELF) // public int _id; // // public String keyword; // // public SearchHistoryModel(int _id, String keyword) { // this._id = _id; // this.keyword = keyword; // } // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/main/IMainView.java import java.util.List; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.database.model.SearchHistoryModel; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.main; /** * Created by SamuelGjk on 2016/5/30. */ public interface IMainView extends IBaseView { String getSearchKeyword();
void updateSearchSuggestions(List<SearchHistoryModel> suggestions);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/search/ISearchView.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // }
import java.util.List; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.data.SearchData;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.search; /** * Created by SamuelGjk on 2016/4/18. */ public interface ISearchView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
// Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/data/SearchData.java // public class SearchData { // public int id; // public String status; // public String title; // @Json(name = "last_name") public String lastName; // public String cover; // public String authors; // public String types; // @Json(name = "hot_hits") public int hotHits; // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/search/ISearchView.java import java.util.List; import moe.yukinoneko.gcomic.base.IBaseView; import moe.yukinoneko.gcomic.data.SearchData; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.search; /** * Created by SamuelGjk on 2016/4/18. */ public interface ISearchView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
void updateResultList(List<SearchData> searchDatas);
SamuelGjk/GComic
app/src/main/java/moe/yukinoneko/gcomic/module/classify/IClassifyView.java
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // }
import java.util.List; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.base.IBaseView;
/* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.classify; /** * Created by SamuelGjk on 2016/4/18. */ public interface IClassifyView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
// Path: app/src/main/java/moe/yukinoneko/gcomic/data/ClassifyData.java // public class ClassifyData { // public int id; // public String title; // public String authors; // public String status; // public String cover; // public String types; // @Json(name = "last_updatetime") public Long lastUpdatetime; // public int num; // } // // Path: app/src/main/java/moe/yukinoneko/gcomic/base/IBaseView.java // public interface IBaseView { // void init(); // } // Path: app/src/main/java/moe/yukinoneko/gcomic/module/classify/IClassifyView.java import java.util.List; import moe.yukinoneko.gcomic.data.ClassifyData; import moe.yukinoneko.gcomic.base.IBaseView; /* * Copyright (C) 2016 SamuelGjk <samuel.alva@outlook.com> * * 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 moe.yukinoneko.gcomic.module.classify; /** * Created by SamuelGjk on 2016/4/18. */ public interface IClassifyView extends IBaseView { void showMessageSnackbar(int resId); void setRefreshing(boolean refreshing);
void updateClassifyList(List<ClassifyData> classifyDatas);
carrotsearch/jsuffixarrays
src/main/java/org/jsuffixarrays/NaiveSort.java
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // }
import static org.jsuffixarrays.Tools.assertAlways; import com.carrotsearch.hppc.sorting.IndirectComparator; import com.carrotsearch.hppc.sorting.IndirectSort; import com.google.common.primitives.Ints;
package org.jsuffixarrays; /** * A naive implementation of suffix sorting based on primitive integer collections and * custom sorting routines (quicksort). */ public final class NaiveSort implements ISuffixArrayBuilder { /** * {@inheritDoc} * <p> * Additional constraints enforced by this implementation: * <ul> * <li>{@link Integer#MIN_VALUE} must not occur in the input</li>, * <li><code>input.length</code> &gt;= <code>start + length + 1</code> (to simplify * border cases)</li> * </ul> */ @Override public int [] buildSuffixArray(int [] input, int start, int length) {
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // } // Path: src/main/java/org/jsuffixarrays/NaiveSort.java import static org.jsuffixarrays.Tools.assertAlways; import com.carrotsearch.hppc.sorting.IndirectComparator; import com.carrotsearch.hppc.sorting.IndirectSort; import com.google.common.primitives.Ints; package org.jsuffixarrays; /** * A naive implementation of suffix sorting based on primitive integer collections and * custom sorting routines (quicksort). */ public final class NaiveSort implements ISuffixArrayBuilder { /** * {@inheritDoc} * <p> * Additional constraints enforced by this implementation: * <ul> * <li>{@link Integer#MIN_VALUE} must not occur in the input</li>, * <li><code>input.length</code> &gt;= <code>start + length + 1</code> (to simplify * border cases)</li> * </ul> */ @Override public int [] buildSuffixArray(int [] input, int start, int length) {
assertAlways(input != null, "input must not be null");
carrotsearch/jsuffixarrays
src/main/java/org/jsuffixarrays/Skew.java
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // }
import static org.jsuffixarrays.Tools.assertAlways; import java.util.Arrays;
return tab; } /** * {@inheritDoc} * <p> * Additional constraints enforced by Karkkainen-Sanders algorithm: * <ul> * <li>non-negative (>0) symbols in the input (because of radix sort)</li>, * <li><code>input.length</code> &gt;= <code>start + length + 3</code> (to simplify * border cases)</li> * <li>length >= 2</li> * </ul> * <p> * If the input contains zero or negative values, or has no extra trailing cells, * adapters can be used in the following way: * * <pre> * return new {@link DensePositiveDecorator}( * new {@link ExtraTrailingCellsDecorator}( * new {@link Skew}(), 3)); * </pre> * * @see ExtraTrailingCellsDecorator * @see DensePositiveDecorator */ @Override public int [] buildSuffixArray(int [] input, int start, int length) {
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // } // Path: src/main/java/org/jsuffixarrays/Skew.java import static org.jsuffixarrays.Tools.assertAlways; import java.util.Arrays; return tab; } /** * {@inheritDoc} * <p> * Additional constraints enforced by Karkkainen-Sanders algorithm: * <ul> * <li>non-negative (>0) symbols in the input (because of radix sort)</li>, * <li><code>input.length</code> &gt;= <code>start + length + 3</code> (to simplify * border cases)</li> * <li>length >= 2</li> * </ul> * <p> * If the input contains zero or negative values, or has no extra trailing cells, * adapters can be used in the following way: * * <pre> * return new {@link DensePositiveDecorator}( * new {@link ExtraTrailingCellsDecorator}( * new {@link Skew}(), 3)); * </pre> * * @see ExtraTrailingCellsDecorator * @see DensePositiveDecorator */ @Override public int [] buildSuffixArray(int [] input, int start, int length) {
assertAlways(input != null, "input must not be null");
carrotsearch/jsuffixarrays
src/main/java/org/jsuffixarrays/QSufSort.java
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // }
import static org.jsuffixarrays.Tools.assertAlways;
package org.jsuffixarrays; /** * <p> * Straightforward reimplementation of the qsufsort algorithm given in: * * <pre> * &lt;code&gt; * Larsson, N. Jesper and Sadakane, Kunihiko. Faster Suffix Sorting. * Report number LU-CS-TR:99-214, LUNDFD6/(NFCS-3140)/1--20/(1999). Department of Computer Science, Lund University&quot; * &lt;/code&gt; * </pre> * <p> * This implementation is basically a translation of the C version given by Peter Sanders: * <tt>http://www.mpi-inf.mpg.de/~sanders/programs/suffix/</tt> * <p> * The implementation of this algorithm makes some assumptions about the input. See * {@link #buildSuffixArray(int[], int, int)} for details. * <p> * Algorithm modifies input during processing, see {@link #QSufSort(boolean)}. */ public class QSufSort implements ISuffixArrayBuilder { /** group array, ultimately suffix array. */ private int I[]; /** inverse array, ultimately inverse of I. */ private int V[]; /** number of symbols aggregated by transform. */ private int r; /** length of already-sorted prefixes. */ private int h; /** * If <code>true</code>, {@link #buildSuffixArray(int[], int, int)} uses copy of input * so it is left intact. */ private final boolean preserveInput; private int start; /** * Default constructor, uses the input array of symbols to preserve memory (and * destroys it). */ public QSufSort() { this.preserveInput = true; } /** * If <code>true</code>, the algorithm will use a copy of the input so it is left * intact. */ public QSufSort(boolean preserveInput) { this.preserveInput = preserveInput; } /** * {@inheritDoc} * <p> * Additional constraints enforced by qsufsort algorithm: * <ul> * <li>non-negative (&ge;0) symbols in the input</li> * <li>length >= 2</li> * </ul> * <p> */ @Override public final int [] buildSuffixArray(int [] input, int start, int length) {
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // } // Path: src/main/java/org/jsuffixarrays/QSufSort.java import static org.jsuffixarrays.Tools.assertAlways; package org.jsuffixarrays; /** * <p> * Straightforward reimplementation of the qsufsort algorithm given in: * * <pre> * &lt;code&gt; * Larsson, N. Jesper and Sadakane, Kunihiko. Faster Suffix Sorting. * Report number LU-CS-TR:99-214, LUNDFD6/(NFCS-3140)/1--20/(1999). Department of Computer Science, Lund University&quot; * &lt;/code&gt; * </pre> * <p> * This implementation is basically a translation of the C version given by Peter Sanders: * <tt>http://www.mpi-inf.mpg.de/~sanders/programs/suffix/</tt> * <p> * The implementation of this algorithm makes some assumptions about the input. See * {@link #buildSuffixArray(int[], int, int)} for details. * <p> * Algorithm modifies input during processing, see {@link #QSufSort(boolean)}. */ public class QSufSort implements ISuffixArrayBuilder { /** group array, ultimately suffix array. */ private int I[]; /** inverse array, ultimately inverse of I. */ private int V[]; /** number of symbols aggregated by transform. */ private int r; /** length of already-sorted prefixes. */ private int h; /** * If <code>true</code>, {@link #buildSuffixArray(int[], int, int)} uses copy of input * so it is left intact. */ private final boolean preserveInput; private int start; /** * Default constructor, uses the input array of symbols to preserve memory (and * destroys it). */ public QSufSort() { this.preserveInput = true; } /** * If <code>true</code>, the algorithm will use a copy of the input so it is left * intact. */ public QSufSort(boolean preserveInput) { this.preserveInput = preserveInput; } /** * {@inheritDoc} * <p> * Additional constraints enforced by qsufsort algorithm: * <ul> * <li>non-negative (&ge;0) symbols in the input</li> * <li>length >= 2</li> * </ul> * <p> */ @Override public final int [] buildSuffixArray(int [] input, int start, int length) {
assertAlways(input.length >= start + length + 1, "no extra space after input end");
carrotsearch/jsuffixarrays
src/main/java/org/jsuffixarrays/DeepShallow.java
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // }
import static org.jsuffixarrays.Tools.assertAlways; import java.util.Arrays;
private Node[] stack; private int start; /** * If <code>true</code>, {@link #buildSuffixArray(int[], int, int)} uses a copy of the input so it is left intact. */ private final boolean preserveInput; public DeepShallow() { preserveInput = true; } public DeepShallow(boolean preserveInput) { this.preserveInput = preserveInput; } /** * {@inheritDoc} * <p> * Additional constraints enforced by Deep-Shallow algorithm: * <ul> * <li>non-negative (&ge;0) symbols in the input</li> * <li>maximal symbol value &lt; <code>256</code></li> * <li><code>input.length</code> &ge; <code>start + length</code> if {@link #preserveInput} is <tt>true</tt></li> * <li><code>input.length</code> &ge; <code>start + length + {@link #OVERSHOOT}</code> if {@link #preserveInput} is <tt>false</tt></li> * <li>length >= 2</li> * </ul> */ @Override public int[] buildSuffixArray(int[] input, int start, int length) {
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // } // Path: src/main/java/org/jsuffixarrays/DeepShallow.java import static org.jsuffixarrays.Tools.assertAlways; import java.util.Arrays; private Node[] stack; private int start; /** * If <code>true</code>, {@link #buildSuffixArray(int[], int, int)} uses a copy of the input so it is left intact. */ private final boolean preserveInput; public DeepShallow() { preserveInput = true; } public DeepShallow(boolean preserveInput) { this.preserveInput = preserveInput; } /** * {@inheritDoc} * <p> * Additional constraints enforced by Deep-Shallow algorithm: * <ul> * <li>non-negative (&ge;0) symbols in the input</li> * <li>maximal symbol value &lt; <code>256</code></li> * <li><code>input.length</code> &ge; <code>start + length</code> if {@link #preserveInput} is <tt>true</tt></li> * <li><code>input.length</code> &ge; <code>start + length + {@link #OVERSHOOT}</code> if {@link #preserveInput} is <tt>false</tt></li> * <li>length >= 2</li> * </ul> */ @Override public int[] buildSuffixArray(int[] input, int start, int length) {
Tools.assertAlways(input.length >= start + length, "Input array is too short");
carrotsearch/jsuffixarrays
src/main/java/org/jsuffixarrays/DivSufSort.java
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // }
import static org.jsuffixarrays.Tools.assertAlways;
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }; /* fields */ private final int ALPHABET_SIZE; private final int BUCKET_A_SIZE; private final int BUCKET_B_SIZE; private int [] SA; private int [] T; private int start; /** * {@inheritDoc} * <p> * Additional constraints enforced by DivSufSort algorithm: * <ul> * <li>non-negative (&ge;0) symbols in the input</li> * <li>symbols limited by alphabet size passed in the constructor.</li> * <li>length >= 2</li> * </ul> * <p> */ @Override public final int [] buildSuffixArray(int [] input, int start, int length) {
// Path: src/main/java/org/jsuffixarrays/Tools.java // static final void assertAlways(boolean condition, String msg) // { // if (!condition) // { // throw new AssertionError(msg); // } // } // Path: src/main/java/org/jsuffixarrays/DivSufSort.java import static org.jsuffixarrays.Tools.assertAlways; 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }; /* fields */ private final int ALPHABET_SIZE; private final int BUCKET_A_SIZE; private final int BUCKET_B_SIZE; private int [] SA; private int [] T; private int start; /** * {@inheritDoc} * <p> * Additional constraints enforced by DivSufSort algorithm: * <ul> * <li>non-negative (&ge;0) symbols in the input</li> * <li>symbols limited by alphabet size passed in the constructor.</li> * <li>length >= 2</li> * </ul> * <p> */ @Override public final int [] buildSuffixArray(int [] input, int start, int length) {
assertAlways(input != null, "input must not be null");
flownclouds/Timo
src/main/java/fm/liu/timo/server/response/PreparedStmtResponse.java
// Path: src/main/java/fm/liu/timo/mysql/PreparedStatement.java // public class PreparedStatement { // // private long id; // private int columnsNumber; // private int parametersNumber; // private int[] parametersType; // private String[] statements; // private boolean endsWithQuestionMark; // // public PreparedStatement(long id, String statement) { // this.id = id; // if (statement.endsWith("?")) { // endsWithQuestionMark = true; // } // this.statements = statement.split("\\?"); // this.parametersNumber = endsWithQuestionMark ? statements.length : statements.length + 1; // if (!statement.contains("?")) { // this.parametersNumber = 0; // } // this.parametersType = new int[parametersNumber]; // } // // public long getId() { // return id; // } // // public int getColumnsNumber() { // return columnsNumber; // } // // public int getParametersNumber() { // return parametersNumber; // } // // public int[] getParametersType() { // return parametersType; // } // // public String[] getStatements() { // return statements; // } // // public boolean isEndsWithQuestionMark() { // return endsWithQuestionMark; // } // // } // // Path: src/main/java/fm/liu/timo/mysql/packet/PreparedOkPacket.java // public class PreparedOkPacket extends ResultSetPacket { // // public byte flag; // public long statementId; // public int columnsNumber; // public int parametersNumber; // public byte filler; // public int warningCount; // // public PreparedOkPacket() { // this.flag = 0; // this.filler = 0; // } // // @Override // public int calcPacketSize() { // return 12; // } // // @Override // protected String getPacketInfo() { // return "MySQL PreparedOk Packet"; // } // // @Override // protected void writeBody(ByteBuffer buffer) { // buffer.put(flag); // BufferUtil.writeUB4(buffer, statementId); // BufferUtil.writeUB2(buffer, columnsNumber); // BufferUtil.writeUB2(buffer, parametersNumber); // buffer.put(filler); // BufferUtil.writeUB2(buffer, warningCount); // } // // @Override // protected void readBody(MySQLMessage mm) { // throw new RuntimeException("readBody for Reply323Packet not implement!"); // } // // }
import java.nio.ByteBuffer; import fm.liu.timo.mysql.PreparedStatement; import fm.liu.timo.mysql.packet.EOFPacket; import fm.liu.timo.mysql.packet.FieldPacket; import fm.liu.timo.mysql.packet.PreparedOkPacket; import fm.liu.timo.net.connection.FrontendConnection;
/* * Copyright 1999-2012 Alibaba Group. * * 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 fm.liu.timo.server.response; /** * @author xianmao.hexm 2012-8-28 */ public class PreparedStmtResponse { public static void response(PreparedStatement pstmt, FrontendConnection c) { byte packetId = 0; // write preparedOk packet
// Path: src/main/java/fm/liu/timo/mysql/PreparedStatement.java // public class PreparedStatement { // // private long id; // private int columnsNumber; // private int parametersNumber; // private int[] parametersType; // private String[] statements; // private boolean endsWithQuestionMark; // // public PreparedStatement(long id, String statement) { // this.id = id; // if (statement.endsWith("?")) { // endsWithQuestionMark = true; // } // this.statements = statement.split("\\?"); // this.parametersNumber = endsWithQuestionMark ? statements.length : statements.length + 1; // if (!statement.contains("?")) { // this.parametersNumber = 0; // } // this.parametersType = new int[parametersNumber]; // } // // public long getId() { // return id; // } // // public int getColumnsNumber() { // return columnsNumber; // } // // public int getParametersNumber() { // return parametersNumber; // } // // public int[] getParametersType() { // return parametersType; // } // // public String[] getStatements() { // return statements; // } // // public boolean isEndsWithQuestionMark() { // return endsWithQuestionMark; // } // // } // // Path: src/main/java/fm/liu/timo/mysql/packet/PreparedOkPacket.java // public class PreparedOkPacket extends ResultSetPacket { // // public byte flag; // public long statementId; // public int columnsNumber; // public int parametersNumber; // public byte filler; // public int warningCount; // // public PreparedOkPacket() { // this.flag = 0; // this.filler = 0; // } // // @Override // public int calcPacketSize() { // return 12; // } // // @Override // protected String getPacketInfo() { // return "MySQL PreparedOk Packet"; // } // // @Override // protected void writeBody(ByteBuffer buffer) { // buffer.put(flag); // BufferUtil.writeUB4(buffer, statementId); // BufferUtil.writeUB2(buffer, columnsNumber); // BufferUtil.writeUB2(buffer, parametersNumber); // buffer.put(filler); // BufferUtil.writeUB2(buffer, warningCount); // } // // @Override // protected void readBody(MySQLMessage mm) { // throw new RuntimeException("readBody for Reply323Packet not implement!"); // } // // } // Path: src/main/java/fm/liu/timo/server/response/PreparedStmtResponse.java import java.nio.ByteBuffer; import fm.liu.timo.mysql.PreparedStatement; import fm.liu.timo.mysql.packet.EOFPacket; import fm.liu.timo.mysql.packet.FieldPacket; import fm.liu.timo.mysql.packet.PreparedOkPacket; import fm.liu.timo.net.connection.FrontendConnection; /* * Copyright 1999-2012 Alibaba Group. * * 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 fm.liu.timo.server.response; /** * @author xianmao.hexm 2012-8-28 */ public class PreparedStmtResponse { public static void response(PreparedStatement pstmt, FrontendConnection c) { byte packetId = 0; // write preparedOk packet
PreparedOkPacket preparedOk = new PreparedOkPacket();