Skip to content

Commit

Permalink
Merge pull request #178 from Telephone2019/work
Browse files Browse the repository at this point in the history
Work
  • Loading branch information
TelephoneTan committed Dec 7, 2020
2 parents ef97385 + 825992c commit d294f4a
Show file tree
Hide file tree
Showing 62 changed files with 1,969 additions and 1,060 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ android {

defaultConfig {
applicationId "com.telephone.coursetable"
minSdkVersion 26
minSdkVersion 24
targetSdkVersion 30
versionCode 3
versionName "3.6.1"
versionName "3.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
android:largeHeap="true"
android:hardwareAccelerated="false">

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.widget.Toast;

import com.telephone.coursetable.Clock.Clock;
import com.telephone.coursetable.Clock.DateTime;
import com.telephone.coursetable.Database.ShowTableNode;
import com.telephone.coursetable.FetchService;
import com.telephone.coursetable.MainActivity;
Expand All @@ -23,6 +24,8 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

import javax.crypto.spec.OAEPParameterSpec;

Expand Down Expand Up @@ -67,9 +70,9 @@ public void onReceive(Context context, Intent intent) {
// open_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(R.id.appwidget_list_title_text, PendingIntent.getBroadcast(context, 0, open_intent, PendingIntent.FLAG_UPDATE_CURRENT));
// refresh date
LocalDateTime now = LocalDateTime.now();
DateTime dateTime = DateTime.getDefault_Instance(Clock.nowTimeStamp());
remoteViews.setTextViewText(R.id.appwidget_list_title_date,
now.getMonthValue() + "月" + now.getDayOfMonth() + "日"
dateTime.getMonth() + "月" + dateTime.getDay() + "日"
+ new String[]{
"",
"星期一",
Expand All @@ -78,7 +81,7 @@ public void onReceive(Context context, Intent intent) {
"星期四",
"星期五",
"星期六",
"星期日"}[now.getDayOfWeek().getValue()] + " ");
"星期日"}[dateTime.getWeekday()] + " ");
// declare the remote views service, so that the app-widget can get its old remote adapter
Intent data_intent = new Intent(context, ListRemoteViewsService.class);
// no need to add extra, because even if you send some extra, the extra won't be sent to the old remote adapter
Expand Down
287 changes: 165 additions & 122 deletions app/src/main/java/com/telephone/coursetable/Clock/Clock.java

Large diffs are not rendered by default.

160 changes: 160 additions & 0 deletions app/src/main/java/com/telephone/coursetable/Clock/DateTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package com.telephone.coursetable.Clock;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Scanner;
import java.util.TimeZone;
import java.util.regex.Pattern;

public class DateTime {

public static TimeZone timezone_GMT8 = TimeZone.getTimeZone("GMT+08:00");

private TimeZone tz;
private Calendar cld;

private final int year;
private final int month;
private final int day;
private int weekday;

public int hour_24;
public int minute;
public int second;

public static DateTime getGMT8_Instance(long timestamp){
return new DateTime(DateTime.timezone_GMT8, timestamp);
}

public static DateTime getDefault_Instance(long timestamp){
return new DateTime(TimeZone.getDefault(), timestamp);
}

/**
* the {@link #weekday} won't be set
* the data MUST be valid
* all of the the time fields will be set to 0
*/
public DateTime(TimeZone tz, int year, int month, int day){
this.tz = tz;
this.cld = Calendar.getInstance(this.tz);

this.year = year;
this.month = month;
this.day = day;

this.hour_24 = 0;
this.minute = 0;
this.second = 0;
}

public DateTime(TimeZone timeZone, long timestamp){
this.tz = timeZone;
this.cld = Calendar.getInstance(this.tz);

cld.setTime(new Date(timestamp));
this.year = cld.get(Calendar.YEAR);
this.month = cld.get(Calendar.MONTH) + 1;
this.day = cld.get(Calendar.DAY_OF_MONTH);
this.weekday = cld.get(Calendar.DAY_OF_WEEK) - 1;
if (this.weekday == 0){
this.weekday = 7;
}
this.hour_24 = cld.get(Calendar.HOUR_OF_DAY);
this.minute = cld.get(Calendar.MINUTE);
this.second = cld.get(Calendar.SECOND);
}

public DateTime(DateTime src, @NonNull String time_string, @NonNull String delimiter) {
this.tz = src.tz;
this.cld = Calendar.getInstance(this.tz);

this.year = src.year;
this.month = src.month;
this.day = src.day;
this.weekday = src.weekday;
Scanner scanner = new Scanner(time_string);
scanner.useDelimiter(delimiter);
this.hour_24 = scanner.nextInt();
this.minute = scanner.nextInt();
if (scanner.hasNext()) {
this.second = scanner.nextInt();
} else {
this.second = 0;
}
}

public long getTime(){
cld.set(
this.year,
this.month - 1,
this.day,
this.hour_24,
this.minute,
this.second
);
return cld.getTime().getTime();
}

public int getYear() {
return year;
}

public int getMonth() {
return month;
}

public int getDay() {
return day;
}

public int getWeekday() {
return weekday;
}

public boolean equals(@NonNull DateTime dateTime) {
return this.getTime() == dateTime.getTime();
}

public boolean before(@NonNull DateTime dateTime){
return this.getTime() < dateTime.getTime();
}

public boolean after(@NonNull DateTime dateTime){
return this.getTime() > dateTime.getTime();
}

public boolean before_or_equals(@NonNull DateTime dateTime){
return this.getTime() < dateTime.getTime() || this.getTime() == dateTime.getTime();
}

public boolean after_or_equals(@NonNull DateTime dateTime){
return this.getTime() > dateTime.getTime() || this.getTime() == dateTime.getTime();
}

@Override
public String toString() {
return "DateTime{" +
"year=" + year +
", month=" + month +
", day=" + day +
", weekday=" + weekday +
", hour_24=" + hour_24 +
", minute=" + minute +
", second=" + second +
", timestamp=" + this.getTime() +
'}';
}

public String dateTimeString(){
return String.format(Locale.getDefault(), "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour_24, minute, second, tz.getDisplayName());
}

public String dateTimeString(Locale locale){
return String.format(Locale.getDefault(), "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour_24, minute, second, tz.getDisplayName(locale));
}
}
69 changes: 69 additions & 0 deletions app/src/main/java/com/telephone/coursetable/Clock/GetDateInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.telephone.coursetable.Clock;

import android.content.SharedPreferences;

import androidx.annotation.Nullable;
import androidx.core.content.res.TypedArrayUtils;

import com.telephone.coursetable.Database.TermInfo;
import com.telephone.coursetable.Database.TermInfoDao;
import com.telephone.coursetable.MyApp;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class GetDateInfo {

// 遇事不决,GMT+8
public static String[] get_a_week_date_info_all_timezone_using_gmt8(@Nullable TermInfo termInfo, long weekNum){

long[] a_week_ts;

if(termInfo == null || weekNum <= 0){
long nts = Clock.nowTimeStamp();
long today_ts1 = nts;
long today_ts2 = nts;

List<Long> ts_list = new LinkedList<>();
ts_list.add(nts);

int expand_num = 6;

for (int i = 0; i < expand_num; i++) {
today_ts1 -= 86400000L;
ts_list.add(0, today_ts1);
}

for (int i = 0; i < expand_num; i++) {
today_ts2 += 86400000L;
ts_list.add(today_ts2);
}

DateTime now_gmt8 = DateTime.getGMT8_Instance(nts);

int start_index = expand_num - (now_gmt8.getWeekday() - 1);
int end_index = expand_num + (7 - now_gmt8.getWeekday());

Long[] a_week_ts_Long = Arrays.copyOfRange(ts_list.toArray(new Long[0]), start_index, end_index + 1);
a_week_ts = new long[a_week_ts_Long.length];
for (int i = 0; i < a_week_ts_Long.length; i++) {
a_week_ts[i] = a_week_ts_Long[i];
}
}else {
a_week_ts = Clock.getAWeekTimeStampForWeekSince(
termInfo.sts,
weekNum
);
}

String[] data_info_ary = new String[a_week_ts.length];

for (int i = 0; i < a_week_ts.length; i++) {
DateTime dateTime_gmt8 = DateTime.getGMT8_Instance(a_week_ts[i]);
data_info_ary[i] = dateTime_gmt8.getMonth() + "." + dateTime_gmt8.getDay();
}

return data_info_ary;
}
}
Loading

0 comments on commit d294f4a

Please sign in to comment.