Skip to content

Commit d294f4a

Browse files
authored
Merge pull request #178 from Telephone2019/work
Work
2 parents ef97385 + 825992c commit d294f4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1969
-1060
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ android {
66

77
defaultConfig {
88
applicationId "com.telephone.coursetable"
9-
minSdkVersion 26
9+
minSdkVersion 24
1010
targetSdkVersion 30
1111
versionCode 3
12-
versionName "3.6.1"
12+
versionName "3.7"
1313

1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
android:roundIcon="@mipmap/ic_launcher_round"
2525
android:supportsRtl="true"
2626
android:theme="@style/AppTheme"
27-
android:usesCleartextTraffic="true">
27+
android:usesCleartextTraffic="true"
28+
android:largeHeap="true"
29+
android:hardwareAccelerated="false">
2830

2931
<provider
3032
android:name="androidx.core.content.FileProvider"

app/src/main/java/com/telephone/coursetable/AppWidgetProvider/List.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.widget.Toast;
1414

1515
import com.telephone.coursetable.Clock.Clock;
16+
import com.telephone.coursetable.Clock.DateTime;
1617
import com.telephone.coursetable.Database.ShowTableNode;
1718
import com.telephone.coursetable.FetchService;
1819
import com.telephone.coursetable.MainActivity;
@@ -23,6 +24,8 @@
2324
import java.time.LocalDateTime;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
27+
import java.util.Calendar;
28+
import java.util.Date;
2629

2730
import javax.crypto.spec.OAEPParameterSpec;
2831

@@ -67,9 +70,9 @@ public void onReceive(Context context, Intent intent) {
6770
// open_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
6871
remoteViews.setOnClickPendingIntent(R.id.appwidget_list_title_text, PendingIntent.getBroadcast(context, 0, open_intent, PendingIntent.FLAG_UPDATE_CURRENT));
6972
// refresh date
70-
LocalDateTime now = LocalDateTime.now();
73+
DateTime dateTime = DateTime.getDefault_Instance(Clock.nowTimeStamp());
7174
remoteViews.setTextViewText(R.id.appwidget_list_title_date,
72-
now.getMonthValue() + "月" + now.getDayOfMonth() + "日"
75+
dateTime.getMonth() + "月" + dateTime.getDay() + "日"
7376
+ new String[]{
7477
"",
7578
"星期一",
@@ -78,7 +81,7 @@ public void onReceive(Context context, Intent intent) {
7881
"星期四",
7982
"星期五",
8083
"星期六",
81-
"星期日"}[now.getDayOfWeek().getValue()] + " ");
84+
"星期日"}[dateTime.getWeekday()] + " ");
8285
// declare the remote views service, so that the app-widget can get its old remote adapter
8386
Intent data_intent = new Intent(context, ListRemoteViewsService.class);
8487
// no need to add extra, because even if you send some extra, the extra won't be sent to the old remote adapter

app/src/main/java/com/telephone/coursetable/Clock/Clock.java

Lines changed: 165 additions & 122 deletions
Large diffs are not rendered by default.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package com.telephone.coursetable.Clock;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
6+
import java.util.Calendar;
7+
import java.util.Date;
8+
import java.util.Locale;
9+
import java.util.Scanner;
10+
import java.util.TimeZone;
11+
import java.util.regex.Pattern;
12+
13+
public class DateTime {
14+
15+
public static TimeZone timezone_GMT8 = TimeZone.getTimeZone("GMT+08:00");
16+
17+
private TimeZone tz;
18+
private Calendar cld;
19+
20+
private final int year;
21+
private final int month;
22+
private final int day;
23+
private int weekday;
24+
25+
public int hour_24;
26+
public int minute;
27+
public int second;
28+
29+
public static DateTime getGMT8_Instance(long timestamp){
30+
return new DateTime(DateTime.timezone_GMT8, timestamp);
31+
}
32+
33+
public static DateTime getDefault_Instance(long timestamp){
34+
return new DateTime(TimeZone.getDefault(), timestamp);
35+
}
36+
37+
/**
38+
* the {@link #weekday} won't be set
39+
* the data MUST be valid
40+
* all of the the time fields will be set to 0
41+
*/
42+
public DateTime(TimeZone tz, int year, int month, int day){
43+
this.tz = tz;
44+
this.cld = Calendar.getInstance(this.tz);
45+
46+
this.year = year;
47+
this.month = month;
48+
this.day = day;
49+
50+
this.hour_24 = 0;
51+
this.minute = 0;
52+
this.second = 0;
53+
}
54+
55+
public DateTime(TimeZone timeZone, long timestamp){
56+
this.tz = timeZone;
57+
this.cld = Calendar.getInstance(this.tz);
58+
59+
cld.setTime(new Date(timestamp));
60+
this.year = cld.get(Calendar.YEAR);
61+
this.month = cld.get(Calendar.MONTH) + 1;
62+
this.day = cld.get(Calendar.DAY_OF_MONTH);
63+
this.weekday = cld.get(Calendar.DAY_OF_WEEK) - 1;
64+
if (this.weekday == 0){
65+
this.weekday = 7;
66+
}
67+
this.hour_24 = cld.get(Calendar.HOUR_OF_DAY);
68+
this.minute = cld.get(Calendar.MINUTE);
69+
this.second = cld.get(Calendar.SECOND);
70+
}
71+
72+
public DateTime(DateTime src, @NonNull String time_string, @NonNull String delimiter) {
73+
this.tz = src.tz;
74+
this.cld = Calendar.getInstance(this.tz);
75+
76+
this.year = src.year;
77+
this.month = src.month;
78+
this.day = src.day;
79+
this.weekday = src.weekday;
80+
Scanner scanner = new Scanner(time_string);
81+
scanner.useDelimiter(delimiter);
82+
this.hour_24 = scanner.nextInt();
83+
this.minute = scanner.nextInt();
84+
if (scanner.hasNext()) {
85+
this.second = scanner.nextInt();
86+
} else {
87+
this.second = 0;
88+
}
89+
}
90+
91+
public long getTime(){
92+
cld.set(
93+
this.year,
94+
this.month - 1,
95+
this.day,
96+
this.hour_24,
97+
this.minute,
98+
this.second
99+
);
100+
return cld.getTime().getTime();
101+
}
102+
103+
public int getYear() {
104+
return year;
105+
}
106+
107+
public int getMonth() {
108+
return month;
109+
}
110+
111+
public int getDay() {
112+
return day;
113+
}
114+
115+
public int getWeekday() {
116+
return weekday;
117+
}
118+
119+
public boolean equals(@NonNull DateTime dateTime) {
120+
return this.getTime() == dateTime.getTime();
121+
}
122+
123+
public boolean before(@NonNull DateTime dateTime){
124+
return this.getTime() < dateTime.getTime();
125+
}
126+
127+
public boolean after(@NonNull DateTime dateTime){
128+
return this.getTime() > dateTime.getTime();
129+
}
130+
131+
public boolean before_or_equals(@NonNull DateTime dateTime){
132+
return this.getTime() < dateTime.getTime() || this.getTime() == dateTime.getTime();
133+
}
134+
135+
public boolean after_or_equals(@NonNull DateTime dateTime){
136+
return this.getTime() > dateTime.getTime() || this.getTime() == dateTime.getTime();
137+
}
138+
139+
@Override
140+
public String toString() {
141+
return "DateTime{" +
142+
"year=" + year +
143+
", month=" + month +
144+
", day=" + day +
145+
", weekday=" + weekday +
146+
", hour_24=" + hour_24 +
147+
", minute=" + minute +
148+
", second=" + second +
149+
", timestamp=" + this.getTime() +
150+
'}';
151+
}
152+
153+
public String dateTimeString(){
154+
return String.format(Locale.getDefault(), "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour_24, minute, second, tz.getDisplayName());
155+
}
156+
157+
public String dateTimeString(Locale locale){
158+
return String.format(Locale.getDefault(), "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour_24, minute, second, tz.getDisplayName(locale));
159+
}
160+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.telephone.coursetable.Clock;
2+
3+
import android.content.SharedPreferences;
4+
5+
import androidx.annotation.Nullable;
6+
import androidx.core.content.res.TypedArrayUtils;
7+
8+
import com.telephone.coursetable.Database.TermInfo;
9+
import com.telephone.coursetable.Database.TermInfoDao;
10+
import com.telephone.coursetable.MyApp;
11+
12+
import java.util.Arrays;
13+
import java.util.LinkedList;
14+
import java.util.List;
15+
16+
public class GetDateInfo {
17+
18+
// 遇事不决,GMT+8
19+
public static String[] get_a_week_date_info_all_timezone_using_gmt8(@Nullable TermInfo termInfo, long weekNum){
20+
21+
long[] a_week_ts;
22+
23+
if(termInfo == null || weekNum <= 0){
24+
long nts = Clock.nowTimeStamp();
25+
long today_ts1 = nts;
26+
long today_ts2 = nts;
27+
28+
List<Long> ts_list = new LinkedList<>();
29+
ts_list.add(nts);
30+
31+
int expand_num = 6;
32+
33+
for (int i = 0; i < expand_num; i++) {
34+
today_ts1 -= 86400000L;
35+
ts_list.add(0, today_ts1);
36+
}
37+
38+
for (int i = 0; i < expand_num; i++) {
39+
today_ts2 += 86400000L;
40+
ts_list.add(today_ts2);
41+
}
42+
43+
DateTime now_gmt8 = DateTime.getGMT8_Instance(nts);
44+
45+
int start_index = expand_num - (now_gmt8.getWeekday() - 1);
46+
int end_index = expand_num + (7 - now_gmt8.getWeekday());
47+
48+
Long[] a_week_ts_Long = Arrays.copyOfRange(ts_list.toArray(new Long[0]), start_index, end_index + 1);
49+
a_week_ts = new long[a_week_ts_Long.length];
50+
for (int i = 0; i < a_week_ts_Long.length; i++) {
51+
a_week_ts[i] = a_week_ts_Long[i];
52+
}
53+
}else {
54+
a_week_ts = Clock.getAWeekTimeStampForWeekSince(
55+
termInfo.sts,
56+
weekNum
57+
);
58+
}
59+
60+
String[] data_info_ary = new String[a_week_ts.length];
61+
62+
for (int i = 0; i < a_week_ts.length; i++) {
63+
DateTime dateTime_gmt8 = DateTime.getGMT8_Instance(a_week_ts[i]);
64+
data_info_ary[i] = dateTime_gmt8.getMonth() + "." + dateTime_gmt8.getDay();
65+
}
66+
67+
return data_info_ary;
68+
}
69+
}

0 commit comments

Comments
 (0)