aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt18
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/IIconUtils.kt13
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Interfaces.kt12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt28
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Realm.kt18
6 files changed, 84 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt
index cd638068..e7a38227 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt
@@ -2,14 +2,24 @@ package com.pitchedapps.frost.utils
import android.os.Bundle
import android.support.v4.app.Fragment
+import com.pitchedapps.frost.fragments.BaseFragment
/**
* Created by Allan Wang on 2017-05-29.
*/
-fun Fragment.withBundle(creator: (Bundle) -> Unit): Fragment {
- val bundle = Bundle()
- creator.invoke(bundle)
- this.arguments = bundle
+private fun Fragment.bundle(): Bundle {
+ if (this.arguments == null)
+ this.arguments = Bundle()
+ return this.arguments
+}
+
+fun <T : Fragment> T.putString(key: String, value: String): T {
+ this.bundle().putString(key, value)
+ return this
+}
+
+fun <T : Fragment> T.putInt(key: String, value: Int): T {
+ this.bundle().putInt(key, value)
return this
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/IIconUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/IIconUtils.kt
new file mode 100644
index 00000000..cc645d93
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/IIconUtils.kt
@@ -0,0 +1,13 @@
+package com.pitchedapps.frost.utils
+
+import android.content.Context
+import android.graphics.drawable.Drawable
+import android.support.annotation.ColorRes
+import com.mikepenz.iconics.IconicsDrawable
+import com.mikepenz.iconics.typeface.IIcon
+
+/**
+ * Created by Allan Wang on 2017-05-29.
+ */
+fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorRes color: Int = android.R.color.white): Drawable
+ = IconicsDrawable(c).icon(this).colorRes(color).sizeDp(sizeDp) \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Interfaces.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Interfaces.kt
new file mode 100644
index 00000000..79904c6e
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Interfaces.kt
@@ -0,0 +1,12 @@
+package com.pitchedapps.frost.utils
+
+import io.reactivex.subjects.Subject
+
+/**
+ * Created by Allan Wang on 2017-05-29.
+ */
+interface ObservableContainer<T> {
+ val observable: Subject<T>
+}
+
+interface KeyPairObservable : ObservableContainer<Pair<Int, Int>> \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
index 279d595e..0151b0ae 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt
@@ -1,12 +1,34 @@
package com.pitchedapps.frost.utils
+import android.util.Log
+import timber.log.Timber
+
+
+
/**
* Created by Allan Wang on 2017-05-28.
*/
class L {
companion object {
- val TAG = "Frost"
- fun e(s: String) = android.util.Log.e(com.pitchedapps.frost.utils.L.Companion.TAG, s)
- fun d(s: String) = android.util.Log.d(com.pitchedapps.frost.utils.L.Companion.TAG, s)
+ val TAG = "Frost: %s"
+ fun e(s: String) = Timber.e(TAG, s)
+ fun d(s: String) = Timber.d(TAG, s)
+ }
+}
+
+internal class CrashReportingTree : Timber.Tree() {
+ override fun log(priority: Int, tag: String, message: String, t: Throwable?) {
+ if (priority == Log.VERBOSE || priority == Log.DEBUG)
+ return
+ Log.println(priority, tag, message)
+// FakeCrashLibrary.log(priority, tag, message)
+
+// if (t != null) {
+// if (priority == Log.ERROR) {
+// FakeCrashLibrary.logError(t)
+// } else if (priority == Log.WARN) {
+// FakeCrashLibrary.logWarning(t)
+// }
+// }
}
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
index c98fd5a5..fc2e9d1c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -13,6 +13,8 @@ class Prefs(c: android.content.Context) {
val LAST_ACTIVE = "last_active"
}
+ private val prefs: android.content.SharedPreferences by lazy { c.getSharedPreferences(com.pitchedapps.frost.utils.Prefs.Companion.PREFERENCE_NAME, android.content.Context.MODE_PRIVATE) }
+
var lastActive: Long
get() = prefs.getLong(com.pitchedapps.frost.utils.Prefs.Companion.LAST_ACTIVE, -1)
set(value) = set(com.pitchedapps.frost.utils.Prefs.Companion.LAST_ACTIVE, System.currentTimeMillis())
@@ -21,8 +23,6 @@ class Prefs(c: android.content.Context) {
lastActive = 0
}
- private val prefs: android.content.SharedPreferences by lazy { c.getSharedPreferences(com.pitchedapps.frost.utils.Prefs.Companion.PREFERENCE_NAME, android.content.Context.MODE_PRIVATE) }
-
private fun set(key: String, value: Boolean) = prefs.edit().putBoolean(key, value).apply()
private fun set(key: String, value: Int) = prefs.edit().putInt(key, value).apply()
private fun set(key: String, value: Long) = prefs.edit().putLong(key, value).apply()
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Realm.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Realm.kt
new file mode 100644
index 00000000..1eded8c9
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Realm.kt
@@ -0,0 +1,18 @@
+package com.pitchedapps.frost.utils
+
+import io.realm.Realm
+import io.realm.RealmConfiguration
+
+/**
+ * Created by Allan Wang on 2017-05-29.
+ */
+@JvmOverloads fun realm(name: String = RealmFiles.main, transaction: Realm.Transaction) {
+ val realm = Realm.getInstance(RealmConfiguration.Builder().name(name).build())
+ realm.executeTransaction(transaction)
+ realm.close()
+}
+
+object RealmFiles {
+ val main = "frost.realm"
+ val TABS = "tabs.realm"
+} \ No newline at end of file