Skip to content

Commit

Permalink
androidQ (#876)
Browse files Browse the repository at this point in the history
* google store targetSdkVersion

* update androidQ

* android10 debug log

* update log

* update log path

* update loginfo

* update log format

* update local log
  • Loading branch information
maxiaoping authored Jan 18, 2021
1 parent 023f049 commit dffdefd
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 149 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/SeadroidApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
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;
private int waitingNumber;
private int totalNumber;
private int scanUploadStatus;
private static SeadroidApplication instance;
private List<GalleryBucketUtils.Bucket> buckets = new ArrayList<>();

public void onCreate() {
super.onCreate();
Expand Down Expand Up @@ -122,4 +126,11 @@ public int getScanUploadStatus() {
return scanUploadStatus;
}

public void setBuckets(List<GalleryBucketUtils.Bucket> buckets) {
this.buckets = buckets;
}

public List<GalleryBucketUtils.Bucket> getBuckets() {
return buckets;
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/seafile/seadroid2/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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));
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand All @@ -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())
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -500,46 +502,64 @@ 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;
}

// 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);
}
Expand Down Expand Up @@ -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<SeafDirent> 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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -100,13 +102,13 @@ public void saveSettings() {
if (isChooseBothPages || isChooseDirPage) {

SettingsManager settingsManager = SettingsManager.instance();
List<String> selectedBuckets = mBucketsFragment.getSelectionFragment().getSelectedBuckets();
if (mBucketsFragment.isAutoScanSelected()){
selectedBuckets.clear();
}
// List<String> 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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -201,7 +204,7 @@ public int getCount() {
if (isChooseLibPage || isChooseDirPage)
return 1;
else
return 6;
return 5;
}

}
Expand Down
Loading

0 comments on commit dffdefd

Please sign in to comment.