Skip to content

Commit

Permalink
Replaced PreferenceActivity for a PreferenceFragmentCompat. App is no…
Browse files Browse the repository at this point in the history
…w a single activity.
  • Loading branch information
rumboalla committed Aug 30, 2016
1 parent a0df756 commit e2e8866
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 459 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:preference-v7:24.2.0'
compile 'org.jsoup:jsoup:1.9.2'
compile 'com.squareup:otto:1.3.8'
compile 'com.google.code.gson:gson:2.7'
Expand Down
51 changes: 47 additions & 4 deletions app/src/main/java/com/apkupdater/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;

import com.apkupdater.adapter.MainActivityPageAdapter;
import com.apkupdater.R;
import com.apkupdater.event.InstalledAppTitleChange;
import com.apkupdater.event.UpdaterTitleChange;
import com.apkupdater.fragment.SettingsFragment;
import com.apkupdater.receiver.BootReceiver_;
import com.apkupdater.service.UpdaterService_;
import com.apkupdater.util.ColorUtitl;
Expand Down Expand Up @@ -54,12 +57,17 @@ public class MainActivity
@Bean
AppState mAppState;

@ViewById(R.id.settings_container)
FrameLayout mSettingsLayout;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreate(
Bundle savedInstanceState
) {
setThemeFromOptions();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

Expand Down Expand Up @@ -96,6 +104,32 @@ void init(
ColorUtitl.getColorFromTheme(getTheme(), android.R.attr.windowBackground)
);
}

// Add the settings fragment and configure the correct state
getSupportFragmentManager().beginTransaction().replace(R.id.settings_container, new SettingsFragment()).commit();
switchSettings(mAppState.getSettingsActive());
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private void switchSettings(
boolean b
) {
if (b) {
mTabLayout.setVisibility(View.GONE);
mViewPager.setVisibility(View.GONE);
mSettingsLayout.setVisibility(View.VISIBLE);
getSupportActionBar().setTitle(getString(R.string.action_settings));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} else {
mTabLayout.setVisibility(View.VISIBLE);
mViewPager.setVisibility(View.VISIBLE);
mSettingsLayout.setVisibility(View.GONE);
getSupportActionBar().setTitle(getString(R.string.app_name));
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}

mAppState.setSettingsActive(b);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -111,7 +145,8 @@ private void checkFirstStart(
new BootReceiver_().onReceive(getBaseContext(), null);

// Set the first start flag to false
mAppState.setmFirstStart(false);
mAppState.setFirstStart(false);
mAppState.setSettingsActive(false);
}
}

Expand All @@ -132,7 +167,7 @@ private void selectTab(
@OptionsItem(R.id.action_settings)
void onSettingsClick(
) {
SettingsActivity_.intent(this).start();
switchSettings(!mAppState.getSettingsActive());
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -145,6 +180,14 @@ void onUpdateClick(

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@OptionsItem(android.R.id.home)
void onHomeClick(
) {
switchSettings(!mAppState.getSettingsActive());
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down

This file was deleted.

Loading

0 comments on commit e2e8866

Please sign in to comment.