Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zorgluf committed May 31, 2022
2 parents 7571c4c + 6eabb0f commit 56123a5
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 119 deletions.
28 changes: 15 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
def nav_version = "2.3.5"
classpath 'com.android.tools.build:gradle:7.2.1'
def nav_version = '2.4.1'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
Expand All @@ -21,8 +21,8 @@ android {
applicationId "fr.nuage.souvenirs"
minSdkVersion 24
targetSdkVersion 30
versionCode 19
versionName "2.4.1"
versionCode 20
versionName "2.5.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", "souvenirs-$versionName")
}
Expand All @@ -43,6 +43,7 @@ android {
lint {
abortOnError false
}
namespace 'fr.nuage.souvenirs'
}

repositories {
Expand All @@ -51,35 +52,36 @@ repositories {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.webkit:webkit:1.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
def lifecycle_version = "2.3.0"
def lifecycle_version = "2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"

implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

implementation "com.github.nextcloud:Android-SingleSignOn:0.6.0"
implementation 'com.squareup.retrofit2:retrofit:2.6.4'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'

def nav_version = '2.3.4'
def nav_version = '2.4.2'
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.4.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.7.0-alpha02'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.preference:preference:1.2.0'

implementation 'androidx.core:core-google-shortcuts:1.0.0'
implementation 'androidx.core:core-google-shortcuts:1.0.1'
}

buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
classpath 'com.android.tools.build:gradle:7.2.1'
}
}
42 changes: 41 additions & 1 deletion app/src/main/java/fr/nuage/souvenirs/model/ImageElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ImageElement extends Element {
private MutableLiveData<Boolean> ldIsPano = new MutableLiveData<>();
private String imagePath;
private String mimeType;
private String name="";
private int size=0;
private int zoom = 100;
private int offsetX = 0;
private int offsetY = 0;
Expand Down Expand Up @@ -94,6 +96,28 @@ public void setMimeType(String mimeType, boolean save) {
}
}

public void setName(String name) {
setName(name,true);
}

public void setName(String name, boolean save) {
this.name = name;
if (save) {
onChange();
}
}

public void setSize(int size) {
setSize(size,true);
}

public void setSize(int size, boolean save) {
this.size = size;
if (save) {
onChange();
}
}

