Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version:2.0.0
Simplified event and event bus structure.

Version:1.6.0
* Add BaseManagerImpl. Logic and data shared by multiple controllers can be put into managers and injected into controllers.
* Delegate fragment's onViewReady lifecycle will be called after state of all controllers are restored if activity is killed by OS
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,8 +72,8 @@ ext {
siteUrl = 'https://github.com/kejunxia/AndroidMvc' // Homepage URL of the library
gitUrl = 'https://github.com/kejunxia/AndroidMvc.git' // Git repository URL
version = [
major: 1,
minor: 6,
major: 2,
minor: 0,
patch : 0
]
libGroup = 'com.shipdream'
Expand Down
2 changes: 1 addition & 1 deletion extension/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion extension/service-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion extension/service-mediastore/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015 Kejun Xia
# Copyright 2016 Kejun Xia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015 Kejun Xia
# Copyright 2016 Kejun Xia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion library/android-mvc-controller/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2016 Kejun Xia
*
* 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.shipdream.lib.android.mvc;

import com.shipdream.lib.poke.exception.PokeException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Kejun Xia
* Copyright 2016 Kejun Xia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,24 +17,24 @@
package com.shipdream.lib.android.mvc;

/**
* StateKeeper can save state of objects implementing {@link StateManaged} into it. The state can
* ModelKeeper can save model of objects implementing {@link MvcBean} into it. The model can
* be got back from the keeper later on.
*/
public interface StateKeeper {
public interface ModelKeeper {
/**
* Save state into this {@link StateKeeper}
* @param state The state to save
* @param type The class type of the state
* Save model into this {@link ModelKeeper}
* @param model The model to save
* @param type The class type of the model
* @param <T>
*/
<T> void saveState(T state, Class<T> type);
<T> void saveModel(T model, Class<T> type);

/**
* Get saved state from the keeper
* @param type The class type of the state
* Retrieves model
* @param type The class type of the model
* @param <T>
* @return null if the state with the given type has not been saved or a null state was saved,
* otherwise state saved previously
* @return null if the model with the given type has not been saved or a null model was saved,
* otherwise returns model saved previously
*/
<T> T getState(Class<T> type);
<T> T retrieveModel(Class<T> type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2016 Kejun Xia
*
* 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.shipdream.lib.android.mvc;

import com.shipdream.lib.poke.util.ReflectUtils;

public abstract class MvcBean<MODEL> {
private MODEL model;

/**
* Bind model to MvcBean
* @param model non-null model
* @throws IllegalArgumentException thrown when null is being bound
*/
public void bindModel(MODEL model) {
if (model == null) {
throw new IllegalArgumentException("Can't bind null model explicitly.");
} else {
this.model = model;
}
}

/**
* Called when the MvcBean is injected for the first time or restored when a new instance of
* this MvcBean needs to be instantiated.
*
* <p>The model of the MvcBean will be instantiated by model's default no-argument constructor.
* However, if the MvcBean needs to be restored, a new instance of model restored by
* {@link #restoreModel(Object)} will replace the model created by this method.</p>
*/
public void onConstruct() {
model = instantiateModel();
}

private MODEL instantiateModel() {
Class<MODEL> type = modelType();
if (type == null) {
return null;
} else {
try {
return new ReflectUtils.newObjectByType<>(type).newInstance();
} catch (Exception e) {
throw new RuntimeException("Fail to instantiate model by its default constructor");
}
}
}

/**
* Called when the MvcBean is disposed. This occurs when the MvcBean is de-referenced and
* not retained by any other objects.
*/
public void onDisposed() {
}

/**
* Model represents the state of this MvcBean.
* @return Null if the MvcBean doesn't need to get its model saved and restored automatically.
*/
public MODEL getModel() {
return model;
}

/**
* Provides the type class of the model.
* @return Implementing class should return the type class of the model that will be used by
* this MvcBean to instantiate its model in {@link #onConstruct()} and restores model in
* {@link #restoreModel(Object)}. Returning null is allowed which means this MvcBean doesn't
* have a model needs to be automatically saved and restored.
*/
public abstract Class<MODEL> modelType();

/**
* Restores the model of this MvcBean.
* <p>
* Note that when {@link #modelType()} returns null, this method will have no effect.
* </p>
*
* @param restoredModel The restored model by {@link ModelKeeper} that will be rebound to the
* MvcBean.
*/
public void restoreModel(MODEL restoredModel) {
if (modelType() != null) {
this.model = restoredModel;
onRestored();
}
}

/**
* Called after {@link #restoreModel(Object)} is called only when {@link #modelType()} returns
* a non-null type class.
*/
public void onRestored() {
}
}
Loading