tyczj / Tweedle

A Kotlin based Android library around the Twitter v2 API
39 stars 6 forks source link

Can you please share some examples to use this with java #2

Closed parth2545 closed 4 years ago

parth2545 commented 4 years ago

I am trying to use this amazing library but I am not able to.There are various problems appearing.I am not that good at kotlin so can you help me out with how we can use this library with java android applications.

tyczj commented 4 years ago

This is a kotlin library and wont work with Java because it uses Kotlin Coroutines among other kotlin only features

parth2545 commented 4 years ago

Hi,

Sorry to bother you, but I am new to android development. Your library is perfect for the app i am trying to develop. But my app is in java and i read everywhere that i can combine kotlin classes in java. So if i create a kotlin class and called it in maniactivity..it won't work???

I am sorry again but little bit guidance will help me lot.

Thank you and have a nice day.

On Tue, Oct 20, 2020, 17:37 tyczj notifications@github.com wrote:

This is a kotlin library and wont work with Java because it uses Kotlin Coroutines among other kotlin only features

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tyczj/Tweedle/issues/2#issuecomment-712991181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROMJSSLFFOL2NUGPMU33YLSLW4EVANCNFSM4SYSYOYA .

tyczj commented 4 years ago

Yes you can use kotlin classes in Java but there are certain things in kotlin you cannot use in Java that this library uses

parth2545 commented 4 years ago

Ohh, Ohkay.. Thank you so much..i was trying from last two days to work with it. Thanks a lot.

On Tue, Oct 20, 2020, 18:42 tyczj notifications@github.com wrote:

Yes you can use kotlin classes in Java but there are certain things in kotlin you cannot use in Java that this library uses

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tyczj/Tweedle/issues/2#issuecomment-713028327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROMJSSYM3YXQMV23KBPFFDSLXDXXANCNFSM4SYSYOYA .

parth2545 commented 4 years ago

Hi, Sorry to bother you again. I used your library in the Kotlin project now. It is working excellent. But I was trying to find if there is a way to just remove tweet from multitweetpayload. I used ( It.data.data.text) but for some reason it is not working.

Do let me know. Thank you.

Also, With some changes , we can use this library for twitter API 1.1 all end points. I tried that and it worked.

On Tue, Oct 20, 2020 at 6:53 PM Parth Patankar parth2545@gmail.com wrote:

Ohh, Ohkay.. Thank you so much..i was trying from last two days to work with it. Thanks a lot.

On Tue, Oct 20, 2020, 18:42 tyczj notifications@github.com wrote:

Yes you can use kotlin classes in Java but there are certain things in kotlin you cannot use in Java that this library uses

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tyczj/Tweedle/issues/2#issuecomment-713028327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROMJSSYM3YXQMV23KBPFFDSLXDXXANCNFSM4SYSYOYA .

tyczj commented 4 years ago

Not sure I understand what you are trying to do. Can you give an example

parth2545 commented 4 years ago

When I am using ( Response.success -> it.data ) I get this result image

But I want to extract just tweet text from it . Therefore I am trying to use ( Response.Success -> it.data.data.text ) from your examples. But it is not working image

So I am asking if there is a inbuilt way to extract tweet text from MultiTweetPayload or do I have to build another method to parse that json output.

On Sat, Oct 24, 2020 at 3:59 PM tyczj notifications@github.com wrote:

Not sure I understand what you are trying to do. Can you give an example

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tyczj/Tweedle/issues/2#issuecomment-715926911, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROMJSW3SU4V66BXL6DD6MDSMLTUXANCNFSM4SYSYOYA .

tyczj commented 4 years ago

I cannot see your images you are trying to post.

A MultiTweetPayload can have one or many results you will have to loop through the list to get all the tweets or a specific one

parth2545 commented 4 years ago

I have updated the last one.

Okay so for looping Multitweetpayload , I have to write different coroutine code ,right?

Sorry again to make it so confusing.

tyczj commented 4 years ago

all you have to do is

it.data.data.forEach{tweetData ->

    tweetData.text //your tweet text

}

Nothing to do with coroutines its basic looping

parth2545 commented 4 years ago

How can I use the function in kotlin in background?? For example : `fun Tweeter() { val token =" val query = "\"Now that Tesla FSD beta\"from:elonmusk"

    var mainActivityViewModel = ViewModelProvider(this).get(MainViewModel::class.java)

    val map = HashMap<String, String>()

    val dal = mainActivityViewModel.getRecentTweets(token, query, map).observe(this, Observer {
        when (it) {
            is Response.Error -> {
                it.exception
            }
            is Response.Success -> it.data.data.forEach { tweetdata -> tweetdata.text }
        }
    })
}`

I should be able to call this function in background even without oncreat? Is that possible?

tyczj commented 4 years ago

it is already executing in the background. if you mean looping through the data you get back from the api then look up how to use kotlin coroutines or other threading methods

parth2545 commented 4 years ago

I meant , how can I use this function without app instance. Like without having app layout on UI??

For ex. My app takes photo , and find out twitter handle in and find if that twitter handle is verified? but once I take photo my app get closed . No app Interface is shown after that and then notification pops up once it checks if it is verified or not. So I want these functions to run in background but it opens the UI everytime or needs me to write oncreate method..

tyczj commented 4 years ago

You will need to use a service or something, these questions are all questions more suited for stackoverflow as they dont really have anything to do with the library