Browse Source

Merge branch 'rv_optimise' of https://github.com/archie94/haven into archie94-rv_optimise

n8fr8 6 months ago
parent
commit
5f31227795

+ 19 - 7
src/main/java/org/havenapp/main/ui/EventActivity.java

@@ -23,6 +23,7 @@ import org.havenapp.main.model.Event;
23 23
 import org.havenapp.main.model.EventTrigger;
24 24
 import org.havenapp.main.resources.IResourceManager;
25 25
 import org.havenapp.main.resources.ResourceManager;
26
+import org.jetbrains.annotations.NotNull;
26 27
 
27 28
 import java.io.File;
28 29
 import java.text.SimpleDateFormat;
@@ -126,7 +127,7 @@ public class EventActivity extends AppCompatActivity implements EventTriggerAdap
126 127
      */
127 128
     private void onEventTriggerListFetched(@NonNull List<EventTrigger> eventTriggerList) {
128 129
         this.eventTriggerList = eventTriggerList;
129
-        setEventTriggerImagePaths(eventTriggerList);
130
+        setEventTriggerImagePaths();
130 131
         mAdapter.setEventTriggers(eventTriggerList);
131 132
     }
132 133
 
@@ -228,20 +229,20 @@ public class EventActivity extends AppCompatActivity implements EventTriggerAdap
228 229
     }
229 230
 
230 231
     @Override
