mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 20:01:50 +01:00
Remove unneeded annotations and some cleanup
This commit is contained in:
parent
5ad06df4ac
commit
a82e1d0e45
@ -1,8 +1,6 @@
|
||||
package eu.kanade.tachiyomi
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import org.acra.ACRA
|
||||
import org.acra.annotation.ReportsCrashes
|
||||
import timber.log.Timber
|
||||
@ -17,29 +15,16 @@ import uy.kohesive.injekt.Injekt
|
||||
)
|
||||
open class App : Application() {
|
||||
|
||||
var appTheme = 0
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
Injekt.importModule(AppModule(this))
|
||||
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
|
||||
|
||||
setupTheme()
|
||||
setupAcra()
|
||||
}
|
||||
|
||||
private fun setupTheme() {
|
||||
appTheme = PreferencesHelper.getTheme(this)
|
||||
}
|
||||
|
||||
protected open fun setupAcra() {
|
||||
ACRA.init(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun get(context: Context): App {
|
||||
return context.applicationContext as App
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,10 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.SystemClock
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.alarmManager
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
/**
|
||||
* This class is used to update the library by firing an alarm after a specified time.
|
||||
@ -25,10 +28,8 @@ class LibraryUpdateAlarm : BroadcastReceiver() {
|
||||
* @param intervalInHours the time in hours when it will be executed. Defaults to the
|
||||
* value stored in preferences.
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun startAlarm(context: Context,
|
||||
intervalInHours: Int = PreferencesHelper.getLibraryUpdateInterval(context)) {
|
||||
intervalInHours: Int = Injekt.get<PreferencesHelper>().libraryUpdateInterval().getOrDefault()) {
|
||||
// Stop previous running alarms if needed, and do not restart it if the interval is 0.
|
||||
stopAlarm(context)
|
||||
if (intervalInHours == 0)
|
||||
|
@ -10,6 +10,8 @@ import eu.kanade.tachiyomi.R
|
||||
*/
|
||||
class PreferenceKeys(context: Context) {
|
||||
|
||||
val theme = context.getString(R.string.pref_theme_key)
|
||||
|
||||
val rotation = context.getString(R.string.pref_rotation_type_key)
|
||||
|
||||
val enableTransitions = context.getString(R.string.pref_enable_transitions_key)
|
||||
@ -78,6 +80,8 @@ class PreferenceKeys(context: Context) {
|
||||
|
||||
val filterUnread = context.getString(R.string.pref_filter_unread_key)
|
||||
|
||||
val automaticUpdateStatus = context.getString(R.string.pref_enable_automatic_updates_key)
|
||||
|
||||
fun sourceUsername(sourceId: Int) = "pref_source_username_$sourceId"
|
||||
|
||||
fun sourcePassword(sourceId: Int) = "pref_source_password_$sourceId"
|
||||
|
@ -13,7 +13,7 @@ import java.io.IOException
|
||||
|
||||
fun <T> Preference<T>.getOrDefault(): T = get() ?: defaultValue()!!
|
||||
|
||||
class PreferencesHelper(private val context: Context) {
|
||||
class PreferencesHelper(context: Context) {
|
||||
|
||||
val keys = PreferenceKeys(context)
|
||||
|
||||
@ -32,28 +32,9 @@ class PreferencesHelper(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun clear() = prefs.edit().clear().apply()
|
||||
|
||||
fun getLibraryUpdateInterval(context: Context): Int {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getInt(
|
||||
context.getString(R.string.pref_library_update_interval_key), 0)
|
||||
}
|
||||
|
||||
fun getAutomaticUpdateStatus(context: Context): Boolean {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
||||
context.getString(R.string.pref_enable_automatic_updates), false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getTheme(context: Context): Int {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getInt(
|
||||
context.getString(R.string.pref_theme_key), 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
prefs.edit().clear().apply()
|
||||
}
|
||||
fun theme() = prefs.getInt(keys.theme, 1)
|
||||
|
||||
fun rotation() = rxPrefs.getInteger(keys.rotation, 1)
|
||||
|
||||
@ -147,4 +128,6 @@ class PreferencesHelper(private val context: Context) {
|
||||
|
||||
fun filterUnread() = rxPrefs.getBoolean(keys.filterUnread, false)
|
||||
|
||||
fun automaticUpdateStatus() = prefs.getBoolean(keys.automaticUpdateStatus, false)
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ import eu.kanade.tachiyomi.util.notification
|
||||
import eu.kanade.tachiyomi.util.notificationManager
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class UpdateDownloaderAlarm : BroadcastReceiver() {
|
||||
|
||||
@ -26,9 +28,8 @@ class UpdateDownloaderAlarm : BroadcastReceiver() {
|
||||
* @param context the application context.
|
||||
* @param intervalInHours the time in hours when it will be executed.
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun startAlarm(context: Context, intervalInHours: Int = 12, isEnabled: Boolean = PreferencesHelper.getAutomaticUpdateStatus(context)) {
|
||||
fun startAlarm(context: Context, intervalInHours: Int = 12,
|
||||
isEnabled: Boolean = Injekt.get<PreferencesHelper>().automaticUpdateStatus()) {
|
||||
// Stop previous running alarms if needed, and do not restart it if the interval is 0.
|
||||
UpdateDownloaderAlarm.stopAlarm(context)
|
||||
if (intervalInHours == 0 || !isEnabled)
|
||||
|
@ -8,8 +8,10 @@ import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.app.ActionBar
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.Toolbar
|
||||
import eu.kanade.tachiyomi.App
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
interface ActivityMixin {
|
||||
|
||||
@ -22,7 +24,7 @@ interface ActivityMixin {
|
||||
}
|
||||
|
||||
fun setAppTheme() {
|
||||
setTheme(when (App.get(getActivity()).appTheme) {
|
||||
setTheme(when (Injekt.get<PreferencesHelper>().theme()) {
|
||||
2 -> R.style.Theme_Tachiyomi_Dark
|
||||
else -> R.style.Theme_Tachiyomi
|
||||
})
|
||||
|
@ -50,7 +50,6 @@ class CategoryActivity : BaseRxActivity<CategoryPresenter>(), ActionMode.Callbac
|
||||
*
|
||||
* @param context context information.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun newIntent(context: Context): Intent {
|
||||
return Intent(context, CategoryActivity::class.java)
|
||||
}
|
||||
|
@ -67,7 +67,6 @@ class DownloadFragment : BaseRxFragment<DownloadPresenter>() {
|
||||
*
|
||||
* @return a new instance of [DownloadFragment].
|
||||
*/
|
||||
@JvmStatic
|
||||
fun newInstance(): DownloadFragment {
|
||||
return DownloadFragment()
|
||||
}
|
||||
|
@ -95,7 +95,6 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
*
|
||||
* @return a new instance of [LibraryFragment].
|
||||
*/
|
||||
@JvmStatic
|
||||
fun newInstance(): LibraryFragment {
|
||||
return LibraryFragment()
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ class RecentChaptersFragment
|
||||
* Create new RecentChaptersFragment.
|
||||
* @return a new instance of [RecentChaptersFragment].
|
||||
*/
|
||||
@JvmStatic
|
||||
fun newInstance(): RecentChaptersFragment {
|
||||
return RecentChaptersFragment()
|
||||
}
|
||||
|
@ -27,9 +27,7 @@ class RecentlyReadFragment : BaseRxFragment<RecentlyReadPresenter>() {
|
||||
companion object {
|
||||
/**
|
||||
* Create new RecentChaptersFragment.
|
||||
*
|
||||
*/
|
||||
@JvmStatic
|
||||
fun newInstance(): RecentlyReadFragment {
|
||||
return RecentlyReadFragment()
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import android.support.v14.preference.MultiSelectListPreference
|
||||
import android.support.v4.app.TaskStackBuilder
|
||||
import android.support.v7.preference.Preference
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.App
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateAlarm
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
@ -62,8 +61,6 @@ class SettingsGeneralFragment : SettingsNestedFragment() {
|
||||
}
|
||||
|
||||
themePreference.setOnPreferenceChangeListener { preference, newValue ->
|
||||
App.get(activity).appTheme = (newValue as String).toInt()
|
||||
|
||||
// Rebuild activity's to apply themes.
|
||||
TaskStackBuilder.create(activity)
|
||||
.addNextIntent(Intent(activity, MainActivity::class.java))
|
||||
|
@ -55,7 +55,7 @@
|
||||
|
||||
<string name="pref_version">pref_version</string>
|
||||
<string name="pref_build_time">pref_build_time</string>
|
||||
<string name="pref_enable_automatic_updates_key">pref_enable_automatic_updates_key</string>
|
||||
<string name="pref_enable_automatic_updates_key">automatic_updates</string>
|
||||
|
||||
<string name="pref_display_catalogue_as_list">pref_display_catalogue_as_list</string>
|
||||
<string name="pref_last_catalogue_source_key">pref_last_catalogue_source_key</string>
|
||||
|
@ -5,6 +5,8 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import eu.kanade.tachiyomi.App
|
||||
import eu.kanade.tachiyomi.AppModule
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.CustomRobolectricGradleTestRunner
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
@ -17,6 +19,9 @@ import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.shadows.ShadowAlarmManager
|
||||
import org.robolectric.shadows.ShadowApplication
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.InjektScope
|
||||
import uy.kohesive.injekt.registry.default.DefaultRegistrar
|
||||
|
||||
@Config(constants = BuildConfig::class, sdk = intArrayOf(Build.VERSION_CODES.LOLLIPOP))
|
||||
@RunWith(CustomRobolectricGradleTestRunner::class)
|
||||
@ -30,6 +35,8 @@ class LibraryUpdateAlarmTest {
|
||||
fun setup() {
|
||||
app = ShadowApplication.getInstance()
|
||||
context = spy(app.applicationContext)
|
||||
Injekt = InjektScope(DefaultRegistrar())
|
||||
Injekt.importModule(AppModule(context as App))
|
||||
|
||||
alarmManager = shadowOf(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user