Commits

Anonymous committed 46e4c50

bug fix on fist most install of app

Comments (0)

Files changed (3)

src/com/w4rlock/backpapermusic/MusicActivity.java

 
 import com.w4rlock.backpapermusic.database.service.MusicDatabaseSyncerService;
 import com.w4rlock.backpapermusic.fragments.MusicListFragment;
+import com.w4rlock.backpapermusic.loaders.LoadingInterface;
 import com.w4rlock.backpapermusic.util.L;
 
 public class MusicActivity extends AbsActivity
 {
-
+	MusicListFragment musicListFragment;
 	@Override
 	protected void onCreate(Bundle savedInstanceState)
 	{
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.activity_music);
-
+		musicListFragment = new MusicListFragment(); 
 		if (savedInstanceState == null)
 		{
-			getSupportFragmentManager().beginTransaction().add(R.id.container, new MusicListFragment()).commit();
+			getSupportFragmentManager().beginTransaction().add(R.id.container,musicListFragment).commit();
 		}
 		com.nostra13.universalimageloader.utils.L.disableLogging();
 
 		L.d("MusicActivity", "Calling Service");
-		MusicDatabaseSyncerService musicDatabaseSyncerService = new MusicDatabaseSyncerService(getApplicationContext(), this);
+		MusicDatabaseSyncerService musicDatabaseSyncerService = new MusicDatabaseSyncerService(getApplicationContext(), loadingInterface);
 		musicDatabaseSyncerService.execute();
 	}
 
 		}
 		return super.onOptionsItemSelected(item);
 	}
+	
+	final LoadingInterface loadingInterface = new LoadingInterface()
+	{
+		
+		@Override
+		public void onProgressUpdate(int percent)
+		{
+			
+		}
+		
+		@Override
+		public void onLoadingStarted()
+		{
+			showSyncStatusBar();
+		}
+		
+		@Override
+		public void onLoadingEnded()
+		{
+			hideSyncStatusBar();
+			musicListFragment.forceLoadDataFromLoader();
+		}
+	};
 }

src/com/w4rlock/backpapermusic/fragments/MusicListFragment.java

 	private static final int NETWORK_MAX_TRIES = 2;
 	private int networkTries = 0;
 	private ListView songsList;
-
+	
+	private static final int LOADER_ID = 0;
+	final MusicLoaderCallbacks musicLoaderCallbacks = new MusicLoaderCallbacks();
 	public MusicListFragment()
 	{
 	}
-
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
 	{
 		songsList = (ListView) rootView.findViewById(R.id.songs_list_view);
 		mMusicAdapter = new MusicListViewAdapter(getActivity(), musics);
 		songsList.setAdapter(mMusicAdapter);
-		getLoaderManager().initLoader(0, null, new MusicLoaderCallbacks());
+		getLoaderManager().initLoader(LOADER_ID, null, musicLoaderCallbacks);
 		songsList.setOnItemClickListener(new AdapterView.OnItemClickListener()
 		{
 
 		});
 		return rootView;
 	}
+	
+	public void forceLoadDataFromLoader(){
+		getLoaderManager().restartLoader(0, null, musicLoaderCallbacks); 
+	}
 
 	final SongDialogPopup.OnSongItemClicked onItemClickListener = new SongDialogPopup.OnSongItemClicked()
 	{

src/com/w4rlock/backpapermusic/loaders/MusicDataLoader.java

 
 import static nl.qbusict.cupboard.CupboardFactory.cupboard;
 
-import java.lang.reflect.Type;
 import java.util.ArrayList;
 
 import nl.qbusict.cupboard.QueryResultIterable;
-
 import android.content.Context;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.support.v4.content.AsyncTaskLoader;
 
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-
 import com.w4rlock.backpapermusic.database.db.MusicDb;
 import com.w4rlock.backpapermusic.models.AsyncResult;
-import com.w4rlock.backpapermusic.models.Music;
 import com.w4rlock.backpapermusic.models.Song;
 import com.w4rlock.backpapermusic.util.L;
 
 public class MusicDataLoader extends AsyncTaskLoader<AsyncResult<ArrayList<Song>>>
 {
-	private static final String url = "http://db.w4rlock.in/media/music_api/0.json";
 	AsyncResult<ArrayList<Song>> result;
 	private static final String DEBUG_TAG = MusicDataLoader.class.toString();