231
-    public void onVideoClick(EventTrigger eventTrigger) {
232
+    public void onVideoClick(@NotNull EventTrigger eventTrigger) {
232 233
         Intent intent = new Intent(this, VideoPlayerActivity.class);
233 234
         intent.setData(Uri.fromFile(new File(eventTrigger.getPath())));
234 235
         startActivity(intent);
235 236
     }
236 237
 
237 238
     @Override
238
-    public void onVideoLongClick(EventTrigger eventTrigger) {
239
+    public void onVideoLongClick(@NotNull EventTrigger eventTrigger) {
239 240
         shareMedia(eventTrigger);
240 241
     }
241 242
 
242 243
     @Override
243
-    public void onImageClick(EventTrigger eventTrigger) {
244
-        int startPosition = 0;
244
+    public void onImageClick(@NotNull EventTrigger eventTrigger, int position) {
245
+        int startPosition = getPositionOfImagePath(position);
245 246
 
246 247
         ShareOverlayView overlayView = new ShareOverlayView(this);
247 248
         ImageViewer viewer = new ImageViewer.Builder<>(this, eventTriggerImagePaths)
@@ -252,7 +253,7 @@ public class EventActivity extends AppCompatActivity implements EventTriggerAdap
252 253
     }
253 254
 
254 255
     @Override
255
-    public void onImageLongClick(EventTrigger eventTrigger) {
256
+    public void onImageLongClick(@NotNull EventTrigger eventTrigger) {
256 257
         shareMedia(eventTrigger);
257 258
     }
258 259
 
@@ -264,7 +265,7 @@ public class EventActivity extends AppCompatActivity implements EventTriggerAdap
264 265
         startActivity(shareIntent);
265 266
     }
266 267
 
267
-    private void setEventTriggerImagePaths(List<EventTrigger> eventTriggerList) {
268
+    private void setEventTriggerImagePaths() {
268 269
         this.eventTriggerImagePaths = new ArrayList<>();
269 270
         for (EventTrigger trigger : eventTriggerList)
270 271
         {
@@ -275,4 +276,15 @@ public class EventActivity extends AppCompatActivity implements EventTriggerAdap
275 276
             }
276 277
         }
277 278
     }
279
+
280
+    private int getPositionOfImagePath(int position) {
281
+        int pos = -1;
282
+        for (int i = 0; i <= position; i++) {
283
+            if (eventTriggerList.get(i).getType() == EventTrigger.CAMERA &&
284
+                    (!TextUtils.isEmpty(eventTriggerList.get(i).getPath()))) {
285
+                pos++;
286
+            }
287
+        }
288
+        return pos;
289
+    }
278 290
 }

+ 4 - 2
src/main/java/org/havenapp/main/ui/EventAdapter.java

@@ -47,6 +47,7 @@ public class EventAdapter extends RecyclerView.Adapter<EventAdapter.EventVH> {
47 47
         String desc = event.getEventTriggerCount() + " " +
48 48
                 resourceManager.getString(R.string.detection_events);
49 49
 
50
+        holder.index.setText("#" + (position + 1));
50 51
         holder.title.setText(title);
51 52
         holder.note.setText(desc);
52 53
 
@@ -58,12 +59,13 @@ public class EventAdapter extends RecyclerView.Adapter<EventAdapter.EventVH> {
58 59
     }
59 60
 
60 61
     class EventVH extends RecyclerView.ViewHolder implements View.OnClickListener {
61
-        TextView title, note;
62
+        TextView index, title, note;
62 63
 
63 64
         EventVH(View itemView) {
64 65
             super(itemView);
65 66
 
66
-           title = itemView.findViewById(R.id.event_item_title);
67
+            index = itemView.findViewById(R.id.index_number);
68
+           title = itemView.findViewById(R.id.title);
67 69
             note = itemView.findViewById(R.id.event_item_desc);
68 70
 
69 71
             itemView.setOnClickListener(this);

+ 41 - 140
src/main/java/org/havenapp/main/ui/EventTriggerAdapter.java

@@ -1,25 +1,17 @@
1 1
 package org.havenapp.main.ui;
2 2
 
3 3
 import android.content.Context;
4
-import android.graphics.drawable.BitmapDrawable;
5
-import android.media.ThumbnailUtils;
6
-import android.net.Uri;
7
-import android.provider.MediaStore;
8
-import android.view.LayoutInflater;
9 4
 import android.view.View;
10 5
 import android.view.ViewGroup;
11
-import android.widget.ImageView;
12
-import android.widget.TextView;
13
-import android.widget.VideoView;
14
-
15
-import com.github.derlio.waveform.SimpleWaveformView;
16
-import com.github.derlio.waveform.soundfile.SoundFile;
17 6
 
18 7
 import org.havenapp.main.R;
19 8
 import org.havenapp.main.model.EventTrigger;
20 9
 import org.havenapp.main.resources.IResourceManager;
10
+import org.havenapp.main.ui.viewholder.AudioVH;
11
+import org.havenapp.main.ui.viewholder.EventTriggerVH;
12
+import org.havenapp.main.ui.viewholder.ImageVH;
13
+import org.havenapp.main.ui.viewholder.VideoVH;
21 14
 
22
-import java.io.File;
23 15
 import java.util.List;
24 16
 
25 17
 import androidx.annotation.NonNull;
@@ -30,7 +22,7 @@ import nl.changer.audiowife.AudioWife;
30 22
  * Created by n8fr8 on 4/16/17.
31 23
  */
32 24
 
33
-public class EventTriggerAdapter extends RecyclerView.Adapter<EventTriggerAdapter.EventTriggerVH> {
25
+public class EventTriggerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
34 26
 
35 27
     private Context context;
36 28
     private IResourceManager resourceManager;
@@ -38,8 +30,6 @@ public class EventTriggerAdapter extends RecyclerView.Adapter<EventTriggerAdapte
38 30
 
39 31
     private EventTriggerClickListener eventTriggerClickListener;
40 32
 
41
-    private final static String AUTHORITY = "org.havenapp.main.fileprovider";
42
-
43 33
     EventTriggerAdapter(Context context, @NonNull List<EventTrigger> eventTriggers,
44 34
                         IResourceManager resourceManager, EventTriggerClickListener eventTriggerClickListener) {
45 35
         this.context = context;
@@ -55,129 +45,61 @@ public class EventTriggerAdapter extends RecyclerView.Adapter<EventTriggerAdapte
55 45
 
56 46
     @NonNull
57 47
     @Override
58
-    public EventTriggerVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
59
-        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_event, parent, false);
60
-
61
-        return new EventTriggerVH(view);
48
+    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
49
+
50
+        switch (viewType) {
51
+            case EventTrigger.CAMERA_VIDEO:
52
+                return new VideoVH(eventTriggerClickListener, context, resourceManager, parent);
53
+            case EventTrigger.CAMERA:
54
+                return new ImageVH(resourceManager, eventTriggerClickListener, parent);
55
+            case EventTrigger.MICROPHONE:
56
+                return new AudioVH(resourceManager, parent);
57
+            case EventTrigger.ACCELEROMETER:
58
+            case EventTrigger.LIGHT:
59
+            case EventTrigger.PRESSURE:
60
+            case EventTrigger.POWER:
61
+            case EventTrigger.BUMP:
62
+                return new EventTriggerVH(resourceManager, parent);
63
+        }
64
+        return new RecyclerView.ViewHolder(new View(context)) {};
62 65
     }
63 66
 
64 67
     @Override
65
-    public void onBindViewHolder(@NonNull EventTriggerVH holder, int position) {
68
+    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
66 69
 
67 70
         final EventTrigger eventTrigger = eventTriggers.get(position);
68 71
 
69
-        String title = eventTrigger.getStringType(resourceManager);
70
-        String desc = eventTrigger.getTime().toLocaleString();
71
-
72
-        holder.image.setVisibility(View.GONE);
73
-        holder.video.setVisibility(View.GONE);
74
-        holder.extra.setVisibility(View.GONE);
75
-        holder.sound.setVisibility(View.GONE);
76
-
77
-
78
-        if (eventTrigger.getPath() != null)
72
+        if (eventTrigger.getPath() != null && eventTrigger.getType() != null)
79 73
         {
80 74
             switch (eventTrigger.getType()) {
81 75
                 case EventTrigger.CAMERA_VIDEO:
82
-                    holder.video.setVisibility(View.VISIBLE);
83
-                    BitmapDrawable bitmapD = new BitmapDrawable(context.getResources(),
84
-                            ThumbnailUtils.createVideoThumbnail(eventTrigger.getPath(),
85
-                            MediaStore.Video.Thumbnails.FULL_SCREEN_KIND));
86
-                    holder.video.setBackground(bitmapD);
87
-                    holder.video.setOnClickListener(view -> {
88
-                        if (eventTriggerClickListener != null) {
89
-                            eventTriggerClickListener.onVideoClick(eventTrigger);
90
-                        }
91
-                    });
92
-
93
-                    holder.video.setOnLongClickListener(view -> {
94
-                        if (eventTriggerClickListener != null) {
95
-                            eventTriggerClickListener.onVideoLongClick(eventTrigger);
96
-                        }
97
-                        return false;
98
-                    });
76
+                    ((VideoVH) holder).bind(eventTrigger, position);
99 77
                     break;
100 78
                 case EventTrigger.CAMERA:
101
-                    holder.image.setVisibility(View.VISIBLE);
102
-
103
-                    /**
104
-                    Uri fileUri = FileProvider.getUriForFile(
105
-                            context,
106
-                            AUTHORITY,
107
-                            new File(eventTrigger.getPath()));
108
-                    holder.image.setImageURI(fileUri);
109
-                    **/
110
-
111
-                    Uri fileUri = Uri.parse("file://" + eventTrigger.getPath());
112
-                    holder.image.setImageURI(fileUri);
113
-
114
-
115
-                    holder.image.setOnClickListener(view -> {
116
-                        if (eventTriggerClickListener != null)
117
-                            eventTriggerClickListener.onImageClick(eventTrigger);
118
-                    });
119
-
120
-                    holder.image.setOnLongClickListener(view -> {
121
-                        if (eventTriggerClickListener != null)
122
-                            eventTriggerClickListener.onImageLongClick(eventTrigger);
123
-                        return false;
124
-                    });
79
+                    ((ImageVH) holder).bind(eventTrigger, position);
125 80
                     break;
126 81
                 case EventTrigger.MICROPHONE:
127
-                    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
128
-
129
-                    holder.sound.setVisibility(View.VISIBLE);
130
-                    final File fileSound = new File(eventTrigger.getPath());
131
-                    try {
132
-                        final SoundFile soundFile = SoundFile.create(fileSound.getPath(), new SoundFile.ProgressListener() {
133
-                            int lastProgress = 0;
134
-
135
-                            @Override
136
-                            public boolean reportProgress(double fractionComplete) {
137
-                                final int progress = (int) (fractionComplete * 100);
138
-                                if (lastProgress == progress) {
139
-                                    return true;
140
-                                }
141
-                                lastProgress = progress;
142
-
143
-                                return true;
144
-                            }
145
-                        });
146
-                        holder.sound.setAudioFile(soundFile);
147
-                        holder.sound.invalidate();
148
-                    } catch (Exception e) {
149
-                    }
150
-
151
-                    holder.extra.setVisibility(View.VISIBLE);
152
-                    holder.extra.removeAllViews();
153
-
154
-                    AudioWife audioWife = new AudioWife();
155
-                    audioWife.init(context, Uri.fromFile(fileSound))
156
-                            .useDefaultUi(holder.extra, inflater);
157
-
82
+                    ((AudioVH) holder).bind(eventTrigger, context, position);
158 83
                     break;
159 84
                 case EventTrigger.ACCELEROMETER:
160
-                    desc += "\n" + resourceManager.getString(R.string.data_speed) + ": " + eventTrigger.getPath();
161
-
85
+                case EventTrigger.BUMP:
86
+                    ((EventTriggerVH) holder)
87
+                            .bind(eventTrigger, resourceManager.getString(R.string.data_speed), position);
162 88
                     break;
163 89
                 case EventTrigger.LIGHT:
164
-                    desc += "\n" + resourceManager.getString(R.string.data_light) + ": " + eventTrigger.getPath();
165
-
90
+                    ((EventTriggerVH) holder)
91
+                            .bind(eventTrigger, resourceManager.getString(R.string.data_light), position);
166 92
                     break;
167 93
                 case EventTrigger.PRESSURE:
168
-                    desc += "\n" + resourceManager.getString(R.string.data_pressure) + ": " + eventTrigger.getPath();
94
+                    ((EventTriggerVH) holder)
95
+                            .bind(eventTrigger, resourceManager.getString(R.string.data_pressure), position);
169 96
                     break;
170 97
                 case EventTrigger.POWER:
171
-                    desc += "\n" + resourceManager.getString(R.string.data_power) + ": " + eventTrigger.getPath();
98
+                    ((EventTriggerVH) holder)
99
+                            .bind(eventTrigger, resourceManager.getString(R.string.data_power), position);
172 100
                     break;
173 101
             }
174
-
175 102
         }
176
-
177
-        holder.title.setText(title);
178
-        holder.note.setText(desc);
179
-
180
-
181 103
     }
182 104
 
183 105
     @Override
@@ -192,32 +114,11 @@ public class EventTriggerAdapter extends RecyclerView.Adapter<EventTriggerAdapte
192 114
         return eventTriggers.size();
193 115
     }
194 116
 
195
-    class EventTriggerVH extends RecyclerView.ViewHolder {
196
-        TextView title, note;
197
-        ImageView image;
198
-        VideoView video;
199
-        ViewGroup extra;
200
-        SimpleWaveformView sound;
201
-        EventTriggerVH(View itemView) {
202
-            super(itemView);
203
-
204
-           title = itemView.findViewById(R.id.event_item_title);
205
-            note = itemView.findViewById(R.id.event_item_desc);
206
-            image = itemView.findViewById(R.id.event_item_image);
207
-            video = itemView.findViewById(R.id.event_item_video);
208
-            extra = itemView.findViewById(R.id.event_item_extra);
209
-            sound = itemView.findViewById(R.id.event_item_sound);
210
-        }
211
-    }
212
-
213
-    public interface EventTriggerClickListener {
214
-        void onVideoClick(EventTrigger eventTrigger);
215
-
216
-        void onVideoLongClick(EventTrigger eventTrigger);
217
-
218
-        void onImageClick(EventTrigger eventTrigger);
219
-
220
-        void onImageLongClick(EventTrigger eventTrigger);
117
+    @Override
118
+    public int getItemViewType(int position) {
119
+        return eventTriggers.get(position).getType();
221 120
     }
222 121
 
122
+    public interface EventTriggerClickListener extends VideoVH.VideoClickListener,
123
+            ImageVH.ImageClickListener {}
223 124
 }

+ 63 - 0
src/main/java/org/havenapp/main/ui/viewholder/AudioVH.kt

@@ -0,0 +1,63 @@
1
+package org.havenapp.main.ui.viewholder
2
+
3
+import android.content.Context
4
+import android.net.Uri
5
+import android.view.LayoutInflater
6
+import android.view.ViewGroup
7
+import android.widget.LinearLayout
8
+import android.widget.TextView
9
+import androidx.recyclerview.widget.RecyclerView
10
+import com.github.derlio.waveform.SimpleWaveformView
11
+import com.github.derlio.waveform.soundfile.SoundFile
12
+import nl.changer.audiowife.AudioWife
13
+import org.havenapp.main.R
14
+import org.havenapp.main.model.EventTrigger
15
+import org.havenapp.main.resources.IResourceManager
16
+import java.io.File
17
+
18
+/**
19
+ * Created by Arka Prava Basu<arkaprava94@gmail.com> on 21/02/19
20
+ **/
21
+class AudioVH(private val resourceManager: IResourceManager, viewGroup: ViewGroup)
22
+    : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context)
23
+        .inflate(R.layout.item_audio, viewGroup, false)) {
24
+
25
+    private val indexNumber = itemView.findViewById<TextView>(R.id.index_number)
26
+    private val audioTitle = itemView.findViewById<TextView>(R.id.title)
27
+    private val audioDesc = itemView.findViewById<TextView>(R.id.item_audio_desc)
28
+    private val waveFormView = itemView.findViewById<SimpleWaveformView>(R.id.item_sound)
29
+    private val playerContainer = itemView.findViewById<LinearLayout>(R.id.item_player_container)
30
+
31
+    fun bind(eventTrigger: EventTrigger, context: Context, position: Int) {
32
+        indexNumber.text = "#${position + 1}"
33
+        audioTitle.text = eventTrigger.getStringType(resourceManager)
34
+        audioDesc.text = eventTrigger.time?.toLocaleString() ?: ""
35
+
36
+        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
37
+
38
+        val fileSound = File(eventTrigger.path)
39
+        try {
40
+            val soundFile = SoundFile.create(fileSound.path, object : SoundFile.ProgressListener {
41
+                var lastProgress = 0
42
+
43
+                override fun reportProgress(fractionComplete: Double): Boolean {
44
+                    val progress = (fractionComplete * 100).toInt()
45
+                    if (lastProgress == progress) {
46
+                        return true
47
+                    }
48
+                    lastProgress = progress
49
+
50
+                    return true
51
+                }
52
+            })
53
+            waveFormView.setAudioFile(soundFile)
54
+            waveFormView.invalidate()
55
+        } catch (e: Exception) {
56
+            e.printStackTrace()
57
+        }
58
+
59
+        playerContainer.removeAllViews()
60
+
61
+        AudioWife().init(context, Uri.fromFile(fileSound)).useDefaultUi(playerContainer, inflater)
62
+    }
63
+}

+ 28 - 0
src/main/java/org/havenapp/main/ui/viewholder/EventTriggerVH.kt

@@ -0,0 +1,28 @@
1
+package org.havenapp.main.ui.viewholder
2
+
3
+import android.view.LayoutInflater
4
+import android.view.ViewGroup
5
+import android.widget.TextView
6
+import androidx.recyclerview.widget.RecyclerView
7
+import org.havenapp.main.R
8
+import org.havenapp.main.model.EventTrigger
9
+import org.havenapp.main.resources.IResourceManager
10
+
11
+/**
12
+ * Created by Arka Prava Basu<arkaprava94@gmail.com> on 21/02/19
13
+ **/
14
+class EventTriggerVH(private val resourceManager: IResourceManager, viewGroup: ViewGroup)
15
+    : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context)
16
+        .inflate(R.layout.item_event_trigger, viewGroup, false)) {
17
+
18
+    private val indexNumber = itemView.findViewById<TextView>(R.id.index_number)
19
+    private val triggerTitle = itemView.findViewById<TextView>(R.id.title)
20
+    private val triggerDesc = itemView.findViewById<TextView>(R.id.item_trigger_desc)
21
+
22
+    fun bind(eventTrigger: EventTrigger, string: String, position: Int) {
23
+        indexNumber.text = "#${position + 1}"
24
+        triggerTitle.text = eventTrigger.getStringType(resourceManager)
25
+        triggerDesc.text = """${eventTrigger.time?.toLocaleString() ?: ""}
26
+            |$string: ${eventTrigger.path}""".trimMargin()
27
+    }
28
+}

