Reformated code according to official kotling style.
This commit is contained in:
parent
3013ae4f35
commit
4d4a2039c8
@ -41,10 +41,10 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
try {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
api = SelfossApi(
|
||||
this,
|
||||
this@AddSourceActivity,
|
||||
prefs.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
this,
|
||||
this@AddSourceActivity,
|
||||
prefs.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
mustLoginToAddSource()
|
||||
@ -69,10 +69,10 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun handleSpoutsSpinner(
|
||||
spoutsSpinner: Spinner,
|
||||
api: SelfossApi?,
|
||||
mProgress: ProgressBar,
|
||||
formContainer: ConstraintLayout
|
||||
spoutsSpinner: Spinner,
|
||||
api: SelfossApi?,
|
||||
mProgress: ProgressBar,
|
||||
formContainer: ConstraintLayout
|
||||
) {
|
||||
val spoutsKV = HashMap<String, String>()
|
||||
spoutsSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
@ -91,8 +91,8 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
var items: Map<String, Spout>
|
||||
api!!.spouts().enqueue(object : Callback<Map<String, Spout>> {
|
||||
override fun onResponse(
|
||||
call: Call<Map<String, Spout>>,
|
||||
response: Response<Map<String, Spout>>
|
||||
call: Call<Map<String, Spout>>,
|
||||
response: Response<Map<String, Spout>>
|
||||
) {
|
||||
if (response.body() != null) {
|
||||
items = response.body()!!
|
||||
@ -106,11 +106,11 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
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)
|
||||
spoutsSpinner.adapter = spinnerArrayAdapter
|
||||
} else {
|
||||
@ -124,9 +124,9 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
|
||||
private fun handleProblemWithSpouts() {
|
||||
Toast.makeText(
|
||||
this@AddSourceActivity,
|
||||
R.string.cant_get_spouts,
|
||||
Toast.LENGTH_SHORT
|
||||
this@AddSourceActivity,
|
||||
R.string.cant_get_spouts,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
mProgress.visibility = View.GONE
|
||||
}
|
||||
@ -134,9 +134,9 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun maybeGetDetailsFromIntentSharing(
|
||||
intent: Intent,
|
||||
sourceUri: EditText,
|
||||
nameInput: EditText
|
||||
intent: Intent,
|
||||
sourceUri: EditText,
|
||||
nameInput: EditText
|
||||
) {
|
||||
if (Intent.ACTION_SEND == intent.action && "text/plain" == intent.type) {
|
||||
sourceUri.setText(intent.getStringExtra(Intent.EXTRA_TEXT))
|
||||
@ -153,38 +153,39 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
|
||||
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()
|
||||
|
||||
if (sourceDetailsAvailable) {
|
||||
Toast.makeText(this, R.string.form_not_complete, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
api.createSource(
|
||||
title,
|
||||
url,
|
||||
mSpoutsValue!!,
|
||||
tags.text.toString(),
|
||||
""
|
||||
title,
|
||||
url,
|
||||
mSpoutsValue!!,
|
||||
tags.text.toString(),
|
||||
""
|
||||
).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (response.body() != null && response.body()!!.isSuccess) {
|
||||
finish()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
this@AddSourceActivity,
|
||||
R.string.cant_create_source,
|
||||
Toast.LENGTH_SHORT
|
||||
this@AddSourceActivity,
|
||||
R.string.cant_create_source,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||
Toast.makeText(
|
||||
this@AddSourceActivity,
|
||||
R.string.cant_create_source,
|
||||
Toast.LENGTH_SHORT
|
||||
this@AddSourceActivity,
|
||||
R.string.cant_create_source,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
|
@ -151,10 +151,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
api = SelfossApi(
|
||||
this,
|
||||
this@HomeActivity,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
sharedPref.getBoolean("should_log_everything", false)
|
||||
this,
|
||||
this@HomeActivity,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
sharedPref.getBoolean("should_log_everything", false)
|
||||
)
|
||||
items = ArrayList()
|
||||
|
||||
@ -168,9 +168,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
|
||||
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()
|
||||
@ -178,79 +178,79 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
val simpleItemTouchCallback =
|
||||
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
|
||||
)
|
||||
}
|
||||
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 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)
|
||||
}
|
||||
|
||||
if (items.size > 0) {
|
||||
badgeNew--
|
||||
reloadBadgeContent()
|
||||
} 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 &&
|
||||
items.size <= maxItemNumber() &&
|
||||
(maxItemNumber() >= itemsNumber || !lastFetchDone)
|
||||
) {
|
||||
if (maxItemNumber() < itemsNumber) {
|
||||
lastFetchDone = true
|
||||
}
|
||||
getElementsAccordingToTab(
|
||||
appendResults = true,
|
||||
offsetOverride = lastVisibleItem
|
||||
)
|
||||
}
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"SWIPE_INDEX_OUT_OF_BOUND",
|
||||
"IndexOutOfBoundsException when swiping"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
val adapter = recyclerView.adapter
|
||||
when (adapter) {
|
||||
is ItemCardAdapter -> adapter.removeItemAtIndex(position)
|
||||
is ItemListAdapter -> adapter.removeItemAtIndex(position)
|
||||
}
|
||||
|
||||
if (items.size > 0) {
|
||||
badgeNew--
|
||||
reloadBadgeContent()
|
||||
} 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 &&
|
||||
items.size <= maxItemNumber() &&
|
||||
(maxItemNumber() >= itemsNumber || !lastFetchDone)
|
||||
) {
|
||||
if (maxItemNumber() < itemsNumber) {
|
||||
lastFetchDone = true
|
||||
}
|
||||
getElementsAccordingToTab(
|
||||
appendResults = true,
|
||||
offsetOverride = lastVisibleItem
|
||||
)
|
||||
}
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"SWIPE_INDEX_OUT_OF_BOUND",
|
||||
"IndexOutOfBoundsException when swiping"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemTouchHelper(simpleItemTouchCallback).attachToRecyclerView(recyclerView)
|
||||
}
|
||||
@ -258,43 +258,43 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
private fun handleBottomBar() {
|
||||
|
||||
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)
|
||||
@ -351,7 +351,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
private fun handleDrawer() {
|
||||
displayAccountHeader =
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getBoolean("account_header_displaying", false)
|
||||
.getBoolean("account_header_displaying", false)
|
||||
|
||||
drawer = drawer {
|
||||
rootViewRes = R.id.drawer_layout
|
||||
@ -385,17 +385,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
iconTintingEnabled = true
|
||||
onClick { _ ->
|
||||
IssueReporterLauncher.forTarget(
|
||||
getString(R.string.report_github_user),
|
||||
getString(R.string.report_github_repo)
|
||||
getString(R.string.report_github_user),
|
||||
getString(R.string.report_github_repo)
|
||||
)
|
||||
.theme(R.style.Theme_App_Light)
|
||||
.guestToken(BuildConfig.GITHUB_TOKEN)
|
||||
.guestEmailRequired(true)
|
||||
.minDescriptionLength(20)
|
||||
.putExtraInfo("Unique ID", settings.getString("unique_id", ""))
|
||||
.putExtraInfo("From github", BuildConfig.GITHUB_VERSION)
|
||||
.homeAsUpEnabled(true)
|
||||
.launch(this@HomeActivity)
|
||||
.theme(R.style.Theme_App_Light)
|
||||
.guestToken(BuildConfig.GITHUB_TOKEN)
|
||||
.guestEmailRequired(true)
|
||||
.minDescriptionLength(20)
|
||||
.putExtraInfo("Unique ID", settings.getString("unique_id", ""))
|
||||
.putExtraInfo("From github", BuildConfig.GITHUB_VERSION)
|
||||
.homeAsUpEnabled(true)
|
||||
.launch(this@HomeActivity)
|
||||
false
|
||||
}
|
||||
}
|
||||
@ -405,11 +405,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
iconTintingEnabled = true
|
||||
onClick { _ ->
|
||||
startActivityForResult(
|
||||
Intent(
|
||||
this@HomeActivity,
|
||||
SettingsActivity::class.java
|
||||
),
|
||||
MENU_PREFERENCES
|
||||
Intent(
|
||||
this@HomeActivity,
|
||||
SettingsActivity::class.java
|
||||
),
|
||||
MENU_PREFERENCES
|
||||
)
|
||||
false
|
||||
}
|
||||
@ -424,9 +424,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
if (maybeTags == null) {
|
||||
if (loadedFromCache) {
|
||||
drawer.addItem(
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_error_loading_tags))
|
||||
.withSelectable(false)
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_error_loading_tags))
|
||||
.withSelectable(false)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@ -443,20 +443,20 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
gd.setSize(30, 30)
|
||||
gd.cornerRadius = 30F
|
||||
drawer.addItem(
|
||||
PrimaryDrawerItem()
|
||||
.withName(tag.tag)
|
||||
.withIdentifier(tag.tag.longHash())
|
||||
.withIcon(gd)
|
||||
.withBadge("${tag.unread}")
|
||||
.withBadgeStyle(
|
||||
BadgeStyle().withTextColor(Color.WHITE)
|
||||
.withColor(appColors.accent)
|
||||
)
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
maybeTagFilter = tag
|
||||
getElementsAccordingToTab()
|
||||
false
|
||||
}
|
||||
PrimaryDrawerItem()
|
||||
.withName(tag.tag)
|
||||
.withIdentifier(tag.tag.longHash())
|
||||
.withIcon(gd)
|
||||
.withBadge("${tag.unread}")
|
||||
.withBadgeStyle(
|
||||
BadgeStyle().withTextColor(Color.WHITE)
|
||||
.withColor(appColors.accent)
|
||||
)
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
maybeTagFilter = tag
|
||||
getElementsAccordingToTab()
|
||||
false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -466,23 +466,23 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
if (maybeSources == null) {
|
||||
if (loadedFromCache) {
|
||||
drawer.addItem(
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_error_loading_sources))
|
||||
.withSelectable(false)
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_error_loading_sources))
|
||||
.withSelectable(false)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
for (tag in maybeSources) {
|
||||
drawer.addItem(
|
||||
CustomUrlPrimaryDrawerItem()
|
||||
.withName(tag.title)
|
||||
.withIdentifier(tag.id.toLong())
|
||||
.withIcon(tag.getIcon(this@HomeActivity))
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
maybeSourceFilter = tag
|
||||
getElementsAccordingToTab()
|
||||
false
|
||||
}
|
||||
CustomUrlPrimaryDrawerItem()
|
||||
.withName(tag.title)
|
||||
.withIdentifier(tag.id.toLong())
|
||||
.withIcon(tag.getIcon(this@HomeActivity))
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
maybeSourceFilter = tag
|
||||
getElementsAccordingToTab()
|
||||
false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -491,86 +491,86 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
drawer.removeAllItems()
|
||||
if (maybeDrawerData != null) {
|
||||
drawer.addItem(
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_item_filters))
|
||||
.withSelectable(false)
|
||||
.withIdentifier(DRAWER_ID_FILTERS)
|
||||
.withBadge(getString(R.string.drawer_action_clear))
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
maybeSourceFilter = null
|
||||
maybeTagFilter = null
|
||||
getElementsAccordingToTab()
|
||||
false
|
||||
}
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_item_filters))
|
||||
.withSelectable(false)
|
||||
.withIdentifier(DRAWER_ID_FILTERS)
|
||||
.withBadge(getString(R.string.drawer_action_clear))
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
maybeSourceFilter = null
|
||||
maybeTagFilter = null
|
||||
getElementsAccordingToTab()
|
||||
false
|
||||
}
|
||||
)
|
||||
drawer.addItem(DividerDrawerItem())
|
||||
drawer.addItem(
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_item_tags))
|
||||
.withIdentifier(DRAWER_ID_TAGS)
|
||||
.withSelectable(false)
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_item_tags))
|
||||
.withIdentifier(DRAWER_ID_TAGS)
|
||||
.withSelectable(false)
|
||||
)
|
||||
handleTags(maybeDrawerData.tags)
|
||||
drawer.addItem(DividerDrawerItem())
|
||||
drawer.addItem(
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_item_sources))
|
||||
.withIdentifier(DRAWER_ID_TAGS)
|
||||
.withBadge(getString(R.string.drawer_action_edit))
|
||||
.withSelectable(false)
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
startActivity(Intent(this, SourcesActivity::class.java))
|
||||
false
|
||||
}
|
||||
SecondaryDrawerItem()
|
||||
.withName(getString(R.string.drawer_item_sources))
|
||||
.withIdentifier(DRAWER_ID_TAGS)
|
||||
.withBadge(getString(R.string.drawer_action_edit))
|
||||
.withSelectable(false)
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
startActivity(Intent(this, SourcesActivity::class.java))
|
||||
false
|
||||
}
|
||||
)
|
||||
handleSources(maybeDrawerData.sources)
|
||||
drawer.addItem(DividerDrawerItem())
|
||||
drawer.addItem(
|
||||
PrimaryDrawerItem()
|
||||
.withName(R.string.action_about)
|
||||
.withSelectable(false)
|
||||
.withIcon(R.drawable.ic_info_outline)
|
||||
.withIconTintingEnabled(true)
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
LibsBuilder()
|
||||
.withActivityStyle(
|
||||
if (appColors.isDarkTheme) {
|
||||
Libs.ActivityStyle.LIGHT_DARK_TOOLBAR
|
||||
} else {
|
||||
Libs.ActivityStyle.DARK
|
||||
}
|
||||
)
|
||||
.withAboutIconShown(true)
|
||||
.withAboutVersionShown(true)
|
||||
.start(this@HomeActivity)
|
||||
false
|
||||
}
|
||||
PrimaryDrawerItem()
|
||||
.withName(R.string.action_about)
|
||||
.withSelectable(false)
|
||||
.withIcon(R.drawable.ic_info_outline)
|
||||
.withIconTintingEnabled(true)
|
||||
.withOnDrawerItemClickListener { _, _, _ ->
|
||||
LibsBuilder()
|
||||
.withActivityStyle(
|
||||
if (appColors.isDarkTheme) {
|
||||
Libs.ActivityStyle.LIGHT_DARK_TOOLBAR
|
||||
} else {
|
||||
Libs.ActivityStyle.DARK
|
||||
}
|
||||
)
|
||||
.withAboutIconShown(true)
|
||||
.withAboutVersionShown(true)
|
||||
.start(this@HomeActivity)
|
||||
false
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
if (!loadedFromCache) {
|
||||
Reservoir.putAsync(
|
||||
"drawerData", maybeDrawerData, object : ReservoirPutCallback {
|
||||
override fun onSuccess() {
|
||||
}
|
||||
"drawerData", maybeDrawerData, object : ReservoirPutCallback {
|
||||
override fun onSuccess() {
|
||||
}
|
||||
|
||||
override fun onFailure(p0: Exception?) {
|
||||
}
|
||||
})
|
||||
override fun onFailure(p0: Exception?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (!loadedFromCache) {
|
||||
drawer.addItem(
|
||||
PrimaryDrawerItem()
|
||||
.withName(getString(R.string.no_tags_loaded))
|
||||
.withIdentifier(DRAWER_ID_TAGS)
|
||||
.withSelectable(false)
|
||||
PrimaryDrawerItem()
|
||||
.withName(getString(R.string.no_tags_loaded))
|
||||
.withIdentifier(DRAWER_ID_TAGS)
|
||||
.withSelectable(false)
|
||||
)
|
||||
drawer.addItem(
|
||||
PrimaryDrawerItem()
|
||||
.withName(getString(R.string.no_sources_loaded))
|
||||
.withIdentifier(DRAWER_ID_SOURCES)
|
||||
.withSelectable(false)
|
||||
PrimaryDrawerItem()
|
||||
.withName(getString(R.string.no_sources_loaded))
|
||||
.withIdentifier(DRAWER_ID_SOURCES)
|
||||
.withSelectable(false)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -583,8 +583,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
fun sourcesApiCall() {
|
||||
api.sources.enqueue(object : Callback<List<Sources>> {
|
||||
override fun onResponse(
|
||||
call: Call<List<Sources>>?,
|
||||
response: Response<List<Sources>>
|
||||
call: Call<List<Sources>>?,
|
||||
response: Response<List<Sources>>
|
||||
) {
|
||||
sources = response.body()
|
||||
val apiDrawerData = DrawerData(tags, sources)
|
||||
@ -600,8 +600,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
|
||||
api.tags.enqueue(object : Callback<List<Tag>> {
|
||||
override fun onResponse(
|
||||
call: Call<List<Tag>>,
|
||||
response: Response<List<Tag>>
|
||||
call: Call<List<Tag>>,
|
||||
response: Response<List<Tag>>
|
||||
) {
|
||||
tags = response.body()
|
||||
sourcesApiCall()
|
||||
@ -614,23 +614,23 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
drawer.addItem(
|
||||
PrimaryDrawerItem().withName(getString(R.string.drawer_loading)).withSelectable(
|
||||
false
|
||||
)
|
||||
PrimaryDrawerItem().withName(getString(R.string.drawer_loading)).withSelectable(
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
val resultType = object : TypeToken<DrawerData>() {}.type
|
||||
Reservoir.getAsync(
|
||||
"drawerData", resultType, object : ReservoirGetCallback<DrawerData> {
|
||||
override fun onSuccess(maybeDrawerData: DrawerData?) {
|
||||
handleDrawerData(maybeDrawerData, loadedFromCache = true)
|
||||
drawerApiCalls(maybeDrawerData)
|
||||
}
|
||||
"drawerData", resultType, object : ReservoirGetCallback<DrawerData> {
|
||||
override fun onSuccess(maybeDrawerData: DrawerData?) {
|
||||
handleDrawerData(maybeDrawerData, loadedFromCache = true)
|
||||
drawerApiCalls(maybeDrawerData)
|
||||
}
|
||||
|
||||
override fun onFailure(p0: Exception?) {
|
||||
drawerApiCalls(null)
|
||||
}
|
||||
})
|
||||
override fun onFailure(p0: Exception?) {
|
||||
drawerApiCalls(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun reloadLayoutManager() {
|
||||
@ -640,19 +640,20 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
// This will only update the layout manager if settings changed
|
||||
when (currentManager) {
|
||||
is StaggeredGridLayoutManager ->
|
||||
if (!shouldBeCardView) {
|
||||
layoutManager = GridLayoutManager(this, calculateNoOfColumns())
|
||||
recyclerView.layoutManager = layoutManager
|
||||
}
|
||||
if (!shouldBeCardView) {
|
||||
layoutManager = GridLayoutManager(this, calculateNoOfColumns())
|
||||
recyclerView.layoutManager = layoutManager
|
||||
}
|
||||
is GridLayoutManager ->
|
||||
if (shouldBeCardView) {
|
||||
layoutManager = StaggeredGridLayoutManager(
|
||||
calculateNoOfColumns(),
|
||||
StaggeredGridLayoutManager.VERTICAL
|
||||
)
|
||||
layoutManager.gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
|
||||
recyclerView.layoutManager = layoutManager
|
||||
}
|
||||
if (shouldBeCardView) {
|
||||
layoutManager = StaggeredGridLayoutManager(
|
||||
calculateNoOfColumns(),
|
||||
StaggeredGridLayoutManager.VERTICAL
|
||||
)
|
||||
layoutManager.gapStrategy =
|
||||
StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
|
||||
recyclerView.layoutManager = layoutManager
|
||||
}
|
||||
else ->
|
||||
if (currentManager == null) {
|
||||
if (!shouldBeCardView) {
|
||||
@ -660,10 +661,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
recyclerView.layoutManager = layoutManager
|
||||
} else {
|
||||
layoutManager = StaggeredGridLayoutManager(
|
||||
calculateNoOfColumns(),
|
||||
StaggeredGridLayoutManager.VERTICAL
|
||||
calculateNoOfColumns(),
|
||||
StaggeredGridLayoutManager.VERTICAL
|
||||
)
|
||||
layoutManager.gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
|
||||
layoutManager.gapStrategy =
|
||||
StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
|
||||
recyclerView.layoutManager = layoutManager
|
||||
}
|
||||
} else {
|
||||
@ -717,7 +719,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
val manager = recyclerView.layoutManager
|
||||
val lastVisibleItem: Int = when (manager) {
|
||||
is StaggeredGridLayoutManager -> manager.findLastCompletelyVisibleItemPositions(
|
||||
null
|
||||
null
|
||||
).last()
|
||||
is GridLayoutManager -> manager.findLastCompletelyVisibleItemPosition()
|
||||
else -> 0
|
||||
@ -736,17 +738,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
private 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,
|
||||
offsetOverride: Int? = null
|
||||
appendResults: Boolean = false,
|
||||
offsetOverride: Int? = null
|
||||
) {
|
||||
offset = if (appendResults && offsetOverride === null) {
|
||||
(offset + itemsNumber)
|
||||
@ -764,9 +766,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
private fun doCallTo(
|
||||
appendResults: Boolean,
|
||||
toastMessage: Int,
|
||||
call: (String?, Long?, String?) -> Call<List<Item>>
|
||||
appendResults: Boolean,
|
||||
toastMessage: Int,
|
||||
call: (String?, Long?, String?) -> Call<List<Item>>
|
||||
) {
|
||||
fun handleItemsResponse(response: Response<List<Item>>) {
|
||||
val shouldUpdate = (response.body() != items)
|
||||
@ -792,34 +794,34 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
call(maybeTagFilter?.tag, maybeSourceFilter?.id?.toLong(), maybeSearchFilter)
|
||||
.enqueue(object : Callback<List<Item>> {
|
||||
override fun onResponse(
|
||||
call: Call<List<Item>>,
|
||||
response: Response<List<Item>>
|
||||
) {
|
||||
handleItemsResponse(response)
|
||||
}
|
||||
.enqueue(object : Callback<List<Item>> {
|
||||
override fun onResponse(
|
||||
call: Call<List<Item>>,
|
||||
response: Response<List<Item>>
|
||||
) {
|
||||
handleItemsResponse(response)
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<List<Item>>, t: Throwable) {
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
toastMessage,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
override fun onFailure(call: Call<List<Item>>, t: Throwable) {
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
toastMessage,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun getUnRead(appendResults: Boolean = false) {
|
||||
elementsShown = UNREAD_SHOWN
|
||||
doCallTo(appendResults, R.string.cant_get_new_elements) { t, id, f ->
|
||||
api.newItems(
|
||||
t,
|
||||
id,
|
||||
f,
|
||||
itemsNumber,
|
||||
offset
|
||||
t,
|
||||
id,
|
||||
f,
|
||||
itemsNumber,
|
||||
offset
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -828,11 +830,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
elementsShown = READ_SHOWN
|
||||
doCallTo(appendResults, R.string.cant_get_read) { t, id, f ->
|
||||
api.readItems(
|
||||
t,
|
||||
id,
|
||||
f,
|
||||
itemsNumber,
|
||||
offset
|
||||
t,
|
||||
id,
|
||||
f,
|
||||
itemsNumber,
|
||||
offset
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -841,11 +843,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
elementsShown = FAV_SHOWN
|
||||
doCallTo(appendResults, R.string.cant_get_favs) { t, id, f ->
|
||||
api.starredItems(
|
||||
t,
|
||||
id,
|
||||
f,
|
||||
itemsNumber,
|
||||
offset
|
||||
t,
|
||||
id,
|
||||
f,
|
||||
itemsNumber,
|
||||
offset
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -866,36 +868,36 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
if (shouldBeCardView) {
|
||||
recyclerAdapter =
|
||||
ItemCardAdapter(
|
||||
this,
|
||||
items,
|
||||
api,
|
||||
customTabActivityHelper,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
fullHeightCards,
|
||||
appColors,
|
||||
debugReadingItems,
|
||||
userIdentifier
|
||||
this,
|
||||
items,
|
||||
api,
|
||||
customTabActivityHelper,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
fullHeightCards,
|
||||
appColors,
|
||||
debugReadingItems,
|
||||
userIdentifier
|
||||
)
|
||||
} else {
|
||||
recyclerAdapter =
|
||||
ItemListAdapter(
|
||||
this,
|
||||
items,
|
||||
api,
|
||||
customTabActivityHelper,
|
||||
clickBehavior,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
debugReadingItems,
|
||||
userIdentifier
|
||||
this,
|
||||
items,
|
||||
api,
|
||||
customTabActivityHelper,
|
||||
clickBehavior,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
debugReadingItems,
|
||||
userIdentifier
|
||||
)
|
||||
|
||||
recyclerView.addItemDecoration(
|
||||
DividerItemDecoration(
|
||||
this@HomeActivity,
|
||||
DividerItemDecoration.VERTICAL
|
||||
)
|
||||
DividerItemDecoration(
|
||||
this@HomeActivity,
|
||||
DividerItemDecoration.VERTICAL
|
||||
)
|
||||
)
|
||||
}
|
||||
recyclerView.adapter = recyclerAdapter
|
||||
@ -935,16 +937,16 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
if (succeeded) {
|
||||
if (displayUnreadCount) {
|
||||
tabNewBadge
|
||||
.setText(badgeNew.toString())
|
||||
.maybeShow()
|
||||
.setText(badgeNew.toString())
|
||||
.maybeShow()
|
||||
}
|
||||
if (displayAllCount) {
|
||||
tabArchiveBadge
|
||||
.setText(badgeAll.toString())
|
||||
.maybeShow()
|
||||
.setText(badgeAll.toString())
|
||||
.maybeShow()
|
||||
tabStarredBadge
|
||||
.setText(badgeFavs.toString())
|
||||
.maybeShow()
|
||||
.setText(badgeFavs.toString())
|
||||
.maybeShow()
|
||||
} else {
|
||||
tabArchiveBadge.removeBadge()
|
||||
tabStarredBadge.removeBadge()
|
||||
@ -1009,21 +1011,21 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
R.id.refresh -> {
|
||||
api.update().enqueue(object : Callback<String> {
|
||||
override fun onResponse(
|
||||
call: Call<String>,
|
||||
response: Response<String>
|
||||
call: Call<String>,
|
||||
response: Response<String>
|
||||
) {
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
R.string.refresh_success_response, Toast.LENGTH_LONG
|
||||
this@HomeActivity,
|
||||
R.string.refresh_success_response, Toast.LENGTH_LONG
|
||||
)
|
||||
.show()
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<String>, t: Throwable) {
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
R.string.refresh_failer_message,
|
||||
Toast.LENGTH_SHORT
|
||||
this@HomeActivity,
|
||||
R.string.refresh_failer_message,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
@ -1037,21 +1039,21 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
|
||||
api.readAll(ids).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (response.body() != null && response.body()!!.isSuccess) {
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
R.string.all_posts_read,
|
||||
Toast.LENGTH_SHORT
|
||||
this@HomeActivity,
|
||||
R.string.all_posts_read,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
tabNewBadge.removeBadge()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
R.string.all_posts_not_read,
|
||||
Toast.LENGTH_SHORT
|
||||
this@HomeActivity,
|
||||
R.string.all_posts_not_read,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
|
||||
@ -1060,9 +1062,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
|
||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
R.string.all_posts_not_read,
|
||||
Toast.LENGTH_SHORT
|
||||
this@HomeActivity,
|
||||
R.string.all_posts_not_read,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
}
|
||||
@ -1070,9 +1072,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
items = ArrayList()
|
||||
if (items.isEmpty()) {
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
R.string.nothing_here,
|
||||
Toast.LENGTH_SHORT
|
||||
this@HomeActivity,
|
||||
R.string.nothing_here,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
handleListResult()
|
||||
@ -1084,7 +1086,8 @@ 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))
|
||||
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))
|
||||
@ -1094,8 +1097,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
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)
|
||||
@ -1107,10 +1110,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
private fun maxItemNumber(): Int =
|
||||
when (elementsShown) {
|
||||
UNREAD_SHOWN -> badgeNew
|
||||
READ_SHOWN -> badgeAll
|
||||
FAV_SHOWN -> badgeFavs
|
||||
else -> badgeNew // if !elementsShown then unread are fetched.
|
||||
}
|
||||
when (elementsShown) {
|
||||
UNREAD_SHOWN -> badgeNew
|
||||
READ_SHOWN -> badgeAll
|
||||
FAV_SHOWN -> badgeFavs
|
||||
else -> badgeNew // if !elementsShown then unread are fetched.
|
||||
}
|
||||
}
|
||||
|
@ -18,42 +18,42 @@ class IntroActivity : MaterialIntroActivity() {
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
|
||||
|
||||
addSlide(
|
||||
SlideFragmentBuilder()
|
||||
.backgroundColor(R.color.colorPrimary)
|
||||
.buttonsColor(R.color.colorAccent)
|
||||
.image(R.drawable.web_hi_res_512)
|
||||
.title(getString(R.string.intro_hello_title))
|
||||
.description(getString(R.string.intro_hello_message))
|
||||
.build()
|
||||
SlideFragmentBuilder()
|
||||
.backgroundColor(R.color.colorPrimary)
|
||||
.buttonsColor(R.color.colorAccent)
|
||||
.image(R.drawable.web_hi_res_512)
|
||||
.title(getString(R.string.intro_hello_title))
|
||||
.description(getString(R.string.intro_hello_message))
|
||||
.build()
|
||||
)
|
||||
|
||||
addSlide(
|
||||
SlideFragmentBuilder()
|
||||
.backgroundColor(R.color.colorAccent)
|
||||
.buttonsColor(R.color.colorPrimary)
|
||||
.image(R.drawable.ic_info_outline_white_48px)
|
||||
.title(getString(R.string.intro_needs_selfoss_title))
|
||||
.description(getString(R.string.intro_needs_selfoss_message))
|
||||
.build(),
|
||||
MessageButtonBehaviour(
|
||||
View.OnClickListener {
|
||||
val browserIntent = Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("https://selfoss.aditu.de")
|
||||
)
|
||||
startActivity(browserIntent)
|
||||
}, getString(R.string.intro_needs_selfoss_link)
|
||||
)
|
||||
SlideFragmentBuilder()
|
||||
.backgroundColor(R.color.colorAccent)
|
||||
.buttonsColor(R.color.colorPrimary)
|
||||
.image(R.drawable.ic_info_outline_white_48px)
|
||||
.title(getString(R.string.intro_needs_selfoss_title))
|
||||
.description(getString(R.string.intro_needs_selfoss_message))
|
||||
.build(),
|
||||
MessageButtonBehaviour(
|
||||
View.OnClickListener {
|
||||
val browserIntent = Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("https://selfoss.aditu.de")
|
||||
)
|
||||
startActivity(browserIntent)
|
||||
}, getString(R.string.intro_needs_selfoss_link)
|
||||
)
|
||||
)
|
||||
|
||||
addSlide(
|
||||
SlideFragmentBuilder()
|
||||
.backgroundColor(R.color.colorPrimaryDark)
|
||||
.buttonsColor(R.color.colorAccentDark)
|
||||
.image(R.drawable.ic_thumb_up_white_48px)
|
||||
.title(getString(R.string.intro_all_set_title))
|
||||
.description(getString(R.string.intro_all_set_message))
|
||||
.build()
|
||||
SlideFragmentBuilder()
|
||||
.backgroundColor(R.color.colorPrimaryDark)
|
||||
.buttonsColor(R.color.colorAccentDark)
|
||||
.image(R.drawable.ic_thumb_up_white_48px)
|
||||
.title(getString(R.string.intro_all_set_title))
|
||||
.description(getString(R.string.intro_all_set_message))
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -77,13 +77,13 @@ class LoginActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
passwordView.setOnEditorActionListener(
|
||||
TextView.OnEditorActionListener { _, id, _ ->
|
||||
if (id == R.id.loginView || id == EditorInfo.IME_NULL) {
|
||||
attemptLogin()
|
||||
return@OnEditorActionListener true
|
||||
}
|
||||
false
|
||||
TextView.OnEditorActionListener { _, id, _ ->
|
||||
if (id == R.id.loginView || id == EditorInfo.IME_NULL) {
|
||||
attemptLogin()
|
||||
return@OnEditorActionListener true
|
||||
}
|
||||
false
|
||||
}
|
||||
)
|
||||
|
||||
signInButton.setOnClickListener { attemptLogin() }
|
||||
@ -111,9 +111,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()
|
||||
}
|
||||
@ -154,9 +154,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
|
||||
@ -191,10 +191,10 @@ class LoginActivity : AppCompatActivity() {
|
||||
editor.apply()
|
||||
|
||||
val api = SelfossApi(
|
||||
this,
|
||||
this@LoginActivity,
|
||||
isWithSelfSignedCert,
|
||||
isWithSelfSignedCert
|
||||
this,
|
||||
this@LoginActivity,
|
||||
isWithSelfSignedCert,
|
||||
isWithSelfSignedCert
|
||||
)
|
||||
api.login().enqueue(object : Callback<SuccessResponse> {
|
||||
private fun preferenceError(t: Throwable) {
|
||||
@ -214,17 +214,17 @@ class LoginActivity : AppCompatActivity() {
|
||||
Crashlytics.log(100, "LOGIN_DEBUG_ERRROR", t.message)
|
||||
Crashlytics.logException(t)
|
||||
Toast.makeText(
|
||||
this@LoginActivity,
|
||||
t.message,
|
||||
Toast.LENGTH_LONG
|
||||
this@LoginActivity,
|
||||
t.message,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
showProgress(false)
|
||||
}
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (response.body() != null && response.body()!!.isSuccess) {
|
||||
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle())
|
||||
@ -246,28 +246,28 @@ class LoginActivity : AppCompatActivity() {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
.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
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
.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
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -281,10 +281,10 @@ 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.login_debug -> {
|
||||
|
@ -14,7 +14,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if (PreferenceManager.getDefaultSharedPreferences(baseContext).getBoolean(
|
||||
"firstStart",
|
||||
true
|
||||
)) {
|
||||
)) {
|
||||
val i = Intent(this@MainActivity, IntroActivity::class.java)
|
||||
startActivity(i)
|
||||
} else {
|
||||
|
@ -47,9 +47,9 @@ class MyApp : MultiDexApplication() {
|
||||
|
||||
private fun initAmplify() {
|
||||
Amplify.initSharedInstance(this)
|
||||
.setPositiveFeedbackCollectors(GooglePlayStoreFeedbackCollector())
|
||||
.setCriticalFeedbackCollectors(DefaultEmailFeedbackCollector(BuildConfig.FEEDBACK_EMAIL))
|
||||
.applyAllDefaultRules()
|
||||
.setPositiveFeedbackCollectors(GooglePlayStoreFeedbackCollector())
|
||||
.setCriticalFeedbackCollectors(DefaultEmailFeedbackCollector(BuildConfig.FEEDBACK_EMAIL))
|
||||
.applyAllDefaultRules()
|
||||
}
|
||||
|
||||
private fun initCache() {
|
||||
@ -63,15 +63,15 @@ class MyApp : MultiDexApplication() {
|
||||
private fun initDrawerImageLoader() {
|
||||
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
|
||||
override fun set(
|
||||
imageView: ImageView?,
|
||||
uri: Uri?,
|
||||
placeholder: Drawable?,
|
||||
tag: String?
|
||||
imageView: ImageView?,
|
||||
uri: Uri?,
|
||||
placeholder: Drawable?,
|
||||
tag: String?
|
||||
) {
|
||||
Glide.with(imageView?.context)
|
||||
.load(uri)
|
||||
.apply(RequestOptions.fitCenterTransform().placeholder(placeholder))
|
||||
.into(imageView)
|
||||
.load(uri)
|
||||
.apply(RequestOptions.fitCenterTransform().placeholder(placeholder))
|
||||
.into(imageView)
|
||||
}
|
||||
|
||||
override fun cancel(imageView: ImageView?) {
|
||||
@ -86,22 +86,34 @@ class MyApp : MultiDexApplication() {
|
||||
|
||||
private fun initTheme() {
|
||||
Scoop.waffleCone()
|
||||
.addFlavor(getString(R.string.default_theme), R.style.NoBar, true)
|
||||
.addDayNightFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark)
|
||||
.addFlavor(getString(R.string.teal_orange_theme), R.style.NoBarTealOrange)
|
||||
.addDayNightFlavor(getString(R.string.teal_orange_dark_theme), R.style.NoBarTealOrangeDark)
|
||||
.addFlavor(getString(R.string.cyan_pink_theme), R.style.NoBarCyanPink)
|
||||
.addDayNightFlavor(getString(R.string.cyan_pink_dark_theme), R.style.NoBarCyanPinkDark)
|
||||
.addFlavor(getString(R.string.grey_orange_theme), R.style.NoBarGreyOrange)
|
||||
.addDayNightFlavor(getString(R.string.grey_orange_dark_theme), R.style.NoBarGreyOrangeDark)
|
||||
.addFlavor(getString(R.string.blue_amber_theme), R.style.NoBarBlueAmber)
|
||||
.addDayNightFlavor(getString(R.string.blue_amber_dark_theme), R.style.NoBarBlueAmberDark)
|
||||
.addFlavor(getString(R.string.indigo_pink_theme), R.style.NoBarIndigoPink)
|
||||
.addDayNightFlavor(getString(R.string.indigo_pink_dark_theme), R.style.NoBarIndigoPinkDark)
|
||||
.addFlavor(getString(R.string.red_teal_theme), R.style.NoBarRedTeal)
|
||||
.addDayNightFlavor(getString(R.string.red_teal_dark_theme), R.style.NoBarRedTealDark)
|
||||
.setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this))
|
||||
.initialize()
|
||||
.addFlavor(getString(R.string.default_theme), R.style.NoBar, true)
|
||||
.addDayNightFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark)
|
||||
.addFlavor(getString(R.string.teal_orange_theme), R.style.NoBarTealOrange)
|
||||
.addDayNightFlavor(
|
||||
getString(R.string.teal_orange_dark_theme),
|
||||
R.style.NoBarTealOrangeDark
|
||||
)
|
||||
.addFlavor(getString(R.string.cyan_pink_theme), R.style.NoBarCyanPink)
|
||||
.addDayNightFlavor(getString(R.string.cyan_pink_dark_theme), R.style.NoBarCyanPinkDark)
|
||||
.addFlavor(getString(R.string.grey_orange_theme), R.style.NoBarGreyOrange)
|
||||
.addDayNightFlavor(
|
||||
getString(R.string.grey_orange_dark_theme),
|
||||
R.style.NoBarGreyOrangeDark
|
||||
)
|
||||
.addFlavor(getString(R.string.blue_amber_theme), R.style.NoBarBlueAmber)
|
||||
.addDayNightFlavor(
|
||||
getString(R.string.blue_amber_dark_theme),
|
||||
R.style.NoBarBlueAmberDark
|
||||
)
|
||||
.addFlavor(getString(R.string.indigo_pink_theme), R.style.NoBarIndigoPink)
|
||||
.addDayNightFlavor(
|
||||
getString(R.string.indigo_pink_dark_theme),
|
||||
R.style.NoBarIndigoPinkDark
|
||||
)
|
||||
.addFlavor(getString(R.string.red_teal_theme), R.style.NoBarRedTeal)
|
||||
.addDayNightFlavor(getString(R.string.red_teal_dark_theme), R.style.NoBarRedTealDark)
|
||||
.setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this))
|
||||
.initialize()
|
||||
}
|
||||
|
||||
private fun tryToHandleBug() {
|
||||
@ -109,8 +121,8 @@ class MyApp : MultiDexApplication() {
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler { thread, e ->
|
||||
if (e is java.lang.NoClassDefFoundError && e.stackTrace.asList().any {
|
||||
it.toString().contains("android.view.ViewDebug")
|
||||
}) {
|
||||
it.toString().contains("android.view.ViewDebug")
|
||||
}) {
|
||||
Unit
|
||||
} else {
|
||||
oldHandler.uncaughtException(thread, e)
|
||||
|
@ -69,9 +69,9 @@ class ReaderActivity : AppCompatActivity() {
|
||||
if (allItems.isEmpty()) {
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"READER_ITEMS_EMPTY",
|
||||
"Items empty when trying to open the Article Reader. Was (static) companion object field set ?"
|
||||
100,
|
||||
"READER_ITEMS_EMPTY",
|
||||
"Items empty when trying to open the Article Reader. Was (static) companion object field set ?"
|
||||
)
|
||||
Crashlytics.logException(Exception("Empty items on Reader Activity."))
|
||||
|
||||
@ -79,10 +79,10 @@ class ReaderActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
api = SelfossApi(
|
||||
this,
|
||||
this@ReaderActivity,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
sharedPref.getBoolean("should_log_everything", false)
|
||||
this,
|
||||
this@ReaderActivity,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
sharedPref.getBoolean("should_log_everything", false)
|
||||
)
|
||||
|
||||
currentItem = intent.getIntExtra("currentItem", 0)
|
||||
@ -101,65 +101,65 @@ class ReaderActivity : AppCompatActivity() {
|
||||
(indicator as CircleIndicator).setViewPager(pager)
|
||||
|
||||
pager.addOnPageChangeListener(
|
||||
object : ViewPager.SimpleOnPageChangeListener() {
|
||||
var isLastItem = false
|
||||
object : ViewPager.SimpleOnPageChangeListener() {
|
||||
var isLastItem = false
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
isLastItem = (position === (allItems.size - 1))
|
||||
override fun onPageSelected(position: Int) {
|
||||
isLastItem = (position === (allItems.size - 1))
|
||||
|
||||
if (allItems[position].starred) {
|
||||
canRemoveFromFavorite()
|
||||
} else {
|
||||
canFavorite()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
if (markOnScroll && (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem))) {
|
||||
api.markItem(allItems[pager.currentItem].id).enqueue(
|
||||
object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (!response.succeeded() && debugReadingItems) {
|
||||
val message =
|
||||
"message: ${response.message()} " +
|
||||
"response isSuccess: ${response.isSuccessful} " +
|
||||
"response code: ${response.code()} " +
|
||||
"response message: ${response.message()} " +
|
||||
"response errorBody: ${response.errorBody()?.string()} " +
|
||||
"body success: ${response.body()?.success} " +
|
||||
"body isSuccess: ${response.body()?.isSuccess}"
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"READ_DEBUG_SUCCESS",
|
||||
message
|
||||
)
|
||||
Crashlytics.logException(Exception("Was success, but did it work ?"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
if (debugReadingItems) {
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"READ_DEBUG_ERROR",
|
||||
t.message
|
||||
)
|
||||
Crashlytics.logException(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
if (allItems[position].starred) {
|
||||
canRemoveFromFavorite()
|
||||
} else {
|
||||
canFavorite()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
if (markOnScroll && (state === ViewPager.SCROLL_STATE_DRAGGING || (state === ViewPager.SCROLL_STATE_IDLE && isLastItem))) {
|
||||
api.markItem(allItems[pager.currentItem].id).enqueue(
|
||||
object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (!response.succeeded() && debugReadingItems) {
|
||||
val message =
|
||||
"message: ${response.message()} " +
|
||||
"response isSuccess: ${response.isSuccessful} " +
|
||||
"response code: ${response.code()} " +
|
||||
"response message: ${response.message()} " +
|
||||
"response errorBody: ${response.errorBody()?.string()} " +
|
||||
"body success: ${response.body()?.success} " +
|
||||
"body isSuccess: ${response.body()?.isSuccess}"
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"READ_DEBUG_SUCCESS",
|
||||
message
|
||||
)
|
||||
Crashlytics.logException(Exception("Was success, but did it work ?"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
if (debugReadingItems) {
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"READ_DEBUG_ERROR",
|
||||
t.message
|
||||
)
|
||||
Crashlytics.logException(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -175,7 +175,8 @@ class ReaderActivity : AppCompatActivity() {
|
||||
oldInstanceState!!.clear()
|
||||
}
|
||||
|
||||
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
|
||||
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) :
|
||||
FragmentStatePagerAdapter(fm) {
|
||||
override fun getCount(): Int {
|
||||
return allItems.size
|
||||
}
|
||||
@ -206,48 +207,50 @@ class ReaderActivity : AppCompatActivity() {
|
||||
return true
|
||||
}
|
||||
R.id.save -> {
|
||||
api.starrItem(allItems[pager.currentItem].id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
api.starrItem(allItems[pager.currentItem].id)
|
||||
.enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
allItems[pager.currentItem] = allItems[pager.currentItem].toggleStar()
|
||||
canRemoveFromFavorite()
|
||||
}
|
||||
) {
|
||||
allItems[pager.currentItem] = allItems[pager.currentItem].toggleStar()
|
||||
canRemoveFromFavorite()
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
Toast.makeText(
|
||||
) {
|
||||
Toast.makeText(
|
||||
baseContext,
|
||||
R.string.cant_mark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
).show()
|
||||
}
|
||||
})
|
||||
}
|
||||
R.id.unsave -> {
|
||||
api.unstarrItem(allItems[pager.currentItem].id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
api.unstarrItem(allItems[pager.currentItem].id)
|
||||
.enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
allItems[pager.currentItem] = allItems[pager.currentItem].toggleStar()
|
||||
canFavorite()
|
||||
}
|
||||
) {
|
||||
allItems[pager.currentItem] = allItems[pager.currentItem].toggleStar()
|
||||
canFavorite()
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
Toast.makeText(
|
||||
) {
|
||||
Toast.makeText(
|
||||
baseContext,
|
||||
R.string.cant_unmark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
).show()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
|
@ -39,10 +39,10 @@ class SourcesActivity : AppCompatActivity() {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
val api = SelfossApi(
|
||||
this,
|
||||
this@SourcesActivity,
|
||||
prefs.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
this,
|
||||
this@SourcesActivity,
|
||||
prefs.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
var items: ArrayList<Sources> = ArrayList()
|
||||
|
||||
@ -51,8 +51,8 @@ class SourcesActivity : AppCompatActivity() {
|
||||
|
||||
api.sources.enqueue(object : Callback<List<Sources>> {
|
||||
override fun onResponse(
|
||||
call: Call<List<Sources>>,
|
||||
response: Response<List<Sources>>
|
||||
call: Call<List<Sources>>,
|
||||
response: Response<List<Sources>>
|
||||
) {
|
||||
if (response.body() != null && response.body()!!.isNotEmpty()) {
|
||||
items = response.body() as ArrayList<Sources>
|
||||
@ -62,18 +62,18 @@ class SourcesActivity : AppCompatActivity() {
|
||||
mAdapter.notifyDataSetChanged()
|
||||
if (items.isEmpty()) {
|
||||
Toast.makeText(
|
||||
this@SourcesActivity,
|
||||
R.string.nothing_here,
|
||||
Toast.LENGTH_SHORT
|
||||
this@SourcesActivity,
|
||||
R.string.nothing_here,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<List<Sources>>, t: Throwable) {
|
||||
Toast.makeText(
|
||||
this@SourcesActivity,
|
||||
R.string.cant_get_sources,
|
||||
Toast.LENGTH_SHORT
|
||||
this@SourcesActivity,
|
||||
R.string.cant_get_sources,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
|
@ -2,8 +2,6 @@ package apps.amine.bou.readerforselfoss.adapters
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.widget.CardView
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.text.Html
|
||||
@ -11,7 +9,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView.ScaleType
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import apps.amine.bou.readerforselfoss.R
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
@ -26,12 +23,10 @@ import apps.amine.bou.readerforselfoss.utils.openInBrowserAsNewTask
|
||||
import apps.amine.bou.readerforselfoss.utils.openItemUrl
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
import apps.amine.bou.readerforselfoss.utils.sourceAndDateText
|
||||
import apps.amine.bou.readerforselfoss.utils.succeeded
|
||||
import apps.amine.bou.readerforselfoss.utils.toTextDrawableString
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import com.bumptech.glide.Glide
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.like.LikeButton
|
||||
import com.like.OnLikeListener
|
||||
import kotlinx.android.synthetic.main.card_item.view.*
|
||||
@ -40,20 +35,21 @@ import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
||||
class ItemCardAdapter(
|
||||
override val app: Activity,
|
||||
override var items: ArrayList<Item>,
|
||||
override val api: SelfossApi,
|
||||
private val helper: CustomTabActivityHelper,
|
||||
private val internalBrowser: Boolean,
|
||||
private val articleViewer: Boolean,
|
||||
private val fullHeightCards: Boolean,
|
||||
private val appColors: AppColors,
|
||||
override val debugReadingItems: Boolean,
|
||||
override val userIdentifier: String
|
||||
override val app: Activity,
|
||||
override var items: ArrayList<Item>,
|
||||
override val api: SelfossApi,
|
||||
private val helper: CustomTabActivityHelper,
|
||||
private val internalBrowser: Boolean,
|
||||
private val articleViewer: Boolean,
|
||||
private val fullHeightCards: Boolean,
|
||||
private val appColors: AppColors,
|
||||
override val debugReadingItems: Boolean,
|
||||
override val userIdentifier: String
|
||||
) : ItemsAdapter<ItemCardAdapter.ViewHolder>() {
|
||||
private val c: Context = app.baseContext
|
||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||
private val imageMaxHeight: Int = c.resources.getDimension(R.dimen.card_image_max_height).toInt()
|
||||
private val imageMaxHeight: Int =
|
||||
c.resources.getDimension(R.dimen.card_image_max_height).toInt()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val v = LayoutInflater.from(c).inflate(R.layout.card_item, parent, false) as CardView
|
||||
@ -87,10 +83,10 @@ class ItemCardAdapter(
|
||||
val color = generator.getColor(itm.sourcetitle)
|
||||
|
||||
val drawable =
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.sourcetitle.toTextDrawableString(), color)
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.sourcetitle.toTextDrawableString(), color)
|
||||
holder.mView.sourceImage.setImageDrawable(drawable)
|
||||
} else {
|
||||
c.circularBitmapDrawable(itm.getIcon(c), holder.mView.sourceImage)
|
||||
@ -117,20 +113,20 @@ class ItemCardAdapter(
|
||||
val (id) = items[adapterPosition]
|
||||
api.starrItem(id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
mView.favButton.isLiked = false
|
||||
Toast.makeText(
|
||||
c,
|
||||
R.string.cant_mark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
c,
|
||||
R.string.cant_mark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
@ -140,20 +136,20 @@ class ItemCardAdapter(
|
||||
val (id) = items[adapterPosition]
|
||||
api.unstarrItem(id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
mView.favButton.isLiked = true
|
||||
Toast.makeText(
|
||||
c,
|
||||
R.string.cant_unmark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
c,
|
||||
R.string.cant_unmark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
@ -175,13 +171,13 @@ class ItemCardAdapter(
|
||||
|
||||
mView.setOnClickListener {
|
||||
c.openItemUrl(
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,13 @@ package apps.amine.bou.readerforselfoss.adapters
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.support.constraint.ConstraintLayout
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.text.Html
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import apps.amine.bou.readerforselfoss.R
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
@ -25,11 +22,9 @@ import apps.amine.bou.readerforselfoss.utils.openInBrowserAsNewTask
|
||||
import apps.amine.bou.readerforselfoss.utils.openItemUrl
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
import apps.amine.bou.readerforselfoss.utils.sourceAndDateText
|
||||
import apps.amine.bou.readerforselfoss.utils.succeeded
|
||||
import apps.amine.bou.readerforselfoss.utils.toTextDrawableString
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.like.LikeButton
|
||||
import com.like.OnLikeListener
|
||||
import kotlinx.android.synthetic.main.list_item.view.*
|
||||
@ -40,15 +35,15 @@ import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class ItemListAdapter(
|
||||
override val app: Activity,
|
||||
override var items: ArrayList<Item>,
|
||||
override val api: SelfossApi,
|
||||
private val helper: CustomTabActivityHelper,
|
||||
private val clickBehavior: Boolean,
|
||||
private val internalBrowser: Boolean,
|
||||
private val articleViewer: Boolean,
|
||||
override val debugReadingItems: Boolean,
|
||||
override val userIdentifier: String
|
||||
override val app: Activity,
|
||||
override var items: ArrayList<Item>,
|
||||
override val api: SelfossApi,
|
||||
private val helper: CustomTabActivityHelper,
|
||||
private val clickBehavior: Boolean,
|
||||
private val internalBrowser: Boolean,
|
||||
private val articleViewer: Boolean,
|
||||
override val debugReadingItems: Boolean,
|
||||
override val userIdentifier: String
|
||||
) : ItemsAdapter<ItemListAdapter.ViewHolder>() {
|
||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||
private val c: Context = app.baseContext
|
||||
@ -56,9 +51,9 @@ class ItemListAdapter(
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val v = LayoutInflater.from(c).inflate(
|
||||
R.layout.list_item,
|
||||
parent,
|
||||
false
|
||||
R.layout.list_item,
|
||||
parent,
|
||||
false
|
||||
) as ConstraintLayout
|
||||
return ViewHolder(v)
|
||||
}
|
||||
@ -74,13 +69,13 @@ class ItemListAdapter(
|
||||
if (itm.getThumbnail(c).isEmpty()) {
|
||||
val sizeInInt = 46
|
||||
val sizeInDp = TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, sizeInInt.toFloat(), c.resources
|
||||
TypedValue.COMPLEX_UNIT_DIP, sizeInInt.toFloat(), c.resources
|
||||
.displayMetrics
|
||||
).toInt()
|
||||
|
||||
val marginInInt = 16
|
||||
val marginInDp = TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, marginInInt.toFloat(), c.resources
|
||||
TypedValue.COMPLEX_UNIT_DIP, marginInInt.toFloat(), c.resources
|
||||
.displayMetrics
|
||||
).toInt()
|
||||
|
||||
@ -94,10 +89,10 @@ class ItemListAdapter(
|
||||
val color = generator.getColor(itm.sourcetitle)
|
||||
|
||||
val drawable =
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.sourcetitle.toTextDrawableString(), color)
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.sourcetitle.toTextDrawableString(), color)
|
||||
|
||||
holder.mView.itemImage.setImageDrawable(drawable)
|
||||
} else {
|
||||
@ -123,8 +118,6 @@ class ItemListAdapter(
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
|
||||
|
||||
inner class ViewHolder(val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) {
|
||||
|
||||
init {
|
||||
@ -139,20 +132,20 @@ class ItemListAdapter(
|
||||
val (id) = items[adapterPosition]
|
||||
api.starrItem(id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
mView.favButton.isLiked = false
|
||||
Toast.makeText(
|
||||
c,
|
||||
R.string.cant_mark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
c,
|
||||
R.string.cant_mark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
@ -162,20 +155,20 @@ class ItemListAdapter(
|
||||
val (id) = items[adapterPosition]
|
||||
api.unstarrItem(id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
call: Call<SuccessResponse>,
|
||||
t: Throwable
|
||||
) {
|
||||
mView.favButton.isLiked = true
|
||||
Toast.makeText(
|
||||
c,
|
||||
R.string.cant_unmark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
c,
|
||||
R.string.cant_unmark_favortie,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
@ -200,13 +193,13 @@ class ItemListAdapter(
|
||||
if (!clickBehavior) {
|
||||
mView.setOnClickListener {
|
||||
c.openItemUrl(
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
)
|
||||
}
|
||||
mView.setOnLongClickListener {
|
||||
@ -217,13 +210,13 @@ class ItemListAdapter(
|
||||
mView.setOnClickListener { actionBarShowHide() }
|
||||
mView.setOnLongClickListener {
|
||||
c.openItemUrl(
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
)
|
||||
true
|
||||
}
|
||||
@ -239,6 +232,4 @@ class ItemListAdapter(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -30,29 +30,29 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
||||
|
||||
private fun doUnmark(i: Item, position: Int) {
|
||||
val s = Snackbar
|
||||
.make(
|
||||
app.findViewById(R.id.coordLayout),
|
||||
R.string.marked_as_read,
|
||||
Snackbar.LENGTH_LONG
|
||||
)
|
||||
.setAction(R.string.undo_string) {
|
||||
items.add(position, i)
|
||||
notifyItemInserted(position)
|
||||
.make(
|
||||
app.findViewById(R.id.coordLayout),
|
||||
R.string.marked_as_read,
|
||||
Snackbar.LENGTH_LONG
|
||||
)
|
||||
.setAction(R.string.undo_string) {
|
||||
items.add(position, i)
|
||||
notifyItemInserted(position)
|
||||
|
||||
api.unmarkItem(i.id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
}
|
||||
api.unmarkItem(i.id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||
items.remove(i)
|
||||
notifyItemRemoved(position)
|
||||
doUnmark(i, position)
|
||||
}
|
||||
})
|
||||
}
|
||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||
items.remove(i)
|
||||
notifyItemRemoved(position)
|
||||
doUnmark(i, position)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
val view = s.view
|
||||
val tv: TextView = view.findViewById(android.support.design.R.id.snackbar_text)
|
||||
@ -69,18 +69,18 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
||||
|
||||
api.markItem(i.id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (!response.succeeded() && debugReadingItems) {
|
||||
val message =
|
||||
"message: ${response.message()} " +
|
||||
"response isSuccess: ${response.isSuccessful} " +
|
||||
"response code: ${response.code()} " +
|
||||
"response message: ${response.message()} " +
|
||||
"response errorBody: ${response.errorBody()?.string()} " +
|
||||
"body success: ${response.body()?.success} " +
|
||||
"body isSuccess: ${response.body()?.isSuccess}"
|
||||
"message: ${response.message()} " +
|
||||
"response isSuccess: ${response.isSuccessful} " +
|
||||
"response code: ${response.code()} " +
|
||||
"response message: ${response.message()} " +
|
||||
"response errorBody: ${response.errorBody()?.string()} " +
|
||||
"body success: ${response.body()?.success} " +
|
||||
"body isSuccess: ${response.body()?.isSuccess}"
|
||||
Crashlytics.setUserIdentifier(userIdentifier)
|
||||
Crashlytics.log(100, "READ_DEBUG_SUCCESS", message)
|
||||
Crashlytics.logException(Exception("Was success, but did it work ?"))
|
||||
@ -98,9 +98,9 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
||||
Toast.makeText(app.baseContext, t.message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
Toast.makeText(
|
||||
app,
|
||||
app.getString(R.string.cant_mark_read),
|
||||
Toast.LENGTH_SHORT
|
||||
app,
|
||||
app.getString(R.string.cant_mark_read),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
items.add(i)
|
||||
notifyItemInserted(position)
|
||||
|
@ -22,18 +22,18 @@ import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
||||
class SourcesListAdapter(
|
||||
private val app: Activity,
|
||||
private val items: ArrayList<Sources>,
|
||||
private val api: SelfossApi
|
||||
private val app: Activity,
|
||||
private val items: ArrayList<Sources>,
|
||||
private val api: SelfossApi
|
||||
) : RecyclerView.Adapter<SourcesListAdapter.ViewHolder>() {
|
||||
private val c: Context = app.baseContext
|
||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val v = LayoutInflater.from(c).inflate(
|
||||
R.layout.source_list_item,
|
||||
parent,
|
||||
false
|
||||
R.layout.source_list_item,
|
||||
parent,
|
||||
false
|
||||
) as ConstraintLayout
|
||||
return ViewHolder(v)
|
||||
}
|
||||
@ -45,10 +45,10 @@ class SourcesListAdapter(
|
||||
val color = generator.getColor(itm.title)
|
||||
|
||||
val drawable =
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.title.toTextDrawableString(), color)
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.title.toTextDrawableString(), color)
|
||||
holder.mView.itemImage.setImageDrawable(drawable)
|
||||
} else {
|
||||
c.circularBitmapDrawable(itm.getIcon(c), holder.mView.itemImage)
|
||||
@ -73,8 +73,8 @@ class SourcesListAdapter(
|
||||
val (id) = items[adapterPosition]
|
||||
api.deleteSource(id).enqueue(object : Callback<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
if (response.body() != null && response.body()!!.isSuccess) {
|
||||
items.removeAt(adapterPosition)
|
||||
@ -82,18 +82,18 @@ class SourcesListAdapter(
|
||||
notifyItemRangeChanged(adapterPosition, itemCount)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
app,
|
||||
R.string.can_delete_source,
|
||||
Toast.LENGTH_SHORT
|
||||
app,
|
||||
R.string.can_delete_source,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||
Toast.makeText(
|
||||
app,
|
||||
R.string.can_delete_source,
|
||||
Toast.LENGTH_SHORT
|
||||
app,
|
||||
R.string.can_delete_source,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
|
@ -21,15 +21,15 @@ class MercuryApi(private val key: String, shouldLog: Boolean) {
|
||||
val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
|
||||
|
||||
val gson = GsonBuilder()
|
||||
.setLenient()
|
||||
.create()
|
||||
.setLenient()
|
||||
.create()
|
||||
val retrofit =
|
||||
Retrofit
|
||||
.Builder()
|
||||
.baseUrl("https://mercury.postlight.com")
|
||||
.client(client)
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
Retrofit
|
||||
.Builder()
|
||||
.baseUrl("https://mercury.postlight.com")
|
||||
.client(client)
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
service = retrofit.create(MercuryService::class.java)
|
||||
}
|
||||
|
||||
|
@ -5,39 +5,40 @@ import android.os.Parcelable
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class ParsedContent(
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("content") val content: String?,
|
||||
@SerializedName("date_published") val date_published: String,
|
||||
@SerializedName("lead_image_url") val lead_image_url: String?,
|
||||
@SerializedName("dek") val dek: String,
|
||||
@SerializedName("url") val url: String,
|
||||
@SerializedName("domain") val domain: String,
|
||||
@SerializedName("excerpt") val excerpt: String,
|
||||
@SerializedName("total_pages") val total_pages: Int,
|
||||
@SerializedName("rendered_pages") val rendered_pages: Int,
|
||||
@SerializedName("next_page_url") val next_page_url: String
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("content") val content: String?,
|
||||
@SerializedName("date_published") val date_published: String,
|
||||
@SerializedName("lead_image_url") val lead_image_url: String?,
|
||||
@SerializedName("dek") val dek: String,
|
||||
@SerializedName("url") val url: String,
|
||||
@SerializedName("domain") val domain: String,
|
||||
@SerializedName("excerpt") val excerpt: String,
|
||||
@SerializedName("total_pages") val total_pages: Int,
|
||||
@SerializedName("rendered_pages") val rendered_pages: Int,
|
||||
@SerializedName("next_page_url") val next_page_url: String
|
||||
) : Parcelable {
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<ParsedContent> = object : Parcelable.Creator<ParsedContent> {
|
||||
override fun createFromParcel(source: Parcel): ParsedContent = ParsedContent(source)
|
||||
override fun newArray(size: Int): Array<ParsedContent?> = arrayOfNulls(size)
|
||||
}
|
||||
val CREATOR: Parcelable.Creator<ParsedContent> =
|
||||
object : Parcelable.Creator<ParsedContent> {
|
||||
override fun createFromParcel(source: Parcel): ParsedContent = ParsedContent(source)
|
||||
override fun newArray(size: Int): Array<ParsedContent?> = arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(source: Parcel) : this(
|
||||
title = source.readString(),
|
||||
content = source.readString(),
|
||||
date_published = source.readString(),
|
||||
lead_image_url = source.readString(),
|
||||
dek = source.readString(),
|
||||
url = source.readString(),
|
||||
domain = source.readString(),
|
||||
excerpt = source.readString(),
|
||||
total_pages = source.readInt(),
|
||||
rendered_pages = source.readInt(),
|
||||
next_page_url = source.readString()
|
||||
title = source.readString(),
|
||||
content = source.readString(),
|
||||
date_published = source.readString(),
|
||||
lead_image_url = source.readString(),
|
||||
dek = source.readString(),
|
||||
url = source.readString(),
|
||||
domain = source.readString(),
|
||||
excerpt = source.readString(),
|
||||
total_pages = source.readInt(),
|
||||
rendered_pages = source.readInt(),
|
||||
next_page_url = source.readString()
|
||||
)
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
@ -10,13 +10,13 @@ internal class BooleanTypeAdapter : JsonDeserializer<Boolean> {
|
||||
|
||||
@Throws(JsonParseException::class)
|
||||
override fun deserialize(
|
||||
json: JsonElement,
|
||||
typeOfT: Type,
|
||||
context: JsonDeserializationContext
|
||||
json: JsonElement,
|
||||
typeOfT: Type,
|
||||
context: JsonDeserializationContext
|
||||
): Boolean? =
|
||||
try {
|
||||
json.asInt == 1
|
||||
} catch (e: Exception) {
|
||||
json.asBoolean
|
||||
}
|
||||
try {
|
||||
json.asInt == 1
|
||||
} catch (e: Exception) {
|
||||
json.asBoolean
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class SelfossApi(
|
||||
c: Context,
|
||||
callingActivity: Activity,
|
||||
isWithSelfSignedCert: Boolean,
|
||||
shouldLog: Boolean
|
||||
c: Context,
|
||||
callingActivity: Activity,
|
||||
isWithSelfSignedCert: Boolean,
|
||||
shouldLog: Boolean
|
||||
) {
|
||||
|
||||
private lateinit var service: SelfossService
|
||||
@ -32,25 +32,25 @@ class SelfossApi(
|
||||
private val password: String
|
||||
|
||||
fun OkHttpClient.Builder.maybeWithSelfSigned(isWithSelfSignedCert: Boolean): OkHttpClient.Builder =
|
||||
if (isWithSelfSignedCert) {
|
||||
getUnsafeHttpClient()
|
||||
} else {
|
||||
this
|
||||
}
|
||||
if (isWithSelfSignedCert) {
|
||||
getUnsafeHttpClient()
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
fun Credentials.createAuthenticator(): DispatchingAuthenticator =
|
||||
DispatchingAuthenticator.Builder()
|
||||
.with("digest", DigestAuthenticator(this))
|
||||
.with("basic", BasicAuthenticator(this))
|
||||
.build()
|
||||
DispatchingAuthenticator.Builder()
|
||||
.with("digest", DigestAuthenticator(this))
|
||||
.with("basic", BasicAuthenticator(this))
|
||||
.build()
|
||||
|
||||
fun DispatchingAuthenticator.getHttpClien(isWithSelfSignedCert: Boolean): OkHttpClient.Builder {
|
||||
val authCache = ConcurrentHashMap<String, CachingAuthenticator>()
|
||||
return OkHttpClient
|
||||
.Builder()
|
||||
.maybeWithSelfSigned(isWithSelfSignedCert)
|
||||
.authenticator(CachingAuthenticatorDecorator(this, authCache))
|
||||
.addInterceptor(AuthenticationCacheInterceptor(authCache))
|
||||
.Builder()
|
||||
.maybeWithSelfSigned(isWithSelfSignedCert)
|
||||
.authenticator(CachingAuthenticatorDecorator(this, authCache))
|
||||
.addInterceptor(AuthenticationCacheInterceptor(authCache))
|
||||
}
|
||||
|
||||
init {
|
||||
@ -58,16 +58,16 @@ class SelfossApi(
|
||||
password = config.userPassword
|
||||
|
||||
val authenticator =
|
||||
Credentials(
|
||||
config.httpUserLogin,
|
||||
config.httpUserPassword
|
||||
).createAuthenticator()
|
||||
Credentials(
|
||||
config.httpUserLogin,
|
||||
config.httpUserPassword
|
||||
).createAuthenticator()
|
||||
|
||||
val gson =
|
||||
GsonBuilder()
|
||||
.registerTypeAdapter(Boolean::class.javaPrimitiveType, BooleanTypeAdapter())
|
||||
.setLenient()
|
||||
.create()
|
||||
GsonBuilder()
|
||||
.registerTypeAdapter(Boolean::class.javaPrimitiveType, BooleanTypeAdapter())
|
||||
.setLenient()
|
||||
.create()
|
||||
|
||||
val logging = HttpLoggingInterceptor()
|
||||
|
||||
@ -83,12 +83,12 @@ class SelfossApi(
|
||||
|
||||
try {
|
||||
val retrofit =
|
||||
Retrofit
|
||||
.Builder()
|
||||
.baseUrl(config.baseUrl)
|
||||
.client(httpClient.build())
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
Retrofit
|
||||
.Builder()
|
||||
.baseUrl(config.baseUrl)
|
||||
.client(httpClient.build())
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
service = retrofit.create(SelfossService::class.java)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Config.logoutAndRedirect(c, callingActivity, config.settings.edit(), baseUrlFail = true)
|
||||
@ -96,59 +96,59 @@ class SelfossApi(
|
||||
}
|
||||
|
||||
fun login(): Call<SuccessResponse> =
|
||||
service.loginToSelfoss(config.userLogin, config.userPassword)
|
||||
service.loginToSelfoss(config.userLogin, config.userPassword)
|
||||
|
||||
fun readItems(
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
itemsNumber: Int,
|
||||
offset: Int
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
itemsNumber: Int,
|
||||
offset: Int
|
||||
): Call<List<Item>> =
|
||||
getItems("read", tag, sourceId, search, itemsNumber, offset)
|
||||
getItems("read", tag, sourceId, search, itemsNumber, offset)
|
||||
|
||||
fun newItems(
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
itemsNumber: Int,
|
||||
offset: Int
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
itemsNumber: Int,
|
||||
offset: Int
|
||||
): Call<List<Item>> =
|
||||
getItems("unread", tag, sourceId, search, itemsNumber, offset)
|
||||
getItems("unread", tag, sourceId, search, itemsNumber, offset)
|
||||
|
||||
fun starredItems(
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
itemsNumber: Int,
|
||||
offset: Int
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
itemsNumber: Int,
|
||||
offset: Int
|
||||
): Call<List<Item>> =
|
||||
getItems("starred", tag, sourceId, search, itemsNumber, offset)
|
||||
getItems("starred", tag, sourceId, search, itemsNumber, offset)
|
||||
|
||||
private fun getItems(
|
||||
type: String,
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
items: Int,
|
||||
offset: Int
|
||||
type: String,
|
||||
tag: String?,
|
||||
sourceId: Long?,
|
||||
search: String?,
|
||||
items: Int,
|
||||
offset: Int
|
||||
): Call<List<Item>> =
|
||||
service.getItems(type, tag, sourceId, search, userName, password, items, offset)
|
||||
service.getItems(type, tag, sourceId, search, userName, password, items, offset)
|
||||
|
||||
fun markItem(itemId: String): Call<SuccessResponse> =
|
||||
service.markAsRead(itemId, userName, password)
|
||||
service.markAsRead(itemId, userName, password)
|
||||
|
||||
fun unmarkItem(itemId: String): Call<SuccessResponse> =
|
||||
service.unmarkAsRead(itemId, userName, password)
|
||||
service.unmarkAsRead(itemId, userName, password)
|
||||
|
||||
fun readAll(ids: List<String>): Call<SuccessResponse> =
|
||||
service.markAllAsRead(ids, userName, password)
|
||||
service.markAllAsRead(ids, userName, password)
|
||||
|
||||
fun starrItem(itemId: String): Call<SuccessResponse> =
|
||||
service.starr(itemId, userName, password)
|
||||
service.starr(itemId, userName, password)
|
||||
|
||||
fun unstarrItem(itemId: String): Call<SuccessResponse> =
|
||||
service.unstarr(itemId, userName, password)
|
||||
service.unstarr(itemId, userName, password)
|
||||
|
||||
val stats: Call<Stats>
|
||||
get() = service.stats(userName, password)
|
||||
@ -157,23 +157,23 @@ class SelfossApi(
|
||||
get() = service.tags(userName, password)
|
||||
|
||||
fun update(): Call<String> =
|
||||
service.update(userName, password)
|
||||
service.update(userName, password)
|
||||
|
||||
val sources: Call<List<Sources>>
|
||||
get() = service.sources(userName, password)
|
||||
|
||||
fun deleteSource(id: String): Call<SuccessResponse> =
|
||||
service.deleteSource(id, userName, password)
|
||||
service.deleteSource(id, userName, password)
|
||||
|
||||
fun spouts(): Call<Map<String, Spout>> =
|
||||
service.spouts(userName, password)
|
||||
service.spouts(userName, password)
|
||||
|
||||
fun createSource(
|
||||
title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
tags: String,
|
||||
filter: String
|
||||
title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
tags: String,
|
||||
filter: String
|
||||
): Call<SuccessResponse> =
|
||||
service.createSource(title, url, spout, tags, filter, userName, password)
|
||||
service.createSource(title, url, spout, tags, filter, userName, password)
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ private fun constructUrl(config: Config?, path: String, file: String): String {
|
||||
}
|
||||
|
||||
data class Tag(
|
||||
@SerializedName("tag") val tag: String,
|
||||
@SerializedName("color") val color: String,
|
||||
@SerializedName("unread") val unread: Int
|
||||
@SerializedName("tag") val tag: String,
|
||||
@SerializedName("color") val color: String,
|
||||
@SerializedName("unread") val unread: Int
|
||||
)
|
||||
|
||||
class SuccessResponse(@SerializedName("success") val success: Boolean) {
|
||||
@ -32,23 +32,23 @@ class SuccessResponse(@SerializedName("success") val success: Boolean) {
|
||||
}
|
||||
|
||||
class Stats(
|
||||
@SerializedName("total") val total: Int,
|
||||
@SerializedName("unread") val unread: Int,
|
||||
@SerializedName("starred") val starred: Int
|
||||
@SerializedName("total") val total: Int,
|
||||
@SerializedName("unread") val unread: Int,
|
||||
@SerializedName("starred") val starred: Int
|
||||
)
|
||||
|
||||
data class Spout(
|
||||
@SerializedName("name") val name: String,
|
||||
@SerializedName("description") val description: String
|
||||
@SerializedName("name") val name: String,
|
||||
@SerializedName("description") val description: String
|
||||
)
|
||||
|
||||
data class Sources(
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("tags") val tags: String,
|
||||
@SerializedName("spout") val spout: String,
|
||||
@SerializedName("error") val error: String,
|
||||
@SerializedName("icon") val icon: String
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("tags") val tags: String,
|
||||
@SerializedName("spout") val spout: String,
|
||||
@SerializedName("error") val error: String,
|
||||
@SerializedName("icon") val icon: String
|
||||
) {
|
||||
var config: Config? = null
|
||||
|
||||
@ -61,16 +61,16 @@ data class Sources(
|
||||
}
|
||||
|
||||
data class Item(
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("datetime") val datetime: String,
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("content") val content: String,
|
||||
@SerializedName("unread") val unread: Boolean,
|
||||
@SerializedName("starred") var starred: Boolean,
|
||||
@SerializedName("thumbnail") val thumbnail: String,
|
||||
@SerializedName("icon") val icon: String,
|
||||
@SerializedName("link") val link: String,
|
||||
@SerializedName("sourcetitle") val sourcetitle: String
|
||||
@SerializedName("id") val id: String,
|
||||
@SerializedName("datetime") val datetime: String,
|
||||
@SerializedName("title") val title: String,
|
||||
@SerializedName("content") val content: String,
|
||||
@SerializedName("unread") val unread: Boolean,
|
||||
@SerializedName("starred") var starred: Boolean,
|
||||
@SerializedName("thumbnail") val thumbnail: String,
|
||||
@SerializedName("icon") val icon: String,
|
||||
@SerializedName("link") val link: String,
|
||||
@SerializedName("sourcetitle") val sourcetitle: String
|
||||
) : Parcelable {
|
||||
|
||||
var config: Config? = null
|
||||
@ -83,16 +83,16 @@ data class Item(
|
||||
}
|
||||
|
||||
constructor(source: Parcel) : this(
|
||||
id = source.readString(),
|
||||
datetime = source.readString(),
|
||||
title = source.readString(),
|
||||
content = source.readString(),
|
||||
unread = 0.toByte() != source.readByte(),
|
||||
starred = 0.toByte() != source.readByte(),
|
||||
thumbnail = source.readString(),
|
||||
icon = source.readString(),
|
||||
link = source.readString(),
|
||||
sourcetitle = source.readString()
|
||||
id = source.readString(),
|
||||
datetime = source.readString(),
|
||||
title = source.readString(),
|
||||
content = source.readString(),
|
||||
unread = 0.toByte() != source.readByte(),
|
||||
starred = 0.toByte() != source.readByte(),
|
||||
thumbnail = source.readString(),
|
||||
icon = source.readString(),
|
||||
link = source.readString(),
|
||||
sourcetitle = source.readString()
|
||||
)
|
||||
|
||||
override fun describeContents() = 0
|
||||
@ -127,15 +127,16 @@ data class Item(
|
||||
// TODO: maybe find a better way to handle these kind of urls
|
||||
fun getLinkDecoded(): String {
|
||||
var stringUrl: String
|
||||
stringUrl = if (link.startsWith("http://news.google.com/news/") || link.startsWith("https://news.google.com/news/")) {
|
||||
if (link.contains("&url=")) {
|
||||
link.substringAfter("&url=")
|
||||
} else {
|
||||
this.link.replace("&", "&")
|
||||
}
|
||||
} else {
|
||||
this.link.replace("&", "&")
|
||||
}
|
||||
stringUrl =
|
||||
if (link.startsWith("http://news.google.com/news/") || link.startsWith("https://news.google.com/news/")) {
|
||||
if (link.contains("&url=")) {
|
||||
link.substringAfter("&url=")
|
||||
} else {
|
||||
this.link.replace("&", "&")
|
||||
}
|
||||
} else {
|
||||
this.link.replace("&", "&")
|
||||
}
|
||||
|
||||
// handle :443 => https
|
||||
if (stringUrl.contains(":443")) {
|
||||
|
@ -17,102 +17,102 @@ internal interface SelfossService {
|
||||
|
||||
@GET("items")
|
||||
fun getItems(
|
||||
@Query("type") type: String,
|
||||
@Query("tag") tag: String?,
|
||||
@Query("source") source: Long?,
|
||||
@Query("search") search: String?,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String,
|
||||
@Query("items") items: Int,
|
||||
@Query("offset") offset: Int
|
||||
@Query("type") type: String,
|
||||
@Query("tag") tag: String?,
|
||||
@Query("source") source: Long?,
|
||||
@Query("search") search: String?,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String,
|
||||
@Query("items") items: Int,
|
||||
@Query("offset") offset: Int
|
||||
): Call<List<Item>>
|
||||
|
||||
@Headers("Content-Type: application/x-www-form-urlencoded")
|
||||
@POST("mark/{id}")
|
||||
fun markAsRead(
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
|
||||
@Headers("Content-Type: application/x-www-form-urlencoded")
|
||||
@POST("unmark/{id}")
|
||||
fun unmarkAsRead(
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("mark")
|
||||
fun markAllAsRead(
|
||||
@Field("ids[]") ids: List<String>,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Field("ids[]") ids: List<String>,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
|
||||
@Headers("Content-Type: application/x-www-form-urlencoded")
|
||||
@POST("starr/{id}")
|
||||
fun starr(
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
|
||||
@Headers("Content-Type: application/x-www-form-urlencoded")
|
||||
@POST("unstarr/{id}")
|
||||
fun unstarr(
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
|
||||
@GET("stats")
|
||||
fun stats(
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<Stats>
|
||||
|
||||
@GET("tags")
|
||||
fun tags(
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<List<Tag>>
|
||||
|
||||
@GET("update")
|
||||
fun update(
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<String>
|
||||
|
||||
@GET("sources/spouts")
|
||||
fun spouts(
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<Map<String, Spout>>
|
||||
|
||||
@GET("sources/list")
|
||||
fun sources(
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<List<Sources>>
|
||||
|
||||
@DELETE("source/{id}")
|
||||
fun deleteSource(
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Path("id") id: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("source")
|
||||
fun createSource(
|
||||
@Field("title") title: String,
|
||||
@Field("url") url: String,
|
||||
@Field("spout") spout: String,
|
||||
@Field("tags") tags: String,
|
||||
@Field("filter") filter: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
@Field("title") title: String,
|
||||
@Field("url") url: String,
|
||||
@Field("spout") spout: String,
|
||||
@Field("tags") tags: String,
|
||||
@Field("filter") filter: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ import android.support.design.widget.FloatingActionButton
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.widget.NestedScrollView
|
||||
import android.text.Html
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
@ -33,7 +31,6 @@ import com.crashlytics.android.Crashlytics
|
||||
import com.ftinc.scoop.Scoop
|
||||
import com.github.rubensousa.floatingtoolbar.FloatingToolbar
|
||||
import kotlinx.android.synthetic.main.fragment_article.view.*
|
||||
import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
@ -65,12 +62,12 @@ class ArticleFragment : Fragment() {
|
||||
private lateinit var rootView: ViewGroup
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
rootView = inflater
|
||||
.inflate(R.layout.fragment_article, container, false) as ViewGroup
|
||||
.inflate(R.layout.fragment_article, container, false) as ViewGroup
|
||||
|
||||
url = allItems[pageNumber.toInt()].getLinkDecoded()
|
||||
contentText = allItems[pageNumber.toInt()].content
|
||||
@ -89,27 +86,27 @@ class ArticleFragment : Fragment() {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
|
||||
mFloatingToolbar.setClickListener(
|
||||
object : FloatingToolbar.ItemClickListener {
|
||||
override fun onItemClick(item: MenuItem) {
|
||||
when (item.itemId) {
|
||||
R.id.more_action -> getContentFromMercury(customTabsIntent, prefs)
|
||||
R.id.share_action -> activity!!.shareLink(url)
|
||||
R.id.open_action -> activity!!.openItemUrl(
|
||||
allItems,
|
||||
pageNumber.toInt(),
|
||||
url,
|
||||
customTabsIntent,
|
||||
false,
|
||||
false,
|
||||
activity!!
|
||||
)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemLongClick(item: MenuItem?) {
|
||||
object : FloatingToolbar.ItemClickListener {
|
||||
override fun onItemClick(item: MenuItem) {
|
||||
when (item.itemId) {
|
||||
R.id.more_action -> getContentFromMercury(customTabsIntent, prefs)
|
||||
R.id.share_action -> activity!!.shareLink(url)
|
||||
R.id.open_action -> activity!!.openItemUrl(
|
||||
allItems,
|
||||
pageNumber.toInt(),
|
||||
url,
|
||||
customTabsIntent,
|
||||
false,
|
||||
false,
|
||||
activity!!
|
||||
)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemLongClick(item: MenuItem?) {
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -124,149 +121,153 @@ class ArticleFragment : Fragment() {
|
||||
if (!contentImage.isEmptyOrNullOrNullString()) {
|
||||
rootView.imageView.visibility = View.VISIBLE
|
||||
Glide
|
||||
.with(activity!!.baseContext)
|
||||
.asBitmap()
|
||||
.load(contentImage)
|
||||
.apply(RequestOptions.fitCenterTransform())
|
||||
.into(rootView.imageView)
|
||||
.with(activity!!.baseContext)
|
||||
.asBitmap()
|
||||
.load(contentImage)
|
||||
.apply(RequestOptions.fitCenterTransform())
|
||||
.into(rootView.imageView)
|
||||
} else {
|
||||
rootView.imageView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
rootView.nestedScrollView.setOnScrollChangeListener(
|
||||
NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||
if (scrollY > oldScrollY) {
|
||||
fab.hide()
|
||||
} else {
|
||||
if (mFloatingToolbar.isShowing) mFloatingToolbar.hide() else fab.show()
|
||||
}
|
||||
NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||
if (scrollY > oldScrollY) {
|
||||
fab.hide()
|
||||
} else {
|
||||
if (mFloatingToolbar.isShowing) mFloatingToolbar.hide() else fab.show()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return rootView
|
||||
}
|
||||
|
||||
private fun getContentFromMercury(
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
prefs: SharedPreferences
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
prefs: SharedPreferences
|
||||
) {
|
||||
rootView.progressBar.visibility = View.VISIBLE
|
||||
val parser = MercuryApi(
|
||||
BuildConfig.MERCURY_KEY,
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
BuildConfig.MERCURY_KEY,
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
|
||||
parser.parseUrl(url).enqueue(
|
||||
object : Callback<ParsedContent> {
|
||||
override fun onResponse(
|
||||
call: Call<ParsedContent>,
|
||||
response: Response<ParsedContent>
|
||||
) {
|
||||
// TODO: clean all the following after finding the mercury content issue
|
||||
try {
|
||||
if (response.body() != null && response.body()!!.content != null && !response.body()!!.content.isNullOrEmpty()) {
|
||||
try {
|
||||
rootView.source.text = response.body()!!.domain
|
||||
rootView.titleView.text = response.body()!!.title
|
||||
url = response.body()!!.url
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"source titleView or url issues"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
|
||||
try {
|
||||
htmlToWebview(response.body()!!.content.orEmpty(), prefs)
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Webview issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
|
||||
try {
|
||||
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty()) {
|
||||
rootView.imageView.visibility = View.VISIBLE
|
||||
try {
|
||||
Glide
|
||||
.with(activity!!.baseContext)
|
||||
.asBitmap()
|
||||
.load(response.body()!!.lead_image_url)
|
||||
.apply(RequestOptions.fitCenterTransform())
|
||||
.into(rootView.imageView)
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Glide issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
} else {
|
||||
rootView.imageView.visibility = View.GONE
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Glide or image issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
|
||||
try {
|
||||
rootView.nestedScrollView.scrollTo(0, 0)
|
||||
|
||||
rootView.progressBar.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Scroll or visibility issues"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
openInBrowserAfterFailing(customTabsIntent)
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Browser after failing issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
object : Callback<ParsedContent> {
|
||||
override fun onResponse(
|
||||
call: Call<ParsedContent>,
|
||||
response: Response<ParsedContent>
|
||||
) {
|
||||
// TODO: clean all the following after finding the mercury content issue
|
||||
try {
|
||||
if (response.body() != null && response.body()!!.content != null && !response.body()!!.content.isNullOrEmpty()) {
|
||||
try {
|
||||
rootView.source.text = response.body()!!.domain
|
||||
rootView.titleView.text = response.body()!!.title
|
||||
url = response.body()!!.url
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"UNCAUGHT (?) Fatal Exception on mercury response"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
"source titleView or url issues"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
|
||||
try {
|
||||
htmlToWebview(response.body()!!.content.orEmpty(), prefs)
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Webview issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
|
||||
try {
|
||||
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty()) {
|
||||
rootView.imageView.visibility = View.VISIBLE
|
||||
try {
|
||||
Glide
|
||||
.with(activity!!.baseContext)
|
||||
.asBitmap()
|
||||
.load(response.body()!!.lead_image_url)
|
||||
.apply(RequestOptions.fitCenterTransform())
|
||||
.into(rootView.imageView)
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(
|
||||
prefs.getString(
|
||||
"unique_id",
|
||||
""
|
||||
)
|
||||
)
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Glide issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
} else {
|
||||
rootView.imageView.visibility = View.GONE
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Glide or image issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
|
||||
try {
|
||||
rootView.nestedScrollView.scrollTo(0, 0)
|
||||
|
||||
rootView.progressBar.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Scroll or visibility issues"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
openInBrowserAfterFailing(customTabsIntent)
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"Browser after failing issue"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"MERCURY_CONTENT_EXCEPTION",
|
||||
"UNCAUGHT (?) Fatal Exception on mercury response"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<ParsedContent>,
|
||||
t: Throwable
|
||||
) = openInBrowserAfterFailing(customTabsIntent)
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call<ParsedContent>,
|
||||
t: Throwable
|
||||
) = openInBrowserAfterFailing(customTabsIntent)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -277,10 +278,20 @@ class ArticleFragment : Fragment() {
|
||||
|
||||
rootView.webcontent.visibility = View.VISIBLE
|
||||
val textColor = if (Scoop.getInstance().currentFlavor.isDayNight) {
|
||||
rootView.webcontent.setBackgroundColor(ContextCompat.getColor(activity!!.baseContext, R.color.dark_webview))
|
||||
rootView.webcontent.setBackgroundColor(
|
||||
ContextCompat.getColor(
|
||||
activity!!.baseContext,
|
||||
R.color.dark_webview
|
||||
)
|
||||
)
|
||||
ContextCompat.getColor(activity!!.baseContext, R.color.dark_webview_text)
|
||||
} else {
|
||||
rootView.webcontent.setBackgroundColor(ContextCompat.getColor(activity!!.baseContext, R.color.light_webview))
|
||||
rootView.webcontent.setBackgroundColor(
|
||||
ContextCompat.getColor(
|
||||
activity!!.baseContext,
|
||||
R.color.light_webview
|
||||
)
|
||||
)
|
||||
ContextCompat.getColor(activity!!.baseContext, R.color.light_webview_text)
|
||||
}
|
||||
|
||||
@ -291,7 +302,8 @@ class ArticleFragment : Fragment() {
|
||||
rootView.webcontent.settings.javaScriptEnabled = false
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
rootView.webcontent.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
||||
rootView.webcontent.settings.layoutAlgorithm =
|
||||
WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
||||
} else {
|
||||
rootView.webcontent.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
|
||||
}
|
||||
@ -308,24 +320,24 @@ class ArticleFragment : Fragment() {
|
||||
}
|
||||
|
||||
rootView.webcontent.loadDataWithBaseURL(
|
||||
baseUrl,
|
||||
"<style>img{display: inline-block;height: auto; width: 100%; max-width: 100%;} a{color: $stringColor;} *:not(a){color: $stringTextColor;}</style>$c",
|
||||
"text/html; charset=utf-8",
|
||||
"utf-8",
|
||||
null
|
||||
baseUrl,
|
||||
"<style>img{display: inline-block;height: auto; width: 100%; max-width: 100%;} a{color: $stringColor;} *:not(a){color: $stringTextColor;}</style>$c",
|
||||
"text/html; charset=utf-8",
|
||||
"utf-8",
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) {
|
||||
rootView.progressBar.visibility = View.GONE
|
||||
activity!!.openItemUrl(
|
||||
allItems,
|
||||
pageNumber.toInt(),
|
||||
url,
|
||||
customTabsIntent,
|
||||
true,
|
||||
false,
|
||||
activity!!
|
||||
allItems,
|
||||
pageNumber.toInt(),
|
||||
url,
|
||||
customTabsIntent,
|
||||
true,
|
||||
false,
|
||||
activity!!
|
||||
)
|
||||
}
|
||||
|
||||
@ -334,8 +346,8 @@ class ArticleFragment : Fragment() {
|
||||
private val ARG_ITEMS = "items"
|
||||
|
||||
fun newInstance(
|
||||
position: Int,
|
||||
allItems: ArrayList<Item>
|
||||
position: Int,
|
||||
allItems: ArrayList<Item>
|
||||
): ArticleFragment {
|
||||
val fragment = ArticleFragment()
|
||||
val args = Bundle()
|
||||
|
@ -16,9 +16,10 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import apps.amine.bou.readerforselfoss.R;
|
||||
import com.ftinc.scoop.Scoop;
|
||||
|
||||
import apps.amine.bou.readerforselfoss.R;
|
||||
|
||||
|
||||
/**
|
||||
* A {@link PreferenceActivity} which implements and proxies the necessary calls
|
||||
@ -40,7 +41,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
|
||||
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
|
||||
AppBarLayout bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
|
||||
Toolbar toolbar = bar.findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
@ -1,8 +1,6 @@
|
||||
package apps.amine.bou.readerforselfoss.settings;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
@ -27,10 +25,13 @@ import android.text.Spanned;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.ftinc.scoop.ui.ScoopSettingsActivity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import apps.amine.bou.readerforselfoss.BuildConfig;
|
||||
import apps.amine.bou.readerforselfoss.R;
|
||||
import apps.amine.bou.readerforselfoss.utils.Config;
|
||||
import com.ftinc.scoop.ui.ScoopSettingsActivity;
|
||||
|
||||
|
||||
/**
|
||||
@ -150,7 +151,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
final SwitchPreference tabOnTap = (SwitchPreference) findPreference("tab_on_tap");
|
||||
tabOnTap.setEnabled(!cardViewActive.isChecked());
|
||||
cardViewActive.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue){
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean isEnabled = (Boolean) newValue;
|
||||
tabOnTap.setEnabled(!isEnabled);
|
||||
return true;
|
||||
@ -159,20 +160,20 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
EditTextPreference itemsNumber = (EditTextPreference) findPreference("prefer_api_items_number");
|
||||
itemsNumber.getEditText().setFilters(new InputFilter[]{
|
||||
new InputFilter (){
|
||||
new InputFilter() {
|
||||
|
||||
@Override
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
try {
|
||||
int input = Integer.parseInt(dest.toString() + source.toString());
|
||||
if (input <= 200 && input >0)
|
||||
return null;
|
||||
} catch (NumberFormatException nfe) {
|
||||
Toast.makeText(getActivity(), R.string.items_number_should_be_number, Toast.LENGTH_LONG).show();
|
||||
@Override
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
try {
|
||||
int input = Integer.parseInt(dest.toString() + source.toString());
|
||||
if (input <= 200 && input > 0)
|
||||
return null;
|
||||
} catch (NumberFormatException nfe) {
|
||||
Toast.makeText(getActivity(), R.string.items_number_should_be_number, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -243,7 +244,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
addPreferencesFromResource(R.xml.pref_links);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
findPreference( "trackerLink" ).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
findPreference("trackerLink").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
openUrl(Uri.parse(BuildConfig.TRACKER_URL));
|
||||
|
@ -4,4 +4,4 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||
import retrofit2.Response
|
||||
|
||||
fun Response<SuccessResponse>.succeeded(): Boolean =
|
||||
this.code() === 200 && this.body() != null && this.body()!!.isSuccess
|
||||
this.code() === 200 && this.body() != null && this.body()!!.isSuccess
|
@ -9,12 +9,12 @@ import apps.amine.bou.readerforselfoss.R
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
|
||||
|
||||
fun String?.isEmptyOrNullOrNullString(): Boolean =
|
||||
this == null || this == "null" || this.isEmpty()
|
||||
this == null || this == "null" || this.isEmpty()
|
||||
|
||||
fun Context.checkApkVersion(
|
||||
settings: SharedPreferences,
|
||||
editor: SharedPreferences.Editor,
|
||||
mFirebaseRemoteConfig: FirebaseRemoteConfig
|
||||
settings: SharedPreferences,
|
||||
editor: SharedPreferences.Editor,
|
||||
mFirebaseRemoteConfig: FirebaseRemoteConfig
|
||||
) = {
|
||||
fun isThereAnUpdate() {
|
||||
val APK_LINK = "github_apk"
|
||||
@ -26,8 +26,8 @@ fun Context.checkApkVersion(
|
||||
alertDialog.setTitle(getString(R.string.new_apk_available_title))
|
||||
alertDialog.setMessage(getString(R.string.new_apk_available_message))
|
||||
alertDialog.setButton(
|
||||
AlertDialog.BUTTON_POSITIVE,
|
||||
getString(R.string.new_apk_available_get)
|
||||
AlertDialog.BUTTON_POSITIVE,
|
||||
getString(R.string.new_apk_available_get)
|
||||
) { _, _ ->
|
||||
editor.putString(APK_LINK, apkLink)
|
||||
editor.apply()
|
||||
@ -35,25 +35,25 @@ fun Context.checkApkVersion(
|
||||
startActivity(browserIntent)
|
||||
}
|
||||
alertDialog.setButton(
|
||||
AlertDialog.BUTTON_NEUTRAL, getString(R.string.new_apk_available_no),
|
||||
{ dialog, _ ->
|
||||
editor.putString(APK_LINK, apkLink)
|
||||
editor.apply()
|
||||
dialog.dismiss()
|
||||
}
|
||||
AlertDialog.BUTTON_NEUTRAL, getString(R.string.new_apk_available_no),
|
||||
{ dialog, _ ->
|
||||
editor.putString(APK_LINK, apkLink)
|
||||
editor.apply()
|
||||
dialog.dismiss()
|
||||
}
|
||||
)
|
||||
alertDialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
mFirebaseRemoteConfig.fetch(43200)
|
||||
.addOnCompleteListener { task ->
|
||||
if (task.isSuccessful) {
|
||||
mFirebaseRemoteConfig.activateFetched()
|
||||
}
|
||||
|
||||
isThereAnUpdate()
|
||||
.addOnCompleteListener { task ->
|
||||
if (task.isSuccessful) {
|
||||
mFirebaseRemoteConfig.activateFetched()
|
||||
}
|
||||
|
||||
isThereAnUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
fun String.longHash(): Long {
|
||||
@ -68,11 +68,11 @@ fun String.longHash(): Long {
|
||||
}
|
||||
|
||||
fun String.toStringUriWithHttp(): String =
|
||||
if (!this.startsWith("https://") && !this.startsWith("http://")) {
|
||||
"http://" + this
|
||||
} else {
|
||||
this
|
||||
}
|
||||
if (!this.startsWith("https://") && !this.startsWith("http://")) {
|
||||
"http://" + this
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
fun Context.shareLink(itemUrl: String) {
|
||||
val sendIntent = Intent()
|
||||
@ -81,9 +81,9 @@ fun Context.shareLink(itemUrl: String) {
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, itemUrl.toStringUriWithHttp())
|
||||
sendIntent.type = "text/plain"
|
||||
startActivity(
|
||||
Intent.createChooser(
|
||||
sendIntent,
|
||||
getString(R.string.share)
|
||||
).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
Intent.createChooser(
|
||||
sendIntent,
|
||||
getString(R.string.share)
|
||||
).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
)
|
||||
}
|
@ -29,10 +29,10 @@ class Config(c: Context) {
|
||||
val settingsName = "paramsselfoss"
|
||||
|
||||
fun logoutAndRedirect(
|
||||
c: Context,
|
||||
callingActivity: Activity,
|
||||
editor: SharedPreferences.Editor,
|
||||
baseUrlFail: Boolean = false
|
||||
c: Context,
|
||||
callingActivity: Activity,
|
||||
editor: SharedPreferences.Editor,
|
||||
baseUrlFail: Boolean = false
|
||||
): Boolean {
|
||||
editor.remove("url")
|
||||
editor.remove("login")
|
||||
|
@ -8,36 +8,36 @@ import javax.net.ssl.TrustManager
|
||||
import javax.net.ssl.X509TrustManager
|
||||
|
||||
fun getUnsafeHttpClient() =
|
||||
try {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
||||
override fun getAcceptedIssuers(): Array<X509Certificate> =
|
||||
arrayOf()
|
||||
try {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
||||
override fun getAcceptedIssuers(): Array<X509Certificate> =
|
||||
arrayOf()
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkClientTrusted(
|
||||
chain: Array<java.security.cert.X509Certificate>,
|
||||
authType: String
|
||||
) {
|
||||
}
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkClientTrusted(
|
||||
chain: Array<java.security.cert.X509Certificate>,
|
||||
authType: String
|
||||
) {
|
||||
}
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkServerTrusted(
|
||||
chain: Array<java.security.cert.X509Certificate>,
|
||||
authType: String
|
||||
) {
|
||||
}
|
||||
})
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkServerTrusted(
|
||||
chain: Array<java.security.cert.X509Certificate>,
|
||||
authType: String
|
||||
) {
|
||||
}
|
||||
})
|
||||
|
||||
// Install the all-trusting trust manager
|
||||
val sslContext = SSLContext.getInstance("SSL")
|
||||
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
||||
// Install the all-trusting trust manager
|
||||
val sslContext = SSLContext.getInstance("SSL")
|
||||
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
||||
|
||||
val sslSocketFactory = sslContext.socketFactory
|
||||
val sslSocketFactory = sslContext.socketFactory
|
||||
|
||||
OkHttpClient.Builder()
|
||||
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
||||
.hostnameVerifier { _, _ -> true }
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
OkHttpClient.Builder()
|
||||
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
||||
.hostnameVerifier { _, _ -> true }
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
}
|
@ -13,7 +13,11 @@ fun String.toTextDrawableString(): String {
|
||||
try {
|
||||
textDrawable.append(s[0])
|
||||
} catch (e: StringIndexOutOfBoundsException) {
|
||||
Crashlytics.log(100, "TEXT_DRAWABLE_INDEX_OUT_OF_BOUND", this + " produces ${e.message}")
|
||||
Crashlytics.log(
|
||||
100,
|
||||
"TEXT_DRAWABLE_INDEX_OUT_OF_BOUND",
|
||||
this + " produces ${e.message}"
|
||||
)
|
||||
Crashlytics.logException(e)
|
||||
}
|
||||
}
|
||||
@ -23,10 +27,10 @@ fun String.toTextDrawableString(): String {
|
||||
fun Item.sourceAndDateText(): String {
|
||||
val formattedDate: String = try {
|
||||
" " + DateUtils.getRelativeTimeSpanString(
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(this.datetime).time,
|
||||
Date().time,
|
||||
DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(this.datetime).time,
|
||||
Date().time,
|
||||
DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||
)
|
||||
} catch (e: ParseException) {
|
||||
e.printStackTrace()
|
||||
|
@ -20,10 +20,10 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent {
|
||||
val actionIntent = Intent(Intent.ACTION_SEND)
|
||||
actionIntent.type = "text/plain"
|
||||
val createPendingShareIntent: PendingIntent = PendingIntent.getActivity(
|
||||
this,
|
||||
0,
|
||||
actionIntent,
|
||||
0
|
||||
this,
|
||||
0,
|
||||
actionIntent,
|
||||
0
|
||||
)
|
||||
|
||||
val intentBuilder = CustomTabsIntent.Builder()
|
||||
@ -35,14 +35,14 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent {
|
||||
|
||||
|
||||
intentBuilder.setStartAnimations(
|
||||
this,
|
||||
R.anim.slide_in_right,
|
||||
R.anim.slide_out_left
|
||||
this,
|
||||
R.anim.slide_in_right,
|
||||
R.anim.slide_out_left
|
||||
)
|
||||
intentBuilder.setExitAnimations(
|
||||
this,
|
||||
android.R.anim.slide_in_left,
|
||||
android.R.anim.slide_out_right
|
||||
this,
|
||||
android.R.anim.slide_in_left,
|
||||
android.R.anim.slide_out_right
|
||||
)
|
||||
|
||||
val closeicon = BitmapFactory.decodeResource(resources, R.drawable.ic_close_white_24dp)
|
||||
@ -50,8 +50,8 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent {
|
||||
|
||||
val shareLabel = this.getString(R.string.label_share)
|
||||
val icon = BitmapFactory.decodeResource(
|
||||
resources,
|
||||
R.drawable.ic_share_white_24dp
|
||||
resources,
|
||||
R.drawable.ic_share_white_24dp
|
||||
)
|
||||
intentBuilder.setActionButton(icon, shareLabel, createPendingShareIntent)
|
||||
|
||||
@ -59,12 +59,12 @@ fun Context.buildCustomTabsIntent(): CustomTabsIntent {
|
||||
}
|
||||
|
||||
fun Context.openItemUrlInternally(
|
||||
allItems: ArrayList<Item>,
|
||||
currentItem: Int,
|
||||
linkDecoded: String,
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
articleViewer: Boolean,
|
||||
app: Activity
|
||||
allItems: ArrayList<Item>,
|
||||
currentItem: Int,
|
||||
linkDecoded: String,
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
articleViewer: Boolean,
|
||||
app: Activity
|
||||
) {
|
||||
if (articleViewer) {
|
||||
ReaderActivity.allItems = allItems
|
||||
@ -74,9 +74,9 @@ fun Context.openItemUrlInternally(
|
||||
} else {
|
||||
try {
|
||||
CustomTabActivityHelper.openCustomTab(
|
||||
app,
|
||||
customTabsIntent,
|
||||
Uri.parse(linkDecoded)
|
||||
app,
|
||||
customTabsIntent,
|
||||
Uri.parse(linkDecoded)
|
||||
) { _, uri ->
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
@ -89,32 +89,32 @@ fun Context.openItemUrlInternally(
|
||||
}
|
||||
|
||||
fun Context.openItemUrl(
|
||||
allItems: ArrayList<Item>,
|
||||
currentItem: Int,
|
||||
linkDecoded: String,
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
internalBrowser: Boolean,
|
||||
articleViewer: Boolean,
|
||||
app: Activity
|
||||
allItems: ArrayList<Item>,
|
||||
currentItem: Int,
|
||||
linkDecoded: String,
|
||||
customTabsIntent: CustomTabsIntent,
|
||||
internalBrowser: Boolean,
|
||||
articleViewer: Boolean,
|
||||
app: Activity
|
||||
) {
|
||||
|
||||
if (!linkDecoded.isUrlValid()) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
this.getString(R.string.cant_open_invalid_url),
|
||||
Toast.LENGTH_LONG
|
||||
this,
|
||||
this.getString(R.string.cant_open_invalid_url),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
} else {
|
||||
if (!internalBrowser) {
|
||||
openInBrowser(linkDecoded, app)
|
||||
} else {
|
||||
this.openItemUrlInternally(
|
||||
allItems,
|
||||
currentItem,
|
||||
linkDecoded,
|
||||
customTabsIntent,
|
||||
articleViewer,
|
||||
app
|
||||
allItems,
|
||||
currentItem,
|
||||
linkDecoded,
|
||||
customTabsIntent,
|
||||
articleViewer,
|
||||
app
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -127,7 +127,7 @@ private fun openInBrowser(linkDecoded: String, app: Activity) {
|
||||
}
|
||||
|
||||
fun String.isUrlValid(): Boolean =
|
||||
HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches()
|
||||
HttpUrl.parse(this) != null && Patterns.WEB_URL.matcher(this).matches()
|
||||
|
||||
fun String.isBaseUrlValid(): Boolean {
|
||||
val baseUrl = HttpUrl.parse(this)
|
||||
|
@ -7,37 +7,37 @@ import android.util.AttributeSet
|
||||
import android.view.View
|
||||
|
||||
class ScrollAwareFABBehavior(
|
||||
context: Context,
|
||||
attrs: AttributeSet
|
||||
context: Context,
|
||||
attrs: AttributeSet
|
||||
) : CoordinatorLayout.Behavior<FloatingActionButton>() {
|
||||
|
||||
override fun onStartNestedScroll(
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
child: FloatingActionButton,
|
||||
directTargetChild: View,
|
||||
target: View,
|
||||
nestedScrollAxes: Int
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
child: FloatingActionButton,
|
||||
directTargetChild: View,
|
||||
target: View,
|
||||
nestedScrollAxes: Int
|
||||
): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onNestedScroll(
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
child: FloatingActionButton,
|
||||
target: View,
|
||||
dxConsumed: Int,
|
||||
dyConsumed: Int,
|
||||
dxUnconsumed: Int,
|
||||
dyUnconsumed: Int
|
||||
coordinatorLayout: CoordinatorLayout,
|
||||
child: FloatingActionButton,
|
||||
target: View,
|
||||
dxConsumed: Int,
|
||||
dyConsumed: Int,
|
||||
dxUnconsumed: Int,
|
||||
dyUnconsumed: Int
|
||||
) {
|
||||
super.onNestedScroll(
|
||||
coordinatorLayout,
|
||||
child,
|
||||
target,
|
||||
dxConsumed,
|
||||
dyConsumed,
|
||||
dxUnconsumed,
|
||||
dyUnconsumed
|
||||
coordinatorLayout,
|
||||
child,
|
||||
target,
|
||||
dxConsumed,
|
||||
dyConsumed,
|
||||
dxUnconsumed,
|
||||
dyUnconsumed
|
||||
)
|
||||
if (dyConsumed > 0 && child.visibility == View.VISIBLE) {
|
||||
child.hide(object : FloatingActionButton.OnVisibilityChangedListener() {
|
||||
|
@ -9,4 +9,4 @@ fun TextBadgeItem.removeBadge(): TextBadgeItem {
|
||||
}
|
||||
|
||||
fun TextBadgeItem.maybeShow(): TextBadgeItem =
|
||||
if (this.isHidden) this.show() else this
|
||||
if (this.isHidden) this.show() else this
|
||||
|
@ -1,8 +1,6 @@
|
||||
package apps.amine.bou.readerforselfoss.utils.customtabs;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -11,6 +9,8 @@ import android.support.customtabs.CustomTabsIntent;
|
||||
import android.support.customtabs.CustomTabsServiceConnection;
|
||||
import android.support.customtabs.CustomTabsSession;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is a helper class to manage the connection to the Custom Tabs Service.
|
||||
*/
|
||||
@ -23,15 +23,15 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
||||
/**
|
||||
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
|
||||
*
|
||||
* @param activity The host activity.
|
||||
* @param activity The host activity.
|
||||
* @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
|
||||
* @param uri the Uri to be opened.
|
||||
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
|
||||
* @param uri the Uri to be opened.
|
||||
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
|
||||
*/
|
||||
public static void openCustomTab(Activity activity,
|
||||
CustomTabsIntent customTabsIntent,
|
||||
Uri uri,
|
||||
CustomTabFallback fallback) {
|
||||
CustomTabsIntent customTabsIntent,
|
||||
Uri uri,
|
||||
CustomTabFallback fallback) {
|
||||
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
|
||||
|
||||
//If we cant find a package name, it means theres no browser that supports
|
||||
@ -48,6 +48,7 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
||||
|
||||
/**
|
||||
* Unbinds the Activity from the Custom Tabs Service.
|
||||
*
|
||||
* @param activity the activity that is connected to the service.
|
||||
*/
|
||||
public void unbindCustomTabsService(Activity activity) {
|
||||
@ -74,6 +75,7 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
||||
|
||||
/**
|
||||
* Register a Callback to be called when connected or disconnected from the Custom Tabs Service.
|
||||
*
|
||||
* @param connectionCallback
|
||||
*/
|
||||
public void setConnectionCallback(ConnectionCallback connectionCallback) {
|
||||
@ -82,6 +84,7 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
||||
|
||||
/**
|
||||
* Binds the Activity to the Custom Tabs Service.
|
||||
*
|
||||
* @param activity the activity to be binded to the service.
|
||||
*/
|
||||
public void bindCustomTabsService(Activity activity) {
|
||||
@ -95,8 +98,8 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)}.
|
||||
* @return true if call to mayLaunchUrl was accepted.
|
||||
* @see {@link CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)}.
|
||||
*/
|
||||
public boolean mayLaunchUrl(Uri uri, Bundle extras, List<Bundle> otherLikelyBundles) {
|
||||
if (mClient == null) return false;
|
||||
@ -142,9 +145,8 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
||||
*/
|
||||
public interface CustomTabFallback {
|
||||
/**
|
||||
*
|
||||
* @param activity The Activity that wants to open the Uri.
|
||||
* @param uri The uri to be opened by the fallback.
|
||||
* @param uri The uri to be opened by the fallback.
|
||||
*/
|
||||
void openUri(Activity activity, Uri uri);
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package apps.amine.bou.readerforselfoss.utils.customtabs;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
@ -14,6 +11,9 @@ import android.support.customtabs.CustomTabsService;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import apps.amine.bou.readerforselfoss.utils.customtabs.helpers.KeepAliveService;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@ -28,7 +28,8 @@ class CustomTabsHelper {
|
||||
|
||||
private static String sPackageNameToUse;
|
||||
|
||||
private CustomTabsHelper() {}
|
||||
private CustomTabsHelper() {
|
||||
}
|
||||
|
||||
public static void addKeepAliveExtra(Context context, Intent intent) {
|
||||
Intent keepAliveIntent = new Intent().setClassName(
|
||||
@ -40,7 +41,7 @@ class CustomTabsHelper {
|
||||
* Goes through all apps that handle VIEW intents and have a warmup service. Picks
|
||||
* the one chosen by the user if there is one, otherwise makes a best effort to return a
|
||||
* valid package name.
|
||||
*
|
||||
* <p>
|
||||
* This is <strong>not</strong> threadsafe.
|
||||
*
|
||||
* @param context {@link Context} to use for accessing {@link PackageManager}.
|
||||
@ -94,6 +95,7 @@ class CustomTabsHelper {
|
||||
|
||||
/**
|
||||
* Used to check whether there is a specialized handler for a given intent.
|
||||
*
|
||||
* @param intent The intent to check with.
|
||||
* @return Whether there is a specialized handler for the given intent.
|
||||
*/
|
||||
|
@ -1,12 +1,12 @@
|
||||
package apps.amine.bou.readerforselfoss.utils.customtabs;
|
||||
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.support.customtabs.CustomTabsClient;
|
||||
import android.support.customtabs.CustomTabsServiceConnection;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Implementation for the CustomTabsServiceConnection that avoids leaking the
|
||||
* ServiceConnectionCallback
|
||||
|
@ -7,6 +7,7 @@ import android.support.customtabs.CustomTabsClient;
|
||||
public interface ServiceConnectionCallback {
|
||||
/**
|
||||
* Called when the service is connected.
|
||||
*
|
||||
* @param client a CustomTabsClient
|
||||
*/
|
||||
void onServiceConnected(CustomTabsClient client);
|
||||
|
@ -15,7 +15,8 @@ import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||
import com.mikepenz.materialdrawer.util.DrawerUIUtils
|
||||
import com.mikepenz.materialize.util.UIUtils
|
||||
|
||||
abstract class CustomUrlBasePrimaryDrawerItem<T, VH : RecyclerView.ViewHolder> : BaseDrawerItem<T, VH>() {
|
||||
abstract class CustomUrlBasePrimaryDrawerItem<T, VH : RecyclerView.ViewHolder> :
|
||||
BaseDrawerItem<T, VH>() {
|
||||
fun withIcon(url: String): T {
|
||||
this.icon = ImageHolder(url)
|
||||
return this as T
|
||||
@ -76,8 +77,8 @@ abstract class CustomUrlBasePrimaryDrawerItem<T, VH : RecyclerView.ViewHolder> :
|
||||
|
||||
//set the background for the item
|
||||
UIUtils.setBackground(
|
||||
viewHolder.view,
|
||||
UIUtils.getSelectableBackground(ctx, selectedColor, true)
|
||||
viewHolder.view,
|
||||
UIUtils.getSelectableBackground(ctx, selectedColor, true)
|
||||
)
|
||||
//set the text for the name
|
||||
StringHolder.applyTo(this.getName(), viewHolder.name)
|
||||
@ -88,9 +89,9 @@ abstract class CustomUrlBasePrimaryDrawerItem<T, VH : RecyclerView.ViewHolder> :
|
||||
viewHolder.name.setTextColor(getTextColorStateList(color, selectedTextColor))
|
||||
//set the description text color
|
||||
ColorHolder.applyToOr(
|
||||
descriptionTextColor,
|
||||
viewHolder.description,
|
||||
getTextColorStateList(color, selectedTextColor)
|
||||
descriptionTextColor,
|
||||
viewHolder.description,
|
||||
getTextColorStateList(color, selectedTextColor)
|
||||
)
|
||||
|
||||
//define the typeface for our textViews
|
||||
|
@ -10,7 +10,9 @@ import com.mikepenz.materialdrawer.holder.BadgeStyle
|
||||
import com.mikepenz.materialdrawer.holder.StringHolder
|
||||
import com.mikepenz.materialdrawer.model.interfaces.ColorfulBadgeable
|
||||
|
||||
class CustomUrlPrimaryDrawerItem : CustomUrlBasePrimaryDrawerItem<CustomUrlPrimaryDrawerItem, CustomUrlPrimaryDrawerItem.ViewHolder>(), ColorfulBadgeable<CustomUrlPrimaryDrawerItem> {
|
||||
class CustomUrlPrimaryDrawerItem :
|
||||
CustomUrlBasePrimaryDrawerItem<CustomUrlPrimaryDrawerItem, CustomUrlPrimaryDrawerItem.ViewHolder>(),
|
||||
ColorfulBadgeable<CustomUrlPrimaryDrawerItem> {
|
||||
protected var mBadge: StringHolder = StringHolder("")
|
||||
protected var mBadgeStyle = BadgeStyle()
|
||||
|
||||
@ -64,8 +66,8 @@ class CustomUrlPrimaryDrawerItem : CustomUrlBasePrimaryDrawerItem<CustomUrlPrima
|
||||
//style the badge if it is visible
|
||||
if (badgeVisible) {
|
||||
mBadgeStyle.style(
|
||||
viewHolder.badge,
|
||||
getTextColorStateList(getColor(ctx), getSelectedTextColor(ctx))
|
||||
viewHolder.badge,
|
||||
getTextColorStateList(getColor(ctx), getSelectedTextColor(ctx))
|
||||
)
|
||||
viewHolder.badgeContainer.visibility = View.VISIBLE
|
||||
} else {
|
||||
|
@ -9,31 +9,31 @@ import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.request.target.BitmapImageViewTarget
|
||||
|
||||
fun Context.bitmapCenterCrop(url: String, iv: ImageView) =
|
||||
Glide.with(this)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(RequestOptions.centerCropTransform())
|
||||
.into(iv)
|
||||
Glide.with(this)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(RequestOptions.centerCropTransform())
|
||||
.into(iv)
|
||||
|
||||
fun Context.bitmapFitCenter(url: String, iv: ImageView) =
|
||||
Glide.with(this)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(RequestOptions.fitCenterTransform())
|
||||
.into(iv)
|
||||
Glide.with(this)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(RequestOptions.fitCenterTransform())
|
||||
.into(iv)
|
||||
|
||||
fun Context.circularBitmapDrawable(url: String, iv: ImageView) =
|
||||
Glide.with(this)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(RequestOptions.centerCropTransform())
|
||||
.into(object : BitmapImageViewTarget(iv) {
|
||||
override fun setResource(resource: Bitmap?) {
|
||||
val circularBitmapDrawable = RoundedBitmapDrawableFactory.create(
|
||||
resources,
|
||||
resource
|
||||
)
|
||||
circularBitmapDrawable.isCircular = true
|
||||
iv.setImageDrawable(circularBitmapDrawable)
|
||||
}
|
||||
})
|
||||
Glide.with(this)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(RequestOptions.centerCropTransform())
|
||||
.into(object : BitmapImageViewTarget(iv) {
|
||||
override fun setResource(resource: Bitmap?) {
|
||||
val circularBitmapDrawable = RoundedBitmapDrawableFactory.create(
|
||||
resources,
|
||||
resource
|
||||
)
|
||||
circularBitmapDrawable.isCircular = true
|
||||
iv.setImageDrawable(circularBitmapDrawable)
|
||||
}
|
||||
})
|
@ -23,9 +23,9 @@ class SelfSignedGlideModule : GlideModule {
|
||||
val client = getUnsafeHttpClient().build()
|
||||
|
||||
registry?.append(
|
||||
GlideUrl::class.java,
|
||||
InputStream::class.java,
|
||||
com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader.Factory(client)
|
||||
GlideUrl::class.java,
|
||||
InputStream::class.java,
|
||||
com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader.Factory(client)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user