private boolean isPhotosphere(String imagePath) {
File mFile = new File(imagePath);
try {
Expand Down Expand Up @@ -144,6 +168,8 @@ public void setImage(String localImagePath, String mimeType) {
public JSONObject completeToJSON(JSONObject json) throws JSONException {
json.put("image",Utils.getRelativePath(pageParent.getAlbum().getAlbumPath(),imagePath));
json.put("mime",mimeType);
json.put("name",name);
json.put("size",size);
json.put("transformType",transformType);
json.put("zoom",zoom);
json.put("offsetX",offsetX);
Expand All @@ -164,6 +190,12 @@ public void completeFromJSON(JSONObject jsonObject) throws JSONException {
if (jsonObject.has("mime")) {
setMimeType(jsonObject.getString("mime"),false);
}
if (jsonObject.has("name")) {
setName(jsonObject.getString("name"),false);
}
if (jsonObject.has("size")) {
setSize(jsonObject.getInt("size"),false);
}
if (jsonObject.has("transformType")) {
setTransformType(jsonObject.getInt("transformType"),false);
}
Expand All @@ -186,6 +218,14 @@ public String getMimeType() {
return mimeType;
}

public String getName() {
return name;
}

public int getSize() {
return size;
}

public int getTransformType() { return transformType; }

public MutableLiveData<String> getLiveDataImagePath() { return ldImagePath; }
Expand All @@ -195,7 +235,7 @@ public MutableLiveData<Integer> getLiveDataTransformType() {
}

private void deleteImageFile() {
if (getImagePath() != null) {
if ((getImagePath() != null) && !(pageParent.getAlbum().getAlbumImage().equals(getImagePath()) )) {
File imageFile = new File(getImagePath());
if (imageFile.exists()) {
imageFile.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public static class ElementResp {
//for imageelement
@SerializedName("image")
String imagePath;
String name;
int size;
@SerializedName("mime")
String mimeType;
int transformType;
Expand Down
52 changes: 37 additions & 15 deletions app/src/main/java/fr/nuage/souvenirs/model/nc/AlbumNC.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.nuage.souvenirs.model.nc;

import static fr.nuage.souvenirs.model.Album.STYLE_FREE;

import android.util.Log;

import androidx.annotation.NonNull;
Expand All @@ -14,8 +16,6 @@

import fr.nuage.souvenirs.model.Album;

import static fr.nuage.souvenirs.model.Album.STYLE_FREE;

public class AlbumNC {

public static final int STATE_NOT_LOADED = 0;
Expand All @@ -24,20 +24,20 @@ public class AlbumNC {

private UUID id;
private String name;
private MutableLiveData<String> ldName = new MutableLiveData<String>();
private final MutableLiveData<String> ldName = new MutableLiveData<>();
private Date date;
private MutableLiveData<Date> ldDate = new MutableLiveData<Date>();
private final MutableLiveData<Date> ldDate = new MutableLiveData<>();
private Date lastEditDate;
private MutableLiveData<Date> ldLastEditDate = new MutableLiveData<Date>();
private final MutableLiveData<Date> ldLastEditDate = new MutableLiveData<>();
private String albumImage;
private Date pagesLastEditDate;
private MutableLiveData<Date> ldPageLastEditDate = new MutableLiveData<Date>();
private final MutableLiveData<Date> ldPageLastEditDate = new MutableLiveData<>();
private ArrayList<PageNC> pages = new ArrayList<>();
private boolean isShared = false;
private MutableLiveData<Boolean> ldIsShared = new MutableLiveData<>();
private final MutableLiveData<Boolean> ldIsShared = new MutableLiveData<>();
private String shareToken;
private int state;
private MutableLiveData<Integer> ldState = new MutableLiveData<>();
private final MutableLiveData<Integer> ldState = new MutableLiveData<>();
private String defaultStyle;


Expand All @@ -49,8 +49,6 @@ public AlbumNC(@NonNull UUID id) {

/**
* create album in NC. not on ui thread.
* @param id
* @return
*/
public static AlbumNC create(@NonNull UUID id) {
APIProvider.AlbumResp albumResp;
Expand All @@ -61,6 +59,9 @@ public static AlbumNC create(@NonNull UUID id) {
Log.i(AlbumNC.class.getName(),"Error on nextcloud album creation "+id.toString());
return null;
}
if (albumResp == null) {
return null;
}
AlbumNC albumNC = new AlbumNC(albumResp.id);
albumNC.load(albumResp);
albumNC.setState(STATE_OK);
Expand Down Expand Up @@ -157,6 +158,7 @@ public boolean save() {
albumResp.defaultStyle = getDefaultStyle();
String result = APIProvider.getApi().modifyAlbum(getId().toString(), albumResp).execute().body();
if ((result != null) && (result.equals("OK"))) {
setState(STATE_OK);
return true;
} else {
throw new IOException("Error on post modifications on album");
Expand Down Expand Up @@ -185,6 +187,7 @@ public boolean delPage(PageNC pageNC) {
tmp.remove(pageNC);
pageNC.clear();
setPages(tmp);
setState(STATE_OK);
return true;
} else {
throw new IOException("Error in delete page");
Expand Down Expand Up @@ -220,6 +223,9 @@ public boolean createPage(PageNC pageNC, int index, String localAlbumPath) {
try {
String result = APIProvider.getApi().createPage(getId().toString(),index,pageNC.generatePageResp()).execute().body();
if ((result != null) && (result.equals("OK"))) {
//update local object
pages.add(index, pageNC);
setState(STATE_OK);
return true;
} else {
throw new IOException("Create page error");
Expand All @@ -235,6 +241,7 @@ public boolean clean() {
try {
String result = APIProvider.getApi().cleanAlbum(getId().toString()).execute().body();
if ((result != null) && (result.equals("OK"))) {
setState(STATE_OK);
return true;
} else {
throw new IOException("Error on clean");
Expand All @@ -256,21 +263,26 @@ public LiveData<Boolean> getLdIsShared() {

public boolean pushAsset(String localAlbumPath, String assetPath) {
//probe asset
APIProvider.AssetProbeResult result = null;
APIProvider.AssetProbeResult result;
try {
result = APIProvider.getApi().AssetProbe(getId().toString(),assetPath).execute().body();
} catch (Exception e) {
Log.i(getClass().getName(),String.format("Error on asset probe request for %1$s",assetPath),e);
setState(STATE_ERROR);
return false;
}
assert result != null;
if (result == null) {
Log.i(getClass().getName(),String.format("Error on asset probe request for %1$s",assetPath));
setState(STATE_ERROR);
return false;
}
//get local asset file path
String localPath = new File(localAlbumPath,assetPath).getPath();
if (result.status.equals("ok")) {
Log.d(getClass().getName(),String.format("Asset %1$s already present.",assetPath));
//check if size equal to local one
if ((result.size == 0) || (result.size == (new File(localPath)).length())) {
setState(STATE_OK);
return true;
}
Log.d(getClass().getName(),String.format("Asset %1$s wrong size on server side, reupload.",assetPath));
Expand All @@ -292,29 +304,34 @@ public boolean pushAsset(String localAlbumPath, String assetPath) {
setState(STATE_ERROR);
return false;
}
setState(STATE_OK);
return true;
}

public boolean pullAsset(String localAlbumPath, String assetPath) {
//test if asset does not exist locally
if (! new File(localAlbumPath,assetPath).exists()) {
//probe asset
APIProvider.AssetProbeResult result = null;
APIProvider.AssetProbeResult result;
try {
result = APIProvider.getApi().AssetProbe(getId().toString(),assetPath).execute().body();
} catch (IOException e) {
Log.i(getClass().getName(),String.format("Error on asset probe request for %1$s",assetPath),e);
setState(STATE_ERROR);
return false;
}
assert result != null;
if (result == null) {
Log.i(getClass().getName(),String.format("Error on asset probe request for %1$s",assetPath));
setState(STATE_ERROR);
return false;
}
if (result.status.equals("ok")) {
String fullAssetPath = result.path;
Log.d(getClass().getName(), String.format("Asset %1$s already at %2$s.", assetPath, fullAssetPath));
if (!fullAssetPath.equals("")) {
//pull file
String destLocalPath = new File(localAlbumPath, Album.DATA_DIR).getPath();
if (Utils.downloadFile(fullAssetPath,destLocalPath)) {
if (Utils.downloadFile(fullAssetPath,destLocalPath,new File(assetPath).getName())) {
Log.d(getClass().getName(), String.format("Asset %1$s downloaded.", assetPath));
} else {
Log.i(getClass().getName(), String.format("Error in download of asset %1$s", assetPath));
Expand All @@ -334,6 +351,7 @@ public boolean pullAsset(String localAlbumPath, String assetPath) {
} else {
Log.d(getClass().getName(), String.format("Asset %1$s already present locally.", assetPath));
}
setState(STATE_OK);
return true;
}

Expand All @@ -351,6 +369,7 @@ public boolean deleteShare() {
if ((result != null) && (result.equals("OK"))) {
setIsShared(false);
setShareToken(null);
setState(STATE_OK);
return true;
} else {
throw new IOException("Wrong result on deleteshare");
Expand Down Expand Up @@ -392,6 +411,7 @@ public boolean movePage(PageNC pageNC, int pos) {
tmp.add(pos-1,tmpPage);
}
setPages(tmp);
setState(STATE_OK);
return true;
} else {
throw new IOException("Error on move page");
Expand Down Expand Up @@ -453,6 +473,7 @@ public boolean load(boolean full) {
if (albumResp == null) {
return false;
}
setState(STATE_OK);
return load(albumResp);
}

Expand All @@ -466,6 +487,7 @@ public boolean pushPage(PageNC remotePage, String albumPath) {
String result = APIProvider.getApi().modifyPage(getId().toString(),remotePage.getId().toString(),remotePage.generatePageResp()).execute().body();
if ((result != null) && (result.equals("OK"))) {
Log.d(getClass().getName(),String.format("Page %1$s uploaded.",getId().toString()));
setState(STATE_OK);
return true;
} else {
throw new IOException("Error in page upload");
Expand Down
Loading

0 comments on commit 56123a5

Please sign in to comment.