+ 58 - 0
src/main/java/org/havenapp/main/ui/viewholder/ImageVH.kt

@@ -0,0 +1,58 @@
1
+package org.havenapp.main.ui.viewholder
2
+
3
+import android.net.Uri
4
+import android.view.LayoutInflater
5
+import android.view.ViewGroup
6
+import android.widget.TextView
7
+import androidx.recyclerview.widget.RecyclerView
8
+import com.facebook.drawee.view.SimpleDraweeView
9
+import org.havenapp.main.R
10
+import org.havenapp.main.model.EventTrigger
11
+import org.havenapp.main.resources.IResourceManager
12
+
13
+/**
14
+ * Created by Arka Prava Basu<arkaprava94@gmail.com> on 21/02/19
15
+ **/
16
+class ImageVH(private val resourceManager: IResourceManager,
17
+              private val listener: ImageClickListener, viewGroup: ViewGroup)
18
+    : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context)
19
+        .inflate(R.layout.item_photo, viewGroup, false)) {
20
+
21
+    private val indexNumber = itemView.findViewById<TextView>(R.id.index_number)
22
+    private val imageTitle = itemView.findViewById<TextView>(R.id.title)
23
+    private val imageDesc = itemView.findViewById<TextView>(R.id.item_camera_desc)
24
+    private val imageView = itemView.findViewById<SimpleDraweeView>(R.id.item_camera_image)
25
+
26
+    fun bind(eventTrigger: EventTrigger, position: Int) {
27
+        indexNumber.text = "#${position + 1}"
28
+        imageTitle.text = eventTrigger.getStringType(resourceManager)
29
+        imageDesc.text = eventTrigger.time?.toLocaleString() ?: ""
30
+
31
+        /**
32
+        Uri fileUri = FileProvider.getUriForFile(
33
+        context,
34
+        AUTHORITY,
35
+        new File(eventTrigger.getPath()));
36
+        holder.image.setImageURI(fileUri);
37
+         **/
38
+
39
+        val fileUri = Uri.parse("file://" + eventTrigger.path!!)
40
+        imageView.setImageURI(fileUri)
41
+
42
+
43
+        imageView.setOnClickListener {
44
+            listener.onImageClick(eventTrigger, position)
45
+        }
46
+
47
+        imageView.setOnLongClickListener {
48
+            listener.onImageLongClick(eventTrigger)
49
+            false
50
+        }
51
+    }
52
+
53
+    interface ImageClickListener {
54
+        fun onImageClick(eventTrigger: EventTrigger, position: Int)
55
+
56
+        fun onImageLongClick(eventTrigger: EventTrigger)
57
+    }
58
+}

