mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-06 13:33:26 +01:00
Merge pull request #64 from spadarian/show_image_caption
Added option to show image title or alt as caption
This commit is contained in:
commit
3c40d8eb23
@ -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);
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -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);
|
||||
|
@ -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>
|
@ -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">
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user