Skip to content

Commit

Permalink
albumClassification (#880)
Browse files Browse the repository at this point in the history
* update androidQ

* android10 debug log

* update log

* update log path

* update loginfo

* update log format

* update local log

* Photo album classification

* album classification

* Update album classification

* Classification of photo album

* Changed album selection style
  • Loading branch information
maxiaoping authored Feb 20, 2021
1 parent dffdefd commit fede1a0
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 100 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 107
versionName "2.2.32"
versionCode 108
versionName "2.2.33"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/com/seafile/seadroid2/SeadroidApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
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 @@ -126,11 +122,4 @@ public int getScanUploadStatus() {
return scanUploadStatus;
}

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

public List<GalleryBucketUtils.Bucket> getBuckets() {
return buckets;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.seafile.seadroid2.cameraupload;

import android.graphics.Bitmap;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.content.Context;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.SettingsManager;
import com.seafile.seadroid2.cameraupload.GalleryBucketUtils;
import com.seafile.seadroid2.util.Utils;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

/**
Expand All @@ -23,27 +31,36 @@
public class BucketsSelectionFragment extends Fragment {

private List<GalleryBucketUtils.Bucket> buckets;
private Bitmap[] thumbnails;
private List<GalleryBucketUtils.Bucket> tempBuckets;
private boolean[] selectedBuckets;
private ImageAdapter imageAdapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View rootView = getActivity().getLayoutInflater().inflate(R.layout.cuc_bucket_selection_layout, null);
buckets = GalleryBucketUtils.getMediaBuckets(getActivity().getApplicationContext());

tempBuckets = GalleryBucketUtils.getMediaBuckets(getActivity().getApplicationContext());
SettingsManager settingsManager = SettingsManager.instance();
List<String> currentBucketList = settingsManager.getCameraUploadBucketList();

thumbnails = new Bitmap[buckets.size()];
LinkedHashSet<GalleryBucketUtils.Bucket> bucketsSet = new LinkedHashSet<>(tempBuckets.size());
bucketsSet.addAll(tempBuckets);
buckets = new ArrayList<>(bucketsSet.size());
Iterator iterator = bucketsSet.iterator();
while (iterator.hasNext()) {
GalleryBucketUtils.Bucket bucket = (GalleryBucketUtils.Bucket) iterator.next();
buckets.add(bucket);
}
selectedBuckets = new boolean[buckets.size()];
for (int i = 0; i < buckets.size(); i++) {
GalleryBucketUtils.Bucket b = buckets.get(i);
if (b.image_id > 0) {
thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
getActivity().getApplicationContext().getContentResolver(), b.image_id,
MediaStore.Images.Thumbnails.MINI_KIND, null);
if (b.isImages != null && b.isImages.equals(GalleryBucketUtils.IMAGES)) {
Uri image_uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, b.imageId);
String image_path = Utils.getRealPathFromURI(SeadroidApplication.getAppContext(), image_uri, "images");
b.imagePath = image_path;
} else {
Uri video_uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, b.videoId);
String videoPath = Utils.getRealPathFromURI(SeadroidApplication.getAppContext(), video_uri, "video");
b.videoPath = videoPath;
}

// if the user has previously selected buckets, mark these.
Expand Down Expand Up @@ -125,16 +142,21 @@ public void onClick(View v) {
int id = v.getId();
selectedBuckets[id] = !selectedBuckets[id];
if (selectedBuckets[id])
holder.marking.setVisibility(View.VISIBLE);
holder.marking.setBackgroundResource(R.drawable.checkbox_checked);
else
holder.marking.setVisibility(View.INVISIBLE);
holder.marking.setBackgroundResource(R.drawable.checkbox_unchecked);
}
});
holder.imageview.setImageBitmap(thumbnails[position]);
if (buckets.get(position).isImages != null && buckets.get(position).isImages.equals(GalleryBucketUtils.IMAGES)) {
Glide.with(getActivity()).load(Uri.fromFile(new File(buckets.get(position).imagePath))).into(holder.imageview);
} else {
Glide.with(getActivity()).load(Uri.fromFile(new File(buckets.get(position).videoPath))).into(holder.imageview);
}

if (selectedBuckets[position])
holder.marking.setVisibility(View.VISIBLE);
holder.marking.setBackgroundResource(R.drawable.checkbox_checked);
else
holder.marking.setVisibility(View.INVISIBLE);
holder.marking.setBackgroundResource(R.drawable.checkbox_unchecked);
holder.id = position;
return convertView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ private void uploadImages(SyncResult syncResult, DataManager dataManager) throws
if (cursor.getCount() > 0) {
// create directories for media buckets
createDirectories(dataManager);

iterateCursor(syncResult, dataManager, cursor, MediaStore.Images.Media._ID);
iterateCursor(syncResult, dataManager, cursor, "images");

if (isCancelled())
return;
Expand Down Expand Up @@ -474,8 +473,7 @@ private void uploadVideos(SyncResult syncResult, DataManager dataManager) throws
if (cursor.getCount() > 0) {
// create directories for media buckets
createDirectories(dataManager);

iterateCursor(syncResult, dataManager, cursor, MediaStore.Video.Media._ID);
iterateCursor(syncResult, dataManager, cursor, "video");

if (isCancelled())
return;
Expand All @@ -502,27 +500,30 @@ private String varArgs(int count) {
* @param cursor
* @throws SeafException
*/
private void iterateCursor(SyncResult syncResult, DataManager dataManager, Cursor cursor, String mediaId) throws SeafException, InterruptedException {
private void iterateCursor(SyncResult syncResult, DataManager dataManager, Cursor cursor, String media) 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);
if (media.equals("images")) {
String image_id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
Uri image_uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, image_id);
if (image_uri == null) {
syncResult.stats.numSkippedEntries++;
continue;
}
file = new File(Utils.getRealPathFromURI(SeadroidApplication.getAppContext(), image_uri, media));
} else {
uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id);
}
if (uri == null) {
syncResult.stats.numSkippedEntries++;
continue;
String video_id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
Uri video_uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, video_id);
if (video_uri == null) {
syncResult.stats.numSkippedEntries++;
continue;
}
file = new File(Utils.getRealPathFromURI(SeadroidApplication.getAppContext(), video_uri, media));
}
file = new File(Utils.getRealPathFromURI(SeadroidApplication.getAppContext(), uri, mediaId));
} else {
int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
if (cursor.getString(dataColumn) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.seafile.seadroid2.util.SystemSwitchUtils;
import com.viewpagerindicator.LinePageIndicator;

import java.util.ArrayList;
import java.util.List;


/**
Expand All @@ -30,7 +30,7 @@ public class CameraUploadConfigActivity extends BaseActivity {

private ViewPager mViewPager;
private LinePageIndicator mIndicator;
// private BucketsFragment mBucketsFragment;
private BucketsFragment mBucketsFragment;
private CloudLibraryFragment mCloudLibFragment;
private WhatToUploadFragment whatToUploadFragment;
private SettingsManager sm;
Expand Down Expand Up @@ -62,7 +62,7 @@ public void onCreate(Bundle savedInstanceState) {

FragmentManager fm = getSupportFragmentManager();
mViewPager.setAdapter(new CameraUploadConfigAdapter(fm));
mViewPager.setOffscreenPageLimit(5);
mViewPager.setOffscreenPageLimit(6);

mIndicator = (LinePageIndicator) findViewById(R.id.cuc_indicator);
mIndicator.setViewPager(mViewPager);
Expand Down Expand Up @@ -102,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(new ArrayList<>());
settingsManager.setCameraUploadBucketList(selectedBuckets);
}

Intent intent = new Intent();
Expand Down Expand Up @@ -186,13 +186,13 @@ public Fragment getItem(int position) {
case 2:
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 4:
case 5:
return new ReadyToScanFragment();
default:
return null;
Expand All @@ -204,7 +204,7 @@ public int getCount() {
if (isChooseLibPage || isChooseDirPage)
return 1;
else
return 5;
return 6;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,34 @@ public class GalleryBucketUtils {
* - https://stackoverflow.com/questions/6248887/android-device-specific-camera-path-issue
*/
public static final String[] CAMERA_BUCKET_NAMES = {"Camera", "100ANDRO", "100MEDIA"};
public static final String IMAGES = "IMAGES";

public static class Bucket {
public String id;
public String name;
public String imageId;
public String videoId;
public String isImages;
public String videoPath;
public String imagePath;
public int image_id = -1;
public boolean isCameraBucket;

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || (obj.getClass() != this.getClass()))
return false;

Bucket a = (Bucket) obj;
return a.name.equals(this.name);
}

@Override
public int hashCode() {
return name.hashCode();
}
}

