Changes:
- Declare RxJava as dependency - Add a folder chooser for downloads - Fix a force close when updating library - Enable ACRA and add a setting to send crash reports - Manga class now uses the default get resolver - Other minor changes
This commit is contained in:
parent
65a2345bf7
commit
e1b68f66f2
18 changed files with 217 additions and 133 deletions
|
@ -70,6 +70,7 @@ dependencies {
|
||||||
compile 'com.jakewharton:disklrucache:2.0.2'
|
compile 'com.jakewharton:disklrucache:2.0.2'
|
||||||
compile 'org.jsoup:jsoup:1.8.3'
|
compile 'org.jsoup:jsoup:1.8.3'
|
||||||
compile 'io.reactivex:rxandroid:1.0.1'
|
compile 'io.reactivex:rxandroid:1.0.1'
|
||||||
|
compile 'io.reactivex:rxjava:1.1.0'
|
||||||
compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1'
|
compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.1'
|
||||||
compile "com.pushtorefresh.storio:sqlite:$STORIO_VERSION"
|
compile "com.pushtorefresh.storio:sqlite:$STORIO_VERSION"
|
||||||
compile "com.pushtorefresh.storio:sqlite-annotations:$STORIO_VERSION"
|
compile "com.pushtorefresh.storio:sqlite-annotations:$STORIO_VERSION"
|
||||||
|
@ -86,6 +87,7 @@ dependencies {
|
||||||
provided "frankiesardo:icepick-processor:$ICEPICK_VERSION"
|
provided "frankiesardo:icepick-processor:$ICEPICK_VERSION"
|
||||||
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
|
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
|
||||||
compile 'eu.davidea:flexible-adapter:4.1.0@aar'
|
compile 'eu.davidea:flexible-adapter:4.1.0@aar'
|
||||||
|
compile 'com.nononsenseapps:filepicker:2.5.0'
|
||||||
|
|
||||||
compile "com.google.dagger:dagger:$DAGGER_VERSION"
|
compile "com.google.dagger:dagger:$DAGGER_VERSION"
|
||||||
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
||||||
|
@ -98,9 +100,6 @@ dependencies {
|
||||||
compile('com.github.afollestad.material-dialogs:core:0.8.5.2@aar') {
|
compile('com.github.afollestad.material-dialogs:core:0.8.5.2@aar') {
|
||||||
transitive = true
|
transitive = true
|
||||||
}
|
}
|
||||||
compile('com.github.afollestad.material-dialogs:commons:0.8.5.2@aar') {
|
|
||||||
transitive = true
|
|
||||||
}
|
|
||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
testCompile "org.hamcrest:hamcrest-core:$HAMCREST_VERSION"
|
testCompile "org.hamcrest:hamcrest-core:$HAMCREST_VERSION"
|
||||||
|
|
|
@ -40,6 +40,12 @@
|
||||||
android:parentActivityName=".ui.main.MainActivity" >
|
android:parentActivityName=".ui.main.MainActivity" >
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".ui.setting.SettingsDownloadsFragment$CustomLayoutPickerActivity"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:theme="@style/FilePickerTheme">
|
||||||
|
</activity>
|
||||||
|
|
||||||
<service android:name=".data.sync.LibraryUpdateService"
|
<service android:name=".data.sync.LibraryUpdateService"
|
||||||
android:exported="false"/>
|
android:exported="false"/>
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.kanade.mangafeed;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.acra.ACRA;
|
||||||
import org.acra.annotation.ReportsCrashes;
|
import org.acra.annotation.ReportsCrashes;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.injection.ComponentReflectionInjector;
|
import eu.kanade.mangafeed.injection.ComponentReflectionInjector;
|
||||||
|
@ -12,30 +13,29 @@ import eu.kanade.mangafeed.injection.module.AppModule;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@ReportsCrashes(
|
@ReportsCrashes(
|
||||||
formUri = "http://couch.kanade.eu/acra-manga/_design/acra-storage/_update/report",
|
formUri = "http://mangafeed.kanade.eu/crash_report",
|
||||||
reportType = org.acra.sender.HttpSender.Type.JSON,
|
reportType = org.acra.sender.HttpSender.Type.JSON,
|
||||||
httpMethod = org.acra.sender.HttpSender.Method.PUT,
|
httpMethod = org.acra.sender.HttpSender.Method.PUT,
|
||||||
formUriBasicAuthLogin="test",
|
excludeMatchingSharedPreferencesKeys={".*username.*",".*password.*"}
|
||||||
formUriBasicAuthPassword="test"
|
|
||||||
)
|
)
|
||||||
public class App extends Application {
|
public class App extends Application {
|
||||||
|
|
||||||
AppComponent mApplicationComponent;
|
AppComponent applicationComponent;
|
||||||
ComponentReflectionInjector<AppComponent> mComponentInjector;
|
ComponentReflectionInjector<AppComponent> componentInjector;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
|
if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
|
||||||
|
|
||||||
mApplicationComponent = DaggerAppComponent.builder()
|
applicationComponent = DaggerAppComponent.builder()
|
||||||
.appModule(new AppModule(this))
|
.appModule(new AppModule(this))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
mComponentInjector =
|
componentInjector =
|
||||||
new ComponentReflectionInjector<>(AppComponent.class, mApplicationComponent);
|
new ComponentReflectionInjector<>(AppComponent.class, applicationComponent);
|
||||||
|
|
||||||
//ACRA.init(this);
|
ACRA.init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static App get(Context context) {
|
public static App get(Context context) {
|
||||||
|
@ -43,15 +43,15 @@ public class App extends Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppComponent getComponent() {
|
public AppComponent getComponent() {
|
||||||
return mApplicationComponent;
|
return applicationComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComponentReflectionInjector<AppComponent> getComponentReflection() {
|
public ComponentReflectionInjector<AppComponent> getComponentReflection() {
|
||||||
return mComponentInjector;
|
return componentInjector;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Needed to replace the component with a test specific one
|
// Needed to replace the component with a test specific one
|
||||||
public void setComponent(AppComponent applicationComponent) {
|
public void setComponent(AppComponent applicationComponent) {
|
||||||
mApplicationComponent = applicationComponent;
|
this.applicationComponent = applicationComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import eu.kanade.mangafeed.data.database.models.ChapterSyncStorIOSQLiteGetResolv
|
||||||
import eu.kanade.mangafeed.data.database.models.ChapterSyncStorIOSQLitePutResolver;
|
import eu.kanade.mangafeed.data.database.models.ChapterSyncStorIOSQLitePutResolver;
|
||||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||||
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteDeleteResolver;
|
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteDeleteResolver;
|
||||||
|
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLiteGetResolver;
|
||||||
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLitePutResolver;
|
import eu.kanade.mangafeed.data.database.models.MangaStorIOSQLitePutResolver;
|
||||||
import eu.kanade.mangafeed.data.database.resolvers.MangaWithUnreadGetResolver;
|
import eu.kanade.mangafeed.data.database.resolvers.MangaWithUnreadGetResolver;
|
||||||
import eu.kanade.mangafeed.data.database.tables.ChapterSyncTable;
|
import eu.kanade.mangafeed.data.database.tables.ChapterSyncTable;
|
||||||
|
@ -46,7 +47,7 @@ public class DatabaseHelper {
|
||||||
.sqliteOpenHelper(new DbOpenHelper(context))
|
.sqliteOpenHelper(new DbOpenHelper(context))
|
||||||
.addTypeMapping(Manga.class, SQLiteTypeMapping.<Manga>builder()
|
.addTypeMapping(Manga.class, SQLiteTypeMapping.<Manga>builder()
|
||||||
.putResolver(new MangaStorIOSQLitePutResolver())
|
.putResolver(new MangaStorIOSQLitePutResolver())
|
||||||
.getResolver(new MangaWithUnreadGetResolver())
|
.getResolver(new MangaStorIOSQLiteGetResolver())
|
||||||
.deleteResolver(new MangaStorIOSQLiteDeleteResolver())
|
.deleteResolver(new MangaStorIOSQLiteDeleteResolver())
|
||||||
.build())
|
.build())
|
||||||
.addTypeMapping(Chapter.class, SQLiteTypeMapping.<Chapter>builder()
|
.addTypeMapping(Chapter.class, SQLiteTypeMapping.<Chapter>builder()
|
||||||
|
@ -94,6 +95,7 @@ public class DatabaseHelper {
|
||||||
.query(favoriteMangasWithUnreadQuery)
|
.query(favoriteMangasWithUnreadQuery)
|
||||||
.observesTables(MangaTable.TABLE, ChapterTable.TABLE)
|
.observesTables(MangaTable.TABLE, ChapterTable.TABLE)
|
||||||
.build())
|
.build())
|
||||||
|
.withGetResolver(MangaWithUnreadGetResolver.instance)
|
||||||
.prepare();
|
.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,11 +9,13 @@ import eu.kanade.mangafeed.data.database.tables.MangaTable;
|
||||||
|
|
||||||
public class MangaWithUnreadGetResolver extends MangaStorIOSQLiteGetResolver {
|
public class MangaWithUnreadGetResolver extends MangaStorIOSQLiteGetResolver {
|
||||||
|
|
||||||
|
public static final MangaWithUnreadGetResolver instance = new MangaWithUnreadGetResolver();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Manga mapFromCursor(@NonNull Cursor cursor) {
|
public Manga mapFromCursor(@NonNull Cursor cursor) {
|
||||||
Manga manga = super.mapFromCursor(cursor);
|
Manga manga = super.mapFromCursor(cursor);
|
||||||
int unreadColumn = cursor.getColumnIndex(MangaTable.COLUMN_UNREAD);
|
int unreadColumn = cursor.getColumnIndex(MangaTable.COLUMN_UNREAD);
|
||||||
if (unreadColumn != -1)
|
|
||||||
manga.unread = cursor.getInt(unreadColumn);
|
manga.unread = cursor.getInt(unreadColumn);
|
||||||
return manga;
|
return manga;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,17 @@ package eu.kanade.mangafeed.data.preference;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.f2prateek.rx.preferences.Preference;
|
import com.f2prateek.rx.preferences.Preference;
|
||||||
import com.f2prateek.rx.preferences.RxSharedPreferences;
|
import com.f2prateek.rx.preferences.RxSharedPreferences;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.data.chaptersync.BaseChapterSync;
|
import eu.kanade.mangafeed.data.chaptersync.BaseChapterSync;
|
||||||
import eu.kanade.mangafeed.data.source.base.Source;
|
import eu.kanade.mangafeed.data.source.base.Source;
|
||||||
import eu.kanade.mangafeed.util.DiskUtils;
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
public class PreferencesHelper {
|
public class PreferencesHelper {
|
||||||
|
@ -24,12 +26,21 @@ public class PreferencesHelper {
|
||||||
private static final String CHAPTERSYNC_ACCOUNT_USERNAME = "pref_chaptersync_username_";
|
private static final String CHAPTERSYNC_ACCOUNT_USERNAME = "pref_chaptersync_username_";
|
||||||
private static final String CHAPTERSYNC_ACCOUNT_PASSWORD = "pref_chaptersync_password_";
|
private static final String CHAPTERSYNC_ACCOUNT_PASSWORD = "pref_chaptersync_password_";
|
||||||
|
|
||||||
|
private File defaultDownloadsDir;
|
||||||
|
|
||||||
public PreferencesHelper(Context context) {
|
public PreferencesHelper(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
PreferenceManager.setDefaultValues(context, R.xml.pref_reader, false);
|
PreferenceManager.setDefaultValues(context, R.xml.pref_reader, false);
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
rxPrefs = RxSharedPreferences.create(prefs);
|
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.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getKey(int keyResource) {
|
private String getKey(int keyResource) {
|
||||||
|
@ -108,7 +119,11 @@ public class PreferencesHelper {
|
||||||
|
|
||||||
public String getDownloadsDirectory() {
|
public String getDownloadsDirectory() {
|
||||||
return prefs.getString(getKey(R.string.pref_download_directory_key),
|
return prefs.getString(getKey(R.string.pref_download_directory_key),
|
||||||
DiskUtils.getStorageDirectories(context)[0]);
|
defaultDownloadsDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadsDirectory(String path) {
|
||||||
|
prefs.edit().putString(getKey(R.string.pref_download_directory_key), path).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDownloadThreads() {
|
public int getDownloadThreads() {
|
||||||
|
|
|
@ -32,7 +32,6 @@ public class LibraryUpdateService extends Service {
|
||||||
@Inject SourceManager sourceManager;
|
@Inject SourceManager sourceManager;
|
||||||
|
|
||||||
private Subscription updateSubscription;
|
private Subscription updateSubscription;
|
||||||
private Subscription favoriteMangasSubscription;
|
|
||||||
|
|
||||||
public static final int UPDATE_NOTIFICATION_ID = 1;
|
public static final int UPDATE_NOTIFICATION_ID = 1;
|
||||||
|
|
||||||
|
@ -68,14 +67,9 @@ public class LibraryUpdateService extends Service {
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (favoriteMangasSubscription != null && !favoriteMangasSubscription.isUnsubscribed())
|
Observable.fromCallable(() -> db.getFavoriteMangas().executeAsBlocking())
|
||||||
favoriteMangasSubscription.unsubscribe();
|
|
||||||
|
|
||||||
favoriteMangasSubscription = db.getFavoriteMangas().createObservable()
|
|
||||||
.subscribe(mangas -> {
|
.subscribe(mangas -> {
|
||||||
// Don't receive further db updates
|
startUpdating(mangas, startId);
|
||||||
favoriteMangasSubscription.unsubscribe();
|
|
||||||
this.startUpdating(mangas, startId);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
|
|
|
@ -3,6 +3,9 @@ package eu.kanade.mangafeed.ui.setting;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -24,13 +27,18 @@ public class SettingsAccountsFragment extends SettingsNestedFragment {
|
||||||
|
|
||||||
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
||||||
SettingsNestedFragment fragment = new SettingsAccountsFragment();
|
SettingsNestedFragment fragment = new SettingsAccountsFragment();
|
||||||
fragment.setBundle(resourcePreference, resourceTitle);
|
fragment.setArgs(resourcePreference, resourceTitle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
App.get(getActivity()).getComponent().inject(this);
|
App.get(getActivity()).getComponent().inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedSate) {
|
||||||
|
View view = super.onCreateView(inflater, container, savedSate);
|
||||||
|
|
||||||
PreferenceScreen screen = getPreferenceScreen();
|
PreferenceScreen screen = getPreferenceScreen();
|
||||||
|
|
||||||
|
@ -60,6 +68,7 @@ public class SettingsAccountsFragment extends SettingsNestedFragment {
|
||||||
chapterSyncCategory.addPreference(dialog);
|
chapterSyncCategory.addPreference(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Source> getSourcesWithLogin() {
|
private List<Source> getSourcesWithLogin() {
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class SettingsActivity extends BaseActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
App.get(getActivity()).getComponent().inject(this);
|
App.get(this).getComponent().inject(this);
|
||||||
setContentView(R.layout.activity_preferences);
|
setContentView(R.layout.activity_preferences);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ package eu.kanade.mangafeed.ui.setting;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
|
||||||
|
@ -25,13 +28,14 @@ public class SettingsCacheFragment extends SettingsNestedFragment implements Pre
|
||||||
|
|
||||||
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
||||||
SettingsNestedFragment fragment = new SettingsCacheFragment();
|
SettingsNestedFragment fragment = new SettingsCacheFragment();
|
||||||
fragment.setBundle(resourcePreference, resourceTitle);
|
fragment.setArgs(resourcePreference, resourceTitle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
||||||
super.onCreate(savedInstanceState);
|
View view = super.onCreateView(inflater, container, savedState);
|
||||||
|
|
||||||
cacheManager = getSettingsActivity().cacheManager;
|
cacheManager = getSettingsActivity().cacheManager;
|
||||||
|
|
||||||
IntListPreference cacheSize = (IntListPreference)findPreference(getString(R.string.pref_chapter_cache_size_key));
|
IntListPreference cacheSize = (IntListPreference)findPreference(getString(R.string.pref_chapter_cache_size_key));
|
||||||
|
@ -44,6 +48,8 @@ public class SettingsCacheFragment extends SettingsNestedFragment implements Pre
|
||||||
clearCache = findPreference(getString(R.string.pref_clear_chapter_cache_key));
|
clearCache = findPreference(getString(R.string.pref_clear_chapter_cache_key));
|
||||||
clearCache.setOnPreferenceClickListener(this);
|
clearCache.setOnPreferenceClickListener(this);
|
||||||
clearCache.setSummary(getString(R.string.used_cache, cacheManager.getReadableSize()));
|
clearCache.setSummary(getString(R.string.used_cache, cacheManager.getReadableSize()));
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,40 +1,93 @@
|
||||||
package eu.kanade.mangafeed.ui.setting;
|
package eu.kanade.mangafeed.ui.setting;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.ListPreference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.nononsenseapps.filepicker.AbstractFilePickerFragment;
|
||||||
|
import com.nononsenseapps.filepicker.FilePickerActivity;
|
||||||
|
import com.nononsenseapps.filepicker.FilePickerFragment;
|
||||||
|
import com.nononsenseapps.filepicker.LogicHandler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.util.DiskUtils;
|
|
||||||
|
|
||||||
public class SettingsDownloadsFragment extends SettingsNestedFragment {
|
public class SettingsDownloadsFragment extends SettingsNestedFragment {
|
||||||
|
|
||||||
|
Preference downloadDirPref;
|
||||||
|
|
||||||
|
public static final int DOWNLOAD_DIR_CODE = 1;
|
||||||
|
|
||||||
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
||||||
SettingsNestedFragment fragment = new SettingsDownloadsFragment();
|
SettingsNestedFragment fragment = new SettingsDownloadsFragment();
|
||||||
fragment.setBundle(resourcePreference, resourceTitle);
|
fragment.setArgs(resourcePreference, resourceTitle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
@Override
|
||||||
super.onCreate(savedInstanceState);
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
|
||||||
PreferenceScreen screen = getPreferenceScreen();
|
downloadDirPref = findPreference(getString(R.string.pref_download_directory_key));
|
||||||
|
|
||||||
ListPreference directoriesPref = new ListPreference(getActivity(), null);
|
downloadDirPref.setOnPreferenceClickListener(preference -> {
|
||||||
|
Intent i = new Intent(getActivity(), CustomLayoutPickerActivity.class);
|
||||||
|
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
|
||||||
|
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
|
||||||
|
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);
|
||||||
|
i.putExtra(FilePickerActivity.EXTRA_START_PATH, preferences.getDownloadsDirectory());
|
||||||
|
|
||||||
String[] externalDirs = DiskUtils.getStorageDirectories(getActivity());
|
startActivityForResult(i, DOWNLOAD_DIR_CODE);
|
||||||
directoriesPref.setKey(getString(R.string.pref_download_directory_key));
|
|
||||||
directoriesPref.setTitle(R.string.pref_download_directory);
|
|
||||||
directoriesPref.setEntryValues(externalDirs);
|
|
||||||
directoriesPref.setEntries(externalDirs);
|
|
||||||
directoriesPref.setSummary(preferences.getDownloadsDirectory());
|
|
||||||
|
|
||||||
directoriesPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
|
||||||
preference.setSummary(newValue.toString());
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
screen.addPreference(directoriesPref);
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
downloadDirPref.setSummary(preferences.getDownloadsDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == DOWNLOAD_DIR_CODE && resultCode == Activity.RESULT_OK) {
|
||||||
|
Uri uri = data.getData();
|
||||||
|
preferences.setDownloadsDirectory(uri.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CustomLayoutPickerActivity extends FilePickerActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractFilePickerFragment<File> getFragment(
|
||||||
|
String startPath, int mode, boolean allowMultiple, boolean allowCreateDir) {
|
||||||
|
AbstractFilePickerFragment<File> fragment = new CustomLayoutFilePickerFragment();
|
||||||
|
fragment.setArgs(startPath, mode, allowMultiple, allowCreateDir);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CustomLayoutFilePickerFragment extends FilePickerFragment {
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View v;
|
||||||
|
switch (viewType) {
|
||||||
|
case LogicHandler.VIEWTYPE_DIR:
|
||||||
|
v = LayoutInflater.from(getActivity()).inflate(R.layout.listitem_dir,
|
||||||
|
parent, false);
|
||||||
|
return new DirViewHolder(v);
|
||||||
|
default:
|
||||||
|
return super.onCreateViewHolder(parent, viewType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ package eu.kanade.mangafeed.ui.setting;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.data.preference.PreferencesHelper;
|
import eu.kanade.mangafeed.data.preference.PreferencesHelper;
|
||||||
import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
|
import eu.kanade.mangafeed.ui.base.activity.BaseActivity;
|
||||||
|
@ -15,17 +18,22 @@ public class SettingsNestedFragment extends PreferenceFragment {
|
||||||
|
|
||||||
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
public static SettingsNestedFragment newInstance(int resourcePreference, int resourceTitle) {
|
||||||
SettingsNestedFragment fragment = new SettingsNestedFragment();
|
SettingsNestedFragment fragment = new SettingsNestedFragment();
|
||||||
fragment.setBundle(resourcePreference, resourceTitle);
|
fragment.setArgs(resourcePreference, resourceTitle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
preferences = getSettingsActivity().preferences;
|
|
||||||
addPreferencesFromResource(getArguments().getInt(RESOURCE_FILE));
|
addPreferencesFromResource(getArguments().getInt(RESOURCE_FILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
preferences = getSettingsActivity().preferences;
|
||||||
|
return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -33,7 +41,7 @@ public class SettingsNestedFragment extends PreferenceFragment {
|
||||||
.setToolbarTitle(getString(getArguments().getInt(TOOLBAR_TITLE)));
|
.setToolbarTitle(getString(getArguments().getInt(TOOLBAR_TITLE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBundle(int resourcePreference, int resourceTitle) {
|
public void setArgs(int resourcePreference, int resourceTitle) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt(RESOURCE_FILE, resourcePreference);
|
args.putInt(RESOURCE_FILE, resourcePreference);
|
||||||
args.putInt(TOOLBAR_TITLE, resourceTitle);
|
args.putInt(TOOLBAR_TITLE, resourceTitle);
|
||||||
|
|
|
@ -1,95 +1,20 @@
|
||||||
package eu.kanade.mangafeed.util;
|
package eu.kanade.mangafeed.util;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
|
|
||||||
public final class DiskUtils {
|
public final class DiskUtils {
|
||||||
private static final Pattern DIR_SEPARATOR = Pattern.compile("/");
|
|
||||||
|
|
||||||
private DiskUtils() {
|
private DiskUtils() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/13976982/removable-storage-external-sdcard-path-by-manufacturers
|
|
||||||
// http://stackoverflow.com/questions/11281010/how-can-i-get-external-sd-card-path-for-android-4-0
|
|
||||||
public static String[] getStorageDirectories(Context context) {
|
|
||||||
final Set<String> storageDirectories = new HashSet<String>();
|
|
||||||
|
|
||||||
storageDirectories.add(context.getFilesDir().getAbsolutePath());
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
||||||
File[] directories = context.getExternalFilesDirs(null);
|
|
||||||
if (directories != null) {
|
|
||||||
for (File storage : directories) {
|
|
||||||
if (storage != null) {
|
|
||||||
storageDirectories.add(storage.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE");
|
|
||||||
final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
|
|
||||||
final String rawEmulatedStorageTarget = System.getenv("EMULATED_STORAGE_TARGET");
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(rawEmulatedStorageTarget)) {
|
|
||||||
if (TextUtils.isEmpty(rawExternalStorage)) {
|
|
||||||
storageDirectories.add("/storage/sdcard0" + File.separator + context.getPackageName());
|
|
||||||
} else {
|
|
||||||
storageDirectories.add(rawExternalStorage + File.separator + context.getPackageName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final String rawUserId;
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
||||||
rawUserId = "";
|
|
||||||
} else {
|
|
||||||
final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
||||||
final String[] folders = DIR_SEPARATOR.split(path);
|
|
||||||
final String lastFolder = folders[folders.length - 1];
|
|
||||||
boolean isDigit = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
Integer.valueOf(lastFolder);
|
|
||||||
isDigit = true;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
// Do Nothing.
|
|
||||||
}
|
|
||||||
|
|
||||||
rawUserId = isDigit ? lastFolder : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(rawUserId)) {
|
|
||||||
storageDirectories.add(rawEmulatedStorageTarget + File.separator + context.getPackageName());
|
|
||||||
} else {
|
|
||||||
storageDirectories.add(rawEmulatedStorageTarget + File.separator + rawUserId + File.separator + context.getPackageName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(rawSecondaryStoragesStr)) {
|
|
||||||
String[] rawSecondaryStorages = rawSecondaryStoragesStr.split(File.pathSeparator);
|
|
||||||
for (int index = 0; index < rawSecondaryStorages.length; index++) {
|
|
||||||
storageDirectories.add(rawSecondaryStorages[index] + File.separator + context.getPackageName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return storageDirectories.toArray(new String[storageDirectories.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String hashKeyForDisk(String key) {
|
public static String hashKeyForDisk(String key) {
|
||||||
String cacheKey;
|
String cacheKey;
|
||||||
try {
|
try {
|
||||||
|
|
37
app/src/main/res/layout/listitem_dir.xml
Normal file
37
app/src/main/res/layout/listitem_dir.xml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/nnf_item_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?android:listPreferredItemHeight"
|
||||||
|
android:background="?selectableItemBackground"
|
||||||
|
android:focusable="true"
|
||||||
|
android:minHeight="?android:listPreferredItemHeight"
|
||||||
|
android:nextFocusLeft="@+id/nnf_button_cancel"
|
||||||
|
android:nextFocusRight="@+id/nnf_button_ok"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/item_icon"
|
||||||
|
android:layout_width="?android:listPreferredItemHeight"
|
||||||
|
android:layout_height="?android:listPreferredItemHeight"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:src="@drawable/nnf_ic_file_folder"
|
||||||
|
android:tint="?attr/colorAccent"
|
||||||
|
android:visibility="visible"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/text1"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="@string/nnf_name" />
|
||||||
|
</LinearLayout>
|
|
@ -64,6 +64,10 @@
|
||||||
<string name="cache_deleted">Cache cleared. %1$d files have been deleted</string>
|
<string name="cache_deleted">Cache cleared. %1$d files have been deleted</string>
|
||||||
<string name="cache_delete_error">An error occurred clearing cache</string>
|
<string name="cache_delete_error">An error occurred clearing cache</string>
|
||||||
|
|
||||||
|
<!-- ACRA -->
|
||||||
|
<string name="pref_enable_acra">Send crash reports</string>
|
||||||
|
<string name="pref_acra_summary">Help fixing bugs. Sensitive data is not sent</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Login dialog -->
|
<!-- Login dialog -->
|
||||||
<string name="accounts_login_title">Login for %1$s</string>
|
<string name="accounts_login_title">Login for %1$s</string>
|
||||||
|
|
|
@ -50,6 +50,21 @@
|
||||||
<item name="android:background">#e5e5e5</item>
|
<item name="android:background">#e5e5e5</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="FilePickerTheme" parent="NNF_BaseTheme.Light">
|
||||||
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
<item name="colorButtonNormal">@color/colorPrimary</item>
|
||||||
|
<item name="android:textSize">14sp</item>
|
||||||
|
|
||||||
|
<item name="alertDialogTheme">@style/FilePickerAlertDialogTheme</item>
|
||||||
|
|
||||||
|
<item name="nnf_toolbarTheme">@style/ThemeOverlay.AppTheme.Dark</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="manga_detail_label">
|
<style name="manga_detail_label">
|
||||||
<item name="android:textSize">15sp</item>
|
<item name="android:textSize">15sp</item>
|
||||||
<item name="android:textStyle">bold</item>
|
<item name="android:textStyle">bold</item>
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
android:orderingFromXml="true">
|
|
||||||
|
|
||||||
<ListPreference android:title="@string/pref_download_threads"
|
<Preference
|
||||||
|
android:title="@string/pref_download_directory"
|
||||||
|
android:key="@string/pref_download_directory_key"/>
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:title="@string/pref_download_threads"
|
||||||
android:key="@string/pref_download_threads_key"
|
android:key="@string/pref_download_threads_key"
|
||||||
android:entries="@array/download_threads"
|
android:entries="@array/download_threads"
|
||||||
android:entryValues="@array/download_threads"
|
android:entryValues="@array/download_threads"
|
||||||
android:defaultValue="1"
|
android:defaultValue="1"
|
||||||
android:order="1"
|
|
||||||
android:summary="%s"/>
|
android:summary="%s"/>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
|
@ -21,4 +21,10 @@
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/pref_category_cache" />
|
android:title="@string/pref_category_cache" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="acra.enable"
|
||||||
|
android:title="@string/pref_enable_acra"
|
||||||
|
android:summary="@string/pref_acra_summary"
|
||||||
|
android:defaultValue="false"/>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Reference in a new issue