This should fix #34
This commit is contained in:
parent
dc970bbf3c
commit
b2d69be5f8
@ -37,7 +37,7 @@ class AddSourceActivity : AppCompatActivity() {
|
|||||||
var api: SelfossApi? = null
|
var api: SelfossApi? = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
api = SelfossApi(this)
|
api = SelfossApi(this, this@AddSourceActivity)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
mustLoginToAddSource()
|
mustLoginToAddSource()
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
|
|
||||||
mCustomTabActivityHelper = CustomTabActivityHelper()
|
mCustomTabActivityHelper = CustomTabActivityHelper()
|
||||||
|
|
||||||
api = SelfossApi(this)
|
api = SelfossApi(this, this@HomeActivity)
|
||||||
items = ArrayList()
|
items = ArrayList()
|
||||||
|
|
||||||
mBottomBar = findViewById(R.id.bottomBar) as BottomBar
|
mBottomBar = findViewById(R.id.bottomBar) as BottomBar
|
||||||
@ -700,14 +700,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_disconnect -> {
|
R.id.action_disconnect -> {
|
||||||
editor.remove("url")
|
return Config.logoutAndRedirect(this, this@HomeActivity, editor)
|
||||||
editor.remove("login")
|
|
||||||
editor.remove("password")
|
|
||||||
editor.apply()
|
|
||||||
val intent = Intent(this, LoginActivity::class.java)
|
|
||||||
startActivity(intent)
|
|
||||||
finish()
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
R.id.action_share_the_app -> {
|
R.id.action_share_the_app -> {
|
||||||
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
|
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
|
||||||
|
@ -56,6 +56,18 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_login)
|
setContentView(R.layout.activity_login)
|
||||||
|
|
||||||
|
if (intent.getBooleanExtra("baseUrlFail", false)) {
|
||||||
|
val alertDialog = AlertDialog.Builder(this).create()
|
||||||
|
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.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
||||||
if (settings.getString("url", "").isNotEmpty()) {
|
if (settings.getString("url", "").isNotEmpty()) {
|
||||||
goToMain()
|
goToMain()
|
||||||
@ -177,7 +189,7 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
editor.putString("httpPassword", httpPassword)
|
editor.putString("httpPassword", httpPassword)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
|
|
||||||
val api = SelfossApi(this@LoginActivity)
|
val api = SelfossApi(this, this@LoginActivity)
|
||||||
api.login().enqueue(object : Callback<SuccessResponse> {
|
api.login().enqueue(object : Callback<SuccessResponse> {
|
||||||
private fun preferenceError() {
|
private fun preferenceError() {
|
||||||
editor.remove("url")
|
editor.remove("url")
|
||||||
|
@ -30,7 +30,7 @@ class SourcesActivity : AppCompatActivity() {
|
|||||||
val mFab = findViewById(R.id.fab) as FloatingActionButton
|
val mFab = findViewById(R.id.fab) as FloatingActionButton
|
||||||
val mRecyclerView = findViewById(R.id.activity_sources) as RecyclerView
|
val mRecyclerView = findViewById(R.id.activity_sources) as RecyclerView
|
||||||
val mLayoutManager = LinearLayoutManager(this)
|
val mLayoutManager = LinearLayoutManager(this)
|
||||||
val api = SelfossApi(this)
|
val api = SelfossApi(this, this@SourcesActivity)
|
||||||
var items: ArrayList<Sources> = ArrayList()
|
var items: ArrayList<Sources> = ArrayList()
|
||||||
|
|
||||||
mFab.attachToRecyclerView(mRecyclerView)
|
mFab.attachToRecyclerView(mRecyclerView)
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
package apps.amine.bou.readerforselfoss.api.selfoss
|
package apps.amine.bou.readerforselfoss.api.selfoss
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.support.v7.app.AlertDialog
|
||||||
|
import android.widget.Toast
|
||||||
|
import apps.amine.bou.readerforselfoss.LoginActivity
|
||||||
|
import apps.amine.bou.readerforselfoss.R
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
import com.burgstaller.okhttp.AuthenticationCacheInterceptor
|
import com.burgstaller.okhttp.AuthenticationCacheInterceptor
|
||||||
@ -20,9 +26,9 @@ import apps.amine.bou.readerforselfoss.utils.Config
|
|||||||
|
|
||||||
|
|
||||||
// codebeat:disable[ARITY,TOO_MANY_FUNCTIONS]
|
// codebeat:disable[ARITY,TOO_MANY_FUNCTIONS]
|
||||||
class SelfossApi(c: Context) {
|
class SelfossApi(c: Context, callingActivity: Activity) {
|
||||||
|
|
||||||
private val service: SelfossService
|
private lateinit var service: SelfossService
|
||||||
private val config: Config = Config(c)
|
private val config: Config = Config(c)
|
||||||
private val userName: String
|
private val userName: String
|
||||||
private val password: String
|
private val password: String
|
||||||
@ -59,6 +65,8 @@ class SelfossApi(c: Context) {
|
|||||||
.setLenient()
|
.setLenient()
|
||||||
.create()
|
.create()
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
val retrofit =
|
val retrofit =
|
||||||
Retrofit
|
Retrofit
|
||||||
.Builder()
|
.Builder()
|
||||||
@ -67,6 +75,9 @@ class SelfossApi(c: Context) {
|
|||||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||||
.build()
|
.build()
|
||||||
service = retrofit.create(SelfossService::class.java)
|
service = retrofit.create(SelfossService::class.java)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
Config.logoutAndRedirect(c, callingActivity, config.settings.edit(), baseUrlFail = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun login(): Call<SuccessResponse> =
|
fun login(): Call<SuccessResponse> =
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
package apps.amine.bou.readerforselfoss.utils
|
package apps.amine.bou.readerforselfoss.utils
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import apps.amine.bou.readerforselfoss.LoginActivity
|
||||||
|
|
||||||
|
|
||||||
class Config(c: Context) {
|
class Config(c: Context) {
|
||||||
|
|
||||||
private val settings: SharedPreferences
|
val settings: SharedPreferences = c.getSharedPreferences(settingsName, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
init {
|
|
||||||
this.settings = c.getSharedPreferences(settingsName, Context.MODE_PRIVATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
val baseUrl: String
|
val baseUrl: String
|
||||||
get() = settings.getString("url", "")
|
get() = settings.getString("url", "")
|
||||||
@ -27,8 +26,24 @@ class Config(c: Context) {
|
|||||||
val httpUserPassword: String
|
val httpUserPassword: String
|
||||||
get() = settings.getString("httpPassword", "")
|
get() = settings.getString("httpPassword", "")
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val settingsName = "paramsselfoss"
|
val settingsName = "paramsselfoss"
|
||||||
|
|
||||||
|
fun logoutAndRedirect(c: Context,
|
||||||
|
callingActivity: Activity,
|
||||||
|
editor: SharedPreferences.Editor,
|
||||||
|
baseUrlFail: Boolean = false): Boolean {
|
||||||
|
editor.remove("url")
|
||||||
|
editor.remove("login")
|
||||||
|
editor.remove("password")
|
||||||
|
editor.apply()
|
||||||
|
val intent = Intent(c, LoginActivity::class.java)
|
||||||
|
if (baseUrlFail)
|
||||||
|
intent.putExtra("baseUrlFail", baseUrlFail)
|
||||||
|
c.startActivity(intent)
|
||||||
|
callingActivity.finish()
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,4 +115,5 @@
|
|||||||
<string name="drawer_loading">Loading …</string>
|
<string name="drawer_loading">Loading …</string>
|
||||||
<string name="menu_home_search">Zoeken</string>
|
<string name="menu_home_search">Zoeken</string>
|
||||||
<string name="can_delete_source">Can\'t delete the source...</string>
|
<string name="can_delete_source">Can\'t delete the source...</string>
|
||||||
|
<string name="base_url_error">There was an issue when trying to communicate with your Selfoss Instance. If the issue persists, please get in touch with me.</string>
|
||||||
</resources>
|
</resources>
|
@ -117,4 +117,5 @@
|
|||||||
<string name="drawer_loading">Loading …</string>
|
<string name="drawer_loading">Loading …</string>
|
||||||
<string name="menu_home_search">Search</string>
|
<string name="menu_home_search">Search</string>
|
||||||
<string name="can_delete_source">Can\'t delete the source...</string>
|
<string name="can_delete_source">Can\'t delete the source...</string>
|
||||||
|
<string name="base_url_error">There was an issue when trying to communicate with your Selfoss Instance. If the issue persists, please get in touch with me.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user