-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/origin/develop'
- Loading branch information
Showing
16 changed files
with
649 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
sample/src/main/java/com/alamkanak/weekview/sample/AsynchronousActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.alamkanak.weekview.sample; | ||
|
||
import android.widget.Toast; | ||
|
||
import com.alamkanak.weekview.WeekViewEvent; | ||
import com.alamkanak.weekview.sample.apiclient.Event; | ||
import com.alamkanak.weekview.sample.apiclient.MyJsonService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
|
||
import retrofit.Callback; | ||
import retrofit.RestAdapter; | ||
import retrofit.RetrofitError; | ||
import retrofit.client.Response; | ||
|
||
/** | ||
* An example of how events can be fetched from network and be displayed on the week view. | ||
* Created by Raquib-ul-Alam Kanak on 1/3/2014. | ||
* Website: http://alamkanak.github.io | ||
*/ | ||
public class AsynchronousActivity extends BaseActivity implements Callback<List<Event>> { | ||
|
||
private List<WeekViewEvent> events = new ArrayList<WeekViewEvent>(); | ||
boolean calledNetwork = false; | ||
|
||
@Override | ||
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) { | ||
|
||
// Download events from network if it hasn't been done already. To understand how events are | ||
// downloaded using retrofit, visit http://square.github.io/retrofit | ||
if (!calledNetwork) { | ||
RestAdapter retrofit = new RestAdapter.Builder() | ||
.setEndpoint("https://api.myjson.com/bins") | ||
.build(); | ||
MyJsonService service = retrofit.create(MyJsonService.class); | ||
service.listEvents(this); | ||
calledNetwork = true; | ||
} | ||
|
||
// Return only the events that matches newYear and newMonth. | ||
List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>(); | ||
for (WeekViewEvent event : events) { | ||
if (eventMatches(event, newYear, newMonth)) { | ||
matchedEvents.add(event); | ||
} | ||
} | ||
return matchedEvents; | ||
} | ||
|
||
/** | ||
* Checks if an event falls into a specific year and month. | ||
* @param event The event to check for. | ||
* @param year The year. | ||
* @param month The month. | ||
* @return True if the event matches the year and month. | ||
*/ | ||
private boolean eventMatches(WeekViewEvent event, int year, int month) { | ||
return (event.getStartTime().get(Calendar.YEAR) == year && event.getStartTime().get(Calendar.MONTH) == month - 1) || (event.getEndTime().get(Calendar.YEAR) == year && event.getEndTime().get(Calendar.MONTH) == month - 1); | ||
} | ||
|
||
@Override | ||
public void success(List<Event> events, Response response) { | ||
this.events.clear(); | ||
for (Event event : events) { | ||
this.events.add(event.toWeekViewEvent()); | ||
} | ||
getWeekView().notifyDatasetChanged(); | ||
} | ||
|
||
@Override | ||
public void failure(RetrofitError error) { | ||
error.printStackTrace(); | ||
Toast.makeText(this, R.string.async_error, Toast.LENGTH_SHORT).show(); | ||
} | ||
} |
Oops, something went wrong.