From fa37a46995d1a1042e96ce925ebe1b672ba6eb0c Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Thu, 21 Feb 2019 02:23:00 +0530 Subject: [PATCH 1/7] Use different viewType according to Event Trigger type in EventTriggerAdapter Signed-off-by: Arka Prava Basu --- .../havenapp/main/ui/EventTriggerAdapter.java | 179 ++++-------------- .../havenapp/main/ui/viewholder/AudioVH.kt | 61 ++++++ .../main/ui/viewholder/EventTriggerVH.kt | 25 +++ .../havenapp/main/ui/viewholder/ImageVH.kt | 56 ++++++ .../havenapp/main/ui/viewholder/VideoVH.kt | 51 +++++ src/main/res/layout/item_audio.xml | 55 ++++++ src/main/res/layout/item_event.xml | 35 ---- src/main/res/layout/item_event_trigger.xml | 38 ++++ src/main/res/layout/item_photo.xml | 45 +++++ src/main/res/layout/item_video.xml | 45 +++++ 10 files changed, 415 insertions(+), 175 deletions(-) create mode 100644 src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt create mode 100644 src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt create mode 100644 src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt create mode 100644 src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt create mode 100644 src/main/res/layout/item_audio.xml create mode 100644 src/main/res/layout/item_event_trigger.xml create mode 100644 src/main/res/layout/item_photo.xml create mode 100644 src/main/res/layout/item_video.xml diff --git a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java index 40b113c8..db3bd40d 100644 --- a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java +++ b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java @@ -1,25 +1,17 @@ package org.havenapp.main.ui; import android.content.Context; -import android.graphics.drawable.BitmapDrawable; -import android.media.ThumbnailUtils; -import android.net.Uri; -import android.provider.MediaStore; -import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.VideoView; - -import com.github.derlio.waveform.SimpleWaveformView; -import com.github.derlio.waveform.soundfile.SoundFile; import org.havenapp.main.R; import org.havenapp.main.model.EventTrigger; import org.havenapp.main.resources.IResourceManager; +import org.havenapp.main.ui.viewholder.AudioVH; +import org.havenapp.main.ui.viewholder.EventTriggerVH; +import org.havenapp.main.ui.viewholder.ImageVH; +import org.havenapp.main.ui.viewholder.VideoVH; -import java.io.File; import java.util.List; import androidx.annotation.NonNull; @@ -30,7 +22,7 @@ * Created by n8fr8 on 4/16/17. */ -public class EventTriggerAdapter extends RecyclerView.Adapter { +public class EventTriggerAdapter extends RecyclerView.Adapter { private Context context; private IResourceManager resourceManager; @@ -38,8 +30,6 @@ public class EventTriggerAdapter extends RecyclerView.Adapter eventTriggers, IResourceManager resourceManager, EventTriggerClickListener eventTriggerClickListener) { this.context = context; @@ -55,129 +45,59 @@ void setEventTriggers(@NonNull List eventTriggers) { @NonNull @Override - public EventTriggerVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_event, parent, false); - - return new EventTriggerVH(view); + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + + switch (viewType) { + case EventTrigger.CAMERA_VIDEO: + return new VideoVH(eventTriggerClickListener, context, resourceManager, parent); + case EventTrigger.CAMERA: + return new ImageVH(resourceManager, eventTriggerClickListener, parent); + case EventTrigger.MICROPHONE: + return new AudioVH(resourceManager, parent); + case EventTrigger.ACCELEROMETER: + case EventTrigger.LIGHT: + case EventTrigger.PRESSURE: + case EventTrigger.POWER: + return new EventTriggerVH(resourceManager, parent); + } + return new RecyclerView.ViewHolder(new View(context)) {}; } @Override - public void onBindViewHolder(@NonNull EventTriggerVH holder, int position) { + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { final EventTrigger eventTrigger = eventTriggers.get(position); - String title = eventTrigger.getStringType(resourceManager); - String desc = eventTrigger.getTime().toLocaleString(); - - holder.image.setVisibility(View.GONE); - holder.video.setVisibility(View.GONE); - holder.extra.setVisibility(View.GONE); - holder.sound.setVisibility(View.GONE); - - - if (eventTrigger.getPath() != null) + if (eventTrigger.getPath() != null && eventTrigger.getType() != null) { switch (eventTrigger.getType()) { case EventTrigger.CAMERA_VIDEO: - holder.video.setVisibility(View.VISIBLE); - BitmapDrawable bitmapD = new BitmapDrawable(context.getResources(), - ThumbnailUtils.createVideoThumbnail(eventTrigger.getPath(), - MediaStore.Video.Thumbnails.FULL_SCREEN_KIND)); - holder.video.setBackground(bitmapD); - holder.video.setOnClickListener(view -> { - if (eventTriggerClickListener != null) { - eventTriggerClickListener.onVideoClick(eventTrigger); - } - }); - - holder.video.setOnLongClickListener(view -> { - if (eventTriggerClickListener != null) { - eventTriggerClickListener.onVideoLongClick(eventTrigger); - } - return false; - }); + ((VideoVH) holder).bind(eventTrigger); break; case EventTrigger.CAMERA: - holder.image.setVisibility(View.VISIBLE); - - /** - Uri fileUri = FileProvider.getUriForFile( - context, - AUTHORITY, - new File(eventTrigger.getPath())); - holder.image.setImageURI(fileUri); - **/ - - Uri fileUri = Uri.parse("file://" + eventTrigger.getPath()); - holder.image.setImageURI(fileUri); - - - holder.image.setOnClickListener(view -> { - if (eventTriggerClickListener != null) - eventTriggerClickListener.onImageClick(eventTrigger); - }); - - holder.image.setOnLongClickListener(view -> { - if (eventTriggerClickListener != null) - eventTriggerClickListener.onImageLongClick(eventTrigger); - return false; - }); + ((ImageVH) holder).bind(eventTrigger); break; case EventTrigger.MICROPHONE: - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - holder.sound.setVisibility(View.VISIBLE); - final File fileSound = new File(eventTrigger.getPath()); - try { - final SoundFile soundFile = SoundFile.create(fileSound.getPath(), new SoundFile.ProgressListener() { - int lastProgress = 0; - - @Override - public boolean reportProgress(double fractionComplete) { - final int progress = (int) (fractionComplete * 100); - if (lastProgress == progress) { - return true; - } - lastProgress = progress; - - return true; - } - }); - holder.sound.setAudioFile(soundFile); - holder.sound.invalidate(); - } catch (Exception e) { - } - - holder.extra.setVisibility(View.VISIBLE); - holder.extra.removeAllViews(); - - AudioWife audioWife = new AudioWife(); - audioWife.init(context, Uri.fromFile(fileSound)) - .useDefaultUi(holder.extra, inflater); - + ((AudioVH) holder).bind(eventTrigger, context); break; case EventTrigger.ACCELEROMETER: - desc += "\n" + resourceManager.getString(R.string.data_speed) + ": " + eventTrigger.getPath(); - + ((EventTriggerVH) holder) + .bind(eventTrigger, resourceManager.getString(R.string.data_speed)); break; case EventTrigger.LIGHT: - desc += "\n" + resourceManager.getString(R.string.data_light) + ": " + eventTrigger.getPath(); - + ((EventTriggerVH) holder) + .bind(eventTrigger, resourceManager.getString(R.string.data_light)); break; case EventTrigger.PRESSURE: - desc += "\n" + resourceManager.getString(R.string.data_pressure) + ": " + eventTrigger.getPath(); + ((EventTriggerVH) holder) + .bind(eventTrigger, resourceManager.getString(R.string.data_pressure)); break; case EventTrigger.POWER: - desc += "\n" + resourceManager.getString(R.string.data_power) + ": " + eventTrigger.getPath(); + ((EventTriggerVH) holder) + .bind(eventTrigger, resourceManager.getString(R.string.data_power)); break; } - } - - holder.title.setText(title); - holder.note.setText(desc); - - } @Override @@ -192,32 +112,11 @@ public int getItemCount() { return eventTriggers.size(); } - class EventTriggerVH extends RecyclerView.ViewHolder { - TextView title, note; - ImageView image; - VideoView video; - ViewGroup extra; - SimpleWaveformView sound; - EventTriggerVH(View itemView) { - super(itemView); - - title = itemView.findViewById(R.id.event_item_title); - note = itemView.findViewById(R.id.event_item_desc); - image = itemView.findViewById(R.id.event_item_image); - video = itemView.findViewById(R.id.event_item_video); - extra = itemView.findViewById(R.id.event_item_extra); - sound = itemView.findViewById(R.id.event_item_sound); - } - } - - public interface EventTriggerClickListener { - void onVideoClick(EventTrigger eventTrigger); - - void onVideoLongClick(EventTrigger eventTrigger); - - void onImageClick(EventTrigger eventTrigger); - - void onImageLongClick(EventTrigger eventTrigger); + @Override + public int getItemViewType(int position) { + return eventTriggers.get(position).getType(); } + public interface EventTriggerClickListener extends VideoVH.VideoClickListener, + ImageVH.ImageClickListener {} } diff --git a/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt new file mode 100644 index 00000000..6f4feab8 --- /dev/null +++ b/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt @@ -0,0 +1,61 @@ +package org.havenapp.main.ui.viewholder + +import android.content.Context +import android.net.Uri +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.github.derlio.waveform.SimpleWaveformView +import com.github.derlio.waveform.soundfile.SoundFile +import nl.changer.audiowife.AudioWife +import org.havenapp.main.R +import org.havenapp.main.model.EventTrigger +import org.havenapp.main.resources.IResourceManager +import java.io.File + +/** + * Created by Arka Prava Basu on 21/02/19 + **/ +class AudioVH(private val resourceManager: IResourceManager, viewGroup: ViewGroup) + : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) + .inflate(R.layout.item_audio, viewGroup, false)) { + + private val audioTitle = itemView.findViewById(R.id.item_audio_title) + private val audioDesc = itemView.findViewById(R.id.item_audio_desc) + private val waveFormView = itemView.findViewById(R.id.item_sound) + private val playerContainer = itemView.findViewById(R.id.item_player_container) + + fun bind(eventTrigger: EventTrigger, context: Context) { + audioTitle.text = eventTrigger.getStringType(resourceManager) + audioDesc.text = eventTrigger.time?.toLocaleString() ?: "" + + val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + + val fileSound = File(eventTrigger.path) + try { + val soundFile = SoundFile.create(fileSound.path, object : SoundFile.ProgressListener { + var lastProgress = 0 + + override fun reportProgress(fractionComplete: Double): Boolean { + val progress = (fractionComplete * 100).toInt() + if (lastProgress == progress) { + return true + } + lastProgress = progress + + return true + } + }) + waveFormView.setAudioFile(soundFile) + waveFormView.invalidate() + } catch (e: Exception) { + e.printStackTrace() + } + + playerContainer.removeAllViews() + + AudioWife().init(context, Uri.fromFile(fileSound)).useDefaultUi(playerContainer, inflater) + } +} diff --git a/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt new file mode 100644 index 00000000..9cbabf6e --- /dev/null +++ b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt @@ -0,0 +1,25 @@ +package org.havenapp.main.ui.viewholder + +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import org.havenapp.main.R +import org.havenapp.main.model.EventTrigger +import org.havenapp.main.resources.IResourceManager + +/** + * Created by Arka Prava Basu on 21/02/19 + **/ +class EventTriggerVH(private val resourceManager: IResourceManager, viewGroup: ViewGroup) + : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) + .inflate(R.layout.item_event_trigger, viewGroup, false)) { + + private val triggerTitle = itemView.findViewById(R.id.item_trigger_title) + private val triggerDesc = itemView.findViewById(R.id.item_trigger_desc) + + fun bind(eventTrigger: EventTrigger, string: String) { + triggerTitle.text = eventTrigger.getStringType(resourceManager) + triggerDesc.text = """${eventTrigger.time?.toLocaleString() ?: ""}\n$string: ${eventTrigger.path}""" + } +} diff --git a/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt new file mode 100644 index 00000000..34184b95 --- /dev/null +++ b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt @@ -0,0 +1,56 @@ +package org.havenapp.main.ui.viewholder + +import android.net.Uri +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.facebook.drawee.view.SimpleDraweeView +import org.havenapp.main.R +import org.havenapp.main.model.EventTrigger +import org.havenapp.main.resources.IResourceManager + +/** + * Created by Arka Prava Basu on 21/02/19 + **/ +class ImageVH(private val resourceManager: IResourceManager, + private val listener: ImageClickListener, viewGroup: ViewGroup) + : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) + .inflate(R.layout.item_photo, viewGroup, false)) { + + private val imageTitle = itemView.findViewById(R.id.item_camera_title) + private val imageDesc = itemView.findViewById(R.id.item_camera_desc) + private val imageView = itemView.findViewById(R.id.item_camera_image) + + fun bind(eventTrigger: EventTrigger) { + imageTitle.text = eventTrigger.getStringType(resourceManager) + imageDesc.text = eventTrigger.time?.toLocaleString() ?: "" + + /** + Uri fileUri = FileProvider.getUriForFile( + context, + AUTHORITY, + new File(eventTrigger.getPath())); + holder.image.setImageURI(fileUri); + **/ + + val fileUri = Uri.parse("file://" + eventTrigger.path!!) + imageView.setImageURI(fileUri) + + + imageView.setOnClickListener { + listener.onImageClick(eventTrigger) + } + + imageView.setOnLongClickListener { + listener.onImageLongClick(eventTrigger) + false + } + } + + interface ImageClickListener { + fun onImageClick(eventTrigger: EventTrigger) + + fun onImageLongClick(eventTrigger: EventTrigger) + } +} diff --git a/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt new file mode 100644 index 00000000..602ca14c --- /dev/null +++ b/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt @@ -0,0 +1,51 @@ +package org.havenapp.main.ui.viewholder + +import android.content.Context +import android.graphics.drawable.BitmapDrawable +import android.media.ThumbnailUtils +import android.provider.MediaStore +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.TextView +import android.widget.VideoView +import androidx.recyclerview.widget.RecyclerView +import org.havenapp.main.R +import org.havenapp.main.model.EventTrigger +import org.havenapp.main.resources.IResourceManager + +/** + * Created by Arka Prava Basu on 21/02/19 + **/ +class VideoVH(private val clickListener: VideoClickListener, private val context: Context, + private val resourceManager: IResourceManager, viewGroup: ViewGroup) + : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) + .inflate(R.layout.item_video, viewGroup, false)) { + + private val title = itemView.findViewById(R.id.item_video_title) + private val desc = itemView.findViewById(R.id.item_video_desc) + private val videoView = itemView.findViewById(R.id.item_video_view) + + fun bind(eventTrigger: EventTrigger) { + title.text = eventTrigger.getStringType(resourceManager) + desc.text = eventTrigger.time?.toLocaleString() ?: "" + + val bitmapD = BitmapDrawable(context.resources, + ThumbnailUtils.createVideoThumbnail(eventTrigger.path, + MediaStore.Video.Thumbnails.FULL_SCREEN_KIND)) + videoView.background = bitmapD + videoView.setOnClickListener { + clickListener.onVideoClick(eventTrigger) + } + + videoView.setOnLongClickListener { + clickListener.onVideoLongClick(eventTrigger) + false + } + } + + interface VideoClickListener { + fun onVideoClick(eventTrigger: EventTrigger) + + fun onVideoLongClick(eventTrigger: EventTrigger) + } +} diff --git a/src/main/res/layout/item_audio.xml b/src/main/res/layout/item_audio.xml new file mode 100644 index 00000000..fdd304da --- /dev/null +++ b/src/main/res/layout/item_audio.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + diff --git a/src/main/res/layout/item_event.xml b/src/main/res/layout/item_event.xml index a80574f3..d31a4e3d 100644 --- a/src/main/res/layout/item_event.xml +++ b/src/main/res/layout/item_event.xml @@ -22,41 +22,6 @@ android:layout_height="wrap_content" tools:text="Title" /> - - - - - - - - + + + + + + + + + + + diff --git a/src/main/res/layout/item_photo.xml b/src/main/res/layout/item_photo.xml new file mode 100644 index 00000000..0914fc3e --- /dev/null +++ b/src/main/res/layout/item_photo.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + diff --git a/src/main/res/layout/item_video.xml b/src/main/res/layout/item_video.xml new file mode 100644 index 00000000..de6e93cd --- /dev/null +++ b/src/main/res/layout/item_video.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + From 1b665f47a515e10dfc2013461f12900f748cf0c8 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Thu, 21 Feb 2019 02:30:12 +0530 Subject: [PATCH 2/7] Adding annotations to keep in sync with Kotlin code Signed-off-by: Arka Prava Basu --- src/main/java/org/havenapp/main/ui/EventActivity.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/havenapp/main/ui/EventActivity.java b/src/main/java/org/havenapp/main/ui/EventActivity.java index 99983fc6..3b5c114a 100644 --- a/src/main/java/org/havenapp/main/ui/EventActivity.java +++ b/src/main/java/org/havenapp/main/ui/EventActivity.java @@ -23,6 +23,7 @@ import org.havenapp.main.model.EventTrigger; import org.havenapp.main.resources.IResourceManager; import org.havenapp.main.resources.ResourceManager; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.text.SimpleDateFormat; @@ -228,19 +229,19 @@ private String generateLog () { } @Override - public void onVideoClick(EventTrigger eventTrigger) { + public void onVideoClick(@NotNull EventTrigger eventTrigger) { Intent intent = new Intent(this, VideoPlayerActivity.class); intent.setData(Uri.fromFile(new File(eventTrigger.getPath()))); startActivity(intent); } @Override - public void onVideoLongClick(EventTrigger eventTrigger) { + public void onVideoLongClick(@NotNull EventTrigger eventTrigger) { shareMedia(eventTrigger); } @Override - public void onImageClick(EventTrigger eventTrigger) { + public void onImageClick(@NotNull EventTrigger eventTrigger) { int startPosition = 0; ShareOverlayView overlayView = new ShareOverlayView(this); @@ -252,7 +253,7 @@ public void onImageClick(EventTrigger eventTrigger) { } @Override - public void onImageLongClick(EventTrigger eventTrigger) { + public void onImageLongClick(@NotNull EventTrigger eventTrigger) { shareMedia(eventTrigger); } From 79f0e1930f8b2f0009c0ca0d0e66780504562010 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Thu, 21 Feb 2019 02:45:41 +0530 Subject: [PATCH 3/7] Bug fix: Set start position while showing the image viewer Signed-off-by: Arka Prava Basu --- .../org/havenapp/main/ui/EventActivity.java | 19 +++++++++++++++---- .../havenapp/main/ui/EventTriggerAdapter.java | 2 +- .../havenapp/main/ui/viewholder/ImageVH.kt | 6 +++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/havenapp/main/ui/EventActivity.java b/src/main/java/org/havenapp/main/ui/EventActivity.java index 3b5c114a..8b0cd8e1 100644 --- a/src/main/java/org/havenapp/main/ui/EventActivity.java +++ b/src/main/java/org/havenapp/main/ui/EventActivity.java @@ -127,7 +127,7 @@ private void onEventFetched(@NonNull Event event) { */ private void onEventTriggerListFetched(@NonNull List eventTriggerList) { this.eventTriggerList = eventTriggerList; - setEventTriggerImagePaths(eventTriggerList); + setEventTriggerImagePaths(); mAdapter.setEventTriggers(eventTriggerList); } @@ -241,8 +241,8 @@ public void onVideoLongClick(@NotNull EventTrigger eventTrigger) { } @Override - public void onImageClick(@NotNull EventTrigger eventTrigger) { - int startPosition = 0; + public void onImageClick(@NotNull EventTrigger eventTrigger, int position) { + int startPosition = getPositionOfImagePath(position); ShareOverlayView overlayView = new ShareOverlayView(this); ImageViewer viewer = new ImageViewer.Builder<>(this, eventTriggerImagePaths) @@ -265,7 +265,7 @@ private void shareMedia (EventTrigger eventTrigger) { startActivity(shareIntent); } - private void setEventTriggerImagePaths(List eventTriggerList) { + private void setEventTriggerImagePaths() { this.eventTriggerImagePaths = new ArrayList<>(); for (EventTrigger trigger : eventTriggerList) { @@ -276,4 +276,15 @@ private void setEventTriggerImagePaths(List eventTriggerList) { } } } + + private int getPositionOfImagePath(int position) { + int pos = -1; + for (int i = 0; i <= position; i++) { + if (eventTriggerList.get(i).getType() == EventTrigger.CAMERA && + (!TextUtils.isEmpty(eventTriggerList.get(i).getPath()))) { + pos++; + } + } + return pos; + } } diff --git a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java index db3bd40d..cb58780c 100644 --- a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java +++ b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java @@ -75,7 +75,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi ((VideoVH) holder).bind(eventTrigger); break; case EventTrigger.CAMERA: - ((ImageVH) holder).bind(eventTrigger); + ((ImageVH) holder).bind(eventTrigger, position); break; case EventTrigger.MICROPHONE: ((AudioVH) holder).bind(eventTrigger, context); diff --git a/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt index 34184b95..d69b79f6 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt @@ -22,7 +22,7 @@ class ImageVH(private val resourceManager: IResourceManager, private val imageDesc = itemView.findViewById(R.id.item_camera_desc) private val imageView = itemView.findViewById(R.id.item_camera_image) - fun bind(eventTrigger: EventTrigger) { + fun bind(eventTrigger: EventTrigger, position: Int) { imageTitle.text = eventTrigger.getStringType(resourceManager) imageDesc.text = eventTrigger.time?.toLocaleString() ?: "" @@ -39,7 +39,7 @@ class ImageVH(private val resourceManager: IResourceManager, imageView.setOnClickListener { - listener.onImageClick(eventTrigger) + listener.onImageClick(eventTrigger, position) } imageView.setOnLongClickListener { @@ -49,7 +49,7 @@ class ImageVH(private val resourceManager: IResourceManager, } interface ImageClickListener { - fun onImageClick(eventTrigger: EventTrigger) + fun onImageClick(eventTrigger: EventTrigger, position: Int) fun onImageLongClick(eventTrigger: EventTrigger) } From 69fa543d227f57a6ac60ccf2fe94ff1c0979b30a Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Fri, 22 Feb 2019 23:17:34 +0530 Subject: [PATCH 4/7] Add index numbers to Event log and Event Triggers Signed-off-by: Arka Prava Basu --- .../org/havenapp/main/ui/EventAdapter.java | 4 ++- .../havenapp/main/ui/EventTriggerAdapter.java | 12 +++---- .../havenapp/main/ui/viewholder/AudioVH.kt | 4 ++- .../main/ui/viewholder/EventTriggerVH.kt | 4 ++- .../havenapp/main/ui/viewholder/ImageVH.kt | 2 ++ .../havenapp/main/ui/viewholder/VideoVH.kt | 4 ++- src/main/res/layout/item_audio.xml | 7 ++++ src/main/res/layout/item_event.xml | 35 +++++++++++-------- src/main/res/layout/item_event_trigger.xml | 9 ++++- src/main/res/layout/item_photo.xml | 14 +++++--- src/main/res/layout/item_video.xml | 14 +++++--- 11 files changed, 76 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/havenapp/main/ui/EventAdapter.java b/src/main/java/org/havenapp/main/ui/EventAdapter.java index 827ab677..27cc45cd 100644 --- a/src/main/java/org/havenapp/main/ui/EventAdapter.java +++ b/src/main/java/org/havenapp/main/ui/EventAdapter.java @@ -47,6 +47,7 @@ public void onBindViewHolder(@NonNull EventVH holder, int position) { String desc = event.getEventTriggerCount() + " " + resourceManager.getString(R.string.detection_events); + holder.index.setText("#" + (position + 1)); holder.title.setText(title); holder.note.setText(desc); @@ -58,11 +59,12 @@ public int getItemCount() { } class EventVH extends RecyclerView.ViewHolder implements View.OnClickListener { - TextView title, note; + TextView index, title, note; EventVH(View itemView) { super(itemView); + index = itemView.findViewById(R.id.index_number); title = itemView.findViewById(R.id.event_item_title); note = itemView.findViewById(R.id.event_item_desc); diff --git a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java index cb58780c..11ea38a9 100644 --- a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java +++ b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java @@ -72,29 +72,29 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi { switch (eventTrigger.getType()) { case EventTrigger.CAMERA_VIDEO: - ((VideoVH) holder).bind(eventTrigger); + ((VideoVH) holder).bind(eventTrigger, position); break; case EventTrigger.CAMERA: ((ImageVH) holder).bind(eventTrigger, position); break; case EventTrigger.MICROPHONE: - ((AudioVH) holder).bind(eventTrigger, context); + ((AudioVH) holder).bind(eventTrigger, context, position); break; case EventTrigger.ACCELEROMETER: ((EventTriggerVH) holder) - .bind(eventTrigger, resourceManager.getString(R.string.data_speed)); + .bind(eventTrigger, resourceManager.getString(R.string.data_speed), position); break; case EventTrigger.LIGHT: ((EventTriggerVH) holder) - .bind(eventTrigger, resourceManager.getString(R.string.data_light)); + .bind(eventTrigger, resourceManager.getString(R.string.data_light), position); break; case EventTrigger.PRESSURE: ((EventTriggerVH) holder) - .bind(eventTrigger, resourceManager.getString(R.string.data_pressure)); + .bind(eventTrigger, resourceManager.getString(R.string.data_pressure), position); break; case EventTrigger.POWER: ((EventTriggerVH) holder) - .bind(eventTrigger, resourceManager.getString(R.string.data_power)); + .bind(eventTrigger, resourceManager.getString(R.string.data_power), position); break; } } diff --git a/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt index 6f4feab8..dea336d9 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt @@ -22,12 +22,14 @@ class AudioVH(private val resourceManager: IResourceManager, viewGroup: ViewGrou : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) .inflate(R.layout.item_audio, viewGroup, false)) { + private val indexNumber = itemView.findViewById(R.id.index_number) private val audioTitle = itemView.findViewById(R.id.item_audio_title) private val audioDesc = itemView.findViewById(R.id.item_audio_desc) private val waveFormView = itemView.findViewById(R.id.item_sound) private val playerContainer = itemView.findViewById(R.id.item_player_container) - fun bind(eventTrigger: EventTrigger, context: Context) { + fun bind(eventTrigger: EventTrigger, context: Context, position: Int) { + indexNumber.text = "#${position + 1}" audioTitle.text = eventTrigger.getStringType(resourceManager) audioDesc.text = eventTrigger.time?.toLocaleString() ?: "" diff --git a/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt index 9cbabf6e..0a054281 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt @@ -15,10 +15,12 @@ class EventTriggerVH(private val resourceManager: IResourceManager, viewGroup: V : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) .inflate(R.layout.item_event_trigger, viewGroup, false)) { + private val indexNumber = itemView.findViewById(R.id.index_number) private val triggerTitle = itemView.findViewById(R.id.item_trigger_title) private val triggerDesc = itemView.findViewById(R.id.item_trigger_desc) - fun bind(eventTrigger: EventTrigger, string: String) { + fun bind(eventTrigger: EventTrigger, string: String, position: Int) { + indexNumber.text = "#${position + 1}" triggerTitle.text = eventTrigger.getStringType(resourceManager) triggerDesc.text = """${eventTrigger.time?.toLocaleString() ?: ""}\n$string: ${eventTrigger.path}""" } diff --git a/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt index d69b79f6..d8365429 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt @@ -18,11 +18,13 @@ class ImageVH(private val resourceManager: IResourceManager, : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) .inflate(R.layout.item_photo, viewGroup, false)) { + private val indexNumber = itemView.findViewById(R.id.index_number) private val imageTitle = itemView.findViewById(R.id.item_camera_title) private val imageDesc = itemView.findViewById(R.id.item_camera_desc) private val imageView = itemView.findViewById(R.id.item_camera_image) fun bind(eventTrigger: EventTrigger, position: Int) { + indexNumber.text = "#${position + 1}" imageTitle.text = eventTrigger.getStringType(resourceManager) imageDesc.text = eventTrigger.time?.toLocaleString() ?: "" diff --git a/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt index 602ca14c..689e3415 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt @@ -21,11 +21,13 @@ class VideoVH(private val clickListener: VideoClickListener, private val context : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context) .inflate(R.layout.item_video, viewGroup, false)) { + private val indexNumber = itemView.findViewById(R.id.index_number) private val title = itemView.findViewById(R.id.item_video_title) private val desc = itemView.findViewById(R.id.item_video_desc) private val videoView = itemView.findViewById(R.id.item_video_view) - fun bind(eventTrigger: EventTrigger) { + fun bind(eventTrigger: EventTrigger, position: Int) { + indexNumber.text = "#${position + 1}" title.text = eventTrigger.getStringType(resourceManager) desc.text = eventTrigger.time?.toLocaleString() ?: "" diff --git a/src/main/res/layout/item_audio.xml b/src/main/res/layout/item_audio.xml index fdd304da..cab1e8f1 100644 --- a/src/main/res/layout/item_audio.xml +++ b/src/main/res/layout/item_audio.xml @@ -15,6 +15,13 @@ android:orientation="vertical" android:padding="@dimen/activity_margin_half"> + + + + + android:paddingLeft="4dp" + android:paddingRight="4dp"> - + diff --git a/src/main/res/layout/item_event_trigger.xml b/src/main/res/layout/item_event_trigger.xml index e46f3090..4def30a4 100644 --- a/src/main/res/layout/item_event_trigger.xml +++ b/src/main/res/layout/item_event_trigger.xml @@ -1,8 +1,8 @@ @@ -14,6 +14,13 @@ android:orientation="vertical" android:padding="@dimen/activity_margin_half"> + + @@ -14,6 +14,13 @@ android:orientation="vertical" android:padding="@dimen/activity_margin_half"> + + + android:scaleType="centerCrop" /> @@ -14,6 +14,13 @@ android:orientation="vertical" android:padding="@dimen/activity_margin_half"> + + + android:scaleType="centerCrop" /> Date: Fri, 22 Feb 2019 23:26:57 +0530 Subject: [PATCH 5/7] Bug fix: Show Bump triggers in List Signed-off-by: Arka Prava Basu --- src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java | 2 ++ .../java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java index 11ea38a9..bdf712f1 100644 --- a/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java +++ b/src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java @@ -58,6 +58,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int case EventTrigger.LIGHT: case EventTrigger.PRESSURE: case EventTrigger.POWER: + case EventTrigger.BUMP: return new EventTriggerVH(resourceManager, parent); } return new RecyclerView.ViewHolder(new View(context)) {}; @@ -81,6 +82,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi ((AudioVH) holder).bind(eventTrigger, context, position); break; case EventTrigger.ACCELEROMETER: + case EventTrigger.BUMP: ((EventTriggerVH) holder) .bind(eventTrigger, resourceManager.getString(R.string.data_speed), position); break; diff --git a/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt index 0a054281..374d937f 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt @@ -22,6 +22,7 @@ class EventTriggerVH(private val resourceManager: IResourceManager, viewGroup: V fun bind(eventTrigger: EventTrigger, string: String, position: Int) { indexNumber.text = "#${position + 1}" triggerTitle.text = eventTrigger.getStringType(resourceManager) - triggerDesc.text = """${eventTrigger.time?.toLocaleString() ?: ""}\n$string: ${eventTrigger.path}""" + triggerDesc.text = """${eventTrigger.time?.toLocaleString() ?: ""} + |$string: ${eventTrigger.path}""".trimMargin() } } From 9c41f2a3a73893e836e9b3300ca55ae6711c6b31 Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Wed, 27 Feb 2019 01:44:16 +0530 Subject: [PATCH 6/7] Move item index number to right Signed-off-by: Arka Prava Basu --- src/main/res/layout/item_audio.xml | 34 +++++++++++++++------- src/main/res/layout/item_event.xml | 34 +++++++++++++++------- src/main/res/layout/item_event_trigger.xml | 34 +++++++++++++++------- src/main/res/layout/item_photo.xml | 34 +++++++++++++++------- src/main/res/layout/item_video.xml | 34 +++++++++++++++------- 5 files changed, 115 insertions(+), 55 deletions(-) diff --git a/src/main/res/layout/item_audio.xml b/src/main/res/layout/item_audio.xml index cab1e8f1..69f44dca 100644 --- a/src/main/res/layout/item_audio.xml +++ b/src/main/res/layout/item_audio.xml @@ -15,19 +15,31 @@ android:orientation="vertical" android:padding="@dimen/activity_margin_half"> - - - + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + - - - + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + - - - + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + - - - + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + - - - + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + Date: Wed, 27 Feb 2019 22:31:13 +0530 Subject: [PATCH 7/7] Extract layout header as a separate view - include this xml in other view xml to reduce code redundancy Signed-off-by: Arka Prava Basu --- .../org/havenapp/main/ui/EventAdapter.java | 2 +- .../havenapp/main/ui/viewholder/AudioVH.kt | 2 +- .../main/ui/viewholder/EventTriggerVH.kt | 2 +- .../havenapp/main/ui/viewholder/ImageVH.kt | 2 +- .../havenapp/main/ui/viewholder/VideoVH.kt | 2 +- src/main/res/layout/item_audio.xml | 27 ++----------------- src/main/res/layout/item_event.xml | 27 ++----------------- src/main/res/layout/item_event_trigger.xml | 27 ++----------------- src/main/res/layout/item_header.xml | 27 +++++++++++++++++++ src/main/res/layout/item_photo.xml | 27 ++----------------- src/main/res/layout/item_video.xml | 27 ++----------------- 11 files changed, 42 insertions(+), 130 deletions(-) create mode 100644 src/main/res/layout/item_header.xml diff --git a/src/main/java/org/havenapp/main/ui/EventAdapter.java b/src/main/java/org/havenapp/main/ui/EventAdapter.java index 27cc45cd..ffb8ad7c 100644 --- a/src/main/java/org/havenapp/main/ui/EventAdapter.java +++ b/src/main/java/org/havenapp/main/ui/EventAdapter.java @@ -65,7 +65,7 @@ class EventVH extends RecyclerView.ViewHolder implements View.OnClickListener { super(itemView); index = itemView.findViewById(R.id.index_number); - title = itemView.findViewById(R.id.event_item_title); + title = itemView.findViewById(R.id.title); note = itemView.findViewById(R.id.event_item_desc); itemView.setOnClickListener(this); diff --git a/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt index dea336d9..d24db6b7 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt @@ -23,7 +23,7 @@ class AudioVH(private val resourceManager: IResourceManager, viewGroup: ViewGrou .inflate(R.layout.item_audio, viewGroup, false)) { private val indexNumber = itemView.findViewById(R.id.index_number) - private val audioTitle = itemView.findViewById(R.id.item_audio_title) + private val audioTitle = itemView.findViewById(R.id.title) private val audioDesc = itemView.findViewById(R.id.item_audio_desc) private val waveFormView = itemView.findViewById(R.id.item_sound) private val playerContainer = itemView.findViewById(R.id.item_player_container) diff --git a/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt index 374d937f..0e7e8f5e 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt @@ -16,7 +16,7 @@ class EventTriggerVH(private val resourceManager: IResourceManager, viewGroup: V .inflate(R.layout.item_event_trigger, viewGroup, false)) { private val indexNumber = itemView.findViewById(R.id.index_number) - private val triggerTitle = itemView.findViewById(R.id.item_trigger_title) + private val triggerTitle = itemView.findViewById(R.id.title) private val triggerDesc = itemView.findViewById(R.id.item_trigger_desc) fun bind(eventTrigger: EventTrigger, string: String, position: Int) { diff --git a/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt index d8365429..8e2f4169 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt @@ -19,7 +19,7 @@ class ImageVH(private val resourceManager: IResourceManager, .inflate(R.layout.item_photo, viewGroup, false)) { private val indexNumber = itemView.findViewById(R.id.index_number) - private val imageTitle = itemView.findViewById(R.id.item_camera_title) + private val imageTitle = itemView.findViewById(R.id.title) private val imageDesc = itemView.findViewById(R.id.item_camera_desc) private val imageView = itemView.findViewById(R.id.item_camera_image) diff --git a/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt b/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt index 689e3415..933f47c1 100644 --- a/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt +++ b/src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt @@ -22,7 +22,7 @@ class VideoVH(private val clickListener: VideoClickListener, private val context .inflate(R.layout.item_video, viewGroup, false)) { private val indexNumber = itemView.findViewById(R.id.index_number) - private val title = itemView.findViewById(R.id.item_video_title) + private val title = itemView.findViewById(R.id.title) private val desc = itemView.findViewById(R.id.item_video_desc) private val videoView = itemView.findViewById(R.id.item_video_view) diff --git a/src/main/res/layout/item_audio.xml b/src/main/res/layout/item_audio.xml index 69f44dca..df2957ab 100644 --- a/src/main/res/layout/item_audio.xml +++ b/src/main/res/layout/item_audio.xml @@ -15,31 +15,8 @@ android:orientation="vertical" android:padding="@dimen/activity_margin_half"> - - - - - - - + - - - - - - - + - - - - - - - + + + + + + + + diff --git a/src/main/res/layout/item_photo.xml b/src/main/res/layout/item_photo.xml index 18c67b7d..5696fd2d 100644 --- a/src/main/res/layout/item_photo.xml +++ b/src/main/res/layout/item_photo.xml @@ -14,31 +14,8 @@ android:orientation="vertical" android:padding="@dimen/activity_margin_half"> - - - - - - - + - - - - - - - +