Starting preferences

This commit is contained in:
inorichi 2015-10-21 19:27:22 +02:00
parent af678a5b3c
commit 985d71a869
11 changed files with 106 additions and 17 deletions

View File

@ -37,6 +37,11 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="eu.kanade.mangafeed.ui.activity.MangaDetailActivity" /> android:value="eu.kanade.mangafeed.ui.activity.MangaDetailActivity" />
</activity> </activity>
<activity
android:name=".ui.activity.SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".ui.activity.MainActivity" >
</activity>
</application> </application>
</manifest> </manifest>

View File

@ -2,28 +2,28 @@ package eu.kanade.mangafeed.data.helpers;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import eu.kanade.mangafeed.R;
public class PreferencesHelper { public class PreferencesHelper {
private static SharedPreferences mPref; private static SharedPreferences mPref;
public static final String PREF_FILE_NAME = "android_boilerplate_pref_file"; private static final String PREF_HIDE_STATUS_BAR = "hide_status_bar";
public PreferencesHelper(Context context) { public PreferencesHelper(Context context) {
mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE); PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
mPref = PreferenceManager.getDefaultSharedPreferences(context);
} }
public void clear() { public void clear() {
mPref.edit().clear().apply(); mPref.edit().clear().apply();
} }
public boolean isFirstRun() { public boolean hideStatusBarSet() {
return mPref.getBoolean("firstrun", true); return mPref.getBoolean(PREF_HIDE_STATUS_BAR, false);
}
public void setNotFirstRun() {
mPref.edit().putBoolean("firstrun", false).commit();
} }
} }

View File

@ -4,7 +4,10 @@ import android.os.Bundle;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
import eu.kanade.mangafeed.data.models.Chapter; import eu.kanade.mangafeed.data.models.Chapter;
import eu.kanade.mangafeed.data.models.Page; import eu.kanade.mangafeed.data.models.Page;
import eu.kanade.mangafeed.sources.Source; import eu.kanade.mangafeed.sources.Source;
@ -18,6 +21,8 @@ import rx.schedulers.Schedulers;
public class ReaderPresenter extends BasePresenter<ReaderActivity> { public class ReaderPresenter extends BasePresenter<ReaderActivity> {
@Inject PreferencesHelper prefs;
private Source source; private Source source;
private Chapter chapter; private Chapter chapter;
private List<Page> pageList; private List<Page> pageList;
@ -52,6 +57,10 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
protected void onTakeView(ReaderActivity view) { protected void onTakeView(ReaderActivity view) {
super.onTakeView(view); super.onTakeView(view);
registerForStickyEvents(); registerForStickyEvents();
if (prefs.hideStatusBarSet()) {
view.hideStatusBar();
}
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package eu.kanade.mangafeed.ui.activity; package eu.kanade.mangafeed.ui.activity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
@ -16,7 +17,6 @@ import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.ui.activity.base.BaseActivity; import eu.kanade.mangafeed.ui.activity.base.BaseActivity;
import eu.kanade.mangafeed.ui.fragment.LibraryFragment; import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
import eu.kanade.mangafeed.ui.fragment.SourceFragment; import eu.kanade.mangafeed.ui.fragment.SourceFragment;
import nucleus.factory.RequiresPresenter;
public class MainActivity extends BaseActivity { public class MainActivity extends BaseActivity {
@ -54,6 +54,7 @@ public class MainActivity extends BaseActivity {
new PrimaryDrawerItem() new PrimaryDrawerItem()
.withName(R.string.settings_title) .withName(R.string.settings_title)
.withIdentifier(R.id.nav_drawer_settings) .withIdentifier(R.id.nav_drawer_settings)
.withSelectable(false)
) )
.withSavedInstance(savedInstanceState) .withSavedInstance(savedInstanceState)
.withOnDrawerItemClickListener( .withOnDrawerItemClickListener(
@ -70,6 +71,7 @@ public class MainActivity extends BaseActivity {
setFragment(SourceFragment.newInstance()); setFragment(SourceFragment.newInstance());
break; break;
case R.id.nav_drawer_settings: case R.id.nav_drawer_settings:
startActivity(new Intent(this, SettingsActivity.class));
break; break;
} }
} }

View File

@ -2,8 +2,11 @@ package eu.kanade.mangafeed.ui.activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
import java.util.List; import java.util.List;
@ -89,4 +92,16 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
String page = (currentPage+1) + "/" + adapter.getCount(); String page = (currentPage+1) + "/" + adapter.getCount();
pageNumber.setText(page); pageNumber.setText(page);
} }
public void hideStatusBar() {
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
} }

View File

@ -0,0 +1,36 @@
package eu.kanade.mangafeed.ui.activity;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v7.widget.Toolbar;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.ui.activity.base.BaseActivity;
public class SettingsActivity extends BaseActivity {
@Bind(R.id.toolbar) Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);
ButterKnife.bind(this);
setupToolbar(toolbar);
getFragmentManager().beginTransaction().replace(R.id.settings_content,
new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}

View File

@ -1,15 +1,9 @@
package eu.kanade.mangafeed.ui.activity.base; package eu.kanade.mangafeed.ui.activity.base;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import eu.kanade.mangafeed.App;
import nucleus.factory.PresenterFactory;
import nucleus.presenter.Presenter;
import nucleus.view.NucleusAppCompatActivity;
public class BaseActivity extends AppCompatActivity { public class BaseActivity extends AppCompatActivity {
protected void setupToolbar(Toolbar toolbar) { protected void setupToolbar(Toolbar toolbar) {

View File

@ -1,7 +1,6 @@
package eu.kanade.mangafeed.ui.fragment.base; package eu.kanade.mangafeed.ui.fragment.base;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import eu.kanade.mangafeed.App; import eu.kanade.mangafeed.App;
import nucleus.factory.PresenterFactory; import nucleus.factory.PresenterFactory;

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<FrameLayout
android:id="@+id/settings_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>

View File

@ -46,5 +46,8 @@
<string name="manga_detail_tab">Info</string> <string name="manga_detail_tab">Info</string>
<string name="manga_chapters_tab">Chapters</string> <string name="manga_chapters_tab">Chapters</string>
<string name="title_activity_viewer">ViewerActivity</string> <string name="title_activity_viewer">ViewerActivity</string>
<string name="title_activity_settings">Settings</string>
<string name="pref_hide_status_bar">Hide status bar</string>
<string name="pref_hide_status_bar_summary">This option will hide the status bar while reading</string>
</resources> </resources>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference android:title="@string/pref_hide_status_bar"
android:defaultValue="false"
android:summary="@string/pref_hide_status_bar_summary"
android:key="hide_status_bar" />
</PreferenceScreen>