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 Jun 28, 2022
2 parents 56123a5 + 563752a commit 643e6ab
Show file tree
Hide file tree
Showing 54 changed files with 1,341 additions and 284 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
applicationId "fr.nuage.souvenirs"
minSdkVersion 24
targetSdkVersion 30
versionCode 20
versionName "2.5.0"
versionCode 21
versionName "2.6.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
setProperty("archivesBaseName", "souvenirs-$versionName")
}
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/fr/nuage/souvenirs/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
}


//display version
findPreference(NEXTCLOUD_VERSION).setSummary(BuildConfig.VERSION_NAME);
}

@Override
public void onPause() {
//refresh NCenabled status in case wifi setting change
NCUtils.updateNCState();
super.onPause();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
11 changes: 3 additions & 8 deletions app/src/main/java/fr/nuage/souvenirs/model/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public class Album {
public static final String STYLE_TILE = "TILE";

private String albumPath;
private MutableLiveData<String> ldName = new MutableLiveData<String>();
private MutableLiveData<String> ldName = new MutableLiveData<>();
private String name;
private MutableLiveData<ArrayList<Page>> ldPages = new MutableLiveData<ArrayList<Page>>();
private MutableLiveData<ArrayList<Page>> ldPages = new MutableLiveData<>();
private ArrayList<Page> pages = new ArrayList<Page>();
private Date pagesLastEditDate;
private MutableLiveData<Date> ldPagesLastEditDate = new MutableLiveData<>();
Expand Down Expand Up @@ -128,11 +128,6 @@ public String getDefaultStyle() {
return defaultStyle;
}

public void reload() {
if (!unsavedModifications) {
load();
}
}

public boolean load() {
Log.d(this.getClass().toString(),"Load Album "+albumPath);
Expand Down Expand Up @@ -229,7 +224,7 @@ public boolean load() {
}
}
} catch (JSONException e) {
Log.w(this.getClass().getSimpleName(),"Wrong file format for "+this.albumPath);
Log.w(this.getClass().getSimpleName(),"Wrong file format for "+this.albumPath,e);
return false;
}
updateAllLiveDataObject();
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/fr/nuage/souvenirs/model/Albums.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public void updateAlbumList() {
Album album = getAlbum(f.getPath());
if (album == null) {
albumList.add(new Album(f.getPath()));
} else {
album.reload();
}
}
}
Expand Down
85 changes: 85 additions & 0 deletions app/src/main/java/fr/nuage/souvenirs/model/AudioElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package fr.nuage.souvenirs.model;

import androidx.lifecycle.MutableLiveData;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.InputStream;

public class AudioElement extends Element {

private String audioPath;
private boolean stop;
private MutableLiveData<String> ldAudioPath = new MutableLiveData<>();
private MutableLiveData<Boolean> ldStop = new MutableLiveData<>();

public AudioElement(String audioPath, boolean stop) {
super();
setAudioPath(audioPath,false);
setStop(stop,false);
}

public AudioElement() {
this("",false);
}

@Override
public JSONObject completeToJSON(JSONObject json) throws JSONException {
json.put("audio",Utils.getRelativePath(pageParent.getAlbum().getAlbumPath(),audioPath));
json.put("stop",stop);
return json;
}

@Override
public void completeFromJSON(JSONObject jsonObject) throws JSONException {
if (jsonObject.has("audio")) {
setAudioPath(new File(pageParent.getAlbum().getAlbumPath(),jsonObject.getString("audio")).getPath(),false);
}
if (jsonObject.has("stop")) {
setStop(jsonObject.getBoolean("stop"),false);
}
}

public void setAudioPath(String audioPath, boolean save) {
this.audioPath = audioPath;
ldAudioPath.postValue(audioPath);
if (save) {
onChange();
}
}

public void setStop(boolean stop, boolean save) {
this.stop = stop;
ldStop.postValue(stop);
if (save) {
onChange();
}
}

public String getAudioPath() {
return audioPath;
}

public boolean isStop() {
return stop;
}

public MutableLiveData<String> getLdAudioPath() {
return ldAudioPath;
}

public MutableLiveData<Boolean> getLdStop() {
return ldStop;
}

public void setAudio(InputStream input, String mimeType) {
String audioPath = pageParent.getAlbum().createDataFile(input,mimeType);
if (audioPath != null) {
setAudioPath(audioPath,true);
} else {
setAudioPath("",true);
}
}
}
24 changes: 18 additions & 6 deletions app/src/main/java/fr/nuage/souvenirs/model/ImageElement.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fr.nuage.souvenirs.model;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.util.Log;

import androidx.lifecycle.MutableLiveData;

