From bc0559e9cc494df35d8cbeaf4aa49f16549ee3e3 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 5 Jun 2017 23:06:15 -0700 Subject: test --- app/.gitignore | 1 + app/build.gradle | 6 +- .../main/kotlin/com/pitchedapps/frost/FrostApp.kt | 2 +- .../com/pitchedapps/frost/SelectorActivity.kt | 16 +++++ .../com/pitchedapps/frost/dbflow/CookiesDb.kt | 5 +- .../com/pitchedapps/frost/views/AccountItem.kt | 71 ++++++++++++++++++++++ app/src/main/res/layout/activity_selector.xml | 47 ++++++++++++++ app/src/main/res/layout/view_account.xml | 18 ++++++ app/src/main/res/values/ids.xml | 4 ++ app/src/main/res/values/strings.xml | 2 + 10 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt create mode 100644 app/src/main/res/layout/activity_selector.xml create mode 100644 app/src/main/res/layout/view_account.xml create mode 100644 app/src/main/res/values/ids.xml (limited to 'app') diff --git a/app/.gitignore b/app/.gitignore index 796b96d1..b90d2f16 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,2 @@ /build +fabric.properties \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 0603b0da..c71f327d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,6 +80,7 @@ dependencies { compile "com.android.support:recyclerview-v7:${ANDROID_SUPPORT_LIBS}" compile "com.android.support:cardview-v7:${ANDROID_SUPPORT_LIBS}" compile "com.android.support:preference-v14:${ANDROID_SUPPORT_LIBS}" + compile "com.android.support.constraint:constraint-layout:${CONSTRAINT_LAYOUT}" //Logging compile "com.jakewharton.timber:timber:${TIMBER}" @@ -119,9 +120,9 @@ dependencies { compile "com.jakewharton.rxbinding2:rxbinding:${RX_BINDING}" compile "com.jakewharton.rxbinding2:rxbinding-appcompat-v7:${RX_BINDING}" - compile "org.greenrobot:eventbus:${EVENT_BUS}" +// compile "org.greenrobot:eventbus:${EVENT_BUS}" - compile "com.facebook.stetho:stetho-okhttp3:${STETHO}" +// compile "com.facebook.stetho:stetho-okhttp3:${STETHO}" compile "com.lapism:searchview:${SEARCH_VIEW}" @@ -147,6 +148,7 @@ dependencies { // transitive = true // } compile "co.zsmb:materialdrawer-kt:${MATERIAL_DRAWER_KT}" + compile "com.mikepenz:fastadapter-commons:${FAST_ADAPTER}@aar" compile "nz.bradcampbell:paperparcel:${PAPER_PARCEL}" compile "nz.bradcampbell:paperparcel-kotlin:${PAPER_PARCEL}" diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index b7b6b2d5..1e9fe6d3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -40,7 +40,7 @@ class FrostApp : Application() { refWatcher = LeakCanary.install(this) if (BuildConfig.DEBUG) { Timber.plant(DebugTree()) - LeakCanary.enableDisplayLeakActivity(this) +// LeakCanary.enableDisplayLeakActivity(this) } else { Fabric.with(this, Crashlytics(), Answers()) Timber.plant(CrashReportingTree()) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt index 5cbd08bc..84e5592c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt @@ -1,10 +1,26 @@ package com.pitchedapps.frost +import android.os.Bundle import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.RecyclerView +import butterknife.ButterKnife +import com.mikepenz.fastadapter.FastAdapter +import com.pitchedapps.frost.utils.bindView +import com.pitchedapps.frost.views.AccountItem /** * Created by Allan Wang on 2017-06-04. */ class SelectorActivity : AppCompatActivity() { + val recycler: RecyclerView by bindView(R.id.selector_recycler) + val adapter = FastItemAdapter() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_selector) + ButterKnife.bind(this) + recycler.adapter = adapter + adapter.addal + } } \ No newline at end of file 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 b2f29656..e48814cf 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt @@ -36,8 +36,11 @@ data class CookieModel(@PrimaryKey var id: Long = Prefs.userIdDefault, var name: fun loadFbCookie(id: Long): CookieModel? = (select from CookieModel::class where (CookieModel_Table.id eq id)).querySingle() fun loadFbCookie(name: String): CookieModel? = (select from CookieModel::class where (CookieModel_Table.name eq name)).querySingle() +/** + * Loads cookies sorted by name + */ fun loadFbCookiesAsync(callback: (cookies: List) -> Unit) { - (select from CookieModel::class).async().queryListResultCallback { _, tResult -> callback.invoke(tResult) }.execute() + (select from CookieModel::class).orderBy(CookieModel_Table.name, true).async().queryListResultCallback { _, tResult -> callback.invoke(tResult) }.execute() } fun saveFbCookie(cookie: CookieModel, callback: (() -> Unit)? = null) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt new file mode 100644 index 00000000..9d6099c6 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt @@ -0,0 +1,71 @@ +package com.pitchedapps.frost.views + +import android.graphics.drawable.Drawable +import android.support.v7.widget.AppCompatTextView +import android.support.v7.widget.RecyclerView +import android.view.View +import android.widget.ImageView +import butterknife.ButterKnife +import com.bumptech.glide.Glide +import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.engine.GlideException +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import com.mikepenz.fastadapter.items.AbstractItem +import com.pitchedapps.frost.R +import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL +import com.pitchedapps.frost.utils.bindView + +/** + * Created by Allan Wang on 2017-06-05. + */ +class AccountItem(val id: Long, val name: String) : AbstractItem() { + constructor() : this(-1L, "") + + override fun getType(): Int = R.id.item_account + + override fun getViewHolder(v: View) = ViewHolder(v) + + override fun getLayoutRes(): Int = R.layout.view_account + + override fun bindView(viewHolder: ViewHolder, payloads: List) { + super.bindView(viewHolder, payloads) + with(viewHolder) { + text.visibility = View.INVISIBLE + if (id != -1L) { + text.text = name + Glide.with(itemView).load(PROFILE_PICTURE_URL(id)).listener(object : RequestListener { + override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + text.fadeIn() + return false + } + + override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { + text.fadeIn() + return false + } + }).into(image) + } else { + text.text = itemView.context.getString(R.string.add_account) + //todo add plus image + } + } + } + + override fun unbindView(holder: ViewHolder) { + super.unbindView(holder) + with(holder) { + text.text = null + image.setImageDrawable(null) + } + } + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val image: ImageView by bindView(R.id.account_image) + val text: AppCompatTextView by bindView(R.id.account_text) + + init { + ButterKnife.bind(v) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_selector.xml b/app/src/main/res/layout/activity_selector.xml new file mode 100644 index 00000000..f238d2ff --- /dev/null +++ b/app/src/main/res/layout/activity_selector.xml @@ -0,0 +1,47 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_account.xml b/app/src/main/res/layout/view_account.xml new file mode 100644 index 00000000..676b46d6 --- /dev/null +++ b/app/src/main/res/layout/view_account.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml new file mode 100644 index 00000000..8df89eb6 --- /dev/null +++ b/app/src/main/res/values/ids.xml @@ -0,0 +1,4 @@ + + + + \ 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 f99bd0ce..7287c4c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,4 +25,6 @@ Getting everything ready… Welcome %s Login + Select Facebook Account + Add Account -- cgit v1.2.3