Skip to content

Commit

Permalink
12/24h, bigger top button, all day duration
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatApo committed Feb 2, 2019
1 parent 7abfc4a commit 940377e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 41 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
targetSdkVersion 27
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionName '1.0.1'
versionCode 20190128
versionName '1.0.2'
versionCode 20190202
}
buildTypes {
release {
Expand Down
89 changes: 52 additions & 37 deletions app/src/main/java/com/dinodevs/timelinewidget/widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public class widget extends AbstractPlugin {

private long next_event;
private String calendarEvents;
private String header_pattern;
private String time_pattern;

// Constants
private static final String HEADER_PATTERN_12H = "hh:mm a\nEEEE, d MMMM";
private static final String HEADER_PATTERN_24H = "HH:mm\nEEEE, d MMMM";
private static final String ELEMENT_PATTERN = "EEEE, d MMMM";
private static final String TIME_PATTERN_12H = "hh:mm a";
private static final String TIME_PATTERN_24H = "HH:mm";
private static final String DATE_PATTERN = "dd/MM/yyyy";


// Set up the widget's layout
Expand Down Expand Up @@ -128,13 +138,29 @@ public void onClick(View v) {
}

private void refresh_time(){
is24h();
TextView time = this.mView.findViewById(R.id.time);
time.setText( dateToString(Calendar.getInstance(),"hh:mm a\nEEEE, d MMMM") );
time.setText( dateToString(Calendar.getInstance(),header_pattern) );
}

boolean is24h;
private void is24h(){
is24h = Settings.System.getString(mContext.getContentResolver(), "time_12_24").equals("24");
Log.d(TAG, "Timeline init is24h: " + is24h);

if (is24h) {
header_pattern = HEADER_PATTERN_24H;
time_pattern = TIME_PATTERN_24H;
} else {
header_pattern = HEADER_PATTERN_12H;
time_pattern = TIME_PATTERN_12H;
}
}

private void loadCalendarEvents() {
eventsList = new ArrayList<>();
next_event = 0;
is24h();

// Load data
calendarEvents = Settings.System.getString(mContext.getContentResolver(), "CustomCalendarData");
Expand Down Expand Up @@ -179,14 +205,14 @@ private void loadCalendarEvents() {
if( next_event==0 ) // Hence this is the next event
next_event = calendar.getTimeInMillis();

start = dateToString( calendar,"hh:mm a" );
start = dateToString( calendar,time_pattern );

// Insert day separator, or not :P
if( !current_loop_date.equals(dateToString( calendar,"EEEE, d MMMM" )) ){
current_loop_date = dateToString(calendar, "EEEE, d MMMM");
if( !current_loop_date.equals(dateToString( calendar,ELEMENT_PATTERN )) ){
current_loop_date = dateToString(calendar, ELEMENT_PATTERN);
// Is it today?
if(current_loop_date.equals(dateToString(Calendar.getInstance(), "EEEE, d MMMM"))){
current_loop_date = "Today";
if(current_loop_date.equals(dateToString(Calendar.getInstance(), ELEMENT_PATTERN))){
current_loop_date = mContext.getResources().getString(R.string.today);
}
HashMap<String, String> date_elem = new HashMap<>();
date_elem.put("title", "");
Expand All @@ -198,13 +224,24 @@ private void loadCalendarEvents() {
// Event has no date, go to next
continue;
}

// No end
if(!data.getString(3).equals("") && !data.getString(3).equals("null")) {
calendar.setTimeInMillis(Long.parseLong(data.getString(3)));
end = " - "+ dateToString(calendar, "hh:mm a");
end = " - "+ dateToString(calendar, time_pattern);
}

// All day events
if((start.startsWith("00") || start.startsWith("12")) && data.getString(3).equals("null")) {
start = mContext.getResources().getString(R.string.all_day);
end = "";
}

// Location
if(!data.getString(4).equals("") && !data.getString(4).equals("null")) {
location = "\n@ "+data.getString(4);
}

event.put("subtitle", start+ end + location );
event.put("dot", mContext.getResources().getString(R.string.bull) );
// adding events to events list
Expand All @@ -214,7 +251,7 @@ private void loadCalendarEvents() {
} catch (JSONException e) {
//default
HashMap<String, String> event = new HashMap<>();
event.put("title", "No events");
event.put("title", mContext.getResources().getString(R.string.no_events));
//event.put("description", "-");
//event.put("start", "-");
//event.put("end", "-");
Expand All @@ -227,8 +264,8 @@ private void loadCalendarEvents() {

if(eventsList.isEmpty()){
HashMap<String, String> elem = new HashMap<>();
elem.put("title", "\nNo events");
elem.put("subtitle", "Make sure you use Amazmod on your phone and that your stock calendar has events.");
elem.put("title", "\n"+mContext.getResources().getString(R.string.no_events));
elem.put("subtitle", mContext.getResources().getString(R.string.no_events_description));
elem.put("dot", "" );
eventsList.add(elem);
}
Expand All @@ -248,7 +285,7 @@ private void toast (String message) {

// Convert a date to format
private String dateToString (Calendar date) {
return (new SimpleDateFormat("dd/MM/yyyy", Locale.US)).format(date.getTime());
return (new SimpleDateFormat(DATE_PATTERN, Locale.US)).format(date.getTime());
}
private String dateToString (Calendar date, String pattern) {
return (new SimpleDateFormat(pattern, Locale.US)).format(date.getTime());
Expand All @@ -263,14 +300,12 @@ private String dateToString (Calendar date, String pattern) {
private void onShow() {
// If view loaded (and was inactive)
if (this.mView != null && !this.isActive) {
refresh_time();

// If an event expired OR new events
if ( next_event+10*1000 < Calendar.getInstance().getTimeInMillis() || !calendarEvents.equals(Settings.System.getString(mContext.getContentResolver(), "CustomCalendarData")) ) {
// If an event expired OR new events OR changed 12/24h
if ( next_event+10*1000 < Calendar.getInstance().getTimeInMillis() || !calendarEvents.equals(Settings.System.getString(mContext.getContentResolver(), "CustomCalendarData")) || is24h != Settings.System.getString(mContext.getContentResolver(), "time_12_24").equals("24") ) {
// Refresh timeline
loadCalendarEvents();
}

refresh_time();
}

// Save state
Expand Down Expand Up @@ -376,24 +411,4 @@ public void onDestroy() {
}


}

/*
abstract class doubleListLayoutAdapter extends SimpleAdapter {
private ArrayList types;
private doubleListLayoutAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to, ArrayList types) {
super(context, data, resource, from, to);
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position) {
return getItem(position).;
}
}
*/
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/widget_timeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<TextView
android:id="@+id/backToTop"
android:layout_width="30dp"
android:layout_height="30dp"
android:gravity="center|top"
android:layout_height="100dp"
android:gravity="center|center"
android:text="@string/top"
android:textColor="#fff"
android:textSize="16sp"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<string name="bull">⚫</string>
<string name="refresh">↺</string>
<string name="top">▲</string>
<string name="today">Today</string>
<string name="all_day">All Day</string>
<string name="no_events">No events</string>
<string name="no_events_description">Make sure you use Amazmod on your phone and that your stock calendar has events.</string>
</resources>

0 comments on commit 940377e

Please sign in to comment.