Added experimental settings with a custom timeout setting.
This commit is contained in:
parent
51add226eb
commit
91a7464bce
@ -89,6 +89,7 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
this,
|
||||
this@AddSourceActivity,
|
||||
prefs.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getString("api_timeout", "-1").toLong(),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
|
@ -195,6 +195,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
this,
|
||||
this@HomeActivity,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
sharedPref.getString("api_timeout", "-1").toLong(),
|
||||
shouldLogEverything
|
||||
)
|
||||
items = ArrayList()
|
||||
|
@ -195,6 +195,7 @@ class LoginActivity : AppCompatActivity() {
|
||||
this,
|
||||
this@LoginActivity,
|
||||
isWithSelfSignedCert,
|
||||
-1L,
|
||||
isWithSelfSignedCert
|
||||
)
|
||||
|
||||
|
@ -95,6 +95,7 @@ class ReaderActivity : AppCompatActivity() {
|
||||
this,
|
||||
this@ReaderActivity,
|
||||
prefs.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getString("api_timeout", "-1").toLong(),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
|
||||
|
@ -60,6 +60,7 @@ class SourcesActivity : AppCompatActivity() {
|
||||
this,
|
||||
this@SourcesActivity,
|
||||
prefs.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getString("api_timeout", "-1").toLong(),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
var items: ArrayList<Source> = ArrayList()
|
||||
|
@ -18,11 +18,13 @@ import retrofit2.Call
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class SelfossApi(
|
||||
c: Context,
|
||||
callingActivity: Activity?,
|
||||
isWithSelfSignedCert: Boolean,
|
||||
timeout: Long,
|
||||
shouldLog: Boolean
|
||||
) {
|
||||
|
||||
@ -38,16 +40,25 @@ class SelfossApi(
|
||||
this
|
||||
}
|
||||
|
||||
fun OkHttpClient.Builder.maybeWithSettingsTimeout(timeout: Long): OkHttpClient.Builder =
|
||||
if (timeout != -1L) {
|
||||
this.readTimeout(timeout, TimeUnit.SECONDS)
|
||||
.connectTimeout(timeout, TimeUnit.SECONDS)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
fun Credentials.createAuthenticator(): DispatchingAuthenticator =
|
||||
DispatchingAuthenticator.Builder()
|
||||
.with("digest", DigestAuthenticator(this))
|
||||
.with("basic", BasicAuthenticator(this))
|
||||
.build()
|
||||
|
||||
fun DispatchingAuthenticator.getHttpClien(isWithSelfSignedCert: Boolean): OkHttpClient.Builder {
|
||||
fun DispatchingAuthenticator.getHttpClien(isWithSelfSignedCert: Boolean, timeout: Long): OkHttpClient.Builder {
|
||||
val authCache = ConcurrentHashMap<String, CachingAuthenticator>()
|
||||
return OkHttpClient
|
||||
.Builder()
|
||||
.maybeWithSettingsTimeout(timeout)
|
||||
.maybeWithSelfSigned(isWithSelfSignedCert)
|
||||
.authenticator(CachingAuthenticatorDecorator(this, authCache))
|
||||
.addInterceptor(AuthenticationCacheInterceptor(authCache))
|
||||
@ -78,7 +89,7 @@ class SelfossApi(
|
||||
HttpLoggingInterceptor.Level.NONE
|
||||
}
|
||||
|
||||
val httpClient = authenticator.getHttpClien(isWithSelfSignedCert)
|
||||
val httpClient = authenticator.getHttpClien(isWithSelfSignedCert, timeout)
|
||||
|
||||
httpClient.addInterceptor(logging)
|
||||
|
||||
|
@ -53,7 +53,6 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con
|
||||
val settings =
|
||||
this.context.getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
||||
val sharedPref = PreferenceManager.getDefaultSharedPreferences(this.context)
|
||||
val shouldLogEverything = sharedPref.getBoolean("should_log_everything", false)
|
||||
val notifyNewItems = sharedPref.getBoolean("notify_new_items", false)
|
||||
|
||||
db = Room.databaseBuilder(
|
||||
@ -65,7 +64,8 @@ class LoadingWorker(val context: Context, params: WorkerParameters) : Worker(con
|
||||
this.context,
|
||||
null,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
shouldLogEverything
|
||||
sharedPref.getString("api_timeout", "-1").toLong(),
|
||||
sharedPref.getBoolean("should_log_everything", false)
|
||||
)
|
||||
|
||||
api.allItems().enqueue(object : Callback<List<Item>> {
|
||||
|
@ -114,6 +114,7 @@ class ArticleFragment : Fragment() {
|
||||
context!!,
|
||||
activity!!,
|
||||
settings.getBoolean("isSelfSignedCert", false),
|
||||
prefs.getString("api_timeout", "-1").toLong(),
|
||||
prefs.getBoolean("should_log_everything", false)
|
||||
)
|
||||
|
||||
|
@ -136,6 +136,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
|| GeneralPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| ArticleViewerPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| OfflinePreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| ExperimentalPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| DebugPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| LinksPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| ThemePreferenceFragment.class.getName().equals(fragmentName);
|
||||
@ -384,6 +385,26 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static class ExperimentalPreferenceFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.pref_experimental);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if (id == android.R.id.home) {
|
||||
getActivity().finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_action_lab.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_lab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 683 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_lab.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_lab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 409 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_lab.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_lab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 871 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_lab.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_lab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_lab.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_lab.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
@ -166,4 +166,6 @@
|
||||
<string name="new_items_notification_text">%1$d new items loaded.</string>
|
||||
<string name="pref_switch_notify_new_items">Notify on new items synced.</string>
|
||||
<string name="shortcut_offline">Offline</string>
|
||||
<string name="pref_api_timeout">Api Timeout</string>
|
||||
<string name="pref_header_experimental">Experimental</string>
|
||||
</resources>
|
||||
|
9
app/src/main/res/xml/pref_experimental.xml
Normal file
9
app/src/main/res/xml/pref_experimental.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<EditTextPreference
|
||||
android:inputType="number"
|
||||
android:key="api_timeout"
|
||||
android:selectAllOnFocus="true"
|
||||
android:singleLine="true"
|
||||
android:title="@string/pref_api_timeout" />
|
||||
|
||||
</PreferenceScreen>
|
@ -32,4 +32,9 @@
|
||||
android:icon="@drawable/ic_info_black_24"
|
||||
android:title="@string/pref_header_links"/>
|
||||
|
||||
<header
|
||||
android:fragment="apps.amine.bou.readerforselfoss.settings.SettingsActivity$ExperimentalPreferenceFragment"
|
||||
android:icon="@drawable/ic_action_lab"
|
||||
android:title="@string/pref_header_experimental"/>
|
||||
|
||||
</preference-headers>
|
||||
|
Loading…
Reference in New Issue
Block a user