Categories
discuss

koin default implementation without name reference

I have 2 Retrofit Clients one of them default and second one has different implementation like (base URL, interceptors etc… )

i need to inject default client without using name reference

first client :-

single<Retrofit> {
Retrofit.Builder()
        .baseUrl(RemoteConstants.BASE_URL)
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .addConverterFactory(APIResponseConverter())
        .addConverterFactory(GsonConverterFactory.create(get()))
        .client(get())
        .build()
    }

Second Client:-

single<Retrofit>("retrofit_second") {
        Retrofit.Builder()
                .baseUrl("diffrent url")
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(get()))
                .client(get("SecondOkHttpClient"))
                .build()
}

My way to inject

val myModule = module {
    factory { get<Retrofit>().create(FirstAPI::class.java) } // Why Koin did not figure it without providing its default name !?
    factory { get<Retrofit>("retrofit_second").create(SecondAPI::class.java) }
    factory<IMyRemoteDataSource> { MyRemoteDataSource(get(), get()) }
    factory<IMyRepository> { MyRepository(get()) }
    factory { MyUseCase(get()) }
}

the result is :

        Multiple definitions found for type 'class retrofit2.Retrofit' - Koin can't choose between :
    Single [name='retrofit_second',class='retrofit2.Retrofit']
    Single [name='Retrofit',class='retrofit2.Retrofit']

Why Koin did not get the default Retrofit instance without providing its default name (Retrofit ) !?

factory { get<Retrofit>().create(FirstAPI::class.java) }

Answer

You are right @Eslam. Current behavior (as of koin:1.0.2) is when you don’t specify the dependency name, it is treated as an empty string. And then the definitions get filtered by class name:

fun searchByClass(clazz: KClass<*>): List<BeanDefinition<*>> {
    return definitions.filter { clazz in it.classes }
}

As a result you get both of your definitions, which results in the above mentioned error: Multiple definitions for class ....

Categories
discuss

ViewBinding manipulate view after inflating

I have an instance where I used to pass my View onto a new method to manipulate a couple of things. here I will provide an example. So Basically I am using a RecyclerView and I am inflating the view when the recylerview creates the view

So now I have the inflated View object now I just pass it to my method to manipulate it.

manipulateView(view) manipulateView sets up the color and attributes for the view children

and that used to work and everything. but now I am moving onto ViewBinding

now I have a ViewStub for where I need to inflate my customView

as follows here is the code

ViewDataBinding viewDataBinding = DataBindingUtil.inflate(layoutInflater, getLayoutResource(), viewGroup, false);
ViewStub viewStub = (ViewStub) viewDataBinding.getRoot().findViewById(R.id.stub);

and then I set the layout for the viewStub here

viewStub.setLayoutResource(getLayoutResource());

now setLayoutResource expects an int value with the id of the layout now my question is how can I call manipulateView on getLayoutResource() should I just pass the viewStub and then call viewStub.getRootView() and Manipulate that view?

It would be the best if I was able to manipulate the ViewDataBinding object it self, Should I just manipulate ViewDataBinding::getRoot?

Answer

The view that gets inflated by calling layoutInflater.inflate(...) is the same view you would get from viewDataBinding.getRoot(). From the docs, root “returns the outermost view”.

So, if that’s what you want to manipulate, I would just call manipulateView(viewDataBinding.root).

Categories
discuss

Get HTML and CSS from grapes.js newsletter editor in Javascript

How to get output HTML and CSS of grapes.js in Javascript ?

I am writing a Django app for newsletter, in which I need a newsletter editor for which I used “grapes.js” newsletter. Everything is fine but I am stuck in part where I need to get the HTML and CSS of the template created with it.
I have:

<script type="text/javascript">
  var editor = grapesjs.init({
  container : '#gjs',
  plugins: ['gjs-preset-newsletter'],
  pluginsOpts: {
    'gjs-preset-newsletter': {
      modalTitleImport: 'Import template',
    'grapesjs-plugin-export': { /* options */ }
      // ... other options
    }
  }
});
function returnHtml(){ 
    console.log('test')
    const mjml = editor.getHtml;
    preview = editor.getHtml
    $("#myiframe").contents().find("body").html(mjml)
}
returnHtml();

This code gives me the html of the template but without the css !

I have tried https://github.com/artf/grapesjs-mjml/issues/2. Can someone please suggest me what i am missing ? Thanks.

EDIT: I have an answer below but what i need is like this with html and css together like in export HTML.Thanks again. https://screenshots.firefox.com/u752bu0nNN97rXlr/127.0.0.1

Answer

Getting only HTML:

var html = editor.getHtml();

Getting only CSS:

var css = editor.getCss();

Getting HTML with CSS inline:

var htmlWithCss = editor.runCommand('gjs-get-inlined-html');
Categories
discuss

NetworkSecurityConfig: No Network Security Config specified, using platform default Error response code: 400

I’m trying to connect to either of these places and get the JSON data:-

https://content.guardianapis.com/search?q=debate&tag=politics/politics&from-date=2014-01-01&api-key=test
https://content.guardianapis.com/search?q=debates&api-key=test
https://content.guardianapis.com/search?api-key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx

All three I can get to via the browser, but when I try to access them via an android app I get the following errors:-

NetworkSecurityConfig: No Network Security Config specified, using platform default
Error response code: 400

I’ve added this to manifest.xml:-

<uses-permission android:name="android.permission.INTERNET"/>

I also added this to the manifest.xml:-

android:networkSecurityConfig="@xml/network_security_config"

And created res/xml/network_security_config.xml, which contains:-

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">content.guardianapis.com</domain>>
    </domain-config>

Which changes the error to:-

D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
Error response code: 400

I know it’s missing:-

<trust-anchors>
    <certificates src="@raw/my_ca"/>
</trust-anchors>

but I have no idea where or what the certificate would be or if it’s needed.

Not really sure what is going on, any help would be appreciated.

IN ADDITION:- I am able to connect fine and get the JSON from this URL:-

https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&eventtype=earthquake&orderby=time&minmag=6&limit=10

All I get is this:-

No Network Security Config specified, using platform default

Buy not error 400 and gets through with a 200 instead. So it makes me think there is something weird going on, but not sure where.

Answer

Try these solutions

Solution 1)

Add the following attribute to the <application tag in AndroidManifest.xml:

android:usesCleartextTraffic="true"

Solution 2)

Add android:networkSecurityConfig="@xml/network_security_config" to the <application tag in app/src/main/AndroidManifest.xml:

<application
        android:name=".ApplicationClass"
        android:allowBackup="true"
        android:hardwareAccelerated="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

With a corresponding network_security_config.xml in app/src/main/res/xml/:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

enter image description here

Refer this answer for more info: Download Manger not working in Android Pie 9.0 (Xiaomi mi A2)

Categories
discuss

Blue flash light (Arc) on Google Maps

Is there any way to have access to the blue flash light appears on google map? I have read in different forums that this blue arc is representative of the reliability of the magnet sensor, is there any way to have access to it in android?

Answer

I went through Android SDK for magnet outputs. I have found one method that measure the accuracy of magnet based direction of movement. Have you seen following method?

@Override
public void onAccuracyChanged(Sensor sensor, int i) {
    if(sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD){

    }
}

This outputs the accuracy in 4 levels for magnet based heading estimation.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..