MobiAds: show first the no already read ads.
authorgumartinm <gustavo@gumartinm.name>
Sun, 24 Jun 2012 01:13:48 +0000 (03:13 +0200)
committergumartinm <gustavo@gumartinm.name>
Sun, 24 Jun 2012 01:13:48 +0000 (03:13 +0200)
Android/MobiAdsReloaded/AndroidManifest.xml
Android/MobiAdsReloaded/src/de/android/mobiads/MobiAdsService.java
Android/MobiAdsReloaded/src/de/android/mobiads/list/MobiAdsLatestList.java
Android/MobiAdsReloaded/src/de/android/mobiads/list/MobiAdsList.java
Android/MobiAdsReloaded/src/de/android/mobiads/provider/Indexer.java

index c444fa6..614c48f 100644 (file)
@@ -18,7 +18,7 @@
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
-    <uses-permission android:name="de.android.mobiads.MOBIADSRECEIVER" />
+    <uses-permission android:name="de.android.mobiads.MOBIADSSERVICERECEIVER" />
 
     <application
         android:icon="@drawable/ic_launcher" android:label="@string/app_name" 
index 116a6ad..d18e836 100644 (file)
@@ -77,7 +77,7 @@ public class MobiAdsService extends Service {
                //TODO: If I do not want to have any trouble, to use a synchronize to access this code here and when
                //receiving new ads. Besides you are using the same code xD. No time right now. I must improve my code
                //but I am in a hurry.
-               if(action.equals("de.android.mobiads.MOBIADSRECEIVER")){
+               if(action.equals("de.android.mobiads.MOBIADSSERVICERECEIVER")){
                        updateNotification();
                }
        }
@@ -148,7 +148,7 @@ public class MobiAdsService extends Service {
         
         
         IntentFilter filter = new IntentFilter();
-        filter.addAction("de.android.mobiads.MOBIADSRECEIVER");
+        filter.addAction("de.android.mobiads.MOBIADSSERVICERECEIVER");
         registerReceiver(receiver, filter);
 
         
index c38ff02..3d77300 100644 (file)
@@ -40,6 +40,28 @@ public class MobiAdsLatestList extends ListActivity implements LoaderManager.Loa
     protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                
+               mReceiver = new BroadcastReceiver() {
+               
+               @Override
+               public void onReceive(Context context, Intent intent) {
+                       String action = intent.getAction();
+                       //This will be run in the main thread of this service. It might be interesting to use a Handler
+                       //for this receiver implementing its own thread. :/
+                       if(action.equals("de.android.mobiads.MOBIADSLISTRECEIVER")){
+                               getLoaderManager().restartLoader(0, null, MobiAdsLatestList.this);
+                       }
+               }
+       };
+       
+       IntentFilter filter = new IntentFilter();
+        filter.addAction("de.android.mobiads.MOBIADSLISTRECEIVER");
+        registerReceiver(mReceiver, filter);
+       }
+       
+       @Override
+    protected void onResume() {
+               super.onResume();
+               
                mAdapter = new AdsEntryLatestAdapter(this, R.layout.ads_entry_list_item);
                 setListAdapter(mAdapter);
                    
@@ -59,37 +81,24 @@ public class MobiAdsLatestList extends ListActivity implements LoaderManager.Loa
                                }
                                
                                //Change notification (if there is one)
-                               Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSRECEIVER");
+                               Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSSERVICERECEIVER");
+                               sendBroadcast(updateDatabase);                  
+                               
+                               mAdapter.remove(entry);
+                               //Update view lists
+                               updateDatabase = new Intent("de.android.mobiads.MOBIADSLISTRECEIVER");
                                sendBroadcast(updateDatabase);
                                
                                Uri uri = Uri.parse(mAdapter.getItem(position).getURL());
                                startActivity(new Intent(Intent.ACTION_VIEW, uri));
                                
-                               //This will update our view showing a nice black background for this item in our list :/
-                               mAdapter.notifyDataSetChanged();
+                               mAdapter.notifyDataSetChanged();                                
                        }
                 });
                 
                 registerForContextMenu(getListView());
            
                 getLoaderManager().initLoader(0, null, this);
-               
-                mReceiver = new BroadcastReceiver() {
-               
-               @Override
-               public void onReceive(Context context, Intent intent) {
-                       String action = intent.getAction();
-                       //This will be run in the main thread of this service. It might be interesting to use a Handler
-                       //for this receiver implementing its own thread. :/
-                       if(action.equals("de.android.mobiads.MOBIADSLISTRECEIVER")){
-                               getLoaderManager().restartLoader(0, null, MobiAdsLatestList.this);
-                       }
-               }
-       };
-       
-       IntentFilter filter = new IntentFilter();
-        filter.addAction("de.android.mobiads.MOBIADSLISTRECEIVER");
-        registerReceiver(mReceiver, filter);
        }
        
        @Override
@@ -110,7 +119,7 @@ public class MobiAdsLatestList extends ListActivity implements LoaderManager.Loa
                        List<AdsEntry> data) {
                
                mAdapter.setData(data);
-               
+               mAdapter.notifyDataSetChanged();
        }
 
        @Override
@@ -146,12 +155,17 @@ public class MobiAdsLatestList extends ListActivity implements LoaderManager.Loa
                                                                                                                                                                                + "/idad/" + idAd);
                
                getContentResolver().delete(uriDelete, null, null);
-               mAdapter.remove(entry);
-               
+                       
                //Change notification (if there is one)
-               Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSRECEIVER");
+               Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSSERVICERECEIVER");
+               sendBroadcast(updateDatabase);
+               
+               //Update view lists
+               updateDatabase = new Intent("de.android.mobiads.MOBIADSLISTRECEIVER");
                sendBroadcast(updateDatabase);
                
+               mAdapter.remove(entry);
+               
                mAdapter.notifyDataSetChanged();
        }
        
index e747b83..18ae170 100644 (file)
@@ -398,15 +398,15 @@ public class MobiAdsList extends Activity {
                        }
                        
                        //Change notification (if there is one)
-                       Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSRECEIVER");
-                       getActivity().sendBroadcast(updateDatabase);
-               
-               //Going to open the web navigator whatever it is... 
-                       Uri uri = Uri.parse(entry.getURL());
-                       startActivity(new Intent(Intent.ACTION_VIEW, uri));             
+                       Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSSERVICERECEIVER");
+                       getActivity().sendBroadcast(updateDatabase);            
                        
                        //This will update our view showing a nice black background for this item in our list :/
                        mAdapter.notifyDataSetChanged();
+                       
+                       //Going to open the web navigator whatever it is... 
+                       Uri uri = Uri.parse(entry.getURL());
+                       startActivity(new Intent(Intent.ACTION_VIEW, uri));             
         }
                
                private void setIsReadEntry(final AdsEntry entry) {
@@ -429,7 +429,7 @@ public class MobiAdsList extends Activity {
                mAdapter.remove(entry);
                
                //Change notification (if there is one)
-                       Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSRECEIVER");
+                       Intent updateDatabase = new Intent("de.android.mobiads.MOBIADSSERVICERECEIVER");
                        getActivity().sendBroadcast(updateDatabase);
                        
                mAdapter.notifyDataSetChanged();
index c44756c..454c843 100644 (file)
@@ -64,7 +64,7 @@ public final class Indexer {
         /**
          * The default sort order for this table
          */
-        public static final String DEFAULT_SORT_ORDER = Index._ID;
+        public static final String DEFAULT_SORT_ORDER = Index.COLUMN_NAME_IS_READ;
         
         /**
          * The MIME type of {@link #CONTENT_URI} providing a directory of notes.