From f833d73fab995a9dc69c56fc0a563432096483df Mon Sep 17 00:00:00 2001 From: Amine Date: Sun, 12 Nov 2017 17:05:36 +0100 Subject: [PATCH] Closes #109. --- CHANGELOG.md | 2 + app/build.gradle | 2 + .../bou/readerforselfoss/AddSourceActivity.kt | 61 ++-- .../bou/readerforselfoss/HomeActivity.kt | 328 ++++++++---------- .../bou/readerforselfoss/LoginActivity.kt | 172 ++++----- .../bou/readerforselfoss/ReaderActivity.kt | 39 +-- .../bou/readerforselfoss/SourcesActivity.kt | 21 +- .../adapters/ItemCardAdapter.kt | 50 +-- .../adapters/ItemListAdapter.kt | 56 ++- .../adapters/SourcesListAdapter.kt | 18 +- app/src/main/res/layout/activity_home.xml | 8 +- app/src/main/res/layout/activity_login.xml | 29 +- app/src/main/res/layout/activity_reader.xml | 6 +- app/src/main/res/layout/activity_sources.xml | 2 +- app/src/main/res/menu/login_menu.xml | 2 +- app/src/main/res/xml/pref_debug.xml | 2 +- 16 files changed, 346 insertions(+), 452 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbefe3b..df5f2d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Hiding FABs on scroll. +- Closing #109 (code cleaning) + **1.5.4.10** - Displaying a loader when "reading more" in the article viewer. diff --git a/app/build.gradle b/app/build.gradle index 1edfc02..940fcc0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,6 +31,8 @@ apply plugin: 'io.fabric' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + repositories { maven { url 'https://maven.fabric.io/public' diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt index ff7e964..333e5ef 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt @@ -5,11 +5,9 @@ import android.os.Bundle import android.preference.PreferenceManager import android.support.constraint.ConstraintLayout import android.support.v7.app.AppCompatActivity -import android.support.v7.widget.Toolbar import android.view.View import android.widget.AdapterView import android.widget.ArrayAdapter -import android.widget.Button import android.widget.EditText import android.widget.ProgressBar 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.isBaseUrlValid import com.ftinc.scoop.Scoop +import kotlinx.android.synthetic.main.activity_add_source.* import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -34,31 +33,29 @@ class AddSourceActivity : AppCompatActivity() { super.onCreate(savedInstanceState) Scoop.getInstance().apply(this) setContentView(R.layout.activity_add_source) - val toolbar: Toolbar = findViewById(R.id.toolbar) + setSupportActionBar(toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(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 try { 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) { mustLoginToAddSource() } - maybeGetDetailsFromIntentSharing(intent, mSourceUri, mNameInput) + maybeGetDetailsFromIntentSharing(intent, sourceUri, nameInput) - mSaveBtn.setOnClickListener { - handleSaveSource(mTags, mNameInput.text.toString(), mSourceUri.text.toString(), api!!) + saveBtn.setOnClickListener { + handleSaveSource(tags, nameInput.text.toString(), sourceUri.text.toString(), api!!) } val config = Config(this) @@ -66,13 +63,13 @@ class AddSourceActivity : AppCompatActivity() { if (config.baseUrl.isEmpty() || !config.baseUrl.isBaseUrlValid()) { mustLoginToAddSource() } 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() - mSpoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + spoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(adapterView: AdapterView<*>, view: View, i: Int, l: Long) { val spoutName = (view as TextView).text.toString() mSpoutsValue = spoutsKV[spoutName] @@ -95,15 +92,15 @@ class AddSourceActivity : AppCompatActivity() { } mProgress.visibility = View.GONE - mForm.visibility = View.VISIBLE + formContainer.visibility = View.VISIBLE val spinnerArrayAdapter = - ArrayAdapter( - this@AddSourceActivity, - android.R.layout.simple_spinner_item, - itemsStrings) + ArrayAdapter( + this@AddSourceActivity, + android.R.layout.simple_spinner_item, + itemsStrings) spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) - mSpoutsSpinner.adapter = spinnerArrayAdapter + spoutsSpinner.adapter = spinnerArrayAdapter } else { 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) { - mSourceUri.setText(intent.getStringExtra(Intent.EXTRA_TEXT)) - mNameInput.setText(intent.getStringExtra(Intent.EXTRA_TITLE)) + sourceUri.setText(intent.getStringExtra(Intent.EXTRA_TEXT)) + nameInput.setText(intent.getStringExtra(Intent.EXTRA_TITLE)) } } @@ -135,7 +132,7 @@ class AddSourceActivity : AppCompatActivity() { 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() @@ -143,11 +140,11 @@ class AddSourceActivity : AppCompatActivity() { Toast.makeText(this, R.string.form_not_complete, Toast.LENGTH_SHORT).show() } else { api.createSource( - title, - url, - mSpoutsValue!!, - mTags.text.toString(), - "" + title, + url, + mSpoutsValue!!, + tags.text.toString(), + "" ).enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { if (response.body() != null && response.body()!!.isSuccess) { diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index 46d7e88..eb90a91 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -9,20 +9,16 @@ import android.graphics.drawable.GradientDrawable import android.net.Uri import android.os.Bundle import android.preference.PreferenceManager -import android.support.design.widget.CoordinatorLayout import android.support.v4.view.MenuItemCompat -import android.support.v4.widget.SwipeRefreshLayout import android.support.v7.app.AppCompatActivity import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView import android.support.v7.widget.SearchView import android.support.v7.widget.StaggeredGridLayoutManager -import android.support.v7.widget.Toolbar import android.support.v7.widget.helper.ItemTouchHelper import android.view.Menu import android.view.MenuItem import android.view.View -import android.widget.TextView import android.widget.Toast import apps.amine.bou.readerforselfoss.adapters.ItemCardAdapter 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.InviteEvent import com.ftinc.scoop.Scoop -import com.github.stkent.amplify.prompt.DefaultLayoutPromptView import com.github.stkent.amplify.tracking.Amplify import com.google.android.gms.appinvite.AppInviteInvitation import com.google.android.gms.common.ConnectionResult @@ -74,6 +69,8 @@ import com.mikepenz.materialdrawer.model.SecondaryDrawerItem import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import kotlinx.android.synthetic.main.activity_home.* + class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { @@ -105,15 +102,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private var displayAccountHeader: 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 tabArchiveBadge: TextBadgeItem private lateinit var tabStarredBadge: TextBadgeItem - private lateinit var toolBar: Toolbar private lateinit var drawer: Drawer private lateinit var api: SelfossApi private lateinit var customTabActivityHelper: CustomTabActivityHelper @@ -140,16 +131,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Scoop.getInstance().apply(this) - setContentView(R.layout.activity_home) - toolBar = findViewById(R.id.toolbar) setSupportActionBar(toolBar) - if (savedInstanceState == null) { - val promptView: DefaultLayoutPromptView = findViewById(R.id.prompt_view) Amplify.getSharedInstance().promptIfReady(promptView) } @@ -167,122 +153,112 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { appColors = AppColors(this@HomeActivity) handleBottomBar() - handleDrawer() - coordinatorLayout = findViewById(R.id.coordLayout) - swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout) - recyclerView = findViewById(R.id.my_recycler_view) - - emptyText = findViewById(R.id.emptyText) - reloadLayoutManager() - handleSwipeRefreshLayout() } private fun handleSwipeRefreshLayout() { swipeRefreshLayout.setColorSchemeResources( - R.color.refresh_progress_1, - R.color.refresh_progress_2, - R.color.refresh_progress_3) + R.color.refresh_progress_1, + R.color.refresh_progress_2, + R.color.refresh_progress_3) swipeRefreshLayout.setOnRefreshListener { handleDrawerItems() getElementsAccordingToTab() } val simpleItemTouchCallback = - object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) { + object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) { - override fun getSwipeDirs(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder?): Int = - if (elementsShown != UNREAD_SHOWN) 0 else super.getSwipeDirs(recyclerView, viewHolder) + override fun getSwipeDirs(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder?): Int = + if (elementsShown != UNREAD_SHOWN) 0 else super.getSwipeDirs(recyclerView, viewHolder) - override fun onMove(recyclerView: RecyclerView, - viewHolder: RecyclerView.ViewHolder, - target: RecyclerView.ViewHolder): Boolean = false + override fun onMove(recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder, + target: RecyclerView.ViewHolder): Boolean = false - override fun onSwiped(viewHolder: RecyclerView.ViewHolder, swipeDir: Int) { - try { - val i = items[viewHolder.adapterPosition] - val position = items.indexOf(i) + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, swipeDir: Int) { + try { + val i = items[viewHolder.adapterPosition] + val position = items.indexOf(i) - val adapter = recyclerView.adapter - when (adapter) { - is ItemCardAdapter -> adapter.removeItemAtIndex(position) - is ItemListAdapter -> adapter.removeItemAtIndex(position) + val adapter = recyclerView.adapter + when (adapter) { + is ItemCardAdapter -> adapter.removeItemAtIndex(position) + is ItemListAdapter -> adapter.removeItemAtIndex(position) + } + + if (items.size > 0) + tabNewBadge.setText("${items.size}").maybeShow() + else + tabNewBadge.hide() + + + val manager = recyclerView.layoutManager + val lastVisibleItem: Int = when (manager) { + is StaggeredGridLayoutManager -> manager.findLastCompletelyVisibleItemPositions(null).last() + is GridLayoutManager -> manager.findLastCompletelyVisibleItemPosition() + else -> 0 + } + + if (lastVisibleItem == (items.size - 1)) { + getElementsAccordingToTab(appendResults = true) + } + + } catch (e: IndexOutOfBoundsException) { + Crashlytics.setUserIdentifier(userIdentifier) + Crashlytics.log(100, "SWIPE_INDEX_OUT_OF_BOUND", "IndexOutOfBoundsException when swiping") + Crashlytics.logException(e) } - if (items.size > 0) - tabNewBadge.setText("${items.size}").maybeShow() - else - tabNewBadge.hide() - - - val manager = recyclerView.layoutManager - val lastVisibleItem: Int = when (manager) { - is StaggeredGridLayoutManager -> manager.findLastCompletelyVisibleItemPositions(null).last() - is GridLayoutManager -> manager.findLastCompletelyVisibleItemPosition() - else -> 0 - } - - if (lastVisibleItem == (items.size - 1)) { - getElementsAccordingToTab(appendResults = true) - } - - } catch (e: IndexOutOfBoundsException) { - Crashlytics.setUserIdentifier(userIdentifier) - Crashlytics.log(100, "SWIPE_INDEX_OUT_OF_BOUND", "IndexOutOfBoundsException when swiping") - Crashlytics.logException(e) } - } - } ItemTouchHelper(simpleItemTouchCallback).attachToRecyclerView(recyclerView) } private fun handleBottomBar() { - bottomBar = findViewById(R.id.bottomBar) - tabNewBadge = TextBadgeItem() - .setText("") - .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.primary) + .setText("") + .setHideOnSelect(false).hide(false) + .setBackgroundColor(appColors.primary) tabArchiveBadge = TextBadgeItem() - .setText("") - .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.primary) + .setText("") + .setHideOnSelect(false).hide(false) + .setBackgroundColor(appColors.primary) tabStarredBadge = TextBadgeItem() - .setText("") - .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.primary) + .setText("") + .setHideOnSelect(false).hide(false) + .setBackgroundColor(appColors.primary) val tabNew = - BottomNavigationItem( - R.drawable.ic_fiber_new_black_24dp, - getString(R.string.tab_new) - ).setActiveColor(appColors.accent) - .setBadgeItem(tabNewBadge) + BottomNavigationItem( + R.drawable.ic_fiber_new_black_24dp, + getString(R.string.tab_new) + ).setActiveColor(appColors.accent) + .setBadgeItem(tabNewBadge) val tabArchive = - BottomNavigationItem( - R.drawable.ic_archive_black_24dp, - getString(R.string.tab_read) - ).setActiveColor(appColors.dark) - .setBadgeItem(tabArchiveBadge) + BottomNavigationItem( + R.drawable.ic_archive_black_24dp, + getString(R.string.tab_read) + ).setActiveColor(appColors.dark) + .setBadgeItem(tabArchiveBadge) val tabStarred = - BottomNavigationItem( - R.drawable.ic_favorite_black_24dp, - getString(R.string.tab_favs) - ).setActiveColorResource(R.color.pink) - .setBadgeItem(tabStarredBadge) + BottomNavigationItem( + R.drawable.ic_favorite_black_24dp, + getString(R.string.tab_favs) + ).setActiveColorResource(R.color.pink) + .setBadgeItem(tabStarredBadge) bottomBar - .addItem(tabNew) - .addItem(tabArchive) - .addItem(tabStarred) - .setFirstSelectedPosition(0) - .initialise() + .addItem(tabNew) + .addItem(tabArchive) + .addItem(tabStarred) + .setFirstSelectedPosition(0) + .initialise() bottomBar.setMode(BottomNavigationBar.MODE_SHIFTING) bottomBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC) @@ -613,29 +589,29 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { override fun onTabUnselected(position: Int) = Unit override fun onTabReselected(position: Int) = - when (mLayoutManager) { - is StaggeredGridLayoutManager -> - if (mLayoutManager.findFirstCompletelyVisibleItemPositions(null)[0] == 0) { - getElementsAccordingToTab() - } else { - mLayoutManager.scrollToPositionWithOffset(0, 0) - } - is GridLayoutManager -> - if (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) { - getElementsAccordingToTab() - } else { - mLayoutManager.scrollToPositionWithOffset(0, 0) - } - else -> Unit - } + when (mLayoutManager) { + is StaggeredGridLayoutManager -> + if (mLayoutManager.findFirstCompletelyVisibleItemPositions(null)[0] == 0) { + getElementsAccordingToTab() + } else { + mLayoutManager.scrollToPositionWithOffset(0, 0) + } + is GridLayoutManager -> + if (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0) { + getElementsAccordingToTab() + } else { + mLayoutManager.scrollToPositionWithOffset(0, 0) + } + else -> Unit + } override fun onTabSelected(position: Int) = - when (position) { - 0 -> getUnRead() - 1 -> getRead() - 2 -> getStarred() - else -> Unit - } + when (position) { + 0 -> getUnRead() + 1 -> getRead() + 2 -> getStarred() + else -> Unit + } }) } @@ -664,21 +640,21 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { } fun mayBeEmpty() = - if (items.isEmpty()) { - emptyText.visibility = View.VISIBLE - recyclerView.visibility = View.GONE - } else { - emptyText.visibility = View.GONE - recyclerView.visibility = View.VISIBLE - } + if (items.isEmpty()) { + emptyText.visibility = View.VISIBLE + recyclerView.visibility = View.GONE + } else { + emptyText.visibility = View.GONE + recyclerView.visibility = View.VISIBLE + } private fun getElementsAccordingToTab(appendResults: Boolean = false) = - when (elementsShown) { - UNREAD_SHOWN -> getUnRead(appendResults) - READ_SHOWN -> getRead(appendResults) - FAV_SHOWN -> getStarred(appendResults) - else -> getUnRead(appendResults) - } + when (elementsShown) { + UNREAD_SHOWN -> getUnRead(appendResults) + READ_SHOWN -> getRead(appendResults) + FAV_SHOWN -> getStarred(appendResults) + else -> getUnRead(appendResults) + } private fun doCallTo(appendResults: Boolean, toastMessage: Int, call: (String?, Long?, String?) -> Call>) { fun handleItemsResponse(response: Response>) { @@ -705,21 +681,21 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { swipeRefreshLayout.post { swipeRefreshLayout.isRefreshing = true } call(maybeTagFilter?.tag, maybeSourceFilter?.id?.toLong(), maybeSearchFilter) - .enqueue(object : Callback> { - override fun onResponse(call: Call>, response: Response>) { - handleItemsResponse(response) - } + .enqueue(object : Callback> { + override fun onResponse(call: Call>, response: Response>) { + handleItemsResponse(response) + } - override fun onFailure(call: Call>, t: Throwable) { - swipeRefreshLayout.isRefreshing = false - Toast.makeText(this@HomeActivity, toastMessage, Toast.LENGTH_SHORT).show() - } - }) + override fun onFailure(call: Call>, t: Throwable) { + swipeRefreshLayout.isRefreshing = false + Toast.makeText(this@HomeActivity, toastMessage, Toast.LENGTH_SHORT).show() + } + }) } private fun getUnRead(appendResults: Boolean = false) { offset = if (appendResults) (offset + itemsNumber) - else 0 + else 0 firstVisible = if (appendResults) firstVisible else 0 elementsShown = UNREAD_SHOWN doCallTo(appendResults, R.string.cant_get_new_elements){t, id, f -> api.newItems(t, id, f, itemsNumber, offset)} @@ -727,7 +703,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private fun getRead(appendResults: Boolean = false) { offset = if (appendResults) (offset + itemsNumber) - else 0 + else 0 firstVisible = if (appendResults) firstVisible else 0 elementsShown = READ_SHOWN doCallTo(appendResults, R.string.cant_get_read){t, id, f -> api.readItems(t, id, f, itemsNumber, offset)} @@ -735,7 +711,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private fun getStarred(appendResults: Boolean = false) { offset = if (appendResults) (offset + itemsNumber) - else 0 + else 0 firstVisible = if (appendResults) firstVisible else 0 elementsShown = FAV_SHOWN doCallTo(appendResults, R.string.cant_get_favs){t, id, f -> api.starredItems(t, id, f, itemsNumber, offset)} @@ -756,29 +732,29 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { val mAdapter: RecyclerView.Adapter<*> if (shouldBeCardView) { mAdapter = - ItemCardAdapter( - this, - items, - api, - customTabActivityHelper, - internalBrowser, - articleViewer, - fullHeightCards, - appColors, - debugReadingItems, - userIdentifier) + ItemCardAdapter( + this, + items, + api, + customTabActivityHelper, + internalBrowser, + articleViewer, + fullHeightCards, + appColors, + debugReadingItems, + userIdentifier) } else { mAdapter = - ItemListAdapter( - this, - items, - api, - customTabActivityHelper, - clickBehavior, - internalBrowser, - articleViewer, - debugReadingItems, - userIdentifier) + ItemListAdapter( + this, + items, + api, + customTabActivityHelper, + clickBehavior, + internalBrowser, + articleViewer, + debugReadingItems, + userIdentifier) } recyclerView.adapter = mAdapter mAdapter.notifyDataSetChanged() @@ -797,15 +773,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { if (response.body() != null) { if (displayUnreadCount) tabNewBadge - .setText(response.body()!!.unread.toString()) - .maybeShow() + .setText(response.body()!!.unread.toString()) + .maybeShow() if (displayAllCount) { tabArchiveBadge - .setText(response.body()!!.total.toString()) - .maybeShow() + .setText(response.body()!!.total.toString()) + .maybeShow() tabStarredBadge - .setText(response.body()!!.starred.toString()) - .maybeShow() + .setText(response.body()!!.starred.toString()) + .maybeShow() } else { tabArchiveBadge.removeBadge() tabStarredBadge.removeBadge() @@ -877,8 +853,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { api.update().enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { Toast.makeText(this@HomeActivity, - R.string.refresh_success_response, Toast.LENGTH_LONG) - .show() + R.string.refresh_success_response, Toast.LENGTH_LONG) + .show() } override fun onFailure(call: Call, t: Throwable) { @@ -923,17 +899,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { R.id.action_share_the_app -> { if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) { val share = AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title)) - .setMessage(getString(R.string.invitation_message)) - .setDeepLink(Uri.parse("https://ymbh5.app.goo.gl/qbvQ")) - .setCallToActionText(getString(R.string.invitation_cta)) - .build() + .setMessage(getString(R.string.invitation_message)) + .setDeepLink(Uri.parse("https://ymbh5.app.goo.gl/qbvQ")) + .setCallToActionText(getString(R.string.invitation_cta)) + .build() startActivityForResult(share, REQUEST_INVITE) } else { val sendIntent = Intent() sendIntent.action = Intent.ACTION_SEND sendIntent.putExtra( - Intent.EXTRA_TEXT, - getString(R.string.invitation_message) + " https://ymbh5.app.goo.gl/qbvQ" + Intent.EXTRA_TEXT, + getString(R.string.invitation_message) + " https://ymbh5.app.goo.gl/qbvQ" ) sendIntent.type = "text/plain" startActivityForResult(sendIntent, REQUEST_INVITE_BYMAIL) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt index 8fb4af3..c10ad9c 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.os.Bundle -import android.support.design.widget.TextInputLayout import android.support.v7.app.AlertDialog import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar @@ -15,9 +14,6 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.view.inputmethod.EditorInfo -import android.widget.Button -import android.widget.EditText -import android.widget.Switch import android.widget.TextView import android.widget.Toast import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi @@ -32,6 +28,8 @@ import com.mikepenz.aboutlibraries.LibsBuilder import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import kotlinx.android.synthetic.main.activity_login.* + class LoginActivity : AppCompatActivity() { @@ -43,14 +41,7 @@ class LoginActivity : AppCompatActivity() { private lateinit var settings: SharedPreferences private lateinit var editor: SharedPreferences.Editor - private lateinit var mFirebaseAnalytics: 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 firebaseAnalytics: FirebaseAnalytics private lateinit var userIdentifier: String private var logErrors: Boolean = false @@ -61,7 +52,6 @@ class LoginActivity : AppCompatActivity() { Scoop.getInstance().apply(this) setContentView(R.layout.activity_login) - val toolbar: Toolbar = findViewById(R.id.toolbar) setSupportActionBar(toolbar) handleBaseUrlFail() @@ -69,7 +59,7 @@ class LoginActivity : AppCompatActivity() { settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) userIdentifier = settings.getString("unique_id", "") - logErrors = settings.getBoolean("loging_debug", false) + logErrors = settings.getBoolean("login_debug", false) editor = settings.edit() @@ -77,60 +67,44 @@ class LoginActivity : AppCompatActivity() { goToMain() } - mFirebaseAnalytics = 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) + firebaseAnalytics = FirebaseAnalytics.getInstance(this) 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 val visi: Int = if (b) View.VISIBLE else View.GONE - warningTextview.visibility = visi + warningText.visibility = visi } - mPasswordView.setOnEditorActionListener(TextView.OnEditorActionListener { _, id, _ -> - if (id == R.id.login || id == EditorInfo.IME_NULL) { + passwordView.setOnEditorActionListener(TextView.OnEditorActionListener { _, id, _ -> + if (id == R.id.loginView || id == EditorInfo.IME_NULL) { attemptLogin() return@OnEditorActionListener true } false }) - mEmailSignInButton.setOnClickListener { attemptLogin() } + signInButton.setOnClickListener { attemptLogin() } - mSwitch.setOnCheckedChangeListener { _, b -> + withLogin.setOnCheckedChangeListener { _, b -> isWithLogin = !isWithLogin val visi: Int = if (b) View.VISIBLE else View.GONE - mLoginLayout.visibility = visi - mPasswordLayout.visibility = visi + loginLayout.visibility = visi + passwordLayout.visibility = visi } - mHTTPSwitch.setOnCheckedChangeListener { _, b -> + withHttpLogin.setOnCheckedChangeListener { _, b -> isWithHTTPLogin = !isWithHTTPLogin val visi: Int = if (b) View.VISIBLE else View.GONE - mHTTPLoginLayout.visibility = visi - mHTTPPasswordLayout.visibility = visi + httpLoginInput.visibility = visi + httpPasswordInput.visibility = visi } } @@ -140,9 +114,9 @@ class LoginActivity : AppCompatActivity() { alertDialog.setTitle(getString(R.string.warning_wrong_url)) alertDialog.setMessage(getString(R.string.base_url_error)) alertDialog.setButton( - AlertDialog.BUTTON_NEUTRAL, - "OK", - { dialog, _ -> dialog.dismiss() }) + AlertDialog.BUTTON_NEUTRAL, + "OK", + { dialog, _ -> dialog.dismiss() }) alertDialog.show() } } @@ -156,25 +130,25 @@ class LoginActivity : AppCompatActivity() { private fun attemptLogin() { // Reset errors. - mUrlView.error = null - mLoginView.error = null - mHTTPLoginView.error = null - mPasswordView.error = null - mHTTPPasswordView.error = null + urlView.error = null + loginView.error = null + httpLoginView.error = null + passwordView.error = null + httpPasswordView.error = null // Store values at the time of the login attempt. - val url = mUrlView.text.toString() - val login = mLoginView.text.toString() - val httpLogin = mHTTPLoginView.text.toString() - val password = mPasswordView.text.toString() - val httpPassword = mHTTPPasswordView.text.toString() + val url = urlView.text.toString() + val login = loginView.text.toString() + val httpLogin = httpLoginView.text.toString() + val password = passwordView.text.toString() + val httpPassword = httpPasswordView.text.toString() var cancel = false var focusView: View? = null if (!url.isBaseUrlValid()) { - mUrlView.error = getString(R.string.login_url_problem) - focusView = mUrlView + urlView.error = getString(R.string.login_url_problem) + focusView = urlView cancel = true inValidCount++ if (inValidCount == 3) { @@ -182,9 +156,9 @@ class LoginActivity : AppCompatActivity() { alertDialog.setTitle(getString(R.string.warning_wrong_url)) alertDialog.setMessage(getString(R.string.text_wrong_url)) alertDialog.setButton( - AlertDialog.BUTTON_NEUTRAL, - "OK", - { dialog, _ -> dialog.dismiss() }) + AlertDialog.BUTTON_NEUTRAL, + "OK", + { dialog, _ -> dialog.dismiss() }) alertDialog.show() inValidCount = 0 } @@ -192,14 +166,14 @@ class LoginActivity : AppCompatActivity() { if (isWithLogin || isWithHTTPLogin) { if (TextUtils.isEmpty(password)) { - mPasswordView.error = getString(R.string.error_invalid_password) - focusView = mPasswordView + passwordView.error = getString(R.string.error_invalid_password) + focusView = passwordView cancel = true } if (TextUtils.isEmpty(login)) { - mLoginView.error = getString(R.string.error_field_required) - focusView = mLoginView + loginView.error = getString(R.string.error_field_required) + focusView = loginView cancel = true } } @@ -226,11 +200,11 @@ class LoginActivity : AppCompatActivity() { editor.remove("password") editor.remove("httpPassword") editor.apply() - mUrlView.error = getString(R.string.wrong_infos) - mLoginView.error = getString(R.string.wrong_infos) - mPasswordView.error = getString(R.string.wrong_infos) - mHTTPLoginView.error = getString(R.string.wrong_infos) - mHTTPPasswordView.error = getString(R.string.wrong_infos) + urlView.error = getString(R.string.wrong_infos) + loginView.error = getString(R.string.wrong_infos) + passwordView.error = getString(R.string.wrong_infos) + httpLoginView.error = getString(R.string.wrong_infos) + httpPasswordView.error = getString(R.string.wrong_infos) if (logErrors) { Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.log(100, "LOGIN_DEBUG_ERRROR", t.message) @@ -242,7 +216,7 @@ class LoginActivity : AppCompatActivity() { override fun onResponse(call: Call, response: Response) { if (response.body() != null && response.body()!!.isSuccess) { - mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle()) + firebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle()) goToMain() } else { preferenceError(Exception("No response body...")) @@ -260,34 +234,34 @@ class LoginActivity : AppCompatActivity() { private fun showProgress(show: Boolean) { val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime) - mLoginFormView.visibility = if (show) View.GONE else View.VISIBLE - mLoginFormView - .animate() - .setDuration(shortAnimTime.toLong()) - .alpha( - if (show) 0F else 1F - ).setListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator) { - mLoginFormView.visibility = if (show) View.GONE else View.VISIBLE - } - }) + loginForm.visibility = if (show) View.GONE else View.VISIBLE + loginForm + .animate() + .setDuration(shortAnimTime.toLong()) + .alpha( + if (show) 0F else 1F + ).setListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animation: Animator) { + loginForm.visibility = if (show) View.GONE else View.VISIBLE + } + }) - mProgressView.visibility = if (show) View.VISIBLE else View.GONE - mProgressView - .animate() - .setDuration(shortAnimTime.toLong()) - .alpha( - if (show) 1F else 0F - ).setListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator) { - mProgressView.visibility = if (show) View.VISIBLE else View.GONE - } - }) + loginProgress.visibility = if (show) View.VISIBLE else View.GONE + loginProgress + .animate() + .setDuration(shortAnimTime.toLong()) + .alpha( + if (show) 1F else 0F + ).setListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animation: Animator) { + loginProgress.visibility = if (show) View.VISIBLE else View.GONE + } + }) } override fun onCreateOptionsMenu(menu: Menu): Boolean { 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 } @@ -295,17 +269,17 @@ class LoginActivity : AppCompatActivity() { when (item.itemId) { R.id.about -> { LibsBuilder() - .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR) - .withAboutIconShown(true) - .withAboutVersionShown(true) - .start(this) + .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR) + .withAboutIconShown(true) + .withAboutVersionShown(true) + .start(this) return true } - R.id.loging_debug -> { + R.id.login_debug -> { val newState = !item.isChecked item.isChecked = newState logErrors = newState - editor.putBoolean("loging_debug", newState) + editor.putBoolean("login_debug", newState) editor.apply() return true } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index 0644755..a385e4f 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -10,10 +10,6 @@ import android.support.v7.app.AppCompatActivity import android.text.Html import android.view.MenuItem 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.ParsedContent import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent @@ -30,16 +26,11 @@ import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import kotlinx.android.synthetic.main.activity_reader.* class ReaderActivity : AppCompatActivity() { 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 url: String private lateinit var contentText: String @@ -59,12 +50,6 @@ class ReaderActivity : AppCompatActivity() { Scoop.getInstance().apply(this) 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") contentText = intent.getStringExtra("content") contentTitle = intent.getStringExtra("title") @@ -109,19 +94,19 @@ class ReaderActivity : AppCompatActivity() { getContentFromMercury(customTabsIntent, prefs) } else { source.text = contentSource - title.text = contentTitle + titleView.text = contentTitle tryToHandleHtml(contentText, customTabsIntent, prefs) if (!contentImage.isEmptyOrNullOrNullString()) { - image.visibility = View.VISIBLE + imageView.visibility = View.VISIBLE Glide .with(baseContext) .asBitmap() .load(contentImage) .apply(RequestOptions.fitCenterTransform()) - .into(image) + .into(imageView) } else { - image.visibility = View.GONE + imageView.visibility = View.GONE } } @@ -135,14 +120,14 @@ class ReaderActivity : AppCompatActivity() { } 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)) parser.parseUrl(url).enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { if (response.body() != null && response.body()!!.content != null && response.body()!!.content.isNotEmpty()) { source.text = response.body()!!.domain - title.text = response.body()!!.title + titleView.text = response.body()!!.title this@ReaderActivity.url = response.body()!!.url 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()) { - image.visibility = View.VISIBLE + imageView.visibility = View.VISIBLE Glide .with(baseContext) .asBitmap() .load(response.body()!!.lead_image_url) .apply(RequestOptions.fitCenterTransform()) - .into(image) + .into(imageView) } else { - image.visibility = View.GONE + imageView.visibility = View.GONE } nestedScrollView.scrollTo(0, 0) - progress.visibility = View.GONE + progressBar.visibility = View.GONE } else openInBrowserAfterFailing(customTabsIntent) } @@ -185,7 +170,7 @@ class ReaderActivity : AppCompatActivity() { } private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) { - progress.visibility = View.GONE + progressBar.visibility = View.GONE this@ReaderActivity.openItemUrl( url, contentText, diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt index aa0ae6d..d6180a8 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/SourcesActivity.kt @@ -3,12 +3,8 @@ package apps.amine.bou.readerforselfoss import android.content.Intent import android.os.Bundle import android.preference.PreferenceManager -import android.support.design.widget.FloatingActionButton import android.support.v7.app.AppCompatActivity 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 apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi @@ -17,17 +13,16 @@ import com.ftinc.scoop.Scoop import retrofit2.Call import retrofit2.Callback import retrofit2.Response - +import kotlinx.android.synthetic.main.activity_sources.* class SourcesActivity : AppCompatActivity() { - private lateinit var mRecyclerView: RecyclerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Scoop.getInstance().apply(this) setContentView(R.layout.activity_sources) - val toolbar: Toolbar = findViewById(R.id.toolbar) + setSupportActionBar(toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) @@ -35,13 +30,11 @@ class SourcesActivity : AppCompatActivity() { override fun onStop() { super.onStop() - mRecyclerView.clearOnScrollListeners() + recyclerView.clearOnScrollListeners() } override fun onResume() { super.onResume() - val mFab: FloatingActionButton = findViewById(R.id.fab) - mRecyclerView = findViewById(R.id.activity_sources) val mLayoutManager = LinearLayoutManager(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)) var items: ArrayList = ArrayList() - mRecyclerView.setHasFixedSize(true) - mRecyclerView.layoutManager = mLayoutManager + recyclerView.setHasFixedSize(true) + recyclerView.layoutManager = mLayoutManager api.sources.enqueue(object : Callback> { override fun onResponse(call: Call>, response: Response>) { @@ -58,7 +51,7 @@ class SourcesActivity : AppCompatActivity() { items = response.body() as ArrayList } val mAdapter = SourcesListAdapter(this@SourcesActivity, items, api) - mRecyclerView.adapter = mAdapter + recyclerView.adapter = mAdapter mAdapter.notifyDataSetChanged() 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)) } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt index f20f5bd..bc15284 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt @@ -9,8 +9,6 @@ import android.support.v7.widget.RecyclerView import android.text.Html import android.view.LayoutInflater import android.view.ViewGroup -import android.widget.ImageButton -import android.widget.ImageView import android.widget.ImageView.ScaleType import android.widget.TextView import android.widget.Toast @@ -38,6 +36,7 @@ import com.like.OnLikeListener import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import kotlinx.android.synthetic.main.card_item.view.* class ItemCardAdapter(private val app: Activity, private val items: ArrayList, @@ -61,16 +60,16 @@ class ItemCardAdapter(private val app: Activity, val itm = items[position] - holder.saveBtn.isLiked = itm.starred - holder.title.text = Html.fromHtml(itm.title) + holder.mView.favButton.isLiked = itm.starred + holder.mView.title.text = Html.fromHtml(itm.title) - holder.sourceTitleAndDate.text = itm.sourceAndDateText() + holder.mView.sourceTitleAndDate.text = itm.sourceAndDateText() if (itm.getThumbnail(c).isEmpty()) { - Glide.with(c).clear(holder.itemImage) - holder.itemImage.setImageDrawable(null) + Glide.with(c).clear(holder.mView.itemImage) + holder.mView.itemImage.setImageDrawable(null) } else { - c.bitmapCenterCrop(itm.getThumbnail(c), holder.itemImage) + c.bitmapCenterCrop(itm.getThumbnail(c), holder.mView.itemImage) } if (itm.getIcon(c).isEmpty()) { @@ -81,12 +80,12 @@ class ItemCardAdapter(private val app: Activity, .builder() .round() .build(itm.sourcetitle.toTextDrawableString(), color) - holder.sourceImage.setImageDrawable(drawable) + holder.mView.sourceImage.setImageDrawable(drawable) } 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 { @@ -160,14 +159,6 @@ class ItemCardAdapter(private val app: Activity, } 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 { mView.setCardBackgroundColor(appColors.cardBackground) handleClickListeners() @@ -175,27 +166,20 @@ class ItemCardAdapter(private val app: Activity, } 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) { - itemImage.maxHeight = c.resources.getDimension(R.dimen.card_image_max_height).toInt() - itemImage.scaleType = ScaleType.CENTER_CROP + mView.itemImage.maxHeight = c.resources.getDimension(R.dimen.card_image_max_height).toInt() + mView.itemImage.scaleType = ScaleType.CENTER_CROP } - saveBtn.setOnLikeListener(object : OnLikeListener { + mView.favButton.setOnLikeListener(object : OnLikeListener { override fun liked(likeButton: LikeButton) { val (id) = items[adapterPosition] api.starrItem(id).enqueue(object : Callback { override fun onResponse(call: Call, response: Response) {} override fun onFailure(call: Call, t: Throwable) { - saveBtn.isLiked = false + mView.favButton.isLiked = false 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, response: Response) {} override fun onFailure(call: Call, t: Throwable) { - saveBtn.isLiked = true + mView.favButton.isLiked = true Toast.makeText(c, R.string.cant_unmark_favortie, Toast.LENGTH_SHORT).show() } }) } }) - shareBtn.setOnClickListener { + mView.shareBtn.setOnClickListener { c.shareLink(items[adapterPosition].getLinkDecoded()) } - browserBtn.setOnClickListener { + mView.browserBtn.setOnClickListener { c.openInBrowserAsNewTask(items[adapterPosition]) } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt index 33b64fc..a622f0f 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt @@ -12,9 +12,6 @@ import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.ImageButton -import android.widget.ImageView -import android.widget.RelativeLayout import android.widget.TextView import android.widget.Toast import apps.amine.bou.readerforselfoss.R @@ -40,7 +37,7 @@ import retrofit2.Callback import retrofit2.Response import java.util.* import kotlin.collections.ArrayList - +import kotlinx.android.synthetic.main.list_item.view.* class ItemListAdapter(private val app: Activity, private val items: ArrayList, @@ -64,10 +61,10 @@ class ItemListAdapter(private val app: Activity, val itm = items[position] - holder.saveBtn.isLiked = itm.starred - holder.title.text = Html.fromHtml(itm.title) + holder.mView.favButton.isLiked = itm.starred + holder.mView.title.text = Html.fromHtml(itm.title) - holder.sourceTitleAndDate.text = itm.sourceAndDateText() + holder.mView.sourceTitleAndDate.text = itm.sourceAndDateText() if (itm.getThumbnail(c).isEmpty()) { val sizeInInt = 46 @@ -80,11 +77,11 @@ class ItemListAdapter(private val app: Activity, TypedValue.COMPLEX_UNIT_DIP, marginInInt.toFloat(), c.resources .displayMetrics).toInt() - val params = holder.sourceImage.layoutParams as ViewGroup.MarginLayoutParams + val params = holder.mView.itemImage.layoutParams as ViewGroup.MarginLayoutParams params.height = sizeInDp params.width = sizeInDp params.setMargins(marginInDp, 0, 0, 0) - holder.sourceImage.layoutParams = params + holder.mView.itemImage.layoutParams = params if (itm.getIcon(c).isEmpty()) { val color = generator.getColor(itm.sourcetitle) @@ -96,17 +93,17 @@ class ItemListAdapter(private val app: Activity, val builder = TextDrawable.builder().round() val drawable = builder.build(textDrawable.toString(), color) - holder.sourceImage.setImageDrawable(drawable) + holder.mView.itemImage.setImageDrawable(drawable) } else { - c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage) + c.circularBitmapDrawable(itm.getIcon(c), holder.mView.itemImage) } } 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 @@ -179,13 +176,6 @@ class ItemListAdapter(private val app: Activity, } 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 { handleClickListeners() @@ -193,23 +183,15 @@ class ItemListAdapter(private val app: Activity, } 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) - - saveBtn.setOnLikeListener(object : OnLikeListener { + mView.favButton.setOnLikeListener(object : OnLikeListener { override fun liked(likeButton: LikeButton) { val (id) = items[adapterPosition] api.starrItem(id).enqueue(object : Callback { override fun onResponse(call: Call, response: Response) {} override fun onFailure(call: Call, t: Throwable) { - saveBtn.isLiked = false + mView.favButton.isLiked = false 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, response: Response) {} override fun onFailure(call: Call, t: Throwable) { - saveBtn.isLiked = true + mView.favButton.isLiked = true Toast.makeText(c, R.string.cant_unmark_favortie, Toast.LENGTH_SHORT).show() } }) } }) - shareBtn.setOnClickListener { + mView.shareBtn.setOnClickListener { c.shareLink(items[adapterPosition].getLinkDecoded()) } - browserBtn.setOnClickListener { + mView.browserBtn.setOnClickListener { c.openInBrowserAsNewTask(items[adapterPosition]) } @@ -279,7 +261,11 @@ class ItemListAdapter(private val app: Activity, private fun actionBarShowHide() { 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 + } } } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt index 89de800..6959542 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt @@ -21,6 +21,7 @@ import com.amulyakhare.textdrawable.util.ColorGenerator import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import kotlinx.android.synthetic.main.source_list_item.view.* class SourcesListAdapter(private val app: Activity, @@ -41,13 +42,13 @@ class SourcesListAdapter(private val app: Activity, val color = generator.getColor(itm.title) val drawable = - TextDrawable - .builder() - .round() - .build(itm.title.toTextDrawableString(), color) - holder.sourceImage.setImageDrawable(drawable) + TextDrawable + .builder() + .round() + .build(itm.title.toTextDrawableString(), color) + holder.itemImage.setImageDrawable(drawable) } else { - c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage) + c.circularBitmapDrawable(itm.getIcon(c), holder.itemImage) } 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) { - lateinit var sourceImage: ImageView + lateinit var itemImage: ImageView lateinit var sourceTitle: TextView init { - handleClickListeners() } private fun handleClickListeners() { - sourceImage = mView.findViewById(R.id.itemImage) - sourceTitle = mView.findViewById(R.id.sourceTitle) val deleteBtn: Button = mView.findViewById(R.id.deleteBtn) diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 0d4256b..ad3b41c 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -9,7 +9,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + android:layout_below="@id/promptView"> @@ -52,14 +52,13 @@ > + android:maxLines="1" /> @@ -77,13 +76,12 @@ android:visibility="gone"> + android:maxLines="1" /> @@ -94,13 +92,12 @@ android:visibility="gone"> + android:maxLines="1" /> @@ -118,7 +115,7 @@ android:visibility="gone"> @@ -131,11 +128,11 @@ android:visibility="gone"> + android:hint="@string/prompt_http_password" + android:inputType="textPassword" />