Skip to content

Commit

Permalink
[android] ads metadata to image viewer fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed May 8, 2017
1 parent 71702d5 commit 74a20bb
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 19 deletions.
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.frostwire.android"
android:installLocation="auto"
android:versionCode="373"
android:versionCode="374"
android:versionName="1.9.4">
<!-- IMPORTANT!! Ignore these, just use as a reference, now it's handled with gradle -->
<!-- Plus android:versionCode="9050xyz" (always commit like this, plus!)-->
Expand Down
Binary file added android/res/drawable/image_info_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 106 additions & 7 deletions android/res/layout/fragment_image_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
*/
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_background_body_light">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_background_body_light"
android:animateLayoutChanges="true">

<ProgressBar
android:id="@+id/fragment_image_viewer_progress_bar"
style="@style/ProgressBarHolo.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:indeterminate="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:indeterminate="true"
/>

<ImageView
Expand All @@ -44,6 +45,104 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/fragment_image_viewer_progress_bar"
android:visibility="gone"
android:layout_centerInParent="true"/>
android:layout_centerInParent="true"
android:visibility="gone"/>

<RelativeLayout
android:id="@+id/fragment_image_viewer_metadata_layout"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:background="#CC000000"
android:clickable="true"
android:padding="25dp">

<LinearLayout
android:id="@+id/fragment_image_viewer_metadata_layout_top_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"
android:textColor="@color/white"/>

<TextView
android:id="@+id/fragment_image_viewer_metadata_filename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="[file name goes here]"
android:textColor="@color/white"
android:textStyle="bold"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/fragment_image_viewer_metadata_layout_top_section"
android:orientation="horizontal"
android:paddingTop="25dp"
android:weightSum="1.0"
android:id="@+id/linearLayout">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/size"
android:textColor="@color/white"/>

<TextView
android:id="@+id/fragment_image_viewer_metadata_filesize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="[file size goes here]"
android:textColor="@color/white"
android:textStyle="bold"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date"
android:textColor="@color/white"/>

<TextView
android:id="@+id/fragment_image_viewer_metadata_date_created"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="[date taken goes here]"
android:textColor="@color/white"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

<ImageButton
android:id="@+id/fragment_image_viewer_info_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_info_icon"
android:background="@color/transparent"
android:layout_above="@+id/fragment_image_viewer_metadata_layout"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-20dp"
/>
</RelativeLayout>
2 changes: 2 additions & 0 deletions android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,6 @@
<string name="vpn_drop_protection_summary">Protect your privacy. Automatically disable BitTorrent transfers unless an encrypted VPN connection is active</string>
<string name="dismiss">Dismiss</string>
<string name="fullscreen">fullscreen</string>
<string name="size">Size</string>
<string name="date">Date</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ protected void initComponents(Bundle savedInstanceState) {
Bundle fileDescriptorBundle = getIntent().getExtras();
ImageViewerFragment imageViewerFragment = (ImageViewerFragment) getFragmentManager().findFragmentById(R.id.fragment_image_viewer);
FileDescriptor fd = new FileDescriptor(fileDescriptorBundle);
imageViewerFragment.updateImage(fd);
imageViewerFragment.updateData(fd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
import android.view.MenuItem;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.frostwire.android.AndroidPlatform;
import com.frostwire.android.R;
Expand All @@ -51,6 +55,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
Expand All @@ -61,11 +66,19 @@
*/
public class ImageViewerFragment extends AbstractFragment {
private static final Logger LOG = Logger.getLogger(ImageViewerFragment.class);
private static int EXPANDED_METADATA_LAYOUT_HEIGHT;
private static final int CONTRACTED_METADATA_LAYOUT_HEIGHT = 100;
private ImageView preloadImageView; // tried doing this with a single imageviewer, didn't work.
private TouchImageView imageView;
private ProgressBar progressBar;
private FileDescriptor fd;
private ImageViewerActionModeCallback actionModeCallback;
private ImageButton infoButton;
private RelativeLayout metadataLayout;
private ViewGroup.LayoutParams metadataLayoutParams;
private TextView fileNameTextView;
private TextView fileSizeTextView;
private TextView fileDateTextView;

public ImageViewerFragment() {
super(R.layout.fragment_image_viewer);
Expand All @@ -75,41 +88,62 @@ public ImageViewerFragment() {

@Override
protected void initComponents(View v) {
fileNameTextView = findView(v, R.id.fragment_image_viewer_metadata_filename);
fileSizeTextView = findView(v, R.id.fragment_image_viewer_metadata_filesize);
fileDateTextView = findView(v, R.id.fragment_image_viewer_metadata_date_created);
progressBar = findView(v, R.id.fragment_image_viewer_progress_bar);
preloadImageView = findView(v, R.id.fragment_image_viewer_preload_image);
imageView = findView(v, R.id.fragment_image_viewer_image);
infoButton = findView(v, R.id.fragment_image_viewer_info_button);
metadataLayout = findView(v, R.id.fragment_image_viewer_metadata_layout);
progressBar.setVisibility(View.VISIBLE);
preloadImageView.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE);
metadataLayout.setVisibility(View.VISIBLE);
metadataLayoutParams = metadataLayout.getLayoutParams();
EXPANDED_METADATA_LAYOUT_HEIGHT = metadataLayoutParams.height;

infoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onInfoButtonClick();
}
});

metadataLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onInfoButtonClick();
}
});
}

