-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
280 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,11 @@ | |
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
#*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
#*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
# GoogleLibraryVersionQuerier | ||
一款Android Studio插件,用于快速查询和替换Google最新版本仓库。 | ||
## 一款Android Studio插件,帮助你快速添加Google依赖库和查询历史版本 | ||
### 特性: | ||
#### 1. 编辑build.gradle时,会有代码提示: | ||
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/1.gif) | ||
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/2.gif) | ||
|
||
<br/> | ||
|
||
#### 2. 光标定位在目标类库,右键可快速查看和替换某个版本: | ||
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/3.gif) ![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/4.gif) | ||
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/5.gif) | ||
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/6.gif) | ||
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/7.gif) | ||
|
||
<br/> | ||
|
||
### 安装: | ||
*Android Studio -> Settings -> Plugins -> Marketplace*: | ||
搜索:***Google Library Version Querier***即可: | ||
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/8.gif) | ||
|
||
<br/> | ||
|
||
### 数据来源:[wanandroid.com](https://wanandroid.com/maven_pom/index) |
Binary file not shown.
Binary file modified
BIN
+5 Bytes
(110%)
...production/GoogleLibraryVersionQuerier/META-INF/GoogleLibraryVersionQuerier.kotlin_module
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.wuyr.google_library_query | ||
|
||
import com.intellij.codeInsight.completion.CompletionContributor | ||
import com.intellij.codeInsight.completion.CompletionInitializationContext | ||
import com.intellij.codeInsight.completion.CompletionParameters | ||
import com.intellij.codeInsight.completion.CompletionResultSet | ||
import com.intellij.codeInsight.lookup.LookupElementBuilder | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.util.PlatformIcons | ||
|
||
|
||
class GradleContributor : CompletionContributor() { | ||
|
||
private var needShow = false | ||
private val acceptFilesName = arrayOf("build.gradle") | ||
|
||
override fun beforeCompletion(context: CompletionInitializationContext) { | ||
needShow = acceptFilesName.contains(context.file.name) | ||
} | ||
|
||
override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) { | ||
if (needShow) { | ||
val lineStartPosition = parameters.editor.caretModel.visualLineStart | ||
val lineEndPosition = parameters.editor.caretModel.visualLineEnd | ||
val currentLineContent = parameters.editor.document.getText(TextRange(lineStartPosition, lineEndPosition)).replace("\n".toRegex(), "").trim() | ||
if (currentLineContent.length < 4) { | ||
return | ||
} | ||
currentLineContent.split("\\s+".toRegex()).let { | ||
if (it.isNotEmpty()) { | ||
var removeImplementation = false | ||
val keyword = if (it.size == 1) { | ||
it.first() | ||
} else { | ||
if (it.first() == "implementation") removeImplementation = true | ||
it.last() | ||
} | ||
matchingLibraries(keyword).forEach { e -> | ||
result.addElement(e.toLookupElement(removeImplementation)) | ||
} | ||
} | ||
} | ||
needShow = false | ||
} | ||
super.fillCompletionVariants(parameters, result) | ||
} | ||
|
||
private fun Pair<String, String>.toLookupElement(removeImplementation: Boolean) = LookupElementBuilder | ||
.create(if (removeImplementation) first.replace("implementation ", "") else first) | ||
.bold().withIcon(PlatformIcons.LIBRARY_ICON).withTypeText(second, true) | ||
.withTypeIconRightAligned(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
@file:Suppress("UNCHECKED_CAST") | ||
|
||
package com.wuyr.google_library_query | ||
|
||
import com.google.gson.Gson | ||
import java.net.URL | ||
import java.nio.charset.Charset | ||
import javax.net.ssl.HttpsURLConnection | ||
import javax.swing.DefaultListModel | ||
|
||
const val BASE_URL = "https://wanandroid.com/maven_pom/" | ||
|
||
@Throws(java.lang.Exception::class) | ||
fun getAvailableVersions(libraryGroup: String, libraryName: String) = search("$libraryGroup:$libraryName") { dataList -> | ||
dataList.find { it["groupName"] == libraryGroup }?.run { | ||
(this["artifactMap"] as? Map<String, Any>)?.run { | ||
(this[libraryName] as? List<Map<String, Any>>)?.map { | ||
it["version"].toString() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Throws(java.lang.Exception::class) | ||
fun matchingLibraries(keyword: String) = ArrayList<Pair<String, String>>().apply { | ||
runSafely { | ||
search(keyword) { dataList -> | ||
dataList.map { | ||
(it["artifactMap"] as? Map<String, List<Map<String, Any>>>)?.values?.map { e -> | ||
e.last().run { | ||
this["content"].toString() to this["group"].toString() | ||
} | ||
} | ||
}.forEach { it?.let { addAll(it) } } | ||
} | ||
} | ||
} | ||
|
||
@Throws(java.lang.Exception::class) | ||
inline fun <O> search(keyword: String, block: (List<Map<String, Any>>) -> O): O? = (URL(BASE_URL + "search/json?k=$keyword").openConnection() as HttpsURLConnection).run { | ||
if (responseCode == 200) { | ||
val json = inputStream.readBytes().toString(Charset.forName("utf-8")) | ||
((Gson().fromJson(json, Map::class.java)["data"]) as? List<Map<String, Any>>)?.run { | ||
block(this) | ||
} | ||
} else null | ||
} | ||
|
||
inline fun <T, R> T.runSafely(block: (T) -> R) = try { | ||
block(this) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
null | ||
} | ||
|
||
fun main() { | ||
val libraryGroup = "androidx.recyclerview" | ||
val libraryName = "recyclerview" | ||
println("json: " + getAvailableVersions(libraryGroup, libraryName)) | ||
println("matchingLibraries: " + matchingLibraries("recy")) | ||
VersionSelectorDialog.show(DefaultListModel<String>().apply { | ||
getAvailableVersions(libraryGroup, libraryName)?.forEach { | ||
addElement(it) | ||
} | ||
}) { | ||
println(it) | ||
} | ||
} |
Oops, something went wrong.