Skip to content

Instantly share code, notes, and snippets.

@sajjadyousefnia
Created June 20, 2024 12:24
Show Gist options
  • Save sajjadyousefnia/7ad58d7680f03d4bdf59f5d29ad26d32 to your computer and use it in GitHub Desktop.
Save sajjadyousefnia/7ad58d7680f03d4bdf59f5d29ad26d32 to your computer and use it in GitHub Desktop.
package com.sands.android.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.sands.android.dao.entity.DownloadModel
import com.sands.android.dao.entity.MdlLastPlay
import com.sands.android.dao.entity.MdlMovie
@Dao
interface AppDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(data: MdlMovie)
@Query("SELECT * FROM movie ")
fun getAll(): List<MdlMovie>
@Query("Delete from movie ")
fun delete()
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertLastPlay(data: MdlLastPlay)
@Query("SELECT * FROM last_play where id_film=:id and type=:type")
fun getLastPlayTime(id: String, type: String): MdlLastPlay?
// ============>>>> Download <<<<============ //
@Insert(onConflict = OnConflictStrategy.REPLACE)
public fun insertNewDownload(download: DownloadModel)
@Query("UPDATE download_model SET percentage=:percent AND downloaded_bytes=:downloaded__bytes WHERE id=:id ")
public fun updatePercentageDownload(id: Long, downloaded__bytes: Long, percent: Int)
@Update()
public fun updateDownload(download: DownloadModel)
@Query(
"UPDATE download_model SET is_complete = 1 " +
" AND downloaded_bytes=total_bytes AND" +
" percentage=100 AND " +
"is_stopped=0 AND " +
"current_speed=0 AND " +
"end_date_time= :currentDateTime " +
"AND is_new = 1 " +
" AND is_stopped=0 WHERE id=:id"
)
public fun updateFinishedDownload(id: Long, currentDateTime: String)
@Query("UPDATE download_model SET is_stopped=:isStopped WHERE id=:id")
public fun checkDownloadStopStatus(id: Long, isStopped: Boolean)
@Delete()
public fun deleteDownload(download: DownloadModel)
@Query("DELETE FROM download_model")
public fun clearAllDownloads()
@Query("SELECT COUNT(*) FROM download_model WHERE url=:url")
public fun checkDownloadExist(url: String): Int
@Query("SELECT * FROM download_model WHERE url=:url LIMIT 1")
public fun getDownloadByUrl(url: String): DownloadModel
@Query("SELECT * FROM download_model WHERE is_complete = 1")
public fun getCompleteDownloadsHistory(): MutableList<DownloadModel>
@Query("SELECT * FROM download_model WHERE is_complete = 0")
public fun getUnfinishedDownloadsHistory(): MutableList<DownloadModel>
@Query("SELECT * FROM download_model")
public fun getAllDownloads(): MutableList<DownloadModel>
@Query("UPDATE download_model SET download_id = :downloadId WHERE id = :id")
public fun updateDownloadId(id: Long, downloadId: Long)
// ============>>>> SETTING <<<<============ //
/*@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertSetting(data: MdlSetting)
@Query("SELECT * FROM setting ")
fun getAllSettingLive(): LiveData<List<MdlSetting>>
@Query("SELECT * FROM setting ")
fun getAllSetting(): List<MdlSetting>
@Query("SELECT * FROM setting WHERE id = 1 ")
fun getSetting(): MdlSetting
@Query("SELECT * FROM setting WHERE password=:password")
fun getSetting(password: String): MdlSetting?*//*
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertLog(data: MdlLog)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertPhone(data: MdlPhone)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertMessages(data: ArrayList<MdlMsg>)
@Query("SELECT * FROM log ORDER BY id DESC")
fun getLogsAll(): List<MdlLog>?
@Query("SELECT * FROM log WHERE type=:type ORDER BY id DESC")
fun getLogs(type: String): List<MdlLog>?
@Query("Delete from log ")
fun deleteAllLogs()
@Query("Delete from log WHERE id=:logId")
fun deleteLog(logId: Int)
@Query("Delete from phone WHERE id=:numId")
fun deletePhone(numId: Int)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertSms(data: MdlMySms)
@Query("SELECT * FROM my_sms")
fun getSms(): List<MdlMySms>?
@Query("SELECT * FROM my_sms")
fun getSmsAll(): List<MdlMySms>?
@Query("SELECT * FROM my_sms WHERE status=:type")
fun getSmsAllByType(type:String): List<MdlMySms>?
@Query("SELECT * FROM my_sms WHERE id=:id")
fun getSms(id: Int): MdlMySms?
@Query("SELECT * FROM phone")
fun getPhones(): LiveData<List<MdlPhone>>?
@Query("SELECT * FROM phone")
fun getPhonesList(): List<MdlPhone>?
@Query("SELECT * FROM msg")
fun getMsg(): LiveData<List<MdlMsg>>?
@Query("SELECT * FROM phone where phone=:phone")
fun findPhone(phone:String): MdlPhone?
@Query("Delete from my_sms ")
fun deleteAllMySms()
@Query("Delete from my_sms WHERE id=:id")
fun deleteMySms(id: Int)
@Query("Delete from log ")
fun deleteAllServerSms()*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment