mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
Move theme checkbox to settings activity
This commit is contained in:
parent
c7909b4f66
commit
7e256175dc
23 changed files with 118 additions and 121 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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...
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue