1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-09 20:42:34 +01:00

move activity instance creators to ContextUtils

This commit is contained in:
Allan Wang 2017-06-03 14:00:04 -07:00
parent 35185958b0
commit 1ae19368bc
9 changed files with 101 additions and 44 deletions

View File

@ -5,6 +5,12 @@
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="MarkdownProjectSettings">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.25" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="LINE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="true" showSelectionInPreview="true">
<PanelProvider>
@ -68,6 +71,30 @@
<textMaps />
</LinkMapSettings>
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
@ -94,7 +121,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true" assert-keyword="true" jdk-15="true">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -3,6 +3,8 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Frost-for-Facebook.iml" filepath="$PROJECT_DIR$/Frost-for-Facebook.iml" />
<module fileurl="file://$PROJECT_DIR$/Frost-for-Facebook.iml" filepath="$PROJECT_DIR$/Frost-for-Facebook.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>

View File

@ -1,9 +1,11 @@
package com.pitchedapps.frost
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.content.ContextCompat
import android.support.v4.widget.SwipeRefreshLayout
@ -24,6 +26,8 @@ import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.bindView
import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.launchNewTask
import com.pitchedapps.frost.views.fadeIn
import com.pitchedapps.frost.views.fadeOut
import com.pitchedapps.frost.views.setTextWithFade
@ -55,11 +59,14 @@ class LoginActivity : AppCompatActivity() {
val usernameObservable = SingleSubject.create<String>()!!
companion object {
fun newInstance(context: Context) {
const val EXTRA_COOKIES = "extra_cookies"
fun newInstance(context: Context, cookies: ArrayList<CookieModel> = arrayListOf()) {
val intent = Intent(context, LoginActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra(EXTRA_COOKIES, cookies)
val bundle = ActivityOptionsCompat.makeCustomAnimation(context, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
ContextCompat.startActivity(context, intent, bundle)
if (context is Activity) context.finish()
}
}
@ -101,6 +108,11 @@ class LoginActivity : AppCompatActivity() {
L.d("Zip done")
if (!foundImage) L.e("Could not get profile photo; Invalid id?\n\t$cookie")
textview.setTextWithFade(String.format(getString(R.string.welcome), name), duration = 500)
Handler().postDelayed({
val cookies = cookies()
cookies.add(cookie)
launchNewTask(MainActivity::class.java, cookies)
}, 1000)
}
loadProfile(cookie.id)
loadUsername(cookie)

View File

@ -1,7 +1,5 @@
package com.pitchedapps.frost
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.design.widget.Snackbar
@ -30,9 +28,7 @@ import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.fragments.BaseFragment
import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.Changelog
import com.pitchedapps.frost.utils.bindView
import com.pitchedapps.frost.utils.toDrawable
import com.pitchedapps.frost.utils.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
@ -46,24 +42,13 @@ class MainActivity : AppCompatActivity() {
val tabs: TabLayout by bindView(R.id.tabs)
lateinit var drawer: Drawer
lateinit var drawerHeader: AccountHeader
lateinit var cookies: ArrayList<CookieModel>
companion object {
const val EXTRA_COOKIES = "extra_cookies"
fun launch(activity: Activity, cookies: List<CookieModel>) {
val intent = (Intent(activity, MainActivity::class.java))
intent.putParcelableArrayListExtra(EXTRA_COOKIES, ArrayList(cookies))
activity.startActivity(intent)
activity.finish()
}
}
val cookies = cookies()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ButterKnife.bind(this)
setSupportActionBar(toolbar)
cookies = intent.extras.getParcelableArrayList<CookieModel>(EXTRA_COOKIES)
adapter = SectionsPagerAdapter(supportFragmentManager, loadFbTabs())
viewPager.adapter = adapter
viewPager.offscreenPageLimit = 5
@ -108,7 +93,7 @@ class MainActivity : AppCompatActivity() {
}
onProfileChanged { _, profile, current ->
if (current) WebOverlayActivity.newInstance(this@MainActivity, FbTab.PROFILE)
else switchUser(profile.name.text, -1)
else switchUser(profile.name.text)
false
}
}
@ -128,7 +113,7 @@ class MainActivity : AppCompatActivity() {
iicon = item.icon
identifier = item.titleId.toLong()
onClick { _ ->
WebOverlayActivity.newInstance(this@MainActivity, item.url)
launchWebOverlay(item.url)
false
}
}
@ -145,7 +130,7 @@ class MainActivity : AppCompatActivity() {
// finish()
}
R.id.action_changelog -> Changelog.show(this)
R.id.action_call -> LoginActivity.newInstance(this)
R.id.action_call -> launchNewTask(LoginActivity::class.java)
R.id.action_db -> adapter.pages.saveAsync(this)
R.id.action_restart -> {
finish();

View File

@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity
import com.pitchedapps.frost.dbflow.loadFbCookiesAsync
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.launchNewTask
/**
* Created by Allan Wang on 2017-05-28.
@ -18,13 +19,13 @@ class StartActivity : AppCompatActivity() {
loadFbCookiesAsync {
cookies ->
L.d("Cookies loaded ${System.currentTimeMillis()} $cookies")
val sorted = cookies.toMutableList()
val sorted = ArrayList(cookies)
val current = cookies.filter { it.id == Prefs.userId }
if (current.isNotEmpty()) {
sorted.remove(current[0])
sorted.add(0, current[0])
}
MainActivity.launch(this, sorted)
launchNewTask(MainActivity::class.java, sorted)
}
}
}

View File

@ -1,16 +1,12 @@
package com.pitchedapps.frost
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import butterknife.ButterKnife
import com.jude.swipbackhelper.SwipeBackHelper
import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.utils.bindView
import com.pitchedapps.frost.utils.url
import com.pitchedapps.frost.web.FrostWebView
@ -22,24 +18,12 @@ class WebOverlayActivity : AppCompatActivity() {
val toolbar: Toolbar by bindView(R.id.toolbar)
val frostWeb: FrostWebView by bindView(R.id.frost_webview)
companion object {
private const val ARG_URL = "arg_url"
fun newInstance(context: Context, url: String) {
val intent = Intent(context, WebOverlayActivity::class.java)
intent.putExtra(ARG_URL, url)
val bundle = ActivityOptionsCompat.makeCustomAnimation(context, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
ContextCompat.startActivity(context, intent, bundle)
}
fun newInstance(context: Context, url: FbTab) = newInstance(context, url.url)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_overlay)
ButterKnife.bind(this)
setSupportActionBar(toolbar)
frostWeb.baseUrl = intent.extras.getString(ARG_URL)
frostWeb.baseUrl = url()
SwipeBackHelper.onCreate(this)
SwipeBackHelper.getCurrentPage(this)
.setSwipeBackEnable(true)

View File

@ -0,0 +1,40 @@
package com.pitchedapps.frost.utils
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.content.ContextCompat
import com.pitchedapps.frost.R
import com.pitchedapps.frost.WebOverlayActivity
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.FbTab
/**
* Created by Allan Wang on 2017-06-03.
*/
private const val EXTRA_COOKIES = "extra_cookies"
private const val ARG_URL = "arg_url"
fun Activity.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<CookieModel> = arrayListOf()) {
val intent = (Intent(this, clazz))
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putParcelableArrayListExtra(EXTRA_COOKIES, cookieList)
startActivity(intent)
finish()
}
fun Activity.cookies(): ArrayList<CookieModel> {
return intent.extras?.getParcelableArrayList<CookieModel>(EXTRA_COOKIES) ?: arrayListOf()
}
fun Context.launchWebOverlay(url: String) {
val intent = Intent(this, WebOverlayActivity::class.java)
intent.putExtra(ARG_URL, url)
val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
ContextCompat.startActivity(this, intent, bundle)
}
fun WebOverlayActivity.url(): String {
return intent.extras?.getString(ARG_URL) ?: FbTab.FEED.url
}

View File

@ -17,7 +17,7 @@ class FrostChromeClient(val progressObservable: Subject<Int>) : WebChromeClient(
override fun onReceivedTitle(view: WebView?, title: String?) {
super.onReceivedTitle(view, title)
L.d("Title $title")
L.v("Title $title")
}
override fun onProgressChanged(view: WebView, newProgress: Int) {