I'm trying to put a placeholder image if the album art doesn't exist. For some reason the image from representativeItem is never null so it simply assigns a blank artwork...
MPMediaItemArtwork *artwork = [[mediaListItem representativeItem] valueForProperty:MPMediaItemPropertyArtwork];
if (artwork) {
sModel.albumImage = [artwork imageWithSize: CGSizeMake (10, 10)];
} else {
sModel.albumImage = [UIImage imageNamed:#"Default_.png"]; //never enters
}
Found the solution, I'm a genius ;)
MPMediaItemArtwork *artwork = [[mediaListItem representativeItem] valueForProperty:MPMediaItemPropertyArtwork];
//If artwork has no size set place holder
if (CGSizeEqualToSize(artwork.bounds.size, CGSizeZero))
{
sModel.albumImage = [UIImage imageNamed:DEFAULT_IMG];
}
else //Otherwise set the artwork found in the library.
{
sModel.albumImage = [artwork imageWithSize: CGSizeMake (SIZE_X, SIZE_Y)];
}
Related
Quick question.
While I write away my data to my firebase database I'd like to order it.
since i'm making an Album collection list I'd love to have it like the picture underneath.. but with bands and albums tho.
the only problem is that I can't read my write string.. in this case $Uname
I can only read the data correctly if I hardcode the location in my .getReference()
my data upload code:
//values
val number = Number_tv.text.toString()
val Uname = Username_TV.text.toString()
val ref = FirebaseDatabase.getInstance().getReference("/userdata/$Uname/$number _key")
val user = User(Username_TV.text.toString(), Email_TV.text.toString(), albumimageURL)
//code
if (number.isEmpty()){
Toast.makeText(this, "Number is empty", Toast.LENGTH_SHORT).show()
}
else{
ref.setValue(user)
.addOnSuccessListener {
Log.d("mainacti", "upload succesful")
}
.addOnFailureListener {
Log.d("mainacti", "I do not work")
}}
}
my data download code:
val ref = FirebaseDatabase.getInstance().getReference("/userdata/Heinz")
ref.addListenerForSingleValueEvent(object: ValueEventListener{
override fun onDataChange(p0: DataSnapshot) {
val adapter = GroupAdapter<GroupieViewHolder>()
p0.children.forEach {
Log.d("Albumlist", it.toString())
val user = it.getValue(User::class.java)
if (user != null){
adapter.add(UserItem(user))
}
}
recyclerview_album.adapter = adapter
}
override fun onCancelled(error: DatabaseError) {
}
})
}
Both codes are in different classes
here's a Log for the reference ("/userdata")
2021-04-16 13:00:42.080 6914-6914/com.example.firetrier D/Albumlist: DataSnapshot { key = Hans, value = {1 _key={albumimageURL=https://firebasestorage.googleapis.com/v0/b/fireupload-4be26.appspot.com/o/albumcover%2Fcb06a4c4-8795-4103-99ef-c2bd55498b2e?alt=media&token=7d3d305e-c266-41fb-b466-cab548fbdd35, email=hans#test.com, username=Hans}} }
2021-04-16 13:00:42.088 6914-6914/com.example.firetrier D/Albumlist: DataSnapshot { key = Heinz, value = {1 _key={albumimageURL=https://firebasestorage.googleapis.com/v0/b/fireupload-4be26.appspot.com/o/albumcover%2Ff00f6651-9ccf-4533-8e1c-af103a1a17e6?alt=media&token=b6e4ad2f-cb4f-47d5-8f00-02bdc4765c00, email=Heinz#doof.com, username=Heinz}, 5 _key={albumimageURL=https://firebasestorage.googleapis.com/v0/b/fireupload-4be26.appspot.com/o/albumcover%2Fc9bb80aa-15a2-48cb-b6f5-6b7a59b11d8d?alt=media&token=facd516d-c3e3-4b61-aa09-23ea9062ccd3, email=hans#test.com, username=Heinz}} }
is there a way to use the value instead of the key?
if I adapt the reference to one of the usernames this is the log
2021-04-16 13:05:54.028 7629-7629/com.example.firetrier D/Albumlist: DataSnapshot { key = 1 _key, value = {albumimageURL=https://firebasestorage.googleapis.com/v0/b/fireupload-4be26.appspot.com/o/albumcover%2Ff00f6651-9ccf-4533-8e1c-af103a1a17e6?alt=media&token=b6e4ad2f-cb4f-47d5-8f00-02bdc4765c00, email=Heinz#doof.com, username=Heinz} }
2021-04-16 13:05:54.040 7629-7629/com.example.firetrier D/Albumlist: DataSnapshot { key = 5 _key, value = {albumimageURL=https://firebasestorage.googleapis.com/v0/b/fireupload-4be26.appspot.com/o/albumcover%2Fc9bb80aa-15a2-48cb-b6f5-6b7a59b11d8d?alt=media&token=facd516d-c3e3-4b61-aa09-23ea9062ccd3, email=hans#test.com, username=Heinz} }
Before explaining I need to say EVERYTHING is working perfect on Android and the problem is on IOS devices I am using react-native-signature-capture , I have two signature field at the same page, I solve the problem of not getting saved but when I save one of the field both of them get the same value for the signature .
How can I handle it?
codes for signature component here
This is the extraInputsList logs in the codes
and this is my RSSSignatureViewManager.m file
#import "RSSignatureViewManager.h"
#import <React/RCTBridgeModule.h>
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTUIManager.h>
#implementation RSSignatureViewManager
#synthesize bridge = _bridge;
#synthesize signView;
RCT_EXPORT_MODULE()
RCT_EXPORT_VIEW_PROPERTY(rotateClockwise, BOOL)
RCT_EXPORT_VIEW_PROPERTY(square, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showBorder, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showNativeButtons, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showTitleLabel, BOOL)
-(dispatch_queue_t) methodQueue
{
return dispatch_get_main_queue();
}
-(UIView *) view
{
self.signView = [[RSSignatureView alloc] init];
self.signView.manager = self;
return signView;
}
// Both of these methods needs to be called from the main thread so the
// UI can clear out the signature.
RCT_EXPORT_METHOD(saveImage:(nonnull NSNumber *)reactTag) {
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
RSSignatureView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[RSSignatureView class]]) {
RCTLogError(#"Cannot find NativeView ", reactTag);
return;
}
[view saveImage];
}];
}
RCT_EXPORT_METHOD(resetImage:(nonnull NSNumber *)reactTag) {
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
RSSignatureView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[RSSignatureView class]]) {
RCTLogError(#"Cannot find NativeView with tag", reactTag);
return;
}
[view erase];
}];
}
-(void) publishSaveImageEvent:(NSString *) aTempPath withEncoded: (NSString *) aEncoded {
[self.bridge.eventDispatcher
sendDeviceEventWithName:#"onSaveEvent"
body:#{
#"pathName": aTempPath,
#"encoded": aEncoded
}];
}
-(void) publishDraggedEvent {
[self.bridge.eventDispatcher
sendDeviceEventWithName:#"onDragEvent"
body:#{#"dragged": #YES}];
}
#end
Solution
just install this package from this git
you can edit package.json like this
"react-native-signature-capture": "git+https://github.com/nomi9995/react-native-signature-capture.git",
Then do yarn install, react-native link react-native-signature-capture, and finally, it works great when I have multiple signature-pads!
UPDATE:
Both the Android and iOS versions save images from any signature box to the same path/filename. To support multiple boxes, you'll need to deal with the encoding/file sequentially. Or you can overload/change the saveImage method to take a filename.
Looks every time you save an image, this library will actively delete the previous image.
Android version from RSSignatureCaptureMainView.java:140
final void saveImage() {
String root = Environment.getExternalStorageDirectory().toString();
// the directory where the signature will be saved
File myDir = new File(root + "/saved_signature");
// make the directory if it does not exist yet
if (!myDir.exists()) {
myDir.mkdirs();
}
// set the file name of your choice
String fname = "signature.png";
// in our case, we delete the previous file, you can remove this
File file = new File(myDir, fname);
if (file.exists()) {
file.delete();
}
.
.
.
iOS version from RSSignatureView.m:186
-(void) saveImage {
saveButton.hidden = YES;
clearButton.hidden = YES;
UIImage *signImage = [self.sign signatureImage: _rotateClockwise withSquare:_square];
saveButton.hidden = NO;
clearButton.hidden = NO;
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:#"/signature.png"];
//remove if file already exists
if ([[NSFileManager defaultManager] fileExistsAtPath:tempPath]) {
[[NSFileManager defaultManager] removeItemAtPath:tempPath error:&error];
if (error) {
NSLog(#"Error: %#", error.debugDescription);
}
}
.
.
.
Previous answer:
This looks to be a known issue.
In RSSignatureViewManager.m, add #import <React/RCTUIManager.h>
and change the method RCT_EXPORT_METHOD to the following
RCT_EXPORT_METHOD(saveImage:(nonnull NSNumber *)reactTag) {
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
RSSignatureView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[RSSignatureView class]]) {
RCTLogError(#"Cannot find NativeView with tag #%#", reactTag);
return;
}
[view saveImage];
}];
}
I've got an Object item.movieimage that contain some texts (item:Object) that is retrieve from my database. The text is changing every week automatically.
If I do trace(item.movieimage) the output is something like this :
text1
text2
text3
text4
The words changes as the code is taking them from my database. The database changes the words every week.
Now, I want my AS3 code to display the third element of item.movieimage.
I've tried to do this :
var my_str:String = item.movieimage+",";
var ary:Array = my_str.split(",");
trace(ary[2]);
But it's not working. The output is "undefined".
Do you know how can I access a specific item in the Array that I've created ? Or how can I access the third item of item.movieimage ?
If I do trace(ary);, the output is :
text1,
text2,
text3,
text4,
EDIT :
For infos :
trace(typeof(item.movieimage)) and trace(typeof(ary)) are :
typeof(item.movieimage)=string
typeof(ary)=object
EDIT 2 :
Here's a screen capture of item.movieimage
Screen Cap of item.movieimage
EDIT 3
Here's my code in order to understand how "item.movieimage"is working
//Variables for downloading content from my database to my AS3 code
var urlReqSearchAll: URLRequest = new URLRequest("http://www.myWebSite/searchMovie4.php");
var loader5:URLLoader = new URLLoader();
//downloading content
function searchAll():void {
if (contains(list)){
list.removeChildren();
}
urlReqSearchAll.method = URLRequestMethod.POST;
loader5.load(urlReqSearchAll);
loader5.addEventListener(Event.COMPLETE,complete);
var variables:URLVariables = new URLVariables();
}
//Content Downloaded.
function complete(e:Event):void {
addChild(list);
products = JSON.parse(loader5.data) as Array;
hourSaved.data.saved=loader5.data;
products.reverse();
for(var i:int = 0; i < products.length; i++){
createListItem(i, products[i]);
}
displayPage(0);
showList();
}
// If too much items --> creates multiple page
const itemsPerPage:uint = 7;
var currentPageIndex:int = 0;
function displayPage(pageIndex:int):void {
list.removeChildren();
currentPageIndex = pageIndex;
var firstItemIndex:int = pageIndex * itemsPerPage;
var j:int = 0;
var lastItemIndex: int = firstItemIndex + 7; // as lastItemIndex should be 10 more
if (lastItemIndex > products.length) // if lastindex is greater than products length
lastItemIndex = products.length;
for(var i:int = firstItemIndex; i< lastItemIndex; i++){
createListItem( j, products[i]); // j control the position and i points to particular element of array..
j++;
}
next.visible = lastItemIndex < products.length - 1;
if(currentPageIndex==0){
previous.visible=false;
}
}
// Display the information downloded from my database
function createListItem(index:int, item:Object):void {
var listItem:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();
myFormat.size = item.title.length > 13 ? 22 : 26
listItem.multiline = true;
listItem.wordWrap = true;
myFormat.align = TextFormatAlign.CENTER;
myFormat.color = 0xA2947C;
myFormat.font = "Ebrima";
myFormat.bold = true;
listItem.defaultTextFormat = myFormat;
listItem.x = 135;
listItem.y = 123+ index * 84;
listItem.width = 200;
listItem.height = 80;
listItem.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
showDetails(item);
});
list.addChild(listItem);
str = item.title;
}
My php file "SearchMovie4.php" is like this :
$products = array();
while ($row = mysql_fetch_array($sql_result)) {
$products[] = array(
"title" => $row["theTitle"],
"movieimage" => $row["movieimage"],
"movielength" => $row["movielength"],
"story" => $row["story"],
);
}
echo json_encode($products);
So, if I do trace(item.movieimage) in AS3 code, it will display all the items in the row movieimage of my database.
If I do trace(item.title) in AS3 code, it will display all the items in the row title of my database.
What I'd like is to be able to do, in my AS3 code, trace(item.movieimage[2]) in order to show me the third item in the row "movieimage".
Well, the text you've provided to the movieimage property of the item object has not the same delimiter as what you have provided to the split() method; in your case the character of comma!
I suspect the delimiter you have, is the "space" character or a new-line character, like the character of carriage retrun.
In the following code snippet, I've used the "space" as the delimiter character:
var item:Object = new Object();
item.movieimage = "text1 text2 text3 text4";
var my_str:String = item.movieimage;
var ary:Array = my_str.split(" ");
trace(ary[2]); // text3
As #someOne said the output shows the list items are each on a new line, so you need to split() against newlines. One of these should work:
// if server uses "\n" newline char
var movies:Array = item.movieimage.split("\n");
// if server uses "\r" carriage return char
var movies:Array = item.movieimage.split("\r");
// if you aren't sure or there's a mixture of newline chars
var movies:Array = item.movieimage.split(/[\r|\n]+/);
Also note that if you have any control over how the server returns these values, you should just return a JSON array (since I see in your screenshot you are already decoding JSON), then you won't have to do any string splitting.
How to Create Profile Property Through Code in DNN (DotNetNuke)?
I tried this code:
DotNetNuke.Entities.Profile.ProfilePropertyDefinition def =
DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Level");
if (def != null)
{
def.DataType = 10;
def.Length = 40;
def.PropertyValue = "Level";
def.PropertyName = "Level";
oUser.Profile.ProfileProperties.Add(def);
}
oUser.Profile.SetProfileProperty("Level", ddlLevel.SelectedItem.Text.ToString().Trim());
DotNetNuke.Entities.Profile.ProfileController.UpdateUserProfile(oUser, oUser.Profile.ProfileProperties);
But it won't work, please help me with suitable solution.
try out this code for adding Profile Property:
if (DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Level") == null)
{
DotNetNuke.Entities.Profile.ProfileController.AddPropertyDefinition(
new DotNetNuke.Entities.Profile.ProfilePropertyDefinition(this.PortalId)
{
PropertyName = "Name",
DataType = 10,
...
});
}
Currently I am working on a new traveling website, but am having problems with 1 thing:
I have a list with all the country's, regions and city's i want to publish. How do I quickly create a page for all of them like this:
Every page should be a subpage like: country/region/city
Every page should have a certain page template
Please let me know, thanks in advance for your time and information!
You can do something like this.
<?php
// $country_list = get_country_list(); // returns list, of the format eg. array('India' => 'Content for the country India', 'Australia' => 'Content for the country Australia')
// $region_list = get_region_list($country); // Get the list of regions for given country, Assuming similar format as country.
// $city_list = get_city_list($region); // Get the list of cities for given region, Assuming similar format as country
/* Code starts here...*/
$country_list = get_country_list();
foreach($country_list as $country_title => $country_content) {
$country_template = 'template_country.php';
$country_page_id = add_new_page($country_title, $country_content, $country_template);
// validate if id is not 0 and break loop or take needed action.
$region_list = get_region_list($country_title);
foreach($region_list as $region_title => $region_content) {
$region_template = 'template_region.php';
$region_page_id = add_new_page($region_title, $region_content, $region_template, $country_page_id);
// validate if id is not 0 and break loop or take needed action.
$city_list = get_city_list($region_title);
foreach($city_list as $city_title => $city_content) {
$city_template = 'template_city.php';
add_new_page($city_title, $city_content, $city_template, $region_page_id);
}
}
}
function add_new_page($title, $content, $template_file, $post_parent = 0) {
$post = array();
$post['post_title'] = $title;
$post['post_content'] = $content;
$post['post_parent'] = $post_parent;
$post['post_status'] = 'publish'; // Can be 'draft' / 'private' / 'pending' / 'future'
$post['post_author'] = 1; // This should be the id of the author.
$post['post_type'] = 'page';
$post_id = wp_insert_post($post);
// check if wp_insert_post is successful
if(0 != $post_id) {
// Set the page template
update_post_meta($post_id, '_wp_page_template', $template_file); // Change the default template to custom template
}
return $post_id;
}
Warning: Make sure that the is executed only once or add any validation to avoid duplicate pages.