AdMob not working with IF statement? - if-statement

This code doesn't work. I checked displayLanguage value. Value is right (displayLanguage="Türkçe"). But it doesn't work.
private void setAdvertisement()
{
Locale _locale = Locale.getDefault();
String displayLanguage = _locale.getDisplayLanguage();
if(displayLanguage == "Türkçe")
{
// Create the adView
adView = new AdView(this, AdSize.BANNER, "My Admob ID");
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout"
// Add the adView to it
linearLayoutAdvertisement.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
}
But this code works fine:
private void setAdvertisement()
{
// Create the adView
adView = new AdView(this, AdSize.BANNER, "My Admob ID");
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout"
// Add the adView to it
linearLayoutAdvertisement.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
I don't understand what the problem is.

This isn't an AdMob issue. But try this:
if ("Türkçe".equals(displayLanguage)) {
..
}

I solved problem. This worked for me:
if(Locale.getDefault().getLanguage().equals("tr"))
{
...
}

Related

How to fill state/region/subregion selections when page is opened in edit mode?

In Laravel 8/livewire 2/aplinejs I need to fill state/region/subregion, which are tables in db
and I select subregion from priorly selected regions and select regions from priorly selected, like
public function updatedSelectedState($state_id)
{
$this->regionsSelectionArray = Region::getRegionsSelectionArray($state_id, 'A');
$this->detailsForm['state_id'] = $state_id;
}
public function updatedSelectedRegion($region_id)
{
$this->subregionsSelectionArray = Subregion::getSubregionsSelectionByRegionIdArray($region_id);
$this->selectedSubregion = null;
}
it works ok for data inserting , but when I open editor in “edit” mode and I neeed to fill initvalue I
failed how do it. I remember when I made similar tasks with jquery I have common bool var which I set to true
when jquery was inited. And in onChange event I checked this var .
But how can I do it in livewire ?
Thanks in advance!
Call the below functions in your edit method
Example:
public function updatedSelectedState($state_id)
{
$this->changeSelectedState($state_id);
}
public function updatedSelectedRegion($region_id)
{
$this->changeSelectedRegion($region_id);
}
public function changeSelectedState($state_id){
$this->regionsSelectionArray = Region::getRegionsSelectionArray($state_id, 'A');
$this->detailsForm['state_id'] = $state_id;
}
public function changeSelectedRegion($region_id)
{
$this->subregionsSelectionArray = Subregion::getSubregionsSelectionByRegionIdArray($region_id);
$this->selectedSubregion = null;
}
public function edit(){
// $state_id = provide your state id here
// $region_id = provide your region id here
$this->changeSelectedState($state_id);
$this->changeSelectedRegion($region_id);
}

Using Persistent Flash Message Library for ColdFusion

I am trying to use a library for showing Flash Messages https://github.com/elpete/flashmessage But I am having trouble getting it working correctly. The documentation isn't that great and I am new to ColdFusion. I want to have the ability to have persistent error messages across pages. Specifically during checkout so when the user needs to go back or a validation error occurs the message will appear. According to the documentation:
The FlashMessage.cfc needs three parameters to work:
A reference to your flash storage object. This object will need
get(key) and put(key, value) methods. A config object with the
following properties: A unique flashKey name to avoid naming
conflicts. A reference to your containerTemplatePath. This is the view
that surrounds each of the individual messages. It will have
references to a flashMessages array and your messageTemplatePath. A
reference to your messageTemplatePath. This is the view that
represents a single message in FlashMessage. It will have a reference
to a single flash message. The name is chosen by you in your container
template. Create your object with your two parameters and then use it
as normal.
I am getting the error
the function getMessages has an invalid return value , can't cast null value to value of type [array]
I had this script somewhat working at one point but it seems very finicky. I believe it is my implementation of it. I am hoping someone here can help me figure out where I went wrong. Or give me some pointers because I am not sure I am even implementing it correctly.
This is What I have in my testing script:
<cfscript>
alertStorage = createObject("component", 'alert');
config = {
flashKey = "myCustomFlashKey",
containerTemplatePath = "/flashmessage/views/_templates/FlashMessageContainer.cfm",
messageTemplatePath = "/flashmessage/views/_templates/FlashMessage.cfm"
};
flash = new flashmessage.models.FlashMessage(alertStorage, config);
flash.message('blah');
flash.danger('boom');
</cfscript>
And inside of alert.cfc I have:
component {
public any function get(key) {
for(var i = 1; i < ArrayLen(session[key]); i++) {
return session[key][i];
}
}
public any function put(key, value) {
ArrayAppend(session.myCustomFlashKey, value);
return true;
}
public any function exists() {
if(structKeyExists(session,"myCustomFlashKey")) {
return true;
} else {
session.myCustomFlashKey = ArrayNew();
return false;
}
}
}
The Flash Message Component looks like this:
component name="FlashMessage" singleton {
/**
* #flashStorage.inject coldbox:flash
* #config.inject coldbox:setting:flashmessage
*/
public FlashMessage function init(any flashStorage, any config) {
instance.flashKey = arguments.config.flashKey;
singleton.flashStorage = arguments.flashStorage;
instance.containerTemplatePath = arguments.config.containerTemplatePath;
instance.messageTemplatePath = arguments.config.messageTemplatePath;
// Initialize our flash messages to an empty array if it hasn't ever been created
if (! singleton.flashStorage.exists(instance.flashKey)) {
setMessages([]);
}
return this;
}
public void function message(required string text, string type = "default") {
appendMessage({ message: arguments.text, type = arguments.type });
}
public any function onMissingMethod(required string methodName, required struct methodArgs) {
message(methodArgs[1], methodName);
}
public any function render() {
var flashMessages = getMessages();
var flashMessageTemplatePath = instance.messageTemplatePath;
savecontent variable="messagesHTML" {
include "#instance.containerTemplatePath#";
}
setMessages([]);
return messagesHTML;
}
public array function getMessages() {
return singleton.flashStorage.get(instance.flashKey, []);
}
private void function setMessages(required array messages) {
singleton.flashStorage.put(
name = instance.flashKey,
value = arguments.messages
);
}
private void function appendMessage(required struct message) {
var currentMessages = getMessages();
ArrayAppend(currentMessages, arguments.message);
setMessages(currentMessages);
}
}

Using protractorjs and mocha how do I read all links on a site?

I'm trying to read all HREF links on a site using protractor and mocha
I am not "married" to any of the technologies, but I'm under the impression that these are the current best in class technologies for driving selenium.
I'm working with the protractor Mocha example file that came with the project which I have tuned from the example code to read:
before(function() {
driver = new webdriver.Builder().
usingServer('http://localhost:4444/wd/hub').
withCapabilities(webdriver.Capabilities.chrome()).build();
driver.manage().timeouts().setScriptTimeout(10000);
ptor = protractor.wrapDriver(driver);
});
function Log(obj){
console.log(JSON.stringify(obj));
}
it.only('should read all HREFS', function(done){
ptor.get('http://www.angularjs.org');
var elements = ptor.findElements(protractor.By.tagName('a'));
Log(protractor.By.tagName('a'));
// {"using":"tag name","value":"a"}
Log(elements);
// Result: {}
// Expected: a full list of every 'a' tag element on the angularjs homepage
});
What appears to be happening is the "elements" list is returning immediately as opposed to after the page loads.
How do I deal with that in selenium+protractor?
OK - so turns out the Async was messing me up a little.
I've tuned the code to make this do what I've asked for above.
it.only('should read all HREFS', function(done){
ptor.get('http://www.angularjs.org');
var elements = ptor.findElements(protractor.By.tagName('a'));
Log(protractor.By.tagName('a'));
Log(elements);
var a = driver.findElements(webdriver.By.tagName('a'));
for (var element in a) {
Log(element);
}
// NOTE ***********************************
// this here is the "answer" the asynchonous nature of javascript means that I
// do not have have access to the contents of the request until I am inside the "then"
// response
//
// from there I have to use the same structure when executing the getAttribute method
a.then(function(elements){
for (var i = 0; i < elements.length; i++){
var link = elements[i];
link.getAttribute('href')
.then(function(value){
Log(value);
});
}
for (e in elements){
var link = elements[e];
Log(link.getTagName());
// I left this in my debugging code for the stackoverflow reader who might
// want to know what other functions they can execute on the LINK object
for (attribute in link) {
Log(attribute);
// "then"
// "cancel"
// "isPending"
// "errback"
// "driver_"
// "id_"
// "constructor"
// "getDriver"
// "toWireValue"
// "schedule_"
// "findElement"
// "isElementPresent"
// "findElements"
// "click"
// "sendKeys"
// "getTagName"
// "getCssValue"
// "getAttribute"
// "getText"
// "getSize"
// "getLocation"
// "isEnabled"
// "isSelected"
// "submit"
// "clear"
// "isDisplayed"
// "getOuterHtml"
// "getInnerHtml"
// "addCallback"
// "addErrback"
// "addBoth"
// "addCallbacks"
}
};
});
});

symfony2.1 translatable saved, but not retrieved

Basically, I had the same problem as here:
Symfony2 & Translatable : entity's locale is empty
Translations where saved in the ext_translations table, but where not being displayed.
After adding the proposed fix, it DID work.
Today I upgraded from 2.0 to 2.1 I managed to get pretty much everything working so far.
But now my translatables are again not being displayed properly (they ARE still being saved properly).
I think it has something to do with the changes to where and how the users locale is stored in 2.1 compared to 2.0 .. but i cannot figure this one out.
Fixed this by registering a custom listener
namespace XXX;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LocaleListener implements EventSubscriberInterface
{
private $defaultLocale;
public function __construct($defaultLocale = 'en')
{
$this->defaultLocale = $defaultLocale;
}
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
if ($locale = $request->attributes->get('_locale')) {
$request->getSession()->set('_locale', $request->getLocale());
} else {
$request->setDefaultLocale($request->getSession()->get('_locale', $this->defaultLocale));
}
}
static public function getSubscribedEvents()
{
return array(
// must be registered before the default Locale listener
KernelEvents::REQUEST => array(array('onKernelRequest', 17)),
);
}
}
then changed
$request->setDefaultLocale($request->getSession()->get('_locale', $this->defaultLocale));
to
$request->setLocale($request->getSession()->get('_locale'));
and used
$this->getRequest()->getSession()->set('_locale', 'nl');
to set the locale, translations and translatables now work
hope this also helps someone else ..

adding an object to a list in play framework

I am new to play, whenever I use list.add(Object) to the list and print the size of the list, it remains 0 !!!
My Method is to like a tutorial, it checks if the logged-in user has liked this tutorial before, if yes, it increments the likeCount of the tutorial by one, and add the tutorial to the like list of the user. If no, it renders that he already likes it.
since the tutorial is not saved in the list, I am not able to check if it is already liked or not !!!
Models:
#Entity
public class RegisteredUser extends Model {
public String name;
#ManyToMany
public List<Tutorial> contributedTutorials;
public RegisteredUser(String name) {
this.name = name;
this.likeList = newArrayList<Tutorial>();
this.save();
}
}
#Entity
public class Tutorial extends Model {
public String Title;
public int likeCount;
public Tutorial(String title) {
this.title = title;
this.likeCount = 0;
}
Controller:
public Tutorials extends Controller {
public static void likeTutorial() {
if (session.get("RegisteredUserId") != null && session.get("tutID") != null ) {
{
long uId = Long.parseLong(session.get("RegisteredUserId"));
RegisteredUser user = RegisteredUser.findById(uId);
long tId = Long.parseLong(session.get("tutID"));
Tutorial tut = Tutorial.findById(tId);
int x = tut.likeCount;
x++;
if (!(user.likeList.contains(tut)))
// to check that this user didn't like this tut before
{
Tutorial.em().createQuery("update Tutorial set likeCount ="+ x +" where id=" +tId).executeUpdate();
tut.refresh();
user.updateLikeList(tut); // THIS IS NOT WORKING!!!
renderText("You have successfully liked this Tutorial " + user.likeList.size());
}
}
renderText("Opps Something went Wrong!!");
}
}
}
The view :
Like
+You don't need to call the this.save() and this.likeList = newArrayList<Tutorial>(); in the constructor. Actually the latter is syntactically wrong.
+Passing the tutorial ID as a session variable is very wrong. You need to pass it as a GET parameter to the action.
+Replace your check with:
// to check that this user didn't like this tut before
if (! user.likeList.contains(tut)) {
// Tutorial.em().createQuery("update Tutorial set likeCount ="+ x +" where id=" +tId).executeUpdate();
// tut.refresh();
// user.updateLikeList(tut); // THIS IS NOT WORKING!!!
tut.likeCount++;
tut.save();
// Since it's a ManyToMany relationship, you only need to add it to one list and the other will reflect properly if mappedBy properly
user.likeList.add(tut); // note that the example you showed uses contributedTutorials not likeList
user.save();
renderText("You have successfully liked this Tutorial " + user.likeList.size());
}
I made all adjustments You mentioned above
And
The mapping in RegisteredUser Model
#ManyToMany
public List<Tutorial> likeList;
and I have added the mapping to Tutorial Model
#ManyToMany
public List<RegisteredUser> likersList;
and adjusted the method in the controller as follows
if (! user.likeList.contains(tut)) {
tut.likeCount++;
//tut.likersList.add(user); // however this raised an error too! at the next line
tut.save();
//as for the likeCount update, it has worked perfectly, Thank You
// Since it's a ManyToMany relationship, you only need to add it to one list and the other will reflect properly if mappedBy properly
//I have modified Model Tutorial as shown above and it didn't work too !
user.likeList.add(tut);
user.save(); // this raised an error!!
renderText("You have successfully liked this Tutorial " + user.likeList.size());
}