Pan
A light weight MV* framework to build android reusable UI components.
?????????????? sample-github-users
????
Getting Started
Pan????????????Pan???????????????????????????
????????Activity???????Pan?????with???ViewModel??????ViewModel?Controller?Activity??????with?????????????????????
public class MainActivity extends PanActivity {
MainViewModel mMainViewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMainViewModel = Pan.with(this, MainViewModel.class)
.controlledBy(MainController.class)
.getViewModel()
.setHelloString("hello Pan!")
.render();
}
}
How clean! ???????Activity??????onResume??????????????????Controller?
???????ViewModel????ViewModel???????????ViewModel??????????
- ?v?????View??
- ?m?????ViewModel?????
render?????ViewModel?????View?
@Xml(R.layout.activity_main) //????ViewModel???????????????View???? public class MainViewModel extends GeneralViewModel {
@Bind(R.id.hello) //Butterknife
Button vHelloTv;
String mHelloString;
@Override
public MainViewModel render() {
vHelloTv.setText(mHelloString);
return this;
}
public MainViewModel setHelloString(String string) {
mHelloString = string;
return this;
}
}
????Controller????????View????Controller??????????????? Controller????????ViewModel??????????????
- ???????bindEvents()?????$vm????ViewModel??
- ??Activity/Fragment????????????????OnResume?????
public class MainController extends GeneralController<MainViewModel>
implements OnResume {
//???Activity?OnResume??
@Override
protected void bindEvents() {
$vm.vHelloTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), $vm.mHelloString, Toast.LENGTH_SHORT).show();
}
}
);
}
@Override
public void onResume() {
Log.d("MainController", "On Resume For " + getActivity());
}
}
?????XML:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/hello"
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
??Pan????
repositories {
//jitpack repository
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.campusappcn:Pan:0.9.3'
}
??? @PrototypeZ??Pan????????????
License
Copyright 2015 ???????????? 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.