Compare commits
5 Commits
1905-use-c
...
1821-bluet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb8333660b | ||
|
|
9925c799a1 | ||
|
|
3ee2d2112c | ||
|
|
da5b2c194a | ||
|
|
244d03a718 |
@@ -2,7 +2,6 @@ image: briar/ci-image-android:latest
|
|||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- optional_tests
|
|
||||||
- check_reproducibility
|
- check_reproducibility
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@@ -32,33 +31,3 @@ test_reproducible:
|
|||||||
- "curl -X POST -F token=${RELEASE_CHECK_TOKEN} -F ref=master -F variables[RELEASE_TAG]=${CI_COMMIT_REF_NAME} https://code.briarproject.org/api/v4/projects/61/trigger/pipeline"
|
- "curl -X POST -F token=${RELEASE_CHECK_TOKEN} -F ref=master -F variables[RELEASE_TAG]=${CI_COMMIT_REF_NAME} https://code.briarproject.org/api/v4/projects/61/trigger/pipeline"
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
|
|
||||||
.optional_tests:
|
|
||||||
stage: optional_tests
|
|
||||||
before_script:
|
|
||||||
- set -e
|
|
||||||
- export GRADLE_USER_HOME=$PWD/.gradle
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .gradle/wrapper
|
|
||||||
- .gradle/caches
|
|
||||||
|
|
||||||
script:
|
|
||||||
- OPTIONAL_TESTS=org.briarproject.bramble.plugin.tor.BridgeTest ./gradlew --info bramble-java:test --tests BridgeTest
|
|
||||||
|
|
||||||
after_script:
|
|
||||||
# these file change every time but should not be cached
|
|
||||||
- rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
|
|
||||||
- rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/
|
|
||||||
|
|
||||||
manual_tests:
|
|
||||||
extends: .optional_tests
|
|
||||||
when: manual
|
|
||||||
except:
|
|
||||||
- tags
|
|
||||||
|
|
||||||
pre_release_tests:
|
|
||||||
extends: .optional_tests
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10214
|
versionCode 10213
|
||||||
versionName "1.2.14"
|
versionName "1.2.13"
|
||||||
consumerProguardFiles 'proguard-rules.txt'
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
return component.getCircumventionProvider().getBridges(false);
|
return component.getCircumventionProvider().getBridges(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long TIMEOUT = SECONDS.toMillis(60);
|
private final static long TIMEOUT = SECONDS.toMillis(30);
|
||||||
|
|
||||||
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M16,17V14H9V10H16V7L21,12L16,17M14,2A2,2 0 0,1 16,4V6H14V4H5V20H14V18H16V20A2,2 0 0,1 14,22H5A2,2 0 0,1 3,20V4A2,2 0 0,1 5,2H14Z" /></svg>
|
|
||||||
|
Before Width: | Height: | Size: 423 B |
@@ -22,11 +22,9 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10214
|
versionCode 10213
|
||||||
versionName "1.2.14"
|
versionName "1.2.13"
|
||||||
applicationId "org.briarproject.briar.android"
|
applicationId "org.briarproject.briar.android"
|
||||||
|
|
||||||
vectorDrawables.useSupportLibrary = true
|
|
||||||
buildConfigField "String", "GitHash",
|
buildConfigField "String", "GitHash",
|
||||||
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
||||||
def now = (long) (System.currentTimeMillis() / 1000)
|
def now = (long) (System.currentTimeMillis() / 1000)
|
||||||
|
|||||||
@@ -448,6 +448,12 @@
|
|||||||
android:label="@string/pending_contact_requests"
|
android:label="@string/pending_contact_requests"
|
||||||
android:theme="@style/BriarTheme" />
|
android:theme="@style/BriarTheme" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".android.bluetoothsetup.BluetoothSetupActivity"
|
||||||
|
android:label="Bluetooth Setup"
|
||||||
|
android:theme="@style/BriarTheme"
|
||||||
|
android:windowSoftInputMode="adjustResize|stateHidden" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
R.string.ongoing_notification_title;
|
R.string.ongoing_notification_title;
|
||||||
int text = locked ? R.string.lock_tap_to_unlock :
|
int text = locked ? R.string.lock_tap_to_unlock :
|
||||||
R.string.ongoing_notification_text;
|
R.string.ongoing_notification_text;
|
||||||
int icon = locked ? R.drawable.notification_lock :
|
int icon = locked ? R.drawable.startup_lock :
|
||||||
R.drawable.notification_ongoing;
|
R.drawable.notification_ongoing;
|
||||||
// Ongoing foreground notification that shows BriarService is running
|
// Ongoing foreground notification that shows BriarService is running
|
||||||
NotificationCompat.Builder b =
|
NotificationCompat.Builder b =
|
||||||
@@ -624,7 +624,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
|
|
||||||
NotificationCompat.Builder b =
|
NotificationCompat.Builder b =
|
||||||
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
|
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
|
||||||
b.setSmallIcon(R.drawable.notification_signout);
|
b.setSmallIcon(R.drawable.ic_signout);
|
||||||
b.setColor(getColor(appContext, R.color.briar_primary));
|
b.setColor(getColor(appContext, R.color.briar_primary));
|
||||||
b.setContentTitle(
|
b.setContentTitle(
|
||||||
appContext.getText(R.string.reminder_notification_title));
|
appContext.getText(R.string.reminder_notification_title));
|
||||||
|
|||||||
@@ -30,17 +30,15 @@ import org.briarproject.bramble.util.StringUtils;
|
|||||||
import org.briarproject.briar.android.account.DozeHelperModule;
|
import org.briarproject.briar.android.account.DozeHelperModule;
|
||||||
import org.briarproject.briar.android.account.LockManagerImpl;
|
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||||
import org.briarproject.briar.android.account.SetupModule;
|
import org.briarproject.briar.android.account.SetupModule;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupModule;
|
||||||
import org.briarproject.briar.android.contact.ContactListModule;
|
import org.briarproject.briar.android.contact.ContactListModule;
|
||||||
import org.briarproject.briar.android.forum.ForumModule;
|
import org.briarproject.briar.android.forum.ForumModule;
|
||||||
import org.briarproject.briar.android.introduction.IntroductionModule;
|
|
||||||
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
||||||
import org.briarproject.briar.android.login.LoginModule;
|
import org.briarproject.briar.android.login.LoginModule;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
|
||||||
import org.briarproject.briar.android.privategroup.list.GroupListModule;
|
import org.briarproject.briar.android.privategroup.list.GroupListModule;
|
||||||
import org.briarproject.briar.android.reporting.DevReportModule;
|
import org.briarproject.briar.android.reporting.DevReportModule;
|
||||||
import org.briarproject.briar.android.settings.SettingsModule;
|
import org.briarproject.briar.android.settings.SettingsModule;
|
||||||
import org.briarproject.briar.android.sharing.SharingModule;
|
|
||||||
import org.briarproject.briar.android.test.TestAvatarCreatorImpl;
|
import org.briarproject.briar.android.test.TestAvatarCreatorImpl;
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
@@ -81,12 +79,10 @@ import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
|||||||
SettingsModule.class,
|
SettingsModule.class,
|
||||||
DevReportModule.class,
|
DevReportModule.class,
|
||||||
ContactListModule.class,
|
ContactListModule.class,
|
||||||
IntroductionModule.class,
|
BluetoothSetupModule.class,
|
||||||
// below need to be within same scope as ViewModelProvider.Factory
|
// below need to be within same scope as ViewModelProvider.Factory
|
||||||
ForumModule.class,
|
ForumModule.BindsModule.class,
|
||||||
GroupListModule.class,
|
GroupListModule.class,
|
||||||
GroupConversationModule.class,
|
|
||||||
SharingModule.class,
|
|
||||||
})
|
})
|
||||||
public class AppModule {
|
public class AppModule {
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ import org.briarproject.briar.android.blog.ReblogFragment;
|
|||||||
import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
||||||
import org.briarproject.briar.android.blog.RssFeedManageActivity;
|
import org.briarproject.briar.android.blog.RssFeedManageActivity;
|
||||||
import org.briarproject.briar.android.blog.WriteBlogPostActivity;
|
import org.briarproject.briar.android.blog.WriteBlogPostActivity;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupActivity;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupChooseFragment;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupPendingFragment;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupStartFragment;
|
||||||
import org.briarproject.briar.android.contact.ContactListFragment;
|
import org.briarproject.briar.android.contact.ContactListFragment;
|
||||||
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
||||||
import org.briarproject.briar.android.contact.add.remote.LinkExchangeFragment;
|
import org.briarproject.briar.android.contact.add.remote.LinkExchangeFragment;
|
||||||
@@ -32,6 +36,7 @@ import org.briarproject.briar.android.conversation.ImageFragment;
|
|||||||
import org.briarproject.briar.android.forum.CreateForumActivity;
|
import org.briarproject.briar.android.forum.CreateForumActivity;
|
||||||
import org.briarproject.briar.android.forum.ForumActivity;
|
import org.briarproject.briar.android.forum.ForumActivity;
|
||||||
import org.briarproject.briar.android.forum.ForumListFragment;
|
import org.briarproject.briar.android.forum.ForumListFragment;
|
||||||
|
import org.briarproject.briar.android.forum.ForumModule;
|
||||||
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
||||||
import org.briarproject.briar.android.introduction.ContactChooserFragment;
|
import org.briarproject.briar.android.introduction.ContactChooserFragment;
|
||||||
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
||||||
@@ -49,6 +54,7 @@ import org.briarproject.briar.android.navdrawer.TransportsActivity;
|
|||||||
import org.briarproject.briar.android.panic.PanicPreferencesActivity;
|
import org.briarproject.briar.android.panic.PanicPreferencesActivity;
|
||||||
import org.briarproject.briar.android.panic.PanicResponderActivity;
|
import org.briarproject.briar.android.panic.PanicResponderActivity;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
||||||
|
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
||||||
import org.briarproject.briar.android.privategroup.creation.CreateGroupActivity;
|
import org.briarproject.briar.android.privategroup.creation.CreateGroupActivity;
|
||||||
import org.briarproject.briar.android.privategroup.creation.CreateGroupFragment;
|
import org.briarproject.briar.android.privategroup.creation.CreateGroupFragment;
|
||||||
import org.briarproject.briar.android.privategroup.creation.CreateGroupModule;
|
import org.briarproject.briar.android.privategroup.creation.CreateGroupModule;
|
||||||
@@ -87,10 +93,12 @@ import dagger.Component;
|
|||||||
ActivityModule.class,
|
ActivityModule.class,
|
||||||
BlogModule.class,
|
BlogModule.class,
|
||||||
CreateGroupModule.class,
|
CreateGroupModule.class,
|
||||||
|
ForumModule.class,
|
||||||
GroupInvitationModule.class,
|
GroupInvitationModule.class,
|
||||||
|
GroupConversationModule.class,
|
||||||
GroupMemberModule.class,
|
GroupMemberModule.class,
|
||||||
GroupRevealModule.class,
|
GroupRevealModule.class,
|
||||||
SharingModule.SharingLegacyModule.class
|
SharingModule.class
|
||||||
}, dependencies = AndroidComponent.class)
|
}, dependencies = AndroidComponent.class)
|
||||||
public interface ActivityComponent {
|
public interface ActivityComponent {
|
||||||
|
|
||||||
@@ -182,6 +190,8 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(CrashReportActivity crashReportActivity);
|
void inject(CrashReportActivity crashReportActivity);
|
||||||
|
|
||||||
|
void inject(BluetoothSetupActivity activity);
|
||||||
|
|
||||||
// Fragments
|
// Fragments
|
||||||
|
|
||||||
void inject(AuthorNameFragment fragment);
|
void inject(AuthorNameFragment fragment);
|
||||||
@@ -238,4 +248,10 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(ConfirmAvatarDialogFragment fragment);
|
void inject(ConfirmAvatarDialogFragment fragment);
|
||||||
|
|
||||||
|
void inject(BluetoothSetupStartFragment fragment);
|
||||||
|
|
||||||
|
void inject(BluetoothSetupChooseFragment fragment);
|
||||||
|
|
||||||
|
void inject(BluetoothSetupPendingFragment fragment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.briarproject.briar.android.BriarApplication;
|
|||||||
import org.briarproject.briar.android.DestroyableContext;
|
import org.briarproject.briar.android.DestroyableContext;
|
||||||
import org.briarproject.briar.android.Localizer;
|
import org.briarproject.briar.android.Localizer;
|
||||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
||||||
|
import org.briarproject.briar.android.forum.ForumModule;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
@@ -86,6 +87,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
activityComponent = DaggerActivityComponent.builder()
|
activityComponent = DaggerActivityComponent.builder()
|
||||||
.androidComponent(applicationComponent)
|
.androidComponent(applicationComponent)
|
||||||
.activityModule(getActivityModule())
|
.activityModule(getActivityModule())
|
||||||
|
.forumModule(getForumModule())
|
||||||
.build();
|
.build();
|
||||||
injectActivity(activityComponent);
|
injectActivity(activityComponent);
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
@@ -120,6 +122,11 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
return new ActivityModule(this);
|
return new ActivityModule(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO use a test module where this is used in tests
|
||||||
|
protected ForumModule getForumModule() {
|
||||||
|
return new ForumModule();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
* @param ownLayout true if the custom toolbar brings its own layout
|
* @param ownLayout true if the custom toolbar brings its own layout
|
||||||
* @return the Toolbar object or null if content view did not contain one
|
* @return the Toolbar object or null if content view did not contain one
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected Toolbar setUpCustomToolbar(boolean ownLayout) {
|
protected Toolbar setUpCustomToolbar(boolean ownLayout) {
|
||||||
// Custom Toolbar
|
// Custom Toolbar
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
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.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupActivity extends BriarActivity implements
|
||||||
|
BaseFragmentListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectActivity(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle state) {
|
||||||
|
super.onCreate(state);
|
||||||
|
setContentView(R.layout.activity_fragment_container);
|
||||||
|
|
||||||
|
ActionBar ab = getSupportActionBar();
|
||||||
|
if (ab != null) {
|
||||||
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
if (state == null) {
|
||||||
|
showInitialFragment(new BluetoothSetupStartFragment());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
onBackPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
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.fragment.BaseFragment;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupChooseFragment extends BaseFragment {
|
||||||
|
private static final String TAG =
|
||||||
|
BluetoothSetupChooseFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
if (getActivity() == null || getContext() == null) return null;
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(requireActivity())
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
View v =
|
||||||
|
inflater.inflate(R.layout.fragment_bluetooth_setup_choose,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
// TODO to enable when user picks a device from list
|
||||||
|
|
||||||
|
Button continueButton = v.findViewById(R.id.continueButton);
|
||||||
|
continueButton.setOnClickListener(view -> {
|
||||||
|
showNextFragment(new BluetoothSetupPendingFragment());
|
||||||
|
});
|
||||||
|
continueButton.setEnabled(true);
|
||||||
|
|
||||||
|
// RecyclerView devices = v.findViewById(R.id.devices);
|
||||||
|
// devices.setHasFixedSize(true);
|
||||||
|
// final LinearLayoutManager layoutManager =
|
||||||
|
// new LinearLayoutManager(getActivity(),
|
||||||
|
// LinearLayoutManager.VERTICAL, false);
|
||||||
|
// devices.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.multibindings.IntoMap;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class BluetoothSetupModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@IntoMap
|
||||||
|
@ViewModelKey(BluetoothSetupViewModel.class)
|
||||||
|
abstract ViewModel bindBluetoothSetupViewModel(
|
||||||
|
BluetoothSetupViewModel bluetoothSetupViewModel);
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
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.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupPendingFragment extends BaseFragment {
|
||||||
|
private static final String TAG =
|
||||||
|
BluetoothSetupPendingFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
if (getActivity() == null || getContext() == null) return null;
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(requireActivity())
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
View v = inflater.inflate(R.layout.fragment_bluetooth_setup_pending,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onContinueButtonClicked() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
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.fragment.BaseFragment;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupStartFragment extends BaseFragment {
|
||||||
|
private static final String TAG =
|
||||||
|
BluetoothSetupStartFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
if (getActivity() == null || getContext() == null) return null;
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(requireActivity())
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
View v = inflater.inflate(R.layout.fragment_bluetooth_setup_start,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
// TODO device-BT and BT-plugin needs to be enabled at this point
|
||||||
|
|
||||||
|
Button startButton = v.findViewById(R.id.startButton);
|
||||||
|
startButton.setOnClickListener(view -> {
|
||||||
|
showNextFragment(new BluetoothSetupChooseFragment());
|
||||||
|
});
|
||||||
|
startButton.setEnabled(true);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public class BluetoothSetupViewModel extends DbViewModel {
|
||||||
|
|
||||||
|
private final static Logger LOG =
|
||||||
|
getLogger(BluetoothSetupViewModel.class.getName());
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BluetoothSetupViewModel(Application application,
|
||||||
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager,
|
||||||
|
TransactionManager db,
|
||||||
|
AndroidExecutor androidExecutor) {
|
||||||
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
|
|
||||||
@@ -44,4 +45,8 @@ public abstract class BaseContactListAdapter<I extends ContactItem, VH extends C
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnContactClickListener<I> {
|
||||||
|
void onItemClick(View view, I item);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.view.ViewGroup;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.NullSafety;
|
import org.briarproject.bramble.api.nullsafety.NullSafety;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.DiffUtil.ItemCallback;
|
import androidx.recyclerview.widget.DiffUtil.ItemCallback;
|
||||||
import androidx.recyclerview.widget.ListAdapter;
|
import androidx.recyclerview.widget.ListAdapter;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupActivity;
|
||||||
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
||||||
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
||||||
import org.briarproject.briar.android.conversation.ConversationActivity;
|
import org.briarproject.briar.android.conversation.ConversationActivity;
|
||||||
@@ -101,8 +103,6 @@ public class ContactListFragment extends BaseFragment
|
|||||||
.observe(getViewLifecycleOwner(), result -> {
|
.observe(getViewLifecycleOwner(), result -> {
|
||||||
result.onError(this::handleException).onSuccess(items -> {
|
result.onError(this::handleException).onSuccess(items -> {
|
||||||
adapter.submitList(items);
|
adapter.submitList(items);
|
||||||
// TODO: this should not be required any longer due to
|
|
||||||
// changes in BriarRecyclerView
|
|
||||||
if (requireNonNull(items).size() == 0) list.showData();
|
if (requireNonNull(items).size() == 0) list.showData();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -135,6 +135,11 @@ public class ContactListFragment extends BaseFragment
|
|||||||
case R.id.action_add_contact_remotely:
|
case R.id.action_add_contact_remotely:
|
||||||
startActivity(
|
startActivity(
|
||||||
new Intent(getContext(), AddContactActivity.class));
|
new Intent(getContext(), AddContactActivity.class));
|
||||||
|
return;
|
||||||
|
case R.id.action_bluetooth_setup:
|
||||||
|
startActivity(
|
||||||
|
new Intent(getContext(),
|
||||||
|
BluetoothSetupActivity.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|||||||
@@ -3,41 +3,70 @@ package org.briarproject.briar.android.contact;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
||||||
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
|
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
|
||||||
|
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
|
||||||
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent;
|
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent;
|
||||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent;
|
||||||
|
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
|
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||||
|
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.arch.core.util.Function;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ContactListViewModel extends ContactsViewModel {
|
class ContactListViewModel extends DbViewModel implements EventListener {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(ContactListViewModel.class.getName());
|
getLogger(ContactListViewModel.class.getName());
|
||||||
|
|
||||||
|
private final ContactManager contactManager;
|
||||||
|
private final AuthorManager authorManager;
|
||||||
|
private final ConversationManager conversationManager;
|
||||||
|
private final ConnectionRegistry connectionRegistry;
|
||||||
|
private final EventBus eventBus;
|
||||||
private final AndroidNotificationManager notificationManager;
|
private final AndroidNotificationManager notificationManager;
|
||||||
|
|
||||||
|
private final MutableLiveData<LiveResult<List<ContactListItem>>>
|
||||||
|
contactListItems = new MutableLiveData<>();
|
||||||
|
|
||||||
private final MutableLiveData<Boolean> hasPendingContacts =
|
private final MutableLiveData<Boolean> hasPendingContacts =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
|
|
||||||
@@ -50,25 +79,99 @@ class ContactListViewModel extends ContactsViewModel {
|
|||||||
ConversationManager conversationManager,
|
ConversationManager conversationManager,
|
||||||
ConnectionRegistry connectionRegistry, EventBus eventBus,
|
ConnectionRegistry connectionRegistry, EventBus eventBus,
|
||||||
AndroidNotificationManager notificationManager) {
|
AndroidNotificationManager notificationManager) {
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
contactManager, authorManager, conversationManager,
|
this.contactManager = contactManager;
|
||||||
connectionRegistry, eventBus);
|
this.authorManager = authorManager;
|
||||||
|
this.conversationManager = conversationManager;
|
||||||
|
this.connectionRegistry = connectionRegistry;
|
||||||
|
this.eventBus = eventBus;
|
||||||
this.notificationManager = notificationManager;
|
this.notificationManager = notificationManager;
|
||||||
|
this.eventBus.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCleared() {
|
||||||
|
super.onCleared();
|
||||||
|
eventBus.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadContacts() {
|
||||||
|
loadList(this::loadContacts, contactListItems::setValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ContactListItem> loadContacts(Transaction txn)
|
||||||
|
throws DbException {
|
||||||
|
long start = now();
|
||||||
|
List<ContactListItem> contacts = new ArrayList<>();
|
||||||
|
for (Contact c : contactManager.getContacts(txn)) {
|
||||||
|
ContactId id = c.getId();
|
||||||
|
AuthorInfo authorInfo = authorManager.getAuthorInfo(txn, c);
|
||||||
|
MessageTracker.GroupCount count =
|
||||||
|
conversationManager.getGroupCount(txn, id);
|
||||||
|
boolean connected = connectionRegistry.isConnected(c.getId());
|
||||||
|
contacts.add(new ContactListItem(c, authorInfo, connected, count));
|
||||||
|
}
|
||||||
|
Collections.sort(contacts);
|
||||||
|
logDuration(LOG, "Full load", start);
|
||||||
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
super.eventOccurred(e);
|
if (e instanceof ContactAddedEvent) {
|
||||||
if (e instanceof PendingContactAddedEvent ||
|
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 ||
|
||||||
e instanceof PendingContactRemovedEvent) {
|
e instanceof PendingContactRemovedEvent) {
|
||||||
checkForPendingContacts();
|
checkForPendingContacts();
|
||||||
|
} else if (e instanceof AvatarUpdatedEvent) {
|
||||||
|
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
||||||
|
updateItem(a.getContactId(), item -> new ContactListItem(item,
|
||||||
|
a.getAttachmentHeader()), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveData<LiveResult<List<ContactListItem>>> getContactListItems() {
|
||||||
|
return contactListItems;
|
||||||
|
}
|
||||||
|
|
||||||
LiveData<Boolean> getHasPendingContacts() {
|
LiveData<Boolean> getHasPendingContacts() {
|
||||||
return hasPendingContacts;
|
return hasPendingContacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateItem(ContactId c,
|
||||||
|
Function<ContactListItem, ContactListItem> replacer, boolean sort) {
|
||||||
|
List<ContactListItem> list = updateListItems(contactListItems,
|
||||||
|
itemToTest -> itemToTest.getContact().getId().equals(c),
|
||||||
|
replacer);
|
||||||
|
if (list == null) return;
|
||||||
|
if (sort) Collections.sort(list);
|
||||||
|
contactListItems.setValue(new LiveResult<>(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeItem(ContactId c) {
|
||||||
|
List<ContactListItem> list = removeListItems(contactListItems,
|
||||||
|
itemToTest -> itemToTest.getContact().getId().equals(c));
|
||||||
|
if (list == null) return;
|
||||||
|
contactListItems.setValue(new LiveResult<>(list));
|
||||||
|
}
|
||||||
|
|
||||||
void checkForPendingContacts() {
|
void checkForPendingContacts() {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,167 +0,0 @@
|
|||||||
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.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public 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();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
|
||||||
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
public interface OnContactClickListener<I> {
|
|
||||||
|
|
||||||
void onItemClick(View view, I item);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ import org.briarproject.bramble.api.contact.ContactId;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter;
|
||||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
import org.briarproject.briar.android.contact.ContactItemViewHolder;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ContactSelectorAdapter extends
|
class ContactSelectorAdapter extends
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import android.view.MenuItem;
|
|||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.briarproject.briar.android.contactselection;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface SharingController {
|
public interface SharingController {
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class SharingControllerImpl implements SharingController, EventListener {
|
public class SharingControllerImpl implements SharingController, EventListener {
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android.conversation;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.transition.Slide;
|
import android.transition.Slide;
|
||||||
@@ -106,7 +105,6 @@ import androidx.recyclerview.selection.SelectionTracker.SelectionObserver;
|
|||||||
import androidx.recyclerview.selection.StorageStrategy;
|
import androidx.recyclerview.selection.StorageStrategy;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import de.hdodenhof.circleimageview.CircleImageView;
|
||||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||||
|
|
||||||
@@ -481,10 +479,12 @@ public class ConversationActivity extends BriarActivity
|
|||||||
@UiThread
|
@UiThread
|
||||||
private void displayContactOnlineStatus() {
|
private void displayContactOnlineStatus() {
|
||||||
if (connectionRegistry.isConnected(contactId)) {
|
if (connectionRegistry.isConnected(contactId)) {
|
||||||
toolbarStatus.setImageResource(R.drawable.contact_online);
|
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
ConversationActivity.this, R.drawable.contact_online));
|
||||||
toolbarStatus.setContentDescription(getString(R.string.online));
|
toolbarStatus.setContentDescription(getString(R.string.online));
|
||||||
} else {
|
} else {
|
||||||
toolbarStatus.setImageResource(R.drawable.contact_offline);
|
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
ConversationActivity.this, R.drawable.contact_offline));
|
||||||
toolbarStatus.setContentDescription(getString(R.string.offline));
|
toolbarStatus.setContentDescription(getString(R.string.offline));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -935,16 +935,13 @@ public class ConversationActivity extends BriarActivity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int color =
|
|
||||||
ContextCompat.getColor(this, R.color.briar_primary);
|
|
||||||
Drawable drawable = VectorDrawableCompat
|
|
||||||
.create(getResources(), R.drawable.ic_more_vert_accent, null);
|
|
||||||
new MaterialTapTargetPrompt.Builder(ConversationActivity.this,
|
new MaterialTapTargetPrompt.Builder(ConversationActivity.this,
|
||||||
R.style.OnboardingDialogTheme).setTarget(target)
|
R.style.OnboardingDialogTheme).setTarget(target)
|
||||||
.setPrimaryText(R.string.introduction_onboarding_title)
|
.setPrimaryText(R.string.introduction_onboarding_title)
|
||||||
.setSecondaryText(R.string.introduction_onboarding_text)
|
.setSecondaryText(R.string.introduction_onboarding_text)
|
||||||
.setIconDrawable(drawable)
|
.setIcon(R.drawable.ic_more_vert_accent)
|
||||||
.setBackgroundColour(color)
|
.setBackgroundColour(
|
||||||
|
ContextCompat.getColor(this, R.color.briar_primary))
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,54 +6,52 @@ import android.os.Bundle;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.forum.ForumController.ForumListener;
|
||||||
import org.briarproject.briar.android.sharing.ForumSharingStatusActivity;
|
import org.briarproject.briar.android.sharing.ForumSharingStatusActivity;
|
||||||
import org.briarproject.briar.android.sharing.ShareForumActivity;
|
import org.briarproject.briar.android.sharing.ShareForumActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||||
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_FORUM;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_FORUM;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.observeOnce;
|
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class ForumActivity extends
|
public class ForumActivity extends
|
||||||
ThreadListActivity<ForumPostItem, ThreadItemAdapter<ForumPostItem>> {
|
ThreadListActivity<Forum, ForumPostItem, ThreadItemAdapter<ForumPostItem>>
|
||||||
|
implements ForumListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ForumController forumController;
|
||||||
|
|
||||||
private ForumViewModel viewModel;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectActivity(ActivityComponent component) {
|
public void injectActivity(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
|
||||||
.get(ForumViewModel.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThreadListViewModel<ForumPostItem> getViewModel() {
|
protected ThreadListController<Forum, ForumPostItem> getController() {
|
||||||
return viewModel;
|
return forumController;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ThreadItemAdapter<ForumPostItem> createAdapter() {
|
|
||||||
return new ThreadItemAdapter<>(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,27 +59,36 @@ public class ForumActivity extends
|
|||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
|
||||||
Toolbar toolbar = setUpCustomToolbar(false);
|
Toolbar toolbar = setUpCustomToolbar(false);
|
||||||
// Open member list on Toolbar click
|
|
||||||
toolbar.setOnClickListener(v -> {
|
|
||||||
Intent i = new Intent(ForumActivity.this,
|
|
||||||
ForumSharingStatusActivity.class);
|
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
|
||||||
startActivity(i);
|
|
||||||
});
|
|
||||||
|
|
||||||
String groupName = getIntent().getStringExtra(GROUP_NAME);
|
Intent i = getIntent();
|
||||||
if (groupName != null) {
|
String groupName = i.getStringExtra(GROUP_NAME);
|
||||||
setTitle(groupName);
|
if (groupName != null) setTitle(groupName);
|
||||||
} else {
|
else loadNamedGroup();
|
||||||
observeOnce(viewModel.loadForum(), this, forum ->
|
|
||||||
setTitle(forum.getName())
|
// Open member list on Toolbar click
|
||||||
);
|
if (toolbar != null) {
|
||||||
|
toolbar.setOnClickListener(v -> {
|
||||||
|
Intent i1 = new Intent(ForumActivity.this,
|
||||||
|
ForumSharingStatusActivity.class);
|
||||||
|
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
|
startActivity(i1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int request, int result,
|
protected void onNamedGroupLoaded(Forum forum) {
|
||||||
@Nullable Intent data) {
|
setTitle(forum.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ThreadItemAdapter<ForumPostItem> createAdapter(
|
||||||
|
LinearLayoutManager layoutManager) {
|
||||||
|
return new ThreadItemAdapter<>(this, layoutManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int request, int result, Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
|
|
||||||
if (request == REQUEST_SHARE_FORUM && result == RESULT_OK) {
|
if (request == REQUEST_SHARE_FORUM && result == RESULT_OK) {
|
||||||
@@ -94,31 +101,32 @@ public class ForumActivity extends
|
|||||||
// Inflate the menu items for use in the action bar
|
// Inflate the menu items for use in the action bar
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.forum_actions, menu);
|
inflater.inflate(R.menu.forum_actions, menu);
|
||||||
super.onCreateOptionsMenu(menu);
|
|
||||||
return true;
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
// Handle presses on the action bar items
|
// Handle presses on the action bar items
|
||||||
int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == R.id.action_forum_share) {
|
case R.id.action_forum_share:
|
||||||
Intent i = new Intent(this, ShareForumActivity.class);
|
Intent i2 = new Intent(this, ShareForumActivity.class);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i2.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i2.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivityForResult(i, REQUEST_SHARE_FORUM);
|
startActivityForResult(i2, REQUEST_SHARE_FORUM);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_forum_sharing_status) {
|
case R.id.action_forum_sharing_status:
|
||||||
Intent i = new Intent(this, ForumSharingStatusActivity.class);
|
Intent i3 = new Intent(this, ForumSharingStatusActivity.class);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i3.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i3.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivity(i);
|
startActivity(i3);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_forum_delete) {
|
case R.id.action_forum_delete:
|
||||||
showUnsubscribeDialog();
|
showUnsubscribeDialog();
|
||||||
return true;
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,7 +135,7 @@ public class ForumActivity extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showUnsubscribeDialog() {
|
private void showUnsubscribeDialog() {
|
||||||
OnClickListener okListener = (dialog, which) -> viewModel.deleteForum();
|
OnClickListener okListener = (dialog, which) -> deleteForum();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this,
|
AlertDialog.Builder builder = new AlertDialog.Builder(this,
|
||||||
R.style.BriarDialogTheme);
|
R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.dialog_title_leave_forum));
|
builder.setTitle(getString(R.string.dialog_title_leave_forum));
|
||||||
@@ -137,4 +145,27 @@ public class ForumActivity extends
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteForum() {
|
||||||
|
forumController.deleteNamedGroup(
|
||||||
|
new UiResultExceptionHandler<Void, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(Void v) {
|
||||||
|
Toast.makeText(ForumActivity.this,
|
||||||
|
R.string.forum_left_toast, LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onForumLeft(ContactId c) {
|
||||||
|
sharingController.remove(c);
|
||||||
|
setToolbarSubTitle(sharingController.getTotalCount(),
|
||||||
|
sharingController.getOnlineCount());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.briarproject.briar.android.forum;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
interface ForumController extends ThreadListController<Forum, ForumPostItem> {
|
||||||
|
|
||||||
|
interface ForumListener extends ThreadListListener<ForumPostItem> {
|
||||||
|
@UiThread
|
||||||
|
void onForumLeft(ContactId c);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
package org.briarproject.briar.android.forum;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
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.MessageId;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.forum.ForumController.ForumListener;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListControllerImpl;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
|
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||||
|
import org.briarproject.briar.api.forum.ForumManager;
|
||||||
|
import org.briarproject.briar.api.forum.ForumPost;
|
||||||
|
import org.briarproject.briar.api.forum.ForumPostHeader;
|
||||||
|
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||||
|
import org.briarproject.briar.api.forum.event.ForumInvitationResponseReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.sharing.event.ContactLeftShareableEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.Math.max;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
class ForumControllerImpl extends
|
||||||
|
ThreadListControllerImpl<Forum, ForumPostItem, ForumPostHeader, ForumPost, ForumListener>
|
||||||
|
implements ForumController {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(ForumControllerImpl.class.getName());
|
||||||
|
|
||||||
|
private final ForumManager forumManager;
|
||||||
|
private final ForumSharingManager forumSharingManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ForumControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||||
|
@CryptoExecutor Executor cryptoExecutor,
|
||||||
|
ForumManager forumManager, ForumSharingManager forumSharingManager,
|
||||||
|
EventBus eventBus, Clock clock, MessageTracker messageTracker,
|
||||||
|
AndroidNotificationManager notificationManager) {
|
||||||
|
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
|
||||||
|
eventBus, clock, notificationManager, messageTracker);
|
||||||
|
this.forumManager = forumManager;
|
||||||
|
this.forumSharingManager = forumSharingManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStart() {
|
||||||
|
super.onActivityStart();
|
||||||
|
notificationManager.clearForumPostNotification(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
super.eventOccurred(e);
|
||||||
|
|
||||||
|
if (e instanceof ForumPostReceivedEvent) {
|
||||||
|
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||||
|
if (f.getGroupId().equals(getGroupId())) {
|
||||||
|
LOG.info("Forum post received, adding...");
|
||||||
|
listener.onItemReceived(buildItem(f.getHeader(), f.getText()));
|
||||||
|
}
|
||||||
|
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||||
|
ForumInvitationResponseReceivedEvent f =
|
||||||
|
(ForumInvitationResponseReceivedEvent) e;
|
||||||
|
ForumInvitationResponse r = f.getMessageHeader();
|
||||||
|
if (r.getShareableId().equals(getGroupId()) && r.wasAccepted()) {
|
||||||
|
LOG.info("Forum invitation was accepted");
|
||||||
|
listener.onInvitationAccepted(f.getContactId());
|
||||||
|
}
|
||||||
|
} else if (e instanceof ContactLeftShareableEvent) {
|
||||||
|
ContactLeftShareableEvent c = (ContactLeftShareableEvent) e;
|
||||||
|
if (c.getGroupId().equals(getGroupId())) {
|
||||||
|
LOG.info("Forum left by contact");
|
||||||
|
listener.onForumLeft(c.getContactId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Forum loadNamedGroup() throws DbException {
|
||||||
|
return forumManager.getForum(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<ForumPostHeader> loadHeaders() throws DbException {
|
||||||
|
return forumManager.getPostHeaders(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String loadMessageText(ForumPostHeader h) throws DbException {
|
||||||
|
return forumManager.getPostText(h.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void markRead(MessageId id) throws DbException {
|
||||||
|
forumManager.setReadFlag(getGroupId(), id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadSharingContacts(
|
||||||
|
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
Collection<Contact> contacts =
|
||||||
|
forumSharingManager.getSharedWith(getGroupId());
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createAndStoreMessage(String text,
|
||||||
|
@Nullable ForumPostItem parentItem,
|
||||||
|
ResultExceptionHandler<ForumPostItem, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
LocalAuthor author = identityManager.getLocalAuthor();
|
||||||
|
GroupCount count = forumManager.getGroupCount(getGroupId());
|
||||||
|
long timestamp = max(count.getLatestMsgTime() + 1,
|
||||||
|
clock.currentTimeMillis());
|
||||||
|
MessageId parentId = parentItem != null ?
|
||||||
|
parentItem.getId() : null;
|
||||||
|
createMessage(text, timestamp, parentId, author, handler);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMessage(String text, long timestamp,
|
||||||
|
@Nullable MessageId parentId, LocalAuthor author,
|
||||||
|
ResultExceptionHandler<ForumPostItem, DbException> handler) {
|
||||||
|
cryptoExecutor.execute(() -> {
|
||||||
|
LOG.info("Creating forum post...");
|
||||||
|
ForumPost msg = forumManager.createLocalPost(getGroupId(), text,
|
||||||
|
timestamp, parentId, author);
|
||||||
|
storePost(msg, text, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ForumPostHeader addLocalMessage(ForumPost p) throws DbException {
|
||||||
|
return forumManager.addLocalPost(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deleteNamedGroup(Forum forum) throws DbException {
|
||||||
|
forumManager.removeForum(forum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ForumPostItem buildItem(ForumPostHeader header, String text) {
|
||||||
|
return new ForumPostItem(header, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,23 +1,32 @@
|
|||||||
package org.briarproject.briar.android.forum;
|
package org.briarproject.briar.android.forum;
|
||||||
|
|
||||||
|
import org.briarproject.briar.android.activity.ActivityScope;
|
||||||
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
import dagger.Binds;
|
import dagger.Binds;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
import dagger.multibindings.IntoMap;
|
import dagger.multibindings.IntoMap;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public interface ForumModule {
|
public class ForumModule {
|
||||||
|
|
||||||
@Binds
|
@Module
|
||||||
@IntoMap
|
public interface BindsModule {
|
||||||
@ViewModelKey(ForumListViewModel.class)
|
@Binds
|
||||||
ViewModel bindForumListViewModel(ForumListViewModel forumListViewModel);
|
@IntoMap
|
||||||
|
@ViewModelKey(ForumListViewModel.class)
|
||||||
|
ViewModel bindForumListViewModel(ForumListViewModel forumListViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
@Binds
|
@ActivityScope
|
||||||
@IntoMap
|
@Provides
|
||||||
@ViewModelKey(ForumViewModel.class)
|
ForumController provideForumController(BaseActivity activity,
|
||||||
ViewModel bindForumViewModel(ForumViewModel forumViewModel);
|
ForumControllerImpl forumController) {
|
||||||
|
activity.addLifecycleController(forumController);
|
||||||
|
return forumController;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
import org.briarproject.briar.android.threaded.ThreadItem;
|
import org.briarproject.briar.android.threaded.ThreadItem;
|
||||||
import org.briarproject.briar.api.forum.ForumPostHeader;
|
import org.briarproject.briar.api.forum.ForumPostHeader;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@@ -16,4 +17,9 @@ class ForumPostItem extends ThreadItem {
|
|||||||
h.getAuthorInfo(), h.isRead());
|
h.getAuthorInfo(), h.isRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ForumPostItem(MessageId messageId, @Nullable MessageId parentId,
|
||||||
|
String text, long timestamp, Author author, AuthorInfo authorInfo) {
|
||||||
|
super(messageId, parentId, text, timestamp, author, authorInfo, true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,231 +0,0 @@
|
|||||||
package org.briarproject.briar.android.forum;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|
||||||
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.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.MessageId;
|
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.sharing.SharingController;
|
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
|
||||||
import org.briarproject.briar.api.forum.Forum;
|
|
||||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
|
||||||
import org.briarproject.briar.api.forum.ForumManager;
|
|
||||||
import org.briarproject.briar.api.forum.ForumPost;
|
|
||||||
import org.briarproject.briar.api.forum.ForumPostHeader;
|
|
||||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
|
||||||
import org.briarproject.briar.api.forum.event.ForumInvitationResponseReceivedEvent;
|
|
||||||
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
|
||||||
import org.briarproject.briar.api.sharing.event.ContactLeftShareableEvent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
|
||||||
import static java.lang.Math.max;
|
|
||||||
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 ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|
||||||
|
|
||||||
private static final Logger LOG = getLogger(ForumViewModel.class.getName());
|
|
||||||
|
|
||||||
private final ForumManager forumManager;
|
|
||||||
private final ForumSharingManager forumSharingManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ForumViewModel(Application application,
|
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
|
||||||
LifecycleManager lifecycleManager,
|
|
||||||
TransactionManager db,
|
|
||||||
AndroidExecutor androidExecutor,
|
|
||||||
IdentityManager identityManager,
|
|
||||||
AndroidNotificationManager notificationManager,
|
|
||||||
SharingController sharingController,
|
|
||||||
@CryptoExecutor Executor cryptoExecutor,
|
|
||||||
Clock clock,
|
|
||||||
MessageTracker messageTracker,
|
|
||||||
EventBus eventBus,
|
|
||||||
ForumManager forumManager,
|
|
||||||
ForumSharingManager forumSharingManager) {
|
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
|
||||||
identityManager, notificationManager, sharingController,
|
|
||||||
cryptoExecutor, clock, messageTracker, eventBus);
|
|
||||||
this.forumManager = forumManager;
|
|
||||||
this.forumSharingManager = forumSharingManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof ForumPostReceivedEvent) {
|
|
||||||
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
|
||||||
if (f.getGroupId().equals(groupId)) {
|
|
||||||
LOG.info("Forum post received, adding...");
|
|
||||||
ForumPostItem item =
|
|
||||||
new ForumPostItem(f.getHeader(), f.getText());
|
|
||||||
addItem(item, false);
|
|
||||||
}
|
|
||||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
|
||||||
ForumInvitationResponseReceivedEvent f =
|
|
||||||
(ForumInvitationResponseReceivedEvent) e;
|
|
||||||
ForumInvitationResponse r = f.getMessageHeader();
|
|
||||||
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
|
||||||
LOG.info("Forum invitation was accepted");
|
|
||||||
sharingController.add(f.getContactId());
|
|
||||||
}
|
|
||||||
} else if (e instanceof ContactLeftShareableEvent) {
|
|
||||||
ContactLeftShareableEvent c = (ContactLeftShareableEvent) e;
|
|
||||||
if (c.getGroupId().equals(groupId)) {
|
|
||||||
LOG.info("Forum left by contact");
|
|
||||||
sharingController.remove(c.getContactId());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
super.eventOccurred(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void clearNotifications() {
|
|
||||||
notificationManager.clearForumPostNotification(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Forum> loadForum() {
|
|
||||||
MutableLiveData<Forum> forum = new MutableLiveData<>();
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
Forum f = forumManager.getForum(groupId);
|
|
||||||
forum.postValue(f);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return forum;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadItems() {
|
|
||||||
loadList(txn -> {
|
|
||||||
long start = now();
|
|
||||||
List<ForumPostHeader> headers =
|
|
||||||
forumManager.getPostHeaders(txn, groupId);
|
|
||||||
logDuration(LOG, "Loading headers", start);
|
|
||||||
start = now();
|
|
||||||
List<ForumPostItem> items = new ArrayList<>();
|
|
||||||
for (ForumPostHeader header : headers) {
|
|
||||||
items.add(loadItem(txn, header));
|
|
||||||
}
|
|
||||||
logDuration(LOG, "Loading bodies and creating items", start);
|
|
||||||
return items;
|
|
||||||
}, this::setItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ForumPostItem loadItem(Transaction txn, ForumPostHeader header)
|
|
||||||
throws DbException {
|
|
||||||
String text = forumManager.getPostText(txn, header.getId());
|
|
||||||
return new ForumPostItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createAndStoreMessage(String text,
|
|
||||||
@Nullable MessageId parentId) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
LocalAuthor author = identityManager.getLocalAuthor();
|
|
||||||
GroupCount count = forumManager.getGroupCount(groupId);
|
|
||||||
long timestamp = max(count.getLatestMsgTime() + 1,
|
|
||||||
clock.currentTimeMillis());
|
|
||||||
createMessage(text, timestamp, parentId, author);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createMessage(String text, long timestamp,
|
|
||||||
@Nullable MessageId parentId, LocalAuthor author) {
|
|
||||||
cryptoExecutor.execute(() -> {
|
|
||||||
LOG.info("Creating forum post...");
|
|
||||||
ForumPost msg = forumManager.createLocalPost(groupId, text,
|
|
||||||
timestamp, parentId, author);
|
|
||||||
storePost(msg, text);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storePost(ForumPost msg, String text) {
|
|
||||||
runOnDbThread(false, txn -> {
|
|
||||||
long start = now();
|
|
||||||
ForumPostHeader header = forumManager.addLocalPost(txn, msg);
|
|
||||||
logDuration(LOG, "Storing forum post", start);
|
|
||||||
txn.attach(() -> {
|
|
||||||
ForumPostItem item = new ForumPostItem(header, text);
|
|
||||||
addItem(item, true);
|
|
||||||
});
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void markItemRead(ForumPostItem item) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
forumManager.setReadFlag(groupId, item.getId(), true);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadSharingContacts() {
|
|
||||||
runOnDbThread(true, txn -> {
|
|
||||||
Collection<Contact> contacts =
|
|
||||||
forumSharingManager.getSharedWith(txn, groupId);
|
|
||||||
Collection<ContactId> contactIds = new ArrayList<>(contacts.size());
|
|
||||||
for (Contact c : contacts) contactIds.add(c.getId());
|
|
||||||
txn.attach(() -> sharingController.addAll(contactIds));
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteForum() {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
Forum f = forumManager.getForum(groupId);
|
|
||||||
forumManager.removeForum(f);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Toast.makeText(getApplication(), R.string.forum_left_toast,
|
|
||||||
LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,42 +5,63 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.contact.ContactListAdapter;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.contact.ContactListItem;
|
import org.briarproject.briar.android.contact.ContactListItem;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
import org.briarproject.briar.android.contact.LegacyContactListAdapter;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||||
|
|
||||||
|
@UiThread
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class ContactChooserFragment extends BaseFragment
|
public class ContactChooserFragment extends BaseFragment {
|
||||||
implements OnContactClickListener<ContactListItem> {
|
|
||||||
|
|
||||||
private static final String TAG = ContactChooserFragment.class.getName();
|
public static final String TAG = ContactChooserFragment.class.getName();
|
||||||
|
private static final Logger LOG = Logger.getLogger(TAG);
|
||||||
|
|
||||||
@Inject
|
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
|
||||||
|
|
||||||
private ContactListViewModel viewModel;
|
|
||||||
private final ContactListAdapter adapter = new ContactListAdapter(this);
|
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
|
private LegacyContactListAdapter adapter;
|
||||||
private ContactId contactId;
|
private ContactId contactId;
|
||||||
|
|
||||||
static ContactChooserFragment newInstance(ContactId id) {
|
// Fields that are accessed from background threads must be volatile
|
||||||
|
private volatile Contact c1;
|
||||||
|
@Inject
|
||||||
|
volatile ContactManager contactManager;
|
||||||
|
@Inject
|
||||||
|
volatile AuthorManager authorManager;
|
||||||
|
@Inject
|
||||||
|
volatile ConversationManager conversationManager;
|
||||||
|
@Inject
|
||||||
|
volatile ConnectionRegistry connectionRegistry;
|
||||||
|
|
||||||
|
public static ContactChooserFragment newInstance(ContactId id) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
||||||
ContactChooserFragment fragment = new ContactChooserFragment();
|
ContactChooserFragment fragment = new ContactChooserFragment();
|
||||||
@@ -52,8 +73,6 @@ public class ContactChooserFragment extends BaseFragment
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
|
||||||
.get(ContactListViewModel.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,20 +82,21 @@ public class ContactChooserFragment extends BaseFragment
|
|||||||
|
|
||||||
View contentView = inflater.inflate(R.layout.list, container, false);
|
View contentView = inflater.inflate(R.layout.list, container, false);
|
||||||
|
|
||||||
|
OnContactClickListener<ContactListItem> onContactClickListener =
|
||||||
|
(view, item) -> {
|
||||||
|
if (c1 == null) throw new IllegalStateException();
|
||||||
|
Contact c2 = item.getContact();
|
||||||
|
showMessageScreen(c1, c2);
|
||||||
|
};
|
||||||
|
adapter = new LegacyContactListAdapter(requireActivity(),
|
||||||
|
onContactClickListener);
|
||||||
|
|
||||||
list = contentView.findViewById(R.id.list);
|
list = contentView.findViewById(R.id.list);
|
||||||
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.setEmptyText(R.string.no_contacts);
|
list.setEmptyText(R.string.no_contacts);
|
||||||
|
|
||||||
contactId = new ContactId(requireArguments().getInt(CONTACT_ID));
|
contactId = new ContactId(requireArguments().getInt(CONTACT_ID));
|
||||||
viewModel.setContactId(contactId);
|
|
||||||
|
|
||||||
viewModel.loadContacts();
|
|
||||||
|
|
||||||
viewModel.getContactListItems().observe(getViewLifecycleOwner(),
|
|
||||||
result -> result.onError(this::handleException)
|
|
||||||
.onSuccess(adapter::submitList)
|
|
||||||
);
|
|
||||||
|
|
||||||
return contentView;
|
return contentView;
|
||||||
}
|
}
|
||||||
@@ -84,13 +104,14 @@ public class ContactChooserFragment extends BaseFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
list.startPeriodicUpdate();
|
loadContacts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
list.stopPeriodicUpdate();
|
adapter.clear();
|
||||||
|
list.showProgressBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -98,15 +119,43 @@ public class ContactChooserFragment extends BaseFragment
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMessageScreen(Contact other) {
|
private void loadContacts() {
|
||||||
|
listener.runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
List<ContactListItem> contacts = new ArrayList<>();
|
||||||
|
for (Contact c : contactManager.getContacts()) {
|
||||||
|
if (c.getId().equals(contactId)) {
|
||||||
|
c1 = c;
|
||||||
|
} else {
|
||||||
|
AuthorInfo authorInfo = authorManager.getAuthorInfo(c);
|
||||||
|
ContactId id = c.getId();
|
||||||
|
GroupCount count =
|
||||||
|
conversationManager.getGroupCount(id);
|
||||||
|
boolean connected =
|
||||||
|
connectionRegistry.isConnected(c.getId());
|
||||||
|
contacts.add(new ContactListItem(c, authorInfo,
|
||||||
|
connected, count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
displayContacts(contacts);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayContacts(List<ContactListItem> contacts) {
|
||||||
|
runOnUiThreadUnlessDestroyed(() -> {
|
||||||
|
if (contacts.isEmpty()) list.showData();
|
||||||
|
else adapter.addAll(contacts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showMessageScreen(Contact c1, Contact c2) {
|
||||||
IntroductionMessageFragment messageFragment =
|
IntroductionMessageFragment messageFragment =
|
||||||
IntroductionMessageFragment.newInstance(contactId.getInt(),
|
IntroductionMessageFragment
|
||||||
other.getId().getInt());
|
.newInstance(c1.getId().getInt(), c2.getId().getInt());
|
||||||
showNextFragment(messageFragment);
|
showNextFragment(messageFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemClick(View view, ContactListItem item) {
|
|
||||||
showMessageScreen(item.getContact());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
package org.briarproject.briar.android.introduction;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
|
||||||
import org.briarproject.briar.android.contact.ContactsViewModel;
|
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
class ContactListViewModel extends ContactsViewModel {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private ContactId contactId;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ContactListViewModel(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,
|
|
||||||
contactManager, authorManager, conversationManager,
|
|
||||||
connectionRegistry, eventBus);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setContactId(ContactId contactId) {
|
|
||||||
this.contactId = contactId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean displayContact(ContactId contactId) {
|
|
||||||
return !requireNonNull(this.contactId).equals(contactId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package org.briarproject.briar.android.introduction;
|
|
||||||
|
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
import dagger.Binds;
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.multibindings.IntoMap;
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public abstract class IntroductionModule {
|
|
||||||
|
|
||||||
@Binds
|
|
||||||
@IntoMap
|
|
||||||
@ViewModelKey(ContactListViewModel.class)
|
|
||||||
abstract ViewModel bindContactListViewModel(
|
|
||||||
ContactListViewModel contactListViewModel);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
package org.briarproject.briar.android.login;
|
package org.briarproject.briar.android.login;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
import static androidx.core.content.ContextCompat.getColor;
|
||||||
|
import static androidx.core.content.ContextCompat.getDrawable;
|
||||||
|
import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class LoginUtils {
|
class LoginUtils {
|
||||||
@@ -15,7 +19,9 @@ class LoginUtils {
|
|||||||
static AlertDialog createKeyStrengthenerErrorDialog(Context ctx) {
|
static AlertDialog createKeyStrengthenerErrorDialog(Context ctx) {
|
||||||
AlertDialog.Builder builder =
|
AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme);
|
||||||
builder.setIcon(getDialogIcon(ctx, R.drawable.alerts_and_states_error));
|
Drawable icon = getDrawable(ctx, R.drawable.alerts_and_states_error);
|
||||||
|
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
||||||
|
builder.setIcon(icon);
|
||||||
builder.setTitle(R.string.dialog_title_cannot_check_password);
|
builder.setTitle(R.string.dialog_title_cannot_check_password);
|
||||||
builder.setMessage(R.string.dialog_message_cannot_check_password);
|
builder.setMessage(R.string.dialog_message_cannot_check_password);
|
||||||
builder.setPositiveButton(R.string.ok, null);
|
builder.setPositiveButton(R.string.ok, null);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.navdrawer;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -60,7 +59,6 @@ import androidx.fragment.app.FragmentTransaction;
|
|||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
|
||||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
@@ -435,7 +433,8 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
Transport t = getItem(position);
|
Transport t = getItem(position);
|
||||||
|
|
||||||
ImageView icon = view.findViewById(R.id.imageView);
|
ImageView icon = view.findViewById(R.id.imageView);
|
||||||
icon.setImageResource(t.iconDrawable);
|
icon.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
NavDrawerActivity.this, t.iconDrawable));
|
||||||
icon.setColorFilter(ContextCompat.getColor(
|
icon.setColorFilter(ContextCompat.getColor(
|
||||||
NavDrawerActivity.this, t.iconColor));
|
NavDrawerActivity.this, t.iconColor));
|
||||||
|
|
||||||
@@ -477,13 +476,11 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
private void showTransportsOnboarding(boolean show, ImageView imageView) {
|
private void showTransportsOnboarding(boolean show, ImageView imageView) {
|
||||||
if (show) {
|
if (show) {
|
||||||
int color = resolveColorAttribute(this, R.attr.colorControlNormal);
|
int color = resolveColorAttribute(this, R.attr.colorControlNormal);
|
||||||
Drawable drawable = VectorDrawableCompat
|
|
||||||
.create(getResources(), R.drawable.transport_tor, null);
|
|
||||||
new MaterialTapTargetPrompt.Builder(NavDrawerActivity.this,
|
new MaterialTapTargetPrompt.Builder(NavDrawerActivity.this,
|
||||||
R.style.OnboardingDialogTheme).setTarget(imageView)
|
R.style.OnboardingDialogTheme).setTarget(imageView)
|
||||||
.setPrimaryText(R.string.network_settings_title)
|
.setPrimaryText(R.string.network_settings_title)
|
||||||
.setSecondaryText(R.string.transports_onboarding_text)
|
.setSecondaryText(R.string.transports_onboarding_text)
|
||||||
.setIconDrawable(drawable)
|
.setIcon(R.drawable.transport_tor)
|
||||||
.setIconDrawableColourFilter(color)
|
.setIconDrawableColourFilter(color)
|
||||||
.setBackgroundColour(
|
.setBackgroundColour(
|
||||||
ContextCompat.getColor(this, R.color.briar_primary))
|
ContextCompat.getColor(this, R.color.briar_primary))
|
||||||
|
|||||||
@@ -141,7 +141,8 @@ public class TransportsActivity extends BriarActivity {
|
|||||||
Transport t = getItem(position);
|
Transport t = getItem(position);
|
||||||
|
|
||||||
ImageView icon = view.findViewById(R.id.icon);
|
ImageView icon = view.findViewById(R.id.icon);
|
||||||
icon.setImageResource(t.iconDrawable);
|
icon.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
TransportsActivity.this, t.iconDrawable));
|
||||||
icon.setColorFilter(ContextCompat.getColor(
|
icon.setColorFilter(ContextCompat.getColor(
|
||||||
TransportsActivity.this, t.iconColor));
|
TransportsActivity.this, t.iconColor));
|
||||||
|
|
||||||
|
|||||||
@@ -1,60 +1,67 @@
|
|||||||
package org.briarproject.briar.android.privategroup.conversation;
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.controller.handler.UiExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.privategroup.conversation.GroupController.GroupListener;
|
||||||
import org.briarproject.briar.android.privategroup.creation.GroupInviteActivity;
|
import org.briarproject.briar.android.privategroup.creation.GroupInviteActivity;
|
||||||
import org.briarproject.briar.android.privategroup.memberlist.GroupMemberListActivity;
|
import org.briarproject.briar.android.privategroup.memberlist.GroupMemberListActivity;
|
||||||
import org.briarproject.briar.android.privategroup.reveal.RevealContactsActivity;
|
import org.briarproject.briar.android.privategroup.reveal.RevealContactsActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_GROUP_INVITE;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_GROUP_INVITE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.observeOnce;
|
|
||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class GroupActivity extends
|
public class GroupActivity extends
|
||||||
ThreadListActivity<GroupMessageItem, GroupMessageAdapter> {
|
ThreadListActivity<PrivateGroup, GroupMessageItem, GroupMessageAdapter>
|
||||||
|
implements GroupListener, OnClickListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
GroupController controller;
|
||||||
|
|
||||||
private GroupViewModel viewModel;
|
@Nullable
|
||||||
|
private Boolean isCreator = null;
|
||||||
|
private boolean isDissolved = false;
|
||||||
|
private MenuItem revealMenuItem, inviteMenuItem, leaveMenuItem,
|
||||||
|
dissolveMenuItem;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectActivity(ActivityComponent component) {
|
public void injectActivity(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
|
||||||
.get(GroupViewModel.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThreadListViewModel<GroupMessageItem> getViewModel() {
|
protected ThreadListController<PrivateGroup, GroupMessageItem> getController() {
|
||||||
return viewModel;
|
return controller;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected GroupMessageAdapter createAdapter() {
|
|
||||||
return new GroupMessageAdapter(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,27 +69,65 @@ public class GroupActivity extends
|
|||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
|
||||||
Toolbar toolbar = setUpCustomToolbar(false);
|
Toolbar toolbar = setUpCustomToolbar(false);
|
||||||
// Open member list on Toolbar click
|
|
||||||
toolbar.setOnClickListener(v -> {
|
|
||||||
Intent i = new Intent(GroupActivity.this,
|
|
||||||
GroupMemberListActivity.class);
|
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
|
||||||
startActivity(i);
|
|
||||||
});
|
|
||||||
|
|
||||||
String groupName = getIntent().getStringExtra(GROUP_NAME);
|
Intent i = getIntent();
|
||||||
|
String groupName = i.getStringExtra(GROUP_NAME);
|
||||||
if (groupName != null) setTitle(groupName);
|
if (groupName != null) setTitle(groupName);
|
||||||
observeOnce(viewModel.getPrivateGroup(), this, privateGroup ->
|
loadNamedGroup();
|
||||||
setTitle(privateGroup.getName())
|
|
||||||
);
|
// Open member list on Toolbar click
|
||||||
observeOnce(viewModel.isCreator(), this, adapter::setIsCreator);
|
if (toolbar != null) {
|
||||||
|
toolbar.setOnClickListener(v -> {
|
||||||
|
Intent i1 = new Intent(GroupActivity.this,
|
||||||
|
GroupMemberListActivity.class);
|
||||||
|
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
|
startActivity(i1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// start with group disabled and enable when not dissolved
|
|
||||||
setGroupEnabled(false);
|
setGroupEnabled(false);
|
||||||
viewModel.isDissolved().observeEvent(this, dissolved -> {
|
}
|
||||||
setGroupEnabled(!dissolved);
|
|
||||||
if (dissolved) onGroupDissolved();
|
@Override
|
||||||
});
|
protected GroupMessageAdapter createAdapter(
|
||||||
|
LinearLayoutManager layoutManager) {
|
||||||
|
return new GroupMessageAdapter(this, layoutManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadItems() {
|
||||||
|
controller.isDissolved(
|
||||||
|
new UiResultExceptionHandler<Boolean, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(Boolean isDissolved) {
|
||||||
|
setGroupEnabled(!isDissolved);
|
||||||
|
GroupActivity.super.loadItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNamedGroupLoaded(PrivateGroup group) {
|
||||||
|
setTitle(group.getName());
|
||||||
|
controller.loadLocalAuthor(
|
||||||
|
new UiResultExceptionHandler<LocalAuthor, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(LocalAuthor author) {
|
||||||
|
isCreator = group.getCreator().equals(author);
|
||||||
|
adapter.setPerspective(isCreator);
|
||||||
|
showMenuItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,61 +136,74 @@ public class GroupActivity extends
|
|||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.group_actions, menu);
|
inflater.inflate(R.menu.group_actions, menu);
|
||||||
|
|
||||||
// show items based on role (which will not change, so observe once)
|
revealMenuItem = menu.findItem(R.id.action_group_reveal);
|
||||||
observeOnce(viewModel.isCreator(), this, isCreator -> {
|
inviteMenuItem = menu.findItem(R.id.action_group_invite);
|
||||||
menu.findItem(R.id.action_group_reveal).setVisible(!isCreator);
|
leaveMenuItem = menu.findItem(R.id.action_group_leave);
|
||||||
menu.findItem(R.id.action_group_invite).setVisible(isCreator);
|
dissolveMenuItem = menu.findItem(R.id.action_group_dissolve);
|
||||||
menu.findItem(R.id.action_group_leave).setVisible(!isCreator);
|
|
||||||
menu.findItem(R.id.action_group_dissolve).setVisible(isCreator);
|
// all role-dependent items are invisible until we know our role
|
||||||
});
|
revealMenuItem.setVisible(false);
|
||||||
super.onCreateOptionsMenu(menu);
|
inviteMenuItem.setVisible(false);
|
||||||
return true;
|
leaveMenuItem.setVisible(false);
|
||||||
|
dissolveMenuItem.setVisible(false);
|
||||||
|
|
||||||
|
// show items based on role
|
||||||
|
showMenuItems();
|
||||||
|
|
||||||
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == R.id.action_group_member_list) {
|
case R.id.action_group_member_list:
|
||||||
Intent i = new Intent(this, GroupMemberListActivity.class);
|
Intent i1 = new Intent(this, GroupMemberListActivity.class);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivity(i);
|
startActivity(i1);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_reveal) {
|
case R.id.action_group_reveal:
|
||||||
if (requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
Intent i = new Intent(this, RevealContactsActivity.class);
|
Intent i2 = new Intent(this, RevealContactsActivity.class);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i2.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivity(i);
|
startActivity(i2);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_invite) {
|
case R.id.action_group_invite:
|
||||||
if (!requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || !isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
Intent i = new Intent(this, GroupInviteActivity.class);
|
Intent i3 = new Intent(this, GroupInviteActivity.class);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i3.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivityForResult(i, REQUEST_GROUP_INVITE);
|
startActivityForResult(i3, REQUEST_GROUP_INVITE);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_leave) {
|
case R.id.action_group_leave:
|
||||||
if (requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
showLeaveGroupDialog();
|
showLeaveGroupDialog();
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_dissolve) {
|
case R.id.action_group_dissolve:
|
||||||
if (!requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || !isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
showDissolveGroupDialog();
|
showDissolveGroupDialog();
|
||||||
return true;
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int request, int result,
|
protected void onActivityResult(int request, int result, Intent data) {
|
||||||
@Nullable Intent data) {
|
|
||||||
if (request == REQUEST_GROUP_INVITE && result == RESULT_OK) {
|
if (request == REQUEST_GROUP_INVITE && result == RESULT_OK) {
|
||||||
displaySnackbar(R.string.groups_invitation_sent);
|
displaySnackbar(R.string.groups_invitation_sent);
|
||||||
} else super.onActivityResult(request, result, data);
|
} else super.onActivityResult(request, result, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemReceived(GroupMessageItem item) {
|
||||||
|
super.onItemReceived(item);
|
||||||
|
if (item instanceof JoinMessageItem) {
|
||||||
|
if (((JoinMessageItem) item).isInitial()) loadSharingContacts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getMaxTextLength() {
|
protected int getMaxTextLength() {
|
||||||
return MAX_GROUP_POST_TEXT_LENGTH;
|
return MAX_GROUP_POST_TEXT_LENGTH;
|
||||||
@@ -153,11 +211,11 @@ public class GroupActivity extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReplyClick(GroupMessageItem item) {
|
public void onReplyClick(GroupMessageItem item) {
|
||||||
Boolean isDissolved = viewModel.isDissolved().getLastValue();
|
if (!isDissolved) super.onReplyClick(item);
|
||||||
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setGroupEnabled(boolean enabled) {
|
private void setGroupEnabled(boolean enabled) {
|
||||||
|
isDissolved = !enabled;
|
||||||
sendController.setReady(enabled);
|
sendController.setReady(enabled);
|
||||||
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
|
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
|
||||||
|
|
||||||
@@ -169,13 +227,21 @@ public class GroupActivity extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showMenuItems() {
|
||||||
|
// we need to have the menu items and know if we are the creator
|
||||||
|
if (leaveMenuItem == null || isCreator == null) return;
|
||||||
|
revealMenuItem.setVisible(!isCreator);
|
||||||
|
inviteMenuItem.setVisible(isCreator);
|
||||||
|
leaveMenuItem.setVisible(!isCreator);
|
||||||
|
dissolveMenuItem.setVisible(isCreator);
|
||||||
|
}
|
||||||
|
|
||||||
private void showLeaveGroupDialog() {
|
private void showLeaveGroupDialog() {
|
||||||
AlertDialog.Builder builder =
|
AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.groups_leave_dialog_title));
|
builder.setTitle(getString(R.string.groups_leave_dialog_title));
|
||||||
builder.setMessage(getString(R.string.groups_leave_dialog_message));
|
builder.setMessage(getString(R.string.groups_leave_dialog_message));
|
||||||
builder.setNegativeButton(R.string.dialog_button_leave,
|
builder.setNegativeButton(R.string.dialog_button_leave, this);
|
||||||
(d, w) -> deleteGroup());
|
|
||||||
builder.setPositiveButton(R.string.cancel, null);
|
builder.setPositiveButton(R.string.cancel, null);
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
@@ -185,19 +251,37 @@ public class GroupActivity extends
|
|||||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.groups_dissolve_dialog_title));
|
builder.setTitle(getString(R.string.groups_dissolve_dialog_title));
|
||||||
builder.setMessage(getString(R.string.groups_dissolve_dialog_message));
|
builder.setMessage(getString(R.string.groups_dissolve_dialog_message));
|
||||||
builder.setNegativeButton(R.string.groups_dissolve_button,
|
builder.setNegativeButton(R.string.groups_dissolve_button, this);
|
||||||
(d, w) -> deleteGroup());
|
|
||||||
builder.setPositiveButton(R.string.cancel, null);
|
builder.setPositiveButton(R.string.cancel, null);
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteGroup() {
|
@Override
|
||||||
// The activity is going to be destroyed by the
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
// GroupRemovedEvent being fired
|
controller.deleteNamedGroup(
|
||||||
viewModel.deletePrivateGroup();
|
new UiExceptionHandler<DbException>(this) {
|
||||||
|
// The activity is going to be destroyed by the
|
||||||
|
// GroupRemovedEvent being fired
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGroupDissolved() {
|
@Override
|
||||||
|
public void onContactRelationshipRevealed(AuthorId memberId, ContactId c,
|
||||||
|
Visibility v) {
|
||||||
|
adapter.updateVisibility(memberId, v);
|
||||||
|
|
||||||
|
sharingController.add(c);
|
||||||
|
setToolbarSubTitle(sharingController.getTotalCount(),
|
||||||
|
sharingController.getOnlineCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGroupDissolved() {
|
||||||
|
setGroupEnabled(false);
|
||||||
AlertDialog.Builder builder =
|
AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.groups_dissolved_dialog_title));
|
builder.setTitle(getString(R.string.groups_dissolved_dialog_title));
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
public interface GroupController
|
||||||
|
extends ThreadListController<PrivateGroup, GroupMessageItem> {
|
||||||
|
|
||||||
|
void loadLocalAuthor(
|
||||||
|
ResultExceptionHandler<LocalAuthor, DbException> handler);
|
||||||
|
|
||||||
|
void isDissolved(
|
||||||
|
ResultExceptionHandler<Boolean, DbException> handler);
|
||||||
|
|
||||||
|
interface GroupListener extends ThreadListListener<GroupMessageItem> {
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void onContactRelationshipRevealed(AuthorId memberId,
|
||||||
|
ContactId contactId, Visibility v);
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void onGroupDissolved();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
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.MessageId;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.privategroup.conversation.GroupController.GroupListener;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListControllerImpl;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMember;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
|
||||||
|
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.ContactRelationshipRevealedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.GroupDissolvedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.Math.max;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
class GroupControllerImpl extends
|
||||||
|
ThreadListControllerImpl<PrivateGroup, GroupMessageItem, GroupMessageHeader, GroupMessage, GroupListener>
|
||||||
|
implements GroupController {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(GroupControllerImpl.class.getName());
|
||||||
|
|
||||||
|
private final PrivateGroupManager privateGroupManager;
|
||||||
|
private final GroupMessageFactory groupMessageFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
GroupControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||||
|
@CryptoExecutor Executor cryptoExecutor,
|
||||||
|
PrivateGroupManager privateGroupManager,
|
||||||
|
GroupMessageFactory groupMessageFactory, EventBus eventBus,
|
||||||
|
MessageTracker messageTracker, Clock clock,
|
||||||
|
AndroidNotificationManager notificationManager) {
|
||||||
|
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
|
||||||
|
eventBus, clock, notificationManager, messageTracker);
|
||||||
|
this.privateGroupManager = privateGroupManager;
|
||||||
|
this.groupMessageFactory = groupMessageFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStart() {
|
||||||
|
super.onActivityStart();
|
||||||
|
notificationManager.clearGroupMessageNotification(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
super.eventOccurred(e);
|
||||||
|
|
||||||
|
if (e instanceof GroupMessageAddedEvent) {
|
||||||
|
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||||
|
if (!g.isLocal() && g.getGroupId().equals(getGroupId())) {
|
||||||
|
LOG.info("Group message received, adding...");
|
||||||
|
listener.onItemReceived(buildItem(g.getHeader(), g.getText()));
|
||||||
|
}
|
||||||
|
} else if (e instanceof ContactRelationshipRevealedEvent) {
|
||||||
|
ContactRelationshipRevealedEvent c =
|
||||||
|
(ContactRelationshipRevealedEvent) e;
|
||||||
|
if (getGroupId().equals(c.getGroupId())) {
|
||||||
|
listener.onContactRelationshipRevealed(c.getMemberId(),
|
||||||
|
c.getContactId(), c.getVisibility());
|
||||||
|
}
|
||||||
|
} else if (e instanceof GroupInvitationResponseReceivedEvent) {
|
||||||
|
GroupInvitationResponseReceivedEvent g =
|
||||||
|
(GroupInvitationResponseReceivedEvent) e;
|
||||||
|
GroupInvitationResponse r = g.getMessageHeader();
|
||||||
|
if (getGroupId().equals(r.getShareableId()) && r.wasAccepted()) {
|
||||||
|
listener.onInvitationAccepted(g.getContactId());
|
||||||
|
}
|
||||||
|
} else if (e instanceof GroupDissolvedEvent) {
|
||||||
|
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
||||||
|
if (getGroupId().equals(g.getGroupId())) {
|
||||||
|
listener.onGroupDissolved();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PrivateGroup loadNamedGroup() throws DbException {
|
||||||
|
return privateGroupManager.getPrivateGroup(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<GroupMessageHeader> loadHeaders() throws DbException {
|
||||||
|
return privateGroupManager.getHeaders(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String loadMessageText(GroupMessageHeader header)
|
||||||
|
throws DbException {
|
||||||
|
if (header instanceof JoinMessageHeader) {
|
||||||
|
// will be looked up later
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return privateGroupManager.getMessageText(header.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void markRead(MessageId id) throws DbException {
|
||||||
|
privateGroupManager.setReadFlag(getGroupId(), id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadSharingContacts(
|
||||||
|
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
Collection<GroupMember> members =
|
||||||
|
privateGroupManager.getMembers(getGroupId());
|
||||||
|
Collection<ContactId> contactIds = new ArrayList<>();
|
||||||
|
for (GroupMember m : members) {
|
||||||
|
if (m.getContactId() != null)
|
||||||
|
contactIds.add(m.getContactId());
|
||||||
|
}
|
||||||
|
handler.onResult(contactIds);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createAndStoreMessage(String text,
|
||||||
|
@Nullable GroupMessageItem parentItem,
|
||||||
|
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
LocalAuthor author = identityManager.getLocalAuthor();
|
||||||
|
MessageId parentId = null;
|
||||||
|
MessageId previousMsgId =
|
||||||
|
privateGroupManager.getPreviousMsgId(getGroupId());
|
||||||
|
GroupCount count =
|
||||||
|
privateGroupManager.getGroupCount(getGroupId());
|
||||||
|
long timestamp = count.getLatestMsgTime();
|
||||||
|
if (parentItem != null) parentId = parentItem.getId();
|
||||||
|
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
|
||||||
|
createMessage(text, timestamp, parentId, author, previousMsgId,
|
||||||
|
handler);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMessage(String text, long timestamp,
|
||||||
|
@Nullable MessageId parentId, LocalAuthor author,
|
||||||
|
MessageId previousMsgId,
|
||||||
|
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||||
|
cryptoExecutor.execute(() -> {
|
||||||
|
LOG.info("Creating group message...");
|
||||||
|
GroupMessage msg = groupMessageFactory
|
||||||
|
.createGroupMessage(getGroupId(), timestamp,
|
||||||
|
parentId, author, text, previousMsgId);
|
||||||
|
storePost(msg, text, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GroupMessageHeader addLocalMessage(GroupMessage message)
|
||||||
|
throws DbException {
|
||||||
|
return privateGroupManager.addLocalMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deleteNamedGroup(PrivateGroup group) throws DbException {
|
||||||
|
privateGroupManager.removePrivateGroup(group.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GroupMessageItem buildItem(GroupMessageHeader header,
|
||||||
|
String text) {
|
||||||
|
if (header instanceof JoinMessageHeader) {
|
||||||
|
return new JoinMessageItem((JoinMessageHeader) header, text);
|
||||||
|
}
|
||||||
|
return new GroupMessageItem(header, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadLocalAuthor(
|
||||||
|
ResultExceptionHandler<LocalAuthor, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
LocalAuthor author = identityManager.getLocalAuthor();
|
||||||
|
handler.onResult(author);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void isDissolved(
|
||||||
|
ResultExceptionHandler<Boolean, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
boolean isDissolved =
|
||||||
|
privateGroupManager.isDissolved(getGroupId());
|
||||||
|
handler.onResult(isDissolved);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
package org.briarproject.briar.android.privategroup.conversation;
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
import org.briarproject.briar.android.activity.ActivityScope;
|
||||||
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
import dagger.Binds;
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.multibindings.IntoMap;
|
import dagger.Provides;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public interface GroupConversationModule {
|
public class GroupConversationModule {
|
||||||
|
|
||||||
@Binds
|
|
||||||
@IntoMap
|
|
||||||
@ViewModelKey(GroupViewModel.class)
|
|
||||||
ViewModel bindGroupViewModel(GroupViewModel groupViewModel);
|
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
|
@Provides
|
||||||
|
GroupController provideGroupController(BaseActivity activity,
|
||||||
|
GroupControllerImpl groupController) {
|
||||||
|
activity.addLifecycleController(groupController);
|
||||||
|
return groupController;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,19 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.threaded.BaseThreadItemViewHolder;
|
import org.briarproject.briar.android.threaded.BaseThreadItemViewHolder;
|
||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
||||||
import org.briarproject.briar.android.threaded.ThreadPostViewHolder;
|
import org.briarproject.briar.android.threaded.ThreadPostViewHolder;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -19,14 +24,15 @@ class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
|||||||
|
|
||||||
private boolean isCreator = false;
|
private boolean isCreator = false;
|
||||||
|
|
||||||
GroupMessageAdapter(ThreadItemListener<GroupMessageItem> listener) {
|
GroupMessageAdapter(ThreadItemListener<GroupMessageItem> listener,
|
||||||
super(listener);
|
LinearLayoutManager layoutManager) {
|
||||||
|
super(listener, layoutManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
GroupMessageItem item = getItem(position);
|
GroupMessageItem item = items.get(position);
|
||||||
return item.getLayout();
|
return item.getLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +47,30 @@ class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
|||||||
return new ThreadPostViewHolder<>(v);
|
return new ThreadPostViewHolder<>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIsCreator(boolean isCreator) {
|
void setPerspective(boolean isCreator) {
|
||||||
this.isCreator = isCreator;
|
this.isCreator = isCreator;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateVisibility(AuthorId memberId, Visibility v) {
|
||||||
|
int position = findItemPosition(memberId);
|
||||||
|
if (position != NO_POSITION) {
|
||||||
|
GroupMessageItem item = items.get(position);
|
||||||
|
if (item instanceof JoinMessageItem) {
|
||||||
|
((JoinMessageItem) item).setVisibility(v);
|
||||||
|
notifyItemChanged(findItemPosition(item), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findItemPosition(AuthorId a) {
|
||||||
|
int count = items.size();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
GroupMessageItem item = items.get(i);
|
||||||
|
if (item.getAuthor().getId().equals(a))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return NO_POSITION; // Not found
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,289 +0,0 @@
|
|||||||
package org.briarproject.briar.android.privategroup.conversation;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|
||||||
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.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.system.AndroidExecutor;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.briar.android.sharing.SharingController;
|
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMember;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
|
|
||||||
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
|
||||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
|
||||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.ContactRelationshipRevealedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.GroupDissolvedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import static java.lang.Math.max;
|
|
||||||
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 GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
|
||||||
|
|
||||||
private static final Logger LOG = getLogger(GroupViewModel.class.getName());
|
|
||||||
|
|
||||||
private final PrivateGroupManager privateGroupManager;
|
|
||||||
private final GroupMessageFactory groupMessageFactory;
|
|
||||||
|
|
||||||
private final MutableLiveData<PrivateGroup> privateGroup =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
private final MutableLiveData<Boolean> isCreator = new MutableLiveData<>();
|
|
||||||
private final MutableLiveEvent<Boolean> isDissolved =
|
|
||||||
new MutableLiveEvent<>();
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
GroupViewModel(Application application,
|
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
|
||||||
LifecycleManager lifecycleManager,
|
|
||||||
TransactionManager db,
|
|
||||||
AndroidExecutor androidExecutor,
|
|
||||||
EventBus eventBus,
|
|
||||||
IdentityManager identityManager,
|
|
||||||
AndroidNotificationManager notificationManager,
|
|
||||||
SharingController sharingController,
|
|
||||||
@CryptoExecutor Executor cryptoExecutor,
|
|
||||||
Clock clock,
|
|
||||||
MessageTracker messageTracker,
|
|
||||||
PrivateGroupManager privateGroupManager,
|
|
||||||
GroupMessageFactory groupMessageFactory) {
|
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
|
||||||
identityManager, notificationManager, sharingController,
|
|
||||||
cryptoExecutor, clock, messageTracker, eventBus);
|
|
||||||
this.privateGroupManager = privateGroupManager;
|
|
||||||
this.groupMessageFactory = groupMessageFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof GroupMessageAddedEvent) {
|
|
||||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
|
||||||
// only act on non-local messages in this group
|
|
||||||
if (!g.isLocal() && g.getGroupId().equals(groupId)) {
|
|
||||||
LOG.info("Group message received, adding...");
|
|
||||||
GroupMessageItem item = buildItem(g.getHeader(), g.getText());
|
|
||||||
addItem(item, false);
|
|
||||||
// In case the join message comes from the creator,
|
|
||||||
// we need to reload the sharing contacts
|
|
||||||
// in case it was delayed and the sharing count is wrong (#850).
|
|
||||||
if (item instanceof JoinMessageItem &&
|
|
||||||
(((JoinMessageItem) item).isInitial())) {
|
|
||||||
loadSharingContacts();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (e instanceof GroupInvitationResponseReceivedEvent) {
|
|
||||||
GroupInvitationResponseReceivedEvent g =
|
|
||||||
(GroupInvitationResponseReceivedEvent) e;
|
|
||||||
GroupInvitationResponse r = g.getMessageHeader();
|
|
||||||
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
|
||||||
sharingController.add(g.getContactId());
|
|
||||||
}
|
|
||||||
} else if (e instanceof ContactRelationshipRevealedEvent) {
|
|
||||||
ContactRelationshipRevealedEvent c =
|
|
||||||
(ContactRelationshipRevealedEvent) e;
|
|
||||||
if (c.getGroupId().equals(groupId)) {
|
|
||||||
sharingController.add(c.getContactId());
|
|
||||||
}
|
|
||||||
} else if (e instanceof GroupDissolvedEvent) {
|
|
||||||
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
|
||||||
if (g.getGroupId().equals(groupId)) {
|
|
||||||
isDissolved.setEvent(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
super.eventOccurred(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void performInitialLoad() {
|
|
||||||
super.performInitialLoad();
|
|
||||||
loadPrivateGroup(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void clearNotifications() {
|
|
||||||
notificationManager.clearGroupMessageNotification(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadPrivateGroup(GroupId groupId) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
PrivateGroup g = privateGroupManager.getPrivateGroup(groupId);
|
|
||||||
privateGroup.postValue(g);
|
|
||||||
Author author = identityManager.getLocalAuthor();
|
|
||||||
isCreator.postValue(g.getCreator().equals(author));
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadItems() {
|
|
||||||
loadList(txn -> {
|
|
||||||
// check first if group is dissolved
|
|
||||||
isDissolved
|
|
||||||
.postEvent(privateGroupManager.isDissolved(txn, groupId));
|
|
||||||
// now continue to load the items
|
|
||||||
long start = now();
|
|
||||||
List<GroupMessageHeader> headers =
|
|
||||||
privateGroupManager.getHeaders(txn, groupId);
|
|
||||||
logDuration(LOG, "Loading headers", start);
|
|
||||||
start = now();
|
|
||||||
List<GroupMessageItem> items = new ArrayList<>();
|
|
||||||
for (GroupMessageHeader header : headers) {
|
|
||||||
items.add(loadItem(txn, header));
|
|
||||||
}
|
|
||||||
logDuration(LOG, "Loading bodies and creating items", start);
|
|
||||||
return items;
|
|
||||||
}, this::setItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GroupMessageItem loadItem(Transaction txn,
|
|
||||||
GroupMessageHeader header) throws DbException {
|
|
||||||
String text;
|
|
||||||
if (header instanceof JoinMessageHeader) {
|
|
||||||
// will be looked up later
|
|
||||||
text = "";
|
|
||||||
} else {
|
|
||||||
text = privateGroupManager.getMessageText(txn, header.getId());
|
|
||||||
}
|
|
||||||
return buildItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GroupMessageItem buildItem(GroupMessageHeader header, String text) {
|
|
||||||
if (header instanceof JoinMessageHeader) {
|
|
||||||
return new JoinMessageItem((JoinMessageHeader) header, text);
|
|
||||||
}
|
|
||||||
return new GroupMessageItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createAndStoreMessage(String text,
|
|
||||||
@Nullable MessageId parentId) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
LocalAuthor author = identityManager.getLocalAuthor();
|
|
||||||
MessageId previousMsgId =
|
|
||||||
privateGroupManager.getPreviousMsgId(groupId);
|
|
||||||
GroupCount count = privateGroupManager.getGroupCount(groupId);
|
|
||||||
long timestamp = count.getLatestMsgTime();
|
|
||||||
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
|
|
||||||
createMessage(text, timestamp, parentId, author, previousMsgId);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createMessage(String text, long timestamp,
|
|
||||||
@Nullable MessageId parentId, LocalAuthor author,
|
|
||||||
MessageId previousMsgId) {
|
|
||||||
cryptoExecutor.execute(() -> {
|
|
||||||
LOG.info("Creating group message...");
|
|
||||||
GroupMessage msg = groupMessageFactory.createGroupMessage(groupId,
|
|
||||||
timestamp, parentId, author, text, previousMsgId);
|
|
||||||
storePost(msg, text);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storePost(GroupMessage msg, String text) {
|
|
||||||
runOnDbThread(false, txn -> {
|
|
||||||
long start = now();
|
|
||||||
GroupMessageHeader header =
|
|
||||||
privateGroupManager.addLocalMessage(txn, msg);
|
|
||||||
logDuration(LOG, "Storing group message", start);
|
|
||||||
txn.attach(() ->
|
|
||||||
addItem(buildItem(header, text), true)
|
|
||||||
);
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void markItemRead(GroupMessageItem item) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
privateGroupManager.setReadFlag(groupId, item.getId(), true);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadSharingContacts() {
|
|
||||||
runOnDbThread(true, txn -> {
|
|
||||||
Collection<GroupMember> members =
|
|
||||||
privateGroupManager.getMembers(txn, groupId);
|
|
||||||
Collection<ContactId> contactIds = new ArrayList<>();
|
|
||||||
for (GroupMember m : members) {
|
|
||||||
if (m.getContactId() != null)
|
|
||||||
contactIds.add(m.getContactId());
|
|
||||||
}
|
|
||||||
txn.attach(() -> sharingController.addAll(contactIds));
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deletePrivateGroup() {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
privateGroupManager.removePrivateGroup(groupId);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<PrivateGroup> getPrivateGroup() {
|
|
||||||
return privateGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Boolean> isCreator() {
|
|
||||||
return isCreator;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveEvent<Boolean> isDissolved() {
|
|
||||||
return isDissolved;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.android.privategroup.conversation;
|
|||||||
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@@ -12,11 +13,13 @@ import androidx.annotation.UiThread;
|
|||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
class JoinMessageItem extends GroupMessageItem {
|
class JoinMessageItem extends GroupMessageItem {
|
||||||
|
|
||||||
|
private Visibility visibility;
|
||||||
private final boolean isInitial;
|
private final boolean isInitial;
|
||||||
|
|
||||||
JoinMessageItem(JoinMessageHeader h, String text) {
|
JoinMessageItem(JoinMessageHeader h, String text) {
|
||||||
super(h, text);
|
super(h, text);
|
||||||
isInitial = h.isInitial();
|
this.visibility = h.getVisibility();
|
||||||
|
this.isInitial = h.isInitial();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,6 +33,14 @@ class JoinMessageItem extends GroupMessageItem {
|
|||||||
return R.layout.list_item_group_join_notice;
|
return R.layout.list_item_group_join_notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Visibility getVisibility() {
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVisibility(Visibility visibility) {
|
||||||
|
this.visibility = visibility;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isInitial() {
|
boolean isInitial() {
|
||||||
return isInitial;
|
return isInitial;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.contactselection.BaseContactSelectorFragment;
|
import org.briarproject.briar.android.contactselection.BaseContactSelectorFragment;
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorController;
|
import org.briarproject.briar.android.contactselection.ContactSelectorController;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import android.view.ViewGroup;
|
|||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
|
||||||
import org.briarproject.briar.android.contactselection.BaseContactSelectorAdapter;
|
import org.briarproject.briar.android.contactselection.BaseContactSelectorAdapter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import android.widget.ImageView;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.contact.OnContactClickListener;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.contactselection.BaseSelectableContactHolder;
|
import org.briarproject.briar.android.contactselection.BaseSelectableContactHolder;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
package org.briarproject.briar.android.sharing;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public interface SharingController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when the owning ViewModel gets cleared,
|
|
||||||
* so the {@link EventBus} can get unregistered.
|
|
||||||
*/
|
|
||||||
void onCleared();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds one contact to be tracked.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void add(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a collection of contacts to be tracked.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void addAll(Collection<ContactId> contacts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when the contact identified by c is no longer sharing
|
|
||||||
* the given group identified by GroupId g.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void remove(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the total number of contacts that have been added.
|
|
||||||
*/
|
|
||||||
LiveData<SharingInfo> getSharingInfo();
|
|
||||||
|
|
||||||
class SharingInfo {
|
|
||||||
public final int total, online;
|
|
||||||
|
|
||||||
SharingInfo(int total, int online) {
|
|
||||||
this.total = total;
|
|
||||||
this.online = online;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
package org.briarproject.briar.android.sharing;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent;
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public class SharingControllerImpl implements SharingController, EventListener {
|
|
||||||
|
|
||||||
private final EventBus eventBus;
|
|
||||||
private final ConnectionRegistry connectionRegistry;
|
|
||||||
|
|
||||||
// UI thread
|
|
||||||
private final Set<ContactId> contacts = new HashSet<>();
|
|
||||||
private final MutableLiveData<SharingInfo> sharingInfo =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
SharingControllerImpl(EventBus eventBus,
|
|
||||||
ConnectionRegistry connectionRegistry) {
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
this.connectionRegistry = connectionRegistry;
|
|
||||||
eventBus.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCleared() {
|
|
||||||
eventBus.removeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof ContactConnectedEvent) {
|
|
||||||
setConnected(((ContactConnectedEvent) e).getContactId());
|
|
||||||
} else if (e instanceof ContactDisconnectedEvent) {
|
|
||||||
setConnected(((ContactDisconnectedEvent) e).getContactId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
private void setConnected(ContactId c) {
|
|
||||||
if (contacts.contains(c)) {
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
private void updateLiveData() {
|
|
||||||
int online = getOnlineCount();
|
|
||||||
sharingInfo.setValue(new SharingInfo(contacts.size(), online));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getOnlineCount() {
|
|
||||||
int online = 0;
|
|
||||||
for (ContactId c : contacts) {
|
|
||||||
if (connectionRegistry.isConnected(c)) online++;
|
|
||||||
}
|
|
||||||
return online;
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@Override
|
|
||||||
public void addAll(Collection<ContactId> c) {
|
|
||||||
contacts.addAll(c);
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@Override
|
|
||||||
public void add(ContactId c) {
|
|
||||||
contacts.add(c);
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@Override
|
|
||||||
public void remove(ContactId c) {
|
|
||||||
contacts.remove(c);
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveData<SharingInfo> getSharingInfo() {
|
|
||||||
return sharingInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,47 +9,36 @@ import dagger.Provides;
|
|||||||
@Module
|
@Module
|
||||||
public class SharingModule {
|
public class SharingModule {
|
||||||
|
|
||||||
@Module
|
@ActivityScope
|
||||||
@Deprecated
|
@Provides
|
||||||
public static class SharingLegacyModule {
|
ShareForumController provideShareForumController(
|
||||||
|
ShareForumControllerImpl shareForumController) {
|
||||||
@ActivityScope
|
return shareForumController;
|
||||||
@Provides
|
|
||||||
ShareForumController provideShareForumController(
|
|
||||||
ShareForumControllerImpl shareForumController) {
|
|
||||||
return shareForumController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
BlogInvitationController provideInvitationBlogController(
|
|
||||||
BaseActivity activity,
|
|
||||||
BlogInvitationControllerImpl blogInvitationController) {
|
|
||||||
activity.addLifecycleController(blogInvitationController);
|
|
||||||
return blogInvitationController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
ForumInvitationController provideInvitationForumController(
|
|
||||||
BaseActivity activity,
|
|
||||||
ForumInvitationControllerImpl forumInvitationController) {
|
|
||||||
activity.addLifecycleController(forumInvitationController);
|
|
||||||
return forumInvitationController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
ShareBlogController provideShareBlogController(
|
|
||||||
ShareBlogControllerImpl shareBlogController) {
|
|
||||||
return shareBlogController;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
@Provides
|
@Provides
|
||||||
SharingController provideSharingController(
|
BlogInvitationController provideInvitationBlogController(
|
||||||
SharingControllerImpl sharingController) {
|
BaseActivity activity,
|
||||||
return sharingController;
|
BlogInvitationControllerImpl blogInvitationController) {
|
||||||
|
activity.addLifecycleController(blogInvitationController);
|
||||||
|
return blogInvitationController;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
|
@Provides
|
||||||
|
ForumInvitationController provideInvitationForumController(
|
||||||
|
BaseActivity activity,
|
||||||
|
ForumInvitationControllerImpl forumInvitationController) {
|
||||||
|
activity.addLifecycleController(forumInvitationController);
|
||||||
|
return forumInvitationController;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
|
@Provides
|
||||||
|
ShareBlogController provideShareBlogController(
|
||||||
|
ShareBlogControllerImpl shareBlogController) {
|
||||||
|
return shareBlogController;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package org.briarproject.briar.android.threaded;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.briar.api.client.MessageTree;
|
||||||
|
import org.briarproject.briar.api.client.MessageTree.MessageNode;
|
||||||
|
import org.briarproject.briar.client.MessageTreeImpl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
@NotNullByDefault
|
||||||
|
public class NestedTreeList<T extends MessageNode> implements Iterable<T> {
|
||||||
|
|
||||||
|
private final MessageTree<T> tree = new MessageTreeImpl<>();
|
||||||
|
private List<T> depthFirstCollection = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addAll(Collection<T> collection) {
|
||||||
|
tree.add(collection);
|
||||||
|
depthFirstCollection = new ArrayList<>(tree.depthFirstOrder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(T elem) {
|
||||||
|
tree.add(elem);
|
||||||
|
depthFirstCollection = new ArrayList<>(tree.depthFirstOrder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
tree.clear();
|
||||||
|
depthFirstCollection.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(int index) {
|
||||||
|
return depthFirstCollection.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return depthFirstCollection.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(MessageId m) {
|
||||||
|
return tree.contains(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return depthFirstCollection.iterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,14 +99,4 @@ public abstract class ThreadItem implements MessageNode {
|
|||||||
return highlighted;
|
return highlighted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return messageId.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(@Nullable Object o) {
|
|
||||||
return o instanceof ThreadItem &&
|
|
||||||
messageId.equals(((ThreadItem) o).messageId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,45 +4,39 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.util.ItemReturningAdapter;
|
import org.briarproject.briar.android.util.ItemReturningAdapter;
|
||||||
|
import org.briarproject.briar.android.util.VersionedAdapter;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.ListAdapter;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
|
||||||
public class ThreadItemAdapter<I extends ThreadItem>
|
public class ThreadItemAdapter<I extends ThreadItem>
|
||||||
extends ListAdapter<I, BaseThreadItemViewHolder<I>>
|
extends RecyclerView.Adapter<BaseThreadItemViewHolder<I>>
|
||||||
implements ItemReturningAdapter<I> {
|
implements VersionedAdapter, ItemReturningAdapter<I> {
|
||||||
|
|
||||||
static final int UNDEFINED = -1;
|
static final int UNDEFINED = -1;
|
||||||
|
|
||||||
|
protected final NestedTreeList<I> items = new NestedTreeList<>();
|
||||||
private final ThreadItemListener<I> listener;
|
private final ThreadItemListener<I> listener;
|
||||||
|
private final LinearLayoutManager layoutManager;
|
||||||
|
|
||||||
public ThreadItemAdapter(ThreadItemListener<I> listener) {
|
private volatile int revision = 0;
|
||||||
super(new DiffUtil.ItemCallback<I>() {
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(I a, I b) {
|
|
||||||
return a.equals(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public ThreadItemAdapter(ThreadItemListener<I> listener,
|
||||||
public boolean areContentsTheSame(I a, I b) {
|
LinearLayoutManager layoutManager) {
|
||||||
return a.isHighlighted() == b.isHighlighted() &&
|
|
||||||
a.isRead() == b.isRead();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
this.layoutManager = layoutManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -57,27 +51,76 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull BaseThreadItemViewHolder<I> ui,
|
public void onBindViewHolder(@NonNull BaseThreadItemViewHolder<I> ui,
|
||||||
int position) {
|
int position) {
|
||||||
I item = getItem(position);
|
I item = items.get(position);
|
||||||
ui.bind(item, listener);
|
ui.bind(item, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
int findItemPosition(MessageId id) {
|
@Override
|
||||||
for (int i = 0; i < getItemCount(); i++) {
|
public int getItemCount() {
|
||||||
if (id.equals(getItem(i).getId())) return i;
|
return items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRevision() {
|
||||||
|
return revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void incrementRevision() {
|
||||||
|
revision++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setItemWithIdVisible(MessageId messageId) {
|
||||||
|
int pos = 0;
|
||||||
|
for (I item : items) {
|
||||||
|
if (item.getId().equals(messageId)) {
|
||||||
|
layoutManager.scrollToPosition(pos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(Collection<I> items) {
|
||||||
|
this.items.clear();
|
||||||
|
this.items.addAll(items);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(I item) {
|
||||||
|
items.add(item);
|
||||||
|
notifyItemInserted(findItemPosition(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public I getItemAt(int position) {
|
||||||
|
if (position == NO_POSITION || position >= items.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return items.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int findItemPosition(@Nullable I item) {
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
if (items.get(i).equals(item)) return i;
|
||||||
}
|
}
|
||||||
return NO_POSITION; // Not found
|
return NO_POSITION; // Not found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean contains(MessageId m) {
|
||||||
|
return items.contains(m);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Highlights the item with the given {@link MessageId}
|
* Highlights the item with the given {@link MessageId}
|
||||||
* and disables the highlight for a previously highlighted item, if any.
|
* and disables the highlight for a previously highlighted item, if any.
|
||||||
* <p>
|
*
|
||||||
* Only one item can be highlighted at a time.
|
* Only one item can be highlighted at a time.
|
||||||
*/
|
*/
|
||||||
void setHighlightedItem(@Nullable MessageId id) {
|
void setHighlightedItem(@Nullable MessageId id) {
|
||||||
for (int i = 0; i < getItemCount(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
I item = getItem(i);
|
I item = items.get(i);
|
||||||
if (item.getId().equals(id)) {
|
if (id != null && item.getId().equals(id)) {
|
||||||
item.setHighlighted(true);
|
item.setHighlighted(true);
|
||||||
notifyItemChanged(i, item);
|
notifyItemChanged(i, item);
|
||||||
} else if (item.isHighlighted()) {
|
} else if (item.isHighlighted()) {
|
||||||
@@ -89,27 +132,20 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
I getHighlightedItem() {
|
I getHighlightedItem() {
|
||||||
for (I item : getCurrentList()) {
|
for (I i : items) {
|
||||||
if (item.isHighlighted()) return item;
|
if (i.isHighlighted()) return i;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
MessageId getFirstVisibleMessageId(LinearLayoutManager layoutManager) {
|
|
||||||
int position = layoutManager.findFirstVisibleItemPosition();
|
|
||||||
if (position == NO_POSITION) return null;
|
|
||||||
return getItemAt(position).getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the position of the first unread item below the current viewport
|
* Returns the position of the first unread item below the current viewport
|
||||||
*/
|
*/
|
||||||
int getVisibleUnreadPosBottom(LinearLayoutManager layoutManager) {
|
int getVisibleUnreadPosBottom() {
|
||||||
int positionBottom = layoutManager.findLastVisibleItemPosition();
|
int positionBottom = layoutManager.findLastVisibleItemPosition();
|
||||||
if (positionBottom == NO_POSITION) return NO_POSITION;
|
if (positionBottom == NO_POSITION) return NO_POSITION;
|
||||||
for (int i = positionBottom + 1; i < getItemCount(); i++) {
|
for (int i = positionBottom + 1; i < items.size(); i++) {
|
||||||
if (!getItem(i).isRead()) return i;
|
if (!items.get(i).isRead()) return i;
|
||||||
}
|
}
|
||||||
return NO_POSITION;
|
return NO_POSITION;
|
||||||
}
|
}
|
||||||
@@ -117,11 +153,11 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
/**
|
/**
|
||||||
* Returns the position of the first unread item above the current viewport
|
* Returns the position of the first unread item above the current viewport
|
||||||
*/
|
*/
|
||||||
int getVisibleUnreadPosTop(LinearLayoutManager layoutManager) {
|
int getVisibleUnreadPosTop() {
|
||||||
int positionTop = layoutManager.findFirstVisibleItemPosition();
|
int positionTop = layoutManager.findFirstVisibleItemPosition();
|
||||||
int position = NO_POSITION;
|
int position = NO_POSITION;
|
||||||
for (int i = 0; i < getItemCount(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
if (i < positionTop && !getItem(i).isRead()) {
|
if (i < positionTop && !items.get(i).isRead()) {
|
||||||
position = i;
|
position = i;
|
||||||
} else if (i >= positionTop) {
|
} else if (i >= positionTop) {
|
||||||
return position;
|
return position;
|
||||||
@@ -130,11 +166,6 @@ public class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
return NO_POSITION;
|
return NO_POSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public I getItemAt(int position) {
|
|
||||||
return getItem(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ThreadItemListener<I> {
|
public interface ThreadItemListener<I> {
|
||||||
void onReplyClick(I item);
|
void onReplyClick(I item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.briar.android.threaded;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public interface ThreadItemList<I extends ThreadItem> extends List<I> {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
MessageId getFirstVisibleItemId();
|
||||||
|
|
||||||
|
void setFirstVisibleId(@Nullable MessageId bottomVisibleItemId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.briarproject.briar.android.threaded;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class ThreadItemListImpl<I extends ThreadItem> extends ArrayList<I>
|
||||||
|
implements ThreadItemList<I> {
|
||||||
|
|
||||||
|
private MessageId bottomVisibleItemId;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageId getFirstVisibleItemId() {
|
||||||
|
return bottomVisibleItemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFirstVisibleId(@Nullable MessageId bottomVisibleItemId) {
|
||||||
|
this.bottomVisibleItemId = bottomVisibleItemId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,18 +2,25 @@ package org.briarproject.briar.android.threaded;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
import org.briarproject.briar.android.sharing.SharingController.SharingInfo;
|
import org.briarproject.briar.android.controller.SharingController;
|
||||||
|
import org.briarproject.briar.android.controller.SharingController.SharingListener;
|
||||||
|
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListController.ThreadListDataSource;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListController.ThreadListListener;
|
||||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
@@ -21,13 +28,18 @@ import org.briarproject.briar.android.view.TextSendController;
|
|||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
import org.briarproject.briar.android.view.UnreadMessageButton;
|
import org.briarproject.briar.android.view.UnreadMessageButton;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
import org.briarproject.briar.api.client.NamedGroup;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
@@ -36,19 +48,32 @@ import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
|||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadItemAdapter<I>>
|
public abstract class ThreadListActivity<G extends NamedGroup, I extends ThreadItem, A extends ThreadItemAdapter<I>>
|
||||||
extends BriarActivity implements SendListener, ThreadItemListener<I> {
|
extends BriarActivity
|
||||||
|
implements ThreadListListener<I>, SendListener, SharingListener,
|
||||||
|
ThreadItemListener<I>, ThreadListDataSource {
|
||||||
|
|
||||||
protected final A adapter = createAdapter();
|
protected static final String KEY_REPLY_ID = "replyId";
|
||||||
protected abstract ThreadListViewModel<I> getViewModel();
|
|
||||||
protected abstract A createAdapter();
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(ThreadListActivity.class.getName());
|
||||||
|
|
||||||
|
protected A adapter;
|
||||||
|
private ThreadScrollListener<I> scrollListener;
|
||||||
protected BriarRecyclerView list;
|
protected BriarRecyclerView list;
|
||||||
|
private LinearLayoutManager layoutManager;
|
||||||
protected TextInputView textInput;
|
protected TextInputView textInput;
|
||||||
protected TextSendController sendController;
|
protected TextSendController sendController;
|
||||||
protected GroupId groupId;
|
protected GroupId groupId;
|
||||||
|
@Nullable
|
||||||
|
private Parcelable layoutManagerState;
|
||||||
|
@Nullable
|
||||||
|
private MessageId replyId;
|
||||||
|
|
||||||
private LinearLayoutManager layoutManager;
|
protected abstract ThreadListController<G, I> getController();
|
||||||
private ThreadScrollListener<I> scrollListener;
|
|
||||||
|
@Inject
|
||||||
|
protected SharingController sharingController;
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
@@ -61,8 +86,7 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||||
if (b == null) throw new IllegalStateException("No GroupId in intent.");
|
if (b == null) throw new IllegalStateException("No GroupId in intent.");
|
||||||
groupId = new GroupId(b);
|
groupId = new GroupId(b);
|
||||||
ThreadListViewModel<I> viewModel = getViewModel();
|
getController().setGroupId(groupId);
|
||||||
viewModel.setGroupId(groupId);
|
|
||||||
|
|
||||||
textInput = findViewById(R.id.text_input_container);
|
textInput = findViewById(R.id.text_input_container);
|
||||||
sendController = new TextSendController(textInput, this, false);
|
sendController = new TextSendController(textInput, this, false);
|
||||||
@@ -76,41 +100,131 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
list = findViewById(R.id.list);
|
list = findViewById(R.id.list);
|
||||||
layoutManager = new LinearLayoutManager(this);
|
layoutManager = new LinearLayoutManager(this);
|
||||||
list.setLayoutManager(layoutManager);
|
list.setLayoutManager(layoutManager);
|
||||||
|
adapter = createAdapter(layoutManager);
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
scrollListener = new ThreadScrollListener<>(adapter, viewModel,
|
scrollListener = new ThreadScrollListener<>(adapter, getController(),
|
||||||
upButton, downButton);
|
upButton, downButton);
|
||||||
list.getRecyclerView().addOnScrollListener(scrollListener);
|
list.getRecyclerView().addOnScrollListener(scrollListener);
|
||||||
|
|
||||||
upButton.setOnClickListener(v -> {
|
upButton.setOnClickListener(v -> {
|
||||||
int position = adapter.getVisibleUnreadPosTop(layoutManager);
|
int position = adapter.getVisibleUnreadPosTop();
|
||||||
if (position != NO_POSITION) {
|
if (position != NO_POSITION) {
|
||||||
list.getRecyclerView().scrollToPosition(position);
|
list.getRecyclerView().scrollToPosition(position);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
downButton.setOnClickListener(v -> {
|
downButton.setOnClickListener(v -> {
|
||||||
int position = adapter.getVisibleUnreadPosBottom(layoutManager);
|
int position = adapter.getVisibleUnreadPosBottom();
|
||||||
if (position != NO_POSITION) {
|
if (position != NO_POSITION) {
|
||||||
list.getRecyclerView().scrollToPosition(position);
|
list.getRecyclerView().scrollToPosition(position);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
viewModel.getItems().observe(this, result -> result
|
if (state != null) {
|
||||||
.onError(this::handleException)
|
byte[] replyIdBytes = state.getByteArray(KEY_REPLY_ID);
|
||||||
.onSuccess(this::displayItems)
|
if (replyIdBytes != null) replyId = new MessageId(replyIdBytes);
|
||||||
);
|
}
|
||||||
|
|
||||||
viewModel.getSharingInfo().observe(this, this::setToolbarSubTitle);
|
sharingController.setSharingListener(this);
|
||||||
|
loadSharingContacts();
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.getGroupRemoved().observe(this, removed -> {
|
@Override
|
||||||
if (removed) supportFinishAfterTransition();
|
@Nullable
|
||||||
});
|
public MessageId getFirstVisibleMessageId() {
|
||||||
|
if (layoutManager != null && adapter != null) {
|
||||||
|
int position =
|
||||||
|
layoutManager.findFirstVisibleItemPosition();
|
||||||
|
I i = adapter.getItemAt(position);
|
||||||
|
return i == null ? null : i.getId();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract A createAdapter(LinearLayoutManager layoutManager);
|
||||||
|
|
||||||
|
protected void loadNamedGroup() {
|
||||||
|
getController().loadNamedGroup(
|
||||||
|
new UiResultExceptionHandler<G, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(G groupItem) {
|
||||||
|
onNamedGroupLoaded(groupItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
protected abstract void onNamedGroupLoaded(G groupItem);
|
||||||
|
|
||||||
|
protected void loadItems() {
|
||||||
|
int revision = adapter.getRevision();
|
||||||
|
getController().loadItems(
|
||||||
|
new UiResultExceptionHandler<ThreadItemList<I>, DbException>(
|
||||||
|
this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(ThreadItemList<I> items) {
|
||||||
|
if (revision == adapter.getRevision()) {
|
||||||
|
adapter.incrementRevision();
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
list.showData();
|
||||||
|
} else {
|
||||||
|
displayItems(items);
|
||||||
|
updateTextInput();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG.info("Concurrent update, reloading");
|
||||||
|
loadItems();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayItems(ThreadItemList<I> items) {
|
||||||
|
adapter.setItems(items);
|
||||||
|
MessageId messageId = items.getFirstVisibleItemId();
|
||||||
|
if (messageId != null)
|
||||||
|
adapter.setItemWithIdVisible(messageId);
|
||||||
|
list.showData();
|
||||||
|
if (layoutManagerState == null) {
|
||||||
|
list.scrollToPosition(0); // Scroll to the top
|
||||||
|
} else {
|
||||||
|
layoutManager.onRestoreInstanceState(layoutManagerState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadSharingContacts() {
|
||||||
|
getController().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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
getViewModel().blockAndClearNotifications();
|
sharingController.onStart();
|
||||||
|
loadItems();
|
||||||
list.startPeriodicUpdate();
|
list.startPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,98 +232,91 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
getViewModel().unblockNotifications();
|
sharingController.onStop();
|
||||||
list.stopPeriodicUpdate();
|
list.stopPeriodicUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
super.onSaveInstanceState(outState);
|
||||||
supportFinishAfterTransition();
|
if (layoutManager != null) {
|
||||||
return true;
|
layoutManagerState = layoutManager.onSaveInstanceState();
|
||||||
|
outState.putParcelable("layoutManager", layoutManagerState);
|
||||||
|
}
|
||||||
|
if (replyId != null) {
|
||||||
|
outState.putByteArray(KEY_REPLY_ID, replyId.getBytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||||
|
super.onRestoreInstanceState(savedInstanceState);
|
||||||
|
layoutManagerState = savedInstanceState.getParcelable("layoutManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
supportFinishAfterTransition();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (adapter.getHighlightedItem() != null) {
|
if (adapter.getHighlightedItem() != null) {
|
||||||
textInput.clearText();
|
textInput.clearText();
|
||||||
getViewModel().setReplyId(null);
|
replyId = null;
|
||||||
updateTextInput();
|
updateTextInput();
|
||||||
} else {
|
} else {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
// store list position, so we can restore it when coming back here
|
|
||||||
if (layoutManager != null && adapter != null) {
|
|
||||||
MessageId id = adapter.getFirstVisibleMessageId(layoutManager);
|
|
||||||
getViewModel().storeMessageId(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void displayItems(List<I> items) {
|
|
||||||
if (items.isEmpty()) {
|
|
||||||
list.showData();
|
|
||||||
} else {
|
|
||||||
adapter.submitList(items, () -> {
|
|
||||||
// do stuff *after* list had been updated
|
|
||||||
scrollAfterListCommitted();
|
|
||||||
updateTextInput();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scrolls to the first visible item last time the activity was open,
|
|
||||||
* if one exists and this is the first time, the list gets displayed.
|
|
||||||
* Or scrolls to a locally added item that has just been added to the list.
|
|
||||||
*/
|
|
||||||
private void scrollAfterListCommitted() {
|
|
||||||
MessageId restoredFirstVisibleItemId =
|
|
||||||
getViewModel().getAndResetRestoredMessageId();
|
|
||||||
MessageId scrollToItem =
|
|
||||||
getViewModel().getAndResetScrollToItem();
|
|
||||||
if (restoredFirstVisibleItemId != null) {
|
|
||||||
scrollToItemAtTop(restoredFirstVisibleItemId);
|
|
||||||
} else if (scrollToItem != null) {
|
|
||||||
scrollToItemAtTop(scrollToItem);
|
|
||||||
}
|
|
||||||
scrollListener.updateUnreadButtons(layoutManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReplyClick(I item) {
|
public void onReplyClick(I item) {
|
||||||
getViewModel().setReplyId(item.getId());
|
replyId = item.getId();
|
||||||
updateTextInput();
|
updateTextInput();
|
||||||
// FIXME This does not work for a hardware keyboard
|
// FIXME This does not work for a hardware keyboard
|
||||||
if (textInput.isKeyboardOpen()) {
|
if (textInput.isKeyboardOpen()) {
|
||||||
scrollToItemAtTop(item.getId());
|
scrollToItemAtTop(item);
|
||||||
} else {
|
} else {
|
||||||
// wait with scrolling until keyboard opened
|
// wait with scrolling until keyboard opened
|
||||||
textInput.setOnKeyboardShownListener(() -> {
|
textInput.setOnKeyboardShownListener(() -> {
|
||||||
scrollToItemAtTop(item.getId());
|
scrollToItemAtTop(item);
|
||||||
textInput.setOnKeyboardShownListener(null);
|
textInput.setOnKeyboardShownListener(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setToolbarSubTitle(SharingInfo sharingInfo) {
|
@Override
|
||||||
|
public void onSharingInfoUpdated(int total, int online) {
|
||||||
|
setToolbarSubTitle(total, online);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInvitationAccepted(ContactId c) {
|
||||||
|
sharingController.add(c);
|
||||||
|
setToolbarSubTitle(sharingController.getTotalCount(),
|
||||||
|
sharingController.getOnlineCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setToolbarSubTitle(int total, int online) {
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setSubtitle(getString(R.string.shared_with,
|
actionBar.setSubtitle(
|
||||||
sharingInfo.total, sharingInfo.online));
|
getString(R.string.shared_with, total, online));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToItemAtTop(MessageId messageId) {
|
private void scrollToItemAtTop(I item) {
|
||||||
int position = adapter.findItemPosition(messageId);
|
int position = adapter.findItemPosition(item);
|
||||||
if (position != NO_POSITION) {
|
if (position != NO_POSITION) {
|
||||||
layoutManager.scrollToPositionWithOffset(position, 0);
|
layoutManager
|
||||||
|
.scrollToPositionWithOffset(position, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +327,6 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateTextInput() {
|
private void updateTextInput() {
|
||||||
MessageId replyId = getViewModel().getReplyId();
|
|
||||||
if (replyId != null) {
|
if (replyId != null) {
|
||||||
textInput.setHint(R.string.forum_message_reply_hint);
|
textInput.setHint(R.string.forum_message_reply_hint);
|
||||||
textInput.showSoftKeyboard();
|
textInput.showSoftKeyboard();
|
||||||
@@ -235,14 +341,54 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
List<AttachmentHeader> headers) {
|
List<AttachmentHeader> headers) {
|
||||||
if (isNullOrEmpty(text)) throw new AssertionError();
|
if (isNullOrEmpty(text)) throw new AssertionError();
|
||||||
|
|
||||||
MessageId replyId = getViewModel().getReplyId();
|
I replyItem = adapter.getHighlightedItem();
|
||||||
getViewModel().createAndStoreMessage(text, replyId);
|
UiResultExceptionHandler<I, DbException> handler =
|
||||||
|
new UiResultExceptionHandler<I, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(I result) {
|
||||||
|
addItem(result, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getController().createAndStoreMessage(text, replyItem, handler);
|
||||||
textInput.hideSoftKeyboard();
|
textInput.hideSoftKeyboard();
|
||||||
textInput.clearText();
|
textInput.clearText();
|
||||||
getViewModel().setReplyId(null);
|
replyId = null;
|
||||||
updateTextInput();
|
updateTextInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int getMaxTextLength();
|
protected abstract int getMaxTextLength();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemReceived(I item) {
|
||||||
|
addItem(item, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGroupRemoved() {
|
||||||
|
supportFinishAfterTransition();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addItem(I item, boolean isLocal) {
|
||||||
|
adapter.incrementRevision();
|
||||||
|
MessageId parent = item.getParentId();
|
||||||
|
if (parent != null && !adapter.contains(parent)) {
|
||||||
|
// We've incremented the adapter's revision, so the item will be
|
||||||
|
// loaded when its parent has been loaded
|
||||||
|
LOG.info("Ignoring item with missing parent");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
adapter.add(item);
|
||||||
|
|
||||||
|
if (isLocal) {
|
||||||
|
scrollToItemAtTop(item);
|
||||||
|
} else {
|
||||||
|
scrollListener.updateUnreadButtons(layoutManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.briarproject.briar.android.threaded;
|
||||||
|
|
||||||
|
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.ActivityLifecycleController;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.api.client.NamedGroup;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ThreadListController<G extends NamedGroup, I extends ThreadItem>
|
||||||
|
extends ActivityLifecycleController {
|
||||||
|
|
||||||
|
void setGroupId(GroupId groupId);
|
||||||
|
|
||||||
|
void loadNamedGroup(ResultExceptionHandler<G, DbException> handler);
|
||||||
|
|
||||||
|
void loadSharingContacts(
|
||||||
|
ResultExceptionHandler<Collection<ContactId>, DbException> handler);
|
||||||
|
|
||||||
|
void loadItems(
|
||||||
|
ResultExceptionHandler<ThreadItemList<I>, DbException> handler);
|
||||||
|
|
||||||
|
void markItemRead(I item);
|
||||||
|
|
||||||
|
void markItemsRead(Collection<I> items);
|
||||||
|
|
||||||
|
void createAndStoreMessage(String text, @Nullable I parentItem,
|
||||||
|
ResultExceptionHandler<I, DbException> handler);
|
||||||
|
|
||||||
|
void deleteNamedGroup(ExceptionHandler<DbException> handler);
|
||||||
|
|
||||||
|
interface ThreadListListener<I> extends ThreadListDataSource {
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void onItemReceived(I item);
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void onGroupRemoved();
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void onInvitationAccepted(ContactId c);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ThreadListDataSource {
|
||||||
|
|
||||||
|
@UiThread @Nullable
|
||||||
|
MessageId getFirstVisibleMessageId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
package org.briarproject.briar.android.threaded;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
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.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.bramble.api.system.Clock;
|
||||||
|
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.android.threaded.ThreadListController.ThreadListListener;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
|
import org.briarproject.briar.api.client.NamedGroup;
|
||||||
|
import org.briarproject.briar.api.client.PostHeader;
|
||||||
|
import org.briarproject.briar.api.client.ThreadedMessage;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import androidx.annotation.CallSuper;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends ThreadItem, H extends PostHeader, M extends ThreadedMessage, L extends ThreadListListener<I>>
|
||||||
|
extends DbControllerImpl
|
||||||
|
implements ThreadListController<G, I>, EventListener {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(ThreadListControllerImpl.class.getName());
|
||||||
|
|
||||||
|
private final EventBus eventBus;
|
||||||
|
private final MessageTracker messageTracker;
|
||||||
|
private final Map<MessageId, String> textCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private volatile GroupId groupId;
|
||||||
|
|
||||||
|
protected final IdentityManager identityManager;
|
||||||
|
protected final AndroidNotificationManager notificationManager;
|
||||||
|
protected final Executor cryptoExecutor;
|
||||||
|
protected final Clock clock;
|
||||||
|
|
||||||
|
// UI thread
|
||||||
|
protected L listener;
|
||||||
|
|
||||||
|
protected ThreadListControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||||
|
@CryptoExecutor Executor cryptoExecutor, EventBus eventBus,
|
||||||
|
Clock clock, AndroidNotificationManager notificationManager,
|
||||||
|
MessageTracker messageTracker) {
|
||||||
|
super(dbExecutor, lifecycleManager);
|
||||||
|
this.identityManager = identityManager;
|
||||||
|
this.cryptoExecutor = cryptoExecutor;
|
||||||
|
this.notificationManager = notificationManager;
|
||||||
|
this.clock = clock;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
this.messageTracker = messageTracker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGroupId(GroupId groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void onActivityCreate(Activity activity) {
|
||||||
|
listener = (L) activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
@Override
|
||||||
|
public void onActivityStart() {
|
||||||
|
notificationManager.blockNotification(getGroupId());
|
||||||
|
eventBus.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
@Override
|
||||||
|
public void onActivityStop() {
|
||||||
|
notificationManager.unblockNotification(getGroupId());
|
||||||
|
eventBus.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityDestroy() {
|
||||||
|
MessageId messageId = listener.getFirstVisibleMessageId();
|
||||||
|
if (messageId != null) {
|
||||||
|
dbExecutor.execute(() -> {
|
||||||
|
try {
|
||||||
|
messageTracker.storeMessageId(groupId, messageId);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
if (e instanceof GroupRemovedEvent) {
|
||||||
|
GroupRemovedEvent s = (GroupRemovedEvent) e;
|
||||||
|
if (s.getGroup().getId().equals(getGroupId())) {
|
||||||
|
LOG.info("Group removed");
|
||||||
|
listener.onGroupRemoved();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadNamedGroup(
|
||||||
|
ResultExceptionHandler<G, DbException> handler) {
|
||||||
|
checkGroupId();
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
long start = now();
|
||||||
|
G groupItem = loadNamedGroup();
|
||||||
|
logDuration(LOG, "Loading group", start);
|
||||||
|
handler.onResult(groupItem);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected abstract G loadNamedGroup() throws DbException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadItems(
|
||||||
|
ResultExceptionHandler<ThreadItemList<I>, DbException> handler) {
|
||||||
|
checkGroupId();
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
// Load headers
|
||||||
|
long start = now();
|
||||||
|
Collection<H> headers = loadHeaders();
|
||||||
|
logDuration(LOG, "Loading headers", start);
|
||||||
|
|
||||||
|
// Load bodies into cache
|
||||||
|
start = now();
|
||||||
|
for (H header : headers) {
|
||||||
|
if (!textCache.containsKey(header.getId())) {
|
||||||
|
textCache.put(header.getId(),
|
||||||
|
loadMessageText(header));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logDuration(LOG, "Loading bodies", start);
|
||||||
|
|
||||||
|
// Build and hand over items
|
||||||
|
handler.onResult(buildItems(headers));
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected abstract Collection<H> loadHeaders() throws DbException;
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected abstract String loadMessageText(H header) throws DbException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markItemRead(I item) {
|
||||||
|
markItemsRead(Collections.singletonList(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markItemsRead(Collection<I> items) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
long start = now();
|
||||||
|
for (I i : items) {
|
||||||
|
markRead(i.getId());
|
||||||
|
}
|
||||||
|
logDuration(LOG, "Marking read", start);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected abstract void markRead(MessageId id) throws DbException;
|
||||||
|
|
||||||
|
protected void storePost(M msg, String text,
|
||||||
|
ResultExceptionHandler<I, DbException> resultHandler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
long start = now();
|
||||||
|
H header = addLocalMessage(msg);
|
||||||
|
textCache.put(msg.getMessage().getId(), text);
|
||||||
|
logDuration(LOG, "Storing message", start);
|
||||||
|
resultHandler.onResult(buildItem(header, text));
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
resultHandler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected abstract H addLocalMessage(M message) throws DbException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteNamedGroup(ExceptionHandler<DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
long start = now();
|
||||||
|
G groupItem = loadNamedGroup();
|
||||||
|
deleteNamedGroup(groupItem);
|
||||||
|
logDuration(LOG, "Removing group", start);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
protected abstract void deleteNamedGroup(G groupItem) throws DbException;
|
||||||
|
|
||||||
|
private ThreadItemList<I> buildItems(Collection<H> headers)
|
||||||
|
throws DbException {
|
||||||
|
ThreadItemList<I> items = new ThreadItemListImpl<>();
|
||||||
|
for (H h : headers) {
|
||||||
|
items.add(buildItem(h, textCache.get(h.getId())));
|
||||||
|
}
|
||||||
|
MessageId msgId = messageTracker.loadStoredMessageId(groupId);
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Loaded last top visible message id " + msgId);
|
||||||
|
items.setFirstVisibleId(msgId);
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract I buildItem(H header, String text);
|
||||||
|
|
||||||
|
protected GroupId getGroupId() {
|
||||||
|
checkGroupId();
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkGroupId() {
|
||||||
|
if (groupId == null) throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
package org.briarproject.briar.android.threaded;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|
||||||
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.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.bramble.api.system.AndroidExecutor;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.briar.android.sharing.SharingController;
|
|
||||||
import org.briarproject.briar.android.sharing.SharingController.SharingInfo;
|
|
||||||
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.client.MessageTracker;
|
|
||||||
import org.briarproject.briar.api.client.MessageTree;
|
|
||||||
import org.briarproject.briar.client.MessageTreeImpl;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
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.LogUtils.logException;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public abstract class ThreadListViewModel<I extends ThreadItem>
|
|
||||||
extends DbViewModel implements EventListener {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
getLogger(ThreadListViewModel.class.getName());
|
|
||||||
|
|
||||||
protected final IdentityManager identityManager;
|
|
||||||
protected final AndroidNotificationManager notificationManager;
|
|
||||||
protected final SharingController sharingController;
|
|
||||||
protected final Executor cryptoExecutor;
|
|
||||||
protected final Clock clock;
|
|
||||||
private final MessageTracker messageTracker;
|
|
||||||
private final EventBus eventBus;
|
|
||||||
|
|
||||||
// UIThread
|
|
||||||
private final MessageTree<I> messageTree = new MessageTreeImpl<>();
|
|
||||||
private final MutableLiveData<LiveResult<List<I>>> items =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
private final MutableLiveData<Boolean> groupRemoved =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
private final AtomicReference<MessageId> scrollToItem =
|
|
||||||
new AtomicReference<>();
|
|
||||||
|
|
||||||
protected volatile GroupId groupId;
|
|
||||||
@Nullable
|
|
||||||
private MessageId replyId;
|
|
||||||
/**
|
|
||||||
* Stored list position. Needs to be loaded and set before the list itself.
|
|
||||||
*/
|
|
||||||
private final AtomicReference<MessageId> storedMessageId =
|
|
||||||
new AtomicReference<>();
|
|
||||||
|
|
||||||
public ThreadListViewModel(Application application,
|
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
|
||||||
LifecycleManager lifecycleManager,
|
|
||||||
TransactionManager db,
|
|
||||||
AndroidExecutor androidExecutor,
|
|
||||||
IdentityManager identityManager,
|
|
||||||
AndroidNotificationManager notificationManager,
|
|
||||||
SharingController sharingController,
|
|
||||||
@CryptoExecutor Executor cryptoExecutor,
|
|
||||||
Clock clock,
|
|
||||||
MessageTracker messageTracker,
|
|
||||||
EventBus eventBus) {
|
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
|
||||||
this.identityManager = identityManager;
|
|
||||||
this.notificationManager = notificationManager;
|
|
||||||
this.cryptoExecutor = cryptoExecutor;
|
|
||||||
this.clock = clock;
|
|
||||||
this.sharingController = sharingController;
|
|
||||||
this.messageTracker = messageTracker;
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
this.eventBus.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCleared() {
|
|
||||||
super.onCleared();
|
|
||||||
eventBus.removeListener(this);
|
|
||||||
sharingController.onCleared();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Needs to be called right after initialization,
|
|
||||||
* before calling any other methods.
|
|
||||||
*/
|
|
||||||
public final void setGroupId(GroupId groupId) {
|
|
||||||
boolean needsInitialLoad = this.groupId == null;
|
|
||||||
this.groupId = groupId;
|
|
||||||
if (needsInitialLoad) performInitialLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
@CallSuper
|
|
||||||
protected void performInitialLoad() {
|
|
||||||
// load stored MessageId (last list position) before the list itself
|
|
||||||
loadStoredMessageId();
|
|
||||||
loadItems();
|
|
||||||
loadSharingContacts();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void clearNotifications();
|
|
||||||
|
|
||||||
void blockAndClearNotifications() {
|
|
||||||
notificationManager.blockNotification(groupId);
|
|
||||||
clearNotifications();
|
|
||||||
}
|
|
||||||
|
|
||||||
void unblockNotifications() {
|
|
||||||
notificationManager.unblockNotification(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@CallSuper
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof GroupRemovedEvent) {
|
|
||||||
GroupRemovedEvent s = (GroupRemovedEvent) e;
|
|
||||||
if (s.getGroup().getId().equals(groupId)) {
|
|
||||||
LOG.info("Group removed");
|
|
||||||
groupRemoved.setValue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadStoredMessageId() {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
storedMessageId
|
|
||||||
.set(messageTracker.loadStoredMessageId(groupId));
|
|
||||||
if (LOG.isLoggable(INFO)) {
|
|
||||||
LOG.info("Loaded last top visible message id " +
|
|
||||||
storedMessageId);
|
|
||||||
}
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void loadItems();
|
|
||||||
|
|
||||||
public abstract void createAndStoreMessage(String text,
|
|
||||||
@Nullable MessageId parentMessageId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the ContactIds of all contacts the group is shared with
|
|
||||||
* and adds them to {@link SharingController}.
|
|
||||||
*/
|
|
||||||
protected abstract void loadSharingContacts();
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
protected void setItems(LiveResult<List<I>> items) {
|
|
||||||
if (items.hasError()) {
|
|
||||||
this.items.setValue(items);
|
|
||||||
} else {
|
|
||||||
messageTree.clear();
|
|
||||||
// not null, because hasError() is false
|
|
||||||
messageTree.add(requireNonNull(items.getResultOrNull()));
|
|
||||||
LiveResult<List<I>> result =
|
|
||||||
new LiveResult<>(messageTree.depthFirstOrder());
|
|
||||||
this.items.setValue(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a remote item on the UI thread.
|
|
||||||
*
|
|
||||||
* @param scrollToItem whether the list will scroll to the newly added item
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
protected void addItem(I item, boolean scrollToItem) {
|
|
||||||
messageTree.add(item);
|
|
||||||
if (scrollToItem) this.scrollToItem.set(item.getId());
|
|
||||||
items.setValue(new LiveResult<>(messageTree.depthFirstOrder()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void setReplyId(@Nullable MessageId id) {
|
|
||||||
replyId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@Nullable
|
|
||||||
MessageId getReplyId() {
|
|
||||||
return replyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void storeMessageId(@Nullable MessageId messageId) {
|
|
||||||
if (messageId != null) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
messageTracker.storeMessageId(groupId, messageId);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void markItemRead(I item);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link MessageId} of the item that was at the top of the
|
|
||||||
* list last time or null if there has been nothing stored, yet.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
MessageId getAndResetRestoredMessageId() {
|
|
||||||
return storedMessageId.getAndSet(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<LiveResult<List<I>>> getItems() {
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<SharingInfo> getSharingInfo() {
|
|
||||||
return sharingController.getSharingInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Boolean> getGroupRemoved() {
|
|
||||||
return groupRemoved;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
MessageId getAndResetScrollToItem() {
|
|
||||||
return scrollToItem.getAndSet(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,15 +20,15 @@ class ThreadScrollListener<I extends ThreadItem>
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(ThreadScrollListener.class.getName());
|
getLogger(ThreadScrollListener.class.getName());
|
||||||
|
|
||||||
private final ThreadListViewModel<I> viewModel;
|
private final ThreadListController<?, I> controller;
|
||||||
private final UnreadMessageButton upButton, downButton;
|
private final UnreadMessageButton upButton, downButton;
|
||||||
|
|
||||||
ThreadScrollListener(ThreadItemAdapter<I> adapter,
|
ThreadScrollListener(ThreadItemAdapter<I> adapter,
|
||||||
ThreadListViewModel<I> viewModel,
|
ThreadListController<?, I> controller,
|
||||||
UnreadMessageButton upButton,
|
UnreadMessageButton upButton,
|
||||||
UnreadMessageButton downButton) {
|
UnreadMessageButton downButton) {
|
||||||
super(adapter);
|
super(adapter);
|
||||||
this.viewModel = viewModel;
|
this.controller = controller;
|
||||||
this.upButton = upButton;
|
this.upButton = upButton;
|
||||||
this.downButton = downButton;
|
this.downButton = downButton;
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ class ThreadScrollListener<I extends ThreadItem>
|
|||||||
protected void onItemVisible(I item) {
|
protected void onItemVisible(I item) {
|
||||||
if (!item.isRead()) {
|
if (!item.isRead()) {
|
||||||
item.setRead(true);
|
item.setRead(true);
|
||||||
viewModel.markItemRead(item);
|
controller.markItemRead(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import androidx.fragment.app.FragmentManager;
|
|||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
|
||||||
|
|
||||||
import static android.content.Context.KEYGUARD_SERVICE;
|
import static android.content.Context.KEYGUARD_SERVICE;
|
||||||
import static android.content.Context.POWER_SERVICE;
|
import static android.content.Context.POWER_SERVICE;
|
||||||
@@ -89,6 +88,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
|||||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||||
import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode;
|
import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode;
|
||||||
import static androidx.core.content.ContextCompat.getColor;
|
import static androidx.core.content.ContextCompat.getColor;
|
||||||
|
import static androidx.core.content.ContextCompat.getDrawable;
|
||||||
import static androidx.core.content.ContextCompat.getSystemService;
|
import static androidx.core.content.ContextCompat.getSystemService;
|
||||||
import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
||||||
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_RTL;
|
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||||
@@ -436,8 +436,7 @@ public class UiUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Drawable getDialogIcon(Context ctx, @DrawableRes int resId) {
|
public static Drawable getDialogIcon(Context ctx, @DrawableRes int resId) {
|
||||||
Drawable icon =
|
Drawable icon = getDrawable(ctx, resId);
|
||||||
VectorDrawableCompat.create(ctx.getResources(), resId, null);
|
|
||||||
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.android.view;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -52,8 +53,9 @@ public class BriarRecyclerView extends FrameLayout {
|
|||||||
R.styleable.BriarRecyclerView);
|
R.styleable.BriarRecyclerView);
|
||||||
isScrollingToEnd = attributes
|
isScrollingToEnd = attributes
|
||||||
.getBoolean(R.styleable.BriarRecyclerView_scrollToEnd, true);
|
.getBoolean(R.styleable.BriarRecyclerView_scrollToEnd, true);
|
||||||
int drawableRes = attributes.getResourceId(R.styleable.BriarRecyclerView_emptyImage, -1);
|
Drawable drawable = attributes
|
||||||
if (drawableRes != -1) setEmptyImage(drawableRes);
|
.getDrawable(R.styleable.BriarRecyclerView_emptyImage);
|
||||||
|
if (drawable != null) setEmptyImage(drawable);
|
||||||
String emtpyText =
|
String emtpyText =
|
||||||
attributes.getString(R.styleable.BriarRecyclerView_emptyText);
|
attributes.getString(R.styleable.BriarRecyclerView_emptyText);
|
||||||
if (emtpyText != null) setEmptyText(emtpyText);
|
if (emtpyText != null) setEmptyText(emtpyText);
|
||||||
@@ -87,26 +89,6 @@ public class BriarRecyclerView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
emptyObserver = new RecyclerView.AdapterDataObserver() {
|
emptyObserver = new RecyclerView.AdapterDataObserver() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChanged() {
|
|
||||||
super.onChanged();
|
|
||||||
showData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemRangeChanged(int positionStart, int itemCount) {
|
|
||||||
super.onItemRangeChanged(positionStart, itemCount);
|
|
||||||
if (itemCount > 0) showData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemRangeMoved(int fromPosition, int toPosition,
|
|
||||||
int itemCount) {
|
|
||||||
super.onItemRangeMoved(fromPosition, toPosition, itemCount);
|
|
||||||
if (itemCount > 0) showData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemRangeInserted(int positionStart, int itemCount) {
|
public void onItemRangeInserted(int positionStart, int itemCount) {
|
||||||
super.onItemRangeInserted(positionStart, itemCount);
|
super.onItemRangeInserted(positionStart, itemCount);
|
||||||
@@ -157,6 +139,11 @@ public class BriarRecyclerView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEmptyImage(Drawable drawable) {
|
||||||
|
if (recyclerView == null) initViews();
|
||||||
|
emptyImage.setImageDrawable(drawable);
|
||||||
|
}
|
||||||
|
|
||||||
public void setEmptyImage(@DrawableRes int res) {
|
public void setEmptyImage(@DrawableRes int res) {
|
||||||
if (recyclerView == null) initViews();
|
if (recyclerView == null) initViews();
|
||||||
emptyImage.setImageResource(res);
|
emptyImage.setImageResource(res);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.app.Activity;
|
|||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -29,7 +28,6 @@ import androidx.customview.view.AbsSavedState;
|
|||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
|
||||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||||
|
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
@@ -255,14 +253,12 @@ public class TextAttachmentController extends TextSendController
|
|||||||
|
|
||||||
public void showImageOnboarding(Activity activity) {
|
public void showImageOnboarding(Activity activity) {
|
||||||
int color = resolveColorAttribute(activity, R.attr.colorControlNormal);
|
int color = resolveColorAttribute(activity, R.attr.colorControlNormal);
|
||||||
Drawable drawable = VectorDrawableCompat
|
|
||||||
.create(activity.getResources(), R.drawable.ic_image, null);
|
|
||||||
new MaterialTapTargetPrompt.Builder(activity,
|
new MaterialTapTargetPrompt.Builder(activity,
|
||||||
R.style.OnboardingDialogTheme).setTarget(sendButton)
|
R.style.OnboardingDialogTheme).setTarget(sendButton)
|
||||||
.setPrimaryText(R.string.dialog_title_image_support)
|
.setPrimaryText(R.string.dialog_title_image_support)
|
||||||
.setSecondaryText(R.string.dialog_message_image_support)
|
.setSecondaryText(R.string.dialog_message_image_support)
|
||||||
.setBackgroundColour(getColor(activity, R.color.briar_primary))
|
.setBackgroundColour(getColor(activity, R.color.briar_primary))
|
||||||
.setIconDrawable(drawable)
|
.setIcon(R.drawable.ic_image)
|
||||||
.setIconDrawableColourFilter(color)
|
.setIconDrawableColourFilter(color)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.briarproject.briar.R;
|
|||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.appcompat.widget.AppCompatImageView;
|
import androidx.appcompat.widget.AppCompatImageView;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
public class TrustIndicatorView extends AppCompatImageView {
|
public class TrustIndicatorView extends AppCompatImageView {
|
||||||
@@ -43,7 +44,7 @@ public class TrustIndicatorView extends AppCompatImageView {
|
|||||||
default:
|
default:
|
||||||
res = R.drawable.trust_indicator_unknown;
|
res = R.drawable.trust_indicator_unknown;
|
||||||
}
|
}
|
||||||
setImageResource(res);
|
setImageDrawable(ContextCompat.getDrawable(getContext(), res));
|
||||||
setVisibility(VISIBLE);
|
setVisibility(VISIBLE);
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.app.Application;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbCallable;
|
import org.briarproject.bramble.api.db.DbCallable;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.DbRunnable;
|
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
@@ -24,7 +23,6 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.arch.core.util.Function;
|
import androidx.arch.core.util.Function;
|
||||||
import androidx.core.util.Consumer;
|
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
@@ -59,8 +57,8 @@ public abstract class DbViewModel extends AndroidViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the DB to open and runs the given task on the
|
* Runs the given task on the {@link DatabaseExecutor}
|
||||||
* {@link DatabaseExecutor}.
|
* and waits for the DB to open.
|
||||||
* <p>
|
* <p>
|
||||||
* If you need a list of items to be displayed in a
|
* If you need a list of items to be displayed in a
|
||||||
* {@link RecyclerView.Adapter},
|
* {@link RecyclerView.Adapter},
|
||||||
@@ -78,29 +76,6 @@ public abstract class DbViewModel extends AndroidViewModel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Waits for the DB to open and runs the given task on the
|
|
||||||
* {@link DatabaseExecutor}.
|
|
||||||
* <p>
|
|
||||||
* If you need a list of items to be displayed in a
|
|
||||||
* {@link RecyclerView.Adapter},
|
|
||||||
* use {@link #loadList(DbCallable, UiConsumer)} instead.
|
|
||||||
*/
|
|
||||||
protected void runOnDbThread(boolean readOnly,
|
|
||||||
DbRunnable<Exception> task, Consumer<Exception> err) {
|
|
||||||
dbExecutor.execute(() -> {
|
|
||||||
try {
|
|
||||||
lifecycleManager.waitForDatabase();
|
|
||||||
db.transaction(readOnly, task);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LOG.warning("Interrupted while waiting for database");
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
} catch (Exception e) {
|
|
||||||
err.accept(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a list of items on the {@link DatabaseExecutor} within a single
|
* Loads a list of items on the {@link DatabaseExecutor} within a single
|
||||||
* {@link Transaction} and publishes it as a {@link LiveResult}
|
* {@link Transaction} and publishes it as a {@link LiveResult}
|
||||||
|
|||||||
@@ -39,17 +39,6 @@ public class LiveEvent<T> extends LiveData<LiveEvent.ConsumableEvent<T>> {
|
|||||||
super.observeForever(observer);
|
super.observeForever(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the last value of the event (even if already consumed)
|
|
||||||
* or null if there hasn't been any value so far.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public T getLastValue() {
|
|
||||||
ConsumableEvent<T> event = getValue();
|
|
||||||
if (event == null) return null;
|
|
||||||
return event.content;
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ConsumableEvent<T> {
|
static class ConsumableEvent<T> {
|
||||||
|
|
||||||
private final T content;
|
private final T content;
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24"
|
|
||||||
android:tint="#FFFFFF">
|
|
||||||
<group android:scaleX="0.92"
|
|
||||||
android:scaleY="0.92"
|
|
||||||
android:translateX="0.96"
|
|
||||||
android:translateY="0.96">
|
|
||||||
<path
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
|
|
||||||
</group>
|
|
||||||
</vector>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24"
|
|
||||||
android:tint="#FFFFFF">
|
|
||||||
<group android:scaleX="0.92"
|
|
||||||
android:scaleY="0.92"
|
|
||||||
android:translateX="0.96"
|
|
||||||
android:translateY="0.96">
|
|
||||||
<path
|
|
||||||
android:fillColor="#FF000000"
|
|
||||||
android:pathData="M16,17V14H9V10H16V7L21,12L16,17M14,2A2,2 0,0 1,16 4V6H14V4H5V20H14V18H16V20A2,2 0,0 1,14 22H5A2,2 0,0 1,3 20V4A2,2 0,0 1,5 2H14Z"/>
|
|
||||||
</group>
|
|
||||||
</vector>
|
|
||||||
|
Before Width: | Height: | Size: 229 B |
|
Before Width: | Height: | Size: 316 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 341 B |
|
Before Width: | Height: | Size: 498 B |
|
Before Width: | Height: | Size: 359 B |
|
Before Width: | Height: | Size: 235 B |
|
Before Width: | Height: | Size: 266 B |
|
Before Width: | Height: | Size: 200 B |
|
Before Width: | Height: | Size: 228 B |
|
Before Width: | Height: | Size: 205 B |
|
Before Width: | Height: | Size: 263 B |
|
Before Width: | Height: | Size: 387 B |
|
Before Width: | Height: | Size: 279 B |
|
Before Width: | Height: | Size: 202 B |
|
Before Width: | Height: | Size: 205 B |
|
Before Width: | Height: | Size: 273 B |
|
Before Width: | Height: | Size: 362 B |
|
Before Width: | Height: | Size: 291 B |
|
Before Width: | Height: | Size: 442 B |
|
Before Width: | Height: | Size: 663 B |
|
Before Width: | Height: | Size: 489 B |