In Phimpme Android one core feature is of sharing images to many different platforms. After sharing we usually wants to look in the our past records, where we uploaded what pictures? Which image we uploaded? What time it was? So I added a feature to view the upload history of images. User can go to the Upload history tab, present in the navigation drawer of the app. From there he can browse the repository.
How I added history feature in Phimpme
-
Store the data when User initiate an upload
To get which data uploading is in progress. I am storing its name, date, time and image path. When user approve to upload image from Sharing Activity.
Created a database model
public class UploadHistoryRealmModel extends RealmObject{ String name; String pathname; String datetime; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPathname() { return pathname; } public void setPathname(String pathname) { this.pathname = pathname; } public String getDatetime() { return datetime; } public void setDatetime(String datetime) { this.datetime = datetime; } }
This is the realm model for storing the name, date, time and image path.
Saving in database
UploadHistoryRealmModel uploadHistory; uploadHistory = realm.createObject(UploadHistoryRealmModel.class); uploadHistory.setName(sharableAccountsList.get(position).toString()); uploadHistory.setPathname(saveFilePath); uploadHistory.setDatetime(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date())); realm.commitTransaction();
Creating realm object and setting the details in begin and commit Transaction block
-
Added upload history entry in Navigation Drawer
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_drawer_uploadhistory" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/ripple" android:clickable="true" android:orientation="horizontal"> <com.mikepenz.iconics.view.IconicsImageView android:id="@+id/Drawer_Upload_Icon" android:layout_width="@dimen/icon_width_height" android:layout_height="@dimen/icon_width_height" app:iiv_icon="gmd-file-upload"/> <TextView android:id="@+id/Drawer_Upload_Item" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/upload_history" android:textColor="@color/md_dark_background" android:textSize="16sp"/> </LinearLayout>
It consist of an ImageView and TextView in a horizontal oriented Linear Layout
-
Showing history in Upload History Activity
Added recyclerview in layout.
<android.support.v7.widget.RecyclerView android:id="@+id/upload_history_recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/toolbar"> </android.support.v7.widget.RecyclerView>
Query the database and updated the adapter of Upload History
uploadResults = realm.where(UploadHistoryRealmModel.class); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); uploadHistoryRecyclerView.setLayoutManager(layoutManager); uploadHistoryRecyclerView.setAdapter(uploadHistoryAdapter);
Added the adapter for recycler view and created an Item using Constraint layout.
Resources
- Realm Docs : https://realm.io/docs/java/latest/?gclid=Cj0KEQjw6-PJBRCO_br1qoOB4LABEiQAEkqcVWPnl36QeBPNq00Y87fuLAeKXAylrsVZML2pwDdluDYaAqKF8P8HAQ#getting-started
- Recycler View adapter:https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html
- Writing in Realm database: https://realm.io/docs/java/latest/?gclid=Cj0KEQjw6-PJBRCO_br1qoOB4LABEiQAEkqcVWPnl36QeBPNq00Y87fuLAeKXAylrsVZML2pwDdluDYaAqKF8P8HAQ#writes
- Query in Realm Database: https://realm.io/docs/java/latest/?gclid=Cj0KEQjw6-PJBRCO_br1qoOB4LABEiQAEkqcVWPnl36QeBPNq00Y87fuLAeKXAylrsVZML2pwDdluDYaAqKF8P8HAQ#queries