/**
Expand Down Expand Up @@ -80,7 +102,8 @@ private static List<Bucket> getVideoBuckets(Context context) {
Bucket b = new Bucket();
b.id = cursor.getString(bucketIdColumnIndex);
b.name = cursor.getString(bucketColumnIndex);

String video_id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
b.videoId = video_id;
b.isCameraBucket = false;
for (String name : CAMERA_BUCKET_NAMES) {
if (b.name != null && b.name.equalsIgnoreCase(name)) {
Expand Down Expand Up @@ -121,8 +144,10 @@ private static List<Bucket> getImageBuckets(Context context) {
Bucket b = new Bucket();
b.id = cursor.getString(bucketIdColumnIndex);
b.name = cursor.getString(bucketColumnIndex);

String image_id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
b.imageId = image_id;
b.isCameraBucket = false;
b.isImages = GalleryBucketUtils.IMAGES;
for (String name : CAMERA_BUCKET_NAMES) {
if (b.name != null && b.name.equalsIgnoreCase(name)) {
b.isCameraBucket = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
}

});
mActivity.saveSettings();
// mActivity.saveSettings();
return rootView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public final static StorageManager getInstance() {
private Location buildClassicLocation() {
Location classic = new Location();
classic.id = -1; // Android IDs start at 0. so "-1" is safe for us
classic.mediaPath = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Seafile/");
String rootPath = SeadroidApplication.getAppContext().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath();
// classic.mediaPath = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Seafile/");
classic.mediaPath = new File(rootPath + "/Seafile/");
classic.cachePath = new File(classic.mediaPath, "cache");
fillLocationInfo(classic);
return classic;
Expand Down
Loading

0 comments on commit fede1a0

Please sign in to comment.