Compare commits
162
Commits
v122092691
...
v122123483
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7420adeb5c | ||
|
|
316027ca3b | ||
|
|
9d58fba5c9 | ||
|
|
284c19ef89 | ||
|
|
7cfd17231a | ||
|
|
527830a5ae | ||
|
|
c4ed30f594 | ||
|
|
156c1681cf | ||
|
|
3593fbca78 | ||
|
|
430fc8e8cb | ||
|
|
4fce19bad4 | ||
|
|
49f5848e7b | ||
|
|
90452100a4 | ||
|
|
bf1196dd0f | ||
|
|
4316dc6516 | ||
|
|
9833a66a64 | ||
|
|
797bf06a9c | ||
|
|
d98b00533d | ||
|
|
bf8f7d8667 | ||
|
|
89c570f34f | ||
|
|
d6a562863a | ||
|
|
a02f06fe2e | ||
|
|
7b088d7bb4 | ||
|
|
477883ed39 | ||
|
|
748ed41096 | ||
|
|
86c50d4881 | ||
|
|
c4c92e6dd9 | ||
|
|
7f0ba193ec | ||
|
|
87ed5b0fa8 | ||
|
|
6947743ac0 | ||
|
|
07e3710d44 | ||
|
|
e68da7764f | ||
|
|
c3ff894027 | ||
|
|
f09f731d30 | ||
|
|
956c4341c7 | ||
|
|
7b68264dd7 | ||
|
|
cfcf030bf8 | ||
|
|
0e7d7a5835 | ||
|
|
0856ebb889 | ||
|
|
25bf68cf0c | ||
|
|
afc6f392c6 | ||
|
|
a0b5e2052b | ||
|
|
87d1ef2bce | ||
|
|
537a6d3a0b | ||
|
|
dbe97f564e | ||
|
|
3a3bf03114 | ||
|
|
c09a32e9ad | ||
|
|
b02a588dff | ||
|
|
a4527940b8 | ||
|
|
9e8a25ed3e | ||
|
|
8ea46e146b | ||
|
|
5ecf3c3f87 | ||
|
|
325f103417 | ||
|
|
ab4b1ae644 | ||
|
|
87ea44754e | ||
|
|
04dec50808 | ||
|
|
e36189e2e7 | ||
|
|
d6bdf510a4 | ||
|
|
a464e93370 | ||
|
|
4b63afe62a | ||
|
|
ac4c4b9441 | ||
|
|
16b10dc1b7 | ||
|
|
02d734eee8 | ||
|
|
c5cdfc0d53 | ||
|
|
6d610ed61a | ||
|
|
792950be7c | ||
|
|
af8969ce4a | ||
|
|
27c55e59a1 | ||
|
|
94a0747947 | ||
|
|
d862bfba4f | ||
|
|
b0d1d9c29a | ||
|
|
7b40a31979 | ||
|
|
823a8c3692 | ||
|
|
5494978db8 | ||
|
|
6076eb1cee | ||
|
|
131101d2ee | ||
|
|
62ad1f45ba | ||
|
|
402d18b889 | ||
|
|
e32699c93f | ||
|
|
059a237b99 | ||
|
|
d2bdbae6c8 | ||
|
|
510fcbe47e | ||
|
|
667e9c1a5d | ||
|
|
53b1d1f8b2 | ||
|
|
c25e8889a4 | ||
|
|
8b0bbe71c9 | ||
|
|
8bfe14c019 | ||
|
|
208babbce3 | ||
|
|
02098a7aa9 | ||
|
|
d0a982f385 | ||
|
|
1d1c121aab | ||
|
|
fe12819163 | ||
|
|
023a30c008 | ||
|
|
a2862a2587 | ||
|
|
054e936657 | ||
|
|
1d2e5069b8 | ||
|
|
a147646743 | ||
|
|
32e7fc0038 | ||
|
|
c15bf44032 | ||
|
|
0bcd55bd4e | ||
|
|
ebef0b3511 | ||
|
|
713ceb05bf | ||
|
|
dc8381b661 | ||
|
|
b5b820c64b | ||
|
|
f7055626d9 | ||
|
|
6ec3e96909 | ||
|
|
22da30eaa8 | ||
|
|
79fd115f5e | ||
|
|
8dc3d319cd | ||
|
|
27bb056397 | ||
|
|
f9ba13dc32 | ||
|
|
6f60ef4346 | ||
|
|
28b950f467 | ||
|
|
a9c7ec3dc1 | ||
|
|
920d4ac1ef | ||
|
|
0e96d313ec | ||
|
|
7211fdb1a3 | ||
|
|
381d6acc82 | ||
|
|
d311c2cdeb | ||
|
|
219cae5d74 | ||
|
|
2968aee309 | ||
|
|
6cb4b35c93 | ||
|
|
15ec0f2d26 | ||
|
|
4781e30da2 | ||
|
|
c8759cc035 | ||
|
|
cb4f2f02ef | ||
|
|
7517626ab7 | ||
|
|
41c951b659 | ||
|
|
ad279c6683 | ||
|
|
5f0817ddb7 | ||
|
|
7124cbcacd | ||
|
|
2a710a1a08 | ||
|
|
82ec2445a1 | ||
|
|
cabb6d494d | ||
|
|
5c12481813 | ||
|
|
b16f86dda1 | ||
|
|
2bc28db2cc | ||
|
|
bf1b680b4a | ||
|
|
e2afff0b8e | ||
|
|
a382fc89ea | ||
|
|
3f0a3903ae | ||
|
|
f46f98cef0 | ||
|
|
bf6f1a917e | ||
|
|
71c0a4d340 | ||
|
|
63c550ead3 | ||
|
|
d81fb79b4f | ||
|
|
144067d5b6 | ||
|
|
8106faa45c | ||
|
|
d9ef301e0f | ||
|
|
90b52232ab | ||
|
|
0f000ea359 | ||
|
|
fb8f81a4c8 | ||
|
|
366b2e10f1 | ||
|
|
d2436bb976 | ||
|
|
ef994460c1 | ||
|
|
758708e18d | ||
|
|
c0381144d1 | ||
|
|
cda3ba6cb4 | ||
|
|
a4636cc0c8 | ||
|
|
60c24fc75a | ||
|
|
5853a19937 | ||
|
|
99f2c04bf6 |
+23
-6
@@ -3,24 +3,34 @@ type: docker
|
|||||||
name: test
|
name: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: AnylyseBuildTest
|
- name: BuildAndTest
|
||||||
image: mingc/android-build-box:latest
|
image: mingc/android-build-box:latest
|
||||||
failure: ignore
|
|
||||||
commands:
|
commands:
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Analysing..."
|
- echo "Configure gradle..."
|
||||||
- ./gradlew sonarqube -Dsonar.projectKey=RFS2 -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\""
|
- mkdir -p ~/.gradle && echo "org.gradle.daemon=false\nignoreGitVersion=true\npushCache=false\nsystemProp.org.gradle.internal.http.connectionTimeout=180000\nsystemProp.org.gradle.internal.http.socketTimeout=180000" >> ~/.gradle/gradle.properties
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Building..."
|
- echo "Building..."
|
||||||
- ./gradlew :androidApp:build -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\"" -P pushCache=false
|
- ./gradlew build -x test
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Testing..."
|
- echo "Testing..."
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
|
- ./gradlew koverMergedXmlReport
|
||||||
environment:
|
environment:
|
||||||
SONAR_HOST_URL:
|
SONAR_HOST_URL:
|
||||||
from_secret: sonarScannerHostUrl
|
from_secret: sonarScannerHostUrl
|
||||||
SONAR_LOGIN:
|
SONAR_LOGIN:
|
||||||
from_secret: sonarScannerLogin
|
from_secret: sonarScannerLogin
|
||||||
|
- name: Analyse
|
||||||
|
image: kytay/sonar-node-plugin
|
||||||
|
settings:
|
||||||
|
sonar_host:
|
||||||
|
from_secret: sonarScannerHostUrl
|
||||||
|
sonar_token:
|
||||||
|
from_secret: sonarScannerLogin
|
||||||
|
use_node_version: 16.18.1
|
||||||
|
sonar_debug: true
|
||||||
|
sonar_project_settings: ./sonar-project.properties
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
@@ -85,8 +95,15 @@ steps:
|
|||||||
- name: build
|
- name: build
|
||||||
image: mingc/android-build-box:latest
|
image: mingc/android-build-box:latest
|
||||||
commands:
|
commands:
|
||||||
|
- echo "---------------------------------------------------------"
|
||||||
|
- echo "Fetch tags..."
|
||||||
|
- git fetch --tags
|
||||||
|
- echo "---------------------------------------------------------"
|
||||||
|
- echo "Configure gradle..."
|
||||||
|
- mkdir -p ~/.gradle && echo "org.gradle.daemon=false\nignoreGitVersion=false\npushCache=false\nsystemProp.org.gradle.internal.http.connectionTimeout=180000\nsystemProp.org.gradle.internal.http.socketTimeout=180000" >> ~/.gradle/gradle.properties
|
||||||
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Generate APK"
|
- echo "Generate APK"
|
||||||
- ./gradlew :androidApp:assembleGithubConfigRelease -PignoreGitVersion=true -P appLoginUrl="\"URL\"" -P appLoginUsername="\"LOGIN\"" -P appLoginPassword="\"PASS\"" -P pushCache=false
|
- ./gradlew :androidApp:assembleGithubConfigRelease -P pushCache=false
|
||||||
- echo "---------------------------------------------------------"
|
- echo "---------------------------------------------------------"
|
||||||
- echo "Get Key"
|
- echo "Get Key"
|
||||||
- wget https://amine-louveau.fr/key
|
- wget https://amine-louveau.fr/key
|
||||||
|
|||||||
@@ -46,28 +46,3 @@ Always check if the web version of your instance is working.
|
|||||||
I won't provide any selfoss instance url. If you want to help, but to not have one, you'll have to install one, and use it.
|
I won't provide any selfoss instance url. If you want to help, but to not have one, you'll have to install one, and use it.
|
||||||
|
|
||||||
All the details to need are [here](https://selfoss.aditu.de/).
|
All the details to need are [here](https://selfoss.aditu.de/).
|
||||||
|
|
||||||
# Build the project
|
|
||||||
|
|
||||||
You can directly import this project into IntellIJ/Android Studio.
|
|
||||||
|
|
||||||
You'll have to:
|
|
||||||
|
|
||||||
- Define some parameters either in `~/.gradle/gradle.properties` or as gradle parameters (see the examples)
|
|
||||||
|
|
||||||
- appLoginUrl, appLoginUsername and appLoginPassword: url, username and password of a selfoss instance. **These are only used for tests. They can be empty if you don't test API calls.**
|
|
||||||
|
|
||||||
### Examples:
|
|
||||||
#### Inside ~/.gradle/gradle.properties
|
|
||||||
|
|
||||||
```
|
|
||||||
appLoginUrl="URL" # It can be empty.
|
|
||||||
appLoginUsername="LOGIN" # It can be empty.
|
|
||||||
appLoginPassword="PASS" # It can be empty.
|
|
||||||
```
|
|
||||||
|
|
||||||
#### As gradle parameters
|
|
||||||
|
|
||||||
```
|
|
||||||
./gradlew .... -P appLoginUrl="URL" -P appLoginUsername="LOGIN" -P appLoginPassword="PASS"
|
|
||||||
```
|
|
||||||
|
|||||||
+56
-42
@@ -1,11 +1,14 @@
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
val ignoreGitVersion: String by project
|
val ignoreGitVersion: String by project
|
||||||
|
val acraVersion = "5.9.7"
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
kotlin("android")
|
kotlin("android")
|
||||||
kotlin("kapt")
|
kotlin("kapt")
|
||||||
|
id("com.mikepenz.aboutlibraries.plugin")
|
||||||
|
id("org.jetbrains.kotlinx.kover") version "0.6.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Project.execWithOutput(cmd: String, ignore: Boolean = false): String {
|
fun Project.execWithOutput(cmd: String, ignore: Boolean = false): String {
|
||||||
@@ -54,11 +57,15 @@ fun versionNameFromGit(): String {
|
|||||||
android {
|
android {
|
||||||
compileOptions {
|
compileOptions {
|
||||||
// Flag to enable support for the new language APIs
|
// Flag to enable support for the new language APIs
|
||||||
isCoreLibraryDesugaringEnabled = true
|
sourceCompatibility = JavaVersion.VERSION_11
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
}
|
}
|
||||||
compileSdk = 31
|
|
||||||
|
// For Kotlin projects
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "11"
|
||||||
|
}
|
||||||
|
compileSdk = 33
|
||||||
buildToolsVersion = "31.0.0"
|
buildToolsVersion = "31.0.0"
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding = true
|
viewBinding = true
|
||||||
@@ -66,7 +73,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "bou.amine.apps.readerforselfossv2.android"
|
applicationId = "bou.amine.apps.readerforselfossv2.android"
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 31
|
targetSdk = 33
|
||||||
versionCode = versionCodeFromGit()
|
versionCode = versionCodeFromGit()
|
||||||
versionName = versionNameFromGit()
|
versionName = versionNameFromGit()
|
||||||
|
|
||||||
@@ -79,6 +86,11 @@ android {
|
|||||||
// tests
|
// tests
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
packagingOptions {
|
||||||
|
resources {
|
||||||
|
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||||
|
}
|
||||||
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
getByName("release") {
|
getByName("release") {
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = true
|
||||||
@@ -86,9 +98,6 @@ android {
|
|||||||
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
|
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
|
||||||
}
|
}
|
||||||
getByName("debug") {
|
getByName("debug") {
|
||||||
buildConfigField("String", "LOGIN_URL", properties["appLoginUrl"] as String)
|
|
||||||
buildConfigField("String", "LOGIN_PASSWORD", properties["appLoginPassword"] as String)
|
|
||||||
buildConfigField("String", "LOGIN_USERNAME", properties["appLoginUsername"] as String)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flavorDimensions.add("build")
|
flavorDimensions.add("build")
|
||||||
@@ -98,9 +107,6 @@ android {
|
|||||||
dimension = "build"
|
dimension = "build"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
namespace = "bou.amine.apps.readerforselfossv2.android"
|
namespace = "bou.amine.apps.readerforselfossv2.android"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -114,13 +120,6 @@ dependencies {
|
|||||||
|
|
||||||
implementation("androidx.preference:preference-ktx:1.1.1")
|
implementation("androidx.preference:preference-ktx:1.1.1")
|
||||||
|
|
||||||
// Testing
|
|
||||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0-alpha02")
|
|
||||||
androidTestImplementation("androidx.test:runner:1.3.1-alpha02")
|
|
||||||
// Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource
|
|
||||||
androidTestImplementation("androidx.test.espresso:espresso-contrib:3.4.0-alpha02")
|
|
||||||
// Espresso-intents for validation and stubbing of Intents
|
|
||||||
androidTestImplementation("androidx.test.espresso:espresso-intents:3.4.0-alpha02")
|
|
||||||
implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs")))
|
implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs")))
|
||||||
|
|
||||||
// Android Support
|
// Android Support
|
||||||
@@ -129,31 +128,18 @@ dependencies {
|
|||||||
implementation("androidx.recyclerview:recyclerview:1.3.0-alpha01")
|
implementation("androidx.recyclerview:recyclerview:1.3.0-alpha01")
|
||||||
implementation("androidx.legacy:legacy-support-v4:1.0.0")
|
implementation("androidx.legacy:legacy-support-v4:1.0.0")
|
||||||
implementation("androidx.vectordrawable:vectordrawable:1.2.0-alpha02")
|
implementation("androidx.vectordrawable:vectordrawable:1.2.0-alpha02")
|
||||||
implementation("androidx.browser:browser:1.4.0")
|
|
||||||
implementation("androidx.cardview:cardview:1.0.0")
|
implementation("androidx.cardview:cardview:1.0.0")
|
||||||
implementation("androidx.annotation:annotation:1.3.0")
|
implementation("androidx.annotation:annotation:1.3.0")
|
||||||
implementation("androidx.work:work-runtime-ktx:2.7.1")
|
implementation("androidx.work:work-runtime-ktx:2.7.1")
|
||||||
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
|
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
|
||||||
implementation("org.jsoup:jsoup:1.14.3")
|
implementation("org.jsoup:jsoup:1.14.3")
|
||||||
|
|
||||||
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
|
|
||||||
|
|
||||||
//multidex
|
//multidex
|
||||||
implementation("androidx.multidex:multidex:2.0.1")
|
implementation("androidx.multidex:multidex:2.0.1")
|
||||||
|
|
||||||
// About
|
// About
|
||||||
implementation("com.mikepenz:aboutlibraries-core:8.9.4")
|
implementation("com.mikepenz:aboutlibraries-core:10.5.1")
|
||||||
implementation("com.mikepenz:aboutlibraries:8.9.4")
|
implementation("com.mikepenz:aboutlibraries:10.5.1")
|
||||||
implementation("com.mikepenz:aboutlibraries-definitions:8.9.4")
|
|
||||||
|
|
||||||
// Async
|
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
|
|
||||||
|
|
||||||
// Retrofit + http logging + okhttp
|
|
||||||
implementation("com.squareup.retrofit2:retrofit:2.9.0")
|
|
||||||
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.3")
|
|
||||||
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
|
|
||||||
implementation("com.burgstaller:okhttp-digest:2.5")
|
|
||||||
|
|
||||||
// Material-ish things
|
// Material-ish things
|
||||||
implementation("com.ashokvarma.android:bottom-navigation-bar:2.2.0")
|
implementation("com.ashokvarma.android:bottom-navigation-bar:2.2.0")
|
||||||
@@ -163,12 +149,7 @@ dependencies {
|
|||||||
kapt("com.github.bumptech.glide:compiler:4.11.0")
|
kapt("com.github.bumptech.glide:compiler:4.11.0")
|
||||||
implementation("com.github.bumptech.glide:okhttp3-integration:4.1.1")
|
implementation("com.github.bumptech.glide:okhttp3-integration:4.1.1")
|
||||||
|
|
||||||
// Drawer
|
|
||||||
implementation("com.mikepenz:materialdrawer:8.4.5")
|
|
||||||
|
|
||||||
// Themes
|
// Themes
|
||||||
implementation("com.52inc:scoops:1.0.0")
|
|
||||||
implementation("com.jaredrummler:colorpicker:1.1.0")
|
|
||||||
implementation("com.github.rubensousa:floatingtoolbar:1.5.1")
|
implementation("com.github.rubensousa:floatingtoolbar:1.5.1")
|
||||||
|
|
||||||
// Pager
|
// Pager
|
||||||
@@ -191,14 +172,47 @@ dependencies {
|
|||||||
|
|
||||||
implementation("androidx.core:core-ktx:1.8.0")
|
implementation("androidx.core:core-ktx:1.8.0")
|
||||||
|
|
||||||
// implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.5.1")
|
|
||||||
// implementation("androidx.lifecycle:lifecycle-common-java8:2.5.1")
|
|
||||||
// implementation("androidx.lifecycle:lifecycle-runtime:2.5.1")
|
|
||||||
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
|
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
|
||||||
|
|
||||||
// Network information
|
// Network information
|
||||||
implementation("com.github.ln-12:multiplatform-connectivity-status:1.3.0")
|
implementation("com.github.ln-12:multiplatform-connectivity-status:1.3.0")
|
||||||
|
|
||||||
// SQLDELIGHT
|
// SQLDELIGHT
|
||||||
implementation("com.squareup.sqldelight:android-driver:1.5.3")
|
implementation("com.squareup.sqldelight:android-driver:1.5.4")
|
||||||
|
|
||||||
|
//test
|
||||||
|
testImplementation("junit:junit:4.13.2")
|
||||||
|
testImplementation("io.mockk:mockk:1.12.0")
|
||||||
|
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
|
||||||
|
|
||||||
|
implementation("ch.acra:acra-http:$acraVersion")
|
||||||
|
implementation("ch.acra:acra-toast:$acraVersion")
|
||||||
|
|
||||||
|
// Matomo
|
||||||
|
implementation("com.github.matomo-org:matomo-sdk-android:4.1.4")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<Test> {
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
|
useJUnit()
|
||||||
|
testLogging {
|
||||||
|
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
|
||||||
|
events = setOf(
|
||||||
|
org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED,
|
||||||
|
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
|
||||||
|
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR
|
||||||
|
)
|
||||||
|
showStandardStreams = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aboutLibraries {
|
||||||
|
offlineMode = true
|
||||||
|
fetchRemoteLicense = false
|
||||||
|
fetchRemoteFunding = false
|
||||||
|
includePlatform = false
|
||||||
|
strictMode = com.mikepenz.aboutlibraries.plugin.StrictMode.FAIL
|
||||||
|
duplicationMode = com.mikepenz.aboutlibraries.plugin.DuplicateMode.MERGE
|
||||||
|
duplicationRule = com.mikepenz.aboutlibraries.plugin.DuplicateRule.GROUP
|
||||||
}
|
}
|
||||||
Vendored
+2
-7
@@ -30,15 +30,8 @@
|
|||||||
<fields>;
|
<fields>;
|
||||||
}
|
}
|
||||||
|
|
||||||
-dontwarn okio.**
|
|
||||||
-dontwarn retrofit2.Platform$Java8
|
|
||||||
-keep class retrofit.** { *; }
|
|
||||||
-keepclasseswithmembers class * {
|
|
||||||
@retrofit.http.* <methods>;
|
|
||||||
}
|
|
||||||
-keepattributes *Annotation*,Signature
|
-keepattributes *Annotation*,Signature
|
||||||
-keepattributes Exceptions
|
-keepattributes Exceptions
|
||||||
-dontwarn okio.**
|
|
||||||
-dontwarn javax.annotation.Nullable
|
-dontwarn javax.annotation.Nullable
|
||||||
-dontwarn javax.annotation.ParametersAreNonnullByDefault
|
-dontwarn javax.annotation.ParametersAreNonnullByDefault
|
||||||
|
|
||||||
@@ -90,3 +83,5 @@
|
|||||||
# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
|
# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
|
||||||
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
|
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
|
||||||
|
|
||||||
|
-dontwarn io.mockk.**
|
||||||
|
-keep class io.mockk.** { *; }
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:theme="@style/NoBar"
|
android:theme="@style/NoBar"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules">
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
android:configChanges="uiMode">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:theme="@style/SplashTheme"
|
android:theme="@style/SplashTheme"
|
||||||
@@ -78,8 +79,5 @@
|
|||||||
android:value="true" />
|
android:value="true" />
|
||||||
|
|
||||||
<meta-data android:name="android.max_aspect" android:value="2.1" />
|
<meta-data android:name="android.max_aspect" android:value="2.1" />
|
||||||
<meta-data
|
|
||||||
android:name="preloaded_fonts"
|
|
||||||
android:resource="@array/preloaded_fonts" />
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package bou.amine.apps.readerforselfossv2.android
|
||||||
|
|
||||||
|
import org.acra.ACRA
|
||||||
|
import org.acra.ktx.sendSilentlyWithAcra
|
||||||
|
|
||||||
|
fun Throwable.sendSilentlyWithAcraWithName(name: String) {
|
||||||
|
ACRA.errorReporter.putCustomData("error_source", name)
|
||||||
|
this.sendSilentlyWithAcra()
|
||||||
|
}
|
||||||
+1
-30
@@ -7,13 +7,10 @@ import android.widget.*
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityAddSourceBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityAddSourceBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid
|
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid
|
||||||
import bou.amine.apps.readerforselfossv2.model.NetworkUnavailableException
|
import bou.amine.apps.readerforselfossv2.model.NetworkUnavailableException
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import com.ftinc.scoop.Scoop
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -26,7 +23,6 @@ class AddSourceActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
private var mSpoutsValue: String? = null
|
private var mSpoutsValue: String? = null
|
||||||
|
|
||||||
private lateinit var appColors: AppColors
|
|
||||||
private lateinit var binding: ActivityAddSourceBinding
|
private lateinit var binding: ActivityAddSourceBinding
|
||||||
|
|
||||||
override val di by closestDI()
|
override val di by closestDI()
|
||||||
@@ -34,43 +30,18 @@ class AddSourceActivity : AppCompatActivity(), DIAware {
|
|||||||
private val appSettingsService : AppSettingsService by instance()
|
private val appSettingsService : AppSettingsService by instance()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
appColors = AppColors(this@AddSourceActivity)
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityAddSourceBinding.inflate(layoutInflater)
|
binding = ActivityAddSourceBinding.inflate(layoutInflater)
|
||||||
val view = binding.root
|
val view = binding.root
|
||||||
|
|
||||||
setContentView(view)
|
setContentView(view)
|
||||||
|
|
||||||
val scoop = Scoop.getInstance()
|
|
||||||
scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar)
|
|
||||||
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
|
|
||||||
|
|
||||||
val drawable = binding.nameInput.background
|
|
||||||
drawable.setTint(appColors.colorAccent)
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: clean
|
|
||||||
binding.nameInput.background = drawable
|
|
||||||
|
|
||||||
val drawable1 = binding.sourceUri.background
|
|
||||||
drawable1.setTint(appColors.colorAccent)
|
|
||||||
|
|
||||||
binding.sourceUri.background = drawable1
|
|
||||||
|
|
||||||
val drawable2 = binding.tags.background
|
|
||||||
drawable2.setTint(appColors.colorAccent)
|
|
||||||
|
|
||||||
binding.tags.background = drawable2
|
|
||||||
|
|
||||||
setSupportActionBar(binding.toolbar)
|
setSupportActionBar(binding.toolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
|
|
||||||
maybeGetDetailsFromIntentSharing(intent, binding.sourceUri, binding.nameInput)
|
maybeGetDetailsFromIntentSharing(intent, binding.sourceUri, binding.nameInput)
|
||||||
|
|
||||||
binding.saveBtn.setTextColor(appColors.colorAccent)
|
|
||||||
|
|
||||||
binding.saveBtn.setOnClickListener {
|
binding.saveBtn.setOnClickListener {
|
||||||
handleSaveSource(
|
handleSaveSource(
|
||||||
binding.tags,
|
binding.tags,
|
||||||
@@ -123,7 +94,7 @@ class AddSourceActivity : AppCompatActivity(), DIAware {
|
|||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
try {
|
try {
|
||||||
val items = repository.getSpouts()
|
val items = repository.getSpouts()
|
||||||
if (items != null) {
|
if (items.isNotEmpty()) {
|
||||||
val itemsStrings = items.map { it.value.name }
|
val itemsStrings = items.map { it.value.name }
|
||||||
for ((key, value) in items) {
|
for ((key, value) in items) {
|
||||||
spoutsKV[value.name] = key
|
spoutsKV[value.name] = key
|
||||||
|
|||||||
+80
-388
@@ -1,23 +1,18 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android
|
package bou.amine.apps.readerforselfossv2.android
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.graphics.drawable.GradientDrawable
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.view.doOnNextLayout
|
import androidx.core.view.doOnNextLayout
|
||||||
import androidx.drawerlayout.widget.DrawerLayout
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.*
|
import androidx.recyclerview.widget.*
|
||||||
import androidx.work.Constraints
|
import androidx.work.Constraints
|
||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
@@ -28,50 +23,31 @@ import bou.amine.apps.readerforselfossv2.android.adapters.ItemListAdapter
|
|||||||
import bou.amine.apps.readerforselfossv2.android.adapters.ItemsAdapter
|
import bou.amine.apps.readerforselfossv2.android.adapters.ItemsAdapter
|
||||||
import bou.amine.apps.readerforselfossv2.android.background.LoadingWorker
|
import bou.amine.apps.readerforselfossv2.android.background.LoadingWorker
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityHomeBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityHomeBinding
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.fragments.FilterSheetFragment
|
||||||
import bou.amine.apps.readerforselfossv2.android.settings.SettingsActivity
|
import bou.amine.apps.readerforselfossv2.android.settings.SettingsActivity
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.maybeShow
|
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.maybeShow
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.removeBadge
|
import bou.amine.apps.readerforselfossv2.android.utils.bottombar.removeBadge
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.*
|
import bou.amine.apps.readerforselfossv2.utils.ItemType
|
||||||
import com.ashokvarma.bottomnavigation.BottomNavigationBar
|
import com.ashokvarma.bottomnavigation.BottomNavigationBar
|
||||||
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
||||||
import com.ashokvarma.bottomnavigation.TextBadgeItem
|
import com.ashokvarma.bottomnavigation.TextBadgeItem
|
||||||
import com.bumptech.glide.Glide
|
|
||||||
import com.bumptech.glide.request.RequestOptions
|
|
||||||
import com.ftinc.scoop.Scoop
|
|
||||||
import com.mikepenz.aboutlibraries.LibsBuilder
|
|
||||||
import com.mikepenz.materialdrawer.holder.BadgeStyle
|
|
||||||
import com.mikepenz.materialdrawer.holder.ColorHolder
|
|
||||||
import com.mikepenz.materialdrawer.holder.StringHolder
|
|
||||||
import com.mikepenz.materialdrawer.model.DividerDrawerItem
|
|
||||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
|
|
||||||
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem
|
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.*
|
|
||||||
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
|
||||||
import com.mikepenz.materialdrawer.util.addStickyFooterItem
|
|
||||||
import com.mikepenz.materialdrawer.util.updateBadge
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.kodein.di.DIAware
|
import org.kodein.di.DIAware
|
||||||
import org.kodein.di.android.closestDI
|
import org.kodein.di.android.closestDI
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
|
import org.matomo.sdk.Tracker
|
||||||
|
import org.matomo.sdk.extra.TrackHelper
|
||||||
|
import java.security.MessageDigest
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAware {
|
class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAware {
|
||||||
|
|
||||||
private val DRAWER_ID_TAGS = 100101L
|
|
||||||
private val DRAWER_ID_HIDDEN_TAGS = 101100L
|
|
||||||
private val DRAWER_ID_SOURCES = 100110L
|
|
||||||
private val DRAWER_ID_FILTERS = 100111L
|
|
||||||
|
|
||||||
private var items: ArrayList<SelfossModel.Item> = ArrayList()
|
private var items: ArrayList<SelfossModel.Item> = ArrayList()
|
||||||
|
|
||||||
private var elementsShown: ItemType = ItemType.UNREAD
|
private var elementsShown: ItemType = ItemType.UNREAD
|
||||||
@@ -80,8 +56,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
private lateinit var tabNewBadge: TextBadgeItem
|
private lateinit var tabNewBadge: TextBadgeItem
|
||||||
private lateinit var tabArchiveBadge: TextBadgeItem
|
private lateinit var tabArchiveBadge: TextBadgeItem
|
||||||
private lateinit var tabStarredBadge: TextBadgeItem
|
private lateinit var tabStarredBadge: TextBadgeItem
|
||||||
private lateinit var customTabActivityHelper: CustomTabActivityHelper
|
|
||||||
private lateinit var appColors: AppColors
|
|
||||||
private var offset: Int = 0
|
private var offset: Int = 0
|
||||||
private var firstVisible: Int = 0
|
private var firstVisible: Int = 0
|
||||||
private lateinit var recyclerViewScrollListener: RecyclerView.OnScrollListener
|
private lateinit var recyclerViewScrollListener: RecyclerView.OnScrollListener
|
||||||
@@ -91,33 +65,23 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
private var fromTabShortcut: Boolean = false
|
private var fromTabShortcut: Boolean = false
|
||||||
|
|
||||||
private lateinit var tagsBadge: Map<Long, Int>
|
|
||||||
|
|
||||||
private val settingsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
private val settingsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
appSettingsService.refreshUserSettings()
|
appSettingsService.refreshUserSettings()
|
||||||
recreate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val di by closestDI()
|
override val di by closestDI()
|
||||||
private val repository : Repository by instance()
|
private val repository : Repository by instance()
|
||||||
private val appSettingsService : AppSettingsService by instance()
|
private val appSettingsService : AppSettingsService by instance()
|
||||||
|
private val tracker : Tracker by instance()
|
||||||
|
|
||||||
data class DrawerData(val tags: List<SelfossModel.Tag>?, val sources: List<SelfossModel.Source>?)
|
|
||||||
|
|
||||||
override fun onStart() {
|
|
||||||
super.onStart()
|
|
||||||
customTabActivityHelper.bindCustomTabsService(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
||||||
// Add appcolors to DI
|
|
||||||
appColors = AppColors(this@HomeActivity)
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityHomeBinding.inflate(layoutInflater)
|
binding = ActivityHomeBinding.inflate(layoutInflater)
|
||||||
val view = binding.root
|
val view = binding.root
|
||||||
|
|
||||||
|
TrackHelper.track().screen("/home").with(tracker)
|
||||||
|
|
||||||
fromTabShortcut = intent.getIntExtra("shortcutTab", -1) != -1
|
fromTabShortcut = intent.getIntExtra("shortcutTab", -1) != -1
|
||||||
repository.offlineOverride = intent.getBooleanExtra("startOffline", false)
|
repository.offlineOverride = intent.getBooleanExtra("startOffline", false)
|
||||||
|
|
||||||
@@ -127,29 +91,19 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
setContentView(view)
|
setContentView(view)
|
||||||
|
|
||||||
handleThemeBinding()
|
|
||||||
|
|
||||||
setSupportActionBar(binding.toolBar)
|
setSupportActionBar(binding.toolBar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
||||||
supportActionBar?.setHomeButtonEnabled(true)
|
|
||||||
val mDrawerToggle = ActionBarDrawerToggle(this, binding.drawerContainer, binding.toolBar, R.string.material_drawer_open, R.string.material_drawer_close)
|
|
||||||
binding.drawerContainer.addDrawerListener(mDrawerToggle)
|
|
||||||
mDrawerToggle.syncState()
|
|
||||||
|
|
||||||
customTabActivityHelper = CustomTabActivityHelper()
|
|
||||||
|
|
||||||
handleBottomBar()
|
handleBottomBar()
|
||||||
initDrawer()
|
|
||||||
|
|
||||||
handleSwipeRefreshLayout()
|
handleSwipeRefreshLayout()
|
||||||
|
|
||||||
getElementsAccordingToTab()
|
|
||||||
|
|
||||||
|
|
||||||
|
if (appSettingsService.isItemCachingEnabled()) {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
repository.tryToCacheItemsAndGetNewOnes()
|
repository.tryToCacheItemsAndGetNewOnes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleSwipeRefreshLayout() {
|
private fun handleSwipeRefreshLayout() {
|
||||||
binding.swipeRefreshLayout.setColorSchemeResources(
|
binding.swipeRefreshLayout.setColorSchemeResources(
|
||||||
@@ -160,7 +114,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||||
repository.offlineOverride = false
|
repository.offlineOverride = false
|
||||||
lastFetchDone = false
|
lastFetchDone = false
|
||||||
handleDrawerItems()
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
binding.swipeRefreshLayout.isRefreshing = false
|
binding.swipeRefreshLayout.isRefreshing = false
|
||||||
@@ -200,18 +153,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
adapter.handleItemAtIndex(position)
|
adapter.handleItemAtIndex(position)
|
||||||
|
|
||||||
reloadBadgeContent()
|
|
||||||
|
|
||||||
val tagHashes = i.tags.map { it.longHash() }
|
|
||||||
tagsBadge = tagsBadge.map {
|
|
||||||
if (tagHashes.contains(it.key)) {
|
|
||||||
(it.key to (it.value - 1))
|
|
||||||
} else {
|
|
||||||
(it.key to it.value)
|
|
||||||
}
|
|
||||||
}.toMap()
|
|
||||||
reloadTagsBadges()
|
|
||||||
|
|
||||||
// Just load everythin
|
// Just load everythin
|
||||||
if (items.size <= 0) {
|
if (items.size <= 0) {
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
@@ -229,32 +170,61 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
ItemTouchHelper(simpleItemTouchCallback).attachToRecyclerView(binding.recyclerView)
|
ItemTouchHelper(simpleItemTouchCallback).attachToRecyclerView(binding.recyclerView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateBottomBarBadgeCount(badge: TextBadgeItem, count: Int) {
|
||||||
|
if (count > 0) {
|
||||||
|
badge
|
||||||
|
.setText(count.toString())
|
||||||
|
.maybeShow()
|
||||||
|
} else {
|
||||||
|
badge.removeBadge()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleBottomBar() {
|
private fun handleBottomBar() {
|
||||||
|
|
||||||
tabNewBadge = TextBadgeItem()
|
tabNewBadge = TextBadgeItem()
|
||||||
.setText("")
|
.setText("")
|
||||||
.setHideOnSelect(false).hide(false)
|
.setHideOnSelect(false).hide(false)
|
||||||
.setBackgroundColor(appColors.colorPrimary)
|
|
||||||
tabArchiveBadge = TextBadgeItem()
|
tabArchiveBadge = TextBadgeItem()
|
||||||
.setText("")
|
.setText("")
|
||||||
.setHideOnSelect(false).hide(false)
|
.setHideOnSelect(false).hide(false)
|
||||||
.setBackgroundColor(appColors.colorPrimary)
|
|
||||||
tabStarredBadge = TextBadgeItem()
|
tabStarredBadge = TextBadgeItem()
|
||||||
.setText("")
|
.setText("")
|
||||||
.setHideOnSelect(false).hide(false)
|
.setHideOnSelect(false).hide(false)
|
||||||
.setBackgroundColor(appColors.colorPrimary)
|
|
||||||
|
if (appSettingsService.isDisplayUnreadCountEnabled()) {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
repository.badgeUnread.collect {
|
||||||
|
updateBottomBarBadgeCount(tabNewBadge, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appSettingsService.isDisplayAllCountEnabled()) {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
repository.badgeAll.collect {
|
||||||
|
updateBottomBarBadgeCount(tabArchiveBadge, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
repository.badgeStarred.collect {
|
||||||
|
updateBottomBarBadgeCount(tabStarredBadge, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val tabNew =
|
val tabNew =
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
R.drawable.ic_tab_fiber_new_black_24dp,
|
R.drawable.ic_tab_fiber_new_black_24dp,
|
||||||
getString(R.string.tab_new)
|
getString(R.string.tab_new)
|
||||||
).setActiveColor(appColors.colorAccent)
|
)
|
||||||
.setBadgeItem(tabNewBadge)
|
.setBadgeItem(tabNewBadge)
|
||||||
val tabArchive =
|
val tabArchive =
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
R.drawable.ic_tab_archive_black_24dp,
|
R.drawable.ic_tab_archive_black_24dp,
|
||||||
getString(R.string.tab_read)
|
getString(R.string.tab_read)
|
||||||
).setActiveColor(appColors.colorAccentDark)
|
)
|
||||||
.setBadgeItem(tabArchiveBadge)
|
.setBadgeItem(tabArchiveBadge)
|
||||||
val tabStarred =
|
val tabStarred =
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
@@ -270,7 +240,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
.setFirstSelectedPosition(0)
|
.setFirstSelectedPosition(0)
|
||||||
.initialise()
|
.initialise()
|
||||||
binding.bottomBar.setMode(BottomNavigationBar.MODE_SHIFTING)
|
binding.bottomBar.setMode(BottomNavigationBar.MODE_SHIFTING)
|
||||||
binding.bottomBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC)
|
|
||||||
|
|
||||||
if (fromTabShortcut) {
|
if (fromTabShortcut) {
|
||||||
binding.bottomBar.selectTab(elementsShown.position - 1)
|
binding.bottomBar.selectTab(elementsShown.position - 1)
|
||||||
@@ -280,12 +249,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
appColors = AppColors(this@HomeActivity)
|
|
||||||
|
|
||||||
handleDrawerItems()
|
|
||||||
|
|
||||||
handleThemeUpdate()
|
|
||||||
|
|
||||||
reloadLayoutManager()
|
reloadLayoutManager()
|
||||||
|
|
||||||
if (appSettingsService.isInfiniteLoadingEnabled()) {
|
if (appSettingsService.isInfiniteLoadingEnabled()) {
|
||||||
@@ -296,6 +259,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
handleBottomBarActions()
|
handleBottomBarActions()
|
||||||
|
|
||||||
|
handleGDPRDialog(appSettingsService.settings.getBoolean("GDPR_shown", false))
|
||||||
|
|
||||||
handleRecurringTask()
|
handleRecurringTask()
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
@@ -305,276 +270,22 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
|
||||||
super.onStop()
|
|
||||||
customTabActivityHelper.unbindCustomTabsService(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleThemeBinding() {
|
private fun handleGDPRDialog(GDPRShown: Boolean) {
|
||||||
val scoop = Scoop.getInstance()
|
val messageDigest: MessageDigest = MessageDigest.getInstance("SHA-256")
|
||||||
scoop.bind(this, Toppings.PRIMARY.value, binding.toolBar)
|
messageDigest.update(appSettingsService.getBaseUrl().toByteArray())
|
||||||
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
|
if (!GDPRShown) {
|
||||||
|
val alertDialog = AlertDialog.Builder(this).create()
|
||||||
|
alertDialog.setTitle(getString(R.string.gdpr_dialog_title))
|
||||||
|
alertDialog.setMessage(getString(R.string.gdpr_dialog_message))
|
||||||
|
alertDialog.setButton(
|
||||||
|
AlertDialog.BUTTON_NEUTRAL,
|
||||||
|
"OK"
|
||||||
|
) { dialog, _ ->
|
||||||
|
appSettingsService.settings.putBoolean("GDPR_shown", true)
|
||||||
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
alertDialog.show()
|
||||||
private fun handleThemeUpdate() {
|
|
||||||
|
|
||||||
val scoop = Scoop.getInstance()
|
|
||||||
scoop.update(Toppings.PRIMARY.value, appColors.colorPrimary)
|
|
||||||
|
|
||||||
scoop.update(Toppings.PRIMARY_DARK.value, appColors.colorPrimaryDark)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initDrawer() {
|
|
||||||
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
|
|
||||||
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
|
|
||||||
Glide.with(this@HomeActivity)
|
|
||||||
.asBitmap()
|
|
||||||
.load(uri)
|
|
||||||
.apply(RequestOptions()
|
|
||||||
.placeholder(R.mipmap.ic_launcher)
|
|
||||||
.fallback(R.mipmap.ic_launcher)
|
|
||||||
.fitCenter())
|
|
||||||
.into(imageView)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun cancel(imageView: ImageView) {
|
|
||||||
Glide.with(this@HomeActivity).clear(imageView)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
val drawerListener = object : DrawerLayout.DrawerListener {
|
|
||||||
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
|
|
||||||
// We do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDrawerOpened(drawerView: View) {
|
|
||||||
binding.bottomBar.hide()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDrawerClosed(drawerView: View) {
|
|
||||||
binding.bottomBar.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDrawerStateChanged(newState: Int) {
|
|
||||||
// We do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.drawerContainer.addDrawerListener(drawerListener)
|
|
||||||
|
|
||||||
// Sticky items
|
|
||||||
addStickyPrimaryItem(R.string.drawer_report_bug, R.drawable.ic_bug_report_black_24dp) { _, _, _ ->
|
|
||||||
val browserIntent =
|
|
||||||
Intent(Intent.ACTION_VIEW, Uri.parse(AppSettingsService.trackerUrl))
|
|
||||||
startActivity(browserIntent)
|
|
||||||
false
|
|
||||||
}
|
|
||||||
addStickyPrimaryItem(R.string.title_activity_settings, R.drawable.ic_settings_black_24dp) { _, _, _ ->
|
|
||||||
settingsLauncher.launch(Intent(this, SettingsActivity::class.java))
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addStickyPrimaryItem(name: Int, icon: Int, clickListener: ((v: View?, item: IDrawerItem<*>, position: Int) -> Boolean)?) {
|
|
||||||
binding.mainDrawer.addStickyFooterItem(
|
|
||||||
PrimaryDrawerItem().apply {
|
|
||||||
nameRes = name
|
|
||||||
iconRes = icon
|
|
||||||
isIconTinted = true
|
|
||||||
onDrawerItemClickListener = clickListener
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleDrawerItems() {
|
|
||||||
tagsBadge = emptyMap()
|
|
||||||
binding.mainDrawer.itemAdapter.add(
|
|
||||||
PrimaryDrawerItem().apply {
|
|
||||||
nameRes = R.string.drawer_loading
|
|
||||||
isSelectable = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
val drawerData = DrawerData(repository.getDBTags().map { it.toView() },
|
|
||||||
repository.getDBSources().map { it.toView() })
|
|
||||||
runOnUiThread {
|
|
||||||
// Only refresh if there is no data in the DB, or if the `UpdateSources` setting is enabled
|
|
||||||
if (drawerData.sources?.isEmpty() == true || appSettingsService.isUpdateSourcesEnabled()) {
|
|
||||||
drawerApiCalls(drawerData)
|
|
||||||
} else {
|
|
||||||
handleDrawerData(drawerData, loadedFromCache = true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun drawerApiCalls(drawerData: DrawerData) {
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
|
||||||
val apiDrawerData = DrawerData(repository.getTags(), repository.getSources())
|
|
||||||
handleDrawerData(if (drawerData != apiDrawerData) apiDrawerData else drawerData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleDrawerData(drawerData: DrawerData, loadedFromCache: Boolean = false) {
|
|
||||||
binding.mainDrawer.itemAdapter.clear()
|
|
||||||
|
|
||||||
// Filters title with clear action
|
|
||||||
secondaryItem(withDivider = false, R.string.drawer_item_filters, DRAWER_ID_FILTERS, R.string.drawer_action_clear) { _,_,_ ->
|
|
||||||
repository.sourceFilter = null
|
|
||||||
repository.tagFilter = null
|
|
||||||
binding.mainDrawer.setSelectionAtPosition(-1)
|
|
||||||
getElementsAccordingToTab()
|
|
||||||
fetchOnEmptyList()
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hidden tags
|
|
||||||
if (drawerData.tags != null && drawerData.tags.isNotEmpty() && appSettingsService.getHiddenTags().isNotEmpty()) {
|
|
||||||
secondaryItem(
|
|
||||||
withDivider = true,
|
|
||||||
R.string.drawer_item_hidden_tags,
|
|
||||||
DRAWER_ID_HIDDEN_TAGS
|
|
||||||
)
|
|
||||||
handleHiddenTags(drawerData.tags)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tags
|
|
||||||
secondaryItem(withDivider = true, R.string.drawer_item_tags, DRAWER_ID_TAGS)
|
|
||||||
if (drawerData.tags == null && !loadedFromCache) {
|
|
||||||
binding.mainDrawer.itemAdapter.add(
|
|
||||||
SecondaryDrawerItem()
|
|
||||||
.apply { nameRes = R.string.drawer_error_loading_tags; isSelectable = false }
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
handleTags(drawerData.tags!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sources
|
|
||||||
secondaryItem(withDivider = true, R.string.drawer_item_sources, DRAWER_ID_SOURCES, R.string.drawer_action_edit) { v, _, _ ->
|
|
||||||
startActivity(Intent(v!!.context, SourcesActivity::class.java))
|
|
||||||
false
|
|
||||||
}
|
|
||||||
if (drawerData.sources == null && !loadedFromCache) {
|
|
||||||
binding.mainDrawer.itemAdapter.add(
|
|
||||||
SecondaryDrawerItem().apply {
|
|
||||||
nameRes = R.string.drawer_error_loading_tags
|
|
||||||
isSelectable = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
handleSources(drawerData.sources!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
// About action
|
|
||||||
binding.mainDrawer.itemAdapter.add(
|
|
||||||
DividerDrawerItem(),
|
|
||||||
PrimaryDrawerItem().apply {
|
|
||||||
nameRes = R.string.action_about
|
|
||||||
isSelectable = false
|
|
||||||
iconRes = R.drawable.ic_info_outline_white_24dp
|
|
||||||
isIconTinted = true
|
|
||||||
onDrawerItemClickListener = { _,_,_ ->
|
|
||||||
LibsBuilder()
|
|
||||||
.withAboutIconShown(true)
|
|
||||||
.withAboutVersionShown(true)
|
|
||||||
.start(this@HomeActivity)
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun secondaryItem(withDivider: Boolean, name: Int, id: Long, badgeId: Int? = null, clickListener: ((v: View?, item: IDrawerItem<*>, position: Int) -> Boolean)? = null) {
|
|
||||||
if (withDivider) {
|
|
||||||
binding.mainDrawer.itemAdapter.add(DividerDrawerItem())
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.mainDrawer.itemAdapter.add(
|
|
||||||
SecondaryDrawerItem().apply {
|
|
||||||
nameRes = name
|
|
||||||
identifier = id
|
|
||||||
isSelectable = false
|
|
||||||
if (badgeId != null) {
|
|
||||||
badgeRes = badgeId
|
|
||||||
}
|
|
||||||
onDrawerItemClickListener = clickListener
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createDrawerItem(it: SelfossModel.Tag) {
|
|
||||||
val gd = GradientDrawable()
|
|
||||||
val gdColor = try {
|
|
||||||
Color.parseColor(it.color)
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
appColors.colorPrimary
|
|
||||||
}
|
|
||||||
gd.setColor(gdColor)
|
|
||||||
gd.shape = GradientDrawable.RECTANGLE
|
|
||||||
gd.setSize(30, 30)
|
|
||||||
gd.cornerRadius = 30F
|
|
||||||
|
|
||||||
val drawerItem = PrimaryDrawerItem()
|
|
||||||
.apply {
|
|
||||||
nameText = it.tag.getHtmlDecoded()
|
|
||||||
identifier = it.tag.longHash()
|
|
||||||
iconDrawable = gd
|
|
||||||
badgeStyle = BadgeStyle().apply {
|
|
||||||
textColor = ColorHolder.fromColor(Color.WHITE)
|
|
||||||
color = ColorHolder.fromColor(appColors.colorAccent)
|
|
||||||
}
|
|
||||||
onDrawerItemClickListener = { _, _, _ ->
|
|
||||||
repository.tagFilter = it
|
|
||||||
repository.sourceFilter = null
|
|
||||||
getElementsAccordingToTab()
|
|
||||||
fetchOnEmptyList()
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (it.unread > 0) {
|
|
||||||
drawerItem.badgeText = it.unread.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.mainDrawer.itemAdapter.add(drawerItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleTags(tags: List<SelfossModel.Tag>) {
|
|
||||||
val filteredTags = tags
|
|
||||||
.filterNot { appSettingsService.getHiddenTags().contains(it.tag) }
|
|
||||||
.sortedBy { it.tag }
|
|
||||||
createTagItems(filteredTags)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleHiddenTags(tags: List<SelfossModel.Tag>) {
|
|
||||||
val filteredHiddenTags: List<SelfossModel.Tag> =
|
|
||||||
tags.filter { appSettingsService.getHiddenTags().contains(it.tag) }
|
|
||||||
createTagItems(filteredHiddenTags)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createTagItems(tags: List<SelfossModel.Tag>) {
|
|
||||||
tagsBadge = tags.associate {
|
|
||||||
createDrawerItem(it)
|
|
||||||
|
|
||||||
(it.tag.longHash() to it.unread)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleSources(sources: List<SelfossModel.Source>) {
|
|
||||||
for (source in sources) {
|
|
||||||
val item = PrimaryDrawerItem().apply {
|
|
||||||
nameText = source.title.getHtmlDecoded()
|
|
||||||
identifier = source.id.toLong()
|
|
||||||
iconUrl = source.getIcon(repository.baseUrl)
|
|
||||||
onDrawerItemClickListener = { _,_,_ ->
|
|
||||||
repository.sourceFilter = source
|
|
||||||
repository.tagFilter = null
|
|
||||||
getElementsAccordingToTab()
|
|
||||||
fetchOnEmptyList()
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binding.mainDrawer.itemAdapter.add(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -659,7 +370,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchOnEmptyList() {
|
fun fetchOnEmptyList() {
|
||||||
binding.recyclerView.doOnNextLayout {
|
binding.recyclerView.doOnNextLayout {
|
||||||
// TODO: do if last element (or is empty ?)
|
// TODO: do if last element (or is empty ?)
|
||||||
getElementsAccordingToTab(true)
|
getElementsAccordingToTab(true)
|
||||||
@@ -700,7 +411,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
binding.emptyText.visibility = View.GONE
|
binding.emptyText.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getElementsAccordingToTab(
|
fun getElementsAccordingToTab(
|
||||||
appendResults: Boolean = false
|
appendResults: Boolean = false
|
||||||
) {
|
) {
|
||||||
offset = if (appendResults && items.size > 0) {
|
offset = if (appendResults && items.size > 0) {
|
||||||
@@ -745,8 +456,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
ItemCardAdapter(
|
ItemCardAdapter(
|
||||||
this,
|
this,
|
||||||
items,
|
items,
|
||||||
customTabActivityHelper,
|
|
||||||
appColors,
|
|
||||||
) {
|
) {
|
||||||
updateItems(it)
|
updateItems(it)
|
||||||
}
|
}
|
||||||
@@ -755,8 +464,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
ItemListAdapter(
|
ItemListAdapter(
|
||||||
this,
|
this,
|
||||||
items,
|
items,
|
||||||
customTabActivityHelper,
|
|
||||||
appColors,
|
|
||||||
) {
|
) {
|
||||||
updateItems(it)
|
updateItems(it)
|
||||||
}
|
}
|
||||||
@@ -779,36 +486,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
private fun reloadBadges() {
|
private fun reloadBadges() {
|
||||||
if (appSettingsService.isDisplayUnreadCountEnabled() || appSettingsService.isDisplayAllCountEnabled()) {
|
if (appSettingsService.isDisplayUnreadCountEnabled() || appSettingsService.isDisplayAllCountEnabled()) {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.reloadBadges()
|
repository.reloadBadges()
|
||||||
reloadBadgeContent()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reloadBadgeContent() {
|
|
||||||
if (appSettingsService.isDisplayUnreadCountEnabled()) {
|
|
||||||
tabNewBadge
|
|
||||||
.setText(repository.badgeUnread.toString())
|
|
||||||
.maybeShow()
|
|
||||||
}
|
|
||||||
if (appSettingsService.isDisplayAllCountEnabled()) {
|
|
||||||
tabArchiveBadge
|
|
||||||
.setText(repository.badgeAll.toString())
|
|
||||||
.maybeShow()
|
|
||||||
tabStarredBadge
|
|
||||||
.setText(repository.badgeStarred.toString())
|
|
||||||
.maybeShow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun reloadTagsBadges() {
|
|
||||||
tagsBadge.forEach {
|
|
||||||
binding.mainDrawer.updateBadge(it.key, StringHolder(it.value.toString()))
|
|
||||||
}
|
|
||||||
binding.mainDrawer.resetDrawerContent()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun calculateNoOfColumns(): Int {
|
private fun calculateNoOfColumns(): Int {
|
||||||
val displayMetrics = resources.displayMetrics
|
val displayMetrics = resources.displayMetrics
|
||||||
val dpWidth = displayMetrics.widthPixels / displayMetrics.density
|
val dpWidth = displayMetrics.widthPixels / displayMetrics.density
|
||||||
@@ -854,6 +537,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
|
R.id.action_filter -> {
|
||||||
|
val filterSheetFragment = FilterSheetFragment()
|
||||||
|
filterSheetFragment.show(supportFragmentManager, FilterSheetFragment.TAG)
|
||||||
|
return true
|
||||||
|
}
|
||||||
R.id.refresh -> {
|
R.id.refresh -> {
|
||||||
needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message) {
|
needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message) {
|
||||||
Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show()
|
||||||
@@ -893,8 +581,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
).show()
|
).show()
|
||||||
tabNewBadge.removeBadge()
|
tabNewBadge.removeBadge()
|
||||||
|
|
||||||
handleDrawerItems()
|
|
||||||
|
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
@@ -911,22 +597,28 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_disconnect -> {
|
R.id.action_disconnect -> {
|
||||||
appSettingsService.clearAll()
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
repository.logout()
|
||||||
|
}
|
||||||
val intent = Intent(this, LoginActivity::class.java)
|
val intent = Intent(this, LoginActivity::class.java)
|
||||||
this.startActivity(intent)
|
this.startActivity(intent)
|
||||||
this@HomeActivity.finish()
|
this@HomeActivity.finish()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
R.id.action_settings -> {
|
||||||
|
settingsLauncher.launch(Intent(this, SettingsActivity::class.java))
|
||||||
|
return true
|
||||||
|
}
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun maxItemNumber(): Int =
|
private fun maxItemNumber(): Int =
|
||||||
when (elementsShown) {
|
when (elementsShown) {
|
||||||
ItemType.UNREAD -> repository.badgeUnread
|
ItemType.UNREAD -> repository.badgeUnread.value
|
||||||
ItemType.ALL -> repository.badgeAll
|
ItemType.ALL -> repository.badgeAll.value
|
||||||
ItemType.STARRED -> repository.badgeStarred
|
ItemType.STARRED -> repository.badgeStarred.value
|
||||||
else -> repository.badgeUnread // if !elementsShown then unread are fetched.
|
else -> repository.badgeUnread.value // if !elementsShown then unread are fetched.
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateItems(adapterItems: ArrayList<SelfossModel.Item>) {
|
private fun updateItems(adapterItems: ArrayList<SelfossModel.Item>) {
|
||||||
|
|||||||
+36
-7
@@ -2,6 +2,7 @@ package bou.amine.apps.readerforselfossv2.android
|
|||||||
|
|
||||||
import android.animation.Animator
|
import android.animation.Animator
|
||||||
import android.animation.AnimatorListenerAdapter
|
import android.animation.AnimatorListenerAdapter
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
@@ -12,8 +13,8 @@ import android.view.inputmethod.EditorInfo
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid
|
import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
@@ -24,23 +25,35 @@ import kotlinx.coroutines.launch
|
|||||||
import org.kodein.di.DIAware
|
import org.kodein.di.DIAware
|
||||||
import org.kodein.di.android.closestDI
|
import org.kodein.di.android.closestDI
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
|
import org.matomo.sdk.Tracker
|
||||||
|
import org.matomo.sdk.extra.DimensionQueue
|
||||||
|
import org.matomo.sdk.extra.DownloadTracker
|
||||||
|
import org.matomo.sdk.extra.TrackHelper
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
|
|
||||||
class LoginActivity : AppCompatActivity(), DIAware {
|
class LoginActivity : AppCompatActivity(), DIAware {
|
||||||
|
|
||||||
private var inValidCount: Int = 0
|
private var inValidCount: Int = 0
|
||||||
private var isWithLogin = false
|
private var isWithLogin = false
|
||||||
|
|
||||||
private lateinit var appColors: AppColors
|
|
||||||
private lateinit var binding: ActivityLoginBinding
|
private lateinit var binding: ActivityLoginBinding
|
||||||
|
|
||||||
override val di by closestDI()
|
override val di by closestDI()
|
||||||
private val repository : Repository by instance()
|
private val repository : Repository by instance()
|
||||||
private val appSettingsService : AppSettingsService by instance()
|
private val appSettingsService : AppSettingsService by instance()
|
||||||
|
private val tracker : Tracker by instance()
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
appColors = AppColors(this@LoginActivity)
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
TrackHelper.track().download().identifier(DownloadTracker.Extra.ApkChecksum(applicationContext))
|
||||||
|
.with(tracker)
|
||||||
|
TrackHelper.track().screen("/login").with(tracker)
|
||||||
|
|
||||||
|
handleTheme()
|
||||||
|
|
||||||
binding = ActivityLoginBinding.inflate(layoutInflater)
|
binding = ActivityLoginBinding.inflate(layoutInflater)
|
||||||
val view = binding.root
|
val view = binding.root
|
||||||
|
|
||||||
@@ -57,6 +70,11 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
handleActions()
|
handleActions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("WrongConstant") // Constant is fetched from the settings
|
||||||
|
private fun handleTheme() {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(appSettingsService.getCurrentTheme())
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleActions() {
|
private fun handleActions() {
|
||||||
|
|
||||||
binding.passwordView.setOnEditorActionListener(
|
binding.passwordView.setOnEditorActionListener(
|
||||||
@@ -94,12 +112,24 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun goToMain() {
|
private fun goToMain() {
|
||||||
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
repository.updateApiVersion()
|
||||||
|
|
||||||
|
val messageDigest: MessageDigest = MessageDigest.getInstance("SHA-256")
|
||||||
|
messageDigest.update(appSettingsService.getBaseUrl().toByteArray())
|
||||||
|
tracker.userId = String(messageDigest.digest())
|
||||||
|
|
||||||
|
val mDimensionQueue = DimensionQueue(tracker)
|
||||||
|
mDimensionQueue.add(1, appSettingsService.getApiVersion().toString())
|
||||||
|
|
||||||
|
tracker.isOptOut = !appSettingsService.isAnalyticsEnabled()
|
||||||
|
}
|
||||||
val intent = Intent(this, HomeActivity::class.java)
|
val intent = Intent(this, HomeActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun preferenceError(t: Throwable) {
|
private fun preferenceError() {
|
||||||
appSettingsService.resetLoginInformation()
|
appSettingsService.resetLoginInformation()
|
||||||
|
|
||||||
binding.urlView.error = getString(R.string.wrong_infos)
|
binding.urlView.error = getString(R.string.wrong_infos)
|
||||||
@@ -164,11 +194,10 @@ class LoginActivity : AppCompatActivity(), DIAware {
|
|||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val result = repository.login()
|
val result = repository.login()
|
||||||
if (result) {
|
if (result) {
|
||||||
repository.updateApiVersion()
|
|
||||||
goToMain()
|
goToMain()
|
||||||
} else {
|
} else {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
preferenceError(Exception("Not success"))
|
preferenceError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import androidx.lifecycle.DefaultLifecycleObserver
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.ProcessLifecycleOwner
|
import androidx.lifecycle.ProcessLifecycleOwner
|
||||||
import androidx.multidex.MultiDexApplication
|
import androidx.multidex.MultiDexApplication
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import bou.amine.apps.readerforselfossv2.DI.networkModule
|
import bou.amine.apps.readerforselfossv2.DI.networkModule
|
||||||
import bou.amine.apps.readerforselfossv2.android.viewmodel.AppViewModel
|
import bou.amine.apps.readerforselfossv2.android.viewmodel.AppViewModel
|
||||||
import bou.amine.apps.readerforselfossv2.dao.DriverFactory
|
import bou.amine.apps.readerforselfossv2.dao.DriverFactory
|
||||||
@@ -21,16 +20,24 @@ import bou.amine.apps.readerforselfossv2.repository.Repository
|
|||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import com.ftinc.scoop.Scoop
|
|
||||||
import com.github.ln_12.library.ConnectivityStatus
|
import com.github.ln_12.library.ConnectivityStatus
|
||||||
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
|
||||||
import io.github.aakira.napier.DebugAntilog
|
import io.github.aakira.napier.DebugAntilog
|
||||||
import io.github.aakira.napier.Napier
|
import io.github.aakira.napier.Napier
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.acra.ACRA
|
||||||
|
import org.acra.ReportField
|
||||||
|
import org.acra.config.httpSender
|
||||||
|
import org.acra.config.toast
|
||||||
|
import org.acra.data.StringFormat
|
||||||
|
import org.acra.ktx.initAcra
|
||||||
|
import org.acra.sender.HttpSender
|
||||||
import org.kodein.di.*
|
import org.kodein.di.*
|
||||||
|
import org.matomo.sdk.Matomo
|
||||||
|
import org.matomo.sdk.Tracker
|
||||||
|
import org.matomo.sdk.TrackerBuilder
|
||||||
|
|
||||||
class MyApp : MultiDexApplication(), DIAware {
|
class MyApp : MultiDexApplication(), DIAware {
|
||||||
|
|
||||||
@@ -38,9 +45,11 @@ class MyApp : MultiDexApplication(), DIAware {
|
|||||||
import(networkModule)
|
import(networkModule)
|
||||||
bind<DriverFactory>() with singleton { DriverFactory(applicationContext) }
|
bind<DriverFactory>() with singleton { DriverFactory(applicationContext) }
|
||||||
bind<ReaderForSelfossDB>() with singleton { ReaderForSelfossDB(driverFactory.createDriver()) }
|
bind<ReaderForSelfossDB>() with singleton { ReaderForSelfossDB(driverFactory.createDriver()) }
|
||||||
bind<Repository>() with singleton { Repository(instance(), instance(), connectivityStatus, instance()) }
|
bind<Repository>() with singleton { Repository(instance(), instance(), isConnectionAvailable, instance()) }
|
||||||
bind<ConnectivityStatus>() with singleton { ConnectivityStatus(applicationContext) }
|
bind<ConnectivityStatus>() with singleton { ConnectivityStatus(applicationContext) }
|
||||||
bind<AppViewModel>() with singleton { AppViewModel(repository = instance()) }
|
bind<AppViewModel>() with singleton { AppViewModel(repository = instance()) }
|
||||||
|
bind<Tracker>() with singleton { TrackerBuilder.createDefault("https://matomo.amine-louveau.fr/matomo.php", if (BuildConfig.DEBUG) 4 else 5).build(
|
||||||
|
Matomo.getInstance(applicationContext)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val repository: Repository by instance()
|
private val repository: Repository by instance()
|
||||||
@@ -48,14 +57,14 @@ class MyApp : MultiDexApplication(), DIAware {
|
|||||||
private val connectivityStatus: ConnectivityStatus by instance()
|
private val connectivityStatus: ConnectivityStatus by instance()
|
||||||
private val driverFactory: DriverFactory by instance()
|
private val driverFactory: DriverFactory by instance()
|
||||||
|
|
||||||
|
// TODO: handle with the "previous" way
|
||||||
|
private val isConnectionAvailable: MutableStateFlow<Boolean> = MutableStateFlow(true)
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
Napier.base(DebugAntilog())
|
Napier.base(DebugAntilog())
|
||||||
|
|
||||||
initDrawerImageLoader()
|
if (!ACRA.isACRASenderServiceProcess()) {
|
||||||
|
|
||||||
initTheme()
|
|
||||||
|
|
||||||
tryToHandleBug()
|
tryToHandleBug()
|
||||||
|
|
||||||
handleNotificationChannels()
|
handleNotificationChannels()
|
||||||
@@ -78,7 +87,34 @@ class MyApp : MultiDexApplication(), DIAware {
|
|||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun attachBaseContext(base: Context?) {
|
||||||
|
super.attachBaseContext(base)
|
||||||
|
|
||||||
|
initAcra {
|
||||||
|
reportFormat = StringFormat.JSON
|
||||||
|
reportContent = listOf(
|
||||||
|
ReportField.REPORT_ID, ReportField.INSTALLATION_ID,
|
||||||
|
ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME,
|
||||||
|
ReportField.BUILD, ReportField.ANDROID_VERSION, ReportField.BRAND, ReportField.PHONE_MODEL,
|
||||||
|
ReportField.AVAILABLE_MEM_SIZE, ReportField.TOTAL_MEM_SIZE,
|
||||||
|
ReportField.STACK_TRACE, ReportField.APPLICATION_LOG, ReportField.LOGCAT,
|
||||||
|
ReportField.INITIAL_CONFIGURATION, ReportField.CRASH_CONFIGURATION, ReportField.IS_SILENT,
|
||||||
|
ReportField.USER_APP_START_DATE, ReportField.USER_COMMENT, ReportField.USER_CRASH_DATE, ReportField.USER_EMAIL, ReportField.CUSTOM_DATA)
|
||||||
|
toast {
|
||||||
|
//required
|
||||||
|
text = getString(R.string.crash_toast_text)
|
||||||
|
length = Toast.LENGTH_SHORT
|
||||||
|
}
|
||||||
|
httpSender {
|
||||||
|
uri = "https://bugs.amine-louveau.fr/report" /*best guess, you may need to adjust this*/
|
||||||
|
basicAuthLogin = "LMTlLZuazADohTCm"
|
||||||
|
basicAuthPassword = "he6ghHp83F0PYPfh"
|
||||||
|
httpMethod = HttpSender.Method.POST
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleNotificationChannels() {
|
private fun handleNotificationChannels() {
|
||||||
@@ -98,41 +134,13 @@ class MyApp : MultiDexApplication(), DIAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initDrawerImageLoader() {
|
|
||||||
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
|
|
||||||
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
|
|
||||||
Glide.with(imageView.context)
|
|
||||||
.load(uri.toString())
|
|
||||||
.apply(RequestOptions.fitCenterTransform().placeholder(placeholder))
|
|
||||||
.into(imageView)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun cancel(imageView: ImageView) {
|
|
||||||
Glide.with(imageView.context).clear(imageView)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun placeholder(ctx: Context, tag: String?): Drawable {
|
|
||||||
return baseContext.resources.getDrawable(R.mipmap.ic_launcher)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun initTheme() {
|
|
||||||
Scoop.waffleCone()
|
|
||||||
.addFlavor(getString(R.string.default_theme), R.style.NoBar, true)
|
|
||||||
.addFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark, false)
|
|
||||||
.setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this))
|
|
||||||
.initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun tryToHandleBug() {
|
private fun tryToHandleBug() {
|
||||||
val oldHandler = Thread.getDefaultUncaughtExceptionHandler()
|
val oldHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler { thread, e ->
|
Thread.setDefaultUncaughtExceptionHandler { thread, e ->
|
||||||
if (e is java.lang.NoClassDefFoundError && e.stackTrace.asList().any {
|
if (e is NoClassDefFoundError && e.stackTrace.asList().any {
|
||||||
it.toString().contains("android.view.ViewDebug")
|
it.toString().contains("android.view.ViewDebug")
|
||||||
}) {
|
}) {
|
||||||
Unit
|
|
||||||
} else {
|
} else {
|
||||||
oldHandler.uncaughtException(thread, e)
|
oldHandler.uncaughtException(thread, e)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-11
@@ -12,12 +12,9 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
|
|||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityReaderBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivityReaderBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.fragments.ArticleFragment
|
import bou.amine.apps.readerforselfossv2.android.fragments.ArticleFragment
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import com.ftinc.scoop.Scoop
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -28,7 +25,6 @@ import org.kodein.di.instance
|
|||||||
class ReaderActivity : AppCompatActivity(), DIAware {
|
class ReaderActivity : AppCompatActivity(), DIAware {
|
||||||
|
|
||||||
private var currentItem: Int = 0
|
private var currentItem: Int = 0
|
||||||
private lateinit var appColors: AppColors
|
|
||||||
|
|
||||||
private lateinit var toolbarMenu: Menu
|
private lateinit var toolbarMenu: Menu
|
||||||
|
|
||||||
@@ -40,9 +36,9 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
private fun showMenuItem(willAddToFavorite: Boolean) {
|
private fun showMenuItem(willAddToFavorite: Boolean) {
|
||||||
if (willAddToFavorite) {
|
if (willAddToFavorite) {
|
||||||
toolbarMenu.findItem(R.id.star).icon.setTint(Color.WHITE)
|
toolbarMenu.findItem(R.id.star).icon?.setTint(Color.WHITE)
|
||||||
} else {
|
} else {
|
||||||
toolbarMenu.findItem(R.id.star).icon.setTint(Color.RED)
|
toolbarMenu.findItem(R.id.star).icon?.setTint(Color.RED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,16 +52,11 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
appColors = AppColors(this)
|
|
||||||
binding = ActivityReaderBinding.inflate(layoutInflater)
|
binding = ActivityReaderBinding.inflate(layoutInflater)
|
||||||
val view = binding.root
|
val view = binding.root
|
||||||
|
|
||||||
setContentView(view)
|
setContentView(view)
|
||||||
|
|
||||||
val scoop = Scoop.getInstance()
|
|
||||||
scoop.bind(this, Toppings.PRIMARY.value, binding.toolBar)
|
|
||||||
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
|
|
||||||
|
|
||||||
setSupportActionBar(binding.toolBar)
|
setSupportActionBar(binding.toolBar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
|
|||||||
+3
-19
@@ -8,11 +8,8 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import bou.amine.apps.readerforselfossv2.android.adapters.SourcesListAdapter
|
import bou.amine.apps.readerforselfossv2.android.adapters.SourcesListAdapter
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import com.ftinc.scoop.Scoop
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -22,21 +19,15 @@ import org.kodein.di.instance
|
|||||||
|
|
||||||
class SourcesActivity : AppCompatActivity(), DIAware {
|
class SourcesActivity : AppCompatActivity(), DIAware {
|
||||||
|
|
||||||
private lateinit var appColors: AppColors
|
|
||||||
private lateinit var binding: ActivitySourcesBinding
|
private lateinit var binding: ActivitySourcesBinding
|
||||||
|
|
||||||
override val di by closestDI()
|
override val di by closestDI()
|
||||||
private val repository : Repository by instance()
|
private val repository : Repository by instance()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
appColors = AppColors(this@SourcesActivity)
|
|
||||||
binding = ActivitySourcesBinding.inflate(layoutInflater)
|
binding = ActivitySourcesBinding.inflate(layoutInflater)
|
||||||
val view = binding.root
|
val view = binding.root
|
||||||
|
|
||||||
val scoop = Scoop.getInstance()
|
|
||||||
scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar)
|
|
||||||
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
setContentView(view)
|
setContentView(view)
|
||||||
@@ -45,8 +36,8 @@ class SourcesActivity : AppCompatActivity(), DIAware {
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
|
|
||||||
binding.fab.rippleColor = appColors.colorAccentDark
|
binding.fab.rippleColor = resources.getColor(R.color.colorAccentDark)
|
||||||
binding.fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent)
|
binding.fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
@@ -65,20 +56,13 @@ class SourcesActivity : AppCompatActivity(), DIAware {
|
|||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
val response = repository.getSources()
|
val response = repository.getSources()
|
||||||
if (response != null) {
|
if (response.isNotEmpty()) {
|
||||||
items = response
|
items = response
|
||||||
val mAdapter = SourcesListAdapter(
|
val mAdapter = SourcesListAdapter(
|
||||||
this@SourcesActivity, items
|
this@SourcesActivity, items
|
||||||
)
|
)
|
||||||
binding.recyclerView.adapter = mAdapter
|
binding.recyclerView.adapter = mAdapter
|
||||||
mAdapter.notifyDataSetChanged()
|
mAdapter.notifyDataSetChanged()
|
||||||
if (items.isEmpty()) {
|
|
||||||
Toast.makeText(
|
|
||||||
this@SourcesActivity,
|
|
||||||
R.string.nothing_here,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@SourcesActivity,
|
this@SourcesActivity,
|
||||||
|
|||||||
+10
-20
@@ -10,11 +10,12 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import bou.amine.apps.readerforselfossv2.android.R
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
|
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.*
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.utils.shareLink
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
@@ -34,8 +35,6 @@ import org.kodein.di.instance
|
|||||||
class ItemCardAdapter(
|
class ItemCardAdapter(
|
||||||
override val app: Activity,
|
override val app: Activity,
|
||||||
override var items: ArrayList<SelfossModel.Item>,
|
override var items: ArrayList<SelfossModel.Item>,
|
||||||
private val helper: CustomTabActivityHelper,
|
|
||||||
override val appColors: AppColors,
|
|
||||||
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
||||||
) : ItemsAdapter<ItemCardAdapter.ViewHolder>() {
|
) : ItemsAdapter<ItemCardAdapter.ViewHolder>() {
|
||||||
private val c: Context = app.baseContext
|
private val c: Context = app.baseContext
|
||||||
@@ -44,8 +43,8 @@ class ItemCardAdapter(
|
|||||||
c.resources.getDimension(R.dimen.card_image_max_height).toInt()
|
c.resources.getDimension(R.dimen.card_image_max_height).toInt()
|
||||||
|
|
||||||
override val di: DI by closestDI(app)
|
override val di: DI by closestDI(app)
|
||||||
override val repository : Repository by instance()
|
override val repository: Repository by instance()
|
||||||
override val appSettingsService : AppSettingsService by instance()
|
override val appSettingsService: AppSettingsService by instance()
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val binding = CardItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding = CardItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
@@ -61,9 +60,9 @@ class ItemCardAdapter(
|
|||||||
|
|
||||||
binding.title.setOnTouchListener(LinkOnTouchListener())
|
binding.title.setOnTouchListener(LinkOnTouchListener())
|
||||||
|
|
||||||
binding.title.setLinkTextColor(appColors.colorAccent)
|
binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent))
|
||||||
|
|
||||||
binding.sourceTitleAndDate.text = itm.sourceAndDateText(repository.dateUtils)
|
binding.sourceTitleAndDate.text = itm.sourceAndDateText()
|
||||||
|
|
||||||
if (!appSettingsService.isFullHeightCardsEnabled()) {
|
if (!appSettingsService.isFullHeightCardsEnabled()) {
|
||||||
binding.itemImage.maxHeight = imageMaxHeight
|
binding.itemImage.maxHeight = imageMaxHeight
|
||||||
@@ -101,7 +100,7 @@ class ItemCardAdapter(
|
|||||||
inner class ViewHolder(val binding: CardItemBinding) : RecyclerView.ViewHolder(binding.root) {
|
inner class ViewHolder(val binding: CardItemBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||||
init {
|
init {
|
||||||
handleClickListeners()
|
handleClickListeners()
|
||||||
handleCustomTabActions()
|
handleLinkOpening()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleClickListeners() {
|
private fun handleClickListeners() {
|
||||||
@@ -111,16 +110,12 @@ class ItemCardAdapter(
|
|||||||
if (item.starred) {
|
if (item.starred) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.unstarr(item)
|
repository.unstarr(item)
|
||||||
// TODO: Handle failure
|
|
||||||
}
|
}
|
||||||
item.starred = false
|
|
||||||
binding.favButton.isSelected = false
|
binding.favButton.isSelected = false
|
||||||
} else {
|
} else {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.starr(item)
|
repository.starr(item)
|
||||||
// TODO: Handle failure
|
|
||||||
}
|
}
|
||||||
item.starred = true
|
|
||||||
binding.favButton.isSelected = true
|
binding.favButton.isSelected = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,17 +130,12 @@ class ItemCardAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleCustomTabActions() {
|
private fun handleLinkOpening() {
|
||||||
val customTabsIntent = c.buildCustomTabsIntent()
|
|
||||||
helper.bindCustomTabsService(app)
|
|
||||||
|
|
||||||
binding.root.setOnClickListener {
|
binding.root.setOnClickListener {
|
||||||
c.openItemUrl(
|
c.openItemUrl(
|
||||||
items,
|
items,
|
||||||
bindingAdapterPosition,
|
bindingAdapterPosition,
|
||||||
items[bindingAdapterPosition].getLinkDecoded(),
|
items[bindingAdapterPosition].getLinkDecoded(),
|
||||||
customTabsIntent,
|
|
||||||
appSettingsService.isInternalBrowserEnabled(),
|
|
||||||
appSettingsService.isArticleViewerEnabled(),
|
appSettingsService.isArticleViewerEnabled(),
|
||||||
app
|
app
|
||||||
)
|
)
|
||||||
|
|||||||
+5
-14
@@ -5,12 +5,10 @@ import android.content.Context
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ListItemBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ListItemBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
|
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener
|
import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.buildCustomTabsIntent
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl
|
import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl
|
||||||
@@ -29,8 +27,6 @@ import org.kodein.di.instance
|
|||||||
class ItemListAdapter(
|
class ItemListAdapter(
|
||||||
override val app: Activity,
|
override val app: Activity,
|
||||||
override var items: ArrayList<SelfossModel.Item>,
|
override var items: ArrayList<SelfossModel.Item>,
|
||||||
private val helper: CustomTabActivityHelper,
|
|
||||||
override val appColors: AppColors,
|
|
||||||
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
||||||
) : ItemsAdapter<ItemListAdapter.ViewHolder>() {
|
) : ItemsAdapter<ItemListAdapter.ViewHolder>() {
|
||||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||||
@@ -53,9 +49,9 @@ class ItemListAdapter(
|
|||||||
|
|
||||||
binding.title.setOnTouchListener(LinkOnTouchListener())
|
binding.title.setOnTouchListener(LinkOnTouchListener())
|
||||||
|
|
||||||
binding.title.setLinkTextColor(appColors.colorAccent)
|
binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent))
|
||||||
|
|
||||||
binding.sourceTitleAndDate.text = itm.sourceAndDateText(repository.dateUtils)
|
binding.sourceTitleAndDate.text = itm.sourceAndDateText()
|
||||||
|
|
||||||
if (itm.getThumbnail(repository.baseUrl).isEmpty()) {
|
if (itm.getThumbnail(repository.baseUrl).isEmpty()) {
|
||||||
|
|
||||||
@@ -83,20 +79,15 @@ class ItemListAdapter(
|
|||||||
inner class ViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root) {
|
inner class ViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
handleCustomTabActions()
|
handleLinkOpening()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleCustomTabActions() {
|
private fun handleLinkOpening() {
|
||||||
val customTabsIntent = c.buildCustomTabsIntent()
|
|
||||||
helper.bindCustomTabsService(app)
|
|
||||||
|
|
||||||
binding.root.setOnClickListener {
|
binding.root.setOnClickListener {
|
||||||
c.openItemUrl(
|
c.openItemUrl(
|
||||||
items,
|
items,
|
||||||
bindingAdapterPosition,
|
bindingAdapterPosition,
|
||||||
items[bindingAdapterPosition].getLinkDecoded(),
|
items[bindingAdapterPosition].getLinkDecoded(),
|
||||||
customTabsIntent,
|
|
||||||
appSettingsService.isInternalBrowserEnabled(),
|
|
||||||
appSettingsService.isArticleViewerEnabled(),
|
appSettingsService.isArticleViewerEnabled(),
|
||||||
app
|
app
|
||||||
)
|
)
|
||||||
|
|||||||
+13
-16
@@ -5,7 +5,6 @@ import android.graphics.Color
|
|||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
@@ -21,7 +20,6 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
abstract val repository: Repository
|
abstract val repository: Repository
|
||||||
abstract val appSettingsService: AppSettingsService
|
abstract val appSettingsService: AppSettingsService
|
||||||
abstract val app: Activity
|
abstract val app: Activity
|
||||||
abstract val appColors: AppColors
|
|
||||||
abstract val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
abstract val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
||||||
|
|
||||||
fun updateAllItems(items: ArrayList<SelfossModel.Item>) {
|
fun updateAllItems(items: ArrayList<SelfossModel.Item>) {
|
||||||
@@ -30,7 +28,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
updateItems(this.items)
|
updateItems(this.items)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unmarkSnackbar(position: Int) {
|
private fun unmarkSnackbar(item: SelfossModel.Item, position: Int) {
|
||||||
val s = Snackbar
|
val s = Snackbar
|
||||||
.make(
|
.make(
|
||||||
app.findViewById(R.id.coordLayout),
|
app.findViewById(R.id.coordLayout),
|
||||||
@@ -39,7 +37,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
)
|
)
|
||||||
.setAction(R.string.undo_string) {
|
.setAction(R.string.undo_string) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
unreadItemAtIndex(position, false)
|
unreadItemAtIndex(item, position, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +47,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
s.show()
|
s.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun markSnackbar(position: Int) {
|
private fun markSnackbar(item: SelfossModel.Item, position: Int) {
|
||||||
val s = Snackbar
|
val s = Snackbar
|
||||||
.make(
|
.make(
|
||||||
app.findViewById(R.id.coordLayout),
|
app.findViewById(R.id.coordLayout),
|
||||||
@@ -57,7 +55,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
)
|
)
|
||||||
.setAction(R.string.undo_string) {
|
.setAction(R.string.undo_string) {
|
||||||
readItemAtIndex(position)
|
readItemAtIndex(item, position, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val view = s.view
|
val view = s.view
|
||||||
@@ -68,37 +66,36 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
|
|
||||||
fun handleItemAtIndex(position: Int) {
|
fun handleItemAtIndex(position: Int) {
|
||||||
if (items[position].unread) {
|
if (items[position].unread) {
|
||||||
readItemAtIndex(position)
|
readItemAtIndex(items[position], position)
|
||||||
} else {
|
} else {
|
||||||
unreadItemAtIndex(position)
|
unreadItemAtIndex(items[position], position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
private fun readItemAtIndex(item: SelfossModel.Item, position: Int, showSnackbar: Boolean = true) {
|
||||||
val i = items[position]
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.markAsRead(i)
|
repository.markAsRead(item)
|
||||||
}
|
}
|
||||||
if (repository.displayedItems == ItemType.UNREAD) {
|
if (repository.displayedItems == ItemType.UNREAD) {
|
||||||
items.remove(i)
|
items.remove(item)
|
||||||
notifyItemRemoved(position)
|
notifyItemRemoved(position)
|
||||||
updateItems(items)
|
updateItems(items)
|
||||||
} else {
|
} else {
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
if (showSnackbar) {
|
if (showSnackbar) {
|
||||||
unmarkSnackbar(position)
|
unmarkSnackbar(item, position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
private fun unreadItemAtIndex(item: SelfossModel.Item, position: Int, showSnackbar: Boolean = true) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.unmarkAsRead(items[position])
|
repository.unmarkAsRead(item)
|
||||||
|
|
||||||
}
|
}
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
if (showSnackbar) {
|
if (showSnackbar) {
|
||||||
markSnackbar(position)
|
markSnackbar(item, position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-5
@@ -61,9 +61,13 @@ class SourcesListAdapter(
|
|||||||
binding.sourceTitle.text = itm.title.getHtmlDecoded()
|
binding.sourceTitle.text = itm.title.getHtmlDecoded()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItemId(position: Int) = position.toLong()
|
||||||
|
|
||||||
|
override fun getItemViewType(position: Int) = position
|
||||||
|
|
||||||
override fun getItemCount(): Int = items.size
|
override fun getItemCount(): Int = items.size
|
||||||
|
|
||||||
inner class ViewHolder(internal val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) {
|
inner class ViewHolder(private val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
handleClickListeners()
|
handleClickListeners()
|
||||||
@@ -74,13 +78,13 @@ class SourcesListAdapter(
|
|||||||
val deleteBtn: Button = mView.findViewById(R.id.deleteBtn)
|
val deleteBtn: Button = mView.findViewById(R.id.deleteBtn)
|
||||||
|
|
||||||
deleteBtn.setOnClickListener {
|
deleteBtn.setOnClickListener {
|
||||||
val (id) = items[adapterPosition]
|
val (id) = items[bindingAdapterPosition]
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val successfullyDeletedSource = repository.deleteSource(id)
|
val successfullyDeletedSource = repository.deleteSource(id)
|
||||||
if (successfullyDeletedSource) {
|
if (successfullyDeletedSource) {
|
||||||
items.removeAt(adapterPosition)
|
items.removeAt(bindingAdapterPosition)
|
||||||
notifyItemRemoved(adapterPosition)
|
notifyItemRemoved(bindingAdapterPosition)
|
||||||
notifyItemRangeChanged(adapterPosition, itemCount)
|
notifyItemRangeChanged(bindingAdapterPosition, itemCount)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
app,
|
app,
|
||||||
|
|||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.api.mercury
|
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.Retrofit
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
|
||||||
|
|
||||||
class MercuryApi() {
|
|
||||||
private val service: MercuryService
|
|
||||||
|
|
||||||
init {
|
|
||||||
|
|
||||||
val interceptor = HttpLoggingInterceptor()
|
|
||||||
interceptor.level = HttpLoggingInterceptor.Level.NONE
|
|
||||||
val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
|
|
||||||
|
|
||||||
val gson = GsonBuilder()
|
|
||||||
.setLenient()
|
|
||||||
.create()
|
|
||||||
val retrofit =
|
|
||||||
Retrofit
|
|
||||||
.Builder()
|
|
||||||
.baseUrl("https://www.amine-louveau.fr")
|
|
||||||
.client(client)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
|
||||||
.build()
|
|
||||||
service = retrofit.create(MercuryService::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseUrl(url: String): Call<ParsedContent> {
|
|
||||||
return service.parseUrl(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-59
@@ -1,59 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.api.mercury
|
|
||||||
|
|
||||||
import android.os.Parcel
|
|
||||||
import android.os.Parcelable
|
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
class ParsedContent(
|
|
||||||
@SerializedName("title") val title: String,
|
|
||||||
@SerializedName("content") val content: String?,
|
|
||||||
@SerializedName("date_published") val date_published: String,
|
|
||||||
@SerializedName("lead_image_url") val lead_image_url: String?,
|
|
||||||
@SerializedName("dek") val dek: String,
|
|
||||||
@SerializedName("url") val url: String,
|
|
||||||
@SerializedName("domain") val domain: String,
|
|
||||||
@SerializedName("excerpt") val excerpt: String,
|
|
||||||
@SerializedName("total_pages") val total_pages: Int,
|
|
||||||
@SerializedName("rendered_pages") val rendered_pages: Int,
|
|
||||||
@SerializedName("next_page_url") val next_page_url: String
|
|
||||||
) : Parcelable {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@JvmField
|
|
||||||
val CREATOR: Parcelable.Creator<ParsedContent> =
|
|
||||||
object : Parcelable.Creator<ParsedContent> {
|
|
||||||
override fun createFromParcel(source: Parcel): ParsedContent = ParsedContent(source)
|
|
||||||
override fun newArray(size: Int): Array<ParsedContent?> = arrayOfNulls(size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(source: Parcel) : this(
|
|
||||||
title = source.readString().orEmpty(),
|
|
||||||
content = source.readString(),
|
|
||||||
date_published = source.readString().orEmpty(),
|
|
||||||
lead_image_url = source.readString(),
|
|
||||||
dek = source.readString().orEmpty(),
|
|
||||||
url = source.readString().orEmpty(),
|
|
||||||
domain = source.readString().orEmpty(),
|
|
||||||
excerpt = source.readString().orEmpty(),
|
|
||||||
total_pages = source.readInt(),
|
|
||||||
rendered_pages = source.readInt(),
|
|
||||||
next_page_url = source.readString().orEmpty()
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun describeContents() = 0
|
|
||||||
|
|
||||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
|
||||||
dest.writeString(title)
|
|
||||||
dest.writeString(content)
|
|
||||||
dest.writeString(date_published)
|
|
||||||
dest.writeString(lead_image_url)
|
|
||||||
dest.writeString(dek)
|
|
||||||
dest.writeString(url)
|
|
||||||
dest.writeString(domain)
|
|
||||||
dest.writeString(excerpt)
|
|
||||||
dest.writeInt(total_pages)
|
|
||||||
dest.writeInt(rendered_pages)
|
|
||||||
dest.writeString(next_page_url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.api.mercury
|
|
||||||
|
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.http.GET
|
|
||||||
import retrofit2.http.Query
|
|
||||||
|
|
||||||
interface MercuryService {
|
|
||||||
@GET("parser.php")
|
|
||||||
fun parseUrl(@Query("link") link: String): Call<ParsedContent>
|
|
||||||
}
|
|
||||||
+4
-2
@@ -52,11 +52,13 @@ override fun doWork(): Result {
|
|||||||
|
|
||||||
repository.handleDBActions()
|
repository.handleDBActions()
|
||||||
|
|
||||||
|
val apiItems = repository.tryToCacheItemsAndGetNewOnes()
|
||||||
if (appSettingsService.isNotifyNewItemsEnabled()) {
|
if (appSettingsService.isNotifyNewItemsEnabled()) {
|
||||||
launch {
|
launch {
|
||||||
handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notificationManager)
|
handleNewItemsNotification(apiItems, notificationManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
apiItems.map { it.preloadImages(context) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Result.success()
|
return Result.success()
|
||||||
@@ -66,6 +68,7 @@ override fun doWork(): Result {
|
|||||||
newItems: List<SelfossModel.Item>?,
|
newItems: List<SelfossModel.Item>?,
|
||||||
notificationManager: NotificationManager
|
notificationManager: NotificationManager
|
||||||
) {
|
) {
|
||||||
|
// TODO: Check if this coroutine is actually required
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val apiItems = newItems.orEmpty()
|
val apiItems = newItems.orEmpty()
|
||||||
|
|
||||||
@@ -102,7 +105,6 @@ override fun doWork(): Result {
|
|||||||
notificationManager.notify(2, newItemsNotification.build())
|
notificationManager.notify(2, newItemsNotification.build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiItems.map { it.preloadImages(context) }
|
|
||||||
Timer("", false).schedule(4000) {
|
Timer("", false).schedule(4000) {
|
||||||
notificationManager.cancel(1)
|
notificationManager.cancel(1)
|
||||||
}
|
}
|
||||||
|
|||||||
+107
-143
@@ -8,6 +8,7 @@ import android.graphics.Typeface
|
|||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.TypedValue
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.webkit.WebResourceResponse
|
import android.webkit.WebResourceResponse
|
||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
@@ -15,27 +16,22 @@ import android.webkit.WebView
|
|||||||
import android.webkit.WebViewClient
|
import android.webkit.WebViewClient
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import bou.amine.apps.readerforselfossv2.android.ImageActivity
|
import bou.amine.apps.readerforselfossv2.android.ImageActivity
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.api.mercury.MercuryApi
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.api.mercury.ParsedContent
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.FragmentArticleBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.FragmentArticleBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.model.ParecelableItem
|
import bou.amine.apps.readerforselfossv2.android.model.ParecelableItem
|
||||||
import bou.amine.apps.readerforselfossv2.android.model.toModel
|
import bou.amine.apps.readerforselfossv2.android.model.toModel
|
||||||
import bou.amine.apps.readerforselfossv2.android.model.toParcelable
|
import bou.amine.apps.readerforselfossv2.android.model.toParcelable
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.buildCustomTabsIntent
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.getBitmapInputStream
|
import bou.amine.apps.readerforselfossv2.android.utils.glide.getBitmapInputStream
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask
|
import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.openItemUrlInternalBrowser
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.shareLink
|
import bou.amine.apps.readerforselfossv2.android.utils.shareLink
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
|
import bou.amine.apps.readerforselfossv2.rest.MercuryApi
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||||
import bou.amine.apps.readerforselfossv2.utils.getImages
|
import bou.amine.apps.readerforselfossv2.utils.getImages
|
||||||
@@ -49,22 +45,22 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.acra.ktx.sendSilentlyWithAcra
|
||||||
|
import org.acra.ktx.sendWithAcra
|
||||||
import org.kodein.di.DI
|
import org.kodein.di.DI
|
||||||
import org.kodein.di.DIAware
|
import org.kodein.di.DIAware
|
||||||
import org.kodein.di.android.x.closestDI
|
import org.kodein.di.android.x.closestDI
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.Callback
|
|
||||||
import retrofit2.Response
|
|
||||||
import java.net.MalformedURLException
|
import java.net.MalformedURLException
|
||||||
|
import java.net.SocketTimeoutException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ExecutionException
|
import java.util.concurrent.ExecutionException
|
||||||
|
|
||||||
|
|
||||||
class ArticleFragment : Fragment(), DIAware {
|
class ArticleFragment : Fragment(), DIAware {
|
||||||
private var fontSize: Int = 16
|
private var fontSize: Int = 16
|
||||||
private lateinit var item: SelfossModel.Item
|
private lateinit var item: SelfossModel.Item
|
||||||
private var mCustomTabActivityHelper: CustomTabActivityHelper? = null
|
|
||||||
private lateinit var url: String
|
private lateinit var url: String
|
||||||
private lateinit var contentText: String
|
private lateinit var contentText: String
|
||||||
private lateinit var contentSource: String
|
private lateinit var contentSource: String
|
||||||
@@ -72,10 +68,9 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
private lateinit var contentTitle: String
|
private lateinit var contentTitle: String
|
||||||
private lateinit var allImages : ArrayList<String>
|
private lateinit var allImages : ArrayList<String>
|
||||||
private lateinit var fab: FloatingActionButton
|
private lateinit var fab: FloatingActionButton
|
||||||
private lateinit var appColors: AppColors
|
|
||||||
private lateinit var textAlignment: String
|
private lateinit var textAlignment: String
|
||||||
private var _binding: FragmentArticleBinding? = null
|
private var _binding: FragmentArticleBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding
|
||||||
|
|
||||||
override val di : DI by closestDI()
|
override val di : DI by closestDI()
|
||||||
private val repository: Repository by instance()
|
private val repository: Repository by instance()
|
||||||
@@ -86,16 +81,10 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
private var font = ""
|
private var font = ""
|
||||||
private var staticBar = false
|
private var staticBar = false
|
||||||
|
|
||||||
override fun onStop() {
|
private val mercuryApi : MercuryApi by instance()
|
||||||
super.onStop()
|
|
||||||
if (mCustomTabActivityHelper != null) {
|
|
||||||
mCustomTabActivityHelper!!.unbindCustomTabsService(activity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
appColors = AppColors(requireActivity())
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val pi: ParecelableItem = requireArguments().getParcelable(ARG_ITEMS)!!
|
val pi: ParecelableItem = requireArguments().getParcelable(ARG_ITEMS)!!
|
||||||
@@ -115,46 +104,30 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
contentText = item.content
|
contentText = item.content
|
||||||
contentTitle = item.title.getHtmlDecoded()
|
contentTitle = item.title.getHtmlDecoded()
|
||||||
contentImage = item.getThumbnail(repository.baseUrl)
|
contentImage = item.getThumbnail(repository.baseUrl)
|
||||||
contentSource = item.sourceAndDateText(repository.dateUtils)
|
contentSource = item.sourceAndDateText()
|
||||||
allImages = item.getImages()
|
allImages = item.getImages()
|
||||||
|
|
||||||
fontSize = appSettingsService.getFontSize()
|
fontSize = appSettingsService.getFontSize()
|
||||||
staticBar = appSettingsService.isStaticBarEnabled()
|
staticBar = appSettingsService.isStaticBarEnabled()
|
||||||
font = appSettingsService.getFont()
|
font = appSettingsService.getFont()
|
||||||
|
|
||||||
if (font.isNotEmpty()) {
|
|
||||||
resId = requireContext().resources.getIdentifier(font, "font", requireContext().packageName)
|
|
||||||
typeface = try {
|
|
||||||
ResourcesCompat.getFont(requireContext(), resId)!!
|
|
||||||
} catch (e: java.lang.Exception) {
|
|
||||||
// Just to be sure
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshAlignment()
|
refreshAlignment()
|
||||||
|
|
||||||
fab = binding.fab
|
fab = binding!!.fab
|
||||||
|
|
||||||
fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent)
|
fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent))
|
||||||
|
|
||||||
fab.rippleColor = appColors.colorAccentDark
|
fab.rippleColor = resources.getColor(R.color.colorAccentDark)
|
||||||
|
|
||||||
val floatingToolbar: FloatingToolbar = binding.floatingToolbar
|
val floatingToolbar: FloatingToolbar = binding!!.floatingToolbar
|
||||||
floatingToolbar.attachFab(fab)
|
floatingToolbar.attachFab(fab)
|
||||||
|
|
||||||
floatingToolbar.background = ColorDrawable(appColors.colorAccent)
|
floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent))
|
||||||
|
|
||||||
val customTabsIntent = requireActivity().buildCustomTabsIntent()
|
|
||||||
mCustomTabActivityHelper = CustomTabActivityHelper()
|
|
||||||
mCustomTabActivityHelper!!.bindCustomTabsService(activity)
|
|
||||||
|
|
||||||
|
|
||||||
floatingToolbar.setClickListener(
|
floatingToolbar.setClickListener(
|
||||||
object : FloatingToolbar.ItemClickListener {
|
object : FloatingToolbar.ItemClickListener {
|
||||||
override fun onItemClick(item: MenuItem) {
|
override fun onItemClick(item: MenuItem) {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.more_action -> getContentFromMercury(customTabsIntent)
|
|
||||||
R.id.share_action -> requireActivity().shareLink(url, contentTitle)
|
R.id.share_action -> requireActivity().shareLink(url, contentTitle)
|
||||||
R.id.open_action -> requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item)
|
R.id.open_action -> requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item)
|
||||||
R.id.unread_action -> if (context != null) {
|
R.id.unread_action -> if (context != null) {
|
||||||
@@ -194,35 +167,35 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
floatingToolbar.show()
|
floatingToolbar.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.source.text = contentSource
|
binding!!.source.text = contentSource
|
||||||
if (typeface != null) {
|
if (typeface != null) {
|
||||||
binding.source.typeface = typeface
|
binding!!.source.typeface = typeface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contentText.isEmptyOrNullOrNullString()) {
|
if (contentText.isEmptyOrNullOrNullString()) {
|
||||||
getContentFromMercury(customTabsIntent)
|
getContentFromMercury()
|
||||||
} else {
|
} else {
|
||||||
binding.titleView.text = contentTitle
|
binding!!.titleView.text = contentTitle
|
||||||
if (typeface != null) {
|
if (typeface != null) {
|
||||||
binding.titleView.typeface = typeface
|
binding!!.titleView.typeface = typeface
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlToWebview()
|
htmlToWebview()
|
||||||
|
|
||||||
if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
|
if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
|
||||||
binding.imageView.visibility = View.VISIBLE
|
binding!!.imageView.visibility = View.VISIBLE
|
||||||
Glide
|
Glide
|
||||||
.with(requireContext())
|
.with(requireContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(contentImage)
|
.load(contentImage)
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
.into(binding.imageView)
|
.into(binding!!.imageView)
|
||||||
} else {
|
} else {
|
||||||
binding.imageView.visibility = View.GONE
|
binding!!.imageView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.nestedScrollView.setOnScrollChangeListener(
|
binding!!.nestedScrollView.setOnScrollChangeListener(
|
||||||
NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||||
if (scrollY > oldScrollY) {
|
if (scrollY > oldScrollY) {
|
||||||
floatingToolbar.hide()
|
floatingToolbar.hide()
|
||||||
@@ -238,6 +211,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
)
|
)
|
||||||
|
|
||||||
} catch (e: InflateException) {
|
} catch (e: InflateException) {
|
||||||
|
e.sendSilentlyWithAcraWithName("webview not available")
|
||||||
AlertDialog.Builder(requireContext())
|
AlertDialog.Builder(requireContext())
|
||||||
.setMessage(requireContext().getString(R.string.webview_dialog_issue_message))
|
.setMessage(requireContext().getString(R.string.webview_dialog_issue_message))
|
||||||
.setTitle(requireContext().getString(R.string.webview_dialog_issue_title))
|
.setTitle(requireContext().getString(R.string.webview_dialog_issue_title))
|
||||||
@@ -250,7 +224,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding.root
|
return binding!!.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -266,142 +240,134 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent) {
|
private fun getContentFromMercury() {
|
||||||
if (repository.isNetworkAvailable()) {
|
if (repository.isNetworkAvailable()) {
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
binding!!.progressBar.visibility = View.VISIBLE
|
||||||
val parser = MercuryApi()
|
|
||||||
|
|
||||||
parser.parseUrl(url).enqueue(
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
object : Callback<ParsedContent> {
|
|
||||||
override fun onResponse(
|
|
||||||
call: Call<ParsedContent>,
|
|
||||||
response: Response<ParsedContent>
|
|
||||||
) {
|
|
||||||
// TODO: clean all the following after finding the mercury content issue
|
|
||||||
try {
|
try {
|
||||||
if (response.body() != null && response.body()!!.content != null && !response.body()!!.content.isNullOrEmpty()) {
|
val response = mercuryApi.query(url)
|
||||||
|
if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) {
|
||||||
|
binding!!.titleView.text = response.data!!.title.orEmpty()
|
||||||
try {
|
try {
|
||||||
binding.titleView.text = response.body()!!.title
|
|
||||||
if (typeface != null) {
|
if (typeface != null) {
|
||||||
binding.titleView.typeface = typeface
|
binding!!.titleView.typeface = typeface
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > typeface")
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Note: Mercury may return relative urls... If it does the url val will not be changed.
|
// Note: Mercury may return relative urls... If it does the url val will not be changed.
|
||||||
URL(response.body()!!.url)
|
URL(response.data!!.url)
|
||||||
url = response.body()!!.url
|
url = response.data!!.url
|
||||||
} catch (e: MalformedURLException) {
|
} catch (e: MalformedURLException) {
|
||||||
// Mercury returned a relative url. We do nothing.
|
// Mercury returned a relative url
|
||||||
}
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > malformedurlexception")
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contentText = response.body()!!.content.orEmpty()
|
contentText = response.data!!.content.orEmpty()
|
||||||
htmlToWebview()
|
htmlToWebview()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > contenttext or html")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) {
|
||||||
try {
|
try {
|
||||||
if (response.body()!!.lead_image_url != null && !response.body()!!.lead_image_url.isNullOrEmpty() && context != null) {
|
binding!!.imageView.visibility = View.VISIBLE
|
||||||
binding.imageView.visibility = View.VISIBLE
|
|
||||||
try {
|
try {
|
||||||
Glide
|
Glide
|
||||||
.with(requireContext())
|
.with(requireContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(
|
.load(
|
||||||
response.body()!!.lead_image_url.orEmpty()
|
response.data!!.lead_image_url.orEmpty()
|
||||||
)
|
)
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
.into(binding.imageView)
|
.into(binding!!.imageView)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.imageView.visibility = View.GONE
|
binding!!.imageView.visibility = View.GONE
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
binding.nestedScrollView.scrollTo(0, 0)
|
binding!!.nestedScrollView.scrollTo(0, 0)
|
||||||
|
binding!!.progressBar.visibility = View.GONE
|
||||||
binding.progressBar.visibility = View.GONE
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (context != null) {
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
openInBrowserAfterFailing()
|
||||||
openInBrowserAfterFailing(customTabsIntent)
|
}
|
||||||
|
} catch (e: SocketTimeoutException) {
|
||||||
|
openInBrowserAfterFailing()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (context != null) {
|
e.sendSilentlyWithAcraWithName("getContentFromMercury > whole thing")
|
||||||
|
openInBrowserAfterFailing()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
if (context != null) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(
|
|
||||||
call: Call<ParsedContent>,
|
|
||||||
t: Throwable
|
|
||||||
) = openInBrowserAfterFailing(customTabsIntent)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun htmlToWebview() {
|
private fun htmlToWebview() {
|
||||||
val stringColor = String.format("#%06X", 0xFFFFFF and appColors.colorAccent)
|
|
||||||
|
|
||||||
val attrs: IntArray = intArrayOf(android.R.attr.fontFamily)
|
val attrs: IntArray = intArrayOf(android.R.attr.fontFamily)
|
||||||
val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs)
|
val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs)
|
||||||
|
|
||||||
|
|
||||||
binding.webcontent.settings.standardFontFamily = a.getString(0)
|
binding!!.webcontent.settings.standardFontFamily = a.getString(0)
|
||||||
binding.webcontent.visibility = View.VISIBLE
|
binding!!.webcontent.visibility = View.VISIBLE
|
||||||
|
|
||||||
// TODO: Set the color strings programmatically
|
val colorOnSurface = TypedValue()
|
||||||
val (stringTextColor, stringBackgroundColor) = if (appColors.isDarkTheme) {
|
requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true)
|
||||||
Pair("#FFFFFF", "#303030")
|
|
||||||
} else {
|
|
||||||
Pair("#212121", "#FAFAFA")
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.webcontent.settings.useWideViewPort = true
|
val colorSurface = TypedValue()
|
||||||
binding.webcontent.settings.loadWithOverviewMode = true
|
requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true)
|
||||||
binding.webcontent.settings.javaScriptEnabled = false
|
|
||||||
|
|
||||||
binding.webcontent.webViewClient = object : WebViewClient() {
|
binding!!.webcontent.settings.useWideViewPort = true
|
||||||
|
binding!!.webcontent.settings.loadWithOverviewMode = true
|
||||||
|
binding!!.webcontent.settings.javaScriptEnabled = false
|
||||||
|
|
||||||
|
binding!!.webcontent.webViewClient = object : WebViewClient() {
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun shouldOverrideUrlLoading(view: WebView?, url : String): Boolean {
|
override fun shouldOverrideUrlLoading(view: WebView?, url : String): Boolean {
|
||||||
if (binding.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
if (binding!!.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||||
requireContext().startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
requireContext().startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun shouldInterceptRequest(view: WebView?, url: String): WebResourceResponse? {
|
override fun shouldInterceptRequest(view: WebView?, url: String): WebResourceResponse? {
|
||||||
val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL)
|
val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL)
|
||||||
if (url.lowercase(Locale.US).contains(".jpg") || url.lowercase(Locale.US).contains(".jpeg")) {
|
if (url.lowercase(Locale.US).contains(".jpg") || url.lowercase(Locale.US).contains(".jpeg")) {
|
||||||
try {
|
try {
|
||||||
val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get()
|
val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get()
|
||||||
return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.JPEG))
|
return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.JPEG))
|
||||||
}catch ( e : ExecutionException) {}
|
} catch ( e : ExecutionException) {
|
||||||
|
e.sendSilentlyWithAcraWithName("shouldInterceptRequest > jpeg")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (url.lowercase(Locale.US).contains(".png")) {
|
else if (url.lowercase(Locale.US).contains(".png")) {
|
||||||
try {
|
try {
|
||||||
val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get()
|
val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get()
|
||||||
return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.PNG))
|
return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.PNG))
|
||||||
}catch ( e : ExecutionException) {}
|
} catch ( e : ExecutionException) {
|
||||||
|
e.sendSilentlyWithAcraWithName("shouldInterceptRequest > png")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (url.lowercase(Locale.US).contains(".webp")) {
|
else if (url.lowercase(Locale.US).contains(".webp")) {
|
||||||
try {
|
try {
|
||||||
val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get()
|
val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get()
|
||||||
return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.WEBP))
|
return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.WEBP))
|
||||||
}catch ( e : ExecutionException) {}
|
} catch ( e : ExecutionException) {
|
||||||
|
e.sendSilentlyWithAcraWithName("shouldInterceptRequest > webp")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.shouldInterceptRequest(view, url)
|
return super.shouldInterceptRequest(view, url)
|
||||||
@@ -409,14 +375,14 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val gestureDetector = GestureDetector(activity, object : GestureDetector.SimpleOnGestureListener() {
|
val gestureDetector = GestureDetector(activity, object : GestureDetector.SimpleOnGestureListener() {
|
||||||
override fun onSingleTapUp(e: MotionEvent?): Boolean {
|
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||||
return performClick()
|
return performClick()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
binding.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event)}
|
binding!!.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event)}
|
||||||
|
|
||||||
binding.webcontent.settings.layoutAlgorithm =
|
binding!!.webcontent.settings.layoutAlgorithm =
|
||||||
WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
||||||
|
|
||||||
var baseUrl: String? = null
|
var baseUrl: String? = null
|
||||||
@@ -425,11 +391,13 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
val itemUrl = URL(url)
|
val itemUrl = URL(url)
|
||||||
baseUrl = itemUrl.protocol + "://" + itemUrl.host
|
baseUrl = itemUrl.protocol + "://" + itemUrl.host
|
||||||
} catch (e: MalformedURLException) {
|
} catch (e: MalformedURLException) {
|
||||||
|
e.sendSilentlyWithAcraWithName("htmlToWebview > item url")
|
||||||
}
|
}
|
||||||
|
|
||||||
val fontName = when (font) {
|
val fontName = when (font) {
|
||||||
getString(R.string.open_sans_font_id) -> "Open Sans"
|
getString(R.string.open_sans_font_id) -> "Open Sans"
|
||||||
getString(R.string.roboto_font_id) -> "Roboto"
|
getString(R.string.roboto_font_id) -> "Roboto"
|
||||||
|
getString(R.string.source_code_pro_font_id) -> "Source Code Pro"
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +413,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.webcontent.loadDataWithBaseURL(
|
binding!!.webcontent.loadDataWithBaseURL(
|
||||||
baseUrl,
|
baseUrl,
|
||||||
"""<html>
|
"""<html>
|
||||||
|<head>
|
|<head>
|
||||||
@@ -458,10 +426,10 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
| max-width: 100%;
|
| max-width: 100%;
|
||||||
| }
|
| }
|
||||||
| a {
|
| a {
|
||||||
| color: $stringColor !important;
|
| color: ${String.format("#%06X", 0xFFFFFF and resources.getColor(R.color.colorAccent))} !important;
|
||||||
| }
|
| }
|
||||||
| *:not(a) {
|
| *:not(a) {
|
||||||
| color: $stringTextColor;
|
| color: ${String.format("#%06X", 0xFFFFFF and colorOnSurface.data)};
|
||||||
| }
|
| }
|
||||||
| * {
|
| * {
|
||||||
| font-size: ${fontSize}px;
|
| font-size: ${fontSize}px;
|
||||||
@@ -469,11 +437,11 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
| word-break: break-word;
|
| word-break: break-word;
|
||||||
| overflow:hidden;
|
| overflow:hidden;
|
||||||
| line-height: 1.5em;
|
| line-height: 1.5em;
|
||||||
| background-color: $stringBackgroundColor;
|
| background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)};
|
||||||
| }
|
| }
|
||||||
| body, html {
|
| body, html {
|
||||||
| background-color: $stringBackgroundColor !important;
|
| background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important;
|
||||||
| border-color: $stringBackgroundColor !important;
|
| border-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)} !important;
|
||||||
| padding: 0 !important;
|
| padding: 0 !important;
|
||||||
| margin: 0 !important;
|
| margin: 0 !important;
|
||||||
| }
|
| }
|
||||||
@@ -483,7 +451,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
| pre, code {
|
| pre, code {
|
||||||
| white-space: pre-wrap;
|
| white-space: pre-wrap;
|
||||||
| width:100%;
|
| width:100%;
|
||||||
| background-color: $stringBackgroundColor;
|
| background-color: ${String.format("#%06X", 0xFFFFFF and colorSurface.data)};
|
||||||
| }
|
| }
|
||||||
| </style>
|
| </style>
|
||||||
| $fontLinkAndStyle
|
| $fontLinkAndStyle
|
||||||
@@ -498,22 +466,18 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun scrollDown() {
|
fun scrollDown() {
|
||||||
val height = binding.nestedScrollView.measuredHeight
|
val height = binding!!.nestedScrollView.measuredHeight
|
||||||
binding.nestedScrollView.smoothScrollBy(0, height/2)
|
binding!!.nestedScrollView.smoothScrollBy(0, height/2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scrollUp() {
|
fun scrollUp() {
|
||||||
val height = binding.nestedScrollView.measuredHeight
|
val height = binding!!.nestedScrollView.measuredHeight
|
||||||
binding.nestedScrollView.smoothScrollBy(0, -height/2)
|
binding!!.nestedScrollView.smoothScrollBy(0, -height/2)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openInBrowserAfterFailing(customTabsIntent: CustomTabsIntent) {
|
private fun openInBrowserAfterFailing() {
|
||||||
binding.progressBar.visibility = View.GONE
|
binding!!.progressBar.visibility = View.GONE
|
||||||
requireActivity().openItemUrlInternalBrowser(
|
requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item)
|
||||||
url,
|
|
||||||
customTabsIntent,
|
|
||||||
requireActivity()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -531,10 +495,10 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun performClick(): Boolean {
|
fun performClick(): Boolean {
|
||||||
if (binding.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE ||
|
if (binding!!.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE ||
|
||||||
binding.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
binding!!.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||||
|
|
||||||
val position : Int = allImages.indexOf(binding.webcontent.hitTestResult.extra)
|
val position : Int = allImages.indexOf(binding!!.webcontent.hitTestResult.extra)
|
||||||
|
|
||||||
val intent = Intent(activity, ImageActivity::class.java)
|
val intent = Intent(activity, ImageActivity::class.java)
|
||||||
intent.putExtra("allImages", allImages)
|
intent.putExtra("allImages", allImages)
|
||||||
|
|||||||
+182
@@ -0,0 +1,182 @@
|
|||||||
|
package bou.amine.apps.readerforselfossv2.android.fragments
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.View.GONE
|
||||||
|
import android.view.View.VISIBLE
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.HomeActivity
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
||||||
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
|
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||||
|
import bou.amine.apps.readerforselfossv2.utils.getIcon
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.load.DataSource
|
||||||
|
import com.bumptech.glide.load.engine.GlideException
|
||||||
|
import com.bumptech.glide.request.RequestListener
|
||||||
|
import com.bumptech.glide.request.target.Target
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
|
import com.google.android.material.chip.Chip
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.kodein.di.DI
|
||||||
|
import org.kodein.di.DIAware
|
||||||
|
import org.kodein.di.android.x.closestDI
|
||||||
|
import org.kodein.di.instance
|
||||||
|
|
||||||
|
|
||||||
|
class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
||||||
|
|
||||||
|
override val di: DI by closestDI()
|
||||||
|
private val repository: Repository by instance()
|
||||||
|
private val appSettingsService: AppSettingsService by instance()
|
||||||
|
|
||||||
|
private var selectedChip: Chip? = null
|
||||||
|
|
||||||
|
@SuppressLint("ResourceAsColor")
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
val binding =
|
||||||
|
bou.amine.apps.readerforselfossv2.android.databinding.FilterFragmentBinding.inflate(
|
||||||
|
inflater,
|
||||||
|
container,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
val tagGroup = binding.tagsGroup
|
||||||
|
val sourceGroup = binding.sourcesGroup
|
||||||
|
|
||||||
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
val tags = repository.getTags()
|
||||||
|
|
||||||
|
tags.forEach { tag ->
|
||||||
|
val c = chipForTag(tag)
|
||||||
|
tagGroup.addView(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
repository.getSources().forEach { source ->
|
||||||
|
val c = Chip(requireContext())
|
||||||
|
|
||||||
|
Glide.with(requireContext())
|
||||||
|
.load(source.getIcon(repository.baseUrl))
|
||||||
|
.listener(object : RequestListener<Drawable?> {
|
||||||
|
override fun onLoadFailed(
|
||||||
|
e: GlideException?,
|
||||||
|
model: Any?,
|
||||||
|
target: Target<Drawable?>?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResourceReady(
|
||||||
|
resource: Drawable?,
|
||||||
|
model: Any?,
|
||||||
|
target: Target<Drawable?>?,
|
||||||
|
dataSource: DataSource?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
c.chipIcon = resource
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}).preload()
|
||||||
|
|
||||||
|
c.text = source.title.getHtmlDecoded()
|
||||||
|
|
||||||
|
c.setOnCloseIconClickListener {
|
||||||
|
(it as Chip).isCloseIconVisible = false
|
||||||
|
selectedChip = null
|
||||||
|
repository.setSourceFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.setOnClickListener {
|
||||||
|
if (selectedChip != null) {
|
||||||
|
selectedChip!!.isCloseIconVisible = false
|
||||||
|
}
|
||||||
|
(it as Chip).isCloseIconVisible = true
|
||||||
|
selectedChip = it
|
||||||
|
repository.setSourceFilter(source)
|
||||||
|
|
||||||
|
repository.setTagFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (repository.sourceFilter.value?.equals(source) == true) {
|
||||||
|
c.isCloseIconVisible = true
|
||||||
|
selectedChip = c
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceGroup.addView(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.progressBar2.visibility = GONE
|
||||||
|
binding.filterView.visibility = VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.floatingActionButton2.setOnClickListener {
|
||||||
|
(activity as HomeActivity).getElementsAccordingToTab()
|
||||||
|
(activity as HomeActivity).fetchOnEmptyList()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun chipForTag(tag: SelfossModel.Tag): Chip {
|
||||||
|
val c = Chip(requireContext())
|
||||||
|
c.text = tag.tag
|
||||||
|
|
||||||
|
val gd = GradientDrawable()
|
||||||
|
val gdColor = try {
|
||||||
|
Color.parseColor(tag.color)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
e.sendSilentlyWithAcraWithName("color issue " + tag.color)
|
||||||
|
resources.getColor(R.color.colorPrimary)
|
||||||
|
}
|
||||||
|
gd.setColor(gdColor)
|
||||||
|
gd.shape = GradientDrawable.RECTANGLE
|
||||||
|
gd.setSize(30, 30)
|
||||||
|
gd.cornerRadius = 30F
|
||||||
|
c.chipIcon = gd
|
||||||
|
|
||||||
|
c.setOnCloseIconClickListener {
|
||||||
|
(it as Chip).isCloseIconVisible = false
|
||||||
|
selectedChip = null
|
||||||
|
repository.setTagFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.setOnClickListener {
|
||||||
|
if (selectedChip != null) {
|
||||||
|
selectedChip!!.isCloseIconVisible = false
|
||||||
|
}
|
||||||
|
(it as Chip).isCloseIconVisible = true
|
||||||
|
selectedChip = it
|
||||||
|
repository.setTagFilter(tag)
|
||||||
|
|
||||||
|
repository.setSourceFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repository.tagFilter.value?.equals(tag) == true) {
|
||||||
|
c.isCloseIconVisible = true
|
||||||
|
selectedChip = c
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "ModalBottomSheet"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+4
-1
@@ -2,11 +2,13 @@ package bou.amine.apps.readerforselfossv2.android.model
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.webkit.URLUtil
|
import android.webkit.URLUtil
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.utils.getImages
|
import bou.amine.apps.readerforselfossv2.utils.getImages
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
|
import org.acra.ktx.sendSilentlyWithAcra
|
||||||
|
|
||||||
fun SelfossModel.Item.preloadImages(context: Context) : Boolean {
|
fun SelfossModel.Item.preloadImages(context: Context) : Boolean {
|
||||||
val imageUrls = this.getImages()
|
val imageUrls = this.getImages()
|
||||||
@@ -23,6 +25,7 @@ fun SelfossModel.Item.preloadImages(context: Context) : Boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e : Error) {
|
} catch (e : Error) {
|
||||||
|
e.sendSilentlyWithAcraWithName("preloadImages")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +38,7 @@ fun String.toTextDrawableString(): String {
|
|||||||
try {
|
try {
|
||||||
textDrawable.append(s[0])
|
textDrawable.append(s[0])
|
||||||
} catch (e: StringIndexOutOfBoundsException) {
|
} catch (e: StringIndexOutOfBoundsException) {
|
||||||
// We do nothing
|
e.sendSilentlyWithAcraWithName("toTextDrawableString")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return textDrawable.toString()
|
return textDrawable.toString()
|
||||||
|
|||||||
+11
-12
@@ -3,7 +3,6 @@ package bou.amine.apps.readerforselfossv2.android.model
|
|||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import com.google.gson.annotations.SerializedName
|
|
||||||
|
|
||||||
fun SelfossModel.Item.toParcelable() : ParecelableItem =
|
fun SelfossModel.Item.toParcelable() : ParecelableItem =
|
||||||
ParecelableItem(
|
ParecelableItem(
|
||||||
@@ -34,17 +33,17 @@ fun ParecelableItem.toModel() : SelfossModel.Item =
|
|||||||
this.tags.split(",")
|
this.tags.split(",")
|
||||||
)
|
)
|
||||||
data class ParecelableItem(
|
data class ParecelableItem(
|
||||||
@SerializedName("id") val id: Int,
|
val id: Int,
|
||||||
@SerializedName("datetime") val datetime: String,
|
val datetime: String,
|
||||||
@SerializedName("title") val title: String,
|
val title: String,
|
||||||
@SerializedName("content") val content: String,
|
val content: String,
|
||||||
@SerializedName("unread") var unread: Boolean,
|
var unread: Boolean,
|
||||||
@SerializedName("starred") var starred: Boolean,
|
var starred: Boolean,
|
||||||
@SerializedName("thumbnail") val thumbnail: String?,
|
val thumbnail: String?,
|
||||||
@SerializedName("icon") val icon: String?,
|
val icon: String?,
|
||||||
@SerializedName("link") val link: String,
|
val link: String,
|
||||||
@SerializedName("sourcetitle") val sourcetitle: String,
|
val sourcetitle: String,
|
||||||
@SerializedName("tags") val tags: String
|
val tags: String
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+36
-27
@@ -7,38 +7,39 @@ import android.text.Editable
|
|||||||
import android.text.InputFilter
|
import android.text.InputFilter
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuInflater
|
|
||||||
import android.view.MenuItem
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.core.widget.addTextChangedListener
|
import androidx.core.widget.addTextChangedListener
|
||||||
import androidx.preference.EditTextPreference
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySettingsBinding
|
import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySettingsBinding
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.AppColors
|
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
||||||
import bou.amine.apps.readerforselfossv2.android.themes.Toppings
|
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
import com.ftinc.scoop.Scoop
|
import com.mikepenz.aboutlibraries.LibsBuilder
|
||||||
|
import org.acra.ktx.sendSilentlyWithAcra
|
||||||
|
import org.acra.ktx.sendWithAcra
|
||||||
|
import org.kodein.di.DIAware
|
||||||
|
import org.kodein.di.android.closestDI
|
||||||
|
import org.kodein.di.instance
|
||||||
|
import org.matomo.sdk.Tracker
|
||||||
|
import org.matomo.sdk.extra.TrackHelper
|
||||||
|
|
||||||
private const val TITLE_TAG = "settingsActivityTitle"
|
private const val TITLE_TAG = "settingsActivityTitle"
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity(),
|
class SettingsActivity : AppCompatActivity(),
|
||||||
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
|
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback, DIAware {
|
||||||
|
override val di by closestDI()
|
||||||
|
|
||||||
|
private val tracker : Tracker by instance()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false)) {
|
|
||||||
setTheme(R.style.NoBarDark)
|
|
||||||
}
|
|
||||||
val binding = ActivitySettingsBinding.inflate(layoutInflater)
|
val binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
val scoop = Scoop.getInstance()
|
TrackHelper.track().screen("/settings").with(tracker)
|
||||||
scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar)
|
|
||||||
scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value)
|
|
||||||
|
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@@ -104,6 +105,21 @@ class SettingsActivity : AppCompatActivity(),
|
|||||||
class MainPreferenceFragment : PreferenceFragmentCompat() {
|
class MainPreferenceFragment : PreferenceFragmentCompat() {
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.pref_main, rootKey)
|
setPreferencesFromResource(R.xml.pref_main, rootKey)
|
||||||
|
|
||||||
|
preferenceManager.findPreference<Preference>("currentMode")?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||||
|
AppCompatDelegate.setDefaultNightMode(newValue.toString().toInt()) // ListPreference Only takes string-arrays ¯\_(ツ)_/¯
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
preferenceManager.findPreference<Preference>("action_about")?.onPreferenceClickListener = Preference.OnPreferenceClickListener { _ ->
|
||||||
|
context?.let {
|
||||||
|
LibsBuilder()
|
||||||
|
.withAboutIconShown(true)
|
||||||
|
.withAboutVersionShown(true)
|
||||||
|
.start(it)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +136,7 @@ class SettingsActivity : AppCompatActivity(),
|
|||||||
val input: Int = (dest.toString() + source.toString()).toInt()
|
val input: Int = (dest.toString() + source.toString()).toInt()
|
||||||
if (input in 1..200) return@InputFilter null
|
if (input in 1..200) return@InputFilter null
|
||||||
} catch (nfe: NumberFormatException) {
|
} catch (nfe: NumberFormatException) {
|
||||||
|
nfe.sendSilentlyWithAcraWithName("GeneralPreferenceFragment")
|
||||||
Toast.makeText(activity, R.string.items_number_should_be_number, Toast.LENGTH_LONG).show()
|
Toast.makeText(activity, R.string.items_number_should_be_number, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
""
|
""
|
||||||
@@ -143,6 +160,7 @@ class SettingsActivity : AppCompatActivity(),
|
|||||||
try {
|
try {
|
||||||
editText.textSize = editable.toString().toInt().toFloat()
|
editText.textSize = editable.toString().toInt().toFloat()
|
||||||
} catch (e: NumberFormatException) {
|
} catch (e: NumberFormatException) {
|
||||||
|
e.sendSilentlyWithAcraWithName("ArticleViewerPreferenceFragment > afterTextChanged")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} }
|
} }
|
||||||
@@ -152,6 +170,7 @@ class SettingsActivity : AppCompatActivity(),
|
|||||||
val input = (dest.toString() + source.toString()).toInt()
|
val input = (dest.toString() + source.toString()).toInt()
|
||||||
if (input > 0) return@InputFilter null
|
if (input > 0) return@InputFilter null
|
||||||
} catch (nfe: NumberFormatException) {
|
} catch (nfe: NumberFormatException) {
|
||||||
|
nfe.sendSilentlyWithAcraWithName("ArticleViewerPreferenceFragment > filters")
|
||||||
}
|
}
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
@@ -169,21 +188,11 @@ class SettingsActivity : AppCompatActivity(),
|
|||||||
class ThemePreferenceFragment : PreferenceFragmentCompat() {
|
class ThemePreferenceFragment : PreferenceFragmentCompat() {
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.pref_theme, rootKey)
|
setPreferencesFromResource(R.xml.pref_theme, rootKey)
|
||||||
setHasOptionsMenu(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
preferenceManager.findPreference<Preference>("currentMode")?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||||
super.onCreateOptionsMenu(menu, inflater)
|
AppCompatDelegate.setDefaultNightMode(newValue.toString().toInt()) // ListPreference Only takes string-arrays ¯\_(ツ)_/¯
|
||||||
inflater.inflate(R.menu.settings_theme, menu)
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
val id = item.itemId
|
|
||||||
if (id == R.id.clear) {
|
|
||||||
AppColors.resetColors()
|
|
||||||
requireActivity().recreate()
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.themes
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import androidx.annotation.ColorInt
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
|
||||||
import com.russhwolf.settings.Settings
|
|
||||||
|
|
||||||
class AppColors(a: Activity) {
|
|
||||||
|
|
||||||
@ColorInt val colorPrimary: Int
|
|
||||||
@ColorInt val colorPrimaryDark: Int
|
|
||||||
@ColorInt val colorAccent: Int
|
|
||||||
@ColorInt val colorAccentDark: Int
|
|
||||||
@ColorInt val colorBackground: Int
|
|
||||||
@ColorInt val textColor: Int
|
|
||||||
val isDarkTheme: Boolean
|
|
||||||
|
|
||||||
init {
|
|
||||||
val settings = Settings()
|
|
||||||
|
|
||||||
colorPrimary =
|
|
||||||
settings.getInt(
|
|
||||||
"color_primary",
|
|
||||||
a.resources.getColor(R.color.colorPrimary)
|
|
||||||
)
|
|
||||||
colorPrimaryDark =
|
|
||||||
settings.getInt(
|
|
||||||
"color_primary_dark",
|
|
||||||
a.resources.getColor(R.color.colorPrimaryDark)
|
|
||||||
)
|
|
||||||
colorAccent =
|
|
||||||
settings.getInt(
|
|
||||||
"color_accent",
|
|
||||||
a.resources.getColor(R.color.colorAccent)
|
|
||||||
)
|
|
||||||
colorAccentDark =
|
|
||||||
settings.getInt(
|
|
||||||
"color_accent_dark",
|
|
||||||
a.resources.getColor(R.color.colorAccentDark)
|
|
||||||
)
|
|
||||||
isDarkTheme =
|
|
||||||
settings.getBoolean(
|
|
||||||
"dark_theme",
|
|
||||||
false
|
|
||||||
)
|
|
||||||
|
|
||||||
colorBackground = if (isDarkTheme) {
|
|
||||||
a.setTheme(R.style.NoBarDark)
|
|
||||||
a.resources.getColor(R.color.darkBackground)
|
|
||||||
} else {
|
|
||||||
a.setTheme(R.style.NoBar)
|
|
||||||
a.resources.getColor(R.color.grey_50)
|
|
||||||
}
|
|
||||||
|
|
||||||
textColor = if (isDarkTheme) {
|
|
||||||
a.resources.getColor(R.color.white)
|
|
||||||
} else {
|
|
||||||
a.resources.getColor(R.color.grey_900)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun resetColors() {
|
|
||||||
val settings = Settings()
|
|
||||||
settings.remove("color_primary")
|
|
||||||
settings.remove("color_primary_dark")
|
|
||||||
settings.remove("color_accent")
|
|
||||||
settings.remove("color_accent_dark")
|
|
||||||
settings.remove("dark_theme")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.themes
|
|
||||||
|
|
||||||
enum class Toppings(val value: Int) {
|
|
||||||
PRIMARY(1),
|
|
||||||
PRIMARY_DARK(2),
|
|
||||||
ACCENT(3),
|
|
||||||
ACCENT_DARK(4)
|
|
||||||
}
|
|
||||||
+13
-126
@@ -1,13 +1,9 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.utils
|
package bou.amine.apps.readerforselfossv2.android.utils
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.ActivityNotFoundException
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.text.Spannable
|
import android.text.Spannable
|
||||||
import android.text.style.ClickableSpan
|
import android.text.style.ClickableSpan
|
||||||
import android.util.Patterns
|
import android.util.Patterns
|
||||||
@@ -15,109 +11,16 @@ import android.view.MotionEvent
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.ReaderActivity
|
import bou.amine.apps.readerforselfossv2.android.ReaderActivity
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper
|
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.utils.toStringUriWithHttp
|
import bou.amine.apps.readerforselfossv2.utils.toStringUriWithHttp
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
|
|
||||||
fun Context.buildCustomTabsIntent(): CustomTabsIntent {
|
|
||||||
|
|
||||||
val actionIntent = Intent(Intent.ACTION_SEND)
|
|
||||||
actionIntent.type = "text/plain"
|
|
||||||
val pflags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
val createPendingShareIntent: PendingIntent = PendingIntent.getActivity(
|
|
||||||
this,
|
|
||||||
0,
|
|
||||||
actionIntent,
|
|
||||||
pflags
|
|
||||||
)
|
|
||||||
|
|
||||||
val intentBuilder = CustomTabsIntent.Builder()
|
|
||||||
|
|
||||||
// TODO: change to primary when it's possible to customize custom tabs title color
|
|
||||||
//intentBuilder.setToolbarColor(c.getResources().getColor(R.color.colorPrimary));
|
|
||||||
intentBuilder.setToolbarColor(resources.getColor(R.color.colorAccentDark))
|
|
||||||
intentBuilder.setShowTitle(true)
|
|
||||||
|
|
||||||
|
|
||||||
intentBuilder.setStartAnimations(
|
|
||||||
this,
|
|
||||||
R.anim.slide_in_right,
|
|
||||||
R.anim.slide_out_left
|
|
||||||
)
|
|
||||||
intentBuilder.setExitAnimations(
|
|
||||||
this,
|
|
||||||
android.R.anim.slide_in_left,
|
|
||||||
android.R.anim.slide_out_right
|
|
||||||
)
|
|
||||||
|
|
||||||
val closeicon = BitmapFactory.decodeResource(resources, R.drawable.ic_close_white_24dp)
|
|
||||||
intentBuilder.setCloseButtonIcon(closeicon)
|
|
||||||
|
|
||||||
val shareLabel = this.getString(R.string.label_share)
|
|
||||||
val icon = BitmapFactory.decodeResource(
|
|
||||||
resources,
|
|
||||||
R.drawable.ic_share_white_24dp
|
|
||||||
)
|
|
||||||
intentBuilder.setActionButton(icon, shareLabel, createPendingShareIntent)
|
|
||||||
|
|
||||||
return intentBuilder.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.openItemUrlInternally(
|
|
||||||
allItems: ArrayList<SelfossModel.Item>,
|
|
||||||
currentItem: Int,
|
|
||||||
linkDecoded: String,
|
|
||||||
customTabsIntent: CustomTabsIntent,
|
|
||||||
articleViewer: Boolean,
|
|
||||||
app: Activity
|
|
||||||
) {
|
|
||||||
if (articleViewer) {
|
|
||||||
ReaderActivity.allItems = allItems
|
|
||||||
val intent = Intent(this, ReaderActivity::class.java)
|
|
||||||
intent.putExtra("currentItem", currentItem)
|
|
||||||
app.startActivity(intent)
|
|
||||||
} else {
|
|
||||||
this.openItemUrlInternalBrowser(
|
|
||||||
linkDecoded,
|
|
||||||
customTabsIntent,
|
|
||||||
app)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.openItemUrlInternalBrowser(
|
|
||||||
linkDecoded: String,
|
|
||||||
customTabsIntent: CustomTabsIntent,
|
|
||||||
app: Activity
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
CustomTabActivityHelper.openCustomTab(
|
|
||||||
app,
|
|
||||||
customTabsIntent,
|
|
||||||
Uri.parse(linkDecoded)
|
|
||||||
) { _, uri ->
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
startActivity(intent)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
openInBrowser(linkDecoded, app)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.openItemUrl(
|
fun Context.openItemUrl(
|
||||||
allItems: ArrayList<SelfossModel.Item>,
|
allItems: ArrayList<SelfossModel.Item>,
|
||||||
currentItem: Int,
|
currentItem: Int,
|
||||||
linkDecoded: String,
|
linkDecoded: String,
|
||||||
customTabsIntent: CustomTabsIntent,
|
|
||||||
internalBrowser: Boolean,
|
|
||||||
articleViewer: Boolean,
|
articleViewer: Boolean,
|
||||||
app: Activity
|
app: Activity
|
||||||
) {
|
) {
|
||||||
@@ -129,34 +32,17 @@ fun Context.openItemUrl(
|
|||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
} else {
|
} else {
|
||||||
if (!internalBrowser) {
|
if (articleViewer) {
|
||||||
openInBrowser(linkDecoded, app)
|
ReaderActivity.allItems = allItems
|
||||||
} else if (articleViewer) {
|
val intent = Intent(this, ReaderActivity::class.java)
|
||||||
this.openItemUrlInternally(
|
intent.putExtra("currentItem", currentItem)
|
||||||
allItems,
|
|
||||||
currentItem,
|
|
||||||
linkDecoded,
|
|
||||||
customTabsIntent,
|
|
||||||
articleViewer,
|
|
||||||
app
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this.openItemUrlInternalBrowser(
|
|
||||||
linkDecoded,
|
|
||||||
customTabsIntent,
|
|
||||||
app
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun openInBrowser(linkDecoded: String, app: Activity) {
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
|
||||||
intent.data = Uri.parse(linkDecoded)
|
|
||||||
try {
|
|
||||||
app.startActivity(intent)
|
app.startActivity(intent)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} else {
|
||||||
Toast.makeText(app.baseContext, e.message, Toast.LENGTH_LONG).show()
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
intent.data = Uri.parse(linkDecoded.toStringUriWithHttp())
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +67,7 @@ fun Context.openInBrowserAsNewTask(i: SelfossModel.Item) {
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinkOnTouchListener: View.OnTouchListener {
|
class LinkOnTouchListener : View.OnTouchListener {
|
||||||
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
|
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
|
||||||
var ret = false
|
var ret = false
|
||||||
val widget: TextView = v as TextView
|
val widget: TextView = v as TextView
|
||||||
@@ -191,7 +77,8 @@ class LinkOnTouchListener: View.OnTouchListener {
|
|||||||
val action = event!!.action
|
val action = event!!.action
|
||||||
|
|
||||||
if (action == MotionEvent.ACTION_UP ||
|
if (action == MotionEvent.ACTION_UP ||
|
||||||
action == MotionEvent.ACTION_DOWN) {
|
action == MotionEvent.ACTION_DOWN
|
||||||
|
) {
|
||||||
var x: Float = event.x
|
var x: Float = event.x
|
||||||
var y: Float = event.y
|
var y: Float = event.y
|
||||||
|
|
||||||
|
|||||||
-153
@@ -1,153 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.utils.customtabs;
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import androidx.browser.customtabs.CustomTabsClient;
|
|
||||||
import androidx.browser.customtabs.CustomTabsIntent;
|
|
||||||
import androidx.browser.customtabs.CustomTabsServiceConnection;
|
|
||||||
import androidx.browser.customtabs.CustomTabsSession;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a helper class to manage the connection to the Custom Tabs Service.
|
|
||||||
*/
|
|
||||||
public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
|
||||||
private CustomTabsSession mCustomTabsSession;
|
|
||||||
private CustomTabsClient mClient;
|
|
||||||
private CustomTabsServiceConnection mConnection;
|
|
||||||
private ConnectionCallback mConnectionCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
|
|
||||||
*
|
|
||||||
* @param activity The host activity.
|
|
||||||
* @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
|
|
||||||
* @param uri the Uri to be opened.
|
|
||||||
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
|
|
||||||
*/
|
|
||||||
public static void openCustomTab(Activity activity,
|
|
||||||
CustomTabsIntent customTabsIntent,
|
|
||||||
Uri uri,
|
|
||||||
CustomTabFallback fallback) {
|
|
||||||
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
|
|
||||||
|
|
||||||
//If we cant find a package name, it means theres no browser that supports
|
|
||||||
//Chrome Custom Tabs installed. So, we fallback to the webview
|
|
||||||
if (packageName == null) {
|
|
||||||
if (fallback != null) {
|
|
||||||
fallback.openUri(activity, uri);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
customTabsIntent.intent.setPackage(packageName);
|
|
||||||
customTabsIntent.launchUrl(activity, uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unbinds the Activity from the Custom Tabs Service.
|
|
||||||
*
|
|
||||||
* @param activity the activity that is connected to the service.
|
|
||||||
*/
|
|
||||||
public void unbindCustomTabsService(Activity activity) {
|
|
||||||
if (mConnection == null) return;
|
|
||||||
activity.unbindService(mConnection);
|
|
||||||
mClient = null;
|
|
||||||
mCustomTabsSession = null;
|
|
||||||
mConnection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates or retrieves an exiting CustomTabsSession.
|
|
||||||
*
|
|
||||||
* @return a CustomTabsSession.
|
|
||||||
*/
|
|
||||||
public CustomTabsSession getSession() {
|
|
||||||
if (mClient == null) {
|
|
||||||
mCustomTabsSession = null;
|
|
||||||
} else if (mCustomTabsSession == null) {
|
|
||||||
mCustomTabsSession = mClient.newSession(null);
|
|
||||||
}
|
|
||||||
return mCustomTabsSession;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a Callback to be called when connected or disconnected from the Custom Tabs Service.
|
|
||||||
*
|
|
||||||
* @param connectionCallback
|
|
||||||
*/
|
|
||||||
public void setConnectionCallback(ConnectionCallback connectionCallback) {
|
|
||||||
this.mConnectionCallback = connectionCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds the Activity to the Custom Tabs Service.
|
|
||||||
*
|
|
||||||
* @param activity the activity to be binded to the service.
|
|
||||||
*/
|
|
||||||
public void bindCustomTabsService(Activity activity) {
|
|
||||||
if (mClient != null) return;
|
|
||||||
|
|
||||||
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
|
|
||||||
if (packageName == null) return;
|
|
||||||
|
|
||||||
mConnection = new ServiceConnection(this);
|
|
||||||
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if call to mayLaunchUrl was accepted.
|
|
||||||
* @see {@link CustomTabsSession#mayLaunchUrl(Uri, Bundle, List)}.
|
|
||||||
*/
|
|
||||||
public boolean mayLaunchUrl(Uri uri, Bundle extras, List<Bundle> otherLikelyBundles) {
|
|
||||||
if (mClient == null) return false;
|
|
||||||
|
|
||||||
CustomTabsSession session = getSession();
|
|
||||||
return session != null && session.mayLaunchUrl(uri, extras, otherLikelyBundles);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceConnected(CustomTabsClient client) {
|
|
||||||
mClient = client;
|
|
||||||
mClient.warmup(0L);
|
|
||||||
if (mConnectionCallback != null) mConnectionCallback.onCustomTabsConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected() {
|
|
||||||
mClient = null;
|
|
||||||
mCustomTabsSession = null;
|
|
||||||
if (mConnectionCallback != null) mConnectionCallback.onCustomTabsDisconnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Callback for when the service is connected or disconnected. Use those callbacks to
|
|
||||||
* handle UI changes when the service is connected or disconnected.
|
|
||||||
*/
|
|
||||||
public interface ConnectionCallback {
|
|
||||||
/**
|
|
||||||
* Called when the service is connected.
|
|
||||||
*/
|
|
||||||
void onCustomTabsConnected();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the service is disconnected.
|
|
||||||
*/
|
|
||||||
void onCustomTabsDisconnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To be used as a fallback to open the Uri when Custom Tabs is not available.
|
|
||||||
*/
|
|
||||||
public interface CustomTabFallback {
|
|
||||||
/**
|
|
||||||
* @param activity The Activity that wants to open the Uri.
|
|
||||||
* @param uri The uri to be opened by the fallback.
|
|
||||||
*/
|
|
||||||
void openUri(Activity activity, Uri uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-129
@@ -1,129 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.utils.customtabs;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import androidx.browser.customtabs.CustomTabsService;
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.utils.customtabs.helpers.KeepAliveService;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
|
||||||
class CustomTabsHelper {
|
|
||||||
private static final String TAG = "CustomTabsHelper";
|
|
||||||
private static final String STABLE_PACKAGE = "com.android.chrome";
|
|
||||||
private static final String BETA_PACKAGE = "com.chrome.beta";
|
|
||||||
private static final String DEV_PACKAGE = "com.chrome.dev";
|
|
||||||
private static final String LOCAL_PACKAGE = "com.google.android.apps.chrome";
|
|
||||||
private static final String EXTRA_CUSTOM_TABS_KEEP_ALIVE =
|
|
||||||
"android.support.customtabs.extra.KEEP_ALIVE";
|
|
||||||
|
|
||||||
private static String sPackageNameToUse;
|
|
||||||
|
|
||||||
private CustomTabsHelper() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addKeepAliveExtra(Context context, Intent intent) {
|
|
||||||
Intent keepAliveIntent = new Intent().setClassName(
|
|
||||||
context.getPackageName(), KeepAliveService.class.getCanonicalName());
|
|
||||||
intent.putExtra(EXTRA_CUSTOM_TABS_KEEP_ALIVE, keepAliveIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Goes through all apps that handle VIEW intents and have a warmup service. Picks
|
|
||||||
* the one chosen by the user if there is one, otherwise makes a best effort to return a
|
|
||||||
* valid package name.
|
|
||||||
* <p>
|
|
||||||
* This is <strong>not</strong> threadsafe.
|
|
||||||
*
|
|
||||||
* @param context {@link Context} to use for accessing {@link PackageManager}.
|
|
||||||
* @return The package name recommended to use for connecting to custom tabs related components.
|
|
||||||
*/
|
|
||||||
public static String getPackageNameToUse(Context context) {
|
|
||||||
if (sPackageNameToUse != null) return sPackageNameToUse;
|
|
||||||
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
// Get default VIEW intent handler.
|
|
||||||
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
|
|
||||||
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
|
|
||||||
String defaultViewHandlerPackageName = null;
|
|
||||||
if (defaultViewHandlerInfo != null) {
|
|
||||||
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all apps that can handle VIEW intents.
|
|
||||||
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
|
|
||||||
List<String> packagesSupportingCustomTabs = new ArrayList<>();
|
|
||||||
for (ResolveInfo info : resolvedActivityList) {
|
|
||||||
Intent serviceIntent = new Intent();
|
|
||||||
serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
|
|
||||||
serviceIntent.setPackage(info.activityInfo.packageName);
|
|
||||||
if (pm.resolveService(serviceIntent, 0) != null) {
|
|
||||||
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
|
|
||||||
// and service calls.
|
|
||||||
if (packagesSupportingCustomTabs.isEmpty()) {
|
|
||||||
sPackageNameToUse = null;
|
|
||||||
} else if (packagesSupportingCustomTabs.size() == 1) {
|
|
||||||
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
|
|
||||||
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
|
|
||||||
&& !hasSpecializedHandlerIntents(context, activityIntent)
|
|
||||||
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
|
|
||||||
sPackageNameToUse = defaultViewHandlerPackageName;
|
|
||||||
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
|
|
||||||
sPackageNameToUse = STABLE_PACKAGE;
|
|
||||||
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
|
|
||||||
sPackageNameToUse = BETA_PACKAGE;
|
|
||||||
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
|
|
||||||
sPackageNameToUse = DEV_PACKAGE;
|
|
||||||
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
|
|
||||||
sPackageNameToUse = LOCAL_PACKAGE;
|
|
||||||
}
|
|
||||||
return sPackageNameToUse;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to check whether there is a specialized handler for a given intent.
|
|
||||||
*
|
|
||||||
* @param intent The intent to check with.
|
|
||||||
* @return Whether there is a specialized handler for the given intent.
|
|
||||||
*/
|
|
||||||
private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) {
|
|
||||||
try {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
List<ResolveInfo> handlers = pm.queryIntentActivities(
|
|
||||||
intent,
|
|
||||||
PackageManager.GET_RESOLVED_FILTER);
|
|
||||||
if (handlers == null || handlers.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (ResolveInfo resolveInfo : handlers) {
|
|
||||||
IntentFilter filter = resolveInfo.filter;
|
|
||||||
if (filter == null) continue;
|
|
||||||
if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue;
|
|
||||||
if (resolveInfo.activityInfo == null) continue;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
Log.e(TAG, "Runtime exception while getting specialized handlers");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return All possible chrome package names that provide custom tabs feature.
|
|
||||||
*/
|
|
||||||
public static String[] getPackages() {
|
|
||||||
return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL_PACKAGE};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.utils.customtabs;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import androidx.browser.customtabs.CustomTabsClient;
|
|
||||||
import androidx.browser.customtabs.CustomTabsServiceConnection;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation for the CustomTabsServiceConnection that avoids leaking the
|
|
||||||
* ServiceConnectionCallback
|
|
||||||
*/
|
|
||||||
public class ServiceConnection extends CustomTabsServiceConnection {
|
|
||||||
// A weak reference to the ServiceConnectionCallback to avoid leaking it.
|
|
||||||
private WeakReference<ServiceConnectionCallback> mConnectionCallback;
|
|
||||||
|
|
||||||
public ServiceConnection(ServiceConnectionCallback connectionCallback) {
|
|
||||||
mConnectionCallback = new WeakReference<>(connectionCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
|
|
||||||
ServiceConnectionCallback connectionCallback = mConnectionCallback.get();
|
|
||||||
if (connectionCallback != null) connectionCallback.onServiceConnected(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
|
||||||
ServiceConnectionCallback connectionCallback = mConnectionCallback.get();
|
|
||||||
if (connectionCallback != null) connectionCallback.onServiceDisconnected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.utils.customtabs;
|
|
||||||
|
|
||||||
|
|
||||||
import androidx.browser.customtabs.CustomTabsClient;
|
|
||||||
|
|
||||||
|
|
||||||
public interface ServiceConnectionCallback {
|
|
||||||
/**
|
|
||||||
* Called when the service is connected.
|
|
||||||
*
|
|
||||||
* @param client a CustomTabsClient
|
|
||||||
*/
|
|
||||||
void onServiceConnected(CustomTabsClient client);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the service is disconnected.
|
|
||||||
*/
|
|
||||||
void onServiceDisconnected();
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.utils.customtabs.helpers;
|
|
||||||
|
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Binder;
|
|
||||||
import android.os.IBinder;
|
|
||||||
|
|
||||||
public class KeepAliveService extends Service {
|
|
||||||
private static final Binder sBinder = new Binder();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return sBinder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
/* From https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/drawerItems/CustomBaseViewHolder.java */
|
|
||||||
package bou.amine.apps.readerforselfossv2.android.utils.drawer
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
|
||||||
|
|
||||||
open class CustomBaseViewHolder(var view: View) : RecyclerView.ViewHolder(view) {
|
|
||||||
var icon: ImageView = view.findViewById(R.id.material_drawer_icon)
|
|
||||||
var name: TextView = view.findViewById(R.id.material_drawer_name)
|
|
||||||
var description: TextView = view.findViewById(R.id.material_drawer_description)
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright 2015 Google Inc. All Rights Reserved.
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<translate android:fromXDelta="100%p" android:toXDelta="0"
|
|
||||||
android:duration="@android:integer/config_mediumAnimTime"/>
|
|
||||||
</set>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright 2015 Google Inc. All Rights Reserved.
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<translate android:fromXDelta="0" android:toXDelta="-100%p"
|
|
||||||
android:duration="@android:integer/config_mediumAnimTime"/>
|
|
||||||
</set>
|
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item
|
<item>
|
||||||
android:drawable="@color/ic_launcher_background"/>
|
<shape android:shape="rectangle" >
|
||||||
|
<solid android:color="?attr/colorSurface" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<bitmap
|
<bitmap
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<bitmap
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:dither="true"
|
||||||
|
android:src="@drawable/checktile"
|
||||||
|
android:tileMode="repeat"/>
|
||||||
Binary file not shown.
|
After
Width:
|
Height:
|
Size:
Gitea Version: 1.28.0+dev-113-ge8befe0268 |