aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-20 15:50:08 -0700
committerAllan Wang <me@allanwang.ca>2017-06-20 15:50:08 -0700
commite916afddb89550d7f99f17e1477ad17f3bd770f9 (patch)
treeb9a846da082599295d2671d29eaee74d9310f4c6 /app/src/main
parent2d7fa0f6d0c152bb9f3fd30370ef510a0d452d00 (diff)
downloadfrost-e916afddb89550d7f99f17e1477ad17f3bd770f9.tar.gz
frost-e916afddb89550d7f99f17e1477ad17f3bd770f9.tar.bz2
frost-e916afddb89550d7f99f17e1477ad17f3bd770f9.zip
Add user switching for notifications
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostWebActivity.kt18
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt21
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt29
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt14
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationExtensions.kt13
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt2
-rw-r--r--app/src/main/res/values/dimens.xml1
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/values/styles.xml2
-rw-r--r--app/src/main/res/xml/changelog.xml5
15 files changed, 80 insertions, 53 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e715dc54..67366d71 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -10,7 +10,6 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
- <uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name=".FrostApp"
@@ -20,10 +19,10 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
- android:theme="@style/FrostThemeBase">
+ android:theme="@style/FrostTheme.Splash">
<activity
android:name=".StartActivity"
- android:configChanges="orientation|screenSize|locale"
+ android:noHistory="true"
android:label="@string/app_name"
android:theme="@style/FrostTheme.Splash">
<intent-filter>
@@ -47,16 +46,15 @@
android:name=".FrostWebActivity"
android:autoRemoveFromRecents="true"
android:exported="true"
- android:label="@string/frost_web"
android:hardwareAccelerated="true"
+ android:label="@string/frost_web"
android:launchMode="singleInstance"
android:taskAffinity="com.pitchedapps.frost.single.web"
android:theme="@style/FrostTheme.Overlay">
- <intent-filter android:autoVerify="true"
+ <intent-filter
+ android:autoVerify="true"
tools:ignore="UnusedAttribute">
- <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
-
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostWebActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostWebActivity.kt
index 31ebfda2..c853e8f0 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/FrostWebActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostWebActivity.kt
@@ -1,17 +1,8 @@
package com.pitchedapps.frost
import android.os.Bundle
-import android.support.design.widget.CoordinatorLayout
-import android.support.v7.app.AppCompatActivity
-import android.support.v7.widget.Toolbar
-import ca.allanwang.kau.utils.*
-import com.jude.swipbackhelper.SwipeBackHelper
-import com.pitchedapps.frost.facebook.FbTab
-import com.pitchedapps.frost.utils.ARG_URL
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.formattedFbUrl
-import com.pitchedapps.frost.utils.setFrostColors
-import com.pitchedapps.frost.web.FrostWebView
/**
@@ -20,8 +11,15 @@ import com.pitchedapps.frost.web.FrostWebView
* Replica of [WebOverlayActivity] with a different base url
* Didn't use activity-alias because it causes issues when only one activity has the singleInstance mode
*/
-class FrostWebActivity:WebOverlayActivity() {
+class FrostWebActivity : WebOverlayActivity() {
+
override val url: String
get() = intent.dataString!!.formattedFbUrl
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ Prefs.prevId = Prefs.userId
+ super.onCreate(savedInstanceState)
+ }
+
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
index ca50d4e2..fcffffb2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
@@ -28,6 +28,7 @@ import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.materialdrawer.AccountHeader
import com.mikepenz.materialdrawer.Drawer
import com.pitchedapps.frost.dbflow.loadFbTabs
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbCookie.switchUser
import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
@@ -83,8 +84,8 @@ class MainActivity : BaseActivity() {
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
val delta: Float by lazy { positionOffset * (255 - 128).toFloat() }
tabsForEachView {
- position, view ->
- view.setAllAlpha(when (position) {
+ tabPosition, view ->
+ view.setAllAlpha(when (tabPosition) {
position -> 255.0f - delta
position + 1 -> 128.0f + delta
else -> 128f
@@ -243,6 +244,11 @@ class MainActivity : BaseActivity() {
return true
}
+ override fun onResume() {
+ super.onResume()
+ FbCookie.switchBackUser { }
+ }
+
override fun onBackPressed() {
if (currentFragment.onBackPressed()) return
super.onBackPressed()
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
index b55b2a10..19fa6362 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
@@ -87,7 +87,6 @@ class SettingsActivity : KPrefActivity() {
_, _, which, text ->
item.pref = options[which]
this@SettingsActivity.scheduleNotifications(item.pref)
- this@SettingsActivity.toast(text)
true
})
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
index bdac366e..0b2be3ee 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
@@ -1,9 +1,10 @@
package com.pitchedapps.frost
import android.os.Bundle
+import android.os.Handler
import android.support.v7.app.AppCompatActivity
import com.pitchedapps.frost.dbflow.loadFbCookiesAsync
-import com.pitchedapps.frost.services.requestNotifications
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.launchNewTask
@@ -16,15 +17,15 @@ class StartActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
L.d("Load cookies ${System.currentTimeMillis()}")
- loadFbCookiesAsync {
- cookies ->
- cookies.forEach { requestNotifications(it.id) }
-
- L.d("Cookies loaded ${System.currentTimeMillis()} $cookies")
- if (cookies.isNotEmpty())
- launchNewTask(if (Prefs.userId != -1L) MainActivity::class.java else SelectorActivity::class.java, ArrayList(cookies))
- else
- launchNewTask(LoginActivity::class.java)
+ FbCookie.switchBackUser {
+ loadFbCookiesAsync {
+ cookies ->
+ L.d("Cookies loaded ${System.currentTimeMillis()} $cookies")
+ if (cookies.isNotEmpty())
+ launchNewTask(if (Prefs.userId != -1L) MainActivity::class.java else SelectorActivity::class.java, ArrayList(cookies))
+ else
+ launchNewTask(LoginActivity::class.java)
+ }
}
}
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
index 320e4028..1660d8db 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
@@ -6,6 +6,8 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import ca.allanwang.kau.utils.*
import com.jude.swipbackhelper.SwipeBackHelper
+import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.ARG_URL
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.formattedFbUrl
@@ -22,27 +24,38 @@ open class WebOverlayActivity : AppCompatActivity() {
val frostWeb: FrostWebView by bindView(R.id.overlay_frost_webview)
val coordinator: CoordinatorLayout by bindView(R.id.overlay_main_content)
+ companion object {
+ const val ARG_USER_ID = "arg_user_id"
+ }
+
open val url: String
get() = intent.extras!!.getString(ARG_URL).formattedFbUrl
+ val userId: Long
+ get() = intent.extras?.getLong(ARG_USER_ID) ?: Prefs.userId
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_overlay)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
- toolbar.setNavigationOnClickListener { onBackPressed() }
- frostWeb.web.setupWebview(url)
- frostWeb.web.loadBaseUrl()
+ toolbar.navigationIcon = GoogleMaterial.Icon.gmd_close.toDrawable(this, 16, Prefs.iconColor)
+ toolbar.setNavigationOnClickListener { slideOut() }
SwipeBackHelper.onCreate(this)
SwipeBackHelper.getCurrentPage(this)
.setSwipeBackEnable(true)
.setSwipeSensitivity(0.5f)
.setSwipeRelateEnable(true)
.setSwipeRelateOffset(300)
- frostWeb.web.addTitleListener({ toolbar.title = it })
setFrostColors(toolbar, themeWindow = false)
coordinator.setBackgroundColor(Prefs.bgColor.withAlpha(255))
+
+ frostWeb.web.setupWebview(url)
+ frostWeb.web.addTitleListener({ toolbar.title = it })
+
+ if (userId != Prefs.userId) FbCookie.switchUser(userId) { frostWeb.web.loadBaseUrl() }
+ else frostWeb.web.loadBaseUrl()
}
/**
@@ -70,8 +83,12 @@ open class WebOverlayActivity : AppCompatActivity() {
override fun onBackPressed() {
if (!frostWeb.onBackPressed()) {
- finish()
- overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_slide_out_right_top)
+ slideOut()
}
}
+
+ fun slideOut() {
+ finish()
+ overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_slide_out_right_top)
+ }
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
index 42232fc6..ac58fb2f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -84,4 +84,18 @@ object FbCookie {
removeCookie(id)
reset(callback)
}
+
+ /**
+ * Notifications may come from different accounts, and we need to switch the cookies to load them
+ * When coming back to the main app, switch back to our original account before continuing
+ */
+ fun switchBackUser(callback: () -> Unit) {
+ if (Prefs.prevId != -1L && Prefs.prevId != Prefs.userId) {
+ switchUser(Prefs.prevId) {
+ L.d("Switched from ${Prefs.userId} to ${Prefs.prevId}")
+ Prefs.prevId = -1L
+ callback()
+ }
+ } else callback()
+ }
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationExtensions.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationExtensions.kt
deleted file mode 100644
index ac94b527..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationExtensions.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.pitchedapps.frost.services
-
-import android.content.Context
-import android.content.Intent
-
-/**
- * Created by Allan Wang on 2017-06-14.
- */
-fun Context.requestNotifications(id: Long) {
- val intent = Intent(this, NotificationService::class.java)
- intent.putExtra(NotificationService.ARG_ID, id)
- startService(intent)
-} \ No newline at end of file
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 813bdce2..9c8bf2e6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
@@ -12,6 +12,7 @@ import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.FrostWebActivity
import com.pitchedapps.frost.R
+import com.pitchedapps.frost.WebOverlayActivity
import com.pitchedapps.frost.dbflow.*
import com.pitchedapps.frost.facebook.FACEBOOK_COM
import com.pitchedapps.frost.facebook.FB_URL_BASE
@@ -109,6 +110,7 @@ class NotificationService : JobService() {
} else {
val intent = Intent(context, FrostWebActivity::class.java)
intent.data = Uri.parse("$FB_URL_BASE$href")
+ intent.putExtra(WebOverlayActivity.ARG_USER_ID, data.id)
val group = "frost_${data.id}"
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
val notifBuilder = context.frostNotification
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 62ed3cdd..40735544 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -17,6 +17,8 @@ object Prefs : KPref() {
var userId: Long by kpref("user_id", -1L)
+ var prevId: Long by kpref("prev_id", -1L)
+
var theme: Int by kpref("theme", 0, postSetter = { value: Int ->
loader.invalidate()
})
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index fe56d6d6..d4942e9e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -30,7 +30,7 @@ import com.pitchedapps.frost.services.NotificationService
internal const val EXTRA_COOKIES = "extra_cookies"
internal const val ARG_URL = "arg_url"
-fun Context.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<CookieModel> = arrayListOf(), clearStack: Boolean = clazz != LoginActivity::class.java) {
+fun Context.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<CookieModel> = arrayListOf(), clearStack: Boolean = false) {
startActivity(clazz, clearStack, {
putParcelableArrayListExtra(EXTRA_COOKIES, cookieList)
})
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index 24bba22f..28f09eea 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -10,5 +10,4 @@
<dimen name="splash_logo">16dp</dimen>
<dimen name="progress_bar_height">1dip</dimen>
<dimen name="account_image_size">100dp</dimen>
-
</resources>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6fd465c2..f05d2ce5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,5 +1,4 @@
<resources>
- <string name="frost_web">Frost Web</string>
<string name="action_settings">Settings</string>
<string name="section_format">Hello World from section: %1$d</string>
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 0adb5967..b999d606 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -3,6 +3,7 @@
<style name="FrostThemeBase" parent="MaterialDrawerTheme.ActionBar">
<item name="colorPrimary">@color/facebook_blue</item>
<item name="colorPrimaryDark">@color/facebook_blue_dark</item>
+ <item name="colorAccent">@android:color/white</item>
</style>
<style name="FrostTheme" parent="@style/FrostThemeBase">
@@ -13,6 +14,7 @@
<style name="FrostTheme.Light" parent="MaterialDrawerTheme.Light.DarkToolbar">
<item name="colorPrimary">@color/facebook_blue</item>
<item name="colorPrimaryDark">@color/facebook_blue_dark</item>
+ <item name="colorAccent">@android:color/black</item>
</style>
<style name="FrostTheme.Transparent">
diff --git a/app/src/main/res/xml/changelog.xml b/app/src/main/res/xml/changelog.xml
index 964bc8e1..fc87ce08 100644
--- a/app/src/main/res/xml/changelog.xml
+++ b/app/src/main/res/xml/changelog.xml
@@ -8,7 +8,10 @@
<version title="v0.2"/>
<item text="Removed unnecessary permissions" />
- <item text="" />
+ <item text="Added notifications" />
+ <item text="Themed more components" />
+ <item text="Separated independent web overlay from in app overlay" />
+ <item text="Allow notifications from any account" />
<item text="" />
<item text="" />
<item text="" />