Merge pull request #595 from msya/msya/add-kotlin
Add Kotlin and Convert SuggestionManager to Kotlin
This commit is contained in:
commit
0183a66e1e
@ -1,4 +1,5 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
apply plugin: 'com.getkeepsafe.dexcount'
|
apply plugin: 'com.getkeepsafe.dexcount'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@ -108,4 +109,7 @@ dependencies {
|
|||||||
def leakCanaryVersion = '1.5.1'
|
def leakCanaryVersion = '1.5.1'
|
||||||
debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
||||||
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
|
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
|
||||||
|
|
||||||
|
// Kotlin
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
package acr.browser.lightning.search;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Single;
|
|
||||||
import com.anthonycr.bonsai.SingleAction;
|
|
||||||
import com.anthonycr.bonsai.SingleSubscriber;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import acr.browser.lightning.database.HistoryItem;
|
|
||||||
import acr.browser.lightning.search.suggestions.BaiduSuggestionsModel;
|
|
||||||
import acr.browser.lightning.search.suggestions.DuckSuggestionsModel;
|
|
||||||
import acr.browser.lightning.search.suggestions.GoogleSuggestionsModel;
|
|
||||||
|
|
||||||
class SuggestionsManager {
|
|
||||||
|
|
||||||
private static volatile boolean sIsTaskExecuting;
|
|
||||||
|
|
||||||
static boolean isRequestInProgress() {
|
|
||||||
return sIsTaskExecuting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
static Single<List<HistoryItem>> createGoogleQueryObservable(@NonNull final String query,
|
|
||||||
@NonNull final Application application) {
|
|
||||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(@NonNull final SingleSubscriber<List<HistoryItem>> subscriber) {
|
|
||||||
sIsTaskExecuting = true;
|
|
||||||
List<HistoryItem> results = new GoogleSuggestionsModel(application).fetchResults(query);
|
|
||||||
subscriber.onItem(results);
|
|
||||||
subscriber.onComplete();
|
|
||||||
sIsTaskExecuting = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
static Single<List<HistoryItem>> createBaiduQueryObservable(@NonNull final String query,
|
|
||||||
@NonNull final Application application) {
|
|
||||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(@NonNull final SingleSubscriber<List<HistoryItem>> subscriber) {
|
|
||||||
sIsTaskExecuting = true;
|
|
||||||
List<HistoryItem> results = new BaiduSuggestionsModel(application).fetchResults(query);
|
|
||||||
subscriber.onItem(results);
|
|
||||||
subscriber.onComplete();
|
|
||||||
sIsTaskExecuting = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
static Single<List<HistoryItem>> createDuckQueryObservable(@NonNull final String query,
|
|
||||||
@NonNull final Application application) {
|
|
||||||
return Single.create(new SingleAction<List<HistoryItem>>() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(@NonNull final SingleSubscriber<List<HistoryItem>> subscriber) {
|
|
||||||
sIsTaskExecuting = true;
|
|
||||||
List<HistoryItem> results = new DuckSuggestionsModel(application).fetchResults(query);
|
|
||||||
subscriber.onItem(results);
|
|
||||||
subscriber.onComplete();
|
|
||||||
sIsTaskExecuting = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,46 @@
|
|||||||
|
package acr.browser.lightning.search
|
||||||
|
|
||||||
|
import acr.browser.lightning.database.HistoryItem
|
||||||
|
import acr.browser.lightning.search.suggestions.BaiduSuggestionsModel
|
||||||
|
import acr.browser.lightning.search.suggestions.DuckSuggestionsModel
|
||||||
|
import acr.browser.lightning.search.suggestions.GoogleSuggestionsModel
|
||||||
|
import android.app.Application
|
||||||
|
import com.anthonycr.bonsai.Single
|
||||||
|
import com.anthonycr.bonsai.SingleAction
|
||||||
|
|
||||||
|
internal object SuggestionsManager {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@Volatile var isRequestInProgress: Boolean = false
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun createGoogleQueryObservable(query: String, application: Application) =
|
||||||
|
Single.create(SingleAction<List<HistoryItem>> { subscriber ->
|
||||||
|
isRequestInProgress = true
|
||||||
|
val results = GoogleSuggestionsModel(application).fetchResults(query)
|
||||||
|
subscriber.onItem(results)
|
||||||
|
subscriber.onComplete()
|
||||||
|
isRequestInProgress = false
|
||||||
|
})
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun createBaiduQueryObservable(query: String, application: Application) =
|
||||||
|
Single.create(SingleAction<List<HistoryItem>> { subscriber ->
|
||||||
|
isRequestInProgress = true
|
||||||
|
val results = BaiduSuggestionsModel(application).fetchResults(query)
|
||||||
|
subscriber.onItem(results)
|
||||||
|
subscriber.onComplete()
|
||||||
|
isRequestInProgress = false
|
||||||
|
})
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun createDuckQueryObservable(query: String, application: Application) =
|
||||||
|
Single.create(SingleAction<List<HistoryItem>> { subscriber ->
|
||||||
|
isRequestInProgress = true
|
||||||
|
val results = DuckSuggestionsModel(application).fetchResults(query)
|
||||||
|
subscriber.onItem(results)
|
||||||
|
subscriber.onComplete()
|
||||||
|
isRequestInProgress = false
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
|
ext.kotlin_version = '1.1.3'
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.3'
|
classpath 'com.android.tools.build:gradle:2.3.3'
|
||||||
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.3'
|
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.3'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user