diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
6 files changed, 48 insertions, 10 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt index 025b9001..0e5c9915 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt @@ -42,7 +42,7 @@ class MainActivity : AppCompatActivity() { lateinit var drawer: Drawer lateinit var drawerHeader: AccountHeader var titleDisposable: Disposable? = null - var refreshObservable = PublishSubject.create<Unit>().observeOn(AndroidSchedulers.mainThread()) + var refreshObservable = PublishSubject.create<Boolean>() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -135,6 +135,10 @@ class MainActivity : AppCompatActivity() { } } + fun refreshAll() { + refreshObservable.onNext(true) + } + override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_main, menu) return true diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt index 11db1a67..f293c3d3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt @@ -2,9 +2,11 @@ package com.pitchedapps.frost import android.os.Bundle import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView import butterknife.ButterKnife import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter +import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.bindView import com.pitchedapps.frost.utils.cookies import com.pitchedapps.frost.views.AccountItem @@ -21,7 +23,9 @@ class SelectorActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_selector) ButterKnife.bind(this) + recycler.layoutManager = GridLayoutManager(this, 2) recycler.adapter = adapter + L.d("Selector ${cookies()}") adapter.add(cookies().map { AccountItem(it) }) adapter.add(AccountItem()) // add account } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt index 04056043..16860cc5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle 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 /** @@ -17,10 +18,12 @@ class StartActivity : AppCompatActivity() { loadFbCookiesAsync { cookies -> L.d("Cookies loaded ${System.currentTimeMillis()} $cookies") - if (cookies.isNotEmpty()) - launchNewTask(MainActivity::class.java, ArrayList(cookies)) - else - launchNewTask(LoginActivity::class.java) + if (cookies.isNotEmpty()) { + if (Prefs.userId != Prefs.userIdDefault) + launchNewTask(MainActivity::class.java, ArrayList(cookies)) + else + launchNewTask(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/fragments/WebFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt index e8fb5a21..0542722f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt @@ -11,6 +11,7 @@ import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.putString import com.pitchedapps.frost.web.FrostWebView import com.pitchedapps.frost.web.FrostWebViewCore +import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable /** @@ -18,14 +19,14 @@ import io.reactivex.disposables.Disposable */ -class WebFragment:Fragment() { +class WebFragment : Fragment() { companion object { private const val ARG_URL = "arg_url" fun newInstance(url: String) = WebFragment().putString(ARG_URL, url) } -// val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } + // val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } val web: FrostWebViewCore by lazy { frostWebView.web } lateinit var url: String lateinit private var frostWebView: FrostWebView @@ -65,8 +66,9 @@ class WebFragment:Fragment() { super.onAttach(context) refreshDisposable?.dispose() if (context is MainActivity) - refreshDisposable = context.refreshObservable.subscribe { - web.clearHistory() + refreshDisposable = context.refreshObservable.observeOn(AndroidSchedulers.mainThread()).subscribe { + clearHistory -> + if (clearHistory) web.clearHistory() web.loadBaseUrl() } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/glide/CircleTransformation.kt b/app/src/main/kotlin/com/pitchedapps/frost/glide/CircleTransformation.kt new file mode 100644 index 00000000..c37d7487 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/glide/CircleTransformation.kt @@ -0,0 +1,19 @@ +package com.pitchedapps.frost.glide + +import android.graphics.Bitmap +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation +import java.security.MessageDigest + +/** + * Created by Allan Wang on 2017-06-06. + */ +class CircleTransformation: BitmapTransformation() { + override fun updateDiskCacheKey(messageDigest: MessageDigest?) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +}
\ No newline at end of file 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 5a17fa8f..e0e33e79 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt @@ -1,5 +1,6 @@ package com.pitchedapps.frost.views +import android.graphics.Bitmap import android.graphics.drawable.Drawable import android.support.v7.widget.AppCompatTextView import android.support.v7.widget.RecyclerView @@ -8,8 +9,11 @@ import android.widget.ImageView import butterknife.ButterKnife import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.Transformation import com.bumptech.glide.load.engine.GlideException +import com.bumptech.glide.load.resource.bitmap.CircleCrop import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target import com.mikepenz.fastadapter.items.AbstractItem import com.pitchedapps.frost.R @@ -36,7 +40,8 @@ class AccountItem(val id: Long, val name: String) : AbstractItem<AccountItem, Ac text.visibility = View.INVISIBLE if (id != -1L) { text.text = name - Glide.with(itemView).load(PROFILE_PICTURE_URL(id)).listener(object : RequestListener<Drawable> { + val options = RequestOptions().transform(CircleCrop()) + Glide.with(itemView).load(PROFILE_PICTURE_URL(id)).apply(options).listener(object : RequestListener<Drawable> { override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { text.fadeIn() return false @@ -48,6 +53,7 @@ class AccountItem(val id: Long, val name: String) : AbstractItem<AccountItem, Ac } }).into(image) } else { + text.visibility = View.VISIBLE text.text = itemView.context.getString(R.string.add_account) //todo add plus image } |