diff --git a/app/build.gradle b/app/build.gradle
index db31066..ced92a5 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,18 +1,18 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 25
- buildToolsVersion '25.0.1'
+ compileSdkVersion 26
+ buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.kiminonawa.mydiary"
minSdkVersion 17
- targetSdkVersion 25
+ targetSdkVersion 26
// versionName rule
// version.yyMMDD_BuildCount_OPTION ,
// BuildCount_OPTION: D = demo , A = alpha, H = hotfix
- versionCode 35
- versionName "0.3.0.170424_1_A"
+ versionCode 36
+ versionName "0.3.0.170509_1_AH"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -31,13 +31,13 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
//Android lib
- compile 'com.android.support:appcompat-v7:25.3.0'
- compile 'com.android.support:design:25.3.0'
- compile 'com.android.support:support-v4:25.3.0'
- compile 'com.android.support:support-v13:25.3.0'
- compile 'com.android.support:recyclerview-v7:25.3.0'
- compile 'com.android.support:gridlayout-v7:25.3.0'
- compile 'com.android.support:cardview-v7:25.3.0'
+ compile 'com.android.support:appcompat-v7:26.1.0'
+ compile 'com.android.support:design:26.1.0'
+ compile 'com.android.support:support-v4:26.1.0'
+ compile 'com.android.support:support-v13:26.1.0'
+ compile 'com.android.support:recyclerview-v7:26.1.0'
+ compile 'com.android.support:gridlayout-v7:26.1.0'
+ compile 'com.android.support:cardview-v7:26.1.0'
testCompile 'junit:junit:4.12'
@@ -48,11 +48,11 @@ dependencies {
compile 'commons-io:commons-io:2.5'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.marshalchen.ultimaterecyclerview:library:0.7.0'
- compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.10.4@aar'){
+ compile ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar'){
transitive=true
}
//Fresco photo
- compile 'com.facebook.fresco:fresco:1.2.0'
+ compile 'com.facebook.fresco:fresco:1.8.0'
//Year class to check the old devices
compile 'com.facebook.device.yearclass:yearclass:2.0.0'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index fa73c25..cfdcf6d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -19,6 +19,8 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
+ android:resizeableActivity="false"
+ android:supportsPictureInPicture="false"
android:supportsRtl="false"
android:theme="@style/AppTheme">
@@ -52,10 +54,10 @@
+ android:theme="@style/Theme_NoActionBar_FullScreen" />
+ android:screenOrientation="portrait" />
getFragment(
return currentFragment;
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
/**
* Override the back-button.
*/
diff --git a/app/src/main/java/com/kiminonawa/mydiary/backup/ExportAsyncTask.java b/app/src/main/java/com/kiminonawa/mydiary/backup/ExportAsyncTask.java
index 93e3953..b76ca19 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/backup/ExportAsyncTask.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/backup/ExportAsyncTask.java
@@ -16,7 +16,9 @@
import com.kiminonawa.mydiary.backup.obj.BUMemoEntries;
import com.kiminonawa.mydiary.db.DBManager;
import com.kiminonawa.mydiary.main.topic.ITopic;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
import java.io.FileWriter;
import java.io.IOException;
@@ -70,8 +72,8 @@ public ExportAsyncTask(Context context, ExportCallBack callBack, String backupZi
this.backupManager.initBackupManagerExportInfo();
this.dbManager = new DBManager(context);
- FileManager backupFM = new FileManager(context, FileManager.BACKUP_DIR);
- this.backupJsonFilePath = backupFM.getDirAbsolutePath() + "/"
+ IDir backupDir = DirFactory.CreateDirByType(context, LocalDir.BACKUP_DIR);
+ this.backupJsonFilePath = backupDir.getDirAbsolutePath() + "/"
+ BackupManager.BACKUP_JSON_FILE_NAME;
this.backupZipRootPath = backupZipRootPath;
this.backupZipFileName = BACKUP_ZIP_FILE_HEADER + sdf.format(new Date()) + BACKUP_ZIP_FILE_SUB_FILE_NAME;
@@ -121,7 +123,7 @@ protected void onPostExecute(Boolean exportSuccessful) {
private void deleteBackupJsonFile() {
- new FileManager(mContext, FileManager.BACKUP_DIR).clearDir();
+ DirFactory.CreateDirByType(mContext, LocalDir.BACKUP_DIR).clearDir();
}
private void outputBackupJson() throws IOException {
diff --git a/app/src/main/java/com/kiminonawa/mydiary/backup/ImportAsyncTask.java b/app/src/main/java/com/kiminonawa/mydiary/backup/ImportAsyncTask.java
index 94356b7..83629e7 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/backup/ImportAsyncTask.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/backup/ImportAsyncTask.java
@@ -14,7 +14,9 @@
import com.kiminonawa.mydiary.backup.obj.BUMemoEntries;
import com.kiminonawa.mydiary.db.DBManager;
import com.kiminonawa.mydiary.main.topic.ITopic;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
import org.apache.commons.io.FileUtils;
@@ -41,7 +43,7 @@ public interface ImportCallBack {
* Backup
*/
private BackupManager backupManager;
- private FileManager backupFileManager, diartFileManager;
+ private IDir backupLocalDir, diaryLocalDir;
private String backupJsonFilePath;
private String backupZieFilePath;
/*
@@ -60,13 +62,13 @@ public interface ImportCallBack {
public ImportAsyncTask(Context context, ImportCallBack callBack, String backupZieFilePath) {
this.mContext = context;
this.dbManager = new DBManager(context);
- FileManager backFM = new FileManager(context, FileManager.BACKUP_DIR);
- this.backupJsonFilePath = backFM.getDirAbsolutePath() + "/"
+ IDir backDir = DirFactory.CreateDirByType(context, LocalDir.BACKUP_DIR);
+ this.backupJsonFilePath = backDir.getDirAbsolutePath() + "/"
+ BackupManager.BACKUP_JSON_FILE_NAME;
this.backupZieFilePath = backupZieFilePath;
- this.backupFileManager = new FileManager(mContext, FileManager.BACKUP_DIR);
- this.diartFileManager = new FileManager(mContext, FileManager.DIARY_ROOT_DIR);
+ this.backupLocalDir = DirFactory.CreateDirByType(mContext, LocalDir.BACKUP_DIR);
+ this.diaryLocalDir = DirFactory.CreateDirByType(mContext, LocalDir.DIARY_ROOT_DIR);
this.callBack = callBack;
this.progressDialog = new ProgressDialog(context);
@@ -84,7 +86,7 @@ protected Boolean doInBackground(Void... params) {
try {
ZipManager zipManager = new ZipManager(mContext);
- FileManager zipBackupFM = new FileManager(mContext, FileManager.BACKUP_DIR);
+ IDir zipBackupFM = DirFactory.CreateDirByType(mContext, LocalDir.BACKUP_DIR);
zipManager.unzip(backupZieFilePath,
zipBackupFM.getDirAbsolutePath() + "/");
loadBackupJsonFileIntoManager();
@@ -93,7 +95,7 @@ protected Boolean doInBackground(Void... params) {
Log.e(TAG, "import flow fail", e);
importSuccessful = false;
} finally {
- backupFileManager.clearDir();
+ backupLocalDir.clearDir();
}
return importSuccessful;
}
@@ -207,10 +209,10 @@ private void saveTopicIntoDB(BackupManager.BackupTopicListBean backupTopic) thro
private void copyDiaryPhoto(long oldTopicId, long newTopicId,
long oldDiaryId, long newDiaryId) throws IOException {
- File backupDiaryDir = new File(backupFileManager.getDirAbsolutePath() + "/diary/" +
+ File backupDiaryDir = new File(backupLocalDir.getDirAbsolutePath() + "/diary/" +
oldTopicId + "/" + oldDiaryId + "/");
if (backupDiaryDir.exists() || backupDiaryDir.isDirectory()) {
- File newDiaryDir = new File(diartFileManager.getDirAbsolutePath() + "/" +
+ File newDiaryDir = new File(diaryLocalDir.getDirAbsolutePath() + "/" +
newTopicId + "/" + newDiaryId + "/");
FileUtils.moveDirectory(backupDiaryDir, newDiaryDir);
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/backup/ZipManager.java b/app/src/main/java/com/kiminonawa/mydiary/backup/ZipManager.java
index 5beb14b..e5f20d0 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/backup/ZipManager.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/backup/ZipManager.java
@@ -3,7 +3,9 @@
import android.content.Context;
import android.util.Log;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -23,18 +25,18 @@
public class ZipManager {
- private FileManager diaryFileManager;
+ private IDir diaryLocalDir;
private final int BUFFER_SIZE = 2048;
public ZipManager(Context context) {
//Copy data form diary
- diaryFileManager = new FileManager(context, FileManager.DIARY_ROOT_DIR);
+ diaryLocalDir = DirFactory.CreateDirByType(context, LocalDir.DIARY_ROOT_DIR);
}
public boolean zipFileAtPath(String backupJsonFilePath, String toLocation) {
- File sourceFile = diaryFileManager.getDir();
+ File sourceFile = diaryLocalDir.getDir();
try {
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(toLocation);
diff --git a/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java b/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java
index 45f58f6..50b5212 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/contacts/ContactsActivity.java
@@ -1,5 +1,6 @@
package com.kiminonawa.mydiary.contacts;
+import android.content.Context;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.os.Bundle;
@@ -14,6 +15,8 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.db.DBManager;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.SPFManager;
import com.kiminonawa.mydiary.shared.ThemeManager;
import com.kiminonawa.mydiary.shared.gui.LetterComparator;
@@ -127,6 +130,11 @@ protected void onCreate(Bundle savedInstanceState) {
initTopicAdapter();
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
private void initLanguageStr() {
EN = Locale.ENGLISH.getLanguage();
JA = Locale.JAPANESE.getLanguage();
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java b/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java
index 8b1c8dc..45486df 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/DiaryActivity.java
@@ -1,5 +1,6 @@
package com.kiminonawa.mydiary.entries;
+import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.NonNull;
@@ -26,6 +27,8 @@
import com.kiminonawa.mydiary.entries.diary.item.IDairyRow;
import com.kiminonawa.mydiary.entries.entries.EntriesEntity;
import com.kiminonawa.mydiary.entries.entries.EntriesFragment;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.ThemeManager;
import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper;
@@ -121,6 +124,11 @@ protected void onStop() {
mGoogleApiClient.disconnect();
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
/**
*
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java
index f6ed056..2a507b8 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/CopyPhotoTask.java
@@ -8,9 +8,11 @@
import android.util.Log;
import com.kiminonawa.mydiary.R;
+import com.kiminonawa.mydiary.entries.diary.item.DiaryTextTag;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import com.kiminonawa.mydiary.shared.photo.BitmapHelper;
import com.kiminonawa.mydiary.shared.photo.ExifUtil;
-import com.kiminonawa.mydiary.shared.FileManager;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -23,7 +25,7 @@
public class CopyPhotoTask extends AsyncTask {
public interface CopyPhotoCallBack {
- void onCopyCompiled(String fileName);
+ void onCopyCompiled(String fileName, DiaryTextTag tag);
}
private Uri uri;
@@ -32,19 +34,20 @@ public interface CopyPhotoCallBack {
private CopyPhotoTask.CopyPhotoCallBack callBack;
private Context mContext;
private int reqWidth, reqHeight;
- private FileManager fileManager;
+ private IDir localDir;
private boolean isAddPicture = false;
-
+ private DiaryTextTag tag;
/**
* From select image
*/
public CopyPhotoTask(Context context, Uri uri,
int reqWidth, int reqHeight,
- FileManager fileManager, CopyPhotoCallBack callBack) {
+ IDir localDir, CopyPhotoCallBack callBack, DiaryTextTag tag) {
this.uri = uri;
- isAddPicture = false;
- initTask(context, reqWidth, reqHeight, fileManager, callBack);
+ this.isAddPicture = false;
+ this.tag = tag;
+ initTask(context, reqWidth, reqHeight, localDir, callBack);
}
@@ -54,19 +57,20 @@ public CopyPhotoTask(Context context, Uri uri,
*/
public CopyPhotoTask(Context context, String srcFileName,
int reqWidth, int reqHeight,
- FileManager fileManager, CopyPhotoCallBack callBack) {
- this.srcFileName = fileManager.getDirAbsolutePath() + "/" + srcFileName;
+ IDir localDir, CopyPhotoCallBack callBack, DiaryTextTag tag) {
+ this.srcFileName = localDir.getDirAbsolutePath() + "/" + srcFileName;
+ this.tag = tag;
isAddPicture = true;
- initTask(context, reqWidth, reqHeight, fileManager, callBack);
+ initTask(context, reqWidth, reqHeight, localDir, callBack);
}
public void initTask(Context context,
int reqWidth, int reqHeight,
- FileManager fileManager, CopyPhotoCallBack callBack) {
+ IDir localDir, CopyPhotoCallBack callBack) {
this.mContext = context;
this.reqWidth = reqWidth;
this.reqHeight = reqHeight;
- this.fileManager = fileManager;
+ this.localDir = localDir;
this.callBack = callBack;
this.progressDialog = new ProgressDialog(context);
@@ -103,16 +107,16 @@ protected String doInBackground(Void... params) {
protected void onPostExecute(String fileName) {
super.onPostExecute(fileName);
progressDialog.dismiss();
- callBack.onCopyCompiled(fileName);
+ callBack.onCopyCompiled(fileName,tag);
}
private String savePhotoToTemp(Bitmap bitmap) throws Exception {
FileOutputStream out = null;
- String fileName = FileManager.createRandomFileName();
+ String fileName = MyDiaryFileUtils.createRandomFileName();
try {
- out = new FileOutputStream(fileManager.getDirAbsolutePath() + "/" + fileName);
+ out = new FileOutputStream(localDir.getDirAbsolutePath() + "/" + fileName);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); // bmp is your Bitmap instance
} finally {
try {
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java
index fd4675c..5fad458 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryFragment.java
@@ -53,12 +53,14 @@
import com.kiminonawa.mydiary.entries.diary.item.IDairyRow;
import com.kiminonawa.mydiary.entries.diary.picker.DatePickerFragment;
import com.kiminonawa.mydiary.entries.diary.picker.TimePickerFragment;
-import com.kiminonawa.mydiary.shared.FileManager;
import com.kiminonawa.mydiary.shared.PermissionHelper;
import com.kiminonawa.mydiary.shared.SPFManager;
import com.kiminonawa.mydiary.shared.ThemeManager;
import com.kiminonawa.mydiary.shared.TimeTools;
import com.kiminonawa.mydiary.shared.ViewTools;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
@@ -125,7 +127,7 @@ public class DiaryFragment extends BaseDiaryFragment implements View.OnClickList
/**
* File
*/
- private FileManager diaryTempFileManager;
+ private IDir diaryTempLocalDir;
/**
* Google Place API
@@ -148,7 +150,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
calendar = Calendar.getInstance();
timeTools = TimeTools.getInstance(getActivity().getApplicationContext());
noLocation = getString(R.string.diary_no_location);
- diaryTempFileManager = new FileManager(getActivity(), getTopicId());
+ diaryTempLocalDir = DirFactory.CreateDiaryAutoSaveDir(getActivity(), getTopicId());
}
@Override
@@ -312,16 +314,16 @@ public void onRequestPermissionsResult(int requestCode,
}
- private void loadFileFromTemp(String fileName) {
+ private void loadFileFromTemp(String fileName,DiaryTextTag tag) {
try {
- String tempFileSrc = FileManager.FILE_HEADER + diaryTempFileManager.getDirAbsolutePath() + "/" + fileName;
-// Bitmap resizeBmp = BitmapFactory.decodeFile(tempFileSrc);
-// if (resizeBmp != null) {
+ String tempFileSrc = MyDiaryFileUtils.FILE_HEADER + diaryTempLocalDir.getDirAbsolutePath() + "/" + fileName;
DiaryPhoto diaryPhoto = new DiaryPhoto(getActivity());
diaryPhoto.setPhoto(Uri.parse(tempFileSrc), fileName);
- DiaryTextTag tag = checkoutOldDiaryContent();
//Check edittext is focused
if (tag != null) {
+ //Delete duplicate text
+ EditText currentEditText = (EditText) diaryItemHelper.get(tag.getPositionTag()).getView();
+ currentEditText.getText().delete(tag.getEdittextIndex(), currentEditText.getText().toString().length());
//Add new edittext
DiaryText diaryText = new DiaryText(getActivity());
diaryText.setPosition(tag.getPositionTag());
@@ -343,9 +345,6 @@ private void loadFileFromTemp(String fileName) {
diaryItemHelper.createItem(diaryText);
diaryText.getView().requestFocus();
}
-// } else {
-// throw new FileNotFoundException(tempFileSrc + "not found or bitmap is null");
-// }
} catch (Exception e) {
Log.e(TAG, e.toString());
Toast.makeText(getActivity(), getString(R.string.toast_photo_path_error), Toast.LENGTH_LONG).show();
@@ -412,7 +411,7 @@ private void clearDiaryPage() {
* The temp file only be clear when click clear button & diary save
*/
private void clearDiaryTemp() {
- diaryTempFileManager.clearDir();
+ diaryTempLocalDir.clearDir();
SPFManager.clearDiaryAutoSave(getActivity(), getTopicId());
}
@@ -483,8 +482,8 @@ private void loadDiaryItemContent(BUDiaryEntries autoSaveDiary) {
String content = "";
if (autoSaveDiary.getDiaryItemList().get(i).getDiaryItemType() == IDairyRow.TYPE_PHOTO) {
diaryItem = new DiaryPhoto(getActivity());
- content = FileManager.FILE_HEADER +
- diaryTempFileManager.getDirAbsolutePath() + "/" +
+ content = MyDiaryFileUtils.FILE_HEADER +
+ diaryTempLocalDir.getDirAbsolutePath() + "/" +
autoSaveDiary.getDiaryItemList().get(i).getDiaryItemContent();
((DiaryPhoto) diaryItem).setDeleteClickListener(this);
//For get the right file name
@@ -589,7 +588,7 @@ public void onProviderDisabled(String provider) {
};
private void openPhotoBottomSheet() {
- DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(false);
+ DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(false,checkoutOldDiaryContent());
diaryPhotoBottomSheet.setTargetFragment(this, 0);
diaryPhotoBottomSheet.show(getFragmentManager(), "diaryPhotoBottomSheet");
}
@@ -605,7 +604,8 @@ private DiaryTextTag checkoutOldDiaryContent() {
int index = currentEditText.getSelectionStart();
String nextEditTextStr = currentEditText.getText().toString()
.substring(index, currentEditText.getText().toString().length());
- currentEditText.getText().delete(index, currentEditText.getText().toString().length());
+ //Set index & text string
+ tag.setEdittextIndex(index);
tag.setNextEditTextStr(nextEditTextStr);
}
}
@@ -614,31 +614,31 @@ private DiaryTextTag checkoutOldDiaryContent() {
@Override
- public void selectPhoto(Uri uri) {
- if (FileManager.isImage(
- FileManager.getFileNameByUri(getActivity(), uri))) {
+ public void selectPhoto(Uri uri,DiaryTextTag tag) {
+ if (MyDiaryFileUtils.isImage(
+ MyDiaryFileUtils.getFileNameByUri(getActivity(), uri))) {
//1.Copy bitmap to temp for rotating & resize
//2.Then Load bitmap call back ;
new CopyPhotoTask(getActivity(), uri,
DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()),
- diaryTempFileManager, this).execute();
+ diaryTempLocalDir, this,tag).execute();
} else {
Toast.makeText(getActivity(), getString(R.string.toast_not_image), Toast.LENGTH_LONG).show();
}
}
@Override
- public void addPhoto(String fileName) {
+ public void addPhoto(String fileName,DiaryTextTag tag) {
//1.get saved file for rotating & resize from temp
//2.Then , Load bitmap in call back ;
new CopyPhotoTask(getActivity(), fileName,
DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()),
- diaryTempFileManager, this).execute();
+ diaryTempLocalDir, this,tag).execute();
}
@Override
- public void onCopyCompiled(String fileName) {
- loadFileFromTemp(fileName);
+ public void onCopyCompiled(String fileName,DiaryTextTag tag) {
+ loadFileFromTemp(fileName,tag);
}
@@ -745,7 +745,7 @@ public void onClick(View v) {
}
break;
case R.id.IV_diary_photo:
- if (FileManager.getSDCardFreeSize() > FileManager.MIN_FREE_SPACE) {
+ if (MyDiaryFileUtils.getSDCardFreeSize() > MyDiaryFileUtils.MIN_FREE_SPACE) {
if (PermissionHelper.checkPermission(this, REQUEST_CAMERA_AND_WRITE_ES_PERMISSION)) {
if (diaryItemHelper.getNowPhotoCount() < DiaryItemHelper.MAX_PHOTO_COUNT) {
openPhotoBottomSheet();
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java
index dd8c53f..fbc1f10 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/DiaryPhotoBottomSheet.java
@@ -18,8 +18,12 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.entries.DiaryActivity;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.entries.diary.item.DiaryTextTag;
import com.kiminonawa.mydiary.shared.ThemeManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import java.io.File;
@@ -32,9 +36,9 @@
public class DiaryPhotoBottomSheet extends BottomSheetDialogFragment implements View.OnClickListener {
public interface PhotoCallBack {
- void addPhoto(String fileName);
+ void addPhoto(String fileName, DiaryTextTag tag);
- void selectPhoto(Uri uri);
+ void selectPhoto(Uri uri, DiaryTextTag tag);
}
private RelativeLayout RL_diary_photo_dialog;
@@ -49,16 +53,17 @@ public interface PhotoCallBack {
/**
* File
*/
- private FileManager fileManager;
+ private IDir localDir;
private String tempFileName;
private PhotoCallBack callBack;
- public static DiaryPhotoBottomSheet newInstance(boolean isEditMode) {
+ public static DiaryPhotoBottomSheet newInstance(boolean isEditMode, DiaryTextTag tag) {
Bundle args = new Bundle();
DiaryPhotoBottomSheet fragment = new DiaryPhotoBottomSheet();
args.putBoolean("isEditMode", isEditMode);
+ args.putParcelable("diaryTextTag", tag);
fragment.setArguments(args);
return fragment;
}
@@ -68,9 +73,9 @@ public static DiaryPhotoBottomSheet newInstance(boolean isEditMode) {
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
if (getArguments().getBoolean("isEditMode", false)) {
- fileManager = new FileManager(getActivity(), FileManager.DIARY_EDIT_CACHE_DIR);
+ localDir = DirFactory.CreateDirByType(getActivity(), LocalDir.DIARY_EDIT_CACHE_DIR);
} else {
- fileManager = new FileManager(getActivity(), ((DiaryActivity) getActivity()).getTopicId());
+ localDir = DirFactory.CreateDiaryAutoSaveDir(getActivity(), ((DiaryActivity) getActivity()).getTopicId());
}
try {
callBack = (PhotoCallBack) getTargetFragment();
@@ -101,16 +106,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
+
+ DiaryTextTag tag = null;
+ if (getArguments().getParcelable("diaryTextTag") instanceof DiaryTextTag) {
+ tag = getArguments().getParcelable("diaryTextTag");
+ }
+
if (requestCode == REQUEST_START_CAMERA_CODE) {
if (resultCode == RESULT_OK) {
- callBack.addPhoto(tempFileName);
+ callBack.addPhoto(tempFileName, tag);
}
dismiss();
} else if (requestCode == REQUEST_SELECT_IMAGE_CODE) {
if (resultCode == RESULT_OK) {
//fix the ZenPhone C & HTC 626 crash issues
if (data != null && data.getData() != null && callBack != null) {
- callBack.selectPhoto(data.getData());
+ callBack.selectPhoto(data.getData(), tag);
} else {
Toast.makeText(getActivity(), getString(R.string.toast_photo_intent_error), Toast.LENGTH_LONG).show();
}
@@ -125,8 +136,8 @@ public void onClick(View v) {
switch (v.getId()) {
case R.id.IV_diary_photo_add_a_photo:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- tempFileName = "/" + fileManager.createRandomFileName();
- File tmpFile = new File(fileManager.getDir(), tempFileName);
+ tempFileName = "/" + MyDiaryFileUtils.createRandomFileName();
+ File tmpFile = new File(localDir.getDir(), tempFileName);
Uri outputFileUri;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
outputFileUri = Uri.fromFile(tmpFile);
@@ -139,7 +150,7 @@ public void onClick(View v) {
startActivityForResult(intent, REQUEST_START_CAMERA_CODE);
break;
case R.id.IV_diary_photo_select_a_photo:
- FileManager.startBrowseImageFile(this, REQUEST_SELECT_IMAGE_CODE);
+ MyDiaryFileUtils.startBrowseImageFile(this, REQUEST_SELECT_IMAGE_CODE);
break;
}
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java
index 43294ac..da97c52 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/SaveDiaryTask.java
@@ -10,7 +10,9 @@
import com.kiminonawa.mydiary.db.DBManager;
import com.kiminonawa.mydiary.entries.diary.item.DiaryItemHelper;
import com.kiminonawa.mydiary.entries.diary.item.IDairyRow;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import java.io.File;
@@ -37,7 +39,7 @@ public interface SaveDiaryCallBack {
private boolean attachment;
private String locationName;
private DiaryItemHelper diaryItemHelper;
- private FileManager tempFileManager, diaryFileManager;
+ private IDir tempLocalDir, diaryLocalDir;
private ProgressDialog progressDialog;
private SaveDiaryCallBack callBack;
@@ -61,7 +63,7 @@ public SaveDiaryTask(Context context, long time, String title,
this.attachment = attachment;
this.locationName = locationName;
this.diaryItemHelper = diaryItemHelper;
- this.tempFileManager = new FileManager(context, topicId);
+ this.tempLocalDir = DirFactory.CreateDiaryAutoSaveDir(context, topicId);
this.callBack = callBack;
progressDialog.show();
@@ -72,17 +74,17 @@ protected Integer doInBackground(Long... params) {
int saveResult = RESULT_INSERT_SUCCESSFUL;
long topicId = params[0];
+ dbManager.opeDB();
+ dbManager.beginTransaction();
try {
- dbManager.opeDB();
- dbManager.beginTransaction();
//Save info
long diaryId = dbManager.insertDiaryInfo(time,
title, moodPosition, weatherPosition,
attachment, topicId, locationName);
//Save content
- diaryFileManager = new FileManager(mContext, topicId, diaryId);
+ diaryLocalDir = DirFactory.CreateDiaryDir(mContext, topicId, diaryId);
//Check no any garbage in this diary.
- diaryFileManager.clearDir();
+ diaryLocalDir.clearDir();
if (diaryId != -1) {
for (int i = 0; i < diaryItemHelper.getItemSize(); i++) {
//Copy photo from temp to diary dir
@@ -100,8 +102,8 @@ protected Integer doInBackground(Long... params) {
} catch (Exception e) {
Log.e(TAG, "save diary fail", e);
//Revert the Data
- if (diaryFileManager != null) {
- diaryFileManager.clearDir();
+ if (diaryLocalDir != null) {
+ diaryLocalDir.clearDir();
}
saveResult = RESULT_INSERT_ERROR;
} finally {
@@ -114,17 +116,17 @@ protected Integer doInBackground(Long... params) {
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
+ progressDialog.dismiss();
if (result == SaveDiaryTask.RESULT_INSERT_SUCCESSFUL) {
Toast.makeText(mContext, mContext.getString(R.string.toast_diary_insert_successful), Toast.LENGTH_LONG).show();
+ callBack.onDiarySaved();
} else {
Toast.makeText(mContext, mContext.getString(R.string.toast_diary_insert_fail), Toast.LENGTH_LONG).show();
}
- progressDialog.dismiss();
- callBack.onDiarySaved();
}
private void savePhoto(String filename) throws Exception {
- FileManager.copy(new File(tempFileManager.getDirAbsolutePath() + "/" + filename),
- new File(diaryFileManager.getDirAbsolutePath() + "/" + filename));
+ MyDiaryFileUtils.copy(new File(tempLocalDir.getDirAbsolutePath() + "/" + filename),
+ new File(diaryLocalDir.getDirAbsolutePath() + "/" + filename));
}
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java
index e707d3c..3b48bd2 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/diary/item/DiaryTextTag.java
@@ -1,18 +1,28 @@
package com.kiminonawa.mydiary.entries.diary.item;
+import android.os.Parcel;
+import android.os.Parcelable;
+
/**
* Created by daxia on 2016/11/21.
* To avoid getting the error focus , and send more data in one method.
*/
-public class DiaryTextTag {
+public class DiaryTextTag implements Parcelable {
private int positionTag;
+ private int edittextIndex;
private String nextEditTextStr;
public DiaryTextTag(int positionTag) {
this.positionTag = positionTag;
}
+ protected DiaryTextTag(Parcel in) {
+ positionTag = in.readInt();
+ edittextIndex = in.readInt();
+ nextEditTextStr = in.readString();
+ }
+
public int getPositionTag() {
return positionTag;
}
@@ -28,4 +38,42 @@ public String getNextEditTextStr() {
public void setNextEditTextStr(String nextEditTextStr) {
this.nextEditTextStr = nextEditTextStr;
}
+
+ public int getEdittextIndex() {
+ return edittextIndex;
+ }
+
+ public void setEdittextIndex(int edittextIndex) {
+ this.edittextIndex = edittextIndex;
+ }
+
+ /*
+ * Parcel
+ */
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(positionTag);
+ dest.writeInt(edittextIndex);
+ dest.writeString(nextEditTextStr);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ @Override
+ public DiaryTextTag createFromParcel(Parcel in) {
+ return new DiaryTextTag(in);
+ }
+
+ @Override
+ public DiaryTextTag[] newArray(int size) {
+ return new DiaryTextTag[size];
+ }
+ };
+
+
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/CopyDiaryToEditCacheTask.java b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/CopyDiaryToEditCacheTask.java
index a136a1e..1edc5a8 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/CopyDiaryToEditCacheTask.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/CopyDiaryToEditCacheTask.java
@@ -5,7 +5,9 @@
import android.widget.Toast;
import com.kiminonawa.mydiary.R;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import java.io.File;
@@ -20,14 +22,14 @@ public interface EditTaskCallBack {
}
private EditTaskCallBack callBack;
- private FileManager editCacheFileManage;
+ private IDir editCacheFileManage;
private Context mContext;
public final static int RESULT_COPY_SUCCESSFUL = 1;
public final static int RESULT_COPY_ERROR = 2;
- public CopyDiaryToEditCacheTask(Context context, FileManager editCacheFileManage,
+ public CopyDiaryToEditCacheTask(Context context, IDir editCacheFileManage,
EditTaskCallBack callBack) {
this.mContext = context;
this.editCacheFileManage = editCacheFileManage;
@@ -41,10 +43,10 @@ protected Integer doInBackground(Long... params) {
long topicId = params[0];
long diaryId = params[1];
try {
- FileManager diaryFileManager = new FileManager(mContext, topicId, diaryId);
- File[] childrenPhoto = diaryFileManager.getDir().listFiles();
- for (int i = 0; i < diaryFileManager.getDir().listFiles().length; i++) {
- copyPhoto(childrenPhoto[i].getName(), diaryFileManager);
+ IDir diaryLocalDir = DirFactory.CreateDiaryDir(mContext, topicId, diaryId);
+ File[] childrenPhoto = diaryLocalDir.getDir().listFiles();
+ for (int i = 0; i < diaryLocalDir.getDir().listFiles().length; i++) {
+ copyPhoto(childrenPhoto[i].getName(), diaryLocalDir);
}
} catch (Exception e) {
e.printStackTrace();
@@ -62,8 +64,8 @@ protected void onPostExecute(Integer result) {
callBack.onCopyToEditCacheCompiled(result);
}
- private void copyPhoto(String filename, FileManager diaryFileManager) throws Exception {
- FileManager.copy(new File(diaryFileManager.getDirAbsolutePath() + "/" + filename),
+ private void copyPhoto(String filename, IDir diaryLocalDir) throws Exception {
+ MyDiaryFileUtils.copy(new File(diaryLocalDir.getDirAbsolutePath() + "/" + filename),
new File(editCacheFileManage.getDirAbsolutePath() + "/" + filename));
}
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryDeleteDialogFragment.java b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryDeleteDialogFragment.java
index 00b0e2d..a6ab85e 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryDeleteDialogFragment.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryDeleteDialogFragment.java
@@ -6,7 +6,7 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.db.DBManager;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
import com.kiminonawa.mydiary.shared.gui.CommonDialogFragment;
import java.io.IOException;
@@ -48,7 +48,7 @@ private void deleteDiary() {
dbManager.closeDB();
//Delete photo data
try {
- deleteDirectory(new FileManager(getActivity(), topicId, diaryId).getDir());
+ deleteDirectory(DirFactory.CreateDiaryDir(getActivity(), topicId, diaryId).getDir());
} catch (IOException e) {
//just do nothing
e.printStackTrace();
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java
index 33ec4cc..b6ebc37 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/DiaryViewerDialogFragment.java
@@ -60,12 +60,15 @@
import com.kiminonawa.mydiary.entries.diary.picker.TimePickerFragment;
import com.kiminonawa.mydiary.entries.photo.PhotoDetailViewerActivity;
import com.kiminonawa.mydiary.entries.photo.PhotoOverviewActivity;
-import com.kiminonawa.mydiary.shared.FileManager;
import com.kiminonawa.mydiary.shared.PermissionHelper;
import com.kiminonawa.mydiary.shared.ScreenHelper;
import com.kiminonawa.mydiary.shared.ThemeManager;
import com.kiminonawa.mydiary.shared.TimeTools;
import com.kiminonawa.mydiary.shared.ViewTools;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper;
import java.lang.ref.WeakReference;
@@ -131,7 +134,7 @@ public interface DiaryViewerCallback {
*/
private long diaryId;
private DiaryItemHelper diaryItemHelper;
- private FileManager diaryFileManager;
+ private IDir diaryLocalDir;
/**
* Edit Mode
@@ -267,10 +270,10 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
if (diaryId != -1) {
if (isEditMode) {
diaryViewerHandler = new DiaryViewerHandler(this);
- diaryFileManager = new FileManager(getActivity(), FileManager.DIARY_EDIT_CACHE_DIR);
- diaryFileManager.clearDir();
+ diaryLocalDir = DirFactory.CreateDirByType(getActivity(), LocalDir.DIARY_EDIT_CACHE_DIR);
+ diaryLocalDir.clearDir();
PB_diary_item_content_hint.setVisibility(View.VISIBLE);
- mTask = new CopyDiaryToEditCacheTask(getActivity(), diaryFileManager, this);
+ mTask = new CopyDiaryToEditCacheTask(getActivity(), diaryLocalDir, this);
//Make ths ProgressBar show 0.7s+.
loadDiaryHandler = new Handler();
initHandlerOrTaskIsRunning = true;
@@ -282,7 +285,7 @@ public void run() {
}
}, 700);
} else {
- diaryFileManager = new FileManager(getActivity(), ((DiaryActivity) getActivity()).getTopicId(), diaryId);
+ diaryLocalDir = DirFactory.CreateDiaryDir(getActivity(), ((DiaryActivity) getActivity()).getTopicId(), diaryId);
diaryPhotoFileList = new ArrayList<>();
initData();
}
@@ -504,8 +507,8 @@ private void loadDiaryItemContent(DBManager dbManager) {
String content = "";
if (diaryContentCursor.getInt(1) == IDairyRow.TYPE_PHOTO) {
diaryItem = new DiaryPhoto(getActivity());
- content = FileManager.FILE_HEADER +
- diaryFileManager.getDirAbsolutePath() + "/" + diaryContentCursor.getString(3);
+ content = MyDiaryFileUtils.FILE_HEADER +
+ diaryLocalDir.getDirAbsolutePath() + "/" + diaryContentCursor.getString(3);
if (isEditMode) {
diaryItem.setEditMode(true);
((DiaryPhoto) diaryItem).setDeleteClickListener(this);
@@ -641,14 +644,16 @@ private void setIcon(int mood, int weather) {
}
}
- private void loadFileFromTemp(String fileName) {
+ private void loadFileFromTemp(String fileName, DiaryTextTag tag) {
try {
- String tempFileSrc = FileManager.FILE_HEADER + diaryFileManager.getDirAbsolutePath() + "/" + fileName;
+ String tempFileSrc = MyDiaryFileUtils.FILE_HEADER + diaryLocalDir.getDirAbsolutePath() + "/" + fileName;
DiaryPhoto diaryPhoto = new DiaryPhoto(getActivity());
diaryPhoto.setPhoto(Uri.parse(tempFileSrc), fileName);
- DiaryTextTag tag = checkoutOldDiaryContent();
//Check edittext is focused
if (tag != null) {
+ //Delete duplicate text
+ EditText currentEditText = (EditText) diaryItemHelper.get(tag.getPositionTag()).getView();
+ currentEditText.getText().delete(tag.getEdittextIndex(), currentEditText.getText().toString().length());
//Add new edittext
DiaryText diaryText = new DiaryText(getActivity());
diaryText.setPosition(tag.getPositionTag());
@@ -689,7 +694,8 @@ private DiaryTextTag checkoutOldDiaryContent() {
int index = currentEditText.getSelectionStart();
String nextEditTextStr = currentEditText.getText().toString()
.substring(index, currentEditText.getText().toString().length());
- currentEditText.getText().delete(index, currentEditText.getText().toString().length());
+ //Set index & text string
+ tag.setEdittextIndex(index);
tag.setNextEditTextStr(nextEditTextStr);
}
}
@@ -708,12 +714,12 @@ private void updateDiary() {
locationName,
//Check attachment
diaryItemHelper.getNowPhotoCount() > 0 ? true : false,
- diaryItemHelper, diaryFileManager, this).execute(((DiaryActivity) getActivity()).getTopicId(), diaryId);
+ diaryItemHelper, diaryLocalDir, this).execute(((DiaryActivity) getActivity()).getTopicId(), diaryId);
}
private void openPhotoBottomSheet() {
- DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(true);
+ DiaryPhotoBottomSheet diaryPhotoBottomSheet = DiaryPhotoBottomSheet.newInstance(true, checkoutOldDiaryContent());
diaryPhotoBottomSheet.setTargetFragment(this, 0);
diaryPhotoBottomSheet.show(getFragmentManager(), "diaryPhotoBottomSheet");
}
@@ -725,31 +731,31 @@ public void onDiaryUpdated() {
}
@Override
- public void selectPhoto(Uri uri) {
- if (FileManager.isImage(
- FileManager.getFileNameByUri(getActivity(), uri))) {
+ public void selectPhoto(Uri uri, DiaryTextTag tag) {
+ if (MyDiaryFileUtils.isImage(
+ MyDiaryFileUtils.getFileNameByUri(getActivity(), uri))) {
//1.Copy bitmap to temp for rotating & resize
//2.Then Load bitmap call back ;
new CopyPhotoTask(getActivity(), uri,
DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()),
- diaryFileManager, this).execute();
+ diaryLocalDir, this, tag).execute();
} else {
Toast.makeText(getActivity(), getString(R.string.toast_not_image), Toast.LENGTH_LONG).show();
}
}
@Override
- public void addPhoto(String fileName) {
+ public void addPhoto(String fileName, DiaryTextTag tag) {
//1.get saved file for rotating & resize from temp
//2.Then , Load bitmap in call back ;
new CopyPhotoTask(getActivity(), fileName,
DiaryItemHelper.getVisibleWidth(getActivity()), DiaryItemHelper.getVisibleHeight(getActivity()),
- diaryFileManager, this).execute();
+ diaryLocalDir, this, tag).execute();
}
@Override
- public void onCopyCompiled(String fileName) {
- loadFileFromTemp(fileName);
+ public void onCopyCompiled(String fileName, DiaryTextTag tag) {
+ loadFileFromTemp(fileName, tag);
}
@@ -772,7 +778,7 @@ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth
setDiaryTime();
TimePickerFragment timePickerFragment = TimePickerFragment.newInstance(calendar.getTimeInMillis());
timePickerFragment.setOnTimeSetListener(this);
- timePickerFragment.show(getFragmentManager(), "timePickerFragment");
+ timePickerFragment.show(getActivity().getSupportFragmentManager(), "timePickerFragment");
}
}
@@ -790,11 +796,12 @@ public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
@Override
public void onCopyToEditCacheCompiled(int result) {
if (result == CopyDiaryToEditCacheTask.RESULT_COPY_SUCCESSFUL) {
- PB_diary_item_content_hint.setVisibility(View.GONE);
initData();
//Open the click listener
IV_diary_clear.setOnClickListener(this);
IV_diary_save.setOnClickListener(this);
+ //hide the loading process bar
+ PB_diary_item_content_hint.setVisibility(View.GONE);
} else {
dismissAllowingStateLoss();
}
@@ -829,7 +836,6 @@ public void onClick(View v) {
break;
case R.id.IV_diary_photo_delete:
int deletePosition = (int) v.getTag();
- Log.e("test", "deletePosition = " + deletePosition);
diaryItemHelper.remove(deletePosition);
LL_diary_item_content.removeViewAt(deletePosition);
diaryItemHelper.mergerAdjacentText(deletePosition);
@@ -846,7 +852,7 @@ public void onClick(View v) {
case R.id.IV_diary_photo:
if (isEditMode) {
//Allow add photo
- if (FileManager.getSDCardFreeSize() > FileManager.MIN_FREE_SPACE) {
+ if (MyDiaryFileUtils.getSDCardFreeSize() > MyDiaryFileUtils.MIN_FREE_SPACE) {
if (PermissionHelper.checkPermission(this, REQUEST_CAMERA_AND_WRITE_ES_PERMISSION)) {
if (diaryItemHelper.getNowPhotoCount() < DiaryItemHelper.MAX_PHOTO_COUNT) {
openPhotoBottomSheet();
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/UpdateDiaryTask.java b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/UpdateDiaryTask.java
index e6e3314..a4f2467 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/entries/UpdateDiaryTask.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/entries/UpdateDiaryTask.java
@@ -9,7 +9,9 @@
import com.kiminonawa.mydiary.db.DBManager;
import com.kiminonawa.mydiary.entries.diary.item.DiaryItemHelper;
import com.kiminonawa.mydiary.entries.diary.item.IDairyRow;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import org.apache.commons.io.FileUtils;
@@ -37,7 +39,7 @@ public interface UpdateDiaryCallBack {
private String location;
private boolean attachment;
private DiaryItemHelper diaryItemHelper;
- private FileManager editCrashFileManager, diaryFileManager;
+ private IDir editCrashLocalDir, diaryLocalDir;
private ProgressDialog progressDialog;
private UpdateDiaryCallBack callBack;
@@ -46,7 +48,7 @@ public interface UpdateDiaryCallBack {
public UpdateDiaryTask(Context context, long time, String title,
int moodPosition, int weatherPosition, String location,
boolean attachment, DiaryItemHelper diaryItemHelper,
- FileManager fileManager, UpdateDiaryCallBack callBack) {
+ IDir localDir, UpdateDiaryCallBack callBack) {
this.dbManager = new DBManager(context);
this.mContext = context;
@@ -57,7 +59,7 @@ public UpdateDiaryTask(Context context, long time, String title,
this.weatherPosition = weatherPosition;
this.attachment = attachment;
this.diaryItemHelper = diaryItemHelper;
- this.editCrashFileManager = fileManager;
+ this.editCrashLocalDir = localDir;
this.callBack = callBack;
progressDialog = new ProgressDialog(context);
@@ -80,8 +82,8 @@ protected Integer doInBackground(Long... params) {
//Delete all item first
dbManager.delAllDiaryItemByDiaryId(diaryId);
//Delete old photo
- diaryFileManager = new FileManager(mContext, topicId, diaryId);
- diaryFileManager.clearDir();
+ diaryLocalDir = DirFactory.CreateDiaryDir(mContext, topicId, diaryId);
+ diaryLocalDir.clearDir();
//Update Diary
dbManager.updateDiary(diaryId, time, title, moodPosition, weatherPosition, location, attachment);
for (int i = 0; i < diaryItemHelper.getItemSize(); i++) {
@@ -94,14 +96,14 @@ protected Integer doInBackground(Long... params) {
, diaryItemHelper.get(i).getContent(), diaryId);
}
//Delete all dir if it is no file.
- if (diaryFileManager.getDir().listFiles().length == 0) {
- FileUtils.deleteDirectory(diaryFileManager.getDir());
+ if (diaryLocalDir.getDir().listFiles().length == 0) {
+ FileUtils.deleteDirectory(diaryLocalDir.getDir());
}
} catch (Exception e) {
updateResult = RESULT_UPDATE_ERROR;
} finally {
dbManager.closeDB();
- editCrashFileManager.clearDir();
+ editCrashLocalDir.clearDir();
}
return updateResult;
}
@@ -119,7 +121,7 @@ protected void onPostExecute(Integer result) {
}
private void savePhoto(String filename) throws Exception {
- FileManager.copy(new File(editCrashFileManager.getDirAbsolutePath() + "/" + filename),
- new File(diaryFileManager.getDirAbsolutePath() + "/" + filename));
+ MyDiaryFileUtils.copy(new File(editCrashLocalDir.getDirAbsolutePath() + "/" + filename),
+ new File(diaryLocalDir.getDirAbsolutePath() + "/" + filename));
}
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java
index 7b42fb6..cdcbae6 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoDetailViewerActivity.java
@@ -1,6 +1,7 @@
package com.kiminonawa.mydiary.entries.photo;
import android.annotation.TargetApi;
+import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
@@ -12,6 +13,8 @@
import android.widget.Toast;
import com.kiminonawa.mydiary.R;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.ScreenHelper;
import java.util.ArrayList;
@@ -71,6 +74,12 @@ public void onCreate(Bundle savedInstanceState) {
}
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setStatusBarColor() {
Window window = getWindow();
diff --git a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java
index 2910900..9f9dd6c 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/entries/photo/PhotoOverviewActivity.java
@@ -1,5 +1,6 @@
package com.kiminonawa.mydiary.entries.photo;
+import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -11,7 +12,10 @@
import android.widget.Toast;
import com.kiminonawa.mydiary.R;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import java.io.File;
import java.util.ArrayList;
@@ -20,7 +24,7 @@
import butterknife.BindView;
import butterknife.ButterKnife;
-import static com.kiminonawa.mydiary.shared.FileManager.DIARY_ROOT_DIR;
+import static com.kiminonawa.mydiary.shared.file.LocalDir.DIARY_ROOT_DIR;
/**
* Created by daxia on 2017/4/12.
@@ -71,8 +75,14 @@ protected void onCreate(Bundle savedInstanceState) {
}
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
private void loadDiaryImageData(long topicId, long diaryId) {
- FileManager diaryRoot = new FileManager(PhotoOverviewActivity.this, DIARY_ROOT_DIR);
+ IDir diaryRoot = DirFactory.CreateDirByType(PhotoOverviewActivity.this, DIARY_ROOT_DIR);
File topicRootFile;
if (diaryId != -1) {
topicRootFile = new File(diaryRoot.getDirAbsolutePath() + "/" + topicId + "/" + diaryId);
diff --git a/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java b/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java
index 534f434..960ce90 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/init/InitActivity.java
@@ -1,6 +1,7 @@
package com.kiminonawa.mydiary.init;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
@@ -11,6 +12,8 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.main.MainActivity;
import com.kiminonawa.mydiary.security.PasswordActivity;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.MyDiaryApplication;
import com.kiminonawa.mydiary.shared.SPFManager;
@@ -52,6 +55,11 @@ protected void onPause() {
initHandler.removeCallbacksAndMessages(null);
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
@Override
public void onInitCompiled(boolean showReleaseNote) {
diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java b/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java
index e0ed976..193a5ca 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/main/AboutActivity.java
@@ -1,10 +1,13 @@
package com.kiminonawa.mydiary.main;
+import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import com.kiminonawa.mydiary.R;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper;
/**
@@ -75,6 +78,12 @@ public void onCreate(Bundle savedInstanceState) {
((TextView) findViewById(R.id.TV_about_text)).setText(license.toString());
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
public class LicenseObj {
public final static int MIT = 0;
diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java b/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java
index c449dc5..3ac6565 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/main/MainActivity.java
@@ -1,5 +1,6 @@
package com.kiminonawa.mydiary.main;
+import android.content.Context;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.os.Bundle;
@@ -33,10 +34,14 @@
import com.kiminonawa.mydiary.main.topic.ITopic;
import com.kiminonawa.mydiary.main.topic.Memo;
import com.kiminonawa.mydiary.oobe.CustomViewTarget;
-import com.kiminonawa.mydiary.shared.FileManager;
import com.kiminonawa.mydiary.shared.SPFManager;
import com.kiminonawa.mydiary.shared.ThemeManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
import com.kiminonawa.mydiary.shared.gui.MyDiaryButton;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper;
import com.kiminonawa.mydiary.shared.statusbar.OOBE;
@@ -188,6 +193,12 @@ public void onDestroy() {
super.onDestroy();
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
@Override
public void onBackPressed() {
if (!isExit) {
@@ -409,9 +420,9 @@ private void updateTopicBg(int position, int topicBgStatus, String newTopicBgFil
if (outputFile.exists()) {
outputFile.delete();
}
- FileManager tempFM = new FileManager(this, FileManager.TEMP_DIR);
+ IDir tempDir = DirFactory.CreateDirByType(this, LocalDir.TEMP_DIR);
FileUtils.moveFile(new File(
- tempFM.getDirAbsolutePath()
+ tempDir.getDirAbsolutePath()
+ "/" + newTopicBgFileName),
outputFile);
//Enter the topic
@@ -570,7 +581,7 @@ public void onTopicDelete(final int position) {
}
//Delete the dir if it exist.
try {
- FileUtils.deleteDirectory(new FileManager(MainActivity.this,
+ FileUtils.deleteDirectory(DirFactory.CreateTopicDir(MainActivity.this,
mainTopicAdapter.getList().get(position).getType(),
mainTopicAdapter.getList().get(position).getId()).getDir());
} catch (IOException e) {
diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java b/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java
index e4c8ce0..8c33fc3 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/main/MainTopicAdapter.java
@@ -1,7 +1,6 @@
package com.kiminonawa.mydiary.main;
import android.content.Intent;
-import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@@ -14,15 +13,13 @@
import android.widget.TextView;
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter;
-import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemViewHolder;
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange;
-import com.h6ah4i.android.widget.advrecyclerview.draggable.annotation.DraggableItemStateFlags;
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemAdapter;
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemConstants;
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultAction;
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionDefault;
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionMoveToSwipedDirection;
-import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractSwipeableItemViewHolder;
+import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder;
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.contacts.ContactsActivity;
import com.kiminonawa.mydiary.db.DBManager;
@@ -50,6 +47,7 @@ public class MainTopicAdapter extends RecyclerView.Adapter topicList, DBManager dbManager) {
this.activity = activity;
this.dbManager = dbManager;
@@ -184,6 +182,10 @@ public int onGetSwipeReactionType(TopicViewHolder holder, int position, int x, i
}
}
+ @Override
+ public void onSwipeItemStarted(TopicViewHolder holder, int position) {
+ }
+
@Override
public void onSetSwipeBackground(TopicViewHolder holder, int position, int type) {
if (type == SwipeableItemConstants.DRAWABLE_SWIPE_NEUTRAL_BACKGROUND) {
@@ -213,14 +215,14 @@ public SwipeResultAction onSwipeItem(TopicViewHolder holder, int position, int r
@Override
public boolean onCheckCanStartDrag(TopicViewHolder holder, int position, int x, int y) {
-
// x, y --- relative from the itemView's top-left
final View containerView = holder.getSwipeableContainerView();
+ final View dragHandleView = holder.getDragHandleView();
- final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
- final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f);
+ final int offsetX = containerView.getLeft() + (int) (containerView.getTranslationX() + 0.5f);
+ final int offsetY = containerView.getTop() + (int) (containerView.getTranslationY() + 0.5f);
- return !topicFilter.isFilter() && ViewTools.hitTest(containerView, x - offsetX, y - offsetY);
+ return !topicFilter.isFilter() && ViewTools.hitTest(dragHandleView, x - offsetX, y - offsetY);
}
@Override
@@ -233,7 +235,6 @@ public void onMoveItem(int fromPosition, int toPosition) {
if (fromPosition == toPosition) {
return;
}
-
//modify the original list
final ITopic originalItem = originalTopicList.remove(fromPosition);
originalTopicList.add(toPosition, originalItem);
@@ -242,6 +243,21 @@ public void onMoveItem(int fromPosition, int toPosition) {
final ITopic filteredItem = filteredTopicList.remove(fromPosition);
filteredTopicList.add(toPosition, filteredItem);
+ notifyDataSetChanged(false);
+ }
+
+ @Override
+ public boolean onCheckCanDrop(int draggingPosition, int dropPosition) {
+ return true;
+ }
+
+ @Override
+ public void onItemDragStarted(int position) {
+ notifyDataSetChanged(false);
+ }
+
+ @Override
+ public void onItemDragFinished(int fromPosition, int toPosition, boolean result) {
//save the new topic order
int orderNumber = originalTopicList.size();
dbManager.opeDB();
@@ -253,11 +269,6 @@ public void onMoveItem(int fromPosition, int toPosition) {
notifyDataSetChanged(false);
}
- @Override
- public boolean onCheckCanDrop(int draggingPosition, int dropPosition) {
- return true;
- }
-
private static class SwipeRightResultAction extends SwipeResultActionMoveToSwipedDirection {
private MainTopicAdapter mAdapter;
private final int mPosition;
@@ -328,11 +339,10 @@ protected void onCleanUp() {
}
- protected class TopicViewHolder extends AbstractSwipeableItemViewHolder implements DraggableItemViewHolder {
+ public static class TopicViewHolder extends AbstractDraggableSwipeableItemViewHolder {
- @DraggableItemStateFlags
- private int mDragStateFlags;
+ private View View_drag_handle;
private ImageView IV_topic_icon;
private TextView TV_topic_title;
private TextView TV_topic_count;
@@ -342,8 +352,9 @@ protected class TopicViewHolder extends AbstractSwipeableItemViewHolder implemen
private RelativeLayout RL_topic_content;
private ImageView IV_topic_left_setting_edit, IV_topic_left_setting_delete;
- protected TopicViewHolder(View rootView) {
+ TopicViewHolder(View rootView) {
super(rootView);
+ this.View_drag_handle = (View) rootView.findViewById(R.id.View_drag_handle);
this.RL_topic_content = (RelativeLayout) rootView.findViewById(R.id.RL_topic_content);
this.IV_topic_icon = (ImageView) rootView.findViewById(R.id.IV_topic_icon);
this.TV_topic_title = (TextView) rootView.findViewById(R.id.TV_topic_title);
@@ -355,8 +366,6 @@ protected TopicViewHolder(View rootView) {
this.LL_topic_left_setting = (LinearLayout) rootView.findViewById(R.id.LL_topic_left_setting);
this.IV_topic_left_setting_edit = (ImageView) rootView.findViewById(R.id.IV_topic_left_setting_edit);
this.IV_topic_left_setting_delete = (ImageView) rootView.findViewById(R.id.IV_topic_left_setting_delete);
-
-
}
@Override
@@ -364,47 +373,39 @@ public View getSwipeableContainerView() {
return RL_topic_content;
}
- @Override
- public void setDragStateFlags(@DraggableItemStateFlags int flags) {
- mDragStateFlags = flags;
- }
-
- @Override
- @DraggableItemStateFlags
- public int getDragStateFlags() {
- return mDragStateFlags;
- }
-
- protected ImageView getIconView() {
+ ImageView getIconView() {
return IV_topic_icon;
}
-
- protected RelativeLayout getRLTopic() {
+ RelativeLayout getRLTopic() {
return RL_topic_view;
}
- protected TextView getTitleView() {
+ TextView getTitleView() {
return TV_topic_title;
}
- protected TextView getTVCount() {
+ TextView getTVCount() {
return TV_topic_count;
}
- protected ImageView getArrow() {
+ ImageView getArrow() {
return IV_topic_arrow_right;
}
- protected View getTopicLeftSettingView() {
+ View getDragHandleView() {
+ return View_drag_handle;
+ }
+
+ View getTopicLeftSettingView() {
return LL_topic_left_setting;
}
- protected View getTopicLeftSettingEditView() {
+ View getTopicLeftSettingEditView() {
return IV_topic_left_setting_edit;
}
- protected View getTopicLeftSettingDeleteView() {
+ View getTopicLeftSettingDeleteView() {
return IV_topic_left_setting_delete;
}
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/TopicDetailDialogFragment.java b/app/src/main/java/com/kiminonawa/mydiary/main/TopicDetailDialogFragment.java
index 3cf883c..e7e0338 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/main/TopicDetailDialogFragment.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/main/TopicDetailDialogFragment.java
@@ -23,9 +23,12 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.main.topic.ITopic;
-import com.kiminonawa.mydiary.shared.FileManager;
import com.kiminonawa.mydiary.shared.PermissionHelper;
import com.kiminonawa.mydiary.shared.ThemeManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import com.kiminonawa.mydiary.shared.gui.MyDiaryButton;
import com.yalantis.ucrop.UCrop;
@@ -180,7 +183,7 @@ public void onRequestPermissionsResult(int requestCode,
if (requestCode == PermissionHelper.REQUEST_WRITE_ES_PERMISSION) {
if (grantResults.length > 0
&& PermissionHelper.checkAllPermissionResult(grantResults)) {
- FileManager.startBrowseImageFile(this, SELECT_TOPIC_BG);
+ MyDiaryFileUtils.startBrowseImageFile(this, SELECT_TOPIC_BG);
} else {
PermissionHelper.showAddPhotoDialog(getActivity());
}
@@ -200,13 +203,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
} else {
topicBgHeight = ThemeManager.getInstance().getTopicBgWithoutEditBarHeight(getActivity());
}
- FileManager tempFileManager = new FileManager(getContext(), FileManager.TEMP_DIR);
+ IDir tempLocalDir = DirFactory.CreateDirByType(getContext(), LocalDir.TEMP_DIR);
//Clear the old photo file
- tempFileManager.clearDir();
+ tempLocalDir.clearDir();
UCrop.Options options = new UCrop.Options();
options.setToolbarColor(ThemeManager.getInstance().getThemeMainColor(getActivity()));
options.setStatusBarColor(ThemeManager.getInstance().getThemeDarkColor(getActivity()));
- UCrop.of(data.getData(), Uri.fromFile(new File(tempFileManager.getDir() + "/" + FileManager.createRandomFileName())))
+ UCrop.of(data.getData(), Uri.fromFile(new File(tempLocalDir.getDir() + "/" + MyDiaryFileUtils.createRandomFileName())))
.withMaxResultSize(topicBgWidth, topicBgHeight)
.withAspectRatio(topicBgWidth, topicBgHeight)
.withOptions(options)
@@ -220,7 +223,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
final Uri resultUri = UCrop.getOutput(data);
IV_topic_detail_topic_bg.setImageBitmap(BitmapFactory.decodeFile(resultUri.getPath()));
- newTopicBgFileName = FileManager.getFileNameByUri(getActivity(), resultUri);
+ newTopicBgFileName = MyDiaryFileUtils.getFileNameByUri(getActivity(), resultUri);
But_topic_detail_default_bg.setEnabled(true);
topicBgStatus = TOPIC_BG_ADD_PHOTO;
} else {
@@ -272,7 +275,7 @@ public void onClick(View v) {
case R.id.IV_topic_detail_topic_bg:
if (PermissionHelper.checkPermission(this, REQUEST_WRITE_ES_PERMISSION)) {
- FileManager.startBrowseImageFile(this, SELECT_TOPIC_BG);
+ MyDiaryFileUtils.startBrowseImageFile(this, SELECT_TOPIC_BG);
}
break;
case R.id.But_topic_detail_default_bg:
diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/YourNameDialogFragment.java b/app/src/main/java/com/kiminonawa/mydiary/main/YourNameDialogFragment.java
index a543e85..bbd384f 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/main/YourNameDialogFragment.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/main/YourNameDialogFragment.java
@@ -18,12 +18,15 @@
import android.widget.Toast;
import com.kiminonawa.mydiary.R;
-import com.kiminonawa.mydiary.shared.FileManager;
import com.kiminonawa.mydiary.shared.PermissionHelper;
import com.kiminonawa.mydiary.shared.SPFManager;
import com.kiminonawa.mydiary.shared.ScreenHelper;
import com.kiminonawa.mydiary.shared.ThemeManager;
import com.kiminonawa.mydiary.shared.ViewTools;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import com.kiminonawa.mydiary.shared.gui.MyDiaryButton;
import com.yalantis.ucrop.UCrop;
@@ -51,7 +54,7 @@ public interface YourNameCallback {
/**
* File
*/
- private FileManager tempFileManager;
+ private IDir tempLocalDir;
private final static int SELECT_PROFILE_PICTURE_BG = 0;
/**
* Profile picture
@@ -122,7 +125,7 @@ public void onRequestPermissionsResult(int requestCode,
if (requestCode == PermissionHelper.REQUEST_WRITE_ES_PERMISSION) {
if (grantResults.length > 0
&& PermissionHelper.checkAllPermissionResult(grantResults)) {
- FileManager.startBrowseImageFile(this, SELECT_PROFILE_PICTURE_BG);
+ MyDiaryFileUtils.startBrowseImageFile(this, SELECT_PROFILE_PICTURE_BG);
} else {
PermissionHelper.showAddPhotoDialog(getActivity());
}
@@ -136,15 +139,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null && data.getData() != null) {
//Create fileManager for get temp folder
- tempFileManager = new FileManager(getActivity(), FileManager.TEMP_DIR);
- tempFileManager.clearDir();
+ tempLocalDir = DirFactory.CreateDirByType(getActivity(), LocalDir.TEMP_DIR);
+ tempLocalDir.clearDir();
//Compute the bg size
int photoSize = ScreenHelper.dpToPixel(getResources(), 50);
UCrop.Options options = new UCrop.Options();
options.setToolbarColor(ThemeManager.getInstance().getThemeMainColor(getActivity()));
options.setStatusBarColor(ThemeManager.getInstance().getThemeDarkColor(getActivity()));
UCrop.of(data.getData(), Uri.fromFile(
- new File(tempFileManager.getDir() + "/" + FileManager.createRandomFileName())))
+ new File(tempLocalDir.getDir() + "/" + MyDiaryFileUtils.createRandomFileName())))
.withMaxResultSize(photoSize, photoSize)
.withAspectRatio(1, 1)
.withOptions(options)
@@ -158,7 +161,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
final Uri resultUri = UCrop.getOutput(data);
IV_your_name_profile_picture.setImageBitmap(BitmapFactory.decodeFile(resultUri.getPath()));
- profilePictureFileName = FileManager.getFileNameByUri(getActivity(), resultUri);
+ profilePictureFileName = MyDiaryFileUtils.getFileNameByUri(getActivity(), resultUri);
isAddNewProfilePicture = true;
} else {
Toast.makeText(getActivity(), getString(R.string.toast_crop_profile_picture_fail), Toast.LENGTH_LONG).show();
@@ -180,7 +183,7 @@ private void saveYourName() {
//Save profile picture
if (isAddNewProfilePicture) {
//Remove the old file
- FileManager bgFM = new FileManager(getActivity(), FileManager.SETTING_DIR);
+ IDir bgFM = DirFactory.CreateDirByType(getActivity(), LocalDir.SETTING_DIR);
File oldProfilePictureFile = new File(bgFM.getDirAbsolutePath()
+ "/" + ThemeManager.CUSTOM_PROFILE_PICTURE_FILENAME);
if (oldProfilePictureFile.exists()) {
@@ -189,8 +192,8 @@ private void saveYourName() {
if (!"".equals(profilePictureFileName)) {
try {
//Copy the profile into setting dir
- FileManager.copy(
- new File(tempFileManager.getDirAbsolutePath() + "/" + profilePictureFileName),
+ MyDiaryFileUtils.copy(
+ new File(tempLocalDir.getDirAbsolutePath() + "/" + profilePictureFileName),
oldProfilePictureFile);
} catch (Exception e) {
e.printStackTrace();
@@ -206,7 +209,7 @@ public void onClick(View v) {
switch (v.getId()) {
case R.id.IV_your_name_profile_picture:
if (PermissionHelper.checkPermission(this, REQUEST_WRITE_ES_PERMISSION)) {
- FileManager.startBrowseImageFile(this, SELECT_PROFILE_PICTURE_BG);
+ MyDiaryFileUtils.startBrowseImageFile(this, SELECT_PROFILE_PICTURE_BG);
}
break;
case R.id.IV_your_name_profile_picture_cancel:
diff --git a/app/src/main/java/com/kiminonawa/mydiary/main/topic/ITopic.java b/app/src/main/java/com/kiminonawa/mydiary/main/topic/ITopic.java
index 874d6b5..46593b4 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/main/topic/ITopic.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/main/topic/ITopic.java
@@ -1,6 +1,11 @@
package com.kiminonawa.mydiary.main.topic;
import android.support.annotation.DrawableRes;
+import android.support.annotation.IntDef;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
/**
* Created by daxia on 2016/10/17.
@@ -21,6 +26,11 @@ public interface ITopic {
*/
int TYPE_MEMO = 2;
+ @Retention(SOURCE)
+ @IntDef({TYPE_CONTACTS, TYPE_DIARY, TYPE_MEMO})
+ public @interface TopicType {
+ }
+
String getTitle();
/**
@@ -28,6 +38,7 @@ public interface ITopic {
*/
void setTitle(String title);
+ @TopicType
int getType();
long getId();
diff --git a/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java b/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java
index dafc39d..982ad1d 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/memo/MemoActivity.java
@@ -1,5 +1,6 @@
package com.kiminonawa.mydiary.memo;
+import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
@@ -13,6 +14,8 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.db.DBManager;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.ThemeManager;
import com.kiminonawa.mydiary.shared.ViewTools;
import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper;
@@ -109,6 +112,12 @@ public void onClick(View v) {
initTopicAdapter();
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
private void loadMemo(boolean openDB) {
memoList.clear();
if (openDB) {
diff --git a/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java b/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java
index 2ffec78..14fc894 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/security/PasswordActivity.java
@@ -1,5 +1,6 @@
package com.kiminonawa.mydiary.security;
+import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.os.Bundle;
@@ -13,6 +14,8 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.main.MainActivity;
import com.kiminonawa.mydiary.shared.Encryption;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.MyDiaryApplication;
import com.kiminonawa.mydiary.shared.SPFManager;
import com.kiminonawa.mydiary.shared.ThemeManager;
@@ -123,6 +126,12 @@ public void onClick(View v) {
initUI();
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
private void initUI() {
IV_password_number_1.requestFocus();
switch (currentMode) {
diff --git a/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java b/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java
index 3d7b64a..7c0a9cd 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/setting/SettingActivity.java
@@ -1,5 +1,6 @@
package com.kiminonawa.mydiary.setting;
+import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.drawable.ColorDrawable;
@@ -16,12 +17,17 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.shared.ColorTools;
-import com.kiminonawa.mydiary.shared.FileManager;
import com.kiminonawa.mydiary.shared.OldVersionHelper;
import com.kiminonawa.mydiary.shared.PermissionHelper;
import com.kiminonawa.mydiary.shared.SPFManager;
import com.kiminonawa.mydiary.shared.ScreenHelper;
import com.kiminonawa.mydiary.shared.ThemeManager;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
+import com.kiminonawa.mydiary.shared.language.LanguagerHelper;
+import com.kiminonawa.mydiary.shared.language.MyContextWrapper;
import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper;
import com.yalantis.ucrop.UCrop;
@@ -56,7 +62,7 @@ public class SettingActivity extends AppCompatActivity implements View.OnClickLi
/**
* File
*/
- private FileManager tempFileManager;
+ private IDir tempLocalDir;
private final static int SELECT_PROFILE_BG = 0;
/**
@@ -78,8 +84,8 @@ public void onCreate(Bundle savedInstanceState) {
themeManager = ThemeManager.getInstance();
//Create fileManager for get temp folder
- tempFileManager = new FileManager(this, FileManager.TEMP_DIR);
- tempFileManager.clearDir();
+ tempLocalDir = DirFactory.CreateDirByType(this, LocalDir.TEMP_DIR);
+ tempLocalDir.clearDir();
SP_setting_theme = (Spinner) findViewById(R.id.SP_setting_theme);
IV_setting_profile_bg = (ImageView) findViewById(R.id.IV_setting_profile_bg);
@@ -111,7 +117,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
UCrop.Options options = new UCrop.Options();
options.setToolbarColor(ThemeManager.getInstance().getThemeMainColor(this));
options.setStatusBarColor(ThemeManager.getInstance().getThemeDarkColor(this));
- UCrop.of(data.getData(), Uri.fromFile(new File(tempFileManager.getDir() + "/" + FileManager.createRandomFileName())))
+ UCrop.of(data.getData(), Uri.fromFile(new File(tempLocalDir.getDir() + "/" + MyDiaryFileUtils.createRandomFileName())))
.withMaxResultSize(bgWidth, bgHeight)
.withOptions(options)
.withAspectRatio(bgWidth, bgHeight)
@@ -125,7 +131,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
final Uri resultUri = UCrop.getOutput(data);
IV_setting_profile_bg.setImageBitmap(BitmapFactory.decodeFile(resultUri.getPath()));
- profileBgFileName = FileManager.getFileNameByUri(this, resultUri);
+ profileBgFileName = MyDiaryFileUtils.getFileNameByUri(this, resultUri);
isAddNewProfileBg = true;
} else {
Toast.makeText(this, getString(R.string.toast_crop_profile_banner_fail), Toast.LENGTH_LONG).show();
@@ -136,13 +142,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
+ @Override
+ protected void attachBaseContext(Context newBase) {
+ super.attachBaseContext(MyContextWrapper.wrap(newBase, LanguagerHelper.getLocaleLanguage(newBase)));
+ }
+
+
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
if (requestCode == PermissionHelper.REQUEST_WRITE_ES_PERMISSION) {
if (grantResults.length > 0
&& PermissionHelper.checkAllPermissionResult(grantResults)) {
- FileManager.startBrowseImageFile(this, SELECT_PROFILE_BG);
+ MyDiaryFileUtils.startBrowseImageFile(this, SELECT_PROFILE_BG);
} else {
PermissionHelper.showAddPhotoDialog(this);
}
@@ -256,7 +268,7 @@ public void onClick(View v) {
break;
case R.id.IV_setting_profile_bg:
if (PermissionHelper.checkPermission(this, REQUEST_WRITE_ES_PERMISSION)) {
- FileManager.startBrowseImageFile(this, SELECT_PROFILE_BG);
+ MyDiaryFileUtils.startBrowseImageFile(this, SELECT_PROFILE_BG);
}
break;
case R.id.But_setting_theme_default:
@@ -277,12 +289,12 @@ public void onClick(View v) {
if (isAddNewProfileBg) {
//For checking new profile bg is image or color.
boolean hasCustomProfileBannerBg = false;
- FileManager settingFM = new FileManager(this, FileManager.SETTING_DIR);
+ IDir settingDir = DirFactory.CreateDirByType(this, LocalDir.SETTING_DIR);
if (!"".equals(profileBgFileName)) {
try {
//Copy the profile into setting dir
- FileManager.copy(new File(tempFileManager.getDirAbsolutePath() + "/" + profileBgFileName),
- new File(settingFM.getDirAbsolutePath() + "/" + ThemeManager.CUSTOM_PROFILE_BANNER_BG_FILENAME));
+ MyDiaryFileUtils.copy(new File(tempLocalDir.getDirAbsolutePath() + "/" + profileBgFileName),
+ new File(settingDir.getDirAbsolutePath() + "/" + ThemeManager.CUSTOM_PROFILE_BANNER_BG_FILENAME));
hasCustomProfileBannerBg = true;
} catch (IOException e) {
e.printStackTrace();
@@ -290,7 +302,7 @@ public void onClick(View v) {
break;
}
} else {
- new File(settingFM.getDirAbsolutePath() + "/" + ThemeManager.CUSTOM_PROFILE_BANNER_BG_FILENAME).delete();
+ new File(settingDir.getDirAbsolutePath() + "/" + ThemeManager.CUSTOM_PROFILE_BANNER_BG_FILENAME).delete();
}
SPFManager.setCustomProfileBannerBg(this, hasCustomProfileBannerBg);
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java b/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java
index 15d2224..bd3746d 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/MyDiaryApplication.java
@@ -1,7 +1,6 @@
package com.kiminonawa.mydiary.shared;
import android.app.Application;
-import android.content.res.Configuration;
import android.support.v7.app.AppCompatDelegate;
import com.facebook.drawee.backends.pipeline.Fresco;
@@ -10,7 +9,6 @@
import com.facebook.imagepipeline.listener.RequestLoggingListener;
import java.util.HashSet;
-import java.util.Locale;
import java.util.Set;
/**
@@ -45,7 +43,6 @@ public void onCreate() {
//init Theme & language
initTheme();
- setLocaleLanguage();
}
@@ -54,49 +51,6 @@ private void initTheme() {
themeManager.setCurrentTheme(SPFManager.getTheme(this));
}
- private void setLocaleLanguage() {
- Locale locale;
- switch (SPFManager.getLocalLanguageCode(this)) {
- case 1:
- locale = Locale.ENGLISH;
- break;
- case 2:
- locale = Locale.JAPANESE;
- break;
- case 3:
- locale = Locale.TRADITIONAL_CHINESE;
- break;
- case 4:
- locale = Locale.SIMPLIFIED_CHINESE;
- break;
- case 5:
- locale = Locale.KOREAN;
- break;
- case 6:
- locale = new Locale("th", "");
- break;
- case 7:
- locale = Locale.FRENCH;
- break;
- case 8:
- locale = new Locale("es", "");
- break;
- // 0 = default = language of system
- default:
- locale = Locale.getDefault();
- break;
- }
- Locale.setDefault(locale);
- Configuration config = getBaseContext().getResources().getConfiguration();
- overwriteConfigurationLocale(config, locale);
- }
-
- private void overwriteConfigurationLocale(Configuration config, Locale locale) {
- //TODO FIX updateConfiguration on Android N
- config.setLocale(locale);
- getBaseContext().getResources()
- .updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
- }
public boolean isHasPassword() {
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/OldVersionHelper.java b/app/src/main/java/com/kiminonawa/mydiary/shared/OldVersionHelper.java
index 65cb26c..85b2b1b 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/shared/OldVersionHelper.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/OldVersionHelper.java
@@ -2,6 +2,11 @@
import android.content.Context;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
+
import org.apache.commons.io.FileUtils;
import java.io.File;
@@ -14,30 +19,30 @@ public class OldVersionHelper {
public static boolean Version17MoveTheDiaryIntoNewDir(Context context) throws Exception {
- FileManager rootFileManager = new FileManager(context, FileManager.ROOT_DIR);
- File[] dataFiles = rootFileManager.getDir().listFiles();
+ IDir rootLocalDir = DirFactory.CreateDirByType(context, LocalDir.ROOT_DIR);
+ File[] dataFiles = rootLocalDir.getDir().listFiles();
boolean moveIntoNewDir = false;
//router all dir first
for (int i = 0; i < dataFiles.length; i++) {
- if (FileManager.isNumeric(dataFiles[i].getName()) && dataFiles[i].listFiles().length > 0) {
+ if (MyDiaryFileUtils.isNumeric(dataFiles[i].getName()) && dataFiles[i].listFiles().length > 0) {
moveIntoNewDir = true;
break;
}
}
//If the numeric dir is exist , move it
if (moveIntoNewDir) {
- FileManager diaryFM = new FileManager(context, FileManager.DIARY_ROOT_DIR);
- File destDir = diaryFM.getDir();
+ IDir diaryDir = DirFactory.CreateDirByType(context, LocalDir.DIARY_ROOT_DIR);
+ File destDir = diaryDir.getDir();
FileUtils.deleteDirectory(destDir);
for (int i = 0; i < dataFiles.length; i++) {
- if (FileManager.isNumeric(dataFiles[i].getName())) {
+ if (MyDiaryFileUtils.isNumeric(dataFiles[i].getName())) {
FileUtils.moveDirectoryToDirectory(dataFiles[i],
- new FileManager(context, FileManager.DIARY_ROOT_DIR).getDir()
+ DirFactory.CreateDirByType(context, LocalDir.DIARY_ROOT_DIR).getDir()
, true);
}
}
//Remove the diary/temp/
- FileUtils.deleteDirectory(new File(diaryFM.getDirAbsolutePath() + "/temp"));
+ FileUtils.deleteDirectory(new File(diaryDir.getDirAbsolutePath() + "/temp"));
}
return moveIntoNewDir;
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java b/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java
index f0bf95e..0c43744 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/ScreenHelper.java
@@ -6,11 +6,10 @@
import android.content.res.Resources;
import android.os.Build;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.util.TypedValue;
import android.view.View;
-import java.text.DecimalFormat;
-
/**
* Created by daxia on 2016/9/23.
*/
@@ -21,8 +20,8 @@ public class ScreenHelper {
public static float getScreenRatio(Activity activity) {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- DecimalFormat mDecimalFormat = new DecimalFormat("#.##");
- float ScreenRatio = Float.valueOf(mDecimalFormat.format(metrics.heightPixels / metrics.widthPixels));
+ float ScreenRatio = (float) metrics.heightPixels / (float) metrics.widthPixels;
+ Log.e("Test", "screenRation = " + ScreenRatio);
return ScreenRatio;
}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/ThemeManager.java b/app/src/main/java/com/kiminonawa/mydiary/shared/ThemeManager.java
index 2cbbee9..7ba0cf6 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/shared/ThemeManager.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/ThemeManager.java
@@ -13,6 +13,9 @@
import com.kiminonawa.mydiary.R;
import com.kiminonawa.mydiary.main.topic.ITopic;
+import com.kiminonawa.mydiary.shared.file.DirFactory;
+import com.kiminonawa.mydiary.shared.file.IDir;
+import com.kiminonawa.mydiary.shared.file.LocalDir;
import com.kiminonawa.mydiary.shared.statusbar.ChinaPhoneHelper;
import java.io.File;
@@ -102,8 +105,8 @@ public Drawable getProfileBgDrawable(Context context) {
bgDrawable = ViewTools.getDrawable(context, R.drawable.profile_theme_bg_mitsuha);
break;
default:
- FileManager settingFM = new FileManager(context, FileManager.SETTING_DIR);
- File profileBgFile = new File(settingFM.getDirAbsolutePath()
+ IDir settingDir = DirFactory.CreateDirByType(context, LocalDir.SETTING_DIR);
+ File profileBgFile = new File(settingDir.getDirAbsolutePath()
+ "/" + CUSTOM_PROFILE_BANNER_BG_FILENAME);
if (profileBgFile.exists()) {
bgDrawable = Drawable.createFromPath(profileBgFile.getAbsolutePath());
@@ -118,8 +121,8 @@ public Drawable getProfileBgDrawable(Context context) {
public Drawable getProfilePictureDrawable(Context context) {
Drawable pictureDrawable;
try {
- FileManager settingFM= new FileManager(context, FileManager.SETTING_DIR);
- File pictureFile = new File(settingFM.getDirAbsolutePath()
+ IDir settingDir = DirFactory.CreateDirByType(context, LocalDir.SETTING_DIR);
+ File pictureFile = new File(settingDir.getDirAbsolutePath()
+ "/" + CUSTOM_PROFILE_PICTURE_FILENAME);
if (pictureFile.exists()) {
pictureDrawable = Drawable.createFromPath(pictureFile.getAbsolutePath());
@@ -173,9 +176,9 @@ public Drawable getTopicBgDrawable(Context context, long topicId, int topicType)
public Drawable getEntriesBgDrawable(Context context, long topicId) {
Drawable bgDrawable;
- FileManager diaryFM = new FileManager(context, FileManager.DIARY_ROOT_DIR);
+ IDir diaryDir = DirFactory.CreateDirByType(context, LocalDir.DIARY_ROOT_DIR);
File entriesBg = new File(
- diaryFM.getDirAbsolutePath()
+ diaryDir.getDirAbsolutePath()
+ "/" + topicId
+ "/" + CUSTOM_TOPIC_BG_FILENAME);
if (entriesBg.exists()) {
@@ -198,9 +201,9 @@ public Drawable getEntriesBgDrawable(Context context, long topicId) {
public Drawable getMemoBgDrawable(Context context, long topicId) {
Drawable bgDrawable;
- FileManager memoFM = new FileManager(context, FileManager.MEMO_ROOT_DIR);
+ IDir memoDir = DirFactory.CreateDirByType(context, LocalDir.MEMO_ROOT_DIR);
File memoBg = new File(
- memoFM.getDirAbsolutePath()
+ memoDir.getDirAbsolutePath()
+ "/" + topicId
+ "/" + CUSTOM_TOPIC_BG_FILENAME);
if (memoBg.exists()) {
@@ -223,9 +226,9 @@ public Drawable getMemoBgDrawable(Context context, long topicId) {
public Drawable getContactsBgDrawable(Context context, long topicId) {
Drawable bgDrawable;
- FileManager contactsFM = new FileManager(context, FileManager.CONTACTS_ROOT_DIR);
+ IDir contactsDir = DirFactory.CreateDirByType(context, LocalDir.CONTACTS_ROOT_DIR);
File contactsBg = new File(
- contactsFM.getDirAbsolutePath()
+ contactsDir.getDirAbsolutePath()
+ "/" + topicId
+ "/" + CUSTOM_TOPIC_BG_FILENAME);
if (contactsBg.exists()) {
@@ -426,24 +429,24 @@ public File getTopicBgSavePathFile(Context context, long topicId, int topicType)
File outputFile;
switch (topicType) {
case ITopic.TYPE_MEMO:
- FileManager memoFM = new FileManager(context, FileManager.MEMO_ROOT_DIR);
+ IDir memoDir = DirFactory.CreateDirByType(context, LocalDir.MEMO_ROOT_DIR);
outputFile = new File(
- memoFM.getDirAbsolutePath()
+ memoDir.getDirAbsolutePath()
+ "/" + topicId
+ "/" + ThemeManager.CUSTOM_TOPIC_BG_FILENAME);
break;
case ITopic.TYPE_CONTACTS:
- FileManager contactsFM = new FileManager(context, FileManager.CONTACTS_ROOT_DIR);
+ IDir contactsDir = DirFactory.CreateDirByType(context, LocalDir.CONTACTS_ROOT_DIR);
outputFile = new File(
- contactsFM.getDirAbsolutePath()
+ contactsDir.getDirAbsolutePath()
+ "/" + topicId
+ "/" + ThemeManager.CUSTOM_TOPIC_BG_FILENAME);
break;
//TYPE_DIARY
default:
- FileManager diaryFM = new FileManager(context, FileManager.DIARY_ROOT_DIR);
+ IDir diaryDir = DirFactory.CreateDirByType(context, LocalDir.DIARY_ROOT_DIR);
outputFile = new File(
- diaryFM.getDirAbsolutePath()
+ diaryDir.getDirAbsolutePath()
+ "/" + topicId
+ "/" + ThemeManager.CUSTOM_TOPIC_BG_FILENAME);
break;
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java b/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java
index 62663bc..3b960d8 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/ViewTools.java
@@ -5,7 +5,6 @@
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.DrawableRes;
-import android.support.v4.view.ViewCompat;
import android.view.View;
import android.widget.ScrollView;
@@ -47,8 +46,8 @@ public static void setScrollBarColor(Context context, ScrollView scrollView) {
}
}
public static boolean hitTest(View v, int x, int y) {
- final int tx = (int) (ViewCompat.getTranslationX(v) + 0.5f);
- final int ty = (int) (ViewCompat.getTranslationY(v) + 0.5f);
+ final int tx = (int) (v.getTranslationX() + 0.5f);
+ final int ty = (int) (v.getTranslationY() + 0.5f);
final int left = v.getLeft() + tx;
final int right = v.getRight() + tx;
final int top = v.getTop() + ty;
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/file/DirFactory.java b/app/src/main/java/com/kiminonawa/mydiary/shared/file/DirFactory.java
new file mode 100644
index 0000000..b35bb53
--- /dev/null
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/file/DirFactory.java
@@ -0,0 +1,110 @@
+package com.kiminonawa.mydiary.shared.file;
+
+import android.content.Context;
+
+import com.kiminonawa.mydiary.main.topic.ITopic;
+
+/**
+ * Created by daxia on 2018/2/8.
+ */
+
+public class DirFactory {
+
+ /**
+ * The path is :
+ * 1.setting , topic bg & profile photo temp
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/temp
+ * 2.diary edit temp
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/diary/editCache
+ * 3.diary saved
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/diary/TOPIC_ID/DIARY_ID/
+ * 4.memo path
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/memo/TOPIC_ID/
+ * 5.contacts path
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/contacts/TOPIC_ID/
+ * 6.Setting path
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/setting/
+ * 7.Backup temp path
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/backup/
+ */
+ private final static String TEMP_DIR_STR = "temp/";
+ private final static String DIARY_ROOT_DIR_STR = "diary/";
+ private final static String MEMO_ROOT_DIR_STR = "memo/";
+ private final static String CONTACTS_ROOT_DIR_STR = "contacts/";
+ private final static String EDIT_CACHE_DIARY_DIR_STR = "diary/editCache/";
+ private final static String SETTING_DIR_STR = "setting/";
+ private final static String BACKUP_DIR_STR = "backup/";
+
+ public static IDir CreateDirByType(Context context, int dirType) {
+ IDir dir = null;
+ switch (dirType) {
+ case IDir.ROOT_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(""));
+ break;
+ case IDir.TEMP_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(TEMP_DIR_STR));
+ break;
+ case IDir.DIARY_ROOT_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(DIARY_ROOT_DIR_STR));
+ break;
+ case IDir.MEMO_ROOT_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(MEMO_ROOT_DIR_STR));
+ break;
+ case IDir.CONTACTS_ROOT_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(CONTACTS_ROOT_DIR_STR));
+ break;
+ case IDir.DIARY_EDIT_CACHE_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(EDIT_CACHE_DIARY_DIR_STR));
+ break;
+ case IDir.SETTING_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(SETTING_DIR_STR));
+ break;
+ case IDir.BACKUP_DIR:
+ dir = new LocalDir(context.getExternalFilesDir(BACKUP_DIR_STR));
+ break;
+ default:
+ dir = null;
+ break;
+ }
+ return dir;
+ }
+
+ /**
+ * Create diary dir
+ */
+ public static IDir CreateDiaryDir(Context context, long topicId, long diaryId) {
+ return new LocalDir(context.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + topicId + "/" + diaryId + "/"));
+ }
+
+ /**
+ * Create diary temp file manager for auto save
+ * /sdcard/Android/data/com.kiminonawa.mydiary/files/diary/TOPIC_ID/temp
+ */
+ public static IDir CreateDiaryAutoSaveDir(Context context, long diaryTopicId) {
+ return new LocalDir(context.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + diaryTopicId + "/temp/"));
+ }
+
+ /**
+ * Create topic dir file manager for delete
+ */
+ public static IDir CreateTopicDir(Context context, @ITopic.TopicType int topicType, long topicId) {
+ IDir dir = null;
+ switch (topicType) {
+ case ITopic.TYPE_MEMO:
+ dir = new LocalDir(context.getExternalFilesDir(MEMO_ROOT_DIR_STR + "/" + topicId + "/"));
+ break;
+ case ITopic.TYPE_CONTACTS:
+ dir = new LocalDir(context.getExternalFilesDir(CONTACTS_ROOT_DIR_STR + "/" + topicId + "/"));
+ break;
+ case ITopic.TYPE_DIARY:
+ dir = new LocalDir(context.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + topicId + "/"));
+ break;
+ default:
+ dir = null;
+ break;
+ }
+ return dir;
+ }
+
+
+}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/file/IDir.java b/app/src/main/java/com/kiminonawa/mydiary/shared/file/IDir.java
new file mode 100644
index 0000000..1cda0d3
--- /dev/null
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/file/IDir.java
@@ -0,0 +1,26 @@
+package com.kiminonawa.mydiary.shared.file;
+
+import java.io.File;
+
+/**
+ * Created by daxia on 2018/2/8.
+ */
+
+public interface IDir {
+
+ int ROOT_DIR = 0;
+ int TEMP_DIR = 1;
+ int DIARY_EDIT_CACHE_DIR = 2;
+ int DIARY_ROOT_DIR = 3;
+ int MEMO_ROOT_DIR = 4;
+ int CONTACTS_ROOT_DIR = 5;
+ int SETTING_DIR = 6;
+ int BACKUP_DIR = 7;
+
+ File getDir();
+
+ String getDirAbsolutePath();
+
+ void clearDir();
+
+}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/file/LocalDir.java b/app/src/main/java/com/kiminonawa/mydiary/shared/file/LocalDir.java
new file mode 100644
index 0000000..d1a0303
--- /dev/null
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/file/LocalDir.java
@@ -0,0 +1,72 @@
+package com.kiminonawa.mydiary.shared.file;
+
+import android.util.Log;
+
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+
+/**
+ * Created by daxia on 2016/11/18.
+ */
+
+//
+// _oo0oo_
+// o8888888o
+// 88" . "88
+// (| -_- |)
+// 0\ = /0
+// ___/`---'\___
+// .' \\| |// '.
+// / \\||| : |||// \
+// / _||||| -:- |||||- \
+// | | \\\ - /// | |
+// | \_| ''\---/'' |_/ |
+// \ .-\__ '-' ___/-. /
+// ___'. .' /--.--\ `. .'___
+// ."" '< `.___\_<|>_/___.' >' "".
+// | | : `- \`.;`\ _ /`;.`/ - ` : | |
+// \ \ `_. \_ __\ /__ _/ .-` / /
+// =====`-.____`.___ \_____/___.-`___.-'=====
+// `=---='
+//
+//
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// 佛祖保佑 永無Bug
+
+public class LocalDir implements IDir {
+
+ private static final String TAG = "LocalDir";
+
+ private File fileDir;
+
+ public LocalDir(File dir) {
+ this.fileDir = dir;
+ }
+
+
+ public File getDir() {
+ return fileDir;
+ }
+
+ public String getDirAbsolutePath() {
+ return fileDir.getAbsolutePath();
+ }
+
+ public void clearDir() {
+ try {
+ if (fileDir != null && fileDir.isDirectory()) {
+ FileUtils.cleanDirectory(fileDir);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "ClearDir file", e);
+ }
+ }
+
+
+
+
+
+
+}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/FileManager.java b/app/src/main/java/com/kiminonawa/mydiary/shared/file/MyDiaryFileUtils.java
similarity index 59%
rename from app/src/main/java/com/kiminonawa/mydiary/shared/FileManager.java
rename to app/src/main/java/com/kiminonawa/mydiary/shared/file/MyDiaryFileUtils.java
index 27acb2b..85ddebb 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/shared/FileManager.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/file/MyDiaryFileUtils.java
@@ -1,4 +1,4 @@
-package com.kiminonawa.mydiary.shared;
+package com.kiminonawa.mydiary.shared.file;
import android.annotation.TargetApi;
import android.app.Activity;
@@ -16,10 +16,6 @@
import android.support.v4.app.Fragment;
import android.util.Log;
-import com.kiminonawa.mydiary.main.topic.ITopic;
-
-import org.apache.commons.io.FileUtils;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -31,169 +27,16 @@
import java.util.UUID;
/**
- * Created by daxia on 2016/11/18.
+ * Created by daxia on 2018/2/8.
*/
-//
-// _oo0oo_
-// o8888888o
-// 88" . "88
-// (| -_- |)
-// 0\ = /0
-// ___/`---'\___
-// .' \\| |// '.
-// / \\||| : |||// \
-// / _||||| -:- |||||- \
-// | | \\\ - /// | |
-// | \_| ''\---/'' |_/ |
-// \ .-\__ '-' ___/-. /
-// ___'. .' /--.--\ `. .'___
-// ."" '< `.___\_<|>_/___.' >' "".
-// | | : `- \`.;`\ _ /`;.`/ - ` : | |
-// \ \ `_. \_ __\ /__ _/ .-` / /
-// =====`-.____`.___ \_____/___.-`___.-'=====
-// `=---='
-//
-//
-// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-//
-// 佛祖保佑 永無Bug
-
-public class FileManager {
-
- private static final String TAG = "FileManager";
+public class MyDiaryFileUtils {
+
+ private static final String TAG = "MyDiaryFileUtils";
//Min free space is 50 MB
public static final int MIN_FREE_SPACE = 50;
public static final String FILE_HEADER = "file://";
- public final static int ROOT_DIR = 0;
- public final static int TEMP_DIR = 1;
- public final static int DIARY_EDIT_CACHE_DIR = 2;
- public final static int DIARY_ROOT_DIR = 3;
- public final static int MEMO_ROOT_DIR = 4;
- public final static int CONTACTS_ROOT_DIR = 5;
- public final static int SETTING_DIR = 6;
- public final static int BACKUP_DIR = 7;
-
- /**
- * The path is :
- * 1.setting , topic bg & profile photo temp
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/temp
- * 2.diary edit temp
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/diary/editCache
- * 3.diary saved
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/diary/TOPIC_ID/DIARY_ID/
- * 4.memo path
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/memo/TOPIC_ID/
- * 5.contacts path
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/contacts/TOPIC_ID/
- * 6.Setting path
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/setting/
- * 7.Backup temp path
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/backup/
- */
- private File fileDir;
- private Context mContext;
- private final static String TEMP_DIR_STR = "temp/";
- private final static String DIARY_ROOT_DIR_STR = "diary/";
- private final static String MEMO_ROOT_DIR_STR = "memo/";
- private final static String CONTACTS_ROOT_DIR_STR = "contacts/";
- private final static String EDIT_CACHE_DIARY_DIR_STR = "diary/editCache/";
- private final static String SETTING_DIR_STR = "setting/";
- private final static String BACKUP_DIR_STR = "backup/";
-
- /**
- * Create trem dir file manager
- *
- * @param context
- */
- public FileManager(Context context, int dir) {
- this.mContext = context;
- switch (dir) {
- case ROOT_DIR:
- this.fileDir = mContext.getExternalFilesDir("");
- break;
- case TEMP_DIR:
- this.fileDir = mContext.getExternalFilesDir(TEMP_DIR_STR);
- break;
- case DIARY_ROOT_DIR:
- this.fileDir = mContext.getExternalFilesDir(DIARY_ROOT_DIR_STR);
- break;
- case MEMO_ROOT_DIR:
- this.fileDir = mContext.getExternalFilesDir(MEMO_ROOT_DIR_STR);
- break;
- case CONTACTS_ROOT_DIR:
- this.fileDir = mContext.getExternalFilesDir(CONTACTS_ROOT_DIR_STR);
- break;
- case DIARY_EDIT_CACHE_DIR:
- this.fileDir = mContext.getExternalFilesDir(EDIT_CACHE_DIARY_DIR_STR);
- break;
- case SETTING_DIR:
- this.fileDir = mContext.getExternalFilesDir(SETTING_DIR_STR);
- break;
- case BACKUP_DIR:
- this.fileDir = mContext.getExternalFilesDir(BACKUP_DIR_STR);
- break;
- }
- }
-
- /**
- * Create diary dir file manager
- */
- public FileManager(Context context, long topicId, long diaryId) {
- this.mContext = context;
- this.fileDir = mContext.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + topicId + "/" + diaryId + "/");
- }
-
- /**
- * Create diary temp file manager for auto save
- * /sdcard/Android/data/com.kiminonawa.mydiary/files/diary/TOPIC_ID/temp
- */
- public FileManager(Context context, long diaryTopicId) {
- this.mContext = context;
- this.fileDir = mContext.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + diaryTopicId + "/temp/");
- }
-
- /**
- * Create topic dir file manager for delete
- */
- public FileManager(Context context, int topicType, long topicId) {
- this.mContext = context;
- switch (topicType) {
- case ITopic.TYPE_MEMO:
- this.fileDir = mContext.getExternalFilesDir(MEMO_ROOT_DIR_STR + "/" + topicId + "/");
-
- break;
- case ITopic.TYPE_CONTACTS:
- this.fileDir = mContext.getExternalFilesDir(CONTACTS_ROOT_DIR_STR + "/" + topicId + "/");
-
- break;
- case ITopic.TYPE_DIARY:
- this.fileDir = mContext.getExternalFilesDir(DIARY_ROOT_DIR_STR + "/" + topicId + "/");
-
- break;
- }
- }
-
-
- public File getDir() {
- return fileDir;
- }
-
- public String getDirAbsolutePath() {
- return fileDir.getAbsolutePath();
- }
-
- public void clearDir() {
- File[] fList = fileDir.listFiles();
- if (fList != null && fileDir.isDirectory()) {
- try {
- FileUtils.cleanDirectory(fileDir);
- } catch (IOException e) {
- Log.e(TAG, "ClearDir file", e);
- }
- }
- }
public static String getFileNameByUri(Context context, Uri uri) {
String displayName = "";
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/language/LanguagerHelper.java b/app/src/main/java/com/kiminonawa/mydiary/shared/language/LanguagerHelper.java
new file mode 100644
index 0000000..0054dad
--- /dev/null
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/language/LanguagerHelper.java
@@ -0,0 +1,57 @@
+package com.kiminonawa.mydiary.shared.language;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Build;
+
+import com.kiminonawa.mydiary.shared.SPFManager;
+
+import java.util.Locale;
+
+/**
+ * Created by daxia on 2017/5/15.
+ */
+
+public class LanguagerHelper {
+
+
+ public static Locale getLocaleLanguage(Context context) {
+ Locale locale;
+ switch (SPFManager.getLocalLanguageCode(context)) {
+ case 1:
+ locale = Locale.ENGLISH;
+ break;
+ case 2:
+ locale = Locale.JAPANESE;
+ break;
+ case 3:
+ locale = Locale.TRADITIONAL_CHINESE;
+ break;
+ case 4:
+ locale = Locale.SIMPLIFIED_CHINESE;
+ break;
+ case 5:
+ locale = Locale.KOREAN;
+ break;
+ case 6:
+ locale = new Locale("th", "");
+ break;
+ case 7:
+ locale = Locale.FRENCH;
+ break;
+ case 8:
+ locale = new Locale("es", "");
+ break;
+ // 0 = default = language of system
+ default:
+ Configuration config = context.getResources().getConfiguration();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ locale = MyContextWrapper.getSystemLocale(config);
+ } else {
+ locale = MyContextWrapper.getSystemLocaleLegacy(config);
+ }
+ break;
+ }
+ return locale;
+ }
+}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/language/MyContextWrapper.java b/app/src/main/java/com/kiminonawa/mydiary/shared/language/MyContextWrapper.java
new file mode 100644
index 0000000..72fb3ca
--- /dev/null
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/language/MyContextWrapper.java
@@ -0,0 +1,57 @@
+package com.kiminonawa.mydiary.shared.language;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.res.Configuration;
+import android.os.Build;
+
+import java.util.Locale;
+
+/**
+ * Created by daxia on 2017/5/15.
+ */
+
+public class MyContextWrapper extends ContextWrapper {
+
+ public MyContextWrapper(Context base) {
+ super(base);
+ }
+
+ @SuppressWarnings("deprecation")
+ public static ContextWrapper wrap(Context context, Locale locale) {
+ Configuration config = context.getResources().getConfiguration();
+ Locale.setDefault(locale);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ setSystemLocale(config, locale);
+ } else {
+ setSystemLocaleLegacy(config, locale);
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ context = context.createConfigurationContext(config);
+ } else {
+ context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
+ }
+ return new MyContextWrapper(context);
+ }
+
+ @SuppressWarnings("deprecation")
+ public static Locale getSystemLocaleLegacy(Configuration config) {
+ return config.locale;
+ }
+
+ @TargetApi(Build.VERSION_CODES.N)
+ public static Locale getSystemLocale(Configuration config) {
+ return config.getLocales().get(0);
+ }
+
+ @SuppressWarnings("deprecation")
+ public static void setSystemLocaleLegacy(Configuration config, Locale locale) {
+ config.locale = locale;
+ }
+
+ @TargetApi(Build.VERSION_CODES.N)
+ public static void setSystemLocale(Configuration config, Locale locale) {
+ config.setLocale(locale);
+ }
+}
diff --git a/app/src/main/java/com/kiminonawa/mydiary/shared/photo/ExifUtil.java b/app/src/main/java/com/kiminonawa/mydiary/shared/photo/ExifUtil.java
index 82bce85..a2356bd 100644
--- a/app/src/main/java/com/kiminonawa/mydiary/shared/photo/ExifUtil.java
+++ b/app/src/main/java/com/kiminonawa/mydiary/shared/photo/ExifUtil.java
@@ -7,7 +7,7 @@
import android.media.ExifInterface;
import android.net.Uri;
-import com.kiminonawa.mydiary.shared.FileManager;
+import com.kiminonawa.mydiary.shared.file.MyDiaryFileUtils;
import java.io.IOException;
@@ -31,7 +31,7 @@ public static Bitmap rotateBitmap(String src, Bitmap bitmap) {
}
public static Bitmap rotateBitmap(Context context, Uri uri, Bitmap bitmap) {
- String path = FileManager.getRealPathFromURI(context, uri);
+ String path = MyDiaryFileUtils.getRealPathFromURI(context, uri);
if (path == null) {
return bitmap;
}
diff --git a/app/src/main/res/layout/fragment_diary.xml b/app/src/main/res/layout/fragment_diary.xml
index 83a28cb..2512027 100644
--- a/app/src/main/res/layout/fragment_diary.xml
+++ b/app/src/main/res/layout/fragment_diary.xml
@@ -71,9 +71,7 @@
+ android:layout_height="match_parent">
+
+
+ android:layout_marginLeft="5dp"
+ android:layout_toRightOf="@id/View_drag_handle" />
Actualizaciónes
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -fix bug on editing diary\n\n
+ **0.3.0.170424_1_A\n
-Fix bug\n
-Support simple photo function\n
-Modify layout\n\n
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index 9e1f1aa..9c1e04c 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -3,7 +3,9 @@
Mises à jour
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -fix bug on editing diary\n\n
+ **0.3.0.170424_1_A\n
-Fix bug\n
-Support simple photo function\n
-Modify layout\n\n
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 09cb3ce..bfe84e4 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -3,7 +3,9 @@
アップデート情報
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -fix bug on editing diary\n\n
+ **0.3.0.170424_1_A\n
-Fix bug\n
-Support simple photo function\n
-Modify layout\n\n
diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml
index 16bcb88..9568405 100644
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -3,7 +3,9 @@
업데이트 정보
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -fix bug on editing diary\n\n
+ **0.3.0.170424_1_A\n
-Fix bug\n
-Support simple photo function\n
-Modify layout\n\n
diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml
index 202d065..74a94dd 100644
--- a/app/src/main/res/values-th/strings.xml
+++ b/app/src/main/res/values-th/strings.xml
@@ -3,7 +3,9 @@
ข้อมูลการอัพเดท
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -fix bug on editing diary\n\n
+ **0.3.0.170424_1_A\n
-Fix bug\n
-Support simple photo function\n
-Modify layout\n\n
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index b75ee92..b08bcc5 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -3,7 +3,9 @@
更新日志
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -修复编辑日记bug\n\n
+ **0.3.0.170424_1_A\n
-修复bug\n
-支援简单的照片功能\n
-调整画面\n\n
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 9d8c525..6393ed2 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -3,7 +3,9 @@
更新情報
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -修復編輯日記bug\n\n
+ **0.3.0.170424_1_A\n
-修復bug\n
-支援簡易的照片功能\n
-調整畫面\n\n
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f231dd2..f94d437 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -4,7 +4,9 @@
Release note
- **0.3.0.170424_1_A\n
+ **0.3.0.170509_1_AH\n
+ -fix bug on editing diary\n\n
+ **0.3.0.170424_1_A\n
-Fix bug\n
-Support simple photo function\n
-Modify layout\n\n
diff --git a/build.gradle b/build.gradle
index 1c3e860..7e01a0a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.1'
+ classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -15,7 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
- maven { url 'https://jitpack.io' }
+ google()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index ad53bbf..92e27ee 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
diff --git a/gradlew b/gradlew
old mode 100755
new mode 100644
diff --git a/lib_module/freso/gestures/build.gradle b/lib_module/freso/gestures/build.gradle
index 5377e4e..1236c81 100644
--- a/lib_module/freso/gestures/build.gradle
+++ b/lib_module/freso/gestures/build.gradle
@@ -11,8 +11,8 @@ dependencies {
}
android {
- compileSdkVersion 25
- buildToolsVersion '25.0.1'
+ compileSdkVersion 26
+ buildToolsVersion '26.0.2'
packagingOptions {
exclude 'NOTICE'
diff --git a/lib_module/freso/zoomable/build.gradle b/lib_module/freso/zoomable/build.gradle
index 4f0334d..bdff656 100644
--- a/lib_module/freso/zoomable/build.gradle
+++ b/lib_module/freso/zoomable/build.gradle
@@ -12,8 +12,8 @@ dependencies {
}
android {
- compileSdkVersion 25
- buildToolsVersion '25.0.1'
+ compileSdkVersion 26
+ buildToolsVersion '26.0.2'
packagingOptions {
exclude 'NOTICE'