Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Crop Image before upload #2542

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
12d9c28
crop image activity
vanshikaarora Mar 3, 2019
d1a14dd
loading image cropping
vanshikaarora Mar 3, 2019
529a1f9
option to edit an image
vanshikaarora Mar 5, 2019
604baab
cropping image for one and ui for multiple
vanshikaarora Mar 5, 2019
10332e9
merge conflicts
vanshikaarora Mar 5, 2019
e01eebd
resolve merge conflicts
vanshikaarora Mar 6, 2019
4841723
multiple uploads
vanshikaarora Mar 11, 2019
dabe0ce
removed edit activity
vanshikaarora Mar 11, 2019
a7b6ed1
codacy issues
vanshikaarora Mar 12, 2019
9de934a
resolved merge conflicts
vanshikaarora Mar 12, 2019
b9316e1
fixed travis-ci issue
vanshikaarora Mar 13, 2019
2632724
fixed issues in case of multiple images
vanshikaarora Mar 14, 2019
bef74c6
finished code for multiple images
vanshikaarora Mar 14, 2019
44caabf
resolved merge conflicts
vanshikaarora Mar 15, 2019
72c7d11
resolved merge conflicts
vanshikaarora Mar 17, 2019
beefef2
resolved merge conflicts
vanshikaarora Mar 19, 2019
90d618b
resolved merge conflicts
vanshikaarora Mar 19, 2019
514da51
copying EXIF data
vanshikaarora Mar 20, 2019
3c6b0ba
resolve merge conflicts
vanshikaarora Mar 23, 2019
f4fd9cd
restored exif to image uri
vanshikaarora Mar 23, 2019
350e5c0
fixed codacy and travis-ci issues
vanshikaarora Mar 23, 2019
ddb43dc
resolved codacy issues
vanshikaarora Mar 23, 2019
7552b14
resolved merge conflicts
vanshikaarora Mar 23, 2019
41c5b34
fixed travis-ci error
vanshikaarora Mar 24, 2019
07982a4
travis
vanshikaarora Mar 24, 2019
0f8998e
resolved merge conflicts
vanshikaarora Mar 25, 2019
ed84b2b
exclude library from jetifier
vanshikaarora Mar 25, 2019
0080b2b
resolved merge conflicts
vanshikaarora Mar 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 20 additions & 12 deletions app/build.gradle
Expand Up @@ -7,7 +7,7 @@ apply from: 'quality.gradle'

def isRunningOnTravisAndIsNotPRBuild = System.getenv("CI") == "true" && file('../play.p12').exists()

