Skip to content

Commit

Permalink
🐛Fix a DateFormat translation bug
Browse files Browse the repository at this point in the history
⬆️Upgrade dependencies
  • Loading branch information
0Kirby committed Jan 26, 2023
1 parent 23153ef commit e17eed9
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 100 deletions.
38 changes: 22 additions & 16 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,33 @@ jobs:
java-version: 11
- name: Assemble release with Gradle
run: chmod +x gradlew &&./gradlew assembleRelease
- name: Find filename and set env
run: echo "FILENAME=`basename app/build/outputs/apk/release/*.apk`" >> $GITHUB_ENV
- name: Sign APK
run: jarsigner -verbose -keystore jtykey.jks -storepass ${{ secrets.STORE_PASS }} app/build/outputs/apk/release/${{ env.FILENAME }} zerokirby
- name: Find FILENAME1 and set env
run: echo "FILENAME1=`basename app/build/outputs/apk/release/*all*`" >> $GITHUB_ENV
- name: Find FILENAME2 and set env
run: echo "FILENAME2=`basename app/build/outputs/apk/release/*arm64*`" >> $GITHUB_ENV
- name: Find FILENAME3 and set env
run: echo "FILENAME3=`basename app/build/outputs/apk/release/*armeabi*`" >> $GITHUB_ENV
- name: Sign APK1
run: jarsigner -verbose -keystore jtykey.jks -storepass ${{ secrets.STORE_PASS }} app/build/outputs/apk/release/${{ env.FILENAME1 }} zerokirby
- name: Sign APK2
run: jarsigner -verbose -keystore jtykey.jks -storepass ${{ secrets.STORE_PASS }} app/build/outputs/apk/release/${{ env.FILENAME2 }} zerokirby
- name: Sign APK3
run: jarsigner -verbose -keystore jtykey.jks -storepass ${{ secrets.STORE_PASS }} app/build/outputs/apk/release/${{ env.FILENAME3 }} zerokirby
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Assets
id: upload-release-assets
uses: dwenegar/upload-release-assets@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/build/outputs/apk/release/${{ env.FILENAME }}
asset_name: ${{ env.FILENAME }}
asset_content_type: application/vnd.android.package-archive
release_id: ${{ steps.create_release.outputs.id }}
assets_path: app/build/outputs/apk/release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
头像存取:通过Java字节流方式进行头像的上传与下载,根据UUID生成唯一的文件名,确保同一用户多次上传的头像不会因重名而被覆盖,并将头像的路径存入数据库以便用户登录时读取头像
# 联系我
QQ:[623768813](http://wpa.qq.com/msgrd?v=3&uin=623768813&site=qq&menu=yes)
E-mail:[email protected]
E-mail:[[email protected]](mailto:[email protected])
个人主页:https://zerokirby.cn
天天笔记主页:https://note.zerokirby.cn
博客:https://blog.zerokirby.cn
34 changes: 27 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ plugins {

android {
compileSdkVersion 33
buildToolsVersion = "33.0.0"
buildToolsVersion = "33.0.1"
defaultConfig {
applicationId "cn.zerokirby.note"
minSdkVersion 21
targetSdkVersion 33
versionCode Integer.valueOf(getDate())
versionName "3.1.1"
versionName "3.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -34,17 +34,37 @@ android {
lint {
abortOnError false
}
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a' //select ABIs to build APKs for
universalApk true //generate an additional APK that contains all the ABIs
}
}
namespace 'cn.zerokirby.note'


android.applicationVariants.all {
variant ->
variant.outputs.all {
outputFileName = "ProgressNote-v${variant.versionName}.apk"
}
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def aid = variant.applicationId.split("\\.")
def name = aid[aid.length - 1]
def abi = output.getFilter(com.android.build.OutputFile.ABI)
if (abi == null) abi = "all"//兼容
def version = variant.versionName
def versionCode = variant.versionCode
def date = new Date()
def formattedDate = date.format('yyyyMMdd_HHmm')
outputFileName = "ProgressNote" +
"_${abi}" +
"_${"v"}${version}" +
"_${formattedDate}.apk"

}
}
}


