Merge pull request #64 from spadarian/show_image_caption

Added option to show image title or alt as caption
This commit is contained in:
Shinokuni 2020-04-20 22:12:06 +02:00 committed by GitHub
commit 3c40d8eb23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 8 deletions

View File

@ -49,6 +49,9 @@ import com.readrops.app.utils.SharedPreferencesManager;
import com.readrops.app.utils.Utils;
import com.readrops.app.viewmodels.ItemViewModel;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.readrops.app.utils.ReadropsKeys.ACTION_BAR_COLOR;
import static com.readrops.app.utils.ReadropsKeys.IMAGE_URL;
import static com.readrops.app.utils.ReadropsKeys.ITEM_ID;
@ -79,6 +82,7 @@ public class ItemActivity extends AppCompatActivity {
private CoordinatorLayout rootLayout;
private String urlToDownload;
private String imageTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -282,15 +286,40 @@ public class ItemActivity extends AppCompatActivity {
.title(R.string.image_options)
.items(R.array.image_options)
.itemsCallback((dialog, itemView, position, text) -> {
if (position == 0)
shareImage(hitTestResult.getExtra());
else {
if (PermissionManager.isPermissionGranted(this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
downloadImage(hitTestResult.getExtra());
else {
switch (position) {
case 0:
shareImage(hitTestResult.getExtra());
break;
case 1:
if (PermissionManager.isPermissionGranted(this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
downloadImage(hitTestResult.getExtra());
else {
urlToDownload = hitTestResult.getExtra();
PermissionManager.requestPermissions(this, WRITE_EXTERNAL_STORAGE_REQUEST, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
break;
case 2:
urlToDownload = hitTestResult.getExtra();
PermissionManager.requestPermissions(this, WRITE_EXTERNAL_STORAGE_REQUEST, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
String content = webView.getItemContent();
Pattern p = Pattern.compile("(<img.*src=\"" + urlToDownload + "\".*>)");
Matcher m = p.matcher(content);
if (m.matches()) {
Pattern p2 = Pattern.compile("<img.*(title|alt)=\"(.*?)\".*>");
Matcher m2 = p2.matcher(content);
if (m2.matches()) {
imageTitle = m2.group(2);
} else {
imageTitle = "";
}
}
new MaterialDialog.Builder(this)
.title(urlToDownload)
.content(imageTitle)
.show();
break;
default:
throw new IllegalStateException("Unexpected value: " + position);
}
})

View File

@ -48,6 +48,11 @@ public class ReadropsWebView extends WebView {
loadData(base64Content, "text/html; charset=utf-8", "base64");
}
public String getItemContent() {
String content = itemWithFeed.getItem().getContent();
return content;
}
private void getColors(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ReadropsWebView);
textColor = typedArray.getColor(R.styleable.ReadropsWebView_textColor, 0);

View File

@ -129,5 +129,7 @@
<string name="auto_synchro_disabled">La synchronisation automatique est désactivée</string>
<string name="enable_auto_synchro_text">Les notifications nécessitent l\'activation de la synchronisation automatique pour fonctionner.\nVoulez-vous ouvrir les paramètres ?</string>
<string name="open">Ouvrir</string>
<string name="back">Retour</string>
<string name="show_caption">Afficher la légende</string>
</resources>

View File

@ -13,6 +13,7 @@
<string-array name="image_options">
<item>@string/share_image</item>
<item>@string/download_image</item>
<item>@string/show_caption</item>
</string-array>
<string-array name="items_per_feed_numbers_values">

View File

@ -136,4 +136,6 @@
<string name="auto_synchro_disabled">Automatic synchronization is disabled</string>
<string name="enable_auto_synchro_text">To be displayed, notifications need auto synchronization to be activated.\nDo you want to open settings ?</string>
<string name="open">Open</string>
<string name="back">Back</string>
<string name="show_caption">Show caption</string>
</resources>