Skip to content

Commit

Permalink
Made syncing seamless
Browse files Browse the repository at this point in the history
  • Loading branch information
HiiYL committed May 2, 2015
1 parent 43d3bd2 commit acfcc4e
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 420 deletions.
Binary file modified .DS_Store
Binary file not shown.
806 changes: 402 additions & 404 deletions .idea/workspace.xml

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions app/src/main/java/com/github/hiiyl/mmuhub/MMLSActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreateDrawer();

mDownloadButton = (ButtonFloat)findViewById(R.id.lecture_notes_download);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if(subjectHasFiles(0)) {
mDownloadButton.show();
}else {
mDownloadButton.hide();
}
}
}, 200);

mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

mViewPager = (ViewPager) findViewById(R.id.pager);
Expand Down Expand Up @@ -101,6 +91,18 @@ public void onClick(View v) {
}else {
MMUSyncAdapter.initializeSyncAdapter(this);
}

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if(subjectHasFiles(mViewPager.getCurrentItem())) {
mDownloadButton.show();
}else {
mDownloadButton.hide();
}
}
}, 200);
}
private boolean subjectHasFiles(int position) {
String pos = Integer.toString(position + 1);
Expand Down Expand Up @@ -128,8 +130,11 @@ public void onStop() {

public void onEventMainThread(SyncEvent event){
if(event.message.equals(Utility.SYNC_FINISHED)) {
SnackBar sync_notify = new SnackBar(this, "Sync Complete");
sync_notify.show();
if(Utility.isFirstSync(this)) {
SnackBar sync_notify = new SnackBar(this, "Sync Complete");
sync_notify.show();
Utility.setFirstSync(this, false);
}
}else if(event.message.equals(Utility.SYNC_BEGIN)) {
SnackBar sync_notify = new SnackBar(this, "Syncing ...");
sync_notify.show();
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/github/hiiyl/mmuhub/MMLSAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public MMLSAdapter(Cursor cursor, Context context){

@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
mHelper = new MMUDbHelper(mContext);
String week_id = groupCursor.getString(groupCursor.getColumnIndex(MMUContract.WeekEntry._ID));
mCursor = MySingleton.getInstance(mContext).getDatabase().query(MMUContract.AnnouncementEntry.TABLE_NAME, null,
"week_id = ?", new String[] {week_id}, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if(key.equals(SYNC_ENABLED)) {
boolean sync_enabled = prefs.getBoolean(SYNC_ENABLED, true);
int sync_enabled_int = (sync_enabled) ? 1 : 0;
ContentResolver.setIsSyncable(MMUSyncAdapter.getSyncAccount(SettingsActivity.this), MMUProvider.getAuthority(), sync_enabled_int);
ContentResolver.setSyncAutomatically(MMUSyncAdapter.getSyncAccount(SettingsActivity.this), MMUProvider.getAuthority(), sync_enabled);
// ContentResolver.setIsSyncable(MMUSyncAdapter.getSyncAccount(SettingsActivity.this), MMUProvider.getAuthority(), sync_enabled_int);
}
if(key.equals(SYNC_INTERVAL)) {
String interval = prefs.getString(SYNC_INTERVAL, "");
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/github/hiiyl/mmuhub/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,14 @@ public static boolean getNotificationsEnabled(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("notifications_enabled", true);
}
public static boolean isFirstSync(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("first_sync", true);
}
public static void setFirstSync(Context context, boolean is_first_sync) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_sync", is_first_sync);
editor.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public MMUSyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
}
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
EventBus.getDefault().postSticky(new SyncEvent(Utility.SYNC_BEGIN));
if(Utility.isFirstSync(getContext())) {
Log.d("FIRST SYNC", "FIRST SYNC");
EventBus.getDefault().postSticky(new SyncEvent(Utility.SYNC_BEGIN));
}
sync_queue = MySingleton.getInstance(getContext()).
getRequestQueue();
Log.d(LOG_TAG, "onPerformSync Called.");
Expand Down

0 comments on commit acfcc4e

Please sign in to comment.