+ 53 - 0
src/main/java/org/havenapp/main/ui/viewholder/VideoVH.kt

@@ -0,0 +1,53 @@
1
+package org.havenapp.main.ui.viewholder
2
+
3
+import android.content.Context
4
+import android.graphics.drawable.BitmapDrawable
5
+import android.media.ThumbnailUtils
6
+import android.provider.MediaStore
7
+import android.view.LayoutInflater
8
+import android.view.ViewGroup
9
+import android.widget.TextView
10
+import android.widget.VideoView
11
+import androidx.recyclerview.widget.RecyclerView
12
+import org.havenapp.main.R
13
+import org.havenapp.main.model.EventTrigger
14
+import org.havenapp.main.resources.IResourceManager
15
+
16
+/**
17
+ * Created by Arka Prava Basu<arkaprava94@gmail.com> on 21/02/19
18
+ **/
19
+class VideoVH(private val clickListener: VideoClickListener, private val context: Context,
20
+              private val resourceManager: IResourceManager, viewGroup: ViewGroup)
21
+    : RecyclerView.ViewHolder(LayoutInflater.from(viewGroup.context)
22
+        .inflate(R.layout.item_video, viewGroup, false)) {
23
+
24
+    private val indexNumber = itemView.findViewById<TextView>(R.id.index_number)
25
+    private val title = itemView.findViewById<TextView>(R.id.title)
26
+    private val desc = itemView.findViewById<TextView>(R.id.item_video_desc)
27
+    private val videoView = itemView.findViewById<VideoView>(R.id.item_video_view)
28
+
29
+    fun bind(eventTrigger: EventTrigger, position: Int) {
30
+        indexNumber.text = "#${position + 1}"
31
+        title.text = eventTrigger.getStringType(resourceManager)
32
+        desc.text = eventTrigger.time?.toLocaleString() ?: ""
33
+
34
+        val bitmapD = BitmapDrawable(context.resources,
35
+                ThumbnailUtils.createVideoThumbnail(eventTrigger.path,
36
+                        MediaStore.Video.Thumbnails.FULL_SCREEN_KIND))
37
+        videoView.background = bitmapD
38
+        videoView.setOnClickListener {
39
+            clickListener.onVideoClick(eventTrigger)
40
+        }
41
+
42
+        videoView.setOnLongClickListener {
43
+            clickListener.onVideoLongClick(eventTrigger)
44
+            false
45
+        }
46
+    }
47
+
48
+    interface VideoClickListener {
49
+        fun onVideoClick(eventTrigger: EventTrigger)
50
+
51
+        fun onVideoLongClick(eventTrigger: EventTrigger)
52
+    }
53
+}

