Skip to content

Commit af5b20d

Browse files
author
Reza Amuzadeh
committed
add new uri base update method
1 parent 228b2d5 commit af5b20d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

MagicalPEC/src/main/java/ir/vasl/magicalpec/utils/Core/MagicalPdfCore.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public boolean addOCG(PointF pointF, String filePath, int currPage, String refer
122122
}
123123
}
124124

125+
public boolean addOCG(Context context, PointF pointF, Uri uri, int currPage, String referenceHash, byte[] OCGCover) throws MagicalException {
126+
return addOCG(context, pointF, uri, currPage, referenceHash, OCGCover);
127+
}
128+
125129
public boolean addOCG(Context context, PointF pointF, Uri uri, int currPage, String referenceHash, byte[] OCGCover, float OCGWidth, float OCGHeight) throws MagicalException {
126130

127131
// Hint: OCG -> optional content group
@@ -303,4 +307,19 @@ public boolean updateOCG(PointF pointF, String filePath, int currPage, String re
303307

304308
}
305309

310+
public boolean updateOCG(Context context, PointF pointF, Uri uri, int currPage, String referenceHash, byte[] newOCGCover) throws MagicalException {
311+
312+
// remove old OCG
313+
if (!removeOCG(context, uri, referenceHash))
314+
throw new MagicalException("Cannot remove OCG with target reference");
315+
316+
// add new OCG
317+
if (!addOCG(context, pointF, uri, currPage, referenceHash, newOCGCover))
318+
throw new MagicalException("Cannot add new OCG with target reference");
319+
320+
// finish method
321+
return true;
322+
323+
}
324+
306325
}

MagicalPEC/src/main/java/ir/vasl/magicalpec/viewModel/MagicalPECViewModel.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void run() {
113113
}
114114

115115
public void removeAllOCGs() {
116+
// under construction
116117
}
117118

118119
public void updateOCG(PointF pointF, String filePath, int currPage, String referenceHash, byte[] newOCGCover) {
@@ -133,4 +134,22 @@ public void run() {
133134
});
134135
}
135136

137+
public void updateOCG(PointF pointF, Uri uri, int currPage, String referenceHash, byte[] newOCGCover) {
138+
MagicalPECViewModel.this.pecCoreStatus.postValue(PECCoreStatusEnum.PROCESSING);
139+
140+
new Handler().post(new Runnable() {
141+
@Override
142+
public void run() {
143+
// Code here will run in UI thread
144+
try {
145+
MagicalPdfCore.getInstance().updateOCG(getApplication(), pointF, uri, currPage, referenceHash, newOCGCover);
146+
MagicalPECViewModel.this.pecCoreStatus.postValue(PECCoreStatusEnum.SUCCESS);
147+
} catch (MagicalException e) {
148+
MagicalPECViewModel.this.pecCoreStatus.postValue(PECCoreStatusEnum.FAILED);
149+
e.printStackTrace();
150+
}
151+
}
152+
});
153+
}
154+
136155
}

0 commit comments

Comments
 (0)