mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 862771641d | |||
| 2128a1718f | |||
| 7e633a2597 | |||
| 2ffe663798 | |||
| 1453bd1314 | |||
| b99426b7c6 | |||
| de1eedc63f | |||
| ec4db3e58f | |||
| 0d2175b641 | |||
| 97620b8a3c |
@@ -8,7 +8,7 @@ ArcaneChat is a Delta Chat Android client built on top of the official Delta Cha
|
||||
- **Language:** Java (Java 8 compatibility)
|
||||
- **Build System:** Gradle with Android Gradle Plugin 8.11.1
|
||||
- **Min SDK:** 21 (Android 5.0)
|
||||
- **Target SDK:** 35 (Android 15)
|
||||
- **Target SDK:** 36 (Android 16)
|
||||
- **NDK Version:** 27.0.12077973
|
||||
- **Native Components:** Rust (deltachat-core-rust submodule)
|
||||
- **UI Framework:** Android SDK, Material Design Components
|
||||
@@ -17,13 +17,23 @@ ArcaneChat is a Delta Chat Android client built on top of the official Delta Cha
|
||||
## Repository Structure
|
||||
|
||||
- `src/main/` - Main application source code
|
||||
- `src/main/java/org/thoughtcrime/securesms/` - Main UI components
|
||||
- `src/main/java/com/b44t/messenger/` - Delta Chat core integration
|
||||
- `src/main/java/chat/delta/rpc/` - JSON-RPC bindings (generated, don't edit manually)
|
||||
- `src/main/res/` - Android resources (layouts, strings, drawables)
|
||||
- `src/androidTest/` - Instrumented tests (UI tests, benchmarks)
|
||||
- `src/androidTest/java/com/b44t/messenger/uitests/` - UI tests
|
||||
- `src/androidTest/java/com/b44t/messenger/uibenchmarks/` - Performance benchmarks
|
||||
- `src/gplay/` - Google Play flavor-specific code
|
||||
- `src/foss/` - F-Droid/FOSS flavor-specific code
|
||||
- `jni/deltachat-core-rust/` - Native Rust core library (submodule)
|
||||
- `jni/deltachat-core-rust/` - Native Rust core library (submodule, **don't edit directly**)
|
||||
- `scripts/` - Build and helper scripts
|
||||
- `scripts/ndk-make.sh` - Build native libraries
|
||||
- `scripts/install-toolchains.sh` - Install Rust cross-compilation toolchains
|
||||
- `scripts/generate-rpc-bindings.sh` - Generate JSON-RPC bindings
|
||||
- `docs/` - Documentation
|
||||
- `fastlane/` - App store metadata and screenshots
|
||||
- `.github/workflows/` - CI/CD workflows (GitHub Actions)
|
||||
|
||||
## Build Instructions
|
||||
|
||||
@@ -33,17 +43,36 @@ ArcaneChat is a Delta Chat Android client built on top of the official Delta Cha
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
This MUST be done first before any build attempts.
|
||||
|
||||
2. **Build native libraries:**
|
||||
2. **Set up environment variables:**
|
||||
```bash
|
||||
export ANDROID_NDK_ROOT=/path/to/ndk/27.0.12077973
|
||||
export PATH=${PATH}:${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/:${ANDROID_NDK_ROOT}
|
||||
```
|
||||
Note: Path format varies by OS (linux-x86_64, darwin-x86_64, etc.)
|
||||
|
||||
3. **Install Rust toolchains:**
|
||||
```bash
|
||||
scripts/install-toolchains.sh
|
||||
```
|
||||
Required for building the native Rust components.
|
||||
|
||||
4. **Build native libraries:**
|
||||
```bash
|
||||
scripts/ndk-make.sh
|
||||
```
|
||||
Note: First run may take significant time as it builds for all architectures (armeabi-v7a, arm64-v8a, x86, x86_64)
|
||||
**IMPORTANT:** First run takes 30-60 minutes as it builds for all architectures (armeabi-v7a, arm64-v8a, x86, x86_64).
|
||||
For faster development builds, build for a single architecture:
|
||||
```bash
|
||||
scripts/ndk-make.sh armeabi-v7a
|
||||
```
|
||||
|
||||
3. **Build APK:**
|
||||
5. **Build APK:**
|
||||
```bash
|
||||
./gradlew assembleDebug
|
||||
```
|
||||
Build time: ~2-5 minutes after native libraries are built.
|
||||
|
||||
### Build Flavors
|
||||
|
||||
@@ -55,6 +84,24 @@ ArcaneChat is a Delta Chat Android client built on top of the official Delta Cha
|
||||
- Debug APKs: `build/outputs/apk/gplay/debug/` and `build/outputs/apk/fat/debug/`
|
||||
- Release APKs require signing configuration in `~/.gradle/gradle.properties`
|
||||
|
||||
### Common Build Issues
|
||||
|
||||
1. **Missing NDK or incorrect version:**
|
||||
- Error: `ANDROID_NDK_ROOT not set` or native library missing
|
||||
- Solution: Install NDK 27.0.12077973 and set ANDROID_NDK_ROOT environment variable
|
||||
|
||||
2. **Submodules not initialized:**
|
||||
- Error: Missing deltachat-core-rust files
|
||||
- Solution: Run `git submodule update --init --recursive`
|
||||
|
||||
3. **Gradle wrapper validation:**
|
||||
- Always validate gradle wrapper before building: `./gradlew wrapper --gradle-version=current`
|
||||
- Wrapper is validated in CI via `gradle/actions/wrapper-validation@v4`
|
||||
|
||||
4. **Clean build issues:**
|
||||
- If build fails, try: `./gradlew clean && scripts/ndk-make.sh && ./gradlew assembleDebug`
|
||||
- Remove `build/` directory if clean doesn't work
|
||||
|
||||
## Testing
|
||||
|
||||
### Running Unit Tests
|
||||
@@ -62,16 +109,19 @@ ArcaneChat is a Delta Chat Android client built on top of the official Delta Cha
|
||||
```bash
|
||||
./gradlew test
|
||||
```
|
||||
Expected duration: 1-3 minutes
|
||||
|
||||
### Running Instrumented Tests
|
||||
|
||||
1. **Disable animations** on your device/emulator:
|
||||
- Developer Options → Set "Window animation scale", "Transition animation scale", and "Animator duration scale" to 0x
|
||||
- **CRITICAL:** Tests will fail if animations are enabled
|
||||
|
||||
2. **Run tests:**
|
||||
```bash
|
||||
./gradlew connectedAndroidTest
|
||||
```
|
||||
Expected duration: 10-30 minutes depending on device/emulator
|
||||
|
||||
### Online Tests
|
||||
|
||||
@@ -129,6 +179,14 @@ TEST_MAIL_PW=yourpassword
|
||||
- Java bindings are in `src/main/java/com/b44t/messenger/Dc*.java`
|
||||
- JSON-RPC bindings in `chat.delta.rpc.*` package (generated via dcrpcgen)
|
||||
|
||||
### Generating JSON-RPC Bindings
|
||||
|
||||
To regenerate JSON-RPC bindings after core changes:
|
||||
```bash
|
||||
./scripts/generate-rpc-bindings.sh
|
||||
```
|
||||
**Note:** Requires Rust tooling and [dcrpcgen tool](https://github.com/chatmail/dcrpcgen) installed
|
||||
|
||||
### Working with Translations
|
||||
|
||||
- Translations managed via Transifex (not in repository)
|
||||
@@ -142,6 +200,43 @@ Decode crash symbols:
|
||||
$ANDROID_NDK_ROOT/ndk-stack --sym obj/local/armeabi-v7a --dump crash.txt > decoded.txt
|
||||
```
|
||||
|
||||
## Validation and Quality Checks
|
||||
|
||||
### Pre-commit Checks
|
||||
|
||||
Before committing changes, always run:
|
||||
|
||||
1. **Gradle wrapper validation:**
|
||||
```bash
|
||||
./gradlew wrapper --gradle-version=current
|
||||
```
|
||||
|
||||
2. **Build verification:**
|
||||
```bash
|
||||
./gradlew assembleDebug
|
||||
```
|
||||
|
||||
3. **Unit tests:**
|
||||
```bash
|
||||
./gradlew test
|
||||
```
|
||||
|
||||
4. **Code style:** Match existing code style in modified files (no automatic formatter configured)
|
||||
|
||||
### When to Rebuild Native Libraries
|
||||
|
||||
Rebuild native libraries (`scripts/ndk-make.sh`) when:
|
||||
- Updating deltachat-core-rust submodule
|
||||
- Modifying anything in `jni/` directory
|
||||
- Changing NDK version
|
||||
- After `git clean -fdx` or fresh clone
|
||||
|
||||
**DO NOT** rebuild native libraries for:
|
||||
- Pure Java/Kotlin code changes
|
||||
- Resource file changes
|
||||
- Gradle configuration changes (unless changing native library linking)
|
||||
- Documentation updates
|
||||
|
||||
## WebXDC Support
|
||||
|
||||
ArcaneChat has extended WebXDC support:
|
||||
@@ -152,12 +247,24 @@ ArcaneChat has extended WebXDC support:
|
||||
|
||||
## Important Files
|
||||
|
||||
- `build.gradle` - Main build configuration
|
||||
- `build.gradle` - Main build configuration (Android Gradle Plugin 8.11.1, Java 8 compatibility)
|
||||
- `CONTRIBUTING.md` - Contribution guidelines
|
||||
- `BUILDING.md` - Detailed build setup
|
||||
- `BUILDING.md` - Detailed build setup instructions
|
||||
- `RELEASE.md` - Release process
|
||||
- `proguard-rules.pro` - ProGuard configuration
|
||||
- `google-services.json` - Firebase configuration (gplay flavor)
|
||||
- `proguard-rules.pro` - ProGuard configuration (enabled for both debug and release)
|
||||
- `google-services.json` - Firebase configuration (gplay flavor only)
|
||||
- `settings.gradle` - Gradle settings
|
||||
- `.github/workflows/` - CI/CD configuration
|
||||
|
||||
## Dependencies and Constraints
|
||||
|
||||
- **Java Version:** Java 8 compatibility (do not use Java 9+ features)
|
||||
- **Gradle:** Use wrapper (`./gradlew`) to ensure correct Gradle version
|
||||
- **NDK:** Must use version 27.0.12077973 (specified in build.gradle)
|
||||
- **Min SDK:** 21 (Android 5.0) - code must be compatible
|
||||
- **Target SDK:** 36 (Android 16) - test on this API level when possible
|
||||
- **ProGuard:** Always enabled - ensure ProGuard rules are correct for new dependencies
|
||||
- **Multi-dex:** Enabled - app exceeds 65k method limit
|
||||
|
||||
## Package Structure
|
||||
|
||||
@@ -173,3 +280,35 @@ ArcaneChat has extended WebXDC support:
|
||||
- Native library must be rebuilt after core changes
|
||||
- ProGuard is enabled in both debug and release builds
|
||||
- Multi-dex is enabled due to app size
|
||||
|
||||
## CI/CD Workflows
|
||||
|
||||
### Preview APK Workflow (.github/workflows/preview-apk.yml)
|
||||
|
||||
Runs on every pull request to build and upload a preview APK:
|
||||
|
||||
1. **Setup steps:**
|
||||
- Checks out repository with submodules
|
||||
- Validates Fastlane metadata
|
||||
- Sets up Rust cache (working-directory: jni/deltachat-core-rust)
|
||||
- Sets up Java 17 (Temurin distribution)
|
||||
- Sets up Android SDK
|
||||
- Caches Gradle dependencies
|
||||
- Sets up NDK r27
|
||||
|
||||
2. **Build process:**
|
||||
```bash
|
||||
scripts/install-toolchains.sh && scripts/ndk-make.sh armeabi-v7a
|
||||
./gradlew --no-daemon -PABI_FILTER=armeabi-v7a assembleFossDebug
|
||||
```
|
||||
Note: Builds only armeabi-v7a for faster CI builds
|
||||
|
||||
3. **Output:** Uploads APK artifact to GitHub Actions
|
||||
|
||||
### Important CI Considerations
|
||||
|
||||
- Always validate Gradle wrapper before committing changes
|
||||
- Fastlane metadata must be valid (validated in CI)
|
||||
- Use `--no-daemon` flag for Gradle in CI environments
|
||||
- CI builds use FOSS flavor to avoid Google Services dependencies
|
||||
- Expected CI build time: 15-25 minutes for full workflow
|
||||
|
||||
@@ -210,6 +210,9 @@ dependencies {
|
||||
implementation "io.noties.markwon:ext-strikethrough:$markwon_version"
|
||||
implementation "io.noties.markwon:inline-parser:$markwon_version"
|
||||
implementation 'com.airbnb.android:lottie:4.2.2' // Lottie animations support.
|
||||
implementation ('com.vdurmont:emoji-java:5.1.1') { // emoji dataset for auto-completion
|
||||
exclude group: 'org.json', module: 'json'
|
||||
}
|
||||
|
||||
def media3_version = "1.8.0" // 1.9.0 need minSdkVersion 23
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ import org.thoughtcrime.securesms.components.ScaleStableImageView;
|
||||
import org.thoughtcrime.securesms.components.SendButton;
|
||||
import org.thoughtcrime.securesms.components.audioplay.AudioPlaybackViewModel;
|
||||
import org.thoughtcrime.securesms.components.audioplay.AudioView;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiSearch;
|
||||
import org.thoughtcrime.securesms.components.emoji.MediaKeyboard;
|
||||
import org.thoughtcrime.securesms.connect.AccountManager;
|
||||
import org.thoughtcrime.securesms.connect.DcEventCenter;
|
||||
@@ -976,6 +977,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
container.addOnKeyboardShownListener(backgroundView);
|
||||
inputPanel.setListener(this);
|
||||
inputPanel.setMediaListener(this);
|
||||
inputPanel.setEmojiSuggestionListener(emoji -> insertEmojiSuggestion(emoji));
|
||||
|
||||
attachmentTypeSelector = null;
|
||||
attachmentManager = new AttachmentManager(this, this);
|
||||
@@ -1593,13 +1595,84 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
if (composeText.getTextTrimmed().length() == 0 || beforeLength == 0) {
|
||||
composeText.postDelayed(ConversationActivity.this::updateToggleButtonState, 50);
|
||||
}
|
||||
updateEmojiSuggestions(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before,int count) {}
|
||||
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {}
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (!hasFocus) inputPanel.hideEmojiSuggestions();
|
||||
}
|
||||
}
|
||||
|
||||
private String lastEmojiQuery = null;
|
||||
|
||||
private void updateEmojiSuggestions(CharSequence text) {
|
||||
String query = getEmojiQuery(text, composeText.getSelectionEnd());
|
||||
if (query == null) {
|
||||
lastEmojiQuery = null;
|
||||
inputPanel.hideEmojiSuggestions();
|
||||
return;
|
||||
}
|
||||
if (query.equals(lastEmojiQuery)) return;
|
||||
lastEmojiQuery = query;
|
||||
Util.runOnBackground(() -> {
|
||||
List<String> results = EmojiSearch.search(query);
|
||||
Util.runOnMain(() -> {
|
||||
if (!query.equals(lastEmojiQuery)) return; // stale result
|
||||
if (results.isEmpty()) {
|
||||
inputPanel.hideEmojiSuggestions();
|
||||
} else {
|
||||
inputPanel.showEmojiSuggestions(results);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the emoji search query if the cursor is positioned after a `:word` pattern,
|
||||
* or null if there is no active emoji query.
|
||||
*/
|
||||
private String getEmojiQuery(CharSequence text, int cursorPos) {
|
||||
if (text == null || cursorPos <= 0) return null;
|
||||
int colonPos = -1;
|
||||
for (int i = cursorPos - 1; i >= 0; i--) {
|
||||
char c = text.charAt(i);
|
||||
if (c == ':') {
|
||||
colonPos = i;
|
||||
break;
|
||||
}
|
||||
if (!Character.isLetterOrDigit(c) && c != '_') break;
|
||||
}
|
||||
if (colonPos < 0) return null;
|
||||
String query = text.subSequence(colonPos + 1, cursorPos).toString();
|
||||
if (query.length() < 2) return null;
|
||||
return query;
|
||||
}
|
||||
|
||||
private void insertEmojiSuggestion(String emoji) {
|
||||
android.text.Editable editable = composeText.getText();
|
||||
if (editable == null) return;
|
||||
int cursorPos = composeText.getSelectionEnd();
|
||||
if (cursorPos < 0) return;
|
||||
// Find colon before the query at the cursor position
|
||||
int colonPos = -1;
|
||||
for (int i = cursorPos - 1; i >= 0; i--) {
|
||||
char c = editable.charAt(i);
|
||||
if (c == ':') {
|
||||
colonPos = i;
|
||||
break;
|
||||
}
|
||||
if (!Character.isLetterOrDigit(c) && c != '_') break;
|
||||
}
|
||||
if (colonPos < 0) return;
|
||||
String query = editable.subSequence(colonPos + 1, cursorPos).toString();
|
||||
if (query.length() < 2) return;
|
||||
editable.replace(colonPos, cursorPos, emoji + " ");
|
||||
lastEmojiQuery = null;
|
||||
inputPanel.hideEmojiSuggestions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,11 +21,14 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.b44t.messenger.DcMsg;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.animation.AnimationCompleteListener;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiSuggestionAdapter;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
|
||||
import org.thoughtcrime.securesms.components.emoji.MediaKeyboard;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
@@ -37,6 +40,7 @@ import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener;
|
||||
import org.thoughtcrime.securesms.util.guava.Optional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@@ -62,6 +66,8 @@ public class InputPanel extends ConstraintLayout
|
||||
private View buttonToggle;
|
||||
private View recordingContainer;
|
||||
private View recordLockCancel;
|
||||
private RecyclerView emojiSuggestions;
|
||||
private EmojiSuggestionAdapter emojiSuggestionAdapter;
|
||||
|
||||
private MicrophoneRecorderView microphoneRecorderView;
|
||||
private SlideToCancel slideToCancel;
|
||||
@@ -103,6 +109,11 @@ public class InputPanel extends ConstraintLayout
|
||||
this.microphoneRecorderView = findViewById(R.id.recorder_view);
|
||||
this.microphoneRecorderView.setListener(this);
|
||||
|
||||
this.emojiSuggestions = findViewById(R.id.emoji_suggestions);
|
||||
this.emojiSuggestionAdapter = new EmojiSuggestionAdapter();
|
||||
this.emojiSuggestions.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||
this.emojiSuggestions.setAdapter(emojiSuggestionAdapter);
|
||||
|
||||
this.recordLockCancel.setOnClickListener(v -> microphoneRecorderView.cancelAction());
|
||||
|
||||
quoteDismiss.setOnClickListener(v -> clearQuote());
|
||||
@@ -229,6 +240,20 @@ public class InputPanel extends ConstraintLayout
|
||||
mediaKeyboard.setKeyboardListener(this);
|
||||
}
|
||||
|
||||
public void setEmojiSuggestionListener(@NonNull EmojiSuggestionAdapter.OnEmojiClickListener listener) {
|
||||
emojiSuggestionAdapter.setOnEmojiClickListener(listener);
|
||||
}
|
||||
|
||||
public void showEmojiSuggestions(@NonNull List<String> emojis) {
|
||||
emojiSuggestionAdapter.setEmojis(emojis);
|
||||
emojiSuggestions.setVisibility(View.VISIBLE);
|
||||
emojiSuggestions.scrollToPosition(0);
|
||||
}
|
||||
|
||||
public void hideEmojiSuggestions() {
|
||||
emojiSuggestions.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordPermissionRequired() {
|
||||
if (listener != null) listener.onRecorderPermissionRequired();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.thoughtcrime.securesms.components.emoji;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.vdurmont.emoji.Emoji;
|
||||
import com.vdurmont.emoji.EmojiManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides emoji search functionality using the emoji-java library.
|
||||
* Used for emoji auto-completion when user types :query in the compose field.
|
||||
*/
|
||||
public final class EmojiSearch {
|
||||
|
||||
private static final int MAX_RESULTS = 20;
|
||||
|
||||
private EmojiSearch() {}
|
||||
|
||||
/**
|
||||
* Search for emojis whose aliases or tags contain the given query (case-insensitive).
|
||||
* Returns up to MAX_RESULTS emoji Unicode strings.
|
||||
*/
|
||||
@NonNull
|
||||
public static List<String> search(@NonNull String query) {
|
||||
if (query.isEmpty()) return Collections.emptyList();
|
||||
String lowerQuery = query.toLowerCase();
|
||||
List<String> results = new ArrayList<>();
|
||||
for (Emoji emoji : EmojiManager.getAll()) {
|
||||
if (matchesQuery(emoji, lowerQuery)) {
|
||||
results.add(emoji.getUnicode());
|
||||
if (results.size() >= MAX_RESULTS) break;
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static boolean matchesQuery(@NonNull Emoji emoji, @NonNull String lowerQuery) {
|
||||
for (String alias : emoji.getAliases()) {
|
||||
if (alias.toLowerCase().contains(lowerQuery)) return true;
|
||||
}
|
||||
for (String tag : emoji.getTags()) {
|
||||
if (tag.toLowerCase().contains(lowerQuery)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.thoughtcrime.securesms.components.emoji;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RecyclerView adapter for showing emoji auto-completion suggestions.
|
||||
*/
|
||||
public class EmojiSuggestionAdapter extends RecyclerView.Adapter<EmojiSuggestionAdapter.EmojiViewHolder> {
|
||||
|
||||
public interface OnEmojiClickListener {
|
||||
void onEmojiClicked(@NonNull String emoji);
|
||||
}
|
||||
|
||||
private final List<String> emojis = new ArrayList<>();
|
||||
private OnEmojiClickListener listener;
|
||||
|
||||
public void setOnEmojiClickListener(OnEmojiClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setEmojis(@NonNull List<String> newEmojis) {
|
||||
int oldSize = emojis.size();
|
||||
emojis.clear();
|
||||
emojis.addAll(newEmojis);
|
||||
int newSize = emojis.size();
|
||||
if (oldSize > 0) notifyItemRangeRemoved(0, oldSize);
|
||||
if (newSize > 0) notifyItemRangeInserted(0, newSize);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public EmojiViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.emoji_suggestion_item, parent, false);
|
||||
return new EmojiViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull EmojiViewHolder holder, int position) {
|
||||
String emoji = emojis.get(position);
|
||||
holder.emojiView.setText(emoji);
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (listener != null) listener.onEmojiClicked(emoji);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return emojis.size();
|
||||
}
|
||||
|
||||
static class EmojiViewHolder extends RecyclerView.ViewHolder {
|
||||
final TextView emojiView;
|
||||
|
||||
EmojiViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
emojiView = itemView.findViewById(R.id.emoji_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,11 +42,24 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/quote_view"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/emoji_suggestions"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:background="?attr/input_panel_bg_color"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/subject_text" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/input_field_frame_layout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/button_toggle"
|
||||
app:layout_constraintTop_toBottomOf="@id/subject_text"
|
||||
app:layout_constraintTop_toBottomOf="@id/emoji_suggestions"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/emoji_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:minWidth="44dp"
|
||||
android:textSize="26sp"
|
||||
android:textColor="?attr/emoji_text_color"
|
||||
android:background="@drawable/touch_highlight_background" />
|
||||
Reference in New Issue
Block a user