if(isRunningOnTravisAndIsNotPRBuild) {
if (isRunningOnTravisAndIsNotPRBuild) {
apply plugin: 'com.github.triplet.play'
}

Expand Down Expand Up @@ -83,18 +83,26 @@ dependencies {
testImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$LEAK_CANARY_VERSION"

// Support libraries
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "com.google.android.material:material:1.1.0-alpha04"
implementation "androidx.browser:browser:1.0.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.exifinterface:exifinterface:1.0.0"
implementation 'androidx.exifinterface:exifinterface:1.0.0'

//swipe_layout
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.nineoldandroids:library:2.4.0'

//image crop
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'

//metadata extractor
implementation 'com.drewnoakes:metadata-extractor:2.11.0'
//implementation fileTree(include:['commons-imaging-1.0-R1401825.jar'], dir: "/media/vanshika/25151b5f-bb91-4813-863c-b418727a0635/vanshika/apps-android-commons/app/libs")
implementation files('libs/commons-imaging-1.0-R1401825.jar')
annotationProcessor 'com.android.tools.build.jetifier:jetifier-core:1.0.0-beta02'
}

android {
Expand Down Expand Up @@ -142,7 +150,7 @@ android {
test.resources.srcDirs += 'src/main/resoures'
}

signingConfigs {
signingConfigs {
release
}

Expand All @@ -151,7 +159,7 @@ android {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
testProguardFile 'test-proguard-rules.txt'
if(isRunningOnTravisAndIsNotPRBuild) {
if (isRunningOnTravisAndIsNotPRBuild) {
signingConfig signingConfigs.release
}
}
Expand All @@ -163,7 +171,7 @@ android {
versionNameSuffix "-debug-" + getBranchName()
}
}

if (isRunningOnTravisAndIsNotPRBuild) {
// configure keystore based on env vars in Travis for automated alpha builds
signingConfigs.release.storeFile = file("../nr-commons.keystore")
Expand All @@ -180,7 +188,7 @@ android {
productFlavors {
prod {

applicationId 'fr.free.nrw.commons'
applicationId 'fr.free.nrw.commons'

buildConfigField "String", "WIKIMEDIA_API_POTD", "\"https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=rss&language=en\""
buildConfigField "String", "WIKIMEDIA_API_HOST", "\"https://commons.wikimedia.org/w/api.php\""
Expand Down Expand Up @@ -257,7 +265,7 @@ android {
buildToolsVersion buildToolsVersion
}

if(isRunningOnTravisAndIsNotPRBuild) {
if (isRunningOnTravisAndIsNotPRBuild) {
play {
track = "alpha"
userFraction = 1
Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.txt
Expand Up @@ -75,3 +75,4 @@
-keep class org.acra.** { *; }
-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
-keep class android.support.v7.widget.** { *; }
59 changes: 23 additions & 36 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -18,17 +18,13 @@
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>


<!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
<uses-permission android:name="android.permission.SET_WALLPAPER" /> <!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
<uses-feature android:name="android.hardware.location.gps" />

<application
android:name=".CommonsApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/LightAppTheme"
android:largeHeap="true"
android:supportsRtl="true"
tools:replace="android:appComponentFactory"
Expand All @@ -39,8 +35,8 @@
android:process=":acra"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true" />

android:finishOnTaskLaunch="true"
/>
<activity android:name=".auth.LoginActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -49,11 +45,11 @@
</intent-filter>
</activity>
<activity android:name=".WelcomeActivity" />

<activity android:name=".upload.UploadActivity"
<activity
android:name=".upload.UploadActivity"
android:configChanges="orientation|screenSize|keyboard"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboard">
android:label="@string/app_name">
<intent-filter android:label="@string/intent_share_upload_label">
<action android:name="android.intent.action.SEND" />

Expand All @@ -73,42 +69,37 @@
</activity>
<activity
android:name=".contributions.MainActivity"
android:configChanges="orientation|screenSize|keyboard"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboard" />
android:label="@string/app_name" />
<activity
android:name=".settings.SettingsActivity"
android:label="@string/title_activity_settings" />
<activity
android:name=".AboutActivity"
android:label="@string/title_activity_about"
android:parentActivityName=".contributions.MainActivity" />

<activity
android:name=".auth.SignupActivity"
android:label="@string/title_activity_signup" />

<activity
android:name=".notification.NotificationActivity"
android:label="@string/navigation_item_notification" />

<activity android:name=".quiz.QuizActivity"
android:label="@string/quiz"/>

<activity android:name=".quiz.QuizResultActivity"
android:label="@string/result"/>

<activity
android:name=".quiz.QuizActivity"
android:label="@string/quiz" />
<activity
android:name=".quiz.QuizResultActivity"
android:label="@string/result" />
<activity
android:name=".category.CategoryImagesActivity"
android:label="@string/title_activity_featured_images"
android:parentActivityName=".contributions.MainActivity"
android:configChanges="orientation|screenSize|keyboard"/>

<activity
android:name=".category.CategoryDetailsActivity"
android:label="@string/title_activity_featured_images"
android:parentActivityName=".contributions.MainActivity" />

<activity
android:name=".explore.categories.ExploreActivity"
android:label="@string/title_activity_explore"
Expand All @@ -117,19 +108,19 @@

<activity
android:name=".explore.SearchActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_search"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden|screenSize"
android:parentActivityName=".contributions.MainActivity"
/>

android:parentActivityName=".contributions.MainActivity" />
<activity
android:name=".achievements.AchievementsActivity"
android:label="@string/Achievements" />

<activity
android:name=".bookmarks.BookmarksActivity"
android:label="@string/title_activity_bookmarks" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />

<activity
android:name=".review.ReviewActivity"
Expand All @@ -143,6 +134,7 @@
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>

<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
Expand All @@ -169,7 +161,6 @@
android:name="android.content.SyncAdapter"
android:resource="@xml/modifications_sync_adapter" />
</service>

<service
android:name="org.acra.sender.SenderService"
android:exported="false"
Expand Down Expand Up @@ -202,21 +193,18 @@
android:exported="false"
android:label="@string/provider_categories"
android:syncable="false" />

<provider
android:name=".explore.recentsearches.RecentSearchesContentProvider"
android:authorities="${applicationId}.explore.recentsearches.contentprovider"
android:exported="false"
android:label="@string/provider_searches"
android:syncable="false" />

<provider
android:name=".bookmarks.pictures.BookmarkPicturesContentProvider"
android:authorities="${applicationId}.bookmarks.contentprovider"
android:exported="false"
android:label="@string/provider_bookmarks"
android:syncable="false" />

<provider
android:name=".bookmarks.locations.BookmarkLocationsContentProvider"
android:authorities="${applicationId}.bookmarks.locations.contentprovider"
Expand All @@ -233,9 +221,8 @@
android:name="android.appwidget.provider"
android:resource="@xml/pic_of_day_app_widget_info" />
</receiver>

<uses-library android:name="org.apache.http.legacy" android:required="false" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />

</application>

</manifest>
</manifest>
Expand Up @@ -13,6 +13,8 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;

import javax.annotation.Nullable;
Expand All @@ -33,7 +35,7 @@ public UploadableFile[] newArray(int size) {
};

private final Uri contentUri;
private final File file;
private File file;

public UploadableFile(Uri contentUri, File file) {
this.contentUri = contentUri;
Expand Down Expand Up @@ -66,6 +68,15 @@ public Uri getMediaUri() {
return Uri.parse(getFilePath());
}

public void updateFilePath(Uri uri){
String path = uri.toString();
try {
file=new File(new URI(path));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}

public String getMimeType(Context context) {
return FileUtils.getMimeType(context, getMediaUri());
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public EXIFReader() {
* And the checks for the presence of EXIF Directories in metadata object
* */

public Single<Integer> processMetadata(String path) {
public static Single<Integer> processMetadata(String path) {
Metadata readMetadata = null;
try {
readMetadata = ImageMetadataReader.readMetadata(new File(path));
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/upload/ImageAdapter.java
@@ -0,0 +1,62 @@
package fr.free.nrw.commons.upload;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.theartofdev.edmodo.cropper.CropImage;

import java.util.ArrayList;

import fr.free.nrw.commons.filepicker.UploadableFile;

public class ImageAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<UploadableFile> files;

// Constructor
public ImageAdapter(Context c, ArrayList<UploadableFile> files) {
this.files = files;
mContext = c;
}

public int getCount() {
return files.size();
}

public Object getItem(int position) {
return null;
}

public long getItemId(int position) {
return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;

if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(250, 250));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageURI(files.get(position).getMediaUri());

return imageView;
}

public void handleClickListener(int position){
CropImage.activity(files.get(position).getMediaUri())
.start((Activity) mContext);
}

// Keep all Images in array
}