mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-11 00:27:49 +01:00
Some base classes and preferences in Kotlin
This commit is contained in:
parent
306b1d74bb
commit
16a5e6c01a
13 changed files with 336 additions and 379 deletions
|
@ -1,197 +0,0 @@
|
|||
package eu.kanade.tachiyomi.data.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.f2prateek.rx.preferences.Preference;
|
||||
import com.f2prateek.rx.preferences.RxSharedPreferences;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService;
|
||||
import eu.kanade.tachiyomi.data.source.base.Source;
|
||||
|
||||
public class PreferencesHelper {
|
||||
|
||||
private Context context;
|
||||
private SharedPreferences prefs;
|
||||
private RxSharedPreferences rxPrefs;
|
||||
|
||||
private static final String SOURCE_ACCOUNT_USERNAME = "pref_source_username_";
|
||||
private static final String SOURCE_ACCOUNT_PASSWORD = "pref_source_password_";
|
||||
private static final String MANGASYNC_ACCOUNT_USERNAME = "pref_mangasync_username_";
|
||||
private static final String MANGASYNC_ACCOUNT_PASSWORD = "pref_mangasync_password_";
|
||||
|
||||
private File defaultDownloadsDir;
|
||||
|
||||
public PreferencesHelper(Context context) {
|
||||
this.context = context;
|
||||
PreferenceManager.setDefaultValues(context, R.xml.pref_reader, false);
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
rxPrefs = RxSharedPreferences.create(prefs);
|
||||
|
||||
defaultDownloadsDir = new File(Environment.getExternalStorageDirectory() +
|
||||
File.separator + context.getString(R.string.app_name), "downloads");
|
||||
|
||||
// Create default directory
|
||||
if (getDownloadsDirectory().equals(defaultDownloadsDir.getAbsolutePath()) &&
|
||||
!defaultDownloadsDir.exists()) {
|
||||
defaultDownloadsDir.mkdirs();
|
||||
}
|
||||
|
||||
// Don't display downloaded chapters in gallery apps creating a ".nomedia" file
|
||||
try {
|
||||
new File(getDownloadsDirectory(), ".nomedia").createNewFile();
|
||||
} catch (IOException e) { /* Ignore */ }
|
||||
}
|
||||
|
||||
private String getKey(int keyResource) {
|
||||
return context.getString(keyResource);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
prefs.edit().clear().apply();
|
||||
}
|
||||
|
||||
public Preference<Integer> rotation() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_rotation_type_key), 1);
|
||||
}
|
||||
|
||||
public Preference<Boolean> enableTransitions() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_enable_transitions_key), true);
|
||||
}
|
||||
|
||||
public Preference<Boolean> showPageNumber() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_show_page_number_key), true);
|
||||
}
|
||||
|
||||
public Preference<Boolean> hideStatusBar() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_hide_status_bar_key), true);
|
||||
}
|
||||
|
||||
public Preference<Boolean> keepScreenOn() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_keep_screen_on_key), true);
|
||||
}
|
||||
|
||||
public Preference<Boolean> customBrightness() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_custom_brightness_key), false);
|
||||
}
|
||||
|
||||
public Preference<Float> customBrightnessValue() {
|
||||
return rxPrefs.getFloat(getKey(R.string.pref_custom_brightness_value_key), 0F);
|
||||
}
|
||||
|
||||
public int getDefaultViewer() {
|
||||
return prefs.getInt(getKey(R.string.pref_default_viewer_key), 1);
|
||||
}
|
||||
|
||||
public Preference<Integer> imageScaleType() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_image_scale_type_key), 1);
|
||||
}
|
||||
|
||||
public Preference<Integer> imageDecoder() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_image_decoder_key), 0);
|
||||
}
|
||||
|
||||
public Preference<Integer> zoomStart() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_zoom_start_key), 1);
|
||||
}
|
||||
|
||||
public Preference<Integer> readerTheme() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_reader_theme_key), 0);
|
||||
}
|
||||
|
||||
public Preference<Integer> portraitColumns() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_library_columns_portrait_key), 0);
|
||||
}
|
||||
|
||||
public Preference<Integer> landscapeColumns() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_library_columns_landscape_key), 0);
|
||||
}
|
||||
|
||||
public boolean updateOnlyNonCompleted() {
|
||||
return prefs.getBoolean(getKey(R.string.pref_update_only_non_completed_key), false);
|
||||
}
|
||||
|
||||
public boolean autoUpdateMangaSync() {
|
||||
return prefs.getBoolean(getKey(R.string.pref_auto_update_manga_sync_key), true);
|
||||
}
|
||||
|
||||
public boolean askUpdateMangaSync() {
|
||||
return prefs.getBoolean(getKey(R.string.pref_ask_update_manga_sync_key), false);
|
||||
}
|
||||
|
||||
public Preference<Integer> lastUsedCatalogueSource() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_last_catalogue_source_key), -1);
|
||||
}
|
||||
|
||||
public boolean seamlessMode() {
|
||||
return prefs.getBoolean(getKey(R.string.pref_seamless_mode_key), true);
|
||||
}
|
||||
|
||||
public Preference<Boolean> catalogueAsList() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_display_catalogue_as_list), false);
|
||||
}
|
||||
|
||||
public String getSourceUsername(Source source) {
|
||||
return prefs.getString(SOURCE_ACCOUNT_USERNAME + source.getId(), "");
|
||||
}
|
||||
|
||||
public String getSourcePassword(Source source) {
|
||||
return prefs.getString(SOURCE_ACCOUNT_PASSWORD + source.getId(), "");
|
||||
}
|
||||
|
||||
public void setSourceCredentials(Source source, String username, String password) {
|
||||
prefs.edit()
|
||||
.putString(SOURCE_ACCOUNT_USERNAME + source.getId(), username)
|
||||
.putString(SOURCE_ACCOUNT_PASSWORD + source.getId(), password)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public String getMangaSyncUsername(MangaSyncService sync) {
|
||||
return prefs.getString(MANGASYNC_ACCOUNT_USERNAME + sync.getId(), "");
|
||||
}
|
||||
|
||||
public String getMangaSyncPassword(MangaSyncService sync) {
|
||||
return prefs.getString(MANGASYNC_ACCOUNT_PASSWORD + sync.getId(), "");
|
||||
}
|
||||
|
||||
public void setMangaSyncCredentials(MangaSyncService sync, String username, String password) {
|
||||
prefs.edit()
|
||||
.putString(MANGASYNC_ACCOUNT_USERNAME + sync.getId(), username)
|
||||
.putString(MANGASYNC_ACCOUNT_PASSWORD + sync.getId(), password)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public String getDownloadsDirectory() {
|
||||
return prefs.getString(getKey(R.string.pref_download_directory_key),
|
||||
defaultDownloadsDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void setDownloadsDirectory(String path) {
|
||||
prefs.edit().putString(getKey(R.string.pref_download_directory_key), path).apply();
|
||||
}
|
||||
|
||||
public Preference<Integer> downloadThreads() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_download_slots_key), 1);
|
||||
}
|
||||
|
||||
public boolean downloadOnlyOverWifi() {
|
||||
return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true);
|
||||
}
|
||||
|
||||
public static int getLibraryUpdateInterval(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getInt(
|
||||
context.getString(R.string.pref_library_update_interval_key), 0);
|
||||
}
|
||||
|
||||
public Preference<Integer> libraryUpdateInterval() {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_library_update_interval_key), 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
package eu.kanade.tachiyomi.data.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.preference.PreferenceManager
|
||||
import com.f2prateek.rx.preferences.Preference
|
||||
import com.f2prateek.rx.preferences.RxSharedPreferences
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService
|
||||
import eu.kanade.tachiyomi.data.source.base.Source
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
class PreferencesHelper(private val context: Context) {
|
||||
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
private val rxPrefs = RxSharedPreferences.create(prefs)
|
||||
|
||||
private val defaultDownloadsDir: File
|
||||
|
||||
init {
|
||||
defaultDownloadsDir = File(Environment.getExternalStorageDirectory().absolutePath +
|
||||
File.separator + context.getString(R.string.app_name), "downloads")
|
||||
|
||||
// Create default directory
|
||||
if (downloadsDirectory == defaultDownloadsDir.absolutePath && !defaultDownloadsDir.exists()) {
|
||||
defaultDownloadsDir.mkdirs()
|
||||
}
|
||||
|
||||
// Don't display downloaded chapters in gallery apps creating a ".nomedia" file
|
||||
try {
|
||||
File(downloadsDirectory, ".nomedia").createNewFile()
|
||||
} catch (e: IOException) {
|
||||
/* Ignore */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val SOURCE_ACCOUNT_USERNAME = "pref_source_username_"
|
||||
const val SOURCE_ACCOUNT_PASSWORD = "pref_source_password_"
|
||||
const val MANGASYNC_ACCOUNT_USERNAME = "pref_mangasync_username_"
|
||||
const val MANGASYNC_ACCOUNT_PASSWORD = "pref_mangasync_password_"
|
||||
|
||||
fun getLibraryUpdateInterval(context: Context): Int {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getInt(
|
||||
context.getString(R.string.pref_library_update_interval_key), 0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getKey(keyResource: Int): String {
|
||||
return context.getString(keyResource)
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
prefs.edit().clear().apply()
|
||||
}
|
||||
|
||||
fun rotation(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_rotation_type_key), 1)
|
||||
}
|
||||
|
||||
fun enableTransitions(): Preference<Boolean> {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_enable_transitions_key), true)
|
||||
}
|
||||
|
||||
fun showPageNumber(): Preference<Boolean> {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_show_page_number_key), true)
|
||||
}
|
||||
|
||||
fun hideStatusBar(): Preference<Boolean> {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_hide_status_bar_key), true)
|
||||
}
|
||||
|
||||
fun keepScreenOn(): Preference<Boolean> {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_keep_screen_on_key), true)
|
||||
}
|
||||
|
||||
fun customBrightness(): Preference<Boolean> {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_custom_brightness_key), false)
|
||||
}
|
||||
|
||||
fun customBrightnessValue(): Preference<Float> {
|
||||
return rxPrefs.getFloat(getKey(R.string.pref_custom_brightness_value_key), 0f)
|
||||
}
|
||||
|
||||
val defaultViewer: Int
|
||||
get() = prefs.getInt(getKey(R.string.pref_default_viewer_key), 1)
|
||||
|
||||
fun imageScaleType(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_image_scale_type_key), 1)
|
||||
}
|
||||
|
||||
fun imageDecoder(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_image_decoder_key), 0)
|
||||
}
|
||||
|
||||
fun zoomStart(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_zoom_start_key), 1)
|
||||
}
|
||||
|
||||
fun readerTheme(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_reader_theme_key), 0)
|
||||
}
|
||||
|
||||
fun portraitColumns(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_library_columns_portrait_key), 0)
|
||||
}
|
||||
|
||||
fun landscapeColumns(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_library_columns_landscape_key), 0)
|
||||
}
|
||||
|
||||
fun updateOnlyNonCompleted(): Boolean {
|
||||
return prefs.getBoolean(getKey(R.string.pref_update_only_non_completed_key), false)
|
||||
}
|
||||
|
||||
fun autoUpdateMangaSync(): Boolean {
|
||||
return prefs.getBoolean(getKey(R.string.pref_auto_update_manga_sync_key), true)
|
||||
}
|
||||
|
||||
fun askUpdateMangaSync(): Boolean {
|
||||
return prefs.getBoolean(getKey(R.string.pref_ask_update_manga_sync_key), false)
|
||||
}
|
||||
|
||||
fun lastUsedCatalogueSource(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_last_catalogue_source_key), -1)
|
||||
}
|
||||
|
||||
fun seamlessMode(): Boolean {
|
||||
return prefs.getBoolean(getKey(R.string.pref_seamless_mode_key), true)
|
||||
}
|
||||
|
||||
fun catalogueAsList(): Preference<Boolean> {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_display_catalogue_as_list), false)
|
||||
}
|
||||
|
||||
fun getSourceUsername(source: Source): String {
|
||||
return prefs.getString(SOURCE_ACCOUNT_USERNAME + source.id, "")
|
||||
}
|
||||
|
||||
fun getSourcePassword(source: Source): String {
|
||||
return prefs.getString(SOURCE_ACCOUNT_PASSWORD + source.id, "")
|
||||
}
|
||||
|
||||
fun setSourceCredentials(source: Source, username: String, password: String) {
|
||||
prefs.edit()
|
||||
.putString(SOURCE_ACCOUNT_USERNAME + source.id, username)
|
||||
.putString(SOURCE_ACCOUNT_PASSWORD + source.id, password)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun getMangaSyncUsername(sync: MangaSyncService): String {
|
||||
return prefs.getString(MANGASYNC_ACCOUNT_USERNAME + sync.id, "")
|
||||
}
|
||||
|
||||
fun getMangaSyncPassword(sync: MangaSyncService): String {
|
||||
return prefs.getString(MANGASYNC_ACCOUNT_PASSWORD + sync.id, "")
|
||||
}
|
||||
|
||||
fun setMangaSyncCredentials(sync: MangaSyncService, username: String, password: String) {
|
||||
prefs.edit()
|
||||
.putString(MANGASYNC_ACCOUNT_USERNAME + sync.id, username)
|
||||
.putString(MANGASYNC_ACCOUNT_PASSWORD + sync.id, password)
|
||||
.apply()
|
||||
}
|
||||
|
||||
var downloadsDirectory: String
|
||||
get() = prefs.getString(getKey(R.string.pref_download_directory_key), defaultDownloadsDir.absolutePath)
|
||||
set(path) = prefs.edit().putString(getKey(R.string.pref_download_directory_key), path).apply()
|
||||
|
||||
fun downloadThreads(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_download_slots_key), 1)
|
||||
}
|
||||
|
||||
fun downloadOnlyOverWifi(): Boolean {
|
||||
return prefs.getBoolean(getKey(R.string.pref_download_only_over_wifi_key), true)
|
||||
}
|
||||
|
||||
fun libraryUpdateInterval(): Preference<Int> {
|
||||
return rxPrefs.getInteger(getKey(R.string.pref_library_update_interval_key), 0)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package eu.kanade.tachiyomi.ui.base.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import eu.kanade.tachiyomi.App;
|
||||
import eu.kanade.tachiyomi.injection.component.AppComponent;
|
||||
import icepick.Icepick;
|
||||
|
||||
public class BaseActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
Icepick.restoreInstanceState(this, savedState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
Icepick.saveInstanceState(this, outState);
|
||||
}
|
||||
|
||||
protected void setupToolbar(Toolbar toolbar) {
|
||||
setSupportActionBar(toolbar);
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(String title) {
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setTitle(title);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(int titleResource) {
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setTitle(getString(titleResource));
|
||||
}
|
||||
|
||||
public void setToolbarSubtitle(String title) {
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setSubtitle(title);
|
||||
}
|
||||
|
||||
public void setToolbarSubtitle(int titleResource) {
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setSubtitle(getString(titleResource));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void registerForEvents() {
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
public void unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
protected AppComponent getApplicationComponent() {
|
||||
return App.get(this).getComponent();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package eu.kanade.tachiyomi.ui.base.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.Toolbar
|
||||
import android.view.MenuItem
|
||||
import eu.kanade.tachiyomi.App
|
||||
import eu.kanade.tachiyomi.injection.component.AppComponent
|
||||
import icepick.Icepick
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
open class BaseActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
Icepick.restoreInstanceState(this, savedState)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
Icepick.saveInstanceState(this, outState)
|
||||
}
|
||||
|
||||
protected fun setupToolbar(toolbar: Toolbar) {
|
||||
setSupportActionBar(toolbar)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
||||
fun setToolbarTitle(title: String) {
|
||||
supportActionBar?.title = title
|
||||
}
|
||||
|
||||
fun setToolbarTitle(titleResource: Int) {
|
||||
supportActionBar?.title = getString(titleResource)
|
||||
}
|
||||
|
||||
fun setToolbarSubtitle(title: String) {
|
||||
supportActionBar?.subtitle = title
|
||||
}
|
||||
|
||||
fun setToolbarSubtitle(titleResource: Int) {
|
||||
supportActionBar?.subtitle = getString(titleResource)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
fun registerForEvents() {
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
fun unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
protected val applicationComponent: AppComponent
|
||||
get() = App.get(this).component
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package eu.kanade.tachiyomi.ui.decoration;
|
||||
package eu.kanade.tachiyomi.ui.base.decoration;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
|
@ -1,45 +0,0 @@
|
|||
package eu.kanade.tachiyomi.ui.base.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity;
|
||||
import icepick.Icepick;
|
||||
|
||||
public class BaseFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
Icepick.restoreInstanceState(this, savedState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
Icepick.saveInstanceState(this, outState);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(String title) {
|
||||
getBaseActivity().setToolbarTitle(title);
|
||||
}
|
||||
|
||||
public void setToolbarTitle(int resourceId) {
|
||||
getBaseActivity().setToolbarTitle(getString(resourceId));
|
||||
}
|
||||
|
||||
public BaseActivity getBaseActivity() {
|
||||
return (BaseActivity) getActivity();
|
||||
}
|
||||
|
||||
public void registerForEvents() {
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
public void unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package eu.kanade.tachiyomi.ui.base.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
import icepick.Icepick
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
open class BaseFragment : Fragment() {
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
Icepick.restoreInstanceState(this, savedState)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
Icepick.saveInstanceState(this, outState)
|
||||
}
|
||||
|
||||
fun setToolbarTitle(title: String) {
|
||||
baseActivity.setToolbarTitle(title)
|
||||
}
|
||||
|
||||
fun setToolbarTitle(resourceId: Int) {
|
||||
baseActivity.setToolbarTitle(getString(resourceId))
|
||||
}
|
||||
|
||||
val baseActivity: BaseActivity
|
||||
get() = activity as BaseActivity
|
||||
|
||||
fun registerForEvents() {
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
fun unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package eu.kanade.tachiyomi.ui.base.presenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import icepick.Icepick;
|
||||
import nucleus.view.ViewWithPresenter;
|
||||
|
||||
public class BasePresenter<V extends ViewWithPresenter> extends RxPresenter<V> {
|
||||
|
||||
private Context context;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedState) {
|
||||
super.onCreate(savedState);
|
||||
Icepick.restoreInstanceState(this, savedState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSave(@NonNull Bundle state) {
|
||||
super.onSave(state);
|
||||
Icepick.saveInstanceState(this, state);
|
||||
}
|
||||
|
||||
public void registerForEvents() {
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
public void unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
public void setContext(Context applicationContext) {
|
||||
context = applicationContext;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package eu.kanade.tachiyomi.ui.base.presenter
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import icepick.Icepick
|
||||
import nucleus.view.ViewWithPresenter
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
open class BasePresenter<V : ViewWithPresenter<*>> : RxPresenter<V>() {
|
||||
|
||||
lateinit var context: Context
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
Icepick.restoreInstanceState(this, savedState)
|
||||
}
|
||||
|
||||
override fun onSave(state: Bundle) {
|
||||
super.onSave(state)
|
||||
Icepick.saveInstanceState(this, state)
|
||||
}
|
||||
|
||||
fun registerForEvents() {
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
fun unregisterForEvents() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
}
|
|
@ -16,8 +16,8 @@ import com.afollestad.materialdialogs.MaterialDialog
|
|||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.ui.base.decoration.DividerItemDecoration
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
||||
import eu.kanade.tachiyomi.ui.decoration.DividerItemDecoration
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaActivity
|
||||
import eu.kanade.tachiyomi.util.ToastUtil
|
||||
|
@ -204,10 +204,10 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleViewHold
|
|||
toolbar.addView(spinner)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(bundle: Bundle) {
|
||||
bundle.putInt(SELECTED_INDEX_KEY, selectedIndex)
|
||||
bundle.putString(QUERY_KEY, query)
|
||||
super.onSaveInstanceState(bundle)
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
outState.putInt(SELECTED_INDEX_KEY, selectedIndex)
|
||||
outState.putString(QUERY_KEY, query)
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
|
@ -309,7 +309,7 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleViewHold
|
|||
*/
|
||||
private fun restartRequest(newQuery: String) {
|
||||
// If text didn't change, do nothing
|
||||
if (query == newQuery || presenter.source == null)
|
||||
if (query == newQuery)
|
||||
return
|
||||
|
||||
query = newQuery
|
||||
|
|
|
@ -30,8 +30,8 @@ import eu.kanade.tachiyomi.data.database.models.Manga;
|
|||
import eu.kanade.tachiyomi.data.download.DownloadService;
|
||||
import eu.kanade.tachiyomi.data.download.model.Download;
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder;
|
||||
import eu.kanade.tachiyomi.ui.base.decoration.DividerItemDecoration;
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment;
|
||||
import eu.kanade.tachiyomi.ui.decoration.DividerItemDecoration;
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaActivity;
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity;
|
||||
import eu.kanade.tachiyomi.util.ToastUtil;
|
||||
|
|
|
@ -13,8 +13,8 @@ import eu.kanade.tachiyomi.data.database.models.MangaChapter
|
|||
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.ui.base.decoration.DividerItemDecoration
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
||||
import eu.kanade.tachiyomi.ui.decoration.DividerItemDecoration
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import kotlinx.android.synthetic.main.fragment_recent_chapters.*
|
||||
import nucleus.factory.RequiresPresenter
|
||||
|
|
|
@ -19,18 +19,19 @@ import rx.Observable
|
|||
* @param view the inflated view for this holder.
|
||||
* @param adapter the adapter handling this holder.
|
||||
* @param listener a listener to react to single tap and long tap events.
|
||||
* @constructor creates a new library holder.
|
||||
* @constructor creates a new recent chapter holder.
|
||||
*/
|
||||
class RecentChaptersHolder(view: View, private val adapter: RecentChaptersAdapter, listener: FlexibleViewHolder.OnListItemClickListener) : FlexibleViewHolder(view, adapter, listener) {
|
||||
class RecentChaptersHolder(view: View, private val adapter: RecentChaptersAdapter, listener: FlexibleViewHolder.OnListItemClickListener) :
|
||||
FlexibleViewHolder(view, adapter, listener) {
|
||||
/**
|
||||
* Color of read chapter
|
||||
*/
|
||||
private val readColor: Int
|
||||
private val readColor = ContextCompat.getColor(view.context, R.color.hint_text)
|
||||
|
||||
/**
|
||||
* Color of unread chapter
|
||||
*/
|
||||
private val unreadColor: Int
|
||||
private val unreadColor = ContextCompat.getColor(view.context, R.color.primary_text)
|
||||
|
||||
/**
|
||||
* Object containing chapter information
|
||||
|
@ -38,10 +39,6 @@ class RecentChaptersHolder(view: View, private val adapter: RecentChaptersAdapte
|
|||
private var mangaChapter: MangaChapter? = null
|
||||
|
||||
init {
|
||||
// Set colors.
|
||||
readColor = ContextCompat.getColor(view.context, R.color.hint_text)
|
||||
unreadColor = ContextCompat.getColor(view.context, R.color.primary_text)
|
||||
|
||||
//Set OnClickListener for download menu
|
||||
itemView.chapterMenu.setOnClickListener { v -> v.post({ showPopupMenu(v) }) }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue