dreampany / framework_arch

A android framwork to work happily. Room Persistence database, RxJava, RxAndroid and Kotlin supported.
http://www.dreampany.com
Apache License 2.0
3 stars 2 forks source link

Feedback framework problem #1

Open tcqq opened 7 years ago

tcqq commented 7 years ago

Hello thanks for your framework, I think your code write very well, but I encountered a problem in use:

BaseActivity.java:

protected <T extends BaseActivity> void openActivity(Class<T> aClass, Task task) {
    Intent intent = new Intent(this, aClass);
    intent.putExtra(Task.class.getName(), (Parcelable) task);
    startActivity(intent);
}

I would like to use your packaging method to achieve Intent send value and accept value, but I will not use, you can give an example, ok?, thank you

dreampany commented 6 years ago

Thanks for your feedback.

Take a look an example. public class UiTask extends Task {

public UiTask() {
}

public UiTask(T item) {
    super(item);
}

public UiTask(T item, Type itemType) {
    super(item);
    setItemType(itemType);
}

}

Word word = new Word; UiTask task = new UiTask<>(word); openActivity(getActivity(), ToolsActivity.class, task);

tcqq commented 6 years ago

Hi, how to create "Word.java"? and how to accept the value?

dreampany commented 6 years ago

Word is a custom object to accept any params you want. And must be implemented as parcelable or serializable. :)

dreampany commented 6 years ago

@Entity(indices = {@Index(value = "word", unique = true)}) public class Word extends BaseSerial implements Comparable {

@PrimaryKey
@NonNull
private String word;
private String pronunciation;
@Ignore
private List<Definition> definitions;
private List<String> examples;
@Ignore
private List<String> synonyms;
@Ignore
private List<String> antonyms;
private long timeToday;
private long time;

public Word(@NotNull String word) {
    this.word = word;
}

@Override
public boolean equals(Object inObject) {
    if (Word.class.isInstance(inObject)) {
        Word word = (Word) inObject;
        return this.word.equals(word.word);
    }
    return false;
}

@Override
public int hashCode() {
    return word.hashCode();
}

@Override
public int compareTo(@NonNull Word item) {
    return word.compareToIgnoreCase(item.word);
}

@Override
public String toString() {
    StringBuilder result = new StringBuilder();
    String newLine = System.getProperty("line.separator");

    result.append(this.getClass().getName());
    result.append(" Object {");
    result.append(newLine);

    //determine fields declared in this class only (no fields of superclass)
    Field[] fields = this.getClass().getDeclaredFields();

    for (Field field : fields) {
        result.append("  ");
        try {
            result.append(field.getName());
            result.append(": ");
            result.append(field.get(this));
        } catch (IllegalAccessException ex) {
        }
        result.append(newLine);
    }
    result.append("}");

    return result.toString();
}

public void setWord(@NonNull String word) {
    this.word = word;
}

public void setPronunciation(String pronunciation) {
    this.pronunciation = pronunciation;
}

public void setDefinitions(List<Definition> definitions) {
    this.definitions = definitions;
}

public void setExamples(List<String> examples) {
    this.examples = examples;
}

public void setSynonyms(List<String> synonyms) {
    this.synonyms = synonyms;
}

public void setAntonyms(List<String> antonyms) {
    this.antonyms = antonyms;
}

public void setTimeToday(long timeToday) {
    this.timeToday = timeToday;
}

public void setTime(long time) {
    this.time = time;
}

@NonNull
public String getWord() {
    return word;
}

public String getPronunciation() {
    return pronunciation;
}

public List<Definition> getDefinitions() {
    return definitions;
}

public List<String> getExamples() {
    return examples;
}

public List<String> getSynonyms() {
    return synonyms;
}

public List<String> getAntonyms() {
    return antonyms;
}

public long getTimeToday() {
    return timeToday;
}

public long getTime() {
    return time;
}

//special public api
public void addDefinition(Definition definition) {
    if (definitions == null) {
        definitions = new ArrayList<>();
    }
    if (!definitions.contains(definition)) {
    definitions.add(definition);}
}

public void addExample(String example) {
    if (examples == null) {
        examples = new ArrayList<>();
    }
    if (!examples.contains(example)) {
    examples.add(example);}
}

public void addSynonym(String synonym) {
    if (synonyms == null) {
        synonyms = new ArrayList<>();
    }
    if (!synonyms.contains(synonym)) {
        synonyms.add(synonym);
    }
}

public void addAntonym(String antonym) {
    if (antonyms == null) {
        antonyms = new ArrayList<>();
    }
    if (!antonyms.contains(antonym)) {
        antonyms.add(antonym);
    }
}

public boolean hasDefinitions() {
    return !(definitions == null || definitions.isEmpty());
}

public boolean hasExamples() {
    return !(examples == null || examples.isEmpty());
}

public boolean hasSynonyms() {
    return !(synonyms == null || synonyms.isEmpty());
}

public boolean hasAntonyms() {
    return !(antonyms == null || antonyms.isEmpty());
}

public boolean containsDefinition(Definition definition) {
    if (hasDefinitions()) {
        return definitions.contains(definition);
    }
    return false;
}

public boolean containsExample(String example) {
    if (hasExamples()) {
        return examples.contains(example);
    }
    return false;
}

public boolean containsSynonym(String synonym) {
    if (hasSynonyms()) {
        return synonyms.contains(synonym);
    }
    return false;
}

public boolean containsAntonym(String antonym) {
    if (hasAntonyms()) {
        return antonyms.contains(antonym);
    }
    return false;
}

public boolean isToday() {
    return timeToday > 0;
}

}

dreampany commented 6 years ago

Hope it will help you. And one more thing, just ignore the Room annotation for your object.

tcqq commented 6 years ago

I want use "Parcelable" to pass a (Test) value via Intent, I tried it for a moment, but something went wrong, what should I do now?

tcqq commented 6 years ago

OneActivity.java:

            Word word = new Word("Test");
            UiTask task = new UiTask<>(word);
            openActivity(TwoActivity.class, task);

TowActivity.java:

    Word word = null;
    LogKit.logInfo(word.getName());

Word.java:

public class Word extends BaseParcel { private String mName;

public Word(String name) {
    this.mName = name;
}

protected Word(Parcel in) {
    super(in);
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    super.writeToParcel(dest, flags);
}

public static final Parcelable.Creator<Word> CREATOR = new Parcelable.Creator<Word>() {
    @Override
    public Word createFromParcel(Parcel in) {
        return new Word(in);
    }

    @Override
    public Word[] newArray(int size) {
        return new Word[size];
    }
};

@Override
public int describeContents() {
    return 0;
}

public String getName() {
    return mName;
}

public Word setName(String name) {
    this.mName = name;
    return this;
}

}

tcqq commented 6 years ago

image UiTask.java and SQLiteTask.java have problem

tcqq commented 6 years ago

image ColorUtil.java has a problem

dreampany commented 6 years ago

Thanks TCQQ, I am going to update fully repository after solving this bug.

tcqq commented 6 years ago

Ok.

tcqq commented 6 years ago

BaseNavigationActivity:

onNavigationItemSelected have a problem, i fixed.

image

In single mode(android:checkableBehavior="single"), clicking selected item invalidates the click event is right, but in click mode(android:checkableBehavior="none") can not do this, because after clicking may jump to other interfaces, when returning from other interface, click the same button again before clicking, click will invalidates.