SVC⛔ [DEPRECATED]
Deprecated
It will be sustained on git below.
https://github.com/BansookNam/svc
It will be sustained on git below.
https://github.com/BansookNam/svc
@SvcFragment
@RequireViews(StatisticViews::class)
@RequireControlTower(StatisticControlTower::class) // magic things do happening
class StatisticFragment : SVC_StatisticFragment() { // SVC_StatisticFragment will be generated after build project.
//extend SVC_{name of class}
}
@SvcDialogFragment
@RequireViews(SampleActionViews::class)
@RequireControlTower(SampleActionControlTower::class)
@RequireListener(SampleActionDialogListener::class) //listener from another screen.
class SampleActionDialog : SVC_SampleActionDialog() { // SVC_SampleActionDialog will be generated after build project.
//extend SVC_{name of class}
}
SVC_{name of controlTower class}
class.ControlTower
.RequireScreen
, RequireViews
annotation above the class.SVC_{YourControlTower}
will be generated automatically by svc processor.@ControlTower
@RequireViews(StatisticViews::class)
@RequireScreen(StatisticFragment::class) //screen which this controlTower will be used.
class StatisticControlTower : SVC_StatisticControlTower(), StatisticViewsAction {
//extend SVC_{name of class}
//implement ViewsAction which 'Views' is needed.
}
@ControlTower
@RequireViews(CommonViews::class)
@RequireScreen(CommonScreen::class) //abstract screen is available to declare. (CommonScreen is interface)
class CommonControlTower : SVC_CommonControlTower(), CommonViewsAction {
//extend SVC_{name of class}
//implement ViewsAction which 'Views' is needed.
}
You can really divide "Views" from Activity and Fragment.
so you can see logic about real Fragment and Activity very well like below. (source link)
@SvcActivity
@RequireViews(TaskDetailViews::class)
@RequireControlTower(TaskDetailCT::class)
class TaskDetailActivity : SVC_TaskDetailActivity() {
var taskId: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
/**
* we should set taskId before super onCreate
* because createControlTower will be called on super.onCreate()
* and taskId is non null String type in constructor of TaskDetailCT
*/
taskId = intent.getStringExtra(EXTRA_TASK_ID)
super.onCreate(savedInstanceState)
}
override fun onSupportNavigateUp(): Boolean {
onBackPressed()
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
val deletePressed = item.itemId == R.id.menu_delete
if (deletePressed) ct.deleteTask()
return deletePressed
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.taskdetail_fragment_menu, menu)
return true
}
fun startEditTastActivity(taskId: String) {
val intent = Intent(this, AddEditTaskActivity::class.java)
intent.putExtra(AddEditTaskActivity.ARGUMENT_EDIT_TASK_ID, taskId)
startActivityForResult(intent, REQUEST_EDIT_TASK)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == REQUEST_EDIT_TASK) {
// If the task was edited successfully, go back to the list.
if (resultCode == Activity.RESULT_OK) {
setResult(Activity.RESULT_OK)
finish()
}
}
}
fun finishAfterDelete() {
setResult(Activity.RESULT_OK)
finish()
}
companion object {
const val EXTRA_TASK_ID = "TASK_ID"
const val REQUEST_EDIT_TASK = 1
}
}
Each alphabet stands for.
S — Screen
V — Views
C — Control Tower
+In addition
ViewsAction — Contains user interaction method which "Views" can produce. and Control Tower should know (such as click, swipe, drag..)
When we use MVP or MVVM, "View"(which is implemented on Activity, Fragment) can easily get Bigger with lots of responsibility. It has 3 main responsibility.
And both MVP, MVVM can call Business logics of Mediator directly.
As same as MVP, Mediator("ControlTower") comunicated with Model.
It's exactly same.
We can use ViewModel in ControlTower to take advantage of "Auto Lifecycle Management". We use ControlTower
as Mediator and ViewModel
as data holder. In this type, ControlTower
has Repositories
and manage the datas
Similar with type1, however in this architecture ViewModel
has Repositories
and manage the data. You can design in type2 in case of Repository
can independently divided with ControlTower
. ViewModel
will contain data change methods.
There are 2 big differences.
With this 2 big differences. We can
CommonViews
from sample)Packages are available in jcenter
Include below in your top build.gradle file
allprojects {
repositories {
jcenter() //add this line
}
}
Include below in your "application" build.gradle file
apply plugin: 'kotlin-kapt'
implementation "com.naver.android.svc:svc:1.0.0"
kapt "com.naver.android.svc:svc-compiler:1.0.0"
Github Link: https://github.com/naver/svc-template
If you want to create Activity, Fragment, DialogFragment quickly. Try SvcTemplate.
clone https://github.com/naver/svc-template.git
run shell script through command line. (Terminal in mac)./install.sh
restart Android Studio
write screen name, author then click "Finish".
You will see "Unresolved Reference" error.
click "Build" - "Rebuild Project" This will create "SVC_{component}" based on annotations.
**Done! Happy coding!
"Views" and "ControlTower" can be reused in different Screens. (It means it has same look or same viewsAction and proccess)
Views you can easily reuse "Views" in this pattern
ControlTower If you want to reuse you should implement your screen as "Screen"or make "Abstract Screen (implements Screen)" with common methods then refer the "Abstract Screen" on your reused "Views" or "ControlTower".
SVC is licensed under the Apache License, Version 2.0. See LICENSE for full license text.
Copyright 2018 NAVER Corp.
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.