This commit is contained in:
Amine 2017-11-12 17:05:36 +01:00
parent 9e6602f114
commit f833d73fab
16 changed files with 346 additions and 452 deletions

View File

@ -2,6 +2,8 @@
- Hiding FABs on scroll. - Hiding FABs on scroll.
- Closing #109 (code cleaning)
**1.5.4.10** **1.5.4.10**
- Displaying a loader when "reading more" in the article viewer. - Displaying a loader when "reading more" in the article viewer.

View File

@ -31,6 +31,8 @@ apply plugin: 'io.fabric'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories { repositories {
maven { maven {
url 'https://maven.fabric.io/public' url 'https://maven.fabric.io/public'

View File

@ -5,11 +5,9 @@ import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.constraint.ConstraintLayout import android.support.constraint.ConstraintLayout
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.EditText import android.widget.EditText
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.Spinner import android.widget.Spinner
@ -21,6 +19,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.Config
import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid
import com.ftinc.scoop.Scoop import com.ftinc.scoop.Scoop
import kotlinx.android.synthetic.main.activity_add_source.*
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
@ -34,31 +33,29 @@ class AddSourceActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
Scoop.getInstance().apply(this) Scoop.getInstance().apply(this)
setContentView(R.layout.activity_add_source) setContentView(R.layout.activity_add_source)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
val mProgress: ProgressBar = findViewById(R.id.progress)
val mForm: ConstraintLayout = findViewById(R.id.formContainer)
val mNameInput: EditText = findViewById(R.id.nameInput)
val mSourceUri: EditText = findViewById(R.id.sourceUri)
val mTags: EditText = findViewById(R.id.tags)
val mSpoutsSpinner: Spinner = findViewById(R.id.spoutsSpinner)
val mSaveBtn: Button = findViewById(R.id.saveBtn)
var api: SelfossApi? = null var api: SelfossApi? = null
try { try {
val prefs = PreferenceManager.getDefaultSharedPreferences(this) val prefs = PreferenceManager.getDefaultSharedPreferences(this)
api = SelfossApi(this, this@AddSourceActivity, prefs.getBoolean("isSelfSignedCert", false), prefs.getBoolean("should_log_everything", false)) api = SelfossApi(
this,
this@AddSourceActivity,
prefs.getBoolean("isSelfSignedCert", false),
prefs.getBoolean("should_log_everything", false)
)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
mustLoginToAddSource() mustLoginToAddSource()
} }
maybeGetDetailsFromIntentSharing(intent, mSourceUri, mNameInput) maybeGetDetailsFromIntentSharing(intent, sourceUri, nameInput)
mSaveBtn.setOnClickListener { saveBtn.setOnClickListener {
handleSaveSource(mTags, mNameInput.text.toString(), mSourceUri.text.toString(), api!!) handleSaveSource(tags, nameInput.text.toString(), sourceUri.text.toString(), api!!)
} }
val config = Config(this) val config = Config(this)
@ -66,13 +63,13 @@ class AddSourceActivity : AppCompatActivity() {
if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) { if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) {
mustLoginToAddSource() mustLoginToAddSource()
} else { } else {
handleSpoutsSpinner(mSpoutsSpinner, api, mProgress, mForm) handleSpoutsSpinner(spoutsSpinner, api, progress, formContainer)
} }
} }
private fun handleSpoutsSpinner(mSpoutsSpinner: Spinner, api: SelfossApi?, mProgress: ProgressBar, mForm: ConstraintLayout) { private fun handleSpoutsSpinner(spoutsSpinner: Spinner, api: SelfossApi?, mProgress: ProgressBar, formContainer: ConstraintLayout) {
val spoutsKV = HashMap<String, String>() val spoutsKV = HashMap<String, String>()
mSpoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { spoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(adapterView: AdapterView<*>, view: View, i: Int, l: Long) { override fun onItemSelected(adapterView: AdapterView<*>, view: View, i: Int, l: Long) {
val spoutName = (view as TextView).text.toString() val spoutName = (view as TextView).text.toString()
mSpoutsValue = spoutsKV[spoutName] mSpoutsValue = spoutsKV[spoutName]
@ -95,7 +92,7 @@ class AddSourceActivity : AppCompatActivity() {
} }
mProgress.visibility = View.GONE mProgress.visibility = View.GONE
mForm.visibility = View.VISIBLE formContainer.visibility = View.VISIBLE
val spinnerArrayAdapter = val spinnerArrayAdapter =
ArrayAdapter( ArrayAdapter(
@ -103,7 +100,7 @@ class AddSourceActivity : AppCompatActivity() {
android.R.layout.simple_spinner_item, android.R.layout.simple_spinner_item,
itemsStrings) itemsStrings)
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
mSpoutsSpinner.adapter = spinnerArrayAdapter spoutsSpinner.adapter = spinnerArrayAdapter
} else { } else {
handleProblemWithSpouts() handleProblemWithSpouts()
@ -121,10 +118,10 @@ class AddSourceActivity : AppCompatActivity() {
}) })
} }
private fun maybeGetDetailsFromIntentSharing(intent: Intent, mSourceUri: EditText, mNameInput: EditText) { private fun maybeGetDetailsFromIntentSharing(intent: Intent, sourceUri: EditText, nameInput: EditText) {
if (Intent.ACTION_SEND == intent.action && "text/plain" == intent.type) { if (Intent.ACTION_SEND == intent.action && "text/plain" == intent.type) {
mSourceUri.setText(intent.getStringExtra(Intent.EXTRA_TEXT)) sourceUri.setText(intent.getStringExtra(Intent.EXTRA_TEXT))
mNameInput.setText(intent.getStringExtra(Intent.EXTRA_TITLE)) nameInput.setText(intent.getStringExtra(Intent.EXTRA_TITLE))
} }
} }
@ -135,7 +132,7 @@ class AddSourceActivity : AppCompatActivity() {
finish() finish()
} }
private fun handleSaveSource(mTags: EditText, title: String, url: String, api: SelfossApi) { private fun handleSaveSource(tags: EditText, title: String, url: String, api: SelfossApi) {
val sourceDetailsAvailable = title.isEmpty() || url.isEmpty() || mSpoutsValue == null || mSpoutsValue!!.isEmpty() val sourceDetailsAvailable = title.isEmpty() || url.isEmpty() || mSpoutsValue == null || mSpoutsValue!!.isEmpty()
@ -146,7 +143,7 @@ class AddSourceActivity : AppCompatActivity() {
title, title,
url, url,
mSpoutsValue!!, mSpoutsValue!!,
mTags.text.toString(), tags.text.toString(),
"" ""
).enqueue(object : Callback<SuccessResponse> { ).enqueue(object : Callback<SuccessResponse> {
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) { override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {

View File

@ -9,20 +9,16 @@ import android.graphics.drawable.GradientDrawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.design.widget.CoordinatorLayout
import android.support.v4.view.MenuItemCompat import android.support.v4.view.MenuItemCompat
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.support.v7.widget.SearchView import android.support.v7.widget.SearchView
import android.support.v7.widget.StaggeredGridLayoutManager import android.support.v7.widget.StaggeredGridLayoutManager
import android.support.v7.widget.Toolbar
import android.support.v7.widget.helper.ItemTouchHelper import android.support.v7.widget.helper.ItemTouchHelper
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import apps.amine.bou.readerforselfoss.adapters.ItemCardAdapter import apps.amine.bou.readerforselfoss.adapters.ItemCardAdapter
import apps.amine.bou.readerforselfoss.adapters.ItemListAdapter import apps.amine.bou.readerforselfoss.adapters.ItemListAdapter
@ -56,7 +52,6 @@ import com.crashlytics.android.Crashlytics
import com.crashlytics.android.answers.Answers import com.crashlytics.android.answers.Answers
import com.crashlytics.android.answers.InviteEvent import com.crashlytics.android.answers.InviteEvent
import com.ftinc.scoop.Scoop import com.ftinc.scoop.Scoop
import com.github.stkent.amplify.prompt.DefaultLayoutPromptView
import com.github.stkent.amplify.tracking.Amplify import com.github.stkent.amplify.tracking.Amplify
import com.google.android.gms.appinvite.AppInviteInvitation import com.google.android.gms.appinvite.AppInviteInvitation
import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.ConnectionResult
@ -74,6 +69,8 @@ import com.mikepenz.materialdrawer.model.SecondaryDrawerItem
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import kotlinx.android.synthetic.main.activity_home.*
class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
@ -105,15 +102,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var displayAccountHeader: Boolean = false private var displayAccountHeader: Boolean = false
private var infiniteScroll: Boolean = false private var infiniteScroll: Boolean = false
private lateinit var emptyText: TextView
private lateinit var recyclerView: RecyclerView
private lateinit var bottomBar: BottomNavigationBar
private lateinit var coordinatorLayout: CoordinatorLayout
private lateinit var swipeRefreshLayout: SwipeRefreshLayout
private lateinit var tabNewBadge: TextBadgeItem private lateinit var tabNewBadge: TextBadgeItem
private lateinit var tabArchiveBadge: TextBadgeItem private lateinit var tabArchiveBadge: TextBadgeItem
private lateinit var tabStarredBadge: TextBadgeItem private lateinit var tabStarredBadge: TextBadgeItem
private lateinit var toolBar: Toolbar
private lateinit var drawer: Drawer private lateinit var drawer: Drawer
private lateinit var api: SelfossApi private lateinit var api: SelfossApi
private lateinit var customTabActivityHelper: CustomTabActivityHelper private lateinit var customTabActivityHelper: CustomTabActivityHelper
@ -140,16 +131,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
Scoop.getInstance().apply(this) Scoop.getInstance().apply(this)
setContentView(R.layout.activity_home) setContentView(R.layout.activity_home)
toolBar = findViewById(R.id.toolbar)
setSupportActionBar(toolBar) setSupportActionBar(toolBar)
if (savedInstanceState == null) { if (savedInstanceState == null) {
val promptView: DefaultLayoutPromptView = findViewById(R.id.prompt_view)
Amplify.getSharedInstance().promptIfReady(promptView) Amplify.getSharedInstance().promptIfReady(promptView)
} }
@ -167,17 +153,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
appColors = AppColors(this@HomeActivity) appColors = AppColors(this@HomeActivity)
handleBottomBar() handleBottomBar()
handleDrawer() handleDrawer()
coordinatorLayout = findViewById(R.id.coordLayout)
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout)
recyclerView = findViewById(R.id.my_recycler_view)
emptyText = findViewById(R.id.emptyText)
reloadLayoutManager() reloadLayoutManager()
handleSwipeRefreshLayout() handleSwipeRefreshLayout()
} }
@ -243,8 +221,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private fun handleBottomBar() { private fun handleBottomBar() {
bottomBar = findViewById(R.id.bottomBar)
tabNewBadge = TextBadgeItem() tabNewBadge = TextBadgeItem()
.setText("") .setText("")
.setHideOnSelect(false).hide(false) .setHideOnSelect(false).hide(false)

View File

@ -6,7 +6,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.support.design.widget.TextInputLayout
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar import android.support.v7.widget.Toolbar
@ -15,9 +14,6 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.widget.Button
import android.widget.EditText
import android.widget.Switch
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
@ -32,6 +28,8 @@ import com.mikepenz.aboutlibraries.LibsBuilder
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import kotlinx.android.synthetic.main.activity_login.*
class LoginActivity : AppCompatActivity() { class LoginActivity : AppCompatActivity() {
@ -43,14 +41,7 @@ class LoginActivity : AppCompatActivity() {
private lateinit var settings: SharedPreferences private lateinit var settings: SharedPreferences
private lateinit var editor: SharedPreferences.Editor private lateinit var editor: SharedPreferences.Editor
private lateinit var mFirebaseAnalytics: FirebaseAnalytics private lateinit var firebaseAnalytics: FirebaseAnalytics
private lateinit var mUrlView: EditText
private lateinit var mLoginView: TextView
private lateinit var mHTTPLoginView: TextView
private lateinit var mProgressView: View
private lateinit var mPasswordView: EditText
private lateinit var mHTTPPasswordView: EditText
private lateinit var mLoginFormView: View
private lateinit var userIdentifier: String private lateinit var userIdentifier: String
private var logErrors: Boolean = false private var logErrors: Boolean = false
@ -61,7 +52,6 @@ class LoginActivity : AppCompatActivity() {
Scoop.getInstance().apply(this) Scoop.getInstance().apply(this)
setContentView(R.layout.activity_login) setContentView(R.layout.activity_login)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
handleBaseUrlFail() handleBaseUrlFail()
@ -69,7 +59,7 @@ class LoginActivity : AppCompatActivity() {
settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
userIdentifier = settings.getString("unique_id", "") userIdentifier = settings.getString("unique_id", "")
logErrors = settings.getBoolean("loging_debug", false) logErrors = settings.getBoolean("login_debug", false)
editor = settings.edit() editor = settings.edit()
@ -77,60 +67,44 @@ class LoginActivity : AppCompatActivity() {
goToMain() goToMain()
} }
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this) firebaseAnalytics = FirebaseAnalytics.getInstance(this)
mUrlView = findViewById(R.id.url)
mLoginView = findViewById(R.id.login)
mHTTPLoginView = findViewById(R.id.httpLogin)
mPasswordView = findViewById(R.id.password)
mHTTPPasswordView = findViewById(R.id.httpPassword)
mLoginFormView = findViewById(R.id.login_form)
mProgressView = findViewById(R.id.login_progress)
handleActions() handleActions()
} }
private fun handleActions() { private fun handleActions() {
val mSwitch: Switch = findViewById(R.id.withLogin)
val mHTTPSwitch: Switch = findViewById(R.id.withHttpLogin)
val mLoginLayout: TextInputLayout = findViewById(R.id.loginLayout)
val mHTTPLoginLayout: TextInputLayout = findViewById(R.id.httpLoginInput)
val mPasswordLayout: TextInputLayout = findViewById(R.id.passwordLayout)
val mHTTPPasswordLayout: TextInputLayout = findViewById(R.id.httpPasswordInput)
val mEmailSignInButton: Button = findViewById(R.id.email_sign_in_button)
val selfHostedSwitch: Switch = findViewById(R.id.withSelfhostedCert)
val warningTextview: TextView = findViewById(R.id.warningText)
selfHostedSwitch.setOnCheckedChangeListener { _, b -> withSelfhostedCert.setOnCheckedChangeListener { _, b ->
isWithSelfSignedCert = !isWithSelfSignedCert isWithSelfSignedCert = !isWithSelfSignedCert
val visi: Int = if (b) View.VISIBLE else View.GONE val visi: Int = if (b) View.VISIBLE else View.GONE
warningTextview.visibility = visi warningText.visibility = visi
} }
mPasswordView.setOnEditorActionListener(TextView.OnEditorActionListener { _, id, _ -> passwordView.setOnEditorActionListener(TextView.OnEditorActionListener { _, id, _ ->
if (id == R.id.login || id == EditorInfo.IME_NULL) { if (id == R.id.loginView || id == EditorInfo.IME_NULL) {
attemptLogin() attemptLogin()
return@OnEditorActionListener true return@OnEditorActionListener true
} }
false false
}) })
mEmailSignInButton.setOnClickListener { attemptLogin() } signInButton.setOnClickListener { attemptLogin() }
mSwitch.setOnCheckedChangeListener { _, b -> withLogin.setOnCheckedChangeListener { _, b ->
isWithLogin = !isWithLogin isWithLogin = !isWithLogin
val visi: Int = if (b) View.VISIBLE else View.GONE val visi: Int = if (b) View.VISIBLE else View.GONE
mLoginLayout.visibility = visi loginLayout.visibility = visi
mPasswordLayout.visibility = visi passwordLayout.visibility = visi
} }
mHTTPSwitch.setOnCheckedChangeListener { _, b -> withHttpLogin.setOnCheckedChangeListener { _, b ->
isWithHTTPLogin = !isWithHTTPLogin isWithHTTPLogin = !isWithHTTPLogin
val visi: Int = if (b) View.VISIBLE else View.GONE val visi: Int = if (b) View.VISIBLE else View.GONE
mHTTPLoginLayout.visibility = visi httpLoginInput.visibility = visi
mHTTPPasswordLayout.visibility = visi httpPasswordInput.visibility = visi
} }
} }
@ -156,25 +130,25 @@ class LoginActivity : AppCompatActivity() {
private fun attemptLogin() { private fun attemptLogin() {
// Reset errors. // Reset errors.
mUrlView.error = null urlView.error = null
mLoginView.error = null loginView.error = null
mHTTPLoginView.error = null httpLoginView.error = null
mPasswordView.error = null passwordView.error = null
mHTTPPasswordView.error = null httpPasswordView.error = null
// Store values at the time of the login attempt. // Store values at the time of the login attempt.
val url = mUrlView.text.toString() val url = urlView.text.toString()
val login = mLoginView.text.toString() val login = loginView.text.toString()
val httpLogin = mHTTPLoginView.text.toString() val httpLogin = httpLoginView.text.toString()
val password = mPasswordView.text.toString() val password = passwordView.text.toString()
val httpPassword = mHTTPPasswordView.text.toString() val httpPassword = httpPasswordView.text.toString()
var cancel = false var cancel = false
var focusView: View? = null var focusView: View? = null
if (!url.isBaseUrlValid()) { if (!url.isBaseUrlValid()) {
mUrlView.error = getString(R.string.login_url_problem) urlView.error = getString(R.string.login_url_problem)
focusView = mUrlView focusView = urlView
cancel = true cancel = true
inValidCount++ inValidCount++
if (inValidCount == 3) { if (inValidCount == 3) {
@ -192,14 +166,14 @@ class LoginActivity : AppCompatActivity() {
if (isWithLogin || isWithHTTPLogin) { if (isWithLogin || isWithHTTPLogin) {
if (TextUtils.isEmpty(password)) { if (TextUtils.isEmpty(password)) {
mPasswordView.error = getString(R.string.error_invalid_password) passwordView.error = getString(R.string.error_invalid_password)
focusView = mPasswordView focusView = passwordView
cancel = true cancel = true
} }
if (TextUtils.isEmpty(login)) { if (TextUtils.isEmpty(login)) {
mLoginView.error = getString(R.string.error_field_required) loginView.error = getString(R.string.error_field_required)
focusView = mLoginView focusView = loginView
cancel = true cancel = true
} }
} }
@ -226,11 +200,11 @@ class LoginActivity : AppCompatActivity() {
editor.remove("password") editor.remove("password")
editor.remove("httpPassword") editor.remove("httpPassword")
editor.apply() editor.apply()
mUrlView.error = getString(R.string.wrong_infos) urlView.error = getString(R.string.wrong_infos)
mLoginView.error = getString(R.string.wrong_infos) loginView.error = getString(R.string.wrong_infos)
mPasswordView.error = getString(R.string.wrong_infos) passwordView.error = getString(R.string.wrong_infos)
mHTTPLoginView.error = getString(R.string.wrong_infos) httpLoginView.error = getString(R.string.wrong_infos)
mHTTPPasswordView.error = getString(R.string.wrong_infos) httpPasswordView.error = getString(R.string.wrong_infos)
if (logErrors) { if (logErrors) {
Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.setUserIdentifier(userIdentifier)
Crashlytics.log(100, "LOGIN_DEBUG_ERRROR", t.message) Crashlytics.log(100, "LOGIN_DEBUG_ERRROR", t.message)
@ -242,7 +216,7 @@ class LoginActivity : AppCompatActivity() {
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) { override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {
if (response.body() != null && response.body()!!.isSuccess) { if (response.body() != null && response.body()!!.isSuccess) {
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle()) firebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle())
goToMain() goToMain()
} else { } else {
preferenceError(Exception("No response body...")) preferenceError(Exception("No response body..."))
@ -260,34 +234,34 @@ class LoginActivity : AppCompatActivity() {
private fun showProgress(show: Boolean) { private fun showProgress(show: Boolean) {
val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime) val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime)
mLoginFormView.visibility = if (show) View.GONE else View.VISIBLE loginForm.visibility = if (show) View.GONE else View.VISIBLE
mLoginFormView loginForm
.animate() .animate()
.setDuration(shortAnimTime.toLong()) .setDuration(shortAnimTime.toLong())
.alpha( .alpha(
if (show) 0F else 1F if (show) 0F else 1F
).setListener(object : AnimatorListenerAdapter() { ).setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
mLoginFormView.visibility = if (show) View.GONE else View.VISIBLE loginForm.visibility = if (show) View.GONE else View.VISIBLE
} }
}) })
mProgressView.visibility = if (show) View.VISIBLE else View.GONE loginProgress.visibility = if (show) View.VISIBLE else View.GONE
mProgressView loginProgress
.animate() .animate()
.setDuration(shortAnimTime.toLong()) .setDuration(shortAnimTime.toLong())
.alpha( .alpha(
if (show) 1F else 0F if (show) 1F else 0F
).setListener(object : AnimatorListenerAdapter() { ).setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
mProgressView.visibility = if (show) View.VISIBLE else View.GONE loginProgress.visibility = if (show) View.VISIBLE else View.GONE
} }
}) })
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.login_menu, menu) menuInflater.inflate(R.menu.login_menu, menu)
menu.findItem(R.id.loging_debug).isChecked = logErrors menu.findItem(R.id.login_debug).isChecked = logErrors
return true return true
} }
@ -301,11 +275,11 @@ class LoginActivity : AppCompatActivity() {
.start(this) .start(this)
return true return true
} }
R.id.loging_debug -> { R.id.login_debug -> {
val newState = !item.isChecked val newState = !item.isChecked
item.isChecked = newState item.isChecked = newState
logErrors = newState logErrors = newState
editor.putBoolean("loging_debug", newState) editor.putBoolean("login_debug", newState)
editor.apply() editor.apply()
return true return true
} }

View File

@ -10,10 +10,6 @@ import android.support.v7.app.AppCompatActivity
import android.text.Html import android.text.Html
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import apps.amine.bou.readerforselfoss.api.mercury.MercuryApi import apps.amine.bou.readerforselfoss.api.mercury.MercuryApi
import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent import apps.amine.bou.readerforselfoss.api.mercury.ParsedContent
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
@ -30,16 +26,11 @@ import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import kotlinx.android.synthetic.main.activity_reader.*
class ReaderActivity : AppCompatActivity() { class ReaderActivity : AppCompatActivity() {
private lateinit var mCustomTabActivityHelper: CustomTabActivityHelper private lateinit var mCustomTabActivityHelper: CustomTabActivityHelper
private lateinit var image: ImageView
private lateinit var source: TextView
private lateinit var title: TextView
private lateinit var content: TextView
private lateinit var progress: FrameLayout
private lateinit var nestedScrollView: NestedScrollView
//private lateinit var content: HtmlTextView //private lateinit var content: HtmlTextView
private lateinit var url: String private lateinit var url: String
private lateinit var contentText: String private lateinit var contentText: String
@ -59,12 +50,6 @@ class ReaderActivity : AppCompatActivity() {
Scoop.getInstance().apply(this) Scoop.getInstance().apply(this)
setContentView(R.layout.activity_reader) setContentView(R.layout.activity_reader)
image = findViewById(R.id.imageView)
source = findViewById(R.id.source)
title = findViewById(R.id.title)
content = findViewById(R.id.content)
progress = findViewById(R.id.progressBar)
nestedScrollView = findViewById(R.id.nestedScrollView)
url = intent.getStringExtra("url") url = intent.getStringExtra("url")
contentText = intent.getStringExtra("content") contentText = intent.getStringExtra("content")
contentTitle = intent.getStringExtra("title") contentTitle = intent.getStringExtra("title")
@ -109,19 +94,19 @@ class ReaderActivity : AppCompatActivity() {
getContentFromMercury(customTabsIntent, prefs) getContentFromMercury(customTabsIntent, prefs)
} else { } else {
source.text = contentSource source.text = contentSource
title.text = contentTitle titleView.text = contentTitle
tryToHandleHtml(contentText, customTabsIntent, prefs) tryToHandleHtml(contentText, customTabsIntent, prefs)
if (!contentImage.isEmptyOrNullOrNullString()) { if (!contentImage.isEmptyOrNullOrNullString()) {
image.visibility = View.VISIBLE imageView.visibility = View.VISIBLE
Glide Glide
.with(baseContext) .with(baseContext)
.asBitmap() .asBitmap()
.load(contentImage) .load(contentImage)
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
.into(image) .into(imageView)
} else { } else {
image.visibility = View.GONE imageView.visibility = View.GONE
} }
} }
@ -135,14 +120,14 @@ class ReaderActivity : AppCompatActivity() {
} }
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent, prefs: SharedPreferences) { private fun getContentFromMercury(customTabsIntent: CustomTabsIntent, prefs: SharedPreferences) {
progress.visibility = View.VISIBLE progressBar.visibility = View.VISIBLE
val parser = MercuryApi(BuildConfig.MERCURY_KEY, prefs.getBoolean("should_log_everything", false)) val parser = MercuryApi(BuildConfig.MERCURY_KEY, prefs.getBoolean("should_log_everything", false))
parser.parseUrl(url).enqueue(object : Callback<ParsedContent> { parser.parseUrl(url).enqueue(object : Callback<ParsedContent> {
override fun onResponse(call: Call<ParsedContent>, response: Response<ParsedContent>) { override fun onResponse(call: Call<ParsedContent>, response: Response<ParsedContent>) {
if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) { if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) {
source.text = response.body()!!.domain source.text = response.body()!!.domain
title.text = response.body()!!.title titleView.text = response.body()!!.title
this@ReaderActivity.url = response.body()!!.url this@ReaderActivity.url = response.body()!!.url
if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) { if (response.body()!!.content != null && !response.body()!!.content.isEmpty()) {
@ -150,20 +135,20 @@ class ReaderActivity : AppCompatActivity() {
} }
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) { if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isEmpty()) {
image.visibility = View.VISIBLE imageView.visibility = View.VISIBLE
Glide Glide
.with(baseContext) .with(baseContext)
.asBitmap() .asBitmap()
.load(response.body()!!.lead_image_url) .load(response.body()!!.lead_image_url)
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
.into(image) .into(imageView)
} else { } else {
image.visibility = View.GONE imageView.visibility = View.GONE
} }
nestedScrollView.scrollTo(0, 0) nestedScrollView.scrollTo(0, 0)
progress.visibility = View.GONE progressBar.visibility = View.GONE
} else openInBrowserAfterFailing(customTabsIntent) } else openInBrowserAfterFailing(customTabsIntent)
} }
@ -185,7 +170,7 @@ class ReaderActivity : AppCompatActivity() {
} }
private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) { private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) {
progress.visibility = View.GONE progressBar.visibility = View.GONE
this@ReaderActivity.openItemUrl( this@ReaderActivity.openItemUrl(
url, url,
contentText, contentText,

View File

@ -3,12 +3,8 @@ package apps.amine.bou.readerforselfoss
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.design.widget.FloatingActionButton
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar
import android.view.View
import android.widget.Toast import android.widget.Toast
import apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter import apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
@ -17,17 +13,16 @@ import com.ftinc.scoop.Scoop
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import kotlinx.android.synthetic.main.activity_sources.*
class SourcesActivity : AppCompatActivity() { class SourcesActivity : AppCompatActivity() {
private lateinit var mRecyclerView: RecyclerView
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
Scoop.getInstance().apply(this) Scoop.getInstance().apply(this)
setContentView(R.layout.activity_sources) setContentView(R.layout.activity_sources)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
@ -35,13 +30,11 @@ class SourcesActivity : AppCompatActivity() {
override fun onStop() { override fun onStop() {
super.onStop() super.onStop()
mRecyclerView.clearOnScrollListeners() recyclerView.clearOnScrollListeners()
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
val mFab: FloatingActionButton = findViewById(R.id.fab)
mRecyclerView = findViewById(R.id.activity_sources)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
val prefs = PreferenceManager.getDefaultSharedPreferences(this) val prefs = PreferenceManager.getDefaultSharedPreferences(this)
@ -49,8 +42,8 @@ class SourcesActivity : AppCompatActivity() {
val api = SelfossApi(this, this@SourcesActivity, prefs.getBoolean("isSelfSignedCert", false), prefs.getBoolean("should_log_everything", false)) val api = SelfossApi(this, this@SourcesActivity, prefs.getBoolean("isSelfSignedCert", false), prefs.getBoolean("should_log_everything", false))
var items: ArrayList<Sources> = ArrayList() var items: ArrayList<Sources> = ArrayList()
mRecyclerView.setHasFixedSize(true) recyclerView.setHasFixedSize(true)
mRecyclerView.layoutManager = mLayoutManager recyclerView.layoutManager = mLayoutManager
api.sources.enqueue(object : Callback<List<Sources>> { api.sources.enqueue(object : Callback<List<Sources>> {
override fun onResponse(call: Call<List<Sources>>, response: Response<List<Sources>>) { override fun onResponse(call: Call<List<Sources>>, response: Response<List<Sources>>) {
@ -58,7 +51,7 @@ class SourcesActivity : AppCompatActivity() {
items = response.body() as ArrayList<Sources> items = response.body() as ArrayList<Sources>
} }
val mAdapter = SourcesListAdapter(this@SourcesActivity, items, api) val mAdapter = SourcesListAdapter(this@SourcesActivity, items, api)
mRecyclerView.adapter = mAdapter recyclerView.adapter = mAdapter
mAdapter.notifyDataSetChanged() mAdapter.notifyDataSetChanged()
if (items.isEmpty()) Toast.makeText(this@SourcesActivity, R.string.nothing_here, Toast.LENGTH_SHORT).show() if (items.isEmpty()) Toast.makeText(this@SourcesActivity, R.string.nothing_here, Toast.LENGTH_SHORT).show()
} }
@ -68,7 +61,7 @@ class SourcesActivity : AppCompatActivity() {
} }
}) })
mFab.setOnClickListener { fab.setOnClickListener {
startActivity(Intent(this@SourcesActivity, AddSourceActivity::class.java)) startActivity(Intent(this@SourcesActivity, AddSourceActivity::class.java))
} }
} }

View File

@ -9,8 +9,6 @@ import android.support.v7.widget.RecyclerView
import android.text.Html import android.text.Html
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.ImageView.ScaleType import android.widget.ImageView.ScaleType
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
@ -38,6 +36,7 @@ import com.like.OnLikeListener
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import kotlinx.android.synthetic.main.card_item.view.*
class ItemCardAdapter(private val app: Activity, class ItemCardAdapter(private val app: Activity,
private val items: ArrayList<Item>, private val items: ArrayList<Item>,
@ -61,16 +60,16 @@ class ItemCardAdapter(private val app: Activity,
val itm = items[position] val itm = items[position]
holder.saveBtn.isLiked = itm.starred holder.mView.favButton.isLiked = itm.starred
holder.title.text = Html.fromHtml(itm.title) holder.mView.title.text = Html.fromHtml(itm.title)
holder.sourceTitleAndDate.text = itm.sourceAndDateText() holder.mView.sourceTitleAndDate.text = itm.sourceAndDateText()
if (itm.getThumbnail(c).isEmpty()) { if (itm.getThumbnail(c).isEmpty()) {
Glide.with(c).clear(holder.itemImage) Glide.with(c).clear(holder.mView.itemImage)
holder.itemImage.setImageDrawable(null) holder.mView.itemImage.setImageDrawable(null)
} else { } else {
c.bitmapCenterCrop(itm.getThumbnail(c), holder.itemImage) c.bitmapCenterCrop(itm.getThumbnail(c), holder.mView.itemImage)
} }
if (itm.getIcon(c).isEmpty()) { if (itm.getIcon(c).isEmpty()) {
@ -81,12 +80,12 @@ class ItemCardAdapter(private val app: Activity,
.builder() .builder()
.round() .round()
.build(itm.sourcetitle.toTextDrawableString(), color) .build(itm.sourcetitle.toTextDrawableString(), color)
holder.sourceImage.setImageDrawable(drawable) holder.mView.sourceImage.setImageDrawable(drawable)
} else { } else {
c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage) c.circularBitmapDrawable(itm.getIcon(c), holder.mView.sourceImage)
} }
holder.saveBtn.isLiked = itm.starred holder.mView.favButton.isLiked = itm.starred
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
@ -160,14 +159,6 @@ class ItemCardAdapter(private val app: Activity,
} }
inner class ViewHolder(val mView: CardView) : RecyclerView.ViewHolder(mView) { inner class ViewHolder(val mView: CardView) : RecyclerView.ViewHolder(mView) {
lateinit var saveBtn: LikeButton
lateinit var browserBtn: ImageButton
lateinit var shareBtn: ImageButton
lateinit var itemImage: ImageView
lateinit var sourceImage: ImageView
lateinit var title: TextView
lateinit var sourceTitleAndDate: TextView
init { init {
mView.setCardBackgroundColor(appColors.cardBackground) mView.setCardBackgroundColor(appColors.cardBackground)
handleClickListeners() handleClickListeners()
@ -175,27 +166,20 @@ class ItemCardAdapter(private val app: Activity,
} }
private fun handleClickListeners() { private fun handleClickListeners() {
sourceImage = mView.findViewById(R.id.sourceImage)
itemImage = mView.findViewById(R.id.itemImage)
title = mView.findViewById(R.id.title)
sourceTitleAndDate = mView.findViewById(R.id.sourceTitleAndDate)
saveBtn = mView.findViewById(R.id.favButton)
shareBtn = mView.findViewById(R.id.shareBtn)
browserBtn = mView.findViewById(R.id.browserBtn)
if (!fullHeightCards) { if (!fullHeightCards) {
itemImage.maxHeight = c.resources.getDimension(R.dimen.card_image_max_height).toInt() mView.itemImage.maxHeight = c.resources.getDimension(R.dimen.card_image_max_height).toInt()
itemImage.scaleType = ScaleType.CENTER_CROP mView.itemImage.scaleType = ScaleType.CENTER_CROP
} }
saveBtn.setOnLikeListener(object : OnLikeListener { mView.favButton.setOnLikeListener(object : OnLikeListener {
override fun liked(likeButton: LikeButton) { override fun liked(likeButton: LikeButton) {
val (id) = items[adapterPosition] val (id) = items[adapterPosition]
api.starrItem(id).enqueue(object : Callback<SuccessResponse> { api.starrItem(id).enqueue(object : Callback<SuccessResponse> {
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {} override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {}
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) { override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
saveBtn.isLiked = false mView.favButton.isLiked = false
Toast.makeText(c, R.string.cant_mark_favortie, Toast.LENGTH_SHORT).show() Toast.makeText(c, R.string.cant_mark_favortie, Toast.LENGTH_SHORT).show()
} }
}) })
@ -207,18 +191,18 @@ class ItemCardAdapter(private val app: Activity,
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {} override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {}
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) { override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
saveBtn.isLiked = true mView.favButton.isLiked = true
Toast.makeText(c, R.string.cant_unmark_favortie, Toast.LENGTH_SHORT).show() Toast.makeText(c, R.string.cant_unmark_favortie, Toast.LENGTH_SHORT).show()
} }
}) })
} }
}) })
shareBtn.setOnClickListener { mView.shareBtn.setOnClickListener {
c.shareLink(items[adapterPosition].getLinkDecoded()) c.shareLink(items[adapterPosition].getLinkDecoded())
} }
browserBtn.setOnClickListener { mView.browserBtn.setOnClickListener {
c.openInBrowserAsNewTask(items[adapterPosition]) c.openInBrowserAsNewTask(items[adapterPosition])
} }
} }

View File

@ -12,9 +12,6 @@ import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import apps.amine.bou.readerforselfoss.R import apps.amine.bou.readerforselfoss.R
@ -40,7 +37,7 @@ import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlinx.android.synthetic.main.list_item.view.*
class ItemListAdapter(private val app: Activity, class ItemListAdapter(private val app: Activity,
private val items: ArrayList<Item>, private val items: ArrayList<Item>,
@ -64,10 +61,10 @@ class ItemListAdapter(private val app: Activity,
val itm = items[position] val itm = items[position]
holder.saveBtn.isLiked = itm.starred holder.mView.favButton.isLiked = itm.starred
holder.title.text = Html.fromHtml(itm.title) holder.mView.title.text = Html.fromHtml(itm.title)
holder.sourceTitleAndDate.text = itm.sourceAndDateText() holder.mView.sourceTitleAndDate.text = itm.sourceAndDateText()
if (itm.getThumbnail(c).isEmpty()) { if (itm.getThumbnail(c).isEmpty()) {
val sizeInInt = 46 val sizeInInt = 46
@ -80,11 +77,11 @@ class ItemListAdapter(private val app: Activity,
TypedValue.COMPLEX_UNIT_DIP, marginInInt.toFloat(), c.resources TypedValue.COMPLEX_UNIT_DIP, marginInInt.toFloat(), c.resources
.displayMetrics).toInt() .displayMetrics).toInt()
val params = holder.sourceImage.layoutParams as ViewGroup.MarginLayoutParams val params = holder.mView.itemImage.layoutParams as ViewGroup.MarginLayoutParams
params.height = sizeInDp params.height = sizeInDp
params.width = sizeInDp params.width = sizeInDp
params.setMargins(marginInDp, 0, 0, 0) params.setMargins(marginInDp, 0, 0, 0)
holder.sourceImage.layoutParams = params holder.mView.itemImage.layoutParams = params
if (itm.getIcon(c).isEmpty()) { if (itm.getIcon(c).isEmpty()) {
val color = generator.getColor(itm.sourcetitle) val color = generator.getColor(itm.sourcetitle)
@ -96,17 +93,17 @@ class ItemListAdapter(private val app: Activity,
val builder = TextDrawable.builder().round() val builder = TextDrawable.builder().round()
val drawable = builder.build(textDrawable.toString(), color) val drawable = builder.build(textDrawable.toString(), color)
holder.sourceImage.setImageDrawable(drawable) holder.mView.itemImage.setImageDrawable(drawable)
} else { } else {
c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage) c.circularBitmapDrawable(itm.getIcon(c), holder.mView.itemImage)
} }
} else { } else {
c.bitmapCenterCrop(itm.getThumbnail(c), holder.sourceImage) c.bitmapCenterCrop(itm.getThumbnail(c), holder.mView.itemImage)
} }
if (bars[position]) holder.actionBar.visibility = View.VISIBLE else holder.actionBar.visibility = View.GONE if (bars[position]) holder.mView.actionBar.visibility = View.VISIBLE else holder.mView.actionBar.visibility = View.GONE
holder.saveBtn.isLiked = itm.starred holder.mView.favButton.isLiked = itm.starred
} }
override fun getItemCount(): Int = items.size override fun getItemCount(): Int = items.size
@ -179,13 +176,6 @@ class ItemListAdapter(private val app: Activity,
} }
inner class ViewHolder(val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) { inner class ViewHolder(val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) {
lateinit var saveBtn: LikeButton
lateinit var browserBtn: ImageButton
lateinit var shareBtn: ImageButton
lateinit var actionBar: RelativeLayout
lateinit var sourceImage: ImageView
lateinit var title: TextView
lateinit var sourceTitleAndDate: TextView
init { init {
handleClickListeners() handleClickListeners()
@ -193,23 +183,15 @@ class ItemListAdapter(private val app: Activity,
} }
private fun handleClickListeners() { private fun handleClickListeners() {
actionBar = mView.findViewById(R.id.actionBar)
sourceImage = mView.findViewById(R.id.itemImage)
title = mView.findViewById(R.id.title)
sourceTitleAndDate = mView.findViewById(R.id.sourceTitleAndDate)
saveBtn = mView.findViewById(R.id.favButton)
shareBtn = mView.findViewById(R.id.shareBtn)
browserBtn = mView.findViewById(R.id.browserBtn)
mView.favButton.setOnLikeListener(object : OnLikeListener {
saveBtn.setOnLikeListener(object : OnLikeListener {
override fun liked(likeButton: LikeButton) { override fun liked(likeButton: LikeButton) {
val (id) = items[adapterPosition] val (id) = items[adapterPosition]
api.starrItem(id).enqueue(object : Callback<SuccessResponse> { api.starrItem(id).enqueue(object : Callback<SuccessResponse> {
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {} override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {}
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) { override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
saveBtn.isLiked = false mView.favButton.isLiked = false
Toast.makeText(c, R.string.cant_mark_favortie, Toast.LENGTH_SHORT).show() Toast.makeText(c, R.string.cant_mark_favortie, Toast.LENGTH_SHORT).show()
} }
}) })
@ -221,18 +203,18 @@ class ItemListAdapter(private val app: Activity,
override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {} override fun onResponse(call: Call<SuccessResponse>, response: Response<SuccessResponse>) {}
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) { override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
saveBtn.isLiked = true mView.favButton.isLiked = true
Toast.makeText(c, R.string.cant_unmark_favortie, Toast.LENGTH_SHORT).show() Toast.makeText(c, R.string.cant_unmark_favortie, Toast.LENGTH_SHORT).show()
} }
}) })
} }
}) })
shareBtn.setOnClickListener { mView.shareBtn.setOnClickListener {
c.shareLink(items[adapterPosition].getLinkDecoded()) c.shareLink(items[adapterPosition].getLinkDecoded())
} }
browserBtn.setOnClickListener { mView.browserBtn.setOnClickListener {
c.openInBrowserAsNewTask(items[adapterPosition]) c.openInBrowserAsNewTask(items[adapterPosition])
} }
@ -279,7 +261,11 @@ class ItemListAdapter(private val app: Activity,
private fun actionBarShowHide() { private fun actionBarShowHide() {
bars[adapterPosition] = true bars[adapterPosition] = true
if (actionBar.visibility == View.GONE) actionBar.visibility = View.VISIBLE else actionBar.visibility = View.GONE if (mView.actionBar.visibility == View.GONE) {
mView.actionBar.visibility = View.VISIBLE
} else {
mView.actionBar.visibility = View.GONE
}
} }
} }
} }

View File

@ -21,6 +21,7 @@ import com.amulyakhare.textdrawable.util.ColorGenerator
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import kotlinx.android.synthetic.main.source_list_item.view.*
class SourcesListAdapter(private val app: Activity, class SourcesListAdapter(private val app: Activity,
@ -45,9 +46,9 @@ class SourcesListAdapter(private val app: Activity,
.builder() .builder()
.round() .round()
.build(itm.title.toTextDrawableString(), color) .build(itm.title.toTextDrawableString(), color)
holder.sourceImage.setImageDrawable(drawable) holder.itemImage.setImageDrawable(drawable)
} else { } else {
c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage) c.circularBitmapDrawable(itm.getIcon(c), holder.itemImage)
} }
holder.sourceTitle.text = itm.title holder.sourceTitle.text = itm.title
@ -58,17 +59,14 @@ class SourcesListAdapter(private val app: Activity,
} }
inner class ViewHolder(internal val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) { inner class ViewHolder(internal val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) {
lateinit var sourceImage: ImageView lateinit var itemImage: ImageView
lateinit var sourceTitle: TextView lateinit var sourceTitle: TextView
init { init {
handleClickListeners() handleClickListeners()
} }
private fun handleClickListeners() { private fun handleClickListeners() {
sourceImage = mView.findViewById(R.id.itemImage)
sourceTitle = mView.findViewById(R.id.sourceTitle)
val deleteBtn: Button = mView.findViewById(R.id.deleteBtn) val deleteBtn: Button = mView.findViewById(R.id.deleteBtn)

View File

@ -9,7 +9,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<com.github.stkent.amplify.prompt.DefaultLayoutPromptView <com.github.stkent.amplify.prompt.DefaultLayoutPromptView
android:id="@+id/prompt_view" android:id="@+id/promptView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:prompt_view_user_opinion_question_title="@string/rating_prompt_title" app:prompt_view_user_opinion_question_title="@string/rating_prompt_title"
@ -34,7 +34,7 @@
android:id="@+id/coordLayout" android:id="@+id/coordLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_below="@id/prompt_view"> android:layout_below="@id/promptView">
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.CoordinatorLayout
android:id="@+id/intern_coordLayout" android:id="@+id/intern_coordLayout"
@ -51,7 +51,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolBar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
app:theme="@style/ToolBarStyle" app:theme="@style/ToolBarStyle"
@ -89,7 +89,7 @@
android:background="@color/transparent" android:background="@color/transparent"
android:visibility="gone" /> android:visibility="gone" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/transparent" android:background="@color/transparent"

View File

@ -28,7 +28,7 @@
android:paddingTop="@dimen/activity_vertical_margin"> android:paddingTop="@dimen/activity_vertical_margin">
<!-- Login progress --> <!-- Login progress -->
<ProgressBar <ProgressBar
android:id="@+id/login_progress" android:id="@+id/loginProgress"
style="?android:attr/progressBarStyleLarge" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -36,7 +36,7 @@
android:visibility="gone"/> android:visibility="gone"/>
<ScrollView <ScrollView
android:id="@+id/login_form" android:id="@+id/loginForm"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -52,14 +52,13 @@
> >
<EditText <EditText
android:id="@+id/url" android:id="@+id/urlView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/prompt_url" android:hint="@string/prompt_url"
android:imeOptions="actionUnspecified" android:imeOptions="actionUnspecified"
android:inputType="textUri" android:inputType="textUri"
android:maxLines="1" android:maxLines="1" />
/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@ -77,13 +76,12 @@
android:visibility="gone"> android:visibility="gone">
<AutoCompleteTextView <AutoCompleteTextView
android:id="@+id/login" android:id="@+id/loginView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/prompt_login" android:hint="@string/prompt_login"
android:inputType="text" android:inputType="text"
android:maxLines="1" android:maxLines="1" />
/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@ -94,13 +92,12 @@
android:visibility="gone"> android:visibility="gone">
<EditText <EditText
android:id="@+id/password" android:id="@+id/passwordView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/prompt_password" android:hint="@string/prompt_password"
android:inputType="textPassword" android:inputType="textPassword"
android:maxLines="1" android:maxLines="1" />
/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@ -118,7 +115,7 @@
android:visibility="gone"> android:visibility="gone">
<EditText <EditText
android:id="@+id/httpLogin" android:id="@+id/httpLoginView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/prompt_http_login" /> android:hint="@string/prompt_http_login" />
@ -131,11 +128,11 @@
android:visibility="gone"> android:visibility="gone">
<EditText <EditText
android:id="@+id/httpPassword" android:id="@+id/httpPasswordView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textPassword" android:hint="@string/prompt_http_password"
android:hint="@string/prompt_http_password" /> android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
<Switch <Switch
@ -153,7 +150,7 @@
android:visibility="gone" /> android:visibility="gone" />
<Button <Button
android:id="@+id/email_sign_in_button" android:id="@+id/signInButton"
style="?android:textAppearanceSmall" style="?android:textAppearanceSmall"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -41,7 +41,7 @@
app:layout_constraintTop_toBottomOf="@+id/imageView" /> app:layout_constraintTop_toBottomOf="@+id/imageView" />
<TextView <TextView
android:id="@+id/title" android:id="@+id/titleView"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
@ -70,7 +70,7 @@
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" /> app:layout_constraintTop_toBottomOf="@+id/titleView" />
<!--<org.sufficientlysecure.htmltextview.HtmlTextView <!--<org.sufficientlysecure.htmltextview.HtmlTextView
android:id="@+id/content" android:id="@+id/content"
@ -85,7 +85,7 @@
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />--> app:layout_constraintTop_toBottomOf="@+id/titleView" />-->
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View File

@ -22,7 +22,7 @@
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/activity_sources" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="vertical" android:scrollbars="vertical"

View File

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/loging_debug" android:id="@+id/login_debug"
android:checkable="true" android:checkable="true"
android:checked="false" android:checked="false"
android:icon="@drawable/ic_bug_report" android:icon="@drawable/ic_bug_report"

View File

@ -10,7 +10,7 @@
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="loging_debug" android:key="login_debug"
android:summaryOff="@string/login_debug_off" android:summaryOff="@string/login_debug_off"
android:summaryOn="@string/login_debug_on" android:summaryOn="@string/login_debug_on"
android:title="@string/login_debug_title" /> android:title="@string/login_debug_title" />