Skip to content

Commit

Permalink
Added images to Pages. A lot of refactoring is now imperative.
Browse files Browse the repository at this point in the history
  • Loading branch information
aiman-al-masoud committed Aug 2, 2021
1 parent 11c7d0a commit aa5dbad
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.luxlunaris.noadpadlight.control.classes;

import android.util.Log;

import com.luxlunaris.noadpadlight.control.interfaces.NotebookListener;
import com.luxlunaris.noadpadlight.control.interfaces.PageListener;
import com.luxlunaris.noadpadlight.control.interfaces.Pageable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Paths {
public static String PAGES_BACKUP_DIR = Paths.APP_DIR_PATH+File.separator+"pages_backup";


public static String TMP_DIR = Paths.APP_DIR_PATH+File.separator+"tmp";
//public static String TMP_DIR = Paths.APP_DIR_PATH+File.separator+"tmp";



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public void compact(List<Page> pages, Page blankPage){
}

blankPage.setText(textBlob);

//TODO: migrate images

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.luxlunaris.noadpadlight.model.classes;

import android.text.Html;
import android.util.Log;

import com.luxlunaris.noadpadlight.control.interfaces.PageListener;
import com.luxlunaris.noadpadlight.model.interfaces.Metadata;
import com.luxlunaris.noadpadlight.model.interfaces.Page;
Expand All @@ -26,6 +29,12 @@ public class SinglePage extends File implements Page {
*/
File textFile;



File imageDir;



/**
* this Page's listeners (Notebook)
*/
Expand All @@ -50,6 +59,7 @@ public SinglePage(String pathname) {
super(pathname);
metadata = new MetadataFile(getPath()+File.separator+"metadata");
textFile = new File(getPath()+File.separator+"text");
imageDir = new File(getPath()+File.separator+"images");
listeners = new ArrayList<>();
}

Expand All @@ -69,6 +79,7 @@ public String getText() {
*/
@Override
public void setText(String text) {
Log.d("TEST_IMAGE", "saving: "+text);
FileIO.write(textFile.getPath(), text);
for(PageListener listener : listeners){
listener.onModified(this);
Expand All @@ -83,15 +94,17 @@ public void setText(String text) {
*/
@Override
public boolean delete() {
textFile.delete();
((MetadataFile)metadata).delete();
boolean del = super.delete();
//textFile.delete();
//((MetadataFile)metadata).delete();
//boolean del = super.delete();
FileIO.deleteDirectory(this.getPath());

//notify the listeners that this got deleted
for(PageListener listener : listeners){
listener.onDeleted(this);
}
return del;
//return del;
return true;
}

/**
Expand All @@ -104,6 +117,7 @@ public void create() {
try {
((MetadataFile)metadata).createNewFile();
textFile.createNewFile();
imageDir.mkdir();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -268,7 +282,7 @@ public void addListener(PageListener listener) {
*/
@Override
public String getPreview() {
return FileIO.readLine(textFile.getPath())+"...\n" +new Date(getLastModifiedTime()).toString();
return FileIO.readLine(textFile.getPath())+"\n" +new Date(getLastModifiedTime()).toString();
}

/**
Expand All @@ -278,7 +292,8 @@ public String getPreview() {
* @return
*/
public boolean contains(String[] keywords){
String text = getText().toUpperCase();
//String text = getText().toUpperCase();
String text = Html.fromHtml(getText()).toString().toUpperCase();
for(String keyword : keywords){
if(!text.contains(keyword.toUpperCase())){
return false;
Expand Down Expand Up @@ -310,6 +325,22 @@ public void setSelected(boolean selected) {
}


@Override
public void addImage(String path, int position) {

File imageCopy = new File(imageDir.getPath()+File.separator+System.currentTimeMillis());
FileIO.copyFile(path, imageCopy.getPath());

String text = getText();

String partBefore = text.substring(0, position);
String partAfter = text.substring(position, text.length()-1);
String tag = "<img src=\'"+imageCopy.getPath()+"\' />";
text = partBefore+" "+tag+" "+partAfter;

setText(text);
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,14 @@ public interface Page extends Serializable {
public void setSelected(boolean select);


/**
* Add an image to this Page.
* @param path
* @param position
*/
public void addImage(String path, int position);




}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.luxlunaris.noadpadlight.model.services;

import android.os.Build;

import androidx.annotation.RequiresApi;

import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.exception.ZipException;

import org.apache.commons.io.FileUtils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -11,6 +17,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;

public class FileIO {

Expand Down Expand Up @@ -135,6 +142,23 @@ public static File unzipDir(String zippedPath, String destPath) {
}


public static void copyFile(String sourcePath, String destPath){

try {
FileUtils.copyFile(new File(sourcePath), new File(destPath));
} catch (IOException e) {
e.printStackTrace();
}
}

public static void deleteDirectory(String path){
try {
FileUtils.deleteDirectory(new File(path));
} catch (IOException e) {
e.printStackTrace();
}
}




Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/luxlunaris/noadpadlight/ui/ImageGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.luxlunaris.noadpadlight.ui;

import android.graphics.drawable.Drawable;
import android.text.Html;
import android.util.Log;

public class ImageGetter implements Html.ImageGetter {


@Override
public Drawable getDrawable(String source) {

Log.d("TEST_TEST", source);

Drawable d = Drawable.createFromPath(source);
d.setBounds(0,0,d.getIntrinsicWidth(),d.getIntrinsicHeight());


Log.d("TEST_TEST", d.toString());

return d;

}
}
Loading

0 comments on commit aa5dbad

Please sign in to comment.