Move theme checkbox to settings activity

This commit is contained in:
Neslihan 2017-03-18 01:49:19 +03:00
parent c7909b4f66
commit 7e256175dc
23 changed files with 118 additions and 121 deletions

View file

@ -5,6 +5,8 @@ import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import fr.free.nrw.commons.theme.BaseActivity;
public class AboutActivity extends BaseActivity {
private TextView versionText;
private TextView licenseText;

View file

@ -1,19 +0,0 @@
package fr.free.nrw.commons;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
public class BaseActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//Check prefs on every activity starts
if (getSharedPreferences("prefs", Context.MODE_PRIVATE).getBoolean("theme", false)) {
setTheme(R.style.LightAppTheme);
}else {
setTheme(R.style.DarkAppTheme); //default
}
super.onCreate(savedInstanceState);
}
}

View file

@ -1,19 +0,0 @@
package fr.free.nrw.commons;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class BaseAppCompatActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//Check prefs on every activity starts
if (getSharedPreferences("prefs", Context.MODE_PRIVATE).getBoolean("theme", false)) {
setTheme(R.style.LightAppTheme);
}else {
setTheme(R.style.DarkAppTheme); //default
}
super.onCreate(savedInstanceState);
}
}

View file

@ -1,13 +1,16 @@
package fr.free.nrw.commons;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
import android.support.v4.content.IntentCompat;
import android.support.v7.app.AppCompatDelegate;
import android.view.MenuInflater;
import android.view.View;
@ -23,10 +26,10 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
//Check prefs on every activity starts
if (getSharedPreferences("prefs", Context.MODE_PRIVATE).getBoolean("theme", false)) {
setTheme(R.style.LightAppTheme);
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false)) {
setTheme(R.style.DarkAppTheme);
}else {
setTheme(R.style.DarkAppTheme); //default
setTheme(R.style.LightAppTheme); //default
}
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
@ -76,7 +79,12 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("theme")){
//Finish current activity and tart new one with selected theme
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
// All the stuff below is just to get a actionbar that says settings...

View file

@ -9,6 +9,8 @@ import android.widget.Button;
import com.viewpagerindicator.CirclePageIndicator;
import fr.free.nrw.commons.theme.BaseActivity;
public class WelcomeActivity extends BaseActivity {
static final int PAGE_WIKIPEDIA = 0,
PAGE_DO_UPLOAD = 1,

View file

@ -11,11 +11,10 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import java.io.IOException;
import fr.free.nrw.commons.BaseAppCompatActivity;
import fr.free.nrw.commons.theme.BaseAppCompatActivity;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.Utils;

View file

@ -8,7 +8,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import fr.free.nrw.commons.BaseActivity;
import fr.free.nrw.commons.theme.BaseActivity;
public class SignupActivity extends BaseActivity {

View file

@ -125,7 +125,6 @@ public class ContributionsActivity
if (mediaDetails != null && savedInstanceState.getBoolean("mediaDetailsVisible")) {
// Feels awful that we have to reset this manually!
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(true);
}
}
requestAuthToken();

View file

@ -11,6 +11,7 @@ import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.IntentCompat;
import android.support.v7.app.ActionBar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@ -166,27 +167,6 @@ public class ContributionsListFragment extends Fragment {
startActivity(nearbyIntent);
return true;
}
case R.id.menu_theme_toggle:
final SharedPreferences prefs = getActivity().getSharedPreferences("prefs", Context.MODE_PRIVATE);
prefs.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if(s.equals("theme")){
//http://stackoverflow.com/questions/5659742/onsharedpreferencechanged-called-multiple-times-why
prefs.unregisterOnSharedPreferenceChangeListener(this);
//Finish current activity and tart new one with selected theme
Intent intent = getActivity().getIntent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
getActivity().finish();
startActivity(intent);
}
}
});
SharedPreferences.Editor editor = prefs.edit();
//put inverse of selected boolean
editor.putBoolean("theme", !prefs.getBoolean("theme", false));
editor.commit();
return true;
case R.id.menu_refresh:
((SourceRefresher)getActivity()).refreshSource();
return true;
@ -229,7 +209,6 @@ public class ContributionsListFragment extends Fragment {
}
menu.findItem(R.id.menu_refresh).setVisible(false);
menu.findItem(R.id.menu_theme_toggle).setActionView(R.layout.theme_toggle_layout);
}
/*http://stackoverflow.com/questions/30076392/how-does-this-strange-condition-happens-when-show-menu-item-icon-in-toolbar-over/30337653#30337653

View file

@ -12,7 +12,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import fr.free.nrw.commons.BaseAppCompatActivity;
import fr.free.nrw.commons.theme.BaseAppCompatActivity;
import fr.free.nrw.commons.R;
public class NearbyActivity extends BaseAppCompatActivity {

View file

@ -0,0 +1,39 @@
package fr.free.nrw.commons.theme;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import fr.free.nrw.commons.R;
public class BaseActivity extends Activity {
boolean currentTheme;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false)) {
currentTheme = true;
setTheme(R.style.DarkAppTheme);
}else {
currentTheme = false;
setTheme(R.style.LightAppTheme); //default
}
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
//Restart activity if theme is changed
Log.d("deneme","onResume Base");
boolean newTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false);
if(currentTheme!=newTheme){ //is activity theme changed
Intent intent = getIntent();
finish();
startActivity(intent);
}
super.onResume();
}
}

View file

@ -0,0 +1,38 @@
package fr.free.nrw.commons.theme;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import fr.free.nrw.commons.R;
public class BaseAppCompatActivity extends AppCompatActivity {
boolean currentTheme;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false)) {
currentTheme = true;g
setTheme(R.style.DarkAppTheme);
}else {
currentTheme = false;
setTheme(R.style.LightAppTheme); //default
}
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
//Restart activity if theme is changed
Log.d("deneme","onResume Base");
boolean newTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false);
if(currentTheme!=newTheme){ //is activity theme changed
Intent intent = getIntent();
finish();
startActivity(intent);
}
super.onResume();
}
}

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
@ -116,7 +117,7 @@ public class SingleUploadFragment extends Fragment {
//Set selected color to white because it should be readable on random images.
TextView selectedText = (TextView) licenseSpinner.getChildAt(0);
if (selectedText != null) {
if (selectedText != null ) {
selectedText.setTextColor(Color.WHITE);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 641 B

View file

@ -1,9 +0,0 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/toggle"
android:state_checked="true"/>
<item
android:drawable="@drawable/toggle_inverse"
android:state_checked="false"/>
</selector>

View file

@ -33,21 +33,12 @@
android:imeOptions="flagNoExtractUi"
/>
<LinearLayout
<Spinner
android:id="@+id/licenseSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/LightAppTheme"
>
<Spinner
android:id="@+id/licenseSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/SpinnerTheme"
/>
</LinearLayout>
android:theme="?attr/spinnerTheme"
/>
<Button
android:text="@string/use_previous"

View file

@ -1,18 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="?attr/toggleButtonIcon"
/>
</LinearLayout>

View file

@ -28,12 +28,6 @@
android:title="@string/menu_nearby"
app:showAsAction="never"
/>
<item android:id="@+id/menu_theme_toggle"
android:title="Night mode"
android:icon="?attr/toggleButtonIcon"
app:actionLayout="@layout/theme_toggle_layout"
app:showAsAction="never"
/>
<item android:id="@+id/menu_refresh"
android:title="@string/menu_refresh"
app:showAsAction="never"

View file

@ -7,7 +7,7 @@
<attr name="fragmentCategorisationBackground" format="reference"/>
<attr name="buttonBackground" format="reference"/>
<attr name="uploadOverlayBackground" format="reference"/>
<attr name="toggleButtonIcon" format="reference"/>
<attr name="spinnerTheme" format="reference"/>
<attr name="iconSend" format="reference"/>
<attr name="iconSave" format="reference"/>
<attr name="iconCamera" format="reference"/>

View file

@ -93,7 +93,7 @@ Tap this message (or hit back) to skip this step.</string>
<string name="allow_gps">Automatically get current location</string>
<string name="allow_gps_summary">Retrieve current location to offer category suggestions if image is not geotagged</string>
<string name="preference_theme">Select theme</string>
<string name="preference_theme_summary">Select application theme as light/dark</string>
<string name="preference_theme_summary">Select if you prefer night mode</string>
<string name="license_name_cc_by_sa_four"> Attribution-ShareAlike 4.0</string>
<string name="license_name_cc_by_four"> Attribution 4.0</string>
<string name="license_name_cc_by_sa"> Attribution-ShareAlike 3.0</string>

View file

@ -8,12 +8,12 @@
<item name="fragmentCategorisationBackground">@color/fragment_categorisation_background_dark</item>
<item name="buttonBackground">@color/button_background_dark</item>
<item name="uploadOverlayBackground">@color/upload_overlay_background_dark</item>
<item name="toggleButtonIcon">@drawable/toggle_inverse</item>
<item name="iconSend">@drawable/ic_send_white_24dp</item>
<item name="iconSave">@drawable/ic_save_white_24dp</item>
<item name="iconCamera">@drawable/ic_photo_camera_white_24dp</item>
<item name="iconPhoto">@drawable/ic_photo_white_24dp</item>
<item name="iconUndo">@drawable/ic_undo_white_24dp</item>
<item name="spinnerTheme">@style/DarkSpinnerTheme</item>
</style>
<style name="LightAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
@ -24,7 +24,6 @@
<item name="fragmentCategorisationBackground">@color/fragment_categorisation_background_light</item>
<item name="buttonBackground">@color/button_background_light</item>
<item name="uploadOverlayBackground">@color/upload_overlay_background_light</item>
<item name="toggleButtonIcon">@drawable/toggle</item>
<item name="iconSend">@drawable/ic_send_white_24dp</item>
<item name="iconSave">@drawable/ic_save_white_24dp</item>
<item name="iconCamera">@drawable/ic_photo_camera_white_24dp</item>
@ -33,9 +32,14 @@
<item name="colorPrimary">@color/action_bar_blue</item>
<item name="colorPrimaryDark">@color/status_bar_blue</item>
<item name="spinnerTheme">@style/LightSpinnerTheme</item>
</style>
<style name="SpinnerTheme" parent="LightAppTheme">
<style name="DarkSpinnerTheme" parent="DarkAppTheme">
<item name="colorControlNormal">#ffffff</item>
</style>
<style name="LightSpinnerTheme" parent="LightAppTheme">
<item name="colorControlNormal">#ffffff</item>
</style>

View file

@ -19,5 +19,11 @@
android:data="@string/beta_opt_in_link" />
</Preference>
<CheckBoxPreference
android:title="@string/preference_theme"
android:defaultValue="false"
android:summary="@string/preference_theme_summary"
android:key="theme" />
</PreferenceScreen>