Skip to content

Instantly share code, notes, and snippets.

@shakalaca
shakalaca / build.gradle
Last active Dec 2, 2020
move & rename APK files
View build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
task wrapper(type: Wrapper) {
@shakalaca
shakalaca / twinapps_required_apps.xml
Created Nov 11, 2019
給 ZenUI 4.0 之後應用分身使用的 app 支援設定檔
View twinapps_required_apps.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="twinapps_required_apps">
<item>com.android.vending</item>
<item>com.google.android.gms</item>
<item>jp.naver.line.android|Line: Free Calls &amp; Messages</item>
<item>com.facebook.katana|Facebook</item>
<item>com.facebook.orca|Messenger - Text and Video Chat for Free</item>
<item>com.tencent.mm|WeChat</item>
<item>com.whatsapp|WhatsApp Messenger</item>
@shakalaca
shakalaca / ct_monitor
Last active Oct 3, 2020
Switch root on / off
View ct_monitor
#!/system/bin/sh
if [ -f /system/xbin/su_ ]; then
# grant permission for changing & executing files (copy from ota survival program)
/system/xbin/supolicy --live "allow init system_file file { write setattr relabelfrom rename }"
/system/xbin/supolicy --live "allow init install_recovery_exec file { setattr relabelfrom relabelto rename }"
/system/xbin/supolicy --live "allow init zygote_exec lnk_file { unlink } "
mount -o rw,remount /system
View gist:dd76398a70a12ead428c20f89e51a29c
private fun initAdapter() {
adapter.addLoadStateListener { loadState ->
// Only show the list if refresh succeeds.
binding.list.isVisible = loadState.source.refresh is LoadState.NotLoading
// Show loading spinner during initial load or refresh.
binding.progressBar.isVisible = loadState.source.refresh is LoadState.Loading
// Show the retry state if initial load or refresh fails.
binding.retryButton.isVisible = loadState.source.refresh is LoadState.Error
}
}
@shakalaca
shakalaca / patch.diff
Created Aug 6, 2020
Fix 403 limit exceeded error
View patch.diff
diff --git a/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt b/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt
index 81b3b8d..7529c8a 100644
--- a/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt
+++ b/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt
@@ -42,7 +42,7 @@ class GithubRepository(
// appending '%' so we can allow other characters to be before and after the query string
val dbQuery = "%${query.replace(' ', '%')}%"
- val pagingSourceFactory = { database.reposDao().reposByName(dbQuery) }
+ val pagingSourceFactory = { database.reposDao().reposByIdx(dbQuery) }
@shakalaca
shakalaca / gist:a68e0e9249477d11521695ade285fc3e
Last active Aug 6, 2020
理想中 PagingState.data (對應到 RemoteKeys) 內容,prev 為上一頁,next 為下一頁。
View gist:a68e0e9249477d11521695ade285fc3e
+---------+--------------+---------+
| prev: 0 | repo 001 | next: 2 |
+---------+--------------+---------+
| prev: 0 | repo 002 | next: 2 |
+---------+--------------+---------+
| prev: 0 | repo 003 | next: 2 |
+---------+--------------+---------+
...
+---------+--------------+---------+
| prev: 0 | repo 048 | next: 2 |
@shakalaca
shakalaca / gist:32198097ba4ba4f402ceafb284ea28f1
Created Aug 6, 2020
實際上 PagingState.data 的內容 (對應 RemoteKeys)
View gist:32198097ba4ba4f402ceafb284ea28f1
+---------+--------------+---------+
| prev: 0 | repo 001 | next: 2 |
+---------+--------------+---------+
| prev: 1 | repo 087 | next: 3 |
+---------+--------------+---------+
| prev: 0 | repo 002 | next: 2 |
+---------+--------------+---------+
...
+---------+--------------+---------+
| prev: 1 | repo 056 | next: 3 |
View RepoDao.kt
interface RepoDao {
@Query("SELECT * FROM repos WHERE " +
"name LIKE :queryString OR description LIKE :queryString " +
"ORDER BY stars DESC, name ASC")
fun reposByName(queryString: String): PagingSource<Int, Repo>
}
View GithubRepository.kt
class GithubRepository {
fun getSearchResultStream(query: String): Flow<PagingData<Repo>> {
val dbQuery = "%${query.replace(' ', '%')}%"
val pagingSourceFactory = { database.reposDao().reposByName(dbQuery)}
return Pager(
config = PagingConfig(pageSize = NETWORK_PAGE_SIZE, enablePlaceholders = false),
remoteMediator = GithubRemoteMediator(query, service, database),
pagingSourceFactory = pagingSourceFactory
).flow
View GithubService.kt
interface GithubService {
/**
* Get repos ordered by stars.
*/
@GET("search/repositories?sort=stars")
suspend fun searchRepos(
@Query("q") query: String,
@Query("page") page: Int,
@Query("per_page") itemsPerPage: Int
): RepoSearchResponse
You can’t perform that action at this time.