Skip to content

Commit

Permalink
Merge pull request #2 from FindaDeveloper/dohun
Browse files Browse the repository at this point in the history
Dohun
  • Loading branch information
kimdohun0104 authored Feb 20, 2021
2 parents dec22ae + a28eddc commit a6d5c9b
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kr.co.finda.androidtemplate

import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManagerListener
import kr.co.finda.androidtemplate.feature.waistUp.WaistUpService

class FindaProjectManagerListener : ProjectManagerListener {

override fun projectOpened(project: Project) {
project.service<WaistUpService>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.intellij.openapi.vfs.VirtualFile
import icons.Icons
import kr.co.finda.androidtemplate.type.PluginError
import kr.co.finda.androidtemplate.feature.createFindaTemplate.dialog.CreateFindaTemplateDialog
import kr.co.finda.androidtemplate.model.ActionRouterImpl
import kr.co.finda.androidtemplate.util.ActionRouterImpl

class CreateFindaTemplateAction :
AnAction(), CreateFindaTemplateActionContract.View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kr.co.finda.androidtemplate.feature.createFindaTemplate.action
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import kr.co.finda.androidtemplate.model.ActionRouter
import kr.co.finda.androidtemplate.util.ActionRouter
import kr.co.finda.androidtemplate.type.PluginError

class CreateFindaTemplateActionPresenter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package kr.co.finda.androidtemplate.feature.createFindaTemplate.dialog

import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EnumComboBoxModel
import com.intellij.ui.components.JBTextField
import com.intellij.ui.layout.panel
import com.intellij.util.ui.FormBuilder
import icons.Icons
import kr.co.finda.androidtemplate.type.PluginError
import kr.co.finda.androidtemplate.model.FileHelperImpl
import kr.co.finda.androidtemplate.model.ReplacerImpl
import kr.co.finda.androidtemplate.util.FileHelperImpl
import kr.co.finda.androidtemplate.util.ReplacerImpl
import kr.co.finda.androidtemplate.type.ScreenType
import javax.swing.JComponent

Expand All @@ -27,28 +28,21 @@ class CreateFindaTemplateDialog(
}

private val screenTypeModel = EnumComboBoxModel(ScreenType::class.java)
private lateinit var nameTextField: JBTextField

private val nameTextField = JBTextField()
private val screenTypeComboBox = ComboBox(screenTypeModel)
private val panel = FormBuilder.createFormBuilder()
.addLabeledComponent("화면 이름:", nameTextField)
.addLabeledComponent("화면 종류:", screenTypeComboBox)
.panel

init {
init()
title = "Create Finda Template"
}

override fun createCenterPanel(): JComponent {
return panel {

row("화면 이름:") {
nameTextField = textField({ "" }, {}).component
}

row("화면 종류:") {
comboBox(
screenTypeModel,
{ screenTypeModel.selectedItem },
{ screenTypeModel.setSelectedItem(it) }
)
}
}
return panel
}

override fun doOKAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package kr.co.finda.androidtemplate.feature.createFindaTemplate.dialog
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import kr.co.finda.androidtemplate.type.PluginError
import kr.co.finda.androidtemplate.model.FileHelper
import kr.co.finda.androidtemplate.model.Replacements
import kr.co.finda.androidtemplate.util.FileHelper
import kr.co.finda.androidtemplate.util.Replacements
import kr.co.finda.androidtemplate.ext.decapitalizeWithUnderBar
import kr.co.finda.androidtemplate.type.FileExtension
import kr.co.finda.androidtemplate.type.ScreenType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.VirtualFile
import icons.Icons
import kr.co.finda.androidtemplate.feature.createViewModelTest.dialog.CreateViewModelTestDialog
import kr.co.finda.androidtemplate.model.ActionRouterImpl
import kr.co.finda.androidtemplate.util.ActionRouterImpl
import kr.co.finda.androidtemplate.type.PluginError

class CreateViewModelTestAction :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kr.co.finda.androidtemplate.feature.createViewModelTest.action
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import kr.co.finda.androidtemplate.model.ActionRouter
import kr.co.finda.androidtemplate.util.ActionRouter
import kr.co.finda.androidtemplate.type.PluginError

class CreateViewModelTestActionPresenter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.components.JBTextField
import com.intellij.ui.layout.panel
import com.intellij.util.ui.FormBuilder
import icons.Icons
import kr.co.finda.androidtemplate.model.FileHelperImpl
import kr.co.finda.androidtemplate.model.ReplacerImpl
import kr.co.finda.androidtemplate.util.FileHelperImpl
import kr.co.finda.androidtemplate.util.ReplacerImpl
import kr.co.finda.androidtemplate.type.PluginError
import javax.swing.JComponent

Expand All @@ -21,19 +21,18 @@ class CreateViewModelTestDialog(
CreateViewModelTestDialogPresenter(this, FileHelperImpl(ReplacerImpl()))
}

private lateinit var nameTextField: JBTextField
private val nameTextField = JBTextField()
private val panel = FormBuilder.createFormBuilder()
.addLabeledComponent("ViewModel 이름:", nameTextField)
.panel

init {
init()
title = "Create ViewModel Test Template"
}

override fun createCenterPanel(): JComponent {
return panel {
row("ViewModel 이름:") {
nameTextField = textField({ "" }, {}).component
}
}
return panel
}

override fun doOKAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package kr.co.finda.androidtemplate.feature.createViewModelTest.dialog

import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import kr.co.finda.androidtemplate.model.FileHelper
import kr.co.finda.androidtemplate.model.Replacements
import kr.co.finda.androidtemplate.util.FileHelper
import kr.co.finda.androidtemplate.util.Replacements
import kr.co.finda.androidtemplate.type.FileExtension
import kr.co.finda.androidtemplate.type.PluginError

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.co.finda.androidtemplate.feature
package kr.co.finda.androidtemplate.feature.liveTemplate

import com.intellij.codeInsight.template.TemplateContextType
import com.intellij.psi.PsiFile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kr.co.finda.androidtemplate.feature.setting

import com.intellij.ui.components.CheckBox
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField
import com.intellij.ui.layout.panel
import com.intellij.util.ui.FormBuilder
import kr.co.finda.androidtemplate.type.WaistUpState
import javax.swing.JPanel

class FindaSettingComponent(
state: WaistUpState
) {

val hideDelayTextField: JBTextField = JBTextField()
val waitDelayTextField: JBTextField = JBTextField()
val waistUpCheckBox: JBCheckBox = JBCheckBox("허리펴! 알림 활성화")

val panel: JPanel = FormBuilder.createFormBuilder()
.addComponent(JBLabel("허리펴! 설정"))
.addLabeledComponent("숨김 시간", hideDelayTextField)
.addLabeledComponent("다음 허리펴! 까지 시간", waitDelayTextField)
.addComponent(waistUpCheckBox)
.panel

init {
hideDelayTextField.text = state.hideDelay.toString()
waitDelayTextField.text = state.waitDelay.toString()
waistUpCheckBox.isSelected = state.isEnabled
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package kr.co.finda.androidtemplate.feature.setting

import com.intellij.openapi.options.Configurable
import kr.co.finda.androidtemplate.feature.waistUp.WaistUpService
import javax.swing.JComponent

class FindaSettingConfigurable : Configurable {

private lateinit var component: FindaSettingComponent

override fun createComponent(): JComponent {
component = FindaSettingComponent(WaistUpService.state)
return component.panel
}

override fun isModified(): Boolean {
val state = WaistUpService.state
return state.isEnabled != component.waistUpCheckBox.isSelected
|| state.hideDelay != component.hideDelayTextField.text.toLong()
|| state.waitDelay != component.waitDelayTextField.text.toLong()
}

override fun apply() {
val state = WaistUpService.state
state.isEnabled = component.waistUpCheckBox.isSelected
state.hideDelay = component.hideDelayTextField.text.toLong()
state.waitDelay = component.waitDelayTextField.text.toLong()

WaistUpService.setNotificationEnable(state.isEnabled)
}

override fun getPreferredFocusedComponent(): JComponent {
return component.hideDelayTextField
}

override fun reset() {
val state = WaistUpService.state
component.waistUpCheckBox.isSelected = state.isEnabled
component.hideDelayTextField.text = state.hideDelay.toString()
component.waitDelayTextField.text = state.waitDelay.toString()
}

override fun getDisplayName(): String {
return "Finda Settings"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kr.co.finda.androidtemplate.feature.waistUp

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.options.newEditor.SettingsDialog
import kr.co.finda.androidtemplate.feature.setting.FindaSettingConfigurable

class SetWaistUpStateAction : AnAction("타이머 설정") {

override fun actionPerformed(e: AnActionEvent) {
ShowSettingsUtil.getInstance().editConfigurable(e.project, FindaSettingConfigurable())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package kr.co.finda.androidtemplate.feature.waistUp

import com.intellij.notification.NotificationDisplayType
import com.intellij.notification.NotificationGroup
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import kotlinx.coroutines.*
import kr.co.finda.androidtemplate.type.WaistUpState

@State(
name = "WaistUp",
storages = [Storage("FindaPlugin.xml")]
)
object WaistUpService : PersistentStateComponent<WaistUpState> {

private val balloonGroup = NotificationGroup(
"FindaTest",
NotificationDisplayType.BALLOON,
true
)

private var state = WaistUpState()

var job: Job? = null

init {
setNotificationEnable(state.isEnabled)
}

override fun getState(): WaistUpState {
return state
}

override fun loadState(state: WaistUpState) {
this.state = state
}

fun setNotificationEnable(isEnable: Boolean) {
job?.cancel()
if (isEnable) startNotification()
}

private fun startNotification() {
job = GlobalScope.launch(Dispatchers.IO) {
while (true) {
val notification = balloonGroup.createNotification(
title = "허리펴!",
content = "Finda 플러그인은 당신의 건강을 책임집니다",
type = NotificationType.WARNING
)
notification.addAction(SetWaistUpStateAction())
notification.notify(null)

delay(state.hideDelay)
notification.expire()

delay(state.waitDelay)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.finda.androidtemplate.type

data class WaistUpState(
var isEnabled: Boolean = true,
var hideDelay: Long = 2000,
var waitDelay: Long = 2000
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.co.finda.androidtemplate.model
package kr.co.finda.androidtemplate.util

interface ActionRouter {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package kr.co.finda.androidtemplate.model
package kr.co.finda.androidtemplate.util

import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.util.ResourceUtil
import kr.co.finda.androidtemplate.ext.replaceAll
import kr.co.finda.androidtemplate.type.FileExtension
import java.io.File
import java.net.URI
import java.nio.file.Files
import java.nio.file.Paths

interface FileHelper {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.co.finda.androidtemplate.model
package kr.co.finda.androidtemplate.util

import kr.co.finda.androidtemplate.ext.replaceAllIfNotNull

Expand Down
Loading

0 comments on commit a6d5c9b

Please sign in to comment.