Skip to content

Commit

Permalink
Add Share Button to directly share files without saving them
Browse files Browse the repository at this point in the history
Signed-off-by: GauthamAsir <[email protected]>
  • Loading branch information
GauthamAsir committed Apr 22, 2020
1 parent e6d3835 commit 66d37f1
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public FilesAdapter(List<Status> imagesList) {
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

context = parent.getContext();
View view = LayoutInflater.from(context).inflate(R.layout.item_status, parent, false);
View view = LayoutInflater.from(context).inflate(R.layout.item_saved_files, parent, false);
return new ItemViewHolder(view);

}
Expand Down Expand Up @@ -72,7 +72,6 @@ public void onClick(View v) {
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+status.getFile().getAbsolutePath()));
context.startActivity(Intent.createChooser(shareIntent, "Share image"));


}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -58,6 +60,19 @@ public void onClick(View v) {
}
});

holder.share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent shareIntent = new Intent(Intent.ACTION_SEND);

shareIntent.setType("image/jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+status.getFile().getAbsolutePath()));
context.startActivity(Intent.createChooser(shareIntent, "Share image"));

}
});

holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.media.MediaPlayer;
Expand Down Expand Up @@ -51,6 +52,19 @@ public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position)
final Status status = videoList.get(position);
holder.imageView.setImageBitmap(status.getThumbnail());

holder.share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent shareIntent = new Intent(Intent.ACTION_SEND);

shareIntent.setType("image/mp4");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+status.getFile().getAbsolutePath()));
context.startActivity(Intent.createChooser(shareIntent, "Share image"));

}
});

LayoutInflater inflater = LayoutInflater.from(context);
final View view1 = inflater.inflate(R.layout.view_video_full_screen, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -53,6 +54,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
container = view.findViewById(R.id.image_container);
swipeRefreshLayout = view.findViewById(R.id.swipeRefreshLayout);

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());

swipeRefreshLayout.setColorSchemeColors(ContextCompat.getColor(getActivity(),android.R.color.holo_orange_dark)
,ContextCompat.getColor(getActivity(),android.R.color.holo_green_dark),
ContextCompat.getColor(getActivity(),R.color.colorPrimary),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -23,7 +24,6 @@
import java.util.Arrays;
import java.util.List;

import a.gautham.statusdownloader.Adapter.ImageAdapter;
import a.gautham.statusdownloader.Adapter.VideoAdapter;
import a.gautham.statusdownloader.Models.Status;
import a.gautham.statusdownloader.R;
Expand Down Expand Up @@ -54,6 +54,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
container = view.findViewById(R.id.videos_container);
swipeRefreshLayout = view.findViewById(R.id.swipeRefreshLayout);

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());

swipeRefreshLayout.setColorSchemeColors(ContextCompat.getColor(getActivity(),android.R.color.holo_orange_dark)
,ContextCompat.getColor(getActivity(),android.R.color.holo_green_dark),
ContextCompat.getColor(getActivity(),R.color.colorPrimary),
Expand Down
51 changes: 51 additions & 0 deletions app/src/main/res/layout/item_saved_files.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/_120sdp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:elevation="@dimen/_10sdp"
android:layout_margin="@dimen/_10sdp"
app:cardCornerRadius="@dimen/_10sdp"
app:cardUseCompatPadding="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rl1">

<ImageView
android:id="@+id/ivThumbnail"
android:layout_width="match_parent"
android:layout_height="@dimen/_90sdp"
android:scaleType="centerCrop"/>

<ImageButton
android:id="@+id/save"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ivThumbnail"
android:src="@drawable/ic_file_download_black"
android:tint="@color/white"
android:gravity="center"
android:backgroundTint="@android:color/transparent"/>

<ImageButton
android:id="@+id/share"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ivThumbnail"
android:src="@drawable/ic_share"
android:tint="@color/white"
android:gravity="center"
android:visibility="gone"
android:backgroundTint="@android:color/transparent"/>

</RelativeLayout>

</RelativeLayout>

</com.google.android.material.card.MaterialCardView>
43 changes: 25 additions & 18 deletions app/src/main/res/layout/item_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,33 @@
android:layout_height="@dimen/_90sdp"
android:scaleType="centerCrop"/>

<ImageButton
android:id="@+id/save"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ivThumbnail"
android:src="@drawable/ic_file_download_black"
android:tint="@color/white"
android:gravity="center"
android:backgroundTint="@android:color/transparent"/>

<ImageButton
android:id="@+id/share"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ivThumbnail"
android:src="@drawable/ic_share"
android:tint="@color/white"
android:gravity="center"
android:visibility="gone"
android:backgroundTint="@android:color/transparent"/>
android:orientation="horizontal"
android:layout_below="@+id/ivThumbnail">

<ImageButton
android:id="@+id/save"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:src="@drawable/ic_file_download_black"
android:tint="@color/white"
android:gravity="center"
android:backgroundTint="@android:color/transparent"/>

<ImageButton
android:id="@+id/share"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:src="@drawable/ic_share"
android:tint="@color/white"
android:gravity="center"
android:backgroundTint="@android:color/transparent"/>

</LinearLayout>

</RelativeLayout>

Expand Down

0 comments on commit 66d37f1

Please sign in to comment.