网络请求
点击这里就出来一个弹框
更新Actions
关注这个
程序底部导入网络请求api
dependencies {//导入 retrofit 和rxjavaimplementation("com.squareup.retrofit2:retrofit:2.9.0")implementation("com.squareup.retrofit2:converter-gson:2.9.0")implementation("com.squareup.retrofit2:adapter-rxjava2:2.9.0")implementation("io.reactivex.rxjava2:rxjava:2.2.21")implementation("io.reactivex.rxjava2:rxandroid:2.1.1")//导入swing 0.3.0implementation("com.github.akarnokd:rxjava2-swing:0.3.0")
}
出来弹框我们先看到的就是布局
直接从头开始写吧
package com.anguomob.anguo.actions.trelloimport com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEventclass TrelloAction :AnAction() {override fun actionPerformed(event: AnActionEvent) {val dialog=TrelloForm(event.project!!,TrelloInjectorImp())dialog.show()}
}
创建一个dialog 并且展示布局
采用了mvp模式
package com.anguomob.anguo.actions.trelloimport retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactoryinterface TrelloInjector {val trelloRepository: TrelloRepositoryval trelloServiceApi: TrelloServiceApifun trelloActionPresenter(view: TrelloFromView): TrelloActionPresenter
}class TrelloInjectorImp : TrelloInjector {override val trelloRepository: TrelloRepository by lazy {TrelloRepositoryImp(trelloServiceApi)}override val trelloServiceApi: TrelloServiceApi by lazy {Retrofit.Builder().addCallAdapterFactory(RxJava2CallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create()).baseUrl("https://api.trello.com/").build().create(TrelloServiceApi::class.java)}override fun trelloActionPresenter(view: TrelloFromView): TrelloActionPresenter {return TrelloActionPresenterImp(view, trelloRepository)}
}
仓库api
package com.anguomob.anguo.actions.trelloimport hu.akarnokd.rxjava2.swing.SwingSchedulers
import io.reactivex.Completable
import io.reactivex.Single
import io.reactivex.schedulers.Schedulersinterface TrelloRepository {fun getCards(formListId: String, key: String, token: String): Single>fun moveCard(cardId: String, toListId: String, key: String, token: String): Completable
}class TrelloRepositoryImp(private val trelloServiceApi: TrelloServiceApi) : TrelloRepository {override fun getCards(formListId: String, key: String, token: String): Single> {return trelloServiceApi.getCards(formListId, key, token).subscribeOn(Schedulers.io()).observeOn(SwingSchedulers.edt())}override fun moveCard(cardId: String, toListId: String, key: String, token: String): Completable {return trelloServiceApi.moveCardToList(cardId, toListId, key, token).subscribeOn(Schedulers.io()).observeOn(SwingSchedulers.edt())}}
servicesApi
package com.anguomob.anguo.actions.trelloimport io.reactivex.Completable
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Queryinterface TrelloServiceApi {@GET("1/boards/{listId}/cards")fun getCards(@Path("listId") listId: String, @Query("key") key: String, @Query("token") token: String): Single>@PUT("1/cards/{cardId}")fun moveCardToList(@Path("cardId") cardId: String,@Query("idList") idList: String,@Query("key") key: String,@Query("token") token: String): Completable}
数据bean
package com.anguomob.anguo.actions.trellodata class Card(val id: String, val name: String, val desc: String)
view点击产生的回调
package com.anguomob.anguo.actions.trellointerface TrelloFromView {fun showCards(cards:List)fun success(card: Card)fun error(error: Throwable)
}
布局内容
package com.anguomob.anguo.actions.trelloimport com.intellij.notification.NotificationDisplayType
import com.intellij.notification.NotificationGroup
import com.intellij.notification.NotificationType
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.layout.panel
import java.awt.Dimension
import javax.swing.*class TrelloForm(val project: Project, trelloInjector: TrelloInjector
) : DialogWrapper(project), TrelloFromView {private var nameCombo: ComboBox = ComboBox().apply {name = "nameCombo"}private var descriptionTextPanel: JTextPane = JTextPane().apply {name = "descriptionTextPanel"text = "test"isEnabled = false}private val presenter: TrelloActionPresenter by lazy {trelloInjector.trelloActionPresenter(this)}init {init()nameCombo.addActionListener {val card = nameCombo.selectedItem as Card?card?.let {descriptionTextPanel.text = it.desc}}presenter.loadCards()}override fun createCenterPanel(): JComponent = panel {row("Name: ") {nameCombo(grow)}row("Description") {descriptionTextPanel()}}.apply {minimumSize = Dimension(500, 340)preferredSize = Dimension(500, 340)}override fun showCards(cards: List) {cards.map {nameCombo.addItem(it)}if (cards.isNotEmpty()) {nameCombo.selectedIndex = 0}}override fun success(card: Card) {close(OK_EXIT_CODE)ApplicationManager.getApplication().invokeLater {//创建通知val notification = NotificationGroup("success", NotificationDisplayType.BALLOON, true).createNotification("成功啦","Move card to newList",NotificationType.INFORMATION,null)notification.notify(project)}}override fun error(error: Throwable) {ApplicationManager.getApplication().invokeLater {//创建通知val notification = NotificationGroup("error", NotificationDisplayType.BALLOON, true).createNotification("error",error.localizedMessage,NotificationType.INFORMATION,null)notification.notify(project)}}
}
核心代码
package com.anguomob.anguo.actions.trellointerface TrelloActionPresenter {fun loadCards()fun moveCard(card: Card)
}class TrelloActionPresenterImp(private val view: TrelloFromView, private val repository: TrelloRepository) :TrelloActionPresenter {val fromListId="xxx"val toListId="xxx"val apiKey="xx"val token="xxxxx"override fun loadCards() {repository.getCards(fromListId, apiKey, token).subscribe({ cards -> view.showCards(cards) }, { error -> view.error(error) })}override fun moveCard(card: Card) {repository.moveCard(card.id, toListId, apiKey, token).subscribe({ view.success(card) }, { error -> view.error(error) })}
}
moveCard 还没用到。
这个loadCards用到了
这个用的是 fromListId
这个id可获取有点费劲
来我教你们
GET获取看板列表
https://api.trello.com/1/members/me/boards?key={{APIKey}}&token={{APIToken}}
var jsonData = pm.response.json();
var boardCardId= jsonData['0']['id']
pm.environment.set("BoardCardId", boardCardId);
然后取出来第一个参数 那么这个参数就是看板咯
看板的cards的 列表id就是这个。
稍微一等 布局就会加载列表
并且选了以后可以把描述打出来
这个插件功能先到这里咯。更多精彩我还在学习。。
上一篇:制作电子签名