Expand All @@ -10,6 +12,7 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -21,12 +24,12 @@ public class ImageElement extends Element {
public static final int ZOOM_OFFSET = 2;
public static final String GOOGLE_PANORAMA_360_MIMETYPE = "application/vnd.google.panorama360+jpg";

private MutableLiveData<String> ldImagePath = new MutableLiveData<String>();
private MutableLiveData<Integer> ldTransformType = new MutableLiveData<>();
private MutableLiveData<Integer> ldZoom = new MutableLiveData<>();
private MutableLiveData<Integer> ldOffsetX = new MutableLiveData<>();
private MutableLiveData<Integer> ldOffsetY = new MutableLiveData<>();
private MutableLiveData<Boolean> ldIsPano = new MutableLiveData<>();
private final MutableLiveData<String> ldImagePath = new MutableLiveData<String>();
private final MutableLiveData<Integer> ldTransformType = new MutableLiveData<>();
private final MutableLiveData<Integer> ldZoom = new MutableLiveData<>();
private final MutableLiveData<Integer> ldOffsetX = new MutableLiveData<>();
private final MutableLiveData<Integer> ldOffsetY = new MutableLiveData<>();
private final MutableLiveData<Boolean> ldIsPano = new MutableLiveData<>();
private String imagePath;
private String mimeType;
private String name="";
Expand Down Expand Up @@ -154,6 +157,15 @@ public void setImage(InputStream input, String mimeType) {
}
}

public void setImage(Bitmap bitmap) {
File imFile = pageParent.getAlbum().createEmptyDataFile("image/jpeg");
try (FileOutputStream out = new FileOutputStream(imFile)) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (IOException e) {
Log.e(getClass().getName(),"Impossible to save image.",e);
}
setImage(imFile.getPath(),"image/jpeg");
}

/**
* This method set the image path attribute to element, without deleting the previous one.
Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/fr/nuage/souvenirs/model/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class Page {

private MutableLiveData<ArrayList<Element>> ldElementsList = new MutableLiveData<ArrayList<Element>>();
private final MutableLiveData<ArrayList<Element>> ldElementsList = new MutableLiveData<ArrayList<Element>>();
private ArrayList<Element> elementsList;
private Album albumParent;
private UUID id;
Expand Down Expand Up @@ -210,7 +210,7 @@ public int getNbTxt() {
public int getNbImage() {
int nb=0;
for (Element e: getElements()) {
if (e.getClass().equals(ImageElement.class)) {
if (e instanceof ImageElement) {
nb += 1;
}
}
Expand Down Expand Up @@ -277,4 +277,25 @@ public PaintElement createPaintElement() {
addElement(paintElement);
return paintElement;
}

public AudioElement createAudioElement() {
AudioElement audioElement = new AudioElement();
addElement(audioElement);
return audioElement;
}

public void removeAudio() {
for (Element e : getElements()) {
if (e.getClass().equals(AudioElement.class)) {
delElement(e);
return;
}
}
}

public VideoElement createVideoElement() {
VideoElement videoElement = new VideoElement();
addElement(videoElement);
return videoElement;
}
}
9 changes: 5 additions & 4 deletions app/src/main/java/fr/nuage/souvenirs/model/PageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static InputStream getInputStreamFromUri(ContentResolver cr, Uri uri) {
}

public void create(int style, AlbumViewModel albumVM, ArrayList<Uri> images, ArrayList<String> texts) {
create(style,albumVM,albumVM.getPages().getValue().size(),images,texts);
create(style,albumVM,albumVM.getLdPages().getValue().size(),images,texts);
}

/* create one page and import all image/text on the page, take default style
Expand Down Expand Up @@ -298,14 +298,15 @@ public void create(int style, AlbumViewModel albumVM, int position, ArrayList<Ur

public void switchStyle(int style, AlbumViewModel albumVM, Page page) {
//extract texts and images
ArrayList<String> texts = new ArrayList<String>();
ArrayList<Uri> images = new ArrayList<Uri>();
ArrayList<String> texts = new ArrayList<>();
ArrayList<Uri> images = new ArrayList<>();
//parse page and fill text and image arrays
for (Element e : page.getElements()) {
if (e.getClass().equals(TextElement.class)) {
texts.add(((TextElement)e).getText());
}
if (e.getClass().equals(ImageElement.class)) {
if (e instanceof ImageElement) {
//FIXME : will not work with video
images.add(Uri.fromFile(new File(((ImageElement)e).getImagePath())));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ public void create(int style, AlbumViewModel albumVM, int position, ArrayList<Ur
@Override
public void applyStyle(int style, Page page) {
//seperate txt and im elements
ArrayList<ImageElement> imageElementArrayList = new ArrayList<>();
ArrayList<Element> imageElementArrayList = new ArrayList<>();
ArrayList<TextElement> textElementArrayList = new ArrayList<>();
for (Element e : page.getElements()) {
if (e.getClass().equals(TextElement.class)) {
textElementArrayList.add((TextElement)e);
}
if (e.getClass().equals(ImageElement.class)) {
imageElementArrayList.add((ImageElement)e);
if (e instanceof ImageElement) {
imageElementArrayList.add(e);
}
}
//read style template and apply
Expand All @@ -176,7 +176,7 @@ public void applyStyle(int style, Page page) {
while ( (imCursor < imageElementArrayList.size()) || (txtCursor < textElementArrayList.size()) ) {
for (Object[] elDef: getPageStyleMap()[style]) {
if (imCursor < imageElementArrayList.size()) {
ImageElement e_img = imageElementArrayList.get(imCursor);
ImageElement e_img = (ImageElement) imageElementArrayList.get(imCursor);
if (e_img != null) {
e_img.setTop((int)elDef[1]);
e_img.setBottom((int)elDef[3]);
Expand Down
Loading

0 comments on commit 643e6ab

Please sign in to comment.