mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Compare commits
141 Commits
1881-threa
...
beta-1.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62cca1335f | ||
|
|
11a18859fb | ||
|
|
1116a7e125 | ||
|
|
415b315292 | ||
|
|
9818ec2b66 | ||
|
|
372516646d | ||
|
|
72e721b0d3 | ||
|
|
6599093611 | ||
|
|
dceeecf1fe | ||
|
|
ace0b9a3d8 | ||
|
|
7c45c90de9 | ||
|
|
c2a4b5e26a | ||
|
|
feac0ad802 | ||
|
|
60478eba3f | ||
|
|
3639952612 | ||
|
|
c4a654b267 | ||
|
|
ecb31a4d32 | ||
|
|
76f201bb2f | ||
|
|
87799b743c | ||
|
|
b898a7c370 | ||
|
|
f3210e3af2 | ||
|
|
225fd6fd49 | ||
|
|
400d259a60 | ||
|
|
4074ac8578 | ||
|
|
b2e6dd4138 | ||
|
|
b608b42174 | ||
|
|
f603254153 | ||
|
|
c851dd228b | ||
|
|
e97478a21a | ||
|
|
726ebcea3f | ||
|
|
2f969775d8 | ||
|
|
d3b855318c | ||
|
|
95104d3383 | ||
|
|
6860a04e8b | ||
|
|
33c24f8655 | ||
|
|
1fa4b78474 | ||
|
|
b678de7529 | ||
|
|
ab1ed0ff5a | ||
|
|
ad20e5230a | ||
|
|
ae923e5777 | ||
|
|
46b4204805 | ||
|
|
2257c005b3 | ||
|
|
eb9ff9c954 | ||
|
|
4f08f81779 | ||
|
|
2b0815aaac | ||
|
|
a9e83491d3 | ||
|
|
ee967c5d8f | ||
|
|
43740777d4 | ||
|
|
d5b0556ea2 | ||
|
|
227f00c10c | ||
|
|
8b4ff2dc8a | ||
|
|
4be2afb915 | ||
|
|
74447b8ec3 | ||
|
|
d95242bd7e | ||
|
|
51794424ce | ||
|
|
5db099bae6 | ||
|
|
a2faa3bd3b | ||
|
|
a3fb7b5680 | ||
|
|
264d110dbd | ||
|
|
839b871a45 | ||
|
|
2fb4825b8f | ||
|
|
3f9a66b1b6 | ||
|
|
d796916387 | ||
|
|
fe07b760ea | ||
|
|
b4a5fe6772 | ||
|
|
e21e6267d7 | ||
|
|
d7afbdf690 | ||
|
|
c5d2661c1d | ||
|
|
b738bdd14e | ||
|
|
629cff20a3 | ||
|
|
6cfb70db95 | ||
|
|
737ecfb620 | ||
|
|
5a424b178e | ||
|
|
59f4e7c34a | ||
|
|
2480824d69 | ||
|
|
a6c2000d81 | ||
|
|
a38a3139d9 | ||
|
|
4c8adaa02b | ||
|
|
8a534b4503 | ||
|
|
e5b2275c82 | ||
|
|
5159593825 | ||
|
|
a546fecc01 | ||
|
|
3e7e37f5f6 | ||
|
|
d095ba0b15 | ||
|
|
7fab97d26c | ||
|
|
6fbc82ee27 | ||
|
|
885b03cfd7 | ||
|
|
f81bfcafeb | ||
|
|
f36f1cf3d4 | ||
|
|
7d6a63d866 | ||
|
|
15ebdf8dd5 | ||
|
|
db2c235283 | ||
|
|
6b61725c6a | ||
|
|
e5bd43469e | ||
|
|
9366c184d8 | ||
|
|
73d2c964d4 | ||
|
|
fb2b4209cf | ||
|
|
a04b512497 | ||
|
|
3d9515e308 | ||
|
|
1b19b331b1 | ||
|
|
d151a2d7f7 | ||
|
|
9712a4b849 | ||
|
|
cf1ac5e3e5 | ||
|
|
cb859e998d | ||
|
|
0b9345f867 | ||
|
|
12988120d1 | ||
|
|
8d6c866e62 | ||
|
|
8f82cf3c73 | ||
|
|
21112ce092 | ||
|
|
21ee3ea00d | ||
|
|
bb964101b3 | ||
|
|
d796eff0f6 | ||
|
|
700ea2b387 | ||
|
|
e4a66615a7 | ||
|
|
6e3a7d8d0c | ||
|
|
166b5d4add | ||
|
|
0fd59a26f6 | ||
|
|
4162bf990a | ||
|
|
09cfadbf7e | ||
|
|
3fb27dbb12 | ||
|
|
ae4a04bada | ||
|
|
831c65b647 | ||
|
|
afcd38b84c | ||
|
|
d670179e30 | ||
|
|
998c435b13 | ||
|
|
4a0327a62b | ||
|
|
70532732c8 | ||
|
|
d69406dfe3 | ||
|
|
98619df867 | ||
|
|
f2eca0fdb6 | ||
|
|
c62a57e8b2 | ||
|
|
239c4a27ad | ||
|
|
e5d78a858d | ||
|
|
5c1bcdeb9d | ||
|
|
6c1f5450cb | ||
|
|
0d070cf422 | ||
|
|
d34d66c691 | ||
|
|
6005d156eb | ||
|
|
94dd75f24b | ||
|
|
c93e5441b0 | ||
|
|
8ec8cc927b |
@@ -1,29 +1,52 @@
|
|||||||
image: briar/ci-image-android:latest
|
image: briar/ci-image-android:latest
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- check_reproducibility
|
- optional_tests
|
||||||
|
- check_reproducibility
|
||||||
|
|
||||||
test:
|
.base-test:
|
||||||
stage: test
|
|
||||||
before_script:
|
before_script:
|
||||||
- set -e
|
- set -e
|
||||||
- export GRADLE_USER_HOME=$PWD/.gradle
|
- export GRADLE_USER_HOME=$PWD/.gradle
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
|
key: "$CI_COMMIT_REF_SLUG"
|
||||||
paths:
|
paths:
|
||||||
- .gradle/wrapper
|
- .gradle/wrapper
|
||||||
- .gradle/caches
|
- .gradle/caches
|
||||||
|
|
||||||
script:
|
|
||||||
- ./gradlew --no-daemon -Djava.security.egd=file:/dev/urandom animalSnifferMain animalSnifferTest
|
|
||||||
- ./gradlew --no-daemon -Djava.security.egd=file:/dev/urandom check compileOfficialDebugAndroidTestSources compileScreenshotDebugAndroidTestSources
|
|
||||||
|
|
||||||
after_script:
|
after_script:
|
||||||
# these file change every time but should not be cached
|
# these file change every time and should not be cached
|
||||||
- rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
|
- rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
|
||||||
- rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/
|
- rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/
|
||||||
|
|
||||||
|
test:
|
||||||
|
extends: .base-test
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- ./gradlew --no-daemon -Djava.security.egd=file:/dev/urandom animalSnifferMain animalSnifferTest
|
||||||
|
- ./gradlew --no-daemon -Djava.security.egd=file:/dev/urandom check
|
||||||
|
|
||||||
|
android test:
|
||||||
|
extends: .base-test
|
||||||
|
stage: optional_tests
|
||||||
|
image: briar/ci-image-android-emulator:latest
|
||||||
|
script:
|
||||||
|
# start emulator first, so it can fail early
|
||||||
|
- start-emulator.sh
|
||||||
|
# run normal and screenshot tests together (exclude Large tests)
|
||||||
|
- ./gradlew -Djava.security.egd=file:/dev/urandom connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest
|
||||||
|
artifacts:
|
||||||
|
name: "${CI_PROJECT_PATH}_${CI_JOB_STAGE}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}"
|
||||||
|
paths:
|
||||||
|
- kernel.log
|
||||||
|
- logcat.txt
|
||||||
|
expire_in: 3 days
|
||||||
|
when: on_failure
|
||||||
|
when: manual
|
||||||
|
except:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- kvm
|
||||||
|
|
||||||
test_reproducible:
|
test_reproducible:
|
||||||
stage: check_reproducibility
|
stage: check_reproducibility
|
||||||
@@ -31,3 +54,34 @@ test_reproducible:
|
|||||||
- "curl -X POST -F token=${RELEASE_CHECK_TOKEN} -F ref=master -F variables[RELEASE_TAG]=${CI_COMMIT_REF_NAME} https://code.briarproject.org/api/v4/projects/61/trigger/pipeline"
|
- "curl -X POST -F token=${RELEASE_CHECK_TOKEN} -F ref=master -F variables[RELEASE_TAG]=${CI_COMMIT_REF_NAME} https://code.briarproject.org/api/v4/projects/61/trigger/pipeline"
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
|
|
||||||
|
.optional_tests:
|
||||||
|
stage: optional_tests
|
||||||
|
before_script:
|
||||||
|
- set -e
|
||||||
|
- export GRADLE_USER_HOME=$PWD/.gradle
|
||||||
|
|
||||||
|
cache:
|
||||||
|
key: "$CI_COMMIT_REF_SLUG"
|
||||||
|
paths:
|
||||||
|
- .gradle/wrapper
|
||||||
|
- .gradle/caches
|
||||||
|
|
||||||
|
script:
|
||||||
|
- OPTIONAL_TESTS=org.briarproject.bramble.plugin.tor.BridgeTest ./gradlew --info bramble-java:test --tests BridgeTest
|
||||||
|
|
||||||
|
after_script:
|
||||||
|
# these file change every time but should not be cached
|
||||||
|
- rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
|
||||||
|
- rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/
|
||||||
|
|
||||||
|
manual_tests:
|
||||||
|
extends: .optional_tests
|
||||||
|
when: manual
|
||||||
|
except:
|
||||||
|
- tags
|
||||||
|
|
||||||
|
pre_release_tests:
|
||||||
|
extends: .optional_tests
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
|||||||
14
.idea/dictionaries/briar.xml
generated
Normal file
14
.idea/dictionaries/briar.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="briar">
|
||||||
|
<words>
|
||||||
|
<w>briar</w>
|
||||||
|
<w>briarproject</w>
|
||||||
|
<w>emoji</w>
|
||||||
|
<w>encrypter</w>
|
||||||
|
<w>identicon</w>
|
||||||
|
<w>introducee</w>
|
||||||
|
<w>introducer</w>
|
||||||
|
<w>onboarding</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
24
.idea/runConfigurations/BridgeTest.xml
generated
Normal file
24
.idea/runConfigurations/BridgeTest.xml
generated
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="BridgeTest" type="AndroidJUnit" factoryName="Android JUnit" nameIsGenerated="true">
|
||||||
|
<module name="briar.bramble-java" />
|
||||||
|
<useClassPathOnly />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="org.briarproject.bramble.plugin.tor.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<option name="PACKAGE_NAME" value="org.briarproject.bramble.plugin.tor" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="org.briarproject.bramble.plugin.tor.BridgeTest" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
|
||||||
|
<envs>
|
||||||
|
<env name="OPTIONAL_TESTS" value="org.briarproject.bramble.plugin.tor.BridgeTest" />
|
||||||
|
</envs>
|
||||||
|
<method v="2">
|
||||||
|
<option name="Android.Gradle.BeforeRunTask" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
51
.idea/runConfigurations/Instrumentation_Tests__destroys_DB_.xml
generated
Normal file
51
.idea/runConfigurations/Instrumentation_Tests__destroys_DB_.xml
generated
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Instrumentation Tests (destroys DB)" type="AndroidTestRunConfigurationType" factoryName="Android Instrumented Tests">
|
||||||
|
<module name="briar.briar-android" />
|
||||||
|
<option name="TESTING_TYPE" value="1" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="CLASS_NAME" value="" />
|
||||||
|
<option name="PACKAGE_NAME" value="org.briarproject.briar.android" />
|
||||||
|
<option name="INSTRUMENTATION_RUNNER_CLASS" value="" />
|
||||||
|
<option name="EXTRA_OPTIONS" value="-e notAnnotation androidx.test.filters.LargeTest" />
|
||||||
|
<option name="INCLUDE_GRADLE_EXTRA_OPTIONS" value="true" />
|
||||||
|
<option name="CLEAR_LOGCAT" value="false" />
|
||||||
|
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
|
||||||
|
<option name="SKIP_NOOP_APK_INSTALLATIONS" value="true" />
|
||||||
|
<option name="FORCE_STOP_RUNNING_APP" value="true" />
|
||||||
|
<option name="TARGET_SELECTION_MODE" value="DEVICE_AND_SNAPSHOT_COMBO_BOX" />
|
||||||
|
<option name="DEBUGGER_TYPE" value="Auto" />
|
||||||
|
<Auto>
|
||||||
|
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||||
|
<option name="SHOW_STATIC_VARS" value="true" />
|
||||||
|
<option name="WORKING_DIR" value="" />
|
||||||
|
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||||
|
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||||
|
</Auto>
|
||||||
|
<Hybrid>
|
||||||
|
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||||
|
<option name="SHOW_STATIC_VARS" value="true" />
|
||||||
|
<option name="WORKING_DIR" value="" />
|
||||||
|
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||||
|
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||||
|
</Hybrid>
|
||||||
|
<Java />
|
||||||
|
<Native>
|
||||||
|
<option name="USE_JAVA_AWARE_DEBUGGER" value="false" />
|
||||||
|
<option name="SHOW_STATIC_VARS" value="true" />
|
||||||
|
<option name="WORKING_DIR" value="" />
|
||||||
|
<option name="TARGET_LOGGING_CHANNELS" value="lldb process:gdb-remote packets" />
|
||||||
|
<option name="SHOW_OPTIMIZED_WARNING" value="true" />
|
||||||
|
</Native>
|
||||||
|
<Profilers>
|
||||||
|
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
|
||||||
|
<option name="STARTUP_PROFILING_ENABLED" value="false" />
|
||||||
|
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
|
||||||
|
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Sample Java Methods" />
|
||||||
|
<option name="STARTUP_NATIVE_MEMORY_PROFILING_ENABLED" value="false" />
|
||||||
|
<option name="NATIVE_MEMORY_SAMPLE_RATE_BYTES" value="2048" />
|
||||||
|
</Profilers>
|
||||||
|
<method v="2">
|
||||||
|
<option name="Android.Gradle.BeforeRunTask" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -8,11 +8,15 @@ android {
|
|||||||
compileSdkVersion 30
|
compileSdkVersion 30
|
||||||
buildToolsVersion '30.0.2'
|
buildToolsVersion '30.0.2'
|
||||||
|
|
||||||
|
packagingOptions {
|
||||||
|
doNotStrip '**/*.so'
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10213
|
versionCode 10220
|
||||||
versionName "1.2.13"
|
versionName "1.2.20"
|
||||||
consumerProguardFiles 'proguard-rules.txt'
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
@@ -38,8 +42,8 @@ configurations {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(path: ':bramble-core', configuration: 'default')
|
implementation project(path: ':bramble-core', configuration: 'default')
|
||||||
tor 'org.briarproject:tor-android:0.3.5.12@zip'
|
tor 'org.briarproject:tor-android:0.3.5.13@zip'
|
||||||
tor 'org.briarproject:obfs4proxy-android:0.0.11-2@zip'
|
tor 'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a@zip'
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,11 @@ class AndroidBluetoothPlugin
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
IoUtils.tryToClose(s, LOG, WARNING);
|
IoUtils.tryToClose(s, LOG, WARNING);
|
||||||
throw e;
|
throw e;
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
// BluetoothSocket#connect() may throw an NPE under unknown
|
||||||
|
// circumstances
|
||||||
|
IoUtils.tryToClose(s, LOG, WARNING);
|
||||||
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class AndroidUtils {
|
|||||||
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
||||||
|
|
||||||
private static final String STORED_REPORTS = "dev-reports";
|
private static final String STORED_REPORTS = "dev-reports";
|
||||||
|
private static final String STORED_LOGCAT = "dev-logcat";
|
||||||
|
|
||||||
public static Collection<String> getSupportedArchitectures() {
|
public static Collection<String> getSupportedArchitectures() {
|
||||||
List<String> abis = new ArrayList<>();
|
List<String> abis = new ArrayList<>();
|
||||||
@@ -107,14 +108,14 @@ public class AndroidUtils {
|
|||||||
return ctx.getDir(STORED_REPORTS, MODE_PRIVATE);
|
return ctx.getDir(STORED_REPORTS, MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File getLogcatFile(Context ctx) {
|
||||||
|
return new File(ctx.getFilesDir(), STORED_LOGCAT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of supported content types for image attachments.
|
* Returns an array of supported content types for image attachments.
|
||||||
* GIFs can't be compressed on API < 24 so they're not supported.
|
|
||||||
* <p>
|
|
||||||
* TODO: Remove this restriction when large message support is added
|
|
||||||
*/
|
*/
|
||||||
public static String[] getSupportedImageContentTypes() {
|
public static String[] getSupportedImageContentTypes() {
|
||||||
if (SDK_INT < 24) return new String[] {"image/jpeg", "image/png"};
|
return new String[] {"image/jpeg", "image/png", "image/gif"};
|
||||||
else return new String[] {"image/jpeg", "image/png", "image/gif"};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ dependencyVerification {
|
|||||||
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
||||||
'org.bouncycastle:bcpkix-jdk15on:1.56:bcpkix-jdk15on-1.56.jar:7043dee4e9e7175e93e0b36f45b1ec1ecb893c5f755667e8b916eb8dd201c6ca',
|
'org.bouncycastle:bcpkix-jdk15on:1.56:bcpkix-jdk15on-1.56.jar:7043dee4e9e7175e93e0b36f45b1ec1ecb893c5f755667e8b916eb8dd201c6ca',
|
||||||
'org.bouncycastle:bcprov-jdk15on:1.56:bcprov-jdk15on-1.56.jar:963e1ee14f808ffb99897d848ddcdb28fa91ddda867eb18d303e82728f878349',
|
'org.bouncycastle:bcprov-jdk15on:1.56:bcprov-jdk15on-1.56.jar:963e1ee14f808ffb99897d848ddcdb28fa91ddda867eb18d303e82728f878349',
|
||||||
'org.briarproject:obfs4proxy-android:0.0.11-2:obfs4proxy-android-0.0.11-2.zip:57e55cbe87aa2aac210fdbb6cd8cdeafe15f825406a08ebf77a8b787aa2c6a8a',
|
'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a:obfs4proxy-android-0.0.12-dev-40245c4a.zip:8ab05a8f8391be2cb5ab2b665c281a06d9e3a756bd0f95a40a36ca927866ea82',
|
||||||
'org.briarproject:tor-android:0.3.5.12:tor-android-0.3.5.12.zip:db71fb3290acff79d572af0752570eaf6aad7c4d88c9b9aa0b4d5afe2b9ead9c',
|
'org.briarproject:tor-android:0.3.5.13:tor-android-0.3.5.13.zip:e0978db136731dae07774b722970cdae1e462fb5adc82845dd80a7e2d87f356c',
|
||||||
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
||||||
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
||||||
'org.checkerframework:checker-qual:2.8.1:checker-qual-2.8.1.jar:9103499008bcecd4e948da29b17864abb64304e15706444ae209d17ebe0575df',
|
'org.checkerframework:checker-qual:2.8.1:checker-qual-2.8.1.jar:9103499008bcecd4e948da29b17864abb64304e15706444ae209d17ebe0575df',
|
||||||
|
|||||||
@@ -19,4 +19,10 @@ public interface StreamDecrypterFactory {
|
|||||||
*/
|
*/
|
||||||
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamDecrypter} for decrypting a log stream.
|
||||||
|
*/
|
||||||
|
StreamDecrypter createLogStreamDecrypter(InputStream in,
|
||||||
|
SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ public interface StreamEncrypterFactory {
|
|||||||
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
||||||
* stream.
|
* stream.
|
||||||
*/
|
*/
|
||||||
StreamEncrypter createContactExchangeStreamDecrypter(OutputStream out,
|
StreamEncrypter createContactExchangeStreamEncrypter(OutputStream out,
|
||||||
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamEncrypter} for encrypting a log stream.
|
||||||
|
*/
|
||||||
|
StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,6 @@ public interface DevConfig {
|
|||||||
String getDevOnionAddress();
|
String getDevOnionAddress();
|
||||||
|
|
||||||
File getReportDir();
|
File getReportDir();
|
||||||
|
|
||||||
|
File getLogcatFile();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,13 @@ public interface StreamReaderFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link InputStream InputStream} for reading from a contact
|
* Creates an {@link InputStream InputStream} for reading from a contact
|
||||||
* exchangestream.
|
* exchange stream.
|
||||||
*/
|
*/
|
||||||
InputStream createContactExchangeStreamReader(InputStream in,
|
InputStream createContactExchangeStreamReader(InputStream in,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an {@link InputStream} for reading from a log stream.
|
||||||
|
*/
|
||||||
|
InputStream createLogStreamReader(InputStream in, SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,19 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface StreamWriterFactory {
|
public interface StreamWriterFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link OutputStream OutputStream} for writing to a
|
* Creates a {@link StreamWriter} for writing to a transport stream.
|
||||||
* transport stream
|
|
||||||
*/
|
*/
|
||||||
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link OutputStream OutputStream} for writing to a contact
|
* Creates a {@link StreamWriter} for writing to a contact exchange stream.
|
||||||
* exchange stream.
|
|
||||||
*/
|
*/
|
||||||
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamWriter} for writing to a log stream.
|
||||||
|
*/
|
||||||
|
StreamWriter createLogStreamWriter(OutputStream out, SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,16 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.Math.min;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
|
||||||
class ScryptKdf implements PasswordBasedKdf {
|
class ScryptKdf implements PasswordBasedKdf {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ScryptKdf.class.getName());
|
getLogger(ScryptKdf.class.getName());
|
||||||
|
|
||||||
private static final int MIN_COST = 256; // Min parameter N
|
private static final int MIN_COST = 256; // Min parameter N
|
||||||
private static final int MAX_COST = 1024 * 1024; // Max parameter N
|
private static final int MAX_COST = 1024 * 1024; // Max parameter N
|
||||||
@@ -33,10 +35,20 @@ class ScryptKdf implements PasswordBasedKdf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int chooseCostParameter() {
|
public int chooseCostParameter() {
|
||||||
|
// Scrypt uses at least 128 * N * r bytes of memory. Don't use more
|
||||||
|
// than half of the JVM's max heap size or we may run out of memory.
|
||||||
|
// https://blog.filippo.io/the-scrypt-parameters/
|
||||||
|
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||||
|
long maxCost = min(MAX_COST, maxMemory / BLOCK_SIZE / 256);
|
||||||
|
if (LOG.isLoggable(INFO) && maxCost < MAX_COST) {
|
||||||
|
LOG.info("Max cost capped at " + maxCost
|
||||||
|
+ " due to max heap size " + maxMemory);
|
||||||
|
}
|
||||||
// Increase the cost from min to max while measuring performance
|
// Increase the cost from min to max while measuring performance
|
||||||
int cost = MIN_COST;
|
int cost = MIN_COST;
|
||||||
while (cost * 2 <= MAX_COST && measureDuration(cost) * 2 <= TARGET_MS)
|
while (cost * 2 <= maxCost && measureDuration(cost) * 2 <= TARGET_MS) {
|
||||||
cost *= 2;
|
cost *= 2;
|
||||||
|
}
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("KDF cost parameter " + cost);
|
LOG.info("KDF cost parameter " + cost);
|
||||||
return cost;
|
return cost;
|
||||||
|
|||||||
@@ -36,4 +36,10 @@ class StreamDecrypterFactoryImpl implements StreamDecrypterFactory {
|
|||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamDecrypterImpl(in, cipherProvider.get(), 0, headerKey);
|
return new StreamDecrypterImpl(in, cipherProvider.get(), 0, headerKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamDecrypter createLogStreamDecrypter(InputStream in,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return createContactExchangeStreamDecrypter(in, headerKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamEncrypter createContactExchangeStreamDecrypter(
|
public StreamEncrypter createContactExchangeStreamEncrypter(
|
||||||
OutputStream out, SecretKey headerKey) {
|
OutputStream out, SecretKey headerKey) {
|
||||||
AuthenticatedCipher cipher = cipherProvider.get();
|
AuthenticatedCipher cipher = cipherProvider.get();
|
||||||
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
||||||
@@ -60,4 +60,10 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
|||||||
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
||||||
headerKey, frameKey);
|
headerKey, frameKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return createContactExchangeStreamEncrypter(out, headerKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,15 +24,21 @@ class StreamReaderFactoryImpl implements StreamReaderFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
||||||
return new StreamReaderImpl(
|
return new StreamReaderImpl(streamDecrypterFactory
|
||||||
streamDecrypterFactory.createStreamDecrypter(in, ctx));
|
.createStreamDecrypter(in, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createContactExchangeStreamReader(InputStream in,
|
public InputStream createContactExchangeStreamReader(InputStream in,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamReaderImpl(
|
return new StreamReaderImpl(streamDecrypterFactory
|
||||||
streamDecrypterFactory.createContactExchangeStreamDecrypter(in,
|
.createContactExchangeStreamDecrypter(in, headerKey));
|
||||||
headerKey));
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream createLogStreamReader(InputStream in,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return new StreamReaderImpl(streamDecrypterFactory
|
||||||
|
.createLogStreamDecrypter(in, headerKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,21 @@ class StreamWriterFactoryImpl implements StreamWriterFactory {
|
|||||||
@Override
|
@Override
|
||||||
public StreamWriter createStreamWriter(OutputStream out,
|
public StreamWriter createStreamWriter(OutputStream out,
|
||||||
StreamContext ctx) {
|
StreamContext ctx) {
|
||||||
return new StreamWriterImpl(
|
return new StreamWriterImpl(streamEncrypterFactory
|
||||||
streamEncrypterFactory.createStreamEncrypter(out, ctx));
|
.createStreamEncrypter(out, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamWriterImpl(
|
return new StreamWriterImpl(streamEncrypterFactory
|
||||||
streamEncrypterFactory.createContactExchangeStreamDecrypter(out,
|
.createContactExchangeStreamEncrypter(out, headerKey));
|
||||||
headerKey));
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamWriter createLogStreamWriter(OutputStream out,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return new StreamWriterImpl(streamEncrypterFactory
|
||||||
|
.createLogStreamEncrypter(out, headerKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
|
Bridge obfs4 192.95.36.142:443 CDF2E852BF539B82BD10E27E9115A31734E378C2 cert=qUVQ0srL1JI/vO6V6m/24anYXiJD3QP2HgzUKQtQ7GRqqUvs7P+tG43RtAqdhLOALP7DJQ iat-mode=1
|
||||||
|
Bridge obfs4 38.229.1.78:80 C8CBDB2464FC9804A69531437BCF2BE31FDD2EE4 cert=Hmyfd2ev46gGY7NoVxA9ngrPF2zCZtzskRTzoWXbxNkzeVnGFPWmrTtILRyqCTjHR+s9dg iat-mode=1
|
||||||
|
Bridge obfs4 38.229.33.83:80 0BAC39417268B96B9F514E7F63FA6FBA1A788955 cert=VwEFpk9F/UN9JED7XpG1XOjm/O8ZCXK80oPecgWnNDZDv5pdkhq1OpbAH0wNqOT6H6BmRQ iat-mode=1
|
||||||
|
Bridge obfs4 37.218.245.14:38224 D9A82D2F9C2F65A18407B1D2B764F130847F8B5D cert=bjRaMrr1BRiAW8IE9U5z27fQaYgOhX1UCmOpg2pFpoMvo6ZgQMzLsaTzzQNTlm7hNcb+Sg iat-mode=0
|
||||||
|
Bridge obfs4 85.31.186.26:443 91A6354697E6B02A386312F68D82CF86824D3606 cert=PBwr+S8JTVZo6MPdHnkTwXJPILWADLqfMGoVvhZClMq/Urndyd42BwX9YFJHZnBB3H0XCw iat-mode=0
|
||||||
|
Bridge obfs4 193.11.166.194:27015 2D82C2E354D531A68469ADF7F878FA6060C6BACA cert=4TLQPJrTSaDffMK7Nbao6LC7G9OW/NHkUwIdjLSS3KYf0Nv4/nQiiI8dY2TcsQx01NniOg iat-mode=0
|
||||||
|
Bridge obfs4 193.11.166.194:27020 86AC7B8D430DAC4117E9F42C9EAED18133863AAF cert=0LDeJH4JzMDtkJJrFphJCiPqKx7loozKN7VNfuukMGfHO0Z8OGdzHVkhVAOfo1mUdv9cMg iat-mode=0
|
||||||
|
Bridge obfs4 193.11.166.194:27025 1AE2C08904527FEA90C4C4F8C1083EA59FBC6FAF cert=ItvYZzW5tn6v3G4UnQa6Qz04Npro6e81AP70YujmK/KXwDFPTs3aHXcHp4n8Vt6w/bv8cA iat-mode=0
|
||||||
|
Bridge obfs4 209.148.46.65:443 74FAD13168806246602538555B5521A0383A1875 cert=ssH+9rP8dG2NLDN2XuFw63hIO/9MNNinLmxQDpVa+7kTOa9/m+tGWT1SmSYpQ9uTBGa6Hw iat-mode=0
|
||||||
|
Bridge obfs4 45.145.95.6:27015 C5B7CD6946FF10C5B3E89691A7D3F2C122D2117C cert=TD7PbUO0/0k6xYHMPW3vJxICfkMZNdkRrb63Zhl5j9dW3iRGiCx0A7mPhe5T2EDzQ35+Zw iat-mode=0
|
||||||
|
Bridge obfs4 51.222.13.177:80 5EDAC3B810E12B01F6FD8050D2FD3E277B289A08 cert=2uplIpLQ0q9+0qMFrK5pkaYRDOe460LL9WHBvatgkuRr/SL31wBOEupaMMJ6koRE6Ld0ew iat-mode=0
|
||||||
Bridge obfs4 78.46.188.239:37356 5A2D2F4158D0453E00C7C176978D3F41D69C45DB cert=3c0SwxpOisbohNxEc4tb875RVW8eOu1opRTVXJhafaKA/PNNtI7ElQIVOVZg1AdL5bxGCw iat-mode=0
|
Bridge obfs4 78.46.188.239:37356 5A2D2F4158D0453E00C7C176978D3F41D69C45DB cert=3c0SwxpOisbohNxEc4tb875RVW8eOu1opRTVXJhafaKA/PNNtI7ElQIVOVZg1AdL5bxGCw iat-mode=0
|
||||||
Bridge obfs4 52.15.78.72:9443 02069A3C5362476936B62BA6F5ACC41ABD573A9B cert=ijYG/OKc7kqu2YzKNFfeXN7/BG2BOgfEP2KyYEiGDQthnHbsOiTWHeIG0WJVW+BckzDgKw iat-mode=0
|
Bridge meek_lite 192.0.2.2:2 97700DFE9F483596DDA6264C4D7DF7641E1E39CE url=https://meek.azureedge.net/ front=ajax.aspnetcdn.com
|
||||||
Bridge obfs4 13.58.29.242:9443 0C58939A77DA6B6B29D4B5236A75865659607AE0 cert=OylWIEHb/ezpq1zWxW0sgKRn+9ARH2eOcQOZ8/Gew+4l+oKOhQ2jUX/Y+FSl61JorXZUWA iat-mode=0
|
|
||||||
Bridge obfs4 45.33.37.112:9443 60A609BB4ABE8D46E634AE81ED29ADAB7776B399 cert=t5v19WmNv5Sc2YPNr8RQids365W7MY8zJwQVkOxBjUMFomMWARDzsbYpcWLLcw0J9Gm+BQ iat-mode=0
|
|
||||||
Bridge meek_lite 0.0.2.0:2 97700DFE9F483596DDA6264C4D7DF7641E1E39CE url=https://meek.azureedge.net/ front=ajax.aspnetcdn.com
|
|
||||||
@@ -16,8 +16,8 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||||
implementation 'net.java.dev.jna:jna:4.5.2'
|
implementation 'net.java.dev.jna:jna:4.5.2'
|
||||||
implementation 'net.java.dev.jna:jna-platform:4.5.2'
|
implementation 'net.java.dev.jna:jna-platform:4.5.2'
|
||||||
tor 'org.briarproject:tor:0.3.5.12@zip'
|
tor 'org.briarproject:tor:0.3.5.13-1@zip'
|
||||||
tor 'org.briarproject:obfs4proxy:0.0.7@zip'
|
tor 'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a@zip'
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.OsUtils.isLinux;
|
import static org.briarproject.bramble.util.OsUtils.isLinux;
|
||||||
|
|
||||||
@@ -96,8 +97,15 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
|||||||
String architecture = null;
|
String architecture = null;
|
||||||
if (isLinux()) {
|
if (isLinux()) {
|
||||||
String arch = System.getProperty("os.arch");
|
String arch = System.getProperty("os.arch");
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("System's os.arch is " + arch);
|
||||||
|
}
|
||||||
if (arch.equals("amd64")) {
|
if (arch.equals("amd64")) {
|
||||||
architecture = "linux-x86_64";
|
architecture = "linux-x86_64";
|
||||||
|
} else if (arch.equals("aarch64")) {
|
||||||
|
architecture = "linux-aarch64";
|
||||||
|
} else if (arch.equals("arm")) {
|
||||||
|
architecture = "linux-armhf";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (architecture == null) {
|
if (architecture == null) {
|
||||||
@@ -105,6 +113,10 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("The selected architecture for Tor is " + architecture);
|
||||||
|
}
|
||||||
|
|
||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
return component.getCircumventionProvider().getBridges(false);
|
return component.getCircumventionProvider().getBridges(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long TIMEOUT = SECONDS.toMillis(30);
|
private final static long TIMEOUT = SECONDS.toMillis(60);
|
||||||
|
|
||||||
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ dependencyVerification {
|
|||||||
'org.apache.ant:ant-launcher:1.9.4:ant-launcher-1.9.4.jar:7bccea20b41801ca17bcbc909a78c835d0f443f12d639c77bd6ae3d05861608d',
|
'org.apache.ant:ant-launcher:1.9.4:ant-launcher-1.9.4.jar:7bccea20b41801ca17bcbc909a78c835d0f443f12d639c77bd6ae3d05861608d',
|
||||||
'org.apache.ant:ant:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
|
'org.apache.ant:ant:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
|
||||||
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
||||||
'org.briarproject:obfs4proxy:0.0.7:obfs4proxy-0.0.7.zip:5b2f693262ce43a7e130f7cc7d5d1617925330640a2eb6d71085e95df8ee0642',
|
'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a:obfs4proxy-0.0.12-dev-40245c4a.zip:172029e7058b3a83ac93ac4991a44bf76e16ce8d46f558f5836d57da3cb3a766',
|
||||||
'org.briarproject:tor:0.3.5.12:tor-0.3.5.12.zip:2f542c4befd216f2226bf7c76e3b8b2d99af6f146a8cb28bf727f42014587006',
|
'org.briarproject:tor:0.3.5.13-1:tor-0.3.5.13-1.zip:ef35c16bf8dc1f4c75ed71d9f55e4514f383d124ec96b859aca647c990927c99',
|
||||||
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
||||||
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
||||||
'org.codehaus.mojo:animal-sniffer-annotations:1.17:animal-sniffer-annotations-1.17.jar:92654f493ecfec52082e76354f0ebf87648dc3d5cec2e3c3cdb947c016747a53',
|
'org.codehaus.mojo:animal-sniffer-annotations:1.17:animal-sniffer-annotations-1.17.jar:92654f493ecfec52082e76354f0ebf87648dc3d5cec2e3c3cdb947c016747a53',
|
||||||
|
|||||||
1
briar-android/artwork/notification_signout.svg
Normal file
1
briar-android/artwork/notification_signout.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M16,17V14H9V10H16V7L21,12L16,17M14,2A2,2 0 0,1 16,4V6H14V4H5V20H14V18H16V20A2,2 0 0,1 14,22H5A2,2 0 0,1 3,20V4A2,2 0 0,1 5,2H14Z" /></svg>
|
||||||
|
After Width: | Height: | Size: 423 B |
@@ -19,12 +19,18 @@ android {
|
|||||||
compileSdkVersion 30
|
compileSdkVersion 30
|
||||||
buildToolsVersion '30.0.2'
|
buildToolsVersion '30.0.2'
|
||||||
|
|
||||||
|
packagingOptions {
|
||||||
|
doNotStrip '**/*.so'
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10213
|
versionCode 10220
|
||||||
versionName "1.2.13"
|
versionName "1.2.20"
|
||||||
applicationId "org.briarproject.briar.android"
|
applicationId "org.briarproject.briar.android"
|
||||||
|
|
||||||
|
vectorDrawables.useSupportLibrary = true
|
||||||
buildConfigField "String", "GitHash",
|
buildConfigField "String", "GitHash",
|
||||||
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
||||||
def now = (long) (System.currentTimeMillis() / 1000)
|
def now = (long) (System.currentTimeMillis() / 1000)
|
||||||
@@ -93,6 +99,7 @@ dependencies {
|
|||||||
implementation project(path: ':bramble-core', configuration: 'default')
|
implementation project(path: ':bramble-core', configuration: 'default')
|
||||||
implementation project(':bramble-android')
|
implementation project(':bramble-android')
|
||||||
|
|
||||||
|
implementation 'androidx.fragment:fragment:1.3.0'
|
||||||
implementation 'androidx.preference:preference:1.1.1'
|
implementation 'androidx.preference:preference:1.1.1'
|
||||||
implementation 'androidx.exifinterface:exifinterface:1.3.1'
|
implementation 'androidx.exifinterface:exifinterface:1.3.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||||
@@ -134,6 +141,7 @@ dependencies {
|
|||||||
testImplementation "org.jmock:jmock:$jmockVersion"
|
testImplementation "org.jmock:jmock:$jmockVersion"
|
||||||
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
|
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
|
||||||
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
|
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
|
||||||
|
testAnnotationProcessor "com.google.dagger:dagger-compiler:2.24"
|
||||||
|
|
||||||
androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
|
androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||||
|
|||||||
@@ -4,16 +4,20 @@ import android.app.Activity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.account.AccountManager;
|
import org.briarproject.bramble.api.account.AccountManager;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||||
|
|
||||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||||
|
import static org.briarproject.briar.android.controller.BriarControllerImpl.DOZE_ASK_AGAIN;
|
||||||
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
@@ -27,6 +31,8 @@ public abstract class UiTest {
|
|||||||
protected AccountManager accountManager;
|
protected AccountManager accountManager;
|
||||||
@Inject
|
@Inject
|
||||||
protected LifecycleManager lifecycleManager;
|
protected LifecycleManager lifecycleManager;
|
||||||
|
@Inject
|
||||||
|
protected SettingsManager settingsManager;
|
||||||
|
|
||||||
public UiTest() {
|
public UiTest() {
|
||||||
BriarTestComponentApplication app = getApplicationContext();
|
BriarTestComponentApplication app = getApplicationContext();
|
||||||
@@ -39,22 +45,8 @@ public abstract class UiTest {
|
|||||||
protected class CleanAccountTestRule<A extends Activity>
|
protected class CleanAccountTestRule<A extends Activity>
|
||||||
extends IntentsTestRule<A> {
|
extends IntentsTestRule<A> {
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final Runnable runnable;
|
|
||||||
|
|
||||||
public CleanAccountTestRule(Class<A> activityClass) {
|
public CleanAccountTestRule(Class<A> activityClass) {
|
||||||
super(activityClass);
|
super(activityClass);
|
||||||
this.runnable = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this if you need to run code before launching the activity.
|
|
||||||
* Note: You need to use {@link #launchActivity(Intent)} yourself
|
|
||||||
* to start the activity.
|
|
||||||
*/
|
|
||||||
public CleanAccountTestRule(Class<A> activityClass, Runnable runnable) {
|
|
||||||
super(activityClass, false, false);
|
|
||||||
this.runnable = runnable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,16 +54,17 @@ public abstract class UiTest {
|
|||||||
super.beforeActivityLaunched();
|
super.beforeActivityLaunched();
|
||||||
accountManager.deleteAccount();
|
accountManager.deleteAccount();
|
||||||
accountManager.createAccount(USERNAME, PASSWORD);
|
accountManager.createAccount(USERNAME, PASSWORD);
|
||||||
if (runnable != null) {
|
Intent serviceIntent =
|
||||||
Intent serviceIntent =
|
new Intent(getApplicationContext(), BriarService.class);
|
||||||
new Intent(getApplicationContext(), BriarService.class);
|
getApplicationContext().startService(serviceIntent);
|
||||||
getApplicationContext().startService(serviceIntent);
|
try {
|
||||||
try {
|
lifecycleManager.waitForStartup();
|
||||||
lifecycleManager.waitForStartup();
|
// do not show doze white-listing dialog
|
||||||
} catch (InterruptedException e) {
|
Settings settings = new Settings();
|
||||||
throw new AssertionError(e);
|
settings.putBoolean(DOZE_ASK_AGAIN, false);
|
||||||
}
|
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||||
runnable.run();
|
} catch (InterruptedException | DbException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,15 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import androidx.test.filters.LargeTest;
|
||||||
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||||
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class PngSuiteImageCompressorTest
|
public class PngSuiteImageCompressorTest
|
||||||
extends AbstractImageCompressorTest {
|
extends AbstractImageCompressorTest {
|
||||||
|
|||||||
@@ -12,11 +12,14 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import androidx.test.filters.LargeTest;
|
||||||
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||||
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class PngSuiteImageSizeCalculatorTest
|
public class PngSuiteImageSizeCalculatorTest
|
||||||
extends AbstractImageSizeCalculatorTest {
|
extends AbstractImageSizeCalculatorTest {
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package org.briarproject.briar.android.conversation;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
import androidx.test.rule.ActivityTestRule;
|
|
||||||
|
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
|
||||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
|
||||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class ConversationActivityNotSignedInTest {
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ActivityTestRule<ConversationActivity> testRule =
|
|
||||||
new ActivityTestRule<>(ConversationActivity.class, false, false);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void openWithoutSignedIn() {
|
|
||||||
Context targetContext = getInstrumentation().getTargetContext();
|
|
||||||
Intent intent = new Intent(targetContext, ConversationActivity.class);
|
|
||||||
intent.putExtra(CONTACT_ID, 1);
|
|
||||||
testRule.launchActivity(intent);
|
|
||||||
|
|
||||||
onView(withText(R.string.sign_in_button))
|
|
||||||
.perform(waitUntilMatches(isDisplayed()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,7 @@ import androidx.test.espresso.contrib.DrawerActions;
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.rule.ActivityTestRule;
|
import androidx.test.rule.ActivityTestRule;
|
||||||
|
|
||||||
|
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
import static androidx.test.espresso.Espresso.onView;
|
||||||
import static androidx.test.espresso.action.ViewActions.click;
|
import static androidx.test.espresso.action.ViewActions.click;
|
||||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||||
@@ -29,7 +30,9 @@ import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
|
|||||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
||||||
|
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
||||||
@@ -76,6 +79,8 @@ public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void appLock() {
|
public void appLock() {
|
||||||
|
assumeTrue("device has no screen lock",
|
||||||
|
hasScreenLock(getApplicationContext()));
|
||||||
// scroll down
|
// scroll down
|
||||||
onView(withClassName(is(RecyclerView.class.getName())))
|
onView(withClassName(is(RecyclerView.class.getName())))
|
||||||
.perform(scrollTo(hasDescendant(
|
.perform(scrollTo(hasDescendant(
|
||||||
|
|||||||
@@ -27,7 +27,10 @@
|
|||||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission
|
||||||
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
|
android:maxSdkVersion="18"
|
||||||
|
tools:ignore="ScopedStorage" />
|
||||||
|
|
||||||
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
@@ -38,6 +41,7 @@
|
|||||||
android:name="org.briarproject.briar.android.BriarApplicationImpl"
|
android:name="org.briarproject.briar.android.BriarApplicationImpl"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:banner="@mipmap/tv_banner"
|
android:banner="@mipmap/tv_banner"
|
||||||
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
android:icon="@mipmap/ic_launcher_round"
|
android:icon="@mipmap/ic_launcher_round"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:logo="@mipmap/ic_launcher_round"
|
android:logo="@mipmap/ic_launcher_round"
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import org.briarproject.briar.BriarCoreModule;
|
|||||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||||
import org.briarproject.briar.android.conversation.glide.BriarModelLoader;
|
import org.briarproject.briar.android.conversation.glide.BriarModelLoader;
|
||||||
|
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||||
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
||||||
import org.briarproject.briar.android.view.EmojiTextInputView;
|
import org.briarproject.briar.android.view.EmojiTextInputView;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
@@ -179,6 +180,10 @@ public interface AndroidComponent
|
|||||||
|
|
||||||
AndroidWakeLockManager wakeLockManager();
|
AndroidWakeLockManager wakeLockManager();
|
||||||
|
|
||||||
|
CachingLogHandler logHandler();
|
||||||
|
|
||||||
|
Thread.UncaughtExceptionHandler exceptionHandler();
|
||||||
|
|
||||||
void inject(SignInReminderReceiver briarService);
|
void inject(SignInReminderReceiver briarService);
|
||||||
|
|
||||||
void inject(BriarService briarService);
|
void inject(BriarService briarService);
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
R.string.ongoing_notification_title;
|
R.string.ongoing_notification_title;
|
||||||
int text = locked ? R.string.lock_tap_to_unlock :
|
int text = locked ? R.string.lock_tap_to_unlock :
|
||||||
R.string.ongoing_notification_text;
|
R.string.ongoing_notification_text;
|
||||||
int icon = locked ? R.drawable.startup_lock :
|
int icon = locked ? R.drawable.notification_lock :
|
||||||
R.drawable.notification_ongoing;
|
R.drawable.notification_ongoing;
|
||||||
// Ongoing foreground notification that shows BriarService is running
|
// Ongoing foreground notification that shows BriarService is running
|
||||||
NotificationCompat.Builder b =
|
NotificationCompat.Builder b =
|
||||||
@@ -624,7 +624,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
|
|
||||||
NotificationCompat.Builder b =
|
NotificationCompat.Builder b =
|
||||||
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
|
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
|
||||||
b.setSmallIcon(R.drawable.ic_signout);
|
b.setSmallIcon(R.drawable.notification_signout);
|
||||||
b.setColor(getColor(appContext, R.color.briar_primary));
|
b.setColor(getColor(appContext, R.color.briar_primary));
|
||||||
b.setContentTitle(
|
b.setContentTitle(
|
||||||
appContext.getText(R.string.reminder_notification_title));
|
appContext.getText(R.string.reminder_notification_title));
|
||||||
|
|||||||
@@ -30,15 +30,18 @@ import org.briarproject.bramble.util.StringUtils;
|
|||||||
import org.briarproject.briar.android.account.DozeHelperModule;
|
import org.briarproject.briar.android.account.DozeHelperModule;
|
||||||
import org.briarproject.briar.android.account.LockManagerImpl;
|
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||||
import org.briarproject.briar.android.account.SetupModule;
|
import org.briarproject.briar.android.account.SetupModule;
|
||||||
|
import org.briarproject.briar.android.blog.BlogModule;
|
||||||
import org.briarproject.briar.android.contact.ContactListModule;
|
import org.briarproject.briar.android.contact.ContactListModule;
|
||||||
import org.briarproject.briar.android.forum.ForumModule;
|
import org.briarproject.briar.android.forum.ForumModule;
|
||||||
|
import org.briarproject.briar.android.introduction.IntroductionModule;
|
||||||
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
||||||
|
import org.briarproject.briar.android.logging.LoggingModule;
|
||||||
import org.briarproject.briar.android.login.LoginModule;
|
import org.briarproject.briar.android.login.LoginModule;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
||||||
import org.briarproject.briar.android.settings.SettingsModule;
|
|
||||||
import org.briarproject.briar.android.privategroup.list.GroupListModule;
|
import org.briarproject.briar.android.privategroup.list.GroupListModule;
|
||||||
import org.briarproject.briar.android.reporting.DevReportModule;
|
import org.briarproject.briar.android.reporting.DevReportModule;
|
||||||
|
import org.briarproject.briar.android.settings.SettingsModule;
|
||||||
import org.briarproject.briar.android.sharing.SharingModule;
|
import org.briarproject.briar.android.sharing.SharingModule;
|
||||||
import org.briarproject.briar.android.test.TestAvatarCreatorImpl;
|
import org.briarproject.briar.android.test.TestAvatarCreatorImpl;
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
||||||
@@ -74,13 +77,16 @@ import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
|||||||
SetupModule.class,
|
SetupModule.class,
|
||||||
DozeHelperModule.class,
|
DozeHelperModule.class,
|
||||||
ContactExchangeModule.class,
|
ContactExchangeModule.class,
|
||||||
|
LoggingModule.class,
|
||||||
LoginModule.class,
|
LoginModule.class,
|
||||||
NavDrawerModule.class,
|
NavDrawerModule.class,
|
||||||
ViewModelModule.class,
|
ViewModelModule.class,
|
||||||
SettingsModule.class,
|
SettingsModule.class,
|
||||||
DevReportModule.class,
|
DevReportModule.class,
|
||||||
ContactListModule.class,
|
ContactListModule.class,
|
||||||
|
IntroductionModule.class,
|
||||||
// below need to be within same scope as ViewModelProvider.Factory
|
// below need to be within same scope as ViewModelProvider.Factory
|
||||||
|
BlogModule.class,
|
||||||
ForumModule.class,
|
ForumModule.class,
|
||||||
GroupListModule.class,
|
GroupListModule.class,
|
||||||
GroupConversationModule.class,
|
GroupConversationModule.class,
|
||||||
@@ -192,6 +198,11 @@ public class AppModule {
|
|||||||
public File getReportDir() {
|
public File getReportDir() {
|
||||||
return AndroidUtils.getReportDir(app.getApplicationContext());
|
return AndroidUtils.getReportDir(app.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getLogcatFile() {
|
||||||
|
return AndroidUtils.getLogcatFile(app.getApplicationContext());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return devConfig;
|
return devConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ import android.content.SharedPreferences;
|
|||||||
import org.briarproject.bramble.BrambleApplication;
|
import org.briarproject.bramble.BrambleApplication;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This exists so that the Application object will not necessarily be cast
|
* This exists so that the Application object will not necessarily be cast
|
||||||
* directly to the Briar application object.
|
* directly to the Briar application object.
|
||||||
@@ -17,8 +14,6 @@ public interface BriarApplication extends BrambleApplication {
|
|||||||
|
|
||||||
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
|
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
|
||||||
|
|
||||||
Collection<LogRecord> getRecentLogRecords();
|
|
||||||
|
|
||||||
AndroidComponent getApplicationComponent();
|
AndroidComponent getApplicationComponent();
|
||||||
|
|
||||||
SharedPreferences getDefaultSharedPreferences();
|
SharedPreferences getDefaultSharedPreferences();
|
||||||
|
|||||||
@@ -20,12 +20,10 @@ import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
|||||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.logging.CachingLogHandler;
|
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||||
import org.briarproject.briar.android.reporting.BriarExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -42,22 +40,18 @@ public class BriarApplicationImpl extends Application
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(BriarApplicationImpl.class.getName());
|
getLogger(BriarApplicationImpl.class.getName());
|
||||||
|
|
||||||
private final CachingLogHandler logHandler = new CachingLogHandler();
|
|
||||||
private final BriarExceptionHandler exceptionHandler =
|
|
||||||
new BriarExceptionHandler(this);
|
|
||||||
|
|
||||||
private AndroidComponent applicationComponent;
|
private AndroidComponent applicationComponent;
|
||||||
private volatile SharedPreferences prefs;
|
private volatile SharedPreferences prefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
|
||||||
if (prefs == null)
|
if (prefs == null)
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(base);
|
prefs = PreferenceManager.getDefaultSharedPreferences(base);
|
||||||
// Loading the language needs to be done here.
|
// Loading the language needs to be done here.
|
||||||
Localizer.initialize(prefs);
|
Localizer.initialize(prefs);
|
||||||
super.attachBaseContext(
|
super.attachBaseContext(
|
||||||
Localizer.getInstance().setLocale(base));
|
Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
setTheme(base, prefs);
|
setTheme(base, prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +61,11 @@ public class BriarApplicationImpl extends Application
|
|||||||
|
|
||||||
if (IS_DEBUG_BUILD) enableStrictMode();
|
if (IS_DEBUG_BUILD) enableStrictMode();
|
||||||
|
|
||||||
|
applicationComponent = createApplicationComponent();
|
||||||
|
UncaughtExceptionHandler exceptionHandler =
|
||||||
|
applicationComponent.exceptionHandler();
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
||||||
|
|
||||||
Logger rootLogger = getLogger("");
|
Logger rootLogger = getLogger("");
|
||||||
Handler[] handlers = rootLogger.getHandlers();
|
Handler[] handlers = rootLogger.getHandlers();
|
||||||
// Disable the Android logger for release builds
|
// Disable the Android logger for release builds
|
||||||
@@ -78,12 +77,12 @@ public class BriarApplicationImpl extends Application
|
|||||||
// Restore the default handlers after the level raising handler
|
// Restore the default handlers after the level raising handler
|
||||||
for (Handler handler : handlers) rootLogger.addHandler(handler);
|
for (Handler handler : handlers) rootLogger.addHandler(handler);
|
||||||
}
|
}
|
||||||
|
CachingLogHandler logHandler = applicationComponent.logHandler();
|
||||||
rootLogger.addHandler(logHandler);
|
rootLogger.addHandler(logHandler);
|
||||||
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
||||||
|
|
||||||
LOG.info("Created");
|
LOG.info("Created");
|
||||||
|
|
||||||
applicationComponent = createApplicationComponent();
|
|
||||||
EmojiManager.install(new GoogleEmojiProvider());
|
EmojiManager.install(new GoogleEmojiProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +135,6 @@ public class BriarApplicationImpl extends Application
|
|||||||
return applicationComponent;
|
return applicationComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<LogRecord> getRecentLogRecords() {
|
|
||||||
return logHandler.getRecentLogRecords();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AndroidComponent getApplicationComponent() {
|
public AndroidComponent getApplicationComponent() {
|
||||||
return applicationComponent;
|
return applicationComponent;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import javax.inject.Inject;
|
|||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||||
import static android.content.Intent.ACTION_SHUTDOWN;
|
import static android.content.Intent.ACTION_SHUTDOWN;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||||
@@ -46,6 +46,7 @@ import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
|
|||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static android.os.Process.myPid;
|
||||||
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -56,8 +57,10 @@ import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
|||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
||||||
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_OLD_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID;
|
||||||
import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK;
|
import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK;
|
||||||
|
import static org.briarproject.briar.api.android.LockManager.EXTRA_PID;
|
||||||
|
|
||||||
public class BriarService extends Service {
|
public class BriarService extends Service {
|
||||||
|
|
||||||
@@ -120,11 +123,17 @@ public class BriarService extends Service {
|
|||||||
if (SDK_INT >= 26) {
|
if (SDK_INT >= 26) {
|
||||||
NotificationManager nm = (NotificationManager)
|
NotificationManager nm = (NotificationManager)
|
||||||
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
|
// Delete the old notification channel, which had
|
||||||
|
// IMPORTANCE_NONE and showed a badge
|
||||||
|
nm.deleteNotificationChannel(ONGOING_CHANNEL_OLD_ID);
|
||||||
|
// Use IMPORTANCE_LOW so the system doesn't show its own
|
||||||
|
// notification on API 26-27
|
||||||
NotificationChannel ongoingChannel = new NotificationChannel(
|
NotificationChannel ongoingChannel = new NotificationChannel(
|
||||||
ONGOING_CHANNEL_ID,
|
ONGOING_CHANNEL_ID,
|
||||||
getString(R.string.ongoing_notification_title),
|
getString(R.string.ongoing_notification_title),
|
||||||
IMPORTANCE_NONE);
|
IMPORTANCE_LOW);
|
||||||
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||||
|
ongoingChannel.setShowBadge(false);
|
||||||
nm.createNotificationChannel(ongoingChannel);
|
nm.createNotificationChannel(ongoingChannel);
|
||||||
NotificationChannel failureChannel = new NotificationChannel(
|
NotificationChannel failureChannel = new NotificationChannel(
|
||||||
FAILURE_CHANNEL_ID,
|
FAILURE_CHANNEL_ID,
|
||||||
@@ -170,6 +179,7 @@ public class BriarService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showStartupFailureNotification(StartResult result) {
|
private void showStartupFailureNotification(StartResult result) {
|
||||||
@@ -202,7 +212,12 @@ public class BriarService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (ACTION_LOCK.equals(intent.getAction())) {
|
if (ACTION_LOCK.equals(intent.getAction())) {
|
||||||
lockManager.setLocked(true);
|
int pid = intent.getIntExtra(EXTRA_PID, -1);
|
||||||
|
if (pid == myPid()) lockManager.setLocked(true);
|
||||||
|
else if (LOG.isLoggable(WARNING)) {
|
||||||
|
LOG.warning("Tried to lock process " + pid + " but this is " +
|
||||||
|
myPid());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return START_NOT_STICKY; // Don't restart automatically if killed
|
return START_NOT_STICKY; // Don't restart automatically if killed
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,21 @@ public class Localizer {
|
|||||||
return new Locale(tag);
|
return new Locale(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the localized version of context
|
/*
|
||||||
|
* Apply localization to the specified context.
|
||||||
|
*
|
||||||
|
* It updates the configuration of the context's resources object but can
|
||||||
|
* also return a new context derived from the context parameter. Hence
|
||||||
|
* make sure to work with the return value of this method instead of
|
||||||
|
* the context you passed as a parameter.
|
||||||
|
*
|
||||||
|
* This method also has side-effects as it calls Locale#setDefault().
|
||||||
|
*
|
||||||
|
* When using this in attachBaseContext() of Application, Service or
|
||||||
|
* Activity subclasses, it is important to not only apply this method to the
|
||||||
|
* base Context parameter received in that method, but also apply it on the
|
||||||
|
* class itself which also extends Context.
|
||||||
|
*/
|
||||||
public Context setLocale(Context context) {
|
public Context setLocale(Context context) {
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
Configuration conf = res.getConfiguration();
|
Configuration conf = res.getConfiguration();
|
||||||
@@ -82,7 +96,7 @@ public class Localizer {
|
|||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
if (SDK_INT >= 17) {
|
if (SDK_INT >= 17) {
|
||||||
conf.setLocale(locale);
|
conf.setLocale(locale);
|
||||||
context.createConfigurationContext(conf);
|
context = context.createConfigurationContext(conf);
|
||||||
} else
|
} else
|
||||||
conf.locale = locale;
|
conf.locale = locale;
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public class DozeFragment extends SetupFragment
|
|||||||
private DozeView dozeView;
|
private DozeView dozeView;
|
||||||
private HuaweiView huaweiView;
|
private HuaweiView huaweiView;
|
||||||
private Button next;
|
private Button next;
|
||||||
private ProgressBar progressBar;
|
|
||||||
private boolean secondAttempt = false;
|
private boolean secondAttempt = false;
|
||||||
|
|
||||||
public static DozeFragment newInstance() {
|
public static DozeFragment newInstance() {
|
||||||
@@ -58,11 +57,19 @@ public class DozeFragment extends SetupFragment
|
|||||||
huaweiView = v.findViewById(R.id.huaweiView);
|
huaweiView = v.findViewById(R.id.huaweiView);
|
||||||
huaweiView.setOnCheckedChangedListener(this);
|
huaweiView.setOnCheckedChangedListener(this);
|
||||||
next = v.findViewById(R.id.next);
|
next = v.findViewById(R.id.next);
|
||||||
progressBar = v.findViewById(R.id.progress);
|
ProgressBar progressBar = v.findViewById(R.id.progress);
|
||||||
|
|
||||||
dozeView.setOnButtonClickListener(this::askForDozeWhitelisting);
|
dozeView.setOnButtonClickListener(this::askForDozeWhitelisting);
|
||||||
next.setOnClickListener(this);
|
next.setOnClickListener(this);
|
||||||
|
|
||||||
|
viewModel.getIsCreatingAccount()
|
||||||
|
.observe(getViewLifecycleOwner(), isCreatingAccount -> {
|
||||||
|
if (isCreatingAccount) {
|
||||||
|
next.setVisibility(INVISIBLE);
|
||||||
|
progressBar.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,15 +111,6 @@ public class DozeFragment extends SetupFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
setNextClicked();
|
|
||||||
viewModel.dozeExceptionConfirmed();
|
viewModel.dozeExceptionConfirmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
void setNextClicked() {
|
|
||||||
super.setNextClicked();
|
|
||||||
|
|
||||||
next.setVisibility(INVISIBLE);
|
|
||||||
progressBar.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ import androidx.lifecycle.LiveData;
|
|||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
||||||
|
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||||
import static android.app.PendingIntent.getService;
|
import static android.app.PendingIntent.getService;
|
||||||
import static android.content.Context.ALARM_SERVICE;
|
import static android.content.Context.ALARM_SERVICE;
|
||||||
|
import static android.os.Process.myPid;
|
||||||
import static android.os.SystemClock.elapsedRealtime;
|
import static android.os.SystemClock.elapsedRealtime;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -75,23 +77,25 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
LockManagerImpl(Application app, SettingsManager settingsManager,
|
LockManagerImpl(Application app, SettingsManager settingsManager,
|
||||||
AndroidNotificationManager notificationManager,
|
AndroidNotificationManager notificationManager,
|
||||||
@DatabaseExecutor Executor dbExecutor) {
|
@DatabaseExecutor Executor dbExecutor) {
|
||||||
this.appContext = app.getApplicationContext();
|
appContext = app.getApplicationContext();
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
this.notificationManager = notificationManager;
|
this.notificationManager = notificationManager;
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
this.alarmManager =
|
alarmManager =
|
||||||
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
||||||
Intent i =
|
Intent i =
|
||||||
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
||||||
this.lockIntent = getService(appContext, 0, i, 0);
|
i.putExtra(EXTRA_PID, myPid());
|
||||||
this.timeoutNever = Integer.valueOf(
|
// When not using FLAG_UPDATE_CURRENT, the intent might have no extras
|
||||||
|
lockIntent = getService(appContext, 0, i, FLAG_UPDATE_CURRENT);
|
||||||
|
timeoutNever = Integer.parseInt(
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_never));
|
appContext.getString(R.string.pref_lock_timeout_value_never));
|
||||||
this.timeoutDefault = Integer.valueOf(
|
timeoutDefault = Integer.parseInt(
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_default));
|
appContext.getString(R.string.pref_lock_timeout_value_default));
|
||||||
this.timeoutMinutes = timeoutNever;
|
timeoutMinutes = timeoutNever;
|
||||||
|
|
||||||
// setting this in the constructor makes #getValue() @NonNull
|
// setting this in the constructor makes #getValue() @NonNull
|
||||||
this.lockable.setValue(false);
|
lockable.setValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -148,7 +152,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
boolean oldValue = lockable.getValue();
|
boolean oldValue = lockable.getValue();
|
||||||
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
||||||
if (oldValue != newValue) {
|
if (oldValue != newValue) {
|
||||||
this.lockable.setValue(newValue);
|
lockable.setValue(newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ public class SetPasswordFragment extends SetupFragment {
|
|||||||
private TextInputEditText passwordConfirmation;
|
private TextInputEditText passwordConfirmation;
|
||||||
private StrengthMeter strengthMeter;
|
private StrengthMeter strengthMeter;
|
||||||
private Button nextButton;
|
private Button nextButton;
|
||||||
private ProgressBar progressBar;
|
|
||||||
|
|
||||||
public static SetPasswordFragment newInstance() {
|
public static SetPasswordFragment newInstance() {
|
||||||
return new SetPasswordFragment();
|
return new SetPasswordFragment();
|
||||||
@@ -64,7 +63,7 @@ public class SetPasswordFragment extends SetupFragment {
|
|||||||
v.findViewById(R.id.password_confirm_wrapper);
|
v.findViewById(R.id.password_confirm_wrapper);
|
||||||
passwordConfirmation = v.findViewById(R.id.password_confirm);
|
passwordConfirmation = v.findViewById(R.id.password_confirm);
|
||||||
nextButton = v.findViewById(R.id.next);
|
nextButton = v.findViewById(R.id.next);
|
||||||
progressBar = v.findViewById(R.id.progress);
|
ProgressBar progressBar = v.findViewById(R.id.progress);
|
||||||
|
|
||||||
passwordEntry.addTextChangedListener(this);
|
passwordEntry.addTextChangedListener(this);
|
||||||
passwordConfirmation.addTextChangedListener(this);
|
passwordConfirmation.addTextChangedListener(this);
|
||||||
@@ -75,6 +74,17 @@ public class SetPasswordFragment extends SetupFragment {
|
|||||||
passwordConfirmation.setImeOptions(IME_ACTION_DONE);
|
passwordConfirmation.setImeOptions(IME_ACTION_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.getIsCreatingAccount()
|
||||||
|
.observe(getViewLifecycleOwner(), isCreatingAccount -> {
|
||||||
|
if (isCreatingAccount) {
|
||||||
|
nextButton.setVisibility(INVISIBLE);
|
||||||
|
progressBar.setVisibility(VISIBLE);
|
||||||
|
// this also avoids the keyboard popping up
|
||||||
|
passwordEntry.setFocusable(false);
|
||||||
|
passwordConfirmation.setFocusable(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,20 +126,6 @@ public class SetPasswordFragment extends SetupFragment {
|
|||||||
IBinder token = passwordEntry.getWindowToken();
|
IBinder token = passwordEntry.getWindowToken();
|
||||||
Object o = getContext().getSystemService(INPUT_METHOD_SERVICE);
|
Object o = getContext().getSystemService(INPUT_METHOD_SERVICE);
|
||||||
((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
|
((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
|
||||||
|
|
||||||
setNextClicked();
|
|
||||||
viewModel.setPassword(passwordEntry.getText().toString());
|
viewModel.setPassword(passwordEntry.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
void setNextClicked() {
|
|
||||||
super.setNextClicked();
|
|
||||||
|
|
||||||
passwordEntry.setFocusable(false);
|
|
||||||
passwordConfirmation.setFocusable(false);
|
|
||||||
if (!viewModel.needToShowDozeFragment()) {
|
|
||||||
nextButton.setVisibility(INVISIBLE);
|
|
||||||
progressBar.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.view.KeyEvent;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.TextView.OnEditorActionListener;
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
@@ -19,8 +18,6 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
@@ -35,7 +32,6 @@ abstract class SetupFragment extends BaseFragment implements TextWatcher,
|
|||||||
OnEditorActionListener, OnClickListener {
|
OnEditorActionListener, OnClickListener {
|
||||||
|
|
||||||
private final static String STATE_KEY_CLICKED = "setupFragmentClicked";
|
private final static String STATE_KEY_CLICKED = "setupFragmentClicked";
|
||||||
private boolean clicked = false;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
@@ -48,27 +44,6 @@ abstract class SetupFragment extends BaseFragment implements TextWatcher,
|
|||||||
.get(SetupViewModel.class);
|
.get(SetupViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
clicked = savedInstanceState.getBoolean(STATE_KEY_CLICKED);
|
|
||||||
}
|
|
||||||
if (clicked) {
|
|
||||||
setNextClicked();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putBoolean(STATE_KEY_CLICKED, clicked);
|
|
||||||
}
|
|
||||||
|
|
||||||
@CallSuper
|
|
||||||
void setNextClicked() {
|
|
||||||
this.clicked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.help_action, menu);
|
inflater.inflate(R.menu.help_action, menu);
|
||||||
@@ -114,5 +89,4 @@ abstract class SetupFragment extends BaseFragment implements TextWatcher,
|
|||||||
public void afterTextChanged(Editable editable) {
|
public void afterTextChanged(Editable editable) {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.briar.android.account.SetupViewModel.State.AUTHOR_NAME;
|
import static org.briarproject.briar.android.account.SetupViewModel.State.AUTHOR_NAME;
|
||||||
@@ -36,6 +38,8 @@ class SetupViewModel extends AndroidViewModel {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private String authorName, password;
|
private String authorName, password;
|
||||||
private final MutableLiveEvent<State> state = new MutableLiveEvent<>();
|
private final MutableLiveEvent<State> state = new MutableLiveEvent<>();
|
||||||
|
private final MutableLiveData<Boolean> isCreatingAccount =
|
||||||
|
new MutableLiveData<>(false);
|
||||||
|
|
||||||
private final AccountManager accountManager;
|
private final AccountManager accountManager;
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
@@ -67,6 +71,10 @@ class SetupViewModel extends AndroidViewModel {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveData<Boolean> getIsCreatingAccount() {
|
||||||
|
return isCreatingAccount;
|
||||||
|
}
|
||||||
|
|
||||||
void setAuthorName(String authorName) {
|
void setAuthorName(String authorName) {
|
||||||
this.authorName = authorName;
|
this.authorName = authorName;
|
||||||
state.setEvent(SET_PASSWORD);
|
state.setEvent(SET_PASSWORD);
|
||||||
@@ -97,6 +105,7 @@ class SetupViewModel extends AndroidViewModel {
|
|||||||
private void createAccount() {
|
private void createAccount() {
|
||||||
if (authorName == null) throw new IllegalStateException();
|
if (authorName == null) throw new IllegalStateException();
|
||||||
if (password == null) throw new IllegalStateException();
|
if (password == null) throw new IllegalStateException();
|
||||||
|
isCreatingAccount.setValue(true);
|
||||||
ioExecutor.execute(() -> {
|
ioExecutor.execute(() -> {
|
||||||
if (accountManager.createAccount(authorName, password)) {
|
if (accountManager.createAccount(authorName, password)) {
|
||||||
LOG.info("Created account");
|
LOG.info("Created account");
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class UnlockActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode,
|
protected void onActivityResult(int requestCode, int resultCode,
|
||||||
Intent data) {
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == REQUEST_KEYGUARD_UNLOCK) {
|
if (requestCode == REQUEST_KEYGUARD_UNLOCK) {
|
||||||
if (resultCode == RESULT_OK) unlock();
|
if (resultCode == RESULT_OK) unlock();
|
||||||
|
|||||||
@@ -11,10 +11,8 @@ import org.briarproject.briar.android.account.SetupActivity;
|
|||||||
import org.briarproject.briar.android.account.UnlockActivity;
|
import org.briarproject.briar.android.account.UnlockActivity;
|
||||||
import org.briarproject.briar.android.blog.BlogActivity;
|
import org.briarproject.briar.android.blog.BlogActivity;
|
||||||
import org.briarproject.briar.android.blog.BlogFragment;
|
import org.briarproject.briar.android.blog.BlogFragment;
|
||||||
import org.briarproject.briar.android.blog.BlogModule;
|
|
||||||
import org.briarproject.briar.android.blog.BlogPostFragment;
|
import org.briarproject.briar.android.blog.BlogPostFragment;
|
||||||
import org.briarproject.briar.android.blog.FeedFragment;
|
import org.briarproject.briar.android.blog.FeedFragment;
|
||||||
import org.briarproject.briar.android.blog.FeedPostFragment;
|
|
||||||
import org.briarproject.briar.android.blog.ReblogActivity;
|
import org.briarproject.briar.android.blog.ReblogActivity;
|
||||||
import org.briarproject.briar.android.blog.ReblogFragment;
|
import org.briarproject.briar.android.blog.ReblogFragment;
|
||||||
import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
||||||
@@ -85,7 +83,6 @@ import dagger.Component;
|
|||||||
@ActivityScope
|
@ActivityScope
|
||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
ActivityModule.class,
|
ActivityModule.class,
|
||||||
BlogModule.class,
|
|
||||||
CreateGroupModule.class,
|
CreateGroupModule.class,
|
||||||
GroupInvitationModule.class,
|
GroupInvitationModule.class,
|
||||||
GroupMemberModule.class,
|
GroupMemberModule.class,
|
||||||
@@ -152,8 +149,6 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(BlogPostFragment fragment);
|
void inject(BlogPostFragment fragment);
|
||||||
|
|
||||||
void inject(FeedPostFragment fragment);
|
|
||||||
|
|
||||||
void inject(ReblogFragment fragment);
|
void inject(ReblogFragment fragment);
|
||||||
|
|
||||||
void inject(ReblogActivity activity);
|
void inject(ReblogActivity activity);
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
super.attachBaseContext(
|
super.attachBaseContext(
|
||||||
Localizer.getInstance().setLocale(base));
|
Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActivityComponent getActivityComponent() {
|
public ActivityComponent getActivityComponent() {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ public interface RequestCodes {
|
|||||||
int REQUEST_INTRODUCTION = 2;
|
int REQUEST_INTRODUCTION = 2;
|
||||||
int REQUEST_GROUP_INVITE = 3;
|
int REQUEST_GROUP_INVITE = 3;
|
||||||
int REQUEST_SHARE_FORUM = 4;
|
int REQUEST_SHARE_FORUM = 4;
|
||||||
int REQUEST_WRITE_BLOG_POST = 5;
|
|
||||||
int REQUEST_SHARE_BLOG = 6;
|
int REQUEST_SHARE_BLOG = 6;
|
||||||
int REQUEST_RINGTONE = 7;
|
int REQUEST_RINGTONE = 7;
|
||||||
int REQUEST_PERMISSION_CAMERA_LOCATION = 8;
|
int REQUEST_PERMISSION_CAMERA_LOCATION = 8;
|
||||||
|
|||||||
@@ -28,9 +28,12 @@ import javax.inject.Inject;
|
|||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
|
||||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.briar.android.attachment.AttachmentItem.State.AVAILABLE;
|
import static org.briarproject.briar.android.attachment.AttachmentItem.State.AVAILABLE;
|
||||||
@@ -86,7 +89,17 @@ class AttachmentRetrieverImpl implements AttachmentRetriever {
|
|||||||
List<AttachmentHeader> headers = messageHeader.getAttachmentHeaders();
|
List<AttachmentHeader> headers = messageHeader.getAttachmentHeaders();
|
||||||
List<LiveData<AttachmentItem>> items = new ArrayList<>(headers.size());
|
List<LiveData<AttachmentItem>> items = new ArrayList<>(headers.size());
|
||||||
boolean needsSize = headers.size() == 1;
|
boolean needsSize = headers.size() == 1;
|
||||||
|
List<String> supported = asList(getSupportedImageContentTypes());
|
||||||
for (AttachmentHeader h : headers) {
|
for (AttachmentHeader h : headers) {
|
||||||
|
// Fail early if we don't support the content type
|
||||||
|
if (!supported.contains(h.getContentType())) {
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Unsupported content type " + h.getContentType());
|
||||||
|
}
|
||||||
|
AttachmentItem item = new AttachmentItem(h, "", ERROR);
|
||||||
|
items.add(new MutableLiveData<>(item));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// try cache for existing item live data
|
// try cache for existing item live data
|
||||||
MutableLiveData<AttachmentItem> liveData =
|
MutableLiveData<AttachmentItem> liveData =
|
||||||
itemsWithSize.get(h.getMessageId());
|
itemsWithSize.get(h.getMessageId());
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
interface BaseController {
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void onStart();
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void onStop();
|
|
||||||
|
|
||||||
void loadBlogPosts(GroupId g,
|
|
||||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler);
|
|
||||||
|
|
||||||
void loadBlogPost(BlogPostHeader header,
|
|
||||||
ResultExceptionHandler<BlogPostItem, DbException> handler);
|
|
||||||
|
|
||||||
void loadBlogPost(GroupId g, MessageId m,
|
|
||||||
ResultExceptionHandler<BlogPostItem, DbException> handler);
|
|
||||||
|
|
||||||
void repeatPost(BlogPostItem item, @Nullable String comment,
|
|
||||||
ExceptionHandler<DbException> handler);
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
interface BlogListener {
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void onBlogPostAdded(BlogPostHeader header, boolean local);
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void onBlogRemoved();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,209 +0,0 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.briar.android.controller.DbControllerImpl;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
|
||||||
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
|
||||||
import org.briarproject.briar.api.blog.BlogManager;
|
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
|
||||||
import org.briarproject.briar.util.HtmlUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
|
||||||
import static org.briarproject.briar.util.HtmlUtils.ARTICLE;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
abstract class BaseControllerImpl extends DbControllerImpl
|
|
||||||
implements BaseController, EventListener {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(BaseControllerImpl.class.getName());
|
|
||||||
|
|
||||||
protected final EventBus eventBus;
|
|
||||||
protected final AndroidNotificationManager notificationManager;
|
|
||||||
protected final IdentityManager identityManager;
|
|
||||||
protected final BlogManager blogManager;
|
|
||||||
|
|
||||||
private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
|
|
||||||
private final Map<MessageId, BlogPostHeader> headerCache =
|
|
||||||
new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
BaseControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
|
||||||
LifecycleManager lifecycleManager, EventBus eventBus,
|
|
||||||
AndroidNotificationManager notificationManager,
|
|
||||||
IdentityManager identityManager, BlogManager blogManager) {
|
|
||||||
super(dbExecutor, lifecycleManager);
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
this.notificationManager = notificationManager;
|
|
||||||
this.identityManager = identityManager;
|
|
||||||
this.blogManager = blogManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@CallSuper
|
|
||||||
public void onStart() {
|
|
||||||
eventBus.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@CallSuper
|
|
||||||
public void onStop() {
|
|
||||||
eventBus.removeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadBlogPosts(GroupId groupId,
|
|
||||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
Collection<BlogPostItem> items = loadItems(groupId);
|
|
||||||
handler.onResult(items);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
handler.onException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<BlogPostItem> loadItems(GroupId groupId) throws DbException {
|
|
||||||
long start = now();
|
|
||||||
Collection<BlogPostHeader> headers =
|
|
||||||
blogManager.getPostHeaders(groupId);
|
|
||||||
logDuration(LOG, "Loading headers", start);
|
|
||||||
Collection<BlogPostItem> items = new ArrayList<>(headers.size());
|
|
||||||
start = now();
|
|
||||||
for (BlogPostHeader h : headers) {
|
|
||||||
headerCache.put(h.getId(), h);
|
|
||||||
BlogPostItem item = getItem(h);
|
|
||||||
items.add(item);
|
|
||||||
}
|
|
||||||
logDuration(LOG, "Loading bodies", start);
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadBlogPost(BlogPostHeader header,
|
|
||||||
ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
|
||||||
|
|
||||||
String text = textCache.get(header.getId());
|
|
||||||
if (text != null) {
|
|
||||||
LOG.info("Loaded text from cache");
|
|
||||||
handler.onResult(new BlogPostItem(header, text));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
long start = now();
|
|
||||||
BlogPostItem item = getItem(header);
|
|
||||||
logDuration(LOG, "Loading text", start);
|
|
||||||
handler.onResult(item);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
handler.onException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadBlogPost(GroupId g, MessageId m,
|
|
||||||
ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
|
||||||
|
|
||||||
BlogPostHeader header = headerCache.get(m);
|
|
||||||
if (header != null) {
|
|
||||||
LOG.info("Loaded header from cache");
|
|
||||||
loadBlogPost(header, handler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
long start = now();
|
|
||||||
BlogPostHeader header1 = getPostHeader(g, m);
|
|
||||||
BlogPostItem item = getItem(header1);
|
|
||||||
logDuration(LOG, "Loading post", start);
|
|
||||||
handler.onResult(item);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
handler.onException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void repeatPost(BlogPostItem item, @Nullable String comment,
|
|
||||||
ExceptionHandler<DbException> handler) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
LocalAuthor a = identityManager.getLocalAuthor();
|
|
||||||
Blog b = blogManager.getPersonalBlog(a);
|
|
||||||
BlogPostHeader h = item.getHeader();
|
|
||||||
blogManager.addLocalComment(a, b.getId(), comment, h);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
handler.onException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlogPostHeader getPostHeader(GroupId g, MessageId m)
|
|
||||||
throws DbException {
|
|
||||||
BlogPostHeader header = headerCache.get(m);
|
|
||||||
if (header == null) {
|
|
||||||
header = blogManager.getPostHeader(g, m);
|
|
||||||
headerCache.put(m, header);
|
|
||||||
}
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DatabaseExecutor
|
|
||||||
private BlogPostItem getItem(BlogPostHeader h) throws DbException {
|
|
||||||
String text;
|
|
||||||
if (h instanceof BlogCommentHeader) {
|
|
||||||
BlogCommentHeader c = (BlogCommentHeader) h;
|
|
||||||
BlogCommentItem item = new BlogCommentItem(c);
|
|
||||||
text = getPostText(item.getPostHeader().getId());
|
|
||||||
item.setText(text);
|
|
||||||
return item;
|
|
||||||
} else {
|
|
||||||
text = getPostText(h.getId());
|
|
||||||
return new BlogPostItem(h, text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DatabaseExecutor
|
|
||||||
private String getPostText(MessageId m) throws DbException {
|
|
||||||
String text = textCache.get(m);
|
|
||||||
if (text == null) {
|
|
||||||
text = HtmlUtils.clean(blogManager.getPostText(m), ARTICLE);
|
|
||||||
textCache.put(m, text);
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
|
||||||
import static android.view.View.INVISIBLE;
|
|
||||||
import static android.view.View.VISIBLE;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
|
||||||
import static org.briarproject.briar.android.util.UiUtils.MIN_DATE_RESOLUTION;
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
abstract class BasePostFragment extends BaseFragment {
|
|
||||||
|
|
||||||
static final String POST_ID = "briar.POST_ID";
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
getLogger(BasePostFragment.class.getName());
|
|
||||||
|
|
||||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
|
||||||
|
|
||||||
protected MessageId postId;
|
|
||||||
private ProgressBar progressBar;
|
|
||||||
private BlogPostViewHolder ui;
|
|
||||||
private BlogPostItem post;
|
|
||||||
private Runnable refresher;
|
|
||||||
|
|
||||||
@CallSuper
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater,
|
|
||||||
@Nullable ViewGroup container,
|
|
||||||
@Nullable Bundle savedInstanceState) {
|
|
||||||
// retrieve MessageId of blog post from arguments
|
|
||||||
byte[] p = requireArguments().getByteArray(POST_ID);
|
|
||||||
if (p == null) throw new IllegalStateException("No post ID in args");
|
|
||||||
postId = new MessageId(p);
|
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.fragment_blog_post, container,
|
|
||||||
false);
|
|
||||||
progressBar = view.findViewById(R.id.progressBar);
|
|
||||||
progressBar.setVisibility(VISIBLE);
|
|
||||||
ui = new BlogPostViewHolder(view, true, new OnBlogPostClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onBlogPostClick(BlogPostItem post) {
|
|
||||||
// We're already there
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAuthorClick(BlogPostItem post) {
|
|
||||||
if (getContext() == null) return;
|
|
||||||
Intent i = new Intent(getContext(), BlogActivity.class);
|
|
||||||
i.putExtra(GROUP_ID, post.getGroupId().getBytes());
|
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
getContext().startActivity(i);
|
|
||||||
}
|
|
||||||
}, getFragmentManager());
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@CallSuper
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
startPeriodicUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@CallSuper
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
stopPeriodicUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
protected void onBlogPostLoaded(BlogPostItem post) {
|
|
||||||
progressBar.setVisibility(INVISIBLE);
|
|
||||||
this.post = post;
|
|
||||||
ui.bindItem(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startPeriodicUpdate() {
|
|
||||||
refresher = () -> {
|
|
||||||
LOG.info("Updating Content...");
|
|
||||||
ui.updateDate(post.getTimestamp());
|
|
||||||
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
|
|
||||||
};
|
|
||||||
LOG.info("Adding Handler Callback");
|
|
||||||
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopPeriodicUpdate() {
|
|
||||||
if (refresher != null) {
|
|
||||||
LOG.info("Removing Handler Callback");
|
|
||||||
handler.removeCallbacks(refresher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
|
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
|
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
||||||
|
import org.briarproject.briar.api.blog.BlogManager;
|
||||||
|
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||||
|
import org.briarproject.briar.util.HtmlUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
import static org.briarproject.briar.util.HtmlUtils.ARTICLE;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
abstract class BaseViewModel extends DbViewModel implements EventListener {
|
||||||
|
|
||||||
|
private static final Logger LOG = getLogger(BaseViewModel.class.getName());
|
||||||
|
|
||||||
|
private final EventBus eventBus;
|
||||||
|
protected final IdentityManager identityManager;
|
||||||
|
protected final AndroidNotificationManager notificationManager;
|
||||||
|
protected final BlogManager blogManager;
|
||||||
|
|
||||||
|
protected final MutableLiveData<LiveResult<ListUpdate>> blogPosts =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
|
||||||
|
BaseViewModel(Application application,
|
||||||
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager,
|
||||||
|
TransactionManager db,
|
||||||
|
AndroidExecutor androidExecutor,
|
||||||
|
EventBus eventBus,
|
||||||
|
IdentityManager identityManager,
|
||||||
|
AndroidNotificationManager notificationManager,
|
||||||
|
BlogManager blogManager) {
|
||||||
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
this.identityManager = identityManager;
|
||||||
|
this.notificationManager = notificationManager;
|
||||||
|
this.blogManager = blogManager;
|
||||||
|
eventBus.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCleared() {
|
||||||
|
super.onCleared();
|
||||||
|
eventBus.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected List<BlogPostItem> loadBlogPosts(Transaction txn, GroupId groupId)
|
||||||
|
throws DbException {
|
||||||
|
long start = now();
|
||||||
|
List<BlogPostHeader> headers =
|
||||||
|
blogManager.getPostHeaders(txn, groupId);
|
||||||
|
logDuration(LOG, "Loading headers", start);
|
||||||
|
List<BlogPostItem> items = new ArrayList<>(headers.size());
|
||||||
|
start = now();
|
||||||
|
for (BlogPostHeader h : headers) {
|
||||||
|
BlogPostItem item = getItem(txn, h);
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
logDuration(LOG, "Loading bodies", start);
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected BlogPostItem getItem(Transaction txn, BlogPostHeader h)
|
||||||
|
throws DbException {
|
||||||
|
String text;
|
||||||
|
if (h instanceof BlogCommentHeader) {
|
||||||
|
BlogCommentHeader c = (BlogCommentHeader) h;
|
||||||
|
BlogCommentItem item = new BlogCommentItem(c);
|
||||||
|
text = getPostText(txn, item.getPostHeader().getId());
|
||||||
|
item.setText(text);
|
||||||
|
return item;
|
||||||
|
} else {
|
||||||
|
text = getPostText(txn, h.getId());
|
||||||
|
return new BlogPostItem(h, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
private String getPostText(Transaction txn, MessageId m)
|
||||||
|
throws DbException {
|
||||||
|
return HtmlUtils.clean(blogManager.getPostText(txn, m), ARTICLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<LiveResult<BlogPostItem>> loadBlogPost(GroupId g, MessageId m) {
|
||||||
|
MutableLiveData<LiveResult<BlogPostItem>> result =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
runOnDbThread(true, txn -> {
|
||||||
|
long start = now();
|
||||||
|
BlogPostHeader header = blogManager.getPostHeader(txn, g, m);
|
||||||
|
BlogPostItem item = getItem(txn, header);
|
||||||
|
logDuration(LOG, "Loading post", start);
|
||||||
|
result.postValue(new LiveResult<>(item));
|
||||||
|
}, e -> {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
result.postValue(new LiveResult<>(e));
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onBlogPostAdded(BlogPostHeader header, boolean local) {
|
||||||
|
runOnDbThread(true, txn -> {
|
||||||
|
BlogPostItem item = getItem(txn, header);
|
||||||
|
txn.attach(() -> onBlogPostItemAdded(item, local));
|
||||||
|
}, this::handleException);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void onBlogPostItemAdded(BlogPostItem item, boolean local) {
|
||||||
|
List<BlogPostItem> items = addListItem(getBlogPostItems(), item);
|
||||||
|
if (items != null) {
|
||||||
|
Collections.sort(items);
|
||||||
|
blogPosts.setValue(new LiveResult<>(new ListUpdate(local, items)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void repeatPost(BlogPostItem item, @Nullable String comment) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
LocalAuthor a = identityManager.getLocalAuthor();
|
||||||
|
Blog b = blogManager.getPersonalBlog(a);
|
||||||
|
BlogPostHeader h = item.getHeader();
|
||||||
|
blogManager.addLocalComment(a, b.getId(), comment, h);
|
||||||
|
} catch (DbException e) {
|
||||||
|
handleException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<LiveResult<ListUpdate>> getBlogPosts() {
|
||||||
|
return blogPosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
@Nullable
|
||||||
|
protected List<BlogPostItem> getBlogPostItems() {
|
||||||
|
LiveResult<ListUpdate> value = blogPosts.getValue();
|
||||||
|
if (value == null) return null;
|
||||||
|
ListUpdate result = value.getResultOrNull();
|
||||||
|
return result == null ? null : result.getItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this after {@link ListUpdate#getPostAddedWasLocal()} was processed.
|
||||||
|
* This prevents it from getting processed again.
|
||||||
|
*/
|
||||||
|
@UiThread
|
||||||
|
void resetLocalUpdate() {
|
||||||
|
LiveResult<ListUpdate> value = blogPosts.getValue();
|
||||||
|
if (value == null) return;
|
||||||
|
ListUpdate result = value.getResultOrNull();
|
||||||
|
result.postAddedWasLocal = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ListUpdate {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Boolean postAddedWasLocal;
|
||||||
|
private final List<BlogPostItem> items;
|
||||||
|
|
||||||
|
ListUpdate(@Nullable Boolean postAddedWasLocal,
|
||||||
|
List<BlogPostItem> items) {
|
||||||
|
this.postAddedWasLocal = postAddedWasLocal;
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null when not a single post was added with this update.
|
||||||
|
* true when a single post was added locally and false if remotely.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Boolean getPostAddedWasLocal() {
|
||||||
|
return postAddedWasLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlogPostItem> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,11 @@ import android.os.Bundle;
|
|||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
import org.briarproject.briar.android.sharing.BlogSharingStatusActivity;
|
import org.briarproject.briar.android.sharing.BlogSharingStatusActivity;
|
||||||
|
|
||||||
@@ -16,6 +18,10 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
import static org.briarproject.briar.android.blog.BlogPostFragment.POST_ID;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -23,7 +29,16 @@ public class BlogActivity extends BriarActivity
|
|||||||
implements BaseFragmentListener {
|
implements BaseFragmentListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BlogController blogController;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BlogViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectActivity(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||||
|
.get(BlogViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle state) {
|
public void onCreate(@Nullable Bundle state) {
|
||||||
@@ -31,32 +46,46 @@ public class BlogActivity extends BriarActivity
|
|||||||
|
|
||||||
// GroupId from Intent
|
// GroupId from Intent
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
GroupId groupId =
|
||||||
if (b == null) throw new IllegalStateException("No group ID in intent");
|
new GroupId(requireNonNull(i.getByteArrayExtra(GROUP_ID)));
|
||||||
GroupId groupId = new GroupId(b);
|
// Get post info from intent
|
||||||
blogController.setGroupId(groupId);
|
@Nullable byte[] postId = i.getByteArrayExtra(POST_ID);
|
||||||
|
|
||||||
|
viewModel.setGroupId(groupId, postId == null);
|
||||||
|
|
||||||
setContentView(R.layout.activity_fragment_container_toolbar);
|
setContentView(R.layout.activity_fragment_container_toolbar);
|
||||||
Toolbar toolbar = setUpCustomToolbar(false);
|
Toolbar toolbar = setUpCustomToolbar(false);
|
||||||
|
|
||||||
// Open Sharing Status on Toolbar click
|
// Open Sharing Status on Toolbar click
|
||||||
if (toolbar != null) {
|
toolbar.setOnClickListener(v -> {
|
||||||
toolbar.setOnClickListener(v -> {
|
Intent i1 = new Intent(BlogActivity.this,
|
||||||
Intent i1 = new Intent(BlogActivity.this,
|
BlogSharingStatusActivity.class);
|
||||||
BlogSharingStatusActivity.class);
|
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
i1.putExtra(GROUP_ID, groupId.getBytes());
|
startActivity(i1);
|
||||||
startActivity(i1);
|
});
|
||||||
});
|
|
||||||
}
|
viewModel.getBlog().observe(this, blog ->
|
||||||
|
setTitle(blog.getBlog().getAuthor().getName())
|
||||||
|
);
|
||||||
|
viewModel.getSharingInfo().observe(this, info ->
|
||||||
|
setToolbarSubTitle(info.total, info.online)
|
||||||
|
);
|
||||||
|
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
showInitialFragment(BlogFragment.newInstance(groupId));
|
if (postId == null) {
|
||||||
|
showInitialFragment(BlogFragment.newInstance(groupId));
|
||||||
|
} else {
|
||||||
|
MessageId messageId = new MessageId(postId);
|
||||||
|
BaseFragment f =
|
||||||
|
BlogPostFragment.newInstance(groupId, messageId);
|
||||||
|
showInitialFragment(f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void setToolbarSubTitle(int total, int online) {
|
||||||
public void injectActivity(ActivityComponent component) {
|
requireNonNull(getSupportActionBar())
|
||||||
component.inject(this);
|
.setSubtitle(getString(R.string.shared_with, total, online));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// This class is not thread-safe
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
class BlogCommentItem extends BlogPostItem {
|
class BlogCommentItem extends BlogPostItem {
|
||||||
|
|
||||||
private static final BlogCommentComparator COMPARATOR =
|
private static final BlogCommentComparator COMPARATOR =
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public interface BlogController extends BaseController {
|
|
||||||
|
|
||||||
void setGroupId(GroupId g);
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void setBlogSharingListener(BlogSharingListener listener);
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void unsetBlogSharingListener(BlogSharingListener listener);
|
|
||||||
|
|
||||||
void loadBlogPosts(
|
|
||||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler);
|
|
||||||
|
|
||||||
void loadBlogPost(MessageId m,
|
|
||||||
ResultExceptionHandler<BlogPostItem, DbException> handler);
|
|
||||||
|
|
||||||
void loadBlog(ResultExceptionHandler<BlogItem, DbException> handler);
|
|
||||||
|
|
||||||
void deleteBlog(ResultExceptionHandler<Void, DbException> handler);
|
|
||||||
|
|
||||||
void loadSharingContacts(
|
|
||||||
ResultExceptionHandler<Collection<ContactId>, DbException> handler);
|
|
||||||
|
|
||||||
interface BlogSharingListener extends BlogListener {
|
|
||||||
@UiThread
|
|
||||||
void onBlogInvitationAccepted(ContactId c);
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void onBlogLeft(ContactId c);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -12,33 +10,25 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.blog.BaseViewModel.ListUpdate;
|
||||||
import org.briarproject.briar.android.blog.BlogController.BlogSharingListener;
|
|
||||||
import org.briarproject.briar.android.controller.SharingController;
|
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.sharing.BlogSharingStatusActivity;
|
import org.briarproject.briar.android.sharing.BlogSharingStatusActivity;
|
||||||
import org.briarproject.briar.android.sharing.ShareBlogActivity;
|
import org.briarproject.briar.android.sharing.ShareBlogActivity;
|
||||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.appcompat.app.ActionBar;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView.LayoutManager;
|
import androidx.recyclerview.widget.RecyclerView.LayoutManager;
|
||||||
|
|
||||||
@@ -48,31 +38,22 @@ import static android.widget.Toast.LENGTH_SHORT;
|
|||||||
import static com.google.android.material.snackbar.Snackbar.LENGTH_LONG;
|
import static com.google.android.material.snackbar.Snackbar.LENGTH_LONG;
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_BLOG;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_BLOG;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_WRITE_BLOG_POST;
|
|
||||||
import static org.briarproject.briar.android.controller.SharingController.SharingListener;
|
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class BlogFragment extends BaseFragment
|
public class BlogFragment extends BaseFragment
|
||||||
implements BlogSharingListener, SharingListener,
|
implements OnBlogPostClickListener {
|
||||||
OnBlogPostClickListener {
|
|
||||||
|
|
||||||
private final static String TAG = BlogFragment.class.getName();
|
private final static String TAG = BlogFragment.class.getName();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BlogController blogController;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
@Inject
|
|
||||||
SharingController sharingController;
|
|
||||||
@Nullable
|
|
||||||
private Parcelable layoutManagerState;
|
|
||||||
|
|
||||||
private GroupId groupId;
|
private GroupId groupId;
|
||||||
private BlogPostAdapter adapter;
|
private BlogViewModel viewModel;
|
||||||
private LayoutManager layoutManager;
|
private final BlogPostAdapter adapter = new BlogPostAdapter(false, this);
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
private MenuItem writeButton, deleteButton;
|
|
||||||
private boolean isMyBlog = false, canDeleteBlog = false;
|
|
||||||
|
|
||||||
static BlogFragment newInstance(GroupId groupId) {
|
static BlogFragment newInstance(GroupId groupId) {
|
||||||
BlogFragment f = new BlogFragment();
|
BlogFragment f = new BlogFragment();
|
||||||
@@ -87,8 +68,8 @@ public class BlogFragment extends BaseFragment
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
blogController.setBlogSharingListener(this);
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
sharingController.setSharingListener(this);
|
.get(BlogViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -103,106 +84,82 @@ public class BlogFragment extends BaseFragment
|
|||||||
|
|
||||||
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
||||||
|
|
||||||
adapter = new BlogPostAdapter(requireActivity(), this,
|
|
||||||
getFragmentManager());
|
|
||||||
list = v.findViewById(R.id.postList);
|
list = v.findViewById(R.id.postList);
|
||||||
layoutManager = new LinearLayoutManager(getActivity());
|
LayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||||
list.setLayoutManager(layoutManager);
|
list.setLayoutManager(layoutManager);
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.showProgressBar();
|
list.showProgressBar();
|
||||||
list.setEmptyText(getString(R.string.blogs_other_blog_empty_state));
|
list.setEmptyText(getString(R.string.blogs_other_blog_empty_state));
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
viewModel.getBlogPosts().observe(getViewLifecycleOwner(), result ->
|
||||||
layoutManagerState =
|
result.onError(this::handleException)
|
||||||
savedInstanceState.getParcelable("layoutManager");
|
.onSuccess(this::onBlogPostsLoaded)
|
||||||
}
|
);
|
||||||
|
viewModel.getBlogRemoved().observe(getViewLifecycleOwner(), removed -> {
|
||||||
|
if (removed) finish();
|
||||||
|
});
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
sharingController.onStart();
|
viewModel.blockAndClearNotifications();
|
||||||
loadBlog();
|
|
||||||
loadSharedContacts();
|
|
||||||
loadBlogPosts(false);
|
|
||||||
list.startPeriodicUpdate();
|
list.startPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
sharingController.onStop();
|
viewModel.unblockNotifications();
|
||||||
list.stopPeriodicUpdate();
|
list.stopPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
blogController.unsetBlogSharingListener(this);
|
|
||||||
sharingController.unsetSharingListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
if (layoutManager != null) {
|
|
||||||
layoutManagerState = layoutManager.onSaveInstanceState();
|
|
||||||
outState.putParcelable("layoutManager", layoutManagerState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.blogs_blog_actions, menu);
|
inflater.inflate(R.menu.blogs_blog_actions, menu);
|
||||||
writeButton = menu.findItem(R.id.action_write_blog_post);
|
MenuItem writeButton = menu.findItem(R.id.action_write_blog_post);
|
||||||
if (isMyBlog) writeButton.setVisible(true);
|
MenuItem deleteButton = menu.findItem(R.id.action_blog_delete);
|
||||||
deleteButton = menu.findItem(R.id.action_blog_delete);
|
viewModel.getBlog().observe(getViewLifecycleOwner(), blog -> {
|
||||||
if (canDeleteBlog) deleteButton.setEnabled(true);
|
if (blog.isOurs()) writeButton.setVisible(true);
|
||||||
|
if (blog.canBeRemoved()) deleteButton.setEnabled(true);
|
||||||
|
});
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
int itemId = item.getItemId();
|
||||||
case R.id.action_write_blog_post:
|
if (itemId == R.id.action_write_blog_post) {
|
||||||
Intent i = new Intent(getActivity(),
|
Intent i = new Intent(getActivity(), WriteBlogPostActivity.class);
|
||||||
WriteBlogPostActivity.class);
|
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
startActivity(i);
|
||||||
startActivityForResult(i, REQUEST_WRITE_BLOG_POST);
|
return true;
|
||||||
return true;
|
} else if (itemId == R.id.action_blog_share) {
|
||||||
case R.id.action_blog_share:
|
Intent i = new Intent(getActivity(), ShareBlogActivity.class);
|
||||||
Intent i2 = new Intent(getActivity(), ShareBlogActivity.class);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i2.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
i2.putExtra(GROUP_ID, groupId.getBytes());
|
startActivityForResult(i, REQUEST_SHARE_BLOG);
|
||||||
startActivityForResult(i2, REQUEST_SHARE_BLOG);
|
return true;
|
||||||
return true;
|
} else if (itemId == R.id.action_blog_sharing_status) {
|
||||||
case R.id.action_blog_sharing_status:
|
Intent i =
|
||||||
Intent i3 = new Intent(getActivity(),
|
new Intent(getActivity(), BlogSharingStatusActivity.class);
|
||||||
BlogSharingStatusActivity.class);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i3.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
i3.putExtra(GROUP_ID, groupId.getBytes());
|
startActivity(i);
|
||||||
startActivity(i3);
|
return true;
|
||||||
return true;
|
} else if (itemId == R.id.action_blog_delete) {
|
||||||
case R.id.action_blog_delete:
|
showDeleteDialog();
|
||||||
showDeleteDialog();
|
return true;
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int request, int result,
|
public void onActivityResult(int request, int result,
|
||||||
@Nullable Intent data) {
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
|
if (request == REQUEST_SHARE_BLOG && result == RESULT_OK) {
|
||||||
if (request == REQUEST_WRITE_BLOG_POST && result == RESULT_OK) {
|
|
||||||
displaySnackbar(R.string.blogs_blog_post_created, true);
|
|
||||||
loadBlogPosts(true);
|
|
||||||
} else if (request == REQUEST_SHARE_BLOG && result == RESULT_OK) {
|
|
||||||
displaySnackbar(R.string.blogs_sharing_snackbar, false);
|
displaySnackbar(R.string.blogs_sharing_snackbar, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,35 +169,26 @@ public class BlogFragment extends BaseFragment
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void onBlogPostsLoaded(ListUpdate update) {
|
||||||
public void onBlogPostAdded(BlogPostHeader header, boolean local) {
|
adapter.submitList(update.getItems(), () -> {
|
||||||
blogController.loadBlogPost(header,
|
Boolean wasLocal = update.getPostAddedWasLocal();
|
||||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
if (wasLocal != null && wasLocal) {
|
||||||
this) {
|
list.scrollToPosition(0);
|
||||||
@Override
|
displaySnackbar(R.string.blogs_blog_post_created,
|
||||||
public void onResultUi(BlogPostItem post) {
|
false);
|
||||||
adapter.add(post);
|
} else if (wasLocal != null) {
|
||||||
if (local) {
|
displaySnackbar(R.string.blogs_blog_post_received,
|
||||||
list.scrollToPosition(0);
|
true);
|
||||||
displaySnackbar(R.string.blogs_blog_post_created,
|
}
|
||||||
false);
|
viewModel.resetLocalUpdate();
|
||||||
} else {
|
list.showData();
|
||||||
displaySnackbar(R.string.blogs_blog_post_received,
|
});
|
||||||
true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlogPostClick(BlogPostItem post) {
|
public void onBlogPostClick(BlogPostItem post) {
|
||||||
BlogPostFragment f = BlogPostFragment.newInstance(post.getId());
|
BlogPostFragment f =
|
||||||
|
BlogPostFragment.newInstance(groupId, post.getId());
|
||||||
showNextFragment(f);
|
showNextFragment(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,111 +204,10 @@ public class BlogFragment extends BaseFragment
|
|||||||
getContext().startActivity(i);
|
getContext().startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBlogPosts(boolean reload) {
|
|
||||||
blogController.loadBlogPosts(
|
|
||||||
new UiResultExceptionHandler<Collection<BlogPostItem>,
|
|
||||||
DbException>(this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(Collection<BlogPostItem> posts) {
|
|
||||||
if (posts.isEmpty()) {
|
|
||||||
list.showData();
|
|
||||||
} else {
|
|
||||||
adapter.addAll(posts);
|
|
||||||
if (reload || layoutManagerState == null) {
|
|
||||||
list.scrollToPosition(0);
|
|
||||||
} else {
|
|
||||||
layoutManager.onRestoreInstanceState(
|
|
||||||
layoutManagerState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadBlog() {
|
|
||||||
blogController.loadBlog(
|
|
||||||
new UiResultExceptionHandler<BlogItem, DbException>(this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(BlogItem blog) {
|
|
||||||
setToolbarTitle(blog.getBlog().getAuthor());
|
|
||||||
if (blog.isOurs())
|
|
||||||
showWriteButton();
|
|
||||||
if (blog.canBeRemoved())
|
|
||||||
enableDeleteButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setToolbarTitle(Author a) {
|
|
||||||
getActivity().setTitle(a.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadSharedContacts() {
|
|
||||||
blogController.loadSharingContacts(
|
|
||||||
new UiResultExceptionHandler<Collection<ContactId>,
|
|
||||||
DbException>(this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(Collection<ContactId> contacts) {
|
|
||||||
sharingController.addAll(contacts);
|
|
||||||
int online = sharingController.getOnlineCount();
|
|
||||||
setToolbarSubTitle(contacts.size(), online);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlogInvitationAccepted(ContactId c) {
|
public void onLinkClick(String url) {
|
||||||
sharingController.add(c);
|
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
||||||
setToolbarSubTitle(sharingController.getTotalCount(),
|
f.show(getParentFragmentManager(), f.getUniqueTag());
|
||||||
sharingController.getOnlineCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlogLeft(ContactId c) {
|
|
||||||
sharingController.remove(c);
|
|
||||||
setToolbarSubTitle(sharingController.getTotalCount(),
|
|
||||||
sharingController.getOnlineCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharingInfoUpdated(int total, int online) {
|
|
||||||
setToolbarSubTitle(total, online);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setToolbarSubTitle(int total, int online) {
|
|
||||||
ActionBar actionBar =
|
|
||||||
((BriarActivity) getActivity()).getSupportActionBar();
|
|
||||||
if (actionBar != null) {
|
|
||||||
actionBar.setSubtitle(
|
|
||||||
getString(R.string.shared_with, total, online));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showWriteButton() {
|
|
||||||
isMyBlog = true;
|
|
||||||
if (writeButton != null)
|
|
||||||
writeButton.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enableDeleteButton() {
|
|
||||||
canDeleteBlog = true;
|
|
||||||
if (deleteButton != null)
|
|
||||||
deleteButton.setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displaySnackbar(int stringId, boolean scroll) {
|
private void displaySnackbar(int stringId, boolean scroll) {
|
||||||
@@ -373,38 +220,21 @@ public class BlogFragment extends BaseFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showDeleteDialog() {
|
private void showDeleteDialog() {
|
||||||
DialogInterface.OnClickListener okListener =
|
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
|
||||||
(dialog, which) -> deleteBlog();
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
|
|
||||||
R.style.BriarDialogTheme);
|
R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.blogs_remove_blog));
|
builder.setTitle(getString(R.string.blogs_remove_blog));
|
||||||
builder.setMessage(
|
builder.setMessage(
|
||||||
getString(R.string.blogs_remove_blog_dialog_message));
|
getString(R.string.blogs_remove_blog_dialog_message));
|
||||||
builder.setPositiveButton(R.string.cancel, null);
|
builder.setPositiveButton(R.string.cancel, null);
|
||||||
builder.setNegativeButton(R.string.blogs_remove_blog_ok, okListener);
|
builder.setNegativeButton(R.string.blogs_remove_blog_ok,
|
||||||
|
(dialog, which) -> deleteBlog());
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteBlog() {
|
private void deleteBlog() {
|
||||||
blogController.deleteBlog(
|
viewModel.deleteBlog();
|
||||||
new UiResultExceptionHandler<Void, DbException>(this) {
|
Toast.makeText(getActivity(), R.string.blogs_blog_removed, LENGTH_SHORT)
|
||||||
@Override
|
.show();
|
||||||
public void onResultUi(Void result) {
|
|
||||||
Toast.makeText(getActivity(),
|
|
||||||
R.string.blogs_blog_removed, LENGTH_SHORT)
|
|
||||||
.show();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlogRemoved() {
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,23 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
import org.briarproject.briar.android.activity.ActivityScope;
|
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||||
import org.briarproject.briar.android.activity.BaseActivity;
|
|
||||||
import org.briarproject.briar.android.controller.SharingController;
|
|
||||||
import org.briarproject.briar.android.controller.SharingControllerImpl;
|
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import dagger.Binds;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.multibindings.IntoMap;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class BlogModule {
|
public interface BlogModule {
|
||||||
|
|
||||||
@ActivityScope
|
@Binds
|
||||||
@Provides
|
@IntoMap
|
||||||
BlogController provideBlogController(BaseActivity activity,
|
@ViewModelKey(FeedViewModel.class)
|
||||||
BlogControllerImpl blogController) {
|
ViewModel bindFeedViewModel(FeedViewModel feedViewModel);
|
||||||
activity.addLifecycleController(blogController);
|
|
||||||
return blogController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
@Binds
|
||||||
@Provides
|
@IntoMap
|
||||||
FeedController provideFeedController(FeedControllerImpl feedController) {
|
@ViewModelKey(BlogViewModel.class)
|
||||||
return feedController;
|
ViewModel bindBlogViewModel(BlogViewModel blogViewModel);
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
SharingController provideSharingController(
|
|
||||||
SharingControllerImpl sharingController) {
|
|
||||||
return sharingController;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -8,52 +7,44 @@ import android.view.ViewGroup;
|
|||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.recyclerview.widget.ListAdapter;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
class BlogPostAdapter extends BriarAdapter<BlogPostItem, BlogPostViewHolder> {
|
class BlogPostAdapter extends ListAdapter<BlogPostItem, BlogPostViewHolder> {
|
||||||
|
|
||||||
|
private final boolean authorClickable;
|
||||||
private final OnBlogPostClickListener listener;
|
private final OnBlogPostClickListener listener;
|
||||||
@Nullable
|
|
||||||
private final FragmentManager fragmentManager;
|
|
||||||
|
|
||||||
BlogPostAdapter(Context ctx, OnBlogPostClickListener listener,
|
BlogPostAdapter(boolean authorClickable, OnBlogPostClickListener listener) {
|
||||||
@Nullable FragmentManager fragmentManager) {
|
super(new DiffUtil.ItemCallback<BlogPostItem>() {
|
||||||
super(ctx, BlogPostItem.class);
|
@Override
|
||||||
|
public boolean areItemsTheSame(BlogPostItem a, BlogPostItem b) {
|
||||||
|
return a.getId().equals(b.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areContentsTheSame(BlogPostItem a, BlogPostItem b) {
|
||||||
|
return a.isRead() == b.isRead();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.authorClickable = authorClickable;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.fragmentManager = fragmentManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlogPostViewHolder onCreateViewHolder(ViewGroup parent,
|
public BlogPostViewHolder onCreateViewHolder(ViewGroup parent,
|
||||||
int viewType) {
|
int viewType) {
|
||||||
View v = LayoutInflater.from(ctx).inflate(
|
View v = LayoutInflater.from(parent.getContext()).inflate(
|
||||||
R.layout.list_item_blog_post, parent, false);
|
R.layout.list_item_blog_post, parent, false);
|
||||||
return new BlogPostViewHolder(v, false, listener, fragmentManager);
|
return new BlogPostViewHolder(v, false, listener, authorClickable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(BlogPostViewHolder ui, int position) {
|
public void onBindViewHolder(BlogPostViewHolder ui, int position) {
|
||||||
ui.bindItem(getItemAt(position));
|
ui.bindItem(getItem(position));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(BlogPostItem a, BlogPostItem b) {
|
|
||||||
return a.compareTo(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(BlogPostItem a, BlogPostItem b) {
|
|
||||||
return a.isRead() == b.isRead();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(BlogPostItem a, BlogPostItem b) {
|
|
||||||
return a.getId().equals(b.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,76 +1,159 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.blog.BaseController.BlogListener;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||||
|
import static android.view.View.INVISIBLE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||||
|
import static org.briarproject.briar.android.util.UiUtils.MIN_DATE_RESOLUTION;
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class BlogPostFragment extends BasePostFragment implements BlogListener {
|
public class BlogPostFragment extends BaseFragment
|
||||||
|
implements OnBlogPostClickListener {
|
||||||
|
|
||||||
private static final String TAG = BlogPostFragment.class.getName();
|
private static final String TAG = BlogPostFragment.class.getName();
|
||||||
|
private static final Logger LOG = getLogger(TAG);
|
||||||
|
|
||||||
|
static final String POST_ID = "briar.POST_ID";
|
||||||
|
|
||||||
|
protected BlogViewModel viewModel;
|
||||||
|
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
private ProgressBar progressBar;
|
||||||
|
private BlogPostViewHolder ui;
|
||||||
|
private BlogPostItem post;
|
||||||
|
private Runnable refresher;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BlogController blogController;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
static BlogPostFragment newInstance(MessageId postId) {
|
static BlogPostFragment newInstance(GroupId blogId, MessageId postId) {
|
||||||
BlogPostFragment f = new BlogPostFragment();
|
BlogPostFragment f = new BlogPostFragment();
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putByteArray(GROUP_ID, blogId.getBytes());
|
||||||
bundle.putByteArray(POST_ID, postId.getBytes());
|
bundle.putByteArray(POST_ID, postId.getBytes());
|
||||||
|
|
||||||
f.setArguments(bundle);
|
f.setArguments(bundle);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(BlogViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
Bundle args = requireArguments();
|
||||||
|
GroupId groupId =
|
||||||
|
new GroupId(requireNonNull(args.getByteArray(GROUP_ID)));
|
||||||
|
MessageId postId =
|
||||||
|
new MessageId(requireNonNull(args.getByteArray(POST_ID)));
|
||||||
|
|
||||||
|
View view = inflater.inflate(R.layout.fragment_blog_post, container,
|
||||||
|
false);
|
||||||
|
progressBar = view.findViewById(R.id.progressBar);
|
||||||
|
progressBar.setVisibility(VISIBLE);
|
||||||
|
ui = new BlogPostViewHolder(view, true, this, false);
|
||||||
|
LifecycleOwner owner = getViewLifecycleOwner();
|
||||||
|
viewModel.loadBlogPost(groupId, postId).observe(owner, result ->
|
||||||
|
result.onError(this::handleException)
|
||||||
|
.onSuccess(this::onBlogPostLoaded)
|
||||||
|
);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
startPeriodicUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
stopPeriodicUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void onBlogPostLoaded(BlogPostItem post) {
|
||||||
|
progressBar.setVisibility(INVISIBLE);
|
||||||
|
this.post = post;
|
||||||
|
ui.bindItem(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlogPostClick(BlogPostItem post) {
|
||||||
|
// We're already there
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthorClick(BlogPostItem post) {
|
||||||
|
Intent i = new Intent(requireContext(), BlogActivity.class);
|
||||||
|
i.putExtra(GROUP_ID, post.getGroupId().getBytes());
|
||||||
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
requireContext().startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLinkClick(String url) {
|
||||||
|
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
||||||
|
f.show(getParentFragmentManager(), f.getUniqueTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startPeriodicUpdate() {
|
||||||
|
refresher = () -> {
|
||||||
|
LOG.info("Updating Content...");
|
||||||
|
ui.updateDate(post.getTimestamp());
|
||||||
|
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
|
||||||
|
};
|
||||||
|
LOG.info("Adding Handler Callback");
|
||||||
|
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopPeriodicUpdate() {
|
||||||
|
if (refresher != null) {
|
||||||
|
LOG.info("Removing Handler Callback");
|
||||||
|
handler.removeCallbacks(refresher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUniqueTag() {
|
public String getUniqueTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void injectFragment(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
blogController.loadBlogPost(postId,
|
|
||||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
|
||||||
this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(BlogPostItem post) {
|
|
||||||
onBlogPostLoaded(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlogPostAdded(BlogPostHeader header, boolean local) {
|
|
||||||
// doesn't matter here
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlogRemoved() {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
|
|||||||
private final BlogPostHeader header;
|
private final BlogPostHeader header;
|
||||||
@Nullable
|
@Nullable
|
||||||
protected String text;
|
protected String text;
|
||||||
private boolean read;
|
private final boolean read;
|
||||||
|
|
||||||
BlogPostItem(BlogPostHeader header, @Nullable String text) {
|
BlogPostItem(BlogPostHeader header, @Nullable String text) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
@@ -74,9 +74,6 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
|
|||||||
|
|
||||||
protected static int compare(BlogPostHeader h1, BlogPostHeader h2) {
|
protected static int compare(BlogPostHeader h1, BlogPostHeader h2) {
|
||||||
// The newest post comes first
|
// The newest post comes first
|
||||||
long aTime = h1.getTimeReceived(), bTime = h2.getTimeReceived();
|
return Long.compare(h2.getTimeReceived(), h1.getTimeReceived());
|
||||||
if (aTime > bTime) return -1;
|
|
||||||
if (aTime < bTime) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,31 +9,31 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.view.AuthorView;
|
import org.briarproject.briar.android.view.AuthorView;
|
||||||
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
|
import static org.briarproject.briar.android.blog.BlogPostFragment.POST_ID;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.TEASER_LENGTH;
|
import static org.briarproject.briar.android.util.UiUtils.TEASER_LENGTH;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.getSpanned;
|
import static org.briarproject.briar.android.util.UiUtils.getSpanned;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.getTeaser;
|
import static org.briarproject.briar.android.util.UiUtils.getTeaser;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.makeLinksClickable;
|
import static org.briarproject.briar.android.util.UiUtils.makeLinksClickable;
|
||||||
import static org.briarproject.briar.api.blog.MessageType.POST;
|
import static org.briarproject.briar.android.view.AuthorView.COMMENTER;
|
||||||
|
import static org.briarproject.briar.android.view.AuthorView.REBLOGGER;
|
||||||
|
import static org.briarproject.briar.android.view.AuthorView.RSS_FEED_REBLOGGED;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
@NotNullByDefault
|
||||||
class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private final Context ctx;
|
private final Context ctx;
|
||||||
@@ -43,20 +43,16 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
private final ImageButton reblogButton;
|
private final ImageButton reblogButton;
|
||||||
private final TextView text;
|
private final TextView text;
|
||||||
private final ViewGroup commentContainer;
|
private final ViewGroup commentContainer;
|
||||||
private final boolean fullText;
|
private final boolean fullText, authorClickable;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final OnBlogPostClickListener listener;
|
private final OnBlogPostClickListener listener;
|
||||||
@Nullable
|
|
||||||
private final FragmentManager fragmentManager;
|
|
||||||
|
|
||||||
BlogPostViewHolder(View v, boolean fullText,
|
BlogPostViewHolder(View v, boolean fullText,
|
||||||
@NonNull OnBlogPostClickListener listener,
|
OnBlogPostClickListener listener, boolean authorClickable) {
|
||||||
@Nullable FragmentManager fragmentManager) {
|
|
||||||
super(v);
|
super(v);
|
||||||
this.fullText = fullText;
|
this.fullText = fullText;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.fragmentManager = fragmentManager;
|
this.authorClickable = authorClickable;
|
||||||
|
|
||||||
ctx = v.getContext();
|
ctx = v.getContext();
|
||||||
layout = v.findViewById(R.id.postLayout);
|
layout = v.findViewById(R.id.postLayout);
|
||||||
@@ -67,10 +63,6 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
commentContainer = v.findViewById(R.id.commentContainer);
|
commentContainer = v.findViewById(R.id.commentContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setVisibility(int visibility) {
|
|
||||||
layout.setVisibility(visibility);
|
|
||||||
}
|
|
||||||
|
|
||||||
void hideReblogButton() {
|
void hideReblogButton() {
|
||||||
reblogButton.setVisibility(GONE);
|
reblogButton.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
@@ -87,15 +79,15 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
return "blogPost" + id.hashCode();
|
return "blogPost" + id.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bindItem(@Nullable BlogPostItem item) {
|
void bindItem(BlogPostItem item) {
|
||||||
if (item == null) return;
|
|
||||||
|
|
||||||
setTransitionName(item.getId());
|
setTransitionName(item.getId());
|
||||||
if (!fullText) {
|
if (!fullText) {
|
||||||
layout.setClickable(true);
|
layout.setClickable(true);
|
||||||
layout.setOnClickListener(v -> listener.onBlogPostClick(item));
|
layout.setOnClickListener(v -> listener.onBlogPostClick(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isReblog = item instanceof BlogCommentItem;
|
||||||
|
|
||||||
// author and date
|
// author and date
|
||||||
BlogPostHeader post = item.getPostHeader();
|
BlogPostHeader post = item.getPostHeader();
|
||||||
author.setAuthor(post.getAuthor(), post.getAuthorInfo());
|
author.setAuthor(post.getAuthor(), post.getAuthorInfo());
|
||||||
@@ -103,7 +95,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
author.setPersona(
|
author.setPersona(
|
||||||
item.isRssFeed() ? AuthorView.RSS_FEED : AuthorView.NORMAL);
|
item.isRssFeed() ? AuthorView.RSS_FEED : AuthorView.NORMAL);
|
||||||
// TODO make author clickable more often #624
|
// TODO make author clickable more often #624
|
||||||
if (!fullText && item.getHeader().getType() == POST) {
|
if (authorClickable && !isReblog) {
|
||||||
author.setAuthorClickable(v -> listener.onAuthorClick(item));
|
author.setAuthorClickable(v -> listener.onAuthorClick(item));
|
||||||
} else {
|
} else {
|
||||||
author.setAuthorNotClickable();
|
author.setAuthorNotClickable();
|
||||||
@@ -114,7 +106,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
if (fullText) {
|
if (fullText) {
|
||||||
text.setText(postText);
|
text.setText(postText);
|
||||||
text.setTextIsSelectable(true);
|
text.setTextIsSelectable(true);
|
||||||
makeLinksClickable(text, fragmentManager);
|
makeLinksClickable(text, listener::onLinkClick);
|
||||||
} else {
|
} else {
|
||||||
text.setTextIsSelectable(false);
|
text.setTextIsSelectable(false);
|
||||||
if (postText.length() > TEASER_LENGTH)
|
if (postText.length() > TEASER_LENGTH)
|
||||||
@@ -132,32 +124,33 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
|
|
||||||
// comments
|
// comments
|
||||||
commentContainer.removeAllViews();
|
commentContainer.removeAllViews();
|
||||||
if (item instanceof BlogCommentItem) {
|
if (isReblog) {
|
||||||
onBindComment((BlogCommentItem) item);
|
onBindComment((BlogCommentItem) item, authorClickable);
|
||||||
} else {
|
} else {
|
||||||
reblogger.setVisibility(GONE);
|
reblogger.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onBindComment(BlogCommentItem item) {
|
private void onBindComment(BlogCommentItem item, boolean authorClickable) {
|
||||||
// reblogger
|
// reblogger
|
||||||
reblogger.setAuthor(item.getAuthor(), item.getAuthorInfo());
|
reblogger.setAuthor(item.getAuthor(), item.getAuthorInfo());
|
||||||
reblogger.setDate(item.getTimestamp());
|
reblogger.setDate(item.getTimestamp());
|
||||||
if (!fullText) {
|
if (authorClickable) {
|
||||||
reblogger.setAuthorClickable(v -> listener.onAuthorClick(item));
|
reblogger.setAuthorClickable(v -> listener.onAuthorClick(item));
|
||||||
|
} else {
|
||||||
|
reblogger.setAuthorNotClickable();
|
||||||
}
|
}
|
||||||
reblogger.setVisibility(VISIBLE);
|
reblogger.setVisibility(VISIBLE);
|
||||||
reblogger.setPersona(AuthorView.REBLOGGER);
|
reblogger.setPersona(REBLOGGER);
|
||||||
|
|
||||||
author.setPersona(item.getHeader().getRootPost().isRssFeed() ?
|
author.setPersona(item.getHeader().getRootPost().isRssFeed() ?
|
||||||
AuthorView.RSS_FEED_REBLOGGED :
|
RSS_FEED_REBLOGGED : COMMENTER);
|
||||||
AuthorView.COMMENTER);
|
|
||||||
|
|
||||||
// comments
|
// comments
|
||||||
|
// TODO use nested RecyclerView instead like we do for Image Attachments
|
||||||
for (BlogCommentHeader c : item.getComments()) {
|
for (BlogCommentHeader c : item.getComments()) {
|
||||||
View v = LayoutInflater.from(ctx)
|
View v = LayoutInflater.from(ctx).inflate(
|
||||||
.inflate(R.layout.list_item_blog_comment,
|
R.layout.list_item_blog_comment, commentContainer, false);
|
||||||
commentContainer, false);
|
|
||||||
|
|
||||||
AuthorView author = v.findViewById(R.id.authorView);
|
AuthorView author = v.findViewById(R.id.authorView);
|
||||||
TextView text = v.findViewById(R.id.textView);
|
TextView text = v.findViewById(R.id.textView);
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Application;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.bramble.api.sync.event.GroupRemovedEvent;
|
import org.briarproject.bramble.api.sync.event.GroupRemovedEvent;
|
||||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
import org.briarproject.briar.android.sharing.SharingController;
|
||||||
|
import org.briarproject.briar.android.sharing.SharingController.SharingInfo;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
import org.briarproject.briar.api.blog.BlogInvitationResponse;
|
import org.briarproject.briar.api.blog.BlogInvitationResponse;
|
||||||
@@ -35,85 +35,54 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
class BlogControllerImpl extends BaseControllerImpl
|
class BlogViewModel extends BaseViewModel {
|
||||||
implements ActivityLifecycleController, BlogController, EventListener {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG = getLogger(BlogViewModel.class.getName());
|
||||||
Logger.getLogger(BlogControllerImpl.class.getName());
|
|
||||||
|
|
||||||
private final BlogSharingManager blogSharingManager;
|
private final BlogSharingManager blogSharingManager;
|
||||||
|
private final SharingController sharingController;
|
||||||
|
|
||||||
// UI thread
|
private volatile GroupId groupId;
|
||||||
@Nullable
|
|
||||||
private BlogSharingListener listener;
|
|
||||||
|
|
||||||
private volatile GroupId groupId = null;
|
private final MutableLiveData<BlogItem> blog = new MutableLiveData<>();
|
||||||
|
private final MutableLiveData<Boolean> blogRemoved =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BlogControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
BlogViewModel(Application application,
|
||||||
LifecycleManager lifecycleManager, EventBus eventBus,
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager,
|
||||||
|
TransactionManager db,
|
||||||
|
AndroidExecutor androidExecutor,
|
||||||
|
EventBus eventBus,
|
||||||
|
IdentityManager identityManager,
|
||||||
AndroidNotificationManager notificationManager,
|
AndroidNotificationManager notificationManager,
|
||||||
IdentityManager identityManager, BlogManager blogManager,
|
BlogManager blogManager,
|
||||||
BlogSharingManager blogSharingManager) {
|
BlogSharingManager blogSharingManager,
|
||||||
super(dbExecutor, lifecycleManager, eventBus, notificationManager,
|
SharingController sharingController) {
|
||||||
identityManager, blogManager);
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
||||||
|
eventBus, identityManager, notificationManager, blogManager);
|
||||||
this.blogSharingManager = blogSharingManager;
|
this.blogSharingManager = blogSharingManager;
|
||||||
}
|
this.sharingController = sharingController;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreate(Activity activity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityStart() {
|
|
||||||
super.onStart();
|
|
||||||
notificationManager.blockNotification(groupId);
|
|
||||||
notificationManager.clearBlogPostNotification(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityStop() {
|
|
||||||
super.onStop();
|
|
||||||
notificationManager.unblockNotification(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityDestroy() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setGroupId(GroupId g) {
|
|
||||||
groupId = g;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBlogSharingListener(BlogSharingListener listener) {
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unsetBlogSharingListener(BlogSharingListener listener) {
|
|
||||||
if (this.listener == listener) this.listener = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (groupId == null || listener == null)
|
|
||||||
throw new IllegalStateException();
|
|
||||||
if (e instanceof BlogPostAddedEvent) {
|
if (e instanceof BlogPostAddedEvent) {
|
||||||
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
||||||
if (b.getGroupId().equals(groupId)) {
|
if (b.getGroupId().equals(groupId)) {
|
||||||
LOG.info("Blog post added");
|
LOG.info("Blog post added");
|
||||||
listener.onBlogPostAdded(b.getHeader(), b.isLocal());
|
onBlogPostAdded(b.getHeader(), b.isLocal());
|
||||||
}
|
}
|
||||||
} else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
} else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
||||||
BlogInvitationResponseReceivedEvent b =
|
BlogInvitationResponseReceivedEvent b =
|
||||||
@@ -121,41 +90,36 @@ class BlogControllerImpl extends BaseControllerImpl
|
|||||||
BlogInvitationResponse r = b.getMessageHeader();
|
BlogInvitationResponse r = b.getMessageHeader();
|
||||||
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
||||||
LOG.info("Blog invitation accepted");
|
LOG.info("Blog invitation accepted");
|
||||||
listener.onBlogInvitationAccepted(b.getContactId());
|
sharingController.add(b.getContactId());
|
||||||
}
|
}
|
||||||
} else if (e instanceof ContactLeftShareableEvent) {
|
} else if (e instanceof ContactLeftShareableEvent) {
|
||||||
ContactLeftShareableEvent s = (ContactLeftShareableEvent) e;
|
ContactLeftShareableEvent s = (ContactLeftShareableEvent) e;
|
||||||
if (s.getGroupId().equals(groupId)) {
|
if (s.getGroupId().equals(groupId)) {
|
||||||
LOG.info("Blog left by contact");
|
LOG.info("Blog left by contact");
|
||||||
listener.onBlogLeft(s.getContactId());
|
sharingController.remove(s.getContactId());
|
||||||
}
|
}
|
||||||
} else if (e instanceof GroupRemovedEvent) {
|
} else if (e instanceof GroupRemovedEvent) {
|
||||||
GroupRemovedEvent g = (GroupRemovedEvent) e;
|
GroupRemovedEvent g = (GroupRemovedEvent) e;
|
||||||
if (g.getGroup().getId().equals(groupId)) {
|
if (g.getGroup().getId().equals(groupId)) {
|
||||||
LOG.info("Blog removed");
|
LOG.info("Blog removed");
|
||||||
listener.onBlogRemoved();
|
blogRemoved.setValue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void loadBlogPosts(
|
* Set this before calling any other methods.
|
||||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
*/
|
||||||
if (groupId == null) throw new IllegalStateException();
|
@UiThread
|
||||||
loadBlogPosts(groupId, handler);
|
public void setGroupId(GroupId groupId, boolean loadAllPosts) {
|
||||||
|
if (this.groupId == groupId) return; // configuration change
|
||||||
|
this.groupId = groupId;
|
||||||
|
loadBlog(groupId);
|
||||||
|
if (loadAllPosts) loadBlogPosts(groupId);
|
||||||
|
loadSharingContacts(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void loadBlog(GroupId groupId) {
|
||||||
public void loadBlogPost(MessageId m,
|
|
||||||
ResultExceptionHandler<BlogPostItem, DbException> handler) {
|
|
||||||
if (groupId == null) throw new IllegalStateException();
|
|
||||||
loadBlogPost(groupId, m, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadBlog(
|
|
||||||
ResultExceptionHandler<BlogItem, DbException> handler) {
|
|
||||||
if (groupId == null) throw new IllegalStateException();
|
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
long start = now();
|
long start = now();
|
||||||
@@ -163,50 +127,65 @@ class BlogControllerImpl extends BaseControllerImpl
|
|||||||
Blog b = blogManager.getBlog(groupId);
|
Blog b = blogManager.getBlog(groupId);
|
||||||
boolean ours = a.getId().equals(b.getAuthor().getId());
|
boolean ours = a.getId().equals(b.getAuthor().getId());
|
||||||
boolean removable = blogManager.canBeRemoved(b);
|
boolean removable = blogManager.canBeRemoved(b);
|
||||||
BlogItem blog = new BlogItem(b, ours, removable);
|
blog.postValue(new BlogItem(b, ours, removable));
|
||||||
logDuration(LOG, "Loading blog", start);
|
logDuration(LOG, "Loading blog", start);
|
||||||
handler.onResult(blog);
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
handleException(e);
|
||||||
handler.onException(e);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void blockAndClearNotifications() {
|
||||||
public void deleteBlog(ResultExceptionHandler<Void, DbException> handler) {
|
notificationManager.blockNotification(groupId);
|
||||||
if (groupId == null) throw new IllegalStateException();
|
notificationManager.clearBlogPostNotification(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void unblockNotifications() {
|
||||||
|
notificationManager.unblockNotification(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadBlogPosts(GroupId groupId) {
|
||||||
|
loadFromDb(txn -> new ListUpdate(null, loadBlogPosts(txn, groupId)),
|
||||||
|
blogPosts::setValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadSharingContacts(GroupId groupId) {
|
||||||
|
runOnDbThread(true, txn -> {
|
||||||
|
Collection<Contact> contacts =
|
||||||
|
blogSharingManager.getSharedWith(txn, groupId);
|
||||||
|
txn.attach(() -> onSharingContactsLoaded(contacts));
|
||||||
|
}, this::handleException);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void onSharingContactsLoaded(Collection<Contact> contacts) {
|
||||||
|
Collection<ContactId> contactIds = new ArrayList<>(contacts.size());
|
||||||
|
for (Contact c : contacts) contactIds.add(c.getId());
|
||||||
|
sharingController.addAll(contactIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteBlog() {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
long start = now();
|
long start = now();
|
||||||
Blog b = blogManager.getBlog(groupId);
|
Blog b = blogManager.getBlog(groupId);
|
||||||
blogManager.removeBlog(b);
|
blogManager.removeBlog(b);
|
||||||
logDuration(LOG, "Removing blog", start);
|
logDuration(LOG, "Removing blog", start);
|
||||||
handler.onResult(null);
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
handleException(e);
|
||||||
handler.onException(e);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
LiveData<BlogItem> getBlog() {
|
||||||
public void loadSharingContacts(
|
return blog;
|
||||||
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
|
||||||
if (groupId == null) throw new IllegalStateException();
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
Collection<Contact> contacts =
|
|
||||||
blogSharingManager.getSharedWith(groupId);
|
|
||||||
Collection<ContactId> contactIds =
|
|
||||||
new ArrayList<>(contacts.size());
|
|
||||||
for (Contact c : contacts) contactIds.add(c.getId());
|
|
||||||
handler.onResult(contactIds);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
handler.onException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveData<Boolean> getBlogRemoved() {
|
||||||
|
return blogRemoved;
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<SharingInfo> getSharingInfo() {
|
||||||
|
return sharingController.getSharingInfo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public interface FeedController extends BaseController {
|
|
||||||
|
|
||||||
void loadBlogPosts(
|
|
||||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler);
|
|
||||||
|
|
||||||
void loadPersonalBlog(ResultExceptionHandler<Blog, DbException> handler);
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void setFeedListener(FeedListener listener);
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void unsetFeedListener(FeedListener listener);
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
interface FeedListener extends BlogListener {
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void onBlogAdded();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.db.NoSuchGroupException;
|
|
||||||
import org.briarproject.bramble.api.db.NoSuchMessageException;
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.event.GroupAddedEvent;
|
|
||||||
import org.briarproject.bramble.api.sync.event.GroupRemovedEvent;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
|
||||||
import org.briarproject.briar.api.blog.BlogManager;
|
|
||||||
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
|
||||||
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class FeedControllerImpl extends BaseControllerImpl implements FeedController {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(FeedControllerImpl.class.getName());
|
|
||||||
|
|
||||||
// UI thread
|
|
||||||
@Nullable
|
|
||||||
private FeedListener listener;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
|
||||||
LifecycleManager lifecycleManager, EventBus eventBus,
|
|
||||||
AndroidNotificationManager notificationManager,
|
|
||||||
IdentityManager identityManager, BlogManager blogManager) {
|
|
||||||
super(dbExecutor, lifecycleManager, eventBus, notificationManager,
|
|
||||||
identityManager, blogManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
if (listener == null) throw new IllegalStateException();
|
|
||||||
notificationManager.blockAllBlogPostNotifications();
|
|
||||||
notificationManager.clearAllBlogPostNotifications();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
notificationManager.unblockAllBlogPostNotifications();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFeedListener(FeedListener listener) {
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unsetFeedListener(FeedListener listener) {
|
|
||||||
if (this.listener == listener) this.listener = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (listener == null) throw new IllegalStateException();
|
|
||||||
if (e instanceof BlogPostAddedEvent) {
|
|
||||||
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
|
||||||
LOG.info("Blog post added");
|
|
||||||
listener.onBlogPostAdded(b.getHeader(), b.isLocal());
|
|
||||||
} else if (e instanceof GroupAddedEvent) {
|
|
||||||
GroupAddedEvent g = (GroupAddedEvent) e;
|
|
||||||
if (g.getGroup().getClientId().equals(CLIENT_ID)) {
|
|
||||||
LOG.info("Blog added");
|
|
||||||
listener.onBlogAdded();
|
|
||||||
}
|
|
||||||
} else if (e instanceof GroupRemovedEvent) {
|
|
||||||
GroupRemovedEvent g = (GroupRemovedEvent) e;
|
|
||||||
if (g.getGroup().getClientId().equals(CLIENT_ID)) {
|
|
||||||
LOG.info("Blog removed");
|
|
||||||
listener.onBlogRemoved();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadBlogPosts(
|
|
||||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
long start = now();
|
|
||||||
Collection<BlogPostItem> posts = new ArrayList<>();
|
|
||||||
for (Blog b : blogManager.getBlogs()) {
|
|
||||||
try {
|
|
||||||
posts.addAll(loadItems(b.getId()));
|
|
||||||
} catch (NoSuchGroupException | NoSuchMessageException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logDuration(LOG, "Loading all posts", start);
|
|
||||||
handler.onResult(posts);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
handler.onException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadPersonalBlog(
|
|
||||||
ResultExceptionHandler<Blog, DbException> handler) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
long start = now();
|
|
||||||
Author a = identityManager.getLocalAuthor();
|
|
||||||
Blog b = blogManager.getPersonalBlog(a);
|
|
||||||
logDuration(LOG, "Loading personal blog", start);
|
|
||||||
handler.onResult(b);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
handler.onException(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.blog;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -10,53 +9,43 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.blog.FeedController.FeedListener;
|
import org.briarproject.briar.android.blog.BaseViewModel.ListUpdate;
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
|
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||||
import static com.google.android.material.snackbar.Snackbar.LENGTH_LONG;
|
import static com.google.android.material.snackbar.Snackbar.LENGTH_LONG;
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_WRITE_BLOG_POST;
|
import static org.briarproject.briar.android.blog.BlogPostFragment.POST_ID;
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class FeedFragment extends BaseFragment implements
|
public class FeedFragment extends BaseFragment
|
||||||
OnBlogPostClickListener, FeedListener {
|
implements OnBlogPostClickListener {
|
||||||
|
|
||||||
public final static String TAG = FeedFragment.class.getName();
|
public final static String TAG = FeedFragment.class.getName();
|
||||||
private static final Logger LOG = Logger.getLogger(TAG);
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedController feedController;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
private BlogPostAdapter adapter;
|
private FeedViewModel viewModel;
|
||||||
|
private final BlogPostAdapter adapter = new BlogPostAdapter(true, this);
|
||||||
private LinearLayoutManager layoutManager;
|
private LinearLayoutManager layoutManager;
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
@Nullable
|
|
||||||
private Blog personalBlog;
|
|
||||||
@Nullable
|
|
||||||
private Parcelable layoutManagerState;
|
|
||||||
|
|
||||||
public static FeedFragment newInstance() {
|
public static FeedFragment newInstance() {
|
||||||
FeedFragment f = new FeedFragment();
|
FeedFragment f = new FeedFragment();
|
||||||
@@ -70,7 +59,8 @@ public class FeedFragment extends BaseFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
feedController.setFeedListener(this);
|
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||||
|
.get(FeedViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -82,9 +72,6 @@ public class FeedFragment extends BaseFragment implements
|
|||||||
|
|
||||||
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
||||||
|
|
||||||
adapter =
|
|
||||||
new BlogPostAdapter(getActivity(), this, getFragmentManager());
|
|
||||||
|
|
||||||
layoutManager = new LinearLayoutManager(getActivity());
|
layoutManager = new LinearLayoutManager(getActivity());
|
||||||
list = v.findViewById(R.id.postList);
|
list = v.findViewById(R.id.postList);
|
||||||
list.setLayoutManager(layoutManager);
|
list.setLayoutManager(layoutManager);
|
||||||
@@ -93,103 +80,39 @@ public class FeedFragment extends BaseFragment implements
|
|||||||
list.setEmptyText(R.string.blogs_feed_empty_state);
|
list.setEmptyText(R.string.blogs_feed_empty_state);
|
||||||
list.setEmptyAction(R.string.blogs_feed_empty_state_action);
|
list.setEmptyAction(R.string.blogs_feed_empty_state_action);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
viewModel.getBlogPosts().observe(getViewLifecycleOwner(), result ->
|
||||||
layoutManagerState =
|
result.onError(this::handleException)
|
||||||
savedInstanceState.getParcelable("layoutManager");
|
.onSuccess(this::onBlogPostsLoaded)
|
||||||
}
|
);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode,
|
|
||||||
@Nullable Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
|
|
||||||
// The BlogPostAddedEvent arrives when the controller is not listening
|
|
||||||
if (requestCode == REQUEST_WRITE_BLOG_POST && resultCode == RESULT_OK) {
|
|
||||||
showSnackBar(R.string.blogs_blog_post_created);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
feedController.onStart();
|
viewModel.blockAndClearAllBlogPostNotifications();
|
||||||
list.startPeriodicUpdate();
|
list.startPeriodicUpdate();
|
||||||
loadPersonalBlog();
|
|
||||||
loadBlogPosts(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
feedController.onStop();
|
viewModel.unblockAllBlogPostNotifications();
|
||||||
adapter.clear();
|
|
||||||
list.showProgressBar();
|
|
||||||
list.stopPeriodicUpdate();
|
list.stopPeriodicUpdate();
|
||||||
// TODO save list position in database/preferences?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void onBlogPostsLoaded(ListUpdate update) {
|
||||||
public void onDestroy() {
|
adapter.submitList(update.getItems(), () -> {
|
||||||
super.onDestroy();
|
Boolean wasLocal = update.getPostAddedWasLocal();
|
||||||
feedController.unsetFeedListener(this);
|
if (wasLocal != null && wasLocal) {
|
||||||
}
|
showSnackBar(R.string.blogs_blog_post_created);
|
||||||
|
} else if (wasLocal != null) {
|
||||||
@Override
|
showSnackBar(R.string.blogs_blog_post_received);
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
}
|
||||||
super.onSaveInstanceState(outState);
|
viewModel.resetLocalUpdate();
|
||||||
if (layoutManager != null) {
|
list.showData();
|
||||||
layoutManagerState = layoutManager.onSaveInstanceState();
|
});
|
||||||
outState.putParcelable("layoutManager", layoutManagerState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadPersonalBlog() {
|
|
||||||
feedController.loadPersonalBlog(
|
|
||||||
new UiResultExceptionHandler<Blog, DbException>(this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(Blog b) {
|
|
||||||
personalBlog = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadBlogPosts(boolean clear) {
|
|
||||||
int revision = adapter.getRevision();
|
|
||||||
feedController.loadBlogPosts(
|
|
||||||
new UiResultExceptionHandler<Collection<BlogPostItem>, DbException>(
|
|
||||||
this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(Collection<BlogPostItem> posts) {
|
|
||||||
if (revision == adapter.getRevision()) {
|
|
||||||
adapter.incrementRevision();
|
|
||||||
if (clear) adapter.setItems(posts);
|
|
||||||
else adapter.addAll(posts);
|
|
||||||
if (posts.isEmpty()) list.showData();
|
|
||||||
if (layoutManagerState == null) {
|
|
||||||
list.scrollToPosition(0); // Scroll to the top
|
|
||||||
} else {
|
|
||||||
layoutManager.onRestoreInstanceState(
|
|
||||||
layoutManagerState);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG.info("Concurrent update, reloading");
|
|
||||||
loadBlogPosts(clear);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -200,67 +123,46 @@ public class FeedFragment extends BaseFragment implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (personalBlog == null) return false;
|
int itemId = item.getItemId();
|
||||||
switch (item.getItemId()) {
|
if (itemId == R.id.action_write_blog_post) {
|
||||||
case R.id.action_write_blog_post:
|
Blog personalBlog = viewModel.getPersonalBlog().getValue();
|
||||||
Intent i1 =
|
if (personalBlog == null) return false;
|
||||||
new Intent(getActivity(), WriteBlogPostActivity.class);
|
Intent i = new Intent(getActivity(), WriteBlogPostActivity.class);
|
||||||
i1.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
i.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
||||||
startActivityForResult(i1, REQUEST_WRITE_BLOG_POST);
|
startActivity(i);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_rss_feeds_import:
|
} else if (itemId == R.id.action_rss_feeds_import) {
|
||||||
Intent i2 =
|
Intent i = new Intent(getActivity(), RssFeedImportActivity.class);
|
||||||
new Intent(getActivity(), RssFeedImportActivity.class);
|
startActivity(i);
|
||||||
startActivity(i2);
|
return true;
|
||||||
return true;
|
} else if (itemId == R.id.action_rss_feeds_manage) {
|
||||||
case R.id.action_rss_feeds_manage:
|
Blog personalBlog = viewModel.getPersonalBlog().getValue();
|
||||||
Intent i3 =
|
if (personalBlog == null) return false;
|
||||||
new Intent(getActivity(), RssFeedManageActivity.class);
|
Intent i = new Intent(getActivity(), RssFeedManageActivity.class);
|
||||||
i3.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
i.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
||||||
startActivity(i3);
|
startActivity(i);
|
||||||
return true;
|
return true;
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
}
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlogPostAdded(BlogPostHeader header, boolean local) {
|
|
||||||
feedController.loadBlogPost(header,
|
|
||||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
|
||||||
this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(BlogPostItem post) {
|
|
||||||
adapter.incrementRevision();
|
|
||||||
adapter.add(post);
|
|
||||||
if (local) {
|
|
||||||
showSnackBar(R.string.blogs_blog_post_created);
|
|
||||||
} else {
|
|
||||||
showSnackBar(R.string.blogs_blog_post_received);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlogPostClick(BlogPostItem post) {
|
public void onBlogPostClick(BlogPostItem post) {
|
||||||
FeedPostFragment f =
|
Intent i = getBlogActivityIntent(post.getGroupId());
|
||||||
FeedPostFragment.newInstance(post.getGroupId(), post.getId());
|
i.putExtra(POST_ID, post.getId().getBytes());
|
||||||
showNextFragment(f);
|
requireContext().startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAuthorClick(BlogPostItem post) {
|
public void onAuthorClick(BlogPostItem post) {
|
||||||
Intent i = new Intent(getContext(), BlogActivity.class);
|
Intent i = getBlogActivityIntent(post.getGroupId());
|
||||||
i.putExtra(GROUP_ID, post.getGroupId().getBytes());
|
requireContext().startActivity(i);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
}
|
||||||
getContext().startActivity(i);
|
|
||||||
|
@Override
|
||||||
|
public void onLinkClick(String url) {
|
||||||
|
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
||||||
|
f.show(getParentFragmentManager(), f.getUniqueTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -268,6 +170,13 @@ public class FeedFragment extends BaseFragment implements
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Intent getBlogActivityIntent(GroupId groupId) {
|
||||||
|
Intent i = new Intent(requireContext(), BlogActivity.class);
|
||||||
|
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
private void showSnackBar(int stringRes) {
|
private void showSnackBar(int stringRes) {
|
||||||
int firstVisible =
|
int firstVisible =
|
||||||
layoutManager.findFirstCompletelyVisibleItemPosition();
|
layoutManager.findFirstCompletelyVisibleItemPosition();
|
||||||
@@ -283,14 +192,4 @@ public class FeedFragment extends BaseFragment implements
|
|||||||
sb.make(list, stringRes, LENGTH_LONG).show();
|
sb.make(list, stringRes, LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlogAdded() {
|
|
||||||
loadBlogPosts(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlogRemoved() {
|
|
||||||
loadBlogPosts(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public class FeedPostFragment extends BasePostFragment {
|
|
||||||
|
|
||||||
private static final String TAG = FeedPostFragment.class.getName();
|
|
||||||
|
|
||||||
private GroupId blogId;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedController feedController;
|
|
||||||
|
|
||||||
static FeedPostFragment newInstance(GroupId blogId, MessageId postId) {
|
|
||||||
FeedPostFragment f = new FeedPostFragment();
|
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putByteArray(GROUP_ID, blogId.getBytes());
|
|
||||||
bundle.putByteArray(POST_ID, postId.getBytes());
|
|
||||||
|
|
||||||
f.setArguments(bundle);
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void injectFragment(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater,
|
|
||||||
@Nullable ViewGroup container,
|
|
||||||
@Nullable Bundle savedInstanceState) {
|
|
||||||
Bundle args = requireArguments();
|
|
||||||
byte[] b = args.getByteArray(GROUP_ID);
|
|
||||||
if (b == null) throw new IllegalStateException("No group ID in args");
|
|
||||||
blogId = new GroupId(b);
|
|
||||||
|
|
||||||
return super.onCreateView(inflater, container, savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUniqueTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
feedController.loadBlogPost(blogId, postId,
|
|
||||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
|
||||||
this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(BlogPostItem post) {
|
|
||||||
onBlogPostLoaded(post);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.sync.event.GroupRemovedEvent;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
|
import org.briarproject.briar.api.blog.BlogManager;
|
||||||
|
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
class FeedViewModel extends BaseViewModel {
|
||||||
|
|
||||||
|
private static final Logger LOG = getLogger(FeedViewModel.class.getName());
|
||||||
|
|
||||||
|
private final MutableLiveData<Blog> personalBlog = new MutableLiveData<>();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedViewModel(Application application,
|
||||||
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager,
|
||||||
|
TransactionManager db,
|
||||||
|
AndroidExecutor androidExecutor,
|
||||||
|
EventBus eventBus,
|
||||||
|
IdentityManager identityManager,
|
||||||
|
AndroidNotificationManager notificationManager,
|
||||||
|
BlogManager blogManager) {
|
||||||
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
||||||
|
eventBus, identityManager, notificationManager, blogManager);
|
||||||
|
loadPersonalBlog();
|
||||||
|
loadAllBlogPosts();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
if (e instanceof BlogPostAddedEvent) {
|
||||||
|
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
||||||
|
LOG.info("Blog post added");
|
||||||
|
onBlogPostAdded(b.getHeader(), b.isLocal());
|
||||||
|
} else if (e instanceof GroupRemovedEvent) {
|
||||||
|
GroupRemovedEvent g = (GroupRemovedEvent) e;
|
||||||
|
if (g.getGroup().getClientId().equals(CLIENT_ID)) {
|
||||||
|
LOG.info("Blog removed");
|
||||||
|
onBlogRemoved(g.getGroup().getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void blockAndClearAllBlogPostNotifications() {
|
||||||
|
notificationManager.blockAllBlogPostNotifications();
|
||||||
|
notificationManager.clearAllBlogPostNotifications();
|
||||||
|
}
|
||||||
|
|
||||||
|
void unblockAllBlogPostNotifications() {
|
||||||
|
notificationManager.unblockAllBlogPostNotifications();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadPersonalBlog() {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
long start = now();
|
||||||
|
Author a = identityManager.getLocalAuthor();
|
||||||
|
Blog b = blogManager.getPersonalBlog(a);
|
||||||
|
logDuration(LOG, "Loading personal blog", start);
|
||||||
|
personalBlog.postValue(b);
|
||||||
|
} catch (DbException e) {
|
||||||
|
handleException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<Blog> getPersonalBlog() {
|
||||||
|
return personalBlog;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAllBlogPosts() {
|
||||||
|
loadFromDb(this::loadAllBlogPosts, blogPosts::setValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
private ListUpdate loadAllBlogPosts(Transaction txn)
|
||||||
|
throws DbException {
|
||||||
|
long start = now();
|
||||||
|
List<BlogPostItem> posts = new ArrayList<>();
|
||||||
|
for (GroupId g : blogManager.getBlogIds(txn)) {
|
||||||
|
posts.addAll(loadBlogPosts(txn, g));
|
||||||
|
}
|
||||||
|
Collections.sort(posts);
|
||||||
|
logDuration(LOG, "Loading all posts", start);
|
||||||
|
return new ListUpdate(null, posts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void onBlogRemoved(GroupId g) {
|
||||||
|
List<BlogPostItem> items = removeListItems(getBlogPostItems(), item ->
|
||||||
|
item.getGroupId().equals(g)
|
||||||
|
);
|
||||||
|
if (items != null) {
|
||||||
|
blogPosts.setValue(new LiveResult<>(new ListUpdate(null, items)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,4 +5,6 @@ interface OnBlogPostClickListener {
|
|||||||
void onBlogPostClick(BlogPostItem post);
|
void onBlogPostClick(BlogPostItem post);
|
||||||
|
|
||||||
void onAuthorClick(BlogPostItem post);
|
void onAuthorClick(BlogPostItem post);
|
||||||
|
|
||||||
|
void onLinkClick(String url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
|
|||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
|
import static org.briarproject.briar.android.blog.BlogPostFragment.POST_ID;
|
||||||
|
|
||||||
public class ReblogActivity extends BriarActivity implements
|
public class ReblogActivity extends BriarActivity implements
|
||||||
BaseFragmentListener {
|
BaseFragmentListener {
|
||||||
@@ -39,13 +39,11 @@ public class ReblogActivity extends BriarActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
case android.R.id.home:
|
onBackPressed();
|
||||||
onBackPressed();
|
return true;
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,19 +7,17 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.controller.handler.UiExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
|
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,13 +25,15 @@ import java.util.List;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import static android.view.View.FOCUS_DOWN;
|
import static android.view.View.FOCUS_DOWN;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.INVISIBLE;
|
import static android.view.View.INVISIBLE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
|
import static org.briarproject.briar.android.blog.BlogPostFragment.POST_ID;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -42,12 +42,13 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
|
|
||||||
public static final String TAG = ReblogFragment.class.getName();
|
public static final String TAG = ReblogFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BlogViewModel viewModel;
|
||||||
private ViewHolder ui;
|
private ViewHolder ui;
|
||||||
private BlogPostItem item;
|
private BlogPostItem item;
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedController feedController;
|
|
||||||
|
|
||||||
static ReblogFragment newInstance(GroupId groupId, MessageId messageId) {
|
static ReblogFragment newInstance(GroupId groupId, MessageId messageId) {
|
||||||
ReblogFragment f = new ReblogFragment();
|
ReblogFragment f = new ReblogFragment();
|
||||||
|
|
||||||
@@ -67,6 +68,8 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(BlogViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,30 +93,20 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
ui.input.setMaxTextLength(MAX_BLOG_POST_TEXT_LENGTH);
|
ui.input.setMaxTextLength(MAX_BLOG_POST_TEXT_LENGTH);
|
||||||
showProgressBar();
|
showProgressBar();
|
||||||
|
|
||||||
feedController.loadBlogPost(blogId, postId,
|
viewModel.loadBlogPost(blogId, postId).observe(getViewLifecycleOwner(),
|
||||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
result -> result.onError(this::handleException)
|
||||||
this) {
|
.onSuccess(this::bindViewHolder)
|
||||||
@Override
|
);
|
||||||
public void onResultUi(BlogPostItem result) {
|
|
||||||
item = result;
|
|
||||||
bindViewHolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindViewHolder() {
|
private void bindViewHolder(BlogPostItem item) {
|
||||||
if (item == null) return;
|
this.item = item;
|
||||||
|
|
||||||
hideProgressBar();
|
hideProgressBar();
|
||||||
|
|
||||||
ui.post.bindItem(item);
|
ui.post.bindItem(this.item);
|
||||||
ui.post.hideReblogButton();
|
ui.post.hideReblogButton();
|
||||||
|
|
||||||
ui.input.setReady(true);
|
ui.input.setReady(true);
|
||||||
@@ -124,13 +117,7 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
public void onSendClick(@Nullable String text,
|
public void onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers) {
|
List<AttachmentHeader> headers) {
|
||||||
ui.input.hideSoftKeyboard();
|
ui.input.hideSoftKeyboard();
|
||||||
feedController.repeatPost(item, text,
|
viewModel.repeatPost(item, text);
|
||||||
new UiExceptionHandler<DbException>(this) {
|
|
||||||
@Override
|
|
||||||
public void onExceptionUi(DbException exception) {
|
|
||||||
handleException(exception);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +131,7 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
ui.input.setVisibility(VISIBLE);
|
ui.input.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ViewHolder {
|
private class ViewHolder implements OnBlogPostClickListener {
|
||||||
|
|
||||||
private final ScrollView scrollView;
|
private final ScrollView scrollView;
|
||||||
private final ProgressBar progressBar;
|
private final ProgressBar progressBar;
|
||||||
@@ -155,18 +142,25 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
scrollView = v.findViewById(R.id.scrollView);
|
scrollView = v.findViewById(R.id.scrollView);
|
||||||
progressBar = v.findViewById(R.id.progressBar);
|
progressBar = v.findViewById(R.id.progressBar);
|
||||||
post = new BlogPostViewHolder(v.findViewById(R.id.postLayout),
|
post = new BlogPostViewHolder(v.findViewById(R.id.postLayout),
|
||||||
true, new OnBlogPostClickListener() {
|
true, this, false);
|
||||||
@Override
|
|
||||||
public void onBlogPostClick(BlogPostItem post) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAuthorClick(BlogPostItem post) {
|
|
||||||
// probably don't want to allow author clicks here
|
|
||||||
}
|
|
||||||
}, getFragmentManager());
|
|
||||||
input = v.findViewById(R.id.inputText);
|
input = v.findViewById(R.id.inputText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlogPostClick(BlogPostItem post) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthorClick(BlogPostItem post) {
|
||||||
|
// probably don't want to allow author clicks here
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLinkClick(String url) {
|
||||||
|
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
||||||
|
f.show(getParentFragmentManager(), f.getUniqueTag());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
|
|
||||||
@@ -45,8 +44,4 @@ public abstract class BaseContactListAdapter<I extends ContactItem, VH extends C
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnContactClickListener<I> {
|
|
||||||
void onItemClick(View view, I item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.view.ViewGroup;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.NullSafety;
|
import org.briarproject.bramble.api.nullsafety.NullSafety;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.DiffUtil.ItemCallback;
|
import androidx.recyclerview.widget.DiffUtil.ItemCallback;
|
||||||
import androidx.recyclerview.widget.ListAdapter;
|
import androidx.recyclerview.widget.ListAdapter;
|
||||||
@@ -16,9 +15,6 @@ import androidx.recyclerview.widget.ListAdapter;
|
|||||||
public class ContactListAdapter extends
|
public class ContactListAdapter extends
|
||||||
ListAdapter<ContactListItem, ContactListItemViewHolder> {
|
ListAdapter<ContactListItem, ContactListItemViewHolder> {
|
||||||
|
|
||||||
// TODO: using the click listener interface from BaseContactListAdapter on
|
|
||||||
// purpose here because it is entangled with ContactListItemViewHolder. At
|
|
||||||
// some point we probably want to change that.
|
|
||||||
protected final OnContactClickListener<ContactListItem> listener;
|
protected final OnContactClickListener<ContactListItem> listener;
|
||||||
|
|
||||||
public ContactListAdapter(
|
public ContactListAdapter(
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
|
||||||
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
||||||
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
||||||
import org.briarproject.briar.android.conversation.ConversationActivity;
|
import org.briarproject.briar.android.conversation.ConversationActivity;
|
||||||
@@ -34,7 +33,6 @@ import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
|||||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial.OnMenuItemClickListener;
|
import io.github.kobakei.materialfabspeeddial.FabSpeedDial.OnMenuItemClickListener;
|
||||||
|
|
||||||
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE;
|
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE;
|
||||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -102,7 +100,6 @@ public class ContactListFragment extends BaseFragment
|
|||||||
.observe(getViewLifecycleOwner(), result -> {
|
.observe(getViewLifecycleOwner(), result -> {
|
||||||
result.onError(this::handleException).onSuccess(items -> {
|
result.onError(this::handleException).onSuccess(items -> {
|
||||||
adapter.submitList(items);
|
adapter.submitList(items);
|
||||||
if (requireNonNull(items).size() == 0) list.showData();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
viewModel.getHasPendingContacts()
|
viewModel.getHasPendingContacts()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|||||||
@@ -3,70 +3,41 @@ package org.briarproject.briar.android.contact;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
|
|
||||||
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
|
|
||||||
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent;
|
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent;
|
||||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent;
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
|
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
|
||||||
import org.briarproject.briar.android.viewmodel.LiveResult;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
|
||||||
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.arch.core.util.Function;
|
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ContactListViewModel extends DbViewModel implements EventListener {
|
class ContactListViewModel extends ContactsViewModel {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(ContactListViewModel.class.getName());
|
getLogger(ContactListViewModel.class.getName());
|
||||||
|
|
||||||
private final ContactManager contactManager;
|
|
||||||
private final AuthorManager authorManager;
|
|
||||||
private final ConversationManager conversationManager;
|
|
||||||
private final ConnectionRegistry connectionRegistry;
|
|
||||||
private final EventBus eventBus;
|
|
||||||
private final AndroidNotificationManager notificationManager;
|
private final AndroidNotificationManager notificationManager;
|
||||||
|
|
||||||
private final MutableLiveData<LiveResult<List<ContactListItem>>>
|
|
||||||
contactListItems = new MutableLiveData<>();
|
|
||||||
|
|
||||||
private final MutableLiveData<Boolean> hasPendingContacts =
|
private final MutableLiveData<Boolean> hasPendingContacts =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
|
|
||||||
@@ -79,99 +50,25 @@ class ContactListViewModel extends DbViewModel implements EventListener {
|
|||||||
ConversationManager conversationManager,
|
ConversationManager conversationManager,
|
||||||
ConnectionRegistry connectionRegistry, EventBus eventBus,
|
ConnectionRegistry connectionRegistry, EventBus eventBus,
|
||||||
AndroidNotificationManager notificationManager) {
|
AndroidNotificationManager notificationManager) {
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
||||||
this.contactManager = contactManager;
|
contactManager, authorManager, conversationManager,
|
||||||
this.authorManager = authorManager;
|
connectionRegistry, eventBus);
|
||||||
this.conversationManager = conversationManager;
|
|
||||||
this.connectionRegistry = connectionRegistry;
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
this.notificationManager = notificationManager;
|
this.notificationManager = notificationManager;
|
||||||
this.eventBus.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCleared() {
|
|
||||||
super.onCleared();
|
|
||||||
eventBus.removeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadContacts() {
|
|
||||||
loadList(this::loadContacts, contactListItems::setValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ContactListItem> loadContacts(Transaction txn)
|
|
||||||
throws DbException {
|
|
||||||
long start = now();
|
|
||||||
List<ContactListItem> contacts = new ArrayList<>();
|
|
||||||
for (Contact c : contactManager.getContacts(txn)) {
|
|
||||||
ContactId id = c.getId();
|
|
||||||
AuthorInfo authorInfo = authorManager.getAuthorInfo(txn, c);
|
|
||||||
MessageTracker.GroupCount count =
|
|
||||||
conversationManager.getGroupCount(txn, id);
|
|
||||||
boolean connected = connectionRegistry.isConnected(c.getId());
|
|
||||||
contacts.add(new ContactListItem(c, authorInfo, connected, count));
|
|
||||||
}
|
|
||||||
Collections.sort(contacts);
|
|
||||||
logDuration(LOG, "Full load", start);
|
|
||||||
return contacts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (e instanceof ContactAddedEvent) {
|
super.eventOccurred(e);
|
||||||
LOG.info("Contact added, reloading");
|
if (e instanceof PendingContactAddedEvent ||
|
||||||
loadContacts();
|
|
||||||
} else if (e instanceof ContactConnectedEvent) {
|
|
||||||
updateItem(((ContactConnectedEvent) e).getContactId(),
|
|
||||||
item -> new ContactListItem(item, true), false);
|
|
||||||
} else if (e instanceof ContactDisconnectedEvent) {
|
|
||||||
updateItem(((ContactDisconnectedEvent) e).getContactId(),
|
|
||||||
item -> new ContactListItem(item, false), false);
|
|
||||||
} else if (e instanceof ContactRemovedEvent) {
|
|
||||||
LOG.info("Contact removed, removing item");
|
|
||||||
removeItem(((ContactRemovedEvent) e).getContactId());
|
|
||||||
} else if (e instanceof ConversationMessageReceivedEvent) {
|
|
||||||
LOG.info("Conversation message received, updating item");
|
|
||||||
ConversationMessageReceivedEvent<?> p =
|
|
||||||
(ConversationMessageReceivedEvent<?>) e;
|
|
||||||
ConversationMessageHeader h = p.getMessageHeader();
|
|
||||||
updateItem(p.getContactId(), item -> new ContactListItem(item, h),
|
|
||||||
true);
|
|
||||||
} else if (e instanceof PendingContactAddedEvent ||
|
|
||||||
e instanceof PendingContactRemovedEvent) {
|
e instanceof PendingContactRemovedEvent) {
|
||||||
checkForPendingContacts();
|
checkForPendingContacts();
|
||||||
} else if (e instanceof AvatarUpdatedEvent) {
|
|
||||||
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
|
||||||
updateItem(a.getContactId(), item -> new ContactListItem(item,
|
|
||||||
a.getAttachmentHeader()), false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<LiveResult<List<ContactListItem>>> getContactListItems() {
|
|
||||||
return contactListItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Boolean> getHasPendingContacts() {
|
LiveData<Boolean> getHasPendingContacts() {
|
||||||
return hasPendingContacts;
|
return hasPendingContacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateItem(ContactId c,
|
|
||||||
Function<ContactListItem, ContactListItem> replacer, boolean sort) {
|
|
||||||
List<ContactListItem> list = updateListItems(contactListItems,
|
|
||||||
itemToTest -> itemToTest.getContact().getId().equals(c),
|
|
||||||
replacer);
|
|
||||||
if (list == null) return;
|
|
||||||
if (sort) Collections.sort(list);
|
|
||||||
contactListItems.setValue(new LiveResult<>(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeItem(ContactId c) {
|
|
||||||
List<ContactListItem> list = removeListItems(contactListItems,
|
|
||||||
itemToTest -> itemToTest.getContact().getId().equals(c));
|
|
||||||
if (list == null) return;
|
|
||||||
contactListItems.setValue(new LiveResult<>(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkForPendingContacts() {
|
void checkForPendingContacts() {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
||||||
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
|
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
|
||||||
|
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent;
|
||||||
|
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
|
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||||
|
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||||
|
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.arch.core.util.Function;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactsViewModel extends DbViewModel implements EventListener {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
getLogger(ContactsViewModel.class.getName());
|
||||||
|
|
||||||
|
protected final ContactManager contactManager;
|
||||||
|
private final AuthorManager authorManager;
|
||||||
|
private final ConversationManager conversationManager;
|
||||||
|
private final ConnectionRegistry connectionRegistry;
|
||||||
|
private final EventBus eventBus;
|
||||||
|
|
||||||
|
private final MutableLiveData<LiveResult<List<ContactListItem>>>
|
||||||
|
contactListItems = new MutableLiveData<>();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ContactsViewModel(Application application,
|
||||||
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager, TransactionManager db,
|
||||||
|
AndroidExecutor androidExecutor, ContactManager contactManager,
|
||||||
|
AuthorManager authorManager,
|
||||||
|
ConversationManager conversationManager,
|
||||||
|
ConnectionRegistry connectionRegistry, EventBus eventBus) {
|
||||||
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
|
this.contactManager = contactManager;
|
||||||
|
this.authorManager = authorManager;
|
||||||
|
this.conversationManager = conversationManager;
|
||||||
|
this.connectionRegistry = connectionRegistry;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
this.eventBus.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCleared() {
|
||||||
|
super.onCleared();
|
||||||
|
eventBus.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadContacts() {
|
||||||
|
loadFromDb(this::loadContacts, contactListItems::setValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ContactListItem> loadContacts(Transaction txn)
|
||||||
|
throws DbException {
|
||||||
|
long start = now();
|
||||||
|
List<ContactListItem> contacts = new ArrayList<>();
|
||||||
|
for (Contact c : contactManager.getContacts(txn)) {
|
||||||
|
ContactId id = c.getId();
|
||||||
|
if (!displayContact(id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
AuthorInfo authorInfo = authorManager.getAuthorInfo(txn, c);
|
||||||
|
MessageTracker.GroupCount count =
|
||||||
|
conversationManager.getGroupCount(txn, id);
|
||||||
|
boolean connected = connectionRegistry.isConnected(c.getId());
|
||||||
|
contacts.add(new ContactListItem(c, authorInfo, connected, count));
|
||||||
|
}
|
||||||
|
Collections.sort(contacts);
|
||||||
|
logDuration(LOG, "Full load", start);
|
||||||
|
return contacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override this method to display only a subset of contacts.
|
||||||
|
*/
|
||||||
|
protected boolean displayContact(ContactId contactId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
if (e instanceof ContactAddedEvent) {
|
||||||
|
LOG.info("Contact added, reloading");
|
||||||
|
loadContacts();
|
||||||
|
} else if (e instanceof ContactConnectedEvent) {
|
||||||
|
updateItem(((ContactConnectedEvent) e).getContactId(),
|
||||||
|
item -> new ContactListItem(item, true), false);
|
||||||
|
} else if (e instanceof ContactDisconnectedEvent) {
|
||||||
|
updateItem(((ContactDisconnectedEvent) e).getContactId(),
|
||||||
|
item -> new ContactListItem(item, false), false);
|
||||||
|
} else if (e instanceof ContactRemovedEvent) {
|
||||||
|
LOG.info("Contact removed, removing item");
|
||||||
|
removeItem(((ContactRemovedEvent) e).getContactId());
|
||||||
|
} else if (e instanceof ConversationMessageReceivedEvent) {
|
||||||
|
LOG.info("Conversation message received, updating item");
|
||||||
|
ConversationMessageReceivedEvent<?> p =
|
||||||
|
(ConversationMessageReceivedEvent<?>) e;
|
||||||
|
ConversationMessageHeader h = p.getMessageHeader();
|
||||||
|
updateItem(p.getContactId(), item -> new ContactListItem(item, h),
|
||||||
|
true);
|
||||||
|
} else if (e instanceof AvatarUpdatedEvent) {
|
||||||
|
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
||||||
|
updateItem(a.getContactId(), item -> new ContactListItem(item,
|
||||||
|
a.getAttachmentHeader()), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<LiveResult<List<ContactListItem>>> getContactListItems() {
|
||||||
|
return contactListItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void updateItem(ContactId c,
|
||||||
|
Function<ContactListItem, ContactListItem> replacer, boolean sort) {
|
||||||
|
List<ContactListItem> list = updateListItems(getList(contactListItems),
|
||||||
|
itemToTest -> itemToTest.getContact().getId().equals(c),
|
||||||
|
replacer);
|
||||||
|
if (list == null) return;
|
||||||
|
if (sort) Collections.sort(list);
|
||||||
|
contactListItems.setValue(new LiveResult<>(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void removeItem(ContactId c) {
|
||||||
|
removeAndUpdateListItems(contactListItems,
|
||||||
|
itemToTest -> itemToTest.getContact().getId().equals(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public class LegacyContactListAdapter extends
|
|
||||||
BaseContactListAdapter<ContactListItem, ContactListItemViewHolder> {
|
|
||||||
|
|
||||||
public LegacyContactListAdapter(Context context,
|
|
||||||
OnContactClickListener<ContactListItem> listener) {
|
|
||||||
super(context, ContactListItem.class, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContactListItemViewHolder onCreateViewHolder(ViewGroup viewGroup,
|
|
||||||
int i) {
|
|
||||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
|
||||||
R.layout.list_item_contact, viewGroup, false);
|
|
||||||
|
|
||||||
return new ContactListItemViewHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(ContactListItem c1, ContactListItem c2) {
|
|
||||||
// check for all properties that influence visual
|
|
||||||
// representation of contact
|
|
||||||
if (c1.isEmpty() != c2.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (c1.getUnreadCount() != c2.getUnreadCount()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (c1.getTimestamp() != c2.getTimestamp()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return c1.isConnected() == c2.isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(ContactListItem c1, ContactListItem c2) {
|
|
||||||
return Long.compare(c2.getTimestamp(), c1.getTimestamp());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public interface OnContactClickListener<I> {
|
||||||
|
|
||||||
|
void onItemClick(View view, I item);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -124,7 +124,7 @@ public class AddContactViewModel extends DbViewModel {
|
|||||||
return addContactResult;
|
return addContactResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePendingContact(String name, PendingContact p) {
|
void updatePendingContact(String name, PendingContact p) {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
contactManager.removePendingContact(p.getId());
|
contactManager.removePendingContact(p.getId());
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.AlertDialog.Builder;
|
import androidx.appcompat.app.AlertDialog.Builder;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
|
||||||
|
|
||||||
import static android.view.View.INVISIBLE;
|
import static android.view.View.INVISIBLE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
@@ -48,6 +48,7 @@ import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
|||||||
public class NicknameFragment extends BaseFragment {
|
public class NicknameFragment extends BaseFragment {
|
||||||
|
|
||||||
private static final String TAG = NicknameFragment.class.getName();
|
private static final String TAG = NicknameFragment.class.getName();
|
||||||
|
private static final String SAVED_LINK = "savedLink";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
@@ -67,6 +68,20 @@ public class NicknameFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(AddContactViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
// When the activity (and the ViewModel) get destroyed,
|
||||||
|
// the link will not be available anymore and needs to be restored.
|
||||||
|
// TODO migrate to SavedStateViewModelFactory (once we can use it)
|
||||||
|
String savedLink = savedInstanceState.getString(SAVED_LINK);
|
||||||
|
if (savedLink != null) viewModel.setRemoteHandshakeLink(savedLink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -74,14 +89,9 @@ public class NicknameFragment extends BaseFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
if (getActivity() == null || getContext() == null) return null;
|
|
||||||
|
|
||||||
View v = inflater.inflate(R.layout.fragment_nickname,
|
View v = inflater.inflate(R.layout.fragment_nickname,
|
||||||
container, false);
|
container, false);
|
||||||
|
|
||||||
viewModel = ViewModelProviders.of(getActivity(), viewModelFactory)
|
|
||||||
.get(AddContactViewModel.class);
|
|
||||||
|
|
||||||
contactNameLayout = v.findViewById(R.id.contactNameLayout);
|
contactNameLayout = v.findViewById(R.id.contactNameLayout);
|
||||||
contactNameInput = v.findViewById(R.id.contactNameInput);
|
contactNameInput = v.findViewById(R.id.contactNameInput);
|
||||||
|
|
||||||
@@ -93,6 +103,12 @@ public class NicknameFragment extends BaseFragment {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putString(SAVED_LINK, viewModel.getRemoteHandshakeLink());
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String getNicknameOrNull() {
|
private String getNicknameOrNull() {
|
||||||
Editable text = contactNameInput.getText();
|
Editable text = contactNameInput.getText();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.contact.ContactId;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter;
|
||||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||||
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
|
||||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||||
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
|
||||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||||
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ContactSelectorAdapter extends
|
class ContactSelectorAdapter extends
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import android.view.MenuItem;
|
|||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.briarproject.briar.android.contactselection;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
package org.briarproject.briar.android.controller;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@NotNullByDefault
|
|
||||||
public interface SharingController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the listener that is called when contacts go on or offline.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void setSharingListener(SharingListener listener);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unsets the listener.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void unsetSharingListener(SharingListener listener);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when your lifecycle starts,
|
|
||||||
* so the listener will be called when information changes.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void onStart();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when your lifecycle stops,
|
|
||||||
* so that the controller knows it can stops listening to events.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void onStop();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds one contact to be tracked.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void add(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a collection of contacts to be tracked.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void addAll(Collection<ContactId> contacts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when the contact identified by c is no longer sharing
|
|
||||||
* the given group identified by GroupId g.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void remove(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of online contacts.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
int getOnlineCount();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the total number of contacts that have been added.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
int getTotalCount();
|
|
||||||
|
|
||||||
interface SharingListener {
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void onSharingInfoUpdated(int total, int online);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package org.briarproject.briar.android.controller;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent;
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@NotNullByDefault
|
|
||||||
public class SharingControllerImpl implements SharingController, EventListener {
|
|
||||||
|
|
||||||
private final EventBus eventBus;
|
|
||||||
private final ConnectionRegistry connectionRegistry;
|
|
||||||
|
|
||||||
// UI thread
|
|
||||||
private final Set<ContactId> contacts = new HashSet<>();
|
|
||||||
|
|
||||||
// UI thread
|
|
||||||
@Nullable
|
|
||||||
private SharingListener listener;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
SharingControllerImpl(EventBus eventBus,
|
|
||||||
ConnectionRegistry connectionRegistry) {
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
this.connectionRegistry = connectionRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSharingListener(SharingListener listener) {
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unsetSharingListener(SharingListener listener) {
|
|
||||||
if (this.listener == listener) this.listener = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
eventBus.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
eventBus.removeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof ContactConnectedEvent) {
|
|
||||||
setConnected(((ContactConnectedEvent) e).getContactId());
|
|
||||||
} else if (e instanceof ContactDisconnectedEvent) {
|
|
||||||
setConnected(((ContactDisconnectedEvent) e).getContactId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
private void setConnected(ContactId c) {
|
|
||||||
if (listener == null) throw new IllegalStateException();
|
|
||||||
if (contacts.contains(c)) {
|
|
||||||
int online = getOnlineCount();
|
|
||||||
listener.onSharingInfoUpdated(contacts.size(), online);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAll(Collection<ContactId> c) {
|
|
||||||
contacts.addAll(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(ContactId c) {
|
|
||||||
contacts.add(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(ContactId c) {
|
|
||||||
contacts.remove(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getOnlineCount() {
|
|
||||||
int online = 0;
|
|
||||||
for (ContactId c : contacts) {
|
|
||||||
if (connectionRegistry.isConnected(c)) online++;
|
|
||||||
}
|
|
||||||
return online;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTotalCount() {
|
|
||||||
return contacts.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android.conversation;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.transition.Slide;
|
import android.transition.Slide;
|
||||||
@@ -105,6 +106,7 @@ import androidx.recyclerview.selection.SelectionTracker.SelectionObserver;
|
|||||||
import androidx.recyclerview.selection.StorageStrategy;
|
import androidx.recyclerview.selection.StorageStrategy;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import de.hdodenhof.circleimageview.CircleImageView;
|
||||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||||
|
|
||||||
@@ -479,12 +481,10 @@ public class ConversationActivity extends BriarActivity
|
|||||||
@UiThread
|
@UiThread
|
||||||
private void displayContactOnlineStatus() {
|
private void displayContactOnlineStatus() {
|
||||||
if (connectionRegistry.isConnected(contactId)) {
|
if (connectionRegistry.isConnected(contactId)) {
|
||||||
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
toolbarStatus.setImageResource(R.drawable.contact_online);
|
||||||
ConversationActivity.this, R.drawable.contact_online));
|
|
||||||
toolbarStatus.setContentDescription(getString(R.string.online));
|
toolbarStatus.setContentDescription(getString(R.string.online));
|
||||||
} else {
|
} else {
|
||||||
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
toolbarStatus.setImageResource(R.drawable.contact_offline);
|
||||||
ConversationActivity.this, R.drawable.contact_offline));
|
|
||||||
toolbarStatus.setContentDescription(getString(R.string.offline));
|
toolbarStatus.setContentDescription(getString(R.string.offline));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -935,13 +935,16 @@ public class ConversationActivity extends BriarActivity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int color =
|
||||||
|
ContextCompat.getColor(this, R.color.briar_primary);
|
||||||
|
Drawable drawable = VectorDrawableCompat
|
||||||
|
.create(getResources(), R.drawable.ic_more_vert_accent, null);
|
||||||
new MaterialTapTargetPrompt.Builder(ConversationActivity.this,
|
new MaterialTapTargetPrompt.Builder(ConversationActivity.this,
|
||||||
R.style.OnboardingDialogTheme).setTarget(target)
|
R.style.OnboardingDialogTheme).setTarget(target)
|
||||||
.setPrimaryText(R.string.introduction_onboarding_title)
|
.setPrimaryText(R.string.introduction_onboarding_title)
|
||||||
.setSecondaryText(R.string.introduction_onboarding_text)
|
.setSecondaryText(R.string.introduction_onboarding_text)
|
||||||
.setIcon(R.drawable.ic_more_vert_accent)
|
.setIconDrawable(drawable)
|
||||||
.setBackgroundColour(
|
.setBackgroundColour(color)
|
||||||
ContextCompat.getColor(this, R.color.briar_primary))
|
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ import org.briarproject.briar.android.attachment.AttachmentItem;
|
|||||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||||
import org.briarproject.briar.android.view.PullDownLayout;
|
import org.briarproject.briar.android.view.PullDownLayout;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -293,13 +290,10 @@ public class ImageActivity extends BriarActivity
|
|||||||
|
|
||||||
@RequiresApi(api = 19)
|
@RequiresApi(api = 19)
|
||||||
private Intent getCreationIntent() {
|
private Intent getCreationIntent() {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss",
|
|
||||||
Locale.getDefault());
|
|
||||||
String fileName = sdf.format(new Date());
|
|
||||||
Intent intent = new Intent(ACTION_CREATE_DOCUMENT);
|
Intent intent = new Intent(ACTION_CREATE_DOCUMENT);
|
||||||
intent.addCategory(CATEGORY_OPENABLE);
|
intent.addCategory(CATEGORY_OPENABLE);
|
||||||
intent.setType(getVisibleAttachment().getMimeType());
|
intent.setType(getVisibleAttachment().getMimeType());
|
||||||
intent.putExtra(EXTRA_TITLE, fileName);
|
intent.putExtra(EXTRA_TITLE, viewModel.getFileName());
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,8 +225,8 @@ public class ImageViewModel extends DbViewModel implements EventListener {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFileName() {
|
String getFileName() {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss",
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd",
|
||||||
Locale.getDefault());
|
Locale.getDefault());
|
||||||
return sdf.format(new Date());
|
return sdf.format(new Date());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,12 +79,6 @@ public class ForumActivity extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
viewModel.clearForumPostNotification();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int request, int result,
|
protected void onActivityResult(int request, int result,
|
||||||
@Nullable Intent data) {
|
@Nullable Intent data) {
|
||||||
@@ -109,16 +103,16 @@ public class ForumActivity extends
|
|||||||
// Handle presses on the action bar items
|
// Handle presses on the action bar items
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
if (itemId == R.id.action_forum_share) {
|
if (itemId == R.id.action_forum_share) {
|
||||||
Intent i2 = new Intent(this, ShareForumActivity.class);
|
Intent i = new Intent(this, ShareForumActivity.class);
|
||||||
i2.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i2.putExtra(GROUP_ID, groupId.getBytes());
|
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivityForResult(i2, REQUEST_SHARE_FORUM);
|
startActivityForResult(i, REQUEST_SHARE_FORUM);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_forum_sharing_status) {
|
} else if (itemId == R.id.action_forum_sharing_status) {
|
||||||
Intent i3 = new Intent(this, ForumSharingStatusActivity.class);
|
Intent i = new Intent(this, ForumSharingStatusActivity.class);
|
||||||
i3.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i3.putExtra(GROUP_ID, groupId.getBytes());
|
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivity(i3);
|
startActivity(i);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_forum_delete) {
|
} else if (itemId == R.id.action_forum_delete) {
|
||||||
showUnsubscribeDialog();
|
showUnsubscribeDialog();
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class ForumListViewModel extends DbViewModel implements EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadForums() {
|
public void loadForums() {
|
||||||
loadList(this::loadForums, forumItems::setValue);
|
loadFromDb(this::loadForums, forumItems::setValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
@@ -145,7 +145,7 @@ class ForumListViewModel extends DbViewModel implements EventListener {
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void onForumPostReceived(GroupId g, ForumPostHeader header) {
|
private void onForumPostReceived(GroupId g, ForumPostHeader header) {
|
||||||
List<ForumListItem> list = updateListItems(forumItems,
|
List<ForumListItem> list = updateListItems(getList(forumItems),
|
||||||
itemToTest -> itemToTest.getForum().getId().equals(g),
|
itemToTest -> itemToTest.getForum().getId().equals(g),
|
||||||
itemToUpdate -> new ForumListItem(itemToUpdate, header));
|
itemToUpdate -> new ForumListItem(itemToUpdate, header));
|
||||||
if (list == null) return;
|
if (list == null) return;
|
||||||
@@ -156,11 +156,9 @@ class ForumListViewModel extends DbViewModel implements EventListener {
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void onGroupRemoved(GroupId groupId) {
|
private void onGroupRemoved(GroupId groupId) {
|
||||||
List<ForumListItem> list = removeListItems(forumItems, i ->
|
removeAndUpdateListItems(forumItems, i ->
|
||||||
i.getForum().getId().equals(groupId)
|
i.getForum().getId().equals(groupId)
|
||||||
);
|
);
|
||||||
if (list == null) return;
|
|
||||||
forumItems.setValue(new LiveResult<>(list));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadForumInvitations() {
|
void loadForumInvitations() {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
|||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
import org.briarproject.briar.api.client.PostHeader;
|
|
||||||
import org.briarproject.briar.api.forum.Forum;
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||||
import org.briarproject.briar.api.forum.ForumManager;
|
import org.briarproject.briar.api.forum.ForumManager;
|
||||||
@@ -94,8 +93,9 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||||
if (f.getGroupId().equals(groupId)) {
|
if (f.getGroupId().equals(groupId)) {
|
||||||
LOG.info("Forum post received, adding...");
|
LOG.info("Forum post received, adding...");
|
||||||
ForumPostItem item = buildItem(f.getHeader(), f.getText());
|
ForumPostItem item =
|
||||||
addItem(item);
|
new ForumPostItem(f.getHeader(), f.getText());
|
||||||
|
addItem(item, false);
|
||||||
}
|
}
|
||||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||||
ForumInvitationResponseReceivedEvent f =
|
ForumInvitationResponseReceivedEvent f =
|
||||||
@@ -116,7 +116,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearForumPostNotification() {
|
protected void clearNotifications() {
|
||||||
notificationManager.clearForumPostNotification(groupId);
|
notificationManager.clearForumPostNotification(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,15 +135,27 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadItems() {
|
public void loadItems() {
|
||||||
loadList(txn -> {
|
loadFromDb(txn -> {
|
||||||
long start = now();
|
long start = now();
|
||||||
List<ForumPostHeader> headers =
|
List<ForumPostHeader> headers =
|
||||||
forumManager.getPostHeaders(txn, groupId);
|
forumManager.getPostHeaders(txn, groupId);
|
||||||
logDuration(LOG, "Loading headers", start);
|
logDuration(LOG, "Loading headers", start);
|
||||||
return createItems(txn, headers, this::buildItem);
|
start = now();
|
||||||
|
List<ForumPostItem> items = new ArrayList<>();
|
||||||
|
for (ForumPostHeader header : headers) {
|
||||||
|
items.add(loadItem(txn, header));
|
||||||
|
}
|
||||||
|
logDuration(LOG, "Loading bodies and creating items", start);
|
||||||
|
return items;
|
||||||
}, this::setItems);
|
}, this::setItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ForumPostItem loadItem(Transaction txn, ForumPostHeader header)
|
||||||
|
throws DbException {
|
||||||
|
String text = forumManager.getPostText(txn, header.getId());
|
||||||
|
return new ForumPostItem(header, text);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createAndStoreMessage(String text,
|
public void createAndStoreMessage(String text,
|
||||||
@Nullable MessageId parentId) {
|
@Nullable MessageId parentId) {
|
||||||
@@ -171,26 +183,15 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void storePost(ForumPost msg, String text) {
|
private void storePost(ForumPost msg, String text) {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(false, txn -> {
|
||||||
try {
|
long start = now();
|
||||||
long start = now();
|
ForumPostHeader header = forumManager.addLocalPost(txn, msg);
|
||||||
ForumPostHeader header = forumManager.addLocalPost(msg);
|
logDuration(LOG, "Storing forum post", start);
|
||||||
addItemAsync(buildItem(header, text));
|
txn.attach(() -> {
|
||||||
logDuration(LOG, "Storing forum post", start);
|
ForumPostItem item = new ForumPostItem(header, text);
|
||||||
} catch (DbException e) {
|
addItem(item, true);
|
||||||
logException(LOG, WARNING, e);
|
});
|
||||||
}
|
}, e -> logException(LOG, WARNING, e));
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private ForumPostItem buildItem(ForumPostHeader header, String text) {
|
|
||||||
return new ForumPostItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String loadMessageText(Transaction txn, PostHeader header)
|
|
||||||
throws DbException {
|
|
||||||
return forumManager.getPostText(txn, header.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -205,18 +206,13 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadSharingContacts() {
|
public void loadSharingContacts() {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(true, txn -> {
|
||||||
try {
|
Collection<Contact> contacts =
|
||||||
Collection<Contact> contacts =
|
forumSharingManager.getSharedWith(txn, groupId);
|
||||||
forumSharingManager.getSharedWith(groupId);
|
Collection<ContactId> contactIds = new ArrayList<>(contacts.size());
|
||||||
Collection<ContactId> contactIds =
|
for (Contact c : contacts) contactIds.add(c.getId());
|
||||||
new ArrayList<>(contacts.size());
|
txn.attach(() -> sharingController.addAll(contactIds));
|
||||||
for (Contact c : contacts) contactIds.add(c.getId());
|
}, e -> logException(LOG, WARNING, e));
|
||||||
sharingController.addAll(contactIds);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteForum() {
|
void deleteForum() {
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|||||||
import org.briarproject.briar.android.DestroyableContext;
|
import org.briarproject.briar.android.DestroyableContext;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -47,13 +46,11 @@ public abstract class BaseFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
case android.R.id.home:
|
requireActivity().onBackPressed();
|
||||||
listener.onBackPressed();
|
return true;
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -79,6 +76,7 @@ public abstract class BaseFragment extends Fragment
|
|||||||
void handleException(Exception e);
|
void handleException(Exception e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
public void runOnUiThreadUnlessDestroyed(Runnable r) {
|
public void runOnUiThreadUnlessDestroyed(Runnable r) {
|
||||||
|
|||||||
@@ -5,74 +5,41 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
import org.briarproject.briar.android.contact.ContactListAdapter;
|
||||||
import org.briarproject.briar.android.contact.ContactListItem;
|
import org.briarproject.briar.android.contact.ContactListItem;
|
||||||
import org.briarproject.briar.android.contact.LegacyContactListAdapter;
|
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class ContactChooserFragment extends BaseFragment {
|
public class ContactChooserFragment extends BaseFragment
|
||||||
|
implements OnContactClickListener<ContactListItem> {
|
||||||
|
|
||||||
public static final String TAG = ContactChooserFragment.class.getName();
|
private static final String TAG = ContactChooserFragment.class.getName();
|
||||||
private static final Logger LOG = Logger.getLogger(TAG);
|
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private IntroductionViewModel viewModel;
|
||||||
|
private final ContactListAdapter adapter = new ContactListAdapter(this);
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
private LegacyContactListAdapter adapter;
|
|
||||||
private ContactId contactId;
|
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
|
||||||
private volatile Contact c1;
|
|
||||||
@Inject
|
|
||||||
volatile ContactManager contactManager;
|
|
||||||
@Inject
|
|
||||||
volatile AuthorManager authorManager;
|
|
||||||
@Inject
|
|
||||||
volatile ConversationManager conversationManager;
|
|
||||||
@Inject
|
|
||||||
volatile ConnectionRegistry connectionRegistry;
|
|
||||||
|
|
||||||
public static ContactChooserFragment newInstance(ContactId id) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
|
|
||||||
ContactChooserFragment fragment = new ContactChooserFragment();
|
|
||||||
args.putInt(CONTACT_ID, id.getInt());
|
|
||||||
fragment.setArguments(args);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(IntroductionViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,23 +47,20 @@ public class ContactChooserFragment extends BaseFragment {
|
|||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
View contentView = inflater.inflate(R.layout.list, container, false);
|
// change toolbar text (relevant when navigating back to this fragment)
|
||||||
|
requireActivity().setTitle(R.string.introduction_activity_title);
|
||||||
|
|
||||||
OnContactClickListener<ContactListItem> onContactClickListener =
|
View contentView = inflater.inflate(R.layout.list, container, false);
|
||||||
(view, item) -> {
|
|
||||||
if (c1 == null) throw new IllegalStateException();
|
|
||||||
Contact c2 = item.getContact();
|
|
||||||
showMessageScreen(c1, c2);
|
|
||||||
};
|
|
||||||
adapter = new LegacyContactListAdapter(requireActivity(),
|
|
||||||
onContactClickListener);
|
|
||||||
|
|
||||||
list = contentView.findViewById(R.id.list);
|
list = contentView.findViewById(R.id.list);
|
||||||
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.setEmptyText(R.string.no_contacts);
|
list.setEmptyText(R.string.no_contacts);
|
||||||
|
|
||||||
contactId = new ContactId(requireArguments().getInt(CONTACT_ID));
|
viewModel.getContactListItems().observe(getViewLifecycleOwner(),
|
||||||
|
result -> result.onError(this::handleException)
|
||||||
|
.onSuccess(adapter::submitList)
|
||||||
|
);
|
||||||
|
|
||||||
return contentView;
|
return contentView;
|
||||||
}
|
}
|
||||||
@@ -104,14 +68,13 @@ public class ContactChooserFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
loadContacts();
|
list.startPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
adapter.clear();
|
list.stopPeriodicUpdate();
|
||||||
list.showProgressBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,43 +82,9 @@ public class ContactChooserFragment extends BaseFragment {
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadContacts() {
|
@Override
|
||||||
listener.runOnDbThread(() -> {
|
public void onItemClick(View view, ContactListItem item) {
|
||||||
try {
|
viewModel.setSecondContactId(item.getContact().getId());
|
||||||
List<ContactListItem> contacts = new ArrayList<>();
|
viewModel.triggerContactSelected();
|
||||||
for (Contact c : contactManager.getContacts()) {
|
|
||||||
if (c.getId().equals(contactId)) {
|
|
||||||
c1 = c;
|
|
||||||
} else {
|
|
||||||
AuthorInfo authorInfo = authorManager.getAuthorInfo(c);
|
|
||||||
ContactId id = c.getId();
|
|
||||||
GroupCount count =
|
|
||||||
conversationManager.getGroupCount(id);
|
|
||||||
boolean connected =
|
|
||||||
connectionRegistry.isConnected(c.getId());
|
|
||||||
contacts.add(new ContactListItem(c, authorInfo,
|
|
||||||
connected, count));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
displayContacts(contacts);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayContacts(List<ContactListItem> contacts) {
|
|
||||||
runOnUiThreadUnlessDestroyed(() -> {
|
|
||||||
if (contacts.isEmpty()) list.showData();
|
|
||||||
else adapter.addAll(contacts);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showMessageScreen(Contact c1, Contact c2) {
|
|
||||||
IntroductionMessageFragment messageFragment =
|
|
||||||
IntroductionMessageFragment
|
|
||||||
.newInstance(c1.getId().getInt(), c2.getId().getInt());
|
|
||||||
showNextFragment(messageFragment);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,30 +9,67 @@ import org.briarproject.briar.android.activity.ActivityComponent;
|
|||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||||
|
|
||||||
public class IntroductionActivity extends BriarActivity
|
public class IntroductionActivity extends BriarActivity
|
||||||
implements BaseFragmentListener {
|
implements BaseFragmentListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private IntroductionViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectActivity(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||||
|
.get(IntroductionViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String BUNDLE_CONTACT2 = "contact2";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
int id = intent.getIntExtra(CONTACT_ID, -1);
|
int contactId1 = intent.getIntExtra(CONTACT_ID, -1);
|
||||||
if (id == -1) throw new IllegalStateException("No ContactId");
|
if (contactId1 == -1)
|
||||||
ContactId contactId = new ContactId(id);
|
throw new IllegalStateException("No ContactId");
|
||||||
|
ContactId firstContactId = new ContactId(contactId1);
|
||||||
|
|
||||||
|
viewModel.setFirstContactId(firstContactId);
|
||||||
|
|
||||||
setContentView(R.layout.activity_fragment_container);
|
setContentView(R.layout.activity_fragment_container);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
showInitialFragment(ContactChooserFragment.newInstance(contactId));
|
showInitialFragment(new ContactChooserFragment());
|
||||||
|
} else {
|
||||||
|
int contactId2 = savedInstanceState.getInt(BUNDLE_CONTACT2);
|
||||||
|
ContactId secondContactId = new ContactId(contactId2);
|
||||||
|
viewModel.setSecondContactId(secondContactId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.getSecondContactSelected().observeEvent(this, e -> {
|
||||||
|
IntroductionMessageFragment fragment =
|
||||||
|
new IntroductionMessageFragment();
|
||||||
|
showNextFragment(fragment);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectActivity(ActivityComponent component) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
component.inject(this);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
ContactId secondContactId = viewModel.getSecondContactId();
|
||||||
|
if (secondContactId != null) {
|
||||||
|
outState.putInt(BUNDLE_CONTACT2, secondContactId.getInt());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.briarproject.briar.android.introduction;
|
||||||
|
|
||||||
|
import org.briarproject.briar.android.contact.ContactItem;
|
||||||
|
|
||||||
|
class IntroductionInfo {
|
||||||
|
private final ContactItem c1;
|
||||||
|
private final ContactItem c2;
|
||||||
|
private final boolean possible;
|
||||||
|
|
||||||
|
IntroductionInfo(ContactItem c1, ContactItem c2,
|
||||||
|
boolean possible) {
|
||||||
|
this.c1 = c1;
|
||||||
|
this.c2 = c2;
|
||||||
|
this.possible = possible;
|
||||||
|
}
|
||||||
|
|
||||||
|
ContactItem getContact1() {
|
||||||
|
return c1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ContactItem getContact2() {
|
||||||
|
return c2;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isPossible() {
|
||||||
|
return possible;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user