@Override
public void onResume() {
super.onResume();
updateImage(fd);
updateData(fd);
}

public void updateImage(FileDescriptor fd) {
public void updateData(FileDescriptor fd) {
this.fd = fd;
if (actionModeCallback == null) {
actionModeCallback = new ImageViewerActionModeCallback(this.fd);
startActionMode(actionModeCallback);
}
Uri fileUri = UIUtils.getFileUri(getActivity(), fd.filePath, false);

updateFileMetadata(fd);

Uri fileUri = UIUtils.getFileUri(getActivity(), fd.filePath, false);
progressBar.setVisibility(View.VISIBLE);
preloadImageView.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE);

ImageLoader imageLoader = ImageLoader.getInstance(getActivity());

// get screen dimensions and orientation once
int[] dimsAndRot = UIUtils.getScreenDimensionsAndRotation(getActivity());
final int screenWidth = dimsAndRot[0];
final int screenHeight = dimsAndRot[1];
int screenRotation = dimsAndRot[2];
final boolean screenIsVertical = screenRotation == Surface.ROTATION_0 || screenRotation == Surface.ROTATION_180;

final boolean screenIsVertical = screenRotation == Surface.ROTATION_0 || screenRotation == Surface.ROTATION_180;
// downsize to bad quality for responsive UI when opening fragment
int preloadingWidth = screenIsVertical ? 0 : 32;
int preloadingHeight = screenIsVertical ? 32 : 0;
Expand All @@ -126,7 +160,18 @@ public void onError() {
getActivity().finish();
}
});
}

private void updateFileMetadata(FileDescriptor fd) {
fileNameTextView.setText(FilenameUtils.getName(fd.filePath));
fileSizeTextView.setText(UIUtils.getBytesInHuman(fd.fileSize));
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(fd.dateAdded*1000);
int numMonth = cal.get(Calendar.MONTH) + 1;
int numDay = cal.get(Calendar.DAY_OF_MONTH) + 1;
String month = numMonth >= 10 ? String.valueOf(numMonth) : "0" + numMonth;
String day = numDay >= 10 ? String.valueOf(numDay) : "0" + numDay;
fileDateTextView.setText(cal.get(Calendar.YEAR) + "-" + month + "-" + day);
}

private void onBitmapLoaded(final Bitmap bitmap,
Expand All @@ -138,7 +183,6 @@ private void onBitmapLoaded(final Bitmap bitmap,
LOG.warn("onBitmapLoaded() -> check your logic. You shouldn't be loading this bitmap on the main thread.");
return;
}

int finalHeight = (int) (screenHeight / 3.0);
int finalWidth = (int) (screenWidth / 3.0);
// downsize it if you have to
Expand All @@ -147,7 +191,6 @@ private void onBitmapLoaded(final Bitmap bitmap,
} else if (!screenIsVertical && bitmap.getWidth() > screenWidth) {
requestCreator.resize(finalWidth, 0);
}

// final image loading in UI thread
getActivity().runOnUiThread(new Runnable() {
@Override
Expand All @@ -169,6 +212,17 @@ public void onError() {
});
}

private void onInfoButtonClick() {
ViewGroup.LayoutParams currentParams = metadataLayout.getLayoutParams();
if (currentParams.height == EXPANDED_METADATA_LAYOUT_HEIGHT) {
currentParams.height = CONTRACTED_METADATA_LAYOUT_HEIGHT;
} else {
currentParams.height = EXPANDED_METADATA_LAYOUT_HEIGHT;
}
metadataLayout.setLayoutParams(currentParams);
}


private class ImageViewerActionModeCallback implements android.support.v7.view.ActionMode.Callback {
private final FileDescriptor fd;
private ActionMode mode;
Expand Down Expand Up @@ -224,7 +278,7 @@ public void onDialogClick(String tag, int which) {
new RenameFileMenuAction(context, null, fd, new AbstractDialog.OnDialogClickListener() {
@Override
public void onDialogClick(String tag, int which) {
if (which==1 && tag !=null) {
if (which == 1 && tag != null) {
onRenameFileMenuDialogOk(tag, fMode);
}
}
Expand Down

0 comments on commit 74a20bb

Please sign in to comment.