+ 51 - 0
src/main/res/layout/item_audio.xml

@@ -0,0 +1,51 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:app="http://schemas.android.com/apk/res-auto"
4
+    xmlns:tools="http://schemas.android.com/tools"
5
+    android:layout_width="match_parent"
6
+    android:layout_height="wrap_content"
7
+    android:layout_margin="@dimen/activity_margin_half"
8
+    android:background="?attr/selectableItemBackground"
9
+    android:orientation="vertical">
10
+
11
+    <LinearLayout
12
+        android:layout_width="match_parent"
13
+        android:layout_height="wrap_content"
14
+        android:background="?attr/selectableItemBackground"
15
+        android:orientation="vertical"
16
+        android:padding="@dimen/activity_margin_half">
17
+
18
+        <include
19
+            layout="@layout/item_header" />
20
+
21
+        <com.github.derlio.waveform.SimpleWaveformView
22
+            android:id="@+id/item_sound"
23
+            android:layout_width="match_parent"
24
+            android:layout_height="144dp"
25
+            app:indicatorColor="@color/colorPrimaryDark"
26
+            app:waveformColor="@color/colorAccent" />
27
+
28
+        <LinearLayout
29
+            android:id="@+id/item_player_container"
30
+            android:layout_width="match_parent"
31
+            android:layout_height="50dp"
32
+            android:gravity="center_vertical"
33
+            android:orientation="vertical"
34
+            android:paddingLeft="4dp"
35
+            android:paddingRight="4dp" />
36
+
37
+        <TextView
38
+            android:id="@+id/item_audio_desc"
39
+            style="@style/TextAppearance.AppCompat.Body1"
40
+            android:layout_width="wrap_content"
41
+            android:layout_height="wrap_content"
42
+            android:alpha="0.54"
43
+            android:ellipsize="end"
44
+            android:maxLines="6"
45
+            android:paddingBottom="@dimen/activity_margin_half"
46
+            android:textColor="@android:color/black"
47
+            tools:text="Description" />
48
+
49
+    </LinearLayout>
50
+
51
+</androidx.cardview.widget.CardView>

