aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt24
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt39
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt55
4 files changed, 98 insertions, 21 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
index 6afc84fd..3a559bc2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
@@ -48,18 +48,18 @@ class FrostApp : Application() {
FbCookie()
super.onCreate()
//Drawer profile loading logic
- DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
- override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String) {
- Glide.with(imageView.context).load(uri).apply(RequestOptions().placeholder(placeholder)).into(imageView)
- }
-
- override fun placeholder(ctx: Context, tag: String): Drawable {
- when (tag) {
- DrawerImageLoader.Tags.PROFILE.name, DrawerImageLoader.Tags.ACCOUNT_HEADER.name -> DrawerUIUtils.getPlaceHolder(ctx)
- }
- return super.placeholder(ctx, tag);
- }
- })
+// DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
+// override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String) {
+// Glide.with(imageView.context).load(uri).apply(RequestOptions().placeholder(placeholder)).into(imageView)
+// }
+//
+// override fun placeholder(ctx: Context, tag: String): Drawable {
+// when (tag) {
+// DrawerImageLoader.Tags.PROFILE.name, DrawerImageLoader.Tags.ACCOUNT_HEADER.name -> DrawerUIUtils.getPlaceHolder(ctx)
+// }
+// return super.placeholder(ctx, tag);
+// }
+// })
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
index cdfebfac..b4320ba3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
@@ -13,7 +13,10 @@ import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.widget.ImageButton
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.showChangelog
+import ca.allanwang.kau.utils.startActivitySlideIn
+import ca.allanwang.kau.utils.withMinAlpha
import co.zsmb.materialdrawerkt.builders.Builder
import co.zsmb.materialdrawerkt.builders.accountHeader
import co.zsmb.materialdrawerkt.builders.drawer
@@ -30,6 +33,7 @@ import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.views.BadgedIcon
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
@@ -76,11 +80,11 @@ class MainActivity : BaseActivity() {
val delta: Float by lazy { positionOffset * (255 - 128).toFloat() }
(0 until tabs.tabCount).asSequence().forEach {
i ->
- tabs.getTabAt(i)?.icon?.alpha = when (i) {
- position -> (255.0 - delta).toInt()
- position + 1 -> (128.0 + delta).toInt()
- else -> 128
- }
+ (tabs.getTabAt(i)!!.customView as BadgedIcon).setAllAlpha(when (i) {
+ position -> 255.0f - delta
+ position + 1 -> 128.0f + delta
+ else -> 128f
+ })
}
}
})
@@ -101,6 +105,11 @@ class MainActivity : BaseActivity() {
super.onTabReselected(tab)
currentFragment.web.scrollOrRefresh()
}
+
+ override fun onTabSelected(tab: TabLayout.Tab) {
+ super.onTabSelected(tab)
+ (tab.customView as BadgedIcon).badgeText = null
+ }
})
headerBadgeObservable.throttleFirst(15, TimeUnit.SECONDS).subscribeOn(Schedulers.newThread())
.map { Jsoup.parse(it) }
@@ -115,10 +124,22 @@ class MainActivity : BaseActivity() {
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
(feed, requests, messages, notifications) ->
- L.d("Header subscription $feed $requests $messages $notifications")
- L.d("contained nulls ${feed == null}")
+ (0 until tabs.tabCount).asSequence().forEach {
+ val tabBadge = tabs.getTabAt(it)!!.customView as BadgedIcon
+ when (tabBadge.iicon) {
+ FbTab.FEED.icon -> tabBadge.badgeText = feed
+ FbTab.FRIENDS.icon -> tabBadge.badgeText = requests
+ FbTab.MESSAGES.icon -> tabBadge.badgeText = messages
+ FbTab.NOTIFICATIONS.icon -> tabBadge.badgeText = notifications
+ }
+ }
}
- adapter.pages.forEach { tabs.addTab(tabs.newTab().setIcon(it.icon.toDrawable(this, sizeDp = 20, color = Prefs.iconColor))) }
+ adapter.pages.forEach {
+ tabs.addTab(tabs.newTab()
+ .setCustomView(BadgedIcon(this).apply {
+ iicon = it.icon
+ }))
+ }
}
fun setupDrawer(savedInstanceState: Bundle?) {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
index f506bd8f..cd66b9c2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
@@ -41,6 +41,7 @@ class NotificationService : JobService() {
override fun onStartJob(params: JobParameters?): Boolean {
future = doAsync {
+ debugNotification("Load notifs")
loadFbCookiesSync().forEach {
data ->
L.i("Handling notifications for ${data.id}")
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
new file mode 100644
index 00000000..bc932480
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
@@ -0,0 +1,55 @@
+package com.pitchedapps.frost.views
+
+import android.content.Context
+import android.graphics.drawable.GradientDrawable
+import android.support.constraint.ConstraintLayout
+import android.util.AttributeSet
+import android.widget.ImageView
+import android.widget.TextView
+import ca.allanwang.kau.utils.*
+import com.mikepenz.iconics.typeface.IIcon
+import com.pitchedapps.frost.R
+import com.pitchedapps.frost.utils.Prefs
+
+
+/**
+ * Created by Allan Wang on 2017-06-19.
+ */
+class BadgedIcon @JvmOverloads constructor(
+ context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : ConstraintLayout(context, attrs, defStyleAttr) {
+
+ val badgeTextView: TextView by bindView(R.id.badge_text)
+ val badgeImage: ImageView by bindView(R.id.badge_image)
+
+ init {
+ inflate(context, R.layout.view_badged_icon, this)
+ val badgeColor = Prefs.headerColor.withAlpha(255).colorToForeground(0.1f)
+ val badgeBackground = GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(badgeColor, badgeColor))
+ badgeBackground.cornerRadius = 13.dpToPx.toFloat()
+ badgeTextView.background = badgeBackground
+ badgeTextView.setTextColor(Prefs.iconColor)
+ }
+
+
+ var iicon: IIcon? = null
+ get() = field
+ set(value) {
+ field = value
+ badgeImage.setImageDrawable(value?.toDrawable(context, color = Prefs.iconColor))
+ }
+
+ fun setAllAlpha(alpha: Float) {
+ //badgeTextView.setTextColor(Prefs.textColor.withAlpha(alpha.toInt()))
+ badgeImage.drawable.alpha = alpha.toInt()
+ }
+
+ var badgeText: String?
+ get() = badgeTextView.text.toString()
+ set(value) {
+ badgeTextView.text = value
+ if (value != null && value != "0") badgeTextView.visible()
+ else badgeTextView.gone()
+ }
+
+} \ No newline at end of file