Exports, some Kotlin stuff, and version 1.0-beta15

This commit is contained in:
2017-08-03 00:00:23 +02:00
parent 898c49802b
commit e79bfdb244
16 changed files with 440 additions and 344 deletions

View File

@ -27,6 +27,8 @@ public class Constants {
public static final String PREFERENCE_SYNC_TIMEOUT = "sync_timeout";
public static final String PREFERENCE_SERVER_POW = "server_pow";
public static final String PREFERENCE_FULL_NODE = "full_node";
public static final String PREFERENCE_POW_AVERAGE = "average_pow_time_ms";
public static final String PREFERENCE_POW_COUNT = "pow_count";
public static final String BITMESSAGE_URL_SCHEMA = "bitmessage:";
public static final Pattern BITMESSAGE_ADDRESS_PATTERN = Pattern.compile("\\bBM-[a-zA-Z0-9]+\\b");

View File

@ -0,0 +1,31 @@
package ch.dissem.apps.abit.util
import android.content.Context
/**
* Created by chrigu on 02.08.17.
*/
object PowStats {
var powUnitTime: Long = 0
var powCount: Long = 0
@JvmStatic
fun getExpectedPowTime(ctx: Context, target: ByteArray): Long {
// val preferences = PreferenceManager.getDefaultSharedPreferences(ctx)
// return preferences.getLong(Constants.PREFERENCE_POW_AVERAGE, 0L)
return 0
}
// fun updatePowTelemetry(ctx: Context, averagePowTime: Long, powCount: Long) {
// val preferences = PreferenceManager.getDefaultSharedPreferences(ctx)
// preferences.edit()
// .putLong(Constants.PREFERENCE_POW_AVERAGE, averagePowTime)
// .putLong(Constants.PREFERENCE_POW_COUNT, powCount)
// .apply()
// }
@JvmStatic
fun addPow(ctx: Context, time: Long, target: ByteArray) {
powCount++
}
}

View File

@ -22,6 +22,8 @@ import ch.dissem.apps.abit.R
import ch.dissem.apps.abit.listener.WifiReceiver
import ch.dissem.apps.abit.notification.ErrorNotification
import ch.dissem.apps.abit.util.Constants.*
import org.slf4j.LoggerFactory
import java.io.File
import java.io.IOException
import java.net.InetAddress
@ -29,6 +31,8 @@ import java.net.InetAddress
* @author Christian Basler
*/
object Preferences {
private val LOG = LoggerFactory.getLogger(Preferences::class.java)
@JvmStatic
fun useTrustedNode(ctx: Context): Boolean {
val trustedNode = getPreference(ctx, PREFERENCE_TRUSTED_NODE) ?: return false
@ -112,4 +116,25 @@ object Preferences {
val preferences = PreferenceManager.getDefaultSharedPreferences(ctx)
preferences.edit().putBoolean(PREFERENCE_FULL_NODE, status).apply()
}
@JvmStatic
fun getExportDirectory(ctx: Context): File {
return File(ctx.filesDir, "exports")
}
@JvmStatic
fun cleanupExportDirectory(ctx: Context) {
val exportDirectory = getExportDirectory(ctx)
if (exportDirectory.exists()) {
exportDirectory.listFiles().forEach { file ->
try {
if (!file.delete()) {
file.deleteOnExit()
}
} catch (e: Exception) {
LOG.debug(e.message, e)
}
}
}
}
}