+ 16 - 55
src/main/res/layout/item_event.xml

@@ -15,66 +15,27 @@
15 15
         android:orientation="vertical"
16 16
         android:padding="@dimen/activity_margin_half">
17 17
 
18
-        <TextView
19
-            android:id="@+id/event_item_title"
20
-            style="@style/TextAppearance.AppCompat.Title"
21
-            android:layout_width="match_parent"
22
-            android:layout_height="wrap_content"
23
-            tools:text="Title" />
24
-
25
-        <com.facebook.drawee.view.SimpleDraweeView
26
-            android:layout_width="match_parent"
27
-            android:layout_height="200dp"
28
-            android:id="@+id/event_item_image"
29
-            android:visibility="gone"
30
-            android:scaleType="centerCrop"
31
-            />
32
-
33
-        <VideoView
34
-            android:layout_width="match_parent"
35
-            android:layout_height="200dp"
36
-            android:id="@+id/event_item_video"
37
-            android:visibility="gone"
38
-            android:scaleType="centerCrop"
39
-            />
40
-
41
-        <com.github.derlio.waveform.SimpleWaveformView
42
-            android:id="@+id/event_item_sound"
43
-            android:layout_width="match_parent"
44
-            android:layout_height="144dp"
45
-            app:waveformColor="@color/colorAccent"
46
-            app:indicatorColor="@color/colorPrimaryDark"
47
-            android:visibility="gone"
48
-            />
49
-
50
-        <LinearLayout
51
-            android:id="@+id/event_item_extra"
52
-            android:layout_width="match_parent"
53
-            android:layout_height="50dp"
54
-            android:gravity="center_vertical"
55
-            android:orientation="vertical"
56
-            android:visibility="gone"
57
-            android:paddingLeft="4dp"
58
-            android:paddingRight="4dp" />
18
+        <include
19
+            layout="@layout/item_header" />
59 20
 
