aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-12-29 15:23:48 -0800
committerAllan Wang <me@allanwang.ca>2019-12-29 15:23:48 -0800
commit57a668d8aebc3f323ee8885fdd8b1396b0ff5b1c (patch)
treeeb56e58927c3d24ca180d6e8fcd33e757aaaacc5 /app/src
parent006bc3d1a4798859fdce3c49f8a8690c823f1d7f (diff)
downloadfrost-57a668d8aebc3f323ee8885fdd8b1396b0ff5b1c.tar.gz
frost-57a668d8aebc3f323ee8885fdd8b1396b0ff5b1c.tar.bz2
frost-57a668d8aebc3f323ee8885fdd8b1396b0ff5b1c.zip
Finish adding remaining click events
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt215
-rw-r--r--app/src/main/res/layout/view_nav_header.xml20
-rw-r--r--app/src/main/res/values/dimens.xml1
-rw-r--r--app/src/main/res/values/styles.xml10
4 files changed, 116 insertions, 130 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
index dee94046..62138b19 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -35,7 +35,6 @@ import android.webkit.WebView
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
-import androidx.annotation.ColorInt
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.widget.Toolbar
import androidx.core.view.updateLayoutParams
@@ -62,6 +61,7 @@ import ca.allanwang.kau.utils.showIf
import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.tint
import ca.allanwang.kau.utils.toDrawable
+import ca.allanwang.kau.utils.toast
import ca.allanwang.kau.utils.visible
import ca.allanwang.kau.utils.withMinAlpha
import com.afollestad.materialdialogs.checkbox.checkBoxPrompt
@@ -86,6 +86,7 @@ import com.pitchedapps.frost.databinding.ViewNavHeaderBinding
import com.pitchedapps.frost.db.CookieDao
import com.pitchedapps.frost.db.CookieEntity
import com.pitchedapps.frost.db.GenericDao
+import com.pitchedapps.frost.db.currentCookie
import com.pitchedapps.frost.db.getTabs
import com.pitchedapps.frost.enums.MainActivityLayout
import com.pitchedapps.frost.facebook.FbCookie
@@ -116,6 +117,8 @@ import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.frostChangelog
import com.pitchedapps.frost.utils.frostEvent
import com.pitchedapps.frost.utils.frostNavigationBar
+import com.pitchedapps.frost.utils.launchLogin
+import com.pitchedapps.frost.utils.launchNewTask
import com.pitchedapps.frost.utils.launchWebOverlay
import com.pitchedapps.frost.utils.setFrostColors
import com.pitchedapps.frost.views.BadgedIcon
@@ -262,18 +265,18 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
}
}
- private fun ActivityMainDrawerWrapperBinding.initDrawer() {
-
- fun createNavDrawable(@ColorInt foregroundColor: Int): RippleDrawable {
- val drawable = drawable(R.drawable.nav_item_background) as RippleDrawable
- drawable.setColor(
- ColorStateList(
- arrayOf(intArrayOf()),
- intArrayOf(foregroundColor.adjustAlpha(0.16f))
- )
+ private fun createNavDrawable(): RippleDrawable {
+ val drawable = drawable(R.drawable.nav_item_background) as RippleDrawable
+ drawable.setColor(
+ ColorStateList(
+ arrayOf(intArrayOf()),
+ intArrayOf(Prefs.accentColor.adjustAlpha(0.16f))
)
- return drawable
- }
+ )
+ return drawable
+ }
+
+ private fun ActivityMainDrawerWrapperBinding.initDrawer() {
val toggle = ActionBarDrawerToggle(
this@BaseMainActivity, drawer, contentBinding.toolbar,
@@ -315,7 +318,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
}
val navBg = Prefs.bgColor.withMinAlpha(200)
setBackgroundColor(navBg)
- itemBackground = createNavDrawable(Prefs.accentColor)
+ itemBackground = createNavDrawable()
itemTextColor = foregroundColor
itemIconTintList = foregroundColor
@@ -373,94 +376,6 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
}
}
-// private fun setupDrawer(savedInstanceState: Bundle?) {
-// val navBg = Prefs.bgColor.withMinAlpha(200).toLong()
-// val navHeader = Prefs.headerColor.withMinAlpha(200)
-// drawer = drawer {
-// toolbar = this@BaseMainActivity.toolbar
-// savedInstance = savedInstanceState
-// translucentStatusBar = false
-// sliderBackgroundColor = navBg
-// drawerHeader = accountHeader {
-// textColor = Prefs.iconColor.toLong()
-// backgroundDrawable = ColorDrawable(navHeader)
-// selectionSecondLineShown = false
-// cookies().forEach { (id, name) ->
-// profile(name = name ?: "") {
-// iconUrl = profilePictureUrl(id)
-// textColor = Prefs.textColor.toLong()
-// selectedTextColor = Prefs.textColor.toLong()
-// selectedColor = 0x00000001.toLong()
-// identifier = id
-// }
-// }
-// profileSetting(nameRes = R.string.kau_logout) {
-// iicon = GoogleMaterial.Icon.gmd_exit_to_app
-// iconColor = Prefs.textColor.toLong()
-// textColor = Prefs.textColor.toLong()
-// identifier = -2L
-// }
-// profileSetting(nameRes = R.string.kau_add_account) {
-// iconDrawable =
-// IconicsDrawable(
-// this@BaseMainActivity,
-// GoogleMaterial.Icon.gmd_add
-// ).actionBar().paddingDp(5)
-// .colorInt(Prefs.textColor)
-// textColor = Prefs.textColor.toLong()
-// identifier = -3L
-// }
-// profileSetting(nameRes = R.string.kau_manage_account) {
-// iicon = GoogleMaterial.Icon.gmd_settings
-// iconColor = Prefs.textColor.toLong()
-// textColor = Prefs.textColor.toLong()
-// identifier = -4L
-// }
-// onProfileChanged { _, profile, current ->
-// if (current) launchWebOverlay(FbItem.PROFILE.url)
-// else when (profile.identifier) {
-// -2L -> {
-// // TODO no backpressure support
-// this@BaseMainActivity.launch {
-// val currentCookie = cookieDao.currentCookie()
-// if (currentCookie == null) {
-// toast(R.string.account_not_found)
-// FbCookie.reset()
-// launchLogin(cookies(), true)
-// } else {
-// materialDialog {
-// title(R.string.kau_logout)
-// message(
-// text =
-// String.format(
-// string(R.string.kau_logout_confirm_as_x),
-// currentCookie.name ?: Prefs.userId.toString()
-// )
-// )
-// positiveButton(R.string.kau_yes) {
-// this@BaseMainActivity.launch {
-// FbCookie.logout(this@BaseMainActivity)
-// }
-// }
-// negativeButton(R.string.kau_no)
-// }
-// }
-// }
-// }
-// -3L -> launchNewTask<LoginActivity>(clearStack = false)
-// -4L -> launchNewTask<SelectorActivity>(cookies(), false)
-// else -> {
-// this@BaseMainActivity.launch {
-// FbCookie.switchUser(profile.identifier)
-// tabsForEachView { _, view -> view.badgeText = null }
-// refreshAll()
-// }
-// }
-// }
-// false
-// }
-// }
-
private inner class NavHeader {
private var orderedAccounts: List<CookieEntity> = cookies()
@@ -498,6 +413,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
height = it.toInt()
}
}
+ withAnimator(arrow.rotation, 0f) {
+ arrow.rotation = it
+ }
withEndAction {
optionsContainer.gone()
}
@@ -516,6 +434,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
height = it.toInt()
}
}
+ withAnimator(arrow.rotation, 180f) {
+ arrow.rotation = it
+ }
withStartAction {
optionsContainer.visible()
}
@@ -525,18 +446,67 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
animator.start()
}
+ val textColor = Prefs.textColor
+
fun TextView.setOptionsIcon(iicon: IIcon) {
setCompoundDrawablesRelativeWithIntrinsicBounds(
- iicon.toDrawable(this@BaseMainActivity, sizeDp = 20),
+ iicon.toDrawable(this@BaseMainActivity, color = textColor, sizeDp = 20),
null,
null,
null
)
+ setTextColor(textColor)
+ background = createNavDrawable()
}
- optionsLogout.setOptionsIcon(GoogleMaterial.Icon.gmd_exit_to_app)
- optionsAddAccount.setOptionsIcon(GoogleMaterial.Icon.gmd_add)
- optionsManageAccount.setOptionsIcon(GoogleMaterial.Icon.gmd_settings)
+ with(optionsLogout) {
+ setOptionsIcon(GoogleMaterial.Icon.gmd_exit_to_app)
+ setOnClickListener {
+ launch {
+ val currentCookie = cookieDao.currentCookie()
+ if (currentCookie == null) {
+ toast(R.string.account_not_found)
+ FbCookie.reset()
+ launchLogin(cookies(), true)
+ } else {
+ materialDialog {
+ title(R.string.kau_logout)
+ message(
+ text =
+ String.format(
+ string(R.string.kau_logout_confirm_as_x),
+ currentCookie.name ?: Prefs.userId.toString()
+ )
+ )
+ positiveButton(R.string.kau_yes) {
+ this@BaseMainActivity.launch {
+ FbCookie.logout(this@BaseMainActivity)
+ }
+ }
+ negativeButton(R.string.kau_no)
+ }
+ }
+ }
+ }
+ }
+ with(optionsAddAccount) {
+ setOptionsIcon(GoogleMaterial.Icon.gmd_add)
+ setOnClickListener {
+ launchNewTask<LoginActivity>(clearStack = false)
+ }
+ }
+ with(optionsManageAccount) {
+ setOptionsIcon(GoogleMaterial.Icon.gmd_settings)
+ setOnClickListener {
+ launchNewTask<SelectorActivity>(cookies(), false)
+ }
+ }
+ arrow.setImageDrawable(
+ GoogleMaterial.Icon.gmd_arrow_drop_down.toDrawable(
+ this@BaseMainActivity,
+ color = Prefs.textColor
+ )
+ )
}
}
@@ -559,9 +529,12 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
avatarTertiary.setAccount(orderedAccounts.getOrNull(2), false)
optionsAccountsContainer.removeAllViews()
name.text = orderedAccounts.getOrNull(0)?.name
+ name.setTextColor(Prefs.textColor)
val glide = Glide.with(root)
val accountSize = dimenPixelSize(R.dimen.drawer_account_avatar_size)
- orderedAccounts.forEach {
+ val textColor = Prefs.textColor
+ val navBackground = createNavDrawable()
+ orderedAccounts.forEach { cookie ->
val tv =
TextView(
this@BaseMainActivity,
@@ -569,7 +542,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
0,
R.style.Main_DrawerAccountUserOptions
)
- glide.load(profilePictureUrl(it.id)).transform(FrostGlide.circleCrop)
+ glide.load(profilePictureUrl(cookie.id)).transform(FrostGlide.circleCrop)
.into(object : CustomTarget<Drawable>(accountSize, accountSize) {
override fun onLoadCleared(placeholder: Drawable?) {
tv.setCompoundDrawablesRelativeWithIntrinsicBounds(
@@ -592,7 +565,12 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
)
}
})
- tv.text = it.name
+ tv.text = cookie.name
+ tv.setTextColor(textColor)
+ tv.background = navBackground
+ tv.setOnClickListener {
+ switchAccount(cookie.id)
+ }
optionsAccountsContainer.addView(tv)
}
}
@@ -620,19 +598,24 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
if (primary) {
launchWebOverlay(FbItem.PROFILE.url)
} else {
- setPrimary(cookie.id)
- pendingUpdate = true
- closeDrawer()
- launch {
- FbCookie.switchUser(cookie.id)
- tabsForEachView { _, view -> view.badgeText = null }
- refreshAll()
- }
+ switchAccount(cookie.id)
}
closeDrawer()
}
}
}
+
+ private fun switchAccount(id: Long) {
+ if (Prefs.userId == id) return
+ setPrimary(id)
+ pendingUpdate = true
+ closeDrawer()
+ launch {
+ FbCookie.switchUser(id)
+ tabsForEachView { _, view -> view.badgeText = null }
+ refreshAll()
+ }
+ }
}
private fun refreshAll() {
diff --git a/app/src/main/res/layout/view_nav_header.xml b/app/src/main/res/layout/view_nav_header.xml
index 38df36d7..a5dc05d6 100644
--- a/app/src/main/res/layout/view_nav_header.xml
+++ b/app/src/main/res/layout/view_nav_header.xml
@@ -8,10 +8,10 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
- android:elevation="2dp"
- android:layout_height="160dp">
+ android:layout_height="160dp"
+ android:elevation="2dp">
- <androidx.appcompat.widget.AppCompatImageView
+ <ImageView
android:id="@+id/background"
android:layout_width="0dp"
android:layout_height="160dp"
@@ -54,9 +54,9 @@
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
- android:layout_marginStart="@dimen/kau_activity_horizontal_margin"
+ android:layout_marginStart="@dimen/drawer_nav_horizontal_margins"
android:layout_marginTop="@dimen/kau_activity_vertical_margin"
- android:layout_marginEnd="@dimen/kau_activity_horizontal_margin"
+ android:layout_marginEnd="@dimen/drawer_nav_horizontal_margins"
android:layout_marginBottom="@dimen/kau_activity_vertical_margin"
android:clickable="false"
android:lines="1"
@@ -69,10 +69,10 @@
<ImageView
android:id="@+id/arrow"
- android:layout_width="18dp"
- android:layout_height="18dp"
- android:layout_marginStart="@dimen/kau_activity_horizontal_margin"
- android:layout_marginEnd="@dimen/kau_activity_horizontal_margin"
+ android:layout_width="12dp"
+ android:layout_height="12dp"
+ android:layout_marginStart="@dimen/drawer_nav_horizontal_margins"
+ android:layout_marginEnd="@dimen/drawer_nav_horizontal_margins"
app:layout_constraintBottom_toBottomOf="@id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/name" />
@@ -84,6 +84,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
android:visibility="gone"
tools:visibility="visible">
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index c81aee3c..b2df756d 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -15,4 +15,5 @@
<dimen name="dialog_corner_radius">8dp</dimen>
<dimen name="drawer_account_avatar_size">32dp</dimen>
+ <dimen name="drawer_nav_horizontal_margins">24dp</dimen>
</resources>
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 38c5de7d..f17d005c 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -141,8 +141,8 @@
<!-- </style>-->
<style name="Main.DrawerMargins" parent="">
- <item name="android:layout_marginStart">@dimen/kau_activity_horizontal_margin</item>
- <item name="android:layout_marginEnd">@dimen/kau_activity_horizontal_margin</item>
+ <item name="android:layout_marginStart">@dimen/drawer_nav_horizontal_margins</item>
+ <item name="android:layout_marginEnd">@dimen/drawer_nav_horizontal_margins</item>
<item name="android:layout_marginTop">@dimen/kau_activity_vertical_margin</item>
<item name="android:layout_marginBottom">@dimen/kau_activity_vertical_margin</item>
</style>
@@ -162,8 +162,8 @@
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:drawablePadding">16dp</item>
- <item name="android:paddingStart">24dp</item>
- <item name="android:paddingEnd">24dp</item>
+ <item name="android:paddingStart">@dimen/drawer_nav_horizontal_margins</item>
+ <item name="android:paddingEnd">@dimen/drawer_nav_horizontal_margins</item>
<item name="android:paddingTop">16dp</item>
<item name="android:paddingBottom">16dp</item>
<item name="android:gravity">center_vertical</item>
@@ -178,7 +178,7 @@
<item name="android:drawablePadding">10dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingStart">18dp</item>
- <item name="android:paddingEnd">24dp</item>
+ <item name="android:paddingEnd">@dimen/drawer_nav_horizontal_margins</item>
</style>
</resources>