Skip to content

Commit

Permalink
Fix upload file pick filter
Browse files Browse the repository at this point in the history
  • Loading branch information
alvince committed Jul 21, 2017
1 parent 9a22473 commit cfebc01
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 33 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.1.3'
ext.kotlin_version = '1.1.3-2'

repositories {
mavenCentral()
Expand Down Expand Up @@ -30,7 +30,7 @@ apply plugin: 'kotlin'
intellij {
version 'IC-2017.1.5'
pluginName 'TinyPic2'
updateSinceUntilBuild false
intellij.updateSinceUntilBuild false
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alvincezy/tinypic2/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Created by alvince on 17-6-28.
*
* @author [email protected]
* @version 2.0.1, 7/20/2017
* @since 2.0
* @version 1.0.1, 7/20/2017
* @since 1.0
*/
public interface Constants {
String LINK_TINY_PNG_DEVELOPER = "https://tinypng.com/developers";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alvincezy/tinypic2/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* Created by alvince on 2017/6/28.
*
* @author [email protected]
* @version 2.0.1, 7/20/2017
* @since 2.0
* @version 1.0.1, 7/20/2017
* @since 1.0
*/
@State(name = "TinyPicPreferences", storages = @Storage(value = "$APP_CONFIG$/TinyPic2.xml"))
public class Preferences implements PersistentStateComponent<Preferences> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alvincezy/tinypic2/TinifyExcutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Created by alvince on 17-7-12.
*
* @author [email protected]
* @version 2.0, 7/12/2017
* @since 2.0
* @version 1.0, 7/12/2017
* @since 1.0
*/
public class TinifyExcutor {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import javax.swing.*
* Created by alvince on 2017/6/28.
*
* @author [email protected]
* @version 2.0, 7/18/2017
* @since 2.0
* @version 1.0, 7/18/2017
* @since 1.0
*/
class TinyPicOptionsConfigurable : SearchableConfigurable, Configurable.NoScroll, Disposable {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alvincezy/tinypic2/ui/PreferencesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* Created by alvince on 2017/6/28.
*
* @author [email protected]
* @version 2.0, 7/18/2017
* @since 2.0
* @version 1.0, 7/18/2017
* @since 1.0
*/
public class PreferencesPanel {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alvincezy/tinypic2/util/ComponentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Created by alvince on 17-6-29.
*
* @author [email protected]
* @version 2.0, 6/28/2017
* @since 2.0
* @version 1.0, 6/28/2017
* @since 1.0
*/
public class ComponentUtil {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alvincezy/tinypic2/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Created by alvince on 17-6-29.
*
* @author [email protected]
* @version 2.0, 6/28/2017
* @since 2.0
* @version 1.0, 6/28/2017
* @since 1.0
*/
public class StringUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.intellij.openapi.project.Project
* Created by alvince on 17-7-11.
*
* @author [email protected]
* @version 2.0, 7/12/2017
* @since 2.0
* @version 1.0, 7/12/2017
* @since 1.0
*/
open class TinifyAction internal constructor() : AnAction() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.alvincezy.tinypic2.actions

import com.alvincezy.tinypic2.TinifyFlowable
import com.alvincezy.tinypic2.TinyPicOptionsConfigurable
import com.alvincezy.tinypic2.model.VirtualFileAware
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.fileChooser.FileChooser
import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.progress.ProgressIndicator
Expand All @@ -26,8 +28,8 @@ import java.util.concurrent.Executors
* Created by alvince on 2017/6/28.
*
* @author [email protected]
* @version 2.0, 7/18/2017
* @since 2.0
* @version 1.0.1, 7/21/2017
* @since 1.0
*/
class TinyPicUploadAction : TinifyAction() {

Expand All @@ -37,7 +39,8 @@ class TinyPicUploadAction : TinifyAction() {

@Volatile internal var taskPool = HashMap<String, Runnable>()

private val tinifySource = ArrayList<VirtualFile>()
private val logger = Logger.getInstance(javaClass)
private val tinifySource = ArrayList<VirtualFileAware>()
private val tinifyThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())

override fun performAction(actionEvent: AnActionEvent, project: Project) {
Expand All @@ -54,15 +57,14 @@ class TinyPicUploadAction : TinifyAction() {
tinifySource.clear()
val descriptor = FileChooserDescriptor(true, true, false, false, false, true)
val selectedFiles = FileChooser.chooseFiles(descriptor, project, null)
Observable.from(selectedFiles)
Observable.just(selectedFiles)
.subscribeOn(Schedulers.io())
.filter {
if (selectedFiles.isNotEmpty()) {
selectedFiles.forEach { parseFilePicked(it) }
}
tinifySource.isNotEmpty()
}
.subscribe({ uploadAndTinify() }, { it.printStackTrace() })
.filter { selectedFiles.isNotEmpty() }
.subscribe({
selectedFiles.forEach { parseFilePicked(it) }
// logger.debug("${tinifySource.toArray()}")
uploadAndTinify()
}, { it.printStackTrace() })
}

@Suppress("name_shadowing")
Expand All @@ -71,7 +73,10 @@ class TinyPicUploadAction : TinifyAction() {
override fun visitFile(file: VirtualFile): Boolean {
val filename = file.name.toLowerCase()
if (filename.endsWith(".jpg") || filename.endsWith(".png")) {
tinifySource.add(file)
val fileW = VirtualFileAware(file)
if (tinifySource.contains(fileW))
return false
tinifySource.add(fileW)
}
return true
}
Expand All @@ -84,7 +89,8 @@ class TinyPicUploadAction : TinifyAction() {
isEnabledInModalContext = false
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Perform Picture Tinify") {
override fun run(indicator: ProgressIndicator) {
tinifySource.forEach { file -> tinifyThreadPool.execute(TaskRunnable(file)) }
tinifySource.map { it.file }
.forEach { file -> tinifyThreadPool.execute(TaskRunnable(file)) }
while (true) {
if (taskPool.isEmpty()) break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import javax.swing.event.HyperlinkEvent
* Created by alvince on 17-7-20.
*
* @author [email protected]
* @version 2.0.1, 7/20/2017
* @since 2.0.1
* @version 1.0.1, 7/20/2017
* @since 1.0.1
*/
class TinifyComponent(project: Project) : AbstractProjectComponent(project) {

Expand Down
33 changes: 33 additions & 0 deletions src/main/kotlin/com/alvincezy/tinypic2/model/VirtualFileAware.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.alvincezy.tinypic2.model

import com.intellij.openapi.vfs.VirtualFile

/**
* Created by alvince on 2017/7/21.
*
* @author [email protected]
* @version 1.0.1, 7/21/2017
*/
class VirtualFileAware(val file: VirtualFile) {

var fileUri = file.url

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false

other as VirtualFileAware

if (fileUri != other.fileUri) return false

return true
}

override fun hashCode(): Int {
return fileUri.hashCode()
}

override fun toString(): String {
return fileUri
}
}

0 comments on commit cfebc01

Please sign in to comment.