60 21
         <RelativeLayout
61 22
             android:layout_width="match_parent"
62 23
             android:layout_height="wrap_content"
63 24
             android:layout_marginTop="@dimen/activity_margin_half"
64
-            android:paddingRight="4dp"
65
-            android:paddingLeft="4dp">
25
+            android:paddingLeft="4dp"
26
+            android:paddingRight="4dp">
66 27
 
67
-        <TextView
68
-            android:id="@+id/event_item_desc"
69
-            style="@style/TextAppearance.AppCompat.Body1"
70
-            android:layout_width="wrap_content"
71
-            android:layout_height="wrap_content"
72
-            android:alpha="0.54"
73
-            android:ellipsize="end"
74
-            android:maxLines="6"
75
-            android:paddingBottom="@dimen/activity_margin_half"
76
-            android:textColor="@android:color/black"
77
-            tools:text="Description" />
28
+            <TextView
29
+                android:id="@+id/event_item_desc"
30
+                style="@style/TextAppearance.AppCompat.Body1"
31
+                android:layout_width="wrap_content"
32
+                android:layout_height="wrap_content"
33
+                android:alpha="0.54"
34
+                android:ellipsize="end"
35
+                android:maxLines="6"
36
+                android:paddingBottom="@dimen/activity_margin_half"
37
+                android:textColor="@android:color/black"
38
+                tools:text="Description" />
78 39
 
79 40
             <ImageView
80 41
                 android:id="@+id/event_action_share"
@@ -82,8 +43,8 @@
82 43
                 android:layout_height="wrap_content"
83 44
                 android:layout_alignParentEnd="true"
84 45
                 android:layout_alignParentRight="true"
85
-                android:visibility="gone"
86 46
                 android:tint="@android:color/black"
47
+                android:visibility="gone"
87 48
                 app:srcCompat="@drawable/ic_share" />
88 49
         </RelativeLayout>
89 50
 

+ 34 - 0
src/main/res/layout/item_event_trigger.xml

@@ -0,0 +1,34 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:tools="http://schemas.android.com/tools"
4
+    android:layout_width="match_parent"
5
+    android:layout_height="wrap_content"
6
+    android:layout_margin="@dimen/activity_margin_half"
7
+    android:background="?attr/selectableItemBackground"
8
+    android:orientation="vertical">
9
+
10
+    <LinearLayout
11
+        android:layout_width="match_parent"
12
+        android:layout_height="wrap_content"
13
+        android:background="?attr/selectableItemBackground"
14
+        android:orientation="vertical"
15
+        android:padding="@dimen/activity_margin_half">
16
+
17
+        <include
18
+            layout="@layout/item_header" />
19
+
20
+        <TextView
21
+            android:id="@+id/item_trigger_desc"
22
+            style="@style/TextAppearance.AppCompat.Body1"
23
+            android:layout_width="wrap_content"
24
+            android:layout_height="wrap_content"
25
+            android:alpha="0.54"
26
+            android:ellipsize="end"
27
+            android:maxLines="6"
28
+            android:paddingBottom="@dimen/activity_margin_half"
29
+            android:textColor="@android:color/black"
30
+            tools:text="Description" />
31
+
32
+    </LinearLayout>
33
+
34
+</androidx.cardview.widget.CardView>

+ 27 - 0
src/main/res/layout/item_header.xml

@@ -0,0 +1,27 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:tools="http://schemas.android.com/tools"
4
+    android:layout_width="match_parent"
5
+    android:layout_height="wrap_content"
6
+    android:gravity="center_vertical"
7
+    android:orientation="horizontal">
8
+
9
+    <TextView
10
+        android:id="@+id/title"
11
+        style="@style/TextAppearance.AppCompat.Title"
12
+        android:layout_width="0dp"
13
+        android:layout_height="wrap_content"
14
+        android:layout_weight="1"
15
+        tools:text="Title" />
16
+
17
+    <TextView
18
+        android:id="@+id/index_number"
19
+        android:layout_width="wrap_content"
20
+        android:layout_height="wrap_content"
21
+        android:layout_marginStart="4dp"
22
+        android:layout_marginLeft="4dp"
23
+        android:textColor="#808080"
24
+        android:textSize="12sp"
25
+        tools:text="#123" />
26
+
27
+</LinearLayout>

+ 40 - 0
src/main/res/layout/item_photo.xml

@@ -0,0 +1,40 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:tools="http://schemas.android.com/tools"
4
+    android:layout_width="match_parent"
5
+    android:layout_height="wrap_content"
6
+    android:layout_margin="@dimen/activity_margin_half"
7
+    android:background="?attr/selectableItemBackground"
8
+    android:orientation="vertical">
9
+
10
+    <LinearLayout
11
+        android:layout_width="match_parent"
12
+        android:layout_height="wrap_content"
13
+        android:background="?attr/selectableItemBackground"
14
+        android:orientation="vertical"
15
+        android:padding="@dimen/activity_margin_half">
16
+
17
+        <include
18
+            layout="@layout/item_header" />
19
+
20
+        <com.facebook.drawee.view.SimpleDraweeView
21
+            android:id="@+id/item_camera_image"
22
+            android:layout_width="match_parent"
23
+            android:layout_height="200dp"
24
+            android:scaleType="centerCrop" />
25
+
26
+        <TextView
27
+            android:id="@+id/item_camera_desc"
28
+            style="@style/TextAppearance.AppCompat.Body1"
29
+            android:layout_width="wrap_content"
30
+            android:layout_height="wrap_content"
31
+            android:alpha="0.54"
32
+            android:ellipsize="end"
33
+            android:maxLines="6"
34
+            android:paddingBottom="@dimen/activity_margin_half"
35
+            android:textColor="@android:color/black"
36
+            tools:text="Description" />
37
+
38
+    </LinearLayout>
39
+
40
+</androidx.cardview.widget.CardView>

+ 40 - 0
src/main/res/layout/item_video.xml

@@ -0,0 +1,40 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:tools="http://schemas.android.com/tools"
4
+    android:layout_width="match_parent"
5
+    android:layout_height="wrap_content"
6
+    android:layout_margin="@dimen/activity_margin_half"
7
+    android:background="?attr/selectableItemBackground"
8
+    android:orientation="vertical">
9
+
10
+    <LinearLayout
11
+        android:layout_width="match_parent"
12
+        android:layout_height="wrap_content"
13
+        android:background="?attr/selectableItemBackground"
14
+        android:orientation="vertical"
15
+        android:padding="@dimen/activity_margin_half">
16
+
17
+        <include
18
+            layout="@layout/item_header" />
19
+
20
+        <VideoView
21
+            android:id="@+id/item_video_view"
22
+            android:layout_width="match_parent"
23
+            android:layout_height="200dp"
24
+            android:scaleType="centerCrop" />
25
+
26
+        <TextView
27
+            android:id="@+id/item_video_desc"
28
+            style="@style/TextAppearance.AppCompat.Body1"
29
+            android:layout_width="wrap_content"
30
+            android:layout_height="wrap_content"
31
+            android:alpha="0.54"
32
+            android:ellipsize="end"
33
+            android:maxLines="6"
34
+            android:paddingBottom="@dimen/activity_margin_half"
35
+            android:textColor="@android:color/black"
36
+            tools:text="Description" />
37
+
38
+    </LinearLayout>
39
+
40
+</androidx.cardview.widget.CardView>