From a17ae247c496d2ec8038f36428812f3c2e410d87 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 12 Jun 2017 16:51:27 -0700 Subject: Add kau and web scrolling --- app/src/main/AndroidManifest.xml | 3 + .../main/kotlin/com/pitchedapps/frost/FrostApp.kt | 2 +- .../kotlin/com/pitchedapps/frost/LoginActivity.kt | 3 +- .../kotlin/com/pitchedapps/frost/MainActivity.kt | 37 ++++-- .../com/pitchedapps/frost/SelectorActivity.kt | 10 +- .../com/pitchedapps/frost/SettingsActivity.kt | 46 ++++++- .../kotlin/com/pitchedapps/frost/StartActivity.kt | 2 +- .../com/pitchedapps/frost/WebOverlayActivity.kt | 4 +- .../com/pitchedapps/frost/dbflow/CookiesDb.kt | 3 +- .../com/pitchedapps/frost/facebook/FbConst.kt | 5 +- .../com/pitchedapps/frost/facebook/FbCookie.kt | 2 +- .../com/pitchedapps/frost/fragments/WebFragment.kt | 6 +- .../frost/preferences/PreferenceBuilder.kt | 65 ---------- .../frost/preferences/PreferenceCheckboxView.kt | 24 ---- .../frost/preferences/PreferenceView.kt | 73 ----------- .../frost/settings/BaseSubSettingsActivity.kt | 11 -- .../settings/MaterialDialogColorPreference.kt | 13 -- .../pitchedapps/frost/settings/SettingsFragment.kt | 31 ----- .../com/pitchedapps/frost/utils/Changelog.kt | 98 --------------- .../com/pitchedapps/frost/utils/ContextUtils.kt | 26 +--- .../com/pitchedapps/frost/utils/FragmentUtils.kt | 24 ---- .../com/pitchedapps/frost/utils/IIconUtils.kt | 19 --- .../com/pitchedapps/frost/utils/Kotterknife.kt | 137 --------------------- .../main/kotlin/com/pitchedapps/frost/utils/L.kt | 9 +- .../kotlin/com/pitchedapps/frost/utils/Prefs.kt | 103 ++-------------- .../com/pitchedapps/frost/views/AccountItem.kt | 9 +- .../com/pitchedapps/frost/web/FrostWebView.kt | 3 +- .../com/pitchedapps/frost/web/FrostWebViewCore.kt | 23 ++-- app/src/main/res/layout/preference_frost.xml | 58 +++++---- app/src/main/res/values/ids.xml | 10 ++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/strings_preferences | 5 +- app/src/main/res/xml/preferences_appearance.xml | 12 -- 33 files changed, 169 insertions(+), 709 deletions(-) delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceBuilder.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceCheckboxView.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceView.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/settings/BaseSubSettingsActivity.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/settings/MaterialDialogColorPreference.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/settings/SettingsFragment.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/utils/Changelog.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/utils/IIconUtils.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/utils/Kotterknife.kt delete mode 100644 app/src/main/res/xml/preferences_appearance.xml (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6a6f71ba..3d001740 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -96,6 +96,9 @@ + if (current) launchWebOverlay(FbTab.PROFILE.url) - else switchUser(profile.identifier, { refreshObservable.onNext(true) }) + else when (profile.identifier) { + -2L -> launchNewTask(LoginActivity::class.java, clearStack = false) + -3L -> launchNewTask(SelectorActivity::class.java, cookies(), false) + else -> switchUser(profile.identifier, { refreshObservable.onNext(true) }) + } false } } @@ -145,11 +166,9 @@ class MainActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.action_settings -> { - launchNewTask(SelectorActivity::class.java, cookies()) -// startActivity(Intent(this, LoginActivity::class.java)) -// finish() + startActivity(Intent(this, SettingsActivity::class.java)) } - R.id.action_changelog -> Changelog.show(this) + R.id.action_changelog -> showChangelog(R.xml.changelog) R.id.action_call -> launchNewTask(LoginActivity::class.java) R.id.action_db -> adapter.pages.saveAsync(this) R.id.action_restart -> restart() @@ -168,7 +187,7 @@ class MainActivity : AppCompatActivity() { inner class SectionsPagerAdapter(fm: FragmentManager, val pages: List) : FragmentPagerAdapter(fm) { - override fun getItem(position: Int) = WebFragment.newInstance(pages[position].url) + override fun getItem(position: Int) = WebFragment(pages[position].url) override fun getCount() = pages.size diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt index 12a165ad..57d0ff4d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt @@ -5,13 +5,11 @@ import android.support.v7.app.AppCompatActivity import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView import android.view.View -import butterknife.ButterKnife import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter import com.mikepenz.fastadapter.listeners.ClickEventHook import com.pitchedapps.frost.facebook.FbCookie -import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.bindView +import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.cookies import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.views.AccountItem @@ -27,14 +25,12 @@ class SelectorActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_selector) - ButterKnife.bind(this) recycler.layoutManager = GridLayoutManager(this, 2) recycler.adapter = adapter adapter.add(cookies().map { AccountItem(it) }) adapter.add(AccountItem(null)) // add account - adapter.withItemEvent(object : ClickEventHook() { - override fun onBind(viewHolder: RecyclerView.ViewHolder): View? - = if (viewHolder is AccountItem.ViewHolder) viewHolder.v else null + adapter.withEventHook(object : ClickEventHook() { + override fun onBind(viewHolder: RecyclerView.ViewHolder): View? = (viewHolder as? AccountItem.ViewHolder)?.v override fun onClick(v: View, position: Int, fastAdapter: FastAdapter, item: AccountItem) { if (item.cookie == null) this@SelectorActivity.launchNewTask(LoginActivity::class.java) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt index 56effb37..b5770739 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt @@ -1,11 +1,51 @@ package com.pitchedapps.frost -import android.preference.PreferenceActivity -import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import ca.allanwang.kau.kpref.KPrefActivity +import ca.allanwang.kau.kpref.KPrefAdapterBuilder +import ca.allanwang.kau.utils.darken +import ca.allanwang.kau.utils.navigationBarColor +import ca.allanwang.kau.views.RippleCanvas +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.pitchedapps.frost.utils.Prefs /** * Created by Allan Wang on 2017-06-06. */ -class SettingsActivity:AppCompatActivity() { +class SettingsActivity : KPrefActivity() { + override fun onCreateKPrefs(savedInstanceState: android.os.Bundle?): KPrefAdapterBuilder.() -> Unit = { + textColor = { Prefs.textColor } + accentColor = { Prefs.textColor } + header(R.string.settings) + colorPicker(title = R.string.text_color, + getter = { Prefs.textColor }, setter = { Prefs.textColor = it; reload() }, + configs = { + allowCustom = true + }) + colorPicker(iicon = GoogleMaterial.Icon.gmd_colorize, + title = R.string.background_color, + getter = { Prefs.bgColor }, setter = { Prefs.bgColor = it; bgCanvas.ripple(it, duration = 500L) }, + configs = { + allowCustomAlpha = false + allowCustom = true + }) + colorPicker(title = R.string.header_color, + getter = { Prefs.headerColor }, setter = { + Prefs.headerColor = it + val darkerColor = it.darken() + this@SettingsActivity.navigationBarColor = darkerColor + toolbarCanvas.ripple(darkerColor, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L) + }, + configs = { + allowCustom = false + }) + } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + bgCanvas.set(Prefs.bgColor) + val darkAccent = Prefs.headerColor.darken() + toolbarCanvas.set(darkAccent) + this.navigationBarColor = darkAccent + } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt index 3dcfc004..751658e9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt @@ -19,7 +19,7 @@ class StartActivity : AppCompatActivity() { cookies -> L.d("Cookies loaded ${System.currentTimeMillis()} $cookies") if (cookies.isNotEmpty()) - launchNewTask(if (Prefs.userId != Prefs.userIdDefault) MainActivity::class.java else SelectorActivity::class.java, ArrayList(cookies)) + launchNewTask(if (Prefs.userId != -1L) MainActivity::class.java else SelectorActivity::class.java, ArrayList(cookies)) else launchNewTask(LoginActivity::class.java) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt index 3ec47a10..1968d07e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt @@ -4,8 +4,9 @@ import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar import butterknife.ButterKnife +import ca.allanwang.kau.utils.bindView import com.jude.swipbackhelper.SwipeBackHelper -import com.pitchedapps.frost.utils.bindView +import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.url import com.pitchedapps.frost.web.FrostWebView @@ -21,7 +22,6 @@ class WebOverlayActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_web_overlay) - ButterKnife.bind(this) setSupportActionBar(toolbar) supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt index e48814cf..46946ab9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt @@ -3,7 +3,6 @@ package com.pitchedapps.frost.dbflow import android.os.Parcel import android.os.Parcelable import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.Prefs import com.raizlabs.android.dbflow.annotation.ConflictAction import com.raizlabs.android.dbflow.annotation.Database import com.raizlabs.android.dbflow.annotation.PrimaryKey @@ -24,7 +23,7 @@ object CookiesDb { @PaperParcel @Table(database = CookiesDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE) -data class CookieModel(@PrimaryKey var id: Long = Prefs.userIdDefault, var name: String? = null, var cookie: String? = null) : BaseModel(), Parcelable { +data class CookieModel(@PrimaryKey var id: Long = -1L, var name: String? = null, var cookie: String? = null) : BaseModel(), Parcelable { companion object { @JvmField val CREATOR = PaperParcelCookieModel.CREATOR } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index 0a7041de..5c8b0a1a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -6,4 +6,7 @@ package com.pitchedapps.frost.facebook const val HTTPS_FACEBOOK_COM = "https://facebook.com" const val FACEBOOK_COM = "facebook.com" const val FB_URL_BASE = "https://m.facebook.com/" -fun PROFILE_PICTURE_URL(id: Long) = "https://graph.facebook.com/$id/picture?type=large" \ No newline at end of file +fun PROFILE_PICTURE_URL(id: Long) = "https://graph.facebook.com/$id/picture?type=large" + +const val USER_AGENT_BASIC = "Mozilla/5.0 (Linux; U; Android 2.3.3; en-gb; Nexus S Build/GRI20) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" +const val USER_AGENT_MESSENGER = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" \ 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 2d46f36a..42232fc6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -59,7 +59,7 @@ object FbCookie { } fun reset(callback: () -> Unit) { - Prefs.userId = Prefs.userIdDefault + Prefs.userId = -1L with(CookieManager.getInstance()) { removeAllCookies({ flush() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt index 2df3ae6f..40f37189 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt @@ -7,8 +7,8 @@ import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import ca.allanwang.kau.utils.withBundle import com.pitchedapps.frost.MainActivity -import com.pitchedapps.frost.utils.putString import com.pitchedapps.frost.web.FrostWebView import com.pitchedapps.frost.web.FrostWebViewCore import io.reactivex.android.schedulers.AndroidSchedulers @@ -23,7 +23,9 @@ class WebFragment : Fragment() { companion object { private const val ARG_URL = "arg_url" - fun newInstance(url: String) = WebFragment().putString(ARG_URL, url) + operator fun invoke(url: String) = WebFragment().withBundle { + putString(ARG_URL, url) + } } // val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceBuilder.kt b/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceBuilder.kt deleted file mode 100644 index f49eac8f..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceBuilder.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.pitchedapps.frost.preferences - -import android.content.Context -import android.support.annotation.ColorInt -import android.support.annotation.ColorRes -import android.support.annotation.StringRes -import com.mikepenz.iconics.typeface.IIcon -import com.pitchedapps.frost.utils.toColor -import com.pitchedapps.frost.utils.toString - -/** - * Created by Allan Wang on 2017-06-06. - */ -//fun Context.preference(setup: PreferenceBuild) - -@DslMarker -annotation class PreferenceMarker - -@PreferenceMarker -enum class PreferenceType() { - HEADER, TEXT, CHECKBOX; - - fun createView(builder: PrefItem) { - - } -} - -@PreferenceMarker -class PrefFrame(val context: Context, val theme: ThemeBuilder? = null, builder: PrefFrameBuilder.() -> Unit) - -@PreferenceMarker -class PrefFrameBuilder() { - val items: MutableList> = mutableListOf() - - fun item(item: PrefItem) { - items.add(item) - } -} - -@PreferenceMarker -class ThemeBuilder(context: Context, @ColorInt text: Int? = null, @ColorRes textRes: Int? = null, - @ColorInt accent: Int? = null, @ColorRes accentRes: Int? = null, - @ColorInt background: Int? = null, @ColorRes backgroundRes: Int? = null) { - val textColor = text ?: textRes?.toColor(context) - val accentColor = accent ?: accentRes?.toColor(context) - val backgroundColor = background ?: backgroundRes?.toColor(context) -} - -@PreferenceMarker -class PrefItem( - context: Context, - val key: String, - title: String? = null, - @StringRes titleRes: Int? = null, - description: String? = null, - @StringRes descriptionRes: Int? = null, - val onClick: (key: String, current: T, callback: (T) -> Unit) -> Unit, - val iicon: IIcon? = null, - val getter: (key: String) -> T, - val setter: (key: String, value: T) -> Unit -) { - val title: String = titleRes?.toString(context) ?: title ?: "" - val description: String = descriptionRes?.toString(context) ?: description ?: "" - val originalValue: T by lazy { getter.invoke(key) } -} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceCheckboxView.kt b/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceCheckboxView.kt deleted file mode 100644 index 311ce051..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceCheckboxView.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.pitchedapps.frost.preferences - -import android.content.Context -import android.content.res.ColorStateList -import android.support.annotation.ColorInt -import android.view.View - -/** - * Created by Allan Wang on 2017-06-06. - */ -class PreferenceCheckboxView(context: Context, builder: PrefItem, themeBuilder: ThemeBuilder?) : PreferenceView(context, builder, themeBuilder) { - - init { - checkbox.visibility = View.VISIBLE - } - - override fun viewWithClick() = checkbox - - override fun setAccentColor(@ColorInt color: Int) { - val state = ColorStateList.valueOf(color) - checkbox.buttonTintList = state - icon.imageTintList = state - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceView.kt b/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceView.kt deleted file mode 100644 index 60c3bb9d..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceView.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.pitchedapps.frost.preferences - -import android.annotation.SuppressLint -import android.content.Context -import android.support.annotation.ColorInt -import android.view.View -import android.widget.CheckBox -import android.widget.ImageView -import android.widget.LinearLayout -import android.widget.TextView -import butterknife.ButterKnife -import com.pitchedapps.frost.R -import com.pitchedapps.frost.utils.bindView -import com.pitchedapps.frost.utils.toDrawable - -@SuppressLint("ViewConstructor") -/** - * Created by Allan Wang on 2017-06-06. - */ -open class PreferenceView( - context: Context, builder: PrefItem, themeBuilder: ThemeBuilder? -) : LinearLayout(context) { - - val iconFrame: LinearLayout by bindView(R.id.icon_frame) - val icon: ImageView by bindView(R.id.icon) - val title: TextView by bindView(R.id.title) - val desc: TextView by bindView(R.id.summary) - val checkbox: CheckBox by bindView(R.id.checkbox) - val key = builder.key - private val getter = builder.getter - private val setter = builder.setter - var pref: T - get() = getter.invoke(key) - set(value) { - setter.invoke(key, value) - } - val original = pref - val hasChanged: Boolean - get() = original == pref - - init { - ButterKnife.bind(this) - title.text = builder.title - desc.text = builder.description - if (builder.iicon == null) iconFrame.visibility = View.GONE - else icon.setImageDrawable(builder.iicon.toDrawable(context, sizeDp = 48)) - if (themeBuilder != null) { - with(themeBuilder) { - if (textColor != null) setTextColor(textColor) - if (accentColor != null) setAccentColor(accentColor) - } - } - setClick(builder.onClick) - } - - fun setClick(listener: (key: String, current: T, callback: (T) -> Unit) -> Unit) { - viewWithClick().setOnClickListener { - listener.invoke(key, pref, { pref = it }) - } - } - - open fun viewWithClick(): View = this - - open fun setTextColor(@ColorInt color: Int) { - title.setTextColor(color) - desc.setTextColor(color) - desc.alpha = 0.7f - } - - //Accent color is not needed for basic prefs - open fun setAccentColor(@ColorInt color: Int) {} - -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/BaseSubSettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/BaseSubSettingsActivity.kt deleted file mode 100644 index a6af3ba6..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/BaseSubSettingsActivity.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.pitchedapps.frost.settings - -import android.preference.PreferenceActivity -import android.support.v7.app.AppCompatActivity - -/** - * Created by Allan Wang on 2017-06-06. - */ -class BaseSubSettingsActivity:PreferenceActivity() { - -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/MaterialDialogColorPreference.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/MaterialDialogColorPreference.kt deleted file mode 100644 index 56a371f8..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/MaterialDialogColorPreference.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.pitchedapps.frost.settings - -import android.content.Context -import android.util.AttributeSet -import com.afollestad.materialdialogs.prefs.MaterialDialogPreference - -/** - * Created by Allan Wang on 2017-06-06. - */ -class MaterialDialogColorPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) - : MaterialDialogPreference(context, attrs, defStyleAttr, defStyleRes) { - -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/SettingsFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/SettingsFragment.kt deleted file mode 100644 index 78ad324a..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/SettingsFragment.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.pitchedapps.frost.settings - -import android.os.Bundle -import android.support.v7.preference.AndroidResources -import android.support.v7.preference.PreferenceFragmentCompat -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import com.pitchedapps.frost.views.RippleCanvas -import com.pitchedapps.frost.views.matchParent - -/** - * Created by Allan Wang on 2017-05-31. - */ -class SettingsFragment : PreferenceFragmentCompat() { - - lateinit var ripple: RippleCanvas - - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val view = super.onCreateView(inflater, container, savedInstanceState)!! - val frame = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER) as ViewGroup - ripple = RippleCanvas(frame.context) - ripple.matchParent() - frame.addView(ripple, 0) - return view - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Changelog.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Changelog.kt deleted file mode 100644 index 14a095a1..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Changelog.kt +++ /dev/null @@ -1,98 +0,0 @@ -package com.pitchedapps.frost.utils - -import android.content.Context -import android.content.res.XmlResourceParser -import android.os.Handler -import android.support.annotation.LayoutRes -import android.support.annotation.NonNull -import android.support.annotation.XmlRes -import android.support.v4.app.FragmentActivity -import android.support.v7.widget.RecyclerView -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.TextView -import com.afollestad.materialdialogs.MaterialDialog -import com.pitchedapps.frost.R -import org.xmlpull.v1.XmlPullParser -import java.util.* - - -/** - * Created by Allan Wang on 2017-05-28. - */ -class Changelog { - companion object { - fun show(@NonNull activity: FragmentActivity, @XmlRes xmlRes: Int = R.xml.changelog) { - val mHandler = Handler() - Thread(Runnable { - val items = parse(activity, xmlRes) - mHandler.post(object : TimerTask() { - override fun run() { - MaterialDialog.Builder(activity) - .title(R.string.changelog) - .positiveText(R.string.great) - .adapter(ChangelogAdapter(items), null) - .show() - } - }) - }).start() - } - } -} - -private class ChangelogAdapter(val items: List>) : RecyclerView.Adapter() { - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ChangelogVH(LayoutInflater.from(parent.context) - .inflate(getLayout(viewType), parent, false)) - - private fun getLayout(position: Int) = items[position].second.layout - - override fun onBindViewHolder(holder: ChangelogVH, position: Int) { - holder.text.text = items[position].first - } - - override fun getItemId(position: Int) = position.toLong() - - override fun getItemViewType(position: Int) = position - - override fun getItemCount() = items.size - - internal class ChangelogVH(itemView: View) : RecyclerView.ViewHolder(itemView) { - val text: TextView = itemView.findViewById(R.id.changelog_text) as TextView - } -} - -private fun parse(context: Context, @XmlRes xmlRes: Int): List> { - val items = mutableListOf>() - context.resources.getXml(xmlRes).use { - parser -> - var eventType = parser.eventType - while (eventType != XmlPullParser.END_DOCUMENT) { - if (eventType == XmlPullParser.START_TAG) - ChangelogType.values.any { it.add(parser, items) } - eventType = parser.next() - } - } - return items -} - -private enum class ChangelogType(val tag: String, val attr: String, @LayoutRes val layout: Int) { - TITLE("title", "version", R.layout.changelog_title), - ITEM("item", "text", R.layout.changelog_content); - - companion object { - val values = values() - } - - /** - * Returns true if tag matches; false otherwise - */ - fun add(parser: XmlResourceParser, list: MutableList>): Boolean { - if (parser.name != tag) return false - if (parser.getAttributeValue(null, attr).isNotBlank()) - list.add(Pair(parser.getAttributeValue(null, attr), this)) - return true - } -} - diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt index f13ec20d..e601283c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.Intent import android.support.v4.app.ActivityOptionsCompat import android.support.v4.content.ContextCompat +import ca.allanwang.kau.utils.startActivity import com.pitchedapps.frost.LoginActivity import com.pitchedapps.frost.R import com.pitchedapps.frost.WebOverlayActivity @@ -17,12 +18,10 @@ import com.pitchedapps.frost.facebook.FbTab private const val EXTRA_COOKIES = "extra_cookies" private const val ARG_URL = "arg_url" -fun Context.launchNewTask(clazz: Class, cookieList: ArrayList = arrayListOf()) { - val intent = (Intent(this, clazz)) - if (clazz != LoginActivity::class.java) 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) - if (this is Activity) finish() +fun Context.launchNewTask(clazz: Class, cookieList: ArrayList = arrayListOf(), clearStack: Boolean = clazz != LoginActivity::class.java) { + startActivity(clazz, clearStack, { + putParcelableArrayListExtra(EXTRA_COOKIES, cookieList) + }) } fun Activity.cookies(): ArrayList { @@ -39,17 +38,4 @@ fun Context.launchWebOverlay(url: String) { fun WebOverlayActivity.url(): String { return intent.extras?.getString(ARG_URL) ?: FbTab.FEED.url -} - -fun Activity.restart(extras: ((Intent) -> Unit)? = null) { - val i = Intent(this, this::class.java) - i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) - extras?.invoke(i) - startActivity(i) - overridePendingTransition(0, 0) //No transitions - finish() - overridePendingTransition(0, 0) -} - -fun Int.toString(c: Context) = c.getString(this) -fun Int.toColor(c: Context) = ContextCompat.getColor(c, this) \ No newline at end of file +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt deleted file mode 100644 index f945c90a..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/FragmentUtils.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.pitchedapps.frost.utils - -import android.os.Bundle -import android.support.v4.app.Fragment - -/** - * Created by Allan Wang on 2017-05-29. - */ - -private fun Fragment.bundle(): Bundle { - if (this.arguments == null) - this.arguments = Bundle() - return this.arguments -} - -fun T.putString(key: String, value: String): T { - this.bundle().putString(key, value) - return this -} - -fun 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 deleted file mode 100644 index 2e0a44c1..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/IIconUtils.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.pitchedapps.frost.utils - -import android.content.Context -import android.content.res.ColorStateList -import android.graphics.Color -import android.graphics.drawable.Drawable -import android.support.annotation.ColorInt -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, @ColorInt color: Int = Color.WHITE): Drawable { - val state = ColorStateList.valueOf(color) - val icon = IconicsDrawable(c).icon(this).sizeDp(sizeDp) - icon.setTintList(state) - return icon -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Kotterknife.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Kotterknife.kt deleted file mode 100644 index 6e3b5c24..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Kotterknife.kt +++ /dev/null @@ -1,137 +0,0 @@ -package com.pitchedapps.frost.utils - -/** - * Created by Allan Wang on 2017-05-29. - * - * Courtesy of Jake Wharton - * - * https://github.com/JakeWharton/kotterknife/blob/master/src/main/kotlin/kotterknife/ButterKnife.kt - */ -import android.app.Activity -import android.app.Dialog -import android.app.DialogFragment -import android.app.Fragment -import android.support.v7.widget.RecyclerView.ViewHolder -import android.view.View -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty -import android.support.v4.app.DialogFragment as SupportDialogFragment -import android.support.v4.app.Fragment as SupportFragment - -public fun View.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) -public fun Activity.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) -public fun Dialog.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) -public fun DialogFragment.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) -public fun SupportDialogFragment.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) -public fun Fragment.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) -public fun SupportFragment.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) -public fun ViewHolder.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) - -public fun View.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) -public fun Activity.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) -public fun Dialog.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) -public fun DialogFragment.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) -public fun SupportDialogFragment.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) -public fun Fragment.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) -public fun SupportFragment.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) -public fun ViewHolder.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) - -public fun View.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) -public fun Activity.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) -public fun Dialog.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) -public fun DialogFragment.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) -public fun SupportDialogFragment.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) -public fun Fragment.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) -public fun SupportFragment.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) -public fun ViewHolder.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) - -public fun View.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) -public fun Activity.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) -public fun Dialog.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) -public fun DialogFragment.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) -public fun SupportDialogFragment.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) -public fun Fragment.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) -public fun SupportFragment.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) -public fun ViewHolder.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) - -private val View.viewFinder: View.(Int) -> View? - get() = { findViewById(it) } -private val Activity.viewFinder: Activity.(Int) -> View? - get() = { findViewById(it) } -private val Dialog.viewFinder: Dialog.(Int) -> View? - get() = { findViewById(it) } -private val DialogFragment.viewFinder: DialogFragment.(Int) -> View? - get() = { dialog.findViewById(it) } -private val SupportDialogFragment.viewFinder: SupportDialogFragment.(Int) -> View? - get() = { dialog.findViewById(it) } -private val Fragment.viewFinder: Fragment.(Int) -> View? - get() = { view.findViewById(it) } -private val SupportFragment.viewFinder: SupportFragment.(Int) -> View? - get() = { view!!.findViewById(it) } -private val ViewHolder.viewFinder: ViewHolder.(Int) -> View? - get() = { itemView.findViewById(it) } - -private fun viewNotFound(id:Int, desc: KProperty<*>): Nothing = - throw IllegalStateException("View ID $id for '${desc.name}' not found.") - -@Suppress("UNCHECKED_CAST") -private fun required(id: Int, finder: T.(Int) -> View?) - = Lazy { t: T, desc -> t.finder(id) as V? ?: viewNotFound(id, desc) } - -@Suppress("UNCHECKED_CAST") -private fun optional(id: Int, finder: T.(Int) -> View?) - = Lazy { t: T, desc -> t.finder(id) as V? } - -@Suppress("UNCHECKED_CAST") -private fun required(ids: IntArray, finder: T.(Int) -> View?) - = Lazy { t: T, desc -> ids.map { t.finder(it) as V? ?: viewNotFound(it, desc) } } - -@Suppress("UNCHECKED_CAST") -private fun optional(ids: IntArray, finder: T.(Int) -> View?) - = Lazy { t: T, desc -> ids.map { t.finder(it) as V? }.filterNotNull() } - -// Like Kotlin's lazy delegate but the initializer gets the target and metadata passed to it -private class Lazy(private val initializer: (T, KProperty<*>) -> V) : ReadOnlyProperty { - private object EMPTY - private var value: Any? = EMPTY - - override fun getValue(thisRef: T, property: KProperty<*>): V { - if (value == EMPTY) { - value = initializer(thisRef, property) - } - @Suppress("UNCHECKED_CAST") - return value as V - } -} \ 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 3d5cf1cb..d9ce828e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt @@ -1,6 +1,7 @@ package com.pitchedapps.frost.utils import android.util.Log +import ca.allanwang.kau.logging.TimberLogger import com.crashlytics.android.Crashlytics import timber.log.Timber @@ -8,13 +9,7 @@ import timber.log.Timber /** * Created by Allan Wang on 2017-05-28. */ -object L { - const val TAG = "Frost: %s" - fun e(s: String) = Timber.e(TAG, s) - fun d(s: String) = Timber.d(TAG, s) - fun i(s: String) = Timber.i(TAG, s) - fun v(s: String) = Timber.v(TAG, s) -} +object L : TimberLogger("Frost") internal class CrashReportingTree : Timber.Tree() { override fun log(priority: Int, tag: String?, message: String?, t: Throwable?) { 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 ec296309..89cccd40 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -1,111 +1,26 @@ package com.pitchedapps.frost.utils -import android.content.Context -import android.content.SharedPreferences import android.graphics.Color +import ca.allanwang.kau.kpref.KPref +import ca.allanwang.kau.kpref.kpref /** * Created by Allan Wang on 2017-05-28. * * Shared Preference object with lazy cached retrievals */ +object Prefs : KPref() { -private val PREFERENCE_NAME = "${com.pitchedapps.frost.BuildConfig.APPLICATION_ID}.prefs" -private val LAST_ACTIVE = "last_active" -private val USER_ID = "user_id" -private val COLOR_TEXT = "color_text" -private val COLOR_BG = "color_bg" -private val COLOR_HEADER = "color_header" -private val COLOR_ICONS = "color_icons" -private val THEME_TYPE = "theme_type" + var lastActive: Long by kpref("last_active", -1L) -object Prefs { + var userId: Long by kpref("user_id", -1L) - private const val prefDefaultLong = -2L - private const val prefDefaultInt = -2 + var textColor: Int by kpref("color_text", Color.BLACK) - lateinit private var c: Context - operator fun invoke(c: Context) { - this.c = c - lastActive = 0 - } + var bgColor: Int by kpref("color_bg", Color.WHITE) - private val sp: SharedPreferences by lazy { c.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE) } + var headerColor: Int by kpref("color_header", 0xff3b5998.toInt()) - var lastActive: Long = prefDefaultLong - get() { - if (field == prefDefaultLong) field = sp.getLong(LAST_ACTIVE, -1) - return field - } - set(value) { - field = value - if (value != prefDefaultLong) set(LAST_ACTIVE, System.currentTimeMillis()) - } + var iconColor: Int by kpref("color_icons", Color.WHITE) - const val userIdDefault = -1L - var userId: Long = prefDefaultLong - get() { - if (field == prefDefaultLong) field = sp.getLong(USER_ID, userIdDefault) - return field - } - set(value) { - field = value - if (value != prefDefaultLong) set(USER_ID, value) - } - - var textColor: Int = prefDefaultInt - get() { - if (field == prefDefaultInt) field = sp.getInt(COLOR_TEXT, Color.BLACK) - return field - } - set(value) { - field = value - if (value != prefDefaultInt) set(COLOR_TEXT, value) - } - - var bgColor: Int = prefDefaultInt - get() { - if (field == prefDefaultInt) field = sp.getInt(COLOR_BG, Color.WHITE) - return field - } - set(value) { - field = value - if (value != prefDefaultInt) set(COLOR_BG, value) - } - - var headerColor: Int = prefDefaultInt - get() { - if (field == prefDefaultInt) field = sp.getInt(COLOR_HEADER, 0xff3b5998.toInt()) - return field - } - set(value) { - field = value - if (value != prefDefaultInt) set(COLOR_HEADER, value) - } - - var iconColor: Int = prefDefaultInt - get() { - if (field == prefDefaultInt) field = sp.getInt(COLOR_ICONS, Color.WHITE) - return field - } - set(value) { - field = value - if (value != prefDefaultInt) set(COLOR_ICONS, value) - } - - private fun set(key: String, value: Boolean) = sp.edit().putBoolean(key, value).apply() - private fun set(key: String, value: Int) = sp.edit().putInt(key, value).apply() - private fun set(key: String, value: Long) = sp.edit().putLong(key, value).apply() - private fun set(key: String, value: String) = sp.edit().putString(key, value).apply() - - fun clear() { - L.d("Clearing Prefs") - sp.edit().clear().apply() - lastActive = prefDefaultLong - userId = prefDefaultLong - textColor = prefDefaultInt - bgColor = prefDefaultInt - headerColor = prefDefaultInt - iconColor = prefDefaultInt - } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt index 6c5d5b6c..8cb189e7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt @@ -5,7 +5,8 @@ import android.support.v7.widget.AppCompatTextView import android.support.v7.widget.RecyclerView import android.view.View import android.widget.ImageView -import butterknife.ButterKnife +import ca.allanwang.kau.utils.bindView +import ca.allanwang.kau.utils.toDrawable import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException @@ -18,8 +19,6 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.pitchedapps.frost.R import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL -import com.pitchedapps.frost.utils.bindView -import com.pitchedapps.frost.utils.toDrawable /** * Created by Allan Wang on 2017-06-05. @@ -70,9 +69,5 @@ class AccountItem(val cookie: CookieModel?) : AbstractItem= Build.VERSION_CODES.N) progress.setProgress(it, true) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt index 146f5a33..1d3f348a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -3,7 +3,6 @@ package com.pitchedapps.frost.web import android.animation.ValueAnimator import android.annotation.SuppressLint import android.content.Context -import android.support.v4.view.MotionEventCompat import android.support.v4.view.NestedScrollingChild import android.support.v4.view.NestedScrollingChildHelper import android.support.v4.view.ViewCompat @@ -12,9 +11,7 @@ import android.view.MotionEvent import android.view.View import android.view.animation.DecelerateInterpolator import android.webkit.WebView -import com.pitchedapps.frost.MainActivity -import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.cookies +import com.pitchedapps.frost.facebook.USER_AGENT_BASIC import io.reactivex.Scheduler import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -53,6 +50,7 @@ class FrostWebViewCore @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") fun setupWebview() { settings.javaScriptEnabled = true + settings.userAgentString = USER_AGENT_BASIC // settings.domStorageEnabled = true setLayerType(View.LAYER_TYPE_HARDWARE, null) setWebViewClient(FrostWebViewClient(refreshObservable)) @@ -72,7 +70,7 @@ class FrostWebViewCore @JvmOverloads constructor( override fun onTouchEvent(ev: MotionEvent): Boolean { val event = MotionEvent.obtain(ev) - val action = MotionEventCompat.getActionMasked(event) + val action = event.action if (action == MotionEvent.ACTION_DOWN) nestedOffsetY = 0 val eventY = event.y.toInt() @@ -115,21 +113,20 @@ class FrostWebViewCore @JvmOverloads constructor( * Otherwise scroll to top */ fun scrollOrRefresh() { - L.d("Scroll or Refresh") if (scrollY < 5) loadBaseUrl() else scrollToTop() } fun scrollToTop() { - if (scrollY > 1000) scrollTo(0, 0) - else { + flingScroll(0, 0) // stop fling + if (scrollY > 10000) { + scrollTo(0, 0) + } else { val animator = ValueAnimator.ofInt(scrollY, 0) - animator.duration = scrollY.toLong() + animator.duration = Math.min(scrollY, 500).toLong() animator.interpolator = DecelerateInterpolator() - animator.addUpdateListener { - scrollY = it.animatedValue as Int - invalidate() - } + animator.addUpdateListener { scrollY = it.animatedValue as Int } + animator.start() } } diff --git a/app/src/main/res/layout/preference_frost.xml b/app/src/main/res/layout/preference_frost.xml index bcbed7f2..939c6d32 100644 --- a/app/src/main/res/layout/preference_frost.xml +++ b/app/src/main/res/layout/preference_frost.xml @@ -2,63 +2,67 @@ + android:gravity="center_vertical" + android:minHeight="?android:attr/listPreferredItemHeightSmall" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" + android:paddingStart="?android:attr/listPreferredItemPaddingStart"> + android:visibility="gone"> + + android:maxHeight="48dp" + android:maxWidth="48dp" /> + android:paddingBottom="16dp" + android:paddingTop="16dp"> - + android:ellipsize="marquee" + android:textAppearance="?android:attr/textAppearanceListItem" /> - + android:textAppearance="?android:attr/textAppearanceListItemSecondary" + android:textColor="?android:attr/textColorSecondary" /> - + android:layout_height="match_parent" + android:gravity="end|center_vertical" + android:paddingLeft="16dp" + android:orientation="vertical" /> \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 8df89eb6..76a167af 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -1,4 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7287c4c0..323cb42a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,4 +27,6 @@ Login Select Facebook Account Add Account + Add Facebook Account + Manage Account diff --git a/app/src/main/res/values/strings_preferences b/app/src/main/res/values/strings_preferences index 5b10d8ae..9cb29553 100644 --- a/app/src/main/res/values/strings_preferences +++ b/app/src/main/res/values/strings_preferences @@ -1,3 +1,6 @@ - Settings + Settings + Text Color + Background Color + Header Color \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_appearance.xml b/app/src/main/res/xml/preferences_appearance.xml deleted file mode 100644 index 23e179fd..00000000 --- a/app/src/main/res/xml/preferences_appearance.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file -- cgit v1.2.3