From 86d9264ee59fcc4f8e342be392c4e23df3f8e250 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 21 Mar 2023 11:03:50 +0100 Subject: [PATCH] create stub chat fragment --- .../conversations/android/ui/Activities.java | 7 +- .../android/ui/activity/MainActivity.java | 2 - .../ui/adapter/ChatOverviewAdapter.java | 13 +++ .../ui/fragment/main/ChatFragment.java | 40 +++++++ .../ui/fragment/main/OverviewFragment.java | 22 ++++ .../res/color/hint_on_tertiary_container.xml | 3 + .../drawable/ic_add_circle_outline_24dp.xml | 10 ++ .../main/res/drawable/ic_lock_open_24dp.xml | 10 ++ .../res/drawable/ic_phone_in_talk_24dp.xml | 10 ++ app/src/main/res/drawable/ic_send_24dp.xml | 11 ++ .../main/res/drawable/ic_video_call_24dp.xml | 10 ++ app/src/main/res/layout/fragment_chat.xml | 106 ++++++++++++++++++ app/src/main/res/layout/item_chatoverview.xml | 2 + app/src/main/res/menu/fragment_chat.xml | 62 ++++++++++ .../main/res/navigation/main_navigation.xml | 12 +- app/src/main/res/values-night/themes.xml | 1 + app/src/main/res/values/attributes.xml | 5 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 12 ++ app/src/main/res/values/themes.xml | 1 + 20 files changed, 333 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/im/conversations/android/ui/fragment/main/ChatFragment.java create mode 100644 app/src/main/res/color/hint_on_tertiary_container.xml create mode 100644 app/src/main/res/drawable/ic_add_circle_outline_24dp.xml create mode 100644 app/src/main/res/drawable/ic_lock_open_24dp.xml create mode 100644 app/src/main/res/drawable/ic_phone_in_talk_24dp.xml create mode 100644 app/src/main/res/drawable/ic_send_24dp.xml create mode 100644 app/src/main/res/drawable/ic_video_call_24dp.xml create mode 100644 app/src/main/res/layout/fragment_chat.xml create mode 100644 app/src/main/res/menu/fragment_chat.xml create mode 100644 app/src/main/res/values/attributes.xml create mode 100644 app/src/main/res/values/styles.xml diff --git a/app/src/main/java/im/conversations/android/ui/Activities.java b/app/src/main/java/im/conversations/android/ui/Activities.java index fdfb5e732..e4af398b2 100644 --- a/app/src/main/java/im/conversations/android/ui/Activities.java +++ b/app/src/main/java/im/conversations/android/ui/Activities.java @@ -1,23 +1,22 @@ package im.conversations.android.ui; +import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; import android.view.View; -import androidx.appcompat.app.AppCompatActivity; import com.google.android.material.elevation.SurfaceColors; public final class Activities { private Activities() {} - public static void setStatusAndNavigationBarColors( - final AppCompatActivity activity, final View view) { + public static void setStatusAndNavigationBarColors(final Activity activity, final View view) { setStatusAndNavigationBarColors(activity, view, false); } public static void setStatusAndNavigationBarColors( - final AppCompatActivity activity, final View view, final boolean raisedStatusBar) { + final Activity activity, final View view, final boolean raisedStatusBar) { final var isLightMode = isLightMode(activity); final var window = activity.getWindow(); final var flags = view.getSystemUiVisibility(); diff --git a/app/src/main/java/im/conversations/android/ui/activity/MainActivity.java b/app/src/main/java/im/conversations/android/ui/activity/MainActivity.java index 28a080b80..0de41ca7f 100644 --- a/app/src/main/java/im/conversations/android/ui/activity/MainActivity.java +++ b/app/src/main/java/im/conversations/android/ui/activity/MainActivity.java @@ -7,7 +7,6 @@ import androidx.lifecycle.ViewModelProvider; import im.conversations.android.R; import im.conversations.android.databinding.ActivityMainBinding; import im.conversations.android.service.ForegroundService; -import im.conversations.android.ui.Activities; import im.conversations.android.ui.model.MainViewModel; public class MainActivity extends BaseActivity { @@ -30,7 +29,6 @@ public class MainActivity extends BaseActivity { finish(); } }); - Activities.setStatusAndNavigationBarColors(this, binding.getRoot()); } @Override diff --git a/app/src/main/java/im/conversations/android/ui/adapter/ChatOverviewAdapter.java b/app/src/main/java/im/conversations/android/ui/adapter/ChatOverviewAdapter.java index 115460fdd..c9b7f7535 100644 --- a/app/src/main/java/im/conversations/android/ui/adapter/ChatOverviewAdapter.java +++ b/app/src/main/java/im/conversations/android/ui/adapter/ChatOverviewAdapter.java @@ -12,6 +12,7 @@ import im.conversations.android.R; import im.conversations.android.database.model.ChatOverviewItem; import im.conversations.android.databinding.ItemChatoverviewBinding; import im.conversations.android.ui.AvatarFetcher; +import java.util.function.Consumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,6 +21,8 @@ public class ChatOverviewAdapter private static final Logger LOGGER = LoggerFactory.getLogger(ChatOverviewAdapter.class); + private Consumer onChatSelected; + public ChatOverviewAdapter(@NonNull DiffUtil.ItemCallback diffCallback) { super(diffCallback); } @@ -42,6 +45,12 @@ public class ChatOverviewAdapter final var addressWithName = chatOverviewItem == null ? null : chatOverviewItem.getAddressWithName(); final var avatar = chatOverviewItem == null ? null : chatOverviewItem.getAvatar(); + holder.binding.chat.setOnClickListener( + (v) -> { + if (onChatSelected != null && chatOverviewItem != null) { + onChatSelected.accept(chatOverviewItem.id); + } + }); if (avatar != null) { holder.binding.avatar.setVisibility(View.VISIBLE); AvatarFetcher.fetchInto(holder.binding.avatar, avatar); @@ -53,6 +62,10 @@ public class ChatOverviewAdapter } } + public void setOnChatSelectedListener(final Consumer onChatSelected) { + this.onChatSelected = onChatSelected; + } + public static class ChatOverviewViewHolder extends RecyclerView.ViewHolder { private final ItemChatoverviewBinding binding; diff --git a/app/src/main/java/im/conversations/android/ui/fragment/main/ChatFragment.java b/app/src/main/java/im/conversations/android/ui/fragment/main/ChatFragment.java new file mode 100644 index 000000000..0563cea57 --- /dev/null +++ b/app/src/main/java/im/conversations/android/ui/fragment/main/ChatFragment.java @@ -0,0 +1,40 @@ +package im.conversations.android.ui.fragment.main; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import im.conversations.android.R; +import im.conversations.android.databinding.FragmentChatBinding; +import im.conversations.android.ui.Activities; +import im.conversations.android.ui.NavControllers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChatFragment extends Fragment { + + private static final Logger LOGGER = LoggerFactory.getLogger(ChatFragment.class); + + private FragmentChatBinding binding; + + @Override + public View onCreateView( + @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + this.binding = DataBindingUtil.inflate(inflater, R.layout.fragment_chat, container, false); + this.binding.materialToolbar.setNavigationOnClickListener( + view -> { + NavControllers.findNavController(requireActivity(), R.id.nav_host_fragment) + .popBackStack(); + }); + this.binding.messageLayout.setEndIconOnClickListener( + v -> { + LOGGER.info("On send pressed"); + }); + Activities.setStatusAndNavigationBarColors(requireActivity(), binding.getRoot(), true); + return this.binding.getRoot(); + } +} diff --git a/app/src/main/java/im/conversations/android/ui/fragment/main/OverviewFragment.java b/app/src/main/java/im/conversations/android/ui/fragment/main/OverviewFragment.java index 51dba6cbd..9208bde4b 100644 --- a/app/src/main/java/im/conversations/android/ui/fragment/main/OverviewFragment.java +++ b/app/src/main/java/im/conversations/android/ui/fragment/main/OverviewFragment.java @@ -23,7 +23,9 @@ import im.conversations.android.database.model.AccountIdentifier; import im.conversations.android.database.model.ChatFilter; import im.conversations.android.database.model.GroupIdentifier; import im.conversations.android.databinding.FragmentOverviewBinding; +import im.conversations.android.ui.Activities; import im.conversations.android.ui.Intents; +import im.conversations.android.ui.NavControllers; import im.conversations.android.ui.activity.SettingsActivity; import im.conversations.android.ui.activity.SetupActivity; import im.conversations.android.ui.adapter.ChatOverviewAdapter; @@ -112,9 +114,17 @@ public class OverviewFragment extends Fragment { requireActivity() .getOnBackPressedDispatcher() .addCallback(getViewLifecycleOwner(), this.searchViewOnBackPressedCallback); + this.chatOverviewAdapter.setOnChatSelectedListener(this::onChatSelected); + Activities.setStatusAndNavigationBarColors(requireActivity(), binding.getRoot()); return binding.getRoot(); } + private void onChatSelected(long chatId) { + final var navController = + NavControllers.findNavController(requireActivity(), R.id.nav_host_fragment); + navController.navigate(OverviewFragmentDirections.overviewToChat(chatId)); + } + @Override public void onResume() { super.onResume(); @@ -238,4 +248,16 @@ public class OverviewFragment extends Fragment { } } } + + @Override + public void onDestroyView() { + nullReferences(); + super.onDestroyView(); + } + + private void nullReferences() { + this.binding.chats.setAdapter(null); + this.chatOverviewAdapter = null; + this.binding = null; + } } diff --git a/app/src/main/res/color/hint_on_tertiary_container.xml b/app/src/main/res/color/hint_on_tertiary_container.xml new file mode 100644 index 000000000..a117b9806 --- /dev/null +++ b/app/src/main/res/color/hint_on_tertiary_container.xml @@ -0,0 +1,3 @@ + + + diff --git a/app/src/main/res/drawable/ic_add_circle_outline_24dp.xml b/app/src/main/res/drawable/ic_add_circle_outline_24dp.xml new file mode 100644 index 000000000..9e9531070 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_circle_outline_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_lock_open_24dp.xml b/app/src/main/res/drawable/ic_lock_open_24dp.xml new file mode 100644 index 000000000..3d34c2a86 --- /dev/null +++ b/app/src/main/res/drawable/ic_lock_open_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_phone_in_talk_24dp.xml b/app/src/main/res/drawable/ic_phone_in_talk_24dp.xml new file mode 100644 index 000000000..acc4716e9 --- /dev/null +++ b/app/src/main/res/drawable/ic_phone_in_talk_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_send_24dp.xml b/app/src/main/res/drawable/ic_send_24dp.xml new file mode 100644 index 000000000..3bf17adcd --- /dev/null +++ b/app/src/main/res/drawable/ic_send_24dp.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_video_call_24dp.xml b/app/src/main/res/drawable/ic_video_call_24dp.xml new file mode 100644 index 000000000..ff796827e --- /dev/null +++ b/app/src/main/res/drawable/ic_video_call_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_chat.xml b/app/src/main/res/layout/fragment_chat.xml new file mode 100644 index 000000000..dedcd870d --- /dev/null +++ b/app/src/main/res/layout/fragment_chat.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + +