Skip to content

Commit

Permalink
Migrate code to Kotlin lang (#5)
Browse files Browse the repository at this point in the history
* Migration to Kotlin (1 of 2): Code converted and refactored

* Migration to Kotlin (2 of 2): Renamed extensions .java to .kt

* Rebranding modules and namespaces

* Fix code after kotlin migration

* More fixes after kotlin migration

* Fixed lint warnings
  • Loading branch information
Alexander Biryukov authored Sep 5, 2020
1 parent 924c6c0 commit 1aac1e1
Show file tree
Hide file tree
Showing 319 changed files with 8,597 additions and 10,000 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
11 changes: 9 additions & 2 deletions dataModule/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
compileSdkVersion 30
buildToolsVersion "29.0.2"

defaultConfig {
minSdkVersion 26
targetSdkVersion 28
targetSdkVersion 30
}

buildTypes {
Expand All @@ -16,3 +17,9 @@ android {
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
8 changes: 2 additions & 6 deletions dataModule/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobnetic.coinguardiandatamodule"
package="com.aneonex.bitcoinchecker.datamodule"
android:versionCode="1"
android:versionName="1.1" >

<!--uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" /-->
android:versionName="2.0" >

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.aneonex.bitcoinchecker.datamodule.config

import com.aneonex.bitcoinchecker.datamodule.model.Market
import com.aneonex.bitcoinchecker.datamodule.model.market.*
import java.util.*

object MarketsConfig {
@kotlin.jvm.JvmField
val MARKETS = LinkedHashMap<String, Market>()
private fun addMarket(market: Market) {
MARKETS[market.key] = market
}

init {
addMarket(Bitstamp())
addMarket(Mercado())
addMarket(Kraken())
addMarket(Bitfinex())
addMarket(Okcoin())
addMarket(Cryptsy())
addMarket(Coinbase())
addMarket(Vircurex())
addMarket(Fxbtc())
addMarket(Bter())
addMarket(Justcoin())
addMarket(Btcturk())
addMarket(Coinse())
addMarket(Campbx())
addMarket(TheRock())
addMarket(CexIO())
addMarket(Virtex())
addMarket(Huobi())
addMarket(VaultOfSatoshi())
addMarket(CoinMarketIO())
addMarket(McxNOW())
addMarket(CryptoTrade())
addMarket(MintPal())
addMarket(CoinJar())
addMarket(Poloniex())
addMarket(Winkdex())
addMarket(BitX())
addMarket(CCex())
addMarket(Bitorado())
addMarket(CryptoRush())
addMarket(CoinDesk())
addMarket(Koinim())
addMarket(FybSE())
addMarket(FybSG())
addMarket(Prelude())
addMarket(BitKonan())
addMarket(BitTrex())
addMarket(Comkort())
addMarket(Bit2c())
addMarket(CryptoAltex())
addMarket(BtcMarkets())
addMarket(Bleutrade())
addMarket(ShareXcoin())
addMarket(Unisend())
addMarket(BitcoinVenezuela())
addMarket(Korbit())
addMarket(CoinTree())
addMarket(Cryptonit())
addMarket(LakeBTC())
addMarket(BitMaszyna())
addMarket(Zaydo())
addMarket(AllCoin())
addMarket(Ripio())
addMarket(DolarBlueNet())
addMarket(CoinSwap())
addMarket(Paymium())
addMarket(Bitso())
addMarket(Cryptoine())
addMarket(BitcoinToYou())
addMarket(BitexLa())
addMarket(ItBit())
addMarket(BitcoinCoId())
addMarket(HitBtc())
addMarket(CleverCoin())
addMarket(BitBay())
addMarket(QuadrigaCX())
addMarket(CoinMateIO())
addMarket(Buttercoin())
addMarket(CoinTraderNet())
addMarket(LocalBitcoins())
addMarket(Cryptopia())
addMarket(Igot())
addMarket(Mexbt())
addMarket(Vaultoro())
addMarket(BitxCom())
addMarket(BtcBox())
addMarket(BtcXIndia())
addMarket(Uphold())
addMarket(YoBit())
addMarket(ShapeShift())
addMarket(BitoEX())
addMarket(OKCoinFutures())
// addMarket(new FoscEx());
addMarket(CoinSecure())
addMarket(Dashcurex())
addMarket(Quoine())
addMarket(Livecoin())
addMarket(Gemini())
addMarket(Coinapult())
addMarket(Btc38())
addMarket(ETHEXIndia())
addMarket(GateCoin())
addMarket(Liqui())
addMarket(ChileBit())
addMarket(SurBitcoin())
addMarket(VBtc())
addMarket(Urdubit())
addMarket(NegocieCoins())
addMarket(BitMEX())
addMarket(BitFlyer())
addMarket(BitFlyerFX())
addMarket(Coinone())
addMarket(Bithumb())
addMarket(Coinsph())
addMarket(Bl3p())
addMarket(SurBtc())
addMarket(CoinFloor())
addMarket(Lykke())
addMarket(Coinnest())
addMarket(Braziliex())
addMarket(Abucoins())
addMarket(Zebpay())
addMarket(Paribu())
addMarket(SatoshiTango())
addMarket(Koinex())
// addMarket(new Unocoin());
addMarket(BlinkTrade())
addMarket(Exmo())
addMarket(Binance())
addMarket(Kucoin())
addMarket(BitcoinTrade())
addMarket(OmniTrade())
addMarket(Coinome())
addMarket(Nocks())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.aneonex.bitcoinchecker.datamodule.config

object Settings {
var userCountry: String? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.aneonex.bitcoinchecker.datamodule.model

import java.util.*

class CheckerInfo(currencyBase: String, currencyCounter: String, currencyPairId: String?, val contractType: Int)
: CurrencyPairInfo(currencyBase, currencyCounter, currencyPairId) {
val currencyBaseLowerCase: String
get() = currencyBase.toLowerCase(Locale.US)
val currencyCounterLowerCase: String
get() = currencyCounter.toLowerCase(Locale.US)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.aneonex.bitcoinchecker.datamodule.model

open class CurrencyPairInfo(val currencyBase: String, val currencyCounter: String, val currencyPairId: String?) : Comparable<CurrencyPairInfo> {
@Throws(NullPointerException::class)
override fun compareTo(other: CurrencyPairInfo): Int {
val compBase = currencyBase.compareTo(other.currencyBase, ignoreCase = true)
return if (compBase != 0) compBase else currencyCounter.compareTo(other.currencyCounter, ignoreCase = true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.aneonex.bitcoinchecker.datamodule.model

class CurrencyPairsListWithDate {
@kotlin.jvm.JvmField
var date: Long = 0
@kotlin.jvm.JvmField
var pairs: List<CurrencyPairInfo>? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.aneonex.bitcoinchecker.datamodule.model

class CurrencySubunit @JvmOverloads constructor(val name: String, val subunitToUnit: Long, val allowDecimal: Boolean = true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.aneonex.bitcoinchecker.datamodule.model

import java.util.*

class CurrencySubunitsMap(vararg currencySubunits: CurrencySubunit) : LinkedHashMap<Long, CurrencySubunit>() {
companion object {
// private const val serialVersionUID = -7219011491064245859L
}

init {
for (currencySubunit in currencySubunits) put(currencySubunit.subunitToUnit, currencySubunit)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.aneonex.bitcoinchecker.datamodule.model

object Futures {
const val CONTRACT_TYPE_WEEKLY = 0
const val CONTRACT_TYPE_BIWEEKLY = 1
// const val CONTRACT_TYPE_MONTHLY = 2
// const val CONTRACT_TYPE_BIMONTHLY = 3
const val CONTRACT_TYPE_QUARTERLY = 4
private val CONTRACT_TYPE_SHORT_NAMES = arrayOf(
"1W",
"2W",
"1M",
"2M",
"3M"
)

@kotlin.jvm.JvmStatic
fun getContractTypeShortName(contractType: Int): String? {
return if (contractType >= 0 && contractType < CONTRACT_TYPE_SHORT_NAMES.size) {
CONTRACT_TYPE_SHORT_NAMES[contractType]
} else null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.aneonex.bitcoinchecker.datamodule.model

import com.aneonex.bitcoinchecker.datamodule.model.currency.CurrencyPairsMap

abstract class FuturesMarket(name: String, ttsName: String, currencyPairs: CurrencyPairsMap?, val contractTypes: IntArray)
: Market(name, ttsName, currencyPairs) {

override fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String {
return getUrl(requestId, checkerInfo, checkerInfo.contractType)
}

protected abstract fun getUrl(requestId: Int, checkerInfo: CheckerInfo, contractType: Int): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.aneonex.bitcoinchecker.datamodule.model

import android.text.TextUtils
import com.aneonex.bitcoinchecker.datamodule.model.currency.CurrencyPairsMap
import com.aneonex.bitcoinchecker.datamodule.util.TimeUtils
import org.json.JSONObject

abstract class Market(name: String, ttsName: String, currencyPairs: CurrencyPairsMap?) {
@kotlin.jvm.JvmField
val key: String = this.javaClass.simpleName

@kotlin.jvm.JvmField
val name: String = name

val ttsName: String = ttsName

@kotlin.jvm.JvmField
val currencyPairs: CurrencyPairsMap?

open val cautionResId: Int
get() = 0

// ====================
// Parse Ticker
// ====================
open fun getNumOfRequests(checkerInfo: CheckerInfo?): Int {
return 1
}

abstract fun getUrl(requestId: Int, checkerInfo: CheckerInfo): String
@Throws(Exception::class)
fun parseTickerMain(requestId: Int, responseString: String, ticker: Ticker, checkerInfo: CheckerInfo): Ticker {
parseTicker(requestId, responseString, ticker, checkerInfo)
if (ticker.timestamp <= 0) ticker.timestamp = System.currentTimeMillis() else ticker.timestamp = TimeUtils.parseTimeToMillis(ticker.timestamp)
return ticker
}

@Throws(Exception::class)
protected open fun parseTicker(requestId: Int, responseString: String, ticker: Ticker, checkerInfo: CheckerInfo) {
parseTickerFromJsonObject(requestId, JSONObject(responseString), ticker, checkerInfo)
}

@Throws(Exception::class)
protected open fun parseTickerFromJsonObject(requestId: Int, jsonObject: JSONObject, ticker: Ticker, checkerInfo: CheckerInfo) {
// do parsing
}

// ====================
// Parse Ticker Error
// ====================
@Throws(Exception::class)
fun parseErrorMain(requestId: Int, responseString: String, checkerInfo: CheckerInfo): String? {
return parseError(requestId, responseString, checkerInfo)
}

@Throws(Exception::class)
protected open fun parseError(requestId: Int, responseString: String, checkerInfo: CheckerInfo): String? {
return parseErrorFromJsonObject(requestId, JSONObject(responseString), checkerInfo)
}

@Throws(Exception::class)
protected open fun parseErrorFromJsonObject(requestId: Int, jsonObject: JSONObject, checkerInfo: CheckerInfo?): String? {
throw Exception()
}

// ====================
// Parse currency pairs
// ====================
open val currencyPairsNumOfRequests: Int
get() = 1

open fun getCurrencyPairsUrl(requestId: Int): String? {
return null
}

@Throws(Exception::class)
fun parseCurrencyPairsMain(requestId: Int, responseString: String, pairs: MutableList<CurrencyPairInfo>) {
parseCurrencyPairs(requestId, responseString, pairs)
for (i in pairs.indices.reversed()) {
val currencyPairInfo = pairs[i]
if (TextUtils.isEmpty(currencyPairInfo.currencyBase) || TextUtils.isEmpty(currencyPairInfo.currencyCounter)) pairs.removeAt(i)
}
}

@Throws(Exception::class)
protected open fun parseCurrencyPairs(requestId: Int, responseString: String, pairs: MutableList<CurrencyPairInfo>) {
parseCurrencyPairsFromJsonObject(requestId, JSONObject(responseString), pairs)
}

@Throws(Exception::class)
protected open fun parseCurrencyPairsFromJsonObject(requestId: Int, jsonObject: JSONObject, pairs: MutableList<CurrencyPairInfo>) {
// do parsing
}

init {
this.currencyPairs = currencyPairs
}
}
Loading

0 comments on commit 1aac1e1

Please sign in to comment.