]> git.zerfleddert.de Git - FreeShisen/commitdiff
when clearing hiscores, update fields immediately.
authorgitknilch <gitknilch@cwde.de>
Sat, 9 Mar 2013 20:53:41 +0000 (21:53 +0100)
committergitknilch <gitknilch@cwde.de>
Sat, 9 Mar 2013 20:53:41 +0000 (21:53 +0100)
src/de/cwde/freeshisen/HighscoreActivity.java
src/de/cwde/freeshisen/SettingsActivity.java

index 70d5f3dc6b1b704196a8fc9b4faa9dde3629b978..bf94458f089b221c8f2ce1b916249e468e2decc1 100644 (file)
@@ -8,15 +8,44 @@ import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 
 
-public class HighscoreActivity extends Activity {
+public class HighscoreActivity extends Activity implements
+OnSharedPreferenceChangeListener {
 
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.highscore);
 
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.highscore);
-               // now fill the values, argh...
-               SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
+               updateTextViews();
+
+               PreferenceManager.getDefaultSharedPreferences(this)
+               .registerOnSharedPreferenceChangeListener(this);
+       }
+
+       @Override
+       protected void onResume() {
+               super.onResume();
+               PreferenceManager.getDefaultSharedPreferences(this)
+               .registerOnSharedPreferenceChangeListener(this);
+       }
+
+       @Override
+       protected void onPause() {
+               super.onPause();
+               PreferenceManager.getDefaultSharedPreferences(this)
+               .unregisterOnSharedPreferenceChangeListener(this);
+       }
+
+       public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+                       String key) {
+               updateTextViews();
+       }
+
+       private void updateTextViews() {
+               // argh...
+               SharedPreferences sp = PreferenceManager
+                               .getDefaultSharedPreferences(this);
                fillTextView(sp, R.id.textViewHL1, "hiscore_HL1");
                fillTextView(sp, R.id.textViewHL2, "hiscore_HL2");
                fillTextView(sp, R.id.textViewHM1, "hiscore_HM1");
                fillTextView(sp, R.id.textViewHL1, "hiscore_HL1");
                fillTextView(sp, R.id.textViewHL2, "hiscore_HL2");
                fillTextView(sp, R.id.textViewHM1, "hiscore_HM1");
@@ -44,35 +73,36 @@ public class HighscoreActivity extends Activity {
 
                builder.setPositiveButton(android.R.string.ok,
                                new DialogInterface.OnClickListener() {
 
                builder.setPositiveButton(android.R.string.ok,
                                new DialogInterface.OnClickListener() {
-                                       public void onClick(DialogInterface dialog, int id) {
-                                               // User clicked OK button - delete hiscores
-                                               SharedPreferences sp = PreferenceManager
-                                                               .getDefaultSharedPreferences(
-                                                                               ((AlertDialog) dialog).getContext());
-                                               SharedPreferences.Editor editor = sp.edit();
-                                               editor.remove("hiscore_HL1");
-                                               editor.remove("hiscore_HL2");
-                                               editor.remove("hiscore_HM1");
-                                               editor.remove("hiscore_HM2");
-                                               editor.remove("hiscore_HS1");
-                                               editor.remove("hiscore_HS2");
-                                               editor.remove("hiscore_EL1");
-                                               editor.remove("hiscore_EL2");
-                                               editor.remove("hiscore_EM1");
-                                               editor.remove("hiscore_EM2");
-                                               editor.remove("hiscore_ES1");
-                                               editor.remove("hiscore_ES2");
-                                               editor.commit();
-                                       }
-                               });
+                       public void onClick(DialogInterface dialog, int id) {
+                               // User clicked OK button - delete hiscores
+                               SharedPreferences sp = PreferenceManager
+                                               .getDefaultSharedPreferences(((AlertDialog) dialog)
+                                                               .getContext());
+                               SharedPreferences.Editor editor = sp.edit();
+                               editor.remove("hiscore_HL1");
+                               editor.remove("hiscore_HL2");
+                               editor.remove("hiscore_HM1");
+                               editor.remove("hiscore_HM2");
+                               editor.remove("hiscore_HS1");
+                               editor.remove("hiscore_HS2");
+                               editor.remove("hiscore_EL1");
+                               editor.remove("hiscore_EL2");
+                               editor.remove("hiscore_EM1");
+                               editor.remove("hiscore_EM2");
+                               editor.remove("hiscore_ES1");
+                               editor.remove("hiscore_ES2");
+                               editor.commit();
+                       }
+               });
                builder.setNegativeButton(android.R.string.cancel,
                                new DialogInterface.OnClickListener() {
                builder.setNegativeButton(android.R.string.cancel,
                                new DialogInterface.OnClickListener() {
-                                       public void onClick(DialogInterface dialog, int id) {
-                                               // User cancelled the dialog - nothing to do
-                                       }
-                               });
+                       public void onClick(DialogInterface dialog, int id) {
+                               // User cancelled the dialog - nothing to do
+                       }
+               });
 
                AlertDialog dialog = builder.create();
                dialog.show();
 
                AlertDialog dialog = builder.create();
                dialog.show();
+               updateTextViews();
        }
 }
        }
 }
index fbc87ae25bdf8fed3c49621b9aa307904d1dc48f..d055b2fed36ee62b4e5415cba9ed6a44080ec581 100644 (file)
@@ -51,7 +51,6 @@ implements OnSharedPreferenceChangeListener {
                .unregisterOnSharedPreferenceChangeListener(this);
        }
 
                .unregisterOnSharedPreferenceChangeListener(this);
        }
 
-
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
                updateSummary(sharedPreferences, key, KEY_PREF_DIFF, R.array.difficulties);
                updateSummary(sharedPreferences, key, KEY_PREF_SIZE, R.array.sizes);
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
                updateSummary(sharedPreferences, key, KEY_PREF_DIFF, R.array.difficulties);
                updateSummary(sharedPreferences, key, KEY_PREF_SIZE, R.array.sizes);
Impressum, Datenschutz