Compare commits
No commits in common. "3e46e2ff297ccdf2096e77d8f896e04e156b5113" and "40e1d1478b4db29577068734f8ae50d36befc037" have entirely different histories.
3e46e2ff29
...
40e1d1478b
@ -35,7 +35,6 @@ steps:
|
|||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
**v123010261**
|
|
||||||
|
|
||||||
- feat: Handle public instances (#126) Co-authored-by: davidoskky <davidoskky@hidden.hidden> Co-committed-by: davidoskky <davidoskky@hidden.hidden>
|
|
||||||
- ci: Pull request should trigger ci.
|
|
||||||
- fix: Complete the disconnection before redirecting to the login screen
|
|
||||||
- Complete the disconnection before redirecting to the login screen
|
|
||||||
|
|
||||||
--------------------------------------------------------------------
|
|
||||||
|
|
||||||
**v123010241**
|
**v123010241**
|
||||||
|
|
||||||
- Merge pull request 'feat: swipe down to close images' (#122) from davidoskky/ReaderForSelfoss-multiplatform:swipe_down into master
|
- Merge pull request 'feat: swipe down to close images' (#122) from davidoskky/ReaderForSelfoss-multiplatform:swipe_down into master
|
||||||
|
@ -36,7 +36,6 @@ import com.ashokvarma.bottomnavigation.TextBadgeItem
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.kodein.di.DIAware
|
import org.kodein.di.DIAware
|
||||||
import org.kodein.di.android.closestDI
|
import org.kodein.di.android.closestDI
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
@ -115,16 +114,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val swipeDirs = if (appSettingsService.getPublicAccess()) {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
val simpleItemTouchCallback =
|
val simpleItemTouchCallback =
|
||||||
object : ItemTouchHelper.SimpleCallback(
|
object : ItemTouchHelper.SimpleCallback(
|
||||||
0,
|
0,
|
||||||
swipeDirs
|
ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
|
||||||
) {
|
) {
|
||||||
override fun getSwipeDirs(
|
override fun getSwipeDirs(
|
||||||
recyclerView: RecyclerView,
|
recyclerView: RecyclerView,
|
||||||
@ -517,10 +510,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
val inflater = menuInflater
|
val inflater = menuInflater
|
||||||
inflater.inflate(R.menu.home_menu, menu)
|
inflater.inflate(R.menu.home_menu, menu)
|
||||||
if (appSettingsService.getPublicAccess()) {
|
|
||||||
menu.removeItem(R.id.readAll)
|
|
||||||
menu.removeItem(R.id.action_sources)
|
|
||||||
}
|
|
||||||
|
|
||||||
val searchItem = menu.findItem(R.id.action_search)
|
val searchItem = menu.findItem(R.id.action_search)
|
||||||
val searchView = searchItem.getActionView() as SearchView
|
val searchView = searchItem.getActionView() as SearchView
|
||||||
@ -599,12 +588,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_disconnect -> {
|
R.id.action_disconnect -> {
|
||||||
runBlocking {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
repository.logout()
|
repository.logout()
|
||||||
}
|
}
|
||||||
|
this@HomeActivity.finish()
|
||||||
val intent = Intent(this, LoginActivity::class.java)
|
val intent = Intent(this, LoginActivity::class.java)
|
||||||
this.startActivity(intent)
|
this.startActivity(intent)
|
||||||
finish()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_settings -> {
|
R.id.action_settings -> {
|
||||||
|
@ -128,7 +128,7 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
private fun goToMain() {
|
private fun goToMain() {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
repository.updateApiInformation()
|
repository.updateApiVersion()
|
||||||
ACRA.errorReporter.putCustomData("SELFOSS_API_VERSION", appSettingsService.getApiVersion().toString())
|
ACRA.errorReporter.putCustomData("SELFOSS_API_VERSION", appSettingsService.getApiVersion().toString())
|
||||||
}
|
}
|
||||||
val intent = Intent(this, HomeActivity::class.java)
|
val intent = Intent(this, HomeActivity::class.java)
|
||||||
|
@ -84,7 +84,7 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun readItem(item: SelfossModel.Item) {
|
private fun readItem(item: SelfossModel.Item) {
|
||||||
if (appSettingsService.isMarkOnScrollEnabled() && !appSettingsService.getPublicAccess()) {
|
if (appSettingsService.isMarkOnScrollEnabled()) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.markAsRead(item)
|
repository.markAsRead(item)
|
||||||
}
|
}
|
||||||
@ -137,17 +137,12 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
inflater.inflate(R.menu.reader_menu, menu)
|
inflater.inflate(R.menu.reader_menu, menu)
|
||||||
toolbarMenu = menu
|
toolbarMenu = menu
|
||||||
|
|
||||||
alignmentMenu()
|
|
||||||
|
|
||||||
if (appSettingsService.getPublicAccess()) {
|
|
||||||
menu.removeItem(R.id.star)
|
|
||||||
} else {
|
|
||||||
if (allItems.isNotEmpty() && allItems[currentItem].starred) {
|
if (allItems.isNotEmpty() && allItems[currentItem].starred) {
|
||||||
canRemoveFromFavorite()
|
canRemoveFromFavorite()
|
||||||
} else {
|
} else {
|
||||||
canFavorite()
|
canFavorite()
|
||||||
}
|
}
|
||||||
|
alignmentMenu()
|
||||||
|
|
||||||
binding.pager.registerOnPageChangeCallback(
|
binding.pager.registerOnPageChangeCallback(
|
||||||
object : ViewPager2.OnPageChangeCallback() {
|
object : ViewPager2.OnPageChangeCallback() {
|
||||||
@ -164,7 +159,6 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -183,7 +177,7 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressedDispatcher.onBackPressed()
|
onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.star -> {
|
R.id.star -> {
|
||||||
|
@ -56,10 +56,6 @@ class ItemCardAdapter(
|
|||||||
val itm = items[position]
|
val itm = items[position]
|
||||||
|
|
||||||
binding.favButton.isSelected = itm.starred
|
binding.favButton.isSelected = itm.starred
|
||||||
if (appSettingsService.getPublicAccess()) {
|
|
||||||
binding.favButton.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.title.text = itm.title.getHtmlDecoded()
|
binding.title.text = itm.title.getHtmlDecoded()
|
||||||
|
|
||||||
binding.title.setOnTouchListener(LinkOnTouchListener())
|
binding.title.setOnTouchListener(LinkOnTouchListener())
|
||||||
|
@ -195,9 +195,6 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
|
|
||||||
private fun handleFloatingToolbar(): FloatingToolbar {
|
private fun handleFloatingToolbar(): FloatingToolbar {
|
||||||
val floatingToolbar: FloatingToolbar = binding.floatingToolbar
|
val floatingToolbar: FloatingToolbar = binding.floatingToolbar
|
||||||
if (appSettingsService.getPublicAccess()) {
|
|
||||||
floatingToolbar.setMenu(R.menu.reader_toolbar_no_read)
|
|
||||||
}
|
|
||||||
floatingToolbar.attachFab(fab)
|
floatingToolbar.attachFab(fab)
|
||||||
|
|
||||||
floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent))
|
floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent))
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
android:id="@+id/sourceImage"
|
android:id="@+id/sourceImage"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
@ -84,32 +85,41 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/title"
|
app:layout_constraintTop_toBottomOf="@+id/title"
|
||||||
tools:text="Google Actualité Il y a 5h" />
|
tools:text="Google Actualité Il y a 5h" />
|
||||||
|
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/sourceTitleAndDate">
|
app:layout_constraintTop_toBottomOf="@+id/sourceTitleAndDate">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/browserBtn"
|
android:id="@+id/favButton"
|
||||||
android:layout_width="35dp"
|
android:layout_width="35dp"
|
||||||
android:layout_height="35dp"
|
android:layout_height="35dp"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:elevation="5dp"
|
android:elevation="5dp"
|
||||||
android:padding="4dp"
|
android:padding="4dp"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
app:srcCompat="@drawable/ic_open_in_browser_black_24dp"
|
app:srcCompat="@drawable/ic_menu_heart_60dp"
|
||||||
app:tint="?android:attr/textColorPrimary" />
|
app:tint="@color/ic_menu_heart_color" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/shareBtn"
|
android:id="@+id/shareBtn"
|
||||||
android:layout_width="35dp"
|
android:layout_width="35dp"
|
||||||
android:layout_height="35dp"
|
android:layout_height="35dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_toLeftOf="@+id/favButton"
|
||||||
|
android:layout_toStartOf="@+id/favButton"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:elevation="5dp"
|
android:elevation="5dp"
|
||||||
@ -119,21 +129,23 @@
|
|||||||
app:tint="?android:attr/textColorPrimary" />
|
app:tint="?android:attr/textColorPrimary" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/favButton"
|
android:id="@+id/browserBtn"
|
||||||
android:layout_width="35dp"
|
android:layout_width="35dp"
|
||||||
android:layout_height="35dp"
|
android:layout_height="35dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_toLeftOf="@+id/shareBtn"
|
||||||
|
android:layout_toStartOf="@+id/shareBtn"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:elevation="5dp"
|
android:elevation="5dp"
|
||||||
android:padding="4dp"
|
android:padding="4dp"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
app:srcCompat="@drawable/ic_menu_heart_60dp"
|
app:srcCompat="@drawable/ic_open_in_browser_black_24dp"
|
||||||
app:tint="@color/ic_menu_heart_color" />
|
app:tint="?android:attr/textColorPrimary" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
android:layout_gravity="end|bottom|end">
|
android:layout_gravity="end|bottom|right">
|
||||||
|
|
||||||
<com.github.rubensousa.floatingtoolbar.FloatingToolbar
|
<com.github.rubensousa.floatingtoolbar.FloatingToolbar
|
||||||
android:id="@+id/floatingToolbar"
|
android:id="@+id/floatingToolbar"
|
||||||
@ -96,9 +96,10 @@
|
|||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end|bottom|end"
|
android:layout_gravity="end|bottom|right"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
android:src="@drawable/ic_add_white_24dp"
|
android:src="@drawable/ic_add_white_24dp"
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/open_action"
|
|
||||||
android:icon="@drawable/ic_open_in_browser_white_24dp"
|
|
||||||
android:title="@string/reader_action_open"
|
|
||||||
app:showAsAction="ifRoom" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/share_action"
|
|
||||||
android:icon="@drawable/ic_share_white_24dp"
|
|
||||||
android:title="@string/reader_action_share"
|
|
||||||
app:showAsAction="ifRoom" />
|
|
||||||
|
|
||||||
</menu>
|
|
@ -20,8 +20,6 @@ import org.junit.Test
|
|||||||
|
|
||||||
private const val BASE_URL = "https://test.com/selfoss/"
|
private const val BASE_URL = "https://test.com/selfoss/"
|
||||||
|
|
||||||
private const val USERNAME = "username"
|
|
||||||
|
|
||||||
private const val SPOUT = "spouts\\rss\\fulltextrss"
|
private const val SPOUT = "spouts\\rss\\fulltextrss"
|
||||||
|
|
||||||
private const val IMAGE_URL = "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
private const val IMAGE_URL = "b3aa8a664d08eb15d6ff1db2fa83e0d9.png"
|
||||||
@ -51,7 +49,7 @@ class RepositoryTest {
|
|||||||
repository = Repository(api, appSettingsService, isConnectionAvailable, db)
|
repository = Repository(api, appSettingsService, isConnectionAvailable, db)
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
repository.updateApiInformation()
|
repository.updateApiVersion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +58,12 @@ class RepositoryTest {
|
|||||||
clearAllMocks()
|
clearAllMocks()
|
||||||
every { appSettingsService.getApiVersion() } returns 4
|
every { appSettingsService.getApiVersion() } returns 4
|
||||||
every { appSettingsService.getBaseUrl() } returns BASE_URL
|
every { appSettingsService.getBaseUrl() } returns BASE_URL
|
||||||
every { appSettingsService.getUserName() } returns USERNAME
|
|
||||||
every { appSettingsService.isItemCachingEnabled() } returns false
|
every { appSettingsService.isItemCachingEnabled() } returns false
|
||||||
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
every { appSettingsService.isUpdateSourcesEnabled() } returns false
|
||||||
|
|
||||||
coEvery { api.apiInformation() } returns StatusAndData(
|
coEvery { api.version() } returns StatusAndData(
|
||||||
success = true,
|
success = true,
|
||||||
data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(false, true))
|
data = SelfossModel.ApiVersion("2.19-ba1e8e3", "4.0.0")
|
||||||
)
|
)
|
||||||
coEvery { api.stats() } returns StatusAndData(
|
coEvery { api.stats() } returns StatusAndData(
|
||||||
success = true,
|
success = true,
|
||||||
@ -84,7 +81,7 @@ class RepositoryTest {
|
|||||||
fun instantiate_repository() {
|
fun instantiate_repository() {
|
||||||
initializeRepository()
|
initializeRepository()
|
||||||
|
|
||||||
coVerify(exactly = 1) { api.apiInformation() }
|
coVerify(exactly = 1) { api.version() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -93,7 +90,7 @@ class RepositoryTest {
|
|||||||
|
|
||||||
initializeRepository(MutableStateFlow(false))
|
initializeRepository(MutableStateFlow(false))
|
||||||
|
|
||||||
coVerify(exactly = 0) { api.apiInformation() }
|
coVerify(exactly = 0) { api.version() }
|
||||||
coVerify(exactly = 0) { api.stats() }
|
coVerify(exactly = 0) { api.stats() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,70 +110,10 @@ class RepositoryTest {
|
|||||||
verify(exactly = 1) { appSettingsService.updateApiVersion(4) }
|
verify(exactly = 1) { appSettingsService.updateApiVersion(4) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun get_public_access() {
|
|
||||||
every { appSettingsService.updatePublicAccess(any()) } returns Unit
|
|
||||||
coEvery { api.apiInformation() } returns StatusAndData(
|
|
||||||
success = true,
|
|
||||||
data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, true))
|
|
||||||
)
|
|
||||||
every { appSettingsService.getUserName() } returns ""
|
|
||||||
|
|
||||||
initializeRepository()
|
|
||||||
|
|
||||||
coVerify(exactly = 1) { api.apiInformation() }
|
|
||||||
coVerify(exactly = 1) { appSettingsService.updatePublicAccess(true) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun get_public_access_username_not_empty() {
|
|
||||||
every { appSettingsService.updatePublicAccess(any()) } returns Unit
|
|
||||||
coEvery { api.apiInformation() } returns StatusAndData(
|
|
||||||
success = true,
|
|
||||||
data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, true))
|
|
||||||
)
|
|
||||||
every { appSettingsService.getUserName() } returns "username"
|
|
||||||
|
|
||||||
initializeRepository()
|
|
||||||
|
|
||||||
coVerify(exactly = 1) { api.apiInformation() }
|
|
||||||
coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun get_public_access_no_auth() {
|
|
||||||
every { appSettingsService.updatePublicAccess(any()) } returns Unit
|
|
||||||
coEvery { api.apiInformation() } returns StatusAndData(
|
|
||||||
success = true,
|
|
||||||
data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(true, false))
|
|
||||||
)
|
|
||||||
every { appSettingsService.getUserName() } returns ""
|
|
||||||
|
|
||||||
initializeRepository()
|
|
||||||
|
|
||||||
coVerify(exactly = 1) { api.apiInformation() }
|
|
||||||
coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun get_public_access_disabled() {
|
|
||||||
every { appSettingsService.updatePublicAccess(any()) } returns Unit
|
|
||||||
coEvery { api.apiInformation() } returns StatusAndData(
|
|
||||||
success = true,
|
|
||||||
data = SelfossModel.ApiInformation("2.19-ba1e8e3", "4.0.0", SelfossModel.ApiConfiguration(false, true))
|
|
||||||
)
|
|
||||||
every { appSettingsService.getUserName() } returns ""
|
|
||||||
|
|
||||||
initializeRepository()
|
|
||||||
|
|
||||||
coVerify(exactly = 1) { api.apiInformation() }
|
|
||||||
coVerify(exactly = 0) { appSettingsService.updatePublicAccess(true) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun get_api_1_date_with_api_4_version_stored() {
|
fun get_api_1_date_with_api_4_version_stored() {
|
||||||
every { appSettingsService.getApiVersion() } returns 4
|
every { appSettingsService.getApiVersion() } returns 4
|
||||||
coEvery { api.apiInformation() } returns StatusAndData(success = false, null)
|
coEvery { api.version() } returns StatusAndData(success = false, null)
|
||||||
val itemParameters = FakeItemParameters()
|
val itemParameters = FakeItemParameters()
|
||||||
itemParameters.datetime = "2021-04-23 11:45:32"
|
itemParameters.datetime = "2021-04-23 11:45:32"
|
||||||
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
|
coEvery { api.getItems(any(), any(), any(), any(), any(), any(), any()) } returns
|
||||||
|
@ -35,32 +35,17 @@ class SelfossModel {
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ApiInformation(
|
data class ApiVersion(
|
||||||
val version: String?,
|
val version: String?,
|
||||||
val apiversion: String?,
|
val apiversion: String?
|
||||||
val configuration: ApiConfiguration?
|
|
||||||
) {
|
) {
|
||||||
fun getApiMajorVersion(): Int {
|
fun getApiMajorVersion() : Int {
|
||||||
var versionNumber = 0
|
var versionNumber = 0
|
||||||
if (apiversion != null) {
|
if (apiversion != null) {
|
||||||
versionNumber = apiversion.substringBefore(".").toInt()
|
versionNumber = apiversion.substringBefore(".").toInt()
|
||||||
}
|
}
|
||||||
return versionNumber
|
return versionNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getApiConfiguration() = configuration ?: ApiConfiguration(null, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ApiConfiguration(
|
|
||||||
@Serializable(with = BooleanSerializer::class)
|
|
||||||
val publicMode: Boolean?,
|
|
||||||
@Serializable(with = BooleanSerializer::class)
|
|
||||||
val authEnabled: Boolean?
|
|
||||||
) {
|
|
||||||
fun isAuthEnabled() = authEnabled ?: true
|
|
||||||
|
|
||||||
fun isPublicModeEnabled() = publicMode ?: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -439,23 +439,13 @@ class Repository(
|
|||||||
api.refreshLoginInformation()
|
api.refreshLoginInformation()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateApiInformation() {
|
suspend fun updateApiVersion() {
|
||||||
val apiMajorVersion = appSettingsService.getApiVersion()
|
val apiMajorVersion = appSettingsService.getApiVersion()
|
||||||
|
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
val fetchedInformation = api.apiInformation()
|
val fetchedVersion = api.version()
|
||||||
if (fetchedInformation.success && fetchedInformation.data != null) {
|
if (fetchedVersion.success && fetchedVersion.data != null && fetchedVersion.data.getApiMajorVersion() != apiMajorVersion) {
|
||||||
if (fetchedInformation.data.getApiMajorVersion() != apiMajorVersion) {
|
appSettingsService.updateApiVersion(fetchedVersion.data.getApiMajorVersion())
|
||||||
appSettingsService.updateApiVersion(fetchedInformation.data.getApiMajorVersion())
|
|
||||||
}
|
|
||||||
// Check if we're accessing the instance in public mode
|
|
||||||
// This happens when auth and public mode are enabled but
|
|
||||||
// no credentials are provided to login
|
|
||||||
if (appSettingsService.getUserName().isEmpty()
|
|
||||||
&& fetchedInformation.data.getApiConfiguration().isAuthEnabled()
|
|
||||||
&& fetchedInformation.data.getApiConfiguration().isPublicModeEnabled()) {
|
|
||||||
appSettingsService.updatePublicAccess(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
suspend fun apiInformation(): StatusAndData<SelfossModel.ApiInformation> =
|
suspend fun version(): StatusAndData<SelfossModel.ApiVersion> =
|
||||||
bodyOrFailure(client.tryToGet(url("/api/about")))
|
bodyOrFailure(client.tryToGet(url("/api/about")))
|
||||||
|
|
||||||
suspend fun markAsRead(id: String): SuccessResponse =
|
suspend fun markAsRead(id: String): SuccessResponse =
|
||||||
|
@ -7,7 +7,6 @@ class AppSettingsService {
|
|||||||
|
|
||||||
// Api related
|
// Api related
|
||||||
private var _apiVersion: Int = -1
|
private var _apiVersion: Int = -1
|
||||||
private var _publicAccess: Boolean? = null
|
|
||||||
private var _baseUrl: String = ""
|
private var _baseUrl: String = ""
|
||||||
private var _userName: String = ""
|
private var _userName: String = ""
|
||||||
private var _password: String = ""
|
private var _password: String = ""
|
||||||
@ -49,32 +48,10 @@ class AppSettingsService {
|
|||||||
return _apiVersion
|
return _apiVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun updateApiVersion(apiMajorVersion: Int) {
|
|
||||||
settings.putInt(API_VERSION_MAJOR, apiMajorVersion)
|
|
||||||
refreshApiVersion()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun refreshApiVersion() {
|
private fun refreshApiVersion() {
|
||||||
_apiVersion = settings.getInt(API_VERSION_MAJOR, -1)
|
_apiVersion = settings.getInt(API_VERSION_MAJOR, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPublicAccess(): Boolean {
|
|
||||||
if (_publicAccess == null) {
|
|
||||||
refreshPublicAccess()
|
|
||||||
}
|
|
||||||
return _publicAccess!!
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updatePublicAccess(publicAccess: Boolean) {
|
|
||||||
settings.putBoolean(API_PUBLIC_ACCESS, publicAccess)
|
|
||||||
refreshPublicAccess()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun refreshPublicAccess() {
|
|
||||||
_publicAccess = settings.getBoolean(API_PUBLIC_ACCESS, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getBaseUrl(): String {
|
fun getBaseUrl(): String {
|
||||||
if (_baseUrl.isEmpty()) {
|
if (_baseUrl.isEmpty()) {
|
||||||
refreshBaseUrl()
|
refreshBaseUrl()
|
||||||
@ -356,7 +333,6 @@ class AppSettingsService {
|
|||||||
refreshUsername()
|
refreshUsername()
|
||||||
refreshBaseUrl()
|
refreshBaseUrl()
|
||||||
refreshApiVersion()
|
refreshApiVersion()
|
||||||
refreshPublicAccess()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refreshUserSettings() {
|
fun refreshUserSettings() {
|
||||||
@ -400,6 +376,11 @@ class AppSettingsService {
|
|||||||
refreshApiSettings()
|
refreshApiSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateApiVersion(apiMajorVersion: Int) {
|
||||||
|
settings.putInt(API_VERSION_MAJOR, apiMajorVersion)
|
||||||
|
refreshApiVersion()
|
||||||
|
}
|
||||||
|
|
||||||
fun clearAll() {
|
fun clearAll() {
|
||||||
settings.clear()
|
settings.clear()
|
||||||
refreshApiSettings()
|
refreshApiSettings()
|
||||||
@ -428,8 +409,6 @@ class AppSettingsService {
|
|||||||
|
|
||||||
const val API_VERSION_MAJOR = "apiVersionMajor"
|
const val API_VERSION_MAJOR = "apiVersionMajor"
|
||||||
|
|
||||||
const val API_PUBLIC_ACCESS = "apiPublicAccess"
|
|
||||||
|
|
||||||
const val API_ITEMS_NUMBER = "prefer_api_items_number"
|
const val API_ITEMS_NUMBER = "prefer_api_items_number"
|
||||||
|
|
||||||
const val API_TIMEOUT = "api_timeout"
|
const val API_TIMEOUT = "api_timeout"
|
||||||
|
Loading…
Reference in New Issue
Block a user