static def getDate() {
return new Date().format("yyyyMMdd")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cn.zerokirby.note.activity;

import static cn.zerokirby.note.MyApplication.getContext;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -17,14 +19,12 @@

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import cn.zerokirby.note.R;
import cn.zerokirby.note.data.NoteDataHelper;
import cn.zerokirby.note.noteutil.Note;
import cn.zerokirby.note.util.YanRenUtilKt;

import static cn.zerokirby.note.MyApplication.getContext;
import ren.imyan.language.LanguageUtil;

public class EditingActivity extends BaseActivity {

Expand Down Expand Up @@ -78,16 +78,15 @@ protected void onCreate(Bundle savedInstanceState) {
initView();//初始化控件

noteId = getIntent().getIntExtra("noteId", 0);//获取点击的数据id

simpleDateFormat = new SimpleDateFormat(YanRenUtilKt.getLocalString(R.string.formatDate), LanguageUtil.getLocale(getContext()));
actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);//设置为可以返回

if (noteId == 0) {//如果没有获取到,则设置标题为新建笔记
actionBar.setTitle(R.string.newNote);

noteTime.setText(new SimpleDateFormat(getContext().getString(R.string.formatDate),
Locale.getDefault()).format(new Date()));
noteTime.setText(simpleDateFormat.format(new Date()));

} else {
actionBar.setTitle(R.string.editNote);//否则设置为编辑笔记
Expand All @@ -101,7 +100,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

simpleDateFormat = new SimpleDateFormat(getContext().getString(R.string.formatDate), Locale.getDefault());
}

//初始化控件
Expand Down
17 changes: 9 additions & 8 deletions app/src/main/java/cn/zerokirby/note/data/NoteDataHelper.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cn.zerokirby.note.data;

import static cn.zerokirby.note.MyApplication.getContext;

import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Toast;

Expand All @@ -14,13 +15,12 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import cn.zerokirby.note.R;
import cn.zerokirby.note.noteutil.Note;
import cn.zerokirby.note.noteutil.NoteChangeConstant;

import static cn.zerokirby.note.MyApplication.getContext;
import cn.zerokirby.note.util.YanRenUtilKt;
import ren.imyan.language.LanguageUtil;

public class NoteDataHelper {

Expand All @@ -40,7 +40,7 @@ public class NoteDataHelper {
public static void initNoteDataHelper() {
databaseHelper = new DatabaseHelper("ProgressNote.db", null, 1);
values = new ContentValues();
simpleDateFormat = new SimpleDateFormat(getContext().getString(R.string.formatDate), Locale.getDefault());

localBroadcastManager = LocalBroadcastManager.getInstance(getContext());
}

Expand All @@ -52,7 +52,7 @@ public static void initNoteDataHelper() {
public static List<Note> initNote(String str) {
try {
List<Note> dataList = new ArrayList<>();

simpleDateFormat = new SimpleDateFormat(YanRenUtilKt.getLocalString(R.string.formatDate), LanguageUtil.getLocale(getContext()));
db = databaseHelper.getReadableDatabase();
cursor = db.query("Note", null, null,
null, null, null, "time desc",
Expand Down Expand Up @@ -151,7 +151,7 @@ public static int saveChange(Note note) {
intent.putExtra("note_data", note);

localBroadcastManager.sendBroadcast(intent);
Toast.makeText(getContext(), R.string.saveSuccess, Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), YanRenUtilKt.getLocalString(R.string.saveSuccess), Toast.LENGTH_SHORT).show();
} finally {
if (values != null) values.clear();
if (cursor != null) cursor.close();
Expand All @@ -160,6 +160,7 @@ public static int saveChange(Note note) {
return noteId;
}


/**
* 删除笔记
*
Expand All @@ -176,7 +177,7 @@ public static void deleteNote(int noteId) {
intent.putExtra("note_id", noteId);
localBroadcastManager.sendBroadcast(intent);

Toast.makeText(getContext(), R.string.deleteSuccess, Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), YanRenUtilKt.getLocalString(R.string.deleteSuccess), Toast.LENGTH_SHORT).show();
} finally {
if (db != null) db.close();
}
Expand Down
84 changes: 55 additions & 29 deletions app/src/main/java/cn/zerokirby/note/noteutil/Note.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package cn.zerokirby.note.noteutil;

import static cn.zerokirby.note.MyApplication.getContext;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import cn.zerokirby.note.R;

import static cn.zerokirby.note.MyApplication.getContext;
import cn.zerokirby.note.util.YanRenUtilKt;
import ren.imyan.language.LanguageUtil;

public class Note implements Parcelable {

Expand Down Expand Up @@ -65,20 +67,31 @@ public void setTime(String time) {

//获取yy年
public String getYear() {
return time.substring(0, 5);
if (time.contains("年"))
return time.substring(0, 5);
else
return time.substring(6, 10);
}

//获取MM月,若为第一位为0,则去掉0
public String getMonth() {
String month = time.substring(5, 8);
if (month.startsWith("0"))
month = month.substring(1);
String month;
if (time.contains("年")) {
month = time.substring(5, 8);
if (month.startsWith("0"))
month = month.substring(1);
} else
month = time.substring(0, 2);
return month;
}

//获取dd日,若为第一位为0,则去掉0
public String getDay() {
String day = time.substring(8, 11);
String day;
if (time.contains("年"))
day = time.substring(8, 11);
else
day = time.substring(3, 5);
if (day.startsWith("0")) {
day = day.substring(1);
}
Expand All @@ -90,48 +103,61 @@ public String getDay() {
*/
public String getPassDay() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
getContext().getString(R.string.format_year_month_day), Locale.getDefault());
YanRenUtilKt.getLocalString(R.string.formatDate), LanguageUtil.getLocale(getContext()));
Date nowTime = null;
String passDay = "";
try {
nowTime = simpleDateFormat.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
long diff = 0;
if (nowTime != null) diff = System.currentTimeMillis() - nowTime.getTime();
int days = (int) (diff / (1000 * 60 * 60 * 24));
if (days == 0)
return getContext().getResources().getString(R.string.today);
else if (days == 1)
return getContext().getResources().getString(R.string.yesterday);
else if (days < 7) {
Calendar calendar = Calendar.getInstance();
int weekday = (7 + calendar.get(Calendar.DAY_OF_WEEK) - days) % 7;
Calendar calendar = Calendar.getInstance();
if (nowTime != null)
calendar.setTime(nowTime);
if (DateUtils.isToday(nowTime.getTime()))
return YanRenUtilKt.getLocalString(R.string.today);
else if (DateUtils.isToday(nowTime.getTime() + 24 * 60 * 60 * 1000))
return YanRenUtilKt.getLocalString(R.string.yesterday);
else {
int weekday = calendar.get(Calendar.DAY_OF_WEEK);
switch (weekday) {
case 0:
return getDay() + getContext().getResources().getString(R.string.saturday);
case 1:
return getDay() + getContext().getResources().getString(R.string.sunday);
passDay = getDay() + YanRenUtilKt.getLocalString(R.string.sunday);
break;
case 2:
return getDay() + getContext().getResources().getString(R.string.monday);
passDay = getDay() + YanRenUtilKt.getLocalString(R.string.monday);
break;
case 3:
return getDay() + getContext().getResources().getString(R.string.tuesday);
passDay = getDay() + YanRenUtilKt.getLocalString(R.string.tuesday);
break;
case 4:
return getDay() + getContext().getResources().getString(R.string.wednesday);
passDay = getDay() + YanRenUtilKt.getLocalString(R.string.wednesday);
break;
case 5:
return getDay() + getContext().getResources().getString(R.string.thursday);
passDay = getDay() + YanRenUtilKt.getLocalString(R.string.thursday);
break;
case 6:
return getDay() + getContext().getResources().getString(R.string.friday);
passDay = getDay() + YanRenUtilKt.getLocalString(R.string.friday);
break;
case 7:
passDay = getDay() + YanRenUtilKt.getLocalString(R.string.saturday);
break;
}
if (time.contains("年"))
return passDay;
else
return "Day " + passDay;
}
return getDay();
}

/**
* 获取HH:mm:ss时 分 秒
*/
public String getHMS() {
return time.substring(12);
if (time.contains("年"))
return time.substring(12);
else
return time.substring(11);
}

private boolean flag = false;//这个成员用来记录dataItem的展开状态
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/cn/zerokirby/note/noteutil/NoteAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Note note = mNoteList.get(position);
holder.title.setText(note.getTitle());//设置标题
holder.content.setText(note.getContent());//设置内容
holder.time.setText(note.getYear() + note.getMonth() + note.getDay() +
"\n" + note.getHMS());//设置标准化日期时间
if (note.getTime().contains("年"))
holder.time.setText(note.getYear() + note.getMonth() + note.getDay() +
"\n" + note.getHMS());//设置标准化日期时间
else
holder.time.setText(note.getMonth() + "/" + note.getDay() + "/" + note.getYear() +
"\n" + note.getHMS());//设置标准化日期时间
}

//为recyclerView的每一个item设置点击事件
Expand Down
Loading

0 comments on commit e17eed9

Please sign in to comment.