diff --git a/app/src/main/java/com/seafile/seadroid2/SeadroidApplication.java b/app/src/main/java/com/seafile/seadroid2/SeadroidApplication.java index 4f119846f..701d73a7a 100644 --- a/app/src/main/java/com/seafile/seadroid2/SeadroidApplication.java +++ b/app/src/main/java/com/seafile/seadroid2/SeadroidApplication.java @@ -15,11 +15,14 @@ import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.nostra13.universalimageloader.core.assist.QueueProcessingType; import com.seafile.seadroid2.avatar.AuthImageDownloader; +import com.seafile.seadroid2.cameraupload.GalleryBucketUtils; import com.seafile.seadroid2.data.StorageManager; import com.seafile.seadroid2.gesturelock.AppLockManager; import com.seafile.seadroid2.ui.CustomNotificationBuilder; import java.io.File; +import java.util.ArrayList; +import java.util.List; public class SeadroidApplication extends Application { private static Context context; @@ -27,6 +30,7 @@ public class SeadroidApplication extends Application { private int totalNumber; private int scanUploadStatus; private static SeadroidApplication instance; + private List buckets = new ArrayList<>(); public void onCreate() { super.onCreate(); @@ -122,4 +126,11 @@ public int getScanUploadStatus() { return scanUploadStatus; } + public void setBuckets(List buckets) { + this.buckets = buckets; + } + + public List getBuckets() { + return buckets; + } } diff --git a/app/src/main/java/com/seafile/seadroid2/SettingsManager.java b/app/src/main/java/com/seafile/seadroid2/SettingsManager.java index 73da8badb..13694f65b 100644 --- a/app/src/main/java/com/seafile/seadroid2/SettingsManager.java +++ b/app/src/main/java/com/seafile/seadroid2/SettingsManager.java @@ -70,9 +70,9 @@ private SettingsManager() { public static final String CAMERA_UPLOAD_ADVANCED_CATEGORY_KEY = "category_camera_upload_advanced_key"; public static final String CAMERA_UPLOAD_ALLOW_DATA_PLAN_SWITCH_KEY = "allow_data_plan_switch_key"; public static final String CAMERA_UPLOAD_ALLOW_VIDEOS_SWITCH_KEY = "allow_videos_upload_switch_key"; - public static final String CAMERA_UPLOAD_BUCKETS_KEY = "camera_upload_buckets_key"; +// public static final String CAMERA_UPLOAD_BUCKETS_KEY = "camera_upload_buckets_key"; public static final String CAMERA_UPLOAD_CATEGORY_KEY = "category_camera_upload_key"; - public static final String CAMERA_UPLOAD_CUSTOM_BUCKETS_KEY = "camera_upload_buckets_switch_key"; +// public static final String CAMERA_UPLOAD_CUSTOM_BUCKETS_KEY = "camera_upload_buckets_switch_key"; public static final String SHARED_PREF_CAMERA_UPLOAD_BUCKETS = PKG + ".camera.buckets"; //contacts public static final String CONTACTS_UPLOAD_CATEGORY_KEY = "category_contacts_upload_key"; diff --git a/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java b/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java index 4bdbd5941..c2ac8daaa 100644 --- a/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java +++ b/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraSyncAdapter.java @@ -11,6 +11,7 @@ import android.content.ServiceConnection; import android.content.SyncResult; import android.database.Cursor; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.IBinder; @@ -174,7 +175,6 @@ private void createDirectories(DataManager dataManager) throws SeafException { // create base directory forceCreateDirectory(dataManager, "/", BASE_DIR); - for (GalleryBucketUtils.Bucket bucket : buckets) { // the user has selected specific buckets: only create directories for these @@ -187,7 +187,6 @@ private void createDirectories(DataManager dataManager) throws SeafException { continue; forceCreateDirectory(dataManager, BASE_DIR, bucket.name); - // update our cache for that server. we will use it later dataManager.getDirentsFromServer(targetRepoId, Utils.pathJoin(BASE_DIR, bucket.name)); } @@ -370,7 +369,7 @@ public void onPerformSync(android.accounts.Account account, } private void uploadImages(SyncResult syncResult, DataManager dataManager) throws SeafException, InterruptedException { - + Utils.utilsLogInfo(true, "========Starting to upload images..."); // Log.d(DEBUG_TAG, "Starting to upload images..."); if (isCancelled()) @@ -408,14 +407,16 @@ private void uploadImages(SyncResult syncResult, DataManager dataManager) throws try { if (cursor == null) { Log.e(DEBUG_TAG, "ContentResolver query failed!"); + Utils.utilsLogInfo(true,"===ContentResolver query failed!"); return; } // Log.d(DEBUG_TAG, "i see " + cursor.getCount() + " new images."); + Utils.utilsLogInfo(true, "===i see " + cursor.getCount() + " images."); if (cursor.getCount() > 0) { // create directories for media buckets createDirectories(dataManager); - iterateCursor(syncResult, dataManager, cursor); + iterateCursor(syncResult, dataManager, cursor, MediaStore.Images.Media._ID); if (isCancelled()) return; @@ -428,7 +429,7 @@ private void uploadImages(SyncResult syncResult, DataManager dataManager) throws } private void uploadVideos(SyncResult syncResult, DataManager dataManager) throws SeafException, InterruptedException { - + Utils.utilsLogInfo(true,"Starting to upload videos..."); // Log.d(DEBUG_TAG, "Starting to upload videos..."); if (isCancelled()) @@ -449,7 +450,6 @@ private void uploadVideos(SyncResult syncResult, DataManager dataManager) throws String selection = MediaStore.Video.VideoColumns.BUCKET_ID + " IN " + varArgs(selectedBuckets.size()); // Log.d(DEBUG_TAG, "ContentResolver selection='"+selection+"' selectionArgs='"+Arrays.deepToString(selectionArgs)+"'"); - // fetch all new videos from the ContentProvider since our last sync Cursor cursor = contentResolver.query( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, @@ -466,14 +466,16 @@ private void uploadVideos(SyncResult syncResult, DataManager dataManager) throws try { if (cursor == null) { Log.e(DEBUG_TAG, "ContentResolver query failed!"); + Utils.utilsLogInfo(true,"====ContentResolver query failed!"); return; } // Log.d(DEBUG_TAG, "i see " + cursor.getCount() + " new videos."); + Utils.utilsLogInfo(true,"=====i see " + cursor.getCount() + " videos."); if (cursor.getCount() > 0) { // create directories for media buckets createDirectories(dataManager); - iterateCursor(syncResult, dataManager, cursor); + iterateCursor(syncResult, dataManager, cursor, MediaStore.Video.Media._ID); if (isCancelled()) return; @@ -500,28 +502,44 @@ private String varArgs(int count) { * @param cursor * @throws SeafException */ - private void iterateCursor(SyncResult syncResult, DataManager dataManager, Cursor cursor) throws SeafException, InterruptedException { + private void iterateCursor(SyncResult syncResult, DataManager dataManager, Cursor cursor, String mediaId) throws SeafException, InterruptedException { tasksInProgress.clear(); + File file; + Uri uri; + String id; // upload them one by one while (!isCancelled() && cursor.moveToNext()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + id = cursor.getString(cursor.getColumnIndexOrThrow(mediaId)); + if (MediaStore.Images.Media._ID.equals(mediaId)) { + uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); + } else { + uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id); + } + if (uri == null) { + syncResult.stats.numSkippedEntries++; + continue; + } + file = new File(Utils.getRealPathFromURI(SeadroidApplication.getAppContext(), uri, mediaId)); + } else { + int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); + if (cursor.getString(dataColumn) == null) { + syncResult.stats.numSkippedEntries++; + continue; + } + file = new File(cursor.getString(dataColumn)); - int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); - int bucketColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME); - - // some inconsistency in the Media Provider? Ignore and continue - if (cursor.getString(dataColumn) == null) { - syncResult.stats.numSkippedEntries++; - continue; } - - File file = new File(cursor.getString(dataColumn)); +// Utils.utilsLogInfo(true,"======iterateCursor"); + int bucketColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME); String bucketName = cursor.getString(bucketColumn); // local file does not exist. some inconsistency in the Media Provider? Ignore and continue if (!file.exists()) { // Log.d(DEBUG_TAG, "Skipping media "+file+" because it doesn't exist"); + Utils.utilsLogInfo(true, "=====Skipping media " + file + " because it doesn't exist"); syncResult.stats.numSkippedEntries++; continue; } @@ -529,17 +547,19 @@ private void iterateCursor(SyncResult syncResult, DataManager dataManager, Curso // Ignore all media by Seafile. We don't want to upload our own cached files. if (file.getAbsolutePath().startsWith(StorageManager.getInstance().getMediaDir().getAbsolutePath())) { // Log.d(DEBUG_TAG, "Skipping media "+file+" because it's part of the Seadroid cache"); + Utils.utilsLogInfo(true, "======Skipping media " + file + " because it's part of the Seadroid cache"); continue; } if (dbHelper.isUploaded(file)) { // Log.d(DEBUG_TAG, "Skipping media " + file + " because we have uploaded it in the past."); +// Utils.utilsLogInfo(true, "=====Skipping media " + file + " because we have uploaded it in the past."); continue; } uploadFile(dataManager, file, bucketName); } - + Utils.utilsLogInfo(true,"=======waitForUploads==="); waitForUploads(); checkUploadResult(syncResult); } @@ -593,10 +613,11 @@ private void checkUploadResult(SyncResult syncResult) throws SeafException { private void uploadFile(DataManager dataManager, File file, String bucketName) throws SeafException { String serverPath = Utils.pathJoin(BASE_DIR, bucketName); - + Utils.utilsLogInfo(true,"=======uploadFile==="); List list = dataManager.getCachedDirents(targetRepoId, serverPath); if (list == null) { Log.e(DEBUG_TAG, "Seadroid dirent cache is empty in uploadFile. Should not happen, aborting."); + Utils.utilsLogInfo(true,"=======Seadroid dirent cache is empty in uploadFile. Should not happen, aborting."); // the dirents were supposed to be refreshed in createDirectories() // something changed, abort. throw SeafException.unknownException; @@ -615,12 +636,14 @@ private void uploadFile(DataManager dataManager, File file, String bucketName) t for (SeafDirent dirent : list) { if (pattern.matcher(dirent.name).matches() && dirent.size == file.length()) { // Log.d(DEBUG_TAG, "File " + file.getName() + " in bucket " + bucketName + " already exists on the server. Skipping."); + Utils.utilsLogInfo(true,"====File " + file.getName() + " in bucket " + bucketName + " already exists on the server. Skipping."); dbHelper.markAsUploaded(file); return; } } // Log.d(DEBUG_TAG, "uploading file " + file.getName() + " to " + serverPath); + Utils.utilsLogInfo(true,"====uploading file " + file.getName() + " to " + serverPath); int taskID = txService.addUploadTask(dataManager.getAccount(), targetRepoId, targetRepoName, serverPath, file.getAbsolutePath(), false, false); tasksInProgress.add(taskID); diff --git a/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraUploadConfigActivity.java b/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraUploadConfigActivity.java index dc10c2aff..7fef5eb5c 100644 --- a/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraUploadConfigActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/cameraupload/CameraUploadConfigActivity.java @@ -8,6 +8,7 @@ import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.View; + import com.seafile.seadroid2.R; import com.seafile.seadroid2.SettingsManager; import com.seafile.seadroid2.account.Account; @@ -18,19 +19,20 @@ import com.seafile.seadroid2.util.SystemSwitchUtils; import com.viewpagerindicator.LinePageIndicator; -import java.util.List; +import java.util.ArrayList; /** * Camera upload configuration helper */ public class CameraUploadConfigActivity extends BaseActivity { - public static final String DEBUG_TAG = "CameraUploadConfigActivity"; + public String DEBUG_TAG = "CameraUploadConfigActivity"; private ViewPager mViewPager; private LinePageIndicator mIndicator; - private BucketsFragment mBucketsFragment; +// private BucketsFragment mBucketsFragment; private CloudLibraryFragment mCloudLibFragment; + private WhatToUploadFragment whatToUploadFragment; private SettingsManager sm; private SeafRepo mSeafRepo; private Account mAccount; @@ -60,7 +62,7 @@ public void onCreate(Bundle savedInstanceState) { FragmentManager fm = getSupportFragmentManager(); mViewPager.setAdapter(new CameraUploadConfigAdapter(fm)); - mViewPager.setOffscreenPageLimit(6); + mViewPager.setOffscreenPageLimit(5); mIndicator = (LinePageIndicator) findViewById(R.id.cuc_indicator); mIndicator.setViewPager(mViewPager); @@ -100,13 +102,13 @@ public void saveSettings() { if (isChooseBothPages || isChooseDirPage) { SettingsManager settingsManager = SettingsManager.instance(); - List selectedBuckets = mBucketsFragment.getSelectionFragment().getSelectedBuckets(); - if (mBucketsFragment.isAutoScanSelected()){ - selectedBuckets.clear(); - } +// List selectedBuckets = mBucketsFragment.getSelectionFragment().getSelectedBuckets(); +// if (mBucketsFragment.isAutoScanSelected()) { +// selectedBuckets.clear(); +// } // this is the only setting that is safed here. all other are returned to caller // and safed there... - settingsManager.setCameraUploadBucketList(selectedBuckets); + settingsManager.setCameraUploadBucketList(new ArrayList<>()); } Intent intent = new Intent(); @@ -164,16 +166,16 @@ public Fragment getItem(int position) { return position == 0 ? new CloudLibraryFragment() : null; } - if (isChooseDirPage) { - switch (position) { - case 0: - mBucketsFragment = new BucketsFragment(); - return mBucketsFragment; - default: - return null; - } - - } +// if (isChooseDirPage) { +// switch (position) { +// case 0: +// mBucketsFragment = new BucketsFragment(); +// return mBucketsFragment; +// default: +// return null; +// } +// +// } // Assign the appropriate screen to the fragment object, based on which screen is displayed. switch (position) { @@ -182,14 +184,15 @@ public Fragment getItem(int position) { case 1: return new HowToUploadFragment(); case 2: - return new WhatToUploadFragment(); + whatToUploadFragment = new WhatToUploadFragment(); + return whatToUploadFragment; +// case 3: +// mBucketsFragment = new BucketsFragment(); +// return mBucketsFragment; case 3: - mBucketsFragment = new BucketsFragment(); - return mBucketsFragment; - case 4: mCloudLibFragment = new CloudLibraryFragment(); return mCloudLibFragment; - case 5: + case 4: return new ReadyToScanFragment(); default: return null; @@ -201,7 +204,7 @@ public int getCount() { if (isChooseLibPage || isChooseDirPage) return 1; else - return 6; + return 5; } } diff --git a/app/src/main/java/com/seafile/seadroid2/cameraupload/GalleryBucketUtils.java b/app/src/main/java/com/seafile/seadroid2/cameraupload/GalleryBucketUtils.java index 2755bdab8..8925b5cf4 100644 --- a/app/src/main/java/com/seafile/seadroid2/cameraupload/GalleryBucketUtils.java +++ b/app/src/main/java/com/seafile/seadroid2/cameraupload/GalleryBucketUtils.java @@ -5,8 +5,6 @@ import android.net.Uri; import android.provider.MediaStore; -import com.seafile.seadroid2.data.StorageManager; - import java.util.ArrayList; import java.util.List; @@ -59,18 +57,15 @@ public static List getMediaBuckets(Context context) { private static List getVideoBuckets(Context context) { Uri images = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; String[] projection = new String[]{ + MediaStore.Video.Media._ID, MediaStore.Video.Media.BUCKET_ID, MediaStore.Video.Media.BUCKET_DISPLAY_NAME, - MediaStore.Video.Media.DATA }; - - String BUCKET_ORDER_BY = MediaStore.Video.Media.BUCKET_DISPLAY_NAME + " ASC"; - String BUCKET_GROUP_BY = "1) GROUP BY 1,(2"; Cursor cursor = context.getContentResolver().query(images, projection, // Which columns to return - BUCKET_GROUP_BY, // Which rows to return (all rows) + null, // Which rows to return (all rows) null, // Selection arguments (none) - BUCKET_ORDER_BY // Ordering + null // Ordering ); List buckets = new ArrayList(); @@ -82,7 +77,6 @@ private static List getVideoBuckets(Context context) { while (cursor.moveToNext()) { int bucketIdColumnIndex = cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_ID); int bucketColumnIndex = cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME); - int dataColumnIndex = cursor.getColumnIndex(MediaStore.Video.Media.DATA); Bucket b = new Bucket(); b.id = cursor.getString(bucketIdColumnIndex); b.name = cursor.getString(bucketColumnIndex); @@ -93,11 +87,7 @@ private static List getVideoBuckets(Context context) { b.isCameraBucket = true; } } - - // ignore buckets created by Seadroid - String file = cursor.getString(dataColumnIndex); - if (file == null || !file.startsWith(StorageManager.getInstance().getMediaDir().getAbsolutePath())) - buckets.add(b); + buckets.add(b); } cursor.close(); @@ -109,17 +99,14 @@ private static List getImageBuckets(Context context) { String[] projection = new String[]{ MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, - MediaStore.Video.Media.DATA, MediaStore.Images.Media._ID }; - String BUCKET_ORDER_BY = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " ASC"; - String BUCKET_GROUP_BY = "1) GROUP BY 1,(2"; Cursor cursor = context.getContentResolver().query(images, projection, // Which columns to return - BUCKET_GROUP_BY, // Which rows to return (all rows) + null, // Which rows to return (all rows) null, // Selection arguments (none) - BUCKET_ORDER_BY // Ordering + null // Ordering ); List buckets = new ArrayList(); @@ -131,12 +118,9 @@ private static List getImageBuckets(Context context) { while (cursor.moveToNext()) { int bucketIdColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID); int bucketColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); - int dataColumnIndex = cursor.getColumnIndex(MediaStore.Video.Media.DATA); - int idColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID); Bucket b = new Bucket(); b.id = cursor.getString(bucketIdColumnIndex); b.name = cursor.getString(bucketColumnIndex); - b.image_id = cursor.getInt(idColumnIndex); b.isCameraBucket = false; for (String name : CAMERA_BUCKET_NAMES) { @@ -144,11 +128,7 @@ private static List getImageBuckets(Context context) { b.isCameraBucket = true; } } - - // ignore buckets created by Seadroid - String file = cursor.getString(dataColumnIndex); - if (file == null || !file.startsWith(StorageManager.getInstance().getMediaDir().getAbsolutePath())) - buckets.add(b); + buckets.add(b); } cursor.close(); diff --git a/app/src/main/java/com/seafile/seadroid2/cameraupload/WhatToUploadFragment.java b/app/src/main/java/com/seafile/seadroid2/cameraupload/WhatToUploadFragment.java index 8f6521cd3..598d81aa8 100644 --- a/app/src/main/java/com/seafile/seadroid2/cameraupload/WhatToUploadFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/cameraupload/WhatToUploadFragment.java @@ -8,6 +8,7 @@ import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; + import com.seafile.seadroid2.R; import com.seafile.seadroid2.SettingsManager; @@ -50,7 +51,7 @@ public void onCheckedChanged(RadioGroup group, int checkedId) { } }); - + mActivity.saveSettings(); return rootView; } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/fragment/SettingsFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/fragment/SettingsFragment.java index de68c52d5..4220f1f87 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/fragment/SettingsFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/fragment/SettingsFragment.java @@ -14,7 +14,6 @@ import android.preference.PreferenceScreen; import android.support.v7.app.AlertDialog; import android.text.Html; -import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Toast; @@ -74,8 +73,8 @@ public class SettingsFragment extends CustomPreferenceFragment { private PreferenceScreen cUploadAdvancedScreen; private PreferenceCategory cUploadAdvancedCategory; private Preference cUploadRepoPref; - private CheckBoxPreference cCustomDirectoriesPref; - private Preference cLocalDirectoriesPref; +// private CheckBoxPreference cCustomDirectoriesPref; +// private Preference cLocalDirectoriesPref; // privacy private PreferenceCategory cPrivacyCategory; private Preference clientEncPref; @@ -368,38 +367,38 @@ public boolean onPreferenceClick(Preference preference) { // } // }); // change local folder CheckBoxPreference - cCustomDirectoriesPref = (CheckBoxPreference) findPreference(SettingsManager.CAMERA_UPLOAD_CUSTOM_BUCKETS_KEY); - cCustomDirectoriesPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (newValue instanceof Boolean) { - boolean isCustom = (Boolean) newValue; - if (!isCustom) { - cUploadAdvancedCategory.removePreference(cLocalDirectoriesPref); - scanCustomDirs(false); - } else { - cUploadAdvancedCategory.addPreference(cLocalDirectoriesPref); - scanCustomDirs(true); - } - return true; - } - - return false; - } - }); +// cCustomDirectoriesPref = (CheckBoxPreference) findPreference(SettingsManager.CAMERA_UPLOAD_CUSTOM_BUCKETS_KEY); +// cCustomDirectoriesPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { +// @Override +// public boolean onPreferenceChange(Preference preference, Object newValue) { +// if (newValue instanceof Boolean) { +// boolean isCustom = (Boolean) newValue; +// if (!isCustom) { +// cUploadAdvancedCategory.removePreference(cLocalDirectoriesPref); +// scanCustomDirs(false); +// } else { +// cUploadAdvancedCategory.addPreference(cLocalDirectoriesPref); +// scanCustomDirs(true); +// } +// return true; +// } +// +// return false; +// } +// }); // change local folder Preference - cLocalDirectoriesPref = findPreference(SettingsManager.CAMERA_UPLOAD_BUCKETS_KEY); - cLocalDirectoriesPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - - // choose media buckets - scanCustomDirs(true); - - return true; - } - }); +// cLocalDirectoriesPref = findPreference(SettingsManager.CAMERA_UPLOAD_BUCKETS_KEY); +// cLocalDirectoriesPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { +// @Override +// public boolean onPreferenceClick(Preference preference) { +// +// // choose media buckets +// scanCustomDirs(true); +// +// return true; +// } +// }); refreshCameraUploadView(); // refreshContactsView(); @@ -634,14 +633,14 @@ private void refreshCameraUploadView() { } } - if (bucketNames.isEmpty()) { - cUploadAdvancedCategory.removePreference(cLocalDirectoriesPref); - cCustomDirectoriesPref.setChecked(false); - } else { - cCustomDirectoriesPref.setChecked(true); - cLocalDirectoriesPref.setSummary(TextUtils.join(", ", bucketNames)); - cUploadAdvancedCategory.addPreference(cLocalDirectoriesPref); - } +// if (bucketNames.isEmpty()) { +// cUploadAdvancedCategory.removePreference(cLocalDirectoriesPref); +// cCustomDirectoriesPref.setChecked(false); +// } else { +// cCustomDirectoriesPref.setChecked(true); +// cLocalDirectoriesPref.setSummary(TextUtils.join(", ", bucketNames)); +// cUploadAdvancedCategory.addPreference(cLocalDirectoriesPref); +// } } @@ -849,6 +848,7 @@ public void onEvent(CameraSyncEvent result) { cUploadRepoState.setSummary(Utils.getUploadStateShow(getActivity())); Log.d(DEBUG_TAG, "==========" + result.getLogInfo()); + Utils.utilsLogInfo(true,"==========" + result.getLogInfo()); } } diff --git a/app/src/main/java/com/seafile/seadroid2/util/SeafileLog.java b/app/src/main/java/com/seafile/seadroid2/util/SeafileLog.java new file mode 100644 index 000000000..ecdf5211b --- /dev/null +++ b/app/src/main/java/com/seafile/seadroid2/util/SeafileLog.java @@ -0,0 +1,141 @@ +package com.seafile.seadroid2.util; + +import android.content.Context; +import android.os.Environment; +import android.util.Log; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +public class SeafileLog { + + private static Boolean MYLOG_SWITCH = true; // Main switch + private static Boolean MYLOG_WRITE_TO_FILE = true;// log switch + private static char MYLOG_TYPE = 'v'; + private static int SDCARD_LOG_FILE_SAVE_DAYS = 0; + private static String MYLOGFILENAME = "Log.txt"; + private static SimpleDateFormat myLogSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// The output format of the log + private static SimpleDateFormat logfile = new SimpleDateFormat("yyyy-MM-dd");// Log file format + public Context context; + + public static void w(String tag, Object msg) { // Warning message + log(tag, msg.toString(), 'w'); + } + + public static void e(String tag, Object msg) { // The error message + log(tag, msg.toString(), 'e'); + } + + public static void d(String tag, Object msg) {// Debugging information + log(tag, msg.toString(), 'd'); + } + + public static void i(String tag, Object msg) {// + log(tag, msg.toString(), 'i'); + } + + public static void v(String tag, Object msg) { + log(tag, msg.toString(), 'v'); + } + + public static void w(String tag, String text) { + log(tag, text, 'w'); + } + + public static void e(String tag, String text) { + log(tag, text, 'e'); + } + + public static void d(String tag, String text) { + log(tag, text, 'd'); + } + + public static void i(String tag, String text) { + log(tag, text, 'i'); + } + + public static void v(String tag, String text) { + log(tag, text, 'v'); + } + + private static void log(String tag, String msg, char level) { + if (MYLOG_SWITCH) {//Log file master switch + if ('e' == level && ('e' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) { + Log.e(tag, msg); + } else if ('w' == level && ('w' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) { + Log.w(tag, msg); + } else if ('d' == level && ('d' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) { + Log.d(tag, msg); + } else if ('i' == level && ('d' == MYLOG_TYPE || 'v' == MYLOG_TYPE)) { + Log.i(tag, msg); + } else { + Log.v(tag, msg); + } + if (MYLOG_WRITE_TO_FILE)//Log write file switch + writeLogtoFile(String.valueOf(level), tag, msg); + } + } + + /** + * Open the log file and write to the log + * + * @param mylogtype + * @param tag + * @param text + */ + private static void writeLogtoFile(String mylogtype, String tag, String text) { + Date nowtime = new Date(); + String needWriteFile = logfile.format(nowtime); + String needWriteMessage = myLogSdf.format(nowtime) + " " + mylogtype + " " + tag + " " + text; + File dirsFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Seafile/"); + if (!dirsFile.exists()) { + dirsFile.mkdirs(); + } + File file = new File(dirsFile.toString(), needWriteFile + MYLOGFILENAME);// MYLOG_PATH_SDCARD_DIR + if (!file.exists()) { + try { + file.createNewFile(); + } catch (Exception e) { + } + } + + try { + FileWriter filerWriter = new FileWriter(file, true); + BufferedWriter bufWriter = new BufferedWriter(filerWriter); + bufWriter.write(needWriteMessage); + bufWriter.newLine(); + bufWriter.close(); + filerWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Delete the specified log file + */ + public static void delFile() { + String needDelFiel = logfile.format(getDateBefore()); + File dirPath = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Seafile/"); + File file = new File(dirPath, needDelFiel + MYLOGFILENAME);// MYLOG_PATH_SDCARD_DIR + if (file.exists()) { + file.delete(); + } + } + + /** + * Use to get the file name of the log to delete + */ + private static Date getDateBefore() { + Date nowtime = new Date(); + Calendar now = Calendar.getInstance(); + now.setTime(nowtime); + now.set(Calendar.DATE, now.get(Calendar.DATE) - SDCARD_LOG_FILE_SAVE_DAYS); + return now.getTime(); + } +} diff --git a/app/src/main/java/com/seafile/seadroid2/util/Utils.java b/app/src/main/java/com/seafile/seadroid2/util/Utils.java index b17395fd2..8e5edd3de 100644 --- a/app/src/main/java/com/seafile/seadroid2/util/Utils.java +++ b/app/src/main/java/com/seafile/seadroid2/util/Utils.java @@ -21,6 +21,7 @@ import android.os.Build; import android.os.Bundle; import android.os.LocaleList; +import android.provider.MediaStore; import android.provider.OpenableColumns; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; @@ -30,13 +31,7 @@ import android.view.View; import android.view.inputmethod.InputMethodManager; import android.webkit.MimeTypeMap; -import android.widget.ImageView; -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.load.model.GlideUrl; -import com.bumptech.glide.load.model.LazyHeaders; -import com.bumptech.glide.request.RequestOptions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.seafile.seadroid2.R; @@ -961,19 +956,38 @@ public static String toURLEncoded(String paramString) { return ""; } - public static void glideImage(Context ct, String urlicon, String token, ImageView iv, int width, int height) { - GlideUrl glideUrl = new GlideUrl(urlicon, new LazyHeaders.Builder() - .addHeader("Authorization", "Token " + token) - .build()); - RequestOptions opt = new RequestOptions() - .placeholder(R.drawable.file_image) - .skipMemoryCache(true) - .override(width, height) - .diskCacheStrategy(DiskCacheStrategy.NONE); - Glide.with(ct) - .asBitmap() - .load(glideUrl) - .apply(opt) - .into(iv); + public static String getRealPathFromURI(Context context, Uri contentUri, String mediaId) { + Cursor cursor = null; + try { + if (MediaStore.Images.Media._ID.equals(mediaId)) {//image + String[] proj = {MediaStore.Images.Media.DATA}; + cursor = context.getContentResolver().query(contentUri, proj, null, null, null); + int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + return cursor.getString(column_index); + } else {//Video + String[] proj = {MediaStore.Video.Media.DATA}; + cursor = context.getContentResolver().query(contentUri, proj, null, null, null); + int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); + cursor.moveToFirst(); + return cursor.getString(column_index); + } + + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally { + if (cursor != null) { + cursor.close(); + } + } + } + + public static void utilsLogInfo(boolean b, String info) { + if (b) { +// Log.d(DEBUG_TAG, info); + SeafileLog.d(DEBUG_TAG, info); + } } } + diff --git a/app/src/main/res/layout/cuc_local_directory_fragment.xml b/app/src/main/res/layout/cuc_local_directory_fragment.xml index 70124d727..9214e9985 100644 --- a/app/src/main/res/layout/cuc_local_directory_fragment.xml +++ b/app/src/main/res/layout/cuc_local_directory_fragment.xml @@ -36,6 +36,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/rb_margin_top" + android:visibility="gone" android:text="@string/settings_cuc_pick_albums" android:textSize="@dimen/tv_subtitle_txt_size"/> diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index a91b17bb1..6569bf9d2 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -93,19 +93,19 @@ android:summaryOn="@string/settings_camera_upload_videos_allowed" android:title="@string/settings_camera_upload_allow_videos"> - - - - + + + + + + + + + + + + +