mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Compare commits
114 Commits
user-testi
...
alpha-1.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 |
@@ -1,30 +1,52 @@
|
||||
image: briar/ci-image-android:latest
|
||||
|
||||
stages:
|
||||
- test
|
||||
- optional_tests
|
||||
- check_reproducibility
|
||||
- test
|
||||
- optional_tests
|
||||
- check_reproducibility
|
||||
|
||||
test:
|
||||
stage: test
|
||||
.base-test:
|
||||
before_script:
|
||||
- set -e
|
||||
- export GRADLE_USER_HOME=$PWD/.gradle
|
||||
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_SLUG"
|
||||
paths:
|
||||
- .gradle/wrapper
|
||||
- .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:
|
||||
# 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 -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:
|
||||
stage: check_reproducibility
|
||||
@@ -40,6 +62,7 @@ test_reproducible:
|
||||
- export GRADLE_USER_HOME=$PWD/.gradle
|
||||
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_SLUG"
|
||||
paths:
|
||||
- .gradle/wrapper
|
||||
- .gradle/caches
|
||||
|
||||
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>
|
||||
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
|
||||
buildToolsVersion '30.0.2'
|
||||
|
||||
packagingOptions {
|
||||
doNotStrip '**/*.so'
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 10214
|
||||
versionName "1.2.14"
|
||||
versionCode 10220
|
||||
versionName "1.2.20"
|
||||
consumerProguardFiles 'proguard-rules.txt'
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
@@ -38,8 +42,8 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
implementation project(path: ':bramble-core', configuration: 'default')
|
||||
tor 'org.briarproject:tor-android:0.3.5.12@zip'
|
||||
tor 'org.briarproject:obfs4proxy-android:0.0.11-2@zip'
|
||||
tor 'org.briarproject:tor-android:0.3.5.13@zip'
|
||||
tor 'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a@zip'
|
||||
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||
|
||||
|
||||
@@ -175,6 +175,11 @@ class AndroidBluetoothPlugin
|
||||
} catch (IOException e) {
|
||||
IoUtils.tryToClose(s, LOG, WARNING);
|
||||
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 STORED_REPORTS = "dev-reports";
|
||||
private static final String STORED_LOGCAT = "dev-logcat";
|
||||
|
||||
public static Collection<String> getSupportedArchitectures() {
|
||||
List<String> abis = new ArrayList<>();
|
||||
@@ -107,14 +108,14 @@ public class AndroidUtils {
|
||||
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.
|
||||
* 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() {
|
||||
if (SDK_INT < 24) return new String[] {"image/jpeg", "image/png"};
|
||||
else return new String[] {"image/jpeg", "image/png", "image/gif"};
|
||||
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.bouncycastle:bcpkix-jdk15on:1.56:bcpkix-jdk15on-1.56.jar:7043dee4e9e7175e93e0b36f45b1ec1ecb893c5f755667e8b916eb8dd201c6ca',
|
||||
'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:tor-android:0.3.5.12:tor-android-0.3.5.12.zip:db71fb3290acff79d572af0752570eaf6aad7c4d88c9b9aa0b4d5afe2b9ead9c',
|
||||
'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.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-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',
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.bramble.api.client;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
@@ -120,17 +119,4 @@ public interface ClientHelper {
|
||||
Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
|
||||
BdfDictionary properties) throws FormatException;
|
||||
|
||||
/**
|
||||
* Retrieves the contact ID from the group metadata of the given contact
|
||||
* group.
|
||||
*/
|
||||
ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
||||
throws DbException, FormatException;
|
||||
|
||||
/**
|
||||
* Stores the given contact ID in the group metadata of the given contact
|
||||
* group.
|
||||
*/
|
||||
void setContactId(Transaction txn, GroupId contactGroupId, ContactId c)
|
||||
throws DbException;
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package org.briarproject.bramble.api.client;
|
||||
|
||||
public interface ContactGroupConstants {
|
||||
|
||||
/**
|
||||
* Group metadata key for associating a contact ID with a contact group.
|
||||
*/
|
||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||
}
|
||||
@@ -19,4 +19,10 @@ public interface StreamDecrypterFactory {
|
||||
*/
|
||||
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
||||
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
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -13,4 +13,6 @@ public interface DevConfig {
|
||||
String getDevOnionAddress();
|
||||
|
||||
File getReportDir();
|
||||
|
||||
File getLogcatFile();
|
||||
}
|
||||
|
||||
@@ -16,8 +16,13 @@ public interface StreamReaderFactory {
|
||||
|
||||
/**
|
||||
* Creates an {@link InputStream InputStream} for reading from a contact
|
||||
* exchangestream.
|
||||
* exchange stream.
|
||||
*/
|
||||
InputStream createContactExchangeStreamReader(InputStream in,
|
||||
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
|
||||
public interface StreamWriterFactory {
|
||||
|
||||
/**
|
||||
* Creates an {@link OutputStream OutputStream} for writing to a
|
||||
* transport stream
|
||||
* Creates a {@link StreamWriter} for writing to a transport stream.
|
||||
*/
|
||||
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
||||
|
||||
/**
|
||||
* Creates an {@link OutputStream OutputStream} for writing to a contact
|
||||
* exchange stream.
|
||||
* Creates a {@link StreamWriter} for writing to a contact exchange stream.
|
||||
*/
|
||||
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||
SecretKey headerKey);
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamWriter} for writing to a log stream.
|
||||
*/
|
||||
StreamWriter createLogStreamWriter(OutputStream out, SecretKey headerKey);
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ValidationUtils {
|
||||
|
||||
@@ -66,9 +64,4 @@ public class ValidationUtils {
|
||||
if (dictionary != null && dictionary.size() != size)
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public static void checkRange(@Nullable Long l, long min, long max)
|
||||
throws FormatException {
|
||||
if (l != null && (l < min || l > max)) throw new FormatException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package org.briarproject.bramble.test;
|
||||
|
||||
public interface TimeTravel {
|
||||
|
||||
void setCurrentTimeMillis(long now) throws InterruptedException;
|
||||
|
||||
void addCurrentTimeMillis(long add) throws InterruptedException;
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import org.briarproject.bramble.rendezvous.RendezvousModule;
|
||||
import org.briarproject.bramble.settings.SettingsModule;
|
||||
import org.briarproject.bramble.sync.SyncModule;
|
||||
import org.briarproject.bramble.sync.validation.ValidationModule;
|
||||
import org.briarproject.bramble.system.ClockModule;
|
||||
import org.briarproject.bramble.transport.TransportModule;
|
||||
import org.briarproject.bramble.versioning.VersioningModule;
|
||||
|
||||
@@ -28,6 +29,7 @@ import dagger.Module;
|
||||
|
||||
@Module(includes = {
|
||||
ClientModule.class,
|
||||
ClockModule.class,
|
||||
ConnectionModule.class,
|
||||
ContactModule.class,
|
||||
CryptoModule.class,
|
||||
|
||||
@@ -2,13 +2,11 @@ package org.briarproject.bramble.client;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||
import org.briarproject.bramble.api.crypto.KeyParser;
|
||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.data.BdfReader;
|
||||
import org.briarproject.bramble.api.data.BdfReaderFactory;
|
||||
@@ -41,7 +39,6 @@ import java.util.Map.Entry;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.client.ContactGroupConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
@@ -392,27 +389,4 @@ class ClientHelperImpl implements ClientHelper {
|
||||
return tpMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary meta =
|
||||
getGroupMetadataAsDictionary(txn, contactGroupId);
|
||||
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e); // Invalid group metadata
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContactId(Transaction txn, GroupId contactGroupId,
|
||||
ContactId c) throws DbException {
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_CONTACT_ID, c.getInt()));
|
||||
try {
|
||||
mergeGroupMetadata(txn, contactGroupId, meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
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.now;
|
||||
|
||||
class ScryptKdf implements PasswordBasedKdf {
|
||||
|
||||
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 MAX_COST = 1024 * 1024; // Max parameter N
|
||||
@@ -33,10 +35,20 @@ class ScryptKdf implements PasswordBasedKdf {
|
||||
|
||||
@Override
|
||||
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
|
||||
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;
|
||||
}
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("KDF cost parameter " + cost);
|
||||
return cost;
|
||||
|
||||
@@ -36,4 +36,10 @@ class StreamDecrypterFactoryImpl implements StreamDecrypterFactory {
|
||||
SecretKey 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
|
||||
public StreamEncrypter createContactExchangeStreamDecrypter(
|
||||
public StreamEncrypter createContactExchangeStreamEncrypter(
|
||||
OutputStream out, SecretKey headerKey) {
|
||||
AuthenticatedCipher cipher = cipherProvider.get();
|
||||
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
||||
@@ -60,4 +60,10 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
||||
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
||||
headerKey, frameKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
||||
SecretKey headerKey) {
|
||||
return createContactExchangeStreamEncrypter(out, headerKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,15 +24,21 @@ class StreamReaderFactoryImpl implements StreamReaderFactory {
|
||||
|
||||
@Override
|
||||
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
||||
return new StreamReaderImpl(
|
||||
streamDecrypterFactory.createStreamDecrypter(in, ctx));
|
||||
return new StreamReaderImpl(streamDecrypterFactory
|
||||
.createStreamDecrypter(in, ctx));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream createContactExchangeStreamReader(InputStream in,
|
||||
SecretKey headerKey) {
|
||||
return new StreamReaderImpl(
|
||||
streamDecrypterFactory.createContactExchangeStreamDecrypter(in,
|
||||
headerKey));
|
||||
return new StreamReaderImpl(streamDecrypterFactory
|
||||
.createContactExchangeStreamDecrypter(in, 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
|
||||
public StreamWriter createStreamWriter(OutputStream out,
|
||||
StreamContext ctx) {
|
||||
return new StreamWriterImpl(
|
||||
streamEncrypterFactory.createStreamEncrypter(out, ctx));
|
||||
return new StreamWriterImpl(streamEncrypterFactory
|
||||
.createStreamEncrypter(out, ctx));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||
SecretKey headerKey) {
|
||||
return new StreamWriterImpl(
|
||||
streamEncrypterFactory.createContactExchangeStreamDecrypter(out,
|
||||
headerKey));
|
||||
return new StreamWriterImpl(streamEncrypterFactory
|
||||
.createContactExchangeStreamEncrypter(out, headerKey));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamWriter createLogStreamWriter(OutputStream out,
|
||||
SecretKey headerKey) {
|
||||
return new StreamWriterImpl(streamEncrypterFactory
|
||||
.createLogStreamEncrypter(out, headerKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@ interface ClientVersioningConstants {
|
||||
// Metadata keys
|
||||
String MSG_KEY_UPDATE_VERSION = "version";
|
||||
String MSG_KEY_LOCAL = "local";
|
||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import static java.util.Collections.emptyList;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||
|
||||
@@ -160,7 +161,13 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
db.addGroup(txn, g);
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
|
||||
// Attach the contact ID to the group
|
||||
clientHelper.setContactId(txn, g.getId(), c.getId());
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
||||
try {
|
||||
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
// Create and store the first local update
|
||||
List<ClientVersion> versions = new ArrayList<>(clients);
|
||||
Collections.sort(versions);
|
||||
@@ -222,7 +229,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
Map<ClientMajorVersion, Visibility> after =
|
||||
getVisibilities(newLocalStates, newRemoteStates);
|
||||
// Call hooks for any visibilities that have changed
|
||||
ContactId c = clientHelper.getContactId(txn, m.getGroupId());
|
||||
ContactId c = getContactId(txn, m.getGroupId());
|
||||
if (!before.equals(after)) {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
callVisibilityHooks(txn, contact, before, after);
|
||||
@@ -514,6 +521,17 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
storeUpdate(txn, g, states, 1);
|
||||
}
|
||||
|
||||
private ContactId getContactId(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary meta =
|
||||
clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ClientState> updateStatesFromRemoteStates(
|
||||
List<ClientState> oldLocalStates, List<ClientState> remoteStates) {
|
||||
Set<ClientMajorVersion> remoteSet = new HashSet<>();
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
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.98:443 011F2599C0E9B27EE74B353155E244813763C3E5 cert=ayq0XzCwhpdysn5o0EyDUbmSOx3X/oTEbzDMvczHOdBJKlvIdHHLJGkZARtT4dcBFArPPg 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 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw 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
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package org.briarproject.bramble;
|
||||
|
||||
import org.briarproject.bramble.system.TimeTravelModule;
|
||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
||||
|
||||
public interface BrambleCoreIntegrationTestEagerSingletons
|
||||
extends BrambleCoreEagerSingletons {
|
||||
|
||||
void inject(TimeTravelModule.EagerSingletons init);
|
||||
void inject(DefaultTaskSchedulerModule.EagerSingletons init);
|
||||
|
||||
class Helper {
|
||||
|
||||
public static void injectEagerSingletons(
|
||||
BrambleCoreIntegrationTestEagerSingletons c) {
|
||||
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
|
||||
c.inject(new TimeTravelModule.EagerSingletons());
|
||||
c.inject(new DefaultTaskSchedulerModule.EagerSingletons());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
package org.briarproject.bramble.system;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* A {@link TaskScheduler} for use in tests. The scheduler keeps all scheduled
|
||||
* tasks in a queue until {@link #runTasks()} is called.
|
||||
*/
|
||||
@NotNullByDefault
|
||||
class TestTaskScheduler implements TaskScheduler {
|
||||
|
||||
private final Queue<Task> queue = new PriorityBlockingQueue<>();
|
||||
private final Clock clock;
|
||||
|
||||
TestTaskScheduler(Clock clock) {
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cancellable schedule(Runnable task, Executor executor, long delay,
|
||||
TimeUnit unit) {
|
||||
AtomicBoolean cancelled = new AtomicBoolean(false);
|
||||
return schedule(task, executor, delay, unit, cancelled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cancellable scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||
long delay, long interval, TimeUnit unit) {
|
||||
AtomicBoolean cancelled = new AtomicBoolean(false);
|
||||
return scheduleWithFixedDelay(task, executor, delay, interval, unit,
|
||||
cancelled);
|
||||
}
|
||||
|
||||
private Cancellable schedule(Runnable task, Executor executor, long delay,
|
||||
TimeUnit unit, AtomicBoolean cancelled) {
|
||||
long delayMillis = MILLISECONDS.convert(delay, unit);
|
||||
long dueMillis = clock.currentTimeMillis() + delayMillis;
|
||||
Task t = new Task(task, executor, dueMillis, cancelled);
|
||||
queue.add(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
private Cancellable scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||
long delay, long interval, TimeUnit unit, AtomicBoolean cancelled) {
|
||||
// All executions of this periodic task share a cancelled flag
|
||||
Runnable wrapped = () -> {
|
||||
task.run();
|
||||
scheduleWithFixedDelay(task, executor, interval, interval, unit,
|
||||
cancelled);
|
||||
};
|
||||
return schedule(wrapped, executor, delay, unit, cancelled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs any scheduled tasks that are due.
|
||||
*/
|
||||
void runTasks() throws InterruptedException {
|
||||
long now = clock.currentTimeMillis();
|
||||
while (true) {
|
||||
Task t = queue.peek();
|
||||
if (t == null || t.dueMillis > now) return;
|
||||
t = queue.poll();
|
||||
// Submit the task to its executor and wait for it to finish
|
||||
if (!t.run().await(1, MINUTES)) fail();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Task
|
||||
implements Cancellable, Comparable<Task> {
|
||||
|
||||
private final Runnable task;
|
||||
private final Executor executor;
|
||||
private final long dueMillis;
|
||||
private final AtomicBoolean cancelled;
|
||||
|
||||
private Task(Runnable task, Executor executor, long dueMillis,
|
||||
AtomicBoolean cancelled) {
|
||||
this.task = task;
|
||||
this.executor = executor;
|
||||
this.dueMillis = dueMillis;
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseCompareMethod") // Animal Sniffer
|
||||
@Override
|
||||
public int compareTo(Task task) {
|
||||
return Long.valueOf(dueMillis).compareTo(task.dueMillis);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the task to its executor and returns a latch that will be
|
||||
* released when the task finishes.
|
||||
*/
|
||||
public CountDownLatch run() {
|
||||
if (cancelled.get()) return new CountDownLatch(0);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
executor.execute(() -> {
|
||||
task.run();
|
||||
latch.countDown();
|
||||
});
|
||||
return latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
cancelled.set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package org.briarproject.bramble.system;
|
||||
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||
import org.briarproject.bramble.test.SettableClock;
|
||||
import org.briarproject.bramble.test.TimeTravel;
|
||||
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class TimeTravelModule {
|
||||
|
||||
public static class EagerSingletons {
|
||||
@Inject
|
||||
TaskScheduler scheduler;
|
||||
}
|
||||
|
||||
private final ScheduledExecutorService scheduledExecutorService;
|
||||
private final Clock clock;
|
||||
private final TaskScheduler taskScheduler;
|
||||
private final TimeTravel timeTravel;
|
||||
|
||||
public TimeTravelModule() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public TimeTravelModule(boolean travel) {
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ScheduledThreadPoolExecutor.DiscardPolicy();
|
||||
scheduledExecutorService =
|
||||
new ScheduledThreadPoolExecutor(1, policy);
|
||||
if (travel) {
|
||||
// Use a SettableClock and TestTaskScheduler to allow time travel
|
||||
AtomicLong time = new AtomicLong(System.currentTimeMillis());
|
||||
clock = new SettableClock(time);
|
||||
TestTaskScheduler testTaskScheduler = new TestTaskScheduler(clock);
|
||||
taskScheduler = testTaskScheduler;
|
||||
timeTravel = new TimeTravel() {
|
||||
@Override
|
||||
public void setCurrentTimeMillis(long now)
|
||||
throws InterruptedException {
|
||||
time.set(now);
|
||||
testTaskScheduler.runTasks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCurrentTimeMillis(long add)
|
||||
throws InterruptedException {
|
||||
time.addAndGet(add);
|
||||
testTaskScheduler.runTasks();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// Use the default clock and task scheduler
|
||||
clock = new SystemClock();
|
||||
taskScheduler = new TaskSchedulerImpl(scheduledExecutorService);
|
||||
timeTravel = new TimeTravel() {
|
||||
@Override
|
||||
public void setCurrentTimeMillis(long now) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCurrentTimeMillis(long add) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
Clock provideClock() {
|
||||
return clock;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
TaskScheduler provideTaskScheduler(LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(scheduledExecutorService);
|
||||
return taskScheduler;
|
||||
}
|
||||
|
||||
@Provides
|
||||
TimeTravel provideTimeTravel() {
|
||||
return timeTravel;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package org.briarproject.bramble.test;
|
||||
import org.briarproject.bramble.api.FeatureFlags;
|
||||
import org.briarproject.bramble.battery.DefaultBatteryManagerModule;
|
||||
import org.briarproject.bramble.event.DefaultEventExecutorModule;
|
||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
||||
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule;
|
||||
import org.briarproject.bramble.system.TimeTravelModule;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
@@ -12,11 +12,11 @@ import dagger.Provides;
|
||||
@Module(includes = {
|
||||
DefaultBatteryManagerModule.class,
|
||||
DefaultEventExecutorModule.class,
|
||||
DefaultTaskSchedulerModule.class,
|
||||
DefaultWakefulIoExecutorModule.class,
|
||||
TestDatabaseConfigModule.class,
|
||||
TestPluginConfigModule.class,
|
||||
TestSecureRandomModule.class,
|
||||
TimeTravelModule.class
|
||||
TestSecureRandomModule.class
|
||||
})
|
||||
public class BrambleCoreIntegrationTestModule {
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -59,6 +60,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
private final ClientId clientId = getClientId();
|
||||
private final long now = System.currentTimeMillis();
|
||||
private final Transaction txn = new Transaction(null, false);
|
||||
private final BdfDictionary groupMeta = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||
|
||||
private ClientVersioningManagerImpl createInstance() {
|
||||
context.checking(new Expectations() {{
|
||||
@@ -120,8 +123,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||
contactGroup.getId(), SHARED);
|
||||
oneOf(clientHelper).setContactId(txn, contactGroup.getId(),
|
||||
contact.getId());
|
||||
oneOf(clientHelper).mergeGroupMetadata(txn, contactGroup.getId(),
|
||||
groupMeta);
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(clientHelper).createMessage(contactGroup.getId(), now,
|
||||
@@ -457,8 +460,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).deleteMessage(txn, oldRemoteUpdateId);
|
||||
oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId);
|
||||
// Get contact ID
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
// No states or visibilities have changed
|
||||
}});
|
||||
|
||||
@@ -488,9 +492,10 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
// Load the latest local update
|
||||
oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId);
|
||||
will(returnValue(oldLocalUpdateBody));
|
||||
// Get contact ID
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
// Get client ID
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
// No states or visibilities have changed
|
||||
}});
|
||||
|
||||
@@ -541,6 +546,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||
BdfDictionary groupMeta = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||
@@ -570,8 +577,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||
newLocalUpdateMeta, true, false);
|
||||
// The client's visibility has changed
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(hook).onClientVisibilityChanging(txn, contact, visibility);
|
||||
@@ -611,6 +619,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||
BdfDictionary groupMeta = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||
@@ -640,8 +650,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||
newLocalUpdateMeta, true, false);
|
||||
// The client's visibility has changed
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE);
|
||||
|
||||
@@ -16,8 +16,8 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||
implementation 'net.java.dev.jna:jna: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:obfs4proxy:0.0.7@zip'
|
||||
tor 'org.briarproject:tor:0.3.5.13-1@zip'
|
||||
tor 'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a@zip'
|
||||
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import org.briarproject.bramble.system.JavaSystemModule;
|
||||
import dagger.Module;
|
||||
|
||||
@Module(includes = {
|
||||
CircumventionModule.class,
|
||||
JavaNetworkModule.class,
|
||||
JavaSystemModule.class,
|
||||
CircumventionModule.class,
|
||||
SocksModule.class
|
||||
})
|
||||
public class BrambleJavaModule {
|
||||
|
||||
@@ -25,6 +25,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.OsUtils.isLinux;
|
||||
|
||||
@@ -96,8 +97,15 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
||||
String architecture = null;
|
||||
if (isLinux()) {
|
||||
String arch = System.getProperty("os.arch");
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("System's os.arch is " + arch);
|
||||
}
|
||||
if (arch.equals("amd64")) {
|
||||
architecture = "linux-x86_64";
|
||||
} else if (arch.equals("aarch64")) {
|
||||
architecture = "linux-aarch64";
|
||||
} else if (arch.equals("arm")) {
|
||||
architecture = "linux-armhf";
|
||||
}
|
||||
}
|
||||
if (architecture == null) {
|
||||
@@ -105,6 +113,10 @@ public class UnixTorPluginFactory implements DuplexPluginFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("The selected architecture for Tor is " + architecture);
|
||||
}
|
||||
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
TorRendezvousCrypto torRendezvousCrypto = new TorRendezvousCryptoImpl();
|
||||
|
||||
@@ -23,8 +23,8 @@ dependencyVerification {
|
||||
'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.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:tor:0.3.5.12:tor-0.3.5.12.zip:2f542c4befd216f2226bf7c76e3b8b2d99af6f146a8cb28bf727f42014587006',
|
||||
'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a:obfs4proxy-0.0.12-dev-40245c4a.zip:172029e7058b3a83ac93ac4991a44bf76e16ce8d46f558f5836d57da3cb3a766',
|
||||
'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-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',
|
||||
|
||||
@@ -19,11 +19,15 @@ android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion '30.0.2'
|
||||
|
||||
packagingOptions {
|
||||
doNotStrip '**/*.so'
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 10214
|
||||
versionName "1.2.14"
|
||||
versionCode 10220
|
||||
versionName "1.2.20"
|
||||
applicationId "org.briarproject.briar.android"
|
||||
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
@@ -95,6 +99,7 @@ dependencies {
|
||||
implementation project(path: ':bramble-core', configuration: 'default')
|
||||
implementation project(':bramble-android')
|
||||
|
||||
implementation 'androidx.fragment:fragment:1.3.0'
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.3.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||
@@ -136,6 +141,7 @@ dependencies {
|
||||
testImplementation "org.jmock:jmock:$jmockVersion"
|
||||
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
|
||||
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
|
||||
testAnnotationProcessor "com.google.dagger:dagger-compiler:2.24"
|
||||
|
||||
androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
|
||||
@@ -4,16 +4,20 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
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.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
|
||||
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")
|
||||
@@ -27,6 +31,8 @@ public abstract class UiTest {
|
||||
protected AccountManager accountManager;
|
||||
@Inject
|
||||
protected LifecycleManager lifecycleManager;
|
||||
@Inject
|
||||
protected SettingsManager settingsManager;
|
||||
|
||||
public UiTest() {
|
||||
BriarTestComponentApplication app = getApplicationContext();
|
||||
@@ -39,22 +45,8 @@ public abstract class UiTest {
|
||||
protected class CleanAccountTestRule<A extends Activity>
|
||||
extends IntentsTestRule<A> {
|
||||
|
||||
@Nullable
|
||||
private final Runnable runnable;
|
||||
|
||||
public CleanAccountTestRule(Class<A> 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
|
||||
@@ -62,16 +54,17 @@ public abstract class UiTest {
|
||||
super.beforeActivityLaunched();
|
||||
accountManager.deleteAccount();
|
||||
accountManager.createAccount(USERNAME, PASSWORD);
|
||||
if (runnable != null) {
|
||||
Intent serviceIntent =
|
||||
new Intent(getApplicationContext(), BriarService.class);
|
||||
getApplicationContext().startService(serviceIntent);
|
||||
try {
|
||||
lifecycleManager.waitForStartup();
|
||||
} catch (InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
runnable.run();
|
||||
Intent serviceIntent =
|
||||
new Intent(getApplicationContext(), BriarService.class);
|
||||
getApplicationContext().startService(serviceIntent);
|
||||
try {
|
||||
lifecycleManager.waitForStartup();
|
||||
// do not show doze white-listing dialog
|
||||
Settings settings = new Settings();
|
||||
settings.putBoolean(DOZE_ASK_AGAIN, false);
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
} catch (InterruptedException | DbException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android;
|
||||
import org.briarproject.bramble.BrambleAndroidModule;
|
||||
import org.briarproject.bramble.BrambleCoreModule;
|
||||
import org.briarproject.bramble.account.BriarAccountModule;
|
||||
import org.briarproject.bramble.system.ClockModule;
|
||||
import org.briarproject.briar.BriarCoreModule;
|
||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||
@@ -17,7 +16,6 @@ import dagger.Component;
|
||||
@Component(modules = {
|
||||
AppModule.class,
|
||||
AttachmentModule.class,
|
||||
ClockModule.class,
|
||||
MediaModule.class,
|
||||
BriarCoreModule.class,
|
||||
BrambleAndroidModule.class,
|
||||
|
||||
@@ -10,12 +10,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.test.filters.LargeTest;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
@LargeTest
|
||||
@RunWith(Parameterized.class)
|
||||
public class PngSuiteImageCompressorTest
|
||||
extends AbstractImageCompressorTest {
|
||||
|
||||
@@ -12,11 +12,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.test.filters.LargeTest;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
@LargeTest
|
||||
@RunWith(Parameterized.class)
|
||||
public class PngSuiteImageSizeCalculatorTest
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android;
|
||||
import org.briarproject.bramble.BrambleAndroidModule;
|
||||
import org.briarproject.bramble.BrambleCoreModule;
|
||||
import org.briarproject.bramble.account.BriarAccountModule;
|
||||
import org.briarproject.bramble.system.ClockModule;
|
||||
import org.briarproject.briar.BriarCoreModule;
|
||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||
@@ -18,7 +17,6 @@ import dagger.Component;
|
||||
@Component(modules = {
|
||||
AppModule.class,
|
||||
AttachmentModule.class,
|
||||
ClockModule.class,
|
||||
MediaModule.class,
|
||||
BriarCoreModule.class,
|
||||
BrambleAndroidModule.class,
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
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.action.ViewActions.click;
|
||||
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.withText;
|
||||
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.junit.Assume.assumeTrue;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
||||
@@ -76,6 +79,8 @@ public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
||||
|
||||
@Test
|
||||
public void appLock() {
|
||||
assumeTrue("device has no screen lock",
|
||||
hasScreenLock(getApplicationContext()));
|
||||
// scroll down
|
||||
onView(withClassName(is(RecyclerView.class.getName())))
|
||||
.perform(scrollTo(hasDescendant(
|
||||
|
||||
@@ -27,7 +27,10 @@
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<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.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
@@ -38,6 +41,7 @@
|
||||
android:name="org.briarproject.briar.android.BriarApplicationImpl"
|
||||
android:allowBackup="false"
|
||||
android:banner="@mipmap/tv_banner"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher_round"
|
||||
android:label="@string/app_name"
|
||||
android:logo="@mipmap/ic_launcher_round"
|
||||
|
||||
@@ -29,12 +29,12 @@ import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.LocationUtils;
|
||||
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
||||
import org.briarproject.bramble.system.ClockModule;
|
||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||
import org.briarproject.briar.BriarCoreModule;
|
||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||
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.view.EmojiTextInputView;
|
||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||
@@ -42,7 +42,6 @@ import org.briarproject.briar.api.android.DozeWatchdog;
|
||||
import org.briarproject.briar.api.android.LockManager;
|
||||
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
||||
import org.briarproject.briar.api.attachment.AttachmentReader;
|
||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||
import org.briarproject.briar.api.blog.BlogManager;
|
||||
import org.briarproject.briar.api.blog.BlogPostFactory;
|
||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||
@@ -77,7 +76,6 @@ import dagger.Component;
|
||||
BriarAccountModule.class,
|
||||
AppModule.class,
|
||||
AttachmentModule.class,
|
||||
ClockModule.class,
|
||||
MediaModule.class
|
||||
})
|
||||
public interface AndroidComponent
|
||||
@@ -182,7 +180,9 @@ public interface AndroidComponent
|
||||
|
||||
AndroidWakeLockManager wakeLockManager();
|
||||
|
||||
AutoDeleteManager autoDeleteManager();
|
||||
CachingLogHandler logHandler();
|
||||
|
||||
Thread.UncaughtExceptionHandler exceptionHandler();
|
||||
|
||||
void inject(SignInReminderReceiver briarService);
|
||||
|
||||
|
||||
@@ -30,9 +30,12 @@ import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.android.account.DozeHelperModule;
|
||||
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||
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.forum.ForumModule;
|
||||
import org.briarproject.briar.android.introduction.IntroductionModule;
|
||||
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.navdrawer.NavDrawerModule;
|
||||
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
||||
@@ -68,18 +71,22 @@ import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
|
||||
@Module(includes = {
|
||||
SetupModule.class,
|
||||
DozeHelperModule.class,
|
||||
ContactExchangeModule.class,
|
||||
LoggingModule.class,
|
||||
LoginModule.class,
|
||||
NavDrawerModule.class,
|
||||
ViewModelModule.class,
|
||||
SettingsModule.class,
|
||||
DevReportModule.class,
|
||||
ContactListModule.class,
|
||||
IntroductionModule.class,
|
||||
// below need to be within same scope as ViewModelProvider.Factory
|
||||
BlogModule.class,
|
||||
ForumModule.class,
|
||||
GroupListModule.class,
|
||||
GroupConversationModule.class,
|
||||
@@ -191,6 +198,11 @@ public class AppModule {
|
||||
public File getReportDir() {
|
||||
return AndroidUtils.getReportDir(app.getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getLogcatFile() {
|
||||
return AndroidUtils.getLogcatFile(app.getApplicationContext());
|
||||
}
|
||||
};
|
||||
return devConfig;
|
||||
}
|
||||
@@ -268,12 +280,12 @@ public class AppModule {
|
||||
|
||||
@Override
|
||||
public boolean shouldEnableImageAttachments() {
|
||||
return false;
|
||||
return IS_DEBUG_BUILD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldEnableProfilePictures() {
|
||||
return false;
|
||||
return IS_DEBUG_BUILD;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,9 +6,6 @@ import android.content.SharedPreferences;
|
||||
import org.briarproject.bramble.BrambleApplication;
|
||||
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
|
||||
* directly to the Briar application object.
|
||||
@@ -17,8 +14,6 @@ public interface BriarApplication extends BrambleApplication {
|
||||
|
||||
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
|
||||
|
||||
Collection<LogRecord> getRecentLogRecords();
|
||||
|
||||
AndroidComponent getApplicationComponent();
|
||||
|
||||
SharedPreferences getDefaultSharedPreferences();
|
||||
|
||||
@@ -20,12 +20,10 @@ import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||
import org.briarproject.briar.android.reporting.BriarExceptionHandler;
|
||||
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.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -42,22 +40,18 @@ public class BriarApplicationImpl extends Application
|
||||
private static final Logger LOG =
|
||||
getLogger(BriarApplicationImpl.class.getName());
|
||||
|
||||
private final CachingLogHandler logHandler = new CachingLogHandler();
|
||||
private final BriarExceptionHandler exceptionHandler =
|
||||
new BriarExceptionHandler(this);
|
||||
|
||||
private AndroidComponent applicationComponent;
|
||||
private volatile SharedPreferences prefs;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
||||
if (prefs == null)
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(base);
|
||||
// Loading the language needs to be done here.
|
||||
Localizer.initialize(prefs);
|
||||
super.attachBaseContext(
|
||||
Localizer.getInstance().setLocale(base));
|
||||
Localizer.getInstance().setLocale(this);
|
||||
setTheme(base, prefs);
|
||||
}
|
||||
|
||||
@@ -67,6 +61,11 @@ public class BriarApplicationImpl extends Application
|
||||
|
||||
if (IS_DEBUG_BUILD) enableStrictMode();
|
||||
|
||||
applicationComponent = createApplicationComponent();
|
||||
UncaughtExceptionHandler exceptionHandler =
|
||||
applicationComponent.exceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
||||
|
||||
Logger rootLogger = getLogger("");
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
// 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
|
||||
for (Handler handler : handlers) rootLogger.addHandler(handler);
|
||||
}
|
||||
CachingLogHandler logHandler = applicationComponent.logHandler();
|
||||
rootLogger.addHandler(logHandler);
|
||||
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
||||
|
||||
LOG.info("Created");
|
||||
|
||||
applicationComponent = createApplicationComponent();
|
||||
EmojiManager.install(new GoogleEmojiProvider());
|
||||
}
|
||||
|
||||
@@ -136,11 +135,6 @@ public class BriarApplicationImpl extends Application
|
||||
return applicationComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<LogRecord> getRecentLogRecords() {
|
||||
return logHandler.getRecentLogRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AndroidComponent getApplicationComponent() {
|
||||
return applicationComponent;
|
||||
|
||||
@@ -37,7 +37,7 @@ import javax.inject.Inject;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
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.content.Intent.ACTION_SHUTDOWN;
|
||||
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_NO_ANIMATION;
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Process.myPid;
|
||||
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
||||
import static java.util.logging.Level.INFO;
|
||||
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_NOTIFICATION_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.LockManager.ACTION_LOCK;
|
||||
import static org.briarproject.briar.api.android.LockManager.EXTRA_PID;
|
||||
|
||||
public class BriarService extends Service {
|
||||
|
||||
@@ -120,11 +123,17 @@ public class BriarService extends Service {
|
||||
if (SDK_INT >= 26) {
|
||||
NotificationManager nm = (NotificationManager)
|
||||
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(
|
||||
ONGOING_CHANNEL_ID,
|
||||
getString(R.string.ongoing_notification_title),
|
||||
IMPORTANCE_NONE);
|
||||
IMPORTANCE_LOW);
|
||||
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||
ongoingChannel.setShowBadge(false);
|
||||
nm.createNotificationChannel(ongoingChannel);
|
||||
NotificationChannel failureChannel = new NotificationChannel(
|
||||
FAILURE_CHANNEL_ID,
|
||||
@@ -170,6 +179,7 @@ public class BriarService extends Service {
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
||||
Localizer.getInstance().setLocale(this);
|
||||
}
|
||||
|
||||
private void showStartupFailureNotification(StartResult result) {
|
||||
@@ -202,7 +212,12 @@ public class BriarService extends Service {
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -68,7 +68,21 @@ public class Localizer {
|
||||
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) {
|
||||
Resources res = context.getResources();
|
||||
Configuration conf = res.getConfiguration();
|
||||
@@ -82,7 +96,7 @@ public class Localizer {
|
||||
Locale.setDefault(locale);
|
||||
if (SDK_INT >= 17) {
|
||||
conf.setLocale(locale);
|
||||
context.createConfigurationContext(conf);
|
||||
context = context.createConfigurationContext(conf);
|
||||
} else
|
||||
conf.locale = locale;
|
||||
//noinspection deprecation
|
||||
|
||||
@@ -33,7 +33,6 @@ public class DozeFragment extends SetupFragment
|
||||
private DozeView dozeView;
|
||||
private HuaweiView huaweiView;
|
||||
private Button next;
|
||||
private ProgressBar progressBar;
|
||||
private boolean secondAttempt = false;
|
||||
|
||||
public static DozeFragment newInstance() {
|
||||
@@ -58,11 +57,19 @@ public class DozeFragment extends SetupFragment
|
||||
huaweiView = v.findViewById(R.id.huaweiView);
|
||||
huaweiView.setOnCheckedChangedListener(this);
|
||||
next = v.findViewById(R.id.next);
|
||||
progressBar = v.findViewById(R.id.progress);
|
||||
ProgressBar progressBar = v.findViewById(R.id.progress);
|
||||
|
||||
dozeView.setOnButtonClickListener(this::askForDozeWhitelisting);
|
||||
next.setOnClickListener(this);
|
||||
|
||||
viewModel.getIsCreatingAccount()
|
||||
.observe(getViewLifecycleOwner(), isCreatingAccount -> {
|
||||
if (isCreatingAccount) {
|
||||
next.setVisibility(INVISIBLE);
|
||||
progressBar.setVisibility(VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -104,15 +111,6 @@ public class DozeFragment extends SetupFragment
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
setNextClicked();
|
||||
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 static android.app.AlarmManager.ELAPSED_REALTIME;
|
||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
import static android.app.PendingIntent.getService;
|
||||
import static android.content.Context.ALARM_SERVICE;
|
||||
import static android.os.Process.myPid;
|
||||
import static android.os.SystemClock.elapsedRealtime;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
@@ -75,23 +77,25 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
LockManagerImpl(Application app, SettingsManager settingsManager,
|
||||
AndroidNotificationManager notificationManager,
|
||||
@DatabaseExecutor Executor dbExecutor) {
|
||||
this.appContext = app.getApplicationContext();
|
||||
appContext = app.getApplicationContext();
|
||||
this.settingsManager = settingsManager;
|
||||
this.notificationManager = notificationManager;
|
||||
this.dbExecutor = dbExecutor;
|
||||
this.alarmManager =
|
||||
alarmManager =
|
||||
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
||||
Intent i =
|
||||
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
||||
this.lockIntent = getService(appContext, 0, i, 0);
|
||||
this.timeoutNever = Integer.valueOf(
|
||||
i.putExtra(EXTRA_PID, myPid());
|
||||
// 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));
|
||||
this.timeoutDefault = Integer.valueOf(
|
||||
timeoutDefault = Integer.parseInt(
|
||||
appContext.getString(R.string.pref_lock_timeout_value_default));
|
||||
this.timeoutMinutes = timeoutNever;
|
||||
timeoutMinutes = timeoutNever;
|
||||
|
||||
// setting this in the constructor makes #getValue() @NonNull
|
||||
this.lockable.setValue(false);
|
||||
lockable.setValue(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,7 +152,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
boolean oldValue = lockable.getValue();
|
||||
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
||||
if (oldValue != newValue) {
|
||||
this.lockable.setValue(newValue);
|
||||
lockable.setValue(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ public class SetPasswordFragment extends SetupFragment {
|
||||
private TextInputEditText passwordConfirmation;
|
||||
private StrengthMeter strengthMeter;
|
||||
private Button nextButton;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
public static SetPasswordFragment newInstance() {
|
||||
return new SetPasswordFragment();
|
||||
@@ -64,7 +63,7 @@ public class SetPasswordFragment extends SetupFragment {
|
||||
v.findViewById(R.id.password_confirm_wrapper);
|
||||
passwordConfirmation = v.findViewById(R.id.password_confirm);
|
||||
nextButton = v.findViewById(R.id.next);
|
||||
progressBar = v.findViewById(R.id.progress);
|
||||
ProgressBar progressBar = v.findViewById(R.id.progress);
|
||||
|
||||
passwordEntry.addTextChangedListener(this);
|
||||
passwordConfirmation.addTextChangedListener(this);
|
||||
@@ -75,6 +74,17 @@ public class SetPasswordFragment extends SetupFragment {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -116,20 +126,6 @@ public class SetPasswordFragment extends SetupFragment {
|
||||
IBinder token = passwordEntry.getWindowToken();
|
||||
Object o = getContext().getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
|
||||
|
||||
setNextClicked();
|
||||
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.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
@@ -19,8 +18,6 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
@@ -35,7 +32,6 @@ abstract class SetupFragment extends BaseFragment implements TextWatcher,
|
||||
OnEditorActionListener, OnClickListener {
|
||||
|
||||
private final static String STATE_KEY_CLICKED = "setupFragmentClicked";
|
||||
private boolean clicked = false;
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
@@ -48,27 +44,6 @@ abstract class SetupFragment extends BaseFragment implements TextWatcher,
|
||||
.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
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.help_action, menu);
|
||||
@@ -114,5 +89,4 @@ abstract class SetupFragment extends BaseFragment implements TextWatcher,
|
||||
public void afterTextChanged(Editable editable) {
|
||||
// noop
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.briar.android.account.SetupViewModel.State.AUTHOR_NAME;
|
||||
@@ -36,6 +38,8 @@ class SetupViewModel extends AndroidViewModel {
|
||||
@Nullable
|
||||
private String authorName, password;
|
||||
private final MutableLiveEvent<State> state = new MutableLiveEvent<>();
|
||||
private final MutableLiveData<Boolean> isCreatingAccount =
|
||||
new MutableLiveData<>(false);
|
||||
|
||||
private final AccountManager accountManager;
|
||||
private final Executor ioExecutor;
|
||||
@@ -67,6 +71,10 @@ class SetupViewModel extends AndroidViewModel {
|
||||
return state;
|
||||
}
|
||||
|
||||
LiveData<Boolean> getIsCreatingAccount() {
|
||||
return isCreatingAccount;
|
||||
}
|
||||
|
||||
void setAuthorName(String authorName) {
|
||||
this.authorName = authorName;
|
||||
state.setEvent(SET_PASSWORD);
|
||||
@@ -97,6 +105,7 @@ class SetupViewModel extends AndroidViewModel {
|
||||
private void createAccount() {
|
||||
if (authorName == null) throw new IllegalStateException();
|
||||
if (password == null) throw new IllegalStateException();
|
||||
isCreatingAccount.setValue(true);
|
||||
ioExecutor.execute(() -> {
|
||||
if (accountManager.createAccount(authorName, password)) {
|
||||
LOG.info("Created account");
|
||||
|
||||
@@ -77,7 +77,7 @@ public class UnlockActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode,
|
||||
Intent data) {
|
||||
@Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_KEYGUARD_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.blog.BlogActivity;
|
||||
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.FeedFragment;
|
||||
import org.briarproject.briar.android.blog.FeedPostFragment;
|
||||
import org.briarproject.briar.android.blog.ReblogActivity;
|
||||
import org.briarproject.briar.android.blog.ReblogFragment;
|
||||
import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
||||
@@ -27,7 +25,6 @@ import org.briarproject.briar.android.contact.add.remote.NicknameFragment;
|
||||
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
||||
import org.briarproject.briar.android.conversation.AliasDialogFragment;
|
||||
import org.briarproject.briar.android.conversation.ConversationActivity;
|
||||
import org.briarproject.briar.android.conversation.ConversationSettingsDialog;
|
||||
import org.briarproject.briar.android.conversation.ImageActivity;
|
||||
import org.briarproject.briar.android.conversation.ImageFragment;
|
||||
import org.briarproject.briar.android.forum.CreateForumActivity;
|
||||
@@ -86,7 +83,6 @@ import dagger.Component;
|
||||
@ActivityScope
|
||||
@Component(modules = {
|
||||
ActivityModule.class,
|
||||
BlogModule.class,
|
||||
CreateGroupModule.class,
|
||||
GroupInvitationModule.class,
|
||||
GroupMemberModule.class,
|
||||
@@ -153,8 +149,6 @@ public interface ActivityComponent {
|
||||
|
||||
void inject(BlogPostFragment fragment);
|
||||
|
||||
void inject(FeedPostFragment fragment);
|
||||
|
||||
void inject(ReblogFragment fragment);
|
||||
|
||||
void inject(ReblogActivity activity);
|
||||
@@ -239,6 +233,4 @@ public interface ActivityComponent {
|
||||
|
||||
void inject(ConfirmAvatarDialogFragment fragment);
|
||||
|
||||
void inject(ConversationSettingsDialog dialog);
|
||||
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(
|
||||
Localizer.getInstance().setLocale(base));
|
||||
Localizer.getInstance().setLocale(this);
|
||||
}
|
||||
|
||||
public ActivityComponent getActivityComponent() {
|
||||
|
||||
@@ -6,7 +6,6 @@ public interface RequestCodes {
|
||||
int REQUEST_INTRODUCTION = 2;
|
||||
int REQUEST_GROUP_INVITE = 3;
|
||||
int REQUEST_SHARE_FORUM = 4;
|
||||
int REQUEST_WRITE_BLOG_POST = 5;
|
||||
int REQUEST_SHARE_BLOG = 6;
|
||||
int REQUEST_RINGTONE = 7;
|
||||
int REQUEST_PERMISSION_CAMERA_LOCATION = 8;
|
||||
|
||||
@@ -28,9 +28,12 @@ import javax.inject.Inject;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
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.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.briar.android.attachment.AttachmentItem.State.AVAILABLE;
|
||||
@@ -86,7 +89,17 @@ class AttachmentRetrieverImpl implements AttachmentRetriever {
|
||||
List<AttachmentHeader> headers = messageHeader.getAttachmentHeaders();
|
||||
List<LiveData<AttachmentItem>> items = new ArrayList<>(headers.size());
|
||||
boolean needsSize = headers.size() == 1;
|
||||
List<String> supported = asList(getSupportedImageContentTypes());
|
||||
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
|
||||
MutableLiveData<AttachmentItem> liveData =
|
||||
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.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
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.BriarActivity;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
import org.briarproject.briar.android.sharing.BlogSharingStatusActivity;
|
||||
|
||||
@@ -16,6 +18,10 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
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
|
||||
@ParametersNotNullByDefault
|
||||
@@ -23,7 +29,16 @@ public class BlogActivity extends BriarActivity
|
||||
implements BaseFragmentListener {
|
||||
|
||||
@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
|
||||
public void onCreate(@Nullable Bundle state) {
|
||||
@@ -31,32 +46,46 @@ public class BlogActivity extends BriarActivity
|
||||
|
||||
// GroupId from Intent
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||
if (b == null) throw new IllegalStateException("No group ID in intent");
|
||||
GroupId groupId = new GroupId(b);
|
||||
blogController.setGroupId(groupId);
|
||||
GroupId groupId =
|
||||
new GroupId(requireNonNull(i.getByteArrayExtra(GROUP_ID)));
|
||||
// Get post info from intent
|
||||
@Nullable byte[] postId = i.getByteArrayExtra(POST_ID);
|
||||
|
||||
viewModel.setGroupId(groupId, postId == null);
|
||||
|
||||
setContentView(R.layout.activity_fragment_container_toolbar);
|
||||
Toolbar toolbar = setUpCustomToolbar(false);
|
||||
|
||||
// Open Sharing Status on Toolbar click
|
||||
if (toolbar != null) {
|
||||
toolbar.setOnClickListener(v -> {
|
||||
Intent i1 = new Intent(BlogActivity.this,
|
||||
BlogSharingStatusActivity.class);
|
||||
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivity(i1);
|
||||
});
|
||||
}
|
||||
toolbar.setOnClickListener(v -> {
|
||||
Intent i1 = new Intent(BlogActivity.this,
|
||||
BlogSharingStatusActivity.class);
|
||||
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||
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) {
|
||||
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
|
||||
public void injectActivity(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
private void setToolbarSubTitle(int total, int online) {
|
||||
requireNonNull(getSupportActionBar())
|
||||
.setSubtitle(getString(R.string.shared_with, total, online));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
// This class is not thread-safe
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
||||
@NotThreadSafe
|
||||
class BlogCommentItem extends BlogPostItem {
|
||||
|
||||
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;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -12,33 +10,25 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
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.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
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.blog.BaseViewModel.ListUpdate;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.sharing.BlogSharingStatusActivity;
|
||||
import org.briarproject.briar.android.sharing.ShareBlogActivity;
|
||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||
|
||||
import java.util.Collection;
|
||||
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
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 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_WRITE_BLOG_POST;
|
||||
import static org.briarproject.briar.android.controller.SharingController.SharingListener;
|
||||
|
||||
@UiThread
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class BlogFragment extends BaseFragment
|
||||
implements BlogSharingListener, SharingListener,
|
||||
OnBlogPostClickListener {
|
||||
implements OnBlogPostClickListener {
|
||||
|
||||
private final static String TAG = BlogFragment.class.getName();
|
||||
|
||||
@Inject
|
||||
BlogController blogController;
|
||||
@Inject
|
||||
SharingController sharingController;
|
||||
@Nullable
|
||||
private Parcelable layoutManagerState;
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
private GroupId groupId;
|
||||
private BlogPostAdapter adapter;
|
||||
private LayoutManager layoutManager;
|
||||
private BlogViewModel viewModel;
|
||||
private final BlogPostAdapter adapter = new BlogPostAdapter(false, this);
|
||||
private BriarRecyclerView list;
|
||||
private MenuItem writeButton, deleteButton;
|
||||
private boolean isMyBlog = false, canDeleteBlog = false;
|
||||
|
||||
static BlogFragment newInstance(GroupId groupId) {
|
||||
BlogFragment f = new BlogFragment();
|
||||
@@ -87,8 +68,8 @@ public class BlogFragment extends BaseFragment
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
blogController.setBlogSharingListener(this);
|
||||
sharingController.setSharingListener(this);
|
||||
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||
.get(BlogViewModel.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -103,106 +84,82 @@ public class BlogFragment extends BaseFragment
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
||||
|
||||
adapter = new BlogPostAdapter(requireActivity(), this,
|
||||
getFragmentManager());
|
||||
list = v.findViewById(R.id.postList);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
LayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||
list.setLayoutManager(layoutManager);
|
||||
list.setAdapter(adapter);
|
||||
list.showProgressBar();
|
||||
list.setEmptyText(getString(R.string.blogs_other_blog_empty_state));
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
layoutManagerState =
|
||||
savedInstanceState.getParcelable("layoutManager");
|
||||
}
|
||||
|
||||
viewModel.getBlogPosts().observe(getViewLifecycleOwner(), result ->
|
||||
result.onError(this::handleException)
|
||||
.onSuccess(this::onBlogPostsLoaded)
|
||||
);
|
||||
viewModel.getBlogRemoved().observe(getViewLifecycleOwner(), removed -> {
|
||||
if (removed) finish();
|
||||
});
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
sharingController.onStart();
|
||||
loadBlog();
|
||||
loadSharedContacts();
|
||||
loadBlogPosts(false);
|
||||
viewModel.blockAndClearNotifications();
|
||||
list.startPeriodicUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
sharingController.onStop();
|
||||
viewModel.unblockNotifications();
|
||||
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
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.blogs_blog_actions, menu);
|
||||
writeButton = menu.findItem(R.id.action_write_blog_post);
|
||||
if (isMyBlog) writeButton.setVisible(true);
|
||||
deleteButton = menu.findItem(R.id.action_blog_delete);
|
||||
if (canDeleteBlog) deleteButton.setEnabled(true);
|
||||
|
||||
MenuItem writeButton = menu.findItem(R.id.action_write_blog_post);
|
||||
MenuItem deleteButton = menu.findItem(R.id.action_blog_delete);
|
||||
viewModel.getBlog().observe(getViewLifecycleOwner(), blog -> {
|
||||
if (blog.isOurs()) writeButton.setVisible(true);
|
||||
if (blog.canBeRemoved()) deleteButton.setEnabled(true);
|
||||
});
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_write_blog_post:
|
||||
Intent i = new Intent(getActivity(),
|
||||
WriteBlogPostActivity.class);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivityForResult(i, REQUEST_WRITE_BLOG_POST);
|
||||
return true;
|
||||
case R.id.action_blog_share:
|
||||
Intent i2 = new Intent(getActivity(), ShareBlogActivity.class);
|
||||
i2.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i2.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivityForResult(i2, REQUEST_SHARE_BLOG);
|
||||
return true;
|
||||
case R.id.action_blog_sharing_status:
|
||||
Intent i3 = new Intent(getActivity(),
|
||||
BlogSharingStatusActivity.class);
|
||||
i3.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i3.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivity(i3);
|
||||
return true;
|
||||
case R.id.action_blog_delete:
|
||||
showDeleteDialog();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_write_blog_post) {
|
||||
Intent i = new Intent(getActivity(), WriteBlogPostActivity.class);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivity(i);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_blog_share) {
|
||||
Intent i = new Intent(getActivity(), ShareBlogActivity.class);
|
||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivityForResult(i, REQUEST_SHARE_BLOG);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_blog_sharing_status) {
|
||||
Intent i =
|
||||
new Intent(getActivity(), BlogSharingStatusActivity.class);
|
||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivity(i);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_blog_delete) {
|
||||
showDeleteDialog();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int request, int result,
|
||||
@Nullable Intent data) {
|
||||
super.onActivityResult(request, result, data);
|
||||
|
||||
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) {
|
||||
if (request == REQUEST_SHARE_BLOG && result == RESULT_OK) {
|
||||
displaySnackbar(R.string.blogs_sharing_snackbar, false);
|
||||
}
|
||||
}
|
||||
@@ -212,35 +169,26 @@ public class BlogFragment extends BaseFragment
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostAdded(BlogPostHeader header, boolean local) {
|
||||
blogController.loadBlogPost(header,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
this) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem post) {
|
||||
adapter.add(post);
|
||||
if (local) {
|
||||
list.scrollToPosition(0);
|
||||
displaySnackbar(R.string.blogs_blog_post_created,
|
||||
false);
|
||||
} else {
|
||||
displaySnackbar(R.string.blogs_blog_post_received,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
);
|
||||
private void onBlogPostsLoaded(ListUpdate update) {
|
||||
adapter.submitList(update.getItems(), () -> {
|
||||
Boolean wasLocal = update.getPostAddedWasLocal();
|
||||
if (wasLocal != null && wasLocal) {
|
||||
list.scrollToPosition(0);
|
||||
displaySnackbar(R.string.blogs_blog_post_created,
|
||||
false);
|
||||
} else if (wasLocal != null) {
|
||||
displaySnackbar(R.string.blogs_blog_post_received,
|
||||
true);
|
||||
}
|
||||
viewModel.resetLocalUpdate();
|
||||
list.showData();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostClick(BlogPostItem post) {
|
||||
BlogPostFragment f = BlogPostFragment.newInstance(post.getId());
|
||||
BlogPostFragment f =
|
||||
BlogPostFragment.newInstance(groupId, post.getId());
|
||||
showNextFragment(f);
|
||||
}
|
||||
|
||||
@@ -256,111 +204,10 @@ public class BlogFragment extends BaseFragment
|
||||
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
|
||||
public void onBlogInvitationAccepted(ContactId c) {
|
||||
sharingController.add(c);
|
||||
setToolbarSubTitle(sharingController.getTotalCount(),
|
||||
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);
|
||||
public void onLinkClick(String url) {
|
||||
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
||||
f.show(getParentFragmentManager(), f.getUniqueTag());
|
||||
}
|
||||
|
||||
private void displaySnackbar(int stringId, boolean scroll) {
|
||||
@@ -373,38 +220,21 @@ public class BlogFragment extends BaseFragment
|
||||
}
|
||||
|
||||
private void showDeleteDialog() {
|
||||
DialogInterface.OnClickListener okListener =
|
||||
(dialog, which) -> deleteBlog();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
|
||||
R.style.BriarDialogTheme);
|
||||
builder.setTitle(getString(R.string.blogs_remove_blog));
|
||||
builder.setMessage(
|
||||
getString(R.string.blogs_remove_blog_dialog_message));
|
||||
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();
|
||||
}
|
||||
|
||||
private void deleteBlog() {
|
||||
blogController.deleteBlog(
|
||||
new UiResultExceptionHandler<Void, DbException>(this) {
|
||||
@Override
|
||||
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() {
|
||||
viewModel.deleteBlog();
|
||||
Toast.makeText(getActivity(), R.string.blogs_blog_removed, LENGTH_SHORT)
|
||||
.show();
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,23 @@
|
||||
package org.briarproject.briar.android.blog;
|
||||
|
||||
import org.briarproject.briar.android.activity.ActivityScope;
|
||||
import org.briarproject.briar.android.activity.BaseActivity;
|
||||
import org.briarproject.briar.android.controller.SharingController;
|
||||
import org.briarproject.briar.android.controller.SharingControllerImpl;
|
||||
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
|
||||
@Module
|
||||
public class BlogModule {
|
||||
public interface BlogModule {
|
||||
|
||||
@ActivityScope
|
||||
@Provides
|
||||
BlogController provideBlogController(BaseActivity activity,
|
||||
BlogControllerImpl blogController) {
|
||||
activity.addLifecycleController(blogController);
|
||||
return blogController;
|
||||
}
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(FeedViewModel.class)
|
||||
ViewModel bindFeedViewModel(FeedViewModel feedViewModel);
|
||||
|
||||
@ActivityScope
|
||||
@Provides
|
||||
FeedController provideFeedController(FeedControllerImpl feedController) {
|
||||
return feedController;
|
||||
}
|
||||
|
||||
@ActivityScope
|
||||
@Provides
|
||||
SharingController provideSharingController(
|
||||
SharingControllerImpl sharingController) {
|
||||
return sharingController;
|
||||
}
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(BlogViewModel.class)
|
||||
ViewModel bindBlogViewModel(BlogViewModel blogViewModel);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.briar.android.blog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
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.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.util.BriarAdapter;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
class BlogPostAdapter extends BriarAdapter<BlogPostItem, BlogPostViewHolder> {
|
||||
class BlogPostAdapter extends ListAdapter<BlogPostItem, BlogPostViewHolder> {
|
||||
|
||||
private final boolean authorClickable;
|
||||
private final OnBlogPostClickListener listener;
|
||||
@Nullable
|
||||
private final FragmentManager fragmentManager;
|
||||
|
||||
BlogPostAdapter(Context ctx, OnBlogPostClickListener listener,
|
||||
@Nullable FragmentManager fragmentManager) {
|
||||
super(ctx, BlogPostItem.class);
|
||||
BlogPostAdapter(boolean authorClickable, OnBlogPostClickListener listener) {
|
||||
super(new DiffUtil.ItemCallback<BlogPostItem>() {
|
||||
@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.fragmentManager = fragmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlogPostViewHolder onCreateViewHolder(ViewGroup parent,
|
||||
int viewType) {
|
||||
View v = LayoutInflater.from(ctx).inflate(
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.list_item_blog_post, parent, false);
|
||||
return new BlogPostViewHolder(v, false, listener, fragmentManager);
|
||||
return new BlogPostViewHolder(v, false, listener, authorClickable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(BlogPostViewHolder ui, int position) {
|
||||
ui.bindItem(getItemAt(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());
|
||||
ui.bindItem(getItem(position));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,76 +1,159 @@
|
||||
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.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.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.blog.BaseController.BlogListener;
|
||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
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
|
||||
@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 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
|
||||
BlogController blogController;
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
static BlogPostFragment newInstance(MessageId postId) {
|
||||
static BlogPostFragment newInstance(GroupId blogId, MessageId postId) {
|
||||
BlogPostFragment f = new BlogPostFragment();
|
||||
|
||||
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);
|
||||
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
|
||||
public String getUniqueTag() {
|
||||
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;
|
||||
@Nullable
|
||||
protected String text;
|
||||
private boolean read;
|
||||
private final boolean read;
|
||||
|
||||
BlogPostItem(BlogPostHeader header, @Nullable String text) {
|
||||
this.header = header;
|
||||
@@ -74,9 +74,6 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
|
||||
|
||||
protected static int compare(BlogPostHeader h1, BlogPostHeader h2) {
|
||||
// The newest post comes first
|
||||
long aTime = h1.getTimeReceived(), bTime = h2.getTimeReceived();
|
||||
if (aTime > bTime) return -1;
|
||||
if (aTime < bTime) return 1;
|
||||
return 0;
|
||||
return Long.compare(h2.getTimeReceived(), h1.getTimeReceived());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,31 +9,31 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.view.AuthorView;
|
||||
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
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.getSpanned;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getTeaser;
|
||||
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
|
||||
@NotNullByDefault
|
||||
class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final Context ctx;
|
||||
@@ -43,20 +43,16 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
private final ImageButton reblogButton;
|
||||
private final TextView text;
|
||||
private final ViewGroup commentContainer;
|
||||
private final boolean fullText;
|
||||
private final boolean fullText, authorClickable;
|
||||
|
||||
@NonNull
|
||||
private final OnBlogPostClickListener listener;
|
||||
@Nullable
|
||||
private final FragmentManager fragmentManager;
|
||||
|
||||
BlogPostViewHolder(View v, boolean fullText,
|
||||
@NonNull OnBlogPostClickListener listener,
|
||||
@Nullable FragmentManager fragmentManager) {
|
||||
OnBlogPostClickListener listener, boolean authorClickable) {
|
||||
super(v);
|
||||
this.fullText = fullText;
|
||||
this.listener = listener;
|
||||
this.fragmentManager = fragmentManager;
|
||||
this.authorClickable = authorClickable;
|
||||
|
||||
ctx = v.getContext();
|
||||
layout = v.findViewById(R.id.postLayout);
|
||||
@@ -67,10 +63,6 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
commentContainer = v.findViewById(R.id.commentContainer);
|
||||
}
|
||||
|
||||
void setVisibility(int visibility) {
|
||||
layout.setVisibility(visibility);
|
||||
}
|
||||
|
||||
void hideReblogButton() {
|
||||
reblogButton.setVisibility(GONE);
|
||||
}
|
||||
@@ -87,15 +79,15 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
return "blogPost" + id.hashCode();
|
||||
}
|
||||
|
||||
void bindItem(@Nullable BlogPostItem item) {
|
||||
if (item == null) return;
|
||||
|
||||
void bindItem(BlogPostItem item) {
|
||||
setTransitionName(item.getId());
|
||||
if (!fullText) {
|
||||
layout.setClickable(true);
|
||||
layout.setOnClickListener(v -> listener.onBlogPostClick(item));
|
||||
}
|
||||
|
||||
boolean isReblog = item instanceof BlogCommentItem;
|
||||
|
||||
// author and date
|
||||
BlogPostHeader post = item.getPostHeader();
|
||||
author.setAuthor(post.getAuthor(), post.getAuthorInfo());
|
||||
@@ -103,7 +95,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
author.setPersona(
|
||||
item.isRssFeed() ? AuthorView.RSS_FEED : AuthorView.NORMAL);
|
||||
// TODO make author clickable more often #624
|
||||
if (!fullText && item.getHeader().getType() == POST) {
|
||||
if (authorClickable && !isReblog) {
|
||||
author.setAuthorClickable(v -> listener.onAuthorClick(item));
|
||||
} else {
|
||||
author.setAuthorNotClickable();
|
||||
@@ -114,7 +106,7 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
if (fullText) {
|
||||
text.setText(postText);
|
||||
text.setTextIsSelectable(true);
|
||||
makeLinksClickable(text, fragmentManager);
|
||||
makeLinksClickable(text, listener::onLinkClick);
|
||||
} else {
|
||||
text.setTextIsSelectable(false);
|
||||
if (postText.length() > TEASER_LENGTH)
|
||||
@@ -132,32 +124,33 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
// comments
|
||||
commentContainer.removeAllViews();
|
||||
if (item instanceof BlogCommentItem) {
|
||||
onBindComment((BlogCommentItem) item);
|
||||
if (isReblog) {
|
||||
onBindComment((BlogCommentItem) item, authorClickable);
|
||||
} else {
|
||||
reblogger.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void onBindComment(BlogCommentItem item) {
|
||||
private void onBindComment(BlogCommentItem item, boolean authorClickable) {
|
||||
// reblogger
|
||||
reblogger.setAuthor(item.getAuthor(), item.getAuthorInfo());
|
||||
reblogger.setDate(item.getTimestamp());
|
||||
if (!fullText) {
|
||||
if (authorClickable) {
|
||||
reblogger.setAuthorClickable(v -> listener.onAuthorClick(item));
|
||||
} else {
|
||||
reblogger.setAuthorNotClickable();
|
||||
}
|
||||
reblogger.setVisibility(VISIBLE);
|
||||
reblogger.setPersona(AuthorView.REBLOGGER);
|
||||
reblogger.setPersona(REBLOGGER);
|
||||
|
||||
author.setPersona(item.getHeader().getRootPost().isRssFeed() ?
|
||||
AuthorView.RSS_FEED_REBLOGGED :
|
||||
AuthorView.COMMENTER);
|
||||
RSS_FEED_REBLOGGED : COMMENTER);
|
||||
|
||||
// comments
|
||||
// TODO use nested RecyclerView instead like we do for Image Attachments
|
||||
for (BlogCommentHeader c : item.getComments()) {
|
||||
View v = LayoutInflater.from(ctx)
|
||||
.inflate(R.layout.list_item_blog_comment,
|
||||
commentContainer, false);
|
||||
View v = LayoutInflater.from(ctx).inflate(
|
||||
R.layout.list_item_blog_comment, commentContainer, false);
|
||||
|
||||
AuthorView author = v.findViewById(R.id.authorView);
|
||||
TextView text = v.findViewById(R.id.textView);
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
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.ContactId;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
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.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.bramble.api.sync.event.GroupRemovedEvent;
|
||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
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.blog.Blog;
|
||||
import org.briarproject.briar.api.blog.BlogInvitationResponse;
|
||||
@@ -35,85 +35,54 @@ import java.util.logging.Logger;
|
||||
|
||||
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.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
class BlogControllerImpl extends BaseControllerImpl
|
||||
implements ActivityLifecycleController, BlogController, EventListener {
|
||||
class BlogViewModel extends BaseViewModel {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BlogControllerImpl.class.getName());
|
||||
private static final Logger LOG = getLogger(BlogViewModel.class.getName());
|
||||
|
||||
private final BlogSharingManager blogSharingManager;
|
||||
private final SharingController sharingController;
|
||||
|
||||
// UI thread
|
||||
@Nullable
|
||||
private BlogSharingListener listener;
|
||||
private volatile GroupId groupId;
|
||||
|
||||
private volatile GroupId groupId = null;
|
||||
private final MutableLiveData<BlogItem> blog = new MutableLiveData<>();
|
||||
private final MutableLiveData<Boolean> blogRemoved =
|
||||
new MutableLiveData<>();
|
||||
|
||||
@Inject
|
||||
BlogControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager, EventBus eventBus,
|
||||
BlogViewModel(Application application,
|
||||
@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager,
|
||||
TransactionManager db,
|
||||
AndroidExecutor androidExecutor,
|
||||
EventBus eventBus,
|
||||
IdentityManager identityManager,
|
||||
AndroidNotificationManager notificationManager,
|
||||
IdentityManager identityManager, BlogManager blogManager,
|
||||
BlogSharingManager blogSharingManager) {
|
||||
super(dbExecutor, lifecycleManager, eventBus, notificationManager,
|
||||
identityManager, blogManager);
|
||||
BlogManager blogManager,
|
||||
BlogSharingManager blogSharingManager,
|
||||
SharingController sharingController) {
|
||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
||||
eventBus, identityManager, notificationManager, blogManager);
|
||||
this.blogSharingManager = blogSharingManager;
|
||||
}
|
||||
|
||||
@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;
|
||||
this.sharingController = sharingController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (groupId == null || listener == null)
|
||||
throw new IllegalStateException();
|
||||
if (e instanceof BlogPostAddedEvent) {
|
||||
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
||||
if (b.getGroupId().equals(groupId)) {
|
||||
LOG.info("Blog post added");
|
||||
listener.onBlogPostAdded(b.getHeader(), b.isLocal());
|
||||
onBlogPostAdded(b.getHeader(), b.isLocal());
|
||||
}
|
||||
} else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
||||
BlogInvitationResponseReceivedEvent b =
|
||||
@@ -121,41 +90,36 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
BlogInvitationResponse r = b.getMessageHeader();
|
||||
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
||||
LOG.info("Blog invitation accepted");
|
||||
listener.onBlogInvitationAccepted(b.getContactId());
|
||||
sharingController.add(b.getContactId());
|
||||
}
|
||||
} else if (e instanceof ContactLeftShareableEvent) {
|
||||
ContactLeftShareableEvent s = (ContactLeftShareableEvent) e;
|
||||
if (s.getGroupId().equals(groupId)) {
|
||||
LOG.info("Blog left by contact");
|
||||
listener.onBlogLeft(s.getContactId());
|
||||
sharingController.remove(s.getContactId());
|
||||
}
|
||||
} else if (e instanceof GroupRemovedEvent) {
|
||||
GroupRemovedEvent g = (GroupRemovedEvent) e;
|
||||
if (g.getGroup().getId().equals(groupId)) {
|
||||
LOG.info("Blog removed");
|
||||
listener.onBlogRemoved();
|
||||
blogRemoved.setValue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBlogPosts(
|
||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
loadBlogPosts(groupId, handler);
|
||||
/**
|
||||
* Set this before calling any other methods.
|
||||
*/
|
||||
@UiThread
|
||||
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
|
||||
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();
|
||||
private void loadBlog(GroupId groupId) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
@@ -163,50 +127,65 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
Blog b = blogManager.getBlog(groupId);
|
||||
boolean ours = a.getId().equals(b.getAuthor().getId());
|
||||
boolean removable = blogManager.canBeRemoved(b);
|
||||
BlogItem blog = new BlogItem(b, ours, removable);
|
||||
blog.postValue(new BlogItem(b, ours, removable));
|
||||
logDuration(LOG, "Loading blog", start);
|
||||
handler.onResult(blog);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handler.onException(e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBlog(ResultExceptionHandler<Void, DbException> handler) {
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
void blockAndClearNotifications() {
|
||||
notificationManager.blockNotification(groupId);
|
||||
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(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
Blog b = blogManager.getBlog(groupId);
|
||||
blogManager.removeBlog(b);
|
||||
logDuration(LOG, "Removing blog", start);
|
||||
handler.onResult(null);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handler.onException(e);
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSharingContacts(
|
||||
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<BlogItem> getBlog() {
|
||||
return blog;
|
||||
}
|
||||
|
||||
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.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -10,53 +9,43 @@ import android.view.MenuItem;
|
||||
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.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.blog.FeedController.FeedListener;
|
||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||
import org.briarproject.briar.android.blog.BaseViewModel.ListUpdate;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||
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.BlogPostHeader;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
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.RequestCodes.REQUEST_WRITE_BLOG_POST;
|
||||
import static org.briarproject.briar.android.blog.BlogPostFragment.POST_ID;
|
||||
|
||||
@UiThread
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class FeedFragment extends BaseFragment implements
|
||||
OnBlogPostClickListener, FeedListener {
|
||||
public class FeedFragment extends BaseFragment
|
||||
implements OnBlogPostClickListener {
|
||||
|
||||
public final static String TAG = FeedFragment.class.getName();
|
||||
private static final Logger LOG = Logger.getLogger(TAG);
|
||||
|
||||
@Inject
|
||||
FeedController feedController;
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
private BlogPostAdapter adapter;
|
||||
private FeedViewModel viewModel;
|
||||
private final BlogPostAdapter adapter = new BlogPostAdapter(true, this);
|
||||
private LinearLayoutManager layoutManager;
|
||||
private BriarRecyclerView list;
|
||||
@Nullable
|
||||
private Blog personalBlog;
|
||||
@Nullable
|
||||
private Parcelable layoutManagerState;
|
||||
|
||||
public static FeedFragment newInstance() {
|
||||
FeedFragment f = new FeedFragment();
|
||||
@@ -70,7 +59,8 @@ public class FeedFragment extends BaseFragment implements
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
feedController.setFeedListener(this);
|
||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||
.get(FeedViewModel.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -82,9 +72,6 @@ public class FeedFragment extends BaseFragment implements
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_blog, container, false);
|
||||
|
||||
adapter =
|
||||
new BlogPostAdapter(getActivity(), this, getFragmentManager());
|
||||
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
list = v.findViewById(R.id.postList);
|
||||
list.setLayoutManager(layoutManager);
|
||||
@@ -93,103 +80,39 @@ public class FeedFragment extends BaseFragment implements
|
||||
list.setEmptyText(R.string.blogs_feed_empty_state);
|
||||
list.setEmptyAction(R.string.blogs_feed_empty_state_action);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
layoutManagerState =
|
||||
savedInstanceState.getParcelable("layoutManager");
|
||||
}
|
||||
viewModel.getBlogPosts().observe(getViewLifecycleOwner(), result ->
|
||||
result.onError(this::handleException)
|
||||
.onSuccess(this::onBlogPostsLoaded)
|
||||
);
|
||||
|
||||
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
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
feedController.onStart();
|
||||
viewModel.blockAndClearAllBlogPostNotifications();
|
||||
list.startPeriodicUpdate();
|
||||
loadPersonalBlog();
|
||||
loadBlogPosts(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
feedController.onStop();
|
||||
adapter.clear();
|
||||
list.showProgressBar();
|
||||
viewModel.unblockAllBlogPostNotifications();
|
||||
list.stopPeriodicUpdate();
|
||||
// TODO save list position in database/preferences?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
feedController.unsetFeedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (layoutManager != null) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
private void onBlogPostsLoaded(ListUpdate update) {
|
||||
adapter.submitList(update.getItems(), () -> {
|
||||
Boolean wasLocal = update.getPostAddedWasLocal();
|
||||
if (wasLocal != null && wasLocal) {
|
||||
showSnackBar(R.string.blogs_blog_post_created);
|
||||
} else if (wasLocal != null) {
|
||||
showSnackBar(R.string.blogs_blog_post_received);
|
||||
}
|
||||
viewModel.resetLocalUpdate();
|
||||
list.showData();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,67 +123,46 @@ public class FeedFragment extends BaseFragment implements
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (personalBlog == null) return false;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_write_blog_post:
|
||||
Intent i1 =
|
||||
new Intent(getActivity(), WriteBlogPostActivity.class);
|
||||
i1.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
||||
startActivityForResult(i1, REQUEST_WRITE_BLOG_POST);
|
||||
return true;
|
||||
case R.id.action_rss_feeds_import:
|
||||
Intent i2 =
|
||||
new Intent(getActivity(), RssFeedImportActivity.class);
|
||||
startActivity(i2);
|
||||
return true;
|
||||
case R.id.action_rss_feeds_manage:
|
||||
Intent i3 =
|
||||
new Intent(getActivity(), RssFeedManageActivity.class);
|
||||
i3.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
||||
startActivity(i3);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_write_blog_post) {
|
||||
Blog personalBlog = viewModel.getPersonalBlog().getValue();
|
||||
if (personalBlog == null) return false;
|
||||
Intent i = new Intent(getActivity(), WriteBlogPostActivity.class);
|
||||
i.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
||||
startActivity(i);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_rss_feeds_import) {
|
||||
Intent i = new Intent(getActivity(), RssFeedImportActivity.class);
|
||||
startActivity(i);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_rss_feeds_manage) {
|
||||
Blog personalBlog = viewModel.getPersonalBlog().getValue();
|
||||
if (personalBlog == null) return false;
|
||||
Intent i = new Intent(getActivity(), RssFeedManageActivity.class);
|
||||
i.putExtra(GROUP_ID, personalBlog.getId().getBytes());
|
||||
startActivity(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
);
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlogPostClick(BlogPostItem post) {
|
||||
FeedPostFragment f =
|
||||
FeedPostFragment.newInstance(post.getGroupId(), post.getId());
|
||||
showNextFragment(f);
|
||||
Intent i = getBlogActivityIntent(post.getGroupId());
|
||||
i.putExtra(POST_ID, post.getId().getBytes());
|
||||
requireContext().startActivity(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthorClick(BlogPostItem post) {
|
||||
Intent i = new Intent(getContext(), BlogActivity.class);
|
||||
i.putExtra(GROUP_ID, post.getGroupId().getBytes());
|
||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
getContext().startActivity(i);
|
||||
Intent i = getBlogActivityIntent(post.getGroupId());
|
||||
requireContext().startActivity(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLinkClick(String url) {
|
||||
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
|
||||
f.show(getParentFragmentManager(), f.getUniqueTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -268,6 +170,13 @@ public class FeedFragment extends BaseFragment implements
|
||||
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) {
|
||||
int firstVisible =
|
||||
layoutManager.findFirstCompletelyVisibleItemPosition();
|
||||
@@ -283,14 +192,4 @@ public class FeedFragment extends BaseFragment implements
|
||||
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 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.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
|
||||
BaseFragmentListener {
|
||||
@@ -39,13 +39,11 @@ public class ReblogActivity extends BriarActivity implements
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,20 +7,17 @@ import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
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.R;
|
||||
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.view.TextInputView;
|
||||
import org.briarproject.briar.android.view.TextSendController;
|
||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||
import org.briarproject.briar.android.view.TextSendController.SendState;
|
||||
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||
|
||||
import java.util.List;
|
||||
@@ -28,8 +25,7 @@ import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import static android.view.View.FOCUS_DOWN;
|
||||
import static android.view.View.GONE;
|
||||
@@ -37,8 +33,7 @@ import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
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.view.TextSendController.SendState.SENT;
|
||||
import static org.briarproject.briar.android.blog.BlogPostFragment.POST_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -47,12 +42,13 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
||||
|
||||
public static final String TAG = ReblogFragment.class.getName();
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
private BlogViewModel viewModel;
|
||||
private ViewHolder ui;
|
||||
private BlogPostItem item;
|
||||
|
||||
@Inject
|
||||
FeedController feedController;
|
||||
|
||||
static ReblogFragment newInstance(GroupId groupId, MessageId messageId) {
|
||||
ReblogFragment f = new ReblogFragment();
|
||||
|
||||
@@ -72,6 +68,8 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||
.get(BlogViewModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,30 +93,20 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
||||
ui.input.setMaxTextLength(MAX_BLOG_POST_TEXT_LENGTH);
|
||||
showProgressBar();
|
||||
|
||||
feedController.loadBlogPost(blogId, postId,
|
||||
new UiResultExceptionHandler<BlogPostItem, DbException>(
|
||||
this) {
|
||||
@Override
|
||||
public void onResultUi(BlogPostItem result) {
|
||||
item = result;
|
||||
bindViewHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
});
|
||||
viewModel.loadBlogPost(blogId, postId).observe(getViewLifecycleOwner(),
|
||||
result -> result.onError(this::handleException)
|
||||
.onSuccess(this::bindViewHolder)
|
||||
);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private void bindViewHolder() {
|
||||
if (item == null) return;
|
||||
private void bindViewHolder(BlogPostItem item) {
|
||||
this.item = item;
|
||||
|
||||
hideProgressBar();
|
||||
|
||||
ui.post.bindItem(item);
|
||||
ui.post.bindItem(this.item);
|
||||
ui.post.hideReblogButton();
|
||||
|
||||
ui.input.setReady(true);
|
||||
@@ -126,18 +114,11 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||
public void onSendClick(@Nullable String text,
|
||||
List<AttachmentHeader> headers) {
|
||||
ui.input.hideSoftKeyboard();
|
||||
feedController.repeatPost(item, text,
|
||||
new UiExceptionHandler<DbException>(this) {
|
||||
@Override
|
||||
public void onExceptionUi(DbException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
});
|
||||
viewModel.repeatPost(item, text);
|
||||
finish();
|
||||
return new MutableLiveData<>(SENT);
|
||||
}
|
||||
|
||||
private void showProgressBar() {
|
||||
@@ -150,7 +131,7 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
||||
ui.input.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
private class ViewHolder implements OnBlogPostClickListener {
|
||||
|
||||
private final ScrollView scrollView;
|
||||
private final ProgressBar progressBar;
|
||||
@@ -161,18 +142,25 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
||||
scrollView = v.findViewById(R.id.scrollView);
|
||||
progressBar = v.findViewById(R.id.progressBar);
|
||||
post = new BlogPostViewHolder(v.findViewById(R.id.postLayout),
|
||||
true, new OnBlogPostClickListener() {
|
||||
@Override
|
||||
public void onBlogPostClick(BlogPostItem post) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthorClick(BlogPostItem post) {
|
||||
// probably don't want to allow author clicks here
|
||||
}
|
||||
}, getFragmentManager());
|
||||
true, this, false);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,16 +31,12 @@ import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
import static org.briarproject.briar.android.view.TextSendController.SendState;
|
||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -116,8 +112,8 @@ public class WriteBlogPostActivity extends BriarActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||
public void onSendClick(@Nullable String text,
|
||||
List<AttachmentHeader> headers) {
|
||||
if (isNullOrEmpty(text)) throw new AssertionError();
|
||||
|
||||
// hide publish button, show progress bar
|
||||
@@ -126,7 +122,6 @@ public class WriteBlogPostActivity extends BriarActivity
|
||||
progressBar.setVisibility(VISIBLE);
|
||||
|
||||
storePost(text);
|
||||
return new MutableLiveData<>(SENT);
|
||||
}
|
||||
|
||||
private void storePost(String text) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.briar.android.contact;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import org.briarproject.briar.android.util.BriarAdapter;
|
||||
|
||||
@@ -45,8 +44,4 @@ public abstract class BaseContactListAdapter<I extends ContactItem, VH extends C
|
||||
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.briar.R;
|
||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||
|
||||
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.NullSafety;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil.ItemCallback;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
@@ -16,9 +15,6 @@ import androidx.recyclerview.widget.ListAdapter;
|
||||
public class ContactListAdapter extends
|
||||
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;
|
||||
|
||||
public ContactListAdapter(
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
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.PendingContactListActivity;
|
||||
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 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;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -102,7 +100,6 @@ public class ContactListFragment extends BaseFragment
|
||||
.observe(getViewLifecycleOwner(), result -> {
|
||||
result.onError(this::handleException).onSuccess(items -> {
|
||||
adapter.submitList(items);
|
||||
if (requireNonNull(items).size() == 0) list.showData();
|
||||
});
|
||||
});
|
||||
viewModel.getHasPendingContacts()
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.widget.TextView;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
@@ -3,70 +3,41 @@ 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.contact.event.PendingContactAddedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
||||
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.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.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.arch.core.util.Function;
|
||||
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;
|
||||
|
||||
@NotNullByDefault
|
||||
class ContactListViewModel extends DbViewModel implements EventListener {
|
||||
class ContactListViewModel extends ContactsViewModel {
|
||||
|
||||
private static final Logger LOG =
|
||||
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 MutableLiveData<LiveResult<List<ContactListItem>>>
|
||||
contactListItems = new MutableLiveData<>();
|
||||
|
||||
private final MutableLiveData<Boolean> hasPendingContacts =
|
||||
new MutableLiveData<>();
|
||||
|
||||
@@ -79,99 +50,25 @@ class ContactListViewModel extends DbViewModel implements EventListener {
|
||||
ConversationManager conversationManager,
|
||||
ConnectionRegistry connectionRegistry, EventBus eventBus,
|
||||
AndroidNotificationManager notificationManager) {
|
||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||
this.contactManager = contactManager;
|
||||
this.authorManager = authorManager;
|
||||
this.conversationManager = conversationManager;
|
||||
this.connectionRegistry = connectionRegistry;
|
||||
this.eventBus = eventBus;
|
||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
||||
contactManager, authorManager, conversationManager,
|
||||
connectionRegistry, eventBus);
|
||||
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
|
||||
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 PendingContactAddedEvent ||
|
||||
super.eventOccurred(e);
|
||||
if (e instanceof PendingContactAddedEvent ||
|
||||
e instanceof PendingContactRemovedEvent) {
|
||||
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() {
|
||||
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() {
|
||||
runOnDbThread(() -> {
|
||||
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;
|
||||
}
|
||||
|
||||
public void updatePendingContact(String name, PendingContact p) {
|
||||
void updatePendingContact(String name, PendingContact p) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
contactManager.removePendingContact(p.getId());
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog.Builder;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
@@ -48,6 +48,7 @@ import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
||||
public class NicknameFragment extends BaseFragment {
|
||||
|
||||
private static final String TAG = NicknameFragment.class.getName();
|
||||
private static final String SAVED_LINK = "savedLink";
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
@@ -67,6 +68,20 @@ public class NicknameFragment extends BaseFragment {
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
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
|
||||
@@ -74,14 +89,9 @@ public class NicknameFragment extends BaseFragment {
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (getActivity() == null || getContext() == null) return null;
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_nickname,
|
||||
container, false);
|
||||
|
||||
viewModel = ViewModelProviders.of(getActivity(), viewModelFactory)
|
||||
.get(AddContactViewModel.class);
|
||||
|
||||
contactNameLayout = v.findViewById(R.id.contactNameLayout);
|
||||
contactNameInput = v.findViewById(R.id.contactNameInput);
|
||||
|
||||
@@ -93,6 +103,12 @@ public class NicknameFragment extends BaseFragment {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(SAVED_LINK, viewModel.getRemoteHandshakeLink());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getNicknameOrNull() {
|
||||
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.briar.android.contact.BaseContactListAdapter;
|
||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.sync.GroupId;
|
||||
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.OnContactClickListener;
|
||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
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.briar.R;
|
||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||
|
||||
@NotNullByDefault
|
||||
class ContactSelectorAdapter extends
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.view.MenuItem;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.briarproject.briar.android.contactselection;
|
||||
import android.view.View;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user