Skip to content

Commit 160cc29

Browse files
committedApr 18, 2024
Better style selection on 2 element page and dynamic style on remove element.
1 parent 3bcae93 commit 160cc29

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed
 

‎app/src/main/java/fr/nuage/souvenirs/model/Page.java

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public void delElement(Element element) {
8787
tmp.remove(element);
8888
setElements(tmp);
8989
}
90+
new TilePageBuilder().applyDefaultStyle(this);
9091
}
9192

9293
public ImageElement createImageElement() {

‎app/src/main/java/fr/nuage/souvenirs/model/TilePageBuilder.java

+32-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import android.content.ContentResolver;
66
import android.net.Uri;
7+
import android.provider.ContactsContract;
78
import android.util.Log;
89
import android.view.LayoutInflater;
910
import android.view.View;
@@ -32,7 +33,7 @@ public class TilePageBuilder {
3233
{ 0, 0, 100, 100 }
3334
},
3435
{
35-
// 2 V (1 small)
36+
// 2 V (1 small) -> title style
3637
{ 0, 0, 100, 80 },
3738
{ 0, 80, 100, 100 }
3839
},
@@ -278,14 +279,38 @@ public void applyStyle(int style, Page page) {
278279
}
279280

280281
public int getDefaultStyle(Page page) {
281-
int defStyle=-1;
282-
for (int i=0;i<getPageStyleMap().length;i++) {
283-
int visibleElements = 0;
284-
for (Element element: page.getElements()) {
285-
if ((element instanceof ImageElement) || (element instanceof TextElement)) {
286-
visibleElements += 1;
282+
int visibleElements = 0;
283+
boolean hasTextElement = false;
284+
boolean areAllPortrait = true;
285+
for (Element element: page.getElements()) {
286+
if ((element instanceof ImageElement) || (element instanceof TextElement) || (element instanceof VideoElement)) {
287+
visibleElements += 1;
288+
}
289+
if (element instanceof TextElement) {
290+
hasTextElement = true;
291+
}
292+
if (element instanceof ImageElement) {
293+
if (!Utils.isImagePortrait((ImageElement)element)) {
294+
areAllPortrait = false;
287295
}
288296
}
297+
}
298+
//for 2 elements
299+
if (visibleElements == 2) {
300+
//if text, apply title style
301+
if (hasTextElement) {
302+
return 1;
303+
}
304+
//if images, test if portrait or landscape
305+
if (areAllPortrait) {
306+
return 3;
307+
} else {
308+
return 2;
309+
}
310+
}
311+
//generic : choose first matching style in list
312+
int defStyle=-1;
313+
for (int i=0;i<getPageStyleMap().length;i++) {
289314
if (getPageStyleMap()[i].length == visibleElements) {
290315
defStyle = i;
291316
break;

‎app/src/main/java/fr/nuage/souvenirs/model/Utils.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ public static void copyFileUsingStream(File source, File dest) throws IOExceptio
3838
}
3939
}
4040

41+
public static boolean isImagePortrait(ImageElement element) {
42+
return element.getImageHeight() > element.getImageWidth();
43+
}
44+
4145
public static class NextcloudFile {
4246

43-
private String filePath;
44-
private boolean isDir;
45-
private long modDate;
47+
private final String filePath;
48+
private final boolean isDir;
49+
private final long modDate;
4650

4751
public NextcloudFile(String filePath, boolean isDir, long modDate) {
4852
this.filePath = filePath;

0 commit comments

Comments
 (0)
Failed to load comments.